Jump to content
  • Advertisement
Sign in to follow this  
miuZ

Managing textures

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

Hello guys/girls,

I would like to have an advice on how to properly design the part of my engine that should manage textures.

Specifically, texture are objects that can be loaded as assets from the point of view of game objects (by loading the models). Therefore, some sort of resource system should manage the load/unload of textures from resource files and their life-span (by also reference counting). This resource system is outside of the renderer part of the engine, and it is independent on the OS and the graphics API.

However, textures are also linked to the renderer as they reside in GPU memory and should be managed also in a graphics API-dependent way (by the renderer, let's say).

So there are two "things" to manage: the texture as an asset, and the texture as a internal graphics resource. How do you manage this two aspects? Do you suggest to have a texture manager who manages textures as resources, handles the loading from files and also is aware of the API-dependent part? In this way the renderer then becomes strictly coupled with the texture manager. I ideally would like to keep the graphics API-dependent code confined inside the renderer.

Otherwise it could be possible to keep the resource management stuff and the graphics API-dependent part in two different places, thus having two "managers", one that handles textures as resources from file and the other one inside the renderer which keeps their API-dependent things and exhibit an API-agnostic interface to everything outside the renderer (and specifically to the texture asset manager).

What are your suggestions?

 

P.S. what about render targets, do you expose them to the other objects (as a replacement for a texture inside a certain material) or you keep them confined in the renderer, not accessible from the outside?

 

Share this post


Link to post
Share on other sites
Advertisement

Asset Map >>has many>> Asset <--is a-- Texture Asset  >>created by>> Texture Factory >>uses>> Graphics API >>can create>> Texture

 

I have a generic asset map, which can acts as a cache on top of the file loading system, returning pointers to assets of different types if they already exist. It doesn't know anything about the types of objects that it's caching, it just views them through an "asset" abstraction.

 

The graphics API can create textures (an abstraction over platform-specific texture objects), but knows nothing about assets/asset-maps/factories.

 

The texture factory is the glue class in the middle -- it knows about the graphics API + textures, and also knows about assets and the asset maps. It can request data off disc, pass that data to the graphics API to instantiate a texture, and then store that texture into an asset map.

 

Render targets are textures, but have no need to ever be handled by a factory or asset map.

Share this post


Link to post
Share on other sites

So, following your design, it would be something like this:

to load a texture asset one should call for example TextureFactory::loadFromFile(filename) that returns a TextureAssetHandle, which corresponds to a TextureAsset, stored in a common AssetMap. The TextureFactory::loadFromFile asks the Renderer to create a texture, let's say calling Renderer::createTexture(width, height, format) which returns a TextureHandle (which could correspond for example to an index inside an internal array of API-specific texture handles); then it reads the asset from disk and then call something like Renderer::fillTextureData(textureHandle, buffer). Then it creates an Asset of type TextureAsset, it stores a reference to the TextureHandle inside that TextureAsset and then it returns to the caller the TextureAssetHandle corresponding to the TextureAsset.

So basically the AssetManager manages the assets (and also the TextureAssets) inside the AssetMap and their life-span, while the Renderer manages the textures and their life-span in an independent way.

Is this more or less what you are suggesting?

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!