-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathxxGraphicD3D10_1.cpp
97 lines (86 loc) · 3.71 KB
/
xxGraphicD3D10_1.cpp
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
//==============================================================================
// xxGraphic : Direct3D 10.1 Source
//
// Copyright (c) 2019-2025 TAiGA
// https://github.com/metarutaiga/xxGraphic
//==============================================================================
#include "xxSystem.h"
#include "dxsdk/d3d10_1.h"
#include "internal/xxGraphicInternalD3D.h"
#include "xxGraphicD3D10.h"
#include "xxGraphicD3D10_1.h"
static void* g_d3dLibrary = nullptr;
//==============================================================================
// Instance
//==============================================================================
uint64_t xxCreateInstanceD3D10_1()
{
if (g_d3dLibrary == nullptr)
g_d3dLibrary = xxLoadLibrary("d3d10_1.dll");
if (g_d3dLibrary == nullptr)
return 0;
xxRegisterFunction(D3D10);
xxRegisterFunctionSingle(xxCreateInstance, xxCreateInstanceD3D10_1);
xxRegisterFunctionSingle(xxDestroyInstance, xxDestroyInstanceD3D10_1);
xxRegisterFunctionSingle(xxGetInstanceName, xxGetInstanceNameD3D10_1);
xxRegisterFunctionSingle(xxCreateDevice, xxCreateDeviceD3D10_1);
return reinterpret_cast<uint64_t>(g_d3dLibrary);
}
//------------------------------------------------------------------------------
void xxDestroyInstanceD3D10_1(uint64_t instance)
{
if (g_d3dLibrary)
{
xxFreeLibrary(g_d3dLibrary);
g_d3dLibrary = nullptr;
}
xxUnregisterFunction();
}
//==============================================================================
// Device
//==============================================================================
uint64_t xxCreateDeviceD3D10_1(uint64_t instance)
{
HMODULE d3d = reinterpret_cast<HMODULE>(instance);
if (d3d == nullptr)
return 0;
PFN_D3D10_CREATE_DEVICE1 D3D10CreateDevice1;
(void*&)D3D10CreateDevice1 = GetProcAddress(d3d, "D3D10CreateDevice1");
if (D3D10CreateDevice1 == nullptr)
return 0;
UINT flags = D3D10_CREATE_DEVICE_ALLOW_NULL_FROM_MAP | D3D10_CREATE_DEVICE_BGRA_SUPPORT;
#if defined(_DEBUG)
flags |= D3D10_CREATE_DEVICE_DEBUG;
#endif
ID3D10Device1* d3dDevice = nullptr;
HRESULT hResult = E_NOTIMPL;
if (hResult != S_OK)
hResult = D3D10CreateDevice1(nullptr, D3D10_DRIVER_TYPE_HARDWARE, nullptr, flags, D3D10_FEATURE_LEVEL_10_1, D3D10_1_SDK_VERSION, &d3dDevice);
if (hResult != S_OK)
hResult = D3D10CreateDevice1(nullptr, D3D10_DRIVER_TYPE_HARDWARE, nullptr, flags, D3D10_FEATURE_LEVEL_10_0, D3D10_1_SDK_VERSION, &d3dDevice);
if (hResult != S_OK)
hResult = D3D10CreateDevice1(nullptr, D3D10_DRIVER_TYPE_HARDWARE, nullptr, flags, D3D10_FEATURE_LEVEL_9_3, D3D10_1_SDK_VERSION, &d3dDevice);
if (hResult != S_OK)
hResult = D3D10CreateDevice1(nullptr, D3D10_DRIVER_TYPE_HARDWARE, nullptr, flags, D3D10_FEATURE_LEVEL_9_2, D3D10_1_SDK_VERSION, &d3dDevice);
if (hResult != S_OK)
hResult = D3D10CreateDevice1(nullptr, D3D10_DRIVER_TYPE_HARDWARE, nullptr, flags, D3D10_FEATURE_LEVEL_9_1, D3D10_1_SDK_VERSION, &d3dDevice);
if (hResult != S_OK)
return 0;
IUnknown* unknown = nullptr;
xxLocalBreak()
{
if (d3dDevice->QueryInterface(__uuidof(ID3D10Device1*), (void**)&unknown) == S_OK)
{
xxLog("xxGraphic", "%s %s (%s)", "Direct3D", "10.1", xxGetInstanceName());
break;
}
if (d3dDevice->QueryInterface(__uuidof(ID3D10Device*), (void**)&unknown) == S_OK)
{
xxLog("xxGraphic", "%s %s (%s)", "Direct3D", "10.0", xxGetInstanceName());
break;
}
}
SafeRelease(unknown);
return reinterpret_cast<uint64_t>(d3dDevice);
}
//==============================================================================