Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Graphics/Drawing.hpp
1163 views
1
#ifndef DRAWING_H
2
#define DRAWING_H
3
4
namespace RSDK
5
{
6
7
#define SURFACE_COUNT (0x40)
8
9
#ifndef SCREEN_COUNT
10
#if RETRO_REV02
11
#define SCREEN_COUNT (4)
12
#else
13
#define SCREEN_COUNT (2)
14
#endif
15
#endif
16
#define CAMERA_COUNT (4)
17
18
#define DEFAULT_PIXWIDTH (424)
19
20
#define LAYER_COUNT (8)
21
#define DRAWGROUP_COUNT (16)
22
23
#define SHADER_COUNT (0x20)
24
25
// Also for "Images" but it's a cleaner name as is
26
#define RETRO_VIDEO_TEXTURE_W (1024)
27
#define RETRO_VIDEO_TEXTURE_H (512)
28
29
enum InkEffects {
30
INK_NONE,
31
INK_BLEND,
32
INK_ALPHA,
33
INK_ADD,
34
INK_SUB,
35
INK_TINT,
36
INK_MASKED,
37
INK_UNMASKED,
38
};
39
40
enum DrawFX { FX_NONE = 0, FX_FLIP = 1, FX_ROTATE = 2, FX_SCALE = 4 };
41
42
enum FlipFlags { FLIP_NONE, FLIP_X, FLIP_Y, FLIP_XY };
43
44
enum Alignments {
45
ALIGN_LEFT,
46
ALIGN_RIGHT,
47
ALIGN_CENTER,
48
};
49
50
enum WindowStates {
51
WINDOWSTATE_UNINITIALIZED,
52
WINDOWSTATE_ACTIVE,
53
WINDOWSTATE_INACTIVE,
54
};
55
56
enum ShaderIDs {
57
SHADER_NONE,
58
SHADER_CLEAN,
59
SHADER_CRT_YEETRON,
60
SHADER_CRT_YEE64,
61
SHADER_YUV_420,
62
SHADER_YUV_422,
63
SHADER_YUV_444,
64
SHADER_RGB_IMAGE,
65
};
66
67
struct GFXSurface {
68
RETRO_HASH_MD5(hash);
69
uint8 *pixels;
70
int32 height;
71
int32 width;
72
int32 lineSize;
73
uint8 scope;
74
};
75
76
struct ScreenInfo {
77
// uint16 *frameBuffer;
78
uint16 frameBuffer[SCREEN_XMAX * SCREEN_YSIZE];
79
Vector2 position;
80
Vector2 size;
81
Vector2 center;
82
int32 pitch;
83
int32 clipBound_X1;
84
int32 clipBound_Y1;
85
int32 clipBound_X2;
86
int32 clipBound_Y2;
87
int32 waterDrawPos;
88
};
89
90
struct CameraInfo {
91
Vector2 *targetPos;
92
Vector2 position;
93
Vector2 offset;
94
bool32 worldRelative;
95
};
96
97
struct DrawList {
98
uint16 entries[ENTITY_COUNT];
99
uint16 layerDrawList[LAYER_COUNT];
100
void (*hookCB)();
101
bool32 sorted;
102
int32 entityCount;
103
int32 layerCount;
104
};
105
106
struct VideoSettings {
107
uint8 windowed;
108
uint8 bordered;
109
uint8 exclusiveFS;
110
uint8 vsync;
111
uint8 tripleBuffered;
112
uint8 shaderSupport;
113
int32 fsWidth;
114
int32 fsHeight;
115
int32 refreshRate;
116
int32 windowWidth;
117
int32 windowHeight;
118
int32 pixWidth;
119
int32 pixHeight;
120
int32 windowState;
121
int32 shaderID;
122
int32 screenCount;
123
uint32 dimTimer;
124
uint32 dimLimit;
125
float dimMax;
126
float dimPercent;
127
float viewportW;
128
float viewportH;
129
float viewportX;
130
float viewportY;
131
};
132
133
enum VideoSettingsValues {
134
VIDEOSETTING_WINDOWED,
135
VIDEOSETTING_BORDERED,
136
VIDEOSETTING_EXCLUSIVEFS,
137
VIDEOSETTING_VSYNC,
138
VIDEOSETTING_TRIPLEBUFFERED,
139
VIDEOSETTING_WINDOW_WIDTH,
140
VIDEOSETTING_WINDOW_HEIGHT,
141
VIDEOSETTING_FSWIDTH,
142
VIDEOSETTING_FSHEIGHT,
143
VIDEOSETTING_REFRESHRATE,
144
VIDEOSETTING_SHADERSUPPORT,
145
VIDEOSETTING_SHADERID,
146
VIDEOSETTING_SCREENCOUNT,
147
#if RETRO_REV02
148
VIDEOSETTING_DIMTIMER,
149
#endif
150
VIDEOSETTING_STREAMSENABLED,
151
VIDEOSETTING_STREAM_VOL,
152
VIDEOSETTING_SFX_VOL,
153
VIDEOSETTING_LANGUAGE,
154
VIDEOSETTING_STORE,
155
VIDEOSETTING_RELOAD,
156
VIDEOSETTING_CHANGED,
157
VIDEOSETTING_WRITE,
158
};
159
160
struct float4 {
161
float x;
162
float y;
163
float z;
164
float w;
165
};
166
167
struct float3 {
168
float x;
169
float y;
170
float z;
171
};
172
173
struct float2 {
174
float x;
175
float y;
176
};
177
178
struct RenderVertex {
179
float3 pos;
180
uint32 color;
181
float2 tex;
182
};
183
184
struct ShaderEntryBase {
185
uint8 linear;
186
char name[0x20];
187
};
188
189
class RenderDeviceBase
190
{
191
public:
192
static bool Init();
193
static void CopyFrameBuffer();
194
static void ProcessDimming();
195
static void FlipScreen();
196
static void Release(bool32 isRefresh);
197
198
static void RefreshWindow();
199
200
static void SetupImageTexture(int32 width, int32 height, uint8 *imagePixels);
201
static void SetupVideoTexture_YUV420(int32 width, int32 height, uint8 *imagePixels);
202
static void SetupVideoTexture_YUV422(int32 width, int32 height, uint8 *imagePixels);
203
static void SetupVideoTexture_YUV424(int32 width, int32 height, uint8 *imagePixels);
204
205
static bool ProcessEvents();
206
207
static void InitFPSCap();
208
static bool CheckFPSCap();
209
static void UpdateFPSCap();
210
211
// Public since it's needed for the ModAPI
212
static bool InitShaders();
213
static void LoadShader(const char *fileName, bool32 linear);
214
215
// ====================
216
// RSDK COMMON START
217
// ====================
218
219
static bool32 isRunning;
220
static int32 windowRefreshDelay;
221
222
static int32 displayWidth[16];
223
static int32 displayHeight[16];
224
static int32 displayCount;
225
226
static int32 lastShaderID;
227
228
#if RETRO_REV02
229
static uint8 startVertex_2P[];
230
static uint8 startVertex_3P[];
231
#endif
232
233
static float2 pixelSize;
234
static float2 textureSize;
235
static float2 viewSize;
236
237
private:
238
static bool SetupRendering();
239
static void InitVertexBuffer();
240
static bool InitGraphicsAPI();
241
242
static void GetDisplays();
243
};
244
245
#if RETRO_RENDERDEVICE_DIRECTX9
246
#include "DX9/DX9RenderDevice.hpp"
247
#elif RETRO_RENDERDEVICE_DIRECTX11
248
#include "DX11/DX11RenderDevice.hpp"
249
#elif RETRO_RENDERDEVICE_SDL2
250
#include "SDL2/SDL2RenderDevice.hpp"
251
#elif RETRO_RENDERDEVICE_GLFW
252
#include "GLFW/GLFWRenderDevice.hpp"
253
#elif RETRO_RENDERDEVICE_VK
254
#include "Vulkan/VulkanRenderDevice.hpp"
255
#elif RETRO_RENDERDEVICE_EGL
256
#include "EGL/EGLRenderDevice.hpp"
257
#endif
258
259
extern DrawList drawGroups[DRAWGROUP_COUNT];
260
extern char drawGroupNames[0x10][0x10];
261
262
extern uint16 blendLookupTable[0x20 * 0x100];
263
extern uint16 subtractLookupTable[0x20 * 0x100];
264
265
extern GFXSurface gfxSurface[SURFACE_COUNT];
266
267
extern float dpi;
268
extern int32 cameraCount;
269
extern ScreenInfo screens[SCREEN_COUNT];
270
extern CameraInfo cameras[CAMERA_COUNT];
271
extern ScreenInfo *currentScreen;
272
273
extern int32 shaderCount;
274
extern ShaderEntry shaderList[SHADER_COUNT];
275
276
extern VideoSettings videoSettings;
277
extern VideoSettings videoSettingsBackup;
278
extern bool32 changedVideoSettings;
279
280
#if RETRO_USE_MOD_LOADER
281
extern int32 userShaderCount;
282
#else
283
#define userShaderCount (4)
284
#endif
285
286
void UpdateGameWindow();
287
288
void GenerateBlendLookupTable();
289
290
void InitSystemSurfaces();
291
292
void GetDisplayInfo(int32 *displayID, int32 *width, int32 *height, int32 *refreshRate, char *text);
293
void GetWindowSize(int32 *width, int32 *height);
294
295
#if RETRO_REV02
296
inline void SetScreenVertices(uint8 startVert2P_S1, uint8 startVert2P_S2, uint8 startVert3P_S1, uint8 startVert3P_S2, uint8 startVert3P_S3)
297
{
298
RenderDevice::startVertex_2P[0] = startVert2P_S1;
299
RenderDevice::startVertex_2P[1] = startVert2P_S2;
300
301
RenderDevice::startVertex_3P[0] = startVert3P_S1;
302
RenderDevice::startVertex_3P[1] = startVert3P_S2;
303
RenderDevice::startVertex_3P[2] = startVert3P_S3;
304
}
305
#endif
306
307
void SetScreenSize(uint8 screenID, uint16 width, uint16 height);
308
309
inline void AddCamera(Vector2 *targetPos, int32 offsetX, int32 offsetY, bool32 worldRelative)
310
{
311
if (cameraCount < CAMERA_COUNT) {
312
cameras[cameraCount].targetPos = targetPos;
313
cameras[cameraCount].offset.x = offsetX;
314
cameras[cameraCount].offset.y = offsetY;
315
cameras[cameraCount].worldRelative = worldRelative;
316
317
++cameraCount;
318
}
319
}
320
321
inline void ClearCameras() { cameraCount = 0; }
322
323
inline void SetClipBounds(uint8 screenID, int32 x1, int32 y1, int32 x2, int32 y2)
324
{
325
ScreenInfo *screen;
326
327
if (screenID < SCREEN_COUNT) {
328
screen = &screens[screenID];
329
330
screen->clipBound_X1 = CLAMP(x1, 0, screen->size.x);
331
screen->clipBound_Y1 = CLAMP(y1, 0, screen->size.y);
332
screen->clipBound_X2 = CLAMP(x2, 0, screen->size.x);
333
screen->clipBound_Y2 = CLAMP(y2, 0, screen->size.y);
334
}
335
}
336
337
int32 GetVideoSetting(int32 id);
338
void SetVideoSetting(int32 id, int32 value);
339
340
inline void AddDrawListRef(uint8 drawGroup, uint16 entityID)
341
{
342
if (drawGroup < DRAWGROUP_COUNT)
343
drawGroups[drawGroup].entries[drawGroups[drawGroup].entityCount++] = entityID;
344
}
345
346
inline uint16 GetDrawListRefSlot(uint8 drawGroup, uint16 listPos)
347
{
348
DrawList *list = &drawGroups[drawGroup];
349
if (drawGroup < DRAWGROUP_COUNT && listPos < list->entityCount)
350
return list->entries[listPos];
351
352
return 0;
353
}
354
355
inline Entity *GetDrawListRef(uint8 drawGroup, uint16 listPos)
356
{
357
DrawList *listPtr = &drawGroups[drawGroup];
358
if (drawGroup < DRAWGROUP_COUNT && listPos < listPtr->entityCount)
359
return &objectEntityList[listPtr->entries[listPos]];
360
361
return NULL;
362
}
363
364
inline void SetDrawGroupProperties(uint8 drawGroup, bool32 sorted, void (*hookCB)())
365
{
366
if (drawGroup < DRAWGROUP_COUNT) {
367
DrawList *list = &drawGroups[drawGroup];
368
list->sorted = sorted;
369
list->hookCB = hookCB;
370
}
371
}
372
373
void SwapDrawListEntries(uint8 drawGroup, uint16 slot1, uint16 slot2, uint16 count);
374
375
void FillScreen(uint32 color, int32 alphaR, int32 alphaG, int32 alphaB);
376
377
void DrawLine(int32 x1, int32 y1, int32 x2, int32 y2, uint32 color, int32 alpha, int32 inkEffect, bool32 screenRelative);
378
void DrawRectangle(int32 x, int32 y, int32 width, int32 height, uint32 color, int32 alpha, int32 inkEffect, bool32 screenRelative);
379
void DrawCircle(int32 x, int32 y, int32 radius, uint32 color, int32 alpha, int32 inkEffect, bool32 screenRelative);
380
void DrawCircleOutline(int32 x, int32 y, int32 innerRadius, int32 outerRadius, uint32 color, int32 alpha, int32 inkEffect, bool32 screenRelative);
381
382
void DrawFace(Vector2 *vertices, int32 vertCount, int32 r, int32 g, int32 b, int32 alpha, int32 inkEffect);
383
void DrawBlendedFace(Vector2 *vertices, uint32 *colors, int32 vertCount, int32 alpha, int32 inkEffect);
384
385
void DrawSprite(Animator *animator, Vector2 *position, bool32 screenRelative);
386
void DrawSpriteFlipped(int32 x, int32 y, int32 width, int32 height, int32 sprX, int32 sprY, int32 direction, int32 inkEffect, int32 alpha,
387
int32 sheetID);
388
void DrawSpriteRotozoom(int32 x, int32 y, int32 pivotX, int32 pivotY, int32 width, int32 height, int32 sprX, int32 sprY, int32 scaleX, int32 scaleY,
389
int32 direction, int16 Rotation, int32 inkEffect, int32 alpha, int32 sheetID);
390
391
void DrawDeformedSprite(uint16 sheetID, int32 inkEffect, int32 alpha);
392
393
void DrawTile(uint16 *tileInfo, int32 countX, int32 countY, Vector2 *position, Vector2 *offset, bool32 screenRelative);
394
void DrawAniTile(uint16 sheetID, uint16 tileIndex, uint16 srcX, uint16 srcY, uint16 width, uint16 height);
395
396
#if RETRO_REV0U || RETRO_USE_MOD_LOADER
397
inline void DrawDynamicAniTile(Animator *animator, uint16 tileIndex)
398
{
399
if (animator->frames) {
400
SpriteFrame *frame = &animator->frames[animator->frameID];
401
DrawAniTile(frame->sheetID, tileIndex, frame->sprX, frame->sprY, frame->width, frame->height);
402
}
403
}
404
#endif
405
406
void DrawString(Animator *animator, Vector2 *position, String *string, int32 endFrame, int32 textLength, int32 align, int32 spacing, void *unused,
407
Vector2 *charPositions, bool32 screenRelative);
408
void DrawDevString(const char *string, int32 x, int32 y, int32 align, uint32 color);
409
410
inline void ClearGfxSurfaces()
411
{
412
// Unload sprite sheets
413
for (int32 s = 0; s < SURFACE_COUNT; ++s) {
414
if (gfxSurface[s].scope != SCOPE_GLOBAL) {
415
MEM_ZERO(gfxSurface[s]);
416
gfxSurface[s].scope = SCOPE_NONE;
417
}
418
}
419
}
420
421
#if RETRO_REV0U
422
#include "Legacy/DrawingLegacy.hpp"
423
#endif
424
425
} // namespace RSDK
426
427
#endif // !DRAWING_H
428
429