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

Melhorias em createDevice

This commit is contained in:
Danilo 2024-07-21 21:54:50 -03:00
parent fae2a4e28f
commit 2a26c5f5da
5 changed files with 56 additions and 26 deletions

View File

@ -23,6 +23,6 @@ project ("xna")
include_directories(${PROJECT_INCLUDES_DIR})
add_subdirectory ("framework")
#add_subdirectory ("samples")
add_subdirectory ("samples")

View File

@ -37,6 +37,8 @@ namespace xna {
setOutputVars(pAdapter, adp->deviceName, adp->monitorHandle);
adp->supportedDisplayModes = getSupportedDisplayModes(pAdapter);
setCurrentDisplayMode(*adp->supportedDisplayModes, SurfaceFormat::Color,
GraphicsDeviceManager::DefaultBackBufferWidth,
GraphicsDeviceManager::DefaultBackBufferHeight, adp->currentDisplayMode);

View File

@ -21,42 +21,58 @@ namespace xna {
}
static void createDevice(GraphicsDevice::PlatformImplementation& impl) {
//
// 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& currentAdapter = impl._adapter;
const auto& pAdapter = GraphicsAdapter::UseNullDevice() ? NULL : currentAdapter->impl->dxAdapter.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(
currentAdapter ? currentAdapter->impl->dxAdapter.Get() : NULL,
D3D_DRIVER_TYPE_UNKNOWN,
//_In_opt_ IDXGIAdapter* pAdapter,
pAdapter,
//D3D_DRIVER_TYPE DriverType,
driverType,
//HMODULE Software,
NULL,
//UINT Flags,
createDeviceFlags,
NULL,
0,
//_In_reads_opt_( FeatureLevels ) CONST D3D_FEATURE_LEVEL* pFeatureLevels,
impl.featureLevels,
//UINT FeatureLevels,
7,
//UINT SDKVersion,
D3D11_SDK_VERSION,
//_COM_Outptr_opt_ ID3D11Device** ppDevice
impl._device.GetAddressOf(),
&impl._featureLevel,
//_Out_opt_ D3D_FEATURE_LEVEL* pFeatureLevel,
&impl.currentFeatureLevel,
//_COM_Outptr_opt_ ID3D11DeviceContext** ppImmediateContext
impl._context.GetAddressOf());
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.GetAddressOf(),
&impl._featureLevel,
impl._context.GetAddressOf());
if FAILED(hr)
Exception::Throw(Exception::FAILED_TO_CREATE);
}
if FAILED(hr)
Exception::Throw(Exception::FAILED_TO_CREATE);
}
static void initAndApplyState(GraphicsDevice::PlatformImplementation& impl, PGraphicsDevice const& device) {

View File

@ -845,7 +845,19 @@ namespace xna {
sptr<GameWindow> _gameWindow = nullptr;
xna::Viewport _viewport{};
sptr<xna::PresentationParameters> _presentationParameters;
D3D_FEATURE_LEVEL _featureLevel{ D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_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;
private:
friend class GraphicsDevice;

View File

@ -4,4 +4,4 @@
# Add source to this project's executable.
add_subdirectory ("01_blank")
add_subdirectory ("02_PlatfformerStarterKit")
#add_subdirectory ("02_PlatfformerStarterKit")