GLSL:iPhone应用程序无法访问内置属性? [英] GLSL: Built-in attributes not accessible for iPhone Apps?

查看:220
本文介绍了GLSL:iPhone应用程序无法访问内置属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里非常绝望。我正在使用Xcode,尝试在iPhone上实现一些OpenGL内容。我必须为Phong-Lighting写一个Shader。我已经声明了我的几何(顶点,索引,计算等)并将各自的参数作为属性传递给着色器(用GLSL编写)。使用这些属性工作正常,一些非常基本的着色器程序正确编译并给出预期的输出。

I am getting really desperate here. I working with Xcode, trying to implement some OpenGL stuff on the iPhone. I have to write a Shader for Phong-Lighting. I got as far as declaring my geometry (vertices, indices, calculating etc.) and passing the respective arguments as attributes to the shader (written in GLSL). Using these attributes works fine, some really basic shader programs compile correctly and give the expected output.

现在我正在尝试开始一些更高级的计算,为此我需要使用GLSL的一些内置属性,即g​​l_NormalMatrix,但每当我尝试时,程序崩溃,我得到一个错误:0:3:使用未声明的标识符'gl_NormalMatrix'。
只要使用任何内置属性(例如gl_Vertex,gl_Normal等),就会发生相同的情况。

Now I'm trying to start with some more advanced calculations, for which I need to use some of the built-in attributes of GLSL, namely i.e. the "gl_NormalMatrix", but whenever I try that, the program crashes and I get an "ERROR: 0:3: Use of undeclared identifier 'gl_NormalMatrix'". It happens identically whenever use any of the built-in attributes such as gl_Vertex, gl_Normal etc.

这些属性在iPhone上的GLSL中是不可用的我错过了什么?也许我还没有完全理解这是如何工作的。如上所述,将我自己的顶点属性传递到着色器工作正常,我也想知道程序应该如何自己知道正确的值 - 所以内置属性的整个概念仍然有点令人困惑我。但每当我尝试运行一些着色器时,我发现在网上看看是否有事情发生,我会抛出这些错误,即使其他人似乎在编写着色器时也广泛使用内置属性。

Are these attributes not available in GLSL on the iPhone or am I missing something? Maybe I haven't fully understood how this works. As mentioned, passing my own vertex attributes into the shader works fine, and I am also wondering how the program should "know" the correct values "on its own" - so the whole concept of built-in attributes is still a bit confusing to me. But whenever I try to run some shaders I found online to see if something happens, I get these errors thrown, even though everyone else seems to use built-in attributes extensively when writing shaders.

我真的希望这里有人可以对此有所了解。提前多谢!

I really hope someone here can shed some light on this. Thousand thanks in advance!

朱莉娅

推荐答案

这些属性不是'无论是在iPhone还是其他地方,都可以在GL ES中使用。 WebGL也是如此。您需要编写自己的矩阵代码,或者如果您只支持iOS 5+,则使用GLKit,并为自己提供属性。请参阅 Kronos的参考卡,以获得令人难以置信的简明摘要使其成为ES 2.0的原因 - 除其他外,它列出了所有可用的内置特殊变量:

Those attributes aren't available in GL ES, whether on the iPhone or elsewhere. And the same goes for WebGL. You need to write your own matrix code, or use GLKit if you're supporting only iOS 5+, and supply attributes for yourself. See Kronos' reference card for an incredibly concise summary of what made it into ES 2.0 — amongst other things it lists all the available built-in special variables as:


  • gl_Position

  • gl_PointSize

  • gl_FragCoord

  • gl_FrontFacing

  • gl_PointCoord

  • gl_FragColor

  • gl_FragData [n]

  • gl_Position
  • gl_PointSize
  • gl_FragCoord
  • gl_FrontFacing
  • gl_PointCoord
  • gl_FragColor
  • gl_FragData[n]

GLKit的数学真的很棒因为它内联并使用ARM的NEON SIMD单元。我认为这是在所有新GL项目中至少指定iOS 5的充分理由。

GLKit's maths stuff is really good because it inlines and uses the ARM's NEON SIMD unit. I consider it a sufficient reason to specify iOS 5 as a minimum in all new GL projects.

这篇关于GLSL:iPhone应用程序无法访问内置属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