tr_local.h 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __TR_LOCAL_H__
  21. #define __TR_LOCAL_H__
  22. #include "Image.h"
  23. #include "MegaTexture.h"
  24. class idRenderWorldLocal;
  25. // everything that is needed by the backend needs
  26. // to be double buffered to allow it to run in
  27. // parallel on a dual cpu machine
  28. const int SMP_FRAMES = 1;
  29. const int FALLOFF_TEXTURE_SIZE = 64;
  30. const float DEFAULT_FOG_DISTANCE = 500.0f;
  31. const int FOG_ENTER_SIZE = 64;
  32. const float FOG_ENTER = (FOG_ENTER_SIZE+1.0f)/(FOG_ENTER_SIZE*2);
  33. // picky to get the bilerp correct at terminator
  34. // idScreenRect gets carried around with each drawSurf, so it makes sense
  35. // to keep it compact, instead of just using the idBounds class
  36. class idScreenRect {
  37. public:
  38. short x1, y1, x2, y2; // inclusive pixel bounds inside viewport
  39. float zmin, zmax; // for depth bounds test
  40. void Clear(); // clear to backwards values
  41. void AddPoint( float x, float y ); // adds a point
  42. void Expand(); // expand by one pixel each way to fix roundoffs
  43. void Intersect( const idScreenRect &rect );
  44. void Union( const idScreenRect &rect );
  45. bool Equals( const idScreenRect &rect ) const;
  46. bool IsEmpty() const;
  47. };
  48. idScreenRect R_ScreenRectFromViewFrustumBounds( const idBounds &bounds );
  49. void R_ShowColoredScreenRect( const idScreenRect &rect, int colorIndex );
  50. typedef enum {
  51. DC_BAD,
  52. DC_RENDERVIEW,
  53. DC_UPDATE_ENTITYDEF,
  54. DC_DELETE_ENTITYDEF,
  55. DC_UPDATE_LIGHTDEF,
  56. DC_DELETE_LIGHTDEF,
  57. DC_LOADMAP,
  58. DC_CROP_RENDER,
  59. DC_UNCROP_RENDER,
  60. DC_CAPTURE_RENDER,
  61. DC_END_FRAME,
  62. DC_DEFINE_MODEL,
  63. DC_SET_PORTAL_STATE,
  64. DC_UPDATE_SOUNDOCCLUSION,
  65. DC_GUI_MODEL
  66. } demoCommand_t;
  67. /*
  68. ==============================================================================
  69. SURFACES
  70. ==============================================================================
  71. */
  72. #include "ModelDecal.h"
  73. #include "ModelOverlay.h"
  74. #include "Interaction.h"
  75. // drawSurf_t structures command the back end to render surfaces
  76. // a given srfTriangles_t may be used with multiple viewEntity_t,
  77. // as when viewed in a subview or multiple viewport render, or
  78. // with multiple shaders when skinned, or, possibly with multiple
  79. // lights, although currently each lighting interaction creates
  80. // unique srfTriangles_t
  81. // drawSurf_t are always allocated and freed every frame, they are never cached
  82. static const int DSF_VIEW_INSIDE_SHADOW = 1;
  83. typedef struct drawSurf_s {
  84. const srfTriangles_t *geo;
  85. const struct viewEntity_s *space;
  86. const idMaterial *material; // may be NULL for shadow volumes
  87. float sort; // material->sort, modified by gui / entity sort offsets
  88. const float *shaderRegisters; // evaluated and adjusted for referenceShaders
  89. const struct drawSurf_s *nextOnLight; // viewLight chains
  90. idScreenRect scissorRect; // for scissor clipping, local inside renderView viewport
  91. int dsFlags; // DSF_VIEW_INSIDE_SHADOW, etc
  92. struct vertCache_s *dynamicTexCoords; // float * in vertex cache memory
  93. // specular directions for non vertex program cards, skybox texcoords, etc
  94. } drawSurf_t;
  95. typedef struct {
  96. int numPlanes; // this is always 6 for now
  97. idPlane planes[6];
  98. // positive sides facing inward
  99. // plane 5 is always the plane the projection is going to, the
  100. // other planes are just clip planes
  101. // all planes are in global coordinates
  102. bool makeClippedPlanes;
  103. // a projected light with a single frustum needs to make sil planes
  104. // from triangles that clip against side planes, but a point light
  105. // that has adjacent frustums doesn't need to
  106. } shadowFrustum_t;
  107. // areas have references to hold all the lights and entities in them
  108. typedef struct areaReference_s {
  109. struct areaReference_s *areaNext; // chain in the area
  110. struct areaReference_s *areaPrev;
  111. struct areaReference_s *ownerNext; // chain on either the entityDef or lightDef
  112. idRenderEntityLocal * entity; // only one of entity / light will be non-NULL
  113. idRenderLightLocal * light; // only one of entity / light will be non-NULL
  114. struct portalArea_s * area; // so owners can find all the areas they are in
  115. } areaReference_t;
  116. // idRenderLight should become the new public interface replacing the qhandle_t to light defs in the idRenderWorld interface
  117. class idRenderLight {
  118. public:
  119. virtual ~idRenderLight() {}
  120. virtual void FreeRenderLight() = 0;
  121. virtual void UpdateRenderLight( const renderLight_t *re, bool forceUpdate = false ) = 0;
  122. virtual void GetRenderLight( renderLight_t *re ) = 0;
  123. virtual void ForceUpdate() = 0;
  124. virtual int GetIndex() = 0;
  125. };
  126. // idRenderEntity should become the new public interface replacing the qhandle_t to entity defs in the idRenderWorld interface
  127. class idRenderEntity {
  128. public:
  129. virtual ~idRenderEntity() {}
  130. virtual void FreeRenderEntity() = 0;
  131. virtual void UpdateRenderEntity( const renderEntity_t *re, bool forceUpdate = false ) = 0;
  132. virtual void GetRenderEntity( renderEntity_t *re ) = 0;
  133. virtual void ForceUpdate() = 0;
  134. virtual int GetIndex() = 0;
  135. // overlays are extra polygons that deform with animating models for blood and damage marks
  136. virtual void ProjectOverlay( const idPlane localTextureAxis[2], const idMaterial *material ) = 0;
  137. virtual void RemoveDecals() = 0;
  138. };
  139. class idRenderLightLocal : public idRenderLight {
  140. public:
  141. idRenderLightLocal();
  142. virtual void FreeRenderLight();
  143. virtual void UpdateRenderLight( const renderLight_t *re, bool forceUpdate = false );
  144. virtual void GetRenderLight( renderLight_t *re );
  145. virtual void ForceUpdate();
  146. virtual int GetIndex();
  147. renderLight_t parms; // specification
  148. bool lightHasMoved; // the light has changed its position since it was
  149. // first added, so the prelight model is not valid
  150. float modelMatrix[16]; // this is just a rearrangement of parms.axis and parms.origin
  151. idRenderWorldLocal * world;
  152. int index; // in world lightdefs
  153. int areaNum; // if not -1, we may be able to cull all the light's
  154. // interactions if !viewDef->connectedAreas[areaNum]
  155. int lastModifiedFrameNum; // to determine if it is constantly changing,
  156. // and should go in the dynamic frame memory, or kept
  157. // in the cached memory
  158. bool archived; // for demo writing
  159. // derived information
  160. idPlane lightProject[4];
  161. const idMaterial * lightShader; // guaranteed to be valid, even if parms.shader isn't
  162. idImage * falloffImage;
  163. idVec3 globalLightOrigin; // accounting for lightCenter and parallel
  164. idPlane frustum[6]; // in global space, positive side facing out, last two are front/back
  165. idWinding * frustumWindings[6]; // used for culling
  166. srfTriangles_t * frustumTris; // triangulated frustumWindings[]
  167. int numShadowFrustums; // one for projected lights, usually six for point lights
  168. shadowFrustum_t shadowFrustums[6];
  169. int viewCount; // if == tr.viewCount, the light is on the viewDef->viewLights list
  170. struct viewLight_s * viewLight;
  171. areaReference_t * references; // each area the light is present in will have a lightRef
  172. idInteraction * firstInteraction; // doubly linked list
  173. idInteraction * lastInteraction;
  174. struct doublePortal_s * foggedPortals;
  175. };
  176. class idRenderEntityLocal : public idRenderEntity {
  177. public:
  178. idRenderEntityLocal();
  179. virtual void FreeRenderEntity();
  180. virtual void UpdateRenderEntity( const renderEntity_t *re, bool forceUpdate = false );
  181. virtual void GetRenderEntity( renderEntity_t *re );
  182. virtual void ForceUpdate();
  183. virtual int GetIndex();
  184. // overlays are extra polygons that deform with animating models for blood and damage marks
  185. virtual void ProjectOverlay( const idPlane localTextureAxis[2], const idMaterial *material );
  186. virtual void RemoveDecals();
  187. renderEntity_t parms;
  188. float modelMatrix[16]; // this is just a rearrangement of parms.axis and parms.origin
  189. idRenderWorldLocal * world;
  190. int index; // in world entityDefs
  191. int lastModifiedFrameNum; // to determine if it is constantly changing,
  192. // and should go in the dynamic frame memory, or kept
  193. // in the cached memory
  194. bool archived; // for demo writing
  195. idRenderModel * dynamicModel; // if parms.model->IsDynamicModel(), this is the generated data
  196. int dynamicModelFrameCount; // continuously animating dynamic models will recreate
  197. // dynamicModel if this doesn't == tr.viewCount
  198. idRenderModel * cachedDynamicModel;
  199. idBounds referenceBounds; // the local bounds used to place entityRefs, either from parms or a model
  200. // a viewEntity_t is created whenever a idRenderEntityLocal is considered for inclusion
  201. // in a given view, even if it turns out to not be visible
  202. int viewCount; // if tr.viewCount == viewCount, viewEntity is valid,
  203. // but the entity may still be off screen
  204. struct viewEntity_s * viewEntity; // in frame temporary memory
  205. int visibleCount;
  206. // if tr.viewCount == visibleCount, at least one ambient
  207. // surface has actually been added by R_AddAmbientDrawsurfs
  208. // note that an entity could still be in the view frustum and not be visible due
  209. // to portal passing
  210. idRenderModelDecal * decals; // chain of decals that have been projected on this model
  211. idRenderModelOverlay * overlay; // blood overlays on animated models
  212. areaReference_t * entityRefs; // chain of all references
  213. idInteraction * firstInteraction; // doubly linked list
  214. idInteraction * lastInteraction;
  215. bool needsPortalSky;
  216. };
  217. // viewLights are allocated on the frame temporary stack memory
  218. // a viewLight contains everything that the back end needs out of an idRenderLightLocal,
  219. // which the front end may be modifying simultaniously if running in SMP mode.
  220. // a viewLight may exist even without any surfaces, and may be relevent for fogging,
  221. // but should never exist if its volume does not intersect the view frustum
  222. typedef struct viewLight_s {
  223. struct viewLight_s * next;
  224. // back end should NOT reference the lightDef, because it can change when running SMP
  225. idRenderLightLocal * lightDef;
  226. // for scissor clipping, local inside renderView viewport
  227. // scissorRect.Empty() is true if the viewEntity_t was never actually
  228. // seen through any portals
  229. idScreenRect scissorRect;
  230. // if the view isn't inside the light, we can use the non-reversed
  231. // shadow drawing, avoiding the draws of the front and rear caps
  232. bool viewInsideLight;
  233. // true if globalLightOrigin is inside the view frustum, even if it may
  234. // be obscured by geometry. This allows us to skip shadows from non-visible objects
  235. bool viewSeesGlobalLightOrigin;
  236. // if !viewInsideLight, the corresponding bit for each of the shadowFrustum
  237. // projection planes that the view is on the negative side of will be set,
  238. // allowing us to skip drawing the projected caps of shadows if we can't see the face
  239. int viewSeesShadowPlaneBits;
  240. idVec3 globalLightOrigin; // global light origin used by backend
  241. idPlane lightProject[4]; // light project used by backend
  242. idPlane fogPlane; // fog plane for backend fog volume rendering
  243. const srfTriangles_t * frustumTris; // light frustum for backend fog volume rendering
  244. const idMaterial * lightShader; // light shader used by backend
  245. const float * shaderRegisters; // shader registers used by backend
  246. idImage * falloffImage; // falloff image used by backend
  247. const struct drawSurf_s *globalShadows; // shadow everything
  248. const struct drawSurf_s *localInteractions; // don't get local shadows
  249. const struct drawSurf_s *localShadows; // don't shadow local Surfaces
  250. const struct drawSurf_s *globalInteractions; // get shadows from everything
  251. const struct drawSurf_s *translucentInteractions; // get shadows from everything
  252. } viewLight_t;
  253. // a viewEntity is created whenever a idRenderEntityLocal is considered for inclusion
  254. // in the current view, but it may still turn out to be culled.
  255. // viewEntity are allocated on the frame temporary stack memory
  256. // a viewEntity contains everything that the back end needs out of a idRenderEntityLocal,
  257. // which the front end may be modifying simultaniously if running in SMP mode.
  258. // A single entityDef can generate multiple viewEntity_t in a single frame, as when seen in a mirror
  259. typedef struct viewEntity_s {
  260. struct viewEntity_s *next;
  261. // back end should NOT reference the entityDef, because it can change when running SMP
  262. idRenderEntityLocal *entityDef;
  263. // for scissor clipping, local inside renderView viewport
  264. // scissorRect.Empty() is true if the viewEntity_t was never actually
  265. // seen through any portals, but was created for shadow casting.
  266. // a viewEntity can have a non-empty scissorRect, meaning that an area
  267. // that it is in is visible, and still not be visible.
  268. idScreenRect scissorRect;
  269. bool weaponDepthHack;
  270. float modelDepthHack;
  271. float modelMatrix[16]; // local coords to global coords
  272. float modelViewMatrix[16]; // local coords to eye coords
  273. } viewEntity_t;
  274. const int MAX_CLIP_PLANES = 1; // we may expand this to six for some subview issues
  275. // viewDefs are allocated on the frame temporary stack memory
  276. typedef struct viewDef_s {
  277. // specified in the call to DrawScene()
  278. renderView_t renderView;
  279. float projectionMatrix[16];
  280. viewEntity_t worldSpace;
  281. idRenderWorldLocal *renderWorld;
  282. float floatTime;
  283. idVec3 initialViewAreaOrigin;
  284. // Used to find the portalArea that view flooding will take place from.
  285. // for a normal view, the initialViewOrigin will be renderView.viewOrg,
  286. // but a mirror may put the projection origin outside
  287. // of any valid area, or in an unconnected area of the map, so the view
  288. // area must be based on a point just off the surface of the mirror / subview.
  289. // It may be possible to get a failed portal pass if the plane of the
  290. // mirror intersects a portal, and the initialViewAreaOrigin is on
  291. // a different side than the renderView.viewOrg is.
  292. bool isSubview; // true if this view is not the main view
  293. bool isMirror; // the portal is a mirror, invert the face culling
  294. bool isXraySubview;
  295. bool isEditor;
  296. int numClipPlanes; // mirrors will often use a single clip plane
  297. idPlane clipPlanes[MAX_CLIP_PLANES]; // in world space, the positive side
  298. // of the plane is the visible side
  299. idScreenRect viewport; // in real pixels and proper Y flip
  300. idScreenRect scissor;
  301. // for scissor clipping, local inside renderView viewport
  302. // subviews may only be rendering part of the main view
  303. // these are real physical pixel values, possibly scaled and offset from the
  304. // renderView x/y/width/height
  305. struct viewDef_s * superView; // never go into an infinite subview loop
  306. struct drawSurf_s * subviewSurface;
  307. // drawSurfs are the visible surfaces of the viewEntities, sorted
  308. // by the material sort parameter
  309. drawSurf_t ** drawSurfs; // we don't use an idList for this, because
  310. int numDrawSurfs; // it is allocated in frame temporary memory
  311. int maxDrawSurfs; // may be resized
  312. struct viewLight_s *viewLights; // chain of all viewLights effecting view
  313. struct viewEntity_s *viewEntitys; // chain of all viewEntities effecting view, including off screen ones casting shadows
  314. // we use viewEntities as a check to see if a given view consists solely
  315. // of 2D rendering, which we can optimize in certain ways. A 2D view will
  316. // not have any viewEntities
  317. idPlane frustum[5]; // positive sides face outward, [4] is the front clip plane
  318. idFrustum viewFrustum;
  319. int areaNum; // -1 = not in a valid area
  320. bool * connectedAreas;
  321. // An array in frame temporary memory that lists if an area can be reached without
  322. // crossing a closed door. This is used to avoid drawing interactions
  323. // when the light is behind a closed door.
  324. } viewDef_t;
  325. // complex light / surface interactions are broken up into multiple passes of a
  326. // simple interaction shader
  327. typedef struct {
  328. const drawSurf_t * surf;
  329. idImage * lightImage;
  330. idImage * lightFalloffImage;
  331. idImage * bumpImage;
  332. idImage * diffuseImage;
  333. idImage * specularImage;
  334. idVec4 diffuseColor; // may have a light color baked into it, will be < tr.backEndRendererMaxLight
  335. idVec4 specularColor; // may have a light color baked into it, will be < tr.backEndRendererMaxLight
  336. stageVertexColor_t vertexColor; // applies to both diffuse and specular
  337. int ambientLight; // use tr.ambientNormalMap instead of normalization cube map
  338. // (not a bool just to avoid an uninitialized memory check of the pad region by valgrind)
  339. // these are loaded into the vertex program
  340. idVec4 localLightOrigin;
  341. idVec4 localViewOrigin;
  342. idVec4 lightProjection[4]; // in local coordinates, possibly with a texture matrix baked in
  343. idVec4 bumpMatrix[2];
  344. idVec4 diffuseMatrix[2];
  345. idVec4 specularMatrix[2];
  346. } drawInteraction_t;
  347. /*
  348. =============================================================
  349. RENDERER BACK END COMMAND QUEUE
  350. TR_CMDS
  351. =============================================================
  352. */
  353. typedef enum {
  354. RC_NOP,
  355. RC_DRAW_VIEW,
  356. RC_SET_BUFFER,
  357. RC_COPY_RENDER,
  358. RC_SWAP_BUFFERS // can't just assume swap at end of list because
  359. // of forced list submission before syncs
  360. } renderCommand_t;
  361. typedef struct {
  362. renderCommand_t commandId, *next;
  363. } emptyCommand_t;
  364. typedef struct {
  365. renderCommand_t commandId, *next;
  366. GLenum buffer;
  367. int frameCount;
  368. } setBufferCommand_t;
  369. typedef struct {
  370. renderCommand_t commandId, *next;
  371. viewDef_t *viewDef;
  372. } drawSurfsCommand_t;
  373. typedef struct {
  374. renderCommand_t commandId, *next;
  375. int x, y, imageWidth, imageHeight;
  376. idImage *image;
  377. int cubeFace; // when copying to a cubeMap
  378. } copyRenderCommand_t;
  379. //=======================================================================
  380. // this is the inital allocation for max number of drawsurfs
  381. // in a given view, but it will automatically grow if needed
  382. const int INITIAL_DRAWSURFS = 0x4000;
  383. // a request for frame memory will never fail
  384. // (until malloc fails), but it may force the
  385. // allocation of a new memory block that will
  386. // be discontinuous with the existing memory
  387. typedef struct frameMemoryBlock_s {
  388. struct frameMemoryBlock_s *next;
  389. int size;
  390. int used;
  391. int poop; // so that base is 16 byte aligned
  392. byte base[4]; // dynamically allocated as [size]
  393. } frameMemoryBlock_t;
  394. // all of the information needed by the back end must be
  395. // contained in a frameData_t. This entire structure is
  396. // duplicated so the front and back end can run in parallel
  397. // on an SMP machine (OBSOLETE: this capability has been removed)
  398. typedef struct {
  399. // one or more blocks of memory for all frame
  400. // temporary allocations
  401. frameMemoryBlock_t *memory;
  402. // alloc will point somewhere into the memory chain
  403. frameMemoryBlock_t *alloc;
  404. srfTriangles_t * firstDeferredFreeTriSurf;
  405. srfTriangles_t * lastDeferredFreeTriSurf;
  406. int memoryHighwater; // max used on any frame
  407. // the currently building command list
  408. // commands can be inserted at the front if needed, as for required
  409. // dynamically generated textures
  410. emptyCommand_t *cmdHead, *cmdTail; // may be of other command type based on commandId
  411. } frameData_t;
  412. extern frameData_t *frameData;
  413. //=======================================================================
  414. void R_LockSurfaceScene( viewDef_t *parms );
  415. void R_ClearCommandChain( void );
  416. void R_AddDrawViewCmd( viewDef_t *parms );
  417. void R_ReloadGuis_f( const idCmdArgs &args );
  418. void R_ListGuis_f( const idCmdArgs &args );
  419. void *R_GetCommandBuffer( int bytes );
  420. // this allows a global override of all materials
  421. bool R_GlobalShaderOverride( const idMaterial **shader );
  422. // this does various checks before calling the idDeclSkin
  423. const idMaterial *R_RemapShaderBySkin( const idMaterial *shader, const idDeclSkin *customSkin, const idMaterial *customShader );
  424. //====================================================
  425. /*
  426. ** performanceCounters_t
  427. */
  428. typedef struct {
  429. int c_sphere_cull_in, c_sphere_cull_clip, c_sphere_cull_out;
  430. int c_box_cull_in, c_box_cull_out;
  431. int c_createInteractions; // number of calls to idInteraction::CreateInteraction
  432. int c_createLightTris;
  433. int c_createShadowVolumes;
  434. int c_generateMd5;
  435. int c_entityDefCallbacks;
  436. int c_alloc, c_free; // counts for R_StaticAllc/R_StaticFree
  437. int c_visibleViewEntities;
  438. int c_shadowViewEntities;
  439. int c_viewLights;
  440. int c_numViews; // number of total views rendered
  441. int c_deformedSurfaces; // idMD5Mesh::GenerateSurface
  442. int c_deformedVerts; // idMD5Mesh::GenerateSurface
  443. int c_deformedIndexes; // idMD5Mesh::GenerateSurface
  444. int c_tangentIndexes; // R_DeriveTangents()
  445. int c_entityUpdates, c_lightUpdates, c_entityReferences, c_lightReferences;
  446. int c_guiSurfs;
  447. int frontEndMsec; // sum of time in all RE_RenderScene's in a frame
  448. } performanceCounters_t;
  449. typedef struct {
  450. int current2DMap;
  451. int current3DMap;
  452. int currentCubeMap;
  453. int texEnv;
  454. textureType_t textureType;
  455. } tmu_t;
  456. const int MAX_MULTITEXTURE_UNITS = 8;
  457. typedef struct {
  458. tmu_t tmu[MAX_MULTITEXTURE_UNITS];
  459. int currenttmu;
  460. int faceCulling;
  461. int glStateBits;
  462. bool forceGlState; // the next GL_State will ignore glStateBits and set everything
  463. } glstate_t;
  464. typedef struct {
  465. int c_surfaces;
  466. int c_shaders;
  467. int c_vertexes;
  468. int c_indexes; // one set per pass
  469. int c_totalIndexes; // counting all passes
  470. int c_drawElements;
  471. int c_drawIndexes;
  472. int c_drawVertexes;
  473. int c_drawRefIndexes;
  474. int c_drawRefVertexes;
  475. int c_shadowElements;
  476. int c_shadowIndexes;
  477. int c_shadowVertexes;
  478. int c_vboIndexes;
  479. float c_overDraw;
  480. float maxLightValue; // for light scale
  481. int msec; // total msec for backend run
  482. } backEndCounters_t;
  483. // all state modified by the back end is separated
  484. // from the front end state
  485. typedef struct {
  486. int frameCount; // used to track all images used in a frame
  487. const viewDef_t * viewDef;
  488. backEndCounters_t pc;
  489. const viewEntity_t *currentSpace; // for detecting when a matrix must change
  490. idScreenRect currentScissor;
  491. // for scissor clipping, local inside renderView viewport
  492. viewLight_t * vLight;
  493. int depthFunc; // GLS_DEPTHFUNC_EQUAL, or GLS_DEPTHFUNC_LESS for translucent
  494. float lightTextureMatrix[16]; // only if lightStage->texture.hasMatrix
  495. float lightColor[4]; // evaluation of current light's color stage
  496. float lightScale; // Every light color calaculation will be multiplied by this,
  497. // which will guarantee that the result is < tr.backEndRendererMaxLight
  498. // A card with high dynamic range will have this set to 1.0
  499. float overBright; // The amount that all light interactions must be multiplied by
  500. // with post processing to get the desired total light level.
  501. // A high dynamic range card will have this set to 1.0.
  502. bool currentRenderCopied; // true if any material has already referenced _currentRender
  503. // our OpenGL state deltas
  504. glstate_t glState;
  505. int c_copyFrameBuffer;
  506. } backEndState_t;
  507. const int MAX_GUI_SURFACES = 1024; // default size of the drawSurfs list for guis, will
  508. // be automatically expanded as needed
  509. typedef enum {
  510. BE_ARB,
  511. BE_NV10,
  512. BE_NV20,
  513. BE_R200,
  514. BE_ARB2,
  515. BE_BAD
  516. } backEndName_t;
  517. typedef struct {
  518. int x, y, width, height; // these are in physical, OpenGL Y-at-bottom pixels
  519. } renderCrop_t;
  520. static const int MAX_RENDER_CROPS = 8;
  521. /*
  522. ** Most renderer globals are defined here.
  523. ** backend functions should never modify any of these fields,
  524. ** but may read fields that aren't dynamically modified
  525. ** by the frontend.
  526. */
  527. class idRenderSystemLocal : public idRenderSystem {
  528. public:
  529. // external functions
  530. virtual void Init( void );
  531. virtual void Shutdown( void );
  532. virtual void InitOpenGL( void );
  533. virtual void ShutdownOpenGL( void );
  534. virtual bool IsOpenGLRunning( void ) const;
  535. virtual bool IsFullScreen( void ) const;
  536. virtual int GetScreenWidth( void ) const;
  537. virtual int GetScreenHeight( void ) const;
  538. virtual idRenderWorld * AllocRenderWorld( void );
  539. virtual void FreeRenderWorld( idRenderWorld *rw );
  540. virtual void BeginLevelLoad( void );
  541. virtual void EndLevelLoad( void );
  542. virtual bool RegisterFont( const char *fontName, fontInfoEx_t &font );
  543. virtual void SetColor( const idVec4 &rgba );
  544. virtual void SetColor4( float r, float g, float b, float a );
  545. virtual void DrawStretchPic ( const idDrawVert *verts, const glIndex_t *indexes, int vertCount, int indexCount, const idMaterial *material,
  546. bool clip = true, float x = 0.0f, float y = 0.0f, float w = 640.0f, float h = 0.0f );
  547. virtual void DrawStretchPic ( float x, float y, float w, float h, float s1, float t1, float s2, float t2, const idMaterial *material );
  548. virtual void DrawStretchTri ( idVec2 p1, idVec2 p2, idVec2 p3, idVec2 t1, idVec2 t2, idVec2 t3, const idMaterial *material );
  549. virtual void GlobalToNormalizedDeviceCoordinates( const idVec3 &global, idVec3 &ndc );
  550. virtual void GetGLSettings( int& width, int& height );
  551. virtual void PrintMemInfo( MemInfo_t *mi );
  552. virtual void DrawSmallChar( int x, int y, int ch, const idMaterial *material );
  553. virtual void DrawSmallStringExt( int x, int y, const char *string, const idVec4 &setColor, bool forceColor, const idMaterial *material );
  554. virtual void DrawBigChar( int x, int y, int ch, const idMaterial *material );
  555. virtual void DrawBigStringExt( int x, int y, const char *string, const idVec4 &setColor, bool forceColor, const idMaterial *material );
  556. virtual void WriteDemoPics();
  557. virtual void DrawDemoPics();
  558. virtual void BeginFrame( int windowWidth, int windowHeight );
  559. virtual void EndFrame( int *frontEndMsec, int *backEndMsec );
  560. virtual void TakeScreenshot( int width, int height, const char *fileName, int downSample, renderView_t *ref );
  561. virtual void CropRenderSize( int width, int height, bool makePowerOfTwo = false, bool forceDimensions = false );
  562. virtual void CaptureRenderToImage( const char *imageName );
  563. virtual void CaptureRenderToFile( const char *fileName, bool fixAlpha );
  564. virtual void UnCrop();
  565. virtual void GetCardCaps( bool &oldCard, bool &nv10or20 );
  566. virtual bool UploadImage( const char *imageName, const byte *data, int width, int height );
  567. public:
  568. // internal functions
  569. idRenderSystemLocal( void );
  570. ~idRenderSystemLocal( void );
  571. void Clear( void );
  572. void SetBackEndRenderer(); // sets tr.backEndRenderer based on cvars
  573. void RenderViewToViewport( const renderView_t *renderView, idScreenRect *viewport );
  574. public:
  575. // renderer globals
  576. bool registered; // cleared at shutdown, set at InitOpenGL
  577. bool takingScreenshot;
  578. int frameCount; // incremented every frame
  579. int viewCount; // incremented every view (twice a scene if subviewed)
  580. // and every R_MarkFragments call
  581. int staticAllocCount; // running total of bytes allocated
  582. float frameShaderTime; // shader time for all non-world 2D rendering
  583. int viewportOffset[2]; // for doing larger-than-window tiled renderings
  584. int tiledViewport[2];
  585. // determines which back end to use, and if vertex programs are in use
  586. backEndName_t backEndRenderer;
  587. bool backEndRendererHasVertexPrograms;
  588. float backEndRendererMaxLight; // 1.0 for standard, unlimited for floats
  589. // determines how much overbrighting needs
  590. // to be done post-process
  591. idVec4 ambientLightVector; // used for "ambient bump mapping"
  592. float sortOffset; // for determinist sorting of equal sort materials
  593. idList<idRenderWorldLocal*>worlds;
  594. idRenderWorldLocal * primaryWorld;
  595. renderView_t primaryRenderView;
  596. viewDef_t * primaryView;
  597. // many console commands need to know which world they should operate on
  598. const idMaterial * defaultMaterial;
  599. idImage * testImage;
  600. idCinematic * testVideo;
  601. float testVideoStartTime;
  602. idImage * ambientCubeImage; // hack for testing dependent ambient lighting
  603. viewDef_t * viewDef;
  604. performanceCounters_t pc; // performance counters
  605. drawSurfsCommand_t lockSurfacesCmd; // use this when r_lockSurfaces = 1
  606. viewEntity_t identitySpace; // can use if we don't know viewDef->worldSpace is valid
  607. FILE * logFile; // for logging GL calls and frame breaks
  608. int stencilIncr, stencilDecr; // GL_INCR / INCR_WRAP_EXT, GL_DECR / GL_DECR_EXT
  609. renderCrop_t renderCrops[MAX_RENDER_CROPS];
  610. int currentRenderCrop;
  611. // GUI drawing variables for surface creation
  612. int guiRecursionLevel; // to prevent infinite overruns
  613. class idGuiModel * guiModel;
  614. class idGuiModel * demoGuiModel;
  615. unsigned short gammaTable[256]; // brightness / gamma modify this
  616. };
  617. extern backEndState_t backEnd;
  618. extern idRenderSystemLocal tr;
  619. extern glconfig_t glConfig; // outside of TR since it shouldn't be cleared during ref re-init
  620. //
  621. // cvars
  622. //
  623. extern idCVar r_ext_vertex_array_range;
  624. extern idCVar r_glDriver; // "opengl32", etc
  625. extern idCVar r_mode; // video mode number
  626. extern idCVar r_displayRefresh; // optional display refresh rate option for vid mode
  627. extern idCVar r_fullscreen; // 0 = windowed, 1 = full screen
  628. extern idCVar r_multiSamples; // number of antialiasing samples
  629. extern idCVar r_ignore; // used for random debugging without defining new vars
  630. extern idCVar r_ignore2; // used for random debugging without defining new vars
  631. extern idCVar r_znear; // near Z clip plane
  632. extern idCVar r_finish; // force a call to glFinish() every frame
  633. extern idCVar r_frontBuffer; // draw to front buffer for debugging
  634. extern idCVar r_swapInterval; // changes wglSwapIntarval
  635. extern idCVar r_offsetFactor; // polygon offset parameter
  636. extern idCVar r_offsetUnits; // polygon offset parameter
  637. extern idCVar r_singleTriangle; // only draw a single triangle per primitive
  638. extern idCVar r_logFile; // number of frames to emit GL logs
  639. extern idCVar r_clear; // force screen clear every frame
  640. extern idCVar r_shadows; // enable shadows
  641. extern idCVar r_subviewOnly; // 1 = don't render main view, allowing subviews to be debugged
  642. extern idCVar r_lightScale; // all light intensities are multiplied by this, which is normally 2
  643. extern idCVar r_flareSize; // scale the flare deforms from the material def
  644. extern idCVar r_gamma; // changes gamma tables
  645. extern idCVar r_brightness; // changes gamma tables
  646. extern idCVar r_renderer; // arb, nv10, nv20, r200, gl2, etc
  647. extern idCVar r_cgVertexProfile; // arbvp1, vp20, vp30
  648. extern idCVar r_cgFragmentProfile; // arbfp1, fp30
  649. extern idCVar r_checkBounds; // compare all surface bounds with precalculated ones
  650. extern idCVar r_useNV20MonoLights; // 1 = allow an interaction pass optimization
  651. extern idCVar r_useLightPortalFlow; // 1 = do a more precise area reference determination
  652. extern idCVar r_useTripleTextureARB; // 1 = cards with 3+ texture units do a two pass instead of three pass
  653. extern idCVar r_useShadowSurfaceScissor;// 1 = scissor shadows by the scissor rect of the interaction surfaces
  654. extern idCVar r_useConstantMaterials; // 1 = use pre-calculated material registers if possible
  655. extern idCVar r_useInteractionTable; // create a full entityDefs * lightDefs table to make finding interactions faster
  656. extern idCVar r_useNodeCommonChildren; // stop pushing reference bounds early when possible
  657. extern idCVar r_useSilRemap; // 1 = consider verts with the same XYZ, but different ST the same for shadows
  658. extern idCVar r_useCulling; // 0 = none, 1 = sphere, 2 = sphere + box
  659. extern idCVar r_useLightCulling; // 0 = none, 1 = box, 2 = exact clip of polyhedron faces
  660. extern idCVar r_useLightScissors; // 1 = use custom scissor rectangle for each light
  661. extern idCVar r_useClippedLightScissors;// 0 = full screen when near clipped, 1 = exact when near clipped, 2 = exact always
  662. extern idCVar r_useEntityCulling; // 0 = none, 1 = box
  663. extern idCVar r_useEntityScissors; // 1 = use custom scissor rectangle for each entity
  664. extern idCVar r_useInteractionCulling; // 1 = cull interactions
  665. extern idCVar r_useInteractionScissors; // 1 = use a custom scissor rectangle for each interaction
  666. extern idCVar r_useFrustumFarDistance; // if != 0 force the view frustum far distance to this distance
  667. extern idCVar r_useShadowCulling; // try to cull shadows from partially visible lights
  668. extern idCVar r_usePreciseTriangleInteractions; // 1 = do winding clipping to determine if each ambiguous tri should be lit
  669. extern idCVar r_useTurboShadow; // 1 = use the infinite projection with W technique for dynamic shadows
  670. extern idCVar r_useExternalShadows; // 1 = skip drawing caps when outside the light volume
  671. extern idCVar r_useOptimizedShadows; // 1 = use the dmap generated static shadow volumes
  672. extern idCVar r_useShadowVertexProgram; // 1 = do the shadow projection in the vertex program on capable cards
  673. extern idCVar r_useShadowProjectedCull; // 1 = discard triangles outside light volume before shadowing
  674. extern idCVar r_useDeferredTangents; // 1 = don't always calc tangents after deform
  675. extern idCVar r_useCachedDynamicModels; // 1 = cache snapshots of dynamic models
  676. extern idCVar r_useTwoSidedStencil; // 1 = do stencil shadows in one pass with different ops on each side
  677. extern idCVar r_useInfiniteFarZ; // 1 = use the no-far-clip-plane trick
  678. extern idCVar r_useScissor; // 1 = scissor clip as portals and lights are processed
  679. extern idCVar r_usePortals; // 1 = use portals to perform area culling, otherwise draw everything
  680. extern idCVar r_useStateCaching; // avoid redundant state changes in GL_*() calls
  681. extern idCVar r_useCombinerDisplayLists;// if 1, put all nvidia register combiner programming in display lists
  682. extern idCVar r_useVertexBuffers; // if 0, don't use ARB_vertex_buffer_object for vertexes
  683. extern idCVar r_useIndexBuffers; // if 0, don't use ARB_vertex_buffer_object for indexes
  684. extern idCVar r_useEntityCallbacks; // if 0, issue the callback immediately at update time, rather than defering
  685. extern idCVar r_lightAllBackFaces; // light all the back faces, even when they would be shadowed
  686. extern idCVar r_useDepthBoundsTest; // use depth bounds test to reduce shadow fill
  687. extern idCVar r_skipPostProcess; // skip all post-process renderings
  688. extern idCVar r_skipSuppress; // ignore the per-view suppressions
  689. extern idCVar r_skipInteractions; // skip all light/surface interaction drawing
  690. extern idCVar r_skipFrontEnd; // bypasses all front end work, but 2D gui rendering still draws
  691. extern idCVar r_skipBackEnd; // don't draw anything
  692. extern idCVar r_skipCopyTexture; // do all rendering, but don't actually copyTexSubImage2D
  693. extern idCVar r_skipRender; // skip 3D rendering, but pass 2D
  694. extern idCVar r_skipRenderContext; // NULL the rendering context during backend 3D rendering
  695. extern idCVar r_skipTranslucent; // skip the translucent interaction rendering
  696. extern idCVar r_skipAmbient; // bypasses all non-interaction drawing
  697. extern idCVar r_skipNewAmbient; // bypasses all vertex/fragment program ambients
  698. extern idCVar r_skipBlendLights; // skip all blend lights
  699. extern idCVar r_skipFogLights; // skip all fog lights
  700. extern idCVar r_skipSubviews; // 1 = don't render any mirrors / cameras / etc
  701. extern idCVar r_skipGuiShaders; // 1 = don't render any gui elements on surfaces
  702. extern idCVar r_skipParticles; // 1 = don't render any particles
  703. extern idCVar r_skipUpdates; // 1 = don't accept any entity or light updates, making everything static
  704. extern idCVar r_skipDeforms; // leave all deform materials in their original state
  705. extern idCVar r_skipDynamicTextures; // don't dynamically create textures
  706. extern idCVar r_skipLightScale; // don't do any post-interaction light scaling, makes things dim on low-dynamic range cards
  707. extern idCVar r_skipBump; // uses a flat surface instead of the bump map
  708. extern idCVar r_skipSpecular; // use black for specular
  709. extern idCVar r_skipDiffuse; // use black for diffuse
  710. extern idCVar r_skipOverlays; // skip overlay surfaces
  711. extern idCVar r_skipROQ;
  712. extern idCVar r_ignoreGLErrors;
  713. extern idCVar r_forceLoadImages; // draw all images to screen after registration
  714. extern idCVar r_demonstrateBug; // used during development to show IHV's their problems
  715. extern idCVar r_screenFraction; // for testing fill rate, the resolution of the entire screen can be changed
  716. extern idCVar r_showUnsmoothedTangents; // highlight geometry rendered with unsmoothed tangents
  717. extern idCVar r_showSilhouette; // highlight edges that are casting shadow planes
  718. extern idCVar r_showVertexColor; // draws all triangles with the solid vertex color
  719. extern idCVar r_showUpdates; // report entity and light updates and ref counts
  720. extern idCVar r_showDemo; // report reads and writes to the demo file
  721. extern idCVar r_showDynamic; // report stats on dynamic surface generation
  722. extern idCVar r_showLightScale; // report the scale factor applied to drawing for overbrights
  723. extern idCVar r_showIntensity; // draw the screen colors based on intensity, red = 0, green = 128, blue = 255
  724. extern idCVar r_showDefs; // report the number of modeDefs and lightDefs in view
  725. extern idCVar r_showTrace; // show the intersection of an eye trace with the world
  726. extern idCVar r_showSmp; // show which end (front or back) is blocking
  727. extern idCVar r_showDepth; // display the contents of the depth buffer and the depth range
  728. extern idCVar r_showImages; // draw all images to screen instead of rendering
  729. extern idCVar r_showTris; // enables wireframe rendering of the world
  730. extern idCVar r_showSurfaceInfo; // show surface material name under crosshair
  731. extern idCVar r_showNormals; // draws wireframe normals
  732. extern idCVar r_showEdges; // draw the sil edges
  733. extern idCVar r_showViewEntitys; // displays the bounding boxes of all view models and optionally the index
  734. extern idCVar r_showTexturePolarity; // shade triangles by texture area polarity
  735. extern idCVar r_showTangentSpace; // shade triangles by tangent space
  736. extern idCVar r_showDominantTri; // draw lines from vertexes to center of dominant triangles
  737. extern idCVar r_showTextureVectors; // draw each triangles texture (tangent) vectors
  738. extern idCVar r_showLights; // 1 = print light info, 2 = also draw volumes
  739. extern idCVar r_showLightCount; // colors surfaces based on light count
  740. extern idCVar r_showShadows; // visualize the stencil shadow volumes
  741. extern idCVar r_showShadowCount; // colors screen based on shadow volume depth complexity
  742. extern idCVar r_showLightScissors; // show light scissor rectangles
  743. extern idCVar r_showEntityScissors; // show entity scissor rectangles
  744. extern idCVar r_showInteractionFrustums;// show a frustum for each interaction
  745. extern idCVar r_showInteractionScissors;// show screen rectangle which contains the interaction frustum
  746. extern idCVar r_showMemory; // print frame memory utilization
  747. extern idCVar r_showCull; // report sphere and box culling stats
  748. extern idCVar r_showInteractions; // report interaction generation activity
  749. extern idCVar r_showSurfaces; // report surface/light/shadow counts
  750. extern idCVar r_showPrimitives; // report vertex/index/draw counts
  751. extern idCVar r_showPortals; // draw portal outlines in color based on passed / not passed
  752. extern idCVar r_showAlloc; // report alloc/free counts
  753. extern idCVar r_showSkel; // draw the skeleton when model animates
  754. extern idCVar r_showOverDraw; // show overdraw
  755. extern idCVar r_jointNameScale; // size of joint names when r_showskel is set to 1
  756. extern idCVar r_jointNameOffset; // offset of joint names when r_showskel is set to 1
  757. extern idCVar r_testGamma; // draw a grid pattern to test gamma levels
  758. extern idCVar r_testStepGamma; // draw a grid pattern to test gamma levels
  759. extern idCVar r_testGammaBias; // draw a grid pattern to test gamma levels
  760. extern idCVar r_testARBProgram; // experiment with vertex/fragment programs
  761. extern idCVar r_singleLight; // suppress all but one light
  762. extern idCVar r_singleEntity; // suppress all but one entity
  763. extern idCVar r_singleArea; // only draw the portal area the view is actually in
  764. extern idCVar r_singleSurface; // suppress all but one surface on each entity
  765. extern idCVar r_shadowPolygonOffset; // bias value added to depth test for stencil shadow drawing
  766. extern idCVar r_shadowPolygonFactor; // scale value for stencil shadow drawing
  767. extern idCVar r_jitter; // randomly subpixel jitter the projection matrix
  768. extern idCVar r_lightSourceRadius; // for soft-shadow sampling
  769. extern idCVar r_lockSurfaces;
  770. extern idCVar r_orderIndexes; // perform index reorganization to optimize vertex use
  771. extern idCVar r_debugLineDepthTest; // perform depth test on debug lines
  772. extern idCVar r_debugLineWidth; // width of debug lines
  773. extern idCVar r_debugArrowStep; // step size of arrow cone line rotation in degrees
  774. extern idCVar r_debugPolygonFilled;
  775. extern idCVar r_materialOverride; // override all materials
  776. extern idCVar r_debugRenderToTexture;
  777. /*
  778. ====================================================================
  779. GL wrapper/helper functions
  780. ====================================================================
  781. */
  782. void GL_SelectTexture( int unit );
  783. void GL_CheckErrors( void );
  784. void GL_ClearStateDelta( void );
  785. void GL_State( int stateVector );
  786. void GL_TexEnv( int env );
  787. void GL_Cull( int cullType );
  788. const int GLS_SRCBLEND_ZERO = 0x00000001;
  789. const int GLS_SRCBLEND_ONE = 0x0;
  790. const int GLS_SRCBLEND_DST_COLOR = 0x00000003;
  791. const int GLS_SRCBLEND_ONE_MINUS_DST_COLOR = 0x00000004;
  792. const int GLS_SRCBLEND_SRC_ALPHA = 0x00000005;
  793. const int GLS_SRCBLEND_ONE_MINUS_SRC_ALPHA = 0x00000006;
  794. const int GLS_SRCBLEND_DST_ALPHA = 0x00000007;
  795. const int GLS_SRCBLEND_ONE_MINUS_DST_ALPHA = 0x00000008;
  796. const int GLS_SRCBLEND_ALPHA_SATURATE = 0x00000009;
  797. const int GLS_SRCBLEND_BITS = 0x0000000f;
  798. const int GLS_DSTBLEND_ZERO = 0x0;
  799. const int GLS_DSTBLEND_ONE = 0x00000020;
  800. const int GLS_DSTBLEND_SRC_COLOR = 0x00000030;
  801. const int GLS_DSTBLEND_ONE_MINUS_SRC_COLOR = 0x00000040;
  802. const int GLS_DSTBLEND_SRC_ALPHA = 0x00000050;
  803. const int GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA = 0x00000060;
  804. const int GLS_DSTBLEND_DST_ALPHA = 0x00000070;
  805. const int GLS_DSTBLEND_ONE_MINUS_DST_ALPHA = 0x00000080;
  806. const int GLS_DSTBLEND_BITS = 0x000000f0;
  807. // these masks are the inverse, meaning when set the glColorMask value will be 0,
  808. // preventing that channel from being written
  809. const int GLS_DEPTHMASK = 0x00000100;
  810. const int GLS_REDMASK = 0x00000200;
  811. const int GLS_GREENMASK = 0x00000400;
  812. const int GLS_BLUEMASK = 0x00000800;
  813. const int GLS_ALPHAMASK = 0x00001000;
  814. const int GLS_COLORMASK = (GLS_REDMASK|GLS_GREENMASK|GLS_BLUEMASK);
  815. const int GLS_POLYMODE_LINE = 0x00002000;
  816. const int GLS_DEPTHFUNC_ALWAYS = 0x00010000;
  817. const int GLS_DEPTHFUNC_EQUAL = 0x00020000;
  818. const int GLS_DEPTHFUNC_LESS = 0x0;
  819. const int GLS_ATEST_EQ_255 = 0x10000000;
  820. const int GLS_ATEST_LT_128 = 0x20000000;
  821. const int GLS_ATEST_GE_128 = 0x40000000;
  822. const int GLS_ATEST_BITS = 0x70000000;
  823. const int GLS_DEFAULT = GLS_DEPTHFUNC_ALWAYS;
  824. void R_Init( void );
  825. void R_InitOpenGL( void );
  826. void R_DoneFreeType( void );
  827. void R_SetColorMappings( void );
  828. void R_ScreenShot_f( const idCmdArgs &args );
  829. void R_StencilShot( void );
  830. bool R_CheckExtension( char *name );
  831. /*
  832. ====================================================================
  833. IMPLEMENTATION SPECIFIC FUNCTIONS
  834. ====================================================================
  835. */
  836. typedef struct {
  837. int width;
  838. int height;
  839. bool fullScreen;
  840. bool stereo;
  841. int displayHz;
  842. int multiSamples;
  843. } glimpParms_t;
  844. bool GLimp_Init( glimpParms_t parms );
  845. // If the desired mode can't be set satisfactorily, false will be returned.
  846. // The renderer will then reset the glimpParms to "safe mode" of 640x480
  847. // fullscreen and try again. If that also fails, the error will be fatal.
  848. bool GLimp_SetScreenParms( glimpParms_t parms );
  849. // will set up gl up with the new parms
  850. void GLimp_Shutdown( void );
  851. // Destroys the rendering context, closes the window, resets the resolution,
  852. // and resets the gamma ramps.
  853. void GLimp_SwapBuffers( void );
  854. // Calls the system specific swapbuffers routine, and may also perform
  855. // other system specific cvar checks that happen every frame.
  856. // This will not be called if 'r_drawBuffer GL_FRONT'
  857. void GLimp_SetGamma( unsigned short red[256],
  858. unsigned short green[256],
  859. unsigned short blue[256] );
  860. // Sets the hardware gamma ramps for gamma and brightness adjustment.
  861. // These are now taken as 16 bit values, so we can take full advantage
  862. // of dacs with >8 bits of precision
  863. bool GLimp_SpawnRenderThread( void (*function)( void ) );
  864. // Returns false if the system only has a single processor
  865. void * GLimp_BackEndSleep( void );
  866. void GLimp_FrontEndSleep( void );
  867. void GLimp_WakeBackEnd( void *data );
  868. // these functions implement the dual processor syncronization
  869. void GLimp_ActivateContext( void );
  870. void GLimp_DeactivateContext( void );
  871. // These are used for managing SMP handoffs of the OpenGL context
  872. // between threads, and as a performance tunining aid. Setting
  873. // 'r_skipRenderContext 1' will call GLimp_DeactivateContext() before
  874. // the 3D rendering code, and GLimp_ActivateContext() afterwards. On
  875. // most OpenGL implementations, this will result in all OpenGL calls
  876. // being immediate returns, which lets us guage how much time is
  877. // being spent inside OpenGL.
  878. void GLimp_EnableLogging( bool enable );
  879. #ifdef USE_SDL
  880. const int GRAB_ENABLE = (1 << 0);
  881. const int GRAB_REENABLE = (1 << 1);
  882. const int GRAB_HIDECURSOR = (1 << 2);
  883. const int GRAB_SETSTATE = (1 << 3);
  884. void GLimp_GrabInput(int flags);
  885. #endif
  886. /*
  887. ====================================================================
  888. MAIN
  889. ====================================================================
  890. */
  891. void R_RenderView( viewDef_t *parms );
  892. // performs radius cull first, then corner cull
  893. bool R_CullLocalBox( const idBounds &bounds, const float modelMatrix[16], int numPlanes, const idPlane *planes );
  894. bool R_RadiusCullLocalBox( const idBounds &bounds, const float modelMatrix[16], int numPlanes, const idPlane *planes );
  895. bool R_CornerCullLocalBox( const idBounds &bounds, const float modelMatrix[16], int numPlanes, const idPlane *planes );
  896. void R_AxisToModelMatrix( const idMat3 &axis, const idVec3 &origin, float modelMatrix[16] );
  897. // note that many of these assume a normalized matrix, and will not work with scaled axis
  898. void R_GlobalPointToLocal( const float modelMatrix[16], const idVec3 &in, idVec3 &out );
  899. void R_GlobalVectorToLocal( const float modelMatrix[16], const idVec3 &in, idVec3 &out );
  900. void R_GlobalPlaneToLocal( const float modelMatrix[16], const idPlane &in, idPlane &out );
  901. void R_PointTimesMatrix( const float modelMatrix[16], const idVec4 &in, idVec4 &out );
  902. void R_LocalPointToGlobal( const float modelMatrix[16], const idVec3 &in, idVec3 &out );
  903. void R_LocalVectorToGlobal( const float modelMatrix[16], const idVec3 &in, idVec3 &out );
  904. void R_LocalPlaneToGlobal( const float modelMatrix[16], const idPlane &in, idPlane &out );
  905. void R_TransformEyeZToWin( float src_z, const float *projectionMatrix, float &dst_z );
  906. void R_GlobalToNormalizedDeviceCoordinates( const idVec3 &global, idVec3 &ndc );
  907. void R_TransformModelToClip( const idVec3 &src, const float *modelMatrix, const float *projectionMatrix, idPlane &eye, idPlane &dst );
  908. void R_TransformClipToDevice( const idPlane &clip, const viewDef_t *view, idVec3 &normalized );
  909. void R_TransposeGLMatrix( const float in[16], float out[16] );
  910. void R_SetViewMatrix( viewDef_t *viewDef );
  911. void myGlMultMatrix( const float *a, const float *b, float *out );
  912. /*
  913. ============================================================
  914. LIGHT
  915. ============================================================
  916. */
  917. void R_ListRenderLightDefs_f( const idCmdArgs &args );
  918. void R_ListRenderEntityDefs_f( const idCmdArgs &args );
  919. bool R_IssueEntityDefCallback( idRenderEntityLocal *def );
  920. idRenderModel *R_EntityDefDynamicModel( idRenderEntityLocal *def );
  921. viewEntity_t *R_SetEntityDefViewEntity( idRenderEntityLocal *def );
  922. viewLight_t *R_SetLightDefViewLight( idRenderLightLocal *def );
  923. void R_AddDrawSurf( const srfTriangles_t *tri, const viewEntity_t *space, const renderEntity_t *renderEntity,
  924. const idMaterial *shader, const idScreenRect &scissor );
  925. void R_LinkLightSurf( const drawSurf_t **link, const srfTriangles_t *tri, const viewEntity_t *space,
  926. const idRenderLightLocal *light, const idMaterial *shader, const idScreenRect &scissor, bool viewInsideShadow );
  927. bool R_CreateAmbientCache( srfTriangles_t *tri, bool needsLighting );
  928. bool R_CreateLightingCache( const idRenderEntityLocal *ent, const idRenderLightLocal *light, srfTriangles_t *tri );
  929. void R_CreatePrivateShadowCache( srfTriangles_t *tri );
  930. void R_CreateVertexProgramShadowCache( srfTriangles_t *tri );
  931. /*
  932. ============================================================
  933. LIGHTRUN
  934. ============================================================
  935. */
  936. void R_RegenerateWorld_f( const idCmdArgs &args );
  937. void R_ModulateLights_f( const idCmdArgs &args );
  938. void R_SetLightProject( idPlane lightProject[4], const idVec3 origin, const idVec3 targetPoint,
  939. const idVec3 rightVector, const idVec3 upVector, const idVec3 start, const idVec3 stop );
  940. void R_AddLightSurfaces( void );
  941. void R_AddModelSurfaces( void );
  942. void R_RemoveUnecessaryViewLights( void );
  943. void R_FreeDerivedData( void );
  944. void R_ReCreateWorldReferences( void );
  945. void R_CreateEntityRefs( idRenderEntityLocal *def );
  946. void R_CreateLightRefs( idRenderLightLocal *light );
  947. void R_DeriveLightData( idRenderLightLocal *light );
  948. void R_FreeLightDefDerivedData( idRenderLightLocal *light );
  949. void R_CheckForEntityDefsUsingModel( idRenderModel *model );
  950. void R_ClearEntityDefDynamicModel( idRenderEntityLocal *def );
  951. void R_FreeEntityDefDerivedData( idRenderEntityLocal *def, bool keepDecals, bool keepCachedDynamicModel );
  952. void R_FreeEntityDefCachedDynamicModel( idRenderEntityLocal *def );
  953. void R_FreeEntityDefDecals( idRenderEntityLocal *def );
  954. void R_FreeEntityDefOverlay( idRenderEntityLocal *def );
  955. void R_FreeEntityDefFadedDecals( idRenderEntityLocal *def, int time );
  956. void R_CreateLightDefFogPortals( idRenderLightLocal *ldef );
  957. /*
  958. ============================================================
  959. POLYTOPE
  960. ============================================================
  961. */
  962. srfTriangles_t *R_PolytopeSurface( int numPlanes, const idPlane *planes, idWinding **windings );
  963. /*
  964. ============================================================
  965. RENDER
  966. ============================================================
  967. */
  968. void RB_EnterWeaponDepthHack();
  969. void RB_EnterModelDepthHack( float depth );
  970. void RB_LeaveDepthHack();
  971. void RB_DrawElementsImmediate( const srfTriangles_t *tri );
  972. void RB_RenderTriangleSurface( const srfTriangles_t *tri );
  973. void RB_T_RenderTriangleSurface( const drawSurf_t *surf );
  974. void RB_RenderDrawSurfListWithFunction( drawSurf_t **drawSurfs, int numDrawSurfs,
  975. void (*triFunc_)( const drawSurf_t *) );
  976. void RB_RenderDrawSurfChainWithFunction( const drawSurf_t *drawSurfs,
  977. void (*triFunc_)( const drawSurf_t *) );
  978. void RB_DrawShaderPasses( drawSurf_t **drawSurfs, int numDrawSurfs );
  979. void RB_LoadShaderTextureMatrix( const float *shaderRegisters, const textureStage_t *texture );
  980. void RB_GetShaderTextureMatrix( const float *shaderRegisters, const textureStage_t *texture, float matrix[16] );
  981. void RB_CreateSingleDrawInteractions( const drawSurf_t *surf, void (*DrawInteraction)(const drawInteraction_t *) );
  982. const shaderStage_t *RB_SetLightTexture( const idRenderLightLocal *light );
  983. void RB_DrawView( const void *data );
  984. void RB_DetermineLightScale( void );
  985. void RB_STD_LightScale( void );
  986. void RB_BeginDrawingView (void);
  987. /*
  988. ============================================================
  989. DRAW_STANDARD
  990. ============================================================
  991. */
  992. void RB_DrawElementsWithCounters( const srfTriangles_t *tri );
  993. void RB_DrawShadowElementsWithCounters( const srfTriangles_t *tri, int numIndexes );
  994. void RB_STD_FillDepthBuffer( drawSurf_t **drawSurfs, int numDrawSurfs );
  995. void RB_BindVariableStageImage( const textureStage_t *texture, const float *shaderRegisters );
  996. void RB_BindStageTexture( const float *shaderRegisters, const textureStage_t *texture, const drawSurf_t *surf );
  997. void RB_FinishStageTexture( const textureStage_t *texture, const drawSurf_t *surf );
  998. void RB_StencilShadowPass( const drawSurf_t *drawSurfs );
  999. void RB_STD_DrawView( void );
  1000. void RB_STD_FogAllLights( void );
  1001. void RB_BakeTextureMatrixIntoTexgen( idPlane lightProject[3], const float textureMatrix[16] );
  1002. /*
  1003. ============================================================
  1004. DRAW_*
  1005. ============================================================
  1006. */
  1007. void RB_ARB_DrawInteractions( void );
  1008. void R_R200_Init( void );
  1009. void RB_R200_DrawInteractions( void );
  1010. void R_NV10_Init( void );
  1011. void RB_NV10_DrawInteractions( void );
  1012. void R_NV20_Init( void );
  1013. void RB_NV20_DrawInteractions( void );
  1014. void R_ARB2_Init( void );
  1015. void RB_ARB2_DrawInteractions( void );
  1016. void R_ReloadARBPrograms_f( const idCmdArgs &args );
  1017. int R_FindARBProgram( GLenum target, const char *program );
  1018. typedef enum {
  1019. PROG_INVALID,
  1020. VPROG_INTERACTION,
  1021. VPROG_ENVIRONMENT,
  1022. VPROG_BUMPY_ENVIRONMENT,
  1023. VPROG_R200_INTERACTION,
  1024. VPROG_STENCIL_SHADOW,
  1025. VPROG_NV20_BUMP_AND_LIGHT,
  1026. VPROG_NV20_DIFFUSE_COLOR,
  1027. VPROG_NV20_SPECULAR_COLOR,
  1028. VPROG_NV20_DIFFUSE_AND_SPECULAR_COLOR,
  1029. VPROG_TEST,
  1030. FPROG_INTERACTION,
  1031. FPROG_ENVIRONMENT,
  1032. FPROG_BUMPY_ENVIRONMENT,
  1033. FPROG_TEST,
  1034. VPROG_AMBIENT,
  1035. FPROG_AMBIENT,
  1036. VPROG_GLASSWARP,
  1037. FPROG_GLASSWARP,
  1038. PROG_USER
  1039. } program_t;
  1040. /*
  1041. All vertex programs use the same constant register layout:
  1042. c[4] localLightOrigin
  1043. c[5] localViewOrigin
  1044. c[6] lightProjection S
  1045. c[7] lightProjection T
  1046. c[8] lightProjection Q
  1047. c[9] lightFalloff S
  1048. c[10] bumpMatrix S
  1049. c[11] bumpMatrix T
  1050. c[12] diffuseMatrix S
  1051. c[13] diffuseMatrix T
  1052. c[14] specularMatrix S
  1053. c[15] specularMatrix T
  1054. c[20] light falloff tq constant
  1055. // texture 0 was cube map
  1056. // texture 1 will be the per-surface bump map
  1057. // texture 2 will be the light falloff texture
  1058. // texture 3 will be the light projection texture
  1059. // texture 4 is the per-surface diffuse map
  1060. // texture 5 is the per-surface specular map
  1061. // texture 6 is the specular half angle cube map
  1062. */
  1063. typedef enum {
  1064. PP_LIGHT_ORIGIN = 4,
  1065. PP_VIEW_ORIGIN,
  1066. PP_LIGHT_PROJECT_S,
  1067. PP_LIGHT_PROJECT_T,
  1068. PP_LIGHT_PROJECT_Q,
  1069. PP_LIGHT_FALLOFF_S,
  1070. PP_BUMP_MATRIX_S,
  1071. PP_BUMP_MATRIX_T,
  1072. PP_DIFFUSE_MATRIX_S,
  1073. PP_DIFFUSE_MATRIX_T,
  1074. PP_SPECULAR_MATRIX_S,
  1075. PP_SPECULAR_MATRIX_T,
  1076. PP_COLOR_MODULATE,
  1077. PP_COLOR_ADD,
  1078. PP_LIGHT_FALLOFF_TQ = 20 // only for NV programs
  1079. } programParameter_t;
  1080. /*
  1081. ============================================================
  1082. TR_STENCILSHADOWS
  1083. "facing" should have one more element than tri->numIndexes / 3, which should be set to 1
  1084. ============================================================
  1085. */
  1086. void R_MakeShadowFrustums( idRenderLightLocal *def );
  1087. typedef enum {
  1088. SG_DYNAMIC, // use infinite projections
  1089. SG_STATIC, // clip to bounds
  1090. SG_OFFLINE // perform very time consuming optimizations
  1091. } shadowGen_t;
  1092. srfTriangles_t *R_CreateShadowVolume( const idRenderEntityLocal *ent,
  1093. const srfTriangles_t *tri, const idRenderLightLocal *light,
  1094. shadowGen_t optimize, srfCullInfo_t &cullInfo );
  1095. /*
  1096. ============================================================
  1097. TR_TURBOSHADOW
  1098. Fast, non-clipped overshoot shadow volumes
  1099. "facing" should have one more element than tri->numIndexes / 3, which should be set to 1
  1100. calling this function may modify "facing" based on culling
  1101. ============================================================
  1102. */
  1103. srfTriangles_t *R_CreateVertexProgramTurboShadowVolume( const idRenderEntityLocal *ent,
  1104. const srfTriangles_t *tri, const idRenderLightLocal *light,
  1105. srfCullInfo_t &cullInfo );
  1106. srfTriangles_t *R_CreateTurboShadowVolume( const idRenderEntityLocal *ent,
  1107. const srfTriangles_t *tri, const idRenderLightLocal *light,
  1108. srfCullInfo_t &cullInfo );
  1109. /*
  1110. ============================================================
  1111. util/shadowopt3
  1112. dmap time optimization of shadow volumes, called from R_CreateShadowVolume
  1113. ============================================================
  1114. */
  1115. typedef struct {
  1116. idVec3 *verts; // includes both front and back projections, caller should free
  1117. int numVerts;
  1118. glIndex_t *indexes; // caller should free
  1119. // indexes must be sorted frontCap, rearCap, silPlanes so the caps can be removed
  1120. // when the viewer is in a position that they don't need to see them
  1121. int numFrontCapIndexes;
  1122. int numRearCapIndexes;
  1123. int numSilPlaneIndexes;
  1124. int totalIndexes;
  1125. } optimizedShadow_t;
  1126. optimizedShadow_t SuperOptimizeOccluders( idVec4 *verts, glIndex_t *indexes, int numIndexes,
  1127. idPlane projectionPlane, idVec3 projectionOrigin );
  1128. void CleanupOptimizedShadowTris( srfTriangles_t *tri );
  1129. /*
  1130. ============================================================
  1131. TRISURF
  1132. ============================================================
  1133. */
  1134. #define USE_TRI_DATA_ALLOCATOR
  1135. void R_InitTriSurfData( void );
  1136. void R_ShutdownTriSurfData( void );
  1137. void R_PurgeTriSurfData( frameData_t *frame );
  1138. void R_ShowTriSurfMemory_f( const idCmdArgs &args );
  1139. srfTriangles_t * R_AllocStaticTriSurf( void );
  1140. srfTriangles_t * R_CopyStaticTriSurf( const srfTriangles_t *tri );
  1141. void R_AllocStaticTriSurfVerts( srfTriangles_t *tri, int numVerts );
  1142. void R_AllocStaticTriSurfIndexes( srfTriangles_t *tri, int numIndexes );
  1143. void R_AllocStaticTriSurfShadowVerts( srfTriangles_t *tri, int numVerts );
  1144. void R_AllocStaticTriSurfPlanes( srfTriangles_t *tri, int numIndexes );
  1145. void R_ResizeStaticTriSurfVerts( srfTriangles_t *tri, int numVerts );
  1146. void R_ResizeStaticTriSurfIndexes( srfTriangles_t *tri, int numIndexes );
  1147. void R_ResizeStaticTriSurfShadowVerts( srfTriangles_t *tri, int numVerts );
  1148. void R_ReferenceStaticTriSurfVerts( srfTriangles_t *tri, const srfTriangles_t *reference );
  1149. void R_ReferenceStaticTriSurfIndexes( srfTriangles_t *tri, const srfTriangles_t *reference );
  1150. void R_FreeStaticTriSurfSilIndexes( srfTriangles_t *tri );
  1151. void R_FreeStaticTriSurf( srfTriangles_t *tri );
  1152. void R_FreeStaticTriSurfVertexCaches( srfTriangles_t *tri );
  1153. void R_ReallyFreeStaticTriSurf( srfTriangles_t *tri );
  1154. void R_FreeDeferredTriSurfs( frameData_t *frame );
  1155. int R_TriSurfMemory( const srfTriangles_t *tri );
  1156. void R_BoundTriSurf( srfTriangles_t *tri );
  1157. void R_RemoveDuplicatedTriangles( srfTriangles_t *tri );
  1158. void R_CreateSilIndexes( srfTriangles_t *tri );
  1159. void R_RemoveDegenerateTriangles( srfTriangles_t *tri );
  1160. void R_RemoveUnusedVerts( srfTriangles_t *tri );
  1161. void R_RangeCheckIndexes( const srfTriangles_t *tri );
  1162. void R_CreateVertexNormals( srfTriangles_t *tri ); // also called by dmap
  1163. void R_DeriveFacePlanes( srfTriangles_t *tri ); // also called by renderbump
  1164. void R_CleanupTriangles( srfTriangles_t *tri, bool createNormals, bool identifySilEdges, bool useUnsmoothedTangents );
  1165. void R_ReverseTriangles( srfTriangles_t *tri );
  1166. // Only deals with vertexes and indexes, not silhouettes, planes, etc.
  1167. // Does NOT perform a cleanup triangles, so there may be duplicated verts in the result.
  1168. srfTriangles_t * R_MergeSurfaceList( const srfTriangles_t **surfaces, int numSurfaces );
  1169. srfTriangles_t * R_MergeTriangles( const srfTriangles_t *tri1, const srfTriangles_t *tri2 );
  1170. // if the deformed verts have significant enough texture coordinate changes to reverse the texture
  1171. // polarity of a triangle, the tangents will be incorrect
  1172. void R_DeriveTangents( srfTriangles_t *tri, bool allocFacePlanes = true );
  1173. // deformable meshes precalculate as much as possible from a base frame, then generate
  1174. // complete srfTriangles_t from just a new set of vertexes
  1175. typedef struct deformInfo_s {
  1176. int numSourceVerts;
  1177. // numOutputVerts may be smaller if the input had duplicated or degenerate triangles
  1178. // it will often be larger if the input had mirrored texture seams that needed
  1179. // to be busted for proper tangent spaces
  1180. int numOutputVerts;
  1181. int numMirroredVerts;
  1182. int * mirroredVerts;
  1183. int numIndexes;
  1184. glIndex_t * indexes;
  1185. glIndex_t * silIndexes;
  1186. int numDupVerts;
  1187. int * dupVerts;
  1188. int numSilEdges;
  1189. silEdge_t * silEdges;
  1190. dominantTri_t * dominantTris;
  1191. } deformInfo_t;
  1192. deformInfo_t * R_BuildDeformInfo( int numVerts, const idDrawVert *verts, int numIndexes, const int *indexes, bool useUnsmoothedTangents );
  1193. void R_FreeDeformInfo( deformInfo_t *deformInfo );
  1194. int R_DeformInfoMemoryUsed( deformInfo_t *deformInfo );
  1195. /*
  1196. ============================================================
  1197. SUBVIEW
  1198. ============================================================
  1199. */
  1200. bool R_PreciseCullSurface( const drawSurf_t *drawSurf, idBounds &ndcBounds );
  1201. bool R_GenerateSubViews( void );
  1202. /*
  1203. ============================================================
  1204. SCENE GENERATION
  1205. ============================================================
  1206. */
  1207. void R_InitFrameData( void );
  1208. void R_ShutdownFrameData( void );
  1209. int R_CountFrameData( void );
  1210. void R_ToggleSmpFrame( void );
  1211. void *R_FrameAlloc( int bytes );
  1212. void *R_ClearedFrameAlloc( int bytes );
  1213. void R_FrameFree( void *data );
  1214. void *R_StaticAlloc( int bytes ); // just malloc with error checking
  1215. void *R_ClearedStaticAlloc( int bytes ); // with memset
  1216. void R_StaticFree( void *data );
  1217. /*
  1218. =============================================================
  1219. RENDERER DEBUG TOOLS
  1220. =============================================================
  1221. */
  1222. float RB_DrawTextLength( const char *text, float scale, int len );
  1223. void RB_AddDebugText( const char *text, const idVec3 &origin, float scale, const idVec4 &color, const idMat3 &viewAxis, const int align, const int lifetime, const bool depthTest );
  1224. void RB_ClearDebugText( int time );
  1225. void RB_AddDebugLine( const idVec4 &color, const idVec3 &start, const idVec3 &end, const int lifeTime, const bool depthTest );
  1226. void RB_ClearDebugLines( int time );
  1227. void RB_AddDebugPolygon( const idVec4 &color, const idWinding &winding, const int lifeTime, const bool depthTest );
  1228. void RB_ClearDebugPolygons( int time );
  1229. void RB_DrawBounds( const idBounds &bounds );
  1230. void RB_ShowLights( drawSurf_t **drawSurfs, int numDrawSurfs );
  1231. void RB_ShowLightCount( drawSurf_t **drawSurfs, int numDrawSurfs );
  1232. void RB_PolygonClear( void );
  1233. void RB_ScanStencilBuffer( void );
  1234. void RB_ShowDestinationAlpha( void );
  1235. void RB_ShowOverdraw( void );
  1236. void RB_RenderDebugTools( drawSurf_t **drawSurfs, int numDrawSurfs );
  1237. void RB_ShutdownDebugTools( void );
  1238. /*
  1239. =============================================================
  1240. TR_BACKEND
  1241. =============================================================
  1242. */
  1243. void RB_SetDefaultGLState( void );
  1244. void RB_SetGL2D( void );
  1245. // write a comment to the r_logFile if it is enabled
  1246. void RB_LogComment( const char *comment, ... ) id_attribute((format(printf,1,2)));
  1247. void RB_ShowImages( void );
  1248. void RB_ExecuteBackEndCommands( const emptyCommand_t *cmds );
  1249. /*
  1250. =============================================================
  1251. TR_GUISURF
  1252. =============================================================
  1253. */
  1254. void R_SurfaceToTextureAxis( const srfTriangles_t *tri, idVec3 &origin, idVec3 axis[3] );
  1255. void R_RenderGuiSurf( idUserInterface *gui, drawSurf_t *drawSurf );
  1256. /*
  1257. =============================================================
  1258. TR_ORDERINDEXES
  1259. =============================================================
  1260. */
  1261. void R_OrderIndexes( int numIndexes, glIndex_t *indexes );
  1262. /*
  1263. =============================================================
  1264. TR_DEFORM
  1265. =============================================================
  1266. */
  1267. void R_DeformDrawSurf( drawSurf_t *drawSurf );
  1268. /*
  1269. =============================================================
  1270. TR_TRACE
  1271. =============================================================
  1272. */
  1273. typedef struct {
  1274. float fraction;
  1275. // only valid if fraction < 1.0
  1276. idVec3 point;
  1277. idVec3 normal;
  1278. int indexes[3];
  1279. } localTrace_t;
  1280. localTrace_t R_LocalTrace( const idVec3 &start, const idVec3 &end, const float radius, const srfTriangles_t *tri );
  1281. void RB_ShowTrace( drawSurf_t **drawSurfs, int numDrawSurfs );
  1282. /*
  1283. =============================================================
  1284. TR_SHADOWBOUNDS
  1285. =============================================================
  1286. */
  1287. idScreenRect R_CalcIntersectionScissor( const idRenderLightLocal * lightDef,
  1288. const idRenderEntityLocal * entityDef,
  1289. const viewDef_t * viewDef );
  1290. //=============================================
  1291. #include "RenderWorld_local.h"
  1292. #include "GuiModel.h"
  1293. #include "VertexCache.h"
  1294. #endif /* !__TR_LOCAL_H__ */