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

82 lines
2.5 KiB
C++
Raw Normal View History

2024-03-18 15:41:46 -03:00
#include "blendstate-dx.hpp"
#include "device-dx.hpp"
namespace xna {
2024-04-13 21:04:12 -03:00
bool BlendState::Initialize(GraphicsDevice& device, xna_error_ptr_arg)
{
if (!device._device) {
xna_error_apply(err, XnaErrorCode::ARGUMENT_IS_NULL);
return false;
}
2024-03-18 15:41:46 -03:00
2024-04-13 21:04:12 -03:00
if (_blendState) {
_blendState->Release();
_blendState = nullptr;
}
2024-03-18 15:41:46 -03:00
2024-04-13 21:04:12 -03:00
const auto hr = device._device->CreateBlendState(&_description, &_blendState);
2024-03-18 15:41:46 -03:00
2024-04-13 21:04:12 -03:00
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return false;
}
return true;
}
bool BlendState::Apply(GraphicsDevice& device, xna_error_ptr_arg) {
if (!device._context) {
xna_error_apply(err, XnaErrorCode::ARGUMENT_IS_NULL);
return false;
}
if (!_blendState) {
const auto init = Initialize(device, err);
if (!init) return false;
}
2024-03-18 15:41:46 -03:00
2024-04-13 21:04:12 -03:00
device._context->OMSetBlendState(_blendState, nullptr, 0xffffffff);
2024-03-18 15:41:46 -03:00
return true;
}
2024-03-21 16:01:47 -03:00
PBlendState IBlendState::Opaque() {
2024-04-13 21:04:12 -03:00
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_DEST_ALPHA;
blendState->_description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
2024-03-21 16:01:47 -03:00
return blendState;
}
PBlendState IBlendState::AlphaBlend() {
2024-04-13 21:04:12 -03:00
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_DEST_ALPHA;
blendState->_description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
2024-03-21 16:01:47 -03:00
return blendState;
}
PBlendState IBlendState::Additive() {
2024-04-13 21:04:12 -03:00
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;
2024-03-21 16:01:47 -03:00
return blendState;
}
PBlendState IBlendState::NonPremultiplied() {
2024-04-13 21:04:12 -03:00
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_DEST_ALPHA;
blendState->_description.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
2024-03-21 16:01:47 -03:00
return blendState;
}
2024-03-18 15:41:46 -03:00
}