What is the purpose of using the glBindAttributeLocation function in GLSL?

Possible duplicate:
Explicit vs Automatic Attribute Binding for OpenGL Shaders
Why should I use glBindAttribLocation?

I tried calling glGetAttribLocation without binding any attribute sites, and this seemed to work. Therefore, I can always cache attribute locations in an array if I want to have instant access. What is the purpose of using glBindAttribLocation?

[OpenGL 2.0]

+4
source share
1 answer

glBindAttribLocation "binds" the index to the attribute name. This allows you to use the same indexes for the same attributes in different shaders. For example: vertex coordinates = 0, texture coordinates = 1, normals = 2. This simplifies the drawing code by matching the shader with your code, and not vice versa (requesting places for attributes).

In my code, I create an enum for common vertex attributes:

 enum { GRAPHICS_ATTRIB_VERTEX = 0, GRAPHICS_ATTRIB_NORMAL, GRAPHICS_ATTRIB_TEXTURE, }; 

Bind them using glBindAttribLocation , then I can use them as follows:

  glVertexAttribPointer(GRAPHICS_ATTRIB_VERTEX, ....); 

This will work with all my shaders without calling glGetAttribLocation .

+7
source

Source: https://habr.com/ru/post/1335860/


All Articles