0

Refer to "Explicit vs Automatic attribute location binding for OpenGL shaders"

If I do not explicitly bind the attributes using glVertexAttribPointer, what default locations will be used?

Where can I find the official link for it?

Community
  • 1
  • 1
user1914692
  • 2,823
  • 5
  • 33
  • 54

2 Answers2

0

Are you asking how generic attributes in a GLSL shader will be assigned to attribute slots (locations)?

That is completely implementation defined if you do not do it yourself. Some will scan the vertex shader and assign them locations in alphabetical order, others will assign them slots based on the order they appear in, but none of this behavior is required. It could be completely random and change every time you run your program for all you know.

That is why you either explicitly bind vertex attributes to a location before linking, or query the location afterwards.

Andon M. Coleman
  • 39,833
  • 2
  • 72
  • 98
0

I think you might be mixing up a couple of different concepts. The question you link is about how locations are assigned to attributes in the vertex shader. glBindAttribLocation() or glGetAttribLocation() are used for that purpose.

glVertexAttribPointer() on the other hand specifies where the data for a attribute comes from, together with some related state of the attribute (type, stride, etc). The specific attribute it works on is given by its location, which is passed as the first argument of the call.

Now, if you never call glVertexAttribPointer() for an attribute, there are a few possible scenarios:

  1. An attribute array is not enabled for the attribute. This happens if glEnableVertexAttribArray() was never called for the attribute, or glDisableVertexAttribArray() was last called. In this case, the current value of the attribute is used, which is the value set with calls like glVertexAttrib4f(), with a default value of (0.0f, 0.0f, 0.0f, 1.0f).

  2. If the attribute array is enabled, the default values correspond to a call of:

    glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, 0, NULL);
    
    1. If you have a VBO bound, this could be valid, since the last argument is a relative offset into the buffer.
    2. If you don't have a VBO bound, the draw call will most likely crash, since it will try to source vertex data from the given pointer address, which is NULL.

All of this can be found in the official OpenGL spec documents, which are accessible at https://www.opengl.org/registry/.

Reto Koradi
  • 49,246
  • 7
  • 76
  • 116