Android orthographic interference glDrawArrays/glVertexAttribPointer

Started by
6 comments, last by polyfrag 11 years ago

This orthrographic image draws fine:


  glDisable(GL_DEPTH_TEST); 
    glUseProgram(g_program[ORTHO]); 
    glUniform1f(g_slots[ORTHO][WIDTH], (float)g_width); 
    glUniform1f(g_slots[ORTHO][HEIGHT], (float)g_height); 
    glUniform4f(g_slots[ORTHO][COLOR], 1, 1, 1, 1); 
    glEnableVertexAttribArray(g_slots[ORTHO][POSITION]); 
    glEnableVertexAttribArray(g_slots[ORTHO][TEXCOORD]); 
    glBindBuffer(GL_ARRAY_BUFFER, 0); 
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 
... 
  glVertexAttribPointer(g_slots[ORTHO][POSITION], 3, GL_FLOAT, GL_FALSE, sizeof(float)*5, &vertices[0]); 
    glVertexAttribPointer(g_slots[ORTHO][TEXCOORD], 2, GL_FLOAT, GL_FALSE, sizeof(float)*5, &vertices[3]); 
    glDrawArrays(GL_TRIANGLES, 0, 6); 
... 
    glEnable(GL_DEPTH_TEST);

But if I place this before it, it doesn't draw:


    glUseProgram(g_program[MODEL]); 
        ... 
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[frame]); 
    glVertexAttribPointer(g_slots[MODEL][TEXCOORD], 2, GL_FLOAT, GL_FALSE, sizeof(CVertexArray2), (void*)offsetof(CVertexArray2,texcoord));

        glUseProgram(g_program[BILLBOARD]); 
        ... 
        glVertexAttribPointer(g_slots[BILLBOARD][POSITION], 3, GL_FLOAT, GL_FALSE, sizeof(float)*5, &vertices[0]); 
        glVertexAttribPointer(g_slots[BILLBOARD][TEXCOORD], 2, GL_FLOAT, GL_FALSE, sizeof(float)*5, &vertices[3]); 
        glDrawArrays(GL_TRIANGLES, 0, 6);

If I get rid of the last glDrawArrays it draws, or if I remove glVertexAttribPointer(g_slots[MODEL][TEXCOORD]...

Any ideas why?

Advertisement

Here's what I broke the problem down to.

The ortho quad will draw if I comment any of these lines:


        glUseProgram(g_program[BILLBOARD]); 
        glEnableVertexAttribArray(g_slots[BILLBOARD][POSITION]); 
        glEnableVertexAttribArray(g_slots[BILLBOARD][TEXCOORD]); 
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glVertexAttribPointer(g_slots[BILLBOARD][POSITION], 3, GL_FLOAT, GL_FALSE, sizeof(float)*5, &vertices[0]); 
        glVertexAttribPointer(g_slots[BILLBOARD][TEXCOORD], 2, GL_FLOAT, GL_FALSE, sizeof(float)*5, &vertices[3]); 
        
        glDrawArrays(GL_TRIANGLES, 0, 6);

It has something to do with the texture because if I get rid of the texture in the billboard shaders, the ortho quad draws:


// billboard.frag

varying lowp vec2 TexCoordOut; 
uniform sampler2D Texture;

void main(void) 
{ 
  lowp vec2 TexCoord = vec2(0,0); 
    gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0) * texture2D(Texture, TexCoord); 
    //gl_FragColor = vec4(1,1,1,1); 
}

Vertex shader billboard.vert somehow effects the vertices of the ortho shader. The ortho quad only draws in the right part of the screen if I remove the line

TexCoordOut = TexCoordIn;


attribute vec4 Position;
attribute vec2 TexCoordIn; 
varying vec2 TexCoordOut;

void main(void) 
{ 
    gl_Position = Position; 
    TexCoordOut = TexCoordIn; 
}

And this works fine on iOS.

Reported a bug:

https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=53820

https://code.google.com/p/android/issues/detail?id=53829&thanks=53829&ts=1364787874

I can only think it might be memory corruption in another part of the program.

No, this is not memory corruption. Definitely some bug in Galaxy Nexus or android.

I broke it down to the simplest example. Try this project (comment #5):

https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=53820

Ugh, they're never going to reply to the issue. Android is such a piece of crap.

Fixed the problem by packing everything into VBO's. Inconvenient, especially for text, but it solved the problem.

This topic is closed to new replies.

Advertisement