1

I can connect a VBO data with the shader's attribute using the followings functions:

GLint attribVertexPosition = glGetAttribLocation(progId, "vertexPosition");
glEnableVertexAttribArray(attribVertexPosition);
glVertexAttribPointer(attribVertexPosition, 3, GL_FLOAT, false, 0, 0);

I analyze a legacy OpenGL code where a VBO is used with the following functions:

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, 0);

How that legacy code makes a connnection between a VBO data and the shader's attribute:

attribute vec3 vertexPosition;

?

Irbis
  • 1,432
  • 1
  • 13
  • 39
  • Isn't that fixed pipeline stuff? I think `glEnableClientState` predates shaders. Alternatively, due to some compat stuff, it's likely that it just binds in some predefined order... – Bartek Banachewicz Feb 06 '23 at 14:35

1 Answers1

3

For these fixed-function functions, the binding between the buffer and the vertex attribute is fixed. You don't tell glVertexArray which attribute it feeds; it always feeds the attribute gl_Vertex, which is defined for you in the shader. It cannot feed any user-defined attribute.

User-defined attributes are a separate set of attributes from the fixed-functioned ones.

Note that NVIDIA hardware is known to violate this rule. It aliases certain attribute locations with certain built-in vertex arrays, which allows user-defined attributes to receive data from fixed-function arrays. Perhaps you are looking at code that relies on this non-standard behavior that is only available on NVIDIA's implementation.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • How it is fixed ? For example I can also call ```glEnableClientState( GL_TEXTURE_COORD_ARRAY );``` and ```glTexCoordPointer```. Then the shader will contain ```attribute vec3 vertexPosition;``` and ```attribute vec2 vertexTexCoord;```. I know that is obsolete but I debug legacy OpenGL code. – Irbis Feb 06 '23 at 16:02
  • Or maybe using a shader which defines attributes doesn't makes sense when a client code uses ```glEnableClientState``` and ```glVertex/TexCoord/NormalPointer``` functions ? – Irbis Feb 06 '23 at 16:19
  • @Irbis: "*How it is fixed ?*" By fiat. The standard specifically says which *pre-defined* vertex shader inputs are fed from these functions. `glTexCoordPointer` feeds one of the `gl_MultiTexCoord#` inputs, depending on the current `glActiveTexture` at the time of use. – Nicol Bolas Feb 06 '23 at 16:34
  • @Irbis: I've added a note about old NVIDIA-specific functionality. – Nicol Bolas Feb 06 '23 at 16:42