mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Corrige GraphicsDevice
This commit is contained in:
parent
c682cb0691
commit
5940d093a4
@ -1,6 +1,5 @@
|
||||
#include "graphics/blendstate.hpp"
|
||||
#include "graphics/gresource.hpp"
|
||||
#include "platform-dx/device-dx.hpp"
|
||||
#include "platform-dx/dxheaders.hpp"
|
||||
#include "platform-dx/dxhelpers.hpp"
|
||||
#include "graphics/blendstate.hpp"
|
||||
@ -21,7 +20,7 @@ namespace xna {
|
||||
|
||||
bool BlendState::Initialize(xna_error_ptr_arg)
|
||||
{
|
||||
if (!m_device || !m_device->_device) {
|
||||
if (!m_device || !m_device->impl->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -31,7 +30,7 @@ namespace xna {
|
||||
impl->dxBlendState = nullptr;
|
||||
}
|
||||
|
||||
const auto hr = m_device->_device->CreateBlendState(
|
||||
const auto hr = m_device->impl->_device->CreateBlendState(
|
||||
&impl->dxDescription,
|
||||
&impl->dxBlendState);
|
||||
|
||||
@ -44,7 +43,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
bool BlendState::Apply(xna_error_ptr_arg) {
|
||||
if (!m_device || !m_device->_context) {
|
||||
if (!m_device || !m_device->impl->_context) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -54,7 +53,7 @@ namespace xna {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_device->_context->OMSetBlendState(
|
||||
m_device->impl->_context->OMSetBlendState(
|
||||
impl->dxBlendState,
|
||||
impl->blendFactor,
|
||||
impl->sampleMask);
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "graphics/buffer.hpp"
|
||||
#include "common/numerics.hpp"
|
||||
#include "platform-dx/dxheaders.hpp"
|
||||
#include "platform-dx/device-dx.hpp"
|
||||
#include "platform-dx/implementations.hpp"
|
||||
|
||||
namespace xna {
|
||||
@ -19,7 +18,7 @@ namespace xna {
|
||||
|
||||
bool ConstantBuffer::Initialize(xna_error_ptr_arg)
|
||||
{
|
||||
if (!m_device || !m_device->_device) {
|
||||
if (!m_device || !m_device->impl->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -29,7 +28,7 @@ namespace xna {
|
||||
impl->_buffer = nullptr;
|
||||
}
|
||||
|
||||
const auto hr = m_device->_device->CreateBuffer(
|
||||
const auto hr = m_device->impl->_device->CreateBuffer(
|
||||
&impl->_description,
|
||||
&impl->_subResource,
|
||||
&impl->_buffer);
|
||||
@ -55,7 +54,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
bool DataBuffer::Initialize(xna_error_ptr_arg) {
|
||||
if (!m_device || !m_device->_device) {
|
||||
if (!m_device || !m_device->impl->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -81,12 +80,12 @@ namespace xna {
|
||||
}
|
||||
|
||||
bool IndexBuffer::Apply(xna_error_ptr_arg) {
|
||||
if (!m_device || !m_device->_context || !impl || !impl->dxBuffer) {
|
||||
if (!m_device || !m_device->impl->_context || !impl || !impl->dxBuffer) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_device->_context->IASetIndexBuffer(impl->dxBuffer, DXGI_FORMAT_R16_UINT, 0);
|
||||
m_device->impl->_context->IASetIndexBuffer(impl->dxBuffer, DXGI_FORMAT_R16_UINT, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -104,7 +103,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
bool VertexBuffer::Apply(xna_error_ptr_arg) {
|
||||
if (!impl || !m_device || !m_device->_context) {
|
||||
if (!impl || !m_device || !m_device->impl->_context) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -116,7 +115,7 @@ namespace xna {
|
||||
|
||||
UINT stride = impl->size;
|
||||
UINT offset = 0;
|
||||
m_device->_context->IASetVertexBuffers(0, 1,
|
||||
m_device->impl->_context->IASetVertexBuffers(0, 1,
|
||||
&impl->dxBuffer, &stride, &offset);
|
||||
|
||||
return true;
|
||||
@ -135,7 +134,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
bool VertexInputLayout::Initialize(DataBuffer& blob, xna_error_ptr_arg) {
|
||||
if (!impl || !m_device || !m_device->_device || !blob.impl->_blob) {
|
||||
if (!impl || !m_device || !m_device->impl->_device || !blob.impl->_blob) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -145,7 +144,7 @@ namespace xna {
|
||||
impl->_inputLayout = nullptr;
|
||||
}
|
||||
|
||||
const auto hr = m_device->_device->CreateInputLayout(
|
||||
const auto hr = m_device->impl->_device->CreateInputLayout(
|
||||
impl->_description.data(),
|
||||
static_cast<UINT>(impl->_description.size()),
|
||||
blob.impl->_blob->GetBufferPointer(),
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include "platform-dx/device-dx.hpp"
|
||||
#include "graphics/depthstencilstate.hpp"
|
||||
#include "platform-dx/dxheaders.hpp"
|
||||
#include "platform-dx/implementations.hpp"
|
||||
@ -43,7 +42,7 @@ namespace xna {
|
||||
|
||||
bool DepthStencilState::Initialize(xna_error_ptr_arg)
|
||||
{
|
||||
if (!m_device || !m_device->_device) {
|
||||
if (!m_device || !m_device->impl->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -53,7 +52,7 @@ namespace xna {
|
||||
impl->dxDepthStencil = nullptr;
|
||||
}
|
||||
|
||||
const auto hr = m_device->_device->CreateDepthStencilState(
|
||||
const auto hr = m_device->impl->_device->CreateDepthStencilState(
|
||||
&impl->dxDescription,
|
||||
&impl->dxDepthStencil);
|
||||
|
||||
@ -67,7 +66,7 @@ namespace xna {
|
||||
|
||||
bool DepthStencilState::Apply(xna_error_ptr_arg)
|
||||
{
|
||||
if (!m_device || !m_device->_context) {
|
||||
if (!m_device || !m_device->impl->_context) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -77,7 +76,7 @@ namespace xna {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_device->_context->OMSetDepthStencilState(impl->dxDepthStencil, 0);
|
||||
m_device->impl->_context->OMSetDepthStencilState(impl->dxDepthStencil, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,157 +1,205 @@
|
||||
#include "common/color.hpp"
|
||||
#include "graphics/adapter.hpp"
|
||||
#include "graphics/blendstate.hpp"
|
||||
#include "graphics/rendertarget.hpp"
|
||||
#include "platform-dx/device-dx.hpp"
|
||||
#include "platform-dx/implementations.hpp"
|
||||
#include "game/gdeviceinfo.hpp"
|
||||
#include "game/gdevicemanager.hpp"
|
||||
|
||||
namespace xna {
|
||||
void reset(GraphicsDevice::PlatformImplementation& impl)
|
||||
{
|
||||
if (impl._device) {
|
||||
impl._device->Release();
|
||||
impl._device = nullptr;
|
||||
}
|
||||
|
||||
if (impl._context) {
|
||||
impl._context->Release();
|
||||
impl._context = nullptr;
|
||||
}
|
||||
|
||||
if (impl._factory) {
|
||||
impl._factory->Release();
|
||||
impl._factory = nullptr;
|
||||
}
|
||||
|
||||
impl._blendState = nullptr;
|
||||
impl._swapChain = nullptr;
|
||||
impl._renderTarget2D = nullptr;
|
||||
}
|
||||
|
||||
bool createDevice(GraphicsDevice::PlatformImplementation& impl) {
|
||||
auto createDeviceFlags = 0;
|
||||
#if _DEBUG
|
||||
createDeviceFlags = D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG;
|
||||
#endif
|
||||
|
||||
|
||||
auto hr = D3D11CreateDevice(
|
||||
impl._adapter->impl->dxadapter,
|
||||
D3D_DRIVER_TYPE_UNKNOWN,
|
||||
NULL,
|
||||
createDeviceFlags,
|
||||
NULL,
|
||||
0,
|
||||
D3D11_SDK_VERSION,
|
||||
&impl._device,
|
||||
&impl._featureLevel,
|
||||
&impl._context);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
OutputDebugString("---> Usando Adaptador WARP: não há suporte ao D3D11\n");
|
||||
|
||||
hr = D3D11CreateDevice(
|
||||
NULL,
|
||||
D3D_DRIVER_TYPE_WARP,
|
||||
NULL,
|
||||
createDeviceFlags,
|
||||
NULL,
|
||||
0,
|
||||
D3D11_SDK_VERSION,
|
||||
&impl._device,
|
||||
&impl._featureLevel,
|
||||
&impl._context);
|
||||
}
|
||||
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
GraphicsDevice::GraphicsDevice() {
|
||||
_adapter = GraphicsAdapter::DefaultAdapter();
|
||||
_adapter->CurrentDisplayMode(SurfaceFormat::Color, GraphicsDeviceManager::DefaultBackBufferWidth, GraphicsDeviceManager::DefaultBackBufferHeight);
|
||||
impl = unew<PlatformImplementation>();
|
||||
impl->_adapter = GraphicsAdapter::DefaultAdapter();
|
||||
impl->_adapter->CurrentDisplayMode(
|
||||
SurfaceFormat::Color,
|
||||
GraphicsDeviceManager::DefaultBackBufferWidth,
|
||||
GraphicsDeviceManager::DefaultBackBufferHeight);
|
||||
}
|
||||
|
||||
GraphicsDevice::GraphicsDevice(GraphicsDeviceInformation const& info) {
|
||||
_adapter = info.Adapter;
|
||||
_presentationParameters = info.Parameters;
|
||||
_adapter->CurrentDisplayMode(
|
||||
_presentationParameters->BackBufferFormat,
|
||||
_presentationParameters->BackBufferWidth,
|
||||
_presentationParameters->BackBufferHeight);
|
||||
impl = unew<PlatformImplementation>();
|
||||
|
||||
impl->_adapter = info.Adapter;
|
||||
impl->_presentationParameters = info.Parameters;
|
||||
impl->_adapter->CurrentDisplayMode(
|
||||
impl->_presentationParameters->BackBufferFormat,
|
||||
impl->_presentationParameters->BackBufferWidth,
|
||||
impl->_presentationParameters->BackBufferHeight);
|
||||
}
|
||||
|
||||
GraphicsDevice::~GraphicsDevice() {
|
||||
impl = nullptr;
|
||||
}
|
||||
|
||||
bool GraphicsDevice::Initialize(GameWindow& gameWindow) {
|
||||
reset();
|
||||
if (!impl)
|
||||
impl = uptr<PlatformImplementation>();
|
||||
|
||||
reset(*impl);
|
||||
|
||||
auto _this = shared_from_this();
|
||||
|
||||
if (!createDevice()) return false;
|
||||
if (!createDevice(*impl))
|
||||
return false;
|
||||
|
||||
auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&_factory);
|
||||
if (FAILED(hr)) return false;
|
||||
auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&impl->_factory);
|
||||
if (FAILED(hr))
|
||||
return false;
|
||||
|
||||
const auto bounds = gameWindow.ClientBounds();
|
||||
|
||||
_viewport = xna::Viewport(0.0F, 0.0F,
|
||||
impl->_viewport = xna::Viewport(0.0F, 0.0F,
|
||||
static_cast<float>(bounds.Width),
|
||||
static_cast<float>(bounds.Height),
|
||||
0.0F, 1.F);
|
||||
|
||||
COLORREF color = gameWindow.impl->Color();
|
||||
_backgroundColor[0] = GetRValue(color) / 255.0f;
|
||||
_backgroundColor[1] = GetGValue(color) / 255.0f;
|
||||
_backgroundColor[2] = GetBValue(color) / 255.0f;
|
||||
_backgroundColor[3] = 1.0f;
|
||||
impl->_backgroundColor[0] = GetRValue(color) / 255.0f;
|
||||
impl->_backgroundColor[1] = GetGValue(color) / 255.0f;
|
||||
impl->_backgroundColor[2] = GetBValue(color) / 255.0f;
|
||||
impl->_backgroundColor[3] = 1.0f;
|
||||
|
||||
_swapChain = New<xna::SwapChain>(_this);
|
||||
_swapChain->Initialize();
|
||||
impl->_swapChain = New<xna::SwapChain>(_this);
|
||||
impl->_swapChain->Initialize();
|
||||
|
||||
hr = _factory->MakeWindowAssociation(gameWindow.impl->WindowHandle(), DXGI_MWA_NO_ALT_ENTER);
|
||||
hr = impl->_factory->MakeWindowAssociation(gameWindow.impl->WindowHandle(), DXGI_MWA_NO_ALT_ENTER);
|
||||
if (FAILED(hr)) return false;
|
||||
|
||||
_renderTarget2D = New<RenderTarget2D>(_this);
|
||||
if (!_renderTarget2D->Initialize())
|
||||
impl->_renderTarget2D = New<RenderTarget2D>(_this);
|
||||
if (!impl->_renderTarget2D->Initialize())
|
||||
return false;
|
||||
|
||||
_renderTarget2D->Apply();
|
||||
impl->_renderTarget2D->Apply();
|
||||
|
||||
D3D11_VIEWPORT view{};
|
||||
view.TopLeftX = _viewport.X;
|
||||
view.TopLeftY = _viewport.Y;
|
||||
view.Width = _viewport.Width;
|
||||
view.Height = _viewport.Height;
|
||||
view.MinDepth = _viewport.MinDetph;
|
||||
view.MaxDepth = _viewport.MaxDepth;
|
||||
view.TopLeftX = impl->_viewport.X;
|
||||
view.TopLeftY = impl->_viewport.Y;
|
||||
view.Width = impl->_viewport.Width;
|
||||
view.Height = impl->_viewport.Height;
|
||||
view.MinDepth = impl->_viewport.MinDetph;
|
||||
view.MaxDepth = impl->_viewport.MaxDepth;
|
||||
|
||||
_context->RSSetViewports(1, &view);
|
||||
impl->_context->RSSetViewports(1, &view);
|
||||
|
||||
_blendState = BlendState::NonPremultiplied();
|
||||
_blendState->Bind(_this);
|
||||
_blendState->Apply();
|
||||
impl->_blendState = BlendState::NonPremultiplied();
|
||||
impl->_blendState->Bind(_this);
|
||||
impl->_blendState->Apply();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GraphicsDevice::Present() {
|
||||
const auto result = _swapChain->Present(_usevsync);
|
||||
_context->OMSetRenderTargets(1, &_renderTarget2D->render_impl->_renderTargetView, nullptr);
|
||||
if (!impl) return false;
|
||||
|
||||
const auto result = impl->_swapChain->Present(impl->_usevsync);
|
||||
impl->_context->OMSetRenderTargets(1, &impl->_renderTarget2D->render_impl->_renderTargetView, nullptr);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool GraphicsDevice::createDevice() {
|
||||
#if _DEBUG
|
||||
_createDeviceFlags |= D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG;
|
||||
#endif
|
||||
|
||||
if FAILED(
|
||||
D3D11CreateDevice(
|
||||
_adapter->impl->dxadapter,
|
||||
D3D_DRIVER_TYPE_UNKNOWN,
|
||||
NULL,
|
||||
_createDeviceFlags,
|
||||
NULL,
|
||||
0,
|
||||
D3D11_SDK_VERSION,
|
||||
&_device,
|
||||
&_featureLevel,
|
||||
&_context)) {
|
||||
|
||||
if FAILED(D3D11CreateDevice(
|
||||
NULL,
|
||||
D3D_DRIVER_TYPE_WARP,
|
||||
NULL,
|
||||
_createDeviceFlags,
|
||||
NULL,
|
||||
0,
|
||||
D3D11_SDK_VERSION,
|
||||
&_device,
|
||||
&_featureLevel,
|
||||
&_context))
|
||||
return false;
|
||||
|
||||
OutputDebugString("---> Usando Adaptador WARP: não há suporte ao D3D11\n");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GraphicsDevice::reset()
|
||||
{
|
||||
if (_device) {
|
||||
_device->Release();
|
||||
_device = nullptr;
|
||||
}
|
||||
|
||||
if (_context) {
|
||||
_context->Release();
|
||||
_context = nullptr;
|
||||
}
|
||||
|
||||
if (_factory) {
|
||||
_factory->Release();
|
||||
_factory = nullptr;
|
||||
}
|
||||
|
||||
_blendState = nullptr;
|
||||
_swapChain = nullptr;
|
||||
_renderTarget2D = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsDevice::Clear() {
|
||||
_context->ClearRenderTargetView(_renderTarget2D->render_impl->_renderTargetView, _backgroundColor);
|
||||
if (!impl) return;
|
||||
|
||||
impl->_context->ClearRenderTargetView(impl->_renderTarget2D->render_impl->_renderTargetView, impl->_backgroundColor);
|
||||
}
|
||||
|
||||
void GraphicsDevice::Clear(Color const& color) {
|
||||
if (!impl) return;
|
||||
|
||||
const auto v4 = color.ToVector4();
|
||||
|
||||
_backgroundColor[0] = v4.X;
|
||||
_backgroundColor[1] = v4.Y;
|
||||
_backgroundColor[2] = v4.Z;
|
||||
_backgroundColor[3] = v4.W;
|
||||
impl->_backgroundColor[0] = v4.X;
|
||||
impl->_backgroundColor[1] = v4.Y;
|
||||
impl->_backgroundColor[2] = v4.Z;
|
||||
impl->_backgroundColor[3] = v4.W;
|
||||
|
||||
_context->ClearRenderTargetView(_renderTarget2D->render_impl->_renderTargetView, _backgroundColor);
|
||||
impl->_context->ClearRenderTargetView(
|
||||
impl->_renderTarget2D->render_impl->_renderTargetView,
|
||||
impl->_backgroundColor);
|
||||
}
|
||||
|
||||
sptr<GraphicsAdapter> GraphicsDevice::Adapter() const {
|
||||
if (!impl) return nullptr;
|
||||
|
||||
return impl->_adapter;
|
||||
}
|
||||
|
||||
void GraphicsDevice::Adapter(sptr<GraphicsAdapter> const& adapter) {
|
||||
if (!impl) return;
|
||||
|
||||
impl->_adapter = adapter;
|
||||
}
|
||||
|
||||
xna::Viewport GraphicsDevice::Viewport() const {
|
||||
if (!impl) return {};
|
||||
|
||||
return impl->_viewport;
|
||||
}
|
||||
|
||||
void GraphicsDevice::Viewport(xna::Viewport const& viewport) {
|
||||
if (!impl) return;
|
||||
|
||||
impl->_viewport = viewport;
|
||||
}
|
||||
|
||||
void GraphicsDevice::UseVSync(bool use) {
|
||||
if (!impl) return;
|
||||
|
||||
impl->_usevsync = use;
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
#include "game/gdevicemanager.hpp"
|
||||
#include "graphics/presentparams.hpp"
|
||||
#include "graphics/swapchain.hpp"
|
||||
#include "platform-dx/device-dx.hpp"
|
||||
#include "platform-dx/game-dx.hpp"
|
||||
#include "platform-dx/implementations.hpp"
|
||||
|
||||
@ -34,10 +33,10 @@ namespace xna {
|
||||
}
|
||||
|
||||
bool GraphicsDeviceManager::ToggleFullScreen() {
|
||||
if (!_game || !_game->graphicsDevice || !_game->graphicsDevice->_swapChain)
|
||||
if (!_game || !_game->graphicsDevice || !_game->graphicsDevice->impl->_swapChain)
|
||||
return false;
|
||||
|
||||
auto& swap = _game->graphicsDevice->_swapChain;
|
||||
auto& swap = _game->graphicsDevice->impl->_swapChain;
|
||||
|
||||
BOOL state = false;
|
||||
auto hr = swap->impl->dxSwapChain->GetFullscreenState(&state, nullptr);
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "graphics/rasterizerstate.hpp"
|
||||
#include "platform-dx/implementations.hpp"
|
||||
#include "platform-dx/device-dx.hpp"
|
||||
|
||||
namespace xna {
|
||||
|
||||
@ -18,7 +17,7 @@ namespace xna {
|
||||
|
||||
bool RasterizerState::Initialize(xna_error_ptr_arg)
|
||||
{
|
||||
if (!impl || !m_device || !m_device->_device) {
|
||||
if (!impl || !m_device || !m_device->impl->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -28,7 +27,7 @@ namespace xna {
|
||||
impl->dxRasterizerState = nullptr;
|
||||
}
|
||||
|
||||
const auto hr = m_device->_device->CreateRasterizerState(
|
||||
const auto hr = m_device->impl->_device->CreateRasterizerState(
|
||||
&impl->dxDescription,
|
||||
&impl->dxRasterizerState);
|
||||
|
||||
@ -42,7 +41,7 @@ namespace xna {
|
||||
|
||||
bool RasterizerState::Apply(xna_error_ptr_arg)
|
||||
{
|
||||
if (!impl || !m_device || !m_device->_context) {
|
||||
if (!impl || !m_device || !m_device->impl->_context) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -52,7 +51,7 @@ namespace xna {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_device->_context->RSSetState(impl->dxRasterizerState);
|
||||
m_device->impl->_context->RSSetState(impl->dxRasterizerState);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,7 +1,4 @@
|
||||
#include "graphics/device.hpp"
|
||||
#include "platform-dx/device-dx.hpp"
|
||||
#include "platform-dx/implementations.hpp"
|
||||
#include "graphics/rendertarget.hpp"
|
||||
|
||||
namespace xna {
|
||||
RenderTarget2D::RenderTarget2D() : Texture2D() {
|
||||
@ -17,7 +14,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
bool RenderTarget2D::Initialize(xna_error_ptr_arg) {
|
||||
if (!impl || !m_device || !m_device->_device) {
|
||||
if (!impl || !m_device || !m_device->impl->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -27,10 +24,10 @@ namespace xna {
|
||||
impl->dxTexture2D = nullptr;
|
||||
}
|
||||
|
||||
if (!m_device->_swapChain->impl->GetBackBuffer(impl->dxTexture2D))
|
||||
if (!m_device->impl->_swapChain->impl->GetBackBuffer(impl->dxTexture2D))
|
||||
return false;
|
||||
|
||||
auto& dxdevice = m_device->_device;
|
||||
auto& dxdevice = m_device->impl->_device;
|
||||
|
||||
const auto hr = dxdevice->CreateRenderTargetView(impl->dxTexture2D, NULL, &render_impl->_renderTargetView);
|
||||
|
||||
@ -43,12 +40,12 @@ namespace xna {
|
||||
}
|
||||
|
||||
bool RenderTarget2D::Apply(xna_error_ptr_arg) {
|
||||
if (!m_device || !m_device->_context) {
|
||||
if (!m_device || !m_device->impl->_context) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& context = m_device->_context;
|
||||
auto& context = m_device->impl->_context;
|
||||
context->OMSetRenderTargets(1, &render_impl->_renderTargetView, nullptr);
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "graphics/samplerstate.hpp"
|
||||
#include "platform-dx/device-dx.hpp"
|
||||
#include "graphics/samplerstate.hpp"
|
||||
#include "platform-dx/implementations.hpp"
|
||||
#include "platform-dx/dxhelpers.hpp"
|
||||
@ -19,7 +18,7 @@ namespace xna {
|
||||
|
||||
bool SamplerState::Initialize(xna_error_ptr_arg)
|
||||
{
|
||||
if (!impl || !m_device || !m_device->_device) {
|
||||
if (!impl || !m_device || !m_device->impl->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -29,7 +28,7 @@ namespace xna {
|
||||
impl->_samplerState = nullptr;
|
||||
}
|
||||
|
||||
const auto hr = m_device->_device->CreateSamplerState(
|
||||
const auto hr = m_device->impl->_device->CreateSamplerState(
|
||||
&impl->_description,
|
||||
&impl->_samplerState);
|
||||
|
||||
@ -43,7 +42,7 @@ namespace xna {
|
||||
|
||||
bool SamplerState::Apply(xna_error_ptr_arg)
|
||||
{
|
||||
if (!impl || !m_device || !m_device->_context) {
|
||||
if (!impl || !m_device || !m_device->impl->_context) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -53,7 +52,7 @@ namespace xna {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_device->_context->PSSetSamplers(0, 1, &impl->_samplerState);
|
||||
m_device->impl->_context->PSSetSamplers(0, 1, &impl->_samplerState);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include "platform-dx/device-dx.hpp"
|
||||
#include "graphics/buffer.hpp"
|
||||
#include "platform-dx/implementations.hpp"
|
||||
#include "graphics/shader.hpp"
|
||||
@ -64,7 +63,7 @@ namespace xna {
|
||||
|
||||
bool VertexShader::Initialize(DataBuffer& buffer, xna_error_ptr_arg)
|
||||
{
|
||||
if (!impl || !m_device || !m_device->_device || !buffer.impl->_blob) {
|
||||
if (!impl || !m_device || !m_device->impl->_device || !buffer.impl->_blob) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -74,7 +73,7 @@ namespace xna {
|
||||
impl->_vertexShader = nullptr;
|
||||
}
|
||||
|
||||
const auto hr = m_device->_device->CreateVertexShader(
|
||||
const auto hr = m_device->impl->_device->CreateVertexShader(
|
||||
buffer.impl->_blob->GetBufferPointer(),
|
||||
buffer.impl->_blob->GetBufferSize(),
|
||||
NULL,
|
||||
@ -90,7 +89,7 @@ namespace xna {
|
||||
|
||||
bool PixelShader::Initialize(DataBuffer& buffer, xna_error_ptr_arg)
|
||||
{
|
||||
if (!impl || !m_device || !m_device->_device || !buffer.impl->_blob) {
|
||||
if (!impl || !m_device || !m_device->impl->_device || !buffer.impl->_blob) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
@ -100,7 +99,7 @@ namespace xna {
|
||||
impl->_pixelShader = nullptr;
|
||||
}
|
||||
|
||||
const auto hr = m_device->_device->CreatePixelShader(
|
||||
const auto hr = m_device->impl->_device->CreatePixelShader(
|
||||
buffer.impl->_blob->GetBufferPointer(),
|
||||
buffer.impl->_blob->GetBufferSize(),
|
||||
NULL,
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include "platform-dx/device-dx.hpp"
|
||||
#include "graphics/rasterizerstate.hpp"
|
||||
#include "graphics/samplerstate.hpp"
|
||||
#include "common/color.hpp"
|
||||
@ -24,7 +23,7 @@ namespace xna {
|
||||
{
|
||||
const auto wString = XnaHToWString(fontFileName);
|
||||
implementation = uNew<PlatformImplementation>();
|
||||
implementation->_dxSpriteFont = New<DxSpriteFont>(device._device, wString.c_str());
|
||||
implementation->_dxSpriteFont = New<DxSpriteFont>(device.impl->_device, wString.c_str());
|
||||
}
|
||||
|
||||
SpriteFont::~SpriteFont() {}
|
||||
@ -47,11 +46,11 @@ namespace xna {
|
||||
}
|
||||
|
||||
SpriteBatch::SpriteBatch(GraphicsDevice& device) {
|
||||
if (!device._context)
|
||||
if (!device.impl->_context)
|
||||
return;
|
||||
|
||||
implementation = uNew<PlatformImplementation>();
|
||||
implementation->_dxspriteBatch = New<DxSpriteBatch>(device._context);
|
||||
implementation->_dxspriteBatch = New<DxSpriteBatch>(device.impl->_context);
|
||||
|
||||
Viewport(device.Viewport());
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "platform-dx/device-dx.hpp"
|
||||
#include "platform-dx/dxhelpers.hpp"
|
||||
#include "graphics/adapter.hpp"
|
||||
#include "graphics/swapchain.hpp"
|
||||
#include "platform-dx/implementations.hpp"
|
||||
#include "graphics/device.hpp"
|
||||
|
||||
namespace xna {
|
||||
SwapChain::SwapChain() : GraphicsResource(nullptr) {
|
||||
@ -18,7 +18,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
static bool internalInit(GraphicsDevice& device, HWND windowHandle, IDXGISwapChain1*& swapChain, DXGI_SWAP_CHAIN_DESC1 const& desc, DXGI_SWAP_CHAIN_FULLSCREEN_DESC const& fdesc) {
|
||||
if (!device._device || !windowHandle)
|
||||
if (!device.impl->_device || !windowHandle)
|
||||
return false;
|
||||
|
||||
if (swapChain) {
|
||||
@ -40,7 +40,7 @@ namespace xna {
|
||||
if (FAILED(hr)) return false;
|
||||
|
||||
dxFactory2->CreateSwapChainForHwnd(
|
||||
device._device,
|
||||
device.impl->_device,
|
||||
windowHandle,
|
||||
&desc,
|
||||
&fdesc,
|
||||
@ -52,12 +52,12 @@ namespace xna {
|
||||
}
|
||||
|
||||
bool SwapChain::Initialize(xna_error_ptr_arg) {
|
||||
if (!impl || !m_device || !m_device->_device) {
|
||||
if (!impl || !m_device || !m_device->impl->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto parameters = m_device->_presentationParameters;
|
||||
const auto parameters = m_device->impl->_presentationParameters;
|
||||
|
||||
impl->dxDescription.Width = static_cast<UINT>(parameters->BackBufferWidth);
|
||||
impl->dxDescription.Height = static_cast<UINT>(parameters->BackBufferHeight);
|
||||
|
@ -1,5 +1,3 @@
|
||||
#include "platform-dx/device-dx.hpp"
|
||||
#include "graphics/adapter.hpp"
|
||||
#include "platform-dx/implementations.hpp"
|
||||
#include "platform-dx/dxhelpers.hpp"
|
||||
|
||||
@ -16,8 +14,8 @@ namespace xna {
|
||||
auto wstr = XnaHToWString(fileName);
|
||||
|
||||
HRESULT result = DirectX::CreateWICTextureFromFile(
|
||||
device._device,
|
||||
device._context,
|
||||
device.impl->_device,
|
||||
device.impl->_context,
|
||||
wstr.c_str(),
|
||||
&resource,
|
||||
&texture2d->impl->dxShaderResource,
|
||||
@ -65,12 +63,12 @@ namespace xna {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_device || !m_device->_device) {
|
||||
if (!m_device || !m_device->impl->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto hr = m_device->_device->CreateTexture2D(&impl->dxDescription, nullptr, &impl->dxTexture2D);
|
||||
auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, &impl->dxTexture2D);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||
@ -85,7 +83,7 @@ namespace xna {
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = m_device->_device->CreateShaderResourceView(resource, &impl->dxShaderDescription, &impl->dxShaderResource);
|
||||
hr = m_device->impl->_device->CreateShaderResourceView(resource, &impl->dxShaderDescription, &impl->dxShaderResource);
|
||||
|
||||
if (resource) {
|
||||
resource->Release();
|
||||
@ -144,7 +142,7 @@ namespace xna {
|
||||
HRESULT internalSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data, xna_error_ptr_arg)
|
||||
{
|
||||
if (!impl.dxTexture2D) {
|
||||
auto hr = device._device->CreateTexture2D(&impl.dxDescription, nullptr, &impl.dxTexture2D);
|
||||
auto hr = device.impl->_device->CreateTexture2D(&impl.dxDescription, nullptr, &impl.dxTexture2D);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||
@ -161,7 +159,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
constexpr int R8G8B8A8U_BYTE_SIZE = 4;
|
||||
device._context->UpdateSubresource(resource, 0, nullptr, data, impl.dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0);
|
||||
device.impl->_context->UpdateSubresource(resource, 0, nullptr, data, impl.dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0);
|
||||
|
||||
if (impl.dxShaderResource) {
|
||||
impl.dxShaderResource->Release();
|
||||
@ -169,7 +167,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
impl.dxShaderDescription.Texture2D.MipLevels = impl.dxDescription.MipLevels;
|
||||
hr = device._device->CreateShaderResourceView(resource, &impl.dxShaderDescription, &impl.dxShaderResource);
|
||||
hr = device.impl->_device->CreateShaderResourceView(resource, &impl.dxShaderDescription, &impl.dxShaderResource);
|
||||
|
||||
if (resource) {
|
||||
resource->Release();
|
||||
@ -188,7 +186,7 @@ namespace xna {
|
||||
|
||||
void Texture2D::SetData(std::vector<Uint> const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg)
|
||||
{
|
||||
if (!impl || !m_device || !m_device->_device || !m_device->_context) {
|
||||
if (!impl || !m_device || !m_device->impl->_device || !m_device->impl->_context) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
@ -198,7 +196,7 @@ namespace xna {
|
||||
|
||||
void Texture2D::SetData(std::vector<Byte> const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg)
|
||||
{
|
||||
if (!m_device || !m_device->_device || !m_device->_context) {
|
||||
if (!m_device || !m_device->impl->_device || !m_device->impl->_context) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
@ -220,7 +218,7 @@ namespace xna {
|
||||
|
||||
void Texture2D::SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg)
|
||||
{
|
||||
if (!m_device || !m_device->_device || !m_device->_context) {
|
||||
if (!m_device || !m_device->impl->_device || !m_device->impl->_context) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
@ -238,7 +236,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
if (!impl->dxTexture2D) {
|
||||
auto hr = m_device->_device->CreateTexture2D(&impl->dxDescription, nullptr, &impl->dxTexture2D);
|
||||
auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, &impl->dxTexture2D);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||
@ -266,7 +264,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
constexpr int R8G8B8A8U_BYTE_SIZE = 4;
|
||||
m_device->_context->UpdateSubresource(resource, 0, rect ? &box : nullptr, finalData.data(), impl->dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0);
|
||||
m_device->impl->_context->UpdateSubresource(resource, 0, rect ? &box : nullptr, finalData.data(), impl->dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0);
|
||||
|
||||
if (impl->dxShaderResource) {
|
||||
impl->dxShaderResource->Release();
|
||||
@ -274,7 +272,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
impl->dxShaderDescription.Texture2D.MipLevels = impl->dxDescription.MipLevels;
|
||||
hr = m_device->_device->CreateShaderResourceView(resource, &impl->dxShaderDescription, &impl->dxShaderResource);
|
||||
hr = m_device->impl->_device->CreateShaderResourceView(resource, &impl->dxShaderDescription, &impl->dxShaderResource);
|
||||
|
||||
if (resource) {
|
||||
resource->Release();
|
||||
@ -291,7 +289,7 @@ namespace xna {
|
||||
|
||||
void Texture2D::SetData(std::vector<Color> const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg)
|
||||
{
|
||||
if (!m_device || !m_device->_device || !m_device->_context) {
|
||||
if (!m_device || !m_device->impl->_device || !m_device->impl->_context) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
@ -314,8 +312,8 @@ namespace xna {
|
||||
ID3D11Resource* resource = nullptr;
|
||||
|
||||
auto hr = DirectX::CreateWICTextureFromMemory(
|
||||
device._device,
|
||||
device._context,
|
||||
device.impl->_device,
|
||||
device.impl->_context,
|
||||
data.data(),
|
||||
data.size(),
|
||||
&resource,
|
||||
|
@ -1,29 +1,27 @@
|
||||
#ifndef XNA_GRAPHICS_DEVICE_HPP
|
||||
#define XNA_GRAPHICS_DEVICE_HPP
|
||||
|
||||
#include "../enums.hpp"
|
||||
#include "../forward.hpp"
|
||||
#include "../game/window.hpp"
|
||||
#include "../types.hpp"
|
||||
#include "adapter.hpp"
|
||||
#include "rendertarget.hpp"
|
||||
#include "swapchain.hpp"
|
||||
#include "viewport.hpp"
|
||||
#include "blendstate.hpp"
|
||||
#include "../default.hpp"
|
||||
|
||||
namespace xna {
|
||||
class IGraphicsDevice {
|
||||
class GraphicsDevice : public std::enable_shared_from_this<GraphicsDevice> {
|
||||
public:
|
||||
virtual ~IGraphicsDevice() {}
|
||||
virtual void Clear() = 0;
|
||||
virtual void Clear(Color const& color) = 0;
|
||||
virtual bool Initialize(GameWindow& gameWindow) = 0;
|
||||
virtual bool Present() = 0;
|
||||
virtual sptr<GraphicsAdapter> Adapter() const = 0;
|
||||
virtual void Adapter(sptr<GraphicsAdapter> const& adapter) = 0;
|
||||
virtual xna::Viewport Viewport() const = 0;
|
||||
virtual void Viewport(xna::Viewport const& viewport) = 0;
|
||||
virtual void UseVSync(bool use) = 0;
|
||||
GraphicsDevice();
|
||||
GraphicsDevice(GraphicsDeviceInformation const& info);
|
||||
~GraphicsDevice();
|
||||
void Clear();
|
||||
void Clear(Color const& color);
|
||||
bool Initialize(GameWindow& gameWindow);
|
||||
bool Present();
|
||||
sptr<GraphicsAdapter> Adapter() const;
|
||||
void Adapter(sptr<GraphicsAdapter> const& adapter);
|
||||
xna::Viewport Viewport() const;
|
||||
void Viewport(xna::Viewport const& viewport);
|
||||
void UseVSync(bool use);
|
||||
|
||||
public:
|
||||
struct PlatformImplementation;
|
||||
uptr<PlatformImplementation> impl = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define XNA_GRAPHICS_SPRITE_HPP
|
||||
|
||||
#include "../default.hpp"
|
||||
#include "../common/numerics.hpp"
|
||||
#include "common/numerics.hpp"
|
||||
#include "common/color.hpp"
|
||||
|
||||
namespace xna {
|
||||
|
@ -1,91 +0,0 @@
|
||||
#ifndef XNA_PLATFORM_DEVICE_DX_HPP
|
||||
#define XNA_PLATFORM_DEVICE_DX_HPP
|
||||
|
||||
#include "../common/color.hpp"
|
||||
#include "../graphics/device.hpp"
|
||||
#include "../graphics/presentparams.hpp"
|
||||
#include "../graphics/viewport.hpp"
|
||||
#include "dxheaders.hpp"
|
||||
#include "game/gdeviceinfo.hpp"
|
||||
|
||||
namespace xna {
|
||||
class GraphicsDevice : public IGraphicsDevice, public std::enable_shared_from_this<GraphicsDevice> {
|
||||
public:
|
||||
GraphicsDevice();
|
||||
GraphicsDevice(GraphicsDeviceInformation const& info);
|
||||
|
||||
virtual ~GraphicsDevice() override {
|
||||
if (_device) {
|
||||
_device->Release();
|
||||
_device = nullptr;
|
||||
}
|
||||
|
||||
if (_context) {
|
||||
_context->Release();
|
||||
_context = nullptr;
|
||||
}
|
||||
|
||||
if (_factory) {
|
||||
_factory->Release();
|
||||
_factory = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void Clear() override;
|
||||
virtual void Clear(Color const& color) override;
|
||||
virtual bool Initialize(GameWindow& gameWindow) override;
|
||||
virtual bool Present() override;
|
||||
|
||||
virtual sptr<GraphicsAdapter> Adapter() const override {
|
||||
return _adapter;
|
||||
}
|
||||
|
||||
virtual void Adapter(sptr<GraphicsAdapter> const& adapter) override {
|
||||
_adapter = adapter;
|
||||
}
|
||||
|
||||
virtual constexpr xna::Viewport Viewport() const override {
|
||||
return _viewport;
|
||||
}
|
||||
|
||||
virtual constexpr void Viewport(xna::Viewport const& viewport) override {
|
||||
_viewport = viewport;
|
||||
}
|
||||
|
||||
virtual void UseVSync(bool use) override {
|
||||
_usevsync = use;
|
||||
}
|
||||
|
||||
constexpr void SetCreateFlags(D3D11_CREATE_DEVICE_FLAG flags) {
|
||||
_createDeviceFlags |= flags;
|
||||
}
|
||||
|
||||
constexpr void ClearCreateFlags() {
|
||||
_createDeviceFlags = 0;
|
||||
}
|
||||
|
||||
bool GetSwapChainBackBuffer(ID3D11Texture2D*& texture2D);
|
||||
|
||||
public:
|
||||
ID3D11Device* _device{ nullptr };
|
||||
ID3D11DeviceContext* _context{ nullptr };
|
||||
IDXGIFactory1* _factory = nullptr;
|
||||
sptr<SwapChain> _swapChain{ nullptr };
|
||||
sptr<GraphicsAdapter> _adapter{ nullptr };
|
||||
sptr<RenderTarget2D> _renderTarget2D{ nullptr };
|
||||
sptr<BlendState> _blendState{ nullptr };
|
||||
xna::Viewport _viewport{};
|
||||
sptr<xna::PresentationParameters> _presentationParameters;
|
||||
|
||||
private:
|
||||
unsigned int _createDeviceFlags{ 0 };
|
||||
D3D_FEATURE_LEVEL _featureLevel{ D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0 };
|
||||
float _backgroundColor[4] = { 0, 0, 0, 0 };
|
||||
bool _usevsync{ true };
|
||||
|
||||
bool createDevice();
|
||||
void reset();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -2,7 +2,7 @@
|
||||
#define XNA_PLATFORM_DX_IMPLEMENTATIONS_HPP
|
||||
|
||||
#include "dxheaders.hpp"
|
||||
#include "platform-dx/device-dx.hpp"
|
||||
#include "graphics/device.hpp"
|
||||
#include "graphics/adapter.hpp"
|
||||
#include "graphics/blendstate.hpp"
|
||||
#include "graphics/buffer.hpp"
|
||||
@ -21,6 +21,8 @@
|
||||
#include "graphics/rendertarget.hpp"
|
||||
#include "game/window.hpp"
|
||||
#include "audio/audioengine.hpp"
|
||||
#include "graphics/viewport.hpp"
|
||||
#include "common/color.hpp"
|
||||
|
||||
namespace xna {
|
||||
struct SpriteFont::PlatformImplementation {
|
||||
@ -174,24 +176,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
struct Keyboard::PlatformImplementation {
|
||||
inline static uptr<DirectX::Keyboard> _dxKeyboard = nullptr;
|
||||
@ -314,26 +299,7 @@ namespace xna {
|
||||
|
||||
ID3D11Buffer* dxBuffer = nullptr;
|
||||
UINT size{ 0 };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline bool VertexBuffer::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_VERTEX_BUFFER, &impl->dxBuffer);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
impl->size = sizeof(T);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct VertexInputLayout::PlatformImplementation {
|
||||
~PlatformImplementation() {
|
||||
@ -476,6 +442,60 @@ namespace xna {
|
||||
|
||||
uptr<DirectX::AudioEngine> _dxAudioEngine = nullptr;
|
||||
};
|
||||
|
||||
struct GraphicsDevice::PlatformImplementation {
|
||||
ID3D11Device* _device{ nullptr };
|
||||
ID3D11DeviceContext* _context{ nullptr };
|
||||
IDXGIFactory1* _factory = nullptr;
|
||||
sptr<SwapChain> _swapChain{ nullptr };
|
||||
sptr<GraphicsAdapter> _adapter{ nullptr };
|
||||
sptr<RenderTarget2D> _renderTarget2D{ nullptr };
|
||||
sptr<BlendState> _blendState{ nullptr };
|
||||
xna::Viewport _viewport{};
|
||||
sptr<xna::PresentationParameters> _presentationParameters;
|
||||
D3D_FEATURE_LEVEL _featureLevel{ D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0 };
|
||||
|
||||
private:
|
||||
friend class GraphicsDevice;
|
||||
float _backgroundColor[4] = { 0, 0, 0, 0 };
|
||||
bool _usevsync{ true };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline bool IndexBuffer::Initialize(std::vector<T> const& data, xna_error_ptr_arg) {
|
||||
if (!impl || !m_device || !m_device->impl->_device || data.empty()) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto hr = DirectX::CreateStaticBuffer(m_device->impl->_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;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool VertexBuffer::Initialize(std::vector<T> const& data, xna_error_ptr_arg) {
|
||||
if (!impl || !m_device || !m_device->impl->_device || data.empty()) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto hr = DirectX::CreateStaticBuffer(m_device->impl->_device, data.data(), data.size(), sizeof(T), D3D11_BIND_VERTEX_BUFFER, &impl->dxBuffer);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
impl->size = sizeof(T);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,5 +1,4 @@
|
||||
#include "content-readers/texture2Dreader-dx.hpp"
|
||||
#include "device-dx.hpp"
|
||||
#include "dx/StepTimer.hpp"
|
||||
#include "dxheaders.hpp"
|
||||
#include "game-dx.hpp"
|
||||
|
Loading…
x
Reference in New Issue
Block a user