1 /*
2 ===========================================================================
3 Copyright (C) 1999 - 2005, Id Software, Inc.
4 Copyright (C) 2000 - 2013, Raven Software, Inc.
5 Copyright (C) 2001 - 2013, Activision, Inc.
6 Copyright (C) 2005 - 2015, ioquake3 contributors
7 Copyright (C) 2013 - 2015, OpenJK contributors
8 
9 This file is part of the OpenJK source code.
10 
11 OpenJK is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License version 2 as
13 published by the Free Software Foundation.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, see <http://www.gnu.org/licenses/>.
22 ===========================================================================
23 */
24 
25 #pragma once
26 
27 #include "../qcommon/q_shared.h"
28 
29 #define	MAX_DLIGHTS		32			// can't be increased, because bit flags are used on surfaces
30 #define	REFENTITYNUM_BITS	11		// can't be increased without changing drawsurf bit packing
31 #define	REFENTITYNUM_MASK	((1<<REFENTITYNUM_BITS) - 1)
32 // the last N-bit number (2^REFENTITYNUM_BITS - 1) is reserved for the special world refentity,
33 //  and this is reflected by the value of MAX_REFENTITIES (which therefore is not a power-of-2)
34 #define	MAX_REFENTITIES		((1<<REFENTITYNUM_BITS) - 1)
35 #define	REFENTITYNUM_WORLD	((1<<REFENTITYNUM_BITS) - 1)
36 
37 #define	MAX_MINI_ENTITIES	1024
38 
39 // renderfx flags
40 #define	RF_MINLIGHT			0x00001	// allways have some light (viewmodel, some items)
41 #define	RF_THIRD_PERSON		0x00002	// don't draw through eyes, only mirrors (player bodies, chat sprites)
42 #define	RF_FIRST_PERSON		0x00004	// only draw through eyes (view weapon, damage blood blob)
43 #define	RF_DEPTHHACK		0x00008	// for view weapon Z crunching
44 #define RF_NODEPTH			0x00010	// No depth at all (seeing through walls)
45 
46 #define RF_VOLUMETRIC		0x00020	// fake volumetric shading
47 
48 #define	RF_NOSHADOW			0x00040	// don't add stencil shadows
49 
50 #define RF_LIGHTING_ORIGIN	0x00080	// use refEntity->lightingOrigin instead of refEntity->origin
51 									// for lighting.  This allows entities to sink into the floor
52 									// with their origin going solid, and allows all parts of a
53 									// player to get the same lighting
54 #define	RF_SHADOW_PLANE		0x00100	// use refEntity->shadowPlane
55 #define	RF_WRAP_FRAMES		0x00200	// mod the model frames by the maxframes to allow continuous
56 										// animation without needing to know the frame count
57 
58 #define RF_FORCE_ENT_ALPHA	0x00400 // override shader alpha settings
59 #define RF_RGB_TINT			0x00800 // override shader rgb settings
60 
61 #define	RF_SHADOW_ONLY		0x01000	//add surfs for shadowing but don't draw them -rww
62 
63 #define	RF_DISTORTION		0x02000	//area distortion effect -rww
64 
65 #define RF_FORKED			0x04000	// override lightning to have forks
66 #define RF_TAPERED			0x08000	// lightning tapers
67 #define RF_GROW				0x10000	// lightning grows from start to end during its life
68 
69 #define RF_DISINTEGRATE1	0x20000	// does a procedural hole-ripping thing.
70 #define RF_DISINTEGRATE2	0x40000	// does a procedural hole-ripping thing with scaling at the ripping point
71 
72 #define RF_SETANIMINDEX		0x80000	//use backEnd.currentEntity->e.skinNum for R_BindAnimatedImage
73 
74 #define RF_ALPHA_DEPTH		0x100000 //depth write on alpha model
75 
76 #define RF_FORCEPOST		0x200000 //force it to post-render -rww
77 
78 // refdef flags
79 #define RDF_NOWORLDMODEL	1		// used for player configuration screen
80 #define RDF_HYPERSPACE		4		// teleportation effect
81 
82 #define RDF_SKYBOXPORTAL	8
83 #define RDF_DRAWSKYBOX		16		// the above marks a scene as being a 'portal sky'.  this flag says to draw it or not
84 
85 #define RDF_AUTOMAP			32		//means this scene is to draw the automap -rww
86 #define	RDF_NOFOG			64		//no global fog in this scene (but still brush fog) -rww
87 #define RDF_ForceSightOn	128		//using force sight
88 
89 extern int	skyboxportal;
90 extern int	drawskyboxportal;
91 
92 typedef byte color4ub_t[4];
93 
94 typedef struct polyVert_s {
95 	vec3_t		xyz;
96 	float		st[2];
97 	byte		modulate[4];
98 } polyVert_t;
99 
100 typedef struct poly_s {
101 	qhandle_t			hShader;
102 	int					numVerts;
103 	polyVert_t			*verts;
104 } poly_t;
105 
106 typedef enum {
107 	RT_MODEL,
108 	RT_POLY,
109 	RT_SPRITE,
110 	RT_ORIENTED_QUAD,
111 	RT_BEAM,
112 	RT_SABER_GLOW,
113 	RT_ELECTRICITY,
114 	RT_PORTALSURFACE,		// doesn't draw anything, just info for portals
115 	RT_LINE,
116 	RT_ORIENTEDLINE,
117 	RT_CYLINDER,
118 	RT_ENT_CHAIN,
119 
120 	RT_MAX_REF_ENTITY_TYPE
121 } refEntityType_t;
122 
123 typedef struct miniRefEntity_s
124 {
125 	refEntityType_t		reType;
126 	int					renderfx;
127 
128 	qhandle_t			hModel;				// opaque type outside refresh
129 
130 	// most recent data
131 	matrix3_t			axis;			// rotation vectors
132 	qboolean			nonNormalizedAxes;	// axis are not normalized, i.e. they have scale
133 	vec3_t				origin;				// also used as MODEL_BEAM's "from"
134 
135 	// previous data for frame interpolation
136 	vec3_t				oldorigin;			// also used as MODEL_BEAM's "to"
137 
138 	// texturing
139 	qhandle_t			customShader;		// use one image for the entire thing
140 
141 	// misc
142 	byte				shaderRGBA[4];		// colors used by rgbgen entity shaders
143 	vec2_t				shaderTexCoord;		// texture coordinates used by tcMod entity modifiers
144 
145 	// extra sprite information
146 	float				radius;
147 	float				rotation;			// size 2 for RT_CYLINDER or number of verts in RT_ELECTRICITY
148 
149 	// misc
150 	float		shaderTime;			// subtracted from refdef time to control effect start times
151 	int			frame;				// also used as MODEL_BEAM's diameter
152 
153 } miniRefEntity_t;
154 
155 typedef struct refEntity_s {
156 	// this stucture must remain identical as the miniRefEntity_t
157 	//
158 	//
159 	refEntityType_t		reType;
160 	int					renderfx;
161 
162 	qhandle_t			hModel;				// opaque type outside refresh
163 
164 	// most recent data
165 	matrix3_t			axis;			// rotation vectors
166 	qboolean			nonNormalizedAxes;	// axis are not normalized, i.e. they have scale
167 	vec3_t				origin;				// also used as MODEL_BEAM's "from"
168 
169 	// previous data for frame interpolation
170 	vec3_t				oldorigin;			// also used as MODEL_BEAM's "to"
171 
172 	// texturing
173 	qhandle_t			customShader;		// use one image for the entire thing
174 
175 	// misc
176 	byte				shaderRGBA[4];		// colors used by rgbgen entity shaders
177 	vec2_t				shaderTexCoord;		// texture coordinates used by tcMod entity modifiers
178 
179 	// extra sprite information
180 	float				radius;
181 	float				rotation;
182 
183 	// misc
184 	float		shaderTime;			// subtracted from refdef time to control effect start times
185 	int			frame;				// also used as MODEL_BEAM's diameter
186 	//
187 	//
188 	// end miniRefEntity_t
189 
190 	//
191 	//
192 	// specific full refEntity_t data
193 	//
194 	//
195 
196 	// most recent data
197 	vec3_t		lightingOrigin;		// so multi-part models can be lit identically (RF_LIGHTING_ORIGIN)
198 	float		shadowPlane;		// projection shadows go here, stencils go slightly lower
199 
200 	// previous data for frame interpolation
201 	int			oldframe;
202 	float		backlerp;			// 0.0 = current, 1.0 = old
203 
204 	// texturing
205 	int			skinNum;			// inline skin index
206 	qhandle_t	customSkin;			// NULL for default skin
207 
208 	// texturing
209 	union
210 	{
211 //		int			skinNum;		// inline skin index
212 //		ivec3_t		terxelCoords;	// coords of patch for RT_TERXELS
213 		struct
214 		{
215 			int		miniStart;
216 			int		miniCount;
217 		} uMini;
218 	} uRefEnt;
219 
220 	// extra sprite information
221 	union {
222 		struct
223 		{
224 			float rotation;
225 			float radius;
226 			byte  vertRGBA[4][4];
227 		} sprite;
228 		struct
229 		{
230 			float width;
231 			float width2;
232 			float stscale;
233 		} line;
234 		struct	// that whole put-the-opening-brace-on-the-same-line-as-the-beginning-of-the-definition coding style is fecal
235 		{
236 			float	width;
237 			vec3_t	control1;
238 			vec3_t	control2;
239 		} bezier;
240 		struct
241 		{
242 			float width;
243 			float width2;
244 			float stscale;
245 			float height;
246 			float bias;
247 			qboolean wrap;
248 		} cylinder;
249 		struct
250 		{
251 			float width;
252 			float deviation;
253 			float stscale;
254 			qboolean wrap;
255 			qboolean taper;
256 		} electricity;
257 	} data;
258 
259 	float		endTime;
260 	float		saberLength;
261 
262 /*
263 Ghoul2 Insert Start
264 */
265 	vec3_t		angles;				// rotation angles - used for Ghoul2
266 
267 	vec3_t		modelScale;			// axis scale for models
268 //	CGhoul2Info_v	*ghoul2;  		// has to be at the end of the ref-ent in order for it to be created properly
269 	void		*ghoul2;  		// has to be at the end of the ref-ent in order for it to be created properly
270 /*
271 Ghoul2 Insert End
272 */
273 } refEntity_t;
274 
275 /*
276 Ghoul2 Insert Start
277 */
278 #define MDXABONEDEF
279 #include "rd-common/mdx_format.h"
280 #include "qcommon/qfiles.h"
281 
282 // skins allow models to be retextured without modifying the model file
283 //this is a mock copy, renderers may have their own implementation.
284 // try not to break the ghoul2 code which is very implicit :/
285 typedef struct _skinSurface_s {
286 	char		name[MAX_QPATH];
287 	void	*shader;
288 } _skinSurface_t;
289 
290 typedef struct skin_s {
291 	char		name[MAX_QPATH];		// game path, including extension
292 	int			numSurfaces;
293 	_skinSurface_t	*surfaces[128];
294 } skin_t;
295 
296 /*
297 Ghoul2 Insert End
298 */
299 typedef enum {
300 	MOD_BAD,
301 	MOD_BRUSH,
302 	MOD_MESH,
303 /*
304 Ghoul2 Insert Start
305 */
306    	MOD_MDXM,
307 	MOD_MDXA
308 /*
309 Ghoul2 Insert End
310 */
311 } modtype_t;
312 
313 typedef struct model_s {
314 	char		name[MAX_QPATH];
315 	modtype_t	type;
316 	int			index;				// model = tr.models[model->index]
317 
318 	int			dataSize;			// just for listing purposes
319 	struct bmodel_s	*bmodel;			// only if type == MOD_BRUSH
320 	md3Header_t	*md3[MD3_MAX_LODS];	// only if type == MOD_MESH
321 /*
322 Ghoul2 Insert Start
323 */
324 	mdxmHeader_t *mdxm;				// only if type == MOD_GL2M which is a GHOUL II Mesh file NOT a GHOUL II animation file
325 	mdxaHeader_t *mdxa;				// only if type == MOD_GL2A which is a GHOUL II Animation file
326 /*
327 Ghoul2 Insert End
328 */
329 	int			 numLods;
330 	qboolean	bspInstance;
331 } model_t;
332 
333 #define	MAX_RENDER_STRINGS			8
334 #define	MAX_RENDER_STRING_LENGTH	32
335 
336 typedef struct refdef_s {
337 	int			x, y, width, height;
338 	float		fov_x, fov_y;
339 	vec3_t		vieworg;
340 	vec3_t		viewangles;
341 	matrix3_t	viewaxis;		// transformation matrix
342 	int			viewContents;		// world contents at vieworg
343 
344 	// time in milliseconds for shader effects and other time dependent rendering issues
345 	int			time;
346 
347 	int			rdflags;			// RDF_NOWORLDMODEL, etc
348 
349 	// 1 bits will prevent the associated area from rendering at all
350 	byte		areamask[MAX_MAP_AREA_BYTES];
351 
352 	// text messages for deform text shaders
353 	char		text[MAX_RENDER_STRINGS][MAX_RENDER_STRING_LENGTH];
354 } refdef_t;
355 
356 
357 enum {
358 	STEREO_CENTER,
359 	STEREO_LEFT,
360 	STEREO_RIGHT
361 };
362 typedef int stereoFrame_t;
363 
364 
365 /*
366 ** glconfig_t
367 **
368 ** Contains variables specific to the OpenGL configuration
369 ** being run right now.  These are constant once the OpenGL
370 ** subsystem is initialized.
371 */
372 typedef enum { // r_ext_preferred_tc_method
373 	TC_NONE,
374 	TC_S3TC,
375 	TC_S3TC_DXT
376 } textureCompression_t;
377 
378 typedef struct glconfig_s {
379 	const char				*renderer_string;
380 	const char				*vendor_string;
381 	const char				*version_string;
382 	const char				*extensions_string;
383 
384 	int						maxTextureSize;			// queried from GL
385 	int						maxActiveTextures;		// multitexture ability
386 	float					maxTextureFilterAnisotropy;
387 
388 	int						colorBits, depthBits, stencilBits;
389 
390 	qboolean				deviceSupportsGamma;
391 	textureCompression_t	textureCompression;
392 	qboolean				textureEnvAddAvailable;
393 	qboolean				clampToEdgeAvailable;
394 
395 	int						vidWidth, vidHeight;
396 
397 	int						displayFrequency;
398 
399 	// synonymous with "does rendering consume the entire screen?", therefore
400 	// a Voodoo or Voodoo2 will have this set to TRUE, as will a Win32 ICD that
401 	// used CDS.
402 	qboolean				isFullscreen;
403 	qboolean				stereoEnabled;
404 } glconfig_t;
405