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

217 lines
5.4 KiB
C++
Raw Normal View History

2024-05-19 16:11:34 -03:00
#include "dxheaders.hpp"
2024-05-21 09:40:59 -03:00
#include "graphics/adapter.hpp"
2024-05-19 21:22:34 -03:00
#include "graphics/blendstate.hpp"
2024-05-21 09:40:59 -03:00
#include "graphics/buffer.hpp"
2024-05-20 10:29:20 -03:00
#include "graphics/depthstencilstate.hpp"
2024-05-21 09:40:59 -03:00
#include "graphics/device.hpp"
2024-05-20 11:51:32 -03:00
#include "graphics/displaymode.hpp"
2024-05-21 09:40:59 -03:00
#include "graphics/sprite.hpp"
#include "input/gamepad.hpp"
2024-05-21 17:24:43 -03:00
#include "input/keyboard.hpp"
2024-05-21 20:43:37 -03:00
#include "input/mouse.hpp"
2024-05-22 10:56:16 -03:00
#include "graphics/rasterizerstate.hpp"
2024-05-22 09:55:25 -03:00
#include "graphics/presentparams.hpp"
2024-05-21 09:40:59 -03:00
#include "platform-dx/rendertarget-dx.hpp"
#include "platform-dx/swapchain-dx.hpp"
2024-05-19 16:11:34 -03:00
namespace xna {
struct SpriteFont::PlatformImplementation {
sptr<DirectX::SpriteFont> _dxSpriteFont = nullptr;
};
struct SpriteBatch::PlatformImplementation {
sptr<DirectX::SpriteBatch> _dxspriteBatch = nullptr;
2024-05-19 17:52:27 -03:00
};
struct GraphicsAdapter::PlatformImplementation {
~PlatformImplementation(){
if (dxadapter) {
dxadapter->Release();
dxadapter = nullptr;
}
}
IDXGIAdapter1* dxadapter = nullptr;
private:
friend class GraphicsAdapter;
Uint _index{ 0 };
sptr<DisplayMode> _currentDisplayMode = nullptr;
public:
2024-05-20 10:41:40 -03:00
bool GetOutput(UINT slot, IDXGIOutput*& output);
2024-05-19 17:52:27 -03:00
};
2024-05-19 21:22:34 -03:00
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;
};
struct BlendState::PlatformImplementation {
~PlatformImplementation() {
if (dxBlendState) {
dxBlendState->Release();
dxBlendState = nullptr;
}
}
ID3D11BlendState* dxBlendState = nullptr;
D3D11_BLEND_DESC dxDescription{};
float blendFactor[4]{ 1.0F, 1.0F, 1.0F, 1.0F };
2024-05-20 10:41:40 -03:00
UINT sampleMask{ 0xffffffff };
2024-05-19 21:22:34 -03:00
};
2024-05-20 09:09:08 -03:00
struct ConstantBuffer::PlatformImplementation {
~PlatformImplementation() {
if (_buffer) {
_buffer->Release();
_buffer = nullptr;
}
}
D3D11_BUFFER_DESC _description{};
D3D11_SUBRESOURCE_DATA _subResource{};
ID3D11Buffer* _buffer = nullptr;
DirectX::XMMATRIX _worldViewProjection;
};
2024-05-20 09:32:34 -03:00
struct DataBuffer::PlatformImplementation {
~PlatformImplementation() {
if (_blob) {
_blob->Release();
_blob = nullptr;
}
}
ID3DBlob* _blob = nullptr;
void Set(ID3DBlob*& blob) {
_blob = blob;
}
};
2024-05-20 10:29:20 -03:00
struct DepthStencilState::PlatformImplementation {
~PlatformImplementation() {
if (dxDepthStencil) {
dxDepthStencil->Release();
dxDepthStencil = nullptr;
}
}
ID3D11DepthStencilState* dxDepthStencil = nullptr;
D3D11_DEPTH_STENCIL_DESC dxDescription{};
2024-05-20 11:51:32 -03:00
};
struct DisplayModeRefreshRate {
constexpr DisplayModeRefreshRate() = default;
constexpr DisplayModeRefreshRate(DXGI_RATIONAL const& dxrational) {
Numerator = dxrational.Numerator;
Denominator = dxrational.Denominator;
}
constexpr DisplayModeRefreshRate(Uint numerator, Uint denominator)
: Numerator(numerator), Denominator(denominator) {}
Uint Numerator{ 0 };
Uint Denominator{ 0 };
constexpr bool operator==(const DisplayModeRefreshRate& other) const
{
return Numerator == other.Numerator && Denominator == other.Denominator;
}
};
struct DisplayModeDescription {
DisplayModeScanlineOrder _scanlineOrdering{ DisplayModeScanlineOrder::Unspecified };
DisplayModeScaling _scaling{ DisplayModeScaling::Unspecified };
DisplayModeRefreshRate _refreshRate{};
constexpr bool operator==(const DisplayModeDescription& other) const
{
return _scanlineOrdering == other._scanlineOrdering && _scaling == other._scaling && _refreshRate == other._refreshRate;
}
};
struct DisplayMode::PlatformImplementation {
std::vector<DisplayModeDescription> Descriptions;
2024-05-20 10:29:20 -03:00
};
2024-05-21 09:40:59 -03:00
struct GamePad::PlatformImplementation {
2024-05-21 09:48:11 -03:00
inline static uptr<DirectX::GamePad> _dxGamePad = nullptr;
2024-05-21 17:24:43 -03:00
void Suspend() {
if (_dxGamePad)
_dxGamePad->Suspend();
}
void Resume() {
if (_dxGamePad)
_dxGamePad->Resume();
}
2024-05-21 09:40:59 -03:00
};
2024-05-21 14:20:37 -03:00
struct IndexBuffer::PlatformImplementation {
~PlatformImplementation() {
if (dxBuffer) {
dxBuffer->Release();
dxBuffer = nullptr;
}
}
ID3D11Buffer* dxBuffer = nullptr;
};
template <typename T>
inline bool IndexBuffer::Initialize(std::vector<T> const& data, xna_error_ptr_arg) {
if (!impl || !m_device || !m_device->_device || data.empty()) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return false;
}
const auto hr = DirectX::CreateStaticBuffer(m_device->_device, data.data(), data.size(), sizeof(T), D3D11_BIND_INDEX_BUFFER, &impl->dxBuffer);
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return false;
}
return true;
}
2024-05-21 17:24:43 -03:00
struct Keyboard::PlatformImplementation {
inline static uptr<DirectX::Keyboard> _dxKeyboard = nullptr;
void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) {
if (_dxKeyboard)
2024-05-21 20:43:37 -03:00
_dxKeyboard->ProcessMessage(message, wParam, lParam);
}
};
struct Mouse::PlatformImplementation {
inline static uptr<DirectX::Mouse> _dxMouse = nullptr;
void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) {
if (_dxMouse)
_dxMouse->ProcessMessage(message, wParam, lParam);
2024-05-21 17:24:43 -03:00
}
};
2024-05-22 10:56:16 -03:00
struct RasterizerState::PlatformImplementation {
~PlatformImplementation() {
if (dxRasterizerState) {
dxRasterizerState->Release();
dxRasterizerState = nullptr;
}
}
ID3D11RasterizerState* dxRasterizerState = nullptr;
D3D11_RASTERIZER_DESC dxDescription{};
};
2024-05-19 16:11:34 -03:00
}