ID3D11Texture2D COM Interface Question

Started by
3 comments, last by Hornsj3 12 years ago
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
}
}
Advertisement
It won't hold it. In fact your m_pTexture should be NULL going into that call.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.


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)?
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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

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

This topic is closed to new replies.

Advertisement