Skip to main content
GameDev.net gamedev.net
🔒 Locked

texture manager class

Started by giugio Jun 29, 2010 at 9:06 AM 5 replies 1.6k views
Original Post
giugio
giugio
Hy.
I would create a texture manager class that contains all the texture in my project.
I have a lot of texture that are the same for much of my meshes , then i think to share the texture with a shared pointer and an stl map , my question is if this method is perform poorly because for each render i must accede to the map(and this is every 1/60 sec).
how i can do better?
with a custom template map or list instead of stl container?
or with c array?
thanks.
Evil Steve
Evil Steve
Why not have each mesh just cache the textures it needs at load time? Then time to access the texture manager doesn't really matter.
WavyVirus
WavyVirus
I have my objects include a texture (pointer) member. They only ask the manager for the texture (causing a map lookup and texture load if it is the first request for the texture) once, when the object is first created. Essentially they cache the texture pointer locally for fast access when rendering.

EDIT: ninja'd by steve, so i'll try and add something - Requesting the texture from the manager only once has the benefit of allowing you to easily keep track of how many objects reference each texture
giugio
giugio
Quote:
Original post by Evil Steve
Why not have each mesh just cache the textures it needs at load time? Then time to access the texture manager doesn't really matter.


sorry , but i'm not understand what you intend for cache.
I would share textures between many mesh that have the same texture.
My idea is to sort the meshes for texture id and draw first the mesh that have shared texture.
For not resend disable the texture to the shader.
Is an too heavy?
Thanks
Zakwayda
Zakwayda
Quote:
Original post by giugio
sorry , but i'm not understand what you intend for cache.
I would share textures between many mesh that have the same texture.
My idea is to sort the meshes for texture id and draw first the mesh that have shared texture.
For not resend disable the texture to the shader.
Is an too heavy?
Thanks
The basic idea (as described by the previous posters) is this:

1. The manager (or cache, or whatever you want to call it - some people don't like the term 'manager') holds (for example) a map whose values are shared pointers to texture objects. This is basically what you described in your original post.

2. The map is *not* queried for every render. Instead, the mesh (or whatever) retrieves a shared pointer to the texture it needs from the manager/cache once only, and then stores it. From then on, it has its own shared pointer that points to the texture.

3. You can then render (and sort by render state, if desired) as usual.

Does that make things more clear?
Kalnos
Kalnos
Quote:
Original post by jyk
Quote:
Original post by giugio
sorry , but i'm not understand what you intend for cache.
I would share textures between many mesh that have the same texture.
My idea is to sort the meshes for texture id and draw first the mesh that have shared texture.
For not resend disable the texture to the shader.
Is an too heavy?
Thanks
The basic idea (as described by the previous posters) is this:

1. The manager (or cache, or whatever you want to call it - some people don't like the term 'manager') holds (for example) a map whose values are shared pointers to texture objects. This is basically what you described in your original post.

2. The map is *not* queried for every render. Instead, the mesh (or whatever) retrieves a shared pointer to the texture it needs from the manager/cache once only, and then stores it. From then on, it has its own shared pointer that points to the texture.

3. You can then render (and sort by render state, if desired) as usual.

Does that make things more clear?


To further clarify, the point is that most systems have something like a 'texture' which is applied to a 'sprite'. The point of storing it in a cache/manager map is to assure that you only load the 'texture' content ONCE and then apply that same content to multiple sprites.
Bozebo
Bozebo
This poses an interesting point.

The OP intends to order objects being sent for render so that objects with the same texture are contiguous and will be rendered one after the other so the texture does not have to be re-bound.

In some scenarios it is best to order objects by distance from the camera location, close to far. That poses a choice between one ordering solution or the other - or am I missing something? This is something I am planning on tackling soon, and I wasn't sure what implications changing texture a lot would have. The other option is to map several textures together onto one 4096x4096 texture so that only 1 is bound. But when using shaders to map the textures are there other things to think about? There must be a good solution for the overall problem? I am planning on working on my first renderer for 3D game environment soon and I do not think I will be using shaders for texturing yet, do they solve many issues previously encountered without them? Or only bring better performance and nicer appearance?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.