1 // SONIC ROBO BLAST 2
2 //-----------------------------------------------------------------------------
3 // Copyright (C) 1998-2000 by DooM Legacy Team.
4 // Copyright (C) 1999-2021 by Sonic Team Junior.
5 //
6 // This program is free software distributed under the
7 // terms of the GNU General Public License, version 2.
8 // See the 'LICENSE' file for more details.
9 //-----------------------------------------------------------------------------
10 /// \file hw_defs.h
11 /// \brief 3D hardware renderer definitions
12 
13 #ifndef _HWR_DEFS_
14 #define _HWR_DEFS_
15 #include "../doomtype.h"
16 #include "../r_defs.h"
17 
18 #define ZCLIP_PLANE 4.0f // Used for the actual game drawing
19 #define NZCLIP_PLANE 0.9f // Seems to be only used for the HUD and screen textures
20 
21 // ==========================================================================
22 //                                                               SIMPLE TYPES
23 // ==========================================================================
24 
25 typedef long            FINT;
26 typedef unsigned long   FUINT;
27 typedef unsigned char   FUBYTE;
28 typedef unsigned long   FBITFIELD;
29 #ifndef __MINGW32__
30 typedef float           FLOAT;
31 #endif
32 typedef unsigned char   FBOOLEAN;
33 
34 // ==========================================================================
35 //                                                                     COLORS
36 // ==========================================================================
37 
38 // byte value for paletted graphics, which represent the transparent color
39 #define HWR_PATCHES_CHROMAKEY_COLORINDEX   255
40 //#define HWR_CHROMAKEY_EQUIVALENTCOLORINDEX 130
41 
42 // the chroma key color shows on border sprites, set it to black
43 #define HWR_PATCHES_CHROMAKEY_COLORVALUE     (0x00000000)    //RGBA format as in grSstWinOpen()
44 
45 // RGBA Color components with float type ranging [ 0 ... 1 ]
46 struct FRGBAFloat
47 {
48 	FLOAT   red;
49 	FLOAT   green;
50 	FLOAT   blue;
51 	FLOAT   alpha;
52 };
53 typedef struct FRGBAFloat FRGBAFloat;
54 
55 struct FColorARGB
56 {
57 	FUBYTE  alpha;
58 	FUBYTE  red;
59 	FUBYTE  green;
60 	FUBYTE  blue;
61 };
62 typedef struct FColorARGB ARGB_t;
63 typedef struct FColorARGB FColorARGB;
64 
65 
66 
67 // ==========================================================================
68 //                                                                    VECTORS
69 // ==========================================================================
70 
71 // Simple 2D coordinate
72 typedef struct
73 {
74 	FLOAT x,y;
75 } F2DCoord, v2d_t;
76 
77 // Simple 3D vector
78 typedef struct FVector
79 {
80 	FLOAT x,y,z;
81 } FVector;
82 
83 // ======================
84 //      wallVert3D
85 // ----------------------
86 // :crab: IS GONE! :crab:
87 // ======================
88 
89 // -----------
90 // structures
91 // -----------
92 
93 //Hurdler: Transform (coords + angles)
94 //BP: transform order : scale(rotation_x(rotation_y(translation(v))))
95 
96 // Kart features
97 //#define USE_FTRANSFORM_ANGLEZ
98 //#define USE_FTRANSFORM_MIRROR
99 
100 // Vanilla features
101 #define USE_MODEL_NEXTFRAME
102 
103 typedef struct
104 {
105 	FLOAT       x,y,z;           // position
106 #ifdef USE_FTRANSFORM_ANGLEZ
107 	FLOAT       anglex,angley,anglez;   // aimingangle / viewangle
108 #else
109 	FLOAT       anglex,angley;   // aimingangle / viewangle
110 #endif
111 	FLOAT       scalex,scaley,scalez;
112 	FLOAT       fovxangle, fovyangle;
113 	UINT8       splitscreen;
114 	boolean     flip;            // screenflip
115 	boolean     roll;
116 	SINT8       rollflip;
117 	FLOAT       rollangle; // done to not override USE_FTRANSFORM_ANGLEZ
118 	UINT8       rotaxis;
119 	FLOAT       centerx, centery;
120 #ifdef USE_FTRANSFORM_MIRROR
121 	boolean     mirror;          // SRB2Kart: Encore Mode
122 #endif
123 	boolean     shearing;        // 14042019
124 	float       viewaiming;      // 17052019
125 } FTransform;
126 
127 // Transformed vector, as passed to HWR API
128 typedef struct
129 {
130 	FLOAT       x,y,z;
131 	FLOAT       s;            // s texture ordinate (s over w)
132 	FLOAT       t;            // t texture ordinate (t over w)
133 } FOutVector;
134 
135 #ifdef GL_SHADERS
136 // Predefined shader types
137 enum
138 {
139 	SHADER_DEFAULT = 0,
140 
141 	SHADER_FLOOR,
142 	SHADER_WALL,
143 	SHADER_SPRITE,
144 	SHADER_MODEL, SHADER_MODEL_LIGHTING,
145 	SHADER_WATER,
146 	SHADER_FOG,
147 	SHADER_SKY,
148 
149 	NUMBASESHADERS,
150 };
151 
152 // Maximum amount of shader programs
153 // Must be higher than NUMBASESHADERS
154 #define HWR_MAXSHADERS 16
155 
156 // Shader sources (vertex and fragment)
157 typedef struct
158 {
159 	char *vertex;
160 	char *fragment;
161 } shadersource_t;
162 
163 // Custom shader reference table
164 typedef struct
165 {
166 	const char *type;
167 	INT32 id;
168 } customshaderxlat_t;
169 
170 #endif
171 
172 typedef struct vbo_vertex_s
173 {
174 	float x, y, z;
175 	float u, v;
176 	unsigned char r, g, b, a;
177 } gl_skyvertex_t;
178 
179 typedef enum gl_skyloopmode_e
180 {
181 	HWD_SKYLOOP_FAN,
182 	HWD_SKYLOOP_STRIP
183 } gl_skyloopmode_t;
184 
185 typedef struct
186 {
187 	gl_skyloopmode_t mode;
188 	int vertexcount;
189 	int vertexindex;
190 	boolean use_texture;
191 } gl_skyloopdef_t;
192 
193 typedef struct
194 {
195 	unsigned int vbo;
196 	int rows, columns;
197 	int loopcount;
198 
199 	int detail, vertex_count;
200 	int texture, width, height;
201 	boolean rebuild; // VBO needs to be rebuilt
202 
203 	gl_skyloopdef_t *loops;
204 	gl_skyvertex_t *data;
205 } gl_sky_t;
206 
207 // ==========================================================================
208 //                                                               RENDER MODES
209 // ==========================================================================
210 
211 // Flags describing how to render a polygon
212 // You pass a combination of these flags to DrawPolygon()
213 enum EPolyFlags
214 {
215 	// Mutually exclusive blend flags
216 	PF_Masked           = 0x00000001,   // Poly is alpha scaled and 0 alpha pixels are discarded (holes in texture)
217 	PF_Translucent      = 0x00000002,   // Poly is transparent, alpha = level of transparency
218 	PF_Environment      = 0x00000004,   // Poly should be drawn environment mapped. (Hurdler: used for text drawing)
219 	PF_Additive         = 0x00000008,   // Source blending factor is additive.
220 	PF_Subtractive      = 0x00000010,   // Subtractive color blending
221 	PF_ReverseSubtract  = 0x00000020,   // Reverse subtract, used in wall splats (decals)
222 	PF_Multiplicative   = 0x00000040,   // Multiplicative color blending
223 	PF_Fog              = 0x20000000,   // Fog blocks
224 	PF_NoAlphaTest      = 0x40000000,   // Disables alpha testing
225 	PF_Blending         = (PF_Masked|PF_Translucent|PF_Environment|PF_Additive|PF_Subtractive|PF_ReverseSubtract|PF_Multiplicative|PF_Fog) & ~PF_NoAlphaTest,
226 
227 	// other flag bits
228 	PF_Occlude          = 0x00000100,   // Updates the depth buffer
229 	PF_NoDepthTest      = 0x00000200,   // Disables the depth test mode
230 	PF_Invisible        = 0x00000400,   // Disables write to color buffer
231 	PF_Decal            = 0x00000800,   // Enables polygon offset
232 	PF_Modulated        = 0x00001000,   // Modulation (multiply output with constant RGBA)
233 	                                    // When set, pass the color constant into the FSurfaceInfo -> PolyColor
234 	PF_NoTexture        = 0x00002000,   // Disables texturing
235 	PF_Corona           = 0x00004000,   // Tells the renderer we are drawing a corona
236 	PF_ColorMapped      = 0x00008000,   // Surface has "tint" and "fade" colors, which are sent as uniforms to a shader.
237 	PF_RemoveYWrap      = 0x00010000,   // Forces clamp texture on Y
238 	PF_ForceWrapX       = 0x00020000,   // Forces repeat texture on X
239 	PF_ForceWrapY       = 0x00040000,   // Forces repeat texture on Y
240 	PF_Ripple           = 0x00100000    // Water ripple effect. The current backend doesn't use it for anything.
241 };
242 
243 
244 enum ESurfFlags
245 {
246 	SF_DYNLIGHT         = 0x00000001,
247 };
248 
249 enum ETextureFlags
250 {
251 	TF_WRAPX       = 0x00000001,        // wrap around X
252 	TF_WRAPY       = 0x00000002,        // wrap around Y
253 	TF_WRAPXY      = TF_WRAPY|TF_WRAPX, // very common so use alias is more easy
254 	TF_CHROMAKEYED = 0x00000010,
255 	TF_TRANSPARENT = 0x00000040,        // texture with some alpha == 0
256 };
257 
258 struct FTextureInfo
259 {
260 	UINT32 width, height;
261 	UINT32 downloaded;
262 	UINT32 format;
263 
264 	struct GLMipmap_s *texture;
265 	struct FTextureInfo *prev, *next;
266 };
267 typedef struct FTextureInfo FTextureInfo;
268 
269 struct FLightInfo
270 {
271 	FUINT			light_level;
272 	FUINT			fade_start;
273 	FUINT			fade_end;
274 };
275 typedef struct FLightInfo FLightInfo;
276 
277 // Description of a renderable surface
278 struct FSurfaceInfo
279 {
280 	FUINT			PolyFlags;
281 	RGBA_t			PolyColor;
282 	RGBA_t			TintColor;
283 	RGBA_t			FadeColor;
284 	FLightInfo		LightInfo;
285 };
286 typedef struct FSurfaceInfo FSurfaceInfo;
287 
288 #define GL_DEFAULTMIX 0x00000000
289 #define GL_DEFAULTFOG 0xFF000000
290 
291 //Hurdler: added for backward compatibility
292 enum hwdsetspecialstate
293 {
294 	HWD_SET_MODEL_LIGHTING = 1,
295 	HWD_SET_SHADERS,
296 	HWD_SET_TEXTUREFILTERMODE,
297 	HWD_SET_TEXTUREANISOTROPICMODE,
298 	HWD_NUMSTATE
299 };
300 
301 typedef enum hwdsetspecialstate hwdspecialstate_t;
302 
303 // Lactozilla: Shader options
304 enum hwdshaderoption
305 {
306 	HWD_SHADEROPTION_OFF,
307 	HWD_SHADEROPTION_ON,
308 	HWD_SHADEROPTION_NOCUSTOM,
309 };
310 
311 typedef enum hwdshaderoption hwdshaderoption_t;
312 
313 // Lactozilla: Shader info
314 // Generally set at the start of the frame.
315 enum hwdshaderinfo
316 {
317 	HWD_SHADERINFO_LEVELTIME = 1,
318 };
319 
320 typedef enum hwdshaderinfo hwdshaderinfo_t;
321 
322 enum hwdfiltermode
323 {
324 	HWD_SET_TEXTUREFILTER_POINTSAMPLED,
325 	HWD_SET_TEXTUREFILTER_BILINEAR,
326 	HWD_SET_TEXTUREFILTER_TRILINEAR,
327 	HWD_SET_TEXTUREFILTER_MIXED1,
328 	HWD_SET_TEXTUREFILTER_MIXED2,
329 	HWD_SET_TEXTUREFILTER_MIXED3,
330 };
331 
332 
333 #endif //_HWR_DEFS_
334