Add dynamic DirectX loading helper.

This commit is contained in:
John Preston 2021-06-30 13:44:28 +03:00
parent 6cea7d4a52
commit 7cedc1f7a5
3 changed files with 3 additions and 64 deletions

View File

@ -12,8 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <VersionHelpers.h>
#include <QtCore/QSysInfo>
#include <d3d11.h>
#define LOAD_SYMBOL(lib, name) ::base::Platform::LoadMethod(lib, #name, name)
namespace Platform {
@ -46,6 +44,7 @@ void init() {
u"rstrtmgr.dll"_q,
u"psapi.dll"_q,
u"user32.dll"_q,
u"d3d9.dll"_q,
u"d3d11.dll"_q,
u"dxgi.dll"_q,
};
@ -54,26 +53,6 @@ void init() {
}
}
// D3D11.DLL
HRESULT (__stdcall *D3D11CreateDevice)(
_In_opt_ IDXGIAdapter* pAdapter,
D3D_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
_In_reads_opt_(FeatureLevels) CONST D3D_FEATURE_LEVEL* pFeatureLevels,
UINT FeatureLevels,
UINT SDKVersion,
_COM_Outptr_opt_ ID3D11Device** ppDevice,
_Out_opt_ D3D_FEATURE_LEVEL* pFeatureLevel,
_COM_Outptr_opt_ ID3D11DeviceContext** ppImmediateContext);
// DXGI.DLL
HRESULT (__stdcall *CreateDXGIFactory1)(
REFIID riid,
_COM_Outptr_ void **ppFactory);
void start() {
init();
@ -123,47 +102,7 @@ void start() {
const auto LibUser32 = SafeLoadLibrary(u"user32.dll"_q);
LOAD_SYMBOL(LibUser32, SetWindowCompositionAttribute);
const auto LibD3D11 = SafeLoadLibrary(u"d3d11.dll"_q);
LOAD_SYMBOL(LibD3D11, D3D11CreateDevice);
const auto LibDXGI = SafeLoadLibrary(u"dxgi.dll"_q);
LOAD_SYMBOL(LibDXGI, CreateDXGIFactory1);
}
} // namespace Dlls
} // namespace Platform
HRESULT WINAPI D3D11CreateDevice(
_In_opt_ IDXGIAdapter* pAdapter,
D3D_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
_In_reads_opt_(FeatureLevels) CONST D3D_FEATURE_LEVEL* pFeatureLevels,
UINT FeatureLevels,
UINT SDKVersion,
_COM_Outptr_opt_ ID3D11Device** ppDevice,
_Out_opt_ D3D_FEATURE_LEVEL* pFeatureLevel,
_COM_Outptr_opt_ ID3D11DeviceContext** ppImmediateContext) {
return Platform::Dlls::D3D11CreateDevice
? Platform::Dlls::D3D11CreateDevice(
pAdapter,
DriverType,
Software,
Flags,
pFeatureLevels,
FeatureLevels,
SDKVersion,
ppDevice,
pFeatureLevel,
ppImmediateContext)
: S_FALSE;
}
HRESULT WINAPI CreateDXGIFactory1(
REFIID riid,
_COM_Outptr_ void **ppFactory) {
return Platform::Dlls::CreateDXGIFactory1
? Platform::Dlls::CreateDXGIFactory1(riid, ppFactory)
: S_FALSE;
}

2
cmake

@ -1 +1 @@
Subproject commit 8d7772ab33f2b04efde728decd8ae265a461b185
Subproject commit e2455f3194b3591d5046d0d38b8e5921c1149302

View File

@ -198,7 +198,6 @@ Open **x86 Native Tools Command Prompt for VS 2019.bat**, go to ***BuildPath***
configure ^
-prefix "%LibrariesPath%\Al-5.15.2" ^
-recheck ^
-debug-and-release ^
-force-debug-info ^
-opensource ^
@ -212,6 +211,7 @@ Open **x86 Native Tools Command Prompt for VS 2019.bat**, go to ***BuildPath***
QMAKE_LIBS_OPENGL_ES2_RELEASE="%LibrariesPath%\angle\out\Release\obj\libGLESv2_static.lib %LibrariesPath%\angle\out\Release\obj\libANGLE_static.lib d3d11.lib d3d9.lib dxgi.lib dxguid.lib" ^
-egl ^
-D "EGLAPI=" ^
-D "DESKTOP_APP_QT_STATIC_ANGLE=" ^
QMAKE_LIBS_EGL_DEBUG="%LibrariesPath%\angle\out\Debug\obj\libEGL_static.lib %LibrariesPath%\angle\out\Debug\obj\libGLESv2_static.lib %LibrariesPath%\angle\out\Debug\obj\libANGLE_static.lib d3d11.lib d3d9.lib dxgi.lib dxguid.lib Gdi32.lib User32.lib" ^
QMAKE_LIBS_EGL_RELEASE="%LibrariesPath%\angle\out\Release\obj\libEGL_static.lib %LibrariesPath%\angle\out\Release\obj\libGLESv2_static.lib %LibrariesPath%\angle\out\Release\obj\libANGLE_static.lib d3d11.lib d3d9.lib dxgi.lib dxguid.lib Gdi32.lib User32.lib" ^
-openssl-linked ^