Jump to content
  • Advertisement
Sign in to follow this  
Raeldor

Texture Manager... First Implementation

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

I am at the point now where I need to add a texture manager to my game to make sure that each texture only gets loaded once for the scene. I was thinking of using a hash table with the filename as the key. Would this be a reasonable first implementation? How have you guys done this in the past? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Not a bad idea, but you should carefully consider what you want the 'data' that your string 'key' corresponds to.

You might consider using a struct with some of the following information:

color depth
width/height
type (RGB, RGBA, etc)
reference counter
graphics API texture handle
other texture parameter info (wrap, clamp, etc)
whether or not the texture was loaded with mipmaps
pointer to the texture data (smart pointer maybe?)
whether or not to the texture data is cached or flushed


These suggestions all depend on what you plan on doing with your textures. Storing this information can be handy if you lose your device, and you need to reload all of your textures.

Share this post


Link to post
Share on other sites
Quote:
Original post by Raeldor
I am at the point now where I need to add a texture manager to my game to make sure that each texture only gets loaded once for the scene. I was thinking of using a hash table with the filename as the key. Would this be a reasonable first implementation? How have you guys done this in the past?

Thanks


That's what I do in my simple 2d engine (except with a std::map, no hash maps in the STL yet) and it works fine, though I'm not doing anything very complex with the textures.

Share this post


Link to post
Share on other sites
Quote:
Original post by godecho
Not a bad idea, but you should carefully consider what you want the 'data' that your string 'key' corresponds to.

You might consider using a struct with some of the following information:

color depth
width/height
type (RGB, RGBA, etc)
reference counter
graphics API texture handle
other texture parameter info (wrap, clamp, etc)
whether or not the texture was loaded with mipmaps
pointer to the texture data (smart pointer maybe?)
whether or not to the texture data is cached or flushed


These suggestions all depend on what you plan on doing with your textures. Storing this information can be handy if you lose your device, and you need to reload all of your textures.


You don't think it is enough to use the texture filename as the key? I already have the information above in my Texture class. Why would I want to pass the whole struct as the hash key when I can just use the filename?

Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by Raeldor

You don't think it is enough to use the texture filename as the key? I already have the information above in my Texture class. Why would I want to pass the whole struct as the hash key when I can just use the filename?

Thanks


i said for the data, not the key

map[key] = data;

but yes, if you've got a whole texture class, that'd be what you'd want to use for the data.

Share this post


Link to post
Share on other sites
Cool, thanks for the replys.

Has anyone used any other methods for this other than hash tables that worked well for them?

Thanks

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!