Archived

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

Deadman55

Encapsulating the D3D Device

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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...)

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites