Sign in to follow this  
Dan Caranfil

Making a copy contructor for a Mesh object

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
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

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