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

Remove XnaErrorCode e implementa Exceções

This commit is contained in:
Danilo 2024-06-22 11:02:01 -03:00
parent b442c158b7
commit 663777a713
27 changed files with 138 additions and 227 deletions

View File

@ -19,7 +19,7 @@ namespace xna {
IDXGIFactory1* pFactory = nullptr; IDXGIFactory1* pFactory = nullptr;
if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory))
return nullptr; Exception::Throw(ExMessage::CreateComponent);
IDXGIAdapter1* pAdapter = nullptr; IDXGIAdapter1* pAdapter = nullptr;
@ -42,7 +42,7 @@ namespace xna {
IDXGIFactory1* pFactory = nullptr; IDXGIFactory1* pFactory = nullptr;
if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory))
return; Exception::Throw(ExMessage::CreateComponent);
IDXGIAdapter1* pAdapter = nullptr; IDXGIAdapter1* pAdapter = nullptr;
UINT count = 0; UINT count = 0;
@ -64,7 +64,7 @@ namespace xna {
IDXGIFactory1* pFactory = nullptr; IDXGIFactory1* pFactory = nullptr;
if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory))
return; Exception::Throw(ExMessage::CreateComponent);
IDXGIAdapter1* pAdapter = nullptr; IDXGIAdapter1* pAdapter = nullptr;
UINT count = 0; UINT count = 0;

View File

