Draw mixed geometry

Started by
13 comments, last by Infinisearch 7 years, 5 months ago

Hi All

I'm looking for more appropriate API calls for:

- model can have different faces (with 1, 2, 3, or 4 vertices)

- model can have different faces' colors

- model can have different materials assigned by user to arbitrary set of polygons

Now I just call glDrawElements for each part/piece of drawing and sometimes it becomes much slower. Please suggest better solution(s)

Thank you

Advertisement

dont call gldrawelements every face you draw

you need to draw the same set of polygons only onvce if you can GL_TRIANGLE_STRIP is cool.

either way you prepare the scene as sending whole buffer to gpu first, then you draw,

dont call gldrawelements every face you draw

Not every, example:

there are, say, 2 blue triangles, their indices start from 0. And there are another 3 blue triangles at indices 100. Now I use 2 calls glDrawElements to draw first 2 then second 3. How can I draw them with one call?

Thx

there are, say, 2 blue triangles, their indices start from 0. And there are another 3 blue triangles at indices 100.

With the same shader and uniforms?

-potential energy is easily made kinetic-

With the same shader and uniforms?
Yes

there are, say, 2 blue triangles, their indices start from 0. And there are another 3 blue triangles at indices 100. Now I use 2 calls glDrawElements to draw first 2 then second 3. How can I draw them with one call?
Put the indices next to each other in the index buffer, then you can make one call.

Besides a dynamic index buffer like hodgman suggests you can also try multidraw. https://www.opengl.org/wiki/Vertex_Rendering#Multi-Draw

-potential energy is easily made kinetic-

Yes, set up the index buffer so that the indices are 0|1|2|3|4|5|100|101|102|103|etc then issue a single glDrawElements call. There's absolutely nothing in the spec for glDrawElements that forces the values to be consecutive.

glDrawElements with GL_TRIANGLES is infinitely more useful than glDrawElements with GL_TRIANGLE_STRIP. Only worry about strips if you're on hardware that requires them; otherwise strips are 1998 technology. Every primitive type (strip/fan/quad/poly/etc) can be expressed in terms of triangles and indices; it may not satisfy strict OpenGL invariance rules, but so long as you don't mix types in a multipass renderer you'll be OK. From there it should be obvious that glDrawElements with GL_TRIANGLES can be used to concatenate primitives of different types so that multiple draw calls become single.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

What you may looking for is the restart-index value. It marks the beginning of a new primitive in a index list.

core since 3.1 (And even before that with GL_NV_primitive_restart, but with a different API I think)

glEnable(GL_PRIMITIVE_RESTART);

glPrimitiveRestartIndex(X); //for easy of use and consistency I would just use the highest value of the index type, e.g. 0xFFFF or 0xFFFFFFFF (Don't use a byte index type! They are very slow on modern hardware)

Or with ARB_ES3_compatibility (Core since 4.3)

glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); //this always uses the highest value of the index type

So with a GL_UNSIGNED_SHORT index with this values:

0|1|2|3|4|5|65535|100|101|102|103

You get this two index primitives:

0|1|2|3|4|5

100|101|102|103

Put the indices next to each other in the index buffer, then you can make one call.
In my case it doesn't work well. I can't change topology as it's better for me/drawing, e.g. p?lygons should follow in their original order, they are used in many ways besides drawing. Creating another one indices (just for drawing) is often counter-productive because it can't be done once for example when a new geometry arrives at every frame

Yes, set up the index buffer so that the indices are 0|1|2|3|4|5|100|101|102|103|etc then issue a single glDrawElements call. There's absolutely nothing in the spec for glDrawElements that forces the values to be consecutive.
I meant "face offset" (not "vertex index"). It looks like

v0|v1v|2|v3|v4|v5|..............|vx|vx|vx|

This topic is closed to new replies.

Advertisement