Jump to content
  • Advertisement
Sign in to follow this  
Hornsj3

ID3D11Texture2D COM Interface Question

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

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?


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

Share this post


Link to post
Share on other sites
Advertisement

It won't hold it. In fact your m_pTexture should be NULL going into that call.


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.


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 );
}

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!