mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Aplica modificações em BlendState
This commit is contained in:
parent
85968753d7
commit
e5177cd8e3
@ -6,9 +6,24 @@
|
|||||||
#include "../enums.hpp"
|
#include "../enums.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
|
struct BlendRenderTarget {
|
||||||
|
bool Enabled{ true };
|
||||||
|
Blend Source{ Blend::SourceAlpha };
|
||||||
|
Blend Destination{ Blend::InverseSourceAlpha };
|
||||||
|
BlendOperation Operation{ BlendOperation::Add };
|
||||||
|
Blend SourceAlpha{ Blend::One };
|
||||||
|
Blend DestinationAlpha{ Blend::Zero };
|
||||||
|
BlendOperation OperationAlpha{ BlendOperation::Add };
|
||||||
|
ColorWriteChannels WriteMask{ ColorWriteChannels::All };
|
||||||
|
|
||||||
|
constexpr BlendRenderTarget() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
using PBlendRenderTarget = sptr<BlendRenderTarget>;
|
||||||
|
|
||||||
class IBlendState {
|
class IBlendState {
|
||||||
public:
|
public:
|
||||||
virtual ~IBlendState(){}
|
virtual ~IBlendState() {}
|
||||||
|
|
||||||
static PBlendState Opaque();
|
static PBlendState Opaque();
|
||||||
static PBlendState AlphaBlend();
|
static PBlendState AlphaBlend();
|
||||||
@ -18,15 +33,9 @@ namespace xna {
|
|||||||
virtual bool Apply(GraphicsDevice* device) = 0;
|
virtual bool Apply(GraphicsDevice* device) = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool _alphaToCoverage{ false };
|
bool AlphaToCoverage{ false };
|
||||||
bool _enabled{ true };
|
bool IndependentBlendEnable{ false };
|
||||||
Blend _source{ Blend::SourceAlpha };
|
PBlendRenderTarget RenderTargets[8];
|
||||||
Blend _destination{ Blend::InverseSourceAlpha };
|
|
||||||
BlendOperation _operation{ BlendOperation::Add };
|
|
||||||
Blend _sourceAlpha{ Blend::One };
|
|
||||||
Blend _destinationAlpha{ Blend::Zero };
|
|
||||||
BlendOperation _operationAlpha{ BlendOperation::Add };
|
|
||||||
ColorWriteChannels _writeMask{ ColorWriteChannels::All };
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,16 +42,18 @@ namespace xna {
|
|||||||
public:
|
public:
|
||||||
constexpr DisplayModeCollection() = default;
|
constexpr DisplayModeCollection() = default;
|
||||||
|
|
||||||
|
DisplayModeCollection(size_t count) : _displayModes(count){}
|
||||||
|
|
||||||
DisplayModeCollection(std::vector<DisplayMode> const& displayModes) :
|
DisplayModeCollection(std::vector<DisplayMode> const& displayModes) :
|
||||||
_displayModes(displayModes) {}
|
_displayModes(displayModes) {}
|
||||||
|
|
||||||
std::vector<DisplayMode> At(SurfaceFormat format) {
|
std::vector<DisplayMode> At(SurfaceFormat format) const {
|
||||||
std::vector<DisplayMode> modes;
|
std::vector<DisplayMode> modes;
|
||||||
At(format, modes);
|
At(format, modes);
|
||||||
return modes;
|
return modes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void At(SurfaceFormat format, std::vector<DisplayMode>& modes) {
|
void At(SurfaceFormat format, std::vector<DisplayMode>& modes) const {
|
||||||
size_t counter = 0;
|
size_t counter = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < _displayModes.size(); ++i) {
|
for (size_t i = 0; i < _displayModes.size(); ++i) {
|
||||||
@ -68,11 +70,23 @@ namespace xna {
|
|||||||
modes.resize(counter);
|
modes.resize(counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<DisplayMode> operator[](SurfaceFormat format) {
|
size_t SurfaceCount(SurfaceFormat format) const {
|
||||||
|
size_t counter = 0;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < _displayModes.size(); ++i) {
|
||||||
|
if (_displayModes[i].Format() == format) {
|
||||||
|
++counter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<DisplayMode> operator[](SurfaceFormat format) const {
|
||||||
return At(format);
|
return At(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
public:
|
||||||
std::vector<DisplayMode> _displayModes;
|
std::vector<DisplayMode> _displayModes;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ namespace xna {
|
|||||||
IDXGIOutput* pOutput = nullptr;
|
IDXGIOutput* pOutput = nullptr;
|
||||||
UINT numModes = 0;
|
UINT numModes = 0;
|
||||||
UINT totalModes = 0;
|
UINT totalModes = 0;
|
||||||
std::vector<DXGI_MODE_DESC> buffer(250);
|
std::vector<DXGI_MODE_DESC> buffer(500);
|
||||||
|
|
||||||
if (_adapter->EnumOutputs(0, &pOutput) != DXGI_ERROR_NOT_FOUND) {
|
if (_adapter->EnumOutputs(0, &pOutput) != DXGI_ERROR_NOT_FOUND) {
|
||||||
for (size_t f = 0; f < SURFACE_FORMAT_COUNT; ++f) {
|
for (size_t f = 0; f < SURFACE_FORMAT_COUNT; ++f) {
|
||||||
@ -97,18 +97,16 @@ namespace xna {
|
|||||||
|
|
||||||
pOutput->Release();
|
pOutput->Release();
|
||||||
|
|
||||||
buffer.resize(totalModes);
|
auto collection = New<DisplayModeCollection>(totalModes);
|
||||||
std::vector<DisplayMode> dmodes;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < buffer.size(); ++i) {
|
for (size_t i = 0; i < totalModes; ++i) {
|
||||||
const auto& modedesc = buffer[i];
|
const auto& modedesc = buffer[i];
|
||||||
const auto surface = SurfaceFormatMapper::ParseToSurface(modedesc.Format);
|
const auto surface = SurfaceFormatMapper::ParseToSurface(modedesc.Format);
|
||||||
|
|
||||||
dmodes[0] = DisplayMode(modedesc.Width, modedesc.Height, surface);
|
collection->_displayModes[i] = DisplayMode(modedesc.Width, modedesc.Height, surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
dmodes.resize(buffer.size());
|
return collection;
|
||||||
return New<DisplayModeCollection>(dmodes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return New<DisplayModeCollection>();
|
return New<DisplayModeCollection>();
|
||||||
@ -116,12 +114,12 @@ namespace xna {
|
|||||||
|
|
||||||
std::vector<PGraphicsAdapter> IGraphicsAdapter::getAllAdapters() {
|
std::vector<PGraphicsAdapter> IGraphicsAdapter::getAllAdapters() {
|
||||||
IDXGIFactory1* pFactory = nullptr;
|
IDXGIFactory1* pFactory = nullptr;
|
||||||
std::vector<PGraphicsAdapter> adapters;
|
|
||||||
|
|
||||||
if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) {
|
if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) {
|
||||||
return adapters;
|
return std::vector<PGraphicsAdapter>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<PGraphicsAdapter> adapters(2);
|
||||||
IDXGIAdapter1* pAdapter = nullptr;
|
IDXGIAdapter1* pAdapter = nullptr;
|
||||||
UINT count = 0;
|
UINT count = 0;
|
||||||
|
|
||||||
@ -131,10 +129,13 @@ namespace xna {
|
|||||||
adp->_index = count;
|
adp->_index = count;
|
||||||
adp->_adapter = pAdapter;
|
adp->_adapter = pAdapter;
|
||||||
|
|
||||||
|
if (adapters.size() == count)
|
||||||
adapters.push_back(adp);
|
adapters.push_back(adp);
|
||||||
|
else
|
||||||
|
adapters[count] = adp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!adapters.empty())
|
if (!adapters.empty() && adapters.size() != count)
|
||||||
adapters.resize(count);
|
adapters.resize(count);
|
||||||
|
|
||||||
return adapters;
|
return adapters;
|
||||||
|
@ -9,16 +9,16 @@ namespace xna {
|
|||||||
bool BlendState::Apply(GraphicsDevice* device) {
|
bool BlendState::Apply(GraphicsDevice* device) {
|
||||||
|
|
||||||
D3D11_BLEND_DESC blendDesc{};
|
D3D11_BLEND_DESC blendDesc{};
|
||||||
blendDesc.AlphaToCoverageEnable = _alphaToCoverage;
|
blendDesc.AlphaToCoverageEnable = AlphaToCoverage;
|
||||||
blendDesc.IndependentBlendEnable = false;
|
blendDesc.IndependentBlendEnable = IndependentBlendEnable;
|
||||||
blendDesc.RenderTarget[0].BlendEnable = _enabled;
|
blendDesc.RenderTarget[0].BlendEnable = RenderTargets[0]->Enabled;
|
||||||
blendDesc.RenderTarget[0].SrcBlend = BlendMapper::ConvertBlend(_source);
|
blendDesc.RenderTarget[0].SrcBlend = BlendMapper::ConvertBlend(RenderTargets[0]->Source);
|
||||||
blendDesc.RenderTarget[0].DestBlend = BlendMapper::ConvertBlend(_destination);
|
blendDesc.RenderTarget[0].DestBlend = BlendMapper::ConvertBlend(RenderTargets[0]->Destination);
|
||||||
blendDesc.RenderTarget[0].BlendOp = BlendMapper::ConvertOperation(_operation);
|
blendDesc.RenderTarget[0].BlendOp = BlendMapper::ConvertOperation(RenderTargets[0]->Operation);
|
||||||
blendDesc.RenderTarget[0].SrcBlendAlpha = BlendMapper::ConvertBlend(_sourceAlpha);
|
blendDesc.RenderTarget[0].SrcBlendAlpha = BlendMapper::ConvertBlend(RenderTargets[0]->SourceAlpha);
|
||||||
blendDesc.RenderTarget[0].DestBlendAlpha = BlendMapper::ConvertBlend(_destinationAlpha);
|
blendDesc.RenderTarget[0].DestBlendAlpha = BlendMapper::ConvertBlend(RenderTargets[0]->DestinationAlpha);
|
||||||
blendDesc.RenderTarget[0].BlendOpAlpha = BlendMapper::ConvertOperation(_operationAlpha);
|
blendDesc.RenderTarget[0].BlendOpAlpha = BlendMapper::ConvertOperation(RenderTargets[0]->OperationAlpha);
|
||||||
blendDesc.RenderTarget[0].RenderTargetWriteMask = BlendMapper::ConvertColorWrite(_writeMask);
|
blendDesc.RenderTarget[0].RenderTargetWriteMask = BlendMapper::ConvertColorWrite(RenderTargets[0]->WriteMask);
|
||||||
|
|
||||||
if (_device == nullptr || _device != device)
|
if (_device == nullptr || _device != device)
|
||||||
_device = device;
|
_device = device;
|
||||||
@ -33,40 +33,44 @@ namespace xna {
|
|||||||
|
|
||||||
PBlendState IBlendState::Opaque() {
|
PBlendState IBlendState::Opaque() {
|
||||||
auto blendState = New<BlendState>(nullptr);
|
auto blendState = New<BlendState>(nullptr);
|
||||||
blendState->_source = Blend::SourceAlpha;
|
blendState->RenderTargets[0] = New<BlendRenderTarget>();
|
||||||
blendState->_sourceAlpha = Blend::SourceAlpha;
|
blendState->RenderTargets[0]->Source = Blend::SourceAlpha;
|
||||||
blendState->_destination = Blend::Zero;
|
blendState->RenderTargets[0]->SourceAlpha = Blend::SourceAlpha;
|
||||||
blendState->_destinationAlpha = Blend::Zero;
|
blendState->RenderTargets[0]->Destination = Blend::Zero;
|
||||||
|
blendState->RenderTargets[0]->DestinationAlpha = Blend::Zero;
|
||||||
|
|
||||||
return blendState;
|
return blendState;
|
||||||
}
|
}
|
||||||
|
|
||||||
PBlendState IBlendState::AlphaBlend() {
|
PBlendState IBlendState::AlphaBlend() {
|
||||||
auto blendState = New<BlendState>(nullptr);
|
auto blendState = New<BlendState>(nullptr);
|
||||||
blendState->_source = Blend::One;
|
blendState->RenderTargets[0] = New<BlendRenderTarget>();
|
||||||
blendState->_sourceAlpha = Blend::One;
|
blendState->RenderTargets[0]->Source = Blend::One;
|
||||||
blendState->_destination = Blend::InverseSourceAlpha;
|
blendState->RenderTargets[0]->SourceAlpha = Blend::One;
|
||||||
blendState->_destinationAlpha = Blend::InverseSourceAlpha;
|
blendState->RenderTargets[0]->Destination = Blend::InverseSourceAlpha;
|
||||||
|
blendState->RenderTargets[0]->DestinationAlpha = Blend::InverseSourceAlpha;
|
||||||
|
|
||||||
return blendState;
|
return blendState;
|
||||||
}
|
}
|
||||||
|
|
||||||
PBlendState IBlendState::Additive() {
|
PBlendState IBlendState::Additive() {
|
||||||
auto blendState = New<BlendState>(nullptr);
|
auto blendState = New<BlendState>(nullptr);
|
||||||
blendState->_source = Blend::SourceAlpha;
|
blendState->RenderTargets[0] = New<BlendRenderTarget>();
|
||||||
blendState->_sourceAlpha = Blend::SourceAlpha;
|
blendState->RenderTargets[0]->Source = Blend::SourceAlpha;
|
||||||
blendState->_destination = Blend::One;
|
blendState->RenderTargets[0]->SourceAlpha = Blend::SourceAlpha;
|
||||||
blendState->_destinationAlpha = Blend::One;
|
blendState->RenderTargets[0]->Destination = Blend::One;
|
||||||
|
blendState->RenderTargets[0]->DestinationAlpha = Blend::One;
|
||||||
|
|
||||||
return blendState;
|
return blendState;
|
||||||
}
|
}
|
||||||
|
|
||||||
PBlendState IBlendState::NonPremultiplied() {
|
PBlendState IBlendState::NonPremultiplied() {
|
||||||
auto blendState = New<BlendState>(nullptr);
|
auto blendState = New<BlendState>(nullptr);
|
||||||
blendState->_source = Blend::SourceAlpha;
|
blendState->RenderTargets[0] = New<BlendRenderTarget>();
|
||||||
blendState->_sourceAlpha = Blend::SourceAlpha;
|
blendState->RenderTargets[0]->Source = Blend::SourceAlpha;
|
||||||
blendState->_destination = Blend::InverseSourceAlpha;
|
blendState->RenderTargets[0]->SourceAlpha = Blend::SourceAlpha;
|
||||||
blendState->_destinationAlpha = Blend::InverseSourceAlpha;
|
blendState->RenderTargets[0]->Destination = Blend::InverseSourceAlpha;
|
||||||
|
blendState->RenderTargets[0]->DestinationAlpha = Blend::InverseSourceAlpha;
|
||||||
|
|
||||||
return blendState;
|
return blendState;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ namespace xna {
|
|||||||
GraphicsDevice::GraphicsDevice() {
|
GraphicsDevice::GraphicsDevice() {
|
||||||
_blendState = BlendState::NonPremultiplied();
|
_blendState = BlendState::NonPremultiplied();
|
||||||
_adapter = GraphicsAdapter::DefaultAdapter();
|
_adapter = GraphicsAdapter::DefaultAdapter();
|
||||||
|
auto a = _adapter->DeviceId();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GraphicsDevice::Initialize(GameWindow& gameWindow) {
|
bool GraphicsDevice::Initialize(GameWindow& gameWindow) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user