3 Replies Latest reply on Feb 9, 2012 12:04 AM by tonyo_au

    problem with glDrawArrays


      Hi All,

      I have posted this on the beginners forum in OpenGl but thought it might be better here


      I have a problem I do not understand. The following code works in a simple test program on AMD - in a more complex program something is affecting glDrawArrays offset index.


      The code works correctly in both programs on nVidia


      glGenBuffers(1, &id);
      glBindBuffer(GL_ARRAY_BUFFER, id);
      glVertexAttribPointer(VERTEX_BINDINGS_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(C3D_VertexC), 0);
      glVertexAttribPointer(VERTEX_BINDINGS_COLOUR, 4,GL_UNSIGNED_BYTE, GL_TRUE,sizeof(C3D_VertexC),(const void*)(sizeof(float)*3));     
        C3D_VertexC v[20];
        for (int i = 0; i < 5; i++)
          float x = (float)i;
          v[i].x = (x-10.0f)/10.0f;
          v[i].y = 0;
          v[i].z = 0;
          v[i].rgba = 255;
        glBufferData(GL_ARRAY_BUFFER, sizeof(C3D_VertexC)*20, NULL, GL_STATIC_DRAW);


      // this draws the 5 points in  the correct location on the screen
      // glBufferSubData(GL_ARRAY_BUFFER, sizeof(C3D_VertexC)*12, // sizeof(C3D_VertexC)*5, v);


      // all verices drawn at 0,0,0 in black
        glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(C3D_VertexC)*5, v);


      glDrawArrays(GL_POINTS, 0, 5);
      glBindBuffer(GL_ARRAY_BUFFER, 0);


      What can affect the first vertex used in glDrawArrays?


        • Re: problem with glDrawArrays

          The problems seems to be caused by using this code prior to the above code



            glDrawElementsIndirect(GL_TRIANGLES,GL_UNSIGNED_INT,(void*   (p_Object*sizeof(C3D_DrawElementsIndirectCommand)));



          I changed this to



          and the code now works

            • Re: problem with glDrawArrays



              I'm not sure why this might be causing a problem. When you changed your glDrawElementsIndirect code to use the absolute address of the array rather than the indirect buffer, you caused the driver to fetch the draw parameters from client memory. This is not directly supported by the hardware and so the driver emulates this with independent draw calls and is therefore equivalent to a simple loop in the application (minus a small amount of driver overhead).


              Off the top of my head, the only thing I can think of is that there's some state leak GPU side, but I would consider that very unlikely. To really debug this, we'll need a test case that reproduces the issue. Besides the code you've already posted, do you have anything you'd be willing to share?