简体   繁体   English

GLSL:iPhone应用程序无法访问内置属性?

[英]GLSL: Built-in attributes not accessible for iPhone Apps?

I am getting really desperate here. 我在这里真是绝望。 I working with Xcode, trying to implement some OpenGL stuff on the iPhone. 我使用Xcode,试图在iPhone上实现一些OpenGL。 I have to write a Shader for Phong-Lighting. 我必须为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). 我尽力声明了自己的几何形状(顶点,索引,计算等),并将各自的参数作为属性传递给着色器(用GLSL编写)。 Using these attributes works fine, some really basic shader programs compile correctly and give the expected output. 使用这些属性可以正常工作,一些真正的基本着色器程序可以正确编译并提供预期的输出。

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 ie the "gl_NormalMatrix", but whenever I try that, the program crashes and I get an "ERROR: 0:3: Use of undeclared identifier 'gl_NormalMatrix'". 现在,我尝试从一些更高级的计算开始,对于这些计算,我需要使用GLSL的一些内置属性,即“ gl_NormalMatrix”,但是每当尝试执行该操作时,程序就会崩溃,并且我得到一个“错误:0:3:使用未声明的标识符'gl_NormalMatrix'”。 It happens identically whenever use any of the built-in attributes such as gl_Vertex, gl_Normal etc. 每当使用任何内置属性(例如gl_Vertex,gl_Normal等)时,发生的情况都相同。

Are these attributes not available in GLSL on the iPhone or am I missing something? 这些属性在iPhone的GLSL中不可用,还是我缺少某些东西? 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! 提前致谢!

Julia 朱莉亚

Those attributes aren't available in GL ES, whether on the iPhone or elsewhere. 这些属性在GL ES中不可用,无论是在iPhone还是其他地方。 And the same goes for WebGL. WebGL也是如此。 You need to write your own matrix code, or use GLKit if you're supporting only iOS 5+, and supply attributes for yourself. 您需要编写自己的矩阵代码,如果仅支持iOS 5+,则需要使用GLKit,并为您自己提供属性。 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: 请参阅Kronos的参考卡 ,以获取有关将其纳入ES 2.0的简明扼要的摘要-其中列出了所有可用的内置特殊变量,其中包括:

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

GLKit's maths stuff is really good because it inlines and uses the ARM's NEON SIMD unit. GLKit的数学知识非常好,因为它可以内联并使用ARM的NEON SIMD单元。 I consider it a sufficient reason to specify iOS 5 as a minimum in all new GL projects. 我认为在所有新的GL项目中至少指定iOS 5为充分理由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM