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.7 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-25 14:51:33 -03:00
bool BlendState::Initialize(xna_error_ptr_arg)
2024-04-13 21:04:12 -03:00
{
2024-04-25 14:51:33 -03:00
if (!m_device || !m_device->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
2024-04-13 21:04:12 -03:00
return false;
}
2024-03-18 15:41:46 -03:00
2024-04-24 14:40:14 -03:00
if (dxBlendState) {
dxBlendState->Release();
dxBlendState = nullptr;
}
2024-03-18 15:41:46 -03:00
2024-04-25 14:51:33 -03:00
const auto hr = m_device->_device->CreateBlendState(&dxDescription, &dxBlendState);
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;
}
2024-04-25 14:51:33 -03:00
bool BlendState::Apply(xna_error_ptr_arg) {
if (!m_device || !m_device->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
2024-04-13 21:04:12 -03:00
return false;
}
2024-04-24 14:40:14 -03:00
if (!dxBlendState) {
2024-04-25 14:51:33 -03:00
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE);
return false;
2024-04-13 21:04:12 -03:00
}
2024-04-24 11:44:41 -03:00
2024-04-25 14:51:33 -03:00
m_device->_context->OMSetBlendState(dxBlendState, blendFactor, sampleMask);
2024-03-18 15:41:46 -03:00
return true;
}
2024-03-21 16:01:47 -03:00
2024-04-25 14:51:33 -03:00
uptr<BlendState> BlendState::Opaque() {
auto blendState = std::unique_ptr<BlendState>(new BlendState());
2024-04-24 14:40:14 -03:00
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;
2024-03-21 16:01:47 -03:00
return blendState;
}
2024-04-25 14:51:33 -03:00
uptr<BlendState> BlendState::AlphaBlend() {
auto blendState = std::unique_ptr<BlendState>(new BlendState());
2024-04-24 14:40:14 -03:00
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;
2024-03-21 16:01:47 -03:00
return blendState;
}
2024-04-25 14:51:33 -03:00
uptr<BlendState> BlendState::Additive() {
auto blendState = std::unique_ptr<BlendState>(new BlendState());
2024-04-24 14:40:14 -03:00
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;
2024-03-21 16:01:47 -03:00
return blendState;
}
2024-04-25 14:51:33 -03:00
uptr<BlendState> BlendState::NonPremultiplied() {
auto blendState = std::unique_ptr<BlendState>(new BlendState());
2024-04-24 14:40:14 -03:00
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;
2024-03-21 16:01:47 -03:00
return blendState;
}
2024-03-18 15:41:46 -03:00
}