-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynlink_d3d11.h
159 lines (138 loc) · 6.06 KB
/
dynlink_d3d11.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
*
* Please refer to the NVIDIA end user license agreement (EULA) associated
* with this source code for terms and conditions that govern your use of
* this software. Any use, reproduction, disclosure, or distribution of
* this software and related documentation outside the terms of the EULA
* is strictly prohibited.
*
*/
//--------------------------------------------------------------------------------------
// File: dynlink_d3d11.h
//
// Shortcut macros and functions for using DX objects
//
// Copyright (c) Microsoft Corporation. All rights reserved
//--------------------------------------------------------------------------------------
#ifndef _DYNLINK_D3D11_H_
#define _DYNLINK_D3D11_H_
// Standard Windows includes
#include <windows.h>
#include <initguid.h>
#include <assert.h>
#include <wchar.h>
#include <mmsystem.h>
#include <commctrl.h> // for InitCommonControls()
#include <shellapi.h> // for ExtractIcon()
#include <new.h> // for placement new
#include <shlobj.h>
#include <math.h>
#include <limits.h>
#include <stdio.h>
// CRT's memory leak detection
#if defined(DEBUG) || defined(_DEBUG)
#include <crtdbg.h>
#endif
// Direct3D9 includes
//#include <d3d9.h>
//#include <d3dx9.h>
// Direct3D10 includes
#include <dxgi.h>
#include <d3d11.h>
#include <d3dx11.h>
// #include <..\Samples\C++\Effects11\Inc\d3dx11effect.h>
// XInput includes
#include <xinput.h>
// HRESULT translation for Direct3D10 and other APIs
#include <dxerr.h>
// strsafe.h deprecates old unsecure string functions. If you
// really do not want to it to (not recommended), then uncomment the next line
//#define STRSAFE_NO_DEPRECATE
#ifndef STRSAFE_NO_DEPRECATE
#pragma deprecated("strncpy")
#pragma deprecated("wcsncpy")
#pragma deprecated("_tcsncpy")
#pragma deprecated("wcsncat")
#pragma deprecated("strncat")
#pragma deprecated("_tcsncat")
#endif
#pragma warning( disable : 4996 ) // disable deprecated warning
#include <strsafe.h>
#pragma warning( default : 4996 )
typedef HRESULT (WINAPI * LPCREATEDXGIFACTORY)(REFIID, void ** );
typedef HRESULT (WINAPI * LPD3D11CREATEDEVICEANDSWAPCHAIN)(__in_opt IDXGIAdapter* pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags, __in_ecount_opt( FeatureLevels ) CONST D3D_FEATURE_LEVEL* pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, __in_opt CONST DXGI_SWAP_CHAIN_DESC* pSwapChainDesc, __out_opt IDXGISwapChain** ppSwapChain, __out_opt ID3D11Device** ppDevice, __out_opt D3D_FEATURE_LEVEL* pFeatureLevel, __out_opt ID3D11DeviceContext** ppImmediateContext );
typedef HRESULT (WINAPI * LPD3D11CREATEDEVICE)( IDXGIAdapter*, D3D_DRIVER_TYPE, HMODULE, UINT32, D3D_FEATURE_LEVEL*, UINT, UINT32, ID3D11Device**, D3D_FEATURE_LEVEL*, ID3D11DeviceContext** );
typedef void (WINAPI * LPD3DX11COMPILEFROMMEMORY)(LPCSTR pSrcData, SIZE_T SrcDataLen, LPCSTR pFileName, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude,
LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3DX11ThreadPump* pPump, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs, HRESULT* pHResult);
static HMODULE s_hModDXGI = NULL;
static LPCREATEDXGIFACTORY sFnPtr_CreateDXGIFactory = NULL;
static HMODULE s_hModD3D11 = NULL;
static HMODULE s_hModD3DX11 = NULL;
static LPD3D11CREATEDEVICE sFnPtr_D3D11CreateDevice = NULL;
static LPD3D11CREATEDEVICEANDSWAPCHAIN sFnPtr_D3D11CreateDeviceAndSwapChain = NULL;
static LPD3DX11COMPILEFROMMEMORY sFnPtr_D3DX11CompileFromMemory = NULL;
// unload the D3D10 DLLs
static bool dynlinkUnloadD3D11API( void )
{
if (s_hModDXGI) {
FreeLibrary( s_hModDXGI ); s_hModDXGI = NULL;
}
if (s_hModD3D11) {
FreeLibrary( s_hModD3D11 ); s_hModD3D11 = NULL;
}
if (s_hModD3DX11) {
FreeLibrary( s_hModD3DX11 ); s_hModD3DX11 = NULL;
}
return true;
}
// Dynamically load the D3D11 DLLs loaded and map the function pointers
static bool dynlinkLoadD3D11API( void )
{
// If both modules are non-NULL, this function has already been called. Note
// that this doesn't guarantee that all ProcAddresses were found.
if( s_hModD3D11 != NULL && s_hModD3DX11 != NULL && s_hModDXGI != NULL )
return true;
#if 1
// This may fail if Direct3D 11 isn't installed
s_hModD3D11 = LoadLibrary( "d3d11.dll" );
if( s_hModD3D11 != NULL )
{
sFnPtr_D3D11CreateDevice = ( LPD3D11CREATEDEVICE )GetProcAddress( s_hModD3D11, "D3D11CreateDevice" );
sFnPtr_D3D11CreateDeviceAndSwapChain = (LPD3D11CREATEDEVICEANDSWAPCHAIN)GetProcAddress( s_hModD3D11, "D3D11CreateDeviceAndSwapChain" );
}
// first try to load D3DX11CompileFromMemory from DirectX 2010 June
s_hModD3DX11 = LoadLibrary( "D3DX11d_43.dll" );
if( s_hModD3DX11 != NULL )
{
sFnPtr_D3DX11CompileFromMemory = ( LPD3DX11COMPILEFROMMEMORY ) GetProcAddress( s_hModD3DX11, "D3DX11CompileFromMemory" );
}
else // if absent try to take it from DirectX 2010 Feb
{
s_hModD3DX11 = LoadLibrary( "D3DX11d_42.dll" );
if( s_hModD3DX11 != NULL )
{
sFnPtr_D3DX11CompileFromMemory = ( LPD3DX11COMPILEFROMMEMORY ) GetProcAddress( s_hModD3DX11, "D3DX11CompileFromMemory" );
}
}
if( !sFnPtr_CreateDXGIFactory )
{
s_hModDXGI = LoadLibrary( "dxgi.dll" );
if( s_hModDXGI )
{
sFnPtr_CreateDXGIFactory = ( LPCREATEDXGIFACTORY )GetProcAddress( s_hModDXGI, "CreateDXGIFactory1" );
}
return ( s_hModDXGI != NULL ) && ( s_hModD3D11 != NULL );
}
return ( s_hModD3D11 != NULL );
#else
sFnPtr_D3D11CreateDevice = ( LPD3D11CREATEDEVICE )D3D11CreateDeviceAndSwapChain;
sFnPtr_D3D11CreateDeviceAndSwapChain = (LPD3D11CREATEDEVICEANDSWAPCHAIN)D3D11CreateDeviceAndSwapChain;
//sFnPtr_D3DX11CreateEffectFromMemory = ( LPD3DX11CREATEEFFECTFROMMEMORY )D3DX11CreateEffectFromMemory;
sFnPtr_D3DX11CompileFromMemory = ( LPD3DX11COMPILEFROMMEMORY )D3DX11CompileFromMemory;
sFnPtr_CreateDXGIFactory = ( LPCREATEDXGIFACTORY )CreateDXGIFactory;
return true;
#endif
return true;
}
#endif