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"
|
||||
|
||||
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 {
|
||||
public:
|
||||
virtual ~IBlendState(){}
|
||||
virtual ~IBlendState() {}
|
||||
|
||||
static PBlendState Opaque();
|
||||
static PBlendState AlphaBlend();
|
||||
@ -18,15 +33,9 @@ namespace xna {
|
||||
virtual bool Apply(GraphicsDevice* device) = 0;
|
||||
|
||||
public:
|
||||
bool _alphaToCoverage{ false };
|
||||
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 };
|
||||
bool AlphaToCoverage{ false };
|
||||
bool IndependentBlendEnable{ false };
|
||||
PBlendRenderTarget RenderTargets[8];
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -36,22 +36,24 @@ namespace xna {
|
||||
Int _width{ 0 };
|
||||
Int _height{ 0 };
|
||||
SurfaceFormat _format{ SurfaceFormat::Color };
|
||||
};
|
||||
};
|
||||
|
||||
class DisplayModeCollection {
|
||||
public:
|
||||
constexpr DisplayModeCollection() = default;
|
||||
|
||||
DisplayModeCollection(size_t count) : _displayModes(count){}
|
||||
|
||||
DisplayModeCollection(std::vector<DisplayMode> const& displayModes) :
|
||||
_displayModes(displayModes) {}
|
||||
|
||||
std::vector<DisplayMode> At(SurfaceFormat format) {
|
||||
std::vector<DisplayMode> At(SurfaceFormat format) const {
|
||||
std::vector<DisplayMode> modes;
|
||||
At(format, modes);
|
||||
return modes;
|
||||
}
|
||||
}
|
||||
|
||||
void At(SurfaceFormat format, std::vector<DisplayMode>& modes) {
|
||||
void At(SurfaceFormat format, std::vector<DisplayMode>& modes) const {
|
||||
size_t counter = 0;
|
||||
|
||||
for (size_t i = 0; i < _displayModes.size(); ++i) {
|
||||
@ -68,11 +70,23 @@ namespace xna {
|
||||
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);
|
||||
}
|
||||
|
||||
private:
|
||||
public:
|
||||
std::vector<DisplayMode> _displayModes;
|
||||
};
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ namespace xna {
|
||||
IDXGIOutput* pOutput = nullptr;
|
||||
UINT numModes = 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) {
|
||||
for (size_t f = 0; f < SURFACE_FORMAT_COUNT; ++f) {
|
||||
@ -95,33 +95,31 @@ namespace xna {
|
||||
totalModes += numModes;
|
||||
}
|
||||
|
||||
pOutput->Release();
|
||||
pOutput->Release();
|
||||
|
||||
auto collection = New<DisplayModeCollection>(totalModes);
|
||||
|
||||
buffer.resize(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 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 New<DisplayModeCollection>(dmodes);
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
return New<DisplayModeCollection>();
|
||||
}
|
||||
|
||||
std::vector<PGraphicsAdapter> IGraphicsAdapter::getAllAdapters() {
|
||||
IDXGIFactory1* pFactory = nullptr;
|
||||
std::vector<PGraphicsAdapter> adapters;
|
||||
IDXGIFactory1* pFactory = nullptr;
|
||||
|
||||
if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) {
|
||||
return adapters;
|
||||
return std::vector<PGraphicsAdapter>();
|
||||
}
|
||||
|
||||
std::vector<PGraphicsAdapter> adapters(2);
|
||||
IDXGIAdapter1* pAdapter = nullptr;
|
||||
UINT count = 0;
|
||||
|
||||
@ -131,10 +129,13 @@ namespace xna {
|
||||
adp->_index = count;
|
||||
adp->_adapter = pAdapter;
|
||||
|
||||
adapters.push_back(adp);
|
||||
if (adapters.size() == count)
|
||||
adapters.push_back(adp);
|
||||
else
|
||||
adapters[count] = adp;
|
||||
}
|
||||
|
||||
if (!adapters.empty())
|
||||
if (!adapters.empty() && adapters.size() != count)
|
||||
adapters.resize(count);
|
||||
|
||||
return adapters;
|
||||
|
@ -9,16 +9,16 @@ namespace xna {
|
||||
bool BlendState::Apply(GraphicsDevice* device) {
|
||||
|
||||
D3D11_BLEND_DESC blendDesc{};
|
||||
blendDesc.AlphaToCoverageEnable = _alphaToCoverage;
|
||||
blendDesc.IndependentBlendEnable = false;
|
||||
blendDesc.RenderTarget[0].BlendEnable = _enabled;
|
||||
blendDesc.RenderTarget[0].SrcBlend = BlendMapper::ConvertBlend(_source);
|
||||
blendDesc.RenderTarget[0].DestBlend = BlendMapper::ConvertBlend(_destination);
|
||||
blendDesc.RenderTarget[0].BlendOp = BlendMapper::ConvertOperation(_operation);
|
||||
blendDesc.RenderTarget[0].SrcBlendAlpha = BlendMapper::ConvertBlend(_sourceAlpha);
|
||||
blendDesc.RenderTarget[0].DestBlendAlpha = BlendMapper::ConvertBlend(_destinationAlpha);
|
||||
blendDesc.RenderTarget[0].BlendOpAlpha = BlendMapper::ConvertOperation(_operationAlpha);
|
||||
blendDesc.RenderTarget[0].RenderTargetWriteMask = BlendMapper::ConvertColorWrite(_writeMask);
|
||||
blendDesc.AlphaToCoverageEnable = AlphaToCoverage;
|
||||
blendDesc.IndependentBlendEnable = IndependentBlendEnable;
|
||||
blendDesc.RenderTarget[0].BlendEnable = RenderTargets[0]->Enabled;
|
||||
blendDesc.RenderTarget[0].SrcBlend = BlendMapper::ConvertBlend(RenderTargets[0]->Source);
|
||||
blendDesc.RenderTarget[0].DestBlend = BlendMapper::ConvertBlend(RenderTargets[0]->Destination);
|
||||
blendDesc.RenderTarget[0].BlendOp = BlendMapper::ConvertOperation(RenderTargets[0]->Operation);
|
||||
blendDesc.RenderTarget[0].SrcBlendAlpha = BlendMapper::ConvertBlend(RenderTargets[0]->SourceAlpha);
|
||||
blendDesc.RenderTarget[0].DestBlendAlpha = BlendMapper::ConvertBlend(RenderTargets[0]->DestinationAlpha);
|
||||
blendDesc.RenderTarget[0].BlendOpAlpha = BlendMapper::ConvertOperation(RenderTargets[0]->OperationAlpha);
|
||||
blendDesc.RenderTarget[0].RenderTargetWriteMask = BlendMapper::ConvertColorWrite(RenderTargets[0]->WriteMask);
|
||||
|
||||
if (_device == nullptr || _device != device)
|
||||
_device = device;
|
||||
@ -33,40 +33,44 @@ namespace xna {
|
||||
|
||||
PBlendState IBlendState::Opaque() {
|
||||
auto blendState = New<BlendState>(nullptr);
|
||||
blendState->_source = Blend::SourceAlpha;
|
||||
blendState->_sourceAlpha = Blend::SourceAlpha;
|
||||
blendState->_destination = Blend::Zero;
|
||||
blendState->_destinationAlpha = Blend::Zero;
|
||||
blendState->RenderTargets[0] = New<BlendRenderTarget>();
|
||||
blendState->RenderTargets[0]->Source = Blend::SourceAlpha;
|
||||
blendState->RenderTargets[0]->SourceAlpha = Blend::SourceAlpha;
|
||||
blendState->RenderTargets[0]->Destination = Blend::Zero;
|
||||
blendState->RenderTargets[0]->DestinationAlpha = Blend::Zero;
|
||||
|
||||
return blendState;
|
||||
}
|
||||
|
||||
PBlendState IBlendState::AlphaBlend() {
|
||||
auto blendState = New<BlendState>(nullptr);
|
||||
blendState->_source = Blend::One;
|
||||
blendState->_sourceAlpha = Blend::One;
|
||||
blendState->_destination = Blend::InverseSourceAlpha;
|
||||
blendState->_destinationAlpha = Blend::InverseSourceAlpha;
|
||||
blendState->RenderTargets[0] = New<BlendRenderTarget>();
|
||||
blendState->RenderTargets[0]->Source = Blend::One;
|
||||
blendState->RenderTargets[0]->SourceAlpha = Blend::One;
|
||||
blendState->RenderTargets[0]->Destination = Blend::InverseSourceAlpha;
|
||||
blendState->RenderTargets[0]->DestinationAlpha = Blend::InverseSourceAlpha;
|
||||
|
||||
return blendState;
|
||||
}
|
||||
|
||||
PBlendState IBlendState::Additive() {
|
||||
auto blendState = New<BlendState>(nullptr);
|
||||
blendState->_source = Blend::SourceAlpha;
|
||||
blendState->_sourceAlpha = Blend::SourceAlpha;
|
||||
blendState->_destination = Blend::One;
|
||||
blendState->_destinationAlpha = Blend::One;
|
||||
blendState->RenderTargets[0] = New<BlendRenderTarget>();
|
||||
blendState->RenderTargets[0]->Source = Blend::SourceAlpha;
|
||||
blendState->RenderTargets[0]->SourceAlpha = Blend::SourceAlpha;
|
||||
blendState->RenderTargets[0]->Destination = Blend::One;
|
||||
blendState->RenderTargets[0]->DestinationAlpha = Blend::One;
|
||||
|
||||
return blendState;
|
||||
}
|
||||
|
||||
PBlendState IBlendState::NonPremultiplied() {
|
||||
auto blendState = New<BlendState>(nullptr);
|
||||
blendState->_source = Blend::SourceAlpha;
|
||||
blendState->_sourceAlpha = Blend::SourceAlpha;
|
||||
blendState->_destination = Blend::InverseSourceAlpha;
|
||||
blendState->_destinationAlpha = Blend::InverseSourceAlpha;
|
||||
blendState->RenderTargets[0] = New<BlendRenderTarget>();
|
||||
blendState->RenderTargets[0]->Source = Blend::SourceAlpha;
|
||||
blendState->RenderTargets[0]->SourceAlpha = Blend::SourceAlpha;
|
||||
blendState->RenderTargets[0]->Destination = Blend::InverseSourceAlpha;
|
||||
blendState->RenderTargets[0]->DestinationAlpha = Blend::InverseSourceAlpha;
|
||||
|
||||
return blendState;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
namespace xna {
|
||||
class BlendState : public IBlendState {
|
||||
public:
|
||||
BlendState(GraphicsDevice* device);
|
||||
BlendState(GraphicsDevice* device);
|
||||
|
||||
virtual ~BlendState() override {
|
||||
if (_blendState) {
|
||||
|
@ -8,7 +8,8 @@
|
||||
namespace xna {
|
||||
GraphicsDevice::GraphicsDevice() {
|
||||
_blendState = BlendState::NonPremultiplied();
|
||||
_adapter = GraphicsAdapter::DefaultAdapter();
|
||||
_adapter = GraphicsAdapter::DefaultAdapter();
|
||||
auto a = _adapter->DeviceId();
|
||||
}
|
||||
|
||||
bool GraphicsDevice::Initialize(GameWindow& gameWindow) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user