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

Correções em GraphicsDevice

This commit is contained in:
Danilo 2024-11-14 21:05:32 -03:00
parent a99e2a4a54
commit 60ff2b1d83
3 changed files with 215 additions and 217 deletions

View File

@ -44,6 +44,9 @@ namespace xna {
D3D_FEATURE_LEVEL CurrentFeatureLevel{ D3D_FEATURE_LEVEL_11_1 };
void Create(GraphicsAdapter& currentAdapter);
void Reset();
private:
friend class GraphicsDevice;
float backgroundColor[4] = { 0, 0, 0, 0 };

View File

@ -1,8 +1,75 @@
#include "xna-dx/framework.hpp"
namespace xna {
static void reset(GraphicsDeviceImplementation& impl);
static void createDevice(GraphicsDeviceImplementation& impl, GraphicsAdapter& currentAdapter);
void GraphicsDeviceImplementation::Create(GraphicsAdapter& currentAdapter) {
// See ref
//
// D3D_DRIVER_TYPE
// https://learn.microsoft.com/en-us/windows/win32/api/d3dcommon/ne-d3dcommon-d3d_driver_type
// D3D11CreateDevice function
// https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-d3d11createdevice
//
auto createDeviceFlags = 0;
#if _DEBUG
createDeviceFlags = D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG;
#endif
const auto& pAdapter = GraphicsAdapter::UseNullDevice() ? NULL : currentAdapter.Implementation->Adapter.Get();
//
// if pAdapter is not NULL driverType must be D3D_DRIVER_TYPE_UNKNOWN
//
auto driverType = D3D_DRIVER_TYPE_UNKNOWN;
if (GraphicsAdapter::UseReferenceDevice())
driverType = D3D_DRIVER_TYPE_WARP;
else if (GraphicsAdapter::UseNullDevice())
driverType = D3D_DRIVER_TYPE_HARDWARE;
auto hr = D3D11CreateDevice(
//_In_opt_ IDXGIAdapter* pAdapter,
pAdapter,
//D3D_DRIVER_TYPE DriverType,
driverType,
//HMODULE Software,
NULL,
//UINT Flags,
createDeviceFlags,
//_In_reads_opt_( FeatureLevels ) CONST D3D_FEATURE_LEVEL* pFeatureLevels,
FeatureLevels,
//UINT FeatureLevels,
7,
//UINT SDKVersion,
D3D11_SDK_VERSION,
//_COM_Outptr_opt_ ID3D11Device** ppDevice
Device.GetAddressOf(),
//_Out_opt_ D3D_FEATURE_LEVEL* pFeatureLevel,
&CurrentFeatureLevel,
//_COM_Outptr_opt_ ID3D11DeviceContext** ppImmediateContext
Context.GetAddressOf());
if FAILED(hr)
Exception::Throw(Exception::FAILED_TO_CREATE);
}
void GraphicsDeviceImplementation::Reset() {
if (Device) {
Device->Release();
Device = nullptr;
}
if (Context) {
Context->Release();
Context = nullptr;
}
if (Factory) {
Factory->Release();
Factory = nullptr;
}
}
static void initAndApplyState(P_BlendState& blendState, P_RasterizerState& rasterizerState,
P_DepthStencilState& depthStencilState, P_SamplerStateCollection& samplerStates, P_GraphicsDevice const& device);
@ -22,11 +89,11 @@ namespace xna {
}
void GraphicsDevice::Initialize() {
reset(*Implementation);
Implementation->Reset();
auto _this = shared_from_this();
createDevice(*Implementation, *adapter);
Implementation->Create(*adapter);
//
// Background
@ -192,78 +259,6 @@ namespace xna {
// INTERNAL
//
void reset(GraphicsDeviceImplementation& 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;
}
}
void createDevice(GraphicsDeviceImplementation& impl, GraphicsAdapter& currentAdapter) {
//
// See ref
//
// D3D_DRIVER_TYPE
// https://learn.microsoft.com/en-us/windows/win32/api/d3dcommon/ne-d3dcommon-d3d_driver_type
//
// D3D11CreateDevice function
// https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-d3d11createdevice
//
auto createDeviceFlags = 0;
#if _DEBUG
createDeviceFlags = D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG;
#endif
const auto& pAdapter = GraphicsAdapter::UseNullDevice() ? NULL : currentAdapter.Implementation->Adapter.Get();
//
// if pAdapter is not NULL driverType must be D3D_DRIVER_TYPE_UNKNOWN
//
auto driverType = D3D_DRIVER_TYPE_UNKNOWN;
if (GraphicsAdapter::UseReferenceDevice())
driverType = D3D_DRIVER_TYPE_WARP;
else if (GraphicsAdapter::UseNullDevice())
driverType = D3D_DRIVER_TYPE_HARDWARE;
auto hr = D3D11CreateDevice(
//_In_opt_ IDXGIAdapter* pAdapter,
pAdapter,
//D3D_DRIVER_TYPE DriverType,
driverType,
//HMODULE Software,
NULL,
//UINT Flags,
createDeviceFlags,
//_In_reads_opt_( FeatureLevels ) CONST D3D_FEATURE_LEVEL* pFeatureLevels,
GraphicsDeviceImplementation::FeatureLevels,
//UINT FeatureLevels,
7,
//UINT SDKVersion,
D3D11_SDK_VERSION,
//_COM_Outptr_opt_ ID3D11Device** ppDevice
impl.Device.GetAddressOf(),
//_Out_opt_ D3D_FEATURE_LEVEL* pFeatureLevel,
&impl.CurrentFeatureLevel,
//_COM_Outptr_opt_ ID3D11DeviceContext** ppImmediateContext
impl.Context.GetAddressOf());
if FAILED(hr)
Exception::Throw(Exception::FAILED_TO_CREATE);
}
static void initAndApplyState(P_BlendState& blendState, P_RasterizerState& rasterizerState, P_DepthStencilState& depthStencilState, P_SamplerStateCollection& samplerStates, P_GraphicsDevice const& device) {
blendState->Bind(device);
blendState->Initialize();