Sign in to follow this  
polyfrag

Android orthographic interference glDrawArrays/glVertexAttribPointer

Recommended Posts

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?

 

Share this post


Link to post
Share on other sites

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; 
}

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this