1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Pequenas correções em Texture2D::Initialize

This commit is contained in:
Danilo 2024-08-05 16:12:53 -03:00
parent fedb773b31
commit c21871a951

View File

@ -35,34 +35,42 @@ namespace xna {
{ {
if (!m_device || !m_device->impl->_device) { if (!m_device || !m_device->impl->_device) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE); Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
} }
auto& deviceImpl = m_device->impl;
HRESULT hr = 0; HRESULT hr = 0;
if (!impl->dxTexture2D) { if (!impl->dxTexture2D) {
hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, impl->dxTexture2D.ReleaseAndGetAddressOf()); hr = deviceImpl->_device->CreateTexture2D(
&impl->dxDescription,
nullptr,
impl->dxTexture2D.ReleaseAndGetAddressOf());
if (FAILED(hr)) { if FAILED(hr)
Exception::Throw(Exception::FAILED_TO_CREATE); Exception::Throw(Exception::FAILED_TO_CREATE);
}
} }
else { else {
//Updates description if texture is not null
impl->dxTexture2D->GetDesc(&impl->dxDescription); impl->dxTexture2D->GetDesc(&impl->dxDescription);
} }
comptr<ID3D11Resource> resource = nullptr; comptr<ID3D11Resource> resource = nullptr;
hr = impl->dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)resource.GetAddressOf()); hr = impl->dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)resource.GetAddressOf());
if (FAILED(hr)) { if FAILED(hr)
Exception::Throw(Exception::INVALID_OPERATION); Exception::Throw(Exception::INVALID_OPERATION);
}
//Only initializes if it is a ShaderResource
if (impl->dxDescription.BindFlags & D3D11_BIND_SHADER_RESOURCE) { if (impl->dxDescription.BindFlags & D3D11_BIND_SHADER_RESOURCE) {
hr = m_device->impl->_device->CreateShaderResourceView(resource.Get(), &impl->dxShaderDescription, impl->dxShaderResource.ReleaseAndGetAddressOf()); hr = deviceImpl->_device->CreateShaderResourceView(
resource.Get(),
&impl->dxShaderDescription,
impl->dxShaderResource.ReleaseAndGetAddressOf());
if (FAILED(hr)) { if FAILED(hr)
Exception::Throw(Exception::FAILED_TO_CREATE); Exception::Throw(Exception::FAILED_TO_CREATE);
}
} }
surfaceFormat = DxHelpers::SurfaceFormatToXna(impl->dxDescription.Format); surfaceFormat = DxHelpers::SurfaceFormatToXna(impl->dxDescription.Format);