1
0
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:
Danilo 2024-04-24 14:40:14 -03:00
parent c3df41bdab
commit da12db2c47
7 changed files with 52 additions and 41 deletions

View File

@ -67,6 +67,13 @@ namespace xna {
using BlendOperation = BlendFunction;
enum class BufferUsage {
Static,
Dynamic,
Immutable,
Staging
};
enum class Buttons {
A = 4096, // 0x00001000
B = 8192, // 0x00002000
@ -107,7 +114,7 @@ namespace xna {
Blue,
Alpha,
All
};
};
enum class ComparisonFunction {
Never,

View File

@ -9,12 +9,12 @@ namespace xna {
return false;
}
if (_blendState) {
_blendState->Release();
_blendState = nullptr;
if (dxBlendState) {
dxBlendState->Release();
dxBlendState = nullptr;
}
const auto hr = device._device->CreateBlendState(&_description, &_blendState);
const auto hr = device._device->CreateBlendState(&dxDescription, &dxBlendState);
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
@ -30,52 +30,52 @@ namespace xna {
return false;
}
if (!_blendState) {
if (!dxBlendState) {
const auto init = Initialize(device, err);
if (!init) return false;
}
device._context->OMSetBlendState(_blendState, blendFactor, sampleMask);
device._context->OMSetBlendState(dxBlendState, blendFactor, sampleMask);
return true;
}
PBlendState IBlendState::Opaque() {
auto blendState = New<BlendState>();
blendState->_description.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
blendState->_description.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO;
blendState->_description.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
blendState->_description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blendState->dxDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
blendState->dxDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO;
blendState->dxDescription.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
blendState->dxDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
return blendState;
}
PBlendState IBlendState::AlphaBlend() {
auto blendState = New<BlendState>();
blendState->_description.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
blendState->_description.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendState->_description.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendState->_description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
blendState->dxDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
blendState->dxDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendState->dxDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendState->dxDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
return blendState;
}
PBlendState IBlendState::Additive() {
auto blendState = New<BlendState>();
blendState->_description.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendState->_description.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
blendState->_description.RenderTarget[0].DestBlend = D3D11_BLEND_ONE;
blendState->_description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
blendState->dxDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendState->dxDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
blendState->dxDescription.RenderTarget[0].DestBlend = D3D11_BLEND_ONE;
blendState->dxDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
return blendState;
}
PBlendState IBlendState::NonPremultiplied() {
auto blendState = New<BlendState>();
blendState->_description.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendState->_description.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
blendState->_description.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendState->_description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
blendState->dxDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendState->dxDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
blendState->dxDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendState->dxDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
return blendState;
}

View File

@ -23,41 +23,41 @@ namespace xna {
BlendState() = default;
virtual ~BlendState() override {
if (_blendState) {
_blendState->Release();
_blendState = nullptr;
if (dxBlendState) {
dxBlendState->Release();
dxBlendState = nullptr;
}
}
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) override;
virtual constexpr void AlphaToCoverageEnable(bool value) override {
_description.AlphaToCoverageEnable = value;
dxDescription.AlphaToCoverageEnable = value;
}
virtual constexpr void IndependentBlendEnable(bool value) override {
_description.IndependentBlendEnable = value;
dxDescription.IndependentBlendEnable = value;
}
virtual void RenderTargets(std::vector<BlendRenderTarget> const& value) override {
for (size_t i = 0; i < value.size() && i < 8; ++i) {
_description.RenderTarget[i].BlendEnable = value[i].Enabled;
_description.RenderTarget[i].SrcBlend = ConvertBlend(value[i].Source);
_description.RenderTarget[i].DestBlend = ConvertBlend(value[i].Destination);
_description.RenderTarget[i].BlendOp = ConvertOperation(value[i].Operation);
_description.RenderTarget[i].SrcBlendAlpha = ConvertBlend(value[i].SourceAlpha);
_description.RenderTarget[i].DestBlendAlpha = ConvertBlend(value[i].DestinationAlpha);
_description.RenderTarget[i].BlendOpAlpha = ConvertOperation(value[i].OperationAlpha);
_description.RenderTarget[i].RenderTargetWriteMask = ConvertColorWrite(value[i].WriteMask);
dxDescription.RenderTarget[i].BlendEnable = value[i].Enabled;
dxDescription.RenderTarget[i].SrcBlend = ConvertBlend(value[i].Source);
dxDescription.RenderTarget[i].DestBlend = ConvertBlend(value[i].Destination);
dxDescription.RenderTarget[i].BlendOp = ConvertOperation(value[i].Operation);
dxDescription.RenderTarget[i].SrcBlendAlpha = ConvertBlend(value[i].SourceAlpha);
dxDescription.RenderTarget[i].DestBlendAlpha = ConvertBlend(value[i].DestinationAlpha);
dxDescription.RenderTarget[i].BlendOpAlpha = ConvertOperation(value[i].OperationAlpha);
dxDescription.RenderTarget[i].RenderTargetWriteMask = ConvertColorWrite(value[i].WriteMask);
}
}
virtual bool Apply(GraphicsDevice& device, xna_error_nullarg) override;
public:
ID3D11BlendState* _blendState{ nullptr };
D3D11_BLEND_DESC _description{};
ID3D11BlendState* dxBlendState{ nullptr };
D3D11_BLEND_DESC dxDescription{};
float blendFactor[4] { 1.0F, 1.0F, 1.0F, 1.0F };
UINT sampleMask{ 0xffffffff };
UINT sampleMask{ 0xffffffff };
public:
static constexpr D3D11_BLEND ConvertBlend(Blend blend) {

View File

@ -4,6 +4,7 @@
#include "../graphics/constbuffer.hpp"
#include "../common/matrix.hpp"
#include "dxheaders.hpp"
#include <BufferHelpers.h>
namespace xna {
class ConstantBuffer : public IConstantBuffer {

View File

@ -40,7 +40,7 @@ namespace xna {
_dxspriteBatch->Begin(
sort,
blendState ? blendState->_blendState : nullptr,
blendState ? blendState->dxBlendState : nullptr,
samplerState ? samplerState->_samplerState : nullptr,
depthStencil ? depthStencil->_depthStencil : nullptr,
rasterizerState ? rasterizerState->_rasterizerState : nullptr,

View File

@ -1,5 +1,6 @@
#include "vertexbuffer-dx.hpp"
#include "device-dx.hpp"
#include <BufferHelpers.h>
namespace xna {
bool VertexBuffer::Initialize(GraphicsDevice& device, xna_error_ptr_arg)
@ -14,6 +15,8 @@ namespace xna {
_buffer = nullptr;
}
const auto hr = device._device->CreateBuffer(
&_description,
&_subResource,

View File

@ -2,8 +2,8 @@
#define XNA_PLATFORM_VERTEXBUFFER_DX_HPP
#include "../graphics/vertexbuffer.hpp"
#include "dxheaders.hpp"
#include "../graphics/vertexposition.hpp"
#include "dxheaders.hpp"
namespace xna {
class VertexBuffer : public IVertexBuffer {