@ -15,11 +15,10 @@ namespace xna {
impl = nullptr; impl = nullptr;
} }
bool BlendState::Initialize(xna_error_ptr_arg) bool BlendState::Initialize()
{ {
if (!m_device || !m_device->impl->_device) { if (!m_device || !m_device->impl->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
if (impl->dxBlendState) { if (impl->dxBlendState) {
@ -32,22 +31,19 @@ namespace xna {
&impl->dxBlendState); &impl->dxBlendState);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return false;
} }
return true; return true;
} }
bool BlendState::Apply(xna_error_ptr_arg) { bool BlendState::Apply() {
if (!m_device || !m_device->impl->_context) { if (!m_device || !m_device->impl->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::ApplyComponent);
return false;
} }
if (!impl->dxBlendState) { if (!impl->dxBlendState) {
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE); Exception::Throw(ExMessage::UnintializedComponent);
return false;
} }
m_device->impl->_context->OMSetBlendState( m_device->impl->_context->OMSetBlendState(

View File

@ -15,11 +15,10 @@ namespace xna {
impl = nullptr; impl = nullptr;
} }
bool ConstantBuffer::Initialize(xna_error_ptr_arg) bool ConstantBuffer::Initialize()
{ {
if (!m_device || !m_device->impl->_device) { if (!m_device || !m_device->impl->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
if (impl->_buffer) { if (impl->_buffer) {
@ -33,8 +32,7 @@ namespace xna {
&impl->_buffer); &impl->_buffer);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return false;
} }
return true; return true;
@ -52,10 +50,9 @@ namespace xna {
impl = nullptr; impl = nullptr;
} }
bool DataBuffer::Initialize(xna_error_ptr_arg) { bool DataBuffer::Initialize() {
if (!m_device || !m_device->impl->_device) { if (!m_device || !m_device->impl->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
if (impl->_blob) { if (impl->_blob) {
@ -78,10 +75,9 @@ namespace xna {
impl = nullptr; impl = nullptr;
} }
bool IndexBuffer::Apply(xna_error_ptr_arg) { bool IndexBuffer::Apply() {
if (!m_device || !m_device->impl->_context || !impl || !impl->dxBuffer) { if (!m_device || !m_device->impl->_context || !impl || !impl->dxBuffer) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::ApplyComponent);
return false;
} }
m_device->impl->_context->IASetIndexBuffer(impl->dxBuffer, DXGI_FORMAT_R16_UINT, 0); m_device->impl->_context->IASetIndexBuffer(impl->dxBuffer, DXGI_FORMAT_R16_UINT, 0);
@ -101,15 +97,13 @@ namespace xna {
impl = nullptr; impl = nullptr;
} }
bool VertexBuffer::Apply(xna_error_ptr_arg) { bool VertexBuffer::Apply() {
if (!impl || !m_device || !m_device->impl->_context) { if (!impl || !m_device || !m_device->impl->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::ApplyComponent);
return false;
} }
if (!impl->dxBuffer) { if (!impl->dxBuffer) {
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE); Exception::Throw(ExMessage::UnintializedComponent);
return false;
} }
UINT stride = impl->size; UINT stride = impl->size;
@ -132,10 +126,9 @@ namespace xna {
impl = nullptr; 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) { if (!impl || !m_device || !m_device->impl->_device || !blob.impl->_blob) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
if (impl->_inputLayout) { if (impl->_inputLayout) {
@ -151,8 +144,7 @@ namespace xna {
&impl->_inputLayout); &impl->_inputLayout);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return false;
} }
return true; return true;

View File

@ -39,11 +39,10 @@ namespace xna {
impl = nullptr; impl = nullptr;
} }
bool DepthStencilState::Initialize(xna_error_ptr_arg) bool DepthStencilState::Initialize()
{ {
if (!m_device || !m_device->impl->_device) { if (!m_device || !m_device->impl->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
if (impl->dxDepthStencil) { if (impl->dxDepthStencil) {
@ -56,23 +55,20 @@ namespace xna {
&impl->dxDepthStencil); &impl->dxDepthStencil);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return false;
} }
return true; return true;
} }
bool DepthStencilState::Apply(xna_error_ptr_arg) bool DepthStencilState::Apply()
{ {
if (!m_device || !m_device->impl->_context) { if (!m_device || !m_device->impl->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InvalidOperation);
return false;
} }
if (!impl->dxDepthStencil) { if (!impl->dxDepthStencil) {
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE); Exception::Throw(ExMessage::UnintializedComponent);
return false;
} }
m_device->impl->_context->OMSetDepthStencilState(impl->dxDepthStencil, 0); m_device->impl->_context->OMSetDepthStencilState(impl->dxDepthStencil, 0);

View File

@ -24,13 +24,11 @@ namespace xna {
impl._renderTarget2D = nullptr; impl._renderTarget2D = nullptr;
} }
static bool createDevice(GraphicsDevice::PlatformImplementation& impl) { static void createDevice(GraphicsDevice::PlatformImplementation& impl) {
auto createDeviceFlags = 0; auto createDeviceFlags = 0;
#if _DEBUG #if _DEBUG
createDeviceFlags = D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG; createDeviceFlags = D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG;
#endif #endif
auto hr = D3D11CreateDevice( auto hr = D3D11CreateDevice(
impl._adapter->impl->dxadapter, impl._adapter->impl->dxadapter,
D3D_DRIVER_TYPE_UNKNOWN, D3D_DRIVER_TYPE_UNKNOWN,
@ -56,10 +54,11 @@ namespace xna {
D3D11_SDK_VERSION, D3D11_SDK_VERSION,
&impl._device, &impl._device,
&impl._featureLevel, &impl._featureLevel,
&impl._context); &impl._context);
if FAILED(hr)
Exception::Throw(ExMessage::CreateComponent);
} }
return SUCCEEDED(hr);
} }
GraphicsDevice::GraphicsDevice() { GraphicsDevice::GraphicsDevice() {
@ -95,12 +94,12 @@ namespace xna {
auto _this = shared_from_this(); auto _this = shared_from_this();
if (!createDevice(*impl)) createDevice(*impl);
return false;
auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&impl->_factory); 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(); const auto bounds = impl->_gameWindow->ClientBounds();
@ -119,9 +118,12 @@ namespace xna {
impl->_swapChain->Initialize(); impl->_swapChain->Initialize();
hr = impl->_factory->MakeWindowAssociation(impl->_gameWindow->impl->WindowHandle(), DXGI_MWA_NO_ALT_ENTER); 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<RenderTarget2D>(_this); impl->_renderTarget2D = New<RenderTarget2D>(_this);
if (!impl->_renderTarget2D->Initialize()) if (!impl->_renderTarget2D->Initialize())
return false; return false;
@ -139,6 +141,7 @@ namespace xna {
impl->_blendState = BlendState::NonPremultiplied(); impl->_blendState = BlendState::NonPremultiplied();
impl->_blendState->Bind(_this); impl->_blendState->Bind(_this);
impl->_blendState->Initialize();
impl->_blendState->Apply(); impl->_blendState->Apply();
return true; return true;

View File

@ -15,11 +15,10 @@ namespace xna {
impl = nullptr; impl = nullptr;
} }
bool RasterizerState::Initialize(xna_error_ptr_arg) bool RasterizerState::Initialize()
{ {
if (!impl || !m_device || !m_device->impl->_device) { if (!impl || !m_device || !m_device->impl->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
if (impl->dxRasterizerState) { if (impl->dxRasterizerState) {
@ -32,23 +31,20 @@ namespace xna {
&impl->dxRasterizerState); &impl->dxRasterizerState);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return false;
} }
return true; return true;
} }
bool RasterizerState::Apply(xna_error_ptr_arg) bool RasterizerState::Apply()
{ {
if (!impl || !m_device || !m_device->impl->_context) { if (!impl || !m_device || !m_device->impl->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
if (!impl->dxRasterizerState) { if (!impl->dxRasterizerState) {
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE); Exception::Throw(ExMessage::UnintializedComponent);
return false;
} }
m_device->impl->_context->RSSetState(impl->dxRasterizerState); m_device->impl->_context->RSSetState(impl->dxRasterizerState);

View File

@ -13,10 +13,9 @@ namespace xna {
render_impl = nullptr; render_impl = nullptr;
} }
bool RenderTarget2D::Initialize(xna_error_ptr_arg) { bool RenderTarget2D::Initialize() {
if (!impl || !m_device || !m_device->impl->_device) { if (!impl || !m_device || !m_device->impl->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
if (impl->dxTexture2D) { if (impl->dxTexture2D) {
@ -32,19 +31,20 @@ namespace xna {
const auto hr = dxdevice->CreateRenderTargetView(impl->dxTexture2D, NULL, &render_impl->_renderTargetView); const auto hr = dxdevice->CreateRenderTargetView(impl->dxTexture2D, NULL, &render_impl->_renderTargetView);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return false;
} }
return true; return true;
} }
bool RenderTarget2D::Apply(xna_error_ptr_arg) { bool RenderTarget2D::Apply() {
if (!m_device || !m_device->impl->_context) { if (!m_device || !m_device->impl->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::ApplyComponent);
return false;
} }
if(!render_impl->_renderTargetView)
Exception::Throw(ExMessage::UnintializedComponent);
auto& context = m_device->impl->_context; auto& context = m_device->impl->_context;
context->OMSetRenderTargets(1, &render_impl->_renderTargetView, nullptr); context->OMSetRenderTargets(1, &render_impl->_renderTargetView, nullptr);
return true; return true;

View File

@ -15,11 +15,10 @@ namespace xna {
impl = nullptr; impl = nullptr;
} }
bool SamplerState::Initialize(xna_error_ptr_arg) bool SamplerState::Initialize()
{ {
if (!impl || !m_device || !m_device->impl->_device) { if (!impl || !m_device || !m_device->impl->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
if (impl->_samplerState) { if (impl->_samplerState) {
@ -32,23 +31,20 @@ namespace xna {
&impl->_samplerState); &impl->_samplerState);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return false;
} }
return true; return true;
} }
bool SamplerState::Apply(xna_error_ptr_arg) bool SamplerState::Apply()
{ {
if (!impl || !m_device || !m_device->impl->_context) { if (!impl || !m_device || !m_device->impl->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InvalidOperation);
return false;
} }
if (!impl->_samplerState) { if (!impl->_samplerState) {
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE); Exception::Throw(ExMessage::UnintializedComponent);
return false;
} }
m_device->impl->_context->PSSetSamplers(0, 1, &impl->_samplerState); m_device->impl->_context->PSSetSamplers(0, 1, &impl->_samplerState);

View File

@ -61,11 +61,10 @@ namespace xna {
impl = nullptr; 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) { if (!impl || !m_device || !m_device->impl->_device || !buffer.impl->_blob) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
if (impl->_vertexShader) { if (impl->_vertexShader) {
@ -80,18 +79,16 @@ namespace xna {
&impl->_vertexShader); &impl->_vertexShader);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return false;
} }
return true; 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) { if (!impl || !m_device || !m_device->impl->_device || !buffer.impl->_blob) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
if (impl->_pixelShader) { if (impl->_pixelShader) {
@ -106,8 +103,7 @@ namespace xna {
&impl->_pixelShader); &impl->_pixelShader);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return false;
} }
return true; return true;

View File

@ -50,10 +50,9 @@ namespace xna {
return true; return true;
} }
bool SwapChain::Initialize(xna_error_ptr_arg) { bool SwapChain::Initialize() {
if (!impl || !m_device || !m_device->impl->_device) { if (!impl || !m_device || !m_device->impl->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
const auto parameters = m_device->impl->_presentationParameters; const auto parameters = m_device->impl->_presentationParameters;

View File

@ -5,7 +5,7 @@ namespace xna {
impl = nullptr; impl = nullptr;
} }
sptr<Texture2D> Texture2D::FromStream(GraphicsDevice& device, String const& fileName, xna_error_ptr_arg) sptr<Texture2D> Texture2D::FromStream(GraphicsDevice& device, String const& fileName)
{ {
auto _this = device.shared_from_this(); auto _this = device.shared_from_this();
auto texture2d = New<Texture2D>(_this); auto texture2d = New<Texture2D>(_this);
@ -21,9 +21,7 @@ namespace xna {
0U); 0U);
if (FAILED(result)) if (FAILED(result))
{ {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
if (resource) { if (resource) {
resource->Release(); resource->Release();
resource = nullptr; resource = nullptr;
@ -35,8 +33,6 @@ namespace xna {
result = resource->QueryInterface(IID_ID3D11Texture2D, (void**)&texture2d->impl->dxTexture2D); result = resource->QueryInterface(IID_ID3D11Texture2D, (void**)&texture2d->impl->dxTexture2D);
if (FAILED(result)) { if (FAILED(result)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
if (resource) { if (resource) {
resource->Release(); resource->Release();
resource = nullptr; resource = nullptr;
@ -55,31 +51,23 @@ namespace xna {
return texture2d; 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) { if (!m_device || !m_device->impl->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, &impl->dxTexture2D); auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, &impl->dxTexture2D);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return false;
} }
ID3D11Resource* resource = nullptr; ID3D11Resource* resource = nullptr;
hr = impl->dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource); hr = impl->dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::InvalidOperation);
return false;
} }
hr = m_device->impl->_device->CreateShaderResourceView(resource, &impl->dxShaderDescription, &impl->dxShaderResource); hr = m_device->impl->_device->CreateShaderResourceView(resource, &impl->dxShaderDescription, &impl->dxShaderResource);
@ -90,8 +78,7 @@ namespace xna {
} }
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return false;
} }
return true; return true;
@ -138,14 +125,13 @@ namespace xna {
impl->dxDescription.Format = DxHelpers::ConvertSurfaceToDXGIFORMAT(format); 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) { if (!impl.dxTexture2D) {
auto hr = device.impl->_device->CreateTexture2D(&impl.dxDescription, nullptr, &impl.dxTexture2D); auto hr = device.impl->_device->CreateTexture2D(&impl.dxDescription, nullptr, &impl.dxTexture2D);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return hr;
} }
} }
@ -153,8 +139,7 @@ namespace xna {
auto hr = impl.dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource); auto hr = impl.dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::InvalidOperation);
return hr;
} }
constexpr int R8G8B8A8U_BYTE_SIZE = 4; constexpr int R8G8B8A8U_BYTE_SIZE = 4;
@ -174,8 +159,7 @@ namespace xna {
} }
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return hr;
} }
impl.dxTexture2D->GetDesc(&impl.dxDescription); impl.dxTexture2D->GetDesc(&impl.dxDescription);
@ -183,21 +167,19 @@ namespace xna {
return NO_ERROR; return NO_ERROR;
} }
void Texture2D::SetData(std::vector<Uint> const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg) void Texture2D::SetData(std::vector<Uint> const& data, size_t startIndex, size_t elementCount)
{ {
if (!impl || !m_device || !m_device->impl->_device || !m_device->impl->_context) { if (!impl || !m_device || !m_device->impl->_device || !m_device->impl->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InvalidOperation);
return;
} }
internalSetData(*impl, *m_device, data.data(), err); internalSetData(*impl, *m_device, data.data());
} }
void Texture2D::SetData(std::vector<Byte> const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg) void Texture2D::SetData(std::vector<Byte> const& data, size_t startIndex, size_t elementCount)
{ {
if (!m_device || !m_device->impl->_device || !m_device->impl->_context) { if (!m_device || !m_device->impl->_device || !m_device->impl->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InvalidOperation);
return;
} }
std::vector<UINT> finalData(elementCount / 4); std::vector<UINT> finalData(elementCount / 4);
@ -212,14 +194,13 @@ namespace xna {
++fIndex; ++fIndex;
} }
internalSetData(*impl, *m_device, finalData.data(), err); internalSetData(*impl, *m_device, finalData.data());
} }
void Texture2D::SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg) void Texture2D::SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount)
{ {
if (!m_device || !m_device->impl->_device || !m_device->impl->_context) { if (!m_device || !m_device->impl->_device || !m_device->impl->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InvalidOperation);
return;
} }
std::vector<UINT> finalData(elementCount / 4); std::vector<UINT> finalData(elementCount / 4);
@ -238,8 +219,7 @@ namespace xna {
auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, &impl->dxTexture2D); auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, &impl->dxTexture2D);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return;
} }
} }
@ -247,8 +227,7 @@ namespace xna {
auto hr = impl->dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource); auto hr = impl->dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::InvalidOperation);
return;
} }
D3D11_BOX box{}; D3D11_BOX box{};
@ -280,18 +259,16 @@ namespace xna {
} }
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return;
} }
impl->dxTexture2D->GetDesc(&impl->dxDescription); impl->dxTexture2D->GetDesc(&impl->dxDescription);
} }
void Texture2D::SetData(std::vector<Color> const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg) void Texture2D::SetData(std::vector<Color> const& data, size_t startIndex, size_t elementCount)
{ {
if (!m_device || !m_device->impl->_device || !m_device->impl->_context) { if (!m_device || !m_device->impl->_device || !m_device->impl->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InvalidOperation);
return;
} }
std::vector<UINT> finalData(elementCount); std::vector<UINT> finalData(elementCount);
@ -302,10 +279,10 @@ namespace xna {
++finalDataIndex; ++finalDataIndex;
} }
internalSetData(*impl, *m_device, finalData.data(), err); internalSetData(*impl, *m_device, finalData.data());
} }
sptr<Texture2D> Texture2D::FromMemory(GraphicsDevice& device, std::vector<Byte> const& data, xna_error_ptr_arg) sptr<Texture2D> Texture2D::FromMemory(GraphicsDevice& device, std::vector<Byte> const& data)
{ {
auto _this = device.shared_from_this(); auto _this = device.shared_from_this();
auto texture2d = New<Texture2D>(_this); auto texture2d = New<Texture2D>(_this);
@ -321,8 +298,6 @@ namespace xna {
if (FAILED(hr)) if (FAILED(hr))
{ {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
if (resource) { if (resource) {
resource->Release(); resource->Release();
resource = nullptr; resource = nullptr;
@ -334,8 +309,6 @@ namespace xna {
hr = resource->QueryInterface(IID_ID3D11Texture2D, (void**)&texture2d->impl->dxTexture2D); hr = resource->QueryInterface(IID_ID3D11Texture2D, (void**)&texture2d->impl->dxTexture2D);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
if (resource) { if (resource) {
resource->Release(); resource->Release();
resource = nullptr; resource = nullptr;

View File

@ -3,7 +3,6 @@
#include "../types.hpp" #include "../types.hpp"
#include "../enums.hpp" #include "../enums.hpp"
#include "../xnaerror.hpp"
#include <fstream> #include <fstream>
#include <filesystem> #include <filesystem>

View File

@ -1,5 +1,4 @@
#include "types.hpp" #include "types.hpp"
#include "forward.hpp" #include "forward.hpp"
#include "enums.hpp" #include "enums.hpp"
#include "helpers.hpp" #include "helpers.hpp"
#include "xnaerror.hpp"

View File

@ -7,14 +7,19 @@
namespace xna { namespace xna {
struct ExMessage { 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 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 { struct Exception {
static void Throw(std::string const& message, const std::source_location location = std::source_location::current()) { static void Throw(std::string const& message, const std::source_location location = std::source_location::current()) {
std::string error; std::string error;
error.append("Exception in: ");
error.append("Exception in: ");
#if _DEBUG #if _DEBUG
error.append(location.file_name()); error.append(location.file_name());
error.append("("); error.append("(");

View File

@ -12,11 +12,11 @@ namespace xna {
BlendState(); BlendState();
BlendState(sptr<GraphicsDevice> const& device); BlendState(sptr<GraphicsDevice> const& device);
~BlendState() override; ~BlendState() override;
bool Initialize(xna_error_nullarg) ; bool Initialize() ;
void AlphaToCoverageEnable(bool value) ; void AlphaToCoverageEnable(bool value) ;
void IndependentBlendEnable(bool value) ; void IndependentBlendEnable(bool value) ;
void RenderTargets(std::vector<BlendRenderTarget> const& value); void RenderTargets(std::vector<BlendRenderTarget> const& value);
bool Apply(xna_error_nullarg); bool Apply();
static uptr<BlendState> Opaque(); static uptr<BlendState> Opaque();
static uptr<BlendState> AlphaBlend(); static uptr<BlendState> AlphaBlend();

View File

@ -10,7 +10,7 @@ namespace xna {
ConstantBuffer(); ConstantBuffer();
ConstantBuffer(sptr<GraphicsDevice> const&); ConstantBuffer(sptr<GraphicsDevice> const&);
~ConstantBuffer() override; ~ConstantBuffer() override;
bool Initialize(xna_error_nullarg); bool Initialize();
public: public:
struct PlatformImplementation; struct PlatformImplementation;
@ -22,7 +22,7 @@ namespace xna {
DataBuffer(); DataBuffer();
DataBuffer(sptr<GraphicsDevice> const&); DataBuffer(sptr<GraphicsDevice> const&);
~DataBuffer() override; ~DataBuffer() override;
bool Initialize(xna_error_nullarg); bool Initialize();
public: public:
struct PlatformImplementation; struct PlatformImplementation;
@ -36,8 +36,8 @@ namespace xna {
~IndexBuffer() override; ~IndexBuffer() override;
template <typename T> template <typename T>
bool Initialize(std::vector<T> const& data, xna_error_nullarg); bool Initialize(std::vector<T> const& data);
bool Apply(xna_error_nullarg); bool Apply();
public: public:
struct PlatformImplementation; struct PlatformImplementation;
@ -50,8 +50,8 @@ namespace xna {
VertexBuffer(sptr<GraphicsDevice> const&); VertexBuffer(sptr<GraphicsDevice> const&);
~VertexBuffer(); ~VertexBuffer();
template <typename T> template <typename T>
bool Initialize(std::vector<T> const& data, xna_error_nullarg); bool Initialize(std::vector<T> const& data);
bool Apply(xna_error_nullarg); bool Apply();
public: public:
struct PlatformImplementation; struct PlatformImplementation;
@ -64,7 +64,7 @@ namespace xna {
VertexInputLayout(sptr<GraphicsDevice> const&); VertexInputLayout(sptr<GraphicsDevice> const&);
~VertexInputLayout(); ~VertexInputLayout();
bool Initialize(DataBuffer& blob, xna_error_nullarg); bool Initialize(DataBuffer& blob);
public: public:
struct PlatformImplementation; struct PlatformImplementation;

View File

@ -12,8 +12,8 @@ namespace xna {
DepthStencilState(sptr<GraphicsDevice> const& device); DepthStencilState(sptr<GraphicsDevice> const& device);
~DepthStencilState() override; ~DepthStencilState() override;
bool Initialize(xna_error_nullarg); bool Initialize();
bool Apply(xna_error_ptr_arg); bool Apply();
void DepthEnabled(bool value); void DepthEnabled(bool value);
void DepthWriteEnabled(bool value); void DepthWriteEnabled(bool value);

View File

@ -10,8 +10,8 @@ namespace xna {
RasterizerState(); RasterizerState();
RasterizerState(sptr<GraphicsDevice> const& device); RasterizerState(sptr<GraphicsDevice> const& device);
~RasterizerState() override; ~RasterizerState() override;
bool Initialize(xna_error_nullarg); bool Initialize();
bool Apply(xna_error_nullarg); bool Apply();
xna::CullMode CullMode() const; xna::CullMode CullMode() const;
void CullMode(xna::CullMode value); void CullMode(xna::CullMode value);
xna::FillMode FillMode() const; xna::FillMode FillMode() const;

View File

@ -11,8 +11,8 @@ namespace xna {
RenderTarget2D(sptr<GraphicsDevice> const& device); RenderTarget2D(sptr<GraphicsDevice> const& device);
~RenderTarget2D() override; ~RenderTarget2D() override;
bool Initialize(xna_error_nullarg); bool Initialize();
bool Apply(xna_error_nullarg); bool Apply();
public: public:
struct PlatformImplementation; struct PlatformImplementation;

View File

@ -10,8 +10,8 @@ namespace xna {
SamplerState(); SamplerState();
SamplerState(sptr<GraphicsDevice> const& device); SamplerState(sptr<GraphicsDevice> const& device);
~SamplerState() override; ~SamplerState() override;
bool Initialize(xna_error_nullarg); bool Initialize();
bool Apply(xna_error_nullarg); bool Apply();
void Filter(TextureFilter value); void Filter(TextureFilter value);
void AddressU(TextureAddressMode value); void AddressU(TextureAddressMode value);
void AddressV(TextureAddressMode value); void AddressV(TextureAddressMode value);

View File

@ -10,7 +10,7 @@ namespace xna {
Shader(); Shader();
Shader(sptr<GraphicsDevice> const& device); Shader(sptr<GraphicsDevice> const& device);
~Shader() override {} ~Shader() override {}
bool Initialize(DataBuffer& buffer, xna_error_nullarg); bool Initialize(DataBuffer& buffer);
static bool CompileFromFile(WString srcFile, String entryPoint, String profile, DataBuffer& blob); static bool CompileFromFile(WString srcFile, String entryPoint, String profile, DataBuffer& blob);
}; };
@ -19,7 +19,7 @@ namespace xna {
VertexShader(); VertexShader();
VertexShader(sptr<GraphicsDevice> const& device); VertexShader(sptr<GraphicsDevice> const& device);
~VertexShader() override; ~VertexShader() override;
bool Initialize(DataBuffer& buffer, xna_error_nullarg); bool Initialize(DataBuffer& buffer);
public: public:
struct PlatformImplementation; struct PlatformImplementation;
@ -31,7 +31,7 @@ namespace xna {
PixelShader(); PixelShader();
PixelShader(sptr<GraphicsDevice> const& device); PixelShader(sptr<GraphicsDevice> const& device);
~PixelShader() override; ~PixelShader() override;
bool Initialize(DataBuffer& buffer, xna_error_nullarg); bool Initialize(DataBuffer& buffer);
public: public:
struct PlatformImplementation; struct PlatformImplementation;

View File

@ -10,7 +10,7 @@ namespace xna {
SwapChain(); SwapChain();
SwapChain(sptr<GraphicsDevice> const& device); SwapChain(sptr<GraphicsDevice> const& device);
~SwapChain() override; ~SwapChain() override;
bool Initialize(xna_error_nullarg); bool Initialize();
bool Present(bool vsync); bool Present(bool vsync);
bool GetBackBuffer(Texture2D& texture2D); bool GetBackBuffer(Texture2D& texture2D);
public: public:

View File

@ -20,13 +20,13 @@ namespace xna {
Int Width() const; Int Width() const;
Int Height() const; Int Height() const;
Rectangle Bounds() const; Rectangle Bounds() const;
bool Initialize(xna_error_nullarg); bool Initialize();
void SetData(std::vector<Color> const& data, size_t startIndex = 0, size_t elementCount = 0, xna_error_nullarg); void SetData(std::vector<Color> const& data, size_t startIndex = 0, size_t elementCount = 0);
void SetData(std::vector<Uint> const& data, size_t startIndex = 0, size_t elementCount = 0, xna_error_nullarg); void SetData(std::vector<Uint> const& data, size_t startIndex = 0, size_t elementCount = 0);
void SetData(std::vector<Byte> const& data, size_t startIndex = 0, size_t elementCount = 0, xna_error_nullarg); void SetData(std::vector<Byte> const& data, size_t startIndex = 0, size_t elementCount = 0);
void SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount, xna_error_nullarg); void SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount);
static sptr<Texture2D> FromStream(GraphicsDevice& device, String const& fileName, xna_error_nullarg); static sptr<Texture2D> FromStream(GraphicsDevice& device, String const& fileName);
static sptr<Texture2D> FromMemory(GraphicsDevice& device, std::vector<Byte> const& data, xna_error_nullarg); static sptr<Texture2D> FromMemory(GraphicsDevice& device, std::vector<Byte> const& data);
public: public:
struct PlatformImplementation; struct PlatformImplementation;

View File

@ -1011,34 +1011,30 @@ namespace xna {
}; };
template <typename T> template <typename T>
inline bool IndexBuffer::Initialize(std::vector<T> const& data, xna_error_ptr_arg) { inline bool IndexBuffer::Initialize(std::vector<T> const& data) {
if (!impl || !m_device || !m_device->impl->_device || data.empty()) { if (!impl || !m_device || !m_device->impl->_device || data.empty()) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
const auto hr = DirectX::CreateStaticBuffer(m_device->impl->_device, data.data(), data.size(), sizeof(T), D3D11_BIND_INDEX_BUFFER, &impl->dxBuffer); const auto hr = DirectX::CreateStaticBuffer(m_device->impl->_device, data.data(), data.size(), sizeof(T), D3D11_BIND_INDEX_BUFFER, &impl->dxBuffer);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return false;
} }
return true; return true;
} }
template <typename T> template <typename T>
inline bool VertexBuffer::Initialize(std::vector<T> const& data, xna_error_ptr_arg) { inline bool VertexBuffer::Initialize(std::vector<T> const& data) {
if (!impl || !m_device || !m_device->impl->_device || data.empty()) { if (!impl || !m_device || !m_device->impl->_device || data.empty()) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); Exception::Throw(ExMessage::InitializeComponent);
return false;
} }
const auto hr = DirectX::CreateStaticBuffer(m_device->impl->_device, data.data(), data.size(), sizeof(T), D3D11_BIND_VERTEX_BUFFER, &impl->dxBuffer); const auto hr = DirectX::CreateStaticBuffer(m_device->impl->_device, data.data(), data.size(), sizeof(T), D3D11_BIND_VERTEX_BUFFER, &impl->dxBuffer);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); Exception::Throw(ExMessage::CreateComponent);
return false;
} }
impl->size = sizeof(T); impl->size = sizeof(T);

View File

@ -1,5 +1,4 @@
#define NOMINMAX #define NOMINMAX
#include "xnaerror.hpp"
#include "types.hpp" #include "types.hpp"
#include "helpers.hpp" #include "helpers.hpp"
#include "enums.hpp" #include "enums.hpp"

View File

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

View File

@ -3,5 +3,5 @@
# #
# Add source to this project's executable. # Add source to this project's executable.
#add_subdirectory ("01_blank") add_subdirectory ("01_blank")
add_subdirectory ("02_PlatfformerStarterKit") add_subdirectory ("02_PlatfformerStarterKit")