Jump to content
  • Advertisement
Sign in to follow this  
Whiles

Api - Specific Resources Design

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

Hey! I am going to design my resouce classes and I have encountered a big problem developing the Texture and Font classes because ... they are api - specific, right ? I don't think I could create a generic Texture class because the engine should load it before rendering the scene or it will be very slow... I should create an abstract texture class and some texture_dx10 and texture_gl classes, but I am looking for a way to: 1) hide the name of the api-specific texture class under the name of the abstract one in a way that the user doesn't see he's directly istantiating a texture_dx9 or texture_gl class... 2) provide a sort of extensible resource system: I could create some function in the renderer such as Texture* t = Renderer->createTexture() but it would not be extensible and user couldn't have the possibiliy to manage the memory of a resource by themselves or to add new resouces ( Renderer would work as a sort of static abstract factory, it could be very difficult to code new resources without editing the renderer code, too )... Could you help me with some ideas please ? I can't go ahead in my engine if I don't solve this design problem.. I hope you will help me :) Thank you!!

Share this post


Link to post
Share on other sites
Advertisement
i dont see why u cant use the renderer as a factory? there will be maybe 7-8 different resource u have to add... Texture, VertexBuffer, etc... thats how i do it...

Share this post


Link to post
Share on other sites
Hi, thanks for the answer !
I would like to avoid the renderer = factory solution because renderer' s scope is to draw polygons, i don't know if formally it's a good design, and because i would like to provide a solution for the game programmer to add custom resources in the engine which, for example, manage the memory in a sort of "custom" way...

Share this post


Link to post
Share on other sites
Quote:
Original post by Whiles
Hi, thanks for the answer !
I would like to avoid the renderer = factory solution because renderer' s scope is to draw polygons, i don't know if formally it's a good design, and because i would like to provide a solution for the game programmer to add custom resources in the engine which, for example, manage the memory in a sort of "custom" way...


what kind of custom resources? the renderer should only handle its own resources such as Textures, VertexBuffers etc... and i think its within the renders scope to create the resources it uses... only the renderer will ever need these resources... so i dont see why you would create them elsewhere... i think this is a good design also if u later want to put the renderer in a seperate thread...

Share this post


Link to post
Share on other sites
Do you know if it's possible to develop a generic texture class ?
It seems like Horde3D has a generic class which loads the pixel data and passes it to opengl ? Is it possible to pass pixel data to Directx, too ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Whiles
Do you know if it's possible to develop a generic texture class ?
It seems like Horde3D has a generic class which loads the pixel data and passes it to opengl ? Is it possible to pass pixel data to Directx, too ?


i dont see what u mean by a "generic texture class" or why u even need it...

i do it like this...

ive got a library with all my interfaces... forexample


namespace graphics
{
class ITexture
{
virtual void Bind() = 0;
}
}





then i implement it for the different APIs...


namespace d3d10
{
class Texture : public ITexture
{
Texture(void* data, /*etc...*/)
{
// do d3d10 stuff
}
void Bind()
{
// do d3d10 stuff
}
// d3d10 items
}
}





then u would do something lile

IRenderer* renderer = new d3d10::Renderer;

ITexture* pTexture = renderer->CreateTexture(); // create a d3d10::Texture but returns a ITexture

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!