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

Implementa RasterizerState

This commit is contained in:
Danilo 2024-04-10 09:51:03 -03:00
parent 66d0aecffe
commit 451d48f020
7 changed files with 168 additions and 11 deletions

View File

@ -3,7 +3,7 @@
#
# Add source to this project's executable.
add_executable (xna WIN32 "xna.cpp" "xna.h" "platform/window-dx.cpp" "platform/device-dx.cpp" "platform/adapter-dx.cpp" "platform/swapchain-dx.cpp" "platform/rendertarget-dx.cpp" "platform/texture-dx.cpp" "platform/blendstate-dx.cpp" "platform/game-dx.cpp" "platform/clock-dx.cpp" "csharp/stream.cpp" "platform/gdevicemanager-dx.cpp" "platform/vertexinput-dx.cpp" "platform/shader-dx.cpp")
add_executable (xna WIN32 "xna.cpp" "xna.h" "platform/window-dx.cpp" "platform/device-dx.cpp" "platform/adapter-dx.cpp" "platform/swapchain-dx.cpp" "platform/rendertarget-dx.cpp" "platform/texture-dx.cpp" "platform/blendstate-dx.cpp" "platform/game-dx.cpp" "platform/clock-dx.cpp" "csharp/stream.cpp" "platform/gdevicemanager-dx.cpp" "platform/vertexinput-dx.cpp" "platform/shader-dx.cpp" "platform/rasterizer-dx.cpp")
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET xna PROPERTY CXX_STANDARD 20)

View File

@ -20,15 +20,7 @@ namespace xna {
InverseSource1Color,
Source1Alpha,
InverseSource1Alpha
};
enum class ColorWriteChannels {
Red,
Green,
Blue,
Alpha,
All
};
};
enum class BlendFunction {
Add = 0,
@ -40,6 +32,20 @@ namespace xna {
using BlendOperation = BlendFunction;
enum class ColorWriteChannels {
Red,
Green,
Blue,
Alpha,
All
};
enum class CullMode {
None,
CullClockwiseFace,
CullCounterClockwiseFace,
};
enum class DepthFormat {
None,
Depth16,
@ -54,6 +60,12 @@ namespace xna {
Portrait = 4,
};
enum class FillMode
{
Solid,
WireFrame,
};
enum class GraphicsProfile {
Reach,
HiDef

View File

@ -99,6 +99,8 @@ namespace xna {
using PTexture = std::shared_ptr<Texture>;
class Texture2D;
using PTexture2D = std::shared_ptr<Texture2D>;
class RasterizerState;
using PRasterizerState = std::shared_ptr<RasterizerState>;
class Shader;
using PShader = std::shared_ptr<Shader>;
class VertexInputLayout;

View File

@ -0,0 +1,18 @@
#ifndef XNA_GRAPHICS_RASTERIZER_HPP
#define XNA_GRAPHICS_RASTERIZER_HPP
#include "../default.hpp"
namespace xna {
class IRasterizerState {
public:
virtual ~IRasterizerState() {}
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) = 0;
virtual xna::CullMode CullMode() const = 0;
virtual void CullMode(xna::CullMode value) = 0;
virtual xna::FillMode FillMode() const = 0;
virtual void FillMode(xna::FillMode value) = 0;
};
}
#endif

View File

@ -0,0 +1,16 @@
#include "rasterizer-dx.hpp"
#include "device-dx.hpp"
namespace xna {
bool RasterizerState::Initialize(GraphicsDevice& device, xna_error_ptr_arg)
{
const auto hr = device._device->CreateRasterizerState(&_description, &_rasterizerState);
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return false;
}
return true;
}
}

View File

@ -0,0 +1,109 @@
#ifndef XNA_PLATFORM_RASTERIZER_DX_HPP
#define XNA_PLATFORM_RASTERIZER_DX_HPP
#include "../graphics/rasterizer.hpp"
#include "dxheaders.hpp"
namespace xna {
class RasterizerState : public IRasterizerState {
public:
RasterizerState(){}
virtual ~RasterizerState() override {
if (_rasterizerState) {
_rasterizerState->Release();
_rasterizerState = nullptr;
}
}
virtual bool Initialize(GraphicsDevice& device, 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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
public:
ID3D11RasterizerState* _rasterizerState = nullptr;
D3D11_RASTERIZER_DESC _description{};
};
}
#endif

View File

@ -13,7 +13,7 @@ namespace xna {
const auto hr = _device->_device->CreateInputLayout(
_description.data(),
_description.size(),
static_cast<UINT>(_description.size()),
blob->GetBufferPointer(),
blob->GetBufferSize(),
&_inputLayout);