Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Graphics/DX9/DX9RenderDevice.hpp
1164 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
UINT refresh_rate;
13
};
14
D3DDISPLAYMODE internal;
15
} * displays;
16
D3DVIEWPORT9 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
static inline void SetWindowTitle()
68
{
69
#if _UNICODE
70
// shoddy workaround to get the title into wide chars in UNICODE mode
71
std::string str = RSDK::gameVerInfo.gameTitle;
72
std::wstring temp = std::wstring(str.begin(), str.end());
73
LPCWSTR gameTitle = temp.c_str();
74
#else
75
std::string str = RSDK::gameVerInfo.gameTitle;
76
LPCSTR gameTitle = str.c_str();
77
#endif
78
79
SetWindowText(windowHandle, gameTitle);
80
}
81
82
static HWND windowHandle;
83
static IDirect3DTexture9 *imageTexture;
84
85
static IDirect3D9 *dx9Context;
86
static IDirect3DDevice9 *dx9Device;
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
101
static void GetDisplays();
102
103
static void ProcessEvent(MSG msg);
104
static LRESULT CALLBACK WindowEventCallback(HWND hRecipient, UINT message, WPARAM wParam, LPARAM lParam);
105
106
static bool useFrequency;
107
108
static LARGE_INTEGER performanceCount, frequency, initialFrequency, curFrequency;
109
110
static HDEVNOTIFY deviceNotif;
111
static PAINTSTRUCT Paint;
112
113
static IDirect3DVertexDeclaration9 *dx9VertexDeclare;
114
static IDirect3DVertexBuffer9 *dx9VertexBuffer;
115
static IDirect3DTexture9 *screenTextures[SCREEN_COUNT];
116
static D3DVIEWPORT9 dx9ViewPort;
117
118
static RECT monitorDisplayRect;
119
static GUID deviceIdentifier;
120
};
121
122
struct ShaderEntry : public ShaderEntryBase {
123
IDirect3DVertexShader9 *vertexShaderObject;
124
IDirect3DPixelShader9 *pixelShaderObject;
125
};
126
127