0

I am in the process of converting an openGL ver 1.0 application to a more modern version. I am stuck on a function and need some help.

basically we read in data points from a file [.SLC] format the data is then inside a data structure of vector<vector<vector<float, float, float>>>

the old rendering:

for [size of first vector]
   for [size of second vector]

       glBegin(GL_LINE_LOOP);       
           for [size of third vector]
                glVertex3f(float, float, float);
       glEnd();

this 3 layer loop represents a single object that I am trying to render via a single call to some method similar to this. I can't seem to get this right though.

glVertexAttribPointer(vp, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), nullptr);
glDrawElements(GL_LINE_LOOP, indices.size() / sizeof(uint32_t), GL_UNSIGNED_INT, NULL);

can someone please point me in the right direction. If you need more information please let me know and Ill try to explain further. Thanks

My issue is putting together the collection of vertex / index to send to the render function.

As the example shows there are 3 loops. I was thinking that just before the start of the 3rd loop start collecting the vertex data.

That part is easy, but the index collection confuses me. If the 3rd loop has [N] vertex should I also have [N] index.

At this point should I send those 2 collections to the render function? If yes then that could end up with hundreds of calls to the render function so the next question would be is there a way to combine all of the data and send it as a single call?

1 Answers1

3

[...] is there a way to combine all of the data and send it as a single call?

If you want to render multiple GL_LINE_LOOP primitives with on draw call, then I recommend to use Primitive Restart:

Primitive restart functionality allows you to tell OpenGL that a particular index value means, not to source a vertex at that index, but to begin a new Primitive

Enable GL_PRIMITIVE_RESTART and define the restart index by glPrimitiveRestartIndex (e.g. 0xFFFFFFFF):

glEnable( GL_PRIMITIVE_RESTART );
glPrimitiveRestartIndex( 0xFFFFFFFF );

e.g. If you want to draw 2 line loops (with one draw call) with the indices (0, 1, 2) and (3, 4, 5, 6) then you have to define the following index array:

std::vector<uint32_t> indices{ 0, 1, 2, 0xFFFFFFFF, 3, 4, 5, 6 };
Nicol Bolas
  • 378,677
  • 53
  • 635
  • 829
Rabbid76
  • 142,694
  • 23
  • 71
  • 112