Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-2-2013-Decompilation
Path: blob/main/RSDKv4/Renderer.hpp
817 views
1
#ifndef RENDERER_H
2
#define RENDERER_H
3
4
#define DRAWFACE_COUNT (0x1000)
5
#define DRAWVERTEX_COUNT (DRAWFACE_COUNT * 4)
6
#define DRAWINDEX_COUNT (DRAWFACE_COUNT * 6)
7
#define TEXTURE_COUNT (0x80)
8
#define MESH_COUNT (0x40)
9
#define RENDERSTATE_COUNT (0x100)
10
11
enum RenderBlendModes {
12
RENDER_BLEND_NONE,
13
RENDER_BLEND_ALPHA,
14
RENDER_BLEND_ALPHA2,
15
RENDER_BLEND_ALPHA3,
16
};
17
18
enum TextureFormats {
19
TEXFMT_NONE,
20
TEXFMT_RGBA4444,
21
TEXFMT_RGBA5551,
22
TEXFMT_RGBA8888,
23
TEXFMT_RETROBUFFER,
24
};
25
26
enum MeshRenderTypes {
27
MESH_COLORS,
28
MESH_NORMALS,
29
MESH_COLORS_NORMALS,
30
};
31
32
struct DrawVertex {
33
float vertX;
34
float vertY;
35
float vertZ;
36
float normalX;
37
float normalY;
38
float normalZ;
39
float texCoordX;
40
float texCoordY;
41
byte r;
42
byte g;
43
byte b;
44
byte a;
45
};
46
47
struct MatrixF {
48
float values[4][4];
49
};
50
51
struct TextureInfo {
52
char fileName[64];
53
int width;
54
int height;
55
float widthN;
56
float heightN;
57
int format;
58
uint id;
59
};
60
61
struct MeshVertex {
62
float vertX;
63
float vertY;
64
float vertZ;
65
float normalX;
66
float normalY;
67
float normalZ;
68
};
69
70
struct MeshInfo {
71
char fileName[64];
72
DrawVertex *vertices;
73
ushort *indices;
74
ushort vertexCount;
75
ushort indexCount;
76
MeshVertex *frames;
77
ushort frameCount;
78
byte textureID;
79
};
80
81
struct MeshAnimator {
82
float animationSpeed;
83
float animationTimer;
84
ushort frameID;
85
ushort loopIndex;
86
ushort frameCount;
87
byte loopAnimation;
88
byte animationFinished;
89
};
90
91
struct RenderState {
92
MatrixF *renderMatrix;
93
DrawVertex *vertPtr;
94
ushort *indexPtr;
95
ushort indexCount;
96
int id;
97
byte blendMode;
98
byte useTexture;
99
byte useColors;
100
byte depthTest;
101
byte useNormals;
102
byte useFilter;
103
};
104
105
extern float retroVertexList[40];
106
extern float screenBufferVertexList[40];
107
108
extern int vertexListSize;
109
extern DrawVertex drawVertexList[DRAWVERTEX_COUNT];
110
extern ushort drawIndexList[DRAWINDEX_COUNT];
111
112
extern byte vertexR;
113
extern byte vertexG;
114
extern byte vertexB;
115
116
extern TextureInfo textureList[TEXTURE_COUNT];
117
extern MeshInfo meshList[MESH_COUNT];
118
119
extern int renderStateCount;
120
extern RenderState renderStateList[RENDERSTATE_COUNT];
121
extern RenderState currentRenderState;
122
123
// Matricies
124
void SetIdentityMatrixF(MatrixF *matrix);
125
void MatrixMultiplyF(MatrixF *matrixA, MatrixF *matrixB);
126
void MatrixTranslateXYZF(MatrixF *Matrix, float x, float y, float z);
127
void MatrixScaleXYZF(MatrixF *matrix, float scaleX, float scaleY, float scaleZ);
128
void MatrixRotateXF(MatrixF *matrix, float rotationX);
129
void MatrixRotateYF(MatrixF *matrix, float rotationY);
130
void MatrixRotateZF(MatrixF *matrix, float rotationZ);
131
void MatrixRotateXYZF(MatrixF *matrix, float rotationX, float rotationY, float rotationZ);
132
void MatrixInvertF(MatrixF *dstMatrix, MatrixF *matrix);
133
134
// Render States
135
void ResetRenderStates();
136
void SetRenderBlendMode(byte mode);
137
void SetRenderVertexColor(byte r, byte g, byte b);
138
void SetPerspectiveMatrix(float w, float h, float near, float far);
139
void SetupDrawIndexList();
140
void SetRenderMatrix(MatrixF *matrix);
141
void NewRenderState();
142
void RenderScene();
143
144
// Textures
145
int LoadTexture(const char *filePath, int format);
146
void ReplaceTexture(const char *filePath, int textureID);
147
void ClearTextures(bool keepBuffer);
148
149
// Meshes
150
MeshInfo *LoadMesh(const char *filePath, byte textureID);
151
void SetMeshVertexColors(MeshInfo *mesh, byte r, byte g, byte b, byte a);
152
void ClearMeshData();
153
void SetMeshAnimation(MeshInfo *mesh, MeshAnimator *animator, ushort frameID, ushort frameCount, float speed);
154
void AnimateMesh(MeshInfo *mesh, MeshAnimator *animator);
155
156
// Rendering
157
void TransferRetroBuffer();
158
void RenderRetroBuffer(int alpha, float z);
159
void RenderImage(float x, float y, float z, float scaleX, float scaleY, float pivotX, float pivotY, float sprW, float sprH, float sprX, float sprY,
160
int alpha, byte texture);
161
void RenderImageClipped(float x, float y, float z, float scaleX, float scaleY, float pivotX, float pivotY, float sprW, float sprH, float sprX,
162
float sprY, int alpha, byte texture);
163
void RenderImageFlipH(float x, float y, float z, float scaleX, float scaleY, float pivotX, float pivotY, float sprW, float sprH, float sprX,
164
float sprY, int alpha, byte texture);
165
void RenderText(ushort *text, int fontID, float x, float y, int z, float scale, int alpha);
166
void RenderTextClipped(ushort *text, int fontID, float x, float y, int z, float scale, int alpha);
167
void RenderRect(float x, float y, float z, float w, float h, byte r, byte g, byte b, int alpha);
168
#if !RETRO_USE_ORIGINAL_CODE
169
void RenderRectClipped(float x, float y, float z, float w, float h, byte r, byte g, byte b, int alpha);
170
#endif
171
void RenderMesh(MeshInfo *mesh, byte type, byte depthTest);
172
173
#endif // !RENDERER_H
174