Sign in to follow this  
Hornsj3

ID3D11Texture2D COM Interface Question

Recommended Posts

Below is a function I am writing to copy data into a texture. My question is will the CreateTexture2D function release the ID3D11Texture2D pointer or do I need to explicitly release it if it holds data?

[CODE]
void InterlockingTiles::recreateTexture()
{
//Do I need to release this interface to prepare for new data?
if(m_pTexture)
{
m_pTexture->Release();
}
HRESULT hr = m_pDevice->CreateTexture2D(
&m_textureDesc,0,&m_pTexture);

if(FAILED(hr))
{
//TODO: throw some exception
}
}
[/CODE]

Share this post


Link to post
Share on other sites
[quote name='mhagain' timestamp='1334506004' post='4931460']
It won't hold it. In fact your m_pTexture should be NULL going into that call.
[/quote]

What does "it won't hold it" mean?

If I have created a texture object and assigned it to the pointer m_pTexture it won't be NULL. If I need to reuse that pointer do I call release and then CreateTexture2D, or am I safe in calling CreateTexture2D without an explicit release (is CreateTexture2D smart enough to release)?

Share this post


Link to post
Share on other sites
Ah, I understand. You're reusing a texture that may or may not have previously existed.

Yes, you should Release it before the next call to CreateTexture2D.

If however the new texture is going to be the same size as the previous one you should consider just updating it (via UpdateSubResource for example) instead.

Share this post


Link to post
Share on other sites
Thank you, that helps a lot.

Here's another function I have to do just what you suggested.

[CODE]
void InterlockingTiles::setHeightMap( const ID3D11Resource* pSrcTexture )
{

//Copy the contents of the resource into the texture
D3D11_BOX box;
box.left = 0;
box.right = m_textureDesc.Width;
box.top = 0;
box.bottom = m_textureDesc.Height;
box.front = 0;
box.back = 1;
m_pContext->CopySubresourceRegion(m_pTexture, 0, 0, 0, 0, (ID3D11Resource*)pSrcTexture, 0, &box );
}
[/CODE]

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