diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index f337f0c..9a9524c 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -41,7 +41,7 @@ add_library (Xn65 STATIC "platform-dx/displaymode.cpp" "platform-dx/init.cpp" "platform-dx/buffer.cpp" -"platform-dx/audioengine.cpp" "graphics/gresource.cpp" "platform-dx/effect.cpp") +"platform-dx/audioengine.cpp" "graphics/gresource.cpp" "platform-dx/effect.cpp" "platform-dx/impl.cpp") if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET Xn65 PROPERTY CXX_STANDARD 20) diff --git a/framework/platform-dx/device.cpp b/framework/platform-dx/device.cpp index a0ac169..7d2836e 100644 --- a/framework/platform-dx/device.cpp +++ b/framework/platform-dx/device.cpp @@ -57,6 +57,22 @@ namespace xna { } } + void initAndApplyState(GraphicsDevice::PlatformImplementation& impl, PGraphicsDevice const& device) { + impl._blendState->Bind(device); + impl._blendState->Initialize(); + impl._blendState->Apply(); + + impl._rasterizerState->Bind(device); + impl._rasterizerState->Initialize(); + impl._rasterizerState->Apply(); + + impl._depthStencilState->Bind(device); + impl._depthStencilState->Initialize(); + impl._depthStencilState->Apply(); + + impl._samplerStates->Apply(*device); + } + GraphicsDevice::GraphicsDevice() { impl = unew(); impl->_adapter = GraphicsAdapter::DefaultAdapter(); @@ -131,7 +147,7 @@ namespace xna { impl->_context->RSSetViewports(1, &view); - impl->InitializeAndApplyStates(_this); + initAndApplyState(*impl, _this); return true; } @@ -143,13 +159,7 @@ namespace xna { impl->_context->OMSetRenderTargets(1, &impl->_renderTarget2D->render_impl->_renderTargetView, nullptr); return result; - } - - void GraphicsDevice::Clear() { - if (!impl) return; - - impl->_context->ClearRenderTargetView(impl->_renderTarget2D->render_impl->_renderTargetView, impl->_backgroundColor); - } + } void GraphicsDevice::Clear(Color const& color) { if (!impl) return; @@ -160,12 +170,37 @@ namespace xna { impl->_backgroundColor[1] = v4.Y; impl->_backgroundColor[2] = v4.Z; impl->_backgroundColor[3] = v4.W; - + impl->_context->ClearRenderTargetView( impl->_renderTarget2D->render_impl->_renderTargetView, impl->_backgroundColor); } + void GraphicsDevice::Clear(ClearOptions options, Color const& color, float depth, Int stencil) { + if (!impl) return; + + switch (options) + { + case xna::ClearOptions::DepthBuffer: + Exception::Throw(ExMessage::NotImplemented); + break; + case xna::ClearOptions::Stencil: + Exception::Throw(ExMessage::NotImplemented); + break; + case xna::ClearOptions::Target: + Clear(color); + break; + default: + return; + } + } + + void GraphicsDevice::Clear(ClearOptions options, Vector4 const& color, float depth, Int stencil) { + if (!impl) return; + + + } + sptr GraphicsDevice::Adapter() const { if (!impl) return nullptr; diff --git a/framework/platform-dx/impl.cpp b/framework/platform-dx/impl.cpp new file mode 100644 index 0000000..e75b09b --- /dev/null +++ b/framework/platform-dx/impl.cpp @@ -0,0 +1,5 @@ +#include "xna/platform-dx/dx.hpp" + +namespace xna { + +} \ No newline at end of file diff --git a/inc/xna/enums.hpp b/inc/xna/enums.hpp index d55fcf5..3bd7aaf 100644 --- a/inc/xna/enums.hpp +++ b/inc/xna/enums.hpp @@ -114,6 +114,12 @@ namespace xna { Pressed, }; + enum class ClearOptions { + DepthBuffer, + Stencil, + Target, + }; + enum class ColorWriteChannels { Red, Green, diff --git a/inc/xna/exception.hpp b/inc/xna/exception.hpp index d981002..36144b2 100644 --- a/inc/xna/exception.hpp +++ b/inc/xna/exception.hpp @@ -16,6 +16,7 @@ namespace xna { inline static const std::string UnintializedComponent = "Component is not initialized"; inline static const std::string MakeWindowAssociation = "Failed to create association with window"; inline static const std::string BuildObject = "Unable to build object"; + inline static const std::string NotImplemented = "Not Implemented"; }; //Structure for throwing exceptions with a message and information from the source file diff --git a/inc/xna/graphics/device.hpp b/inc/xna/graphics/device.hpp index 2c7e63b..1d78173 100644 --- a/inc/xna/graphics/device.hpp +++ b/inc/xna/graphics/device.hpp @@ -32,9 +32,10 @@ namespace xna { Int MultiSampleMask() const; //Gets or sets a bitmask controlling modification of the samples in a multisample render target. The default value is -1 (0xffffffff). void MultiSampleMask(Int value); - - void Clear(); + void Clear(Color const& color); + void Clear(ClearOptions options, Color const& color, float depth, Int stencil); + void Clear(ClearOptions options, Vector4 const& color, float depth, Int stencil); bool Initialize(); bool Present(); diff --git a/inc/xna/graphics/samplerstate.hpp b/inc/xna/graphics/samplerstate.hpp index 51c6a1f..2f07d1e 100644 --- a/inc/xna/graphics/samplerstate.hpp +++ b/inc/xna/graphics/samplerstate.hpp @@ -91,6 +91,10 @@ namespace xna { return samplers[index]; } + constexpr size_t Count() const { + return samplers.size(); + } + void Apply(GraphicsDevice const& device); public: diff --git a/inc/xna/platform-dx/dx.hpp b/inc/xna/platform-dx/dx.hpp index fba5fad..b741418 100644 --- a/inc/xna/platform-dx/dx.hpp +++ b/inc/xna/platform-dx/dx.hpp @@ -951,24 +951,7 @@ namespace xna { _factory->Release(); _factory = nullptr; } - } - - private: - void InitializeAndApplyStates(PGraphicsDevice const& device) { - _blendState->Bind(device); - _blendState->Initialize(); - _blendState->Apply(); - - _rasterizerState->Bind(device); - _rasterizerState->Initialize(); - _rasterizerState->Apply(); - - _depthStencilState->Bind(device); - _depthStencilState->Initialize(); - _depthStencilState->Apply(); - - _samplerStates->Apply(*device); - } + } public: ID3D11Device* _device = nullptr;