I am attempting to redraw with the same arrays using glDrawArrays in a GLKView on iOS. When I comment out any two of these calls, the other draw call draws as I expect. My last hunch was that I was attempting to draw at the same depth, so I introduced a depth uniform and am setting the depth in the vertex shader like so:
gl_Position = vec4(position.xy, 0.1*depth, 1.0);
the depth coming in is a lowp vector with a value of 0, 1, or 2. This didn't have any effect.
Here is my drawRect: method
- (void)drawRect:(CGRect)rect
{
glClearColor(0., 0.0, 0.0, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Render the object again with ES2
glUseProgram(_program);
// the colors
glBindVertexArrayOES(_vertexArray);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _wheelMaskTexture);
glUniform1i(uniforms[UNIFORM_TEXTURE], 0);
glUniform1f(uniforms[UNIFORM_COLOR_DEPTH], COLOR_DRAW);
glUniform1f(uniforms[UNIFORM_COLOR_ANGLE], _angle);
glDrawArrays(GL_TRIANGLES, 0, 6);
// the sat
glBindVertexArrayOES(_vertexArray);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _satMaskTexture);
glUniform1i(uniforms[UNIFORM_TEXTURE], 0);
glUniform1i(uniforms[UNIFORM_COLOR_DEPTH], SATURATION_DRAW);
glUniform1f(uniforms[UNIFORM_COLOR_ANGLE], _satAngle);
glDrawArrays(GL_TRIANGLES, 0, 6);
// the bright
glBindVertexArrayOES(_vertexArray);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _brightMaskTexture);
glUniform1i(uniforms[UNIFORM_TEXTURE], 0);
glUniform1i(uniforms[UNIFORM_COLOR_DEPTH], BRIGHTNESS_DRAW);
glUniform1f(uniforms[UNIFORM_COLOR_ANGLE], _brightnessAngle);
glDrawArrays(GL_TRIANGLES, 0, 6);
}
My GLKView is set up with a drawableDepthFormat = GLKViewDrawableDepthFormat24
. I haven't set up any transforms because what I'm drawing is basically a simple color wheel.
There is no world or model transform. I'm simply drawing the same square 3 times one on top of the other without transforming. There are 3 different mask images that are used to mask out the fragments that I care about in the fragment shader like so:
gl_FragColor = vec4(rgb, texture2D(wheelMask, texCoord).a);
Why wouldn't all three glDrawArrays
calls draw as expected? As I mentioned early any one of them by themselves draws as expected. As it is, with all three, only the first glDrawArrays
draws as expected.