mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementações em BlendState
This commit is contained in:
parent
c3df41bdab
commit
da12db2c47
@ -67,6 +67,13 @@ namespace xna {
|
|||||||
|
|
||||||
using BlendOperation = BlendFunction;
|
using BlendOperation = BlendFunction;
|
||||||
|
|
||||||
|
enum class BufferUsage {
|
||||||
|
Static,
|
||||||
|
Dynamic,
|
||||||
|
Immutable,
|
||||||
|
Staging
|
||||||
|
};
|
||||||
|
|
||||||
enum class Buttons {
|
enum class Buttons {
|
||||||
A = 4096, // 0x00001000
|
A = 4096, // 0x00001000
|
||||||
B = 8192, // 0x00002000
|
B = 8192, // 0x00002000
|
||||||
@ -107,7 +114,7 @@ namespace xna {
|
|||||||
Blue,
|
Blue,
|
||||||
Alpha,
|
Alpha,
|
||||||
All
|
All
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class ComparisonFunction {
|
enum class ComparisonFunction {
|
||||||
Never,
|
Never,
|
||||||
|
@ -9,12 +9,12 @@ namespace xna {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_blendState) {
|
if (dxBlendState) {
|
||||||
_blendState->Release();
|
dxBlendState->Release();
|
||||||
_blendState = nullptr;
|
dxBlendState = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto hr = device._device->CreateBlendState(&_description, &_blendState);
|
const auto hr = device._device->CreateBlendState(&dxDescription, &dxBlendState);
|
||||||
|
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||||
@ -30,52 +30,52 @@ namespace xna {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_blendState) {
|
if (!dxBlendState) {
|
||||||
const auto init = Initialize(device, err);
|
const auto init = Initialize(device, err);
|
||||||
if (!init) return false;
|
if (!init) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
device._context->OMSetBlendState(_blendState, blendFactor, sampleMask);
|
device._context->OMSetBlendState(dxBlendState, blendFactor, sampleMask);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
PBlendState IBlendState::Opaque() {
|
PBlendState IBlendState::Opaque() {
|
||||||
auto blendState = New<BlendState>();
|
auto blendState = New<BlendState>();
|
||||||
blendState->_description.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
|
blendState->dxDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
|
||||||
blendState->_description.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO;
|
blendState->dxDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO;
|
||||||
blendState->_description.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
|
blendState->dxDescription.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
|
||||||
blendState->_description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
|
blendState->dxDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
|
||||||
|
|
||||||
return blendState;
|
return blendState;
|
||||||
}
|
}
|
||||||
|
|
||||||
PBlendState IBlendState::AlphaBlend() {
|
PBlendState IBlendState::AlphaBlend() {
|
||||||
auto blendState = New<BlendState>();
|
auto blendState = New<BlendState>();
|
||||||
blendState->_description.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
|
blendState->dxDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
|
||||||
blendState->_description.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
|
blendState->dxDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
|
||||||
blendState->_description.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
blendState->dxDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
||||||
blendState->_description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
blendState->dxDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
||||||
|
|
||||||
return blendState;
|
return blendState;
|
||||||
}
|
}
|
||||||
|
|
||||||
PBlendState IBlendState::Additive() {
|
PBlendState IBlendState::Additive() {
|
||||||
auto blendState = New<BlendState>();
|
auto blendState = New<BlendState>();
|
||||||
blendState->_description.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
blendState->dxDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
||||||
blendState->_description.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
|
blendState->dxDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
|
||||||
blendState->_description.RenderTarget[0].DestBlend = D3D11_BLEND_ONE;
|
blendState->dxDescription.RenderTarget[0].DestBlend = D3D11_BLEND_ONE;
|
||||||
blendState->_description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
|
blendState->dxDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
|
||||||
|
|
||||||
return blendState;
|
return blendState;
|
||||||
}
|
}
|
||||||
|
|
||||||
PBlendState IBlendState::NonPremultiplied() {
|
PBlendState IBlendState::NonPremultiplied() {
|
||||||
auto blendState = New<BlendState>();
|
auto blendState = New<BlendState>();
|
||||||
blendState->_description.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
blendState->dxDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
||||||
blendState->_description.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
|
blendState->dxDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
|
||||||
blendState->_description.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
blendState->dxDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
||||||
blendState->_description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
blendState->dxDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
||||||
|
|
||||||
return blendState;
|
return blendState;
|
||||||
}
|
}
|
||||||
|
@ -23,41 +23,41 @@ namespace xna {
|
|||||||
BlendState() = default;
|
BlendState() = default;
|
||||||
|
|
||||||
virtual ~BlendState() override {
|
virtual ~BlendState() override {
|
||||||
if (_blendState) {
|
if (dxBlendState) {
|
||||||
_blendState->Release();
|
dxBlendState->Release();
|
||||||
_blendState = nullptr;
|
dxBlendState = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) override;
|
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) override;
|
||||||
|
|
||||||
virtual constexpr void AlphaToCoverageEnable(bool value) override {
|
virtual constexpr void AlphaToCoverageEnable(bool value) override {
|
||||||
_description.AlphaToCoverageEnable = value;
|
dxDescription.AlphaToCoverageEnable = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual constexpr void IndependentBlendEnable(bool value) override {
|
virtual constexpr void IndependentBlendEnable(bool value) override {
|
||||||
_description.IndependentBlendEnable = value;
|
dxDescription.IndependentBlendEnable = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void RenderTargets(std::vector<BlendRenderTarget> const& value) override {
|
virtual void RenderTargets(std::vector<BlendRenderTarget> const& value) override {
|
||||||
for (size_t i = 0; i < value.size() && i < 8; ++i) {
|
for (size_t i = 0; i < value.size() && i < 8; ++i) {
|
||||||
_description.RenderTarget[i].BlendEnable = value[i].Enabled;
|
dxDescription.RenderTarget[i].BlendEnable = value[i].Enabled;
|
||||||
_description.RenderTarget[i].SrcBlend = ConvertBlend(value[i].Source);
|
dxDescription.RenderTarget[i].SrcBlend = ConvertBlend(value[i].Source);
|
||||||
_description.RenderTarget[i].DestBlend = ConvertBlend(value[i].Destination);
|
dxDescription.RenderTarget[i].DestBlend = ConvertBlend(value[i].Destination);
|
||||||
_description.RenderTarget[i].BlendOp = ConvertOperation(value[i].Operation);
|
dxDescription.RenderTarget[i].BlendOp = ConvertOperation(value[i].Operation);
|
||||||
_description.RenderTarget[i].SrcBlendAlpha = ConvertBlend(value[i].SourceAlpha);
|
dxDescription.RenderTarget[i].SrcBlendAlpha = ConvertBlend(value[i].SourceAlpha);
|
||||||
_description.RenderTarget[i].DestBlendAlpha = ConvertBlend(value[i].DestinationAlpha);
|
dxDescription.RenderTarget[i].DestBlendAlpha = ConvertBlend(value[i].DestinationAlpha);
|
||||||
_description.RenderTarget[i].BlendOpAlpha = ConvertOperation(value[i].OperationAlpha);
|
dxDescription.RenderTarget[i].BlendOpAlpha = ConvertOperation(value[i].OperationAlpha);
|
||||||
_description.RenderTarget[i].RenderTargetWriteMask = ConvertColorWrite(value[i].WriteMask);
|
dxDescription.RenderTarget[i].RenderTargetWriteMask = ConvertColorWrite(value[i].WriteMask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool Apply(GraphicsDevice& device, xna_error_nullarg) override;
|
virtual bool Apply(GraphicsDevice& device, xna_error_nullarg) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ID3D11BlendState* _blendState{ nullptr };
|
ID3D11BlendState* dxBlendState{ nullptr };
|
||||||
D3D11_BLEND_DESC _description{};
|
D3D11_BLEND_DESC dxDescription{};
|
||||||
float blendFactor[4] { 1.0F, 1.0F, 1.0F, 1.0F };
|
float blendFactor[4] { 1.0F, 1.0F, 1.0F, 1.0F };
|
||||||
UINT sampleMask{ 0xffffffff };
|
UINT sampleMask{ 0xffffffff };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr D3D11_BLEND ConvertBlend(Blend blend) {
|
static constexpr D3D11_BLEND ConvertBlend(Blend blend) {
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "../graphics/constbuffer.hpp"
|
#include "../graphics/constbuffer.hpp"
|
||||||
#include "../common/matrix.hpp"
|
#include "../common/matrix.hpp"
|
||||||
#include "dxheaders.hpp"
|
#include "dxheaders.hpp"
|
||||||
|
#include <BufferHelpers.h>
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
class ConstantBuffer : public IConstantBuffer {
|
class ConstantBuffer : public IConstantBuffer {
|
||||||
|
@ -40,7 +40,7 @@ namespace xna {
|
|||||||
|
|
||||||
_dxspriteBatch->Begin(
|
_dxspriteBatch->Begin(
|
||||||
sort,
|
sort,
|
||||||
blendState ? blendState->_blendState : nullptr,
|
blendState ? blendState->dxBlendState : nullptr,
|
||||||
samplerState ? samplerState->_samplerState : nullptr,
|
samplerState ? samplerState->_samplerState : nullptr,
|
||||||
depthStencil ? depthStencil->_depthStencil : nullptr,
|
depthStencil ? depthStencil->_depthStencil : nullptr,
|
||||||
rasterizerState ? rasterizerState->_rasterizerState : nullptr,
|
rasterizerState ? rasterizerState->_rasterizerState : nullptr,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "vertexbuffer-dx.hpp"
|
#include "vertexbuffer-dx.hpp"
|
||||||
#include "device-dx.hpp"
|
#include "device-dx.hpp"
|
||||||
|
#include <BufferHelpers.h>
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
bool VertexBuffer::Initialize(GraphicsDevice& device, xna_error_ptr_arg)
|
bool VertexBuffer::Initialize(GraphicsDevice& device, xna_error_ptr_arg)
|
||||||
@ -14,6 +15,8 @@ namespace xna {
|
|||||||
_buffer = nullptr;
|
_buffer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const auto hr = device._device->CreateBuffer(
|
const auto hr = device._device->CreateBuffer(
|
||||||
&_description,
|
&_description,
|
||||||
&_subResource,
|
&_subResource,
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
#define XNA_PLATFORM_VERTEXBUFFER_DX_HPP
|
#define XNA_PLATFORM_VERTEXBUFFER_DX_HPP
|
||||||
|
|
||||||
#include "../graphics/vertexbuffer.hpp"
|
#include "../graphics/vertexbuffer.hpp"
|
||||||
#include "dxheaders.hpp"
|
|
||||||
#include "../graphics/vertexposition.hpp"
|
#include "../graphics/vertexposition.hpp"
|
||||||
|
#include "dxheaders.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
class VertexBuffer : public IVertexBuffer {
|
class VertexBuffer : public IVertexBuffer {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user