diff --git a/framework/graphics/blendstate.hpp b/framework/graphics/blendstate.hpp index 39853e8..f648b6b 100644 --- a/framework/graphics/blendstate.hpp +++ b/framework/graphics/blendstate.hpp @@ -6,9 +6,24 @@ #include "../enums.hpp" namespace xna { + struct BlendRenderTarget { + bool Enabled{ true }; + Blend Source{ Blend::SourceAlpha }; + Blend Destination{ Blend::InverseSourceAlpha }; + BlendOperation Operation{ BlendOperation::Add }; + Blend SourceAlpha{ Blend::One }; + Blend DestinationAlpha{ Blend::Zero }; + BlendOperation OperationAlpha{ BlendOperation::Add }; + ColorWriteChannels WriteMask{ ColorWriteChannels::All }; + + constexpr BlendRenderTarget() = default; + }; + + using PBlendRenderTarget = sptr; + class IBlendState { public: - virtual ~IBlendState(){} + virtual ~IBlendState() {} static PBlendState Opaque(); static PBlendState AlphaBlend(); @@ -18,15 +33,9 @@ namespace xna { virtual bool Apply(GraphicsDevice* device) = 0; public: - bool _alphaToCoverage{ false }; - bool _enabled{ true }; - Blend _source{ Blend::SourceAlpha }; - Blend _destination{ Blend::InverseSourceAlpha }; - BlendOperation _operation{ BlendOperation::Add }; - Blend _sourceAlpha{ Blend::One }; - Blend _destinationAlpha{ Blend::Zero }; - BlendOperation _operationAlpha{ BlendOperation::Add }; - ColorWriteChannels _writeMask{ ColorWriteChannels::All }; + bool AlphaToCoverage{ false }; + bool IndependentBlendEnable{ false }; + PBlendRenderTarget RenderTargets[8]; }; } diff --git a/framework/graphics/displaymode.hpp b/framework/graphics/displaymode.hpp index 37033e8..e1c4142 100644 --- a/framework/graphics/displaymode.hpp +++ b/framework/graphics/displaymode.hpp @@ -36,22 +36,24 @@ namespace xna { Int _width{ 0 }; Int _height{ 0 }; SurfaceFormat _format{ SurfaceFormat::Color }; - }; + }; class DisplayModeCollection { public: constexpr DisplayModeCollection() = default; + DisplayModeCollection(size_t count) : _displayModes(count){} + DisplayModeCollection(std::vector const& displayModes) : _displayModes(displayModes) {} - std::vector At(SurfaceFormat format) { + std::vector At(SurfaceFormat format) const { std::vector modes; At(format, modes); return modes; - } + } - void At(SurfaceFormat format, std::vector& modes) { + void At(SurfaceFormat format, std::vector& modes) const { size_t counter = 0; for (size_t i = 0; i < _displayModes.size(); ++i) { @@ -68,11 +70,23 @@ namespace xna { modes.resize(counter); } - std::vector operator[](SurfaceFormat format) { + size_t SurfaceCount(SurfaceFormat format) const { + size_t counter = 0; + + for (size_t i = 0; i < _displayModes.size(); ++i) { + if (_displayModes[i].Format() == format) { + ++counter; + } + } + + return counter; + } + + std::vector operator[](SurfaceFormat format) const { return At(format); } - private: + public: std::vector _displayModes; }; } diff --git a/framework/platform/adapter-dx.cpp b/framework/platform/adapter-dx.cpp index 5383df0..0a8c09d 100644 --- a/framework/platform/adapter-dx.cpp +++ b/framework/platform/adapter-dx.cpp @@ -75,7 +75,7 @@ namespace xna { IDXGIOutput* pOutput = nullptr; UINT numModes = 0; UINT totalModes = 0; - std::vector buffer(250); + std::vector buffer(500); if (_adapter->EnumOutputs(0, &pOutput) != DXGI_ERROR_NOT_FOUND) { for (size_t f = 0; f < SURFACE_FORMAT_COUNT; ++f) { @@ -95,33 +95,31 @@ namespace xna { totalModes += numModes; } - pOutput->Release(); + pOutput->Release(); + + auto collection = New(totalModes); - buffer.resize(totalModes); - std::vector dmodes; - - for (size_t i = 0; i < buffer.size(); ++i) { + for (size_t i = 0; i < totalModes; ++i) { const auto& modedesc = buffer[i]; const auto surface = SurfaceFormatMapper::ParseToSurface(modedesc.Format); - dmodes[0] = DisplayMode(modedesc.Width, modedesc.Height, surface); + collection->_displayModes[i] = DisplayMode(modedesc.Width, modedesc.Height, surface); } - - dmodes.resize(buffer.size()); - return New(dmodes); + + return collection; } return New(); } std::vector IGraphicsAdapter::getAllAdapters() { - IDXGIFactory1* pFactory = nullptr; - std::vector adapters; + IDXGIFactory1* pFactory = nullptr; if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) { - return adapters; + return std::vector(); } + std::vector adapters(2); IDXGIAdapter1* pAdapter = nullptr; UINT count = 0; @@ -131,10 +129,13 @@ namespace xna { adp->_index = count; adp->_adapter = pAdapter; - adapters.push_back(adp); + if (adapters.size() == count) + adapters.push_back(adp); + else + adapters[count] = adp; } - if (!adapters.empty()) + if (!adapters.empty() && adapters.size() != count) adapters.resize(count); return adapters; diff --git a/framework/platform/blendstate-dx.cpp b/framework/platform/blendstate-dx.cpp index c2beabe..3dd79ba 100644 --- a/framework/platform/blendstate-dx.cpp +++ b/framework/platform/blendstate-dx.cpp @@ -9,16 +9,16 @@ namespace xna { bool BlendState::Apply(GraphicsDevice* device) { D3D11_BLEND_DESC blendDesc{}; - blendDesc.AlphaToCoverageEnable = _alphaToCoverage; - blendDesc.IndependentBlendEnable = false; - blendDesc.RenderTarget[0].BlendEnable = _enabled; - blendDesc.RenderTarget[0].SrcBlend = BlendMapper::ConvertBlend(_source); - blendDesc.RenderTarget[0].DestBlend = BlendMapper::ConvertBlend(_destination); - blendDesc.RenderTarget[0].BlendOp = BlendMapper::ConvertOperation(_operation); - blendDesc.RenderTarget[0].SrcBlendAlpha = BlendMapper::ConvertBlend(_sourceAlpha); - blendDesc.RenderTarget[0].DestBlendAlpha = BlendMapper::ConvertBlend(_destinationAlpha); - blendDesc.RenderTarget[0].BlendOpAlpha = BlendMapper::ConvertOperation(_operationAlpha); - blendDesc.RenderTarget[0].RenderTargetWriteMask = BlendMapper::ConvertColorWrite(_writeMask); + blendDesc.AlphaToCoverageEnable = AlphaToCoverage; + blendDesc.IndependentBlendEnable = IndependentBlendEnable; + blendDesc.RenderTarget[0].BlendEnable = RenderTargets[0]->Enabled; + blendDesc.RenderTarget[0].SrcBlend = BlendMapper::ConvertBlend(RenderTargets[0]->Source); + blendDesc.RenderTarget[0].DestBlend = BlendMapper::ConvertBlend(RenderTargets[0]->Destination); + blendDesc.RenderTarget[0].BlendOp = BlendMapper::ConvertOperation(RenderTargets[0]->Operation); + blendDesc.RenderTarget[0].SrcBlendAlpha = BlendMapper::ConvertBlend(RenderTargets[0]->SourceAlpha); + blendDesc.RenderTarget[0].DestBlendAlpha = BlendMapper::ConvertBlend(RenderTargets[0]->DestinationAlpha); + blendDesc.RenderTarget[0].BlendOpAlpha = BlendMapper::ConvertOperation(RenderTargets[0]->OperationAlpha); + blendDesc.RenderTarget[0].RenderTargetWriteMask = BlendMapper::ConvertColorWrite(RenderTargets[0]->WriteMask); if (_device == nullptr || _device != device) _device = device; @@ -33,40 +33,44 @@ namespace xna { PBlendState IBlendState::Opaque() { auto blendState = New(nullptr); - blendState->_source = Blend::SourceAlpha; - blendState->_sourceAlpha = Blend::SourceAlpha; - blendState->_destination = Blend::Zero; - blendState->_destinationAlpha = Blend::Zero; + blendState->RenderTargets[0] = New(); + blendState->RenderTargets[0]->Source = Blend::SourceAlpha; + blendState->RenderTargets[0]->SourceAlpha = Blend::SourceAlpha; + blendState->RenderTargets[0]->Destination = Blend::Zero; + blendState->RenderTargets[0]->DestinationAlpha = Blend::Zero; return blendState; } PBlendState IBlendState::AlphaBlend() { auto blendState = New(nullptr); - blendState->_source = Blend::One; - blendState->_sourceAlpha = Blend::One; - blendState->_destination = Blend::InverseSourceAlpha; - blendState->_destinationAlpha = Blend::InverseSourceAlpha; + blendState->RenderTargets[0] = New(); + blendState->RenderTargets[0]->Source = Blend::One; + blendState->RenderTargets[0]->SourceAlpha = Blend::One; + blendState->RenderTargets[0]->Destination = Blend::InverseSourceAlpha; + blendState->RenderTargets[0]->DestinationAlpha = Blend::InverseSourceAlpha; return blendState; } PBlendState IBlendState::Additive() { auto blendState = New(nullptr); - blendState->_source = Blend::SourceAlpha; - blendState->_sourceAlpha = Blend::SourceAlpha; - blendState->_destination = Blend::One; - blendState->_destinationAlpha = Blend::One; + blendState->RenderTargets[0] = New(); + blendState->RenderTargets[0]->Source = Blend::SourceAlpha; + blendState->RenderTargets[0]->SourceAlpha = Blend::SourceAlpha; + blendState->RenderTargets[0]->Destination = Blend::One; + blendState->RenderTargets[0]->DestinationAlpha = Blend::One; return blendState; } PBlendState IBlendState::NonPremultiplied() { auto blendState = New(nullptr); - blendState->_source = Blend::SourceAlpha; - blendState->_sourceAlpha = Blend::SourceAlpha; - blendState->_destination = Blend::InverseSourceAlpha; - blendState->_destinationAlpha = Blend::InverseSourceAlpha; + blendState->RenderTargets[0] = New(); + blendState->RenderTargets[0]->Source = Blend::SourceAlpha; + blendState->RenderTargets[0]->SourceAlpha = Blend::SourceAlpha; + blendState->RenderTargets[0]->Destination = Blend::InverseSourceAlpha; + blendState->RenderTargets[0]->DestinationAlpha = Blend::InverseSourceAlpha; return blendState; } diff --git a/framework/platform/blendstate-dx.hpp b/framework/platform/blendstate-dx.hpp index 83bbb0b..6328dac 100644 --- a/framework/platform/blendstate-dx.hpp +++ b/framework/platform/blendstate-dx.hpp @@ -8,7 +8,7 @@ namespace xna { class BlendState : public IBlendState { public: - BlendState(GraphicsDevice* device); + BlendState(GraphicsDevice* device); virtual ~BlendState() override { if (_blendState) { diff --git a/framework/platform/device-dx.cpp b/framework/platform/device-dx.cpp index eb6cbb7..4cc714e 100644 --- a/framework/platform/device-dx.cpp +++ b/framework/platform/device-dx.cpp @@ -8,7 +8,8 @@ namespace xna { GraphicsDevice::GraphicsDevice() { _blendState = BlendState::NonPremultiplied(); - _adapter = GraphicsAdapter::DefaultAdapter(); + _adapter = GraphicsAdapter::DefaultAdapter(); + auto a = _adapter->DeviceId(); } bool GraphicsDevice::Initialize(GameWindow& gameWindow) {