Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

The Frugal Gourmet

Meshes that share textures

This topic is 5302 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

Hypothetical: Let''s say I have about 20 meshes that I render to the screen, and they all share common textures.... And, I am keyed into the D3DXMesh class with DirectX. I would *like*, if possible, to limit the number of SetTexture() calls. What do you think is the best way to handle this? Do I need to use some other system? How should I do it? Any advice would be helpful. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Sort your meshes by their textures before rendering.

I have a huge map made out of tiles, where every tile can have an infinite number of components. A component represents a mesh with a texture. The textures are loaded as resources, so only differing textures are actually loaded. I then allocate a big array of component pointers (Component *SList[NumComponents]), go through a big loop to point them to the real components in the map, then use qsort to sort them by their texture's filename / ID / whatever. Then when rendering, I use the sorted list of pointers to draw all components, only calling SetTexture when rendering a component that uses a different textures than the last one rendered.

Help any?

[edited by - Jiia on May 10, 2004 8:08:35 AM]

Share this post


Link to post
Share on other sites
Cool, thanks. Yeah, I had kinda figured out something similar with resources insofar as not having too many textures loaded in memory. They can all share textures pretty easily.

The one additional problem I would like to solve is too many calls to SetTexture(). Every single rendered model is basically calling SetTexture() multiple times every frame, yet they use the same texture. It would be nice if somehow I could only call SetTexture() for each texture used and render the parts of models appropriately. This may be too difficult, however, and not really worth my time. In fact, probably I just should forget about this idea for now. Too hard!

Share this post


Link to post
Share on other sites
quote:

The one additional problem I would like to solve is too many calls to SetTexture().



Add a texture index (i.e. "unsigned int iTextureIndex") to your mesh class (or, if you're just using an array of meshes, create an array of texture indexes).

During the rendering, do something like this:


for(int i=0; i < NUM_TEXTURES; i++)
{
m_pD3DDevice->SetTexture(0,&m_pTextures[i]);
for(int i2 = 0; i2 < NUM_MESHES; i2++)
{
if(Mesh[i2].iTextureIndex == i) // I assume that "Mesh" is some sort of mesh container class.

{
Mesh[i2].Draw(); // this function would be where you called draw primitive.

}
}
}


[edited by - Etnu on May 10, 2004 11:24:13 AM]

Share this post


Link to post
Share on other sites

  • 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!