From 663777a713989b22579b951a360a05b073f99e89 Mon Sep 17 00:00:00 2001 From: Danilo Date: Sat, 22 Jun 2024 11:02:01 -0300 Subject: [PATCH] =?UTF-8?q?Remove=20XnaErrorCode=20e=20implementa=20Exce?= =?UTF-8?q?=C3=A7=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/platform-dx/adapter.cpp | 6 +- framework/platform-dx/blendstate.cpp | 16 ++--- framework/platform-dx/buffer.cpp | 34 ++++----- framework/platform-dx/depthstencilstate.cpp | 16 ++--- framework/platform-dx/device.cpp | 25 ++++--- framework/platform-dx/rasterizerstate.cpp | 16 ++--- framework/platform-dx/rendertarget.cpp | 16 ++--- framework/platform-dx/samplerstate.cpp | 16 ++--- framework/platform-dx/shader.cpp | 16 ++--- framework/platform-dx/swapchain.cpp | 5 +- framework/platform-dx/texture.cpp | 79 +++++++-------------- inc/xna/csharp/stream.hpp | 1 - inc/xna/default.hpp | 3 +- inc/xna/exception.hpp | 7 +- inc/xna/graphics/blendstate.hpp | 4 +- inc/xna/graphics/buffer.hpp | 14 ++-- inc/xna/graphics/depthstencilstate.hpp | 4 +- inc/xna/graphics/rasterizerstate.hpp | 4 +- inc/xna/graphics/rendertarget.hpp | 4 +- inc/xna/graphics/samplerstate.hpp | 4 +- inc/xna/graphics/shader.hpp | 6 +- inc/xna/graphics/swapchain.hpp | 2 +- inc/xna/graphics/texture.hpp | 14 ++-- inc/xna/platform-dx/dx.hpp | 16 ++--- inc/xna/xna.hpp | 1 - inc/xna/xnaerror.hpp | 34 --------- samples/CMakeLists.txt | 2 +- 27 files changed, 138 insertions(+), 227 deletions(-) delete mode 100644 inc/xna/xnaerror.hpp diff --git a/framework/platform-dx/adapter.cpp b/framework/platform-dx/adapter.cpp index a522ea7..e2c0973 100644 --- a/framework/platform-dx/adapter.cpp +++ b/framework/platform-dx/adapter.cpp @@ -19,7 +19,7 @@ namespace xna { IDXGIFactory1* pFactory = nullptr; if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) - return nullptr; + Exception::Throw(ExMessage::CreateComponent); IDXGIAdapter1* pAdapter = nullptr; @@ -42,7 +42,7 @@ namespace xna { IDXGIFactory1* pFactory = nullptr; if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) - return; + Exception::Throw(ExMessage::CreateComponent); IDXGIAdapter1* pAdapter = nullptr; UINT count = 0; @@ -64,7 +64,7 @@ namespace xna { IDXGIFactory1* pFactory = nullptr; if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) - return; + Exception::Throw(ExMessage::CreateComponent); IDXGIAdapter1* pAdapter = nullptr; UINT count = 0; diff --git a/framework/platform-dx/blendstate.cpp b/framework/platform-dx/blendstate.cpp index 0a680dc..c840811 100644 --- a/framework/platform-dx/blendstate.cpp +++ b/framework/platform-dx/blendstate.cpp @@ -15,11 +15,10 @@ namespace xna { impl = nullptr; } - bool BlendState::Initialize(xna_error_ptr_arg) + bool BlendState::Initialize() { if (!m_device || !m_device->impl->_device) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } if (impl->dxBlendState) { @@ -32,22 +31,19 @@ namespace xna { &impl->dxBlendState); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; + Exception::Throw(ExMessage::CreateComponent); } return true; } - bool BlendState::Apply(xna_error_ptr_arg) { + bool BlendState::Apply() { if (!m_device || !m_device->impl->_context) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::ApplyComponent); } if (!impl->dxBlendState) { - xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE); - return false; + Exception::Throw(ExMessage::UnintializedComponent); } m_device->impl->_context->OMSetBlendState( diff --git a/framework/platform-dx/buffer.cpp b/framework/platform-dx/buffer.cpp index 61cf105..1fb1b0c 100644 --- a/framework/platform-dx/buffer.cpp +++ b/framework/platform-dx/buffer.cpp @@ -15,11 +15,10 @@ namespace xna { impl = nullptr; } - bool ConstantBuffer::Initialize(xna_error_ptr_arg) + bool ConstantBuffer::Initialize() { if (!m_device || !m_device->impl->_device) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } if (impl->_buffer) { @@ -33,8 +32,7 @@ namespace xna { &impl->_buffer); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; + Exception::Throw(ExMessage::CreateComponent); } return true; @@ -52,10 +50,9 @@ namespace xna { impl = nullptr; } - bool DataBuffer::Initialize(xna_error_ptr_arg) { + bool DataBuffer::Initialize() { if (!m_device || !m_device->impl->_device) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } if (impl->_blob) { @@ -78,10 +75,9 @@ namespace xna { impl = nullptr; } - bool IndexBuffer::Apply(xna_error_ptr_arg) { + bool IndexBuffer::Apply() { if (!m_device || !m_device->impl->_context || !impl || !impl->dxBuffer) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::ApplyComponent); } m_device->impl->_context->IASetIndexBuffer(impl->dxBuffer, DXGI_FORMAT_R16_UINT, 0); @@ -101,15 +97,13 @@ namespace xna { impl = nullptr; } - bool VertexBuffer::Apply(xna_error_ptr_arg) { + bool VertexBuffer::Apply() { if (!impl || !m_device || !m_device->impl->_context) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::ApplyComponent); } if (!impl->dxBuffer) { - xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE); - return false; + Exception::Throw(ExMessage::UnintializedComponent); } UINT stride = impl->size; @@ -132,10 +126,9 @@ namespace xna { impl = nullptr; } - bool VertexInputLayout::Initialize(DataBuffer& blob, xna_error_ptr_arg) { + bool VertexInputLayout::Initialize(DataBuffer& blob) { if (!impl || !m_device || !m_device->impl->_device || !blob.impl->_blob) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } if (impl->_inputLayout) { @@ -151,8 +144,7 @@ namespace xna { &impl->_inputLayout); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; + Exception::Throw(ExMessage::CreateComponent); } return true; diff --git a/framework/platform-dx/depthstencilstate.cpp b/framework/platform-dx/depthstencilstate.cpp index d5b680f..7afc539 100644 --- a/framework/platform-dx/depthstencilstate.cpp +++ b/framework/platform-dx/depthstencilstate.cpp @@ -39,11 +39,10 @@ namespace xna { impl = nullptr; } - bool DepthStencilState::Initialize(xna_error_ptr_arg) + bool DepthStencilState::Initialize() { if (!m_device || !m_device->impl->_device) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } if (impl->dxDepthStencil) { @@ -56,23 +55,20 @@ namespace xna { &impl->dxDepthStencil); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; + Exception::Throw(ExMessage::CreateComponent); } return true; } - bool DepthStencilState::Apply(xna_error_ptr_arg) + bool DepthStencilState::Apply() { if (!m_device || !m_device->impl->_context) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InvalidOperation); } if (!impl->dxDepthStencil) { - xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE); - return false; + Exception::Throw(ExMessage::UnintializedComponent); } m_device->impl->_context->OMSetDepthStencilState(impl->dxDepthStencil, 0); diff --git a/framework/platform-dx/device.cpp b/framework/platform-dx/device.cpp index 2ebcb01..9c1cba5 100644 --- a/framework/platform-dx/device.cpp +++ b/framework/platform-dx/device.cpp @@ -24,13 +24,11 @@ namespace xna { impl._renderTarget2D = nullptr; } - static bool createDevice(GraphicsDevice::PlatformImplementation& impl) { + static void createDevice(GraphicsDevice::PlatformImplementation& impl) { auto createDeviceFlags = 0; #if _DEBUG createDeviceFlags = D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG; #endif - - auto hr = D3D11CreateDevice( impl._adapter->impl->dxadapter, D3D_DRIVER_TYPE_UNKNOWN, @@ -56,10 +54,11 @@ namespace xna { D3D11_SDK_VERSION, &impl._device, &impl._featureLevel, - &impl._context); + &impl._context); + + if FAILED(hr) + Exception::Throw(ExMessage::CreateComponent); } - - return SUCCEEDED(hr); } GraphicsDevice::GraphicsDevice() { @@ -95,12 +94,12 @@ namespace xna { auto _this = shared_from_this(); - if (!createDevice(*impl)) - return false; + createDevice(*impl); auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&impl->_factory); - if (FAILED(hr)) - return false; + + if FAILED(hr) + Exception::Throw(ExMessage::CreateComponent); const auto bounds = impl->_gameWindow->ClientBounds(); @@ -119,9 +118,12 @@ namespace xna { impl->_swapChain->Initialize(); hr = impl->_factory->MakeWindowAssociation(impl->_gameWindow->impl->WindowHandle(), DXGI_MWA_NO_ALT_ENTER); - if (FAILED(hr)) return false; + + if (FAILED(hr)) + Exception::Throw(ExMessage::MakeWindowAssociation); impl->_renderTarget2D = New(_this); + if (!impl->_renderTarget2D->Initialize()) return false; @@ -139,6 +141,7 @@ namespace xna { impl->_blendState = BlendState::NonPremultiplied(); impl->_blendState->Bind(_this); + impl->_blendState->Initialize(); impl->_blendState->Apply(); return true; diff --git a/framework/platform-dx/rasterizerstate.cpp b/framework/platform-dx/rasterizerstate.cpp index 311865c..89d2c54 100644 --- a/framework/platform-dx/rasterizerstate.cpp +++ b/framework/platform-dx/rasterizerstate.cpp @@ -15,11 +15,10 @@ namespace xna { impl = nullptr; } - bool RasterizerState::Initialize(xna_error_ptr_arg) + bool RasterizerState::Initialize() { if (!impl || !m_device || !m_device->impl->_device) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } if (impl->dxRasterizerState) { @@ -32,23 +31,20 @@ namespace xna { &impl->dxRasterizerState); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; + Exception::Throw(ExMessage::CreateComponent); } return true; } - bool RasterizerState::Apply(xna_error_ptr_arg) + bool RasterizerState::Apply() { if (!impl || !m_device || !m_device->impl->_context) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } if (!impl->dxRasterizerState) { - xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE); - return false; + Exception::Throw(ExMessage::UnintializedComponent); } m_device->impl->_context->RSSetState(impl->dxRasterizerState); diff --git a/framework/platform-dx/rendertarget.cpp b/framework/platform-dx/rendertarget.cpp index d266c0d..2f0bd14 100644 --- a/framework/platform-dx/rendertarget.cpp +++ b/framework/platform-dx/rendertarget.cpp @@ -13,10 +13,9 @@ namespace xna { render_impl = nullptr; } - bool RenderTarget2D::Initialize(xna_error_ptr_arg) { + bool RenderTarget2D::Initialize() { if (!impl || !m_device || !m_device->impl->_device) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } if (impl->dxTexture2D) { @@ -32,19 +31,20 @@ namespace xna { const auto hr = dxdevice->CreateRenderTargetView(impl->dxTexture2D, NULL, &render_impl->_renderTargetView); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; + Exception::Throw(ExMessage::CreateComponent); } return true; } - bool RenderTarget2D::Apply(xna_error_ptr_arg) { + bool RenderTarget2D::Apply() { if (!m_device || !m_device->impl->_context) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::ApplyComponent); } + if(!render_impl->_renderTargetView) + Exception::Throw(ExMessage::UnintializedComponent); + auto& context = m_device->impl->_context; context->OMSetRenderTargets(1, &render_impl->_renderTargetView, nullptr); return true; diff --git a/framework/platform-dx/samplerstate.cpp b/framework/platform-dx/samplerstate.cpp index 597c5cb..1d0cd43 100644 --- a/framework/platform-dx/samplerstate.cpp +++ b/framework/platform-dx/samplerstate.cpp @@ -15,11 +15,10 @@ namespace xna { impl = nullptr; } - bool SamplerState::Initialize(xna_error_ptr_arg) + bool SamplerState::Initialize() { if (!impl || !m_device || !m_device->impl->_device) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } if (impl->_samplerState) { @@ -32,23 +31,20 @@ namespace xna { &impl->_samplerState); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; + Exception::Throw(ExMessage::CreateComponent); } return true; } - bool SamplerState::Apply(xna_error_ptr_arg) + bool SamplerState::Apply() { if (!impl || !m_device || !m_device->impl->_context) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InvalidOperation); } if (!impl->_samplerState) { - xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE); - return false; + Exception::Throw(ExMessage::UnintializedComponent); } m_device->impl->_context->PSSetSamplers(0, 1, &impl->_samplerState); diff --git a/framework/platform-dx/shader.cpp b/framework/platform-dx/shader.cpp index 9ed7453..8ceda6b 100644 --- a/framework/platform-dx/shader.cpp +++ b/framework/platform-dx/shader.cpp @@ -61,11 +61,10 @@ namespace xna { impl = nullptr; } - bool VertexShader::Initialize(DataBuffer& buffer, xna_error_ptr_arg) + bool VertexShader::Initialize(DataBuffer& buffer) { if (!impl || !m_device || !m_device->impl->_device || !buffer.impl->_blob) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } if (impl->_vertexShader) { @@ -80,18 +79,16 @@ namespace xna { &impl->_vertexShader); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; + Exception::Throw(ExMessage::CreateComponent); } return true; } - bool PixelShader::Initialize(DataBuffer& buffer, xna_error_ptr_arg) + bool PixelShader::Initialize(DataBuffer& buffer) { if (!impl || !m_device || !m_device->impl->_device || !buffer.impl->_blob) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } if (impl->_pixelShader) { @@ -106,8 +103,7 @@ namespace xna { &impl->_pixelShader); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; + Exception::Throw(ExMessage::CreateComponent); } return true; diff --git a/framework/platform-dx/swapchain.cpp b/framework/platform-dx/swapchain.cpp index f47fa39..a131568 100644 --- a/framework/platform-dx/swapchain.cpp +++ b/framework/platform-dx/swapchain.cpp @@ -50,10 +50,9 @@ namespace xna { return true; } - bool SwapChain::Initialize(xna_error_ptr_arg) { + bool SwapChain::Initialize() { if (!impl || !m_device || !m_device->impl->_device) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } const auto parameters = m_device->impl->_presentationParameters; diff --git a/framework/platform-dx/texture.cpp b/framework/platform-dx/texture.cpp index 0a95a67..703f200 100644 --- a/framework/platform-dx/texture.cpp +++ b/framework/platform-dx/texture.cpp @@ -5,7 +5,7 @@ namespace xna { impl = nullptr; } - sptr Texture2D::FromStream(GraphicsDevice& device, String const& fileName, xna_error_ptr_arg) + sptr Texture2D::FromStream(GraphicsDevice& device, String const& fileName) { auto _this = device.shared_from_this(); auto texture2d = New(_this); @@ -21,9 +21,7 @@ namespace xna { 0U); if (FAILED(result)) - { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - + { if (resource) { resource->Release(); resource = nullptr; @@ -35,8 +33,6 @@ namespace xna { result = resource->QueryInterface(IID_ID3D11Texture2D, (void**)&texture2d->impl->dxTexture2D); if (FAILED(result)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - if (resource) { resource->Release(); resource = nullptr; @@ -55,31 +51,23 @@ namespace xna { return texture2d; } - bool Texture2D::Initialize(xna_error_ptr_arg) + bool Texture2D::Initialize() { - if (impl->dxTexture2D) { - xna_error_apply(err, XnaErrorCode::WARNING_INITIALIZED_RESOURCE); - return false; - } - if (!m_device || !m_device->impl->_device) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, &impl->dxTexture2D); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; + Exception::Throw(ExMessage::CreateComponent); } ID3D11Resource* resource = nullptr; hr = impl->dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; + Exception::Throw(ExMessage::InvalidOperation); } hr = m_device->impl->_device->CreateShaderResourceView(resource, &impl->dxShaderDescription, &impl->dxShaderResource); @@ -90,8 +78,7 @@ namespace xna { } if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; + Exception::Throw(ExMessage::CreateComponent); } return true; @@ -138,14 +125,13 @@ namespace xna { impl->dxDescription.Format = DxHelpers::ConvertSurfaceToDXGIFORMAT(format); } - HRESULT internalSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data, xna_error_ptr_arg) + HRESULT internalSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data) { if (!impl.dxTexture2D) { auto hr = device.impl->_device->CreateTexture2D(&impl.dxDescription, nullptr, &impl.dxTexture2D); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return hr; + Exception::Throw(ExMessage::CreateComponent); } } @@ -153,8 +139,7 @@ namespace xna { auto hr = impl.dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return hr; + Exception::Throw(ExMessage::InvalidOperation); } constexpr int R8G8B8A8U_BYTE_SIZE = 4; @@ -174,8 +159,7 @@ namespace xna { } if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return hr; + Exception::Throw(ExMessage::CreateComponent); } impl.dxTexture2D->GetDesc(&impl.dxDescription); @@ -183,21 +167,19 @@ namespace xna { return NO_ERROR; } - void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg) + void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount) { if (!impl || !m_device || !m_device->impl->_device || !m_device->impl->_context) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return; + Exception::Throw(ExMessage::InvalidOperation); } - internalSetData(*impl, *m_device, data.data(), err); + internalSetData(*impl, *m_device, data.data()); } - void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg) + void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount) { if (!m_device || !m_device->impl->_device || !m_device->impl->_context) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return; + Exception::Throw(ExMessage::InvalidOperation); } std::vector finalData(elementCount / 4); @@ -212,14 +194,13 @@ namespace xna { ++fIndex; } - internalSetData(*impl, *m_device, finalData.data(), err); + internalSetData(*impl, *m_device, finalData.data()); } - void Texture2D::SetData(Int level, Rectangle* rect, std::vector const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg) + void Texture2D::SetData(Int level, Rectangle* rect, std::vector const& data, size_t startIndex, size_t elementCount) { if (!m_device || !m_device->impl->_device || !m_device->impl->_context) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return; + Exception::Throw(ExMessage::InvalidOperation); } std::vector finalData(elementCount / 4); @@ -238,8 +219,7 @@ namespace xna { auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, &impl->dxTexture2D); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return; + Exception::Throw(ExMessage::CreateComponent); } } @@ -247,8 +227,7 @@ namespace xna { auto hr = impl->dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return; + Exception::Throw(ExMessage::InvalidOperation); } D3D11_BOX box{}; @@ -280,18 +259,16 @@ namespace xna { } if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return; + Exception::Throw(ExMessage::CreateComponent); } impl->dxTexture2D->GetDesc(&impl->dxDescription); } - void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg) + void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount) { if (!m_device || !m_device->impl->_device || !m_device->impl->_context) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return; + Exception::Throw(ExMessage::InvalidOperation); } std::vector finalData(elementCount); @@ -302,10 +279,10 @@ namespace xna { ++finalDataIndex; } - internalSetData(*impl, *m_device, finalData.data(), err); + internalSetData(*impl, *m_device, finalData.data()); } - sptr Texture2D::FromMemory(GraphicsDevice& device, std::vector const& data, xna_error_ptr_arg) + sptr Texture2D::FromMemory(GraphicsDevice& device, std::vector const& data) { auto _this = device.shared_from_this(); auto texture2d = New(_this); @@ -321,8 +298,6 @@ namespace xna { if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - if (resource) { resource->Release(); resource = nullptr; @@ -334,8 +309,6 @@ namespace xna { hr = resource->QueryInterface(IID_ID3D11Texture2D, (void**)&texture2d->impl->dxTexture2D); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - if (resource) { resource->Release(); resource = nullptr; diff --git a/inc/xna/csharp/stream.hpp b/inc/xna/csharp/stream.hpp index 75977fb..8e8d4b7 100644 --- a/inc/xna/csharp/stream.hpp +++ b/inc/xna/csharp/stream.hpp @@ -3,7 +3,6 @@ #include "../types.hpp" #include "../enums.hpp" -#include "../xnaerror.hpp" #include #include diff --git a/inc/xna/default.hpp b/inc/xna/default.hpp index ee10054..1e7dae5 100644 --- a/inc/xna/default.hpp +++ b/inc/xna/default.hpp @@ -1,5 +1,4 @@ #include "types.hpp" #include "forward.hpp" #include "enums.hpp" -#include "helpers.hpp" -#include "xnaerror.hpp" \ No newline at end of file +#include "helpers.hpp" \ No newline at end of file diff --git a/inc/xna/exception.hpp b/inc/xna/exception.hpp index fd29578..01ee089 100644 --- a/inc/xna/exception.hpp +++ b/inc/xna/exception.hpp @@ -7,14 +7,19 @@ namespace xna { struct ExMessage { + inline static const std::string InvalidOperation = "An invalid operation occurred."; inline static const std::string InitializeComponent = "Unable to initialize component"; + inline static const std::string CreateComponent = "Failed to create component"; + inline static const std::string ApplyComponent = "Failed to apply component"; + inline static const std::string UnintializedComponent = "Component is not initialized"; + inline static const std::string MakeWindowAssociation = "Failed to create association with window"; }; struct Exception { static void Throw(std::string const& message, const std::source_location location = std::source_location::current()) { std::string error; - error.append("Exception in: "); + error.append("Exception in: "); #if _DEBUG error.append(location.file_name()); error.append("("); diff --git a/inc/xna/graphics/blendstate.hpp b/inc/xna/graphics/blendstate.hpp index ce9e4de..8affba0 100644 --- a/inc/xna/graphics/blendstate.hpp +++ b/inc/xna/graphics/blendstate.hpp @@ -12,11 +12,11 @@ namespace xna { BlendState(); BlendState(sptr const& device); ~BlendState() override; - bool Initialize(xna_error_nullarg) ; + bool Initialize() ; void AlphaToCoverageEnable(bool value) ; void IndependentBlendEnable(bool value) ; void RenderTargets(std::vector const& value); - bool Apply(xna_error_nullarg); + bool Apply(); static uptr Opaque(); static uptr AlphaBlend(); diff --git a/inc/xna/graphics/buffer.hpp b/inc/xna/graphics/buffer.hpp index 0adde1e..66e4671 100644 --- a/inc/xna/graphics/buffer.hpp +++ b/inc/xna/graphics/buffer.hpp @@ -10,7 +10,7 @@ namespace xna { ConstantBuffer(); ConstantBuffer(sptr const&); ~ConstantBuffer() override; - bool Initialize(xna_error_nullarg); + bool Initialize(); public: struct PlatformImplementation; @@ -22,7 +22,7 @@ namespace xna { DataBuffer(); DataBuffer(sptr const&); ~DataBuffer() override; - bool Initialize(xna_error_nullarg); + bool Initialize(); public: struct PlatformImplementation; @@ -36,8 +36,8 @@ namespace xna { ~IndexBuffer() override; template - bool Initialize(std::vector const& data, xna_error_nullarg); - bool Apply(xna_error_nullarg); + bool Initialize(std::vector const& data); + bool Apply(); public: struct PlatformImplementation; @@ -50,8 +50,8 @@ namespace xna { VertexBuffer(sptr const&); ~VertexBuffer(); template - bool Initialize(std::vector const& data, xna_error_nullarg); - bool Apply(xna_error_nullarg); + bool Initialize(std::vector const& data); + bool Apply(); public: struct PlatformImplementation; @@ -64,7 +64,7 @@ namespace xna { VertexInputLayout(sptr const&); ~VertexInputLayout(); - bool Initialize(DataBuffer& blob, xna_error_nullarg); + bool Initialize(DataBuffer& blob); public: struct PlatformImplementation; diff --git a/inc/xna/graphics/depthstencilstate.hpp b/inc/xna/graphics/depthstencilstate.hpp index 1decdbc..fe4b954 100644 --- a/inc/xna/graphics/depthstencilstate.hpp +++ b/inc/xna/graphics/depthstencilstate.hpp @@ -12,8 +12,8 @@ namespace xna { DepthStencilState(sptr const& device); ~DepthStencilState() override; - bool Initialize(xna_error_nullarg); - bool Apply(xna_error_ptr_arg); + bool Initialize(); + bool Apply(); void DepthEnabled(bool value); void DepthWriteEnabled(bool value); diff --git a/inc/xna/graphics/rasterizerstate.hpp b/inc/xna/graphics/rasterizerstate.hpp index da861b9..3c8ff40 100644 --- a/inc/xna/graphics/rasterizerstate.hpp +++ b/inc/xna/graphics/rasterizerstate.hpp @@ -10,8 +10,8 @@ namespace xna { RasterizerState(); RasterizerState(sptr const& device); ~RasterizerState() override; - bool Initialize(xna_error_nullarg); - bool Apply(xna_error_nullarg); + bool Initialize(); + bool Apply(); xna::CullMode CullMode() const; void CullMode(xna::CullMode value); xna::FillMode FillMode() const; diff --git a/inc/xna/graphics/rendertarget.hpp b/inc/xna/graphics/rendertarget.hpp index 1a41f3d..5c4adc7 100644 --- a/inc/xna/graphics/rendertarget.hpp +++ b/inc/xna/graphics/rendertarget.hpp @@ -11,8 +11,8 @@ namespace xna { RenderTarget2D(sptr const& device); ~RenderTarget2D() override; - bool Initialize(xna_error_nullarg); - bool Apply(xna_error_nullarg); + bool Initialize(); + bool Apply(); public: struct PlatformImplementation; diff --git a/inc/xna/graphics/samplerstate.hpp b/inc/xna/graphics/samplerstate.hpp index a959bdd..59ae1a4 100644 --- a/inc/xna/graphics/samplerstate.hpp +++ b/inc/xna/graphics/samplerstate.hpp @@ -10,8 +10,8 @@ namespace xna { SamplerState(); SamplerState(sptr const& device); ~SamplerState() override; - bool Initialize(xna_error_nullarg); - bool Apply(xna_error_nullarg); + bool Initialize(); + bool Apply(); void Filter(TextureFilter value); void AddressU(TextureAddressMode value); void AddressV(TextureAddressMode value); diff --git a/inc/xna/graphics/shader.hpp b/inc/xna/graphics/shader.hpp index 3ec1733..158eb19 100644 --- a/inc/xna/graphics/shader.hpp +++ b/inc/xna/graphics/shader.hpp @@ -10,7 +10,7 @@ namespace xna { Shader(); Shader(sptr const& device); ~Shader() override {} - bool Initialize(DataBuffer& buffer, xna_error_nullarg); + bool Initialize(DataBuffer& buffer); static bool CompileFromFile(WString srcFile, String entryPoint, String profile, DataBuffer& blob); }; @@ -19,7 +19,7 @@ namespace xna { VertexShader(); VertexShader(sptr const& device); ~VertexShader() override; - bool Initialize(DataBuffer& buffer, xna_error_nullarg); + bool Initialize(DataBuffer& buffer); public: struct PlatformImplementation; @@ -31,7 +31,7 @@ namespace xna { PixelShader(); PixelShader(sptr const& device); ~PixelShader() override; - bool Initialize(DataBuffer& buffer, xna_error_nullarg); + bool Initialize(DataBuffer& buffer); public: struct PlatformImplementation; diff --git a/inc/xna/graphics/swapchain.hpp b/inc/xna/graphics/swapchain.hpp index bb4d5f1..2674027 100644 --- a/inc/xna/graphics/swapchain.hpp +++ b/inc/xna/graphics/swapchain.hpp @@ -10,7 +10,7 @@ namespace xna { SwapChain(); SwapChain(sptr const& device); ~SwapChain() override; - bool Initialize(xna_error_nullarg); + bool Initialize(); bool Present(bool vsync); bool GetBackBuffer(Texture2D& texture2D); public: diff --git a/inc/xna/graphics/texture.hpp b/inc/xna/graphics/texture.hpp index baea647..e5afae4 100644 --- a/inc/xna/graphics/texture.hpp +++ b/inc/xna/graphics/texture.hpp @@ -20,13 +20,13 @@ namespace xna { Int Width() const; Int Height() const; Rectangle Bounds() const; - bool Initialize(xna_error_nullarg); - void SetData(std::vector const& data, size_t startIndex = 0, size_t elementCount = 0, xna_error_nullarg); - void SetData(std::vector const& data, size_t startIndex = 0, size_t elementCount = 0, xna_error_nullarg); - void SetData(std::vector const& data, size_t startIndex = 0, size_t elementCount = 0, xna_error_nullarg); - void SetData(Int level, Rectangle* rect, std::vector const& data, size_t startIndex, size_t elementCount, xna_error_nullarg); - static sptr FromStream(GraphicsDevice& device, String const& fileName, xna_error_nullarg); - static sptr FromMemory(GraphicsDevice& device, std::vector const& data, xna_error_nullarg); + bool Initialize(); + void SetData(std::vector const& data, size_t startIndex = 0, size_t elementCount = 0); + void SetData(std::vector const& data, size_t startIndex = 0, size_t elementCount = 0); + void SetData(std::vector const& data, size_t startIndex = 0, size_t elementCount = 0); + void SetData(Int level, Rectangle* rect, std::vector const& data, size_t startIndex, size_t elementCount); + static sptr FromStream(GraphicsDevice& device, String const& fileName); + static sptr FromMemory(GraphicsDevice& device, std::vector const& data); public: struct PlatformImplementation; diff --git a/inc/xna/platform-dx/dx.hpp b/inc/xna/platform-dx/dx.hpp index cacad3c..7ad64d6 100644 --- a/inc/xna/platform-dx/dx.hpp +++ b/inc/xna/platform-dx/dx.hpp @@ -1011,34 +1011,30 @@ namespace xna { }; template - inline bool IndexBuffer::Initialize(std::vector const& data, xna_error_ptr_arg) { + inline bool IndexBuffer::Initialize(std::vector const& data) { if (!impl || !m_device || !m_device->impl->_device || data.empty()) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } const auto hr = DirectX::CreateStaticBuffer(m_device->impl->_device, data.data(), data.size(), sizeof(T), D3D11_BIND_INDEX_BUFFER, &impl->dxBuffer); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; + Exception::Throw(ExMessage::CreateComponent); } return true; } template - inline bool VertexBuffer::Initialize(std::vector const& data, xna_error_ptr_arg) { + inline bool VertexBuffer::Initialize(std::vector const& data) { if (!impl || !m_device || !m_device->impl->_device || data.empty()) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; + Exception::Throw(ExMessage::InitializeComponent); } const auto hr = DirectX::CreateStaticBuffer(m_device->impl->_device, data.data(), data.size(), sizeof(T), D3D11_BIND_VERTEX_BUFFER, &impl->dxBuffer); if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; + Exception::Throw(ExMessage::CreateComponent); } impl->size = sizeof(T); diff --git a/inc/xna/xna.hpp b/inc/xna/xna.hpp index b19b922..fe1fe83 100644 --- a/inc/xna/xna.hpp +++ b/inc/xna/xna.hpp @@ -1,5 +1,4 @@ #define NOMINMAX -#include "xnaerror.hpp" #include "types.hpp" #include "helpers.hpp" #include "enums.hpp" diff --git a/inc/xna/xnaerror.hpp b/inc/xna/xnaerror.hpp deleted file mode 100644 index dcdf274..0000000 --- a/inc/xna/xnaerror.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef XNA_XNAERROR_HPP -#define XNA_XNAERROR_HPP - -namespace xna { - enum class XnaErrorCode { - NONE, - ARGUMENT_OUT_OF_RANGE, - ARGUMENT_IS_NULL, - INVALID_OPERATION, - FAILED_OPERATION, - OVERFLOW_OPERATION, - NULL_CAST, - BAD_CAST, - STREAM_ERROR, - UNINTIALIZED_RESOURCE, - END_OF_FILE, - BAD_TYPE, - WARNING_INITIALIZED_RESOURCE - }; - - inline void xna_error_apply(XnaErrorCode* source, XnaErrorCode const& value) { - if (source != nullptr) - *source = value; - } - - inline bool xna_error_haserros(XnaErrorCode* source) { - return source != nullptr && *source != XnaErrorCode::NONE; - } - -#define xna_error_nullarg XnaErrorCode* err = nullptr -#define xna_error_ptr_arg XnaErrorCode* err -} - -#endif \ No newline at end of file diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index b164777..45257e9 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -3,5 +3,5 @@ # # Add source to this project's executable. -#add_subdirectory ("01_blank") +add_subdirectory ("01_blank") add_subdirectory ("02_PlatfformerStarterKit")