Issue when porting from OpenGL 1.1 to OpenGL-ES 2.0

前端 未结 1 692
一向
一向 2020-12-22 12:18

this is my opengl-es 2.0 code :

{
    for (surfnum=0;surfnum

        
相关标签:
1条回答
  • 2020-12-22 12:33

    Your code doesn't make sense.

    {
        for (surfnum=0;surfnum<surftotal;surfnum++){
            for (i=0;i<triNum[surfnum];i++){
                GLfloat *Vertices[] = { triArray[surfnum][i].normpt1,  triArray[surfnum][i].normpt2,triArray[surfnum][i].normpt3};
                glGenBuffers(1, &ui32Vbo);
                glBindBuffer(GL_ARRAY_BUFFER, ui32Vbo);
                unsigned int uiSize = 3 * (sizeof(GLfloat) * 1); 
            glBufferData(GL_ARRAY_BUFFER, uiSize,*Vertices, GL_STATIC_DRAW);
            }
        }
    }
    

    Are you actually creating a buffer object for each triangle? Well, you're not even doing that, because you only have a buffer object for each set of 3 floats, which isn't even a full triangle. I can only assume that this is a vertex position. You keep calling glGenBuffers in the middle of this loop, so it will dutifully generate another buffer object. Creating too many buffer objects may be why you're hitting software fallbacks.

    Also, doesn't normpt1 contain the normal, not the position?

    And then there's this:

    for(int i = 0; i < 80000; ++i)
    {
        glClear(GL_COLOR_BUFFER_BIT);
        int i32Location = glGetUniformLocation(uiProgramObject, "projmatrix");
        glUniformMatrix4fv( i32Location, 1, GL_FALSE, pfIdentity);
        glEnableVertexAttribArray(VERTEX_ARRAY);
        glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, 0);
        glDrawArrays(GL_TRIANGLES, 0,i);
        eglSwapBuffers(eglDisplay, eglSurface);
    }
    

    First, you didn't glBindBuffer your buffer object. Yes, I know it is still bound from before, but it's always good to be explicit about these things.

    Most importantly, what is this: glDrawArrays(GL_TRIANGLES, 0,i);? Isn't i the array index? The third parameter needs to be the number of vertices to draw. And GL_TRIANGLES will fail unless this value is divisible by 3.

    But that doesn't matter, since the buffer object you last created only has enough room for 1 vertex. So it is impossible to render from.

    0 讨论(0)
提交回复
热议问题