-
Notifications
You must be signed in to change notification settings - Fork 1
/
OmniScalerGraphics.cpp
306 lines (263 loc) · 7.78 KB
/
OmniScalerGraphics.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
////////////////////////////////////////////////////////////////////////////////
// Filename: OmniScalerGraphics.cpp
////////////////////////////////////////////////////////////////////////////////
#include "OmniScalerGraphics.h"
OmniScalerGraphics::OmniScalerGraphics()
{
m_Direct3D = 0;
}
OmniScalerGraphics::OmniScalerGraphics(const OmniScalerGraphics& other)
{
}
OmniScalerGraphics::~OmniScalerGraphics()
{
}
bool OmniScalerGraphics::Initialize(
HWND& d3dHwnd, // omniscaler D3D HWND
HWND& gHwnd, // game HWND
HANDLE& appHandle, // Shared surface handle
int& gRealScreenWidth, // screen width
int& gRealScreenHeight, // screen height
int& gRealRefreshRate, // screen refresh rate
int& gScreenWidth, // game window width
int& gScreenHeight, // game window height
float& topOffset, // top offset
float& bottomOffset, // bottom offset
float& leftOffset, // left offset
float& rightOffset, // right offset
bool linearInterpolation, // linear interpolation filtering
bool MousePointerLinear, // mouse pointer linear interpolation
bool integerScaling, // integer scaling
float integerScalingOverride, // integer scaling scale
bool IntegerScalingOverscan, // integer scaling overscan
int* mouseCursorBmpData, // mouse cursor bitmap data
float mousePosRemap_xscale, // mouse position remap scale X
float mousePosRemap_yscale, // mouse position remap scale Y
int mousePointer_size, // mouse pointer size
RECT& mouse_area, // mouse area RECT
bool MousePointerEnable // Enable custom mouse pointer
)
{
bool result;
// Create the Direct3D object.
m_Direct3D = new OmniScalerD3D;
if (!m_Direct3D)
{
return false;
}
// Initialize the Direct3D object.
result = m_Direct3D->Initialize(VSYNC_ENABLED, d3dHwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR, gHwnd, appHandle, gRealScreenWidth, gRealScreenHeight, gRealRefreshRate, gScreenWidth, gScreenHeight);
if (!result)
{
MessageBox(d3dHwnd, L"Could not initialize Direct3D.", L"Error", MB_OK);
return false;
}
// Create the camera object.
m_Camera = new CameraClass;
if (!m_Camera)
{
return false;
}
// Set the initial position of the camera.
m_Camera->SetPosition(0.0f, 0.0f, -5.0f);
// Create the model object.
m_Model = new ModelClass;
if (!m_Model)
{
return false;
}
// Initialize the model object.
result = m_Model->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), gHwnd, appHandle, gRealScreenWidth, gRealScreenHeight, gScreenWidth, gScreenHeight, topOffset, bottomOffset, leftOffset, rightOffset, integerScaling, integerScalingOverride, IntegerScalingOverscan, mouseCursorBmpData, mousePosRemap_xscale, mousePosRemap_yscale, mousePointer_size, mouse_area);
if (!result)
{
MessageBox(gHwnd, L"Could not initialize the model object.", L"Error", MB_OK);
return false;
}
// Create the texture shader object.
m_TextureShader = new TextureShaderClass;
if (!m_TextureShader)
{
return false;
}
// Initialize the color shader object.
result = m_TextureShader->Initialize(m_Direct3D->GetDevice(), gHwnd, linearInterpolation);
if (!result)
{
MessageBox(gHwnd, L"Could not initialize the color shader object.", L"Error", MB_OK);
return false;
}
if (MousePointerEnable)
{
// Create the cursor object.
m_CursorModel = new CursorModelClass;
if (!m_CursorModel)
{
return false;
}
// Initialize the cursor object.
result = m_CursorModel->Initialize(
m_Direct3D->GetDevice(),
m_Direct3D->GetDeviceContext(),
gHwnd,
appHandle,
gRealScreenWidth,
gRealScreenHeight,
gScreenWidth,
gScreenHeight,
topOffset,
bottomOffset,
leftOffset,
rightOffset,
integerScaling,
IntegerScalingOverscan,
mouseCursorBmpData,
mousePosRemap_xscale,
mousePosRemap_yscale,
mousePointer_size,
mouse_area);
if (!result)
{
MessageBox(gHwnd, L"Could not initialize the cursor object.", L"Error", MB_OK);
return false;
}
// Create the cursor shader object.
m_CursorShader = new CursorShaderClass;
if (!m_CursorShader)
{
return false;
}
// Initialize the cursor shader object.
result = m_CursorShader->Initialize(m_Direct3D->GetDevice(), gHwnd, MousePointerLinear);
if (!result)
{
MessageBox(gHwnd, L"Could not initialize the cursor shader object.", L"Error", MB_OK);
return false;
}
}
return true;
}
void OmniScalerGraphics::Shutdown()
{
// Release the Direct3D object.
if (m_Direct3D)
{
m_Direct3D->Shutdown();
delete m_Direct3D;
m_Direct3D = 0;
}
return;
}
bool OmniScalerGraphics::UpdateScreen(
bool integerScaling,
bool linearInterpolation,
float x,
float y,
float mousePosRemap_xscale,
float mousePosRemap_yscale,
RECT gsr,
HWND& hwnd, // game HWND
int gRealScreenWidth, // screen width
int gRealScreenHeight, // screen height
int gScreenWidth, // game window width
int gScreenHeight, // game window height
int mcursor_w, // Mouse Pointer size
bool MousePointerEnable // Enable custom mouse pointer
)
{
bool result;
// Render the graphics scene.
result = Render(
integerScaling,
linearInterpolation,
x,
y,
mousePosRemap_xscale,
mousePosRemap_yscale,
gsr,
hwnd,
gRealScreenWidth,
gRealScreenHeight,
gScreenWidth,
gScreenHeight,
mcursor_w,
MousePointerEnable
);
if (!result)
{
return false;
}
return true;
}
bool OmniScalerGraphics::Render(
bool integerScaling,
bool linearInterpolation,
float mouseX,
float mouseY,
float mousePosRemap_xscale,
float mousePosRemap_yscale,
RECT gsr,
HWND& hwnd, // game HWND
int gRealScreenWidth, // screen width
int gRealScreenHeight, // screen height
int gScreenWidth, // game window width
int gScreenHeight, // game window height
int mcursor_w, // Mouse Pointer size
bool MousePointerEnable // Enable custom mouse pointer
)
{
XMMATRIX worldMatrix, viewMatrix, projectionMatrix, orthoMatrix;
bool result;
// Clear the buffers to begin the scene.
m_Direct3D->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);
// Generate the view matrix based on the camera's position.
m_Camera->Render();
// Get the world, view, and projection matrices from the camera and d3d objects.
m_Direct3D->GetWorldMatrix(worldMatrix);
m_Camera->GetViewMatrix(viewMatrix);
m_Direct3D->GetProjectionMatrix(projectionMatrix);
m_Direct3D->GetOrthoMatrix(orthoMatrix);
// Turn off the Z buffer to begin all 2D rendering.
m_Direct3D->TurnZBufferOff();
// Put the game model vertex and index buffers on the graphics pipeline to prepare them for drawing.
m_Model->Render(m_Direct3D->GetDeviceContext());
// Render the model using the texture shader.
result = m_TextureShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, orthoMatrix, m_Model->GetTexture(), linearInterpolation);
if (!result)
{
return false;
}
if (MousePointerEnable)
{
// enable alpha blending for mouse cursor transparency
m_Direct3D->TurnOnAlphaBlending();
// Put the mouse cursor model vertex and index buffers on the graphics pipeline to prepare them for drawing.
m_CursorModel->Render(hwnd, m_Direct3D->GetDeviceContext(), gRealScreenWidth, gRealScreenHeight, gScreenWidth, gScreenHeight, mouseX, mouseY, mcursor_w);
// Render the model using the mouse cursor texture shader.
result = m_CursorShader->Render(
m_Direct3D->GetDeviceContext(),
m_CursorModel->GetIndexCount(),
worldMatrix,
viewMatrix,
orthoMatrix,
m_CursorModel->GetTexture(),
linearInterpolation,
gRealScreenWidth,
gRealScreenHeight,
gScreenWidth,
gScreenHeight,
mouseX,
mouseY,
mcursor_w
);
if (!result)
{
return false;
}
m_Direct3D->TurnOffAlphaBlending();
}
// Turn the Z buffer back on now that all 2D rendering has completed.
m_Direct3D->TurnZBufferOn();
// Present the rendered scene to the screen.
m_Direct3D->EndScene();
return true;
}