diff --git a/CMakeLists.txt b/CMakeLists.txt index e7a3d84..3757379 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ project ("xna") # Include sub-projects. include_directories(${PROJECT_INCLUDES_DIR}) add_subdirectory ("framework") -add_subdirectory ("samples") + +#add_subdirectory ("samples") diff --git a/framework/platform-dx/depthstencilstate.cpp b/framework/platform-dx/depthstencilstate.cpp index 2aa4e6b..0ee93db 100644 --- a/framework/platform-dx/depthstencilstate.cpp +++ b/framework/platform-dx/depthstencilstate.cpp @@ -18,8 +18,8 @@ namespace xna { _description.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; _description.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; - _description.StencilReadMask = IntMaxValue; - _description.StencilWriteMask = IntMaxValue; + _description.StencilReadMask = static_cast(IntMaxValue); + _description.StencilWriteMask = static_cast(IntMaxValue); _description.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; return _description; diff --git a/framework/platform-dx/sprite.cpp b/framework/platform-dx/sprite.cpp index 5bae260..26a2461 100644 --- a/framework/platform-dx/sprite.cpp +++ b/framework/platform-dx/sprite.cpp @@ -150,27 +150,38 @@ namespace xna { t.M21, t.M22, t.M23, t.M24, t.M31, t.M32, t.M33, t.M34, t.M41, t.M42, t.M43, t.M44); + + std::function effectFunc = nullptr; - if (effect && !impl->dxInputLayout) { - void const* shaderByteCode; - size_t byteCodeLength; + //if Effect is not null set effectBuffer and inputLayout + if (effect && effect->impl) { + bool effectBufferChanged = false; - effect->impl->dxEffect->GetVertexShaderBytecode(&shaderByteCode, &byteCodeLength); + if (!impl->effectBuffer || impl->effectBuffer != effect->impl->dxEffect) { + impl->effectBuffer = effect->impl->dxEffect; + effectBufferChanged = true; + } - m_device->impl->_device->CreateInputLayout( - DirectX::VertexPositionColorTexture::InputElements, - DirectX::VertexPositionColorTexture::InputElementCount, - shaderByteCode, byteCodeLength, - impl->dxInputLayout.GetAddressOf()); - } + if (effectBufferChanged) { + void const* shaderByteCode; + size_t byteCodeLength; - auto& context = m_device->impl->_context; + effect->impl->dxEffect->GetVertexShaderBytecode(&shaderByteCode, &byteCodeLength); - std::function funcEffect = [=] { - effect->impl->dxEffect->Apply(context.Get()); - context->IASetInputLayout(impl->dxInputLayout.Get()); - }; - std::function funcVoid = [=] {}; + m_device->impl->_device->CreateInputLayout( + DirectX::VertexPositionColorTexture::InputElements, + DirectX::VertexPositionColorTexture::InputElementCount, + shaderByteCode, byteCodeLength, + impl->dxInputLayout.GetAddressOf()); + } + + auto& context = m_device->impl->_context; + + effectFunc = [=] { + impl->effectBuffer->Apply(context.Get()); + context->IASetInputLayout(impl->dxInputLayout.Get()); + }; + } impl->_dxspriteBatch->Begin( sort, @@ -178,7 +189,7 @@ namespace xna { samplerState ? samplerState->impl->_samplerState.Get() : nullptr, depthStencil ? depthStencil->impl->dxDepthStencil.Get() : nullptr, rasterizerState ? rasterizerState->impl->dxRasterizerState.Get() : nullptr, - effect ? funcEffect : funcVoid, + effectFunc, matrix ); } diff --git a/inc/xna/xna-dx.hpp b/inc/xna/xna-dx.hpp index 75944f6..a3bf2f3 100644 --- a/inc/xna/xna-dx.hpp +++ b/inc/xna/xna-dx.hpp @@ -1,5 +1,7 @@ -#ifndef XNA_PLATFORMDX_DX_HPP -#define XNA_PLATFORMDX_DX_HPP +#ifndef XNA_XNA_DX_HPP +#define XNA_XNA_DX_HPP + +#define NOMINMAX //---------------- DX INCLUDES ----------------// @@ -12,10 +14,12 @@ #include "d3d11.h" #include #include -//HSLS AND EFFECTS -#include +#include +#include #include -#include "effects11/d3dx11effect.h" +#include +#include +#include //DirectXTK #include #include @@ -39,7 +43,6 @@ #include #include //Windows -#define NOMINMAX #include #include #include @@ -62,7 +65,7 @@ namespace xna { struct DxHelpers { static constexpr DirectX::XMVECTOR VectorToDx(Vector2 const& value) { - DirectX::XMVECTOR v; + DirectX::XMVECTOR v{}; v.m128_f32[0] = value.X; v.m128_f32[1] = value.Y; @@ -72,7 +75,7 @@ namespace xna { static constexpr DirectX::XMVECTOR VectorToDx(Vector3 const& value) { - DirectX::XMVECTOR v; + DirectX::XMVECTOR v{}; v.m128_f32[0] = value.X; v.m128_f32[1] = value.Y; @@ -82,7 +85,7 @@ namespace xna { } static constexpr DirectX::XMFLOAT3 Vector3ToDx(Vector3 const& value) { - DirectX::XMFLOAT3 v; + DirectX::XMFLOAT3 v{}; v.x = value.X; v.y = value.Y; @@ -92,7 +95,7 @@ namespace xna { } static constexpr DirectX::XMVECTOR VectorToDx(Vector4 const& value) { - DirectX::XMVECTOR v; + DirectX::XMVECTOR v{}; v.m128_f32[0] = value.X; v.m128_f32[1] = value.Y; @@ -554,7 +557,7 @@ namespace xna { uint64_t m_targetElapsedTicks; }; - //---------------- IMPL ----------------// + //---------------- IMPLEMENTATIONS ----------------// struct SpriteFont::PlatformImplementation { uptr _dxSpriteFont{ nullptr }; @@ -563,6 +566,7 @@ namespace xna { struct SpriteBatch::PlatformImplementation { sptr _dxspriteBatch = nullptr; comptr dxInputLayout = nullptr; + sptr effectBuffer = nullptr; }; struct GraphicsAdapter::PlatformImplementation { @@ -683,7 +687,7 @@ namespace xna { DXGI_SWAP_CHAIN_DESC1 dxDescription{}; DXGI_SWAP_CHAIN_FULLSCREEN_DESC dxFullScreenDescription{}; - bool GetBackBuffer(comptr& texture2D) { + bool GetBackBuffer(comptr& texture2D) const { if (!dxSwapChain) return false; @@ -769,7 +773,7 @@ namespace xna { ShowCursor(visible); } - inline void Close() { + inline void Close() const { PostMessage(_windowHandle, WM_DESTROY, 0, 0); } diff --git a/samples/02_PlatfformerStarterKit/headers.hpp b/samples/02_PlatfformerStarterKit/headers.hpp index 951642e..ca5e858 100644 --- a/samples/02_PlatfformerStarterKit/headers.hpp +++ b/samples/02_PlatfformerStarterKit/headers.hpp @@ -1,2 +1 @@ -#include "xna/xna.hpp" #include "xna/xna-dx.hpp" \ No newline at end of file