1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00
xn65/framework/platform/blendstate-dx.hpp

108 lines
2.9 KiB
C++
Raw Normal View History

2024-03-18 15:41:46 -03:00
#ifndef XNA_PLATFORM_BLENDSTATE_HPP
#define XNA_PLATFORM_BLENDSTATE_HPP
#include "../graphics/blendstate.hpp"
#include "dxgi.h"
#include "d3d11.h"
namespace xna {
2024-03-21 16:01:47 -03:00
class BlendState : public IBlendState {
2024-03-18 15:41:46 -03:00
public:
2024-03-24 16:12:17 -03:00
BlendState(GraphicsDevice* device);
2024-03-21 16:01:47 -03:00
virtual ~BlendState() override {
2024-03-18 15:41:46 -03:00
if (_blendState) {
_blendState->Release();
_blendState = nullptr;
}
}
2024-03-21 16:01:47 -03:00
virtual bool Apply(GraphicsDevice* device) override;
public:
ID3D11BlendState* _blendState{ nullptr };
GraphicsDevice* _device{ nullptr };
};
2024-03-18 15:41:46 -03:00
struct BlendMapper {
static constexpr D3D11_BLEND ConvertBlend(Blend blend) {
switch (blend)
{
case xna::Blend::Zero:
return D3D11_BLEND_ZERO;
case xna::Blend::One:
return D3D11_BLEND_ONE;
case xna::Blend::SourceColor:
return D3D11_BLEND_SRC_COLOR;
case xna::Blend::InverseSourceColor:
return D3D11_BLEND_INV_SRC_COLOR;
case xna::Blend::SourceAlpha:
return D3D11_BLEND_SRC_ALPHA;
case xna::Blend::InverseSourceAlpha:
return D3D11_BLEND_INV_SRC_ALPHA;
case xna::Blend::DestinationAlpha:
return D3D11_BLEND_DEST_ALPHA;
case xna::Blend::InverseDestinationAlpha:
return D3D11_BLEND_INV_DEST_ALPHA;
case xna::Blend::DestinationColor:
return D3D11_BLEND_DEST_COLOR;
case xna::Blend::InverseDestinationColor:
return D3D11_BLEND_INV_DEST_COLOR;
case xna::Blend::SourceAlphaSaturation:
return D3D11_BLEND_SRC_ALPHA_SAT;
case xna::Blend::BlendFactor:
return D3D11_BLEND_BLEND_FACTOR;
case xna::Blend::InverseBlendFactor:
return D3D11_BLEND_INV_BLEND_FACTOR;
case xna::Blend::Source1Color:
return D3D11_BLEND_SRC1_COLOR;
case xna::Blend::InverseSource1Color:
return D3D11_BLEND_INV_SRC1_COLOR;
case xna::Blend::Source1Alpha:
return D3D11_BLEND_SRC1_ALPHA;
case xna::Blend::InverseSource1Alpha:
return D3D11_BLEND_INV_SRC1_ALPHA;
default:
return D3D11_BLEND_ZERO;
}
}
static constexpr D3D11_BLEND_OP ConvertOperation(BlendOperation op) {
switch (op)
{
case BlendOperation::Add:
return D3D11_BLEND_OP_ADD;
case BlendOperation::Subtract:
return D3D11_BLEND_OP_SUBTRACT;
case BlendOperation::ReverseSubtract:
return D3D11_BLEND_OP_REV_SUBTRACT;
case BlendOperation::Min:
return D3D11_BLEND_OP_MIN;
case BlendOperation::Max:
return D3D11_BLEND_OP_MAX;
default:
return D3D11_BLEND_OP_ADD;
}
}
static constexpr D3D11_COLOR_WRITE_ENABLE ConvertColorWrite(ColorWriteChannels colorWrite) {
switch (colorWrite)
{
case xna::ColorWriteChannels::Red:
return D3D11_COLOR_WRITE_ENABLE_RED;
case xna::ColorWriteChannels::Green:
return D3D11_COLOR_WRITE_ENABLE_GREEN;
case xna::ColorWriteChannels::Blue:
return D3D11_COLOR_WRITE_ENABLE_BLUE;
case xna::ColorWriteChannels::Alpha:
return D3D11_COLOR_WRITE_ENABLE_ALPHA;
case xna::ColorWriteChannels::All:
return D3D11_COLOR_WRITE_ENABLE_ALL;
default:
return D3D11_COLOR_WRITE_ENABLE_ALL;
}
}
};
}
#endif