Sign in to follow this  

copy texture

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

Okay, now I know how to copy a mesh, but how do I copy an IDirect3DTexture9? Again, it's abstract, so I can't just use a copy constructor. I looked it up in the documentation, and there's no D3DX function. Do I have to copy it myself? If so, how can I do that? I offer the thanks of a humble newbie to you. :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
why would you want to copy it? just tell D3D to use that texture when you need to.

Share this post


Link to post
Share on other sites
The texture belongs to a "GameObject". Actually, each GameObject has its own list of textures:

vector<IDirect3DTexture9*> textures;

It iterates through the sub-sections of its mesh, each time activating a texture from a list. When a GameObject has to clone itself, it needs to copy the textures over, too. Initially, I just did this:

obj.textures = textures;

This worked, except that the list holds pointers to textures, not the textures themselves. When the original object is deleted, it releases its textures. Since the clone of the object only has pointers to textures, they now point to garbage. That's why I need to copy the actual textures, not just copy the pointers.

Share this post


Link to post
Share on other sites
Consider using smart pointers instead, and only deleting the texture when there are no more GameObjects using it. Or setting up a separate manager for the textures, which GameObjects can ask for (references to) textures as needed.

Share this post


Link to post
Share on other sites
IDirect3DTexture9 is already a reference-counted object. All you have to do is call texture->AddRef() any time you copy the pointer. Subsequent texture->Release() calls will decrement the counter and only delete it when the reference count is zero.

Share this post


Link to post
Share on other sites

This topic is 4687 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.

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