Sign in to follow this  
terry_burns85

Sharing the LPDIRECT3DDEVICE9 across a project

Recommended Posts

Evening people, I am currently revisiting my old renderer to optimise its performance and came across something i remembered was a sticking point back when i first designed it, the sharing of the device across classes in a project. I.e. loading meshes, textures etc.. Currently its all done through pointers and parameters. But was just wondering how anyone else has approached this.

Share this post


Link to post
Share on other sites
i have a global namespace for these sort of things


globals.h:

namespace Engine
{
namespace DX
{
extern LPDIRECT3DDEVICE9 device;
extern D3DCAPS9 caps;
}

... more global stuff
}

globals.cpp:

LPDIRECT3DDEVICE9 Engine::DX::device = NULL;
D3DCAPS9 Engine::DX::caps;





now you can access it from anywhere u include the header like this:


Engine::DX::device





auto-complete feature makes it easy to type. downside is the external declaration which is a little more typing. i would love to find a way to do it without.

Share this post


Link to post
Share on other sites
I also prefer to pass the device pointer around to classes constructors, and have the class AddRef() and Release() in the c'tor and d'tor. At work, we have a singleton for the renderer which contains the device pointer, which isn't much better than a global IMO.

Share this post


Link to post
Share on other sites
I am trying to avoid global variables as much as possible... So everything is passed as pointers. I use Singleton fo some special classes like TextureManager or EffectManager, which are shared within whole engine... but DX device is created only on one place and then passed everywhere by pointers... Its better, you can have more devices, not just one, If you have more GPUs.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this