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

Adiciona PlatformImplementation em GraphicsDevice

This commit is contained in:
Danilo 2024-11-14 15:25:11 -03:00
parent b186fe754d
commit af091f4fd4
13 changed files with 158 additions and 157 deletions

View File

@ -21,7 +21,34 @@ namespace xna {
struct GraphicsAdapterImplementation { struct GraphicsAdapterImplementation {
comptr<IDXGIAdapter1> Adapter; comptr<IDXGIAdapter1> Adapter;
comptr<IDXGIFactory1> Factory; comptr<IDXGIFactory1> Factory;
}; };
struct GraphicsDeviceImplementation {
comptr<ID3D11Device> Device;
comptr<ID3D11DeviceContext> Context;
comptr<IDXGIFactory1> Factory;
std::shared_ptr<SwapChain> SwapChain;
std::shared_ptr<RenderTarget2D> RenderTarget2D;
intptr_t WindowHandle{ 0 };
D3D_FEATURE_LEVEL FeatureLevels[7] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1,
};
D3D_FEATURE_LEVEL CurrentFeatureLevel{ D3D_FEATURE_LEVEL_11_1 };
private:
friend class GraphicsDevice;
float backgroundColor[4] = { 0, 0, 0, 0 };
UINT vSyncValue = 1;
};
struct SpriteFont::PlatformImplementation { struct SpriteFont::PlatformImplementation {
uptr<DirectX::SpriteFont> dxSpriteFont{ nullptr }; uptr<DirectX::SpriteFont> dxSpriteFont{ nullptr };
@ -242,35 +269,7 @@ namespace xna {
} }
uptr<DirectX::AudioEngine> _dxAudioEngine = nullptr; uptr<DirectX::AudioEngine> _dxAudioEngine = nullptr;
}; };
struct GraphicsDevice::PlatformImplementation {
comptr<ID3D11Device> _device = nullptr;
comptr<ID3D11DeviceContext> _context = nullptr;
comptr<IDXGIFactory1> _factory = nullptr;
sptr<SwapChain> _swapChain = nullptr;
sptr<RenderTarget2D> _renderTarget2D = nullptr;
intptr_t windowHandle{ 0 };
D3D_FEATURE_LEVEL featureLevels[7] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1,
};
D3D_FEATURE_LEVEL currentFeatureLevel{ D3D_FEATURE_LEVEL_11_1 };
private:
friend class GraphicsDevice;
float _backgroundColor[4] = { 0, 0, 0, 0 };
UINT vSyncValue = 1;
};
struct Game::PlatformImplementation { struct Game::PlatformImplementation {
private: private:

View File

@ -1,38 +1,44 @@
#ifndef XNA_GRAPHICS_DEVICE_HPP #ifndef XNA_GRAPHICS_DEVICE_HPP
#define XNA_GRAPHICS_DEVICE_HPP #define XNA_GRAPHICS_DEVICE_HPP
#include "../default.hpp" #include "../platform.hpp"
#include "presentparams.hpp" #include "presentparams.hpp"
#include "viewport.hpp" #include "viewport.hpp"
#include <memory>
namespace xna { namespace xna {
struct GraphicsDeviceImplementation;
//Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders. //Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders.
class GraphicsDevice : public std::enable_shared_from_this<GraphicsDevice> { class GraphicsDevice : public std::enable_shared_from_this<GraphicsDevice>, public PlatformImplementation<GraphicsDeviceImplementation> {
public: public:
GraphicsDevice(); GraphicsDevice();
GraphicsDevice(P_GraphicsAdapter const& adapter, GraphicsProfile const& graphicsProfile, P_PresentationParameters const& presentationParameters); GraphicsDevice(
std::shared_ptr<GraphicsAdapter> const& adapter,
GraphicsProfile const& graphicsProfile,
std::shared_ptr<PresentationParameters> const& presentationParameters);
//Gets the graphics adapter. //Gets the graphics adapter.
inline P_GraphicsAdapter Adapter() const { return adapter; } inline std::shared_ptr<GraphicsAdapter> Adapter() const { return adapter; }
//Gets or sets a system-defined instance of a blend state object initialized for alpha blending. The default value is BlendState.Opaque. //Gets or sets a system-defined instance of a blend state object initialized for alpha blending. The default value is BlendState.Opaque.
inline P_BlendState BlendState() const { return blendState; } inline std::shared_ptr<xna::BlendState> BlendState() const { return blendState; }
//Gets or sets a system-defined instance of a blend state object initialized for alpha blending. The default value is BlendState.Opaque. //Gets or sets a system-defined instance of a blend state object initialized for alpha blending. The default value is BlendState.Opaque.
void BlendState(P_BlendState const& value); void BlendState(std::shared_ptr<xna::BlendState> const& value);
//Gets or sets a system-defined instance of a depth-stencil state object. The default value is DepthStencilState.Default. //Gets or sets a system-defined instance of a depth-stencil state object. The default value is DepthStencilState.Default.
inline P_DepthStencilState DepthStencilState() const { return depthStencilState; } inline std::shared_ptr<xna::DepthStencilState> DepthStencilState() const { return depthStencilState; }
//Gets or sets a system-defined instance of a depth-stencil state object. The default value is DepthStencilState.Default. //Gets or sets a system-defined instance of a depth-stencil state object. The default value is DepthStencilState.Default.
void DepthStencilState(P_DepthStencilState const& value); void DepthStencilState(std::shared_ptr<xna::DepthStencilState> const& value);
//Gets or sets rasterizer state. The default value is RasterizerState.CullCounterClockwise. //Gets or sets rasterizer state. The default value is RasterizerState.CullCounterClockwise.
inline P_RasterizerState RasterizerState() const { return rasterizerState; } inline std::shared_ptr<xna::RasterizerState> RasterizerState() const { return rasterizerState; }
//Gets or sets rasterizer state. The default value is RasterizerState.CullCounterClockwise. //Gets or sets rasterizer state. The default value is RasterizerState.CullCounterClockwise.
void RasterizerState(P_RasterizerState const& value); void RasterizerState(std::shared_ptr<xna::RasterizerState> const& value);
//Retrieves a collection of SamplerState objects for the current GraphicsDevice. //Retrieves a collection of SamplerState objects for the current GraphicsDevice.
inline P_SamplerStateCollection SamplerStates() const { return samplerStateCollection; } inline std::shared_ptr<SamplerStateCollection> SamplerStates() const { return samplerStateCollection; }
//Gets the graphics profile. //Gets the graphics profile.
constexpr GraphicsProfile Profile() const { return graphicsProfile; } constexpr GraphicsProfile Profile() const { return graphicsProfile; }
//Gets the presentation parameters associated with this graphics device. //Gets the presentation parameters associated with this graphics device.
P_PresentationParameters PresentParameters() const { return presentationParameters; } std::shared_ptr<PresentationParameters> PresentParameters() const { return presentationParameters; }
//Clears resource buffers. //Clears resource buffers.
void Clear(Color const& color) const; void Clear(Color const& color) const;
//Clears resource buffers. //Clears resource buffers.
@ -40,30 +46,26 @@ namespace xna {
//Presents the display with the contents of the next buffer in the sequence of back buffers owned by the GraphicsDevice. //Presents the display with the contents of the next buffer in the sequence of back buffers owned by the GraphicsDevice.
bool Present() const; bool Present() const;
//Resets the presentation parameters for the current GraphicsDevice. //Resets the presentation parameters for the current GraphicsDevice.
void Reset(P_PresentationParameters const& presentationParameters, P_GraphicsAdapter const& graphicsAdapter); void Reset(std::shared_ptr<PresentationParameters> const& presentationParameters, std::shared_ptr<GraphicsAdapter> const& graphicsAdapter);
//Gets or sets a viewport identifying the portion of the render target to receive draw calls. //Gets or sets a viewport identifying the portion of the render target to receive draw calls.
constexpr xna::Viewport Viewport() const { return viewport; } constexpr xna::Viewport Viewport() const { return viewport; }
//Gets or sets a viewport identifying the portion of the render target to receive draw calls. //Gets or sets a viewport identifying the portion of the render target to receive draw calls.
void Viewport(xna::Viewport const& viewport); void Viewport(xna::Viewport const& viewport);
//Sets a new render target for this GraphicsDevice. //Sets a new render target for this GraphicsDevice.
void SetRenderTarget(P_RenderTarget2D const& renderTarget) { this->renderTarget = renderTarget; } void SetRenderTarget(std::shared_ptr<RenderTarget2D> const& renderTarget) { this->renderTarget = renderTarget; }
void Initialize(); void Initialize();
private: private:
P_GraphicsAdapter adapter{ nullptr }; std::shared_ptr<GraphicsAdapter> adapter{ nullptr };
P_BlendState blendState{ nullptr }; std::shared_ptr<xna::BlendState> blendState{ nullptr };
P_DepthStencilState depthStencilState{ nullptr }; std::shared_ptr<xna::DepthStencilState> depthStencilState{ nullptr };
P_RasterizerState rasterizerState{ nullptr }; std::shared_ptr<xna::RasterizerState> rasterizerState{ nullptr };
P_SamplerStateCollection samplerStateCollection{ nullptr }; std::shared_ptr<SamplerStateCollection> samplerStateCollection{ nullptr };
P_PresentationParameters presentationParameters{ nullptr }; std::shared_ptr<PresentationParameters> presentationParameters{ nullptr };
P_RenderTarget2D renderTarget{ nullptr }; std::shared_ptr<RenderTarget2D> renderTarget{ nullptr };
GraphicsProfile graphicsProfile{ GraphicsProfile::HiDef }; GraphicsProfile graphicsProfile{ GraphicsProfile::HiDef };
xna::Viewport viewport{}; xna::Viewport viewport{};
public:
struct PlatformImplementation;
uptr<PlatformImplementation> impl = nullptr;
}; };
} }

View File

@ -97,7 +97,7 @@ namespace xna {
bool BlendState::Initialize() bool BlendState::Initialize()
{ {
if (!m_device || !m_device->impl->_device) { if (!m_device || !m_device->Implementation->Device) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE); Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
} }
@ -105,7 +105,7 @@ namespace xna {
Implementation->BlendState = nullptr; Implementation->BlendState = nullptr;
} }
const auto hr = m_device->impl->_device->CreateBlendState( const auto hr = m_device->Implementation->Device->CreateBlendState(
&Implementation->Description, &Implementation->Description,
Implementation->BlendState.GetAddressOf()); Implementation->BlendState.GetAddressOf());
@ -117,7 +117,7 @@ namespace xna {
} }
bool BlendState::Apply() { bool BlendState::Apply() {
if (!m_device || !m_device->impl->_context) { if (!m_device || !m_device->Implementation->Context) {
Exception::Throw(Exception::FAILED_TO_APPLY); Exception::Throw(Exception::FAILED_TO_APPLY);
} }
@ -125,7 +125,7 @@ namespace xna {
Initialize(); Initialize();
} }
m_device->impl->_context->OMSetBlendState( m_device->Implementation->Context->OMSetBlendState(
Implementation->BlendState.Get(), Implementation->BlendState.Get(),
Implementation->BlendFactor, Implementation->BlendFactor,
Implementation->SampleMask); Implementation->SampleMask);

View File

@ -37,7 +37,7 @@ namespace xna {
bool DepthStencilState::Initialize() bool DepthStencilState::Initialize()
{ {
if (!m_device || !m_device->impl->_device) { if (!m_device || !m_device->Implementation->Device) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE); Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
} }
@ -45,7 +45,7 @@ namespace xna {
Implementation->DepthStencil = nullptr; Implementation->DepthStencil = nullptr;
} }
const auto hr = m_device->impl->_device->CreateDepthStencilState( const auto hr = m_device->Implementation->Device->CreateDepthStencilState(
&Implementation->Description, &Implementation->Description,
Implementation->DepthStencil.GetAddressOf()); Implementation->DepthStencil.GetAddressOf());
@ -58,7 +58,7 @@ namespace xna {
bool DepthStencilState::Apply() bool DepthStencilState::Apply()
{ {
if (!m_device || !m_device->impl->_context) { if (!m_device || !m_device->Implementation->Context) {
Exception::Throw(Exception::INVALID_OPERATION); Exception::Throw(Exception::INVALID_OPERATION);
} }
@ -66,7 +66,7 @@ namespace xna {
Initialize(); Initialize();
} }
m_device->impl->_context->OMSetDepthStencilState(Implementation->DepthStencil.Get(), 0); m_device->Implementation->Context->OMSetDepthStencilState(Implementation->DepthStencil.Get(), 0);
return true; return true;
} }

View File

@ -1,19 +1,19 @@
#include "xna-dx/framework.hpp" #include "xna-dx/framework.hpp"
namespace xna { namespace xna {
static void reset(GraphicsDevice::PlatformImplementation& impl); static void reset(GraphicsDeviceImplementation& impl);
static void createDevice(GraphicsDevice::PlatformImplementation& impl, GraphicsAdapter& currentAdapter); static void createDevice(GraphicsDeviceImplementation& impl, GraphicsAdapter& currentAdapter);
static void initAndApplyState(P_BlendState& blendState, P_RasterizerState& rasterizerState, static void initAndApplyState(P_BlendState& blendState, P_RasterizerState& rasterizerState,
P_DepthStencilState& depthStencilState, P_SamplerStateCollection& samplerStates, P_GraphicsDevice const& device); P_DepthStencilState& depthStencilState, P_SamplerStateCollection& samplerStates, P_GraphicsDevice const& device);
GraphicsDevice::GraphicsDevice() { GraphicsDevice::GraphicsDevice() {
impl = unew<PlatformImplementation>(); Implementation = unew<GraphicsDeviceImplementation>();
adapter = GraphicsAdapter::DefaultAdapter(); adapter = GraphicsAdapter::DefaultAdapter();
} }
GraphicsDevice::GraphicsDevice(sptr<GraphicsAdapter> const& adapter, GraphicsProfile const& graphicsProfile, sptr<PresentationParameters> const& presentationParameters) GraphicsDevice::GraphicsDevice(sptr<GraphicsAdapter> const& adapter, GraphicsProfile const& graphicsProfile, sptr<PresentationParameters> const& presentationParameters)
: adapter(adapter), graphicsProfile(graphicsProfile), presentationParameters(presentationParameters) { : adapter(adapter), graphicsProfile(graphicsProfile), presentationParameters(presentationParameters) {
impl = unew<PlatformImplementation>(); Implementation = unew<GraphicsDeviceImplementation>();
blendState = xna::BlendState::Opaque(); blendState = xna::BlendState::Opaque();
depthStencilState = xna::DepthStencilState::Default(); depthStencilState = xna::DepthStencilState::Default();
@ -22,11 +22,11 @@ namespace xna {
} }
void GraphicsDevice::Initialize() { void GraphicsDevice::Initialize() {
reset(*impl); reset(*Implementation);
auto _this = shared_from_this(); auto _this = shared_from_this();
createDevice(*impl, *adapter); createDevice(*Implementation, *adapter);
// //
// Background // Background
@ -35,22 +35,22 @@ namespace xna {
const auto backColor = Colors::CornflowerBlue; const auto backColor = Colors::CornflowerBlue;
const auto backColorV3 = backColor.ToVector3(); const auto backColorV3 = backColor.ToVector3();
impl->_backgroundColor[0] = backColorV3.X; Implementation->backgroundColor[0] = backColorV3.X;
impl->_backgroundColor[1] = backColorV3.Y; Implementation->backgroundColor[1] = backColorV3.Y;
impl->_backgroundColor[2] = backColorV3.Z; Implementation->backgroundColor[2] = backColorV3.Z;
impl->_backgroundColor[3] = 1.0f; Implementation->backgroundColor[3] = 1.0f;
// //
// Window Association // Window Association
// //
auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&impl->_factory); auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&Implementation->Factory);
if FAILED(hr) if FAILED(hr)
Exception::Throw(Exception::FAILED_TO_CREATE); Exception::Throw(Exception::FAILED_TO_CREATE);
auto hwnd = reinterpret_cast<HWND>(presentationParameters->DeviceWindowHandle); auto hwnd = reinterpret_cast<HWND>(presentationParameters->DeviceWindowHandle);
hr = impl->_factory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER); hr = Implementation->Factory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER);
if (FAILED(hr)) if (FAILED(hr))
Exception::Throw(Exception::FAILED_TO_MAKE_WINDOW_ASSOCIATION); Exception::Throw(Exception::FAILED_TO_MAKE_WINDOW_ASSOCIATION);
@ -65,7 +65,7 @@ namespace xna {
0.0F, 1.F); 0.0F, 1.F);
D3D11_VIEWPORT view = DxHelpers::ViewportToDx(viewport); D3D11_VIEWPORT view = DxHelpers::ViewportToDx(viewport);
impl->_context->RSSetViewports(1, &view); Implementation->Context->RSSetViewports(1, &view);
// //
// States // States
@ -84,18 +84,18 @@ namespace xna {
case PresentInterval::Default: case PresentInterval::Default:
case PresentInterval::One: case PresentInterval::One:
case PresentInterval::Two: case PresentInterval::Two:
impl->vSyncValue = 1; Implementation->vSyncValue = 1;
break; break;
case PresentInterval::Immediate: case PresentInterval::Immediate:
impl->vSyncValue = 0; Implementation->vSyncValue = 0;
break; break;
default: default:
impl->vSyncValue = 1; Implementation->vSyncValue = 1;
break; break;
} }
impl->_swapChain = snew<xna::SwapChain>(_this); Implementation->SwapChain = snew<xna::SwapChain>(_this);
impl->_swapChain->Initialize(); Implementation->SwapChain->Initialize();
// //
//Render Target //Render Target
@ -103,44 +103,44 @@ namespace xna {
if (renderTarget) { if (renderTarget) {
renderTarget->Initialize(); renderTarget->Initialize();
impl->_renderTarget2D = renderTarget; Implementation->RenderTarget2D = renderTarget;
} }
else { else {
impl->_renderTarget2D = RenderTarget2D::FromBackBuffer(_this); Implementation->RenderTarget2D = RenderTarget2D::FromBackBuffer(_this);
} }
const auto& renderView = impl->_renderTarget2D->impl2->_renderTargetView; const auto& renderView = Implementation->RenderTarget2D->impl2->_renderTargetView;
impl->_context->OMSetRenderTargets(1, renderView.GetAddressOf(), nullptr); Implementation->Context->OMSetRenderTargets(1, renderView.GetAddressOf(), nullptr);
} }
bool GraphicsDevice::Present() const { bool GraphicsDevice::Present() const {
bool result = impl->_swapChain->Present(impl->vSyncValue != 0); bool result = Implementation->SwapChain->Present(Implementation->vSyncValue != 0);
impl->_context->OMSetRenderTargets( Implementation->Context->OMSetRenderTargets(
1, 1,
impl->_renderTarget2D->impl2->_renderTargetView.GetAddressOf(), Implementation->RenderTarget2D->impl2->_renderTargetView.GetAddressOf(),
nullptr); nullptr);
return result; return result;
} }
void GraphicsDevice::Clear(Color const& color) const { void GraphicsDevice::Clear(Color const& color) const {
if (!impl) return; if (!Implementation) return;
const auto v4 = color.ToVector4(); const auto v4 = color.ToVector4();
impl->_backgroundColor[0] = v4.X; Implementation->backgroundColor[0] = v4.X;
impl->_backgroundColor[1] = v4.Y; Implementation->backgroundColor[1] = v4.Y;
impl->_backgroundColor[2] = v4.Z; Implementation->backgroundColor[2] = v4.Z;
impl->_backgroundColor[3] = v4.W; Implementation->backgroundColor[3] = v4.W;
impl->_context->ClearRenderTargetView( Implementation->Context->ClearRenderTargetView(
impl->_renderTarget2D->impl2->_renderTargetView.Get(), Implementation->RenderTarget2D->impl2->_renderTargetView.Get(),
impl->_backgroundColor); Implementation->backgroundColor);
} }
void GraphicsDevice::Clear(ClearOptions options, Color const& color, float depth, Int stencil) const { void GraphicsDevice::Clear(ClearOptions options, Color const& color, float depth, Int stencil) const {
if (!impl) return; if (!Implementation) return;
switch (options) switch (options)
{ {
@ -162,7 +162,7 @@ namespace xna {
viewport = value; viewport = value;
const auto view = DxHelpers::ViewportToDx(viewport); const auto view = DxHelpers::ViewportToDx(viewport);
impl->_context->RSSetViewports(1, &view); Implementation->Context->RSSetViewports(1, &view);
} }
void GraphicsDevice::BlendState(sptr<xna::BlendState> const& value) { void GraphicsDevice::BlendState(sptr<xna::BlendState> const& value) {
@ -181,7 +181,7 @@ namespace xna {
} }
void GraphicsDevice::Reset(sptr<PresentationParameters> const& parameters, sptr<GraphicsAdapter> const& graphicsAdapter){ void GraphicsDevice::Reset(sptr<PresentationParameters> const& parameters, sptr<GraphicsAdapter> const& graphicsAdapter){
impl = unew<PlatformImplementation>(); Implementation = unew<GraphicsDeviceImplementation>();
adapter = graphicsAdapter; adapter = graphicsAdapter;
presentationParameters = parameters; presentationParameters = parameters;
@ -192,25 +192,25 @@ namespace xna {
// INTERNAL // INTERNAL
// //
void reset(GraphicsDevice::PlatformImplementation& impl) void reset(GraphicsDeviceImplementation& impl)
{ {
if (impl._device) { if (impl.Device) {
impl._device->Release(); impl.Device->Release();
impl._device = nullptr; impl.Device = nullptr;
} }
if (impl._context) { if (impl.Context) {
impl._context->Release(); impl.Context->Release();
impl._context = nullptr; impl.Context = nullptr;
} }
if (impl._factory) { if (impl.Factory) {
impl._factory->Release(); impl.Factory->Release();
impl._factory = nullptr; impl.Factory = nullptr;
} }
} }
void createDevice(GraphicsDevice::PlatformImplementation& impl, GraphicsAdapter& currentAdapter) { void createDevice(GraphicsDeviceImplementation& impl, GraphicsAdapter& currentAdapter) {
// //
// See ref // See ref
// //
@ -248,17 +248,17 @@ namespace xna {
//UINT Flags, //UINT Flags,
createDeviceFlags, createDeviceFlags,
//_In_reads_opt_( FeatureLevels ) CONST D3D_FEATURE_LEVEL* pFeatureLevels, //_In_reads_opt_( FeatureLevels ) CONST D3D_FEATURE_LEVEL* pFeatureLevels,
impl.featureLevels, impl.FeatureLevels,
//UINT FeatureLevels, //UINT FeatureLevels,
7, 7,
//UINT SDKVersion, //UINT SDKVersion,
D3D11_SDK_VERSION, D3D11_SDK_VERSION,
//_COM_Outptr_opt_ ID3D11Device** ppDevice //_COM_Outptr_opt_ ID3D11Device** ppDevice
impl._device.GetAddressOf(), impl.Device.GetAddressOf(),
//_Out_opt_ D3D_FEATURE_LEVEL* pFeatureLevel, //_Out_opt_ D3D_FEATURE_LEVEL* pFeatureLevel,
&impl.currentFeatureLevel, &impl.CurrentFeatureLevel,
//_COM_Outptr_opt_ ID3D11DeviceContext** ppImmediateContext //_COM_Outptr_opt_ ID3D11DeviceContext** ppImmediateContext
impl._context.GetAddressOf()); impl.Context.GetAddressOf());
if FAILED(hr) if FAILED(hr)
Exception::Throw(Exception::FAILED_TO_CREATE); Exception::Throw(Exception::FAILED_TO_CREATE);

View File

@ -16,7 +16,7 @@ namespace xna {
BasicEffect::BasicEffect(sptr<GraphicsDevice> const& device) : Effect(device) { BasicEffect::BasicEffect(sptr<GraphicsDevice> const& device) : Effect(device) {
impl = unew<PlatformImplementation>(); impl = unew<PlatformImplementation>();
uptr<DxEffectFactory> fxFactory = unew<DxEffectFactory>(device->impl->_device.Get()); uptr<DxEffectFactory> fxFactory = unew<DxEffectFactory>(device->Implementation->Device.Get());
DxEffectFactory::EffectInfo info; DxEffectFactory::EffectInfo info;
info.name = L"basic"; info.name = L"basic";
info.alpha = 1.f; info.alpha = 1.f;
@ -25,7 +25,7 @@ namespace xna {
info.specularColor = DxHelpers::Vector3ToDx(specularColor); info.specularColor = DxHelpers::Vector3ToDx(specularColor);
info.specularPower = specularPower; info.specularPower = specularPower;
Effect::impl->dxEffect = fxFactory->CreateEffect(info, device->impl->_context.Get()); Effect::impl->dxEffect = fxFactory->CreateEffect(info, device->Implementation->Context.Get());
impl->dxBasicEffect = reinterpret_pointer_cast<DxBasicEffect>(Effect::impl->dxEffect); impl->dxBasicEffect = reinterpret_pointer_cast<DxBasicEffect>(Effect::impl->dxEffect);
} }

View File

@ -25,10 +25,10 @@ namespace xna {
} }
bool GraphicsDeviceManager::ToggleFullScreen() { bool GraphicsDeviceManager::ToggleFullScreen() {
if (!game || !game->graphicsDevice || !game->graphicsDevice->impl->_swapChain) if (!game || !game->graphicsDevice || !game->graphicsDevice->Implementation->SwapChain)
return false; return false;
auto& swap = game->graphicsDevice->impl->_swapChain; auto& swap = game->graphicsDevice->Implementation->SwapChain;
BOOL state = false; BOOL state = false;
auto hr = swap->impl->dxSwapChain->GetFullscreenState(&state, nullptr); auto hr = swap->impl->dxSwapChain->GetFullscreenState(&state, nullptr);

View File

@ -17,7 +17,7 @@ namespace xna {
bool RasterizerState::Initialize() bool RasterizerState::Initialize()
{ {
if (!impl || !m_device || !m_device->impl->_device) { if (!impl || !m_device || !m_device->Implementation->Device) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE); Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
} }
@ -25,7 +25,7 @@ namespace xna {
impl->dxRasterizerState = nullptr; impl->dxRasterizerState = nullptr;
} }
const auto hr = m_device->impl->_device->CreateRasterizerState( const auto hr = m_device->Implementation->Device->CreateRasterizerState(
&impl->dxDescription, &impl->dxDescription,
impl->dxRasterizerState.GetAddressOf()); impl->dxRasterizerState.GetAddressOf());
@ -38,7 +38,7 @@ namespace xna {
bool RasterizerState::Apply() bool RasterizerState::Apply()
{ {
if (!impl || !m_device || !m_device->impl->_context) { if (!impl || !m_device || !m_device->Implementation->Context) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE); Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
} }
@ -46,7 +46,7 @@ namespace xna {
Exception::Throw(Exception::INVALID_OPERATION); Exception::Throw(Exception::INVALID_OPERATION);
} }
m_device->impl->_context->RSSetState(impl->dxRasterizerState.Get()); m_device->Implementation->Context->RSSetState(impl->dxRasterizerState.Get());
return true; return true;
} }

View File

@ -10,7 +10,7 @@ namespace xna {
} }
P_RenderTarget2D RenderTarget2D::FromBackBuffer(P_GraphicsDevice const& device) { P_RenderTarget2D RenderTarget2D::FromBackBuffer(P_GraphicsDevice const& device) {
auto& swapChain = device->impl->_swapChain; auto& swapChain = device->Implementation->SwapChain;
auto rt = snew<RenderTarget2D>(device); auto rt = snew<RenderTarget2D>(device);
auto& implementation = rt->impl; auto& implementation = rt->impl;
auto& implementation2 = rt->impl2; auto& implementation2 = rt->impl2;
@ -26,7 +26,7 @@ namespace xna {
} }
void RenderTarget2D::Initialize() { void RenderTarget2D::Initialize() {
if (!impl || !m_device || !m_device->impl->_device) { if (!impl || !m_device || !m_device->Implementation->Device) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE); Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
} }
@ -39,7 +39,7 @@ namespace xna {
Texture2D::Initialize(); Texture2D::Initialize();
auto& dxdevice = m_device->impl->_device; auto& dxdevice = m_device->Implementation->Device;
const auto hr = dxdevice->CreateRenderTargetView( const auto hr = dxdevice->CreateRenderTargetView(
impl->dxTexture2D.Get(), impl->dxTexture2D.Get(),

View File

@ -11,7 +11,7 @@ namespace xna {
bool SamplerState::Initialize() bool SamplerState::Initialize()
{ {
if (!impl || !m_device || !m_device->impl->_device) { if (!impl || !m_device || !m_device->Implementation->Device) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE); Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
} }
@ -19,7 +19,7 @@ namespace xna {
impl->_samplerState = nullptr; impl->_samplerState = nullptr;
} }
const auto hr = m_device->impl->_device->CreateSamplerState( const auto hr = m_device->Implementation->Device->CreateSamplerState(
&impl->_description, &impl->_description,
impl->_samplerState.GetAddressOf()); impl->_samplerState.GetAddressOf());
@ -32,7 +32,7 @@ namespace xna {
bool SamplerState::Apply() bool SamplerState::Apply()
{ {
if (!impl || !m_device || !m_device->impl->_context) { if (!impl || !m_device || !m_device->Implementation->Context) {
Exception::Throw(Exception::INVALID_OPERATION); Exception::Throw(Exception::INVALID_OPERATION);
} }
@ -40,7 +40,7 @@ namespace xna {
Exception::Throw(Exception::INVALID_OPERATION); Exception::Throw(Exception::INVALID_OPERATION);
} }
m_device->impl->_context->PSSetSamplers(0, 1, impl->_samplerState.GetAddressOf()); m_device->Implementation->Context->PSSetSamplers(0, 1, impl->_samplerState.GetAddressOf());
return true; return true;
} }
@ -49,7 +49,7 @@ namespace xna {
if (samplers.empty()) if (samplers.empty())
return; return;
if (!device.impl || !device.impl->_device || !device.impl->_context) { if (!device.Implementation || !device.Implementation->Device || !device.Implementation->Context) {
Exception::Throw(Exception::INVALID_OPERATION); Exception::Throw(Exception::INVALID_OPERATION);
} }
@ -65,7 +65,7 @@ namespace xna {
states[i]->AddRef(); states[i]->AddRef();
} }
device.impl->_context->PSSetSamplers( device.Implementation->Context->PSSetSamplers(
0, 0,
static_cast<UINT>(states.size()), static_cast<UINT>(states.size()),
states.data()); states.data());

View File

@ -110,12 +110,12 @@ namespace xna {
SpriteBatch::SpriteBatch(sptr<GraphicsDevice> const& device) : GraphicsResource(device) { SpriteBatch::SpriteBatch(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
Exception::ThrowIfNull(device, nameof(device)); Exception::ThrowIfNull(device, nameof(device));
Exception::ThrowIfNull(device->impl->_context.Get(), nameof(device->impl->_context)); Exception::ThrowIfNull(device->Implementation->Context.Get(), nameof(device->Implementation->Context));
impl = unew<PlatformImplementation>(); impl = unew<PlatformImplementation>();
impl->dxSpriteBatch = snew<DxSpriteBatch>( impl->dxSpriteBatch = snew<DxSpriteBatch>(
//ID3D11DeviceContext* deviceContext //ID3D11DeviceContext* deviceContext
device->impl->_context.Get() device->Implementation->Context.Get()
); );
Viewport(device->Viewport()); Viewport(device->Viewport());
@ -139,14 +139,14 @@ namespace xna {
effect->impl->dxEffect->GetVertexShaderBytecode(&shaderByteCode, &byteCodeLength); effect->impl->dxEffect->GetVertexShaderBytecode(&shaderByteCode, &byteCodeLength);
m_device->impl->_device->CreateInputLayout( m_device->Implementation->Device->CreateInputLayout(
DirectX::VertexPositionColorTexture::InputElements, DirectX::VertexPositionColorTexture::InputElements,
DirectX::VertexPositionColorTexture::InputElementCount, DirectX::VertexPositionColorTexture::InputElementCount,
shaderByteCode, byteCodeLength, shaderByteCode, byteCodeLength,
impl->dxInputLayout.GetAddressOf()); impl->dxInputLayout.GetAddressOf());
} }
auto& context = m_device->impl->_context; auto& context = m_device->Implementation->Context;
effectFunc = [=] { effectFunc = [=] {
impl->dxEffectBuffer->Apply(context.Get()); impl->dxEffectBuffer->Apply(context.Get());

View File

@ -17,7 +17,7 @@ namespace xna {
} }
static bool internalInit(GraphicsDevice& device, HWND windowHandle, comptr<IDXGISwapChain1>& swapChain, DXGI_SWAP_CHAIN_DESC1 const& desc, DXGI_SWAP_CHAIN_FULLSCREEN_DESC const& fdesc) { static bool internalInit(GraphicsDevice& device, HWND windowHandle, comptr<IDXGISwapChain1>& swapChain, DXGI_SWAP_CHAIN_DESC1 const& desc, DXGI_SWAP_CHAIN_FULLSCREEN_DESC const& fdesc) {
if (!device.impl->_device || !windowHandle) if (!device.Implementation->Device || !windowHandle)
return false; return false;
if (swapChain) { if (swapChain) {
@ -33,7 +33,7 @@ namespace xna {
return false; return false;
dxFactory2->CreateSwapChainForHwnd( dxFactory2->CreateSwapChainForHwnd(
device.impl->_device.Get(), device.Implementation->Device.Get(),
windowHandle, windowHandle,
&desc, &desc,
&fdesc, &fdesc,
@ -44,7 +44,7 @@ namespace xna {
} }
bool SwapChain::Initialize() { bool SwapChain::Initialize() {
if (!impl || !m_device || !m_device->impl->_device) { if (!impl || !m_device || !m_device->Implementation->Device) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE); Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
} }

View File

@ -33,16 +33,16 @@ namespace xna {
void Texture2D::Initialize() void Texture2D::Initialize()
{ {
if (!m_device || !m_device->impl->_device) { if (!m_device || !m_device->Implementation->Device) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE); Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
} }
auto& deviceImpl = m_device->impl; auto& deviceImpl = m_device->Implementation;
HRESULT hr = 0; HRESULT hr = 0;
if (!impl->dxTexture2D) { if (!impl->dxTexture2D) {
hr = deviceImpl->_device->CreateTexture2D( hr = deviceImpl->Device->CreateTexture2D(
&impl->dxDescription, &impl->dxDescription,
nullptr, nullptr,
impl->dxTexture2D.ReleaseAndGetAddressOf()); impl->dxTexture2D.ReleaseAndGetAddressOf());
@ -63,7 +63,7 @@ namespace xna {
//Only initializes if it is a ShaderResource //Only initializes if it is a ShaderResource
if (impl->dxDescription.BindFlags & D3D11_BIND_SHADER_RESOURCE) { if (impl->dxDescription.BindFlags & D3D11_BIND_SHADER_RESOURCE) {
hr = deviceImpl->_device->CreateShaderResourceView( hr = deviceImpl->Device->CreateShaderResourceView(
resource.Get(), resource.Get(),
&impl->dxShaderDescription, &impl->dxShaderDescription,
impl->dxShaderResource.ReleaseAndGetAddressOf()); impl->dxShaderResource.ReleaseAndGetAddressOf());
@ -81,7 +81,7 @@ namespace xna {
void Texture2D::SetData(std::vector<Uint> const& data, size_t startIndex, size_t elementCount) void Texture2D::SetData(std::vector<Uint> const& data, size_t startIndex, size_t elementCount)
{ {
if (!impl || !m_device || !m_device->impl->_device || !m_device->impl->_context) { if (!impl || !m_device || !m_device->Implementation->Device || !m_device->Implementation->Context) {
Exception::Throw(Exception::INVALID_OPERATION); Exception::Throw(Exception::INVALID_OPERATION);
} }
@ -90,7 +90,7 @@ namespace xna {
void Texture2D::SetData(std::vector<Byte> const& data, size_t startIndex, size_t elementCount) void Texture2D::SetData(std::vector<Byte> const& data, size_t startIndex, size_t elementCount)
{ {
if (!m_device || !m_device->impl->_device || !m_device->impl->_context) { if (!m_device || !m_device->Implementation->Device || !m_device->Implementation->Context) {
Exception::Throw(Exception::INVALID_OPERATION); Exception::Throw(Exception::INVALID_OPERATION);
} }
@ -111,7 +111,7 @@ namespace xna {
void Texture2D::SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount) void Texture2D::SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount)
{ {
if (!m_device || !m_device->impl->_device || !m_device->impl->_context) { if (!m_device || !m_device->Implementation->Device || !m_device->Implementation->Context) {
Exception::Throw(Exception::INVALID_OPERATION); Exception::Throw(Exception::INVALID_OPERATION);
} }
@ -128,7 +128,7 @@ namespace xna {
} }
if (!impl->dxTexture2D) { if (!impl->dxTexture2D) {
auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, impl->dxTexture2D.GetAddressOf()); auto hr = m_device->Implementation->Device->CreateTexture2D(&impl->dxDescription, nullptr, impl->dxTexture2D.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(Exception::FAILED_TO_CREATE); Exception::Throw(Exception::FAILED_TO_CREATE);
@ -154,11 +154,11 @@ namespace xna {
} }
constexpr int R8G8B8A8U_BYTE_SIZE = 4; constexpr int R8G8B8A8U_BYTE_SIZE = 4;
m_device->impl->_context->UpdateSubresource(resource.Get(), 0, rect ? &box : nullptr, finalData.data(), impl->dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0); m_device->Implementation->Context->UpdateSubresource(resource.Get(), 0, rect ? &box : nullptr, finalData.data(), impl->dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0);
impl->dxShaderDescription.Format = impl->dxDescription.Format; impl->dxShaderDescription.Format = impl->dxDescription.Format;
impl->dxShaderDescription.Texture2D.MipLevels = impl->dxDescription.MipLevels; impl->dxShaderDescription.Texture2D.MipLevels = impl->dxDescription.MipLevels;
hr = m_device->impl->_device->CreateShaderResourceView(resource.Get(), &impl->dxShaderDescription, impl->dxShaderResource.ReleaseAndGetAddressOf()); hr = m_device->Implementation->Device->CreateShaderResourceView(resource.Get(), &impl->dxShaderDescription, impl->dxShaderResource.ReleaseAndGetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(Exception::FAILED_TO_CREATE); Exception::Throw(Exception::FAILED_TO_CREATE);
@ -169,7 +169,7 @@ namespace xna {
void Texture2D::SetData(std::vector<Color> const& data, size_t startIndex, size_t elementCount) void Texture2D::SetData(std::vector<Color> const& data, size_t startIndex, size_t elementCount)
{ {
if (!m_device || !m_device->impl->_device || !m_device->impl->_context) { if (!m_device || !m_device->Implementation->Device || !m_device->Implementation->Context) {
Exception::Throw(Exception::INVALID_OPERATION); Exception::Throw(Exception::INVALID_OPERATION);
} }
@ -201,8 +201,8 @@ namespace xna {
auto wstr = XnaHelper::ToWString(fileName); auto wstr = XnaHelper::ToWString(fileName);
HRESULT result = DirectX::CreateWICTextureFromFile( HRESULT result = DirectX::CreateWICTextureFromFile(
device.impl->_device.Get(), device.Implementation->Device.Get(),
device.impl->_context.Get(), device.Implementation->Context.Get(),
wstr.c_str(), wstr.c_str(),
resource.GetAddressOf(), resource.GetAddressOf(),
texture2d->impl->dxShaderResource.ReleaseAndGetAddressOf(), texture2d->impl->dxShaderResource.ReleaseAndGetAddressOf(),
@ -232,8 +232,8 @@ namespace xna {
comptr<ID3D11Resource> resource = nullptr; comptr<ID3D11Resource> resource = nullptr;
auto hr = DirectX::CreateWICTextureFromMemory( auto hr = DirectX::CreateWICTextureFromMemory(
device.impl->_device.Get(), device.Implementation->Device.Get(),
device.impl->_context.Get(), device.Implementation->Context.Get(),
data.data(), data.data(),
data.size(), data.size(),
resource.GetAddressOf(), resource.GetAddressOf(),
@ -260,7 +260,7 @@ namespace xna {
HRESULT internalTexture2DSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data) HRESULT internalTexture2DSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data)
{ {
if (!impl.dxTexture2D) { if (!impl.dxTexture2D) {
auto hr = device.impl->_device->CreateTexture2D(&impl.dxDescription, nullptr, impl.dxTexture2D.ReleaseAndGetAddressOf()); auto hr = device.Implementation->Device->CreateTexture2D(&impl.dxDescription, nullptr, impl.dxTexture2D.ReleaseAndGetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(Exception::FAILED_TO_CREATE); Exception::Throw(Exception::FAILED_TO_CREATE);
@ -275,10 +275,10 @@ namespace xna {
} }
constexpr int R8G8B8A8U_BYTE_SIZE = 4; constexpr int R8G8B8A8U_BYTE_SIZE = 4;
device.impl->_context->UpdateSubresource(resource.Get(), 0, nullptr, data, impl.dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0); device.Implementation->Context->UpdateSubresource(resource.Get(), 0, nullptr, data, impl.dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0);
impl.dxShaderDescription.Texture2D.MipLevels = impl.dxDescription.MipLevels; impl.dxShaderDescription.Texture2D.MipLevels = impl.dxDescription.MipLevels;
hr = device.impl->_device->CreateShaderResourceView(resource.Get(), &impl.dxShaderDescription, impl.dxShaderResource.ReleaseAndGetAddressOf()); hr = device.Implementation->Device->CreateShaderResourceView(resource.Get(), &impl.dxShaderDescription, impl.dxShaderResource.ReleaseAndGetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(Exception::FAILED_TO_CREATE); Exception::Throw(Exception::FAILED_TO_CREATE);