Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

tr_local.h

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 
00023 
00024 #ifndef TR_LOCAL_H
00025 #define TR_LOCAL_H
00026 
00027 #include "../game/q_shared.h"
00028 #include "../qcommon/qfiles.h"
00029 #include "../qcommon/qcommon.h"
00030 #include "tr_public.h"
00031 #include "qgl.h"
00032 
00033 #define GL_INDEX_TYPE       GL_UNSIGNED_INT
00034 typedef unsigned int glIndex_t;
00035 
00036 // fast float to int conversion
00037 #if id386 && !( (defined __linux__ || defined __FreeBSD__ ) && (defined __i386__ ) ) // rb010123
00038 long myftol( float f );
00039 #else
00040 #define myftol(x) ((int)(x))
00041 #endif
00042 
00043 
00044 // everything that is needed by the backend needs
00045 // to be double buffered to allow it to run in
00046 // parallel on a dual cpu machine
00047 #define SMP_FRAMES      2
00048 
00049 // 12 bits
00050 // see QSORT_SHADERNUM_SHIFT
00051 #define MAX_SHADERS             16384
00052 
00053 //#define MAX_SHADER_STATES 2048
00054 #define MAX_STATES_PER_SHADER 32
00055 #define MAX_STATE_NAME 32
00056 
00057 // can't be increased without changing bit packing for drawsurfs
00058 
00059 
00060 typedef struct dlight_s {
00061     vec3_t  origin;
00062     vec3_t  color;              // range from 0.0 to 1.0, should be color normalized
00063     float   radius;
00064 
00065     vec3_t  transformed;        // origin in local coordinate system
00066     int     additive;           // texture detail is lost tho when the lightmap is dark
00067 } dlight_t;
00068 
00069 
00070 // a trRefEntity_t has all the information passed in by
00071 // the client game, as well as some locally derived info
00072 typedef struct {
00073     refEntity_t e;
00074 
00075     float       axisLength;     // compensate for non-normalized axis
00076 
00077     qboolean    needDlights;    // true for bmodels that touch a dlight
00078     qboolean    lightingCalculated;
00079     vec3_t      lightDir;       // normalized direction towards light
00080     vec3_t      ambientLight;   // color normalized to 0-255
00081     int         ambientLightInt;    // 32 bit rgba packed
00082     vec3_t      directedLight;
00083 } trRefEntity_t;
00084 
00085 
00086 typedef struct {
00087     vec3_t      origin;         // in world coordinates
00088     vec3_t      axis[3];        // orientation in world
00089     vec3_t      viewOrigin;     // viewParms->or.origin in local coordinates
00090     float       modelMatrix[16];
00091 } orientationr_t;
00092 
00093 typedef struct image_s {
00094     char        imgName[MAX_QPATH];     // game path, including extension
00095     int         width, height;              // source image
00096     int         uploadWidth, uploadHeight;  // after power of two and picmip but not including clamp to MAX_TEXTURE_SIZE
00097     GLuint      texnum;                 // gl texture binding
00098 
00099     int         frameUsed;          // for texture usage in frame statistics
00100 
00101     int         internalFormat;
00102     int         TMU;                // only needed for voodoo2
00103 
00104     qboolean    mipmap;
00105     qboolean    allowPicmip;
00106     int         wrapClampMode;      // GL_CLAMP or GL_REPEAT
00107 
00108     struct image_s* next;
00109 } image_t;
00110 
00111 //===============================================================================
00112 
00113 typedef enum {
00114     SS_BAD,
00115     SS_PORTAL,          // mirrors, portals, viewscreens
00116     SS_ENVIRONMENT,     // sky box
00117     SS_OPAQUE,          // opaque
00118 
00119     SS_DECAL,           // scorch marks, etc.
00120     SS_SEE_THROUGH,     // ladders, grates, grills that may have small blended edges
00121                         // in addition to alpha test
00122     SS_BANNER,
00123 
00124     SS_FOG,
00125 
00126     SS_UNDERWATER,      // for items that should be drawn in front of the water plane
00127 
00128     SS_BLEND0,          // regular transparency and filters
00129     SS_BLEND1,          // generally only used for additive type effects
00130     SS_BLEND2,
00131     SS_BLEND3,
00132 
00133     SS_BLEND6,
00134     SS_STENCIL_SHADOW,
00135     SS_ALMOST_NEAREST,  // gun smoke puffs
00136 
00137     SS_NEAREST          // blood blobs
00138 } shaderSort_t;
00139 
00140 
00141 #define MAX_SHADER_STAGES 8
00142 
00143 typedef enum {
00144     GF_NONE,
00145 
00146     GF_SIN,
00147     GF_SQUARE,
00148     GF_TRIANGLE,
00149     GF_SAWTOOTH, 
00150     GF_INVERSE_SAWTOOTH, 
00151 
00152     GF_NOISE
00153 
00154 } genFunc_t;
00155 
00156 
00157 typedef enum {
00158     DEFORM_NONE,
00159     DEFORM_WAVE,
00160     DEFORM_NORMALS,
00161     DEFORM_BULGE,
00162     DEFORM_MOVE,
00163     DEFORM_PROJECTION_SHADOW,
00164     DEFORM_AUTOSPRITE,
00165     DEFORM_AUTOSPRITE2,
00166     DEFORM_TEXT0,
00167     DEFORM_TEXT1,
00168     DEFORM_TEXT2,
00169     DEFORM_TEXT3,
00170     DEFORM_TEXT4,
00171     DEFORM_TEXT5,
00172     DEFORM_TEXT6,
00173     DEFORM_TEXT7
00174 } deform_t;
00175 
00176 typedef enum {
00177     AGEN_IDENTITY,
00178     AGEN_SKIP,
00179     AGEN_ENTITY,
00180     AGEN_ONE_MINUS_ENTITY,
00181     AGEN_VERTEX,
00182     AGEN_ONE_MINUS_VERTEX,
00183     AGEN_LIGHTING_SPECULAR,
00184     AGEN_WAVEFORM,
00185     AGEN_PORTAL,
00186     AGEN_CONST
00187 } alphaGen_t;
00188 
00189 typedef enum {
00190     CGEN_BAD,
00191     CGEN_IDENTITY_LIGHTING, // tr.identityLight
00192     CGEN_IDENTITY,          // always (1,1,1,1)
00193     CGEN_ENTITY,            // grabbed from entity's modulate field
00194     CGEN_ONE_MINUS_ENTITY,  // grabbed from 1 - entity.modulate
00195     CGEN_EXACT_VERTEX,      // tess.vertexColors
00196     CGEN_VERTEX,            // tess.vertexColors * tr.identityLight
00197     CGEN_ONE_MINUS_VERTEX,
00198     CGEN_WAVEFORM,          // programmatically generated
00199     CGEN_LIGHTING_DIFFUSE,
00200     CGEN_FOG,               // standard fog
00201     CGEN_CONST              // fixed color
00202 } colorGen_t;
00203 
00204 typedef enum {
00205     TCGEN_BAD,
00206     TCGEN_IDENTITY,         // clear to 0,0
00207     TCGEN_LIGHTMAP,
00208     TCGEN_TEXTURE,
00209     TCGEN_ENVIRONMENT_MAPPED,
00210     TCGEN_FOG,
00211     TCGEN_VECTOR            // S and T from world coordinates
00212 } texCoordGen_t;
00213 
00214 typedef enum {
00215     ACFF_NONE,
00216     ACFF_MODULATE_RGB,
00217     ACFF_MODULATE_RGBA,
00218     ACFF_MODULATE_ALPHA
00219 } acff_t;
00220 
00221 typedef struct {
00222     genFunc_t   func;
00223 
00224     float base;
00225     float amplitude;
00226     float phase;
00227     float frequency;
00228 } waveForm_t;
00229 
00230 #define TR_MAX_TEXMODS 4
00231 
00232 typedef enum {
00233     TMOD_NONE,
00234     TMOD_TRANSFORM,
00235     TMOD_TURBULENT,
00236     TMOD_SCROLL,
00237     TMOD_SCALE,
00238     TMOD_STRETCH,
00239     TMOD_ROTATE,
00240     TMOD_ENTITY_TRANSLATE
00241 } texMod_t;
00242 
00243 #define MAX_SHADER_DEFORMS  3
00244 typedef struct {
00245     deform_t    deformation;            // vertex coordinate modification type
00246 
00247     vec3_t      moveVector;
00248     waveForm_t  deformationWave;
00249     float       deformationSpread;
00250 
00251     float       bulgeWidth;
00252     float       bulgeHeight;
00253     float       bulgeSpeed;
00254 } deformStage_t;
00255 
00256 
00257 typedef struct {
00258     texMod_t        type;
00259 
00260     // used for TMOD_TURBULENT and TMOD_STRETCH
00261     waveForm_t      wave;
00262 
00263     // used for TMOD_TRANSFORM
00264     float           matrix[2][2];       // s' = s * m[0][0] + t * m[1][0] + trans[0]
00265     float           translate[2];       // t' = s * m[0][1] + t * m[0][1] + trans[1]
00266 
00267     // used for TMOD_SCALE
00268     float           scale[2];           // s *= scale[0]
00269                                         // t *= scale[1]
00270 
00271     // used for TMOD_SCROLL
00272     float           scroll[2];          // s' = s + scroll[0] * time
00273                                         // t' = t + scroll[1] * time
00274 
00275     // + = clockwise
00276     // - = counterclockwise
00277     float           rotateSpeed;
00278 
00279 } texModInfo_t;
00280 
00281 
00282 #define MAX_IMAGE_ANIMATIONS    8
00283 
00284 typedef struct {
00285     image_t         *image[MAX_IMAGE_ANIMATIONS];
00286     int             numImageAnimations;
00287     float           imageAnimationSpeed;
00288 
00289     texCoordGen_t   tcGen;
00290     vec3_t          tcGenVectors[2];
00291 
00292     int             numTexMods;
00293     texModInfo_t    *texMods;
00294 
00295     int             videoMapHandle;
00296     qboolean        isLightmap;
00297     qboolean        vertexLightmap;
00298     qboolean        isVideoMap;
00299 } textureBundle_t;
00300 
00301 #define NUM_TEXTURE_BUNDLES 2
00302 
00303 typedef struct {
00304     qboolean        active;
00305     
00306     textureBundle_t bundle[NUM_TEXTURE_BUNDLES];
00307 
00308     waveForm_t      rgbWave;
00309     colorGen_t      rgbGen;
00310 
00311     waveForm_t      alphaWave;
00312     alphaGen_t      alphaGen;
00313 
00314     byte            constantColor[4];           // for CGEN_CONST and AGEN_CONST
00315 
00316     unsigned        stateBits;                  // GLS_xxxx mask
00317 
00318     acff_t          adjustColorsForFog;
00319 
00320     qboolean        isDetail;
00321 } shaderStage_t;
00322 
00323 struct shaderCommands_s;
00324 
00325 #define LIGHTMAP_2D         -4      // shader is for 2D rendering
00326 #define LIGHTMAP_BY_VERTEX  -3      // pre-lit triangle models
00327 #define LIGHTMAP_WHITEIMAGE -2
00328 #define LIGHTMAP_NONE       -1
00329 
00330 typedef enum {
00331     CT_FRONT_SIDED,
00332     CT_BACK_SIDED,
00333     CT_TWO_SIDED
00334 } cullType_t;
00335 
00336 typedef enum {
00337     FP_NONE,        // surface is translucent and will just be adjusted properly
00338     FP_EQUAL,       // surface is opaque but possibly alpha tested
00339     FP_LE           // surface is trnaslucent, but still needs a fog pass (fog surface)
00340 } fogPass_t;
00341 
00342 typedef struct {
00343     float       cloudHeight;
00344     image_t     *outerbox[6], *innerbox[6];
00345 } skyParms_t;
00346 
00347 typedef struct {
00348     vec3_t  color;
00349     float   depthForOpaque;
00350 } fogParms_t;
00351 
00352 
00353 typedef struct shader_s {
00354     char        name[MAX_QPATH];        // game path, including extension
00355     int         lightmapIndex;          // for a shader to match, both name and lightmapIndex must match
00356 
00357     int         index;                  // this shader == tr.shaders[index]
00358     int         sortedIndex;            // this shader == tr.sortedShaders[sortedIndex]
00359 
00360     float       sort;                   // lower numbered shaders draw before higher numbered
00361 
00362     qboolean    defaultShader;          // we want to return index 0 if the shader failed to
00363                                         // load for some reason, but R_FindShader should
00364                                         // still keep a name allocated for it, so if
00365                                         // something calls RE_RegisterShader again with
00366                                         // the same name, we don't try looking for it again
00367 
00368     qboolean    explicitlyDefined;      // found in a .shader file
00369 
00370     int         surfaceFlags;           // if explicitlyDefined, this will have SURF_* flags
00371     int         contentFlags;
00372 
00373     qboolean    entityMergable;         // merge across entites optimizable (smoke, blood)
00374 
00375     qboolean    isSky;
00376     skyParms_t  sky;
00377     fogParms_t  fogParms;
00378 
00379     float       portalRange;            // distance to fog out at
00380 
00381     int         multitextureEnv;        // 0, GL_MODULATE, GL_ADD (FIXME: put in stage)
00382 
00383     cullType_t  cullType;               // CT_FRONT_SIDED, CT_BACK_SIDED, or CT_TWO_SIDED
00384     qboolean    polygonOffset;          // set for decals and other items that must be offset 
00385     qboolean    noMipMaps;              // for console fonts, 2D elements, etc.
00386     qboolean    noPicMip;               // for images that must always be full resolution
00387 
00388     fogPass_t   fogPass;                // draw a blended pass, possibly with depth test equals
00389 
00390     qboolean    needsNormal;            // not all shaders will need all data to be gathered
00391     qboolean    needsST1;
00392     qboolean    needsST2;
00393     qboolean    needsColor;
00394 
00395     int         numDeforms;
00396     deformStage_t   deforms[MAX_SHADER_DEFORMS];
00397 
00398     int         numUnfoggedPasses;
00399     shaderStage_t   *stages[MAX_SHADER_STAGES];     
00400 
00401     void        (*optimalStageIteratorFunc)( void );
00402 
00403   float clampTime;                                  // time this shader is clamped to
00404   float timeOffset;                                 // current time offset for this shader
00405 
00406   int numStates;                                    // if non-zero this is a state shader
00407   struct shader_s *currentShader;                   // current state if this is a state shader
00408   struct shader_s *parentShader;                    // current state if this is a state shader
00409   int currentState;                                 // current state index for cycle purposes
00410   long expireTime;                                  // time in milliseconds this expires
00411 
00412   struct shader_s *remappedShader;                  // current shader this one is remapped too
00413 
00414   int shaderStates[MAX_STATES_PER_SHADER];          // index to valid shader states
00415 
00416     struct  shader_s    *next;
00417 } shader_t;
00418 
00419 typedef struct shaderState_s {
00420   char shaderName[MAX_QPATH];     // name of shader this state belongs to
00421   char name[MAX_STATE_NAME];      // name of this state
00422   char stateShader[MAX_QPATH];    // shader this name invokes
00423   int cycleTime;                  // time this cycle lasts, <= 0 is forever
00424   shader_t *shader;
00425 } shaderState_t;
00426 
00427 
00428 // trRefdef_t holds everything that comes in refdef_t,
00429 // as well as the locally generated scene information
00430 typedef struct {
00431     int         x, y, width, height;
00432     float       fov_x, fov_y;
00433     vec3_t      vieworg;
00434     vec3_t      viewaxis[3];        // transformation matrix
00435 
00436     int         time;               // time in milliseconds for shader effects and other time dependent rendering issues
00437     int         rdflags;            // RDF_NOWORLDMODEL, etc
00438 
00439     // 1 bits will prevent the associated area from rendering at all
00440     byte        areamask[MAX_MAP_AREA_BYTES];
00441     qboolean    areamaskModified;   // qtrue if areamask changed since last scene
00442 
00443     float       floatTime;          // tr.refdef.time / 1000.0
00444 
00445     // text messages for deform text shaders
00446     char        text[MAX_RENDER_STRINGS][MAX_RENDER_STRING_LENGTH];
00447 
00448     int         num_entities;
00449     trRefEntity_t   *entities;
00450 
00451     int         num_dlights;
00452     struct dlight_s *dlights;
00453 
00454     int         numPolys;
00455     struct srfPoly_s    *polys;
00456 
00457     int         numDrawSurfs;
00458     struct drawSurf_s   *drawSurfs;
00459 
00460 
00461 } trRefdef_t;
00462 
00463 
00464 //=================================================================================
00465 
00466 // skins allow models to be retextured without modifying the model file
00467 typedef struct {
00468     char        name[MAX_QPATH];
00469     shader_t    *shader;
00470 } skinSurface_t;
00471 
00472 typedef struct skin_s {
00473     char        name[MAX_QPATH];        // game path, including extension
00474     int         numSurfaces;
00475     skinSurface_t   *surfaces[MD3_MAX_SURFACES];
00476 } skin_t;
00477 
00478 
00479 typedef struct {
00480     int         originalBrushNumber;
00481     vec3_t      bounds[2];
00482 
00483     unsigned    colorInt;               // in packed byte format
00484     float       tcScale;                // texture coordinate vector scales
00485     fogParms_t  parms;
00486 
00487     // for clipping distance in fog when outside
00488     qboolean    hasSurface;
00489     float       surface[4];
00490 } fog_t;
00491 
00492 typedef struct {
00493     orientationr_t  or;
00494     orientationr_t  world;
00495     vec3_t      pvsOrigin;          // may be different than or.origin for portals
00496     qboolean    isPortal;           // true if this view is through a portal
00497     qboolean    isMirror;           // the portal is a mirror, invert the face culling
00498     int         frameSceneNum;      // copied from tr.frameSceneNum
00499     int         frameCount;         // copied from tr.frameCount
00500     cplane_t    portalPlane;        // clip anything behind this if mirroring
00501     int         viewportX, viewportY, viewportWidth, viewportHeight;
00502     float       fovX, fovY;
00503     float       projectionMatrix[16];
00504     cplane_t    frustum[4];
00505     vec3_t      visBounds[2];
00506     float       zFar;
00507 } viewParms_t;
00508 
00509 
00510 /*
00511 ==============================================================================
00512 
00513 SURFACES
00514 
00515 ==============================================================================
00516 */
00517 
00518 // any changes in surfaceType must be mirrored in rb_surfaceTable[]
00519 typedef enum {
00520     SF_BAD,
00521     SF_SKIP,                // ignore
00522     SF_FACE,
00523     SF_GRID,
00524     SF_TRIANGLES,
00525     SF_POLY,
00526     SF_MD3,
00527     SF_MD4,
00528     SF_FLARE,
00529     SF_ENTITY,              // beams, rails, lightning, etc that can be determined by entity
00530     SF_DISPLAY_LIST,
00531 
00532     SF_NUM_SURFACE_TYPES,
00533     SF_MAX = 0x7fffffff         // ensures that sizeof( surfaceType_t ) == sizeof( int )
00534 } surfaceType_t;
00535 
00536 typedef struct drawSurf_s {
00537     unsigned            sort;           // bit combination for fast compares
00538     surfaceType_t       *surface;       // any of surface*_t
00539 } drawSurf_t;
00540 
00541 #define MAX_FACE_POINTS     64
00542 
00543 #define MAX_PATCH_SIZE      32          // max dimensions of a patch mesh in map file
00544 #define MAX_GRID_SIZE       65          // max dimensions of a grid mesh in memory
00545 
00546 // when cgame directly specifies a polygon, it becomes a srfPoly_t
00547 // as soon as it is called
00548 typedef struct srfPoly_s {
00549     surfaceType_t   surfaceType;
00550     qhandle_t       hShader;
00551     int             fogIndex;
00552     int             numVerts;
00553     polyVert_t      *verts;
00554 } srfPoly_t;
00555 
00556 typedef struct srfDisplayList_s {
00557     surfaceType_t   surfaceType;
00558     int             listNum;
00559 } srfDisplayList_t;
00560 
00561 
00562 typedef struct srfFlare_s {
00563     surfaceType_t   surfaceType;
00564     vec3_t          origin;
00565     vec3_t          normal;
00566     vec3_t          color;
00567 } srfFlare_t;
00568 
00569 typedef struct srfGridMesh_s {
00570     surfaceType_t   surfaceType;
00571 
00572     // dynamic lighting information
00573     int             dlightBits[SMP_FRAMES];
00574 
00575     // culling information
00576     vec3_t          meshBounds[2];
00577     vec3_t          localOrigin;
00578     float           meshRadius;
00579 
00580     // lod information, which may be different
00581     // than the culling information to allow for
00582     // groups of curves that LOD as a unit
00583     vec3_t          lodOrigin;
00584     float           lodRadius;
00585     int             lodFixed;
00586     int             lodStitched;
00587 
00588     // vertexes
00589     int             width, height;
00590     float           *widthLodError;
00591     float           *heightLodError;
00592     drawVert_t      verts[1];       // variable sized
00593 } srfGridMesh_t;
00594 
00595 
00596 
00597 #define VERTEXSIZE  8
00598 typedef struct {
00599     surfaceType_t   surfaceType;
00600     cplane_t    plane;
00601 
00602     // dynamic lighting information
00603     int         dlightBits[SMP_FRAMES];
00604 
00605     // triangle definitions (no normals at points)
00606     int         numPoints;
00607     int         numIndices;
00608     int         ofsIndices;
00609     float       points[1][VERTEXSIZE];  // variable sized
00610                                         // there is a variable length list of indices here also
00611 } srfSurfaceFace_t;
00612 
00613 
00614 // misc_models in maps are turned into direct geometry by q3map
00615 typedef struct {
00616     surfaceType_t   surfaceType;
00617 
00618     // dynamic lighting information
00619     int             dlightBits[SMP_FRAMES];
00620 
00621     // culling information (FIXME: use this!)
00622     vec3_t          bounds[2];
00623     vec3_t          localOrigin;
00624     float           radius;
00625 
00626     // triangle definitions
00627     int             numIndexes;
00628     int             *indexes;
00629 
00630     int             numVerts;
00631     drawVert_t      *verts;
00632 } srfTriangles_t;
00633 
00634 
00635 extern  void (*rb_surfaceTable[SF_NUM_SURFACE_TYPES])(void *);
00636 
00637 /*
00638 ==============================================================================
00639 
00640 BRUSH MODELS
00641 
00642 ==============================================================================
00643 */
00644 
00645 
00646 //
00647 // in memory representation
00648 //
00649 
00650 #define SIDE_FRONT  0
00651 #define SIDE_BACK   1
00652 #define SIDE_ON     2
00653 
00654 typedef struct msurface_s {
00655     int                 viewCount;      // if == tr.viewCount, already added
00656     struct shader_s     *shader;
00657     int                 fogIndex;
00658 
00659     surfaceType_t       *data;          // any of srf*_t
00660 } msurface_t;
00661 
00662 
00663 
00664 #define CONTENTS_NODE       -1
00665 typedef struct mnode_s {
00666     // common with leaf and node
00667     int         contents;       // -1 for nodes, to differentiate from leafs
00668     int         visframe;       // node needs to be traversed if current
00669     vec3_t      mins, maxs;     // for bounding box culling
00670     struct mnode_s  *parent;
00671 
00672     // node specific
00673     cplane_t    *plane;
00674     struct mnode_s  *children[2];   
00675 
00676     // leaf specific
00677     int         cluster;
00678     int         area;
00679 
00680     msurface_t  **firstmarksurface;
00681     int         nummarksurfaces;
00682 } mnode_t;
00683 
00684 typedef struct {
00685     vec3_t      bounds[2];      // for culling
00686     msurface_t  *firstSurface;
00687     int         numSurfaces;
00688 } bmodel_t;
00689 
00690 typedef struct {
00691     char        name[MAX_QPATH];        // ie: maps/tim_dm2.bsp
00692     char        baseName[MAX_QPATH];    // ie: tim_dm2
00693 
00694     int         dataSize;
00695 
00696     int         numShaders;
00697     dshader_t   *shaders;
00698 
00699     bmodel_t    *bmodels;
00700 
00701     int         numplanes;
00702     cplane_t    *planes;
00703 
00704     int         numnodes;       // includes leafs
00705     int         numDecisionNodes;
00706     mnode_t     *nodes;
00707 
00708     int         numsurfaces;
00709     msurface_t  *surfaces;
00710 
00711     int         nummarksurfaces;
00712     msurface_t  **marksurfaces;
00713 
00714     int         numfogs;
00715     fog_t       *fogs;
00716 
00717     vec3_t      lightGridOrigin;
00718     vec3_t      lightGridSize;
00719     vec3_t      lightGridInverseSize;
00720     int         lightGridBounds[3];
00721     byte        *lightGridData;
00722 
00723 
00724     int         numClusters;
00725     int         clusterBytes;
00726     const byte  *vis;           // may be passed in by CM_LoadMap to save space
00727 
00728     byte        *novis;         // clusterBytes of 0xff
00729 
00730     char        *entityString;
00731     char        *entityParsePoint;
00732 } world_t;
00733 
00734 //======================================================================
00735 
00736 typedef enum {
00737     MOD_BAD,
00738     MOD_BRUSH,
00739     MOD_MESH,
00740     MOD_MD4
00741 } modtype_t;
00742 
00743 typedef struct model_s {
00744     char        name[MAX_QPATH];
00745     modtype_t   type;
00746     int         index;              // model = tr.models[model->index]
00747 
00748     int         dataSize;           // just for listing purposes
00749     bmodel_t    *bmodel;            // only if type == MOD_BRUSH
00750     md3Header_t *md3[MD3_MAX_LODS]; // only if type == MOD_MESH
00751     md4Header_t *md4;               // only if type == MOD_MD4
00752 
00753     int          numLods;
00754 } model_t;
00755 
00756 
00757 #define MAX_MOD_KNOWN   1024
00758 
00759 void        R_ModelInit (void);
00760 model_t     *R_GetModelByHandle( qhandle_t hModel );
00761 int         R_LerpTag( orientation_t *tag, qhandle_t handle, int startFrame, int endFrame, 
00762                      float frac, const char *tagName );
00763 void        R_ModelBounds( qhandle_t handle, vec3_t mins, vec3_t maxs );
00764 
00765 void        R_Modellist_f (void);
00766 
00767 //====================================================
00768 extern  refimport_t     ri;
00769 
00770 #define MAX_DRAWIMAGES          2048
00771 #define MAX_LIGHTMAPS           256
00772 #define MAX_SKINS               1024
00773 
00774 
00775 #define MAX_DRAWSURFS           0x10000
00776 #define DRAWSURF_MASK           (MAX_DRAWSURFS-1)
00777 
00778 /*
00779 
00780 the drawsurf sort data is packed into a single 32 bit value so it can be
00781 compared quickly during the qsorting process
00782 
00783 the bits are allocated as follows:
00784 
00785 21 - 31 : sorted shader index
00786 11 - 20 : entity index
00787 2 - 6   : fog index
00788 //2     : used to be clipped flag REMOVED - 03.21.00 rad
00789 0 - 1   : dlightmap index
00790 
00791     TTimo - 1.32
00792 17-31 : sorted shader index
00793 7-16  : entity index
00794 2-6   : fog index
00795 0-1   : dlightmap index
00796 */
00797 #define QSORT_SHADERNUM_SHIFT   17
00798 #define QSORT_ENTITYNUM_SHIFT   7
00799 #define QSORT_FOGNUM_SHIFT      2
00800 
00801 extern  int         gl_filter_min, gl_filter_max;
00802 
00803 /*
00804 ** performanceCounters_t
00805 */
00806 typedef struct {
00807     int     c_sphere_cull_patch_in, c_sphere_cull_patch_clip, c_sphere_cull_patch_out;
00808     int     c_box_cull_patch_in, c_box_cull_patch_clip, c_box_cull_patch_out;
00809     int     c_sphere_cull_md3_in, c_sphere_cull_md3_clip, c_sphere_cull_md3_out;
00810     int     c_box_cull_md3_in, c_box_cull_md3_clip, c_box_cull_md3_out;
00811 
00812     int     c_leafs;
00813     int     c_dlightSurfaces;
00814     int     c_dlightSurfacesCulled;
00815 } frontEndCounters_t;
00816 
00817 #define FOG_TABLE_SIZE      256
00818 #define FUNCTABLE_SIZE      1024
00819 #define FUNCTABLE_SIZE2     10
00820 #define FUNCTABLE_MASK      (FUNCTABLE_SIZE-1)
00821 
00822 
00823 // the renderer front end should never modify glstate_t
00824 typedef struct {
00825     int         currenttextures[2];
00826     int         currenttmu;
00827     qboolean    finishCalled;
00828     int         texEnv[2];
00829     int         faceCulling;
00830     unsigned long   glStateBits;
00831 } glstate_t;
00832 
00833 
00834 typedef struct {
00835     int     c_surfaces, c_shaders, c_vertexes, c_indexes, c_totalIndexes;
00836     float   c_overDraw;
00837     
00838     int     c_dlightVertexes;
00839     int     c_dlightIndexes;
00840 
00841     int     c_flareAdds;
00842     int     c_flareTests;
00843     int     c_flareRenders;
00844 
00845     int     msec;           // total msec for backend run
00846 } backEndCounters_t;
00847 
00848 // all state modified by the back end is seperated
00849 // from the front end state
00850 typedef struct {
00851     int         smpFrame;
00852     trRefdef_t  refdef;
00853     viewParms_t viewParms;
00854     orientationr_t  or;
00855     backEndCounters_t   pc;
00856     qboolean    isHyperspace;
00857     trRefEntity_t   *currentEntity;
00858     qboolean    skyRenderedThisView;    // flag for drawing sun
00859 
00860     qboolean    projection2D;   // if qtrue, drawstretchpic doesn't need to change modes
00861     byte        color2D[4];
00862     qboolean    vertexes2D;     // shader needs to be finished
00863     trRefEntity_t   entity2D;   // currentEntity will point at this when doing 2D rendering
00864 } backEndState_t;
00865 
00866 /*
00867 ** trGlobals_t 
00868 **
00869 ** Most renderer globals are defined here.
00870 ** backend functions should never modify any of these fields,
00871 ** but may read fields that aren't dynamically modified
00872 ** by the frontend.
00873 */
00874 typedef struct {
00875     qboolean                registered;     // cleared at shutdown, set at beginRegistration
00876 
00877     int                     visCount;       // incremented every time a new vis cluster is entered
00878     int                     frameCount;     // incremented every frame
00879     int                     sceneCount;     // incremented every scene
00880     int                     viewCount;      // incremented every view (twice a scene if portaled)
00881                                             // and every R_MarkFragments call
00882 
00883     int                     smpFrame;       // toggles from 0 to 1 every endFrame
00884 
00885     int                     frameSceneNum;  // zeroed at RE_BeginFrame
00886 
00887     qboolean                worldMapLoaded;
00888     world_t                 *world;
00889 
00890     const byte              *externalVisData;   // from RE_SetWorldVisData, shared with CM_Load
00891 
00892     image_t                 *defaultImage;
00893     image_t                 *scratchImage[32];
00894     image_t                 *fogImage;
00895     image_t                 *dlightImage;   // inverse-quare highlight for projective adding
00896     image_t                 *flareImage;
00897     image_t                 *whiteImage;            // full of 0xff
00898     image_t                 *identityLightImage;    // full of tr.identityLightByte
00899 
00900     shader_t                *defaultShader;
00901     shader_t                *shadowShader;
00902     shader_t                *projectionShadowShader;
00903 
00904     shader_t                *flareShader;
00905     shader_t                *sunShader;
00906 
00907     int                     numLightmaps;
00908     image_t                 *lightmaps[MAX_LIGHTMAPS];
00909 
00910     trRefEntity_t           *currentEntity;
00911     trRefEntity_t           worldEntity;        // point currentEntity at this when rendering world
00912     int                     currentEntityNum;
00913     int                     shiftedEntityNum;   // currentEntityNum << QSORT_ENTITYNUM_SHIFT
00914     model_t                 *currentModel;
00915 
00916     viewParms_t             viewParms;
00917 
00918     float                   identityLight;      // 1.0 / ( 1 << overbrightBits )
00919     int                     identityLightByte;  // identityLight * 255
00920     int                     overbrightBits;     // r_overbrightBits->integer, but set to 0 if no hw gamma
00921 
00922     orientationr_t          or;                 // for current entity
00923 
00924     trRefdef_t              refdef;
00925 
00926     int                     viewCluster;
00927 
00928     vec3_t                  sunLight;           // from the sky shader for this level
00929     vec3_t                  sunDirection;
00930 
00931     frontEndCounters_t      pc;
00932     int                     frontEndMsec;       // not in pc due to clearing issue
00933 
00934     //
00935     // put large tables at the end, so most elements will be
00936     // within the +/32K indexed range on risc processors
00937     //
00938     model_t                 *models[MAX_MOD_KNOWN];
00939     int                     numModels;
00940 
00941     int                     numImages;
00942     image_t                 *images[MAX_DRAWIMAGES];
00943 
00944     // shader indexes from other modules will be looked up in tr.shaders[]
00945     // shader indexes from drawsurfs will be looked up in sortedShaders[]
00946     // lower indexed sortedShaders must be rendered first (opaque surfaces before translucent)
00947     int                     numShaders;
00948     shader_t                *shaders[MAX_SHADERS];
00949     shader_t                *sortedShaders[MAX_SHADERS];
00950 
00951     int                     numSkins;
00952     skin_t                  *skins[MAX_SKINS];
00953 
00954     float                   sinTable[FUNCTABLE_SIZE];
00955     float                   squareTable[FUNCTABLE_SIZE];
00956     float                   triangleTable[FUNCTABLE_SIZE];
00957     float                   sawToothTable[FUNCTABLE_SIZE];
00958     float                   inverseSawToothTable[FUNCTABLE_SIZE];
00959     float                   fogTable[FOG_TABLE_SIZE];
00960 } trGlobals_t;
00961 
00962 extern backEndState_t   backEnd;
00963 extern trGlobals_t  tr;
00964 extern glconfig_t   glConfig;       // outside of TR since it shouldn't be cleared during ref re-init
00965 extern glstate_t    glState;        // outside of TR since it shouldn't be cleared during ref re-init
00966 
00967 
00968 //
00969 // cvars
00970 //
00971 extern cvar_t   *r_flareSize;
00972 extern cvar_t   *r_flareFade;
00973 
00974 extern cvar_t   *r_railWidth;
00975 extern cvar_t   *r_railCoreWidth;
00976 extern cvar_t   *r_railSegmentLength;
00977 
00978 extern cvar_t   *r_ignore;              // used for debugging anything
00979 extern cvar_t   *r_verbose;             // used for verbose debug spew
00980 extern cvar_t   *r_ignoreFastPath;      // allows us to ignore our Tess fast paths
00981 
00982 extern cvar_t   *r_znear;               // near Z clip plane
00983 
00984 extern cvar_t   *r_stencilbits;         // number of desired stencil bits
00985 extern cvar_t   *r_depthbits;           // number of desired depth bits
00986 extern cvar_t   *r_colorbits;           // number of desired color bits, only relevant for fullscreen
00987 extern cvar_t   *r_stereo;              // desired pixelformat stereo flag
00988 extern cvar_t   *r_texturebits;         // number of desired texture bits
00989                                         // 0 = use framebuffer depth
00990                                         // 16 = use 16-bit textures
00991                                         // 32 = use 32-bit textures
00992                                         // all else = error
00993 
00994 extern cvar_t   *r_measureOverdraw;     // enables stencil buffer overdraw measurement
00995 
00996 extern cvar_t   *r_lodbias;             // push/pull LOD transitions
00997 extern cvar_t   *r_lodscale;
00998 
00999 extern cvar_t   *r_primitives;          // "0" = based on compiled vertex array existance
01000                                         // "1" = glDrawElemet tristrips
01001                                         // "2" = glDrawElements triangles
01002                                         // "-1" = no drawing
01003 
01004 extern cvar_t   *r_inGameVideo;             // controls whether in game video should be draw
01005 extern cvar_t   *r_fastsky;             // controls whether sky should be cleared or drawn
01006 extern cvar_t   *r_drawSun;             // controls drawing of sun quad
01007 extern cvar_t   *r_dynamiclight;        // dynamic lights enabled/disabled
01008 extern cvar_t   *r_dlightBacks;         // dlight non-facing surfaces for continuity
01009 
01010 extern  cvar_t  *r_norefresh;           // bypasses the ref rendering
01011 extern  cvar_t  *r_drawentities;        // disable/enable entity rendering
01012 extern  cvar_t  *r_drawworld;           // disable/enable world rendering
01013 extern  cvar_t  *r_speeds;              // various levels of information display
01014 extern  cvar_t  *r_detailTextures;      // enables/disables detail texturing stages
01015 extern  cvar_t  *r_novis;               // disable/enable usage of PVS
01016 extern  cvar_t  *r_nocull;
01017 extern  cvar_t  *r_facePlaneCull;       // enables culling of planar surfaces with back side test
01018 extern  cvar_t  *r_nocurves;
01019 extern  cvar_t  *r_showcluster;
01020 
01021 extern cvar_t   *r_mode;                // video mode
01022 extern cvar_t   *r_fullscreen;
01023 extern cvar_t   *r_gamma;
01024 extern cvar_t   *r_displayRefresh;      // optional display refresh option
01025 extern cvar_t   *r_ignorehwgamma;       // overrides hardware gamma capabilities
01026 
01027 extern cvar_t   *r_allowExtensions;             // global enable/disable of OpenGL extensions
01028 extern cvar_t   *r_ext_compressed_textures;     // these control use of specific extensions
01029 extern cvar_t   *r_ext_gamma_control;
01030 extern cvar_t   *r_ext_texenv_op;
01031 extern cvar_t   *r_ext_multitexture;
01032 extern cvar_t   *r_ext_compiled_vertex_array;
01033 extern cvar_t   *r_ext_texture_env_add;
01034 
01035 extern  cvar_t  *r_nobind;                      // turns off binding to appropriate textures
01036 extern  cvar_t  *r_singleShader;                // make most world faces use default shader
01037 extern  cvar_t  *r_roundImagesDown;
01038 extern  cvar_t  *r_colorMipLevels;              // development aid to see texture mip usage
01039 extern  cvar_t  *r_picmip;                      // controls picmip values
01040 extern  cvar_t  *r_finish;
01041 extern  cvar_t  *r_drawBuffer;
01042 extern  cvar_t  *r_glDriver;
01043 extern  cvar_t  *r_swapInterval;
01044 extern  cvar_t  *r_textureMode;
01045 extern  cvar_t  *r_offsetFactor;
01046 extern  cvar_t  *r_offsetUnits;
01047 
01048 extern  cvar_t  *r_fullbright;                  // avoid lightmap pass
01049 extern  cvar_t  *r_lightmap;                    // render lightmaps only
01050 extern  cvar_t  *r_vertexLight;                 // vertex lighting mode for better performance
01051 extern  cvar_t  *r_uiFullScreen;                // ui is running fullscreen
01052 
01053 extern  cvar_t  *r_logFile;                     // number of frames to emit GL logs
01054 extern  cvar_t  *r_showtris;                    // enables wireframe rendering of the world
01055 extern  cvar_t  *r_showsky;                     // forces sky in front of all surfaces
01056 extern  cvar_t  *r_shownormals;                 // draws wireframe normals
01057 extern  cvar_t  *r_clear;                       // force screen clear every frame
01058 
01059 extern  cvar_t  *r_shadows;                     // controls shadows: 0 = none, 1 = blur, 2 = stencil, 3 = black planar projection
01060 extern  cvar_t  *r_flares;                      // light flares
01061 
01062 extern  cvar_t  *r_intensity;
01063 
01064 extern  cvar_t  *r_lockpvs;
01065 extern  cvar_t  *r_noportals;
01066 extern  cvar_t  *r_portalOnly;
01067 
01068 extern  cvar_t  *r_subdivisions;
01069 extern  cvar_t  *r_lodCurveError;
01070 extern  cvar_t  *r_smp;
01071 extern  cvar_t  *r_showSmp;
01072 extern  cvar_t  *r_skipBackEnd;
01073 
01074 extern  cvar_t  *r_ignoreGLErrors;
01075 
01076 extern  cvar_t  *r_overBrightBits;
01077 extern  cvar_t  *r_mapOverBrightBits;
01078 
01079 extern  cvar_t  *r_debugSurface;
01080 extern  cvar_t  *r_simpleMipMaps;
01081 
01082 extern  cvar_t  *r_showImages;
01083 extern  cvar_t  *r_debugSort;
01084 
01085 extern  cvar_t  *r_printShaders;
01086 extern  cvar_t  *r_saveFontData;
01087 
01088 //====================================================================
01089 
01090 float R_NoiseGet4f( float x, float y, float z, float t );
01091 void  R_NoiseInit( void );
01092 
01093 void R_SwapBuffers( int );
01094 
01095 void R_RenderView( viewParms_t *parms );
01096 
01097 void R_AddMD3Surfaces( trRefEntity_t *e );
01098 void R_AddNullModelSurfaces( trRefEntity_t *e );
01099 void R_AddBeamSurfaces( trRefEntity_t *e );
01100 void R_AddRailSurfaces( trRefEntity_t *e, qboolean isUnderwater );
01101 void R_AddLightningBoltSurfaces( trRefEntity_t *e );
01102 
01103 void R_AddPolygonSurfaces( void );
01104 
01105 void R_DecomposeSort( unsigned sort, int *entityNum, shader_t **shader, 
01106                      int *fogNum, int *dlightMap );
01107 
01108 void R_AddDrawSurf( surfaceType_t *surface, shader_t *shader, int fogIndex, int dlightMap );
01109 
01110 
01111 #define CULL_IN     0       // completely unclipped
01112 #define CULL_CLIP   1       // clipped by one or more planes
01113 #define CULL_OUT    2       // completely outside the clipping planes
01114 void R_LocalNormalToWorld (vec3_t local, vec3_t world);
01115 void R_LocalPointToWorld (vec3_t local, vec3_t world);
01116 int R_CullLocalBox (vec3_t bounds[2]);
01117 int R_CullPointAndRadius( vec3_t origin, float radius );
01118 int R_CullLocalPointAndRadius( vec3_t origin, float radius );
01119 
01120 void R_RotateForEntity( const trRefEntity_t *ent, const viewParms_t *viewParms, orientationr_t *or );
01121 
01122 /*
01123 ** GL wrapper/helper functions
01124 */
01125 void    GL_Bind( image_t *image );
01126 void    GL_SetDefaultState (void);
01127 void    GL_SelectTexture( int unit );
01128 void    GL_TextureMode( const char *string );
01129 void    GL_CheckErrors( void );
01130 void    GL_State( unsigned long stateVector );
01131 void    GL_TexEnv( int env );
01132 void    GL_Cull( int cullType );
01133 
01134 #define GLS_SRCBLEND_ZERO                       0x00000001
01135 #define GLS_SRCBLEND_ONE                        0x00000002
01136 #define GLS_SRCBLEND_DST_COLOR                  0x00000003
01137 #define GLS_SRCBLEND_ONE_MINUS_DST_COLOR        0x00000004
01138 #define GLS_SRCBLEND_SRC_ALPHA                  0x00000005
01139 #define GLS_SRCBLEND_ONE_MINUS_SRC_ALPHA        0x00000006
01140 #define GLS_SRCBLEND_DST_ALPHA                  0x00000007
01141 #define GLS_SRCBLEND_ONE_MINUS_DST_ALPHA        0x00000008
01142 #define GLS_SRCBLEND_ALPHA_SATURATE             0x00000009
01143 #define     GLS_SRCBLEND_BITS                   0x0000000f
01144 
01145 #define GLS_DSTBLEND_ZERO                       0x00000010
01146 #define GLS_DSTBLEND_ONE                        0x00000020
01147 #define GLS_DSTBLEND_SRC_COLOR                  0x00000030
01148 #define GLS_DSTBLEND_ONE_MINUS_SRC_COLOR        0x00000040
01149 #define GLS_DSTBLEND_SRC_ALPHA                  0x00000050
01150 #define GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA        0x00000060
01151 #define GLS_DSTBLEND_DST_ALPHA                  0x00000070
01152 #define GLS_DSTBLEND_ONE_MINUS_DST_ALPHA        0x00000080
01153 #define     GLS_DSTBLEND_BITS                   0x000000f0
01154 
01155 #define GLS_DEPTHMASK_TRUE                      0x00000100
01156 
01157 #define GLS_POLYMODE_LINE                       0x00001000
01158 
01159 #define GLS_DEPTHTEST_DISABLE                   0x00010000
01160 #define GLS_DEPTHFUNC_EQUAL                     0x00020000
01161 
01162 #define GLS_ATEST_GT_0                          0x10000000
01163 #define GLS_ATEST_LT_80                         0x20000000
01164 #define GLS_ATEST_GE_80                         0x40000000
01165 #define     GLS_ATEST_BITS                      0x70000000
01166 
01167 #define GLS_DEFAULT         GLS_DEPTHMASK_TRUE
01168 
01169 void