PDA

View Full Version : Has specification described this situation?



blackbird
07-07-2011, 07:04 AM
At client side, submit vertex positions and render:



GLuint vao, vbo;
glGenVertexArrays(1,&vao);
glBindVertexArray(vao);
glGenBuffers(1,&vbo);
glBindBuffer(GL_ARRAY_BUFFER,vbo);
glBufferData(GL_ARRAY_BUFFER,sizeof(GLfloat)*4*ver tex_count,pVertexPositionData);
glVertexAttribPointer(0,4,GL_FLOAT,GL_FALSE,0,(voi d*)0);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLE,triangle_count,0);
glBindVertexArray(0);


But in the shader program, declare more attributes:



attribute vec4 vertex; // index 0
attribute vec4 color; // index 1

void main()
{
// color variable should contain undefined value
// how about use vertex variable only?
gl_Position=vertex;
}




In my experiment, it works well. Has specification described this situation, or it depends on the driver?

mbentrup
07-07-2011, 09:17 AM
If you haven't enabled VertexAttribArray(1), the driver will pass the "current" value for this attribiute, i.e. usually the last value set with glVertexAttrib4f(1, x,y,z,w) or similar functions.

AFAIR the current value is undefined after some functions, but this shouldn't be a problem if you don't use the attrib. In fact many GLSL compilers will detect that this attribute is not used and remove the attribute, so that glGetAttribLocation for this attribute returns -1.

Alfonse Reinheart
07-07-2011, 10:12 AM
AFAIR the current value is undefined after some functions, but this shouldn't be a problem if you don't use the attrib.

Because rendering in the core spec is not defined in terms of changing global state, the default generic attributes are always well-defined, according to the core spec.