cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

tonyo_au
Journeyman III

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);
glEnableVertexAttribArray(VERTEX_BINDINGS_POSITION);
glVertexAttribPointer(VERTEX_BINDINGS_COLOUR, 4,GL_UNSIGNED_BYTE, GL_TRUE,sizeof(C3D_VertexC),(const void*)(sizeof(float)*3));     
glEnableVertexAttribArray(VERTEX_BINDINGS_COLOUR);
   
{
  C3D_VertexC v[20];
  for (int i = 0; i < 5; i++)
  {
    float x = (float)i;
    v.x = (x-10.0f)/10.0f;
    v.y = 0;
    v.z = 0;
    v.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);
glDeleteBuffers(1,&id);

What can affect the first vertex used in glDrawArrays?

   

0 Likes
3 Replies
tonyo_au
Journeyman III

Re: problem with glDrawArrays

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

  glBindBuffer(GL_DRAW_INDIRECT_BUFFER,c_DrawCommands);

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

  glBindBuffer(GL_DRAW_INDIRECT_BUFFER,0);

I changed this to

glDrawElementsIndirect(GL_TRIANGLES,GL_UNSIGNED_INT,&c_DrawCommand[p_Object]);

and the code now works

0 Likes
gsellers
Staff
Staff

Re: problem with glDrawArrays

Hi,

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?

Thanks,

0 Likes
tonyo_au
Journeyman III

Re: problem with glDrawArrays

I will see if I can produce it in a simpler program

0 Likes