1
\$\begingroup\$

I can display a textured quad by using D3D11 & DirectXTex's ScratchImage and CreateShaderResourceView. How would I be able to render this texture to another one similarly created? I know that I need to create a RenderTargetView and use Map somehow but I don't know how it all fits together I'm quite mixed up. I have studied Braynzarsoft's Tutorial 34 How to Render to Texture but I couldn't congeal the information into a logical form of understanding. Plus the registration doesn't work and can't download the source code. Finally should I actually just use DirectX::CopyRectangle or is it too slow? In good faith here is how I create the texture:

m_spTexture.reset(new ScratchImage);

WCHAR wcExt[_MAX_EXT];
_wsplitpath_s(wsFilename.c_str(), nullptr, 0, nullptr, 0, nullptr, 0, wcExt, _MAX_EXT);

HRESULT hr;
if ( _wcsicmp(wcExt, L".dds") == 0)
{
    hr = LoadFromDDSFile(wsFilename.c_str(), DDS_FLAGS_NONE, &m_stInfo, *m_spTexture);
}
else if (_wcsicmp(wcExt, L".tga") == 0)
{
    hr = LoadFromTGAFile(wsFilename.c_str(), &m_stInfo, *m_spTexture);
}
else
{
    hr = LoadFromWICFile(wsFilename.c_str(), WIC_FLAGS_NONE, &m_stInfo, *m_spTexture);
}

if (SUCCEEDED(hr))
{
    hr = CreateShaderResourceView(g_pEngine->GetD3DObj()->m_spD3DDevice.Get(),
                                  m_spTexture->GetImages(), 
                                  m_spTexture->GetImageCount(),
                                  m_stInfo, 
                                  m_spSRV.GetAddressOf() );
    if (FAILED(hr))
        return hr;
}

return hr;

I look forward to and appreciate your thoughts.

\$\endgroup\$
2
  • \$\begingroup\$ What exactly are you trying to accomplish? You can use ID3D11Device::CopyResource but I suspect you actually want more than that, especially since you refer to rendering to the texture. \$\endgroup\$ – MooseBoys Nov 9 '14 at 6:19
  • \$\begingroup\$ @MooseBoys That sounds brilliant. Thanks. Also its counterpart is useful. What I am trying to do is put a small texture on a larger texture of a quad. How am I able to do blending then with this function or its counterpart ::CopySubresourceRegion? Is at all possible? \$\endgroup\$ – Elixir Nov 9 '14 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.