The order of calling gl functions

Hello, i am using opengl 3.3 for creating simple c++ opengl application.
Now i dont use VBO for storage vertice datas.

Instead i use:

  • glGetAttribLocation(...,"aPosition") > glVertexAttribPointer(...,(pointer to vertices float array)) > glEnableVertexAttribArray(...)

to define data of attribute ("attribute vec3 aPosition" in my vertex shader) and:

  • glGetUniformLocation(...) > glUniform...(...)

to define data of unifotms.

I’m interested, in what order of calling aforementioned functions regarding other gl functions (such as:

  • glCreateProgram() > glAttachShader(...,vs) > glAttachShader(...,fs) > glLinkProgram(...) > glUseProgram(...))?

In other words, when i should call glGetAttribLocation(...), glVertexAttribPointer(...), glEnableVertexAttribArray(...) and glGetUniformLocation(...), glUniform...(...) regarding such functions as glLinkProgram(...), glUseProgram(...) ?

Also I’m interested, what does glBindAttribLocation(...) have to do with this situation and what function does he perform?

glGetAttribLocation and glGetUniformLocation can be called once the program is linked. glUniform affects the current program so must be called after glUseProgram. glVertexAttribPointer can be called at any point prior to a draw call; the program doesn’t matter (you can issue multiple draw calls using different programs but using the same set of attribute arrays).

glBindAttribLocation is called prior to linking to force an attribute to use a specific location. If it isn’t used, the attribute location is determined by any layout(location=...) qualifier for that attribute in the vertex shader’s source code. If the location isn’t specified by either of those mechanisms, the linker will assign a location to the attribute and the application will need to use glGetAttribLocation to query the location. If you force a specific location (either in the shader source code or with glBindAttribLocation), you don’t need to query it with glGetAttribLocation.

1 Like