Encapsulating the D3D Device

Started by
4 comments, last by Deadman55 20 years, 11 months ago
Where do you guys put your device object, if we''re talking an OOP 3D engine? It''s gotta be quite accessible to a few classes that are outside the "core" if you know what I mean.. Make it a static class member?
Advertisement
Uhm, I have a DX class and have simply put it there amongst other shiet

Then when I create the dx object, the Device object is accessible through the dx object. I think that works just fine, at least so long... (Did the same with DirectDraw...)

Yeah.. Doh why didn''t I think of that lol.. I used that method in previous approaches. But if one thinks more abstract.. If you have lets say an Entity class with common functions such as Render() and Update(), which you add to a Render Manager of some kind that easily renders all of your Entity classes....

the Entity class must have access to a device in the Render() function right? or? swap pointers? i don''t want to do the whole D3DDeviceClass->GetDeviceObject()->DrawPrimitive(Entity->vertices)) because it''s ugly! do you see what i''m trying to ask? hehe...
you can use a singleton, then at the beginning of the render function:

IDirect3DDevice8 * Device = D3DDeviceClass::GetInstance()->GetDevice();

//render away with the device

or using a global pointer:

IDirect3DDevice8 * Device = D3DDeviceClass->GetDevice();
I have mine setup like this (I just arted messing with a few days ago so take it at that)

class CRenderer{   Render()   {      //loop through all CRenderables and call their render method   }   AddRenderable(CRenderable*);   RemoveRenderable(CRenderable*);   IDirect3D8 *GetDevice(){return m_D3DDevice};};class CRenderable{   CRenderable(CRenderer *Renderer); // constructuor needs to know what render instance we belong to   Render()   {      // Do render stuff call m_pRenderer->GetDevice() as needed.   }   CRenderable *m_pRenderer;};// Usage:CRenderer MyRenderer;CRenderable MyCube;MyRenderer.AddRenderable(&MyCube);MyRenderer.Render(); 
All of your replies sounds good. I''ll use a mixture =)
thanks

This topic is closed to new replies.

Advertisement