Archived

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

texture managing?

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

well... I am working on my own RenderSystem.lib.. it is going to be a simple RenderSystem library.. later I will implement it in a engine with physics and scenegraph and so but now I would like to know wich way would be the best to manage textures? 1) using some kind of texture manager in the rendersystem lib that will load the texture and return an ID for it and then when a mesh that needs it will be rendered it asks the texture manager for the texture and then binds it... one way of doing this is to let the rendersystem itself load the texture e.g. unsigned int uiMyTexture = RenderSystem->CreateTexture("data\\marble.tga"); or I could let the user write the loading process so I pass in a unified way of storing the texture data so the rendersystem itself don''t need to provided the loading code of different texture types e.g. // load some texture, tga, jpg, whatever ... // calculate the needed memory space int iWidth; // width of texture int iHeight; // height of texture int iBpp; // Bits per pixel ... // allocate space for the texture to load cTextureData *t_data = new cTextureData(iWidth, iHeight, iBpp); // push the temp buffer that containes the texture data t_data->Push( texturedata ); // Make the texture aviable for rendersystem unsinged int TexID = RenderSystem->RegisterTexture( t_data ); 2) or using pointers of some kind, I have seen that some use the rendersystem somthing like this cTexture *MyTexture = RenderSystem->CreateTexture(...); and then it will return a API dependent Texture class that is inherited from the cTexture class wich has the basics need for the engine to run.. //base class class cTexture { ... }; class cTextureGL : public cTexture { // OpenGL specefic stuff ... }; class cTextureD3D : public cTexture { // Direct3D specefic stuff ... };

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
the first choice is cool. using handles vs pointers offers more safter i think. debugging can be easier as you have a handle ID vs an address.

Share this post


Link to post
Share on other sites
The way to do it is use the second method for internals - i.e. texture manager class in the rendersystem and then the first method for exposing access to the textures so what you end up with is a mapping of textureID''s to cTexture pointers. What the handle method also enables you to do is a paging system, since the user of the library doesn''t need to know the address of the loaded texture.

As for the rendersystem knowing how to load images etc.. a good method is to use a codec type method i.e. have a codec class which defines an interface for decoding an image, and them have the se registered to the rendersystem. This potentially enables you to allow pluggable support for multiple texture types using dll''s.

James

Share this post


Link to post
Share on other sites