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 {
comptr<IDXGIAdapter1> Adapter;
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 {
uptr<DirectX::SpriteFont> dxSpriteFont{ nullptr };
@ -242,35 +269,7 @@ namespace xna {
}
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 {
private:

View File

@ -1,38 +1,44 @@
#ifndef XNA_GRAPHICS_DEVICE_HPP
#define XNA_GRAPHICS_DEVICE_HPP
#include "../default.hpp"
#include "../platform.hpp"
#include "presentparams.hpp"
#include "viewport.hpp"
#include <memory>
namespace xna {
struct GraphicsDeviceImplementation;
//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:
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.
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.
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.
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.
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.
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.
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.
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.
inline P_SamplerStateCollection SamplerStates() const { return samplerStateCollection; }
inline std::shared_ptr<SamplerStateCollection> SamplerStates() const { return samplerStateCollection; }
//Gets the graphics profile.
constexpr GraphicsProfile Profile() const { return graphicsProfile; }
//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.
void Clear(Color const& color) const;
//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.
bool Present() const;
//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.
constexpr xna::Viewport Viewport() const { return viewport; }
//Gets or sets a viewport identifying the portion of the render target to receive draw calls.
void Viewport(xna::Viewport const& viewport);
//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();
private:
P_GraphicsAdapter adapter{ nullptr };
P_BlendState blendState{ nullptr };
P_DepthStencilState depthStencilState{ nullptr };
P_RasterizerState rasterizerState{ nullptr };
P_SamplerStateCollection samplerStateCollection{ nullptr };
P_PresentationParameters presentationParameters{ nullptr };
P_RenderTarget2D renderTarget{ nullptr };
std::shared_ptr<GraphicsAdapter> adapter{ nullptr };
std::shared_ptr<xna::BlendState> blendState{ nullptr };
std::shared_ptr<xna::DepthStencilState> depthStencilState{ nullptr };
std::shared_ptr<xna::RasterizerState> rasterizerState{ nullptr };
std::shared_ptr<SamplerStateCollection> samplerStateCollection{ nullptr };
std::shared_ptr<PresentationParameters> presentationParameters{ nullptr };
std::shared_ptr<RenderTarget2D> renderTarget{ nullptr };
GraphicsProfile graphicsProfile{ GraphicsProfile::HiDef };
xna::Viewport viewport{};
public:
struct PlatformImplementation;
uptr<PlatformImplementation> impl = nullptr;
xna::Viewport viewport{};
};
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -110,12 +110,12 @@ namespace xna {
SpriteBatch::SpriteBatch(sptr<GraphicsDevice> const& device) : GraphicsResource(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->dxSpriteBatch = snew<DxSpriteBatch>(
//ID3D11DeviceContext* deviceContext
device->impl->_context.Get()
device->Implementation->Context.Get()
);
Viewport(device->Viewport());
@ -139,14 +139,14 @@ namespace xna {
effect->impl->dxEffect->GetVertexShaderBytecode(&shaderByteCode, &byteCodeLength);
m_device->impl->_device->CreateInputLayout(
m_device->Implementation->Device->CreateInputLayout(
DirectX::VertexPositionColorTexture::InputElements,
DirectX::VertexPositionColorTexture::InputElementCount,
shaderByteCode, byteCodeLength,
impl->dxInputLayout.GetAddressOf());
}
auto& context = m_device->impl->_context;
auto& context = m_device->Implementation->Context;
effectFunc = [=] {
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) {
if (!device.impl->_device || !windowHandle)
if (!device.Implementation->Device || !windowHandle)
return false;
if (swapChain) {
@ -33,7 +33,7 @@ namespace xna {
return false;
dxFactory2->CreateSwapChainForHwnd(
device.impl->_device.Get(),
device.Implementation->Device.Get(),
windowHandle,
&desc,
&fdesc,
@ -44,7 +44,7 @@ namespace xna {
}
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);
}

View File

@ -33,16 +33,16 @@ namespace xna {
void Texture2D::Initialize()
{
if (!m_device || !m_device->impl->_device) {
if (!m_device || !m_device->Implementation->Device) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
}
auto& deviceImpl = m_device->impl;
auto& deviceImpl = m_device->Implementation;
HRESULT hr = 0;
if (!impl->dxTexture2D) {
hr = deviceImpl->_device->CreateTexture2D(
hr = deviceImpl->Device->CreateTexture2D(
&impl->dxDescription,
nullptr,
impl->dxTexture2D.ReleaseAndGetAddressOf());
@ -63,7 +63,7 @@ namespace xna {
//Only initializes if it is a ShaderResource
if (impl->dxDescription.BindFlags & D3D11_BIND_SHADER_RESOURCE) {
hr = deviceImpl->_device->CreateShaderResourceView(
hr = deviceImpl->Device->CreateShaderResourceView(
resource.Get(),
&impl->dxShaderDescription,
impl->dxShaderResource.ReleaseAndGetAddressOf());
@ -81,7 +81,7 @@ namespace xna {
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);
}
@ -90,7 +90,7 @@ namespace xna {
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);
}
@ -111,7 +111,7 @@ namespace xna {
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);
}
@ -128,7 +128,7 @@ namespace xna {
}
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)) {
Exception::Throw(Exception::FAILED_TO_CREATE);
@ -154,11 +154,11 @@ namespace xna {
}
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.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)) {
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)
{
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);
}
@ -201,8 +201,8 @@ namespace xna {
auto wstr = XnaHelper::ToWString(fileName);
HRESULT result = DirectX::CreateWICTextureFromFile(
device.impl->_device.Get(),
device.impl->_context.Get(),
device.Implementation->Device.Get(),
device.Implementation->Context.Get(),
wstr.c_str(),
resource.GetAddressOf(),
texture2d->impl->dxShaderResource.ReleaseAndGetAddressOf(),
@ -232,8 +232,8 @@ namespace xna {
comptr<ID3D11Resource> resource = nullptr;
auto hr = DirectX::CreateWICTextureFromMemory(
device.impl->_device.Get(),
device.impl->_context.Get(),
device.Implementation->Device.Get(),
device.Implementation->Context.Get(),
data.data(),
data.size(),
resource.GetAddressOf(),
@ -260,7 +260,7 @@ namespace xna {
HRESULT internalTexture2DSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data)
{
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)) {
Exception::Throw(Exception::FAILED_TO_CREATE);
@ -275,10 +275,10 @@ namespace xna {
}
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;
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)) {
Exception::Throw(Exception::FAILED_TO_CREATE);