mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementa recursos gráficos
This commit is contained in:
parent
a7cef87f59
commit
dcf6c06cfb
@ -166,9 +166,9 @@ namespace xna {
|
||||
};
|
||||
|
||||
enum class FillMode
|
||||
{
|
||||
Solid,
|
||||
{
|
||||
WireFrame,
|
||||
Solid,
|
||||
};
|
||||
|
||||
enum class GamePadCapabilitiesType
|
||||
@ -446,8 +446,8 @@ namespace xna {
|
||||
|
||||
enum class TextureAddressMode {
|
||||
Wrap,
|
||||
Clamp,
|
||||
Mirror,
|
||||
Clamp,
|
||||
Border,
|
||||
MirrorOnce
|
||||
};
|
||||
|
@ -9,17 +9,12 @@ namespace xna {
|
||||
class IBlendState {
|
||||
public:
|
||||
virtual ~IBlendState() {}
|
||||
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) = 0;
|
||||
virtual bool Initialize(xna_error_nullarg) = 0;
|
||||
virtual void AlphaToCoverageEnable(bool value) = 0;
|
||||
virtual void IndependentBlendEnable(bool value) = 0;
|
||||
virtual void RenderTargets(std::vector<BlendRenderTarget> const& value) = 0;
|
||||
|
||||
virtual bool Apply(GraphicsDevice& device, xna_error_nullarg) = 0;
|
||||
|
||||
static PBlendState Opaque();
|
||||
static PBlendState AlphaBlend();
|
||||
static PBlendState Additive();
|
||||
static PBlendState NonPremultiplied();
|
||||
virtual bool Apply(xna_error_nullarg) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,8 @@ namespace xna {
|
||||
class IDepthStencilState {
|
||||
public:
|
||||
virtual ~IDepthStencilState(){}
|
||||
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) = 0;
|
||||
virtual bool Apply(GraphicsDevice& device, xna_error_ptr_arg) = 0;
|
||||
virtual bool Initialize(xna_error_nullarg) = 0;
|
||||
virtual bool Apply(xna_error_ptr_arg) = 0;
|
||||
|
||||
virtual void DepthEnabled(bool value) = 0;
|
||||
virtual void DepthWriteEnabled(bool value) = 0;
|
||||
@ -38,11 +38,7 @@ namespace xna {
|
||||
virtual StencilOperation StencilBackFacePass() = 0;
|
||||
virtual StencilOperation StencilBackFaceFail() = 0;
|
||||
virtual StencilOperation StencilBackFaceDepthFail() = 0;
|
||||
virtual ComparisonFunction StencilBackFaceCompare() = 0;
|
||||
|
||||
static PDepthStencilState None();
|
||||
static PDepthStencilState Default();
|
||||
static PDepthStencilState DepthRead();
|
||||
virtual ComparisonFunction StencilBackFaceCompare() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,8 @@ namespace xna {
|
||||
class IRasterizerState {
|
||||
public:
|
||||
virtual ~IRasterizerState() {}
|
||||
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) = 0;
|
||||
virtual bool Initialize(xna_error_nullarg) = 0;
|
||||
virtual bool Apply(xna_error_nullarg) = 0;
|
||||
virtual xna::CullMode CullMode() const = 0;
|
||||
virtual void CullMode(xna::CullMode value) = 0;
|
||||
virtual xna::FillMode FillMode() const = 0;
|
||||
|
@ -7,7 +7,7 @@ namespace xna {
|
||||
class IShader {
|
||||
public:
|
||||
virtual ~IShader() {}
|
||||
virtual bool Initialize(GraphicsDevice& device, DataBuffer& buffer, xna_error_nullarg) = 0;
|
||||
virtual bool Initialize(DataBuffer& buffer, xna_error_nullarg) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ namespace xna {
|
||||
class ISwapChain {
|
||||
public:
|
||||
virtual ~ISwapChain() {}
|
||||
virtual bool Initialize(GraphicsDevice& device, GameWindow const& gameWindow) = 0;
|
||||
virtual bool Initialize(GameWindow const& gameWindow, xna_error_nullarg) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,10 @@
|
||||
#include "device-dx.hpp"
|
||||
|
||||
namespace xna {
|
||||
bool BlendState::Initialize(GraphicsDevice& device, xna_error_ptr_arg)
|
||||
bool BlendState::Initialize(xna_error_ptr_arg)
|
||||
{
|
||||
if (!device._device) {
|
||||
xna_error_apply(err, XnaErrorCode::ARGUMENT_IS_NULL);
|
||||
if (!m_device || !m_device->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ namespace xna {
|
||||
dxBlendState = nullptr;
|
||||
}
|
||||
|
||||
const auto hr = device._device->CreateBlendState(&dxDescription, &dxBlendState);
|
||||
const auto hr = m_device->_device->CreateBlendState(&dxDescription, &dxBlendState);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||
@ -24,24 +24,24 @@ namespace xna {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BlendState::Apply(GraphicsDevice& device, xna_error_ptr_arg) {
|
||||
if (!device._context) {
|
||||
xna_error_apply(err, XnaErrorCode::ARGUMENT_IS_NULL);
|
||||
bool BlendState::Apply(xna_error_ptr_arg) {
|
||||
if (!m_device || !m_device->_context) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!dxBlendState) {
|
||||
const auto init = Initialize(device, err);
|
||||
if (!init) return false;
|
||||
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE);
|
||||
return false;
|
||||
}
|
||||
|
||||
device._context->OMSetBlendState(dxBlendState, blendFactor, sampleMask);
|
||||
m_device->_context->OMSetBlendState(dxBlendState, blendFactor, sampleMask);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
PBlendState IBlendState::Opaque() {
|
||||
auto blendState = New<BlendState>();
|
||||
uptr<BlendState> BlendState::Opaque() {
|
||||
auto blendState = std::unique_ptr<BlendState>(new BlendState());
|
||||
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;
|
||||
@ -50,8 +50,8 @@ namespace xna {
|
||||
return blendState;
|
||||
}
|
||||
|
||||
PBlendState IBlendState::AlphaBlend() {
|
||||
auto blendState = New<BlendState>();
|
||||
uptr<BlendState> BlendState::AlphaBlend() {
|
||||
auto blendState = std::unique_ptr<BlendState>(new BlendState());
|
||||
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;
|
||||
@ -60,8 +60,8 @@ namespace xna {
|
||||
return blendState;
|
||||
}
|
||||
|
||||
PBlendState IBlendState::Additive() {
|
||||
auto blendState = New<BlendState>();
|
||||
uptr<BlendState> BlendState::Additive() {
|
||||
auto blendState = std::unique_ptr<BlendState>(new BlendState());
|
||||
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;
|
||||
@ -70,8 +70,8 @@ namespace xna {
|
||||
return blendState;
|
||||
}
|
||||
|
||||
PBlendState IBlendState::NonPremultiplied() {
|
||||
auto blendState = New<BlendState>();
|
||||
uptr<BlendState> BlendState::NonPremultiplied() {
|
||||
auto blendState = std::unique_ptr<BlendState>(new BlendState());
|
||||
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;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define XNA_PLATFORM_BLENDSTATE_HPP
|
||||
|
||||
#include "../graphics/blendstate.hpp"
|
||||
#include "../graphics/gresource.hpp"
|
||||
#include "dxheaders.hpp"
|
||||
|
||||
namespace xna {
|
||||
@ -18,9 +19,9 @@ namespace xna {
|
||||
constexpr BlendRenderTarget() = default;
|
||||
};
|
||||
|
||||
class BlendState : public IBlendState {
|
||||
class BlendState : public IBlendState, public GraphicsResource {
|
||||
public:
|
||||
BlendState() = default;
|
||||
BlendState(GraphicsDevice* device) : GraphicsResource(device) {};
|
||||
|
||||
virtual ~BlendState() override {
|
||||
if (dxBlendState) {
|
||||
@ -28,7 +29,7 @@ namespace xna {
|
||||
dxBlendState = nullptr;
|
||||
}
|
||||
}
|
||||
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) override;
|
||||
virtual bool Initialize(xna_error_nullarg) override;
|
||||
|
||||
virtual constexpr void AlphaToCoverageEnable(bool value) override {
|
||||
dxDescription.AlphaToCoverageEnable = value;
|
||||
@ -51,13 +52,21 @@ namespace xna {
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool Apply(GraphicsDevice& device, xna_error_nullarg) override;
|
||||
virtual bool Apply(xna_error_nullarg) override;
|
||||
|
||||
static uptr<BlendState> Opaque();
|
||||
static uptr<BlendState> AlphaBlend();
|
||||
static uptr<BlendState> Additive();
|
||||
static uptr<BlendState> NonPremultiplied();
|
||||
|
||||
public:
|
||||
ID3D11BlendState* dxBlendState{ nullptr };
|
||||
D3D11_BLEND_DESC dxDescription{};
|
||||
float blendFactor[4] { 1.0F, 1.0F, 1.0F, 1.0F };
|
||||
UINT sampleMask{ 0xffffffff };
|
||||
UINT sampleMask{ 0xffffffff };
|
||||
|
||||
private:
|
||||
BlendState() : GraphicsResource(nullptr){}
|
||||
|
||||
public:
|
||||
static constexpr D3D11_BLEND ConvertBlend(Blend blend) {
|
||||
|
@ -2,19 +2,19 @@
|
||||
#include "device-dx.hpp"
|
||||
|
||||
namespace xna {
|
||||
bool DepthStencilState::Initialize(GraphicsDevice& device, xna_error_ptr_arg)
|
||||
bool DepthStencilState::Initialize(xna_error_ptr_arg)
|
||||
{
|
||||
if (!device._device) {
|
||||
xna_error_apply(err, XnaErrorCode::ARGUMENT_IS_NULL);
|
||||
if (!m_device || !m_device->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_depthStencil) {
|
||||
_depthStencil->Release();
|
||||
_depthStencil = nullptr;
|
||||
if (dxDepthStencil) {
|
||||
dxDepthStencil->Release();
|
||||
dxDepthStencil = nullptr;
|
||||
}
|
||||
|
||||
const auto hr = device._device->CreateDepthStencilState(&_description, &_depthStencil);
|
||||
const auto hr = m_device->_device->CreateDepthStencilState(&dxDescription, &dxDepthStencil);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||
@ -24,43 +24,43 @@ namespace xna {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DepthStencilState::Apply(GraphicsDevice& device, xna_error_ptr_arg)
|
||||
bool DepthStencilState::Apply(xna_error_ptr_arg)
|
||||
{
|
||||
if (!device._context) {
|
||||
xna_error_apply(err, XnaErrorCode::ARGUMENT_IS_NULL);
|
||||
if (!m_device || !m_device->_context) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_depthStencil) {
|
||||
const auto init = Initialize(device, err);
|
||||
if (!init) return false;
|
||||
if (!dxDepthStencil) {
|
||||
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE);
|
||||
return false;
|
||||
}
|
||||
|
||||
device._context->OMSetDepthStencilState(_depthStencil, 0);
|
||||
m_device->_context->OMSetDepthStencilState(dxDepthStencil, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
PDepthStencilState IDepthStencilState::None() {
|
||||
auto stencil = New<DepthStencilState>();
|
||||
stencil->_description.DepthEnable = false;
|
||||
stencil->_description.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
uptr<DepthStencilState> DepthStencilState::None() {
|
||||
auto stencil = std::unique_ptr<DepthStencilState>(new DepthStencilState());
|
||||
stencil->dxDescription.DepthEnable = false;
|
||||
stencil->dxDescription.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
|
||||
return stencil;
|
||||
}
|
||||
|
||||
PDepthStencilState IDepthStencilState::Default() {
|
||||
auto stencil = New<DepthStencilState>();
|
||||
stencil->_description.DepthEnable = true;
|
||||
stencil->_description.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
|
||||
uptr<DepthStencilState> DepthStencilState::Default() {
|
||||
auto stencil = std::unique_ptr<DepthStencilState>(new DepthStencilState());
|
||||
stencil->dxDescription.DepthEnable = true;
|
||||
stencil->dxDescription.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
|
||||
|
||||
return stencil;
|
||||
}
|
||||
|
||||
PDepthStencilState IDepthStencilState::DepthRead() {
|
||||
auto stencil = New<DepthStencilState>();
|
||||
stencil->_description.DepthEnable = true;
|
||||
stencil->_description.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
uptr<DepthStencilState> DepthStencilState::DepthRead() {
|
||||
auto stencil = std::unique_ptr<DepthStencilState>(new DepthStencilState());
|
||||
stencil->dxDescription.DepthEnable = true;
|
||||
stencil->dxDescription.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
|
||||
return stencil;
|
||||
}
|
||||
|
@ -2,16 +2,175 @@
|
||||
#define XNA_PLATFORM_DEPTHSTENCILSTATE_DX_HPP
|
||||
|
||||
#include "../graphics/depthstencilstate.hpp"
|
||||
#include "../graphics/gresource.hpp"
|
||||
#include "dxheaders.hpp"
|
||||
|
||||
namespace xna {
|
||||
class DepthStencilState : public IDepthStencilState {
|
||||
class DepthStencilState : public IDepthStencilState, public GraphicsResource {
|
||||
public:
|
||||
DepthStencilState() {
|
||||
DepthStencilState(GraphicsDevice* device) : GraphicsResource(device) {
|
||||
dxDescription = defaultDesc();
|
||||
}
|
||||
|
||||
virtual ~DepthStencilState() override {
|
||||
if (dxDepthStencil) {
|
||||
dxDepthStencil->Release();
|
||||
dxDepthStencil = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool Initialize(xna_error_nullarg) override;
|
||||
virtual bool Apply(xna_error_ptr_arg) override;
|
||||
|
||||
virtual constexpr void DepthEnabled(bool value) override {
|
||||
dxDescription.DepthEnable = value;
|
||||
}
|
||||
|
||||
virtual constexpr void DepthWriteEnabled(bool value) override {
|
||||
dxDescription.DepthWriteMask = static_cast<D3D11_DEPTH_WRITE_MASK>(value);
|
||||
}
|
||||
|
||||
virtual constexpr void DepthCompareFunction(ComparisonFunction value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
dxDescription.DepthFunc = static_cast<D3D11_COMPARISON_FUNC>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilEnabled(bool value) override {
|
||||
dxDescription.StencilEnable = value;
|
||||
}
|
||||
|
||||
virtual constexpr void StencilReadMask(int value) override {
|
||||
dxDescription.StencilReadMask = static_cast<UINT8>(value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilWriteMask(int value) override {
|
||||
dxDescription.StencilWriteMask = static_cast<UINT8>(value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilFrontFacePass(StencilOperation value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
dxDescription.FrontFace.StencilPassOp = static_cast<D3D11_STENCIL_OP>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilFrontFaceFail(StencilOperation value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
dxDescription.FrontFace.StencilFailOp = static_cast<D3D11_STENCIL_OP>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilFrontFaceDepthFail(StencilOperation value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
dxDescription.FrontFace.StencilDepthFailOp = static_cast<D3D11_STENCIL_OP>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilFrontFaceCompare(ComparisonFunction value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
dxDescription.FrontFace.StencilFunc = static_cast<D3D11_COMPARISON_FUNC>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilBackFacePass(StencilOperation value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
dxDescription.BackFace.StencilPassOp = static_cast<D3D11_STENCIL_OP>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilBackFaceFail(StencilOperation value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
dxDescription.BackFace.StencilFailOp = static_cast<D3D11_STENCIL_OP>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilBackFaceDepthFail(StencilOperation value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
dxDescription.BackFace.StencilDepthFailOp = static_cast<D3D11_STENCIL_OP>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilBackFaceCompare(ComparisonFunction value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
dxDescription.BackFace.StencilFunc = static_cast<D3D11_COMPARISON_FUNC>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr bool DepthEnabled() override {
|
||||
return dxDescription.DepthEnable;
|
||||
}
|
||||
|
||||
virtual constexpr bool DepthWriteEnabled() override {
|
||||
return static_cast<bool>(dxDescription.DepthWriteMask);
|
||||
}
|
||||
|
||||
virtual constexpr ComparisonFunction DepthCompareFunction() override {
|
||||
const auto _value = static_cast<int>(dxDescription.DepthFunc) - 1;
|
||||
return static_cast<ComparisonFunction>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr bool StencilEnabled() override {
|
||||
return dxDescription.StencilEnable;
|
||||
}
|
||||
|
||||
virtual constexpr int StencilReadMask() override {
|
||||
return static_cast<int>(dxDescription.StencilReadMask);
|
||||
}
|
||||
|
||||
virtual constexpr int StencilWriteMask() override {
|
||||
return static_cast<int>(dxDescription.StencilWriteMask);
|
||||
}
|
||||
|
||||
virtual constexpr StencilOperation StencilFrontFacePass() override {
|
||||
const auto _value = static_cast<int>(dxDescription.FrontFace.StencilPassOp) - 1;
|
||||
return static_cast<StencilOperation>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr StencilOperation StencilFrontFaceFail() override {
|
||||
const auto _value = static_cast<int>(dxDescription.FrontFace.StencilFailOp) - 1;
|
||||
return static_cast<StencilOperation>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr StencilOperation StencilFrontFaceDepthFail() override {
|
||||
const auto _value = static_cast<int>(dxDescription.FrontFace.StencilDepthFailOp) - 1;
|
||||
return static_cast<StencilOperation>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr ComparisonFunction StencilFrontFaceCompare() override {
|
||||
const auto _value = static_cast<int>(dxDescription.FrontFace.StencilFunc) - 1;
|
||||
return static_cast<ComparisonFunction>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr StencilOperation StencilBackFacePass() override {
|
||||
const auto _value = static_cast<int>(dxDescription.BackFace.StencilPassOp) - 1;
|
||||
return static_cast<StencilOperation>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr StencilOperation StencilBackFaceFail() override {
|
||||
const auto _value = static_cast<int>(dxDescription.BackFace.StencilFailOp) - 1;
|
||||
return static_cast<StencilOperation>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr StencilOperation StencilBackFaceDepthFail() override {
|
||||
const auto _value = static_cast<int>(dxDescription.BackFace.StencilDepthFailOp) - 1;
|
||||
return static_cast<StencilOperation>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr ComparisonFunction StencilBackFaceCompare() override {
|
||||
const auto _value = static_cast<int>(dxDescription.BackFace.StencilFunc) - 1;
|
||||
return static_cast<ComparisonFunction>(_value);
|
||||
}
|
||||
|
||||
static uptr<DepthStencilState> None();
|
||||
static uptr<DepthStencilState> Default();
|
||||
static uptr<DepthStencilState> DepthRead();
|
||||
|
||||
public:
|
||||
ID3D11DepthStencilState* dxDepthStencil = nullptr;
|
||||
D3D11_DEPTH_STENCIL_DESC dxDescription{};
|
||||
|
||||
private:
|
||||
DepthStencilState() : GraphicsResource(nullptr) {
|
||||
dxDescription = defaultDesc();
|
||||
}
|
||||
|
||||
static D3D11_DEPTH_STENCIL_DESC defaultDesc() {
|
||||
D3D11_DEPTH_STENCIL_DESC _description{};
|
||||
_description.DepthEnable = true;
|
||||
_description.StencilEnable = true;
|
||||
_description.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
|
||||
|
||||
|
||||
_description.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
||||
_description.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
||||
_description.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
||||
@ -25,151 +184,9 @@ namespace xna {
|
||||
_description.StencilReadMask = 0;
|
||||
_description.StencilWriteMask = 0;
|
||||
_description.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
}
|
||||
|
||||
virtual ~DepthStencilState() override {
|
||||
if (_depthStencil) {
|
||||
_depthStencil->Release();
|
||||
_depthStencil = nullptr;
|
||||
}
|
||||
return _description;
|
||||
}
|
||||
|
||||
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) override;
|
||||
virtual bool Apply(GraphicsDevice& device, xna_error_ptr_arg) override;
|
||||
|
||||
virtual constexpr void DepthEnabled(bool value) override {
|
||||
_description.DepthEnable = value;
|
||||
}
|
||||
|
||||
virtual constexpr void DepthWriteEnabled(bool value) override {
|
||||
_description.DepthWriteMask = static_cast<D3D11_DEPTH_WRITE_MASK>(value);
|
||||
}
|
||||
|
||||
virtual constexpr void DepthCompareFunction(ComparisonFunction value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
_description.DepthFunc = static_cast<D3D11_COMPARISON_FUNC>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilEnabled(bool value) override {
|
||||
_description.StencilEnable = value;
|
||||
}
|
||||
|
||||
virtual constexpr void StencilReadMask(int value) override {
|
||||
_description.StencilReadMask = static_cast<UINT8>(value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilWriteMask(int value) override {
|
||||
_description.StencilWriteMask = static_cast<UINT8>(value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilFrontFacePass(StencilOperation value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
_description.FrontFace.StencilPassOp = static_cast<D3D11_STENCIL_OP>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilFrontFaceFail(StencilOperation value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
_description.FrontFace.StencilFailOp = static_cast<D3D11_STENCIL_OP>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilFrontFaceDepthFail(StencilOperation value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
_description.FrontFace.StencilDepthFailOp = static_cast<D3D11_STENCIL_OP>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilFrontFaceCompare(ComparisonFunction value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
_description.FrontFace.StencilFunc = static_cast<D3D11_COMPARISON_FUNC>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilBackFacePass(StencilOperation value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
_description.BackFace.StencilPassOp = static_cast<D3D11_STENCIL_OP>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilBackFaceFail(StencilOperation value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
_description.BackFace.StencilFailOp = static_cast<D3D11_STENCIL_OP>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilBackFaceDepthFail(StencilOperation value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
_description.BackFace.StencilDepthFailOp = static_cast<D3D11_STENCIL_OP>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr void StencilBackFaceCompare(ComparisonFunction value) override {
|
||||
const auto _value = static_cast<int>(value) + 1;
|
||||
_description.BackFace.StencilFunc = static_cast<D3D11_COMPARISON_FUNC>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr bool DepthEnabled() override {
|
||||
return _description.DepthEnable;
|
||||
}
|
||||
|
||||
virtual constexpr bool DepthWriteEnabled() override {
|
||||
return static_cast<bool>(_description.DepthWriteMask);
|
||||
}
|
||||
|
||||
virtual constexpr ComparisonFunction DepthCompareFunction() override {
|
||||
const auto _value = static_cast<int>(_description.DepthFunc) - 1;
|
||||
return static_cast<ComparisonFunction>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr bool StencilEnabled() override {
|
||||
return _description.StencilEnable;
|
||||
}
|
||||
|
||||
virtual constexpr int StencilReadMask() override {
|
||||
return static_cast<int>(_description.StencilReadMask);
|
||||
}
|
||||
|
||||
virtual constexpr int StencilWriteMask() override {
|
||||
return static_cast<int>(_description.StencilWriteMask);
|
||||
}
|
||||
|
||||
virtual constexpr StencilOperation StencilFrontFacePass() override {
|
||||
const auto _value = static_cast<int>(_description.FrontFace.StencilPassOp) - 1;
|
||||
return static_cast<StencilOperation>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr StencilOperation StencilFrontFaceFail() override {
|
||||
const auto _value = static_cast<int>(_description.FrontFace.StencilFailOp) - 1;
|
||||
return static_cast<StencilOperation>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr StencilOperation StencilFrontFaceDepthFail() override {
|
||||
const auto _value = static_cast<int>(_description.FrontFace.StencilDepthFailOp) - 1;
|
||||
return static_cast<StencilOperation>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr ComparisonFunction StencilFrontFaceCompare() override {
|
||||
const auto _value = static_cast<int>(_description.FrontFace.StencilFunc) - 1;
|
||||
return static_cast<ComparisonFunction>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr StencilOperation StencilBackFacePass() override {
|
||||
const auto _value = static_cast<int>(_description.BackFace.StencilPassOp) - 1;
|
||||
return static_cast<StencilOperation>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr StencilOperation StencilBackFaceFail() override {
|
||||
const auto _value = static_cast<int>(_description.BackFace.StencilFailOp) - 1;
|
||||
return static_cast<StencilOperation>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr StencilOperation StencilBackFaceDepthFail() override {
|
||||
const auto _value = static_cast<int>(_description.BackFace.StencilDepthFailOp) - 1;
|
||||
return static_cast<StencilOperation>(_value);
|
||||
}
|
||||
|
||||
virtual constexpr ComparisonFunction StencilBackFaceCompare() override {
|
||||
const auto _value = static_cast<int>(_description.BackFace.StencilFunc) - 1;
|
||||
return static_cast<ComparisonFunction>(_value);
|
||||
}
|
||||
|
||||
public:
|
||||
ID3D11DepthStencilState* _depthStencil = nullptr;
|
||||
D3D11_DEPTH_STENCIL_DESC _description{};
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ namespace xna {
|
||||
|
||||
if (_blendState == nullptr)
|
||||
_blendState = BlendState::NonPremultiplied();
|
||||
_blendState->Bind(this);
|
||||
|
||||
_createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||
|
||||
@ -66,9 +67,9 @@ namespace xna {
|
||||
_backgroundColor[3] = 1.0f;
|
||||
|
||||
if (!_swapChain)
|
||||
_swapChain = New<xna::SwapChain>();
|
||||
_swapChain = New<xna::SwapChain>(this);
|
||||
|
||||
_swapChain->Initialize(*this, gameWindow);
|
||||
_swapChain->Initialize(gameWindow);
|
||||
|
||||
if FAILED(_factory->MakeWindowAssociation(gameWindow.WindowHandle(), DXGI_MWA_NO_ALT_ENTER))
|
||||
return false;
|
||||
@ -92,7 +93,7 @@ namespace xna {
|
||||
|
||||
_context->RSSetViewports(1, &view);
|
||||
|
||||
_blendState->Apply(*this);
|
||||
_blendState->Apply();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2,15 +2,64 @@
|
||||
#include "device-dx.hpp"
|
||||
|
||||
namespace xna {
|
||||
bool RasterizerState::Initialize(GraphicsDevice& device, xna_error_ptr_arg)
|
||||
bool RasterizerState::Initialize(xna_error_ptr_arg)
|
||||
{
|
||||
const auto hr = device._device->CreateRasterizerState(&_description, &_rasterizerState);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
if (!m_device || !m_device->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto hr = m_device->_device->CreateRasterizerState(&dxDescription, &dxRasterizerState);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RasterizerState::Apply(xna_error_ptr_arg)
|
||||
{
|
||||
if (!m_device || !m_device->_context) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!dxRasterizerState) {
|
||||
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_device->_context->RSSetState(dxRasterizerState);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uptr<RasterizerState> RasterizerState::CullNone()
|
||||
{
|
||||
auto raster = std::unique_ptr<RasterizerState>(new RasterizerState());
|
||||
raster->dxDescription.FillMode = D3D11_FILL_SOLID;
|
||||
raster->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_NONE;
|
||||
raster->dxDescription.DepthClipEnable = true;
|
||||
return raster;
|
||||
}
|
||||
|
||||
uptr<RasterizerState> RasterizerState::CullClockwise()
|
||||
{
|
||||
auto raster = std::unique_ptr<RasterizerState>(new RasterizerState());
|
||||
raster->dxDescription.FillMode = D3D11_FILL_SOLID;
|
||||
raster->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_FRONT;
|
||||
raster->dxDescription.DepthClipEnable = true;
|
||||
return raster;
|
||||
}
|
||||
|
||||
uptr<RasterizerState> RasterizerState::CullCounterClockwise()
|
||||
{
|
||||
auto raster = std::unique_ptr<RasterizerState>(new RasterizerState());
|
||||
raster->dxDescription.FillMode = D3D11_FILL_SOLID;
|
||||
raster->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK;
|
||||
raster->dxDescription.DepthClipEnable = true;
|
||||
return raster;
|
||||
}
|
||||
}
|
||||
|
@ -2,107 +2,50 @@
|
||||
#define XNA_PLATFORM_RASTERIZERSTATE_DX_HPP
|
||||
|
||||
#include "../graphics/rasterizerstate.hpp"
|
||||
#include "../graphics/gresource.hpp"
|
||||
#include "dxheaders.hpp"
|
||||
|
||||
namespace xna {
|
||||
class RasterizerState : public IRasterizerState {
|
||||
class RasterizerState : public IRasterizerState, public GraphicsResource {
|
||||
public:
|
||||
RasterizerState(){}
|
||||
RasterizerState(GraphicsDevice* device) : GraphicsResource(device){}
|
||||
|
||||
virtual ~RasterizerState() override {
|
||||
if (_rasterizerState) {
|
||||
_rasterizerState->Release();
|
||||
_rasterizerState = nullptr;
|
||||
if (dxRasterizerState) {
|
||||
dxRasterizerState->Release();
|
||||
dxRasterizerState = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) override;
|
||||
virtual bool Initialize(xna_error_nullarg) override;
|
||||
virtual bool Apply(xna_error_nullarg) override;
|
||||
|
||||
virtual constexpr xna::CullMode CullMode() const override {
|
||||
switch (_description.CullMode)
|
||||
{
|
||||
case D3D11_CULL_NONE:
|
||||
return xna::CullMode::None;
|
||||
case D3D11_CULL_FRONT:
|
||||
return xna::CullMode::CullClockwiseFace;
|
||||
case D3D11_CULL_BACK:
|
||||
return xna::CullMode::CullCounterClockwiseFace;
|
||||
default:
|
||||
return xna::CullMode::None;
|
||||
}
|
||||
return static_cast<xna::CullMode>(static_cast<int>(dxDescription.CullMode) - 1);
|
||||
}
|
||||
|
||||
virtual constexpr void CullMode(xna::CullMode value) override {
|
||||
switch (value)
|
||||
{
|
||||
case xna::CullMode::None:
|
||||
_description.CullMode = D3D11_CULL_NONE;
|
||||
break;
|
||||
case xna::CullMode::CullClockwiseFace:
|
||||
_description.CullMode = D3D11_CULL_FRONT;
|
||||
break;
|
||||
case xna::CullMode::CullCounterClockwiseFace:
|
||||
_description.CullMode = D3D11_CULL_BACK;
|
||||
break;
|
||||
default:
|
||||
_description.CullMode = D3D11_CULL_NONE;
|
||||
break;
|
||||
}
|
||||
dxDescription.CullMode = static_cast<D3D11_CULL_MODE>(static_cast<int>(value) + 1);
|
||||
}
|
||||
|
||||
virtual constexpr xna::FillMode FillMode() const override {
|
||||
switch (_description.FillMode) {
|
||||
case D3D11_FILL_SOLID:
|
||||
return xna::FillMode::Solid;
|
||||
case D3D11_FILL_WIREFRAME:
|
||||
return xna::FillMode::WireFrame;
|
||||
default:
|
||||
return xna::FillMode::Solid;
|
||||
}
|
||||
return static_cast<xna::FillMode>(static_cast<int>(dxDescription.FillMode) - 2);
|
||||
}
|
||||
|
||||
virtual constexpr void FillMode(xna::FillMode value) override {
|
||||
switch (value)
|
||||
{
|
||||
case xna::FillMode::Solid:
|
||||
_description.FillMode = D3D11_FILL_SOLID;
|
||||
break;
|
||||
case xna::FillMode::WireFrame:
|
||||
_description.FillMode = D3D11_FILL_WIREFRAME;
|
||||
break;
|
||||
default:
|
||||
_description.FillMode = D3D11_FILL_SOLID;
|
||||
break;
|
||||
}
|
||||
dxDescription.FillMode = static_cast<D3D11_FILL_MODE>(static_cast<int>(value) + 2);
|
||||
}
|
||||
|
||||
static PRasterizerState CullNone() {
|
||||
auto raster = New<RasterizerState>();
|
||||
raster->_description.FillMode = D3D11_FILL_SOLID;
|
||||
raster->_description.CullMode = D3D11_CULL_MODE::D3D11_CULL_NONE;
|
||||
raster->_description.DepthClipEnable = true;
|
||||
return raster;
|
||||
}
|
||||
|
||||
static PRasterizerState CullClockwise() {
|
||||
auto raster = New<RasterizerState>();
|
||||
raster->_description.FillMode = D3D11_FILL_SOLID;
|
||||
raster->_description.CullMode = D3D11_CULL_MODE::D3D11_CULL_FRONT;
|
||||
raster->_description.DepthClipEnable = true;
|
||||
return raster;
|
||||
}
|
||||
|
||||
static PRasterizerState CullCounterClockwise() {
|
||||
auto raster = New<RasterizerState>();
|
||||
raster->_description.FillMode = D3D11_FILL_SOLID;
|
||||
raster->_description.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK;
|
||||
raster->_description.DepthClipEnable = true;
|
||||
return raster;
|
||||
}
|
||||
static uptr<RasterizerState> CullNone();
|
||||
static uptr<RasterizerState> CullClockwise();
|
||||
static uptr<RasterizerState> CullCounterClockwise();
|
||||
|
||||
public:
|
||||
ID3D11RasterizerState* _rasterizerState = nullptr;
|
||||
D3D11_RASTERIZER_DESC _description{};
|
||||
ID3D11RasterizerState* dxRasterizerState = nullptr;
|
||||
D3D11_RASTERIZER_DESC dxDescription{};
|
||||
|
||||
private:
|
||||
RasterizerState() : GraphicsResource(nullptr){}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -68,36 +68,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
virtual constexpr void Comparison(ComparisonFunction value) override {
|
||||
switch (value)
|
||||
{
|
||||
case xna::ComparisonFunction::Never:
|
||||
_description.ComparisonFunc = D3D11_COMPARISON_NEVER;
|
||||
break;
|
||||
case xna::ComparisonFunction::Less:
|
||||
_description.ComparisonFunc = D3D11_COMPARISON_LESS;
|
||||
break;
|
||||
case xna::ComparisonFunction::Equal:
|
||||
_description.ComparisonFunc = D3D11_COMPARISON_EQUAL;
|
||||
break;
|
||||
case xna::ComparisonFunction::LessEquals:
|
||||
_description.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
|
||||
break;
|
||||
case xna::ComparisonFunction::Greater:
|
||||
_description.ComparisonFunc = D3D11_COMPARISON_GREATER;
|
||||
break;
|
||||
case xna::ComparisonFunction::NotEqual:
|
||||
_description.ComparisonFunc = D3D11_COMPARISON_NOT_EQUAL;
|
||||
break;
|
||||
case xna::ComparisonFunction::GreaterEqual:
|
||||
_description.ComparisonFunc = D3D11_COMPARISON_GREATER_EQUAL;
|
||||
break;
|
||||
case xna::ComparisonFunction::Always:
|
||||
_description.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
|
||||
break;
|
||||
default:
|
||||
_description.ComparisonFunc = D3D11_COMPARISON_NEVER;
|
||||
break;
|
||||
}
|
||||
_description.ComparisonFunc = static_cast<D3D11_COMPARISON_FUNC>(static_cast<int>(value) + 1);
|
||||
}
|
||||
|
||||
virtual constexpr void MipLODBias(float value) override {
|
||||
@ -161,27 +132,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
virtual ComparisonFunction Comparison() const override {
|
||||
switch (_description.ComparisonFunc)
|
||||
{
|
||||
case D3D11_COMPARISON_NEVER :
|
||||
return xna::ComparisonFunction::Never;
|
||||
case D3D11_COMPARISON_LESS:
|
||||
return xna::ComparisonFunction::Less;
|
||||
case D3D11_COMPARISON_EQUAL:
|
||||
return xna::ComparisonFunction::Equal;
|
||||
case D3D11_COMPARISON_LESS_EQUAL:
|
||||
return xna::ComparisonFunction::LessEquals;
|
||||
case D3D11_COMPARISON_GREATER:
|
||||
return xna::ComparisonFunction::Greater;
|
||||
case D3D11_COMPARISON_NOT_EQUAL:
|
||||
return xna::ComparisonFunction::NotEqual;
|
||||
case D3D11_COMPARISON_GREATER_EQUAL:
|
||||
return xna::ComparisonFunction::GreaterEqual;
|
||||
case D3D11_COMPARISON_ALWAYS:
|
||||
return xna::ComparisonFunction::Always;
|
||||
default:
|
||||
return xna::ComparisonFunction::Never;
|
||||
}
|
||||
return static_cast<ComparisonFunction>(_description.ComparisonFunc - 1);
|
||||
}
|
||||
|
||||
virtual constexpr float MipLODBias() const override {
|
||||
@ -206,46 +157,11 @@ namespace xna {
|
||||
|
||||
public:
|
||||
static constexpr void ConvertAddressMode(TextureAddressMode value, D3D11_TEXTURE_ADDRESS_MODE& target) {
|
||||
switch (value)
|
||||
{
|
||||
case xna::TextureAddressMode::Wrap:
|
||||
target = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
break;
|
||||
case xna::TextureAddressMode::Clamp:
|
||||
target = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
break;
|
||||
case xna::TextureAddressMode::Mirror:
|
||||
target = D3D11_TEXTURE_ADDRESS_MIRROR;
|
||||
break;
|
||||
case xna::TextureAddressMode::Border:
|
||||
target = D3D11_TEXTURE_ADDRESS_BORDER;
|
||||
break;
|
||||
case xna::TextureAddressMode::MirrorOnce:
|
||||
target = D3D11_TEXTURE_ADDRESS_MIRROR_ONCE;
|
||||
break;
|
||||
default:
|
||||
target = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
break;
|
||||
}
|
||||
target = static_cast<D3D11_TEXTURE_ADDRESS_MODE>(static_cast<int>(value) + 1);
|
||||
}
|
||||
|
||||
static constexpr void ConvertAddressMode(D3D11_TEXTURE_ADDRESS_MODE value, TextureAddressMode& target) {
|
||||
switch (value)
|
||||
{
|
||||
case D3D11_TEXTURE_ADDRESS_WRAP:
|
||||
target = TextureAddressMode::Wrap;
|
||||
case D3D11_TEXTURE_ADDRESS_CLAMP:
|
||||
target = TextureAddressMode::Clamp;
|
||||
case D3D11_TEXTURE_ADDRESS_MIRROR:
|
||||
target = TextureAddressMode::Mirror;
|
||||
case D3D11_TEXTURE_ADDRESS_BORDER:
|
||||
target = TextureAddressMode::Border;
|
||||
case D3D11_TEXTURE_ADDRESS_MIRROR_ONCE:
|
||||
target = TextureAddressMode::MirrorOnce;
|
||||
default:
|
||||
target = TextureAddressMode::Wrap;
|
||||
break;
|
||||
}
|
||||
target = static_cast<TextureAddressMode>(value - 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -47,9 +47,9 @@ namespace xna {
|
||||
return hr;
|
||||
}
|
||||
|
||||
bool VertexShader::Initialize(GraphicsDevice& device, DataBuffer& buffer, xna_error_ptr_arg)
|
||||
bool VertexShader::Initialize(DataBuffer& buffer, xna_error_ptr_arg)
|
||||
{
|
||||
if (!device._device || !buffer._blob) {
|
||||
if (!m_device || !m_device->_device || !buffer._blob) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -59,7 +59,7 @@ namespace xna {
|
||||
_vertexShader = nullptr;
|
||||
}
|
||||
|
||||
const auto hr = device._device->CreateVertexShader(
|
||||
const auto hr = m_device->_device->CreateVertexShader(
|
||||
buffer._blob->GetBufferPointer(),
|
||||
buffer._blob->GetBufferSize(),
|
||||
NULL,
|
||||
@ -73,9 +73,9 @@ namespace xna {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PixelShader::Initialize(GraphicsDevice& device, DataBuffer& buffer, xna_error_ptr_arg)
|
||||
bool PixelShader::Initialize(DataBuffer& buffer, xna_error_ptr_arg)
|
||||
{
|
||||
if (!device._device || !buffer._blob) {
|
||||
if (!m_device || !m_device->_device || !buffer._blob) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -85,7 +85,7 @@ namespace xna {
|
||||
_pixelShader = nullptr;
|
||||
}
|
||||
|
||||
const auto hr = device._device->CreatePixelShader(
|
||||
const auto hr = m_device->_device->CreatePixelShader(
|
||||
buffer._blob->GetBufferPointer(),
|
||||
buffer._blob->GetBufferSize(),
|
||||
NULL,
|
||||
|
@ -2,23 +2,24 @@
|
||||
#define XNA_PLATFORM_SHADER_DX_HPP
|
||||
|
||||
#include "../graphics/shader.hpp"
|
||||
#include "../graphics/gresource.hpp"
|
||||
#include "dxheaders.hpp"
|
||||
|
||||
namespace xna {
|
||||
class Shader : public IShader {
|
||||
class Shader : public IShader, public GraphicsResource {
|
||||
public:
|
||||
Shader() = default;
|
||||
Shader(GraphicsDevice* device) : GraphicsResource(device){}
|
||||
|
||||
virtual ~Shader() override {}
|
||||
|
||||
virtual bool Initialize(GraphicsDevice& device, DataBuffer& buffer, xna_error_nullarg) override {}
|
||||
virtual bool Initialize(DataBuffer& buffer, xna_error_nullarg) override {}
|
||||
|
||||
static HRESULT CompileFromFile(_In_ LPCWSTR srcFile, _In_ LPCSTR entryPoint, _In_ LPCSTR profile, _Outptr_ ID3DBlob** blob);
|
||||
};
|
||||
|
||||
class VertexShader : public Shader {
|
||||
public:
|
||||
VertexShader() = default;
|
||||
VertexShader(GraphicsDevice* device) : Shader(device){}
|
||||
|
||||
virtual ~VertexShader() override {
|
||||
if (_vertexShader) {
|
||||
@ -27,7 +28,7 @@ namespace xna {
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool Initialize(GraphicsDevice& device, DataBuffer& buffer, xna_error_nullarg) override;
|
||||
virtual bool Initialize(DataBuffer& buffer, xna_error_nullarg) override;
|
||||
|
||||
public:
|
||||
ID3D11VertexShader* _vertexShader = nullptr;
|
||||
@ -35,7 +36,7 @@ namespace xna {
|
||||
|
||||
class PixelShader : public Shader {
|
||||
public:
|
||||
PixelShader() = default;
|
||||
PixelShader(GraphicsDevice* device) : Shader(device) {}
|
||||
|
||||
virtual ~PixelShader() override {
|
||||
if (_pixelShader) {
|
||||
@ -44,7 +45,7 @@ namespace xna {
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool Initialize(GraphicsDevice& device, DataBuffer& buffer, xna_error_nullarg) override;
|
||||
virtual bool Initialize(DataBuffer& buffer, xna_error_nullarg) override;
|
||||
|
||||
public:
|
||||
ID3D11PixelShader* _pixelShader = nullptr;
|
||||
|
@ -17,6 +17,9 @@ using DirectX::GXMVECTOR;
|
||||
|
||||
namespace xna {
|
||||
SpriteBatch::SpriteBatch(GraphicsDevice& device) {
|
||||
if (!device._context)
|
||||
return;
|
||||
|
||||
_dxspriteBatch = New<DxSpriteBatch>(device._context);
|
||||
|
||||
Viewport(device.Viewport());
|
||||
@ -42,8 +45,8 @@ namespace xna {
|
||||
sort,
|
||||
blendState ? blendState->dxBlendState : nullptr,
|
||||
samplerState ? samplerState->_samplerState : nullptr,
|
||||
depthStencil ? depthStencil->_depthStencil : nullptr,
|
||||
rasterizerState ? rasterizerState->_rasterizerState : nullptr,
|
||||
depthStencil ? depthStencil->dxDepthStencil : nullptr,
|
||||
rasterizerState ? rasterizerState->dxRasterizerState : nullptr,
|
||||
nullptr,
|
||||
matrix
|
||||
);
|
||||
|
@ -44,27 +44,7 @@ namespace xna {
|
||||
|
||||
public:
|
||||
static constexpr void ConvertSpriteSort(SpriteSortMode value, DirectX::SpriteSortMode& target) {
|
||||
switch (value)
|
||||
{
|
||||
case xna::SpriteSortMode::Deferred:
|
||||
target = DirectX::SpriteSortMode_Deferred;
|
||||
break;
|
||||
case xna::SpriteSortMode::Immediate:
|
||||
target = DirectX::SpriteSortMode_Immediate;
|
||||
break;
|
||||
case xna::SpriteSortMode::Texture:
|
||||
target = DirectX::SpriteSortMode_Texture;
|
||||
break;
|
||||
case xna::SpriteSortMode::BackToFront:
|
||||
target = DirectX::SpriteSortMode_BackToFront;
|
||||
break;
|
||||
case xna::SpriteSortMode::FrontToBack:
|
||||
target = DirectX::SpriteSortMode_FrontToBack;
|
||||
break;
|
||||
default:
|
||||
target = DirectX::SpriteSortMode_Deferred;
|
||||
break;
|
||||
}
|
||||
target = static_cast<DirectX::SpriteSortMode>(static_cast<int>(value));
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -37,7 +37,12 @@ namespace xna {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SwapChain::Initialize(GraphicsDevice& device, GameWindow const& gameWindow) {
|
||||
bool SwapChain::Initialize(GameWindow const& gameWindow, xna_error_ptr_arg) {
|
||||
if (!m_device || !m_device->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto bounds = gameWindow.ClientBounds();
|
||||
|
||||
dxDescription.Width = static_cast<UINT>(bounds.Width);
|
||||
@ -56,14 +61,19 @@ namespace xna {
|
||||
dxFullScreenDescription.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
|
||||
dxFullScreenDescription.Windowed = gameWindow.Mode() != GameWindowMode::Fullscreen;
|
||||
|
||||
return internalInit(device, gameWindow, dxSwapChain, dxDescription, dxFullScreenDescription);
|
||||
return internalInit(*m_device, gameWindow, dxSwapChain, dxDescription, dxFullScreenDescription);
|
||||
}
|
||||
|
||||
bool SwapChain::Initialize(GraphicsDevice& device, GameWindow const& gameWindow, DXGI_SWAP_CHAIN_DESC1 const& desc, DXGI_SWAP_CHAIN_FULLSCREEN_DESC const& fullScreenDesc)
|
||||
bool SwapChain::Initialize(GameWindow const& gameWindow, DXGI_SWAP_CHAIN_DESC1 const& desc, DXGI_SWAP_CHAIN_FULLSCREEN_DESC const& fullScreenDesc, xna_error_ptr_arg)
|
||||
{
|
||||
if (!m_device || !m_device->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
dxDescription = desc;
|
||||
dxFullScreenDescription = fullScreenDesc;
|
||||
return internalInit(device, gameWindow, dxSwapChain, dxDescription, dxFullScreenDescription);
|
||||
return internalInit(*m_device, gameWindow, dxSwapChain, dxDescription, dxFullScreenDescription);
|
||||
}
|
||||
|
||||
bool SwapChain::GetBackBuffer(ID3D11Texture2D*& texture2D) {
|
||||
|
@ -4,10 +4,13 @@
|
||||
#include "../graphics/swapchain.hpp"
|
||||
#include "window-dx.hpp"
|
||||
#include "dxheaders.hpp"
|
||||
#include "../graphics/gresource.hpp"
|
||||
|
||||
namespace xna {
|
||||
class SwapChain : public ISwapChain{
|
||||
class SwapChain : public ISwapChain, public GraphicsResource {
|
||||
public:
|
||||
SwapChain(GraphicsDevice* device): GraphicsResource(device){}
|
||||
|
||||
virtual ~SwapChain() override {
|
||||
if (dxSwapChain) {
|
||||
dxSwapChain->Release();
|
||||
@ -15,8 +18,8 @@ namespace xna {
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool Initialize(GraphicsDevice& device, GameWindow const& gameWindow) override;
|
||||
bool Initialize(GraphicsDevice& device, GameWindow const& gameWindow, DXGI_SWAP_CHAIN_DESC1 const& desc, DXGI_SWAP_CHAIN_FULLSCREEN_DESC const& fullScreenDesc);
|
||||
virtual bool Initialize(GameWindow const& gameWindow, xna_error_nullarg) override;
|
||||
bool Initialize(GameWindow const& gameWindow, DXGI_SWAP_CHAIN_DESC1 const& desc, DXGI_SWAP_CHAIN_FULLSCREEN_DESC const& fullScreenDesc, xna_error_nullarg);
|
||||
|
||||
bool GetBackBuffer(ID3D11Texture2D*& texture2D);
|
||||
|
||||
|
@ -26,18 +26,6 @@ namespace xna {
|
||||
|
||||
XnaErrorCode err;
|
||||
texture = Texture2D::FromStream(*_graphicsDevice, "D:\\sprite.jpg", &err);
|
||||
|
||||
std::vector<VertexPositionColor> data(3);
|
||||
data[0] = VertexPositionColor(Vector3(0.0F, 0.5F, 0.5F), Colors::AliceBlue);
|
||||
data[0] = VertexPositionColor(Vector3(0.5F, -0.5F, 0.5F), Colors::Red);
|
||||
data[0] = VertexPositionColor(Vector3(-0.5F, -0.5F, 0.5F), Colors::AliceBlue);
|
||||
|
||||
VertexBuffer<VertexPositionColor> vbuffer(_graphicsDevice.get(), data);
|
||||
vbuffer.Initialize(&err);
|
||||
|
||||
D3D11_BUFFER_DESC desc;
|
||||
vbuffer.dxBuffer->GetDesc(&desc);
|
||||
|
||||
|
||||
Game::LoadContent();
|
||||
}
|
||||
|
@ -11,7 +11,8 @@ namespace xna {
|
||||
OVERFLOW_OPERATION,
|
||||
NULL_CAST,
|
||||
BAD_CAST,
|
||||
STREAM_ERROR
|
||||
STREAM_ERROR,
|
||||
UNINTIALIZED_RESOURCE
|
||||
};
|
||||
|
||||
inline void xna_error_apply(XnaErrorCode* source, XnaErrorCode const& value) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user