Debian Codegraph @

code/renderergl1/tr_local.h

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22
23
24 #ifndef TR_LOCAL_H
25 #define TR_LOCAL_H
26
27 #include "../qcommon/q_shared.h"
28 #include "../qcommon/qfiles.h"
29 #include "../qcommon/qcommon.h"
30 #include "../renderercommon/tr_public.h"
31 #include "../renderercommon/tr_common.h"
32 #include "../renderercommon/iqm.h"
33 #include "../renderercommon/qgl.h"
34
35 #define GLE(ret, name, ...) extern name##proc * qgl##name;
36 QGL_1_1_PROCS;
37 QGL_1_1_FIXED_FUNCTION_PROCS;
38 QGL_DESKTOP_1_1_PROCS;
39 QGL_DESKTOP_1_1_FIXED_FUNCTION_PROCS;
40 QGL_3_0_PROCS;
41 #undef GLE
42
43 #define GL_INDEX_TYPE GL_UNSIGNED_INT
44 typedef unsigned int glIndex_t;
45
46 // 14 bits
47 // can't be increased without changing bit packing for drawsurfs
48 // see QSORT_SHADERNUM_SHIFT
49 #define SHADERNUM_BITS 14
50 #define MAX_SHADERS (1<<SHADERNUM_BITS)
51
52
53
54 typedef struct dlight_s {
55 vec3_t origin;
56 vec3_t color; // range from 0.0 to 1.0, should be color normalized
57 float radius;
58
59 vec3_t transformed; // origin in local coordinate system
60 int additive; // texture detail is lost tho when the lightmap is dark
61 } dlight_t;
62
63
64 // a trRefEntity_t has all the information passed in by
65 // the client game, as well as some locally derived info
66 typedef struct {
67 refEntity_t e;
68
69 float axisLength; // compensate for non-normalized axis
70
71 qboolean needDlights; // true for bmodels that touch a dlight
72 qboolean lightingCalculated;
73 vec3_t lightDir; // normalized direction towards light
74 vec3_t ambientLight; // color normalized to 0-255
75 int ambientLightInt; // 32 bit rgba packed
76 vec3_t directedLight;
77 } trRefEntity_t;
78
79
80 typedef struct {
81 vec3_t origin; // in world coordinates
82 vec3_t axis[3]; // orientation in world
83 vec3_t viewOrigin; // viewParms->or.origin in local coordinates
84 float modelMatrix[16];
85 } orientationr_t;
86
87 //===============================================================================
88
89 typedef enum {
90 SS_BAD,
91 SS_PORTAL, // mirrors, portals, viewscreens
92 SS_ENVIRONMENT, // sky box
93 SS_OPAQUE, // opaque
94
95 SS_DECAL, // scorch marks, etc.
96 SS_SEE_THROUGH, // ladders, grates, grills that may have small blended edges
97 // in addition to alpha test
98 SS_BANNER,
99
100 SS_FOG,
101
102 SS_UNDERWATER, // for items that should be drawn in front of the water plane
103
104 SS_BLEND0, // regular transparency and filters
105 SS_BLEND1, // generally only used for additive type effects
106 SS_BLEND2,
107 SS_BLEND3,
108
109 SS_BLEND6,
110 SS_STENCIL_SHADOW,
111 SS_ALMOST_NEAREST, // gun smoke puffs
112
113 SS_NEAREST // blood blobs
114 } shaderSort_t;
115
116
117 #define MAX_SHADER_STAGES 8
118
119 typedef enum {
120 GF_NONE,
121
122 GF_SIN,
123 GF_SQUARE,
124 GF_TRIANGLE,
125 GF_SAWTOOTH,
126 GF_INVERSE_SAWTOOTH,
127
128 GF_NOISE
129
130 } genFunc_t;
131
132
133 typedef enum {
134 DEFORM_NONE,
135 DEFORM_WAVE,
136 DEFORM_NORMALS,
137 DEFORM_BULGE,
138 DEFORM_MOVE,
139 DEFORM_PROJECTION_SHADOW,
140 DEFORM_AUTOSPRITE,
141 DEFORM_AUTOSPRITE2,
142 DEFORM_TEXT0,
143 DEFORM_TEXT1,
144 DEFORM_TEXT2,
145 DEFORM_TEXT3,
146 DEFORM_TEXT4,
147 DEFORM_TEXT5,
148 DEFORM_TEXT6,
149 DEFORM_TEXT7
150 } deform_t;
151
152 typedef enum {
153 AGEN_IDENTITY,
154 AGEN_SKIP,
155 AGEN_ENTITY,
156 AGEN_ONE_MINUS_ENTITY,
157 AGEN_VERTEX,
158 AGEN_ONE_MINUS_VERTEX,
159 AGEN_LIGHTING_SPECULAR,
160 AGEN_WAVEFORM,
161 AGEN_PORTAL,
162 AGEN_CONST
163 } alphaGen_t;
164
165 typedef enum {
166 CGEN_BAD,
167 CGEN_IDENTITY_LIGHTING, // tr.identityLight
168 CGEN_IDENTITY, // always (1,1,1,1)
169 CGEN_ENTITY, // grabbed from entity's modulate field
170 CGEN_ONE_MINUS_ENTITY, // grabbed from 1 - entity.modulate
171 CGEN_EXACT_VERTEX, // tess.vertexColors
172 CGEN_VERTEX, // tess.vertexColors * tr.identityLight
173 CGEN_ONE_MINUS_VERTEX,
174 CGEN_WAVEFORM, // programmatically generated
175 CGEN_LIGHTING_DIFFUSE,
176 CGEN_FOG, // standard fog
177 CGEN_CONST // fixed color
178 } colorGen_t;
179
180 typedef enum {
181 TCGEN_BAD,
182 TCGEN_IDENTITY, // clear to 0,0
183 TCGEN_LIGHTMAP,
184 TCGEN_TEXTURE,
185 TCGEN_ENVIRONMENT_MAPPED,
186 TCGEN_FOG,
187 TCGEN_VECTOR // S and T from world coordinates
188 } texCoordGen_t;
189
190 typedef enum {
191 ACFF_NONE,
192 ACFF_MODULATE_RGB,
193 ACFF_MODULATE_RGBA,
194 ACFF_MODULATE_ALPHA
195 } acff_t;
196
197 typedef struct {
198 genFunc_t func;
199
200 float base;
201 float amplitude;
202 float phase;
203 float frequency;
204 } waveForm_t;
205
206 #define TR_MAX_TEXMODS 4
207
208 typedef enum {
209 TMOD_NONE,
210 TMOD_TRANSFORM,
211 TMOD_TURBULENT,
212 TMOD_SCROLL,
213 TMOD_SCALE,
214 TMOD_STRETCH,
215 TMOD_ROTATE,
216 TMOD_ENTITY_TRANSLATE
217 } texMod_t;
218
219 #define MAX_SHADER_DEFORMS 3
220 typedef struct {
221 deform_t deformation; // vertex coordinate modification type
222
223 vec3_t moveVector;
224 waveForm_t deformationWave;
225 float deformationSpread;
226
227 float bulgeWidth;
228 float bulgeHeight;
229 float bulgeSpeed;
230 } deformStage_t;
231
232
233 typedef struct {
234 texMod_t type;
235
236 // used for TMOD_TURBULENT and TMOD_STRETCH
237 waveForm_t wave;
238
239 // used for TMOD_TRANSFORM
240 float matrix[2][2]; // s' = s * m[0][0] + t * m[1][0] + trans[0]
241 float translate[2]; // t' = s * m[0][1] + t * m[0][1] + trans[1]
242
243 // used for TMOD_SCALE
244 float scale[2]; // s *= scale[0]
245 // t *= scale[1]
246
247 // used for TMOD_SCROLL
248 float scroll[2]; // s' = s + scroll[0] * time
249 // t' = t + scroll[1] * time
250
251 // + = clockwise
252 // - = counterclockwise
253 float rotateSpeed;
254
255 } texModInfo_t;
256
257
258 #define MAX_IMAGE_ANIMATIONS 8
259
260 typedef struct {
261 image_t *image[MAX_IMAGE_ANIMATIONS];
262 int numImageAnimations;
263 float imageAnimationSpeed;
264
265 texCoordGen_t tcGen;
266 vec3_t tcGenVectors[2];
267
268 int numTexMods;
269 texModInfo_t *texMods;
270
271 int videoMapHandle;
272 qboolean isLightmap;
273 qboolean isVideoMap;
274 } textureBundle_t;
275
276 #define NUM_TEXTURE_BUNDLES 2
277
278 typedef struct {
279 qboolean active;
280
281 textureBundle_t bundle[NUM_TEXTURE_BUNDLES];
282
283 waveForm_t rgbWave;
284 colorGen_t rgbGen;
285
286 waveForm_t alphaWave;
287 alphaGen_t alphaGen;
288
289 byte constantColor[4]; // for CGEN_CONST and AGEN_CONST
290
291 unsigned stateBits; // GLS_xxxx mask
292
293 acff_t adjustColorsForFog;
294
295 qboolean isDetail;
296 } shaderStage_t;
297
298 struct shaderCommands_s;
299
300 typedef enum {
301 CT_FRONT_SIDED,
302 CT_BACK_SIDED,
303 CT_TWO_SIDED
304 } cullType_t;
305
306 typedef enum {
307 FP_NONE, // surface is translucent and will just be adjusted properly
308 FP_EQUAL, // surface is opaque but possibly alpha tested
309 FP_LE // surface is trnaslucent, but still needs a fog pass (fog surface)
310 } fogPass_t;
311
312 typedef struct {
313 float cloudHeight;
314 image_t *outerbox[6], *innerbox[6];
315 } skyParms_t;
316
317 typedef struct {
318 vec3_t color;
319 float depthForOpaque;
320 } fogParms_t;
321
322
323 typedef struct shader_s {
324 char name[MAX_QPATH]; // game path, including extension
325 int lightmapIndex; // for a shader to match, both name and lightmapIndex must match
326
327 int index; // this shader == tr.shaders[index]
328 int sortedIndex; // this shader == tr.sortedShaders[sortedIndex]
329
330 float sort; // lower numbered shaders draw before higher numbered
331
332 qboolean defaultShader; // we want to return index 0 if the shader failed to
333 // load for some reason, but R_FindShader should
334 // still keep a name allocated for it, so if
335 // something calls RE_RegisterShader again with
336 // the same name, we don't try looking for it again
337
338 qboolean explicitlyDefined; // found in a .shader file
339
340 int surfaceFlags; // if explicitlyDefined, this will have SURF_* flags
341 int contentFlags;
342
343 qboolean entityMergable; // merge across entites optimizable (smoke, blood)
344
345 qboolean isSky;
346 skyParms_t sky;
347 fogParms_t fogParms;
348
349 float portalRange; // distance to fog out at
350
351 int multitextureEnv; // 0, GL_MODULATE, GL_ADD (FIXME: put in stage)
352
353 cullType_t cullType; // CT_FRONT_SIDED, CT_BACK_SIDED, or CT_TWO_SIDED
354 qboolean polygonOffset; // set for decals and other items that must be offset
355 qboolean noMipMaps; // for console fonts, 2D elements, etc.
356 qboolean noPicMip; // for images that must always be full resolution
357
358 fogPass_t fogPass; // draw a blended pass, possibly with depth test equals
359
360 qboolean needsNormal; // not all shaders will need all data to be gathered
361 qboolean needsST1;
362 qboolean needsST2;
363 qboolean needsColor;
364
365 int numDeforms;
366 deformStage_t deforms[MAX_SHADER_DEFORMS];
367
368 int numUnfoggedPasses;
369 shaderStage_t *stages[MAX_SHADER_STAGES];
370
371 void (*optimalStageIteratorFunc)( void );
372
373 double clampTime; // time this shader is clamped to
374 double timeOffset; // current time offset for this shader
375
376 struct shader_s *remappedShader; // current shader this one is remapped too
377
378 struct shader_s *next;
379 } shader_t;
380
381
382 // trRefdef_t holds everything that comes in refdef_t,
383 // as well as the locally generated scene information
384 typedef struct {
385 int x, y, width, height;
386 float fov_x, fov_y;
387 vec3_t vieworg;
388 vec3_t viewaxis[3]; // transformation matrix
389
390 stereoFrame_t stereoFrame;
391
392 int time; // time in milliseconds for shader effects and other time dependent rendering issues
393 int rdflags; // RDF_NOWORLDMODEL, etc
394
395 // 1 bits will prevent the associated area from rendering at all
396 byte areamask[MAX_MAP_AREA_BYTES];
397 qboolean areamaskModified; // qtrue if areamask changed since last scene
398
399 double floatTime; // tr.refdef.time / 1000.0
400
401 // text messages for deform text shaders
402 char text[MAX_RENDER_STRINGS][MAX_RENDER_STRING_LENGTH];
403
404 int num_entities;
405 trRefEntity_t *entities;
406
407 int num_dlights;
408 struct dlight_s *dlights;
409
410 int numPolys;
411 struct srfPoly_s *polys;
412
413 int numDrawSurfs;
414 struct drawSurf_s *drawSurfs;
415
416
417 } trRefdef_t;
418
419
420 //=================================================================================
421
422 // max surfaces per-skin
423 // This is an arbitry limit. Vanilla Q3 only supported 32 surfaces in skins but failed to
424 // enforce the maximum limit when reading skin files. It was possile to use more than 32
425 // surfaces which accessed out of bounds memory past end of skin->surfaces hunk block.
426 #define MAX_SKIN_SURFACES 256
427
428 // skins allow models to be retextured without modifying the model file
429 typedef struct {
430 char name[MAX_QPATH];
431 shader_t *shader;
432 } skinSurface_t;
433
434 typedef struct skin_s {
435 char name[MAX_QPATH]; // game path, including extension
436 int numSurfaces;
437 skinSurface_t *surfaces; // dynamically allocated array of surfaces
438 } skin_t;
439
440
441 typedef struct {
442 int originalBrushNumber;
443 vec3_t bounds[2];
444
445 unsigned colorInt; // in packed byte format
446 float tcScale; // texture coordinate vector scales
447 fogParms_t parms;
448
449 // for clipping distance in fog when outside
450 qboolean hasSurface;
451 float surface[4];
452 } fog_t;
453
454 typedef struct {
455 orientationr_t or;
456 orientationr_t world;
457 vec3_t pvsOrigin; // may be different than or.origin for portals
458 qboolean isPortal; // true if this view is through a portal
459 qboolean isMirror; // the portal is a mirror, invert the face culling
460 int frameSceneNum; // copied from tr.frameSceneNum
461 int frameCount; // copied from tr.frameCount
462 cplane_t portalPlane; // clip anything behind this if mirroring
463 int viewportX, viewportY, viewportWidth, viewportHeight;
464 float fovX, fovY;
465 float projectionMatrix[16];
466 cplane_t frustum[4];
467 vec3_t visBounds[2];
468 float zFar;
469 stereoFrame_t stereoFrame;
470 } viewParms_t;
471
472
473 /*
474 ==============================================================================
475
476 SURFACES
477
478 ==============================================================================
479 */
480
481 // any changes in surfaceType must be mirrored in rb_surfaceTable[]
482 typedef enum {
483 SF_BAD,
484 SF_SKIP, // ignore
485 SF_FACE,
486 SF_GRID,
487 SF_TRIANGLES,
488 SF_POLY,
489 SF_MD3,
490 SF_MDR,
491 SF_IQM,
492 SF_FLARE,
493 SF_ENTITY, // beams, rails, lightning, etc that can be determined by entity
494
495 SF_NUM_SURFACE_TYPES,
496 SF_MAX = 0x7fffffff // ensures that sizeof( surfaceType_t ) == sizeof( int )
497 } surfaceType_t;
498
499 typedef struct drawSurf_s {
500 unsigned sort; // bit combination for fast compares
501 surfaceType_t *surface; // any of surface*_t
502 } drawSurf_t;
503
504 #define MAX_FACE_POINTS 64
505
506 #define MAX_PATCH_SIZE 32 // max dimensions of a patch mesh in map file
507 #define MAX_GRID_SIZE 65 // max dimensions of a grid mesh in memory
508
509 // when cgame directly specifies a polygon, it becomes a srfPoly_t
510 // as soon as it is called
511 typedef struct srfPoly_s {
512 surfaceType_t surfaceType;
513 qhandle_t hShader;
514 int fogIndex;
515 int numVerts;
516 polyVert_t *verts;
517 } srfPoly_t;
518
519
520 typedef struct srfFlare_s {
521 surfaceType_t surfaceType;
522 vec3_t origin;
523 vec3_t normal;
524 vec3_t color;
525 } srfFlare_t;
526
527 typedef struct srfGridMesh_s {
528 surfaceType_t surfaceType;
529
530 // dynamic lighting information
531 int dlightBits;
532
533 // culling information
534 vec3_t meshBounds[2];
535 vec3_t localOrigin;
536 float meshRadius;
537
538 // lod information, which may be different
539 // than the culling information to allow for
540 // groups of curves that LOD as a unit
541 vec3_t lodOrigin;
542 float lodRadius;
543 int lodFixed;
544 int lodStitched;
545
546 // vertexes
547 int width, height;
548 float *widthLodError;
549 float *heightLodError;
550 drawVert_t verts[1]; // variable sized
551 } srfGridMesh_t;
552
553
554
555 #define VERTEXSIZE 8
556 typedef struct {
557 surfaceType_t surfaceType;
558 cplane_t plane;
559
560 // dynamic lighting information
561 int dlightBits;
562
563 // triangle definitions (no normals at points)
564 int numPoints;
565 int numIndices;
566 int ofsIndices;
567 float points[1][VERTEXSIZE]; // variable sized
568 // there is a variable length list of indices here also
569 } srfSurfaceFace_t;
570
571
572 // misc_models in maps are turned into direct geometry by q3map
573 typedef struct {
574 surfaceType_t surfaceType;
575
576 // dynamic lighting information
577 int dlightBits;
578
579 // culling information (FIXME: use this!)
580 vec3_t bounds[2];
581 vec3_t localOrigin;
582 float radius;
583
584 // triangle definitions
585 int numIndexes;
586 int *indexes;
587
588 int numVerts;
589 drawVert_t *verts;
590 } srfTriangles_t;
591
592 typedef struct {
593 vec3_t translate;
594 quat_t rotate;
595 vec3_t scale;
596 } iqmTransform_t;
597
598 // inter-quake-model
599 typedef struct {
600 int num_vertexes;
601 int num_triangles;
602 int num_frames;
603 int num_surfaces;
604 int num_joints;
605 int num_poses;
606 struct srfIQModel_s *surfaces;
607
608 int *triangles;
609
610 // vertex arrays
611 float *positions;
612 float *texcoords;
613 float *normals;
614 float *tangents;
615 byte *colors;
616 int *influences; // [num_vertexes] indexes into influenceBlendVertexes
617
618 // unique list of vertex blend indexes/weights for faster CPU vertex skinning
619 byte *influenceBlendIndexes; // [num_influences]
620 union {
621 float *f;
622 byte *b;
623 } influenceBlendWeights; // [num_influences]
624
625 // depending upon the exporter, blend indices and weights might be int/float
626 // as opposed to the recommended byte/byte, for example Noesis exports
627 // int/float whereas the official IQM tool exports byte/byte
628 int blendWeightsType; // IQM_UBYTE or IQM_FLOAT
629
630 char *jointNames;
631 int *jointParents;
632 float *bindJoints; // [num_joints * 12]
633 float *invBindJoints; // [num_joints * 12]
634 iqmTransform_t *poses; // [num_frames * num_poses]
635 float *bounds;
636 } iqmData_t;
637
638 // inter-quake-model surface
639 typedef struct srfIQModel_s {
640 surfaceType_t surfaceType;
641 char name[MAX_QPATH];
642 shader_t *shader;
643 iqmData_t *data;
644 int first_vertex, num_vertexes;
645 int first_triangle, num_triangles;
646 int first_influence, num_influences;
647 } srfIQModel_t;
648
649
650 extern void (*rb_surfaceTable[SF_NUM_SURFACE_TYPES])(void *);
651
652 /*
653 ==============================================================================
654
655 BRUSH MODELS
656
657 ==============================================================================
658 */
659
660
661 //
662 // in memory representation
663 //
664
665 #define SIDE_FRONT 0
666 #define SIDE_BACK 1
667 #define SIDE_ON 2
668
669 typedef struct msurface_s {
670 int viewCount; // if == tr.viewCount, already added
671 struct shader_s *shader;
672 int fogIndex;
673
674 surfaceType_t *data; // any of srf*_t
675 } msurface_t;
676
677
678
679 #define CONTENTS_NODE -1
680 typedef struct mnode_s {
681 // common with leaf and node
682 int contents; // -1 for nodes, to differentiate from leafs
683 int visframe; // node needs to be traversed if current
684 vec3_t mins, maxs; // for bounding box culling
685 struct mnode_s *parent;
686
687 // node specific
688 cplane_t *plane;
689 struct mnode_s *children[2];
690
691 // leaf specific
692 int cluster;
693 int area;
694
695 msurface_t **firstmarksurface;
696 int nummarksurfaces;
697 } mnode_t;
698
699 typedef struct {
700 vec3_t bounds[2]; // for culling
701 msurface_t *firstSurface;
702 int numSurfaces;
703 } bmodel_t;
704
705 typedef struct {
706 char name[MAX_QPATH]; // ie: maps/tim_dm2.bsp
707 char baseName[MAX_QPATH]; // ie: tim_dm2
708
709 int dataSize;
710
711 int numShaders;
712 dshader_t *shaders;
713
714 bmodel_t *bmodels;
715
716 int numplanes;
717 cplane_t *planes;
718
719 int numnodes; // includes leafs
720 int numDecisionNodes;
721 mnode_t *nodes;
722
723 int numsurfaces;
724 msurface_t *surfaces;
725
726 int nummarksurfaces;
727 msurface_t **marksurfaces;
728
729 int numfogs;
730 fog_t *fogs;
731
732 vec3_t lightGridOrigin;
733 vec3_t lightGridSize;
734 vec3_t lightGridInverseSize;
735 int lightGridBounds[3];
736 byte *lightGridData;
737
738
739 int numClusters;
740 int clusterBytes;
741 const byte *vis; // may be passed in by CM_LoadMap to save space
742
743 byte *novis; // clusterBytes of 0xff
744
745 char *entityString;
746 char *entityParsePoint;
747 } world_t;
748
749 //======================================================================
750
751 typedef enum {
752 MOD_BAD,
753 MOD_BRUSH,
754 MOD_MESH,
755 MOD_MDR,
756 MOD_IQM
757 } modtype_t;
758
759 typedef struct model_s {
760 char name[MAX_QPATH];
761 modtype_t type;
762 int index; // model = tr.models[model->index]
763
764 int dataSize; // just for listing purposes
765 bmodel_t *bmodel; // only if type == MOD_BRUSH
766 md3Header_t *md3[MD3_MAX_LODS]; // only if type == MOD_MESH
767 void *modelData; // only if type == (MOD_MDR | MOD_IQM)
768
769 int numLods;
770 } model_t;
771
772
773 #define MAX_MOD_KNOWN 1024
774
775 void R_ModelInit (void);
776 model_t *R_GetModelByHandle( qhandle_t hModel );
777 int R_LerpTag( orientation_t *tag, qhandle_t handle, int startFrame, int endFrame,
778 float frac, const char *tagName );
779 void R_ModelBounds( qhandle_t handle, vec3_t mins, vec3_t maxs );
780
781 void R_Modellist_f (void);
782
783 //====================================================
784
785 #define MAX_DRAWIMAGES 2048
786 #define MAX_SKINS 1024
787
788
789 #define MAX_DRAWSURFS 0x10000
790 #define DRAWSURF_MASK (MAX_DRAWSURFS-1)
791
792 /*
793
794 the drawsurf sort data is packed into a single 32 bit value so it can be
795 compared quickly during the qsorting process
796
797 the bits are allocated as follows:
798
799 0 - 1 : dlightmap index
800 //2 : used to be clipped flag REMOVED - 03.21.00 rad
801 2 - 6 : fog index
802 11 - 20 : entity index
803 21 - 31 : sorted shader index
804
805 TTimo - 1.32
806 0-1 : dlightmap index
807 2-6 : fog index
808 7-16 : entity index
809 17-30 : sorted shader index
810 */
811 #define QSORT_FOGNUM_SHIFT 2
812 #define QSORT_REFENTITYNUM_SHIFT 7
813 #define QSORT_SHADERNUM_SHIFT (QSORT_REFENTITYNUM_SHIFT+REFENTITYNUM_BITS)
814 #if (QSORT_SHADERNUM_SHIFT+SHADERNUM_BITS) > 32
815 #error "Need to update sorting, too many bits."
816 #endif
817
818 extern int gl_filter_min, gl_filter_max;
819
820 /*
821 ** performanceCounters_t
822 */
823 typedef struct {
824 int c_sphere_cull_patch_in, c_sphere_cull_patch_clip, c_sphere_cull_patch_out;
825 int c_box_cull_patch_in, c_box_cull_patch_clip, c_box_cull_patch_out;
826 int c_sphere_cull_md3_in, c_sphere_cull_md3_clip, c_sphere_cull_md3_out;
827 int c_box_cull_md3_in, c_box_cull_md3_clip, c_box_cull_md3_out;
828
829 int c_leafs;
830 int c_dlightSurfaces;
831 int c_dlightSurfacesCulled;
832 } frontEndCounters_t;
833
834 #define FOG_TABLE_SIZE 256
835 #define FUNCTABLE_SIZE 1024
836 #define FUNCTABLE_SIZE2 10
837 #define FUNCTABLE_MASK (FUNCTABLE_SIZE-1)
838
839
840 // the renderer front end should never modify glstate_t
841 typedef struct {
842 int currenttextures[2];
843 int currenttmu;
844 qboolean finishCalled;
845 int texEnv[2];
846 int faceCulling;
847 unsigned long glStateBits;
848 } glstate_t;
849
850 typedef struct {
851 int c_surfaces, c_shaders, c_vertexes, c_indexes, c_totalIndexes;
852 float c_overDraw;
853
854 int c_dlightVertexes;
855 int c_dlightIndexes;
856
857 int c_flareAdds;
858 int c_flareTests;
859 int c_flareRenders;
860
861 int msec; // total msec for backend run
862 } backEndCounters_t;
863
864 // all state modified by the back end is separated
865 // from the front end state
866 typedef struct {
867 trRefdef_t refdef;
868 viewParms_t viewParms;
869 orientationr_t or;
870 backEndCounters_t pc;
871 qboolean isHyperspace;
872 trRefEntity_t *currentEntity;
873 qboolean skyRenderedThisView; // flag for drawing sun
874
875 qboolean projection2D; // if qtrue, drawstretchpic doesn't need to change modes
876 byte color2D[4];
877 qboolean vertexes2D; // shader needs to be finished
878 trRefEntity_t entity2D; // currentEntity will point at this when doing 2D rendering
879 } backEndState_t;
880
881 /*
882 ** trGlobals_t
883 **
884 ** Most renderer globals are defined here.
885 ** backend functions should never modify any of these fields,
886 ** but may read fields that aren't dynamically modified
887 ** by the frontend.
888 */
889 typedef struct {
890 qboolean registered; // cleared at shutdown, set at beginRegistration
891
892 int visCount; // incremented every time a new vis cluster is entered
893 int frameCount; // incremented every frame
894 int sceneCount; // incremented every scene
895 int viewCount; // incremented every view (twice a scene if portaled)
896 // and every R_MarkFragments call
897
898 int frameSceneNum; // zeroed at RE_BeginFrame
899
900 qboolean worldMapLoaded;
901 world_t *world;
902
903 const byte *externalVisData; // from RE_SetWorldVisData, shared with CM_Load
904
905 image_t *defaultImage;
906 image_t *scratchImage[32];
907 image_t *fogImage;
908 image_t *dlightImage; // inverse-quare highlight for projective adding
909 image_t *flareImage;
910 image_t *whiteImage; // full of 0xff
911 image_t *identityLightImage; // full of tr.identityLightByte
912
913 shader_t *defaultShader;
914 shader_t *shadowShader;
915 shader_t *projectionShadowShader;
916
917 shader_t *flareShader;
918 shader_t *sunShader;
919
920 int numLightmaps;
921 image_t **lightmaps;
922
923 trRefEntity_t *currentEntity;
924 trRefEntity_t worldEntity; // point currentEntity at this when rendering world
925 int currentEntityNum;
926 int shiftedEntityNum; // currentEntityNum << QSORT_REFENTITYNUM_SHIFT
927 model_t *currentModel;
928
929 viewParms_t viewParms;
930
931 float identityLight; // 1.0 / ( 1 << overbrightBits )
932 int identityLightByte; // identityLight * 255
933 int overbrightBits; // r_overbrightBits->integer, but set to 0 if no hw gamma
934
935 orientationr_t or; // for current entity
936
937 trRefdef_t refdef;
938
939 int viewCluster;
940
941 vec3_t sunLight; // from the sky shader for this level
942 vec3_t sunDirection;
943
944 frontEndCounters_t pc;
945 int frontEndMsec; // not in pc due to clearing issue
946
947 //
948 // put large tables at the end, so most elements will be
949 // within the +/32K indexed range on risc processors
950 //
951 model_t *models[MAX_MOD_KNOWN];
952 int numModels;
953
954 int numImages;
955 image_t *images[MAX_DRAWIMAGES];
956
957 // shader indexes from other modules will be looked up in tr.shaders[]
958 // shader indexes from drawsurfs will be looked up in sortedShaders[]
959 // lower indexed sortedShaders must be rendered first (opaque surfaces before translucent)
960 int numShaders;
961 shader_t *shaders[MAX_SHADERS];
962 shader_t *sortedShaders[MAX_SHADERS];
963
964 int numSkins;
965 skin_t *skins[MAX_SKINS];
966
967 float sinTable[FUNCTABLE_SIZE];
968 float squareTable[FUNCTABLE_SIZE];
969 float triangleTable[FUNCTABLE_SIZE];
970 float sawToothTable[FUNCTABLE_SIZE];
971 float inverseSawToothTable[FUNCTABLE_SIZE];
972 float fogTable[FOG_TABLE_SIZE];
973 } trGlobals_t;
974
975 extern backEndState_t backEnd;
976 extern trGlobals_t tr;
977 extern glstate_t glState; // outside of TR since it shouldn't be cleared during ref re-init
978
979 //
980 // cvars
981 //
982 extern cvar_t *r_flareSize;
983 extern cvar_t *r_flareFade;
984 // coefficient for the flare intensity falloff function.
985 #define FLARE_STDCOEFF "150"
986 extern cvar_t *r_flareCoeff;
987
988 extern cvar_t *r_railWidth;
989 extern cvar_t *r_railCoreWidth;
990 extern cvar_t *r_railSegmentLength;
991
992 extern cvar_t *r_ignore; // used for debugging anything
993 extern cvar_t *r_verbose; // used for verbose debug spew
994 extern cvar_t *r_ignoreFastPath; // allows us to ignore our Tess fast paths
995
996 extern cvar_t *r_znear; // near Z clip plane
997 extern cvar_t *r_zproj; // z distance of projection plane
998 extern cvar_t *r_stereoSeparation; // separation of cameras for stereo rendering
999
1000 extern cvar_t *r_measureOverdraw; // enables stencil buffer overdraw measurement
1001
1002 extern cvar_t *r_lodbias; // push/pull LOD transitions
1003 extern cvar_t *r_lodscale;
1004
1005 extern cvar_t *r_primitives; // "0" = based on compiled vertex array existence
1006 // "1" = glDrawElemet tristrips
1007 // "2" = glDrawElements triangles
1008 // "-1" = no drawing
1009
1010 extern cvar_t *r_inGameVideo; // controls whether in game video should be draw
1011 extern cvar_t *r_fastsky; // controls whether sky should be cleared or drawn
1012 extern cvar_t *r_drawSun; // controls drawing of sun quad
1013 extern cvar_t *r_dynamiclight; // dynamic lights enabled/disabled
1014 extern cvar_t *r_dlightBacks; // dlight non-facing surfaces for continuity
1015
1016 extern cvar_t *r_norefresh; // bypasses the ref rendering
1017 extern cvar_t *r_drawentities; // disable/enable entity rendering
1018 extern cvar_t *r_drawworld; // disable/enable world rendering
1019 extern cvar_t *r_speeds; // various levels of information display
1020 extern cvar_t *r_detailTextures; // enables/disables detail texturing stages
1021 extern cvar_t *r_novis; // disable/enable usage of PVS
1022 extern cvar_t *r_nocull;
1023 extern cvar_t *r_facePlaneCull; // enables culling of planar surfaces with back side test
1024 extern cvar_t *r_nocurves;
1025 extern cvar_t *r_showcluster;
1026
1027 extern cvar_t *r_gamma;
1028 extern cvar_t *r_displayRefresh; // optional display refresh option
1029
1030 extern cvar_t *r_nobind; // turns off binding to appropriate textures
1031 extern cvar_t *r_singleShader; // make most world faces use default shader
1032 extern cvar_t *r_roundImagesDown;
1033 extern cvar_t *r_colorMipLevels; // development aid to see texture mip usage
1034 extern cvar_t *r_picmip; // controls picmip values
1035 extern cvar_t *r_finish;
1036 extern cvar_t *r_textureMode;
1037 extern cvar_t *r_offsetFactor;
1038 extern cvar_t *r_offsetUnits;
1039
1040 extern cvar_t *r_fullbright; // avoid lightmap pass
1041 extern cvar_t *r_lightmap; // render lightmaps only
1042 extern cvar_t *r_vertexLight; // vertex lighting mode for better performance
1043 extern cvar_t *r_uiFullScreen; // ui is running fullscreen
1044
1045 extern cvar_t *r_logFile; // number of frames to emit GL logs
1046 extern cvar_t *r_showtris; // enables wireframe rendering of the world
1047 extern cvar_t *r_showsky; // forces sky in front of all surfaces
1048 extern cvar_t *r_shownormals; // draws wireframe normals
1049 extern cvar_t *r_clear; // force screen clear every frame
1050
1051 extern cvar_t *r_shadows; // controls shadows: 0 = none, 1 = blur, 2 = stencil, 3 = black planar projection
1052 extern cvar_t *r_flares; // light flares
1053
1054 extern cvar_t *r_intensity;
1055
1056 extern cvar_t *r_lockpvs;
1057 extern cvar_t *r_noportals;
1058 extern cvar_t *r_portalOnly;
1059
1060 extern cvar_t *r_subdivisions;
1061 extern cvar_t *r_lodCurveError;
1062 extern cvar_t *r_skipBackEnd;
1063
1064 extern cvar_t *r_anaglyphMode;
1065
1066 extern cvar_t *r_greyscale;
1067
1068 extern cvar_t *r_ignoreGLErrors;
1069
1070 extern cvar_t *r_overBrightBits;
1071 extern cvar_t *r_mapOverBrightBits;
1072
1073 extern cvar_t *r_debugSurface;
1074 extern cvar_t *r_simpleMipMaps;
1075
1076 extern cvar_t *r_showImages;
1077 extern cvar_t *r_debugSort;
1078
1079 extern cvar_t *r_printShaders;
1080
1081 extern cvar_t *r_marksOnTriangleMeshes;
1082
1083 //====================================================================
1084
1085 void R_SwapBuffers( int );
1086
1087 void R_RenderView( viewParms_t *parms );
1088
1089 void R_AddMD3Surfaces( trRefEntity_t *e );
1090 void R_AddNullModelSurfaces( trRefEntity_t *e );
1091 void R_AddBeamSurfaces( trRefEntity_t *e );
1092 void R_AddRailSurfaces( trRefEntity_t *e, qboolean isUnderwater );
1093 void R_AddLightningBoltSurfaces( trRefEntity_t *e );
1094
1095 void R_AddPolygonSurfaces( void );
1096
1097 void R_DecomposeSort( unsigned sort, int *entityNum, shader_t **shader,
1098 int *fogNum, int *dlightMap );
1099
1100 void R_AddDrawSurf( surfaceType_t *surface, shader_t *shader, int fogIndex, int dlightMap );
1101
1102
1103 #define CULL_IN 0 // completely unclipped
1104 #define CULL_CLIP 1 // clipped by one or more planes
1105 #define CULL_OUT 2 // completely outside the clipping planes
1106 void R_LocalNormalToWorld (vec3_t local, vec3_t world);
1107 void R_LocalPointToWorld (vec3_t local, vec3_t world);
1108 int R_CullLocalBox (vec3_t bounds[2]);
1109 int R_CullPointAndRadius( vec3_t origin, float radius );
1110 int R_CullLocalPointAndRadius( vec3_t origin, float radius );
1111
1112 void R_SetupProjection(viewParms_t *dest, float zProj, qboolean computeFrustum);
1113 void R_RotateForEntity( const trRefEntity_t *ent, const viewParms_t *viewParms, orientationr_t *or );
1114
1115 /*
1116 ** GL wrapper/helper functions
1117 */
1118 void GL_Bind( image_t *image );
1119 void GL_SetDefaultState (void);
1120 void GL_SelectTexture( int unit );
1121 void GL_TextureMode( const char *string );
1122 void GL_CheckErrors( void );
1123 void GL_State( unsigned long stateVector );
1124 void GL_TexEnv( int env );
1125 void GL_Cull( int cullType );
1126
1127 #define GLS_SRCBLEND_ZERO 0x00000001
1128 #define GLS_SRCBLEND_ONE 0x00000002
1129 #define GLS_SRCBLEND_DST_COLOR 0x00000003
1130 #define GLS_SRCBLEND_ONE_MINUS_DST_COLOR 0x00000004
1131 #define GLS_SRCBLEND_SRC_ALPHA 0x00000005
1132 #define GLS_SRCBLEND_ONE_MINUS_SRC_ALPHA 0x00000006
1133 #define GLS_SRCBLEND_DST_ALPHA 0x00000007
1134 #define GLS_SRCBLEND_ONE_MINUS_DST_ALPHA 0x00000008
1135 #define GLS_SRCBLEND_ALPHA_SATURATE 0x00000009
1136 #define GLS_SRCBLEND_BITS 0x0000000f
1137
1138 #define GLS_DSTBLEND_ZERO 0x00000010
1139 #define GLS_DSTBLEND_ONE 0x00000020
1140 #define GLS_DSTBLEND_SRC_COLOR 0x00000030
1141 #define GLS_DSTBLEND_ONE_MINUS_SRC_COLOR 0x00000040
1142 #define GLS_DSTBLEND_SRC_ALPHA 0x00000050
1143 #define GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA 0x00000060
1144 #define GLS_DSTBLEND_DST_ALPHA 0x00000070
1145 #define GLS_DSTBLEND_ONE_MINUS_DST_ALPHA 0x00000080
1146 #define GLS_DSTBLEND_BITS 0x000000f0
1147
1148 #define GLS_DEPTHMASK_TRUE 0x00000100
1149
1150 #define GLS_POLYMODE_LINE 0x00001000
1151
1152 #define GLS_DEPTHTEST_DISABLE 0x00010000
1153 #define GLS_DEPTHFUNC_EQUAL 0x00020000
1154
1155 #define GLS_ATEST_GT_0 0x10000000
1156 #define GLS_ATEST_LT_80 0x20000000
1157 #define GLS_ATEST_GE_80 0x40000000
1158 #define GLS_ATEST_BITS 0x70000000
1159
1160 #define GLS_DEFAULT GLS_DEPTHMASK_TRUE
1161
1162 void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty);
1163 void RE_UploadCinematic (int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty);
1164
1165 void RE_BeginFrame( stereoFrame_t stereoFrame );
1166 void RE_BeginRegistration( glconfig_t *glconfig );
1167 void RE_LoadWorldMap( const char *mapname );
1168 void RE_SetWorldVisData( const byte *vis );
1169 qhandle_t RE_RegisterModel( const char *name );
1170 qhandle_t RE_RegisterSkin( const char *name );
1171 void RE_Shutdown( qboolean destroyWindow );
1172
1173 qboolean R_GetEntityToken( char *buffer, int size );
1174
1175 model_t *R_AllocModel( void );
1176
1177 void R_Init( void );
1178
1179 void R_SetColorMappings( void );
1180 void R_GammaCorrect( byte *buffer, int bufSize );
1181
1182 void R_ImageList_f( void );
1183 void R_SkinList_f( void );
1184 // https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=516
1185 const void *RB_TakeScreenshotCmd( const void *data );
1186 void R_ScreenShot_f( void );
1187
1188 void R_InitFogTable( void );
1189 float R_FogFactor( float s, float t );
1190 void R_InitImages( void );
1191 void R_DeleteTextures( void );
1192 int R_SumOfUsedImages( void );
1193 void R_InitSkins( void );
1194 skin_t *R_GetSkinByHandle( qhandle_t hSkin );
1195
1196 int R_ComputeLOD( trRefEntity_t *ent );
1197
1198 const void *RB_TakeVideoFrameCmd( const void *data );
1199
1200 //
1201 // tr_shader.c
1202 //
1203 shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImage );
1204 shader_t *R_GetShaderByHandle( qhandle_t hShader );
1205 shader_t *R_GetShaderByState( int index, long *cycleTime );
1206 shader_t *R_FindShaderByName( const char *name );
1207 void R_InitShaders( void );
1208 void R_ShaderList_f( void );
1209 void R_RemapShader(const char *oldShader, const char *newShader, const char *timeOffset);
1210
1211 /*
1212 ====================================================================
1213
1214 TESSELATOR/SHADER DECLARATIONS
1215
1216 ====================================================================
1217 */
1218 typedef byte color4ub_t[4];
1219
1220 typedef struct stageVars
1221 {
1222 color4ub_t colors[SHADER_MAX_VERTEXES];
1223 vec2_t texcoords[NUM_TEXTURE_BUNDLES][SHADER_MAX_VERTEXES];
1224 } stageVars_t;
1225
1226
1227 typedef struct shaderCommands_s
1228 {
1229 glIndex_t indexes[SHADER_MAX_INDEXES] Q_ALIGN(16);
1230 vec4_t xyz[SHADER_MAX_VERTEXES] Q_ALIGN(16);
1231 vec4_t normal[SHADER_MAX_VERTEXES] Q_ALIGN(16);
1232 vec2_t texCoords[SHADER_MAX_VERTEXES][2] Q_ALIGN(16);
1233 color4ub_t vertexColors[SHADER_MAX_VERTEXES] Q_ALIGN(16);
1234 int vertexDlightBits[SHADER_MAX_VERTEXES] Q_ALIGN(16);
1235
1236 stageVars_t svars Q_ALIGN(16);
1237
1238 color4ub_t constantColor255[SHADER_MAX_VERTEXES] Q_ALIGN(16);
1239
1240 shader_t *shader;
1241 double shaderTime;
1242 int fogNum;
1243
1244 int dlightBits; // or together of all vertexDlightBits
1245
1246 int numIndexes;
1247 int numVertexes;
1248
1249 // info extracted from current shader
1250 int numPasses;
1251 void (*currentStageIteratorFunc)( void );
1252 shaderStage_t **xstages;
1253 } shaderCommands_t;
1254
1255 extern shaderCommands_t tess;
1256
1257 void RB_BeginSurface(shader_t *shader, int fogNum );
1258 void RB_EndSurface(void);
1259 void RB_CheckOverflow( int verts, int indexes );
1260 #define RB_CHECKOVERFLOW(v,i) if (tess.numVertexes + (v) >= SHADER_MAX_VERTEXES || tess.numIndexes + (i) >= SHADER_MAX_INDEXES ) {RB_CheckOverflow(v,i);}
1261
1262 void RB_StageIteratorGeneric( void );
1263 void RB_StageIteratorSky( void );
1264 void RB_StageIteratorVertexLitTexture( void );
1265 void RB_StageIteratorLightmappedMultitexture( void );
1266
1267 void RB_AddQuadStamp( vec3_t origin, vec3_t left, vec3_t up, byte *color );
1268 void RB_AddQuadStampExt( vec3_t origin, vec3_t left, vec3_t up, byte *color, float s1, float t1, float s2, float t2 );
1269
1270 void RB_ShowImages( void );
1271
1272
1273 /*
1274 ============================================================
1275
1276 WORLD MAP
1277
1278 ============================================================
1279 */
1280
1281 void R_AddBrushModelSurfaces( trRefEntity_t *e );
1282 void R_AddWorldSurfaces( void );
1283 qboolean R_inPVS( const vec3_t p1, const vec3_t p2 );
1284
1285
1286 /*
1287 ============================================================
1288
1289 FLARES
1290
1291 ============================================================
1292 */
1293
1294 void R_ClearFlares( void );
1295
1296 void RB_AddFlare( void *surface, int fogNum, vec3_t point, vec3_t color, vec3_t normal );
1297 void RB_AddDlightFlares( void );
1298 void RB_RenderFlares (void);
1299
1300 /*
1301 ============================================================
1302
1303 LIGHTS
1304
1305 ============================================================
1306 */
1307
1308 void R_DlightBmodel( bmodel_t *bmodel );
1309 void R_SetupEntityLighting( const trRefdef_t *refdef, trRefEntity_t *ent );
1310 void R_TransformDlights( int count, dlight_t *dl, orientationr_t *or );
1311 int R_LightForPoint( vec3_t point, vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir );
1312
1313
1314 /*
1315 ============================================================
1316
1317 SHADOWS
1318
1319 ============================================================
1320 */
1321
1322 void RB_ShadowTessEnd( void );
1323 void RB_ShadowFinish( void );
1324 void RB_ProjectionShadowDeform( void );
1325
1326 /*
1327 ============================================================
1328
1329 SKIES
1330
1331 ============================================================
1332 */
1333
1334 void R_BuildCloudData( shaderCommands_t *shader );
1335 void R_InitSkyTexCoords( float cloudLayerHeight );
1336 void R_DrawSkyBox( shaderCommands_t *shader );
1337 void RB_DrawSun( float scale, shader_t *shader );
1338 void RB_ClipSkyPolygons( shaderCommands_t *shader );
1339
1340 /*
1341 ============================================================
1342
1343 CURVE TESSELATION
1344
1345 ============================================================
1346 */
1347
1348 #define PATCH_STITCHING
1349
1350 srfGridMesh_t *R_SubdividePatchToGrid( int width, int height,
1351 drawVert_t points[MAX_PATCH_SIZE*MAX_PATCH_SIZE] );
1352 srfGridMesh_t *R_GridInsertColumn( srfGridMesh_t *grid, int column, int row, vec3_t point, float loderror );
1353 srfGridMesh_t *R_GridInsertRow( srfGridMesh_t *grid, int row, int column, vec3_t point, float loderror );
1354 void R_FreeSurfaceGridMesh( srfGridMesh_t *grid );
1355
1356 /*
1357 ============================================================
1358
1359 MARKERS, POLYGON PROJECTION ON WORLD POLYGONS
1360
1361 ============================================================
1362 */
1363
1364 int R_MarkFragments( int numPoints, const vec3_t *points, const vec3_t projection,
1365 int maxPoints, vec3_t pointBuffer, int maxFragments, markFragment_t *fragmentBuffer );
1366
1367
1368 /*
1369 ============================================================
1370
1371 SCENE GENERATION
1372
1373 ============================================================
1374 */
1375
1376 void R_InitNextFrame( void );
1377
1378 void RE_ClearScene( void );
1379 void RE_AddRefEntityToScene( const refEntity_t *ent );
1380 void RE_AddPolyToScene( qhandle_t hShader , int numVerts, const polyVert_t *verts, int num );
1381 void RE_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b );
1382 void RE_AddAdditiveLightToScene( const vec3_t org, float intensity, float r, float g, float b );
1383 void RE_RenderScene( const refdef_t *fd );
1384
1385 /*
1386 =============================================================
1387
1388 UNCOMPRESSING BONES
1389
1390 =============================================================
1391 */
1392
1393 #define MC_BITS_X (16)
1394 #define MC_BITS_Y (16)
1395 #define MC_BITS_Z (16)
1396 #define MC_BITS_VECT (16)
1397
1398 #define MC_SCALE_X (1.0f/64)
1399 #define MC_SCALE_Y (1.0f/64)
1400 #define MC_SCALE_Z (1.0f/64)
1401
1402 void MC_UnCompress(float mat[3][4],const unsigned char * comp);
1403
1404 /*
1405 =============================================================
1406
1407 ANIMATED MODELS
1408
1409 =============================================================
1410 */
1411
1412 void R_MDRAddAnimSurfaces( trRefEntity_t *ent );
1413 void RB_MDRSurfaceAnim( mdrSurface_t *surface );
1414 qboolean R_LoadIQM (model_t *mod, void *buffer, int filesize, const char *name );
1415 void R_AddIQMSurfaces( trRefEntity_t *ent );
1416 void RB_IQMSurfaceAnim( surfaceType_t *surface );
1417 int R_IQMLerpTag( orientation_t *tag, iqmData_t *data,
1418 int startFrame, int endFrame,
1419 float frac, const char *tagName );
1420
1421 /*
1422 =============================================================
1423 =============================================================
1424 */
1425 void R_TransformModelToClip( const vec3_t src, const float *modelMatrix, const float *projectionMatrix,
1426 vec4_t eye, vec4_t dst );
1427 void R_TransformClipToWindow( const vec4_t clip, const viewParms_t *view, vec4_t normalized, vec4_t window );
1428
1429 void RB_DeformTessGeometry( void );
1430
1431 void RB_CalcEnvironmentTexCoords( float *dstTexCoords );
1432 void RB_CalcFogTexCoords( float *dstTexCoords );
1433 void RB_CalcScrollTexCoords( const float scroll[2], float *dstTexCoords );
1434 void RB_CalcRotateTexCoords( float rotSpeed, float *dstTexCoords );
1435 void RB_CalcScaleTexCoords( const float scale[2], float *dstTexCoords );
1436 void RB_CalcTurbulentTexCoords( const waveForm_t *wf, float *dstTexCoords );
1437 void RB_CalcTransformTexCoords( const texModInfo_t *tmi, float *dstTexCoords );
1438 void RB_CalcModulateColorsByFog( unsigned char *dstColors );
1439 void RB_CalcModulateAlphasByFog( unsigned char *dstColors );
1440 void RB_CalcModulateRGBAsByFog( unsigned char *dstColors );
1441 void RB_CalcWaveAlpha( const waveForm_t *wf, unsigned char *dstColors );
1442 void RB_CalcWaveColor( const waveForm_t *wf, unsigned char *dstColors );
1443 void RB_CalcAlphaFromEntity( unsigned char *dstColors );
1444 void RB_CalcAlphaFromOneMinusEntity( unsigned char *dstColors );
1445 void RB_CalcStretchTexCoords( const waveForm_t *wf, float *texCoords );
1446 void RB_CalcColorFromEntity( unsigned char *dstColors );
1447 void RB_CalcColorFromOneMinusEntity( unsigned char *dstColors );
1448 void RB_CalcSpecularAlpha( unsigned char *alphas );
1449 void RB_CalcDiffuseColor( unsigned char *colors );
1450
1451 /*
1452 =============================================================
1453
1454 RENDERER BACK END FUNCTIONS
1455
1456 =============================================================
1457 */
1458
1459 void RB_ExecuteRenderCommands( const void *data );
1460
1461 /*
1462 =============================================================
1463
1464 RENDERER BACK END COMMAND QUEUE
1465
1466 =============================================================
1467 */
1468
1469 #define MAX_RENDER_COMMANDS 0x40000
1470
1471 typedef struct {
1472 byte cmds[MAX_RENDER_COMMANDS];
1473 int used;
1474 } renderCommandList_t;
1475
1476 typedef struct {
1477 int commandId;
1478 float color[4];
1479 } setColorCommand_t;
1480
1481 typedef struct {
1482 int commandId;
1483 int buffer;
1484 } drawBufferCommand_t;
1485
1486 typedef struct {
1487 int commandId;
1488 image_t *image;
1489 int width;
1490 int height;
1491 void *data;
1492 } subImageCommand_t;
1493
1494 typedef struct {
1495 int commandId;
1496 } swapBuffersCommand_t;
1497
1498 typedef struct {
1499 int commandId;
1500 int buffer;
1501 } endFrameCommand_t;
1502
1503 typedef struct {
1504 int commandId;
1505 shader_t *shader;
1506 float x, y;
1507 float w, h;
1508 float s1, t1;
1509 float s2, t2;
1510 } stretchPicCommand_t;
1511
1512 typedef struct {
1513 int commandId;
1514 trRefdef_t refdef;
1515 viewParms_t viewParms;
1516 drawSurf_t *drawSurfs;
1517 int numDrawSurfs;
1518 } drawSurfsCommand_t;
1519
1520 typedef struct {
1521 int commandId;
1522 int x;
1523 int y;
1524 int width;
1525 int height;
1526 char *fileName;
1527 qboolean jpeg;
1528 } screenshotCommand_t;
1529
1530 typedef struct {
1531 int commandId;
1532 int width;
1533 int height;
1534 byte *captureBuffer;
1535 byte *encodeBuffer;
1536 qboolean motionJpeg;
1537 } videoFrameCommand_t;
1538
1539 typedef struct
1540 {
1541 int commandId;
1542
1543 GLboolean rgba[4];
1544 } colorMaskCommand_t;
1545
1546 typedef struct
1547 {
1548 int commandId;
1549 } clearDepthCommand_t;
1550
1551 typedef enum {
1552 RC_END_OF_LIST,
1553 RC_SET_COLOR,
1554 RC_STRETCH_PIC,
1555 RC_DRAW_SURFS,
1556 RC_DRAW_BUFFER,
1557 RC_SWAP_BUFFERS,
1558 RC_SCREENSHOT,
1559 RC_VIDEOFRAME,
1560 RC_COLORMASK,
1561 RC_CLEARDEPTH
1562 } renderCommand_t;
1563
1564
1565 // these are sort of arbitrary limits.
1566 // the limits apply to the sum of all scenes in a frame --
1567 // the main view, all the 3D icons, etc
1568 #define MAX_POLYS 600
1569 #define MAX_POLYVERTS 3000
1570
1571 // all of the information needed by the back end must be
1572 // contained in a backEndData_t
1573 typedef struct {
1574 drawSurf_t drawSurfs[MAX_DRAWSURFS];
1575 dlight_t dlights[MAX_DLIGHTS];
1576 trRefEntity_t entities[MAX_REFENTITIES];
1577 srfPoly_t *polys;//[MAX_POLYS];
1578 polyVert_t *polyVerts;//[MAX_POLYVERTS];
1579 renderCommandList_t commands;
1580 } backEndData_t;
1581
1582 extern int max_polys;
1583 extern int max_polyverts;
1584
1585 extern backEndData_t *backEndData; // the second one may not be allocated
1586
1587
1588 void *R_GetCommandBuffer( int bytes );
1589 void RB_ExecuteRenderCommands( const void *data );
1590
1591 void R_IssuePendingRenderCommands( void );
1592
1593 void R_AddDrawSurfCmd( drawSurf_t *drawSurfs, int numDrawSurfs );
1594
1595 void RE_SetColor( const float *rgba );
1596 void RE_StretchPic ( float x, float y, float w, float h,
1597 float s1, float t1, float s2, float t2, qhandle_t hShader );
1598 void RE_BeginFrame( stereoFrame_t stereoFrame );
1599 void RE_EndFrame( int *frontEndMsec, int *backEndMsec );
1600 void RE_SaveJPG(char * filename, int quality, int image_width, int image_height,
1601 unsigned char *image_buffer, int padding);
1602 size_t RE_SaveJPGToBuffer(byte *buffer, size_t bufSize, int quality,
1603 int image_width, int image_height, byte *image_buffer, int padding);
1604 void RE_TakeVideoFrame( int width, int height,
1605 byte *captureBuffer, byte *encodeBuffer, qboolean motionJpeg );
1606
1607 void R_DrawElements( int numIndexes, const glIndex_t *indexes );
1608 void VectorArrayNormalize( vec4_t *normals, unsigned int count );
1609
1610 #ifdef idppc_altivec
1611 void LerpMeshVertexes_altivec( md3Surface_t *surf, float backlerp );
1612 void ProjectDlightTexture_altivec( void );
1613 void RB_CalcDiffuseColor_altivec( unsigned char *colors );
1614 #endif
1615
1616 #endif //TR_LOCAL_H