• Advertisement
Sign in to follow this  

[DX9] Copy LPDIRECT3DDEVICE9 adress

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

Hello :)

I have two classes, one Device class and one SpriteHandling class.

My LPDIRECT3DDEVICE9 device interface is a member of the device class, in this class I also have the LPD3DXSPRITE interface to initialize the sprite COM using:

D3DXCreateSprite(device, &sprite)


Now my SpriteHandler class will load all textures and meta data., however the D3DXCreateTextureFromFile() requires that I pass the device. Instead of having to keep passing my GraphicsDevice object into the SpirteHandler object I would much rather have the device adress as a member available.

Which brings the question if this is proper:
WinMain:

DEVICEOBJECT GraphicsDevice();
SPRITEHANDLER Sprites(GraphicsDevice.GetDevice());



LPDIRECT3DDEVICE9 DEVICEOBJECT::GetDevice()
{
return device;
}



void SPRITEHANDLER::InitHandler(LPDIRECT3DDEVICE9 _device)
{
device = _device;
return;
}


Class:

class SPRITEHANDLER
{
public:
SPRITEHANDLER(LPDIRECT3DDEVICE9 device)
{
//init stuff
InitHandler(device);
}
~SPRITEHANDLER()
{
//release stuff
if(TestSprite)
TestSprite->Release();
}

void InitHandler(LPDIRECT3DDEVICE9 device);
void LoadSprite();


protected:
LPDIRECT3DDEVICE9 device; //Copy device adress in here
LPDIRECT3DTEXTURE9 TestSprite;
};


where device is a LPDIRECT3DDEVICE9 member in the SpriteHandler class. The passed _device is from the GraphicsDevice class where it is initialized.

Share this post


Link to post
Share on other sites
Advertisement
Hidden
My D3DXCreateTextureFromFile() in SPRITEHANDLER::LoadSprite() fails. So i guess I need another way of doing this...

Share this post


Link to post
One thing I would add to this is to AddRef your device in SPRITEHANDLER::InitHandler and Release it in the appropriate place (probably the destructor for your SPRITEHANDLER). This would follow proper COM convention and make sure that the reference to device in SPRITEHANDLER remains valid even if something else releases it.

Don't forget OnLostDevice and OnResetDevice for your ID3DXSprite - it creates some resources of it's own behind the scenes (namely a vertex buffer and an index buffer).

Share this post


Link to post
Share on other sites
Alternately, rather than use raw pointers, use a smart pointer like CComPtr and don't worry about explicit AddRef() and Release() calls.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement