1
\$\begingroup\$

My program contains two shader programs in it. The following code is for preparing one of the shader program's attributes:

int positionHandle2 = glGetAttribLocation(programAColorUTranslate, "vPosition");
glEnableVertexAttribArray(positionHandle2);
glVertexAttribPointer(positionHandle2, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
translateHandleAColorUTranslate = glGetUniformLocation(programAColorUTranslate, "vTranslate");

int aColorHandle = glGetAttribLocation(programAColorUTranslate, "aColor");
glEnableVertexAttribArray(aColorHandle);
/*glVertexAttribPointer(aColorHandle, 3, GL_FLOAT, GL_TRUE, 5 * sizeof(float), 0);*/

At this point, the program works fine, except that the vertices drawn by the above shader program are not colored, since the line above is commented out. However, if I uncomment the line above (and change the stride of position handle to 5 * sizeof(float)) to try to add colors to the above shader program's vertices, random shapes appear in my program. Supposedly, the above line should only alter triangles rendered by one of the shader programs, not both. However, every single vertex in my program is being rendered incorrectly after uncommenting the about line, to the point that the program becomes unrecognizable from before.

\$\endgroup\$
2
\$\begingroup\$

In OpenGL ES 2.0 a program object does not contain the vertex array state (which you are modifying in your question). That data is global, so it applies to whatever the current program is. The program object does have state that controls which attributes are active (but note this is not the state that glEnableVertexAttribArray is modifying), and the size/type/etc of the attributes, but not the state that controls what data is bound to them.

For details on exactly what state is covered under a particular GL object, see section 6.2 State Tables in the ES 2.0 spec. Anything not listed in a table for X Object State is global state. Specifically in this case, see Tables 6.2 Vertex Array Data and 6.15 Program Object State.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.