Jump to content

  • Log In with Google      Sign In   
  • Create Account

ID3D11Texture2D COM Interface Question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Hornsj3   Members   -  Reputation: 191

Like
0Likes
Like

Posted 15 April 2012 - 09:46 AM

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


Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 8285

Like
0Likes
Like

Posted 15 April 2012 - 10:06 AM

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

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 Hornsj3   Members   -  Reputation: 191

Like
0Likes
Like

Posted 15 April 2012 - 10:13 AM

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

#4 mhagain   Crossbones+   -  Reputation: 8285

Like
0Likes
Like

Posted 15 April 2012 - 11:16 AM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#5 Hornsj3   Members   -  Reputation: 191

Like
0Likes
Like

Posted 15 April 2012 - 05:29 PM

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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS