Jump to content
  • Advertisement
Sign in to follow this  
Dan Caranfil

Making a copy contructor for a Mesh object

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

The problem I'm having is that it's impossible to alocate memory for a LPD3DXMESH object, new LPD3DXMESH doesn't work. How do you do this? Also does anyone know any resource about copy contructors for DirectX objects (I'm interested in a copy constructor for a mesh object of course)?

Share this post


Link to post
Share on other sites
Advertisement
you cant call new because directX follows Component Object Model
The constructors and destructors are either private or protected.. "i think"

you can always create a wrapper class for LPD3DXMESH and make all the little new and delete call you want...

but here is a copy mesh function for you


// copies a mesh
// make sure the mesh you send in is valid or no copy will occure
// if this fails it returns NULL
LPD3DXMesh CopyMesh( LPD3DXMesh srcMesh )
{
// make sure mesh is
if( srcMesh == NULL )
return NULL;

LPDIRECT3DDEVICE9 pTempDevice = NULL;

// get the device
if( FAILED( srcMesh->GetDevice( pTempDevice ) ))
return NULL

// the new mesh to be created
LPD3DXMesh newMesh = NULL;

HRESULT hr

// clone the mesh
hr = srcMesh->CloneMeshFVF(srcMesh->GetOptions(), srcMesh->GetFVF(), pTempDevice, &newMesh);

// release the device
pTempDevice->Release();

// see if mesh was cloned
if( FAILED( hr ))
return NULL;

// success
return newMesh;
}
//
//
//usage
//
LPD3DXMesh pMesh = CopyMesh( aValidMesh );

if( pMesh == NULL )
// failed
//
//




<<::EDIT::>> dont forget to release the newMesh if the mesh is not NULL

Share this post


Link to post
Share on other sites
Quote:
Original post by Dan Caranfil
The problem I'm having is that it's impossible to alocate memory for a LPD3DXMESH object, new LPD3DXMESH doesn't work. How do you do this?

Use any of the mesh creation functions, passing it the address of a mesh interface pointer.

Share this post


Link to post
Share on other sites
If you don't intend to modify the copied buffer they could point to the same data, call addRef on the LPD3DXMESH object (assuming you release it in the destructor).

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!