From c21871a9519a10b0a0569c4827e8b455eee8435f Mon Sep 17 00:00:00 2001 From: Danilo Date: Mon, 5 Aug 2024 16:12:53 -0300 Subject: [PATCH] =?UTF-8?q?Pequenas=20corre=C3=A7=C3=B5es=20em=20Texture2D?= =?UTF-8?q?::Initialize?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/platform-dx/texture.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/framework/platform-dx/texture.cpp b/framework/platform-dx/texture.cpp index 1dde906..a4955d1 100644 --- a/framework/platform-dx/texture.cpp +++ b/framework/platform-dx/texture.cpp @@ -35,34 +35,42 @@ namespace xna { { if (!m_device || !m_device->impl->_device) { Exception::Throw(Exception::UNABLE_TO_INITIALIZE); - } + } + + auto& deviceImpl = m_device->impl; HRESULT hr = 0; - + 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); - } } else { + //Updates description if texture is not null impl->dxTexture2D->GetDesc(&impl->dxDescription); } comptr resource = nullptr; hr = impl->dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)resource.GetAddressOf()); - if (FAILED(hr)) { + if FAILED(hr) Exception::Throw(Exception::INVALID_OPERATION); - } + //Only initializes if it is a ShaderResource 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); - } + } surfaceFormat = DxHelpers::SurfaceFormatToXna(impl->dxDescription.Format);