mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Adiciona ImplementationBase em BlendState
This commit is contained in:
parent
234a957484
commit
077caf7a05
@ -4,7 +4,7 @@
|
||||
#include "headers.hpp"
|
||||
|
||||
namespace xna {
|
||||
struct GraphicsAdapter::ImplementationBase::PlatformImplementation {
|
||||
struct GraphicsAdapterImpl {
|
||||
comptr<IDXGIAdapter1> Adapter() const {
|
||||
return adapter;
|
||||
}
|
||||
@ -20,16 +20,6 @@ namespace xna {
|
||||
comptr<IDXGIFactory1> factory;
|
||||
};
|
||||
|
||||
struct SpriteFont::PlatformImplementation {
|
||||
uptr<DirectX::SpriteFont> dxSpriteFont{ nullptr };
|
||||
};
|
||||
|
||||
struct SpriteBatch::PlatformImplementation {
|
||||
sptr<DirectX::SpriteBatch> dxSpriteBatch = nullptr;
|
||||
comptr<ID3D11InputLayout> dxInputLayout = nullptr;
|
||||
sptr<DirectX::DX11::IEffect> dxEffectBuffer = nullptr;
|
||||
};
|
||||
|
||||
struct BlendRenderTarget {
|
||||
bool Enabled{ true };
|
||||
Blend Source{ Blend::SourceAlpha };
|
||||
@ -43,13 +33,25 @@ namespace xna {
|
||||
constexpr BlendRenderTarget() = default;
|
||||
};
|
||||
|
||||
struct BlendState::PlatformImplementation {
|
||||
comptr<ID3D11BlendState> dxBlendState = nullptr;
|
||||
D3D11_BLEND_DESC dxDescription{};
|
||||
float blendFactor[4]{ 1.0F, 1.0F, 1.0F, 1.0F };
|
||||
UINT sampleMask{ 0xffffffff };
|
||||
struct BlendStateImplementation {
|
||||
friend class BlendState;
|
||||
|
||||
D3D11_BLEND_DESC Description{};
|
||||
float BlendFactor[4]{ 1.0F, 1.0F, 1.0F, 1.0F };
|
||||
UINT SampleMask{ 0xffffffff };
|
||||
comptr<ID3D11BlendState> BlendState;
|
||||
};
|
||||
|
||||
struct SpriteFont::PlatformImplementation {
|
||||
uptr<DirectX::SpriteFont> dxSpriteFont{ nullptr };
|
||||
};
|
||||
|
||||
struct SpriteBatch::PlatformImplementation {
|
||||
sptr<DirectX::SpriteBatch> dxSpriteBatch = nullptr;
|
||||
comptr<ID3D11InputLayout> dxInputLayout = nullptr;
|
||||
sptr<DirectX::DX11::IEffect> dxEffectBuffer = nullptr;
|
||||
};
|
||||
|
||||
struct DepthStencilState::PlatformImplementation {
|
||||
comptr<ID3D11DepthStencilState> dxDepthStencil = nullptr;
|
||||
D3D11_DEPTH_STENCIL_DESC dxDescription{};
|
||||
|
@ -1,15 +1,17 @@
|
||||
#ifndef XNA_GRAPHICS_ADAPTER_HPP
|
||||
#define XNA_GRAPHICS_ADAPTER_HPP
|
||||
|
||||
#include "displaymode.hpp"
|
||||
#include "../platform.hpp"
|
||||
#include <memory>
|
||||
#include "displaymode.hpp"
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace xna {
|
||||
|
||||
struct GraphicsAdapterImpl;
|
||||
//Provides methods to retrieve and manipulate graphics adapters.
|
||||
class GraphicsAdapter : public ImplementationBase {
|
||||
class GraphicsAdapter : public ImplementationBase<GraphicsAdapterImpl> {
|
||||
public:
|
||||
//Collection of available adapters on the system.
|
||||
static void Adapters(std::vector<std::unique_ptr<GraphicsAdapter>>& adapters);
|
||||
|
@ -4,12 +4,14 @@
|
||||
#include "../common/color.hpp"
|
||||
#include "../default.hpp"
|
||||
#include "gresource.hpp"
|
||||
#include "../platform.hpp"
|
||||
|
||||
namespace xna {
|
||||
struct BlendRenderTarget;
|
||||
struct BlendStateImplementation;
|
||||
|
||||
//Contains blend state for the device.
|
||||
class BlendState : public GraphicsResource {
|
||||
class BlendState : public GraphicsResource, public ImplementationBase<BlendStateImplementation> {
|
||||
public:
|
||||
BlendState();
|
||||
BlendState(sptr<GraphicsDevice> const& device);
|
||||
@ -70,11 +72,7 @@ namespace xna {
|
||||
static uptr<BlendState> Additive();
|
||||
//A built-in state object with settings for blending with non-premultipled alpha,
|
||||
//that is blending source and destination data using alpha while assuming the color data contains no alpha information.
|
||||
static uptr<BlendState> NonPremultiplied();
|
||||
|
||||
public:
|
||||
struct PlatformImplementation;
|
||||
uptr<PlatformImplementation> impl = nullptr;
|
||||
static uptr<BlendState> NonPremultiplied();
|
||||
};
|
||||
|
||||
using PBlendState = sptr<BlendState>;
|
||||
|
@ -4,9 +4,10 @@
|
||||
#include <memory>
|
||||
|
||||
namespace xna {
|
||||
struct ImplementationBase {
|
||||
struct PlatformImplementation;
|
||||
std::unique_ptr<PlatformImplementation> Implementation;
|
||||
template <typename T> struct ImplementationBase {
|
||||
virtual ~ImplementationBase() {}
|
||||
|
||||
std::unique_ptr<T> Implementation;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ namespace xna {
|
||||
static sptr<DisplayModeCollection> getSupportedDisplayModes(comptr<IDXGIAdapter1>& dxAdapter);
|
||||
|
||||
GraphicsAdapter::GraphicsAdapter() {
|
||||
Implementation = unew<PlatformImplementation>();
|
||||
Implementation = unew<GraphicsAdapterImpl>();
|
||||
}
|
||||
|
||||
uptr<GraphicsAdapter> GraphicsAdapter::DefaultAdapter() {
|
||||
|
@ -6,73 +6,73 @@ namespace xna {
|
||||
BlendState::BlendState() : BlendState(nullptr) {}
|
||||
|
||||
BlendState::BlendState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
|
||||
impl = unew<PlatformImplementation>();
|
||||
impl->dxDescription.AlphaToCoverageEnable = false;
|
||||
impl->dxDescription.IndependentBlendEnable = false;
|
||||
impl->dxDescription.RenderTarget[0].BlendEnable = true;
|
||||
impl->dxDescription.RenderTarget[0].SrcBlend = DxHelpers::BlendToDx(Blend::One);
|
||||
impl->dxDescription.RenderTarget[0].DestBlend = DxHelpers::BlendToDx(Blend::One);
|
||||
impl->dxDescription.RenderTarget[0].BlendOp = DxHelpers::BlendOperationToDx(BlendFunction::Add);
|
||||
impl->dxDescription.RenderTarget[0].SrcBlendAlpha = DxHelpers::BlendToDx(Blend::One);
|
||||
impl->dxDescription.RenderTarget[0].DestBlendAlpha = DxHelpers::BlendToDx(Blend::One);
|
||||
impl->dxDescription.RenderTarget[0].BlendOpAlpha = DxHelpers::BlendOperationToDx(BlendFunction::Add);
|
||||
impl->dxDescription.RenderTarget[0].RenderTargetWriteMask = DxHelpers::ColorWriteChannelsToDx(ColorWriteChannels::All);
|
||||
Implementation = unew<BlendStateImplementation>();
|
||||
Implementation->Description.AlphaToCoverageEnable = false;
|
||||
Implementation->Description.IndependentBlendEnable = false;
|
||||
Implementation->Description.RenderTarget[0].BlendEnable = true;
|
||||
Implementation->Description.RenderTarget[0].SrcBlend = DxHelpers::BlendToDx(Blend::One);
|
||||
Implementation->Description.RenderTarget[0].DestBlend = DxHelpers::BlendToDx(Blend::One);
|
||||
Implementation->Description.RenderTarget[0].BlendOp = DxHelpers::BlendOperationToDx(BlendFunction::Add);
|
||||
Implementation->Description.RenderTarget[0].SrcBlendAlpha = DxHelpers::BlendToDx(Blend::One);
|
||||
Implementation->Description.RenderTarget[0].DestBlendAlpha = DxHelpers::BlendToDx(Blend::One);
|
||||
Implementation->Description.RenderTarget[0].BlendOpAlpha = DxHelpers::BlendOperationToDx(BlendFunction::Add);
|
||||
Implementation->Description.RenderTarget[0].RenderTargetWriteMask = DxHelpers::ColorWriteChannelsToDx(ColorWriteChannels::All);
|
||||
}
|
||||
|
||||
BlendFunction BlendState::AlphaBlendFunction() const {
|
||||
return DxHelpers::BlendOperationToXna(impl->dxDescription.RenderTarget[0].BlendOpAlpha);
|
||||
return DxHelpers::BlendOperationToXna(Implementation->Description.RenderTarget[0].BlendOpAlpha);
|
||||
}
|
||||
|
||||
void BlendState::AlphaBlendFunction(BlendFunction value) {
|
||||
impl->dxDescription.RenderTarget[0].BlendOpAlpha = DxHelpers::BlendOperationToDx(value);
|
||||
Implementation->Description.RenderTarget[0].BlendOpAlpha = DxHelpers::BlendOperationToDx(value);
|
||||
}
|
||||
|
||||
Blend BlendState::AlphaDestinationBlend() const {
|
||||
return DxHelpers::BlendToXna(impl->dxDescription.RenderTarget[0].DestBlendAlpha);
|
||||
return DxHelpers::BlendToXna(Implementation->Description.RenderTarget[0].DestBlendAlpha);
|
||||
}
|
||||
|
||||
void BlendState::AlphaDestinationBlend(Blend value) {
|
||||
impl->dxDescription.RenderTarget[0].DestBlendAlpha = DxHelpers::BlendToDx(value);
|
||||
Implementation->Description.RenderTarget[0].DestBlendAlpha = DxHelpers::BlendToDx(value);
|
||||
}
|
||||
|
||||
Blend BlendState::AlphaSourceBlend() const {
|
||||
return DxHelpers::BlendToXna(impl->dxDescription.RenderTarget[0].SrcBlendAlpha);
|
||||
return DxHelpers::BlendToXna(Implementation->Description.RenderTarget[0].SrcBlendAlpha);
|
||||
}
|
||||
|
||||
void BlendState::AlphaSourceBlend(Blend value) {
|
||||
impl->dxDescription.RenderTarget[0].SrcBlendAlpha = DxHelpers::BlendToDx(value);
|
||||
Implementation->Description.RenderTarget[0].SrcBlendAlpha = DxHelpers::BlendToDx(value);
|
||||
}
|
||||
|
||||
BlendFunction BlendState::ColorBlendFunction() const {
|
||||
return DxHelpers::BlendOperationToXna(impl->dxDescription.RenderTarget[0].BlendOp);
|
||||
return DxHelpers::BlendOperationToXna(Implementation->Description.RenderTarget[0].BlendOp);
|
||||
}
|
||||
|
||||
void BlendState::ColorBlendFunction(BlendFunction value) {
|
||||
impl->dxDescription.RenderTarget[0].BlendOp = DxHelpers::BlendOperationToDx(value);
|
||||
Implementation->Description.RenderTarget[0].BlendOp = DxHelpers::BlendOperationToDx(value);
|
||||
}
|
||||
|
||||
Blend BlendState::ColorDestinationBlend() const {
|
||||
return DxHelpers::BlendToXna(impl->dxDescription.RenderTarget[0].DestBlend);
|
||||
return DxHelpers::BlendToXna(Implementation->Description.RenderTarget[0].DestBlend);
|
||||
}
|
||||
|
||||
void BlendState::ColorDestinationBlend(Blend value) {
|
||||
impl->dxDescription.RenderTarget[0].DestBlend = DxHelpers::BlendToDx(value);
|
||||
Implementation->Description.RenderTarget[0].DestBlend = DxHelpers::BlendToDx(value);
|
||||
}
|
||||
|
||||
Blend BlendState::ColorSourceBlend() const {
|
||||
return DxHelpers::BlendToXna(impl->dxDescription.RenderTarget[0].SrcBlend);
|
||||
return DxHelpers::BlendToXna(Implementation->Description.RenderTarget[0].SrcBlend);
|
||||
}
|
||||
|
||||
void BlendState::ColorSourceBlend(Blend value) {
|
||||
impl->dxDescription.RenderTarget[0].SrcBlend = DxHelpers::BlendToDx(value);
|
||||
Implementation->Description.RenderTarget[0].SrcBlend = DxHelpers::BlendToDx(value);
|
||||
}
|
||||
|
||||
Color BlendState::BlendFactor() const {
|
||||
auto color = Color(
|
||||
impl->blendFactor[0],
|
||||
impl->blendFactor[1],
|
||||
impl->blendFactor[2],
|
||||
impl->blendFactor[3]
|
||||
Implementation->BlendFactor[0],
|
||||
Implementation->BlendFactor[1],
|
||||
Implementation->BlendFactor[2],
|
||||
Implementation->BlendFactor[3]
|
||||
);
|
||||
|
||||
return color;
|
||||
@ -81,18 +81,18 @@ namespace xna {
|
||||
void BlendState::BlendFactor(Color const& value) {
|
||||
auto v4 = value.ToVector4();
|
||||
|
||||
impl->blendFactor[0] = v4.X;
|
||||
impl->blendFactor[1] = v4.Y;
|
||||
impl->blendFactor[2] = v4.Z;
|
||||
impl->blendFactor[3] = v4.W;
|
||||
Implementation->BlendFactor[0] = v4.X;
|
||||
Implementation->BlendFactor[1] = v4.Y;
|
||||
Implementation->BlendFactor[2] = v4.Z;
|
||||
Implementation->BlendFactor[3] = v4.W;
|
||||
}
|
||||
|
||||
Int BlendState::MultiSampleMask() const {
|
||||
return static_cast<Int>(impl->sampleMask);
|
||||
return static_cast<Int>(Implementation->SampleMask);
|
||||
}
|
||||
|
||||
void BlendState::MultiSampleMast(Int value) {
|
||||
impl->sampleMask = static_cast<UINT>(value);
|
||||
Implementation->SampleMask = static_cast<UINT>(value);
|
||||
}
|
||||
|
||||
bool BlendState::Initialize()
|
||||
@ -101,13 +101,13 @@ namespace xna {
|
||||
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
||||
}
|
||||
|
||||
if (impl->dxBlendState) {
|
||||
impl->dxBlendState = nullptr;
|
||||
if (Implementation->BlendState) {
|
||||
Implementation->BlendState = nullptr;
|
||||
}
|
||||
|
||||
const auto hr = m_device->impl->_device->CreateBlendState(
|
||||
&impl->dxDescription,
|
||||
impl->dxBlendState.GetAddressOf());
|
||||
&Implementation->Description,
|
||||
Implementation->BlendState.GetAddressOf());
|
||||
|
||||
if (FAILED(hr)) {
|
||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||
@ -121,75 +121,75 @@ namespace xna {
|
||||
Exception::Throw(Exception::FAILED_TO_APPLY);
|
||||
}
|
||||
|
||||
if (!impl->dxBlendState) {
|
||||
if (!Implementation->BlendState) {
|
||||
Initialize();
|
||||
}
|
||||
|
||||
m_device->impl->_context->OMSetBlendState(
|
||||
impl->dxBlendState.Get(),
|
||||
impl->blendFactor,
|
||||
impl->sampleMask);
|
||||
Implementation->BlendState.Get(),
|
||||
Implementation->BlendFactor,
|
||||
Implementation->SampleMask);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BlendState::AlphaToCoverageEnable(bool value) {
|
||||
impl->dxDescription.AlphaToCoverageEnable = value;
|
||||
Implementation->Description.AlphaToCoverageEnable = value;
|
||||
}
|
||||
|
||||
void BlendState::IndependentBlendEnable(bool value) {
|
||||
impl->dxDescription.IndependentBlendEnable = value;
|
||||
Implementation->Description.IndependentBlendEnable = value;
|
||||
}
|
||||
|
||||
void BlendState::RenderTargets(std::vector<BlendRenderTarget> const& value) {
|
||||
for (size_t i = 0; i < value.size() && i < 8; ++i) {
|
||||
impl->dxDescription.RenderTarget[i].BlendEnable = value[i].Enabled;
|
||||
impl->dxDescription.RenderTarget[i].SrcBlend = DxHelpers::BlendToDx(value[i].Source);
|
||||
impl->dxDescription.RenderTarget[i].DestBlend = DxHelpers::BlendToDx(value[i].Destination);
|
||||
impl->dxDescription.RenderTarget[i].BlendOp = DxHelpers::BlendOperationToDx(value[i].Operation);
|
||||
impl->dxDescription.RenderTarget[i].SrcBlendAlpha = DxHelpers::BlendToDx(value[i].SourceAlpha);
|
||||
impl->dxDescription.RenderTarget[i].DestBlendAlpha = DxHelpers::BlendToDx(value[i].DestinationAlpha);
|
||||
impl->dxDescription.RenderTarget[i].BlendOpAlpha = DxHelpers::BlendOperationToDx(value[i].OperationAlpha);
|
||||
impl->dxDescription.RenderTarget[i].RenderTargetWriteMask = DxHelpers::ColorWriteChannelsToDx(value[i].WriteMask);
|
||||
Implementation->Description.RenderTarget[i].BlendEnable = value[i].Enabled;
|
||||
Implementation->Description.RenderTarget[i].SrcBlend = DxHelpers::BlendToDx(value[i].Source);
|
||||
Implementation->Description.RenderTarget[i].DestBlend = DxHelpers::BlendToDx(value[i].Destination);
|
||||
Implementation->Description.RenderTarget[i].BlendOp = DxHelpers::BlendOperationToDx(value[i].Operation);
|
||||
Implementation->Description.RenderTarget[i].SrcBlendAlpha = DxHelpers::BlendToDx(value[i].SourceAlpha);
|
||||
Implementation->Description.RenderTarget[i].DestBlendAlpha = DxHelpers::BlendToDx(value[i].DestinationAlpha);
|
||||
Implementation->Description.RenderTarget[i].BlendOpAlpha = DxHelpers::BlendOperationToDx(value[i].OperationAlpha);
|
||||
Implementation->Description.RenderTarget[i].RenderTargetWriteMask = DxHelpers::ColorWriteChannelsToDx(value[i].WriteMask);
|
||||
}
|
||||
}
|
||||
|
||||
uptr<BlendState> BlendState::Opaque() {
|
||||
auto blendState = unew<BlendState>();
|
||||
blendState->impl->dxDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
|
||||
blendState->impl->dxDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
|
||||
blendState->impl->dxDescription.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
|
||||
blendState->impl->dxDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
|
||||
blendState->Implementation->Description.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
|
||||
blendState->Implementation->Description.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
|
||||
blendState->Implementation->Description.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
|
||||
blendState->Implementation->Description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
|
||||
|
||||
return blendState;
|
||||
}
|
||||
|
||||
uptr<BlendState> BlendState::AlphaBlend() {
|
||||
auto blendState = unew<BlendState>();
|
||||
blendState->impl->dxDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
|
||||
blendState->impl->dxDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
|
||||
blendState->impl->dxDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
blendState->impl->dxDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
blendState->Implementation->Description.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
|
||||
blendState->Implementation->Description.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
|
||||
blendState->Implementation->Description.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
blendState->Implementation->Description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
|
||||
return blendState;
|
||||
}
|
||||
|
||||
uptr<BlendState> BlendState::Additive() {
|
||||
auto blendState = unew<BlendState>();
|
||||
blendState->impl->dxDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
||||
blendState->impl->dxDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
|
||||
blendState->impl->dxDescription.RenderTarget[0].DestBlend = D3D11_BLEND_ONE;
|
||||
blendState->impl->dxDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
|
||||
blendState->Implementation->Description.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
||||
blendState->Implementation->Description.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
|
||||
blendState->Implementation->Description.RenderTarget[0].DestBlend = D3D11_BLEND_ONE;
|
||||
blendState->Implementation->Description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
|
||||
|
||||
return blendState;
|
||||
}
|
||||
|
||||
uptr<BlendState> BlendState::NonPremultiplied() {
|
||||
auto blendState = unew<BlendState>();
|
||||
blendState->impl->dxDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
||||
blendState->impl->dxDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
|
||||
blendState->impl->dxDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
blendState->impl->dxDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
blendState->Implementation->Description.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
||||
blendState->Implementation->Description.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
|
||||
blendState->Implementation->Description.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
blendState->Implementation->Description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
|
||||
return blendState;
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ namespace xna {
|
||||
|
||||
impl->dxSpriteBatch->Begin(
|
||||
_sortMode,
|
||||
blendState ? blendState->impl->dxBlendState.Get() : nullptr,
|
||||
blendState ? blendState->Implementation->BlendState.Get() : nullptr,
|
||||
samplerState ? samplerState->impl->_samplerState.Get() : nullptr,
|
||||
depthStencil ? depthStencil->impl->dxDepthStencil.Get() : nullptr,
|
||||
rasterizerState ? rasterizerState->impl->dxRasterizerState.Get() : nullptr,
|
||||
|
Loading…
x
Reference in New Issue
Block a user