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

View File

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

View File

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

View File

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

View File

@ -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<RenderTarget2D>(_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;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@ namespace xna {
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 texture2d = New<Texture2D>(_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<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) {
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<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) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return;
Exception::Throw(ExMessage::InvalidOperation);
}
std::vector<UINT> 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<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) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return;
Exception::Throw(ExMessage::InvalidOperation);
}
std::vector<UINT> 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<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) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return;
Exception::Throw(ExMessage::InvalidOperation);
}
std::vector<UINT> finalData(elementCount);
@ -302,10 +279,10 @@ namespace xna {
++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 texture2d = New<Texture2D>(_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;

View File

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

View File

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

View File

@ -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("(");

View File

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

View File

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

View File

@ -12,8 +12,8 @@ namespace xna {
DepthStencilState(sptr<GraphicsDevice> 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);

View File

@ -10,8 +10,8 @@ namespace xna {
RasterizerState();
RasterizerState(sptr<GraphicsDevice> 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;

View File

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

View File

@ -10,8 +10,8 @@ namespace xna {
SamplerState();
SamplerState(sptr<GraphicsDevice> 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);

View File

@ -10,7 +10,7 @@ namespace xna {
Shader();
Shader(sptr<GraphicsDevice> 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<GraphicsDevice> 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<GraphicsDevice> const& device);
~PixelShader() override;
bool Initialize(DataBuffer& buffer, xna_error_nullarg);
bool Initialize(DataBuffer& buffer);
public:
struct PlatformImplementation;

View File

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

View File

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

View File

@ -1011,34 +1011,30 @@ namespace xna {
};
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()) {
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 <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()) {
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);

View File

@ -1,5 +1,4 @@
#define NOMINMAX
#include "xnaerror.hpp"
#include "types.hpp"
#include "helpers.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_subdirectory ("01_blank")
add_subdirectory ("01_blank")
add_subdirectory ("02_PlatfformerStarterKit")