Jump to content
  • Advertisement
Sign in to follow this  

VertexArrays and Materials problem

This topic is 4724 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 there. I have the following problem. I'm exporting from 3d studio max a mesh, along with it's materials. each face in mesh has a smoothGroup ID and a material ID. Then i split the mesh into submeshes, according to unique combinations of the 2 ID types (material and smooth group). Then I load it into my program and i want to render it using vertex arrays, specifically MultiDrawArrays. This function should render each submesh independentely, using an array of count values, which count the number of primitives for each submesh. The problem is that i want to change material according to each submesh'es material ID, using glMaterial. But then I cannot use MultiDrawArrays, only DrawArrays, which is a quite performance hit in my program, because the main objective is physical simulation and not time counsuming rendering. Do you know any method of doing this, by keeping the single MultiDrawArrays call, but changing the materials every now and then?

Share this post


Link to post
Share on other sites
Advertisement
Unfortunately each call to draw arrays will batch draw all the vertices with the current state configuration. All is not lost however; store all of the data in a VBO and render the mesh in pieces.

I do something like this:
<set all states for this submesh/group>
glDrawArrays( GL_TRIANGLES, m_pGroupOffsets[iGroupCounter++], 3*group->numtriangles);

the second parameter offsets into the data array to where a particular submesh (with a different material in your case) starts and then I tell glDrawArrays to render 3*group->numtriangles (group for me is like submesh for you) indices.

I hope this is somewhat clear.

You should use VBOs so that you don't have to upload each submesh's data each frame - if you have many submesh's that could be expensive.

Share this post


Link to post
Share on other sites
This is a good solution. As you say, i should use a vertex buffer object and just call glMaterial for every submesh i need(they are ordered so if they differ only in smooth group i don't need to change the material). The only problem is that some of the meshes i need to update every frame, some of them i dont'. So should i use VBO for those which are changing with the DYNAMIC_DRAW option? Is this efficient? Or i shouldn't bother using VBO with objects that are changing very often?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!