Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Graphics/DX11/DX11RenderDevice.hpp
1168 views
1
const auto _wapiShowCursor = ShowCursor;
2
const auto _wapiGetCursorPos = GetCursorPos;
3
4
class RenderDevice : public RenderDeviceBase
5
{
6
public:
7
struct WindowInfo {
8
union {
9
struct {
10
UINT width;
11
UINT height;
12
DXGI_RATIONAL refresh_rate;
13
};
14
DXGI_MODE_DESC internal;
15
} * displays;
16
D3D11_VIEWPORT viewport;
17
};
18
static WindowInfo displayInfo;
19
20
static bool Init();
21
static void CopyFrameBuffer();
22
static void FlipScreen();
23
static void Release(bool32 isRefresh);
24
25
static void RefreshWindow();
26
static void GetWindowSize(int32 *width, int32 *height);
27
28
static void SetupImageTexture(int32 width, int32 height, uint8 *imagePixels);
29
static void SetupVideoTexture_YUV420(int32 width, int32 height, uint8 *yPlane, uint8 *uPlane, uint8 *vPlane, int32 strideY, int32 strideU,
30
int32 strideV);
31
static void SetupVideoTexture_YUV422(int32 width, int32 height, uint8 *yPlane, uint8 *uPlane, uint8 *vPlane, int32 strideY, int32 strideU,
32
int32 strideV);
33
static void SetupVideoTexture_YUV444(int32 width, int32 height, uint8 *yPlane, uint8 *uPlane, uint8 *vPlane, int32 strideY, int32 strideU,
34
int32 strideV);
35
36
static bool ProcessEvents();
37
38
static void InitFPSCap();
39
static bool CheckFPSCap();
40
static void UpdateFPSCap();
41
42
static bool InitShaders();
43
static void LoadShader(const char *fileName, bool32 linear);
44
45
inline static void ShowCursor(bool32 shown)
46
{
47
if (shown) {
48
while (_wapiShowCursor(true) < 0)
49
;
50
}
51
else {
52
while (_wapiShowCursor(false) >= 0)
53
;
54
}
55
}
56
57
inline static bool GetCursorPos(Vector2 *pos)
58
{
59
POINT cursorPos{};
60
_wapiGetCursorPos(&cursorPos);
61
ScreenToClient(windowHandle, &cursorPos);
62
pos->x = cursorPos.x;
63
pos->y = cursorPos.y;
64
return true;
65
}
66
67
inline static void SetWindowTitle()
68
{
69
#if _UNICODE
70
// shoddy workaround to get the title into wide chars in UNICODE mode
71
std::string str = gameVerInfo.gameTitle;
72
std::wstring temp = std::wstring(str.begin(), str.end());
73
LPCWSTR gameTitle = temp.c_str();
74
#else
75
std::string str = gameVerInfo.gameTitle;
76
LPCSTR gameTitle = str.c_str();
77
#endif
78
79
SetWindowText(windowHandle, gameTitle);
80
}
81
82
static HWND windowHandle;
83
static ID3D11Texture2D *imageTexture;
84
85
static ID3D11DeviceContext *dx11Context;
86
static ID3D11Device *dx11Device;
87
88
static UINT dxAdapter;
89
static int32 adapterCount;
90
91
// WinMain args
92
static HINSTANCE hInstance;
93
static HINSTANCE hPrevInstance;
94
static INT nShowCmd;
95
96
private:
97
static bool SetupRendering();
98
static void InitVertexBuffer();
99
static bool InitGraphicsAPI();
100
static bool LoadBackupShader();
101
102
static void GetDisplays();
103
104
inline static std::vector<IDXGIAdapter *> GetAdapterList()
105
{
106
std::vector<IDXGIAdapter *> adapterList;
107
108
IDXGIFactory *dxgiFactory = nullptr;
109
HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void **)&dxgiFactory);
110
if (FAILED(hr))
111
return adapterList;
112
113
IDXGIAdapter *pAdapter;
114
for (UINT i = 0; dxgiFactory->EnumAdapters(i, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++i) adapterList.push_back(pAdapter);
115
dxgiFactory->Release();
116
117
return adapterList;
118
}
119
120
static void ProcessEvent(MSG msg);
121
static LRESULT CALLBACK WindowEventCallback(HWND hRecipient, UINT message, WPARAM wParam, LPARAM lParam);
122
123
static bool useFrequency;
124
125
static LARGE_INTEGER performanceCount, frequency, initialFrequency, curFrequency;
126
127
static HDEVNOTIFY deviceNotif;
128
static PAINTSTRUCT Paint;
129
130
static ID3D11Buffer *dx11VertexBuffer;
131
static ID3D11Texture2D *screenTextures[SCREEN_COUNT];
132
static ID3D11ShaderResourceView *screenTextureViews[SCREEN_COUNT];
133
static ID3D11ShaderResourceView *imageTextureView;
134
static D3D11_VIEWPORT dx11ViewPort;
135
136
static IDXGISwapChain *swapChain;
137
static ID3D11RenderTargetView *renderView;
138
139
static ID3D11RasterizerState *rasterState;
140
static ID3D11SamplerState *samplerPoint;
141
static ID3D11SamplerState *samplerLinear;
142
143
static ID3D11Buffer *psConstBuffer;
144
145
static D3D_DRIVER_TYPE driverType;
146
static D3D_FEATURE_LEVEL featureLevel;
147
148
static RECT monitorDisplayRect;
149
static LUID deviceIdentifier;
150
};
151
152
struct ShaderEntry : public ShaderEntryBase {
153
ID3D11VertexShader *vertexShaderObject;
154
ID3D11PixelShader *pixelShaderObject;
155
156
ID3D11InputLayout *vertexDeclare;
157
};
158
159