Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does glValidateProgram fail when no VAO is bound?

I have a problem validating my shader program in LWJGL/OpenGL 3.
I read the documentation, but I can't seem to find a reason why a VAO is needed when calling glValidateProgram.

int program = glCreateProgram();
int vertexShader = glCreateShader(...);
int fragmentShader = glCreateShader(...);
// ... vertex and fragment shader loading, compiling, errorchecking ...
glAttachShader(program, vertexShader);
glAttachShader(program, fragmentShader);
glBindAttribLocation(program, 0, "position");
glBindAttribLocation(program, 1, "color");
glLinkProgram(program);
glDetachShader(program, shader);
glDetachShader(program, shader);
glValidateProgram(program);
if (glGetProgrami(program, GL_VALIDATE_STATUS) != GL_TRUE)
    System.exit(-1);

This exits the program without any error message.
GL_LINK_STATUS is OK and GL.getErrors() also has nothing to report.
But when creating a VAO around glValidateProgram it works just fine.
I can also just ignore the fact that glGetProgrami returns GL_FALSE and just run the shader program.

What i mean with creating a VAO around glValidateProgram():

int vao = glGenVertexArrays();
glBindVertexArray(vao);
glValidateProgram(program);
if (glGetProgrami(program, GL_VALIDATE_STATUS) != GL_TRUE)
    System.exit(-1);
glDeleteVertexArrays(vao);

When I do this, GL_VALIDATE_STATUS is true and I can draw my stuff.

The used shaders are simple passthrough shaders.
The vertex shader returns the position and the fragment shader returns the color.

So, why do I have to bind an VAO even though I can immediately delete it after the validation?

like image 676
iHaveNoIdeaWhatImDoing Avatar asked Sep 29 '16 04:09

iHaveNoIdeaWhatImDoing


People also ask

What is stored in a VAO?

A Vertex Array Object (VAO) is an OpenGL Object that stores all of the state needed to supply vertex data (with one minor exception noted below). It stores the format of the vertex data as well as the Buffer Objects (see below) providing the vertex data arrays.

What is vertex attribute in OpenGL?

A vertex attribute is an input variable to a shader that is supplied with per-vertex data. In OpenGL core profile, they are specified as in variables in a vertex shader and are backed by a GL_ARRAY_BUFFER . These variable can contain, for example, positions, normals or texture coordinates.

What is VAO in OpenGL?

A Vertex Array Object (VAO) is an object which contains one or more Vertex Buffer Objects and is designed to store the information for a complete rendered object.


1 Answers

This behavior matches the OpenGL spec. I'm using the OpenGL 3.3 spec as reference.

In appendix E.2.2 "Removed Features" on page 344, it says:

The default vertex array object (the name zero) is also deprecated. Calling VertexAttribPointer when no buffer object or no vertex array object is bound will generate an INVALID_OPERATION error, as will calling any array drawing command when no vertex array object is bound.

The spec for glValidateProgram() on page 82 says:

ValidateProgram will check for all the conditions that could lead to an INVALID_OPERATION error when rendering commands are issued, and may check for other conditions as well.

So because issuing a draw command without a VAO bound will given a GL_INVALID_OPERATION error, and glValidateProgram() checks if a draw command would give a GL_INVALID_OPERATION error, what you're seeing is exactly as expected.

like image 82
Reto Koradi Avatar answered Sep 23 '22 14:09

Reto Koradi