mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Corrige SamplerState
This commit is contained in:
parent
20c29b4c3c
commit
a29d9d2790
@ -4,9 +4,13 @@
|
|||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
|
|
||||||
RasterizerState::RasterizerState() : GraphicsResource(nullptr){}
|
RasterizerState::RasterizerState() : GraphicsResource(nullptr){
|
||||||
|
impl = unew<PlatformImplementation>();
|
||||||
|
}
|
||||||
|
|
||||||
RasterizerState::RasterizerState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {}
|
RasterizerState::RasterizerState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
|
||||||
|
impl = unew<PlatformImplementation>();
|
||||||
|
}
|
||||||
|
|
||||||
RasterizerState::~RasterizerState() {
|
RasterizerState::~RasterizerState() {
|
||||||
impl = nullptr;
|
impl = nullptr;
|
||||||
@ -19,6 +23,11 @@ namespace xna {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (impl->dxRasterizerState) {
|
||||||
|
impl->dxRasterizerState->Release();
|
||||||
|
impl->dxRasterizerState = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
const auto hr = m_device->_device->CreateRasterizerState(
|
const auto hr = m_device->_device->CreateRasterizerState(
|
||||||
&impl->dxDescription,
|
&impl->dxDescription,
|
||||||
&impl->dxRasterizerState);
|
&impl->dxRasterizerState);
|
||||||
|
@ -1,90 +1,37 @@
|
|||||||
#include "platform-dx/samplerstate-dx.hpp"
|
#include "graphics/samplerstate.hpp"
|
||||||
#include "platform-dx/device-dx.hpp"
|
#include "platform-dx/device-dx.hpp"
|
||||||
|
#include "graphics/samplerstate.hpp"
|
||||||
|
#include "platform-dx/implementations.hpp"
|
||||||
|
#include "platform-dx/dxhelpers.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
bool SamplerState::Apply(xna_error_ptr_arg)
|
SamplerState::SamplerState() : GraphicsResource(nullptr) {
|
||||||
{
|
impl = unew<PlatformImplementation>();
|
||||||
if (!m_device || !m_device->_context) {
|
|
||||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_samplerState) {
|
|
||||||
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_device->_context->PSSetSamplers(0, 1, &_samplerState);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
uptr<SamplerState> SamplerState::PoinWrap() {
|
|
||||||
auto state = std::unique_ptr<SamplerState>(new SamplerState());
|
|
||||||
state->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
|
|
||||||
state->_description.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
||||||
state->_description.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
||||||
state->_description.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uptr<SamplerState> SamplerState::PointClamp() {
|
SamplerState::SamplerState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
|
||||||
auto state = std::unique_ptr<SamplerState>(new SamplerState());
|
impl = unew<PlatformImplementation>();
|
||||||
state->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
|
|
||||||
state->_description.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
||||||
state->_description.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
||||||
state->_description.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uptr<SamplerState> SamplerState::LinearWrap() {
|
SamplerState::~SamplerState() {
|
||||||
auto state = std::unique_ptr<SamplerState>(new SamplerState());
|
impl = nullptr;
|
||||||
state->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
|
||||||
state->_description.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
||||||
state->_description.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
||||||
state->_description.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
uptr<SamplerState> SamplerState::LinearClamp() {
|
|
||||||
auto state = std::unique_ptr<SamplerState>(new SamplerState());
|
|
||||||
state->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
|
||||||
state->_description.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
||||||
state->_description.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
||||||
state->_description.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
uptr<SamplerState> SamplerState::AnisotropicWrap() {
|
|
||||||
auto state = std::unique_ptr<SamplerState>(new SamplerState());
|
|
||||||
state->_description.Filter = D3D11_FILTER_ANISOTROPIC;
|
|
||||||
state->_description.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
||||||
state->_description.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
||||||
state->_description.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
uptr<SamplerState> SamplerState::AnisotropicClamp() {
|
|
||||||
auto state = std::unique_ptr<SamplerState>(new SamplerState());
|
|
||||||
state->_description.Filter = D3D11_FILTER_ANISOTROPIC;
|
|
||||||
state->_description.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
||||||
state->_description.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
||||||
state->_description.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SamplerState::Initialize(xna_error_ptr_arg)
|
bool SamplerState::Initialize(xna_error_ptr_arg)
|
||||||
{
|
{
|
||||||
if (!m_device || !m_device->_device) {
|
if (!impl || !m_device || !m_device->_device) {
|
||||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_samplerState) {
|
if (impl->_samplerState) {
|
||||||
_samplerState->Release();
|
impl->_samplerState->Release();
|
||||||
_samplerState = nullptr;
|
impl->_samplerState = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto hr = m_device->_device->CreateSamplerState(&_description, &_samplerState);
|
const auto hr = m_device->_device->CreateSamplerState(
|
||||||
|
&impl->_description,
|
||||||
|
&impl->_samplerState);
|
||||||
|
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||||
@ -93,4 +40,205 @@ namespace xna {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SamplerState::Apply(xna_error_ptr_arg)
|
||||||
|
{
|
||||||
|
if (!impl || !m_device || !m_device->_context) {
|
||||||
|
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!impl->_samplerState) {
|
||||||
|
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_device->_context->PSSetSamplers(0, 1, &impl->_samplerState);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
uptr<SamplerState> SamplerState::PoinWrap() {
|
||||||
|
auto state = unew<SamplerState>();
|
||||||
|
state->impl->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
|
||||||
|
state->impl->_description.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||||
|
state->impl->_description.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||||
|
state->impl->_description.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
uptr<SamplerState> SamplerState::PointClamp() {
|
||||||
|
auto state = unew<SamplerState>();
|
||||||
|
state->impl->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
|
||||||
|
state->impl->_description.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
|
state->impl->_description.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
|
state->impl->_description.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
uptr<SamplerState> SamplerState::LinearWrap() {
|
||||||
|
auto state = unew<SamplerState>();
|
||||||
|
state->impl->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||||
|
state->impl->_description.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||||
|
state->impl->_description.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||||
|
state->impl->_description.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
uptr<SamplerState> SamplerState::LinearClamp() {
|
||||||
|
auto state = unew<SamplerState>();
|
||||||
|
state->impl->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||||
|
state->impl->_description.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
|
state->impl->_description.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
|
state->impl->_description.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
uptr<SamplerState> SamplerState::AnisotropicWrap() {
|
||||||
|
auto state = unew<SamplerState>();
|
||||||
|
state->impl->_description.Filter = D3D11_FILTER_ANISOTROPIC;
|
||||||
|
state->impl->_description.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||||
|
state->impl->_description.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||||
|
state->impl->_description.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
uptr<SamplerState> SamplerState::AnisotropicClamp() {
|
||||||
|
auto state = unew<SamplerState>();
|
||||||
|
state->impl->_description.Filter = D3D11_FILTER_ANISOTROPIC;
|
||||||
|
state->impl->_description.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
|
state->impl->_description.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
|
state->impl->_description.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SamplerState::Filter(TextureFilter value) {
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case xna::TextureFilter::Linear:
|
||||||
|
impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||||
|
break;
|
||||||
|
case xna::TextureFilter::Point:
|
||||||
|
impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_MIP_POINT;
|
||||||
|
break;
|
||||||
|
case xna::TextureFilter::Anisotropic:
|
||||||
|
impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_ANISOTROPIC;
|
||||||
|
break;
|
||||||
|
case xna::TextureFilter::LinearMipPoint:
|
||||||
|
impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
|
||||||
|
break;
|
||||||
|
case xna::TextureFilter::PointMipLinear:
|
||||||
|
impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR;
|
||||||
|
break;
|
||||||
|
case xna::TextureFilter::MinLinearMagPointMipLinear:
|
||||||
|
impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
|
||||||
|
break;
|
||||||
|
case xna::TextureFilter::MinLinearMagPointMipPoint:
|
||||||
|
impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT;
|
||||||
|
break;
|
||||||
|
case xna::TextureFilter::MinPointMagLinearMipLinear:
|
||||||
|
impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
|
||||||
|
break;
|
||||||
|
case xna::TextureFilter::MinPointMagLinearMipPoint:
|
||||||
|
impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SamplerState::AddressU(TextureAddressMode value) {
|
||||||
|
DxHelpers::ConvertAddressMode(value, impl->_description.AddressU);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SamplerState::AddressV(TextureAddressMode value) {
|
||||||
|
DxHelpers::ConvertAddressMode(value, impl->_description.AddressV);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SamplerState::AddressW(TextureAddressMode value) {
|
||||||
|
DxHelpers::ConvertAddressMode(value, impl->_description.AddressW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SamplerState::Comparison(ComparisonFunction value) {
|
||||||
|
impl->_description.ComparisonFunc = static_cast<D3D11_COMPARISON_FUNC>(static_cast<int>(value) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SamplerState::MipLODBias(float value) {
|
||||||
|
impl->_description.MipLODBias = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SamplerState::MinLOD(float value) {
|
||||||
|
impl->_description.MinLOD = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SamplerState::MaxLOD(float value) {
|
||||||
|
impl->_description.MaxLOD = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SamplerState::MaxAnisotropy(Uint value) {
|
||||||
|
impl->_description.MaxAnisotropy = static_cast<UINT>(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureFilter SamplerState::Filter() const {
|
||||||
|
switch (impl->_description.Filter)
|
||||||
|
{
|
||||||
|
case D3D11_FILTER::D3D11_FILTER_MIN_MAG_MIP_LINEAR:
|
||||||
|
return xna::TextureFilter::Linear;
|
||||||
|
case D3D11_FILTER_MIN_MAG_MIP_POINT:
|
||||||
|
return xna::TextureFilter::Point;
|
||||||
|
case D3D11_FILTER_ANISOTROPIC:
|
||||||
|
return xna::TextureFilter::Anisotropic;
|
||||||
|
case D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT:
|
||||||
|
return xna::TextureFilter::LinearMipPoint;
|
||||||
|
case D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR:
|
||||||
|
return xna::TextureFilter::PointMipLinear;
|
||||||
|
case D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR:
|
||||||
|
return xna::TextureFilter::MinLinearMagPointMipLinear;
|
||||||
|
case D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT:
|
||||||
|
return xna::TextureFilter::MinLinearMagPointMipPoint;
|
||||||
|
case D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR:
|
||||||
|
return xna::TextureFilter::MinPointMagLinearMipLinear;
|
||||||
|
case D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT:
|
||||||
|
return xna::TextureFilter::MinPointMagLinearMipPoint;
|
||||||
|
default:
|
||||||
|
return xna::TextureFilter::Linear;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureAddressMode SamplerState::AddressU() const {
|
||||||
|
TextureAddressMode mode;
|
||||||
|
DxHelpers::ConvertAddressMode(impl->_description.AddressU, mode);
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureAddressMode SamplerState::AddressV() const {
|
||||||
|
TextureAddressMode mode;
|
||||||
|
DxHelpers::ConvertAddressMode(impl->_description.AddressV, mode);
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureAddressMode SamplerState::AddressW() const {
|
||||||
|
TextureAddressMode mode;
|
||||||
|
DxHelpers::ConvertAddressMode(impl->_description.AddressW, mode);
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
ComparisonFunction SamplerState::Comparison() const {
|
||||||
|
return static_cast<ComparisonFunction>(impl->_description.ComparisonFunc - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
float SamplerState::MipLODBias() const {
|
||||||
|
return impl->_description.MipLODBias;
|
||||||
|
}
|
||||||
|
|
||||||
|
float SamplerState::MinLOD() const {
|
||||||
|
return impl->_description.MinLOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
float SamplerState::MaxLOD() const {
|
||||||
|
return impl->_description.MaxLOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint SamplerState::MaxAnisotropy() const {
|
||||||
|
return impl->_description.MaxAnisotropy;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
#include "platform-dx/device-dx.hpp"
|
#include "platform-dx/device-dx.hpp"
|
||||||
#include "graphics/rasterizerstate.hpp"
|
#include "graphics/rasterizerstate.hpp"
|
||||||
#include "platform-dx/samplerstate-dx.hpp"
|
#include "graphics/samplerstate.hpp"
|
||||||
#include "platform-dx/texture-dx.hpp"
|
#include "platform-dx/texture-dx.hpp"
|
||||||
#include "common/color.hpp"
|
#include "common/color.hpp"
|
||||||
#include "common/numerics.hpp"
|
#include "common/numerics.hpp"
|
||||||
@ -79,7 +79,7 @@ namespace xna {
|
|||||||
implementation->_dxspriteBatch->Begin(
|
implementation->_dxspriteBatch->Begin(
|
||||||
sort,
|
sort,
|
||||||
blendState ? blendState->impl->dxBlendState : nullptr,
|
blendState ? blendState->impl->dxBlendState : nullptr,
|
||||||
samplerState ? samplerState->_samplerState : nullptr,
|
samplerState ? samplerState->impl->_samplerState : nullptr,
|
||||||
depthStencil ? depthStencil->impl->dxDepthStencil : nullptr,
|
depthStencil ? depthStencil->impl->dxDepthStencil : nullptr,
|
||||||
rasterizerState ? rasterizerState->impl->dxRasterizerState : nullptr,
|
rasterizerState ? rasterizerState->impl->dxRasterizerState : nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
|
@ -2,31 +2,45 @@
|
|||||||
#define XNA_GRAPHICS_SAMPLERSTATE_HPP
|
#define XNA_GRAPHICS_SAMPLERSTATE_HPP
|
||||||
|
|
||||||
#include "../default.hpp"
|
#include "../default.hpp"
|
||||||
|
#include "gresource.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
class ISamplerState {
|
class SamplerState : GraphicsResource {
|
||||||
public:
|
public:
|
||||||
virtual ~ISamplerState(){}
|
SamplerState();
|
||||||
virtual bool Initialize(xna_error_nullarg) = 0;
|
SamplerState(sptr<GraphicsDevice> const& device);
|
||||||
virtual bool Apply(xna_error_nullarg) = 0;
|
~SamplerState();
|
||||||
virtual void Filter(TextureFilter value) = 0;
|
bool Initialize(xna_error_nullarg);
|
||||||
virtual void AddressU(TextureAddressMode value) = 0;
|
bool Apply(xna_error_nullarg);
|
||||||
virtual void AddressV(TextureAddressMode value) = 0;
|
void Filter(TextureFilter value);
|
||||||
virtual void AddressW(TextureAddressMode value) = 0;
|
void AddressU(TextureAddressMode value);
|
||||||
virtual void Comparison(ComparisonFunction value) = 0;
|
void AddressV(TextureAddressMode value);
|
||||||
virtual void MipLODBias(float value) = 0;
|
void AddressW(TextureAddressMode value);
|
||||||
virtual void MinLOD(float value) = 0;
|
void Comparison(ComparisonFunction value);
|
||||||
virtual void MaxLOD(float value) = 0;
|
void MipLODBias(float value);
|
||||||
virtual void MaxAnisotropy(Uint value) = 0;
|
void MinLOD(float value);
|
||||||
virtual TextureFilter Filter() const = 0;
|
void MaxLOD(float value);
|
||||||
virtual TextureAddressMode AddressU() const = 0;
|
void MaxAnisotropy(Uint value);
|
||||||
virtual TextureAddressMode AddressV() const = 0;
|
TextureFilter Filter() const;
|
||||||
virtual TextureAddressMode AddressW() const = 0;
|
TextureAddressMode AddressU() const;
|
||||||
virtual ComparisonFunction Comparison() const = 0;
|
TextureAddressMode AddressV() const;
|
||||||
virtual float MipLODBias() const = 0;
|
TextureAddressMode AddressW() const;
|
||||||
virtual float MinLOD() const = 0;
|
ComparisonFunction Comparison() const;
|
||||||
virtual float MaxLOD() const = 0;
|
float MipLODBias() const;
|
||||||
virtual Uint MaxAnisotropy() const = 0;
|
float MinLOD() const;
|
||||||
|
float MaxLOD() const;
|
||||||
|
Uint MaxAnisotropy() const;
|
||||||
|
|
||||||
|
static uptr<SamplerState> PoinWrap();
|
||||||
|
static uptr<SamplerState> PointClamp();
|
||||||
|
static uptr<SamplerState> LinearWrap();
|
||||||
|
static uptr<SamplerState> LinearClamp();
|
||||||
|
static uptr<SamplerState> AnisotropicWrap();
|
||||||
|
static uptr<SamplerState> AnisotropicClamp();
|
||||||
|
|
||||||
|
public:
|
||||||
|
struct PlatformImplementation;
|
||||||
|
uptr<PlatformImplementation> impl = nullptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,5 +161,13 @@ namespace xna {
|
|||||||
return D3D11_COLOR_WRITE_ENABLE_ALL;
|
return D3D11_COLOR_WRITE_ENABLE_ALL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static constexpr void ConvertAddressMode(TextureAddressMode value, D3D11_TEXTURE_ADDRESS_MODE& target) {
|
||||||
|
target = static_cast<D3D11_TEXTURE_ADDRESS_MODE>(static_cast<int>(value) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr void ConvertAddressMode(D3D11_TEXTURE_ADDRESS_MODE value, TextureAddressMode& target) {
|
||||||
|
target = static_cast<TextureAddressMode>(value - 1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -6,6 +6,7 @@
|
|||||||
#include "graphics/device.hpp"
|
#include "graphics/device.hpp"
|
||||||
#include "graphics/displaymode.hpp"
|
#include "graphics/displaymode.hpp"
|
||||||
#include "graphics/sprite.hpp"
|
#include "graphics/sprite.hpp"
|
||||||
|
#include "graphics/samplerstate.hpp"
|
||||||
#include "input/gamepad.hpp"
|
#include "input/gamepad.hpp"
|
||||||
#include "input/keyboard.hpp"
|
#include "input/keyboard.hpp"
|
||||||
#include "input/mouse.hpp"
|
#include "input/mouse.hpp"
|
||||||
@ -214,4 +215,16 @@ namespace xna {
|
|||||||
ID3D11RasterizerState* dxRasterizerState = nullptr;
|
ID3D11RasterizerState* dxRasterizerState = nullptr;
|
||||||
D3D11_RASTERIZER_DESC dxDescription{};
|
D3D11_RASTERIZER_DESC dxDescription{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SamplerState::PlatformImplementation {
|
||||||
|
~PlatformImplementation() {
|
||||||
|
if (_samplerState) {
|
||||||
|
_samplerState->Release();
|
||||||
|
_samplerState = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ID3D11SamplerState* _samplerState = nullptr;
|
||||||
|
D3D11_SAMPLER_DESC _description{};
|
||||||
|
};
|
||||||
}
|
}
|
@ -1,181 +0,0 @@
|
|||||||
#ifndef XNA_PLATFORM_SAMPLERSTATE_DX_HPP
|
|
||||||
#define XNA_PLATFORM_SAMPLERSTATE_DX_HPP
|
|
||||||
|
|
||||||
#include "../graphics/samplerstate.hpp"
|
|
||||||
#include "../graphics/gresource.hpp"
|
|
||||||
#include "dxheaders.hpp"
|
|
||||||
|
|
||||||
namespace xna {
|
|
||||||
class SamplerState : public ISamplerState, public GraphicsResource {
|
|
||||||
public:
|
|
||||||
SamplerState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
|
|
||||||
_description.MaxAnisotropy = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~SamplerState() override {
|
|
||||||
if (_samplerState) {
|
|
||||||
_samplerState->Release();
|
|
||||||
_samplerState = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool Initialize(xna_error_nullarg) override;
|
|
||||||
virtual bool Apply(xna_error_nullarg) override;
|
|
||||||
|
|
||||||
virtual constexpr void Filter(TextureFilter value) override {
|
|
||||||
switch (value)
|
|
||||||
{
|
|
||||||
case xna::TextureFilter::Linear:
|
|
||||||
_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
|
||||||
break;
|
|
||||||
case xna::TextureFilter::Point:
|
|
||||||
_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_MIP_POINT;
|
|
||||||
break;
|
|
||||||
case xna::TextureFilter::Anisotropic:
|
|
||||||
_description.Filter = D3D11_FILTER::D3D11_FILTER_ANISOTROPIC;
|
|
||||||
break;
|
|
||||||
case xna::TextureFilter::LinearMipPoint:
|
|
||||||
_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
|
|
||||||
break;
|
|
||||||
case xna::TextureFilter::PointMipLinear:
|
|
||||||
_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR;
|
|
||||||
break;
|
|
||||||
case xna::TextureFilter::MinLinearMagPointMipLinear:
|
|
||||||
_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
|
|
||||||
break;
|
|
||||||
case xna::TextureFilter::MinLinearMagPointMipPoint:
|
|
||||||
_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT;
|
|
||||||
break;
|
|
||||||
case xna::TextureFilter::MinPointMagLinearMipLinear:
|
|
||||||
_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
|
|
||||||
break;
|
|
||||||
case xna::TextureFilter::MinPointMagLinearMipPoint:
|
|
||||||
_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr void AddressU(TextureAddressMode value) override {
|
|
||||||
ConvertAddressMode(value, _description.AddressU);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr void AddressV(TextureAddressMode value) override {
|
|
||||||
ConvertAddressMode(value, _description.AddressV);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr void AddressW(TextureAddressMode value) override {
|
|
||||||
ConvertAddressMode(value, _description.AddressW);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr void Comparison(ComparisonFunction value) override {
|
|
||||||
_description.ComparisonFunc = static_cast<D3D11_COMPARISON_FUNC>(static_cast<int>(value) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr void MipLODBias(float value) override {
|
|
||||||
_description.MipLODBias = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr void MinLOD(float value) override {
|
|
||||||
_description.MinLOD = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr void MaxLOD(float value) override {
|
|
||||||
_description.MaxLOD = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void MaxAnisotropy(Uint value) override {
|
|
||||||
_description.MaxAnisotropy = static_cast<UINT>(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr TextureFilter Filter() const override {
|
|
||||||
switch (_description.Filter)
|
|
||||||
{
|
|
||||||
case D3D11_FILTER::D3D11_FILTER_MIN_MAG_MIP_LINEAR:
|
|
||||||
return xna::TextureFilter::Linear;
|
|
||||||
case D3D11_FILTER_MIN_MAG_MIP_POINT:
|
|
||||||
return xna::TextureFilter::Point;
|
|
||||||
case D3D11_FILTER_ANISOTROPIC:
|
|
||||||
return xna::TextureFilter::Anisotropic;
|
|
||||||
case D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT:
|
|
||||||
return xna::TextureFilter::LinearMipPoint;
|
|
||||||
case D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR:
|
|
||||||
return xna::TextureFilter::PointMipLinear;
|
|
||||||
case D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR:
|
|
||||||
return xna::TextureFilter::MinLinearMagPointMipLinear;
|
|
||||||
case D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT:
|
|
||||||
return xna::TextureFilter::MinLinearMagPointMipPoint;
|
|
||||||
case D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR:
|
|
||||||
return xna::TextureFilter::MinPointMagLinearMipLinear;
|
|
||||||
case D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT:
|
|
||||||
return xna::TextureFilter::MinPointMagLinearMipPoint;
|
|
||||||
default:
|
|
||||||
return xna::TextureFilter::Linear;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr TextureAddressMode AddressU() const override {
|
|
||||||
TextureAddressMode mode;
|
|
||||||
ConvertAddressMode(_description.AddressU, mode);
|
|
||||||
return mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr TextureAddressMode AddressV() const override {
|
|
||||||
TextureAddressMode mode;
|
|
||||||
ConvertAddressMode(_description.AddressV, mode);
|
|
||||||
return mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr TextureAddressMode AddressW() const override {
|
|
||||||
TextureAddressMode mode;
|
|
||||||
ConvertAddressMode(_description.AddressW, mode);
|
|
||||||
return mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ComparisonFunction Comparison() const override {
|
|
||||||
return static_cast<ComparisonFunction>(_description.ComparisonFunc - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr float MipLODBias() const override {
|
|
||||||
return _description.MipLODBias;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr float MinLOD() const override {
|
|
||||||
return _description.MinLOD;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr float MaxLOD() const override {
|
|
||||||
return _description.MaxLOD;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual constexpr Uint MaxAnisotropy() const override {
|
|
||||||
return _description.MaxAnisotropy;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uptr<SamplerState> PoinWrap();
|
|
||||||
static uptr<SamplerState> PointClamp();
|
|
||||||
static uptr<SamplerState> LinearWrap();
|
|
||||||
static uptr<SamplerState> LinearClamp();
|
|
||||||
static uptr<SamplerState> AnisotropicWrap();
|
|
||||||
static uptr<SamplerState> AnisotropicClamp();
|
|
||||||
|
|
||||||
public:
|
|
||||||
ID3D11SamplerState* _samplerState = nullptr;
|
|
||||||
D3D11_SAMPLER_DESC _description{};
|
|
||||||
|
|
||||||
public:
|
|
||||||
static constexpr void ConvertAddressMode(TextureAddressMode value, D3D11_TEXTURE_ADDRESS_MODE& target) {
|
|
||||||
target = static_cast<D3D11_TEXTURE_ADDRESS_MODE>(static_cast<int>(value) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr void ConvertAddressMode(D3D11_TEXTURE_ADDRESS_MODE value, TextureAddressMode& target) {
|
|
||||||
target = static_cast<TextureAddressMode>(value - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
SamplerState() : GraphicsResource(nullptr) {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -8,7 +8,6 @@
|
|||||||
#include "gdevicemanager-dx.hpp"
|
#include "gdevicemanager-dx.hpp"
|
||||||
#include "init-dx.hpp"
|
#include "init-dx.hpp"
|
||||||
#include "rendertarget-dx.hpp"
|
#include "rendertarget-dx.hpp"
|
||||||
#include "samplerstate-dx.hpp"
|
|
||||||
#include "shader-dx.hpp"
|
#include "shader-dx.hpp"
|
||||||
#include "soundeffect-dx.hpp"
|
#include "soundeffect-dx.hpp"
|
||||||
#include "swapchain-dx.hpp"
|
#include "swapchain-dx.hpp"
|
||||||
|
@ -61,6 +61,16 @@ namespace xna {
|
|||||||
return std::make_unique<_Ty>(std::forward<_Types>(_Args)...);
|
return std::make_unique<_Ty>(std::forward<_Types>(_Args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class _Ty, class... _Types>
|
||||||
|
inline std::shared_ptr<_Ty> snew(_Types&&... _Args) {
|
||||||
|
return std::make_shared<_Ty>(std::forward<_Types>(_Args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Ty, class... _Types>
|
||||||
|
inline std::unique_ptr<_Ty> unew(_Types&&... _Args) {
|
||||||
|
return std::make_unique<_Ty>(std::forward<_Types>(_Args)...);
|
||||||
|
}
|
||||||
|
|
||||||
//See ref: https://en.cppreference.com/w/cpp/error/assert
|
//See ref: https://en.cppreference.com/w/cpp/error/assert
|
||||||
#define assertm(exp, msg) assert(((void)msg, exp))
|
#define assertm(exp, msg) assert(((void)msg, exp))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user