Jump to content
  • Advertisement
Sign in to follow this  
Tommato

Draw mixed geometry

This topic is 719 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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,

Share this post


Link to post
Share on other sites
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

Edited by Tommato

Share this post


Link to post
Share on other sites

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? 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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|

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!