OpenMoHAA 0.82.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
727typedef struct {
728 orientationr_t ori;
729 orientationr_t world;
730 vec3_t pvsOrigin; // may be different than or.origin for portals
731 qboolean isPortal; // true if this view is through a portal
732 qboolean isMirror; // the portal is a mirror, invert the face culling
733 qboolean isPortalSky; // since 2.0 whether or not this view is a portal sky
734 int frameSceneNum; // copied from tr.frameSceneNum
735 int frameCount; // copied from tr.frameCount
736 cplane_t portalPlane; // clip anything behind this if mirroring
737 int viewportX, viewportY, viewportWidth, viewportHeight;
738 float fovX, fovY;
739 float projectionMatrix[16];
740 cplane_t frustum[5];
741 vec3_t visBounds[2];
742 float zFar;
743 depthfog_t fog;
744 float farplane_distance;
745 float farplane_bias; // added in 2.0
746 float farplane_color[3];
747 qboolean farplane_cull;
748 qboolean renderTerrain; // added in 2.0
750
751
752/*
753==============================================================================
754
755SURFACES
756
757==============================================================================
758*/
759
760typedef struct drawSurf_s {
761 unsigned sort; // bit combination for fast compares
762 surfaceType_t *surface; // any of surface*_t
763} drawSurf_t;
764
765#define MAX_FACE_POINTS 64
766
767#define MAX_PATCH_SIZE 32 // max dimensions of a patch mesh in map file
768#define MAX_GRID_SIZE 65 // max dimensions of a grid mesh in memory
769
770// when cgame directly specifies a polygon, it becomes a srfPoly_t
771// as soon as it is called
772typedef struct srfPoly_s {
773 surfaceType_t surfaceType;
774 qhandle_t hShader;
775 int numVerts;
776 polyVert_t *verts;
777 int renderfx;
778} srfPoly_t;
779
780typedef struct srfMarkFragment_s {
781 surfaceType_t surfaceType;
782 int iIndex;
783 int numVerts;
784 polyVert_t* verts;
785} srfMarkFragment_t;
786
787typedef struct srfDisplayList_s {
788 surfaceType_t surfaceType;
789 int listNum;
790} srfDisplayList_t;
791
792
793typedef struct srfFlare_s {
794 surfaceType_t surfaceType;
795 vec3_t origin;
796 vec3_t normal;
797 vec3_t color;
798} srfFlare_t;
799
800typedef struct srfGridMesh_s {
801 surfaceType_t surfaceType;
802
803 // dynamic lighting information
804 int dlightBits[SMP_FRAMES];
805 int dlightMap[SMP_FRAMES];
806
807 // culling information
808 vec3_t meshBounds[2];
809 vec3_t localOrigin;
810 float meshRadius;
811
812 // lightmap data
813 float lightmapOffset[2];
814 int lmX;
815 int lmY;
816 int lmWidth;
817 int lmHeight;
818 unsigned char *lmData;
819
820 // lod information, which may be different
821 // than the culling information to allow for
822 // groups of curves that LOD as a unit
823 vec3_t lodOrigin;
824 float lodRadius;
825 int lodFixed;
826 int lodStitched;
827
828 // vertexes
829 int width, height;
830 float *widthLodError;
831 float *heightLodError;
832 drawVert_t verts[1]; // variable sized
833} srfGridMesh_t;
834
835
836
837#define VERTEXSIZE 8
838typedef struct {
839 surfaceType_t surfaceType;
840 cplane_t plane;
841
842 // dynamic lighting information
843 int dlightBits[SMP_FRAMES];
844 int dlightMap[SMP_FRAMES];
845 float lightmapOffset[2];
846 int lmWidth;
847 int lmHeight;
848 int lmX;
849 int lmY;
850 byte* lmData;
851 vec3_t lmOrigin;
852 vec3_t lmVecs[2];
853 vec3_t lmInverseVecs[2];
854
855 // triangle definitions (no normals at points)
856 int numPoints;
857 int numIndices;
858 int ofsIndices;
859 float points[1][VERTEXSIZE]; // variable sized
860 // there is a variable length list of indices here also
862
863
864// misc_models in maps are turned into direct geometry by q3map
865typedef struct {
866 surfaceType_t surfaceType;
867
868 // dynamic lighting information
869 int dlightBits[SMP_FRAMES];
870
871 // culling information (FIXME: use this!)
872 vec3_t bounds[2];
873 vec3_t localOrigin;
874 float radius;
875
876 // triangle definitions
877 int numIndexes;
878 int *indexes;
879
880 int numVerts;
881 drawVert_t *verts;
883
884typedef union varnodeUnpacked_u {
885 float fVariance;
886 int flags;
887 /*
888 struct {
889#if !Q3_BIG_ENDIAN
890 byte flags;
891 unsigned char unused[3];
892#else
893 unsigned char unused[3];
894 byte flags;
895#endif
896 } s;
897 */
898} varnodeUnpacked_t;
899
900typedef unsigned short terraInt;
901
902typedef struct terrainVert_s {
903 vec3_t xyz;
904 vec2_t texCoords[2];
905 float fVariance;
906 float fHgtAvg;
907 float fHgtAdd;
908 unsigned int uiDistRecalc;
909 terraInt nRef;
910 terraInt iVertArray;
911 byte* pHgt;
912 terraInt iNext;
913 terraInt iPrev;
915
916typedef struct terraTri_s {
917 unsigned short iPt[3];
918 terraInt nSplit;
919 unsigned int uiDistRecalc;
920 struct cTerraPatchUnpacked_s* patch;
921 varnodeUnpacked_t* varnode;
922 terraInt index;
923 byte lod;
924 byte byConstChecks;
925 terraInt iLeft;
926 terraInt iRight;
927 terraInt iBase;
928 terraInt iLeftChild;
929 terraInt iRightChild;
930 terraInt iParent;
931 terraInt iPrev;
932 terraInt iNext;
933} terraTri_t;
934
935typedef struct srfTerrain_s {
936 surfaceType_t surfaceType;
937 terraInt iVertHead;
938 terraInt iTriHead;
939 terraInt iTriTail;
940 terraInt iMergeHead;
941 int nVerts;
942 int nTris;
943 int lmapSize;
944 int dlightBits[2];
945 float lmapStep;
946 int dlightMap[2];
947 byte* lmData;
948 float lmapX;
949 float lmapY;
950} srfTerrain_t;
951
952typedef struct cTerraPatchUnpacked_s {
953 srfTerrain_t drawinfo;
954 int viewCount;
955 int visCountCheck;
956 int visCountDraw;
957 int frameCount;
958 unsigned int uiDistRecalc;
959 float s;
960 float t;
961 vec2_t texCoord[2][2];
962 float x0;
963 float y0;
964 float z0;
965 float zmax;
966 shader_t* shader;
967 short int iNorth;
968 short int iEast;
969 short int iSouth;
970 short int iWest;
971 struct cTerraPatchUnpacked_s* pNextActive;
972 varnodeUnpacked_t varTree[2][63];
973 unsigned char heightmap[81];
974 byte flags;
975 byte byDirty;
977
978typedef struct srfStaticModel_s {
979 surfaceType_t surfaceType;
980 struct cStaticModelUnpacked_s* parent;
981} srfStaticModel_t;
982
984 qboolean useSpecialLighting;
985 qboolean bLightGridCalculated;
986 qboolean bRendered;
987 char model[128];
988 vec3_t origin;
989 vec3_t angles;
990 vec3_t axis[3];
991 float scale;
992 int firstVertexData;
993 int numVertexData;
994 int visCount;
995 dtiki_t* tiki;
996 sphere_dlight_t dlights[MAX_DLIGHTS];
997 int numdlights;
998 float radius;
999 float cull_radius;
1000 int iGridLighting;
1001 float lodpercentage[2];
1003
1004extern void (*rb_surfaceTable[SF_NUM_SURFACE_TYPES])(void *);
1005
1006/*
1007==============================================================================
1008
1009BRUSH MODELS
1010
1011==============================================================================
1012*/
1013
1014
1015//
1016// in memory representation
1017//
1018
1019#define SIDE_FRONT 0
1020#define SIDE_BACK 1
1021#define SIDE_ON 2
1022
1023typedef struct msurface_s {
1024 int viewCount; // if == tr.viewCount, already added
1025 int frameCount;
1026 struct shader_s *shader;
1027 int fogIndex;
1028
1029 surfaceType_t *data; // any of srf*_t
1030} msurface_t;
1031
1032
1033
1034#define CONTENTS_NODE -1
1035typedef struct mnode_s {
1036 // common with leaf and node
1037 int contents; // -1 for nodes, to differentiate from leafs
1038 int visframe; // node needs to be traversed if current
1039 vec3_t mins, maxs; // for bounding box culling
1040 struct mnode_s *parent;
1041
1042 // node specific
1043 cplane_t *plane;
1044 struct mnode_s *children[2];
1045
1046 // leaf specific
1047 int cluster;
1048 int area;
1049 spherel_t** lights;
1050 int numlights;
1051
1052 msurface_t **firstmarksurface;
1053 int nummarksurfaces;
1054
1055 int firstTerraPatch;
1056 int numTerraPatches;
1057 int firstStaticModel;
1058 int numStaticModels;
1059 void** pFirstMarkFragment;
1060 int iNumMarkFragment;
1061} mnode_t;
1062
1063typedef struct {
1064 vec3_t bounds[2]; // for culling
1065 msurface_t *firstSurface;
1066 int numSurfaces;
1067 void** pFirstMarkFragment;
1068 int iNumMarkFragment;
1069 int frameCount;
1070 qboolean hasLightmap;
1071} bmodel_t;
1072
1073typedef struct {
1074 float width;
1075 float height;
1076 float origin_x;
1077 float origin_y;
1078 float scale;
1079 shader_t* shader;
1080} sprite_t;
1081
1082typedef struct {
1083 char name[MAX_QPATH]; // ie: maps/tim_dm2.bsp
1084 char baseName[MAX_QPATH]; // ie: tim_dm2
1085
1086 int dataSize;
1087
1088 int numShaders;
1089 dshader_t *shaders;
1090
1091 int numBmodels;
1092 bmodel_t *bmodels;
1093
1094 int numplanes;
1095 cplane_t *planes;
1096
1097 int numnodes; // includes leafs
1098 int numDecisionNodes;
1099 mnode_t *nodes;
1100
1101 int numsurfaces;
1102 msurface_t *surfaces;
1103
1104 int nummarksurfaces;
1105 msurface_t **marksurfaces;
1106
1107 vec3_t lightGridMins;
1108 vec3_t lightGridSize;
1109 vec3_t lightGridOOSize;
1110 int lightGridBounds[3];
1111 unsigned short* lightGridOffsets;
1112 byte *lightGridData;
1113 byte lightGridPalette[768];
1114
1115 int numTerraPatches;
1116 cTerraPatchUnpacked_t* terraPatches;
1117 cTerraPatchUnpacked_t* activeTerraPatches;
1118
1119 int numVisTerraPatches;
1120 cTerraPatchUnpacked_t** visTerraPatches;
1121
1122 int numStaticModelData;
1123 byte* staticModelData;
1124
1125 int numStaticModels;
1126 cStaticModelUnpacked_t* staticModels;
1127
1128 int numVisStaticModels;
1129 cStaticModelUnpacked_t** visStaticModels;
1130
1131 int numClusters;
1132 int clusterBytes;
1133 const byte *vis; // may be passed in by CM_LoadMap to save space
1134
1135 byte *novis; // clusterBytes of 0xff
1136 byte *lighting;
1137} world_t;
1138
1139//======================================================================
1140
1141typedef enum {
1142 MOD_BAD,
1143 MOD_BRUSH,
1144 MOD_TIKI,
1145 MOD_SPRITE
1146} modtype_t;
1147
1148typedef struct model_s {
1149 char name[MAX_QPATH];
1150 modtype_t type;
1151 int index; // model = tr.models[model->index]
1152
1153 qboolean serveronly;
1154 union {
1155 bmodel_t* bmodel;
1156 dtiki_t* tiki;
1157 sprite_t* sprite;
1158 } d;
1159} model_t;
1160
1161
1162#define MAX_MOD_KNOWN 1024
1163
1164void R_ModelInit (void);
1165model_t *R_GetModelByHandle( qhandle_t hModel );
1166int R_LerpTag( orientation_t *tag, qhandle_t handle, int startFrame, int endFrame,
1167 float frac, const char *tagName );
1168
1169void R_Modellist_f (void);
1170
1171//====================================================
1172extern refimport_t ri;
1173
1174#define MAX_DRAWIMAGES 2048
1175#define MAX_LIGHTMAPS 256
1176#define MAX_SKINS 1024
1177#define MAX_SPHERE_LIGHTS 512
1178
1179#define MAX_DRAWSURFS 0x10000
1180#define MAX_SPRITESURFS 0x8000
1181#define DRAWSURF_MASK (MAX_DRAWSURFS-1)
1182
1183#define MAX_SPRITE_DIST 16384.0f
1184#define MAX_SPRITE_DIST_SQUARED (MAX_SPRITE_DIST * MAX_SPRITE_DIST)
1185
1186/*
1187
1188the drawsurf sort data is packed into a single 32 bit value so it can be
1189compared quickly during the qsorting process
1190
1191the bits are allocated as follows:
1192
119321 - 31 : sorted shader index
119411 - 20 : entity index
11952 - 6 : fog index
1196//2 : used to be clipped flag REMOVED - 03.21.00 rad
11970 - 1 : dlightmap index
1198
1199 TTimo - 1.32
120017-31 : sorted shader index
12017-16 : entity index
12022-6 : fog index
12030-1 : dlightmap index
1204*/
1205#define QSORT_SHADERNUM_SHIFT 21 // was 22, decreased in 2.30
1206#define QSORT_ENTITYNUM_SHIFT 8
1207#define QSORT_FOGNUM_SHIFT 2
1208#define QSORT_REFENTITYNUM_SHIFT 7
1209#define QSORT_STATICMODEL_SHIFT 20 // was 21, decreased in 2.30
1210
1211extern int gl_filter_min, gl_filter_max;
1212
1213/*
1214** performanceCounters_t
1215*/
1216typedef struct {
1217 int c_sphere_cull_patch_in, c_sphere_cull_patch_clip, c_sphere_cull_patch_out;
1218 int c_box_cull_patch_in, c_box_cull_patch_clip, c_box_cull_patch_out;
1219 int c_sphere_cull_md3_in, c_sphere_cull_md3_clip, c_sphere_cull_md3_out;
1220 int c_box_cull_md3_in, c_box_cull_md3_clip, c_box_cull_md3_out;
1221
1222 int c_leafs;
1223 int c_dlightSurfaces;
1224 int c_dlightSurfacesCulled;
1225 int c_dlightMaps;
1226 int c_dlightTexels;
1228
1229#define FOG_TABLE_SIZE 256
1230#define FUNCTABLE_SIZE 1024
1231#define FUNCTABLE_SIZE2 10
1232#define FUNCTABLE_MASK (FUNCTABLE_SIZE-1)
1233
1234
1235// the renderer front end should never modify glstate_t
1236typedef struct {
1237 int currenttextures[2];
1238 int currenttmu;
1239 qboolean finishCalled;
1240 int texEnv[2];
1241 int faceCulling;
1242 int cntTexEnvExt;
1243 int cntnvblendmode;
1244 long unsigned int glStateBits;
1245 long unsigned int externalSetState;
1246 vec4_t fFogColor;
1247} glstate_t;
1248
1249
1250typedef struct {
1251 int c_surfaces, c_shaders, c_vertexes, c_indexes, c_totalIndexes, c_characterlights;
1252 float c_overDraw;
1253
1254 int c_dlightVertexes;
1255 int c_dlightIndexes;
1256
1257 int c_flareAdds;
1258 int c_flareTests;
1259 int c_flareRenders;
1260
1261 int msec; // total msec for backend run
1263
1264// all state modified by the back end is seperated
1265// from the front end state
1266typedef struct {
1267 int smpFrame;
1268 trRefdef_t refdef;
1269 viewParms_t viewParms;
1270 orientationr_t ori;
1272 qboolean isHyperspace;
1273 trRefEntity_t *currentEntity;
1274 qboolean skyRenderedThisView; // flag for drawing sun
1275 sphereor_t spheres[MAX_SPHERE_LIGHTS];
1276 unsigned short numSpheresUsed;
1277 sphereor_t* currentSphere;
1278 sphereor_t spareSphere;
1279 sphereor_t hudSphere;
1280 cStaticModelUnpacked_t* currentStaticModel;
1281 int dsStreamVert;
1282 qboolean in2D; // if qtrue, drawstretchpic doesn't need to change modes
1283 byte color2D[4];
1284 qboolean vertexes2D; // shader needs to be finished
1285 trRefEntity_t entity2D; // currentEntity will point at this when doing 2D rendering
1286 int backEndMsec;
1287 float shaderStartTime;
1289
1290/*
1291** trGlobals_t
1292**
1293** Most renderer globals are defined here.
1294** backend functions should never modify any of these fields,
1295** but may read fields that aren't dynamically modified
1296** by the frontend.
1297*/
1298typedef struct {
1299 qboolean registered; // cleared at shutdown, set at beginRegistration
1300
1301 int visCount; // incremented every time a new vis cluster is entered
1302 int frameCount; // incremented every frame
1303 int sceneCount; // incremented every scene
1304 int viewCount; // incremented every view (twice a scene if portaled)
1305 // and every R_MarkFragments call
1306
1307 int smpFrame; // toggles from 0 to 1 every endFrame
1308
1309 int frameSceneNum; // zeroed at RE_BeginFrame
1310
1311 qboolean worldMapLoaded;
1312 world_t *world;
1313
1314 const byte *externalVisData; // from RE_SetWorldVisData, shared with CM_Load
1315
1316 image_t *defaultImage;
1317 image_t *scratchImage;
1318 image_t *fogImage;
1319 image_t *dlightImage; // inverse-quare highlight for projective adding
1320 image_t *flareImage;
1321 image_t *whiteImage; // full of 0xff
1322 image_t *identityLightImage; // full of tr.identityLightByte
1323 image_t *dlightImages[15];
1324
1325 shader_t *defaultShader;
1326 shader_t *shadowShader;
1327 shader_t *projectionShadowShader;
1328
1329 shader_t *flareShader;
1330 shader_t *sunShader;
1331
1332 int numLightmaps;
1333 image_t *lightmaps[MAX_LIGHTMAPS];
1334
1335 trRefEntity_t *currentEntity;
1336 trRefEntity_t worldEntity; // point currentEntity at this when rendering world
1337 int currentEntityNum;
1338 int currentSpriteNum;
1339 int shiftedEntityNum; // currentEntityNum << QSORT_ENTITYNUM_SHIFT
1340 int shiftedIsStatic;
1341 model_t *currentModel;
1342
1343 viewParms_t viewParms;
1344
1345 float identityLight; // 1.0 / ( 1 << overbrightBits )
1346 int identityLightByte; // identityLight * 255
1347 int overbrightBits; // r_overbrightBits->integer, but set to 0 if no hw gamma
1348 int overbrightShift;
1349 float overbrightMult;
1350 int needsLightScale;
1351
1352 orientationr_t ori; // for current entity
1353
1354 portalsky_t portalsky;
1355 qboolean skyRendered;
1356 qboolean portalRendered;
1357 trRefdef_t refdef;
1358
1359 int viewCluster;
1360
1361 vec3_t sunLight; // from the sky shader for this level
1362 vec3_t sunDirection;
1363
1365 int frontEndMsec; // not in pc due to clearing issue
1366
1367 //
1368 // put large tables at the end, so most elements will be
1369 // within the +/32K indexed range on risc processors
1370 //
1371 model_t models[MAX_MOD_KNOWN];
1372 int numModels;
1373
1374 int numImages;
1375 image_t images[MAX_DRAWIMAGES];
1376
1377 // shader indexes from other modules will be looked up in tr.shaders[]
1378 // shader indexes from drawsurfs will be looked up in sortedShaders[]
1379 // lower indexed sortedShaders must be rendered first (opaque surfaces before translucent)
1380 int numShaders;
1381 shader_t *shaders[MAX_SHADERS];
1382 shader_t *sortedShaders[MAX_SHADERS];
1383
1384 int numSkins;
1385 skin_t *skins[MAX_SKINS];
1386
1387 float sinTable[FUNCTABLE_SIZE];
1388 float squareTable[FUNCTABLE_SIZE];
1389 float triangleTable[FUNCTABLE_SIZE];
1390 float sawToothTable[FUNCTABLE_SIZE];
1391 float inverseSawToothTable[FUNCTABLE_SIZE];
1392
1393 spherel_t sSunLight;
1394 spherel_t sLights[1532];
1395 int numSLights;
1396 int rendererhandle;
1397 qboolean shadersParsed;
1398 int frame_skel_index;
1399 int skel_index[1024];
1400 fontheader_t* pFontDebugStrings;
1401
1402 int farclip;
1403} trGlobals_t;
1404
1405extern backEndState_t backEnd;
1406extern trGlobals_t tr;
1407extern glconfig_t glConfig; // outside of TR since it shouldn't be cleared during ref re-init
1408
1409// These variables should live inside glConfig but can't because of
1410// compatibility issues to the original ID vms. If you release a stand-alone
1411// game and your mod uses tr_types.h from this build you can safely move them
1412// to the glconfig_t struct.
1413extern qboolean textureFilterAnisotropic;
1414extern int maxAnisotropy;
1415extern float displayAspect;
1416extern qboolean haveClampToEdge;
1417
1418extern glstate_t glState; // outside of TR since it shouldn't be cleared during ref re-init
1419extern int r_sequencenumber;
1420
1421
1422//
1423// cvars
1424//
1425extern cvar_t *r_flareSize;
1426extern cvar_t *r_flareFade;
1427
1428extern cvar_t *r_ignore; // used for debugging anything
1429extern cvar_t *r_verbose; // used for verbose debug spew
1430extern cvar_t *r_ignoreFastPath; // allows us to ignore our Tess fast paths
1431
1432extern cvar_t *r_znear; // near Z clip plane
1433
1434extern cvar_t *r_stencilbits; // number of desired stencil bits
1435extern cvar_t *r_depthbits; // number of desired depth bits
1436extern cvar_t *r_colorbits; // number of desired color bits, only relevant for fullscreen
1437extern cvar_t *r_stereo; // desired pixelformat stereo flag
1438extern cvar_t *r_textureDetails;
1439extern cvar_t *r_texturebits; // number of desired texture bits
1440 // 0 = use framebuffer depth
1441 // 16 = use 16-bit textures
1442 // 32 = use 32-bit textures
1443 // all else = error
1444
1445extern cvar_t *r_measureOverdraw; // enables stencil buffer overdraw measurement
1446
1447extern cvar_t *r_lodscale;
1448
1449extern cvar_t *r_primitives; // "0" = based on compiled vertex array existance
1450 // "1" = glDrawElemet tristrips
1451 // "2" = glDrawElements triangles
1452 // "-1" = no drawing
1453
1454extern cvar_t *r_largemap;
1455extern cvar_t *r_inGameVideo; // controls whether in game video should be draw
1456extern cvar_t *r_fastsky; // controls whether sky should be cleared or drawn
1457extern cvar_t *r_fastdlights;
1458extern cvar_t *r_drawSun; // controls drawing of sun quad
1459extern cvar_t *r_dlightBacks; // dlight non-facing surfaces for continuity
1460
1461extern cvar_t *r_norefresh; // bypasses the ref rendering
1462extern cvar_t *r_drawentities; // disable/enable entity rendering
1463extern cvar_t *r_drawentitypoly;
1464extern cvar_t *r_drawstaticmodels;
1465extern cvar_t *r_drawstaticmodelpoly;
1466extern cvar_t *r_drawbrushes;
1467extern cvar_t *r_drawbrushmodels;
1468extern cvar_t *r_drawstaticdecals;
1469extern cvar_t *r_drawterrain;
1470extern cvar_t *r_drawsprites;
1471extern cvar_t *r_drawspherelights;
1472extern cvar_t *r_drawworld; // disable/enable world rendering
1473extern cvar_t *r_speeds; // various levels of information display
1474extern cvar_t *r_detailTextures; // enables/disables detail texturing stages
1475extern cvar_t *r_novis; // disable/enable usage of PVS
1476extern cvar_t *r_nocull;
1477extern cvar_t *r_showcull;
1478extern cvar_t *r_facePlaneCull; // enables culling of planar surfaces with back side test
1479extern cvar_t *r_nocurves;
1480extern cvar_t *r_showcluster;
1481
1482extern cvar_t *r_mode; // video mode
1483extern cvar_t *r_maxmode;
1484extern cvar_t *r_vidmode1024;
1485extern cvar_t *r_vidmodemax;
1486extern cvar_t *r_fullscreen;
1487extern cvar_t *r_gamma;
1488extern cvar_t *r_displayRefresh; // optional display refresh option
1489extern cvar_t *r_ignorehwgamma; // overrides hardware gamma capabilities
1490
1491extern cvar_t *r_allowExtensions; // global enable/disable of OpenGL extensions
1492extern cvar_t *r_ext_compressed_textures; // these control use of specific extensions
1493extern cvar_t *r_ext_gamma_control;
1494extern cvar_t *r_ext_texenv_op;
1495extern cvar_t *r_ext_multitexture;
1496extern cvar_t *r_ext_compiled_vertex_array;
1497extern cvar_t *r_ext_texture_env_add;
1498extern cvar_t *r_ext_texture_env_combine;
1499extern cvar_t *r_ext_aniso_filter;
1500extern cvar_t *r_ext_max_anisotropy;
1501extern cvar_t *r_forceClampToEdge;
1502extern cvar_t *r_geForce3WorkAround;
1503extern cvar_t *r_reset_tc_array;
1504
1505extern cvar_t *r_nobind; // turns off binding to appropriate textures
1506extern cvar_t *r_singleShader; // make most world faces use default shader
1507extern cvar_t *r_lerpmodels;
1508extern cvar_t *r_roundImagesDown;
1509extern cvar_t *r_colorMipLevels; // development aid to see texture mip usage
1510extern cvar_t *r_picmip; // controls picmip values
1511extern cvar_t *r_finish;
1512extern cvar_t *r_drawBuffer;
1513extern cvar_t *r_glDriver;
1514extern cvar_t *r_swapInterval;
1515extern cvar_t *r_textureMode;
1516extern cvar_t *r_offsetFactor;
1517extern cvar_t *r_offsetUnits;
1518
1519extern cvar_t *r_fullbright; // avoid lightmap pass
1520extern cvar_t *r_lightmap; // render lightmaps only
1521extern cvar_t *r_vertexLight; // vertex lighting mode for better performance
1522
1523extern cvar_t *r_logFile; // number of frames to emit GL logs
1524extern cvar_t *r_showtris; // enables wireframe rendering of the world
1525extern cvar_t *r_showsky; // forces sky in front of all surfaces
1526extern cvar_t *r_shownormals; // draws wireframe normals
1527extern cvar_t *r_showhbox;
1528extern cvar_t *r_showstaticbboxes;
1529extern cvar_t *r_clear; // force screen clear every frame
1530
1531extern cvar_t *r_shadows; // controls shadows: 0 = none, 1 = blur, 2 = stencil, 3 = black planar projection
1532extern cvar_t *r_entlight_scale;
1533extern cvar_t *r_entlight_errbound;
1534extern cvar_t *r_entlight_cubelevel;
1535extern cvar_t *r_entlight_cubefraction;
1536extern cvar_t *r_entlight_maxcalc;
1537extern cvar_t *r_flares; // light flares
1538
1539extern cvar_t *r_intensity;
1540
1541extern cvar_t *r_lockpvs;
1542extern cvar_t *r_noportals;
1543extern cvar_t *r_entlightmap;
1544extern cvar_t *r_fastentlight;
1545extern cvar_t *r_portalOnly;
1546
1547extern cvar_t *r_subdivisions;
1548extern cvar_t *r_lodCurveError;
1549extern cvar_t *r_skipBackEnd;
1550
1551extern cvar_t *r_anaglyphMode;
1552
1553extern cvar_t *r_ignoreGLErrors;
1554
1555extern cvar_t *r_overBrightBits;
1556extern cvar_t *r_mapOverBrightBits;
1557
1558extern cvar_t *r_debugSurface;
1559
1560extern cvar_t *r_showImages;
1561extern cvar_t *r_showlod;
1562extern cvar_t *r_showstaticlod;
1563extern cvar_t *r_debugSort;
1564
1565extern cvar_t *r_printShaders;
1566extern cvar_t *r_saveFontData;
1567
1568extern cvar_t* r_staticlod;
1569extern cvar_t* r_lodscale;
1570extern cvar_t* r_lodcap;
1571extern cvar_t* r_lodviewmodelcap;
1572
1573extern cvar_t* r_uselod;
1574extern cvar_t* lod_LOD;
1575extern cvar_t* lod_minLOD;
1576extern cvar_t* lod_maxLOD;
1577extern cvar_t* lod_LOD_slider;
1578extern cvar_t* lod_curve_0_val;
1579extern cvar_t* lod_curve_1_val;
1580extern cvar_t* lod_curve_2_val;
1581extern cvar_t* lod_curve_3_val;
1582extern cvar_t* lod_curve_4_val;
1583extern cvar_t* lod_edit_0;
1584extern cvar_t* lod_edit_1;
1585extern cvar_t* lod_edit_2;
1586extern cvar_t* lod_edit_3;
1587extern cvar_t* lod_edit_4;
1588extern cvar_t* lod_curve_0_slider;
1589extern cvar_t* lod_curve_1_slider;
1590extern cvar_t* lod_curve_2_slider;
1591extern cvar_t* lod_curve_3_slider;
1592extern cvar_t* lod_curve_4_slider;
1593extern cvar_t* lod_pitch_val;
1594extern cvar_t* lod_zee_val;
1595extern cvar_t* lod_mesh;
1596extern cvar_t* lod_meshname;
1597extern cvar_t* lod_tikiname;
1598extern cvar_t* lod_metric;
1599extern cvar_t* lod_tris;
1600extern cvar_t* lod_position;
1601extern cvar_t* lod_save;
1602extern cvar_t* lod_tool;
1603extern cvar_t* sys_cpuid;
1604extern cvar_t* r_sse;
1605extern cvar_t* r_static_shaderdata0;
1606extern cvar_t* r_static_shaderdata1;
1607extern cvar_t* r_static_shaderdata2;
1608extern cvar_t* r_static_shaderdata3;
1609extern cvar_t* r_static_shadermultiplier0;
1610extern cvar_t* r_static_shadermultiplier1;
1611extern cvar_t* r_static_shadermultiplier2;
1612extern cvar_t* r_static_shadermultiplier3;
1613
1614extern cvar_t* r_numdebuglines;
1615
1616extern cvar_t* r_stipplelines;
1617extern cvar_t* r_light_lines;
1618extern cvar_t* r_light_sun_line;
1619extern cvar_t* r_light_int_scale;
1620extern cvar_t* r_light_nolight;
1621extern cvar_t* r_light_showgrid;
1622extern cvar_t* r_skyportal;
1623extern cvar_t* r_skyportal_origin;
1624extern cvar_t* r_farplane;
1625extern cvar_t* r_farplane_bias;
1626extern cvar_t* r_farplane_color;
1627extern cvar_t* r_farplane_nocull;
1628extern cvar_t* r_farplane_nofog;
1629extern cvar_t* r_skybox_farplane;
1630extern cvar_t* r_farclip;
1631extern cvar_t* r_lightcoronasize;
1632extern cvar_t* r_useglfog;
1633extern cvar_t* r_debuglines_depthmask;
1634extern cvar_t* r_smoothsmokelight;
1635extern cvar_t* r_showportal;
1636extern cvar_t* ter_minMarkRadius;
1637extern cvar_t* ter_fastMarks;
1638extern cvar_t* r_alpha_foliage1;
1639extern cvar_t* r_alpha_foliage2;
1640extern cvar_t* r_blendtrees;
1641extern cvar_t* r_blendbushes;
1642extern cvar_t* r_bumpmap;
1643extern cvar_t* r_loadjpg;
1644extern cvar_t* r_loadftx;
1645
1646extern cvar_t* r_showSkeleton;
1647extern cvar_t* r_developer;
1648extern cvar_t* r_fps;
1649
1650//====================================================================
1651
1652void R_NoiseInit( void );
1653
1654void R_RenderView( viewParms_t *parms );
1655
1656qboolean SurfIsOffscreen(const srfSurfaceFace_t* surface, shader_t* shader, int entityNum);
1657
1658void R_AddMD3Surfaces( trRefEntity_t *e );
1659void R_AddNullModelSurfaces( trRefEntity_t *e );
1660void R_AddBeamSurfaces( trRefEntity_t *e );
1661void R_AddRailSurfaces( trRefEntity_t *e, qboolean isUnderwater );
1662void R_AddLightningBoltSurfaces( trRefEntity_t *e );
1663
1664void R_AddPolygonSurfaces( void );
1665
1666void R_DecomposeSort(unsigned int sort, int* entityNum, shader_t** shader, int* dlightMap, qboolean* bStaticModel);
1667
1668void R_AddDrawSurf(surfaceType_t* surface, shader_t* shader, int dlightMap);
1669
1670
1671#define CULL_IN 0 // completely unclipped
1672#define CULL_CLIP 1 // clipped by one or more planes
1673#define CULL_OUT 2 // completely outside the clipping planes
1674void R_LocalNormalToWorld (const vec3_t local, vec3_t world);
1675void R_LocalPointToWorld (const vec3_t local, vec3_t world);
1676int R_CullLocalBoxOffset(const vec3_t offset, vec3_t bounds[2]);
1677int R_CullLocalBox (vec3_t bounds[2]);
1678int R_CullPointAndRadius( vec3_t origin, float radius );
1679int R_CullLocalPointAndRadius( vec3_t origin, float radius );
1680int R_DistanceCullLocalPointAndRadius(float fDist, const vec3_t pt, float radius);
1681int R_DistanceCullPointAndRadius(float fDist, const vec3_t pt, float radius);
1682
1683void R_RotateForEntity( const trRefEntity_t *ent, const viewParms_t *viewParms, orientationr_t *ori );
1684void R_RotateForStaticModel(cStaticModelUnpacked_t* SM, const viewParms_t* viewParms, orientationr_t* ori );
1685void R_RotateForViewer(void);
1686void R_SetupFrustum(void);
1687
1688/*
1689** GL wrapper/helper functions
1690*/
1691void GL_SetFogColor(const vec4_t fColor);
1692void GL_Bind( image_t *image );
1693void GL_SetDefaultState (void);
1694void GL_SelectTexture( int unit );
1695void GL_TextureMode( const char *string );
1696void GL_CheckErrors( void );
1697void GL_State( unsigned long stateVector );
1698void GL_TexEnv( int env );
1699void GL_Cull( int cullType );
1700
1701#define GLS_SRCBLEND_ZERO 0x00000001
1702#define GLS_SRCBLEND_ONE 0x00000002
1703#define GLS_SRCBLEND_DST_COLOR 0x00000003
1704#define GLS_SRCBLEND_ONE_MINUS_DST_COLOR 0x00000004
1705#define GLS_SRCBLEND_SRC_ALPHA 0x00000005
1706#define GLS_SRCBLEND_ONE_MINUS_SRC_ALPHA 0x00000006
1707#define GLS_SRCBLEND_DST_ALPHA 0x00000007
1708#define GLS_SRCBLEND_ONE_MINUS_DST_ALPHA 0x00000008
1709#define GLS_SRCBLEND_ALPHA_SATURATE 0x00000009
1710#define GLS_SRCBLEND_BITS 0x0000000f
1711
1712#define GLS_DSTBLEND_ZERO 0x00000010
1713#define GLS_DSTBLEND_ONE 0x00000020
1714#define GLS_DSTBLEND_SRC_COLOR 0x00000030
1715#define GLS_DSTBLEND_ONE_MINUS_SRC_COLOR 0x00000040
1716#define GLS_DSTBLEND_SRC_ALPHA 0x00000050
1717#define GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA 0x00000060
1718#define GLS_DSTBLEND_DST_ALPHA 0x00000070
1719#define GLS_DSTBLEND_ONE_MINUS_DST_ALPHA 0x00000080
1720#define GLS_DSTBLEND_BITS 0x000000f0
1721
1722#define GLS_DEPTHMASK_TRUE 0x00000100
1723#define GLS_COLOR_MASK 0x00000200
1724#define GLS_POLYMODE_LINE 0x00000400
1725#define GLS_DEPTHTEST_DISABLE 0x00000800
1726#define GLS_DEPTHFUNC_EQUAL 0x00001000
1727
1728#define GLS_CLAMP_EDGE 0x00002000
1729#define GLS_MULTITEXTURE 0x00004000
1730#define GLS_MULTITEXTURE_ENV 0x00008000
1731#define GLS_FOG 0x00010000
1732
1733#define GLS_FOG_ENABLED 0x00020000
1734#define GLS_FOG_BLACK 0x00040000
1735#define GLS_FOG_WHITE 0x00080000
1736#define GLS_FOG_COLOR (GLS_FOG_BLACK | GLS_FOG_WHITE)
1737#define GLS_FOG_BITS (GLS_FOG_WHITE|GLS_FOG_BLACK|GLS_FOG_ENABLED)
1738#define GLS_COLOR_NOMASK 0x00100000
1739
1740#define GLS_ATEST_GT_0 0x10000000
1741#define GLS_ATEST_LT_80 0x20000000
1742#define GLS_ATEST_GE_80 0x30000000
1743#define GLS_ATEST_LT_FOLIAGE1 0x40000000
1744#define GLS_ATEST_GE_FOLIAGE1 0x50000000
1745#define GLS_ATEST_LT_FOLIAGE2 0x60000000
1746#define GLS_ATEST_GE_FOLIAGE2 0x70000000
1747#define GLS_ATEST_BITS 0x70000000
1748
1749#define GLS_DEFAULT GLS_DEPTHMASK_TRUE
1750
1751void Draw_SetColor(const vec4_t rgba);
1752void Draw_StretchPic(float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader);
1753void 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);
1754void Draw_TilePic(float x, float y, float w, float h, qhandle_t hShader);
1755void Draw_TilePicOffset(float x, float y, float w, float h, qhandle_t hShader, int offsetX, int offsetY);
1756void Draw_TrianglePic(const vec2_t vPoints[3], const vec2_t vTexCoords[3], qhandle_t hShader);
1757void DrawBox(float x, float y, float w, float h);
1758void AddBox(float x, float y, float w, float h);
1759void Set2DWindow(int x, int y, int w, int h, float left, float right, float bottom, float top, float n, float f);
1760void RE_Scissor(int x, int y, int width, int height);
1761void DrawLineLoop(const vec2_t* points, int count, int stipple_factor, int stipple_mask);
1762void RE_StretchRaw(int x, int y, int w, int h, int cols, int rows, int components, const byte* data);
1763void RE_UploadCinematic (int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty);
1764
1765void RE_BeginFrame( stereoFrame_t stereoFrame );
1766void RE_BeginRegistration( glconfig_t *glconfig );
1767void RE_LoadWorldMap( const char *mapname );
1768void RE_PrintBSPFileSizes(void);
1769int RE_MapVersion(void);
1770void RE_SetWorldVisData( const byte *vis );
1771qhandle_t RE_RegisterModel( const char *name );
1772qhandle_t RE_RegisterSkin( const char *name );
1773void RE_Shutdown( qboolean destroyWindow );
1774void R_ClearWorld(void);
1775
1776qboolean R_GetEntityToken( char *buffer, int size );
1777
1778model_t *R_AllocModel( void );
1779
1780void R_Init( void );
1781
1782image_t *R_FindImageFileOld(const char* name, qboolean mipmap, qboolean allowPicmip, qboolean force32bit, int glWrapClampModeX, int glWrapClampModeY);
1783image_t *R_RefreshImageFileOld(const char* name, qboolean mipmap, qboolean allowPicmip, qboolean force32bit, int glWrapClampModeX, int glWrapClampModeY);
1784
1785image_t* R_CreateImageOld(
1786 const char* name,
1787 byte* pic,
1788 int width,
1789 int height,
1790 int numMipmaps,
1791 int iMipmapsAvailable,
1792 qboolean allowPicmip,
1793 qboolean force32bit,
1794 qboolean hasAlpha,
1795 int glCompressMode,
1796 int glWrapClampModeX,
1797 int glWrapClampModeY
1798);
1799
1800qboolean R_ImageExists(const char* name);
1801int R_CountTextureMemory();
1802qboolean R_LoadRawImage(const char *name, byte **pic, int *width, int *height);
1803void R_FreeRawImage(byte *pic);
1804
1805qboolean R_GetModeInfo( int *width, int *height, float *windowAspect, int mode );
1806
1807void R_SetColorMappings( void );
1808void R_GammaCorrect( byte *buffer, int bufSize );
1809
1810void R_ImageList_f( void );
1811void R_SkinList_f( void );
1812// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=516
1813const void *RB_TakeScreenshotCmd( const void *data );
1814void R_ScreenShot_f( void );
1815
1816void R_InitImages( void );
1817void R_FreeImage(image_t* image);
1818void R_DeleteTextures( void );
1819void R_FreeUnusedImages( void );
1820int R_SumOfUsedImages( void );
1821skin_t *R_GetSkinByHandle( qhandle_t hSkin );
1822
1823const void *RB_TakeVideoFrameCmd( const void *data );
1824
1825//
1826// tr_shader.c
1827//
1828qhandle_t RE_RegisterShader( const char *name );
1829qhandle_t RE_RegisterShaderNoMip( const char *name );
1830qhandle_t RE_RefreshShaderNoMip(const char* name);
1831qhandle_t RE_RegisterShaderFromImage(const char *name, int lightmapIndex, image_t *image, qboolean mipRawImage);
1832
1833shader_t* R_FindShader(const char* name, int lightmapIndex, qboolean mipRawImage, qboolean picmip, qboolean wrapx, qboolean wrapy);
1834shader_t *R_GetShaderByHandle( qhandle_t hShader );
1835shader_t *R_GetShaderByState( int index, long *cycleTime );
1836void R_StartupShaders();
1837void R_ShutdownShaders();
1838void R_SetupShaders();
1839shader_t *R_FindShaderByName( const char *name );
1840void R_ShaderList_f( void );
1841void R_RemapShader(const char *oldShader, const char *newShader, const char *timeOffset);
1842
1843/*
1844====================================================================
1845
1846IMPLEMENTATION SPECIFIC FUNCTIONS
1847
1848====================================================================
1849*/
1850
1851void GLimp_Init( qboolean fixedFunction );
1852void GLimp_Shutdown( void );
1853void GLimp_EndFrame( void );
1854
1855qboolean GLimp_SpawnRenderThread( void (*function)( void ) );
1856void *GLimp_RendererSleep( void );
1857void GLimp_FrontEndSleep( void );
1858void GLimp_WakeRenderer( void *data );
1859
1860void GLimp_LogComment( char *comment );
1861
1862// NOTE TTimo linux works with float gamma value, not the gamma table
1863// the params won't be used, getting the r_gamma cvar directly
1864void GLimp_SetGamma( unsigned char red[256],
1865 unsigned char green[256],
1866 unsigned char blue[256] );
1867
1868
1869/*
1870====================================================================
1871
1872TESSELATOR/SHADER DECLARATIONS
1873
1874====================================================================
1875*/
1876typedef byte color4ub_t[4];
1877
1878typedef struct stageVars
1879{
1880 color4ub_t colors[SHADER_MAX_VERTEXES];
1881 vec2_t texcoords[NUM_TEXTURE_BUNDLES][SHADER_MAX_VERTEXES];
1882} stageVars_t;
1883
1884typedef struct shaderCommands_s
1885{
1886 glIndex_t indexes[SHADER_MAX_INDEXES] QALIGN(16);
1887 vec4_t xyz[SHADER_MAX_VERTEXES] QALIGN(16);
1888 vec4_t normal[SHADER_MAX_VERTEXES] QALIGN(16);
1889 vec2_t texCoords[SHADER_MAX_VERTEXES][2] QALIGN(16);
1890 color4ub_t vertexColors[SHADER_MAX_VERTEXES] QALIGN(16);
1891 int vertexDlightBits[SHADER_MAX_VERTEXES] QALIGN(16);
1892
1893 stageVars_t svars QALIGN(16);
1894
1895 color4ub_t constantColor255[SHADER_MAX_VERTEXES] QALIGN(16);
1896
1897 shader_t *shader;
1898 float shaderTime;
1899 int fogNum;
1900
1901 int dlightBits; // or together of all vertexDlightBits
1902 int dlightMap;
1903
1904 int numIndexes;
1905 int numVertexes;
1906
1907 // info extracted from current shader
1908 int numPasses;
1909 void (*currentStageIteratorFunc)( void );
1910 shaderStage_t **xstages;
1911 qboolean no_global_fog;
1912 qboolean vertexColorValid;
1913} shaderCommands_t;
1914
1915extern shaderCommands_t tess;
1916
1917void RB_BeginSurface(shader_t *shader );
1918void RB_EndSurface(void);
1919void RB_CheckOverflow( int verts, int indexes );
1920#define RB_CHECKOVERFLOW(v,i) if (tess.numVertexes + (v) >= SHADER_MAX_VERTEXES || tess.numIndexes + (i) >= SHADER_MAX_INDEXES ) {RB_CheckOverflow(v,i);}
1921
1922void RB_StageIteratorGeneric( void );
1923void RB_StageIteratorSky( void );
1924void RB_StageIteratorVertexLitTextureUnfogged( void );
1925void RB_StageIteratorLightmappedMultitextureUnfogged( void );
1926
1927void RB_AddQuadStamp( vec3_t origin, vec3_t left, vec3_t up, byte *color );
1928void RB_AddQuadStampExt( vec3_t origin, vec3_t left, vec3_t up, byte *color, float s1, float t1, float s2, float t2 );
1929
1930void RB_ShowImages( qboolean quiet );
1931
1932
1933/*
1934============================================================
1935
1936WORLD MAP
1937
1938============================================================
1939*/
1940
1941extern terraTri_t* g_pTris;
1942extern terrainVert_t* g_pVert;
1943
1944void R_AddBrushModelSurfaces( trRefEntity_t *e );
1945void R_GetInlineModelBounds(int iIndex, vec3_t vMins, vec3_t vMaxs);
1946int R_SphereInLeafs(const vec3_t p, float r, mnode_t** nodes, int nMaxNodes);
1947mnode_t* R_PointInLeaf(const vec3_t p);
1948int R_DlightTerrain(cTerraPatchUnpacked_t* surf, int dlightBits);
1949int R_CheckDlightTerrain(cTerraPatchUnpacked_t* surf, int dlightBits);
1950void R_AddWorldSurfaces( void );
1951qboolean R_inPVS( const vec3_t p1, const vec3_t p2 );
1952
1953
1954/*
1955============================================================
1956
1957FLARES
1958
1959============================================================
1960*/
1961
1962void R_ClearFlares( void );
1963
1964void RB_AddFlare( void *surface, int fogNum, vec3_t point, vec3_t color, vec3_t normal );
1965void RB_AddDlightFlares( void );
1966void RB_RenderFlares (void);
1967
1968/*
1969============================================================
1970
1971LIGHTS
1972
1973============================================================
1974*/
1975
1976void R_DlightBmodel( bmodel_t *bmodel );
1977void R_GetLightingGridValue(const vec3_t vPos, vec3_t vLight);
1978void R_GetLightingGridValueFast(const vec3_t vPos, vec3_t vLight);
1979void R_GetLightingForDecal(vec3_t vLight, const vec3_t vFacing, const vec3_t vOrigin);
1980void R_GetLightingForSmoke(vec3_t vLight, const vec3_t vOrigin);
1981void R_SetupEntityLighting( const trRefdef_t *refdef, trRefEntity_t *ent );
1982void RB_SetupEntityGridLighting();
1983void RB_SetupStaticModelGridLighting(trRefdef_t* refdef, cStaticModelUnpacked_t* ent, const vec3_t lightOrigin);
1984int R_RealDlightPatch(srfGridMesh_t* srf, int dlightBit);
1985int R_RealDlightFace(srfSurfaceFace_t* srf, int dlightBits);
1986int R_RealDlightTerrain(cTerraPatchUnpacked_t* srf, int dlightBits);
1987void R_TransformDlights( int count, dlight_t *dl, orientationr_t *ori );
1988void RB_Light_Real(unsigned char* colors);
1989void RB_Sphere_BuildDLights();
1990void RB_Sphere_SetupEntity();
1991void RB_Grid_SetupEntity();
1992void RB_Grid_SetupStaticModel();
1993void RB_Light_Fullbright(unsigned char* colors);
1994void R_Sphere_InitLights();
1995int R_GatherLightSources(const vec3_t vPos, vec3_t* pvLightPos, vec3_t* pvLightIntensity, int iMaxLights);
1996void R_ClearRealDlights();
1997void R_UploadDlights();
1998
1999int R_LightForPoint(vec3_t point, vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir);
2000
2001/*
2002============================================================
2003
2004SHADOWS
2005
2006============================================================
2007*/
2008
2009void RB_ShadowTessEnd( void );
2010void RB_ComputeShadowVolume();
2011void RB_ShadowFinish( void );
2012void RB_ProjectionShadowDeform( void );
2013
2014/*
2015============================================================
2016
2017SKIES
2018
2019============================================================
2020*/
2021
2022void R_BuildCloudData( shaderCommands_t *shader );
2023void R_InitSkyTexCoords( float cloudLayerHeight );
2024void R_DrawSkyBox( shaderCommands_t *shader );
2025void RB_DrawSun( void );
2026void RB_ClipSkyPolygons( shaderCommands_t *shader );
2027
2028/*
2029============================================================
2030
2031CURVE TESSELATION
2032
2033============================================================
2034*/
2035
2036#define PATCH_STITCHING
2037
2038srfGridMesh_t *R_SubdividePatchToGrid( int width, int height, float subdivide,
2039 drawVert_t points[MAX_PATCH_SIZE*MAX_PATCH_SIZE] );
2040srfGridMesh_t *R_GridInsertColumn( srfGridMesh_t *grid, int column, int row, vec3_t point, float loderror );
2041srfGridMesh_t *R_GridInsertRow( srfGridMesh_t *grid, int row, int column, vec3_t point, float loderror );
2042void R_FreeSurfaceGridMesh( srfGridMesh_t *grid );
2043
2044/*
2045============================================================
2046
2047MARKERS, POLYGON PROJECTION ON WORLD POLYGONS
2048
2049============================================================
2050*/
2051
2052int R_MarkFragments( int numPoints, const vec3_t *points, const vec3_t projection,
2053 int maxPoints, vec3_t pointBuffer, int maxFragments, markFragment_t *fragmentBuffer, float fRadiusSquared);
2054
2055int R_MarkFragmentsForInlineModel(clipHandle_t bmodel, const vec3_t vAngles, const vec3_t vOrigin, int numPoints,
2056 const vec3_t* points, const vec3_t projection, int maxPoints, vec3_t pointBuffer,
2057 int maxFragments, markFragment_t* fragmentBuffer, float fRadiusSquared);
2058
2059
2060/*
2061============================================================
2062
2063SCENE GENERATION
2064
2065============================================================
2066*/
2067
2068void R_InitNextFrame( void );
2069
2070void RE_ClearScene( void );
2071void RE_AddRefEntityToScene( const refEntity_t *ent, int parentEntityNumber);
2072void RE_AddRefSpriteToScene(const refEntity_t* ent);
2073void RE_AddTerrainMarkToScene(int iTerrainIndex, qhandle_t hShader, int numVerts, const polyVert_t* verts, int renderfx);
2074refEntity_t* RE_GetRenderEntity(int entityNumber);
2075qboolean RE_AddPolyToScene(qhandle_t hShader, int numVerts, const polyVert_t* verts, int renderfx);
2076void RE_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b, int type );
2077void RE_AddAdditiveLightToScene( const vec3_t org, float intensity, float r, float g, float b );
2078void RE_RenderScene( const refdef_t *fd );
2079
2080/*
2081=============================================================
2082
2083ANIMATED MODELS
2084
2085=============================================================
2086*/
2087
2088void R_MakeAnimModel( model_t *model );
2089void R_AddAnimSurfaces(trRefEntity_t* ent);
2090
2091/*
2092=============================================================
2093
2094FONT
2095
2096=============================================================
2097*/
2098void R_ShutdownFont();
2099fontheader_t* R_LoadFont(const char* name);
2100void R_LoadFontShader(fontheader_sgl_t* font);
2101void R_DrawString(fontheader_t* font, const char* text, float x, float y, int maxlen, const float *pvVirtualScreen);
2102void R_DrawFloatingString(fontheader_t* font, const char* text, const vec3_t org, const vec4_t color, float scale, int maxlen);
2103float R_GetFontHeight(const fontheader_t* font);
2104float R_GetFontStringWidth(const fontheader_t* font, const char* s);
2105
2106/*
2107=============================================================
2108
2109GHOST
2110
2111=============================================================
2112*/
2113
2114void R_UpdateGhostTextures();
2115void R_SetGhostImage(const char* name, image_t* image);
2116void LoadGHOST(const char* name, byte** pic, int* width, int* height);
2117
2118/*
2119=============================================================
2120
2121MARKS
2122
2123=============================================================
2124*/
2125void R_LevelMarksLoad(const char* szBSPName);
2126void R_LevelMarksInit();
2127void R_LevelMarksFree();
2128void R_UpdateLevelMarksSystem();
2129void R_AddPermanentMarkFragmentSurfaces(void** pFirstMarkFragment, int iNumMarkFragment);
2130
2131/*
2132=============================================================
2133
2134SKY PORTALS
2135
2136=============================================================
2137*/
2138void R_Sky_Init();
2139void R_Sky_Reset();
2140void R_Sky_AddSurf(msurface_t* surf);
2141void R_Sky_Render();
2142
2143/*
2144=============================================================
2145
2146SPRITE
2147
2148=============================================================
2149*/
2150sprite_t* SPR_RegisterSprite(const char* name);
2151void RB_DrawSprite(const refSprite_t* spr);
2152
2153
2154/*
2155=============================================================
2156
2157SUN FLARE
2158
2159=============================================================
2160*/
2161void R_InitLensFlare();
2162void R_DrawLensFlares();
2163
2164/*
2165=============================================================
2166
2167SWIPE
2168
2169=============================================================
2170*/
2171void RB_DrawSwipeSurface(surfaceType_t* pswipe);
2172void RE_SwipeBegin(float thistime, float life, qhandle_t shader);
2173void RE_SwipeEnd();
2174void R_AddSwipeSurfaces();
2175
2176/*
2177=============================================================
2178
2179TERRAIN
2180
2181=============================================================
2182*/
2183void R_MarkTerrainPatch(cTerraPatchUnpacked_t* pPatch);
2184void R_AddTerrainSurfaces();
2185void R_AddTerrainMarkSurfaces();
2186void R_InitTerrain();
2187void R_ShutdownTerrain();
2188void R_TerrainFree();
2189void R_TerrainPrepareFrame();
2190qboolean R_TerrainHeightForPoly(cTerraPatchUnpacked_t* pPatch, polyVert_t* pVerts, int nVerts);
2191void R_SwapTerraPatch(cTerraPatch_t* pPatch);
2192
2193void R_TerrainCrater_f(void);
2194
2195/*
2196=============================================================
2197
2198TIKI
2199
2200=============================================================
2201*/
2202struct skelHeaderGame_s;
2203struct skelAnimFrame_s;
2204
2205void R_InitStaticModels(void);
2206void RE_FreeModels(void);
2207qhandle_t RE_SpawnEffectModel(const char* szModel, vec3_t vPos, vec3_t* axis);
2208qhandle_t RE_RegisterServerModel(const char* name);
2209void RE_UnregisterServerModel(qhandle_t hModel);
2210orientation_t RE_TIKI_Orientation(refEntity_t* model, int tagnum);
2211qboolean RE_TIKI_IsOnGround(refEntity_t* model, int tagnum, float threshold);
2212float R_ModelRadius(qhandle_t handle);
2213void R_ModelBounds(qhandle_t handle, vec3_t mins, vec3_t maxs);
2214dtiki_t* R_Model_GetHandle(qhandle_t handle);
2215
2216float R_GetRadius(refEntity_t* model);
2217void R_GetFrame(refEntity_t* model, struct skelAnimFrame_s* newFrame);
2218void RE_ForceUpdatePose(refEntity_t* model);
2219void RE_SetFrameNumber(int frameNumber);
2220void R_UpdatePoseInternal(refEntity_t* model);
2221void RB_SkelMesh(skelSurfaceGame_t* sf);
2222void RB_StaticMesh(staticSurface_t* staticSurf);
2223void RB_Static_BuildDLights();
2224void R_InfoStaticModels_f(void);
2225void R_PrintInfoStaticModels();
2226void R_AddSkelSurfaces(trRefEntity_t* ent);
2227void R_AddStaticModelSurfaces(void);
2228void R_CountTikiLodTris(dtiki_t* tiki, float lodpercentage, int* render_tris, int* total_tris);
2229float R_CalcLod(const vec3_t origin, float radius);
2230int GetLodCutoff(struct skelHeaderGame_s* skelmodel, float lod_val, int renderfx);
2231int GetToolLodCutoff(struct skelHeaderGame_s* skelmodel, float lod_val);
2232void R_InfoWorldTris_f(void);
2233void R_PrintInfoWorldtris(void);
2234void R_DebugSkeleton(void);
2235
2236extern int g_nStaticSurfaces;
2237extern qboolean g_bInfostaticmodels;
2238extern qboolean g_bInfoworldtris;
2239
2240/*
2241=============================================================
2242
2243UTIL
2244
2245=============================================================
2246*/
2247
2248void RB_StreamBegin(shader_t* shader);
2249void RB_StreamEnd(void);
2250void RB_StreamBeginDrawSurf(void);
2251void RB_StreamEndDrawSurf(void);
2252static void addTriangle(void);
2253void RB_Vertex3fv(vec3_t v);
2254void RB_Vertex3f(vec_t x, vec_t y, vec_t z);
2255void RB_Vertex2f(vec_t x, vec_t y);
2256void RB_Color4f(vec_t r, vec_t g, vec_t b, vec_t a);
2257void RB_Color3f(vec_t r, vec_t g, vec_t b);
2258void RB_Color3fv(vec3_t col);
2259void RB_Color4bv(unsigned char* colors);
2260void RB_Texcoord2f(float s, float t);
2261void RB_Texcoord2fv(vec2_t st);
2262void R_DrawDebugNumber(const vec3_t org, float number, float scale, float r, float g, float b, int precision);
2263void 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);
2264void R_DebugCircle(const vec3_t org, float radius, float r, float g, float b, float alpha, qboolean horizontal);
2265void R_DebugLine(const vec3_t start, const vec3_t end, float r, float g, float b, float alpha);
2266int RE_GetShaderWidth(qhandle_t hShader);
2267int RE_GetShaderHeight(qhandle_t hShader);
2268const char* RE_GetShaderName(qhandle_t hShader);
2269const char* RE_GetModelName(qhandle_t hModel);
2270
2271/*
2272=============================================================
2273=============================================================
2274*/
2275void R_TransformModelToClip( const vec3_t src, const float *modelMatrix, const float *projectionMatrix,
2276 vec4_t eye, vec4_t dst );
2277void R_TransformClipToWindow( const vec4_t clip, const viewParms_t *view, vec4_t normalized, vec4_t window );
2278
2279void RB_DeformTessGeometry( void );
2280
2281void RB_CalcEnvironmentTexCoords( float *dstTexCoords );
2282void RB_CalcEnvironmentTexCoords2( float *dstTexCoords );
2283void RB_CalcSunReflectionTexCoords( float *dstTexCoords );
2284void RB_CalcOffsetTexCoords(const float* offset, float* st);
2285void RB_CalcParallaxTexCoords(const float* rate, float* st);
2286void RB_TextureAxisFromPlane(const vec3_t normal, vec3_t xv, vec3_t yv);
2287void RB_QuakeTextureVecs(const vec3_t normal, const vec2_t scale, vec3_t mappingVecs[2]);
2288void RB_CalcMacroTexCoords(const float* rate, float* st);
2289void RB_CalcScrollTexCoords( const float scroll[2], float *dstTexCoords );
2290void RB_CalcRotateTexCoords( float degsPerSecond, float degsPerSecondCoef, float* st, float start );
2291void RB_CalcScaleTexCoords( const float scale[2], float *dstTexCoords );
2292void RB_CalcTurbulentTexCoords( const waveForm_t *wf, float *dstTexCoords );
2293void RB_CalcTransformTexCoords( const texModInfo_t *tmi, float *dstTexCoords );
2294void RB_CalcWaveAlpha( const waveForm_t *wf, unsigned char *dstColors );
2295void RB_CalcWaveColor(const waveForm_t* wf, unsigned char* dstColors, unsigned char* constantColor);
2296void RB_CalcAlphaFromEntity( unsigned char *dstColors );
2297void RB_CalcAlphaFromOneMinusEntity( unsigned char *dstColors );
2298void RB_CalcStretchTexCoords( const waveForm_t *wf, float *texCoords );
2299void RB_CalcColorFromEntity( unsigned char *dstColors );
2300void RB_CalcColorFromOneMinusEntity( unsigned char *dstColors );
2301void RB_CalcColorFromConstant(unsigned char* dstColors, unsigned char* constantColor);
2302void RB_CalcRGBFromDot(unsigned char* colors, float alphaMin, float alphaMax);
2303void RB_CalcRGBFromOneMinusDot(unsigned char* colors, float alphaMin, float alphaMax);
2304void RB_CalcAlphaFromConstant(unsigned char* dstColors, int constantAlpha);
2305void RB_CalcAlphaFromDot(unsigned char* colors, float alphaMin, float alphaMax);
2306void RB_CalcAlphaFromHeightFade(unsigned char* colors, float alphaMin, float alphaMax);
2307void RB_CalcAlphaFromOneMinusDot(unsigned char* colors, float alphaMin, float alphaMax);
2308void RB_CalcAlphaFromTexCoords(unsigned char* colors, float alphaMin, float alphaMax, int alphaMinCap, int alphaCap, float sWeight, float tWeight, float* st);
2309void RB_CalcRGBFromTexCoords(unsigned char* colors, float alphaMin, float alphaMax, int alphaMinCap, int alphaCap, float sWeight, float tWeight, float* st);
2310void RB_CalcSpecularAlpha(unsigned char* alphas, float alphaMax, vec3_t lightOrigin);
2311void RB_CalcLightGridColor(unsigned char* colors);
2312void RB_CalcAlphaFromDotView(unsigned char* colors, float alphaMin, float alphaMax);
2313void RB_CalcAlphaFromOneMinusDotView(unsigned char* colors, float alphaMin, float alphaMax);
2314void RB_CalcDiffuseColor( unsigned char *colors );
2315
2316void RB_CalcStretchTexCoords(const waveForm_t* wf, float* st);
2317void RB_CalcTransWaveTexCoords(const waveForm_t* wf, float* st);
2318void RB_CalcTransWaveTexCoordsT(const waveForm_t* wf, float* st);
2319void RB_CalcBulgeTexCoords(const waveForm_t* wf, float* st);
2320
2321/*
2322=============================================================
2323
2324RENDERER BACK END FUNCTIONS
2325
2326=============================================================
2327*/
2328
2329void RB_RenderThread( void );
2330void RB_ExecuteRenderCommands( const void *data );
2331
2332/*
2333=============================================================
2334
2335RENDERER BACK END COMMAND QUEUE
2336
2337=============================================================
2338*/
2339
2340#define MAX_RENDER_COMMANDS 0x40000
2341
2342typedef struct suninfo_s {
2343 vec3_t color;
2344 vec3_t direction;
2345 vec3_t flaredirection;
2346 char szFlareName[64];
2347 qboolean exists;
2348} suninfo_t;
2349
2350extern suninfo_t s_sun;
2351
2352typedef struct {
2353 byte cmds[MAX_RENDER_COMMANDS];
2354 int used;
2356
2357typedef struct {
2358 int commandId;
2359 float color[4];
2361
2362typedef struct {
2363 int commandId;
2364 int buffer;
2366
2367typedef struct {
2368 int commandId;
2369 image_t *image;
2370 int width;
2371 int height;
2372 void *data;
2374
2375typedef struct {
2376 int commandId;
2378
2379typedef struct {
2380 int commandId;
2381 int buffer;
2383
2384typedef struct {
2385 int commandId;
2386 shader_t *shader;
2387 float x, y;
2388 float w, h;
2389 float s1, t1;
2390 float s2, t2;
2392
2393typedef struct {
2394 int commandId;
2395 trRefdef_t refdef;
2396 viewParms_t viewParms;
2397 drawSurf_t *drawSurfs;
2398 int numDrawSurfs;
2400
2401typedef struct {
2402 int commandId;
2403 int x;
2404 int y;
2405 int width;
2406 int height;
2407 char *fileName;
2408 qboolean jpeg;
2410
2411typedef struct {
2412 int commandId;
2413 int width;
2414 int height;
2415 byte *captureBuffer;
2416 byte *encodeBuffer;
2417 qboolean motionJpeg;
2419
2420typedef struct
2421{
2422 int commandId;
2423
2424 GLboolean rgba[4];
2426
2427typedef struct
2428{
2429 int commandId;
2431
2432typedef enum {
2433 RC_END_OF_LIST,
2434 RC_SET_COLOR,
2435 RC_STRETCH_PIC,
2436 RC_DRAW_SURFS,
2437 RC_SPRITE_SURFS,
2438 RC_DRAW_BUFFER,
2439 RC_SWAP_BUFFERS,
2440 RC_SCREENSHOT,
2441 RC_VIDEOFRAME,
2442 RC_COLORMASK,
2443 RC_CLEARDEPTH
2444} renderCommand_t;
2445
2446
2447// these are sort of arbitrary limits.
2448// the limits apply to the sum of all scenes in a frame --
2449// the main view, all the 3D icons, etc
2450#define MAX_POLYS 4096
2451#define MAX_POLYVERTS 16384
2452#define MAX_TERMARKS 1024
2453
2454// all of the information needed by the back end must be
2455// contained in a backEndData_t. This entire structure is
2456// duplicated so the front and back end can run in parallel
2457// on an SMP machine
2458typedef struct {
2459 drawSurf_t drawSurfs[MAX_DRAWSURFS];
2460 drawSurf_t spriteSurfs[MAX_SPRITESURFS];
2461 dlight_t dlights[MAX_DLIGHTS];
2462 trRefEntity_t entities[MAX_ENTITIES];
2463 srfMarkFragment_t* terMarks;
2464 srfPoly_t *polys;
2465 polyVert_t *polyVerts;
2466 refSprite_t sprites[2048];
2467 cStaticModelUnpacked_t* staticModels;
2468 byte* staticModelData;
2469 renderCommandList_t commands;
2471
2472extern int max_polys;
2473extern int max_polyverts;
2474extern int max_termarks;
2475
2476extern backEndData_t *backEndData; // the second one may not be allocated
2477
2478extern volatile renderCommandList_t *renderCommandList;
2479
2480extern volatile qboolean renderThreadActive;
2481
2482
2483void *R_GetCommandBuffer( int bytes );
2484void R_AddDrawSurfCmd( drawSurf_t *drawSurfs, int numDrawSurfs );
2485void R_AddSpriteSurfCmd( drawSurf_t* drawSurfs, int numDrawSurfs );
2486void RB_ExecuteRenderCommands( const void *data );
2487
2488void R_SavePerformanceCounters(void);
2489void R_InitCommandBuffers( void );
2490void R_ShutdownCommandBuffers( void );
2491
2492void R_SyncRenderThread( void );
2493
2494void R_AddDrawSurfCmd( drawSurf_t *drawSurfs, int numDrawSurfs );
2495
2496void RE_SetColor( const float *rgba );
2497void RE_StretchPic ( float x, float y, float w, float h,
2498 float s1, float t1, float s2, float t2, qhandle_t hShader );
2499void RE_BeginFrame( stereoFrame_t stereoFrame );
2500void RE_EndFrame( int *frontEndMsec, int *backEndMsec );
2501void RE_SaveJPG(char* filename, int quality, int image_width, int image_height,
2502 unsigned char* image_buffer, int padding);
2503size_t RE_SaveJPGToBuffer(byte* buffer, size_t bufSize, int quality,
2504 int image_width, int image_height, byte* image_buffer, int padding);
2505void RE_TakeVideoFrame( int width, int height,
2506 byte *captureBuffer, byte *encodeBuffer, qboolean motionJpeg );
2507
2508void SaveJPG(char * filename, int quality, int image_width, int image_height, unsigned char *image_buffer);
2509
2510void UI_LoadResource(const char* name);
2511
2512#ifdef __cplusplus
2513}
2514#endif
Definition tr_local.h:1250
Definition tr_local.h:2458
Definition tr_local.h:1266
Definition tr_local.h:1063
Definition tr_local.h:983
Definition navigation_bsp.h:148
Definition tr_local.h:952
Definition navigation_bsp.h:307
Definition tr_local.h:2428
Definition tr_local.h:2421
Definition tr_local.h:409
Definition tr_local.h:720
Definition tr_local.h:169
Definition tr_local.h:2362
Definition tr_local.h:760
Definition tr_local.h:2393
Definition qfiles.h:637
Definition qfiles.h:543
Definition tr_local.h:2379
Definition tr_local.h:542
Definition tr_local.h:707
Definition tr_local.h:1216
Definition tr_types.h:244
Definition tr_local.h:1236
Definition q_shared.h:1493
Definition tr_local.h:1035
Definition tr_local.h:1148
Definition tr_local.h:1023
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:2352
Definition tr_local.h:2401
Definition tr_local.h:2357
Definition tr_local.h:1885
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:1073
Definition tr_local.h:787
Definition tr_local.h:793
Definition tr_local.h:800
Definition tr_local.h:780
Definition tr_local.h:772
Definition tr_local.h:978
Definition tr_local.h:838
Definition tr_local.h:935
Definition tr_local.h:865
Definition tr_local.h:1879
Definition tiki_shared.h:354
Definition tr_local.h:2384
Definition tr_local.h:2367
Definition tr_local.h:2342
Definition tr_local.h:2375
Definition tr_local.h:916
Definition navigation_bsp.h:280
Definition tr_local.h:902
Definition navigation_bsp.h:268
Definition tr_local.h:422
Definition tr_local.h:455
Definition tr_local.h:1298
Definition tr_local.h:181
Definition tr_local.h:633
Definition tr_local.h:2411
Definition tr_local.h:727
Definition tr_local.h:379
Definition tr_local.h:1082
Definition navigation_bsp.h:213