OpenGL ES中glBindAttribLocation函数的使用
我无法在 OpenGL ES 2.0 中使用 glBindAttribLocation
函数
有人能给我完整的上下文吗? 类似吗
g_pLightDir = g_pEffect10->GetVariableByName( "g_LightDir" )->AsVector();
与 DirectX 10 ?在各个网站上在线阅读,但无法使用此功能。需要帮助..
I dont get the use of glBindAttribLocation
function in OpenGL ES 2.0
Can some one give me the full context ? Is it something like
g_pLightDir = g_pEffect10->GetVariableByName( "g_LightDir" )->AsVector();
in DirectX 10 ? Read online in various sites, but couldn't get the use of this function. Help needed..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过此函数,您可以为用户定义的着色器属性(而不是统一的,如代码示例所示)指定属性索引,稍后在引用该属性时使用该属性索引。
假设您有一个顶点着色器:
然后您可以将索引绑定到这些变量,
您可以使用您喜欢的任何非负数(在小范围内)。然后,当引用这些属性时,您可以使用它们的索引,例如在
glVertexAttribPointer
或glEnableVertexAttribArray
函数中。但请记住,在链接程序之前必须调用
glBindAttribLocation
。您也可以省略它。然后,OpenGL 在链接期间自动将索引绑定到所有使用的属性,稍后可以通过glGetAttribLocation
查询这些属性。但通过glBindAttribLocation,您可以建立自己的属性索引语义并保持一致。较新的 GLSL 版本甚至允许您在着色器内指定属性索引(使用
layout
语法),从而不再需要glBindAttribLocation
或glGetAttribLocation
>,但我不确定ES是否支持这一点。但我的回答并没有告诉你更多你看过的“各种”网站或任何优秀的 OpenGL/GLSL 书籍,所以如果你仍然不明白,请更深入地研究 GLSL 的基础知识。
This function let's you specify an attribute index for a user defined shader attribute (not for a uniform, as your code sample suggests), which you later use when refering to the attribute.
Say you have a vertex shader:
You then can bind indices to those variables, with
You can use whatever non-negative numbers you like (in a small range). Then when refering to these attributes you use their indices, e.g. in
glVertexAttribPointer
orglEnableVertexAttribArray
functions.But keep in mind that
glBindAttribLocation
has to be called before linking the program. You can also omit it. Then OpenGL automatically binds indices to all used attributes during linking, which can later be queried byglGetAttribLocation
. But withglBindAttribLocation
you can establish your own attribute index semantics and keep them consistent.The newer GLSL versions even allow you to specify the attribute indices within the shader (using the
layout
syntax), removing the need for eitherglBindAttribLocation
orglGetAttribLocation
, but I'm not sure if this is supported in ES.But my answer doesn't tell you more than those "various" sites you looked at or any good OpenGL/GLSL book, so if you still don't get it, delve a little deeper into the basics of GLSL.
我从未使用过 Direct X,但 glBindAttribLocation 用于定义着色器中属性的位置,假设您的着色器中有这一行:
然后您可以使用 glBindAttribLocation 来设置该 vec3 的位置,您必须在创建之后执行此操作将顶点着色器附加到着色器程序,但在链接它之前(或者您必须“重新链接”它)。如果您不指定位置,编译器将为您指定位置,您可以使用 glGetAttribLocation 查询位置。
I never used Direct X, but glBindAttribLocation is used to define the location for a Attribute in your shader, say you have this row in your shader:
Then you can use glBindAttribLocation to set a location for that vec3, you must do this after you have attached your vertex-shader to your shader-program but before you link it (or you have to "relink" it). If you dont specify a location the compiler will do it for you and you can query the location with glGetAttribLocation.