1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4 
5 This file is part of Quake III Arena source code.
6 
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11 
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 ===========================================================================
21 */
22 
23 
24 #ifndef TR_LOCAL_H
25 #define TR_LOCAL_H
26 
27 #include "../qcommon/q_shared.h"
28 #include "../qcommon/qfiles.h"
29 #include "../qcommon/qcommon.h"
30 #include "tr_public.h"
31 #include "qgl.h"
32 
33 #define GL_INDEX_TYPE		GL_UNSIGNED_INT
34 typedef unsigned int glIndex_t;
35 
36 // fast float to int conversion
37 #if id386 && !defined(__GNUC__)
38 long myftol( float f );
39 #else
40 #define	myftol(x) ((int)(x))
41 #endif
42 
43 
44 // everything that is needed by the backend needs
45 // to be double buffered to allow it to run in
46 // parallel on a dual cpu machine
47 #define	SMP_FRAMES		2
48 
49 // 12 bits
50 // see QSORT_SHADERNUM_SHIFT
51 #define	MAX_SHADERS				16384
52 
53 //#define MAX_SHADER_STATES 2048
54 #define MAX_STATES_PER_SHADER 32
55 #define MAX_STATE_NAME 32
56 
57 // can't be increased without changing bit packing for drawsurfs
58 
59 
60 typedef struct dlight_s {
61 	vec3_t	origin;
62 	vec3_t	color;				// range from 0.0 to 1.0, should be color normalized
63 	float	radius;
64 
65 	vec3_t	transformed;		// origin in local coordinate system
66 	int		additive;			// texture detail is lost tho when the lightmap is dark
67 } dlight_t;
68 
69 
70 // a trRefEntity_t has all the information passed in by
71 // the client game, as well as some locally derived info
72 typedef struct {
73 	refEntity_t	e;
74 
75 	float		axisLength;		// compensate for non-normalized axis
76 
77 	qboolean	needDlights;	// true for bmodels that touch a dlight
78 	qboolean	lightingCalculated;
79 	vec3_t		lightDir;		// normalized direction towards light
80 	vec3_t		ambientLight;	// color normalized to 0-255
81 	int			ambientLightInt;	// 32 bit rgba packed
82 	vec3_t		directedLight;
83 	vec3_t		dynamicLight;
84 	float		lightDistance;
85 } trRefEntity_t;
86 
87 
88 typedef struct {
89 	vec3_t		origin;			// in world coordinates
90 	vec3_t		axis[3];		// orientation in world
91 	vec3_t		viewOrigin;		// viewParms->or.origin in local coordinates
92 	float		modelMatrix[16];
93 } orientationr_t;
94 
95 typedef struct image_s {
96 	char		imgName[MAX_QPATH];		// game path, including extension
97 	int			width, height;				// source image
98 	int			uploadWidth, uploadHeight;	// after power of two and picmip but not including clamp to MAX_TEXTURE_SIZE
99 	GLuint		texnum;					// gl texture binding
100 
101 	int			frameUsed;			// for texture usage in frame statistics
102 
103 	int			internalFormat;
104 	int			TMU;				// only needed for voodoo2
105 
106 	qboolean	mipmap;
107 	qboolean	allowPicmip;
108 	int			wrapClampMode;		// GL_CLAMP_TO_EDGE or GL_REPEAT
109 
110 	struct image_s*	next;
111 } image_t;
112 
113 //===============================================================================
114 
115 typedef enum {
116 	SS_BAD,
117 	SS_PORTAL,			// mirrors, portals, viewscreens
118 	SS_ENVIRONMENT,		// sky box
119 	SS_OPAQUE,			// opaque
120 
121 	SS_DECAL,			// scorch marks, etc.
122 	SS_SEE_THROUGH,		// ladders, grates, grills that may have small blended edges
123 						// in addition to alpha test
124 	SS_BANNER,
125 
126 	SS_FOG,
127 
128 	SS_UNDERWATER,		// for items that should be drawn in front of the water plane
129 
130 	SS_BLEND0,			// regular transparency and filters
131 	SS_BLEND1,			// generally only used for additive type effects
132 	SS_BLEND2,
133 	SS_BLEND3,
134 
135 	SS_BLEND6,
136 	SS_STENCIL_SHADOW,
137 	SS_ALMOST_NEAREST,	// gun smoke puffs
138 
139 	SS_NEAREST			// blood blobs
140 } shaderSort_t;
141 
142 
143 #define MAX_SHADER_STAGES 8
144 
145 typedef enum {
146 	GF_NONE,
147 
148 	GF_SIN,
149 	GF_SQUARE,
150 	GF_TRIANGLE,
151 	GF_SAWTOOTH,
152 	GF_INVERSE_SAWTOOTH,
153 
154 	GF_NOISE
155 
156 } genFunc_t;
157 
158 
159 typedef enum {
160 	DEFORM_NONE,
161 	DEFORM_WAVE,
162 	DEFORM_NORMALS,
163 	DEFORM_BULGE,
164 	DEFORM_MOVE,
165 	DEFORM_PROJECTION_SHADOW,
166 	DEFORM_AUTOSPRITE,
167 	DEFORM_AUTOSPRITE2,
168 	DEFORM_TEXT0,
169 	DEFORM_TEXT1,
170 	DEFORM_TEXT2,
171 	DEFORM_TEXT3,
172 	DEFORM_TEXT4,
173 	DEFORM_TEXT5,
174 	DEFORM_TEXT6,
175 	DEFORM_TEXT7
176 } deform_t;
177 
178 typedef enum {
179 	AGEN_IDENTITY,
180 	AGEN_SKIP,
181 	AGEN_ENTITY,
182 	AGEN_ONE_MINUS_ENTITY,
183 	AGEN_VERTEX,
184 	AGEN_ONE_MINUS_VERTEX,
185 	AGEN_LIGHTING_SPECULAR,
186 	AGEN_WAVEFORM,
187 	AGEN_PORTAL,
188 	AGEN_CONST
189 } alphaGen_t;
190 
191 typedef enum {
192 	CGEN_BAD,
193 	CGEN_IDENTITY_LIGHTING,	// tr.identityLight
194 	CGEN_IDENTITY,			// always (1,1,1,1)
195 	CGEN_ENTITY,			// grabbed from entity's modulate field
196 	CGEN_ONE_MINUS_ENTITY,	// grabbed from 1 - entity.modulate
197 	CGEN_EXACT_VERTEX,		// tess.vertexColors
198 	CGEN_VERTEX,			// tess.vertexColors * tr.identityLight
199 	CGEN_ONE_MINUS_VERTEX,
200 	CGEN_WAVEFORM,			// programmatically generated
201 	CGEN_LIGHTING_DIFFUSE,
202 	CGEN_LIGHTING_UNIFORM,
203 	CGEN_LIGHTING_DYNAMIC,
204 	CGEN_FOG,				// standard fog
205 	CGEN_CONST				// fixed color
206 } colorGen_t;
207 
208 typedef enum {
209 	TCGEN_BAD,
210 	TCGEN_IDENTITY,			// clear to 0,0
211 	TCGEN_LIGHTMAP,
212 	TCGEN_TEXTURE,
213 	TCGEN_ENVIRONMENT_MAPPED,
214 	TCGEN_ENVIRONMENT_CELSHADE_MAPPED,
215 	TCGEN_FOG,
216 	TCGEN_VECTOR			// S and T from world coordinates
217 } texCoordGen_t;
218 
219 typedef enum {
220 	ACFF_NONE,
221 	ACFF_MODULATE_RGB,
222 	ACFF_MODULATE_RGBA,
223 	ACFF_MODULATE_ALPHA
224 } acff_t;
225 
226 typedef struct {
227 	genFunc_t	func;
228 
229 	float base;
230 	float amplitude;
231 	float phase;
232 	float frequency;
233 } waveForm_t;
234 
235 #define TR_MAX_TEXMODS 4
236 
237 typedef enum {
238 	TMOD_NONE,
239 	TMOD_TRANSFORM,
240 	TMOD_TURBULENT,
241 	TMOD_SCROLL,
242 	TMOD_SCALE,
243 	TMOD_STRETCH,
244 	TMOD_ROTATE,
245 	TMOD_ENTITY_TRANSLATE
246 } texMod_t;
247 
248 #define	MAX_SHADER_DEFORMS	3
249 typedef struct {
250 	deform_t	deformation;			// vertex coordinate modification type
251 
252 	vec3_t		moveVector;
253 	waveForm_t	deformationWave;
254 	float		deformationSpread;
255 
256 	float		bulgeWidth;
257 	float		bulgeHeight;
258 	float		bulgeSpeed;
259 } deformStage_t;
260 
261 
262 typedef struct {
263 	texMod_t		type;
264 
265 	// used for TMOD_TURBULENT and TMOD_STRETCH
266 	waveForm_t		wave;
267 
268 	// used for TMOD_TRANSFORM
269 	float			matrix[2][2];		// s' = s * m[0][0] + t * m[1][0] + trans[0]
270 	float			translate[2];		// t' = s * m[0][1] + t * m[0][1] + trans[1]
271 
272 	// used for TMOD_SCALE
273 	float			scale[2];			// s *= scale[0]
274 	                                    // t *= scale[1]
275 
276 	// used for TMOD_SCROLL
277 	float			scroll[2];			// s' = s + scroll[0] * time
278 										// t' = t + scroll[1] * time
279 
280 	// + = clockwise
281 	// - = counterclockwise
282 	float			rotateSpeed;
283 
284 } texModInfo_t;
285 
286 
287 #define	MAX_IMAGE_ANIMATIONS	8
288 
289 typedef struct {
290 	image_t			*image[MAX_IMAGE_ANIMATIONS];
291 	int				numImageAnimations;
292 	float			imageAnimationSpeed;
293 
294 	texCoordGen_t	tcGen;
295 	vec3_t			tcGenVectors[2];
296 
297 	int				numTexMods;
298 	texModInfo_t	*texMods;
299 
300 	int				videoMapHandle;
301 	qboolean		isLightmap;
302 	qboolean		vertexLightmap;
303 	qboolean		isVideoMap;
304 } textureBundle_t;
305 
306 #define NUM_TEXTURE_BUNDLES 8
307 
308 typedef struct {
309 	qboolean		active;
310 
311 	textureBundle_t	bundle[NUM_TEXTURE_BUNDLES];
312 
313 	waveForm_t		rgbWave;
314 	colorGen_t		rgbGen;
315 
316 	waveForm_t		alphaWave;
317 	alphaGen_t		alphaGen;
318 
319 	byte			constantColor[4];			// for CGEN_CONST and AGEN_CONST
320 
321 	unsigned		stateBits;					// GLS_xxxx mask
322 
323 	acff_t			adjustColorsForFog;
324 
325 	qboolean		isDetail;
326 	int				mipBias;
327 
328 	int				isGLSL;
329 	qhandle_t		program;
330 } shaderStage_t;
331 
332 struct shaderCommands_s;
333 
334 // any change in the LIGHTMAP_* defines here MUST be reflected in
335 // R_FindShader() in tr_bsp.c
336 #define LIGHTMAP_2D         -4	// shader is for 2D rendering
337 #define LIGHTMAP_BY_VERTEX  -3	// pre-lit triangle models
338 #define LIGHTMAP_WHITEIMAGE -2
339 #define LIGHTMAP_NONE       -1
340 
341 typedef enum {
342 	CT_FRONT_SIDED,
343 	CT_BACK_SIDED,
344 	CT_TWO_SIDED
345 } cullType_t;
346 
347 typedef enum {
348 	FP_NONE,		// surface is translucent and will just be adjusted properly
349 	FP_EQUAL,		// surface is opaque but possibly alpha tested
350 	FP_LE			// surface is trnaslucent, but still needs a fog pass (fog surface)
351 } fogPass_t;
352 
353 typedef struct {
354 	float		cloudHeight;
355 	image_t		*outerbox[6], *innerbox[6];
356 } skyParms_t;
357 
358 typedef struct {
359 	vec3_t	color;
360 	float	depthForOpaque;
361 } fogParms_t;
362 
363 
364 typedef struct shader_s {
365 	char		name[MAX_QPATH];		// game path, including extension
366 	int			lightmapIndex;			// for a shader to match, both name and lightmapIndex must match
367 
368 	int			index;					// this shader == tr.shaders[index]
369 	int			sortedIndex;			// this shader == tr.sortedShaders[sortedIndex]
370 
371 	float		sort;					// lower numbered shaders draw before higher numbered
372 
373 	qboolean	defaultShader;			// we want to return index 0 if the shader failed to
374 										// load for some reason, but R_FindShader should
375 										// still keep a name allocated for it, so if
376 										// something calls RE_RegisterShader again with
377 										// the same name, we don't try looking for it again
378 
379 	qboolean	explicitlyDefined;		// found in a .shader file
380 
381 	int			surfaceFlags;			// if explicitlyDefined, this will have SURF_* flags
382 	int			contentFlags;
383 
384 	qboolean	entityMergable;			// merge across entites optimizable (smoke, blood)
385 
386 	qboolean	isSky;
387 	skyParms_t	sky;
388 	fogParms_t	fogParms;
389 
390 	float		portalRange;			// distance to fog out at
391 
392 	int			multitextureEnv;		// 0, GL_MODULATE, GL_ADD (FIXME: put in stage)
393 
394 	cullType_t	cullType;				// CT_FRONT_SIDED, CT_BACK_SIDED, or CT_TWO_SIDED
395 	qboolean	polygonOffset;			// set for decals and other items that must be offset
396 	qboolean	noMipMaps;				// for console fonts, 2D elements, etc.
397 	qboolean	noPicMip;				// for images that must always be full resolution
398 
399 	fogPass_t	fogPass;				// draw a blended pass, possibly with depth test equals
400 
401 	qboolean	needsNormal;			// not all shaders will need all data to be gathered
402 	qboolean	needsST1;
403 	qboolean	needsST2;
404 	qboolean	needsColor;
405 
406 	int			numDeforms;
407 	deformStage_t	deforms[MAX_SHADER_DEFORMS];
408 
409 	int			numUnfoggedPasses;
410 	shaderStage_t	*stages[MAX_SHADER_STAGES];
411 
412 	void		(*optimalStageIteratorFunc)( void );
413 
414   float clampTime;                                  // time this shader is clamped to
415   float timeOffset;                                 // current time offset for this shader
416 
417   int numStates;                                    // if non-zero this is a state shader
418   struct shader_s *currentShader;                   // current state if this is a state shader
419   struct shader_s *parentShader;                    // current state if this is a state shader
420   int currentState;                                 // current state index for cycle purposes
421   long expireTime;                                  // time in milliseconds this expires
422 
423   struct shader_s *remappedShader;                  // current shader this one is remapped too
424 
425   int shaderStates[MAX_STATES_PER_SHADER];          // index to valid shader states
426 
427 	struct	shader_s	*next;
428 } shader_t;
429 
430 typedef struct shaderState_s {
431   char shaderName[MAX_QPATH];     // name of shader this state belongs to
432   char name[MAX_STATE_NAME];      // name of this state
433   char stateShader[MAX_QPATH];    // shader this name invokes
434   int cycleTime;                  // time this cycle lasts, <= 0 is forever
435   shader_t *shader;
436 } shaderState_t;
437 
438 
439 // trRefdef_t holds everything that comes in refdef_t,
440 // as well as the locally generated scene information
441 typedef struct {
442 	int			x, y, width, height;
443 	float		fov_x, fov_y;
444 	vec3_t		vieworg;
445 	vec3_t		viewaxis[3];		// transformation matrix
446 
447 	stereoFrame_t	stereoFrame;
448 
449 	int			time;				// time in milliseconds for shader effects and other time dependent rendering issues
450 	int			rdflags;			// RDF_NOWORLDMODEL, etc
451 
452 	// 1 bits will prevent the associated area from rendering at all
453 	byte		areamask[MAX_MAP_AREA_BYTES];
454 	qboolean	areamaskModified;	// qtrue if areamask changed since last scene
455 
456 	float		floatTime;			// tr.refdef.time / 1000.0
457 
458 	// text messages for deform text shaders
459 	char		text[MAX_RENDER_STRINGS][MAX_RENDER_STRING_LENGTH];
460 
461 	int			num_entities;
462 	trRefEntity_t	*entities;
463 
464 	int			num_dlights;
465 	struct dlight_s	*dlights;
466 
467 	int			numPolys;
468 	struct srfPoly_s	*polys;
469 
470 	int			numDrawSurfs;
471 	struct drawSurf_s	*drawSurfs;
472 
473 
474 } trRefdef_t;
475 
476 
477 //=================================================================================
478 
479 // skins allow models to be retextured without modifying the model file
480 typedef struct {
481 	char		name[MAX_QPATH];
482 	shader_t	*shader;
483 } skinSurface_t;
484 
485 typedef struct skin_s {
486 	char		name[MAX_QPATH];		// game path, including extension
487 	int			numSurfaces;
488 	skinSurface_t	*surfaces[MD3_MAX_SURFACES];
489 } skin_t;
490 
491 
492 typedef struct {
493 	int			originalBrushNumber;
494 	vec3_t		bounds[2];
495 
496 	unsigned	colorInt;				// in packed byte format
497 	float		tcScale;				// texture coordinate vector scales
498 	fogParms_t	parms;
499 
500 	// for clipping distance in fog when outside
501 	qboolean	hasSurface;
502 	float		surface[4];
503 } fog_t;
504 
505 typedef struct {
506 	orientationr_t	or;
507 	orientationr_t	world;
508 	vec3_t		pvsOrigin;			// may be different than or.origin for portals
509 	qboolean	isPortal;			// true if this view is through a portal
510 	qboolean	isMirror;			// the portal is a mirror, invert the face culling
511 	int			frameSceneNum;		// copied from tr.frameSceneNum
512 	int			frameCount;			// copied from tr.frameCount
513 	cplane_t	portalPlane;		// clip anything behind this if mirroring
514 	int			viewportX, viewportY, viewportWidth, viewportHeight;
515 	float		fovX, fovY;
516 	float		projectionMatrix[16];
517 	cplane_t	frustum[4];
518 	vec3_t		visBounds[2];
519 	float		zFar;
520 	stereoFrame_t	stereoFrame;
521 } viewParms_t;
522 
523 
524 /*
525 ==============================================================================
526 
527 SURFACES
528 
529 ==============================================================================
530 */
531 
532 // any changes in surfaceType must be mirrored in rb_surfaceTable[]
533 typedef enum {
534 	SF_BAD,
535 	SF_SKIP,				// ignore
536 	SF_FACE,
537 	SF_GRID,
538 	SF_TRIANGLES,
539 	SF_POLY,
540 	SF_MD3,
541 	SF_MD4,
542 #ifdef RAVENMD4
543 	SF_MDR,
544 #endif
545 	SF_FLARE,
546 	SF_ENTITY,				// beams, rails, lightning, etc that can be determined by entity
547 	SF_DISPLAY_LIST,
548 
549 	SF_NUM_SURFACE_TYPES,
550 	SF_MAX = 0x7fffffff			// ensures that sizeof( surfaceType_t ) == sizeof( int )
551 } surfaceType_t;
552 
553 typedef struct drawSurf_s {
554 	unsigned			sort;			// bit combination for fast compares
555 	surfaceType_t		*surface;		// any of surface*_t
556 } drawSurf_t;
557 
558 #define	MAX_FACE_POINTS		64
559 
560 #define	MAX_PATCH_SIZE		32			// max dimensions of a patch mesh in map file
561 #define	MAX_GRID_SIZE		65			// max dimensions of a grid mesh in memory
562 
563 // when cgame directly specifies a polygon, it becomes a srfPoly_t
564 // as soon as it is called
565 typedef struct srfPoly_s {
566 	surfaceType_t	surfaceType;
567 	qhandle_t		hShader;
568 	int				fogIndex;
569 	int				numVerts;
570 	polyVert_t		*verts;
571 } srfPoly_t;
572 
573 typedef struct srfDisplayList_s {
574 	surfaceType_t	surfaceType;
575 	int				listNum;
576 } srfDisplayList_t;
577 
578 
579 typedef struct srfFlare_s {
580 	surfaceType_t	surfaceType;
581 	vec3_t			origin;
582 	vec3_t			normal;
583 	vec3_t			color;
584 } srfFlare_t;
585 
586 typedef struct srfGridMesh_s {
587 	surfaceType_t	surfaceType;
588 
589 	// dynamic lighting information
590 	int				dlightBits[SMP_FRAMES];
591 
592 	// culling information
593 	vec3_t			meshBounds[2];
594 	vec3_t			localOrigin;
595 	float			meshRadius;
596 
597 	// lod information, which may be different
598 	// than the culling information to allow for
599 	// groups of curves that LOD as a unit
600 	vec3_t			lodOrigin;
601 	float			lodRadius;
602 	int				lodFixed;
603 	int				lodStitched;
604 
605 	// vertexes
606 	int				width, height;
607 	float			*widthLodError;
608 	float			*heightLodError;
609 	drawVert_t		verts[1];		// variable sized
610 } srfGridMesh_t;
611 
612 
613 
614 #define	VERTEXSIZE	8
615 typedef struct {
616 	surfaceType_t	surfaceType;
617 	cplane_t	plane;
618 
619 	// dynamic lighting information
620 	int			dlightBits[SMP_FRAMES];
621 
622 	// triangle definitions (no normals at points)
623 	int			numPoints;
624 	int			numIndices;
625 	int			ofsIndices;
626 	float		points[1][VERTEXSIZE];	// variable sized
627 										// there is a variable length list of indices here also
628 } srfSurfaceFace_t;
629 
630 
631 // misc_models in maps are turned into direct geometry by q3map
632 typedef struct {
633 	surfaceType_t	surfaceType;
634 
635 	// dynamic lighting information
636 	int				dlightBits[SMP_FRAMES];
637 
638 	// culling information (FIXME: use this!)
639 	vec3_t			bounds[2];
640 	vec3_t			localOrigin;
641 	float			radius;
642 
643 	// triangle definitions
644 	int				numIndexes;
645 	int				*indexes;
646 
647 	int				numVerts;
648 	drawVert_t		*verts;
649 } srfTriangles_t;
650 
651 
652 extern	void (*rb_surfaceTable[SF_NUM_SURFACE_TYPES])(void *);
653 
654 /*
655 ==============================================================================
656 
657 BRUSH MODELS
658 
659 ==============================================================================
660 */
661 
662 
663 //
664 // in memory representation
665 //
666 
667 #define	SIDE_FRONT	0
668 #define	SIDE_BACK	1
669 #define	SIDE_ON		2
670 
671 typedef struct msurface_s {
672 	int					viewCount;		// if == tr.viewCount, already added
673 	struct shader_s		*shader;
674 	int					fogIndex;
675 
676 	surfaceType_t		*data;			// any of srf*_t
677 } msurface_t;
678 
679 
680 
681 #define	CONTENTS_NODE		-1
682 typedef struct mnode_s {
683 	// common with leaf and node
684 	int			contents;		// -1 for nodes, to differentiate from leafs
685 	int			visframe;		// node needs to be traversed if current
686 	vec3_t		mins, maxs;		// for bounding box culling
687 	struct mnode_s	*parent;
688 
689 	// node specific
690 	cplane_t	*plane;
691 	struct mnode_s	*children[2];
692 
693 	// leaf specific
694 	int			cluster;
695 	int			area;
696 
697 	msurface_t	**firstmarksurface;
698 	int			nummarksurfaces;
699 } mnode_t;
700 
701 typedef struct {
702 	vec3_t		bounds[2];		// for culling
703 	msurface_t	*firstSurface;
704 	int			numSurfaces;
705 } bmodel_t;
706 
707 typedef struct {
708 	char		name[MAX_QPATH];		// ie: maps/tim_dm2.bsp
709 	char		baseName[MAX_QPATH];	// ie: tim_dm2
710 
711 	int			dataSize;
712 
713 	int			numShaders;
714 	dshader_t	*shaders;
715 
716 	bmodel_t	*bmodels;
717 
718 	int			numplanes;
719 	cplane_t	*planes;
720 
721 	int			numnodes;		// includes leafs
722 	int			numDecisionNodes;
723 	mnode_t		*nodes;
724 
725 	int			numsurfaces;
726 	msurface_t	*surfaces;
727 
728 	int			nummarksurfaces;
729 	msurface_t	**marksurfaces;
730 
731 	int			numfogs;
732 	fog_t		*fogs;
733 
734 	vec3_t		lightGridOrigin;
735 	vec3_t		lightGridSize;
736 	vec3_t		lightGridInverseSize;
737 	int			lightGridBounds[3];
738 	byte		*lightGridData;
739 
740 
741 	int			numClusters;
742 	int			clusterBytes;
743 	const byte	*vis;			// may be passed in by CM_LoadMap to save space
744 
745 	byte		*novis;			// clusterBytes of 0xff
746 
747 	char		*entityString;
748 	char		*entityParsePoint;
749 } world_t;
750 
751 #define MAX_PROGRAMS 256
752 #define MAX_PROGRAM_OBJECTS 8
753 
754 typedef struct {
755 	int				index;
756 	char			name[MAX_QPATH];
757 	qboolean		valid;
758 	GLhandleARB		program;
759 
760 	GLint			u_AlphaGen;
761 	alphaGen_t		v_AlphaGen;
762 
763 	GLint			u_AmbientLight;
764 	vec3_t			v_AmbientLight;
765 
766 	GLint			u_DynamicLight;
767 	vec3_t			v_DynamicLight;
768 
769 	GLint			u_LightDistance;
770 	float			v_LightDistance;
771 
772 	GLint			u_ColorGen;
773 	colorGen_t		v_ColorGen;
774 
775 	GLint			u_ConstantColor;
776 	byte			v_ConstantColor[4];
777 
778 	GLint			u_DirectedLight;
779 	vec3_t			v_DirectedLight;
780 
781 	GLint			u_EntityColor;
782 	byte			v_EntityColor[4];
783 
784 	GLint			u_FogColor;
785 	unsigned		v_FogColor;
786 
787 	GLint			u_Greyscale;
788 	int				v_Greyscale;
789 
790 	GLint			u_IdentityLight;
791 	float			v_IdentityLight;
792 
793 	GLint			u_LightDirection;
794 	vec3_t			v_LightDirection;
795 
796 	GLint			u_ModelViewMatrix;
797 	float			v_ModelViewMatrix[16];
798 
799 	GLint			u_ModelViewProjectionMatrix;
800 	float			v_ModelViewProjectionMatrix[16];
801 
802 	GLint			u_ProjectionMatrix;
803 	float			v_ProjectionMatrix[16];
804 
805 	GLint			u_TCGen0;
806 	texCoordGen_t	v_TCGen0;
807 
808 	GLint			u_TCGen1;
809 	texCoordGen_t	v_TCGen1;
810 
811 	GLint			u_TexEnv;
812 	int				v_TexEnv;
813 
814 	GLint			u_Texture0;
815 	GLint			u_Texture1;
816 	GLint			u_Texture2;
817 	GLint			u_Texture3;
818 	GLint			u_Texture4;
819 	GLint			u_Texture5;
820 	GLint			u_Texture6;
821 	GLint			u_Texture7;
822 
823 	GLint			u_Time;
824 	float			v_Time;
825 
826 	GLint			u_ViewOrigin;
827 	vec3_t			v_ViewOrigin;
828 
829 //Postprocessing usefull vars
830 	GLint			u_ScreenSizeX;
831 	GLint			u_ScreenSizeY;
832 	GLfloat			u_ScreenToNextPixelX;
833 	GLfloat			u_ScreenToNextPixelY;
834 	GLfloat			u_zFar;
835 
836 //End Postprocess Vars
837 
838 
839 } glslProgram_t;
840 //======================================================================
841 
842 typedef enum {
843 	MOD_BAD,
844 	MOD_BRUSH,
845 	MOD_MESH,
846 	MOD_MD4,
847 #ifdef RAVENMD4
848 	MOD_MDR
849 #endif
850 } modtype_t;
851 
852 typedef struct model_s {
853 	char		name[MAX_QPATH];
854 	modtype_t	type;
855 	int			index;				// model = tr.models[model->index]
856 
857 	int			dataSize;			// just for listing purposes
858 	bmodel_t	*bmodel;			// only if type == MOD_BRUSH
859 	md3Header_t	*md3[MD3_MAX_LODS];	// only if type == MOD_MESH
860 	void	*md4;				// only if type == (MOD_MD4 | MOD_MDR)
861 
862 	int			 numLods;
863 } model_t;
864 
865 
866 #define	MAX_MOD_KNOWN	1024
867 
868 void		R_ModelInit (void);
869 model_t		*R_GetModelByHandle( qhandle_t hModel );
870 int			R_LerpTag( orientation_t *tag, qhandle_t handle, int startFrame, int endFrame,
871 					 float frac, const char *tagName );
872 void		R_ModelBounds( qhandle_t handle, vec3_t mins, vec3_t maxs );
873 
874 void		R_Modellist_f (void);
875 
876 //====================================================
877 extern	refimport_t		ri;
878 
879 #define	MAX_DRAWIMAGES			2048
880 #define	MAX_LIGHTMAPS			256
881 #define	MAX_SKINS				1024
882 
883 
884 #define	MAX_DRAWSURFS			0x10000
885 #define	DRAWSURF_MASK			(MAX_DRAWSURFS-1)
886 
887 /*
888 
889 the drawsurf sort data is packed into a single 32 bit value so it can be
890 compared quickly during the qsorting process
891 
892 the bits are allocated as follows:
893 
894 21 - 31	: sorted shader index
895 11 - 20	: entity index
896 2 - 6	: fog index
897 //2		: used to be clipped flag REMOVED - 03.21.00 rad
898 0 - 1	: dlightmap index
899 
900 	TTimo - 1.32
901 17-31 : sorted shader index
902 7-16  : entity index
903 2-6   : fog index
904 0-1   : dlightmap index
905 */
906 #define	QSORT_SHADERNUM_SHIFT	17
907 #define	QSORT_ENTITYNUM_SHIFT	7
908 #define	QSORT_FOGNUM_SHIFT		2
909 
910 extern	int			gl_filter_min, gl_filter_max;
911 
912 /*
913 ** performanceCounters_t
914 */
915 typedef struct {
916 	int		c_sphere_cull_patch_in, c_sphere_cull_patch_clip, c_sphere_cull_patch_out;
917 	int		c_box_cull_patch_in, c_box_cull_patch_clip, c_box_cull_patch_out;
918 	int		c_sphere_cull_md3_in, c_sphere_cull_md3_clip, c_sphere_cull_md3_out;
919 	int		c_box_cull_md3_in, c_box_cull_md3_clip, c_box_cull_md3_out;
920 
921 	int		c_leafs;
922 	int		c_dlightSurfaces;
923 	int		c_dlightSurfacesCulled;
924 } frontEndCounters_t;
925 
926 #define	FOG_TABLE_SIZE		256
927 #define FUNCTABLE_SIZE		1024
928 #define FUNCTABLE_SIZE2		10
929 #define FUNCTABLE_MASK		(FUNCTABLE_SIZE-1)
930 
931 
932 // the renderer front end should never modify glstate_t
933 typedef struct {
934 	int			currenttextures[2];
935 	int			currenttmu;
936 	float		currentModelViewMatrix[16];
937 	float		currentModelViewProjectionMatrix[16];
938 	float		currentProjectionMatrix[16];
939 	qhandle_t	currentProgram;
940 	qhandle_t	postprocessingProgram;
941 	qboolean	finishCalled;
942 	int			texEnv[2];
943 	int			faceCulling;
944 	unsigned long	glStateBits;
945 } glstate_t;
946 
947 
948 typedef struct {
949 	int		c_surfaces, c_shaders, c_vertexes, c_indexes, c_totalIndexes;
950 	float	c_overDraw;
951 
952 	int		c_dlightVertexes;
953 	int		c_dlightIndexes;
954 
955 	int		c_flareAdds;
956 	int		c_flareTests;
957 	int		c_flareRenders;
958 
959 	int		msec;			// total msec for backend run
960 } backEndCounters_t;
961 
962 // all state modified by the back end is seperated
963 // from the front end state
964 typedef struct {
965 	int			smpFrame;
966 	trRefdef_t	refdef;
967 	viewParms_t	viewParms;
968 	orientationr_t	or;
969 	backEndCounters_t	pc;
970 	qboolean	isHyperspace;
971 	trRefEntity_t	*currentEntity;
972 	qboolean	skyRenderedThisView;	// flag for drawing sun
973 
974 	qboolean	projection2D;	// if qtrue, drawstretchpic doesn't need to change modes
975 	byte		color2D[4];
976 	qboolean	vertexes2D;		// shader needs to be finished
977 	qboolean	doneBloom;		// done bloom this frame
978 	qboolean	donepostproc;		// done postprocess this frame
979 	qboolean	doneSurfaces;   // done any 3d surfaces already
980 	trRefEntity_t	entity2D;	// currentEntity will point at this when doing 2D rendering
981 } backEndState_t;
982 
983 /*
984 ** trGlobals_t
985 **
986 ** Most renderer globals are defined here.
987 ** backend functions should never modify any of these fields,
988 ** but may read fields that aren't dynamically modified
989 ** by the frontend.
990 */
991 typedef struct {
992 	qboolean				registered;		// cleared at shutdown, set at beginRegistration
993 
994 	int						visCount;		// incremented every time a new vis cluster is entered
995 	int						frameCount;		// incremented every frame
996 	int						sceneCount;		// incremented every scene
997 	int						viewCount;		// incremented every view (twice a scene if portaled)
998 											// and every R_MarkFragments call
999 
1000 	int						smpFrame;		// toggles from 0 to 1 every endFrame
1001 
1002 	int						frameSceneNum;	// zeroed at RE_BeginFrame
1003 
1004 	qboolean				worldMapLoaded;
1005 	world_t					*world;
1006 
1007 	const byte				*externalVisData;	// from RE_SetWorldVisData, shared with CM_Load
1008 
1009 	image_t					*defaultImage;
1010 	image_t					*scratchImage[32];
1011 	image_t					*fogImage;
1012 	image_t					*dlightImage;	// inverse-quare highlight for projective adding
1013 	image_t					*flareImage;
1014 	image_t					*whiteImage;			// full of 0xff
1015 	image_t					*identityLightImage;	// full of tr.identityLightByte
1016 
1017 	shader_t				*defaultShader;
1018 	shader_t				*shadowShader;
1019 	shader_t				*projectionShadowShader;
1020 
1021 	shader_t				*flareShader;
1022 	shader_t				*sunShader;
1023 
1024 	qhandle_t				skipProgram;
1025 	qhandle_t				defaultProgram;
1026 	qhandle_t				vertexLitProgram;
1027 	qhandle_t				lightmappedMultitextureProgram;
1028 	qhandle_t				skyProgram;
1029 	qhandle_t				postprocessingProgram;
1030 
1031 	int						numPrograms;
1032 	glslProgram_t			*programs[MAX_PROGRAMS];
1033 	int						numLightmaps;
1034 	image_t					**lightmaps;
1035 
1036 	trRefEntity_t			*currentEntity;
1037 	trRefEntity_t			worldEntity;		// point currentEntity at this when rendering world
1038 	int						currentEntityNum;
1039 	int						shiftedEntityNum;	// currentEntityNum << QSORT_ENTITYNUM_SHIFT
1040 	model_t					*currentModel;
1041 
1042 	viewParms_t				viewParms;
1043 
1044 	float					identityLight;		// 1.0 / ( 1 << overbrightBits )
1045 	int						identityLightByte;	// identityLight * 255
1046 	int						overbrightBits;		// r_overbrightBits->integer, but set to 0 if no hw gamma
1047 
1048 	orientationr_t			or;					// for current entity
1049 
1050 	trRefdef_t				refdef;
1051 
1052 	int						viewCluster;
1053 
1054 	vec3_t					sunLight;			// from the sky shader for this level
1055 	vec3_t					sunDirection;
1056 
1057 	frontEndCounters_t		pc;
1058 	int						frontEndMsec;		// not in pc due to clearing issue
1059 
1060 	//
1061 	// put large tables at the end, so most elements will be
1062 	// within the +/32K indexed range on risc processors
1063 	//
1064 	model_t					*models[MAX_MOD_KNOWN];
1065 	int						numModels;
1066 
1067 	int						numAnimations;
1068 
1069 	int						numImages;
1070 	image_t					*images[MAX_DRAWIMAGES];
1071 
1072 	// shader indexes from other modules will be looked up in tr.shaders[]
1073 	// shader indexes from drawsurfs will be looked up in sortedShaders[]
1074 	// lower indexed sortedShaders must be rendered first (opaque surfaces before translucent)
1075 	int						numShaders;
1076 	shader_t				*shaders[MAX_SHADERS];
1077 	shader_t				*sortedShaders[MAX_SHADERS];
1078 
1079 	int						numSkins;
1080 	skin_t					*skins[MAX_SKINS];
1081 
1082 	float					sinTable[FUNCTABLE_SIZE];
1083 	float					squareTable[FUNCTABLE_SIZE];
1084 	float					triangleTable[FUNCTABLE_SIZE];
1085 	float					sawToothTable[FUNCTABLE_SIZE];
1086 	float					inverseSawToothTable[FUNCTABLE_SIZE];
1087 	float					fogTable[FOG_TABLE_SIZE];
1088 } trGlobals_t;
1089 
1090 extern backEndState_t	backEnd;
1091 extern trGlobals_t	tr;
1092 extern glconfig_t	glConfig;		// outside of TR since it shouldn't be cleared during ref re-init
1093 extern glstate_t	glState;		// outside of TR since it shouldn't be cleared during ref re-init
1094 
1095 // These two variables should live inside glConfig but can't because of compatibility issues to the original ID vms.
1096 // If you release a stand-alone game and your mod uses tr_types.h from this build you can safely move them to
1097 // the glconfig_t struct.
1098 extern qboolean  textureFilterAnisotropic;
1099 extern int       maxAnisotropy;
1100 extern qboolean  vertexShaders;
1101 extern qboolean  postprocess;
1102 extern char		 depthimage;
1103 extern float     displayAspect;
1104 
1105 
1106 //
1107 // cvars
1108 //
1109 extern cvar_t	*r_flareSize;
1110 extern cvar_t	*r_flareFade;
1111 // coefficient for the flare intensity falloff function.
1112 #define FLARE_STDCOEFF "150"
1113 extern cvar_t	*r_flareCoeff;
1114 
1115 extern cvar_t	*r_railWidth;
1116 extern cvar_t	*r_railCoreWidth;
1117 extern cvar_t	*r_railSegmentLength;
1118 
1119 extern cvar_t	*r_ignore;				// used for debugging anything
1120 extern cvar_t	*r_verbose;				// used for verbose debug spew
1121 extern cvar_t	*r_ignoreFastPath;		// allows us to ignore our Tess fast paths
1122 
1123 extern cvar_t	*r_znear;				// near Z clip plane
1124 extern cvar_t	*r_zproj;				// z distance of projection plane
1125 extern cvar_t	*r_stereoSeparation;			// separation of cameras for stereo rendering
1126 
1127 extern cvar_t	*r_stencilbits;			// number of desired stencil bits
1128 extern cvar_t	*r_depthbits;			// number of desired depth bits
1129 extern cvar_t	*r_colorbits;			// number of desired color bits, only relevant for fullscreen
1130 extern cvar_t	*r_texturebits;			// number of desired texture bits
1131 extern cvar_t	*r_ext_multisample;
1132 										// 0 = use framebuffer depth
1133 										// 16 = use 16-bit textures
1134 										// 32 = use 32-bit textures
1135 										// all else = error
1136 
1137 extern cvar_t	*r_measureOverdraw;		// enables stencil buffer overdraw measurement
1138 
1139 extern cvar_t	*r_lodbias;				// push/pull LOD transitions
1140 extern cvar_t	*r_lodscale;
1141 
1142 extern cvar_t	*r_primitives;			// "0" = based on compiled vertex array existance
1143 										// "1" = glDrawElemet tristrips
1144 										// "2" = glDrawElements triangles
1145 										// "-1" = no drawing
1146 
1147 extern cvar_t	*r_inGameVideo;				// controls whether in game video should be draw
1148 extern cvar_t	*r_fastsky;				// controls whether sky should be cleared or drawn
1149 extern cvar_t	*r_drawSun;				// controls drawing of sun quad
1150 extern cvar_t	*r_dynamiclight;		// dynamic lights enabled/disabled
1151 extern cvar_t	*r_dlightBacks;			// dlight non-facing surfaces for continuity
1152 
1153 extern	cvar_t	*r_norefresh;			// bypasses the ref rendering
1154 extern	cvar_t	*r_drawentities;		// disable/enable entity rendering
1155 extern	cvar_t	*r_drawworld;			// disable/enable world rendering
1156 extern	cvar_t	*r_speeds;				// various levels of information display
1157 extern  cvar_t	*r_detailTextures;		// enables/disables detail texturing stages
1158 extern	cvar_t	*r_novis;				// disable/enable usage of PVS
1159 extern	cvar_t	*r_nocull;
1160 extern	cvar_t	*r_facePlaneCull;		// enables culling of planar surfaces with back side test
1161 extern	cvar_t	*r_nocurves;
1162 extern	cvar_t	*r_showcluster;
1163 
1164 extern cvar_t	*r_mode;				// video mode
1165 extern cvar_t	*r_fullscreen;
1166 extern cvar_t	*r_noborder;
1167 extern cvar_t	*r_gamma;
1168 extern cvar_t	*r_ignorehwgamma;		// overrides hardware gamma capabilities
1169 
1170 extern cvar_t	*r_allowExtensions;				// global enable/disable of OpenGL extensions
1171 extern cvar_t	*r_ext_compressed_textures;		// these control use of specific extensions
1172 extern cvar_t	*r_ext_multitexture;
1173 extern cvar_t	*r_ext_compiled_vertex_array;
1174 extern cvar_t	*r_ext_texture_env_add;
1175 
1176 extern cvar_t	*r_ext_texture_filter_anisotropic;
1177 extern cvar_t	*r_ext_max_anisotropy;
1178 
1179 extern cvar_t	*r_ext_vertex_shader;
1180 extern cvar_t	*r_postprocess;
1181 extern	cvar_t	*r_nobind;						// turns off binding to appropriate textures
1182 extern	cvar_t	*r_singleShader;				// make most world faces use default shader
1183 extern	cvar_t	*r_roundImagesDown;
1184 extern	cvar_t	*r_colorMipLevels;				// development aid to see texture mip usage
1185 extern	cvar_t	*r_picmip;						// controls picmip values
1186 extern	cvar_t	*r_finish;
1187 extern	cvar_t	*r_drawBuffer;
1188 extern	cvar_t	*r_swapInterval;
1189 extern	cvar_t	*r_textureMode;
1190 extern	cvar_t	*r_offsetFactor;
1191 extern	cvar_t	*r_offsetUnits;
1192 
1193 extern	cvar_t	*r_fullbright;					// avoid lightmap pass
1194 extern	cvar_t	*r_lightmap;					// render lightmaps only
1195 extern	cvar_t	*r_vertexLight;					// vertex lighting mode for better performance
1196 extern	cvar_t	*r_uiFullScreen;				// ui is running fullscreen
1197 
1198 extern	cvar_t	*r_logFile;						// number of frames to emit GL logs
1199 extern	cvar_t	*r_showtris;					// enables wireframe rendering of the world
1200 extern	cvar_t	*r_showsky;						// forces sky in front of all surfaces
1201 extern	cvar_t	*r_shownormals;					// draws wireframe normals
1202 extern	cvar_t	*r_clear;						// force screen clear every frame
1203 
1204 extern	cvar_t	*r_shadows;						// controls shadows: 0 = none, 1 = blur, 2 = stencil, 3 = black planar projection
1205 extern	cvar_t	*r_flares;						// light flares
1206 
1207 extern	cvar_t	*r_intensity;
1208 
1209 extern	cvar_t	*r_lockpvs;
1210 extern	cvar_t	*r_noportals;
1211 extern	cvar_t	*r_portalOnly;
1212 
1213 extern	cvar_t	*r_subdivisions;
1214 extern	cvar_t	*r_lodCurveError;
1215 extern	cvar_t	*r_smp;
1216 extern	cvar_t	*r_showSmp;
1217 extern	cvar_t	*r_skipBackEnd;
1218 
1219 extern	cvar_t	*r_stereoEnabled;
1220 extern	cvar_t	*r_anaglyphMode;
1221 
1222 extern	cvar_t	*r_greyscale;
1223 
1224 extern	cvar_t	*r_monolightmaps;
1225 extern	cvar_t	*r_ignoreGLErrors;
1226 
1227 extern	cvar_t	*r_overBrightBits;
1228 extern	cvar_t	*r_mapOverBrightBits;
1229 
1230 extern	cvar_t	*r_debugSurface;
1231 extern	cvar_t	*r_simpleMipMaps;
1232 
1233 extern	cvar_t	*r_showImages;
1234 extern	cvar_t	*r_debugSort;
1235 
1236 extern	cvar_t	*r_printShaders;
1237 extern	cvar_t	*r_saveFontData;
1238 
1239 extern cvar_t	*r_marksOnTriangleMeshes;
1240 
1241 extern	cvar_t	*r_lensReflection1;
1242 extern	cvar_t	*r_lensReflection2;
1243 extern	cvar_t	*r_lensReflectionBrightness;
1244 
1245 
1246 extern	cvar_t	*r_envMode;
1247 extern	cvar_t	*r_specMode;
1248 //extern	cvar_t	*r_waveMode;
1249 
1250 extern	cvar_t	*r_flaresDlight;
1251 //extern	cvar_t	*r_flaresSurfradii;
1252 
1253 //====================================================================
1254 
1255 float R_NoiseGet4f( float x, float y, float z, float t );
1256 void  R_NoiseInit( void );
1257 
1258 void R_SwapBuffers( int );
1259 
1260 void R_RenderView( viewParms_t *parms );
1261 
1262 void R_AddMD3Surfaces( trRefEntity_t *e );
1263 void R_AddNullModelSurfaces( trRefEntity_t *e );
1264 void R_AddBeamSurfaces( trRefEntity_t *e );
1265 void R_AddRailSurfaces( trRefEntity_t *e, qboolean isUnderwater );
1266 void R_AddLightningBoltSurfaces( trRefEntity_t *e );
1267 
1268 void R_AddPolygonSurfaces( void );
1269 
1270 void R_DecomposeSort( unsigned sort, int *entityNum, shader_t **shader,
1271 					 int *fogNum, int *dlightMap );
1272 
1273 void R_AddDrawSurf( surfaceType_t *surface, shader_t *shader, int fogIndex, int dlightMap );
1274 
1275 
1276 #define	CULL_IN		0		// completely unclipped
1277 #define	CULL_CLIP	1		// clipped by one or more planes
1278 #define	CULL_OUT	2		// completely outside the clipping planes
1279 void R_LocalNormalToWorld (vec3_t local, vec3_t world);
1280 void R_LocalPointToWorld (vec3_t local, vec3_t world);
1281 int R_CullLocalBox (vec3_t bounds[2]);
1282 int R_CullPointAndRadius( vec3_t origin, float radius );
1283 int R_CullLocalPointAndRadius( vec3_t origin, float radius );
1284 
1285 void R_SetupProjection(viewParms_t *dest, float zProj, qboolean computeFrustum);
1286 void R_RotateForEntity( const trRefEntity_t *ent, const viewParms_t *viewParms, orientationr_t *or );
1287 
1288 /*
1289 ** GL wrapper/helper functions
1290 */
1291 void	GL_Bind( image_t *image );
1292 void	GL_SetDefaultState (void);
1293 void	GL_SelectTexture( int unit );
1294 void	GL_TextureMode( const char *string );
1295 void	GL_CheckErrors( void );
1296 void	GL_State( unsigned long stateVector );
1297 void	GL_TexEnv( int env );
1298 void	GL_Cull( int cullType );
1299 
1300 #define GLS_SRCBLEND_ZERO						0x00000001
1301 #define GLS_SRCBLEND_ONE						0x00000002
1302 #define GLS_SRCBLEND_DST_COLOR					0x00000003
1303 #define GLS_SRCBLEND_ONE_MINUS_DST_COLOR		0x00000004
1304 #define GLS_SRCBLEND_SRC_ALPHA					0x00000005
1305 #define GLS_SRCBLEND_ONE_MINUS_SRC_ALPHA		0x00000006
1306 #define GLS_SRCBLEND_DST_ALPHA					0x00000007
1307 #define GLS_SRCBLEND_ONE_MINUS_DST_ALPHA		0x00000008
1308 #define GLS_SRCBLEND_ALPHA_SATURATE				0x00000009
1309 #define		GLS_SRCBLEND_BITS					0x0000000f
1310 
1311 #define GLS_DSTBLEND_ZERO						0x00000010
1312 #define GLS_DSTBLEND_ONE						0x00000020
1313 #define GLS_DSTBLEND_SRC_COLOR					0x00000030
1314 #define GLS_DSTBLEND_ONE_MINUS_SRC_COLOR		0x00000040
1315 #define GLS_DSTBLEND_SRC_ALPHA					0x00000050
1316 #define GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA		0x00000060
1317 #define GLS_DSTBLEND_DST_ALPHA					0x00000070
1318 #define GLS_DSTBLEND_ONE_MINUS_DST_ALPHA		0x00000080
1319 #define		GLS_DSTBLEND_BITS					0x000000f0
1320 
1321 #define GLS_DEPTHMASK_TRUE						0x00000100
1322 
1323 #define GLS_POLYMODE_LINE						0x00001000
1324 
1325 #define GLS_DEPTHTEST_DISABLE					0x00010000
1326 #define GLS_DEPTHFUNC_EQUAL						0x00020000
1327 
1328 #define GLS_ATEST_GT_0							0x10000000
1329 #define GLS_ATEST_LT_80							0x20000000
1330 #define GLS_ATEST_GE_80							0x40000000
1331 #define		GLS_ATEST_BITS						0x70000000
1332 
1333 #define GLS_DEFAULT			GLS_DEPTHMASK_TRUE
1334 
1335 void	RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty);
1336 void	RE_UploadCinematic (int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty);
1337 
1338 void		RE_BeginFrame( stereoFrame_t stereoFrame );
1339 void		RE_BeginRegistration( glconfig_t *glconfig );
1340 void		RE_LoadWorldMap( const char *mapname );
1341 void		RE_SetWorldVisData( const byte *vis );
1342 qhandle_t	RE_RegisterModel( const char *name );
1343 qhandle_t	RE_RegisterSkin( const char *name );
1344 void		RE_Shutdown( qboolean destroyWindow );
1345 
1346 qboolean	R_GetEntityToken( char *buffer, int size );
1347 
1348 model_t		*R_AllocModel( void );
1349 
1350 void    	R_Init( void );
1351 image_t		*R_FindImageFile( const char *name, qboolean mipmap, qboolean allowPicmip, int glWrapClampMode );
1352 
1353 image_t		*R_CreateImage( const char *name, const byte *pic, int width, int height, qboolean mipmap
1354 					, qboolean allowPicmip, int wrapClampMode );
1355 qboolean	R_GetModeInfo( int *width, int *height, float *windowAspect, int mode );
1356 
1357 void		R_SetColorMappings( void );
1358 void		R_GammaCorrect( byte *buffer, int bufSize );
1359 
1360 void	R_ImageList_f( void );
1361 void	R_SkinList_f( void );
1362 // https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=516
1363 const void *RB_TakeScreenshotCmd( const void *data );
1364 void	R_ScreenShot_f( void );
1365 
1366 void	R_InitFogTable( void );
1367 float	R_FogFactor( float s, float t );
1368 void	R_InitImages( void );
1369 void	R_DeleteTextures( void );
1370 int		R_SumOfUsedImages( void );
1371 void	R_InitSkins( void );
1372 skin_t	*R_GetSkinByHandle( qhandle_t hSkin );
1373 
1374 int R_ComputeLOD( trRefEntity_t *ent );
1375 
1376 const void *RB_TakeVideoFrameCmd( const void *data );
1377 
1378 //
1379 // tr_shader.c
1380 //
1381 qhandle_t		 RE_RegisterShaderLightMap( const char *name, int lightmapIndex );
1382 qhandle_t		 RE_RegisterShader( const char *name );
1383 qhandle_t		 RE_RegisterShaderNoMip( const char *name );
1384 qhandle_t RE_RegisterShaderFromImage(const char *name, int lightmapIndex, image_t *image, qboolean mipRawImage);
1385 
1386 shader_t	*R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImage );
1387 shader_t	*R_GetShaderByHandle( qhandle_t hShader );
1388 shader_t	*R_GetShaderByState( int index, long *cycleTime );
1389 shader_t *R_FindShaderByName( const char *name );
1390 void		R_InitShaders( void );
1391 void		R_ShaderList_f( void );
1392 void    R_RemapShader(const char *oldShader, const char *newShader, const char *timeOffset);
1393 
1394 /*
1395 ====================================================================
1396 
1397 IMPLEMENTATION SPECIFIC FUNCTIONS
1398 
1399 ====================================================================
1400 */
1401 
1402 void		GLimp_Init( void );
1403 void		GLimp_Shutdown( void );
1404 void		GLimp_EndFrame( void );
1405 
1406 qboolean	GLimp_SpawnRenderThread( void (*function)( void ) );
1407 void		*GLimp_RendererSleep( void );
1408 void		GLimp_FrontEndSleep( void );
1409 void		GLimp_WakeRenderer( void *data );
1410 
1411 void		GLimp_LogComment( char *comment );
1412 
1413 // NOTE TTimo linux works with float gamma value, not the gamma table
1414 //   the params won't be used, getting the r_gamma cvar directly
1415 void		GLimp_SetGamma( unsigned char red[256],
1416 						    unsigned char green[256],
1417 							unsigned char blue[256] );
1418 
1419 
1420 /*
1421 ====================================================================
1422 
1423 TESSELATOR/SHADER DECLARATIONS
1424 
1425 ====================================================================
1426 */
1427 typedef byte color4ub_t[4];
1428 
1429 typedef struct stageVars
1430 {
1431 	color4ub_t	colors[SHADER_MAX_VERTEXES];
1432 	vec2_t		texcoords[NUM_TEXTURE_BUNDLES][SHADER_MAX_VERTEXES];
1433 } stageVars_t;
1434 
1435 
1436 typedef struct shaderCommands_s
1437 {
1438 	glIndex_t	indexes[SHADER_MAX_INDEXES] QALIGN(16);
1439 	vec4_t		xyz[SHADER_MAX_VERTEXES] QALIGN(16);
1440 	vec4_t		normal[SHADER_MAX_VERTEXES] QALIGN(16);
1441 	vec2_t		texCoords[SHADER_MAX_VERTEXES][2] QALIGN(16);
1442 	color4ub_t	vertexColors[SHADER_MAX_VERTEXES] QALIGN(16);
1443 	int			vertexDlightBits[SHADER_MAX_VERTEXES] QALIGN(16);
1444 
1445 	stageVars_t	svars QALIGN(16);
1446 
1447 	color4ub_t	constantColor255[SHADER_MAX_VERTEXES] QALIGN(16);
1448 
1449 	shader_t	*shader;
1450 	float		shaderTime;
1451 	int			fogNum;
1452 
1453 	int			dlightBits;	// or together of all vertexDlightBits
1454 
1455 	int			numIndexes;
1456 	int			numVertexes;
1457 
1458 	// info extracted from current shader
1459 	int			numPasses;
1460 	void		(*currentStageIteratorFunc)( void );
1461 	shaderStage_t	**xstages;
1462 } shaderCommands_t;
1463 
1464 extern	shaderCommands_t	tess;
1465 
1466 void RB_SetGL2D (void);
1467 void RB_BeginSurface(shader_t *shader, int fogNum );
1468 void RB_EndSurface(void);
1469 void RB_CheckOverflow( int verts, int indexes );
1470 #define RB_CHECKOVERFLOW(v,i) if (tess.numVertexes + (v) >= SHADER_MAX_VERTEXES || tess.numIndexes + (i) >= SHADER_MAX_INDEXES ) {RB_CheckOverflow(v,i);}
1471 
1472 void RB_StageIteratorGeneric( void );
1473 void RB_StageIteratorSky( void );
1474 void RB_StageIteratorVertexLitTexture( void );
1475 void RB_StageIteratorLightmappedMultitexture( void );
1476 
1477 void RB_AddQuadStamp( vec3_t origin, vec3_t left, vec3_t up, byte *color );
1478 void RB_AddQuadStampExt( vec3_t origin, vec3_t left, vec3_t up, byte *color, float s1, float t1, float s2, float t2 );
1479 
1480 void RB_ShowImages( void );
1481 
1482 
1483 /*
1484 ============================================================
1485 
1486 WORLD MAP
1487 
1488 ============================================================
1489 */
1490 
1491 void R_AddBrushModelSurfaces( trRefEntity_t *e );
1492 void R_AddWorldSurfaces( void );
1493 qboolean R_inPVS( const vec3_t p1, const vec3_t p2 );
1494 
1495 
1496 /*
1497 ============================================================
1498 
1499 FLARES
1500 
1501 ============================================================
1502 */
1503 
1504 void R_ClearFlares( void );
1505 
1506 void RB_AddFlare( void *surface, int fogNum, vec3_t point, vec3_t color, vec3_t normal, int radii );
1507 void RB_AddDlightFlares( void );
1508 void RB_RenderFlares (void);
1509 
1510 /*
1511 ============================================================
1512 
1513 GLSL
1514 
1515 ============================================================
1516 */
1517 
1518 /*
1519  * R_GLSL_SetUniform
1520  * Only upload uniform data when value changes
1521  */
R_GLSL_SetUniform_AlphaGen(glslProgram_t * program,alphaGen_t value)1522 static ID_INLINE void R_GLSL_SetUniform_AlphaGen(glslProgram_t *program, alphaGen_t value) {
1523 	if (program->v_AlphaGen == value)
1524 		return;
1525 
1526 	program->v_AlphaGen = value;
1527 	qglUniform1iARB(program->u_AlphaGen, value);
1528 }
1529 
R_GLSL_SetUniform_AmbientLight(glslProgram_t * program,const vec3_t value)1530 static ID_INLINE void R_GLSL_SetUniform_AmbientLight(glslProgram_t *program, const vec3_t value) {
1531 	if (VectorCompare(program->v_AmbientLight, value))
1532 		return;
1533 
1534 	VectorCopy(value, program->v_AmbientLight);
1535 	qglUniform3fARB(program->u_AmbientLight, value[0] / 255.0f, value[1] / 255.0f, value[2] / 255.0f);
1536 }
1537 
R_GLSL_SetUniform_DynamicLight(glslProgram_t * program,const vec3_t value)1538 static ID_INLINE void R_GLSL_SetUniform_DynamicLight(glslProgram_t *program, const vec3_t value) {
1539 	if (VectorCompare(program->v_DynamicLight, value))
1540 		return;
1541 
1542 	VectorCopy(value, program->v_DynamicLight);
1543 	qglUniform3fARB(program->u_DynamicLight, value[0] / 255.0f, value[1] / 255.0f, value[2] / 255.0f);
1544 }
1545 
R_GLSL_SetUniform_LightDistance(glslProgram_t * program,float value)1546 static ID_INLINE void R_GLSL_SetUniform_LightDistance(glslProgram_t *program, float value) {
1547 	if (program->v_LightDistance == value)
1548 		return;
1549 
1550 	program->v_LightDistance = value;
1551 	qglUniform1fARB(program->u_LightDistance, value);
1552 }
1553 
R_GLSL_SetUniform_ColorGen(glslProgram_t * program,colorGen_t value)1554 static ID_INLINE void R_GLSL_SetUniform_ColorGen(glslProgram_t *program, colorGen_t value) {
1555 	if (program->v_ColorGen == value)
1556 		return;
1557 
1558 	program->v_ColorGen = value;
1559 	qglUniform1iARB(program->u_ColorGen, value);
1560 }
1561 
R_GLSL_SetUniform_ConstantColor(glslProgram_t * program,byte value[4])1562 static ID_INLINE void R_GLSL_SetUniform_ConstantColor(glslProgram_t *program, byte value[4]) {
1563 	if (program->v_ConstantColor[0] == value[0] &&
1564 		program->v_ConstantColor[1] == value[1] &&
1565 		program->v_ConstantColor[2] == value[2] &&
1566 		program->v_ConstantColor[3] == value[3])
1567 		return;
1568 
1569 	program->v_ConstantColor[0] = value[0];
1570 	program->v_ConstantColor[1] = value[1];
1571 	program->v_ConstantColor[2] = value[2];
1572 	program->v_ConstantColor[3] = value[3];
1573 	qglUniform4fARB(program->u_ConstantColor, value[0] / 255.0f, value[1] / 255.0f, value[2] / 255.0f, value[3] / 255.0f);
1574 }
1575 
R_GLSL_SetUniform_DirectedLight(glslProgram_t * program,const vec3_t value)1576 static ID_INLINE void R_GLSL_SetUniform_DirectedLight(glslProgram_t *program, const vec3_t value) {
1577 	if (VectorCompare(program->v_DirectedLight, value))
1578 		return;
1579 
1580 	VectorCopy(value, program->v_DirectedLight);
1581 	qglUniform3fARB(program->u_DirectedLight, value[0] / 255.0f, value[1] / 255.0f, value[2] / 255.0f);
1582 }
1583 
R_GLSL_SetUniform_EntityColor(glslProgram_t * program,byte value[4])1584 static ID_INLINE void R_GLSL_SetUniform_EntityColor(glslProgram_t *program, byte value[4]) {
1585 	if (program->v_EntityColor[0] == value[0] &&
1586 		program->v_EntityColor[1] == value[1] &&
1587 		program->v_EntityColor[2] == value[2] &&
1588 		program->v_EntityColor[3] == value[3])
1589 		return;
1590 
1591 	program->v_EntityColor[0] = value[0];
1592 	program->v_EntityColor[1] = value[1];
1593 	program->v_EntityColor[2] = value[2];
1594 	program->v_EntityColor[3] = value[3];
1595 	qglUniform4fARB(program->u_EntityColor, value[0] / 255.0f, value[1] / 255.0f, value[2] / 255.0f, value[3] / 255.0f);
1596 }
1597 
R_GLSL_SetUniform_FogColor(glslProgram_t * program,unsigned value)1598 static ID_INLINE void R_GLSL_SetUniform_FogColor(glslProgram_t *program, unsigned value) {
1599 	byte	temp[4];
1600 
1601 	if (program->v_FogColor == value)
1602 		return;
1603 
1604 	*(unsigned *)temp = value;
1605 
1606 	program->v_FogColor = value;
1607 	qglUniform4fARB(program->u_FogColor, temp[0] / 255.0f, temp[1] / 255.0f, temp[2] / 255.0f, temp[3] / 255.0f);
1608 }
1609 
R_GLSL_SetUniform_Greyscale(glslProgram_t * program,int value)1610 static ID_INLINE void R_GLSL_SetUniform_Greyscale(glslProgram_t *program, int value) {
1611 	if (program->v_Greyscale == value)
1612 		return;
1613 
1614 	program->v_Greyscale = value;
1615 	qglUniform1iARB(program->u_Greyscale, value);
1616 }
1617 
R_GLSL_SetUniform_IdentityLight(glslProgram_t * program,float value)1618 static ID_INLINE void R_GLSL_SetUniform_IdentityLight(glslProgram_t *program, float value) {
1619 	if (program->v_IdentityLight == value)
1620 		return;
1621 
1622 	program->v_IdentityLight = value;
1623 	qglUniform1fARB(program->u_IdentityLight, value);
1624 }
1625 
R_GLSL_SetUniform_LightDirection(glslProgram_t * program,const vec3_t value)1626 static ID_INLINE void R_GLSL_SetUniform_LightDirection(glslProgram_t *program, const vec3_t value) {
1627 	if (VectorCompare(program->v_LightDirection, value))
1628 		return;
1629 
1630 	VectorCopy(value, program->v_LightDirection);
1631 	qglUniform3fARB(program->u_LightDirection, value[0], value[1], value[2]);
1632 }
1633 
R_GLSL_SetUniform_ModelViewMatrix(glslProgram_t * program,const float value[16])1634 static ID_INLINE void R_GLSL_SetUniform_ModelViewMatrix(glslProgram_t *program, const float value[16]) {
1635 	if (Matrix4Compare(program->v_ModelViewMatrix, value))
1636 		return;
1637 
1638 	Matrix4Copy(value, program->v_ModelViewMatrix);
1639 	qglUniformMatrix4fvARB(program->u_ModelViewMatrix, 1, GL_FALSE, value);
1640 }
1641 
R_GLSL_SetUniform_ModelViewProjectionMatrix(glslProgram_t * program,const float value[16])1642 static ID_INLINE void R_GLSL_SetUniform_ModelViewProjectionMatrix(glslProgram_t *program, const float value[16]) {
1643 	if (Matrix4Compare(program->v_ModelViewProjectionMatrix, value))
1644 		return;
1645 
1646 	Matrix4Copy(value, program->v_ModelViewProjectionMatrix);
1647 	qglUniformMatrix4fvARB(program->u_ModelViewProjectionMatrix, 1, GL_FALSE, value);
1648 }
1649 
R_GLSL_SetUniform_ProjectionMatrix(glslProgram_t * program,const float value[16])1650 static ID_INLINE void R_GLSL_SetUniform_ProjectionMatrix(glslProgram_t *program, const float value[16]) {
1651 	if (Matrix4Compare(program->v_ProjectionMatrix, value))
1652 		return;
1653 
1654 	Matrix4Copy(value, program->v_ProjectionMatrix);
1655 	qglUniformMatrix4fvARB(program->u_ProjectionMatrix, 1, GL_FALSE, value);
1656 }
1657 
R_GLSL_SetUniform_TCGen0(glslProgram_t * program,texCoordGen_t value)1658 static ID_INLINE void R_GLSL_SetUniform_TCGen0(glslProgram_t *program, texCoordGen_t value) {
1659 	if (program->v_TCGen0 == value)
1660 		return;
1661 
1662 	program->v_TCGen0 = value;
1663 	qglUniform1iARB(program->u_TCGen0, value);
1664 }
1665 
R_GLSL_SetUniform_TCGen1(glslProgram_t * program,texCoordGen_t value)1666 static ID_INLINE void R_GLSL_SetUniform_TCGen1(glslProgram_t *program, texCoordGen_t value) {
1667 	if (program->v_TCGen1 == value)
1668 		return;
1669 
1670 	program->v_TCGen1 = value;
1671 	qglUniform1iARB(program->u_TCGen1, value);
1672 }
1673 
R_GLSL_SetUniform_TexEnv(glslProgram_t * program,int value)1674 static ID_INLINE void R_GLSL_SetUniform_TexEnv(glslProgram_t *program, int value) {
1675 	switch (value) {
1676 		case GL_REPLACE:
1677 			value = 0;
1678 			break;
1679 		case GL_MODULATE:
1680 			value = 1;
1681 			break;
1682 		case GL_DECAL:
1683 			value = 2;
1684 			break;
1685 		case GL_ADD:
1686 			value = 4;
1687 			break;
1688 		default:
1689 			value = -1;
1690 	}
1691 
1692 	if (program->v_TexEnv == value)
1693 		return;
1694 
1695 	program->v_TexEnv = value;
1696 
1697 	qglUniform1iARB(program->u_TexEnv, value);
1698 }
1699 
R_GLSL_SetUniform_Texture0(glslProgram_t * program,GLint value)1700 static ID_INLINE void R_GLSL_SetUniform_Texture0(glslProgram_t *program, GLint value) {
1701 	qglUniform1iARB(program->u_Texture0, value);
1702 }
1703 
R_GLSL_SetUniform_Texture1(glslProgram_t * program,GLint value)1704 static ID_INLINE void R_GLSL_SetUniform_Texture1(glslProgram_t *program, GLint value) {
1705 	qglUniform1iARB(program->u_Texture1, value);
1706 }
1707 
R_GLSL_SetUniform_Texture2(glslProgram_t * program,GLint value)1708 static ID_INLINE void R_GLSL_SetUniform_Texture2(glslProgram_t *program, GLint value) {
1709 	qglUniform1iARB(program->u_Texture2, value);
1710 }
1711 
R_GLSL_SetUniform_Texture3(glslProgram_t * program,GLint value)1712 static ID_INLINE void R_GLSL_SetUniform_Texture3(glslProgram_t *program, GLint value) {
1713 	qglUniform1iARB(program->u_Texture3, value);
1714 }
1715 
R_GLSL_SetUniform_Texture4(glslProgram_t * program,GLint value)1716 static ID_INLINE void R_GLSL_SetUniform_Texture4(glslProgram_t *program, GLint value) {
1717 	qglUniform1iARB(program->u_Texture4, value);
1718 }
1719 
R_GLSL_SetUniform_Texture5(glslProgram_t * program,GLint value)1720 static ID_INLINE void R_GLSL_SetUniform_Texture5(glslProgram_t *program, GLint value) {
1721 	qglUniform1iARB(program->u_Texture5, value);
1722 }
1723 
R_GLSL_SetUniform_Texture6(glslProgram_t * program,GLint value)1724 static ID_INLINE void R_GLSL_SetUniform_Texture6(glslProgram_t *program, GLint value) {
1725 	qglUniform1iARB(program->u_Texture6, value);
1726 }
1727 
R_GLSL_SetUniform_Texture7(glslProgram_t * program,GLint value)1728 static ID_INLINE void R_GLSL_SetUniform_Texture7(glslProgram_t *program, GLint value) {
1729 	qglUniform1iARB(program->u_Texture7, value);
1730 }
1731 
R_GLSL_SetUniform_Time(glslProgram_t * program,float value)1732 static ID_INLINE void R_GLSL_SetUniform_Time(glslProgram_t *program, float value) {
1733 	if (program->v_Time == value)
1734 		return;
1735 
1736 	program->v_Time = value;
1737 	qglUniform1fARB(program->u_Time, value);
1738 }
1739 
R_GLSL_SetUniform_ViewOrigin(glslProgram_t * program,const vec3_t value)1740 static ID_INLINE void R_GLSL_SetUniform_ViewOrigin(glslProgram_t *program, const vec3_t value) {
1741 	if (VectorCompare(program->v_ViewOrigin, value))
1742 		return;
1743 
1744 	VectorCopy(value, program->v_ViewOrigin);
1745 	qglUniform3fARB(program->u_ViewOrigin, value[0], value[1], value[2]);
1746 }
1747 
1748 // Postprocess Vars
R_GLSL_SetUniform_u_ScreenSizeX(glslProgram_t * program,GLint value)1749 static ID_INLINE void R_GLSL_SetUniform_u_ScreenSizeX(glslProgram_t *program, GLint value) {
1750 	qglUniform1iARB(program->u_ScreenSizeX, value);
1751 }
R_GLSL_SetUniform_u_ScreenSizeY(glslProgram_t * program,GLint value)1752 static ID_INLINE void R_GLSL_SetUniform_u_ScreenSizeY(glslProgram_t *program, GLint value) {
1753 	qglUniform1iARB(program->u_ScreenSizeY, value);
1754 }
1755 
R_GLSL_SetUniform_u_ScreenToNextPixelX(glslProgram_t * program,GLfloat value)1756 static ID_INLINE void R_GLSL_SetUniform_u_ScreenToNextPixelX(glslProgram_t *program, GLfloat value) {
1757 	qglUniform1fARB(program->u_ScreenToNextPixelX, value);
1758 }
1759 
R_GLSL_SetUniform_u_ScreenToNextPixelY(glslProgram_t * program,GLfloat value)1760 static ID_INLINE void R_GLSL_SetUniform_u_ScreenToNextPixelY(glslProgram_t *program, GLfloat value) {
1761 	qglUniform1fARB(program->u_ScreenToNextPixelY, value);
1762 }
1763 
R_GLSL_SetUniform_u_zFar(glslProgram_t * program,GLfloat value)1764 static ID_INLINE void R_GLSL_SetUniform_u_zFar(glslProgram_t *program, GLfloat value) {
1765 	qglUniform1fARB(program->u_zFar, value);
1766 }
1767 
1768 
1769 void R_GLSL_Init(void);
1770 qhandle_t RE_GLSL_RegisterProgram(const char *name, const char *programVertexObjects, int numVertexObjects, const char *programFragmentObjects, int numFragmentObjects);
1771 void R_GLSL_UseProgram(qhandle_t index);
1772 void RB_GLSL_StageIteratorGeneric(void);
1773 void RB_GLSL_StageIteratorVertexLitTexture(void);
1774 void RB_GLSL_StageIteratorLightmappedMultitexture(void);
1775 void RB_GLSL_StageIteratorSky(void);
1776 
1777 /*
1778 ============================================================
1779 LIGHTS
1780 
1781 ============================================================
1782 */
1783 
1784 void R_DlightBmodel( bmodel_t *bmodel );
1785 void R_SetupEntityLighting( const trRefdef_t *refdef, trRefEntity_t *ent );
1786 void R_TransformDlights( int count, dlight_t *dl, orientationr_t *or );
1787 int R_LightForPoint( vec3_t point, vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir );
1788 
1789 
1790 /*
1791 ============================================================
1792 
1793 SHADOWS
1794 
1795 ============================================================
1796 */
1797 
1798 void RB_ShadowTessEnd( void );
1799 void RB_ShadowFinish( void );
1800 void RB_ProjectionShadowDeform( void );
1801 
1802 /*
1803 ============================================================
1804 
1805 SKIES
1806 
1807 ============================================================
1808 */
1809 
1810 void R_BuildCloudData( shaderCommands_t *shader );
1811 void R_InitSkyTexCoords( float cloudLayerHeight );
1812 void R_DrawSkyBox( shaderCommands_t *shader );
1813 void RB_DrawSun( void );
1814 void RB_ClipSkyPolygons( shaderCommands_t *shader );
1815 
1816 /*
1817 ============================================================
1818 
1819 CURVE TESSELATION
1820 
1821 ============================================================
1822 */
1823 
1824 #define PATCH_STITCHING
1825 
1826 srfGridMesh_t *R_SubdividePatchToGrid( int width, int height,
1827 								drawVert_t points[MAX_PATCH_SIZE*MAX_PATCH_SIZE] );
1828 srfGridMesh_t *R_GridInsertColumn( srfGridMesh_t *grid, int column, int row, vec3_t point, float loderror );
1829 srfGridMesh_t *R_GridInsertRow( srfGridMesh_t *grid, int row, int column, vec3_t point, float loderror );
1830 void R_FreeSurfaceGridMesh( srfGridMesh_t *grid );
1831 
1832 /*
1833 ============================================================
1834 
1835 MARKERS, POLYGON PROJECTION ON WORLD POLYGONS
1836 
1837 ============================================================
1838 */
1839 
1840 int R_MarkFragments( int numPoints, const vec3_t *points, const vec3_t projection,
1841 				   int maxPoints, vec3_t pointBuffer, int maxFragments, markFragment_t *fragmentBuffer );
1842 
1843 
1844 /*
1845 ============================================================
1846 
1847 SCENE GENERATION
1848 
1849 ============================================================
1850 */
1851 
1852 void R_ToggleSmpFrame( void );
1853 
1854 void RE_ClearScene( void );
1855 void RE_AddRefEntityToScene( const refEntity_t *ent );
1856 void RE_AddPolyToScene( qhandle_t hShader , int numVerts, const polyVert_t *verts, int num );
1857 void RE_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b );
1858 void RE_AddAdditiveLightToScene( const vec3_t org, float intensity, float r, float g, float b );
1859 void RE_RenderScene( const refdef_t *fd );
1860 
1861 #ifdef RAVENMD4
1862 /*
1863 =============================================================
1864 
1865 UNCOMPRESSING BONES
1866 
1867 =============================================================
1868 */
1869 
1870 #define MC_BITS_X (16)
1871 #define MC_BITS_Y (16)
1872 #define MC_BITS_Z (16)
1873 #define MC_BITS_VECT (16)
1874 
1875 #define MC_SCALE_X (1.0f/64)
1876 #define MC_SCALE_Y (1.0f/64)
1877 #define MC_SCALE_Z (1.0f/64)
1878 
1879 void MC_UnCompress(float mat[3][4],const unsigned char * comp);
1880 #endif
1881 
1882 /*
1883 =============================================================
1884 
1885 ANIMATED MODELS
1886 
1887 =============================================================
1888 */
1889 
1890 // void R_MakeAnimModel( model_t *model );      haven't seen this one really, so not needed I guess.
1891 void R_AddAnimSurfaces( trRefEntity_t *ent );
1892 void RB_SurfaceAnim( md4Surface_t *surfType );
1893 #ifdef RAVENMD4
1894 void R_MDRAddAnimSurfaces( trRefEntity_t *ent );
1895 void RB_MDRSurfaceAnim( md4Surface_t *surface );
1896 #endif
1897 
1898 /*
1899 =============================================================
1900 
1901 IMAGE LOADERS
1902 
1903 =============================================================
1904 */
1905 
1906 void R_LoadBMP( const char *name, byte **pic, int *width, int *height );
1907 void R_LoadJPG( const char *name, byte **pic, int *width, int *height );
1908 void R_LoadPCX( const char *name, byte **pic, int *width, int *height );
1909 void R_LoadPNG( const char *name, byte **pic, int *width, int *height );
1910 void R_LoadTGA( const char *name, byte **pic, int *width, int *height );
1911 
1912 /*
1913 =============================================================
1914 =============================================================
1915 */
1916 void	R_TransformModelToClip( const vec3_t src, const float *modelMatrix, const float *projectionMatrix,
1917 							vec4_t eye, vec4_t dst );
1918 void	R_TransformClipToWindow( const vec4_t clip, const viewParms_t *view, vec4_t normalized, vec4_t window );
1919 
1920 void	RB_DeformTessGeometry( void );
1921 
1922 void	RB_CalcEnvironmentTexCoords( float *dstTexCoords );
1923 void	RB_CalcEnvironmentCelShadeTexCoords( float *dstTexCoords );
1924 void	RB_CalcEnvironmentTexCoordsNew( float *dstTexCoords );
1925 void	RB_CalcEnvironmentTexCoordsHW(void);
1926 void	RB_CalcFogTexCoords( float *dstTexCoords );
1927 void	RB_CalcScrollTexCoords( const float scroll[2], float *dstTexCoords );
1928 void	RB_CalcRotateTexCoords( float rotSpeed, float *dstTexCoords );
1929 void	RB_CalcScaleTexCoords( const float scale[2], float *dstTexCoords );
1930 void	RB_CalcTurbulentTexCoords( const waveForm_t *wf, float *dstTexCoords );
1931 void	RB_CalcTransformTexCoords( const texModInfo_t *tmi, float *dstTexCoords );
1932 void	RB_CalcModulateColorsByFog( unsigned char *dstColors );
1933 void	RB_CalcModulateAlphasByFog( unsigned char *dstColors );
1934 void	RB_CalcModulateRGBAsByFog( unsigned char *dstColors );
1935 void	RB_CalcWaveAlpha( const waveForm_t *wf, unsigned char *dstColors );
1936 void	RB_CalcWaveColor( const waveForm_t *wf, unsigned char *dstColors );
1937 void	RB_CalcAlphaFromEntity( unsigned char *dstColors );
1938 void	RB_CalcAlphaFromOneMinusEntity( unsigned char *dstColors );
1939 void	RB_CalcStretchTexCoords( const waveForm_t *wf, float *texCoords );
1940 void	RB_CalcColorFromEntity( unsigned char *dstColors );
1941 void	RB_CalcColorFromOneMinusEntity( unsigned char *dstColors );
1942 void	RB_CalcSpecularAlpha( unsigned char *alphas );
1943 void	RB_CalcSpecularAlphaNew( unsigned char *alphas );
1944 void	RB_CalcDiffuseColor( unsigned char *colors );
1945 void	RB_CalcUniformColor( unsigned char *colors );
1946 void	RB_CalcDynamicColor( unsigned char *colors );
1947 
1948 /*
1949 =============================================================
1950 
1951 RENDERER BACK END FUNCTIONS
1952 
1953 =============================================================
1954 */
1955 
1956 void RB_RenderThread( void );
1957 void RB_ExecuteRenderCommands( const void *data );
1958 
1959 /*
1960 =============================================================
1961 
1962 RENDERER BACK END COMMAND QUEUE
1963 
1964 =============================================================
1965 */
1966 
1967 #define	MAX_RENDER_COMMANDS	0x40000
1968 
1969 typedef struct {
1970 	byte	cmds[MAX_RENDER_COMMANDS];
1971 	int		used;
1972 } renderCommandList_t;
1973 
1974 typedef struct {
1975 	int		commandId;
1976 	float	color[4];
1977 } setColorCommand_t;
1978 
1979 typedef struct {
1980 	int		commandId;
1981 	int		buffer;
1982 } drawBufferCommand_t;
1983 
1984 typedef struct {
1985 	int		commandId;
1986 	image_t	*image;
1987 	int		width;
1988 	int		height;
1989 	void	*data;
1990 } subImageCommand_t;
1991 
1992 typedef struct {
1993 	int		commandId;
1994 } swapBuffersCommand_t;
1995 
1996 typedef struct {
1997 	int		commandId;
1998 	int		buffer;
1999 } endFrameCommand_t;
2000 
2001 typedef struct {
2002 	int		commandId;
2003 	shader_t	*shader;
2004 	float	x, y;
2005 	float	w, h;
2006 	float	s1, t1;
2007 	float	s2, t2;
2008 } stretchPicCommand_t;
2009 
2010 typedef struct {
2011 	int		commandId;
2012 	trRefdef_t	refdef;
2013 	viewParms_t	viewParms;
2014 	drawSurf_t *drawSurfs;
2015 	int		numDrawSurfs;
2016 } drawSurfsCommand_t;
2017 
2018 typedef struct {
2019 	int commandId;
2020 	int x;
2021 	int y;
2022 	int width;
2023 	int height;
2024 	char *fileName;
2025 	qboolean jpeg;
2026 } screenshotCommand_t;
2027 
2028 typedef struct {
2029 	int						commandId;
2030 	int						width;
2031 	int						height;
2032 	byte					*captureBuffer;
2033 	byte					*encodeBuffer;
2034 	qboolean			motionJpeg;
2035 } videoFrameCommand_t;
2036 
2037 typedef struct
2038 {
2039 	int commandId;
2040 
2041 	GLboolean rgba[4];
2042 } colorMaskCommand_t;
2043 
2044 typedef struct
2045 {
2046 	int commandId;
2047 } clearDepthCommand_t;
2048 
2049 typedef enum {
2050 	RC_END_OF_LIST,
2051 	RC_SET_COLOR,
2052 	RC_STRETCH_PIC,
2053 	RC_DRAW_SURFS,
2054 	RC_DRAW_BUFFER,
2055 	RC_SWAP_BUFFERS,
2056 	RC_SCREENSHOT,
2057 	RC_VIDEOFRAME,
2058 	RC_COLORMASK,
2059 	RC_CLEARDEPTH
2060 } renderCommand_t;
2061 
2062 
2063 // these are sort of arbitrary limits.
2064 // the limits apply to the sum of all scenes in a frame --
2065 // the main view, all the 3D icons, etc
2066 #define	MAX_POLYS		600
2067 #define	MAX_POLYVERTS	3000
2068 
2069 // all of the information needed by the back end must be
2070 // contained in a backEndData_t.  This entire structure is
2071 // duplicated so the front and back end can run in parallel
2072 // on an SMP machine
2073 typedef struct {
2074 	drawSurf_t	drawSurfs[MAX_DRAWSURFS];
2075 	dlight_t	dlights[MAX_DLIGHTS];
2076 	trRefEntity_t	entities[MAX_ENTITIES];
2077 	srfPoly_t	*polys;//[MAX_POLYS];
2078 	polyVert_t	*polyVerts;//[MAX_POLYVERTS];
2079 	renderCommandList_t	commands;
2080 } backEndData_t;
2081 
2082 extern	int		max_polys;
2083 extern	int		max_polyverts;
2084 
2085 extern	backEndData_t	*backEndData[SMP_FRAMES];	// the second one may not be allocated
2086 
2087 extern	volatile renderCommandList_t	*renderCommandList;
2088 
2089 extern	volatile qboolean	renderThreadActive;
2090 
2091 
2092 void *R_GetCommandBuffer( int bytes );
2093 void RB_ExecuteRenderCommands( const void *data );
2094 
2095 void R_InitCommandBuffers( void );
2096 void R_ShutdownCommandBuffers( void );
2097 
2098 void R_SyncRenderThread( void );
2099 
2100 void R_AddDrawSurfCmd( drawSurf_t *drawSurfs, int numDrawSurfs );
2101 
2102 void RE_SetColor( const float *rgba );
2103 void RE_StretchPic ( float x, float y, float w, float h,
2104 					  float s1, float t1, float s2, float t2, qhandle_t hShader );
2105 void RE_BeginFrame( stereoFrame_t stereoFrame );
2106 void RE_EndFrame( int *frontEndMsec, int *backEndMsec );
2107 void SaveJPG(char * filename, int quality, int image_width, int image_height, unsigned char *image_buffer);
2108 int SaveJPGToBuffer( byte *buffer, int quality,
2109 		int image_width, int image_height,
2110 		byte *image_buffer );
2111 void RE_TakeVideoFrame( int width, int height,
2112 		byte *captureBuffer, byte *encodeBuffer, qboolean motionJpeg );
2113 
2114 // font stuff
2115 void R_InitFreeType( void );
2116 void R_DoneFreeType( void );
2117 void RE_RegisterFont(const char *fontName, int pointSize, fontInfo_t *font);
2118 
2119 //Bloom Stuff
2120 void R_BloomInit( void );
2121 void R_BloomScreen( void );
2122 
2123 // Postprocessing
2124 void R_PostprocessScreen( void );
2125 void R_PostprocessingInit(void);
2126 
2127 #endif //TR_LOCAL_H
2128