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

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

问题描述

我在这里变得非常绝望.我使用 Xcode,试图在 iPhone 上实现一些 OpenGL 的东西.我必须为 Phong-Lighting 编写一个着色器.我已经声明了我的几何体(顶点、索引、计算等)并将各自的参数作为属性传递给着色器(用 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!

朱莉娅

推荐答案

这些属性在 GL ES 中不可用,无论是在 iPhone 还是其他地方.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]

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天全站免登陆