diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index 438f181..a0f3d55 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -20,7 +20,7 @@ add_executable (xna WIN32 "platform/shader-dx.cpp" "platform/rasterizerstate-dx.cpp" "platform/vertexbuffer-dx.cpp" -"platform/indexbuffer-dx.cpp" + "platform/samplerstate-dx.cpp" diff --git a/framework/platform/buffer.cpp b/framework/platform/buffer.cpp index 4622197..7366236 100644 --- a/framework/platform/buffer.cpp +++ b/framework/platform/buffer.cpp @@ -6,7 +6,7 @@ namespace xna { ConstantBuffer::ConstantBuffer() : GraphicsResource(nullptr){ - impl = uNew(); + impl = uNew(); } ConstantBuffer::ConstantBuffer(sptr const& device) : GraphicsResource(device){ @@ -67,4 +67,27 @@ namespace xna { return true; } + + IndexBuffer::IndexBuffer() : GraphicsResource(nullptr) { + impl = uNew(); + } + + IndexBuffer::IndexBuffer(sptr const& device) : GraphicsResource(device) { + impl = uNew(); + } + + IndexBuffer::~IndexBuffer() { + impl = nullptr; + } + + bool IndexBuffer::Apply(xna_error_ptr_arg) { + if (!m_device || !m_device->_context || !impl || !impl->dxBuffer) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return false; + } + + m_device->_context->IASetIndexBuffer(impl->dxBuffer, DXGI_FORMAT_R16_UINT, 0); + + return true; + } } \ No newline at end of file diff --git a/framework/platform/game-dx.cpp b/framework/platform/game-dx.cpp index 96567c1..e85273d 100644 --- a/framework/platform/game-dx.cpp +++ b/framework/platform/game-dx.cpp @@ -41,6 +41,10 @@ namespace xna { } void Game::Initialize() { + Keyboard::Initialize(); + Mouse::Initialize(); + GamePad::Initialize(); + #if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/) Microsoft::WRL::Wrappers::RoInitializeWrapper initialize(RO_INIT_MULTITHREADED); if (FAILED(initialize)) @@ -53,10 +57,7 @@ namespace xna { { MessageBox(nullptr, "Ocorreu um erro ao chamar CoInitializeEx.", "XN65", MB_OK); } -#endif - Keyboard::Initialize(); - Mouse::Initialize(); - GamePad::Initialize(); +#endif _audioEngine = New(); diff --git a/framework/platform/indexbuffer-dx.cpp b/framework/platform/indexbuffer-dx.cpp deleted file mode 100644 index 59d6db1..0000000 --- a/framework/platform/indexbuffer-dx.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "platform-dx/indexbuffer-dx.hpp" -#include "platform-dx/device-dx.hpp" - -namespace xna { -} \ No newline at end of file diff --git a/inc/graphics/buffer.hpp b/inc/graphics/buffer.hpp index 8e11de9..2a36ecf 100644 --- a/inc/graphics/buffer.hpp +++ b/inc/graphics/buffer.hpp @@ -24,6 +24,21 @@ namespace xna { ~DataBuffer(); bool Initialize(xna_error_nullarg); + public: + struct PlatformImplementation; + uptr impl = nullptr; + }; + + class IndexBuffer : public GraphicsResource { + public: + IndexBuffer(); + IndexBuffer(sptr const&); + ~IndexBuffer(); + + template + bool Initialize(std::vector const& data, xna_error_nullarg); + bool Apply(xna_error_nullarg); + public: struct PlatformImplementation; uptr impl = nullptr; diff --git a/inc/graphics/indexbuffer.hpp b/inc/graphics/indexbuffer.hpp deleted file mode 100644 index e5b7995..0000000 --- a/inc/graphics/indexbuffer.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef XNA_GRAPHICS_INDEXBUFFER_HPP -#define XNA_GRAPHICS_INDEXBUFFER_HPP - -#include "../default.hpp" - -namespace xna { - class IIndexBuffer { - public: - virtual ~IIndexBuffer() {} - virtual bool Initialize(xna_error_nullarg) = 0; - }; -} - -#endif \ No newline at end of file diff --git a/inc/input/gamepad.hpp b/inc/input/gamepad.hpp index 1d3364f..043bc16 100644 --- a/inc/input/gamepad.hpp +++ b/inc/input/gamepad.hpp @@ -157,7 +157,7 @@ namespace xna { }; struct GamePadState { - GamePadState() = default; + constexpr GamePadState() = default; constexpr bool IsButtonDown(xna::Buttons button) const { switch (button) diff --git a/inc/platform-dx/implementations.hpp b/inc/platform-dx/implementations.hpp index d47b409..696d07b 100644 --- a/inc/platform-dx/implementations.hpp +++ b/inc/platform-dx/implementations.hpp @@ -150,4 +150,32 @@ namespace xna { inline static uptr _dxGamePad = nullptr; }; + + struct IndexBuffer::PlatformImplementation { + ~PlatformImplementation() { + if (dxBuffer) { + dxBuffer->Release(); + dxBuffer = nullptr; + } + } + + ID3D11Buffer* dxBuffer = nullptr; + }; + + template + inline bool IndexBuffer::Initialize(std::vector const& data, xna_error_ptr_arg) { + if (!impl || !m_device || !m_device->_device || data.empty()) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return false; + } + + const auto hr = DirectX::CreateStaticBuffer(m_device->_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; + } + + return true; + } } \ No newline at end of file diff --git a/inc/platform-dx/indexbuffer-dx.hpp b/inc/platform-dx/indexbuffer-dx.hpp deleted file mode 100644 index eb4ebba..0000000 --- a/inc/platform-dx/indexbuffer-dx.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef XNA_PLATFORM_INDEXBUFFER_DX_HPP -#define XNA_PLATFORM_INDEXBUFFER_DX_HPP - -#include "../graphics/gresource.hpp" -#include "../graphics/indexbuffer.hpp" -#include "device-dx.hpp" -#include "dxheaders.hpp" -#include -#include - -namespace xna { - template - class IndexBuffer : public IIndexBuffer, public GraphicsResource { - public: - constexpr IndexBuffer(GraphicsDevice* device) : GraphicsResource(device) {} - - constexpr IndexBuffer(GraphicsDevice* device, std::vector const& indices) : data(indices), GraphicsResource(device) {} - - virtual ~IndexBuffer() override { - if (dxBuffer) { - dxBuffer->Release(); - dxBuffer = nullptr; - } - } - - virtual bool Initialize(xna_error_ptr_arg) override { - if (!m_device || !m_device->_device || data.empty()) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; - } - - const auto hr = DirectX::CreateStaticBuffer(m_device->_device, data.data(), data.size(), sizeof(T), D3D11_BIND_INDEX_BUFFER, &dxBuffer); - - if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return false; - } - - return true; - } - - virtual bool Apply(xna_error_ptr_arg) override { - if (!m_device || !m_device->_context || !dxBuffer) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; - } - - m_device->_context->IASetIndexBuffer(dxBuffer, DXGI_FORMAT_R16_UINT, 0); - - return true; - } - - public: - ID3D11Buffer* dxBuffer = nullptr; - std::vector data; - }; -} - -#endif \ No newline at end of file diff --git a/inc/platform-dx/xna-dx.hpp b/inc/platform-dx/xna-dx.hpp index 968884e..76846e5 100644 --- a/inc/platform-dx/xna-dx.hpp +++ b/inc/platform-dx/xna-dx.hpp @@ -6,7 +6,6 @@ #include "game-dx.hpp" #include "gdeviceinfo-dx.hpp" #include "gdevicemanager-dx.hpp" -#include "indexbuffer-dx.hpp" #include "init-dx.hpp" #include "keyboard-dx.hpp" #include "mouse-dx.hpp" diff --git a/inc/xna.hpp b/inc/xna.hpp index e4f4730..c599a6a 100644 --- a/inc/xna.hpp +++ b/inc/xna.hpp @@ -37,7 +37,6 @@ #include "graphics/device.hpp" #include "graphics/displaymode.hpp" #include "graphics/gresource.hpp" -#include "graphics/indexbuffer.hpp" #include "graphics/presentparams.hpp" #include "graphics/rasterizerstate.hpp" #include "graphics/rendertarget.hpp"