OpenMoHAA 0.83.0
Loading...
Searching...
No Matches
tr_local.h
1/*
2===========================================================================
3Copyright (C) 1999-2005 Id Software, Inc.
4
5This file is part of Quake III Arena source code.
6
7Quake III Arena source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12Quake III Arena source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with Foobar; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23#pragma once
24
25#include "../qcommon/q_shared.h"
26#include "../qcommon/qfiles.h"
27#include "../qcommon/qcommon.h"
28#include "tr_public.h"
29#include "../renderercommon/qgl.h"
30#include "../renderercommon/tr_common.h"
31#include "qgl.h"
32
33#ifdef __cplusplus
34#define GLE(ret, name, ...) extern "C" name##proc * qgl##name;
35#else
36#define GLE(ret, name, ...) extern name##proc * qgl##name;
37#endif
38
39QGL_1_1_PROCS;
40QGL_1_1_FIXED_FUNCTION_PROCS;
41QGL_1_3_PROCS;
42QGL_DESKTOP_1_1_PROCS;
43QGL_DESKTOP_1_1_FIXED_FUNCTION_PROCS;
44QGL_3_0_PROCS;
45
46#undef GLE
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52#define GL_INDEX_TYPE GL_UNSIGNED_INT
53typedef unsigned int glIndex_t;
54
55// fast float to int conversion
56#if id386 && !( (defined __linux__ || defined __FreeBSD__ ) && (defined __i386__ ) ) // rb010123
57long myftol( float f );
58#else
59#define myftol(x) ((int)(x))
60#endif
61
62
63// everything that is needed by the backend needs
64// to be double buffered to allow it to run in
65// parallel on a dual cpu machine
66#define SMP_FRAMES 2
67
68// 12 bits
69// see QSORT_SHADERNUM_SHIFT
70#define MAX_SHADERS 16384
71
72//#define MAX_SHADER_STATES 2048
73#define MAX_STATES_PER_SHADER 32
74#define MAX_STATE_NAME 32
75
76// can't be increased without changing bit packing for drawsurfs
77
78typedef struct skelSurfaceGame_s skelSurfaceGame_t;
79typedef struct staticSurface_s staticSurface_t;
80
81// any changes in surfaceType must be mirrored in rb_surfaceTable[]
82typedef enum {
83 SF_BAD,
84 SF_SKIP, // ignore
85 SF_FACE,
86 SF_GRID,
87 SF_POLY,
88 SF_MARK_FRAG,
89 SF_FLARE,
90 SF_ENTITY, // beams, rails, lightning, etc that can be determined by entity
91 SF_DISPLAY_LIST,
92 SF_TIKI_SKEL,
93 SF_TIKI_STATIC,
94 SF_SWIPE,
95 SF_SPRITE,
96 SF_TERRAIN_PATCH,
97 SF_TRIANGLES,
98 SF_MD3,
99 SF_MD4,
100
101 SF_NUM_SURFACE_TYPES,
102 SF_MAX = 0x7fffffff // ensures that sizeof( surfaceType_t ) == sizeof( int )
103} surfaceType_t;
104
105typedef struct {
106 struct mnode_s* cntNode;
107 struct msurface_s* skySurfs[32];
108 int numSurfs;
109 vec3_t offset;
110 vec3_t mins;
111 vec3_t maxs;
113
114typedef struct {
115 vec3_t transformed;
116 int index;
118
119typedef enum {
120 LIGHT_POINT,
121 LIGHT_DIRECTIONAL,
122 LIGHT_SPOT,
123 LIGHT_SPOT_FAST
124} lighttype_t;
125
126typedef struct reallightinfo_s {
127 vec3_t color;
128 lighttype_t eType;
129 float fIntensity;
130 float fDist;
131 float fSpotSlope;
132 float fSpotConst;
133 float fSpotScale;
134 vec3_t vOrigin;
135 vec3_t vDirection;
136} reallightinfo_t;
137
138typedef float cube_entry_t[3][4];
139
140typedef struct {
141 vec3_t origin;
142 vec3_t worldOrigin;
143 vec3_t traceOrigin;
144 float radius;
145 struct mnode_s* leaves[8];
146 void(*TessFunction) (unsigned char* dstColors);
147 union {
148 unsigned char level[4];
149 int value;
150 } ambient;
151 int numRealLights;
152 reallightinfo_t light[MAX_REAL_LIGHTS];
153 int bUsesCubeMap;
154 float cubemap[24][3][4];
155} sphereor_t;
156
157typedef struct spherel_s {
158 vec3_t origin;
159 vec3_t color;
160 float intensity;
161 struct mnode_s* leaf;
162 int needs_trace;
163 int spot_light;
164 float spot_radiusbydistance;
165 vec3_t spot_dir;
166 int reference_count;
167} spherel_t;
168
169typedef struct dlight_s {
170 vec3_t origin;
171 vec3_t color; // range from 0.0 to 1.0, should be color normalized
172 float radius;
173
174 dlighttype_t type;
175 vec3_t transformed; // origin in local coordinate system
176} dlight_t;
177
178
179// a trRefEntity_t has all the information passed in by
180// the client game, as well as some locally derived info
181typedef struct {
182 refEntity_t e;
183
184 float axisLength; // compensate for non-normalized axis
185
186 qboolean needDlights; // true for bmodels that touch a dlight
187 qboolean bLightGridCalculated;
188 int iGridLighting;
189 float lodpercentage[2];
190 qboolean sphereCalculated;
191 int lightingSphere;
192
193 //
194 // old lighting variables
195 //
196 vec3_t lightDir; // normalized direction towards light
197 vec3_t ambientLight; // color normalized to 0-255
198 int ambientLightInt; // 32 bit rgba packed
199 vec3_t directedLight;
201
202typedef struct refSprite_s {
203 surfaceType_t surftype;
204 int hModel;
205 int shaderNum;
206 float origin[3];
207 float scale;
208 float axis[3][3];
209 unsigned char shaderRGBA[4];
210 int renderfx;
211 float shaderTime;
212} refSprite_t;
213
214typedef struct {
215 vec3_t origin; // in world coordinates
216 vec3_t axis[3]; // orientation in world
217 vec3_t viewOrigin; // viewParms->or.origin in local coordinates
218 float modelMatrix[16];
220
221/*
222typedef struct image_s {
223 char imgName[MAX_QPATH]; // game path, including extension
224 int width, height; // source image
225 int uploadWidth, uploadHeight; // after power of two and picmip but not including clamp to MAX_TEXTURE_SIZE
226 GLuint texnum; // gl texture binding
227
228 int frameUsed; // for texture usage in frame statistics
229 int bytesUsed;
230
231 int internalFormat;
232 int TMU; // only needed for voodoo2
233 int numMipmaps;
234
235 qboolean dynamicallyUpdated;
236 qboolean allowPicmip;
237 qboolean force32bit;
238 int wrapClampModeX;
239 int wrapClampModeY;
240 int r_sequence;
241 int UseCount;
242
243 struct image_s* next;
244} image_t;
245*/
246
247//===============================================================================
248
249typedef enum {
250 SS_BAD,
251 SS_PORTAL, // mirrors, portals, viewscreens
252 SS_PORTALSKY,
253 SS_ENVIRONMENT, // sky box
254 SS_OPAQUE, // opaque
255
256 SS_DECAL, // scorch marks, etc.
257 SS_SEE_THROUGH, // ladders, grates, grills that may have small blended edges
258 // in addition to alpha test
259 SS_BANNER,
260
261 SS_UNDERWATER, // for items that should be drawn in front of the water plane
262
263 SS_BLEND0, // regular transparency and filters
264 SS_BLEND1, // generally only used for additive type effects
265 SS_BLEND2,
266 SS_BLEND3,
267
268 SS_BLEND6,
269 SS_STENCIL_SHADOW,
270 SS_ALMOST_NEAREST, // gun smoke puffs
271
272 SS_NEAREST // blood blobs
273} shaderSort_t;
274
275
276#define MAX_SHADER_STAGES 8
277
278typedef enum {
279 GF_NONE,
280
281 GF_SIN,
282 GF_SQUARE,
283 GF_TRIANGLE,
284 GF_SAWTOOTH,
285 GF_INVERSE_SAWTOOTH,
286
287 GF_NOISE
288
289} genFunc_t;
290
291typedef enum {
292 USE_S_COORDS,
293 USE_T_COORDS
294} texDirection_t;
295
296typedef enum {
297 DEFORM_NONE,
298 DEFORM_WAVE,
299 DEFORM_NORMALS,
300 DEFORM_BULGE,
301 DEFORM_MOVE,
302 DEFORM_AUTOSPRITE,
303 DEFORM_AUTOSPRITE2,
304 DEFORM_LIGHTGLOW,
305 DEFORM_FLAP_S,
306 DEFORM_FLAP_T
307} deform_t;
308
309typedef enum {
310 AGEN_IDENTITY,
311 AGEN_SKIP,
312 AGEN_ENTITY,
313 AGEN_ONE_MINUS_ENTITY,
314 AGEN_VERTEX,
315 AGEN_ONE_MINUS_VERTEX,
316 AGEN_LIGHTING_SPECULAR,
317 AGEN_WAVEFORM,
318 AGEN_PORTAL,
319 AGEN_NOISE,
320 AGEN_DOT,
321 AGEN_ONE_MINUS_DOT,
322 AGEN_CONSTANT,
323 AGEN_GLOBAL_ALPHA,
324 AGEN_SKYALPHA,
325 AGEN_ONE_MINUS_SKYALPHA,
326 AGEN_SCOORD,
327 AGEN_TCOORD,
328 AGEN_DIST_FADE,
329 AGEN_ONE_MINUS_DIST_FADE,
330 AGEN_TIKI_DIST_FADE,
331 AGEN_ONE_MINUS_TIKI_DIST_FADE,
332 AGEN_DOT_VIEW,
333 AGEN_ONE_MINUS_DOT_VIEW,
334 AGEN_HEIGHT_FADE,
335} alphaGen_t;
336
337typedef enum {
338 CGEN_BAD,
339 CGEN_IDENTITY_LIGHTING, // tr.identityLight
340 CGEN_IDENTITY, // always (1,1,1,1)
341 CGEN_ENTITY, // grabbed from entity's modulate field
342 CGEN_ONE_MINUS_ENTITY, // grabbed from 1 - entity.modulate
343 CGEN_EXACT_VERTEX, // tess.vertexColors
344 CGEN_VERTEX, // tess.vertexColors * tr.identityLight
345 CGEN_ONE_MINUS_VERTEX,
346 CGEN_WAVEFORM, // programmatically generated
347 CGEN_MULTIPLY_BY_WAVEFORM,
348 CGEN_LIGHTING_GRID,
349 CGEN_LIGHTING_SPHERICAL,
350 CGEN_CONSTANT,
351 CGEN_NOISE,
352 CGEN_GLOBAL_COLOR,
353 CGEN_STATIC,
354 CGEN_SCOORD,
355 CGEN_TCOORD,
356 CGEN_DOT,
357 CGEN_ONE_MINUS_DOT
358} colorGen_t;
359
360typedef enum {
361 TCGEN_BAD,
362 TCGEN_IDENTITY, // clear to 0,0
363 TCGEN_LIGHTMAP,
364 TCGEN_TEXTURE,
365 TCGEN_ENVIRONMENT_MAPPED,
366 TCGEN_VECTOR, // S and T from world coordinates
367 TCGEN_ENVIRONMENT_MAPPED2,
368 TCGEN_SUN_REFLECTION,
369 TCGEN_FOG
370} texCoordGen_t;
371
372typedef enum {
373 ACFF_NONE,
374 ACFF_MODULATE_RGB,
375 ACFF_MODULATE_RGBA,
376 ACFF_MODULATE_ALPHA
377} acff_t;
378
379typedef struct {
380 genFunc_t func;
381
382 float base;
383 float amplitude;
384 float phase;
385 float frequency;
386} waveForm_t;
387
388#define TR_MAX_TEXMODS 4
389
390typedef enum {
391 TMOD_NONE,
392 TMOD_TRANSFORM,
393 TMOD_TURBULENT,
394 TMOD_SCROLL,
395 TMOD_SCALE,
396 TMOD_STRETCH,
397 TMOD_ROTATE,
398 TMOD_ENTITY_TRANSLATE,
399 TMOD_NOISE,
400 TMOD_OFFSET,
401 TMOD_PARALLAX,
402 TMOD_MACRO,
403 TMOD_WAVETRANS,
404 TMOD_WAVETRANT,
405 TMOD_BULGETRANS
406} texMod_t;
407
408#define MAX_SHADER_DEFORMS 3
409typedef struct {
410 deform_t deformation; // vertex coordinate modification type
411
412 vec3_t moveVector;
413 waveForm_t deformationWave;
414 float deformationSpread;
415
416 float bulgeWidth;
417 float bulgeHeight;
418 float bulgeSpeed;
420
421
422typedef struct {
423 texMod_t type;
424
425 // used for TMOD_TURBULENT and TMOD_STRETCH
426 waveForm_t wave;
427
428 // used for TMOD_TRANSFORM
429 float matrix[2][2]; // s' = s * m[0][0] + t * m[1][0] + trans[0]
430 float translate[2]; // t' = s * m[0][1] + t * m[0][1] + trans[1]
431
432 // used for TMOD_SCALE
433 float scale[2]; // s *= scale[0]
434 // t *= scale[1]
435
436 // used for TMOD_PARALLAX
437 float rate[2];
438
439 // used for TMOD_SCROLL
440 float scroll[2]; // s' = s + scroll[0] * time
441 // t' = t + scroll[1] * time
442
443 // + = clockwise
444 // - = counterclockwise
445 float rotateSpeed;
446 float rotateStart;
447 float rotateCoef;
448
450
451
452#define MAX_IMAGE_ANIMATIONS 64
453#define BUNDLE_ANIMATE_ONCE 1
454
455typedef struct {
456 image_t *image[MAX_IMAGE_ANIMATIONS];
457 int numImageAnimations;
458 float imageAnimationSpeed;
459 float imageAnimationPhase;
460
461 texCoordGen_t tcGen;
462 vec3_t tcGenVectors[2];
463
464 int numTexMods;
465 texModInfo_t *texMods;
466
467 int videoMapHandle;
468 qboolean isLightmap;
469 qboolean vertexLightmap;
470 qboolean isVideoMap;
471 int flags;
473
474#define NUM_TEXTURE_BUNDLES 2
475
476typedef struct {
477 qboolean active;
478 qboolean hasNormalMap;
479
480 textureBundle_t bundle[NUM_TEXTURE_BUNDLES];
481 image_t *normalMap;
482 int multitextureEnv; // 0, GL_MODULATE, GL_ADD (FIXME: put in stage)
483
484 waveForm_t rgbWave;
485 colorGen_t rgbGen;
486
487 waveForm_t alphaWave;
488 alphaGen_t alphaGen;
489
490 unsigned stateBits; // GLS_xxxx mask
491
492
493 qboolean noMipMaps;
494 qboolean noPicMip;
495 qboolean force32bit;
496
497 float alphaMin;
498 float alphaMax;
499 vec3_t specOrigin;
500
501 byte colorConst[4]; // for CGEN_CONST and AGEN_CONST
502 byte alphaConst;
503 byte alphaConstMin;
505
506struct shaderCommands_s;
507
508#define LIGHTMAP_2D -4 // shader is for 2D rendering
509#define LIGHTMAP_BY_VERTEX -3 // pre-lit triangle models
510#define LIGHTMAP_WHITEIMAGE -2
511#define LIGHTMAP_NONE -1
512
513typedef enum {
514 CT_FRONT_SIDED,
515 CT_BACK_SIDED,
516 CT_TWO_SIDED
517} cullType_t;
518
519typedef enum {
520 FP_NONE, // surface is translucent and will just be adjusted properly
521 FP_EQUAL, // surface is opaque but possibly alpha tested
522 FP_LE // surface is trnaslucent, but still needs a fog pass (fog surface)
523} fogPass_t;
524
525typedef struct {
526 float cloudHeight;
527 image_t *outerbox[6], *innerbox[6];
528} skyParms_t;
529
530typedef enum {
531 SPRITE_PARALLEL,
532 SPRITE_PARALLEL_ORIENTED,
533 SPRITE_ORIENTED,
534 SPRITE_PARALLEL_UPRIGHT
535} spriteType_t;
536
537typedef struct {
538 spriteType_t type;
539 float scale;
541
542typedef struct {
543 vec3_t color;
544 float depthForOpaque;
545} fogParms_t;
546
547
548typedef struct shader_s {
549 char name[MAX_QPATH]; // game path, including extension
550 int lightmapIndex; // for a shader to match, both name and lightmapIndex must match
551
552 int index; // this shader == tr.shaders[index]
553 int sortedIndex; // this shader == tr.sortedShaders[sortedIndex]
554
555 float sort; // lower numbered shaders draw before higher numbered
556
557 qboolean defaultShader; // we want to return index 0 if the shader failed to
558 // load for some reason, but R_FindShader should
559 // still keep a name allocated for it, so if
560 // something calls RE_RegisterShader again with
561 // the same name, we don't try looking for it again
562
563 qboolean explicitlyDefined; // found in a .shader file
564
565 int surfaceFlags; // if explicitlyDefined, this will have SURF_* flags
566 int contentFlags;
567
568 qboolean entityMergable; // merge across entites optimizable (smoke, blood)
569
570 qboolean isSky;
571 skyParms_t sky;
572 spriteParms_t sprite;
573 qboolean isPortalSky;
574 float subdivisions;
575 float fDistRange;
576 float fDistNear;
577 fogParms_t fogParms;
578
579 float portalRange; // distance to fog out at
580
581 cullType_t cullType; // CT_FRONT_SIDED, CT_BACK_SIDED, or CT_TWO_SIDED
582 qboolean polygonOffset; // set for decals and other items that must be offset
583 qboolean noMipMaps; // for console fonts, 2D elements, etc.
584 qboolean noPicMip; // for images that must always be full resolution
585
586 fogPass_t fogPass; // draw a blended pass, possibly with depth test equals
587
588 qboolean needsNormal; // not all shaders will need all data to be gathered
589 qboolean needsST1;
590 qboolean needsST2;
591 qboolean needsColor;
592
593 int numDeforms;
594 deformStage_t deforms[MAX_SHADER_DEFORMS];
595
596 int numUnfoggedPasses;
597 shaderStage_t * unfoggedStages[MAX_SHADER_STAGES];
598
599 int needsLGrid;
600 int needsLSpherical;
601 int stagesWithAlphaFog;
602 int flags;
603
604 void (*optimalStageIteratorFunc)( void );
605
606 float clampTime; // time this shader is clamped to
607 float timeOffset; // current time offset for this shader
608
609 int numStates; // if non-zero this is a state shader
610 struct shader_s *currentShader; // current state if this is a state shader
611 struct shader_s *parentShader; // current state if this is a state shader
612 int currentState; // current state index for cycle purposes
613 long expireTime; // time in milliseconds this expires
614
615 struct shader_s *remappedShader; // current shader this one is remapped too
616
617 int shaderStates[MAX_STATES_PER_SHADER]; // index to valid shader states
618
619 struct shader_s *next;
620} shader_t;
621
622typedef struct shaderState_s {
623 char shaderName[MAX_QPATH]; // name of shader this state belongs to
624 char name[MAX_STATE_NAME]; // name of this state
625 char stateShader[MAX_QPATH]; // shader this name invokes
626 int cycleTime; // time this cycle lasts, <= 0 is forever
627 shader_t *shader;
628} shaderState_t;
629
630
631// trRefdef_t holds everything that comes in refdef_t,
632// as well as the locally generated scene information
633typedef struct {
634 int x, y, width, height;
635 float fov_x, fov_y;
636 vec3_t vieworg;
637 vec3_t viewaxis[3]; // transformation matrix
638
639 stereoFrame_t stereoFrame;
640
641 int time; // time in milliseconds for shader effects and other time dependent rendering issues
642 int rdflags; // RDF_NOWORLDMODEL, etc
643
644 // 1 bits will prevent the associated area from rendering at all
645 byte areamask[MAX_MAP_AREA_BYTES];
646 qboolean areamaskModified; // qtrue if areamask changed since last scene
647
648 float floatTime; // tr.refdef.time / 1000.0
649
650 // text messages for deform text shaders
651 char text[MAX_RENDER_STRINGS][MAX_RENDER_STRING_LENGTH];
652
653 int num_entities;
654 trRefEntity_t *entities;
655
656 int num_sprites;
657 refSprite_t *sprites;
658
659 int num_dlights;
660 struct dlight_s *dlights;
661
662 int numTerMarks;
663 struct srfMarkFragment_s *terMarks;
664
665 int numPolys;
666 struct srfPoly_s *polys;
667
668 int numDrawSurfs;
669 struct drawSurf_s *drawSurfs;
670
671 int numSpriteSurfs;
672 struct drawSurf_s *spriteSurfs;
673
674 int numStaticModels;
675 struct cStaticModelUnpacked_s *staticModels;
676
677 int numStaticModelData;
678 unsigned char *staticModelData;
679 qboolean sky_portal;
680 float sky_alpha;
681 vec3_t sky_origin;
682 vec3_t sky_axis[3];
683 // added in 2.0
684 //==
685 qboolean skybox_farplane;
686 qboolean render_terrain;
687 //==
688
689} trRefdef_t;
690
691
692//=================================================================================
693
694// skins allow models to be retextured without modifying the model file
695typedef struct {
696 char name[MAX_QPATH];
697 shader_t *shader;
699
700typedef struct skin_s {
701 char name[MAX_QPATH]; // game path, including extension
702 int numSurfaces;
703 skinSurface_t *surfaces[MD3_MAX_SURFACES];
704} skin_t;
705
706
707typedef struct {
708 int originalBrushNumber;
709 vec3_t bounds[2];
710
711 unsigned colorInt; // in packed byte format
712 float tcScale; // texture coordinate vector scales
713 fogParms_t parms;
714
715 // for clipping distance in fog when outside
716 qboolean hasSurface;
717 float surface[4];
718} fog_t;
719
720typedef struct depthfog_s {
721 float len;
722 float oolen;
723 int enabled;
724 int extrafrustums;
725} depthfog_t;
726
727// Doesn't cull anything
728#define FARPLANE_CULL_NONE 0
729// Cull outside the maximum distance
730#define FARPLANE_CULL_STANDARD 1
731// Cull outside the maximum distance ONLY if the view is a portal sky
732#define FARPLANE_CULL_PORTALSKY 2
733
734typedef struct {
735 orientationr_t ori;
736 orientationr_t world;
737 vec3_t pvsOrigin; // may be different than or.origin for portals
738 qboolean isPortal; // true if this view is through a portal
739 qboolean isMirror; // the portal is a mirror, invert the face culling
740 qboolean isPortalSky; // since 2.0 whether or not this view is a portal sky
741 int frameSceneNum; // copied from tr.frameSceneNum
742 int frameCount; // copied from tr.frameCount
743 cplane_t portalPlane; // clip anything behind this if mirroring
744 int viewportX, viewportY, viewportWidth, viewportHeight;
745 float fovX, fovY;
746 float projectionMatrix[16];
747 cplane_t frustum[5];
748 vec3_t visBounds[2];
749 float zFar;
750 depthfog_t fog;
751 float farplane_distance;
752 float farplane_bias; // added in 2.0
753 float farplane_color[3];
754 int farplane_cull;
755 qboolean renderTerrain; // added in 2.0
757
758
759/*
760==============================================================================
761
762SURFACES
763
764==============================================================================
765*/
766
767typedef struct drawSurf_s {
768 unsigned sort; // bit combination for fast compares
769 surfaceType_t *surface; // any of surface*_t
770} drawSurf_t;
771
772#define MAX_FACE_POINTS 64
773
774#define MAX_PATCH_SIZE 32 // max dimensions of a patch mesh in map file
775#define MAX_GRID_SIZE 65 // max dimensions of a grid mesh in memory
776
777// when cgame directly specifies a polygon, it becomes a srfPoly_t
778// as soon as it is called
779typedef struct srfPoly_s {
780 surfaceType_t surfaceType;
781 qhandle_t hShader;
782 int numVerts;
783 polyVert_t *verts;
784 int renderfx;
785} srfPoly_t;
786
787typedef struct srfMarkFragment_s {
788 surfaceType_t surfaceType;
789 int iIndex;
790 int numVerts;
791 polyVert_t* verts;
792} srfMarkFragment_t;
793
794typedef struct srfDisplayList_s {
795 surfaceType_t surfaceType;
796 int listNum;
797} srfDisplayList_t;
798
799
800typedef struct srfFlare_s {
801 surfaceType_t surfaceType;
802 vec3_t origin;
803 vec3_t normal;
804 vec3_t color;
805} srfFlare_t;
806
807typedef struct srfGridMesh_s {
808 surfaceType_t surfaceType;
809
810 // dynamic lighting information
811 int dlightBits[SMP_FRAMES];
812 int dlightMap[SMP_FRAMES];
813
814 // culling information
815 vec3_t meshBounds[2];
816 vec3_t localOrigin;
817 float meshRadius;
818
819 // lightmap data
820 float lightmapOffset[2];
821 int lmX;
822 int lmY;
823 int lmWidth;
824 int lmHeight;
825 unsigned char *lmData;
826
827 // lod information, which may be different
828 // than the culling information to allow for
829 // groups of curves that LOD as a unit
830 vec3_t lodOrigin;
831 float lodRadius;
832 int lodFixed;
833 int lodStitched;
834
835 // vertexes
836 int width, height;
837 float *widthLodError;
838 float *heightLodError;
839 drawVert_t verts[1]; // variable sized
840} srfGridMesh_t;
841
842
843
844#define VERTEXSIZE 8
845typedef struct {
846 surfaceType_t surfaceType;
847 cplane_t plane;
848
849 // dynamic lighting information
850 int dlightBits[SMP_FRAMES];
851 int dlightMap[SMP_FRAMES];
852 float lightmapOffset[2];
853 int lmWidth;
854 int lmHeight;
855 int lmX;
856 int lmY;
857 byte* lmData;
858 vec3_t lmOrigin;
859 vec3_t lmVecs[2];
860 vec3_t lmInverseVecs[2];
861
862 // triangle definitions (no normals at points)
863 int numPoints;
864 int numIndices;
865 int ofsIndices;
866 float points[1][VERTEXSIZE]; // variable sized
867 // there is a variable length list of indices here also
869
870
871// misc_models in maps are turned into direct geometry by q3map
872typedef struct {
873 surfaceType_t surfaceType;
874
875 // dynamic lighting information
876 int dlightBits[SMP_FRAMES];
877
878 // culling information (FIXME: use this!)
879 vec3_t bounds[2];
880 vec3_t localOrigin;
881 float radius;
882
883 // triangle definitions
884 int numIndexes;
885 int *indexes;
886
887 int numVerts;
888 drawVert_t *verts;
890
891typedef union varnodeUnpacked_u {
892 float fVariance;
893 int flags;
894 /*
895 struct {
896#if !Q3_BIG_ENDIAN
897 byte flags;
898 unsigned char unused[3];
899#else
900 unsigned char unused[3];
901 byte flags;
902#endif
903 } s;
904 */
905} varnodeUnpacked_t;
906
907typedef unsigned short terraInt;
908
909typedef struct terrainVert_s {
910 vec3_t xyz;
911 vec2_t texCoords[2];
912 float fVariance;
913 float fHgtAvg;
914 float fHgtAdd;
915 unsigned int uiDistRecalc;
916 terraInt nRef;
917 terraInt iVertArray;
918 byte* pHgt;
919 terraInt iNext;
920 terraInt iPrev;
922
923typedef struct terraTri_s {
924 unsigned short iPt[3];
925 terraInt nSplit;
926 unsigned int uiDistRecalc;
927 struct cTerraPatchUnpacked_s* patch;
928 varnodeUnpacked_t* varnode;
929 terraInt index;
930 byte lod;
931 byte byConstChecks;
932 terraInt iLeft;
933 terraInt iRight;
934 terraInt iBase;
935 terraInt iLeftChild;
936 terraInt iRightChild;
937 terraInt iParent;
938 terraInt iPrev;
939 terraInt iNext;
940} terraTri_t;
941
942typedef struct srfTerrain_s {
943 surfaceType_t surfaceType;
944 terraInt iVertHead;
945 terraInt iTriHead;
946 terraInt iTriTail;
947 terraInt iMergeHead;
948 int nVerts;
949 int nTris;
950 int lmapSize;
951 int dlightBits[2];
952 float lmapStep;
953 int dlightMap[2];
954 byte* lmData;
955 float lmapX;
956 float lmapY;
957} srfTerrain_t;
958
959typedef struct cTerraPatchUnpacked_s {
960 srfTerrain_t drawinfo;
961 int viewCount;
962 int visCountCheck;
963 int visCountDraw;
964 int frameCount;
965 unsigned int uiDistRecalc;
966 float s;
967 float t;
968 vec2_t texCoord[2][2];
969 float x0;
970 float y0;
971 float z0;
972 float zmax;
973 shader_t* shader;
974 short int iNorth;
975 short int iEast;
976 short int iSouth;
977 short int iWest;
978 struct cTerraPatchUnpacked_s* pNextActive;
979 varnodeUnpacked_t varTree[2][63];
980 unsigned char heightmap[81];
981 byte flags;
982 byte byDirty;
984
985typedef struct srfStaticModel_s {
986 surfaceType_t surfaceType;
987 struct cStaticModelUnpacked_s* parent;
988} srfStaticModel_t;
989
991 qboolean useSpecialLighting;
992 qboolean bLightGridCalculated;
993 qboolean bRendered;
994 char model[128];
995 vec3_t origin;
996 vec3_t angles;
997 vec3_t axis[3];
998 float scale;
999 int firstVertexData;
1000 int numVertexData;
1001 int visCount;
1002 dtiki_t* tiki;
1003 sphere_dlight_t dlights[MAX_DLIGHTS];
1004 int numdlights;
1005 float radius;
1006 float cull_radius;
1007 int iGridLighting;
1008 float lodpercentage[2];
1010
1011extern void (*rb_surfaceTable[SF_NUM_SURFACE_TYPES])(void *);
1012
1013/*
1014==============================================================================
1015
1016BRUSH MODELS
1017
1018==============================================================================
1019*/
1020
1021
1022//
1023// in memory representation
1024//
1025
1026#define SIDE_FRONT 0
1027#define SIDE_BACK 1
1028#define SIDE_ON 2
1029
1030typedef struct msurface_s {
1031 int viewCount; // if == tr.viewCount, already added
1032 int frameCount;
1033 struct shader_s *shader;
1034 int fogIndex;
1035
1036 surfaceType_t *data; // any of srf*_t
1037} msurface_t;
1038
1039
1040
1041#define CONTENTS_NODE -1
1042typedef struct mnode_s {
1043 // common with leaf and node
1044 int contents; // -1 for nodes, to differentiate from leafs
1045 int visframe; // node needs to be traversed if current
1046 vec3_t mins, maxs; // for bounding box culling
1047 struct mnode_s *parent;
1048
1049 // node specific
1050 cplane_t *plane;
1051 struct mnode_s *children[2];
1052
1053 // leaf specific
1054 int cluster;
1055 int area;
1056 spherel_t** lights;
1057 int numlights;
1058
1059 msurface_t **firstmarksurface;
1060 int nummarksurfaces;
1061
1062 int firstTerraPatch;
1063 int numTerraPatches;
1064 int firstStaticModel;
1065 int numStaticModels;
1066 void** pFirstMarkFragment;
1067 int iNumMarkFragment;
1068} mnode_t;
1069
1070typedef struct {
1071 vec3_t bounds[2]; // for culling
1072 msurface_t *firstSurface;
1073 int numSurfaces;
1074 void** pFirstMarkFragment;
1075 int iNumMarkFragment;
1076 int frameCount;
1077 qboolean hasLightmap;
1078} bmodel_t;
1079
1080typedef struct {
1081 float width;
1082 float height;
1083 float origin_x;
1084 float origin_y;
1085 float scale;
1086 shader_t* shader;
1087} sprite_t;
1088
1089typedef struct {
1090 char name[MAX_QPATH]; // ie: maps/tim_dm2.bsp
1091 char baseName[MAX_QPATH]; // ie: tim_dm2
1092
1093 int dataSize;
1094
1095 int numShaders;
1096 dshader_t *shaders;
1097
1098 int numBmodels;
1099 bmodel_t *bmodels;
1100
1101 int numplanes;
1102 cplane_t *planes;
1103
1104 int numnodes; // includes leafs
1105 int numDecisionNodes;
1106 mnode_t *nodes;
1107
1108 int numsurfaces;
1109 msurface_t *surfaces;
1110
1111 int nummarksurfaces;
1112 msurface_t **marksurfaces;
1113
1114 vec3_t lightGridMins;
1115 vec3_t lightGridSize;
1116 vec3_t lightGridOOSize;
1117 int lightGridBounds[3];
1118 unsigned short* lightGridOffsets;
1119 byte *lightGridData;
1120 byte lightGridPalette[768];
1121
1122 int numTerraPatches;
1123 cTerraPatchUnpacked_t* terraPatches;
1124 cTerraPatchUnpacked_t* activeTerraPatches;
1125
1126 int numVisTerraPatches;
1127 cTerraPatchUnpacked_t** visTerraPatches;
1128
1129 int numStaticModelData;
1130 byte* staticModelData;
1131
1132 int numStaticModels;
1133 cStaticModelUnpacked_t* staticModels;
1134
1135 int numVisStaticModels;
1136 cStaticModelUnpacked_t** visStaticModels;
1137
1138 int numClusters;
1139 int clusterBytes;
1140 const byte *vis; // may be passed in by CM_LoadMap to save space
1141
1142 byte *novis; // clusterBytes of 0xff
1143 byte *lighting;
1144} world_t;
1145
1146//======================================================================
1147
1148typedef enum {
1149 MOD_BAD,
1150 MOD_BRUSH,
1151 MOD_TIKI,
1152 MOD_SPRITE
1153} modtype_t;
1154
1155typedef struct model_s {
1156 char name[MAX_QPATH];
1157 modtype_t type;
1158 int index; // model = tr.models[model->index]
1159
1160 qboolean serveronly;
1161 union {
1162 bmodel_t* bmodel;
1163 dtiki_t* tiki;
1164 sprite_t* sprite;
1165 } d;
1166} model_t;
1167
1168
1169#define MAX_MOD_KNOWN 1024
1170
1171void R_ModelInit (void);
1172model_t *R_GetModelByHandle( qhandle_t hModel );
1173int R_LerpTag( orientation_t *tag, qhandle_t handle, int startFrame, int endFrame,
1174 float frac, const char *tagName );
1175
1176void R_Modellist_f (void);
1177
1178//====================================================
1179extern refimport_t ri;
1180
1181#define MAX_DRAWIMAGES 2048
1182#define MAX_LIGHTMAPS 256
1183#define MAX_SKINS 1024
1184#define MAX_SPHERE_LIGHTS 512
1185
1186#define MAX_DRAWSURFS 0x10000
1187#define MAX_SPRITESURFS 0x8000
1188#define DRAWSURF_MASK (MAX_DRAWSURFS-1)
1189
1190#define MAX_SPRITE_DIST 16384.0f
1191#define MAX_SPRITE_DIST_SQUARED (MAX_SPRITE_DIST * MAX_SPRITE_DIST)
1192
1193/*
1194
1195the drawsurf sort data is packed into a single 32 bit value so it can be
1196compared quickly during the qsorting process
1197
1198the bits are allocated as follows:
1199
120021 - 31 : sorted shader index
120111 - 20 : entity index
12022 - 6 : fog index
1203//2 : used to be clipped flag REMOVED - 03.21.00 rad
12040 - 1 : dlightmap index
1205
1206 TTimo - 1.32
120717-31 : sorted shader index
12087-16 : entity index
12092-6 : fog index
12100-1 : dlightmap index
1211*/
1212#define QSORT_SHADERNUM_SHIFT 21 // was 22, decreased in 2.30
1213#define QSORT_ENTITYNUM_SHIFT 8
1214#define QSORT_FOGNUM_SHIFT 2
1215#define QSORT_REFENTITYNUM_SHIFT 7
1216#define QSORT_STATICMODEL_SHIFT 20 // was 21, decreased in 2.30
1217
1218extern int gl_filter_min, gl_filter_max;
1219
1220/*
1221** performanceCounters_t
1222*/
1223typedef struct {
1224 int c_sphere_cull_patch_in, c_sphere_cull_patch_clip, c_sphere_cull_patch_out;
1225 int c_box_cull_patch_in, c_box_cull_patch_clip, c_box_cull_patch_out;
1226 int c_sphere_cull_md3_in, c_sphere_cull_md3_clip, c_sphere_cull_md3_out;
1227 int c_box_cull_md3_in, c_box_cull_md3_clip, c_box_cull_md3_out;
1228
1229 int c_leafs;
1230 int c_dlightSurfaces;
1231 int c_dlightSurfacesCulled;
1232 int c_dlightMaps;
1233 int c_dlightTexels;
1235
1236#define FOG_TABLE_SIZE 256
1237#define FUNCTABLE_SIZE 1024
1238#define FUNCTABLE_SIZE2 10
1239#define FUNCTABLE_MASK (FUNCTABLE_SIZE-1)
1240
1241
1242// the renderer front end should never modify glstate_t
1243typedef struct {
1244 int currenttextures[2];
1245 int currenttmu;
1246 qboolean finishCalled;
1247 int texEnv[2];
1248 int faceCulling;
1249 int cntTexEnvExt;
1250 int cntnvblendmode;
1251 long unsigned int glStateBits;
1252 long unsigned int externalSetState;
1253 vec4_t fFogColor;
1254} glstate_t;
1255
1256
1257typedef struct {
1258 int c_surfaces, c_shaders, c_vertexes, c_indexes, c_totalIndexes, c_characterlights;
1259 float c_overDraw;
1260
1261 int c_dlightVertexes;
1262 int c_dlightIndexes;
1263
1264 int c_flareAdds;
1265 int c_flareTests;
1266 int c_flareRenders;
1267
1268 int msec; // total msec for backend run
1270
1271// all state modified by the back end is seperated
1272// from the front end state
1273typedef struct {
1274 int smpFrame;
1275 trRefdef_t refdef;
1276 viewParms_t viewParms;
1277 orientationr_t ori;
1279 qboolean isHyperspace;
1280 trRefEntity_t *currentEntity;
1281 qboolean skyRenderedThisView; // flag for drawing sun
1282 sphereor_t spheres[MAX_SPHERE_LIGHTS];
1283 unsigned short numSpheresUsed;
1284 sphereor_t* currentSphere;
1285 sphereor_t spareSphere;
1286 sphereor_t hudSphere;
1287 cStaticModelUnpacked_t* currentStaticModel;
1288 int dsStreamVert;
1289 qboolean in2D; // if qtrue, drawstretchpic doesn't need to change modes
1290 byte color2D[4];
1291 qboolean vertexes2D; // shader needs to be finished
1292 trRefEntity_t entity2D; // currentEntity will point at this when doing 2D rendering
1293 int backEndMsec;
1294 float shaderStartTime;
1296
1297/*
1298** trGlobals_t
1299**
1300** Most renderer globals are defined here.
1301** backend functions should never modify any of these fields,
1302** but may read fields that aren't dynamically modified
1303** by the frontend.
1304*/
1305typedef struct {
1306 qboolean registered; // cleared at shutdown, set at beginRegistration
1307
1308 int visCount; // incremented every time a new vis cluster is entered
1309 int frameCount; // incremented every frame
1310 int sceneCount; // incremented every scene
1311 int viewCount; // incremented every view (twice a scene if portaled)
1312 // and every R_MarkFragments call
1313
1314 int smpFrame; // toggles from 0 to 1 every endFrame
1315
1316 int frameSceneNum; // zeroed at RE_BeginFrame
1317
1318 qboolean worldMapLoaded;
1319 world_t *world;
1320
1321 const byte *externalVisData; // from RE_SetWorldVisData, shared with CM_Load
1322
1323 image_t *defaultImage;
1324 image_t *scratchImage;
1325 image_t *fogImage;
1326 image_t *dlightImage; // inverse-quare highlight for projective adding
1327 image_t *flareImage;
1328 image_t *whiteImage; // full of 0xff
1329 image_t *identityLightImage; // full of tr.identityLightByte
1330 image_t *dlightImages[15];
1331
1332 shader_t *defaultShader;
1333 shader_t *shadowShader;
1334 shader_t *projectionShadowShader;
1335
1336 shader_t *flareShader;
1337 shader_t *sunShader;
1338
1339 int numLightmaps;
1340 image_t *lightmaps[MAX_LIGHTMAPS];
1341
1342 trRefEntity_t *currentEntity;
1343 trRefEntity_t worldEntity; // point currentEntity at this when rendering world
1344 int currentEntityNum;
1345 int currentSpriteNum;
1346 int shiftedEntityNum; // currentEntityNum << QSORT_ENTITYNUM_SHIFT
1347 int shiftedIsStatic;
1348 model_t *currentModel;
1349
1350 viewParms_t viewParms;
1351
1352 float identityLight; // 1.0 / ( 1 << overbrightBits )
1353 int identityLightByte; // identityLight * 255
1354 int overbrightBits; // r_overbrightBits->integer, but set to 0 if no hw gamma
1355 int overbrightShift;
1356 float overbrightMult;
1357 int needsLightScale;
1358
1359 orientationr_t ori; // for current entity
1360
1361 portalsky_t portalsky;
1362 qboolean skyRendered;
1363 qboolean portalRendered;
1364 trRefdef_t refdef;
1365
1366 int viewCluster;
1367
1368 vec3_t sunLight; // from the sky shader for this level
1369 vec3_t sunDirection;
1370
1372 int frontEndMsec; // not in pc due to clearing issue
1373
1374 //
1375 // put large tables at the end, so most elements will be
1376 // within the +/32K indexed range on risc processors
1377 //
1378 model_t models[MAX_MOD_KNOWN];
1379 int numModels;
1380
1381 int numImages;
1382 image_t images[MAX_DRAWIMAGES];
1383
1384 // shader indexes from other modules will be looked up in tr.shaders[]
1385 // shader indexes from drawsurfs will be looked up in sortedShaders[]
1386 // lower indexed sortedShaders must be rendered first (opaque surfaces before translucent)
1387 int numShaders;
1388 shader_t *shaders[MAX_SHADERS];
1389 shader_t *sortedShaders[MAX_SHADERS];
1390
1391 int numSkins;
1392 skin_t *skins[MAX_SKINS];
1393
1394 float sinTable[FUNCTABLE_SIZE];
1395 float squareTable[FUNCTABLE_SIZE];
1396 float triangleTable[FUNCTABLE_SIZE];
1397 float sawToothTable[FUNCTABLE_SIZE];
1398 float inverseSawToothTable[FUNCTABLE_SIZE];
1399
1400 spherel_t sSunLight;
1401 spherel_t sLights[1532];
1402 int numSLights;
1403 int rendererhandle;
1404 qboolean shadersParsed;
1405 int frame_skel_index;
1406 int skel_index[1024];
1407 fontheader_t* pFontDebugStrings;
1408
1409 int farclip;
1410} trGlobals_t;
1411
1412extern backEndState_t backEnd;
1413extern trGlobals_t tr;
1414extern glconfig_t glConfig; // outside of TR since it shouldn't be cleared during ref re-init
1415
1416// These variables should live inside glConfig but can't because of
1417// compatibility issues to the original ID vms. If you release a stand-alone
1418// game and your mod uses tr_types.h from this build you can safely move them
1419// to the glconfig_t struct.
1420extern qboolean textureFilterAnisotropic;
1421extern int maxAnisotropy;
1422extern float displayAspect;
1423extern qboolean haveClampToEdge;
1424
1425extern glstate_t glState; // outside of TR since it shouldn't be cleared during ref re-init
1426extern int r_sequencenumber;
1427
1428
1429//
1430// cvars
1431//
1432extern cvar_t *r_flareSize;
1433extern cvar_t *r_flareFade;
1434
1435extern cvar_t *r_ignore; // used for debugging anything
1436extern cvar_t *r_verbose; // used for verbose debug spew
1437extern cvar_t *r_ignoreFastPath; // allows us to ignore our Tess fast paths
1438
1439extern cvar_t *r_znear; // near Z clip plane
1440
1441extern cvar_t *r_stencilbits; // number of desired stencil bits
1442extern cvar_t *r_depthbits; // number of desired depth bits
1443extern cvar_t *r_colorbits; // number of desired color bits, only relevant for fullscreen
1444extern cvar_t *r_stereo; // desired pixelformat stereo flag
1445extern cvar_t *r_textureDetails;
1446extern cvar_t *r_texturebits; // number of desired texture bits
1447 // 0 = use framebuffer depth
1448 // 16 = use 16-bit textures
1449 // 32 = use 32-bit textures
1450 // all else = error
1451
1452extern cvar_t *r_measureOverdraw; // enables stencil buffer overdraw measurement
1453
1454extern cvar_t *r_lodscale;
1455
1456extern cvar_t *r_primitives; // "0" = based on compiled vertex array existance
1457 // "1" = glDrawElemet tristrips
1458 // "2" = glDrawElements triangles
1459 // "-1" = no drawing
1460
1461extern cvar_t *r_largemap;
1462extern cvar_t *r_inGameVideo; // controls whether in game video should be draw
1463extern cvar_t *r_fastsky; // controls whether sky should be cleared or drawn
1464extern cvar_t *r_fastdlights;
1465extern cvar_t *r_drawSun; // controls drawing of sun quad
1466extern cvar_t *r_dlightBacks; // dlight non-facing surfaces for continuity
1467
1468extern cvar_t *r_norefresh; // bypasses the ref rendering
1469extern cvar_t *r_drawentities; // disable/enable entity rendering
1470extern cvar_t *r_drawentitypoly;
1471extern cvar_t *r_drawstaticmodels;
1472extern cvar_t *r_drawstaticmodelpoly;
1473extern cvar_t *r_drawbrushes;
1474extern cvar_t *r_drawbrushmodels;
1475extern cvar_t *r_drawstaticdecals;
1476extern cvar_t *r_drawterrain;
1477extern cvar_t *r_drawsprites;
1478extern cvar_t *r_drawspherelights;
1479extern cvar_t *r_drawworld; // disable/enable world rendering
1480extern cvar_t *r_speeds; // various levels of information display
1481extern cvar_t *r_detailTextures; // enables/disables detail texturing stages
1482extern cvar_t *r_novis; // disable/enable usage of PVS
1483extern cvar_t *r_nocull;
1484extern cvar_t *r_showcull;
1485extern cvar_t *r_facePlaneCull; // enables culling of planar surfaces with back side test
1486extern cvar_t *r_nocurves;
1487extern cvar_t *r_showcluster;
1488
1489extern cvar_t *r_mode; // video mode
1490extern cvar_t *r_maxmode;
1491extern cvar_t *r_vidmode1024;
1492extern cvar_t *r_vidmodemax;
1493extern cvar_t *r_fullscreen;
1494extern cvar_t *r_gamma;
1495extern cvar_t *r_displayRefresh; // optional display refresh option
1496extern cvar_t *r_ignorehwgamma; // overrides hardware gamma capabilities
1497
1498extern cvar_t *r_allowExtensions; // global enable/disable of OpenGL extensions
1499extern cvar_t *r_ext_compressed_textures; // these control use of specific extensions
1500extern cvar_t *r_ext_gamma_control;
1501extern cvar_t *r_ext_texenv_op;
1502extern cvar_t *r_ext_multitexture;
1503extern cvar_t *r_ext_compiled_vertex_array;
1504extern cvar_t *r_ext_texture_env_add;
1505extern cvar_t *r_ext_texture_env_combine;
1506extern cvar_t *r_ext_aniso_filter;
1507extern cvar_t *r_ext_max_anisotropy;
1508extern cvar_t *r_forceClampToEdge;
1509extern cvar_t *r_geForce3WorkAround;
1510extern cvar_t *r_reset_tc_array;
1511
1512extern cvar_t *r_nobind; // turns off binding to appropriate textures
1513extern cvar_t *r_singleShader; // make most world faces use default shader
1514extern cvar_t *r_lerpmodels;
1515extern cvar_t *r_roundImagesDown;
1516extern cvar_t *r_colorMipLevels; // development aid to see texture mip usage
1517extern cvar_t *r_picmip; // controls picmip values
1518extern cvar_t *r_finish;
1519extern cvar_t *r_drawBuffer;
1520extern cvar_t *r_glDriver;
1521extern cvar_t *r_swapInterval;
1522extern cvar_t *r_textureMode;
1523extern cvar_t *r_offsetFactor;
1524extern cvar_t *r_offsetUnits;
1525
1526extern cvar_t *r_fullbright; // avoid lightmap pass
1527extern cvar_t *r_lightmap; // render lightmaps only
1528extern cvar_t *r_vertexLight; // vertex lighting mode for better performance
1529
1530extern cvar_t *r_logFile; // number of frames to emit GL logs
1531extern cvar_t *r_showtris; // enables wireframe rendering of the world
1532extern cvar_t *r_showsky; // forces sky in front of all surfaces
1533extern cvar_t *r_shownormals; // draws wireframe normals
1534extern cvar_t *r_showhbox;
1535extern cvar_t *r_showstaticbboxes;
1536extern cvar_t *r_clear; // force screen clear every frame
1537
1538extern cvar_t *r_shadows; // controls shadows: 0 = none, 1 = blur, 2 = stencil, 3 = black planar projection
1539extern cvar_t *r_entlight_scale;
1540extern cvar_t *r_entlight_errbound;
1541extern cvar_t *r_entlight_cubelevel;
1542extern cvar_t *r_entlight_cubefraction;
1543extern cvar_t *r_entlight_maxcalc;
1544extern cvar_t *r_flares; // light flares
1545
1546extern cvar_t *r_intensity;
1547
1548extern cvar_t *r_lockpvs;
1549extern cvar_t *r_noportals;
1550extern cvar_t *r_entlightmap;
1551extern cvar_t *r_fastentlight;
1552extern cvar_t *r_portalOnly;
1553
1554extern cvar_t *r_subdivisions;
1555extern cvar_t *r_lodCurveError;
1556extern cvar_t *r_skipBackEnd;
1557
1558extern cvar_t *r_anaglyphMode;
1559
1560extern cvar_t *r_ignoreGLErrors;
1561
1562extern cvar_t *r_overBrightBits;
1563extern cvar_t *r_mapOverBrightBits;
1564
1565extern cvar_t *r_debugSurface;
1566
1567extern cvar_t *r_showImages;
1568extern cvar_t *r_showlod;
1569extern cvar_t *r_showstaticlod;
1570extern cvar_t *r_debugSort;
1571
1572extern cvar_t *r_printShaders;
1573extern cvar_t *r_saveFontData;
1574
1575extern cvar_t* r_staticlod;
1576extern cvar_t* r_lodscale;
1577extern cvar_t* r_lodcap;
1578extern cvar_t* r_lodviewmodelcap;
1579
1580extern cvar_t* r_uselod;
1581extern cvar_t* lod_LOD;
1582extern cvar_t* lod_minLOD;
1583extern cvar_t* lod_maxLOD;
1584extern cvar_t* lod_LOD_slider;
1585extern cvar_t* lod_curve_0_val;
1586extern cvar_t* lod_curve_1_val;
1587extern cvar_t* lod_curve_2_val;
1588extern cvar_t* lod_curve_3_val;
1589extern cvar_t* lod_curve_4_val;
1590extern cvar_t* lod_edit_0;
1591extern cvar_t* lod_edit_1;
1592extern cvar_t* lod_edit_2;
1593extern cvar_t* lod_edit_3;
1594extern cvar_t* lod_edit_4;
1595extern cvar_t* lod_curve_0_slider;
1596extern cvar_t* lod_curve_1_slider;
1597extern cvar_t* lod_curve_2_slider;
1598extern cvar_t* lod_curve_3_slider;
1599extern cvar_t* lod_curve_4_slider;
1600extern cvar_t* lod_pitch_val;
1601extern cvar_t* lod_zee_val;
1602extern cvar_t* lod_mesh;
1603extern cvar_t* lod_meshname;
1604extern cvar_t* lod_tikiname;
1605extern cvar_t* lod_metric;
1606extern cvar_t* lod_tris;
1607extern cvar_t* lod_position;
1608extern cvar_t* lod_save;
1609extern cvar_t* lod_tool;
1610extern cvar_t* sys_cpuid;
1611extern cvar_t* r_sse;
1612extern cvar_t* r_static_shaderdata0;
1613extern cvar_t* r_static_shaderdata1;
1614extern cvar_t* r_static_shaderdata2;
1615extern cvar_t* r_static_shaderdata3;
1616extern cvar_t* r_static_shadermultiplier0;
1617extern cvar_t* r_static_shadermultiplier1;
1618extern cvar_t* r_static_shadermultiplier2;
1619extern cvar_t* r_static_shadermultiplier3;
1620
1621extern cvar_t* r_numdebuglines;
1622
1623extern cvar_t* r_stipplelines;
1624extern cvar_t* r_light_lines;
1625extern cvar_t* r_light_sun_line;
1626extern cvar_t* r_light_int_scale;
1627extern cvar_t* r_light_nolight;
1628extern cvar_t* r_light_showgrid;
1629extern cvar_t* r_skyportal;
1630extern cvar_t* r_skyportal_origin;
1631extern cvar_t* r_farplane;
1632extern cvar_t* r_farplane_bias;
1633extern cvar_t* r_farplane_color;
1634extern cvar_t* r_farplane_nocull;
1635extern cvar_t* r_farplane_nofog;
1636extern cvar_t* r_skybox_farplane;
1637extern cvar_t* r_farclip;
1638extern cvar_t* r_lightcoronasize;
1639extern cvar_t* r_useglfog;
1640extern cvar_t* r_debuglines_depthmask;
1641extern cvar_t* r_smoothsmokelight;
1642extern cvar_t* r_showportal;
1643extern cvar_t* ter_minMarkRadius;
1644extern cvar_t* ter_fastMarks;
1645extern cvar_t* r_alpha_foliage1;
1646extern cvar_t* r_alpha_foliage2;
1647extern cvar_t* r_blendtrees;
1648extern cvar_t* r_blendbushes;
1649extern cvar_t* r_bumpmap;
1650extern cvar_t* r_loadjpg;
1651extern cvar_t* r_loadftx;
1652
1653extern cvar_t* r_showSkeleton;
1654extern cvar_t* r_developer;
1655extern cvar_t* r_fps;
1656
1657//====================================================================
1658
1659void R_NoiseInit( void );
1660
1661void R_RenderView( viewParms_t *parms );
1662
1663qboolean SurfIsOffscreen(const srfSurfaceFace_t* surface, shader_t* shader, int entityNum);
1664
1665void R_AddMD3Surfaces( trRefEntity_t *e );
1666void R_AddNullModelSurfaces( trRefEntity_t *e );
1667void R_AddBeamSurfaces( trRefEntity_t *e );
1668void R_AddRailSurfaces( trRefEntity_t *e, qboolean isUnderwater );
1669void R_AddLightningBoltSurfaces( trRefEntity_t *e );
1670
1671void R_AddPolygonSurfaces( void );
1672
1673void R_DecomposeSort(unsigned int sort, int* entityNum, shader_t** shader, int* dlightMap, qboolean* bStaticModel);
1674
1675void R_AddDrawSurf(surfaceType_t* surface, shader_t* shader, int dlightMap);
1676
1677
1678#define CULL_IN 0 // completely unclipped
1679#define CULL_CLIP 1 // clipped by one or more planes
1680#define CULL_OUT 2 // completely outside the clipping planes
1681void R_LocalNormalToWorld (const vec3_t local, vec3_t world);
1682void R_LocalPointToWorld (const vec3_t local, vec3_t world);
1683int R_CullLocalBoxOffset(const vec3_t offset, vec3_t bounds[2]);
1684int R_CullLocalBox (vec3_t bounds[2]);
1685int R_CullPointAndRadius( vec3_t origin, float radius );
1686int R_CullLocalPointAndRadius( vec3_t origin, float radius );
1687int R_DistanceCullLocalPointAndRadius(float fDist, const vec3_t pt, float radius);
1688int R_DistanceCullPointAndRadius(float fDist, const vec3_t pt, float radius);
1689
1690void R_RotateForEntity( const trRefEntity_t *ent, const viewParms_t *viewParms, orientationr_t *ori );
1691void R_RotateForStaticModel(cStaticModelUnpacked_t* SM, const viewParms_t* viewParms, orientationr_t* ori );
1692void R_RotateForViewer(void);
1693void R_SetupFrustum(void);
1694
1695/*
1696** GL wrapper/helper functions
1697*/
1698void GL_SetFogColor(const vec4_t fColor);
1699void GL_Bind( image_t *image );
1700void GL_SetDefaultState (void);
1701void GL_SelectTexture( int unit );
1702void GL_TextureMode( const char *string );
1703void GL_CheckErrors( void );
1704void GL_State( unsigned long stateVector );
1705void GL_TexEnv( int env );
1706void GL_Cull( int cullType );
1707
1708#define GLS_SRCBLEND_ZERO 0x00000001
1709#define GLS_SRCBLEND_ONE 0x00000002
1710#define GLS_SRCBLEND_DST_COLOR 0x00000003
1711#define GLS_SRCBLEND_ONE_MINUS_DST_COLOR 0x00000004
1712#define GLS_SRCBLEND_SRC_ALPHA 0x00000005
1713#define GLS_SRCBLEND_ONE_MINUS_SRC_ALPHA 0x00000006
1714#define GLS_SRCBLEND_DST_ALPHA 0x00000007
1715#define GLS_SRCBLEND_ONE_MINUS_DST_ALPHA 0x00000008
1716#define GLS_SRCBLEND_ALPHA_SATURATE 0x00000009
1717#define GLS_SRCBLEND_BITS 0x0000000f
1718
1719#define GLS_DSTBLEND_ZERO 0x00000010
1720#define GLS_DSTBLEND_ONE 0x00000020
1721#define GLS_DSTBLEND_SRC_COLOR 0x00000030
1722#define GLS_DSTBLEND_ONE_MINUS_SRC_COLOR 0x00000040
1723#define GLS_DSTBLEND_SRC_ALPHA 0x00000050
1724#define GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA 0x00000060
1725#define GLS_DSTBLEND_DST_ALPHA 0x00000070
1726#define GLS_DSTBLEND_ONE_MINUS_DST_ALPHA 0x00000080
1727#define GLS_DSTBLEND_BITS 0x000000f0
1728
1729#define GLS_DEPTHMASK_TRUE 0x00000100
1730#define GLS_COLOR_MASK 0x00000200
1731#define GLS_POLYMODE_LINE 0x00000400
1732#define GLS_DEPTHTEST_DISABLE 0x00000800
1733#define GLS_DEPTHFUNC_EQUAL 0x00001000
1734
1735#define GLS_CLAMP_EDGE 0x00002000
1736#define GLS_MULTITEXTURE 0x00004000
1737#define GLS_MULTITEXTURE_ENV 0x00008000
1738#define GLS_FOG 0x00010000
1739
1740#define GLS_FOG_ENABLED 0x00020000
1741#define GLS_FOG_BLACK 0x00040000
1742#define GLS_FOG_WHITE 0x00080000
1743#define GLS_FOG_COLOR (GLS_FOG_BLACK | GLS_FOG_WHITE)
1744#define GLS_FOG_BITS (GLS_FOG_WHITE|GLS_FOG_BLACK|GLS_FOG_ENABLED)
1745#define GLS_COLOR_NOMASK 0x00100000
1746
1747#define GLS_ATEST_GT_0 0x10000000
1748#define GLS_ATEST_LT_80 0x20000000
1749#define GLS_ATEST_GE_80 0x30000000
1750#define GLS_ATEST_LT_FOLIAGE1 0x40000000
1751#define GLS_ATEST_GE_FOLIAGE1 0x50000000
1752#define GLS_ATEST_LT_FOLIAGE2 0x60000000
1753#define GLS_ATEST_GE_FOLIAGE2 0x70000000
1754#define GLS_ATEST_BITS 0x70000000
1755
1756#define GLS_DEFAULT GLS_DEPTHMASK_TRUE
1757
1758void Draw_SetColor(const vec4_t rgba);
1759void Draw_StretchPic(float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader);
1760void Draw_StretchPic2(float x, float y, float w, float h, float s1, float t1, float s2, float t2, float sx, float sy, qhandle_t hShader);
1761void Draw_TilePic(float x, float y, float w, float h, qhandle_t hShader);
1762void Draw_TilePicOffset(float x, float y, float w, float h, qhandle_t hShader, int offsetX, int offsetY);
1763void Draw_TrianglePic(const vec2_t vPoints[3], const vec2_t vTexCoords[3], qhandle_t hShader);
1764void DrawBox(float x, float y, float w, float h);
1765void AddBox(float x, float y, float w, float h);
1766void Set2DWindow(int x, int y, int w, int h, float left, float right, float bottom, float top, float n, float f);
1767void RE_Scissor(int x, int y, int width, int height);
1768void DrawLineLoop(const vec2_t* points, int count, int stipple_factor, int stipple_mask);
1769void RE_StretchRaw(int x, int y, int w, int h, int cols, int rows, int components, const byte* data);
1770void RE_UploadCinematic (int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty);
1771
1772void RE_BeginFrame( stereoFrame_t stereoFrame );
1773void RE_BeginRegistration( glconfig_t *glconfig );
1774void RE_LoadWorldMap( const char *mapname );
1775void RE_PrintBSPFileSizes(void);
1776int RE_MapVersion(void);
1777void RE_SetWorldVisData( const byte *vis );
1778qhandle_t RE_RegisterModel( const char *name );
1779qhandle_t RE_RegisterSkin( const char *name );
1780void RE_Shutdown( qboolean destroyWindow );
1781void R_ClearWorld(void);
1782
1783qboolean R_GetEntityToken( char *buffer, int size );
1784
1785model_t *R_AllocModel( void );
1786
1787void R_Init( void );
1788
1789image_t *R_FindImageFileOld(const char* name, qboolean mipmap, qboolean allowPicmip, qboolean force32bit, int glWrapClampModeX, int glWrapClampModeY);
1790image_t *R_RefreshImageFileOld(const char* name, qboolean mipmap, qboolean allowPicmip, qboolean force32bit, int glWrapClampModeX, int glWrapClampModeY);
1791
1792image_t* R_CreateImageOld(
1793 const char* name,
1794 byte* pic,
1795 int width,
1796 int height,
1797 int numMipmaps,
1798 int iMipmapsAvailable,
1799 qboolean allowPicmip,
1800 qboolean force32bit,
1801 qboolean hasAlpha,
1802 int glCompressMode,
1803 int glWrapClampModeX,
1804 int glWrapClampModeY
1805);
1806
1807qboolean R_ImageExists(const char* name);
1808int R_CountTextureMemory();
1809qboolean R_LoadRawImage(const char *name, byte **pic, int *width, int *height);
1810void R_FreeRawImage(byte *pic);
1811
1812qboolean R_GetModeInfo( int *width, int *height, float *windowAspect, int mode );
1813
1814void R_SetColorMappings( void );
1815void R_GammaCorrect( byte *buffer, int bufSize );
1816
1817void R_ImageList_f( void );
1818void R_SkinList_f( void );
1819// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=516
1820const void *RB_TakeScreenshotCmd( const void *data );
1821void R_ScreenShot_f( void );
1822
1823void R_InitImages( void );
1824void R_FreeImage(image_t* image);
1825void R_DeleteTextures( void );
1826void R_FreeUnusedImages( void );
1827int R_SumOfUsedImages( void );
1828skin_t *R_GetSkinByHandle( qhandle_t hSkin );
1829
1830const void *RB_TakeVideoFrameCmd( const void *data );
1831
1832//
1833// tr_shader.c
1834//
1835qhandle_t RE_RegisterShader( const char *name );
1836qhandle_t RE_RegisterShaderNoMip( const char *name );
1837qhandle_t RE_RefreshShaderNoMip(const char* name);
1838qhandle_t RE_RegisterShaderFromImage(const char *name, int lightmapIndex, image_t *image, qboolean mipRawImage);
1839
1840shader_t* R_FindShader(const char* name, int lightmapIndex, qboolean mipRawImage, qboolean picmip, qboolean wrapx, qboolean wrapy);
1841shader_t *R_GetShaderByHandle( qhandle_t hShader );
1842shader_t *R_GetShaderByState( int index, long *cycleTime );
1843void R_StartupShaders();
1844void R_ShutdownShaders();
1845void R_SetupShaders();
1846shader_t *R_FindShaderByName( const char *name );
1847void R_ShaderList_f( void );
1848void R_RemapShader(const char *oldShader, const char *newShader, const char *timeOffset);
1849
1850/*
1851====================================================================
1852
1853IMPLEMENTATION SPECIFIC FUNCTIONS
1854
1855====================================================================
1856*/
1857
1858void GLimp_Init( qboolean fixedFunction );
1859void GLimp_Shutdown( void );
1860void GLimp_EndFrame( void );
1861
1862qboolean GLimp_SpawnRenderThread( void (*function)( void ) );
1863void *GLimp_RendererSleep( void );
1864void GLimp_FrontEndSleep( void );
1865void GLimp_WakeRenderer( void *data );
1866
1867void GLimp_LogComment( char *comment );
1868
1869// NOTE TTimo linux works with float gamma value, not the gamma table
1870// the params won't be used, getting the r_gamma cvar directly
1871void GLimp_SetGamma( unsigned char red[256],
1872 unsigned char green[256],
1873 unsigned char blue[256] );
1874
1875
1876/*
1877====================================================================
1878
1879TESSELATOR/SHADER DECLARATIONS
1880
1881====================================================================
1882*/
1883typedef byte color4ub_t[4];
1884
1885typedef struct stageVars
1886{
1887 color4ub_t colors[SHADER_MAX_VERTEXES];
1888 vec2_t texcoords[NUM_TEXTURE_BUNDLES][SHADER_MAX_VERTEXES];
1889} stageVars_t;
1890
1891typedef struct shaderCommands_s
1892{
1893 glIndex_t indexes[SHADER_MAX_INDEXES] Q_ALIGN(16);
1894 vec4_t xyz[SHADER_MAX_VERTEXES] Q_ALIGN(16);
1895 vec4_t normal[SHADER_MAX_VERTEXES] Q_ALIGN(16);
1896 vec2_t texCoords[SHADER_MAX_VERTEXES][2] Q_ALIGN(16);
1897 color4ub_t vertexColors[SHADER_MAX_VERTEXES] Q_ALIGN(16);
1898 int vertexDlightBits[SHADER_MAX_VERTEXES] Q_ALIGN(16);
1899
1900 stageVars_t svars Q_ALIGN(16);
1901
1902 color4ub_t constantColor255[SHADER_MAX_VERTEXES] Q_ALIGN(16);
1903
1904 shader_t *shader;
1905 float shaderTime;
1906 int fogNum;
1907
1908 int dlightBits; // or together of all vertexDlightBits
1909 int dlightMap;
1910
1911 int numIndexes;
1912 int numVertexes;
1913
1914 // info extracted from current shader
1915 int numPasses;
1916 void (*currentStageIteratorFunc)( void );
1917 shaderStage_t **xstages;
1918 qboolean no_global_fog;
1919 qboolean vertexColorValid;
1920} shaderCommands_t;
1921
1922extern shaderCommands_t tess;
1923
1924void RB_BeginSurface(shader_t *shader );
1925void RB_EndSurface(void);
1926void RB_CheckOverflow( int verts, int indexes );
1927#define RB_CHECKOVERFLOW(v,i) if (tess.numVertexes + (v) >= SHADER_MAX_VERTEXES || tess.numIndexes + (i) >= SHADER_MAX_INDEXES ) {RB_CheckOverflow(v,i);}
1928
1929void RB_StageIteratorGeneric( void );
1930void RB_StageIteratorSky( void );
1931void RB_StageIteratorVertexLitTextureUnfogged( void );
1932void RB_StageIteratorLightmappedMultitextureUnfogged( void );
1933
1934void RB_AddQuadStamp( vec3_t origin, vec3_t left, vec3_t up, byte *color );
1935void RB_AddQuadStampExt( vec3_t origin, vec3_t left, vec3_t up, byte *color, float s1, float t1, float s2, float t2 );
1936
1937void RB_ShowImages( qboolean quiet );
1938
1939
1940/*
1941============================================================
1942
1943WORLD MAP
1944
1945============================================================
1946*/
1947
1948extern terraTri_t* g_pTris;
1949extern terrainVert_t* g_pVert;
1950
1951void R_AddBrushModelSurfaces( trRefEntity_t *e );
1952void R_GetInlineModelBounds(int iIndex, vec3_t vMins, vec3_t vMaxs);
1953int R_SphereInLeafs(const vec3_t p, float r, mnode_t** nodes, int nMaxNodes);
1954mnode_t* R_PointInLeaf(const vec3_t p);
1955int R_DlightTerrain(cTerraPatchUnpacked_t* surf, int dlightBits);
1956int R_CheckDlightTerrain(cTerraPatchUnpacked_t* surf, int dlightBits);
1957void R_AddWorldSurfaces( void );
1958qboolean R_inPVS( const vec3_t p1, const vec3_t p2 );
1959
1960
1961/*
1962============================================================
1963
1964FLARES
1965
1966============================================================
1967*/
1968
1969void R_ClearFlares( void );
1970
1971void RB_AddFlare( void *surface, int fogNum, vec3_t point, vec3_t color, vec3_t normal );
1972void RB_AddDlightFlares( void );
1973void RB_RenderFlares (void);
1974
1975/*
1976============================================================
1977
1978LIGHTS
1979
1980============================================================
1981*/
1982
1983void R_DlightBmodel( bmodel_t *bmodel );
1984void R_GetLightingGridValue(const vec3_t vPos, vec3_t vLight);
1985void R_GetLightingGridValueFast(const vec3_t vPos, vec3_t vLight);
1986void R_GetLightingForDecal(vec3_t vLight, const vec3_t vFacing, const vec3_t vOrigin);
1987void R_GetLightingForSmoke(vec3_t vLight, const vec3_t vOrigin);
1988void R_SetupEntityLighting( const trRefdef_t *refdef, trRefEntity_t *ent );
1989void RB_SetupEntityGridLighting();
1990void RB_SetupStaticModelGridLighting(trRefdef_t* refdef, cStaticModelUnpacked_t* ent, const vec3_t lightOrigin);
1991int R_RealDlightPatch(srfGridMesh_t* srf, int dlightBit);
1992int R_RealDlightFace(srfSurfaceFace_t* srf, int dlightBits);
1993int R_RealDlightTerrain(cTerraPatchUnpacked_t* srf, int dlightBits);
1994void R_TransformDlights( int count, dlight_t *dl, orientationr_t *ori );
1995void RB_Light_Real(unsigned char* colors);
1996void RB_Sphere_BuildDLights();
1997void RB_Sphere_SetupEntity();
1998void RB_Grid_SetupEntity();
1999void RB_Grid_SetupStaticModel();
2000void RB_Light_Fullbright(unsigned char* colors);
2001void R_Sphere_InitLights();
2002int R_GatherLightSources(const vec3_t vPos, vec3_t* pvLightPos, vec3_t* pvLightIntensity, int iMaxLights);
2003void R_ClearRealDlights();
2004void R_UploadDlights();
2005
2006int R_LightForPoint(vec3_t point, vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir);
2007
2008/*
2009============================================================
2010
2011SHADOWS
2012
2013============================================================
2014*/
2015
2016void RB_ShadowTessEnd( void );
2017void RB_ComputeShadowVolume();
2018void RB_ShadowFinish( void );
2019void RB_ProjectionShadowDeform( void );
2020
2021/*
2022============================================================
2023
2024SKIES
2025
2026============================================================
2027*/
2028
2029void R_BuildCloudData( shaderCommands_t *shader );
2030void R_InitSkyTexCoords( float cloudLayerHeight );
2031void R_DrawSkyBox( shaderCommands_t *shader );
2032void RB_DrawSun( void );
2033void RB_ClipSkyPolygons( shaderCommands_t *shader );
2034
2035/*
2036============================================================
2037
2038CURVE TESSELATION
2039
2040============================================================
2041*/
2042
2043#define PATCH_STITCHING
2044
2045srfGridMesh_t *R_SubdividePatchToGrid( int width, int height, float subdivide,
2046 drawVert_t points[MAX_PATCH_SIZE*MAX_PATCH_SIZE] );
2047srfGridMesh_t *R_GridInsertColumn( srfGridMesh_t *grid, int column, int row, vec3_t point, float loderror );
2048srfGridMesh_t *R_GridInsertRow( srfGridMesh_t *grid, int row, int column, vec3_t point, float loderror );
2049void R_FreeSurfaceGridMesh( srfGridMesh_t *grid );
2050
2051/*
2052============================================================
2053
2054MARKERS, POLYGON PROJECTION ON WORLD POLYGONS
2055
2056============================================================
2057*/
2058
2059int R_MarkFragments( int numPoints, const vec3_t *points, const vec3_t projection,
2060 int maxPoints, vec3_t pointBuffer, int maxFragments, markFragment_t *fragmentBuffer, float fRadiusSquared);
2061
2062int R_MarkFragmentsForInlineModel(clipHandle_t bmodel, const vec3_t vAngles, const vec3_t vOrigin, int numPoints,
2063 const vec3_t* points, const vec3_t projection, int maxPoints, vec3_t pointBuffer,
2064 int maxFragments, markFragment_t* fragmentBuffer, float fRadiusSquared);
2065
2066
2067/*
2068============================================================
2069
2070SCENE GENERATION
2071
2072============================================================
2073*/
2074
2075void R_InitNextFrame( void );
2076
2077void RE_ClearScene( void );
2078void RE_AddRefEntityToScene( const refEntity_t *ent, int parentEntityNumber);
2079void RE_AddRefSpriteToScene(const refEntity_t* ent);
2080void RE_AddTerrainMarkToScene(int iTerrainIndex, qhandle_t hShader, int numVerts, const polyVert_t* verts, int renderfx);
2081refEntity_t* RE_GetRenderEntity(int entityNumber);
2082qboolean RE_AddPolyToScene(qhandle_t hShader, int numVerts, const polyVert_t* verts, int renderfx);
2083void RE_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b, int type );
2084void RE_AddAdditiveLightToScene( const vec3_t org, float intensity, float r, float g, float b );
2085void RE_RenderScene( const refdef_t *fd );
2086
2087/*
2088=============================================================
2089
2090ANIMATED MODELS
2091
2092=============================================================
2093*/
2094
2095void R_MakeAnimModel( model_t *model );
2096void R_AddAnimSurfaces(trRefEntity_t* ent);
2097
2098/*
2099=============================================================
2100
2101FONT
2102
2103=============================================================
2104*/
2105void R_ShutdownFont();
2106fontheader_t* R_LoadFont(const char* name);
2107void R_LoadFontShader(fontheader_sgl_t* font);
2108void R_DrawString(fontheader_t* font, const char* text, float x, float y, int maxlen, const float *pvVirtualScreen);
2109void R_DrawFloatingString(fontheader_t* font, const char* text, const vec3_t org, const vec4_t color, float scale, int maxlen);
2110float R_GetFontHeight(const fontheader_t* font);
2111float R_GetFontStringWidth(const fontheader_t* font, const char* s);
2112
2113/*
2114=============================================================
2115
2116GHOST
2117
2118=============================================================
2119*/
2120
2121void R_UpdateGhostTextures();
2122void R_SetGhostImage(const char* name, image_t* image);
2123void LoadGHOST(const char* name, byte** pic, int* width, int* height);
2124
2125/*
2126=============================================================
2127
2128MARKS
2129
2130=============================================================
2131*/
2132void R_LevelMarksLoad(const char* szBSPName);
2133void R_LevelMarksInit();
2134void R_LevelMarksFree();
2135void R_UpdateLevelMarksSystem();
2136void R_AddPermanentMarkFragmentSurfaces(void** pFirstMarkFragment, int iNumMarkFragment);
2137
2138/*
2139=============================================================
2140
2141SKY PORTALS
2142
2143=============================================================
2144*/
2145void R_Sky_Init();
2146void R_Sky_Reset();
2147void R_Sky_AddSurf(msurface_t* surf);
2148void R_Sky_Render();
2149
2150/*
2151=============================================================
2152
2153SPRITE
2154
2155=============================================================
2156*/
2157sprite_t* SPR_RegisterSprite(const char* name);
2158void RB_DrawSprite(const refSprite_t* spr);
2159
2160
2161/*
2162=============================================================
2163
2164SUN FLARE
2165
2166=============================================================
2167*/
2168void R_InitLensFlare();
2169void R_DrawLensFlares();
2170
2171/*
2172=============================================================
2173
2174SWIPE
2175
2176=============================================================
2177*/
2178void RB_DrawSwipeSurface(surfaceType_t* pswipe);
2179void RE_SwipeBegin(float thistime, float life, qhandle_t shader);
2180void RE_SwipeEnd();
2181void R_AddSwipeSurfaces();
2182
2183/*
2184=============================================================
2185
2186TERRAIN
2187
2188=============================================================
2189*/
2190void R_MarkTerrainPatch(cTerraPatchUnpacked_t* pPatch);
2191void R_AddTerrainSurfaces();
2192void R_AddTerrainMarkSurfaces();
2193void R_InitTerrain();
2194void R_ShutdownTerrain();
2195void R_TerrainFree();
2196void R_TerrainPrepareFrame();
2197qboolean R_TerrainHeightForPoly(cTerraPatchUnpacked_t* pPatch, polyVert_t* pVerts, int nVerts);
2198void R_SwapTerraPatch(cTerraPatch_t* pPatch);
2199
2200void R_TerrainCrater_f(void);
2201
2202/*
2203=============================================================
2204
2205TIKI
2206
2207=============================================================
2208*/
2209struct skelHeaderGame_s;
2210struct skelAnimFrame_s;
2211
2212void R_InitStaticModels(void);
2213void RE_FreeModels(void);
2214qhandle_t RE_SpawnEffectModel(const char* szModel, vec3_t vPos, vec3_t* axis);
2215qhandle_t RE_RegisterServerModel(const char* name);
2216void RE_UnregisterServerModel(qhandle_t hModel);
2217orientation_t RE_TIKI_Orientation(refEntity_t* model, int tagnum);
2218qboolean RE_TIKI_IsOnGround(refEntity_t* model, int tagnum, float threshold);
2219float R_ModelRadius(qhandle_t handle);
2220void R_ModelBounds(qhandle_t handle, vec3_t mins, vec3_t maxs);
2221dtiki_t* R_Model_GetHandle(qhandle_t handle);
2222
2223float R_GetRadius(refEntity_t* model);
2224void R_GetFrame(refEntity_t* model, struct skelAnimFrame_s* newFrame);
2225void RE_ForceUpdatePose(refEntity_t* model);
2226void RE_SetFrameNumber(int frameNumber);
2227void R_UpdatePoseInternal(refEntity_t* model);
2228void RB_SkelMesh(skelSurfaceGame_t* sf);
2229void RB_StaticMesh(staticSurface_t* staticSurf);
2230void RB_Static_BuildDLights();
2231void R_InfoStaticModels_f(void);
2232void R_PrintInfoStaticModels();
2233void R_AddSkelSurfaces(trRefEntity_t* ent);
2234void R_AddStaticModelSurfaces(void);
2235void R_CountTikiLodTris(dtiki_t* tiki, float lodpercentage, int* render_tris, int* total_tris);
2236float R_CalcLod(const vec3_t origin, float radius);
2237int GetLodCutoff(struct skelHeaderGame_s* skelmodel, float lod_val, int renderfx);
2238int GetToolLodCutoff(struct skelHeaderGame_s* skelmodel, float lod_val);
2239void R_InfoWorldTris_f(void);
2240void R_PrintInfoWorldtris(void);
2241void R_DebugSkeleton(void);
2242
2243extern int g_nStaticSurfaces;
2244extern qboolean g_bInfostaticmodels;
2245extern qboolean g_bInfoworldtris;
2246
2247/*
2248=============================================================
2249
2250UTIL
2251
2252=============================================================
2253*/
2254
2255void RB_StreamBegin(shader_t* shader);
2256void RB_StreamEnd(void);
2257void RB_StreamBeginDrawSurf(void);
2258void RB_StreamEndDrawSurf(void);
2259static void addTriangle(void);
2260void RB_Vertex3fv(vec3_t v);
2261void RB_Vertex3f(vec_t x, vec_t y, vec_t z);
2262void RB_Vertex2f(vec_t x, vec_t y);
2263void RB_Color4f(vec_t r, vec_t g, vec_t b, vec_t a);
2264void RB_Color3f(vec_t r, vec_t g, vec_t b);
2265void RB_Color3fv(vec3_t col);
2266void RB_Color4bv(unsigned char* colors);
2267void RB_Texcoord2f(float s, float t);
2268void RB_Texcoord2fv(vec2_t st);
2269void R_DrawDebugNumber(const vec3_t org, float number, float scale, float r, float g, float b, int precision);
2270void R_DebugRotatedBBox(const vec3_t org, const vec3_t ang, const vec3_t mins, const vec3_t maxs, float r, float g, float b, float alpha);
2271void R_DebugCircle(const vec3_t org, float radius, float r, float g, float b, float alpha, qboolean horizontal);
2272void R_DebugLine(const vec3_t start, const vec3_t end, float r, float g, float b, float alpha);
2273int RE_GetShaderWidth(qhandle_t hShader);
2274int RE_GetShaderHeight(qhandle_t hShader);
2275const char* RE_GetShaderName(qhandle_t hShader);
2276const char* RE_GetModelName(qhandle_t hModel);
2277
2278/*
2279=============================================================
2280=============================================================
2281*/
2282void R_TransformModelToClip( const vec3_t src, const float *modelMatrix, const float *projectionMatrix,
2283 vec4_t eye, vec4_t dst );
2284void R_TransformClipToWindow( const vec4_t clip, const viewParms_t *view, vec4_t normalized, vec4_t window );
2285
2286void RB_DeformTessGeometry( void );
2287
2288void RB_CalcEnvironmentTexCoords( float *dstTexCoords );
2289void RB_CalcEnvironmentTexCoords2( float *dstTexCoords );
2290void RB_CalcSunReflectionTexCoords( float *dstTexCoords );
2291void RB_CalcOffsetTexCoords(const float* offset, float* st);
2292void RB_CalcParallaxTexCoords(const float* rate, float* st);
2293void RB_TextureAxisFromPlane(const vec3_t normal, vec3_t xv, vec3_t yv);
2294void RB_QuakeTextureVecs(const vec3_t normal, const vec2_t scale, vec3_t mappingVecs[2]);
2295void RB_CalcMacroTexCoords(const float* rate, float* st);
2296void RB_CalcScrollTexCoords( const float scroll[2], float *dstTexCoords );
2297void RB_CalcRotateTexCoords( float degsPerSecond, float degsPerSecondCoef, float* st, float start );
2298void RB_CalcScaleTexCoords( const float scale[2], float *dstTexCoords );
2299void RB_CalcTurbulentTexCoords( const waveForm_t *wf, float *dstTexCoords );
2300void RB_CalcTransformTexCoords( const texModInfo_t *tmi, float *dstTexCoords );
2301void RB_CalcWaveAlpha( const waveForm_t *wf, unsigned char *dstColors );
2302void RB_CalcWaveColor(const waveForm_t* wf, unsigned char* dstColors, unsigned char* constantColor);
2303void RB_CalcAlphaFromEntity( unsigned char *dstColors );
2304void RB_CalcAlphaFromOneMinusEntity( unsigned char *dstColors );
2305void RB_CalcStretchTexCoords( const waveForm_t *wf, float *texCoords );
2306void RB_CalcColorFromEntity( unsigned char *dstColors );
2307void RB_CalcColorFromOneMinusEntity( unsigned char *dstColors );
2308void RB_CalcColorFromConstant(unsigned char* dstColors, unsigned char* constantColor);
2309void RB_CalcRGBFromDot(unsigned char* colors, float alphaMin, float alphaMax);
2310void RB_CalcRGBFromOneMinusDot(unsigned char* colors, float alphaMin, float alphaMax);
2311void RB_CalcAlphaFromConstant(unsigned char* dstColors, int constantAlpha);
2312void RB_CalcAlphaFromDot(unsigned char* colors, float alphaMin, float alphaMax);
2313void RB_CalcAlphaFromHeightFade(unsigned char* colors, float alphaMin, float alphaMax);
2314void RB_CalcAlphaFromOneMinusDot(unsigned char* colors, float alphaMin, float alphaMax);
2315void RB_CalcAlphaFromTexCoords(unsigned char* colors, float alphaMin, float alphaMax, int alphaMinCap, int alphaCap, float sWeight, float tWeight, float* st);
2316void RB_CalcRGBFromTexCoords(unsigned char* colors, float alphaMin, float alphaMax, int alphaMinCap, int alphaCap, float sWeight, float tWeight, float* st);
2317void RB_CalcSpecularAlpha(unsigned char* alphas, float alphaMax, vec3_t lightOrigin);
2318void RB_CalcLightGridColor(unsigned char* colors);
2319void RB_CalcAlphaFromDotView(unsigned char* colors, float alphaMin, float alphaMax);
2320void RB_CalcAlphaFromOneMinusDotView(unsigned char* colors, float alphaMin, float alphaMax);
2321void RB_CalcDiffuseColor( unsigned char *colors );
2322
2323void RB_CalcStretchTexCoords(const waveForm_t* wf, float* st);
2324void RB_CalcTransWaveTexCoords(const waveForm_t* wf, float* st);
2325void RB_CalcTransWaveTexCoordsT(const waveForm_t* wf, float* st);
2326void RB_CalcBulgeTexCoords(const waveForm_t* wf, float* st);
2327
2328/*
2329=============================================================
2330
2331RENDERER BACK END FUNCTIONS
2332
2333=============================================================
2334*/
2335
2336void RB_RenderThread( void );
2337void RB_ExecuteRenderCommands( const void *data );
2338
2339/*
2340=============================================================
2341
2342RENDERER BACK END COMMAND QUEUE
2343
2344=============================================================
2345*/
2346
2347#define MAX_RENDER_COMMANDS 0x40000
2348
2349typedef struct suninfo_s {
2350 vec3_t color;
2351 vec3_t direction;
2352 vec3_t flaredirection;
2353 char szFlareName[64];
2354 qboolean exists;
2355} suninfo_t;
2356
2357extern suninfo_t s_sun;
2358
2359typedef struct {
2360 byte cmds[MAX_RENDER_COMMANDS];
2361 int used;
2363
2364typedef struct {
2365 int commandId;
2366 float color[4];
2368
2369typedef struct {
2370 int commandId;
2371 int buffer;
2373
2374typedef struct {
2375 int commandId;
2376 image_t *image;
2377 int width;
2378 int height;
2379 void *data;
2381
2382typedef struct {
2383 int commandId;
2385
2386typedef struct {
2387 int commandId;
2388 int buffer;
2390
2391typedef struct {
2392 int commandId;
2393 shader_t *shader;
2394 float x, y;
2395 float w, h;
2396 float s1, t1;
2397 float s2, t2;
2399
2400typedef struct {
2401 int commandId;
2402 trRefdef_t refdef;
2403 viewParms_t viewParms;
2404 drawSurf_t *drawSurfs;
2405 int numDrawSurfs;
2407
2408typedef struct {
2409 int commandId;
2410 int x;
2411 int y;
2412 int width;
2413 int height;
2414 char *fileName;
2415 qboolean jpeg;
2417
2418typedef struct {
2419 int commandId;
2420 int width;
2421 int height;
2422 byte *captureBuffer;
2423 byte *encodeBuffer;
2424 qboolean motionJpeg;
2426
2427typedef struct
2428{
2429 int commandId;
2430
2431 GLboolean rgba[4];
2433
2434typedef struct
2435{
2436 int commandId;
2438
2439typedef enum {
2440 RC_END_OF_LIST,
2441 RC_SET_COLOR,
2442 RC_STRETCH_PIC,
2443 RC_DRAW_SURFS,
2444 RC_SPRITE_SURFS,
2445 RC_DRAW_BUFFER,
2446 RC_SWAP_BUFFERS,
2447 RC_SCREENSHOT,
2448 RC_VIDEOFRAME,
2449 RC_COLORMASK,
2450 RC_CLEARDEPTH
2451} renderCommand_t;
2452
2453
2454// these are sort of arbitrary limits.
2455// the limits apply to the sum of all scenes in a frame --
2456// the main view, all the 3D icons, etc
2457#define MAX_POLYS 4096
2458#define MAX_POLYVERTS 16384
2459#define MAX_TERMARKS 1024
2460
2461// all of the information needed by the back end must be
2462// contained in a backEndData_t. This entire structure is
2463// duplicated so the front and back end can run in parallel
2464// on an SMP machine
2465typedef struct {
2466 drawSurf_t drawSurfs[MAX_DRAWSURFS];
2467 drawSurf_t spriteSurfs[MAX_SPRITESURFS];
2468 dlight_t dlights[MAX_DLIGHTS];
2469 trRefEntity_t entities[MAX_ENTITIES];
2470 srfMarkFragment_t* terMarks;
2471 srfPoly_t *polys;
2472 polyVert_t *polyVerts;
2473 refSprite_t sprites[2048];
2474 cStaticModelUnpacked_t* staticModels;
2475 byte* staticModelData;
2476 renderCommandList_t commands;
2478
2479extern int max_polys;
2480extern int max_polyverts;
2481extern int max_termarks;
2482
2483extern backEndData_t *backEndData; // the second one may not be allocated
2484
2485extern volatile renderCommandList_t *renderCommandList;
2486
2487extern volatile qboolean renderThreadActive;
2488
2489
2490void *R_GetCommandBuffer( int bytes );
2491void R_AddDrawSurfCmd( drawSurf_t *drawSurfs, int numDrawSurfs );
2492void R_AddSpriteSurfCmd( drawSurf_t* drawSurfs, int numDrawSurfs );
2493void RB_ExecuteRenderCommands( const void *data );
2494
2495void R_SavePerformanceCounters(void);
2496void R_InitCommandBuffers( void );
2497void R_ShutdownCommandBuffers( void );
2498
2499void R_SyncRenderThread( void );
2500
2501void R_AddDrawSurfCmd( drawSurf_t *drawSurfs, int numDrawSurfs );
2502
2503void RE_SetColor( const float *rgba );
2504void RE_StretchPic ( float x, float y, float w, float h,
2505 float s1, float t1, float s2, float t2, qhandle_t hShader );
2506void RE_BeginFrame( stereoFrame_t stereoFrame );
2507void RE_EndFrame( int *frontEndMsec, int *backEndMsec );
2508void RE_SaveJPG(char* filename, int quality, int image_width, int image_height,
2509 unsigned char* image_buffer, int padding);
2510size_t RE_SaveJPGToBuffer(byte* buffer, size_t bufSize, int quality,
2511 int image_width, int image_height, byte* image_buffer, int padding);
2512void RE_TakeVideoFrame( int width, int height,
2513 byte *captureBuffer, byte *encodeBuffer, qboolean motionJpeg );
2514
2515void SaveJPG(char * filename, int quality, int image_width, int image_height, unsigned char *image_buffer);
2516
2517void UI_LoadResource(const char* name);
2518
2519#ifdef __cplusplus
2520}
2521#endif
Definition tr_local.h:1257
Definition tr_local.h:2465
Definition tr_local.h:1273
Definition tr_local.h:1070
Definition tr_local.h:990
Definition navigation_bsp.h:149
Definition tr_local.h:959
Definition navigation_bsp.h:308
Definition tr_local.h:2435
Definition tr_local.h:2428
Definition tr_local.h:409
Definition tr_local.h:720
Definition tr_local.h:169
Definition tr_local.h:2369
Definition tr_local.h:767
Definition tr_local.h:2400
Definition qfiles.h:630
Definition qfiles.h:536
Definition tr_local.h:2386
Definition tr_local.h:542
Definition tr_local.h:707
Definition tr_local.h:1223
Definition tr_types.h:244
Definition tr_local.h:1243
Definition q_shared.h:1493
Definition tr_local.h:1042
Definition tr_local.h:1155
Definition tr_local.h:1030
Definition q_shared.h:1524
Definition tr_local.h:214
Definition tr_types.h:67
Definition tr_local.h:105
Definition tr_local.h:126
Definition tr_types.h:95
Definition tr_local.h:202
Definition tr_types.h:162
Definition tr_public.h:186
Definition tr_local.h:2359
Definition tr_local.h:2408
Definition tr_local.h:2364
Definition tr_local.h:1892
Definition tr_local.h:476
Definition tr_local.h:622
Definition tr_local.h:548
Definition skeletor.h:42
Definition tiki_shared.h:257
Definition tiki_shared.h:238
Definition tr_local.h:695
Definition tr_local.h:700
Definition tr_local.h:525
Definition tr_local.h:114
Definition tr_local.h:157
Definition tr_local.h:140
Definition tr_local.h:537
Definition tr_local.h:1080
Definition tr_local.h:794
Definition tr_local.h:800
Definition tr_local.h:807
Definition tr_local.h:787
Definition tr_local.h:779
Definition tr_local.h:985
Definition tr_local.h:845
Definition tr_local.h:942
Definition tr_local.h:872
Definition tr_local.h:1886
Definition tiki_shared.h:354
Definition tr_local.h:2391
Definition tr_local.h:2374
Definition tr_local.h:2349
Definition tr_local.h:2382
Definition tr_local.h:923
Definition navigation_bsp.h:281
Definition tr_local.h:909
Definition navigation_bsp.h:269
Definition tr_local.h:422
Definition tr_local.h:455
Definition tr_local.h:1305
Definition tr_local.h:181
Definition tr_local.h:633
Definition tr_local.h:2418
Definition tr_local.h:734
Definition tr_local.h:379
Definition tr_local.h:1089
Definition navigation_bsp.h:214