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