RenderSystem_init.cpp 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325
  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. #include "../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "tr_local.h"
  23. // Vista OpenGL wrapper check
  24. #ifdef _WIN32
  25. #include "../sys/win32/win_local.h"
  26. #endif
  27. // functions that are not called every frame
  28. glconfig_t glConfig;
  29. static void GfxInfo_f( void );
  30. const char *r_rendererArgs[] = { "best", "arb", "arb2", "Cg", "exp", "nv10", "nv20", "r200", NULL };
  31. idCVar r_inhibitFragmentProgram( "r_inhibitFragmentProgram", "0", CVAR_RENDERER | CVAR_BOOL, "ignore the fragment program extension" );
  32. idCVar r_glDriver( "r_glDriver", "", CVAR_RENDERER, "\"opengl32\", etc." );
  33. idCVar r_useLightPortalFlow( "r_useLightPortalFlow", "1", CVAR_RENDERER | CVAR_BOOL, "use a more precise area reference determination" );
  34. idCVar r_multiSamples( "r_multiSamples", "0", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER, "number of antialiasing samples" );
  35. idCVar r_mode( "r_mode", "3", CVAR_ARCHIVE | CVAR_RENDERER | CVAR_INTEGER, "video mode number" );
  36. idCVar r_displayRefresh( "r_displayRefresh", "0", CVAR_RENDERER | CVAR_INTEGER | CVAR_NOCHEAT, "optional display refresh rate option for vid mode", 0.0f, 200.0f );
  37. idCVar r_fullscreen( "r_fullscreen", "1", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_BOOL, "0 = windowed, 1 = full screen" );
  38. idCVar r_customWidth( "r_customWidth", "720", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER, "custom screen width. set r_mode to -1 to activate" );
  39. idCVar r_customHeight( "r_customHeight", "486", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER, "custom screen height. set r_mode to -1 to activate" );
  40. idCVar r_singleTriangle( "r_singleTriangle", "0", CVAR_RENDERER | CVAR_BOOL, "only draw a single triangle per primitive" );
  41. idCVar r_checkBounds( "r_checkBounds", "0", CVAR_RENDERER | CVAR_BOOL, "compare all surface bounds with precalculated ones" );
  42. idCVar r_useNV20MonoLights( "r_useNV20MonoLights", "1", CVAR_RENDERER | CVAR_INTEGER, "use pass optimization for mono lights" );
  43. idCVar r_useConstantMaterials( "r_useConstantMaterials", "1", CVAR_RENDERER | CVAR_BOOL, "use pre-calculated material registers if possible" );
  44. idCVar r_useTripleTextureARB( "r_useTripleTextureARB", "1", CVAR_RENDERER | CVAR_BOOL, "cards with 3+ texture units do a two pass instead of three pass" );
  45. idCVar r_useSilRemap( "r_useSilRemap", "1", CVAR_RENDERER | CVAR_BOOL, "consider verts with the same XYZ, but different ST the same for shadows" );
  46. idCVar r_useNodeCommonChildren( "r_useNodeCommonChildren", "1", CVAR_RENDERER | CVAR_BOOL, "stop pushing reference bounds early when possible" );
  47. idCVar r_useShadowProjectedCull( "r_useShadowProjectedCull", "1", CVAR_RENDERER | CVAR_BOOL, "discard triangles outside light volume before shadowing" );
  48. idCVar r_useShadowVertexProgram( "r_useShadowVertexProgram", "1", CVAR_RENDERER | CVAR_BOOL, "do the shadow projection in the vertex program on capable cards" );
  49. idCVar r_useShadowSurfaceScissor( "r_useShadowSurfaceScissor", "1", CVAR_RENDERER | CVAR_BOOL, "scissor shadows by the scissor rect of the interaction surfaces" );
  50. idCVar r_useInteractionTable( "r_useInteractionTable", "1", CVAR_RENDERER | CVAR_BOOL, "create a full entityDefs * lightDefs table to make finding interactions faster" );
  51. idCVar r_useTurboShadow( "r_useTurboShadow", "1", CVAR_RENDERER | CVAR_BOOL, "use the infinite projection with W technique for dynamic shadows" );
  52. idCVar r_useTwoSidedStencil( "r_useTwoSidedStencil", "1", CVAR_RENDERER | CVAR_BOOL, "do stencil shadows in one pass with different ops on each side" );
  53. idCVar r_useDeferredTangents( "r_useDeferredTangents", "1", CVAR_RENDERER | CVAR_BOOL, "defer tangents calculations after deform" );
  54. idCVar r_useCachedDynamicModels( "r_useCachedDynamicModels", "1", CVAR_RENDERER | CVAR_BOOL, "cache snapshots of dynamic models" );
  55. idCVar r_useVertexBuffers( "r_useVertexBuffers", "1", CVAR_RENDERER | CVAR_INTEGER, "use ARB_vertex_buffer_object for vertexes", 0, 1, idCmdSystem::ArgCompletion_Integer<0,1> );
  56. idCVar r_useIndexBuffers( "r_useIndexBuffers", "0", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER, "use ARB_vertex_buffer_object for indexes", 0, 1, idCmdSystem::ArgCompletion_Integer<0,1> );
  57. idCVar r_useStateCaching( "r_useStateCaching", "1", CVAR_RENDERER | CVAR_BOOL, "avoid redundant state changes in GL_*() calls" );
  58. idCVar r_useInfiniteFarZ( "r_useInfiniteFarZ", "1", CVAR_RENDERER | CVAR_BOOL, "use the no-far-clip-plane trick" );
  59. idCVar r_znear( "r_znear", "3", CVAR_RENDERER | CVAR_FLOAT, "near Z clip plane distance", 0.001f, 200.0f );
  60. idCVar r_ignoreGLErrors( "r_ignoreGLErrors", "1", CVAR_RENDERER | CVAR_BOOL, "ignore GL errors" );
  61. idCVar r_finish( "r_finish", "0", CVAR_RENDERER | CVAR_BOOL, "force a call to glFinish() every frame" );
  62. idCVar r_swapInterval( "r_swapInterval", "0", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER, "changes wglSwapIntarval" );
  63. idCVar r_gamma( "r_gamma", "1", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_FLOAT, "changes gamma tables", 0.5f, 3.0f );
  64. idCVar r_brightness( "r_brightness", "1", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_FLOAT, "changes gamma tables", 0.5f, 2.0f );
  65. idCVar r_renderer( "r_renderer", "best", CVAR_RENDERER | CVAR_ARCHIVE, "hardware specific renderer path to use", r_rendererArgs, idCmdSystem::ArgCompletion_String<r_rendererArgs> );
  66. idCVar r_jitter( "r_jitter", "0", CVAR_RENDERER | CVAR_BOOL, "randomly subpixel jitter the projection matrix" );
  67. idCVar r_skipSuppress( "r_skipSuppress", "0", CVAR_RENDERER | CVAR_BOOL, "ignore the per-view suppressions" );
  68. idCVar r_skipPostProcess( "r_skipPostProcess", "0", CVAR_RENDERER | CVAR_BOOL, "skip all post-process renderings" );
  69. idCVar r_skipLightScale( "r_skipLightScale", "0", CVAR_RENDERER | CVAR_BOOL, "don't do any post-interaction light scaling, makes things dim on low-dynamic range cards" );
  70. idCVar r_skipInteractions( "r_skipInteractions", "0", CVAR_RENDERER | CVAR_BOOL, "skip all light/surface interaction drawing" );
  71. idCVar r_skipDynamicTextures( "r_skipDynamicTextures", "0", CVAR_RENDERER | CVAR_BOOL, "don't dynamically create textures" );
  72. idCVar r_skipCopyTexture( "r_skipCopyTexture", "0", CVAR_RENDERER | CVAR_BOOL, "do all rendering, but don't actually copyTexSubImage2D" );
  73. idCVar r_skipBackEnd( "r_skipBackEnd", "0", CVAR_RENDERER | CVAR_BOOL, "don't draw anything" );
  74. idCVar r_skipRender( "r_skipRender", "0", CVAR_RENDERER | CVAR_BOOL, "skip 3D rendering, but pass 2D" );
  75. idCVar r_skipRenderContext( "r_skipRenderContext", "0", CVAR_RENDERER | CVAR_BOOL, "NULL the rendering context during backend 3D rendering" );
  76. idCVar r_skipTranslucent( "r_skipTranslucent", "0", CVAR_RENDERER | CVAR_BOOL, "skip the translucent interaction rendering" );
  77. idCVar r_skipAmbient( "r_skipAmbient", "0", CVAR_RENDERER | CVAR_BOOL, "bypasses all non-interaction drawing" );
  78. idCVar r_skipNewAmbient( "r_skipNewAmbient", "0", CVAR_RENDERER | CVAR_BOOL | CVAR_ARCHIVE, "bypasses all vertex/fragment program ambient drawing" );
  79. idCVar r_skipBlendLights( "r_skipBlendLights", "0", CVAR_RENDERER | CVAR_BOOL, "skip all blend lights" );
  80. idCVar r_skipFogLights( "r_skipFogLights", "0", CVAR_RENDERER | CVAR_BOOL, "skip all fog lights" );
  81. idCVar r_skipDeforms( "r_skipDeforms", "0", CVAR_RENDERER | CVAR_BOOL, "leave all deform materials in their original state" );
  82. idCVar r_skipFrontEnd( "r_skipFrontEnd", "0", CVAR_RENDERER | CVAR_BOOL, "bypasses all front end work, but 2D gui rendering still draws" );
  83. idCVar r_skipUpdates( "r_skipUpdates", "0", CVAR_RENDERER | CVAR_BOOL, "1 = don't accept any entity or light updates, making everything static" );
  84. idCVar r_skipOverlays( "r_skipOverlays", "0", CVAR_RENDERER | CVAR_BOOL, "skip overlay surfaces" );
  85. idCVar r_skipSpecular( "r_skipSpecular", "0", CVAR_RENDERER | CVAR_BOOL | CVAR_CHEAT | CVAR_ARCHIVE, "use black for specular1" );
  86. idCVar r_skipBump( "r_skipBump", "0", CVAR_RENDERER | CVAR_BOOL | CVAR_ARCHIVE, "uses a flat surface instead of the bump map" );
  87. idCVar r_skipDiffuse( "r_skipDiffuse", "0", CVAR_RENDERER | CVAR_BOOL, "use black for diffuse" );
  88. idCVar r_skipROQ( "r_skipROQ", "0", CVAR_RENDERER | CVAR_BOOL, "skip ROQ decoding" );
  89. idCVar r_ignore( "r_ignore", "0", CVAR_RENDERER, "used for random debugging without defining new vars" );
  90. idCVar r_ignore2( "r_ignore2", "0", CVAR_RENDERER, "used for random debugging without defining new vars" );
  91. idCVar r_usePreciseTriangleInteractions( "r_usePreciseTriangleInteractions", "0", CVAR_RENDERER | CVAR_BOOL, "1 = do winding clipping to determine if each ambiguous tri should be lit" );
  92. idCVar r_useCulling( "r_useCulling", "2", CVAR_RENDERER | CVAR_INTEGER, "0 = none, 1 = sphere, 2 = sphere + box", 0, 2, idCmdSystem::ArgCompletion_Integer<0,2> );
  93. idCVar r_useLightCulling( "r_useLightCulling", "3", CVAR_RENDERER | CVAR_INTEGER, "0 = none, 1 = box, 2 = exact clip of polyhedron faces, 3 = also areas", 0, 3, idCmdSystem::ArgCompletion_Integer<0,3> );
  94. idCVar r_useLightScissors( "r_useLightScissors", "1", CVAR_RENDERER | CVAR_BOOL, "1 = use custom scissor rectangle for each light" );
  95. idCVar r_useClippedLightScissors( "r_useClippedLightScissors", "1", CVAR_RENDERER | CVAR_INTEGER, "0 = full screen when near clipped, 1 = exact when near clipped, 2 = exact always", 0, 2, idCmdSystem::ArgCompletion_Integer<0,2> );
  96. idCVar r_useEntityCulling( "r_useEntityCulling", "1", CVAR_RENDERER | CVAR_BOOL, "0 = none, 1 = box" );
  97. idCVar r_useEntityScissors( "r_useEntityScissors", "0", CVAR_RENDERER | CVAR_BOOL, "1 = use custom scissor rectangle for each entity" );
  98. idCVar r_useInteractionCulling( "r_useInteractionCulling", "1", CVAR_RENDERER | CVAR_BOOL, "1 = cull interactions" );
  99. idCVar r_useInteractionScissors( "r_useInteractionScissors", "2", CVAR_RENDERER | CVAR_INTEGER, "1 = use a custom scissor rectangle for each shadow interaction, 2 = also crop using portal scissors", -2, 2, idCmdSystem::ArgCompletion_Integer<-2,2> );
  100. idCVar r_useShadowCulling( "r_useShadowCulling", "1", CVAR_RENDERER | CVAR_BOOL, "try to cull shadows from partially visible lights" );
  101. idCVar r_useFrustumFarDistance( "r_useFrustumFarDistance", "0", CVAR_RENDERER | CVAR_FLOAT, "if != 0 force the view frustum far distance to this distance" );
  102. idCVar r_logFile( "r_logFile", "0", CVAR_RENDERER | CVAR_INTEGER, "number of frames to emit GL logs" );
  103. idCVar r_clear( "r_clear", "2", CVAR_RENDERER, "force screen clear every frame, 1 = purple, 2 = black, 'r g b' = custom" );
  104. idCVar r_offsetFactor( "r_offsetfactor", "0", CVAR_RENDERER | CVAR_FLOAT, "polygon offset parameter" );
  105. idCVar r_offsetUnits( "r_offsetunits", "-600", CVAR_RENDERER | CVAR_FLOAT, "polygon offset parameter" );
  106. idCVar r_shadowPolygonOffset( "r_shadowPolygonOffset", "-1", CVAR_RENDERER | CVAR_FLOAT, "bias value added to depth test for stencil shadow drawing" );
  107. idCVar r_shadowPolygonFactor( "r_shadowPolygonFactor", "0", CVAR_RENDERER | CVAR_FLOAT, "scale value for stencil shadow drawing" );
  108. idCVar r_frontBuffer( "r_frontBuffer", "0", CVAR_RENDERER | CVAR_BOOL, "draw to front buffer for debugging" );
  109. idCVar r_skipSubviews( "r_skipSubviews", "0", CVAR_RENDERER | CVAR_INTEGER, "1 = don't render any gui elements on surfaces" );
  110. idCVar r_skipGuiShaders( "r_skipGuiShaders", "0", CVAR_RENDERER | CVAR_INTEGER, "1 = skip all gui elements on surfaces, 2 = skip drawing but still handle events, 3 = draw but skip events", 0, 3, idCmdSystem::ArgCompletion_Integer<0,3> );
  111. idCVar r_skipParticles( "r_skipParticles", "0", CVAR_RENDERER | CVAR_INTEGER, "1 = skip all particle systems", 0, 1, idCmdSystem::ArgCompletion_Integer<0,1> );
  112. idCVar r_subviewOnly( "r_subviewOnly", "0", CVAR_RENDERER | CVAR_BOOL, "1 = don't render main view, allowing subviews to be debugged" );
  113. idCVar r_shadows( "r_shadows", "1", CVAR_RENDERER | CVAR_BOOL | CVAR_ARCHIVE, "enable shadows" );
  114. idCVar r_testARBProgram( "r_testARBProgram", "0", CVAR_RENDERER | CVAR_BOOL, "experiment with vertex/fragment programs" );
  115. idCVar r_testGamma( "r_testGamma", "0", CVAR_RENDERER | CVAR_FLOAT, "if > 0 draw a grid pattern to test gamma levels", 0, 195 );
  116. idCVar r_testGammaBias( "r_testGammaBias", "0", CVAR_RENDERER | CVAR_FLOAT, "if > 0 draw a grid pattern to test gamma levels" );
  117. idCVar r_testStepGamma( "r_testStepGamma", "0", CVAR_RENDERER | CVAR_FLOAT, "if > 0 draw a grid pattern to test gamma levels" );
  118. idCVar r_lightScale( "r_lightScale", "2", CVAR_RENDERER | CVAR_FLOAT, "all light intensities are multiplied by this" );
  119. idCVar r_lightSourceRadius( "r_lightSourceRadius", "0", CVAR_RENDERER | CVAR_FLOAT, "for soft-shadow sampling" );
  120. idCVar r_flareSize( "r_flareSize", "1", CVAR_RENDERER | CVAR_FLOAT, "scale the flare deforms from the material def" );
  121. idCVar r_useExternalShadows( "r_useExternalShadows", "1", CVAR_RENDERER | CVAR_INTEGER, "1 = skip drawing caps when outside the light volume, 2 = force to no caps for testing", 0, 2, idCmdSystem::ArgCompletion_Integer<0,2> );
  122. idCVar r_useOptimizedShadows( "r_useOptimizedShadows", "1", CVAR_RENDERER | CVAR_BOOL, "use the dmap generated static shadow volumes" );
  123. idCVar r_useScissor( "r_useScissor", "1", CVAR_RENDERER | CVAR_BOOL, "scissor clip as portals and lights are processed" );
  124. idCVar r_useCombinerDisplayLists( "r_useCombinerDisplayLists", "1", CVAR_RENDERER | CVAR_BOOL | CVAR_NOCHEAT, "put all nvidia register combiner programming in display lists" );
  125. idCVar r_useDepthBoundsTest( "r_useDepthBoundsTest", "1", CVAR_RENDERER | CVAR_BOOL, "use depth bounds test to reduce shadow fill" );
  126. idCVar r_screenFraction( "r_screenFraction", "100", CVAR_RENDERER | CVAR_INTEGER, "for testing fill rate, the resolution of the entire screen can be changed" );
  127. idCVar r_demonstrateBug( "r_demonstrateBug", "0", CVAR_RENDERER | CVAR_BOOL, "used during development to show IHV's their problems" );
  128. idCVar r_usePortals( "r_usePortals", "1", CVAR_RENDERER | CVAR_BOOL, " 1 = use portals to perform area culling, otherwise draw everything" );
  129. idCVar r_singleLight( "r_singleLight", "-1", CVAR_RENDERER | CVAR_INTEGER, "suppress all but one light" );
  130. idCVar r_singleEntity( "r_singleEntity", "-1", CVAR_RENDERER | CVAR_INTEGER, "suppress all but one entity" );
  131. idCVar r_singleSurface( "r_singleSurface", "-1", CVAR_RENDERER | CVAR_INTEGER, "suppress all but one surface on each entity" );
  132. idCVar r_singleArea( "r_singleArea", "0", CVAR_RENDERER | CVAR_BOOL, "only draw the portal area the view is actually in" );
  133. idCVar r_forceLoadImages( "r_forceLoadImages", "0", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_BOOL, "draw all images to screen after registration" );
  134. idCVar r_orderIndexes( "r_orderIndexes", "1", CVAR_RENDERER | CVAR_BOOL, "perform index reorganization to optimize vertex use" );
  135. idCVar r_lightAllBackFaces( "r_lightAllBackFaces", "0", CVAR_RENDERER | CVAR_BOOL, "light all the back faces, even when they would be shadowed" );
  136. // visual debugging info
  137. idCVar r_showPortals( "r_showPortals", "0", CVAR_RENDERER | CVAR_BOOL, "draw portal outlines in color based on passed / not passed" );
  138. idCVar r_showUnsmoothedTangents( "r_showUnsmoothedTangents", "0", CVAR_RENDERER | CVAR_BOOL, "if 1, put all nvidia register combiner programming in display lists" );
  139. idCVar r_showSilhouette( "r_showSilhouette", "0", CVAR_RENDERER | CVAR_BOOL, "highlight edges that are casting shadow planes" );
  140. idCVar r_showVertexColor( "r_showVertexColor", "0", CVAR_RENDERER | CVAR_BOOL, "draws all triangles with the solid vertex color" );
  141. idCVar r_showUpdates( "r_showUpdates", "0", CVAR_RENDERER | CVAR_BOOL, "report entity and light updates and ref counts" );
  142. idCVar r_showDemo( "r_showDemo", "0", CVAR_RENDERER | CVAR_BOOL, "report reads and writes to the demo file" );
  143. idCVar r_showDynamic( "r_showDynamic", "0", CVAR_RENDERER | CVAR_BOOL, "report stats on dynamic surface generation" );
  144. idCVar r_showLightScale( "r_showLightScale", "0", CVAR_RENDERER | CVAR_BOOL, "report the scale factor applied to drawing for overbrights" );
  145. idCVar r_showDefs( "r_showDefs", "0", CVAR_RENDERER | CVAR_BOOL, "report the number of modeDefs and lightDefs in view" );
  146. idCVar r_showTrace( "r_showTrace", "0", CVAR_RENDERER | CVAR_INTEGER, "show the intersection of an eye trace with the world", idCmdSystem::ArgCompletion_Integer<0,2> );
  147. idCVar r_showIntensity( "r_showIntensity", "0", CVAR_RENDERER | CVAR_BOOL, "draw the screen colors based on intensity, red = 0, green = 128, blue = 255" );
  148. idCVar r_showImages( "r_showImages", "0", CVAR_RENDERER | CVAR_INTEGER, "1 = show all images instead of rendering, 2 = show in proportional size", 0, 2, idCmdSystem::ArgCompletion_Integer<0,2> );
  149. idCVar r_showSmp( "r_showSmp", "0", CVAR_RENDERER | CVAR_BOOL, "show which end (front or back) is blocking" );
  150. idCVar r_showLights( "r_showLights", "0", CVAR_RENDERER | CVAR_INTEGER, "1 = just print volumes numbers, highlighting ones covering the view, 2 = also draw planes of each volume, 3 = also draw edges of each volume", 0, 3, idCmdSystem::ArgCompletion_Integer<0,3> );
  151. idCVar r_showShadows( "r_showShadows", "0", CVAR_RENDERER | CVAR_INTEGER, "1 = visualize the stencil shadow volumes, 2 = draw filled in", 0, 3, idCmdSystem::ArgCompletion_Integer<0,3> );
  152. idCVar r_showShadowCount( "r_showShadowCount", "0", CVAR_RENDERER | CVAR_INTEGER, "colors screen based on shadow volume depth complexity, >= 2 = print overdraw count based on stencil index values, 3 = only show turboshadows, 4 = only show static shadows", 0, 4, idCmdSystem::ArgCompletion_Integer<0,4> );
  153. idCVar r_showLightScissors( "r_showLightScissors", "0", CVAR_RENDERER | CVAR_BOOL, "show light scissor rectangles" );
  154. idCVar r_showEntityScissors( "r_showEntityScissors", "0", CVAR_RENDERER | CVAR_BOOL, "show entity scissor rectangles" );
  155. idCVar r_showInteractionFrustums( "r_showInteractionFrustums", "0", CVAR_RENDERER | CVAR_INTEGER, "1 = show a frustum for each interaction, 2 = also draw lines to light origin, 3 = also draw entity bbox", 0, 3, idCmdSystem::ArgCompletion_Integer<0,3> );
  156. idCVar r_showInteractionScissors( "r_showInteractionScissors", "0", CVAR_RENDERER | CVAR_INTEGER, "1 = show screen rectangle which contains the interaction frustum, 2 = also draw construction lines", 0, 2, idCmdSystem::ArgCompletion_Integer<0,2> );
  157. idCVar r_showLightCount( "r_showLightCount", "0", CVAR_RENDERER | CVAR_INTEGER, "1 = colors surfaces based on light count, 2 = also count everything through walls, 3 = also print overdraw", 0, 3, idCmdSystem::ArgCompletion_Integer<0,3> );
  158. idCVar r_showViewEntitys( "r_showViewEntitys", "0", CVAR_RENDERER | CVAR_INTEGER, "1 = displays the bounding boxes of all view models, 2 = print index numbers" );
  159. idCVar r_showTris( "r_showTris", "0", CVAR_RENDERER | CVAR_INTEGER, "enables wireframe rendering of the world, 1 = only draw visible ones, 2 = draw all front facing, 3 = draw all", 0, 3, idCmdSystem::ArgCompletion_Integer<0,3> );
  160. idCVar r_showSurfaceInfo( "r_showSurfaceInfo", "0", CVAR_RENDERER | CVAR_BOOL, "show surface material name under crosshair" );
  161. idCVar r_showNormals( "r_showNormals", "0", CVAR_RENDERER | CVAR_FLOAT, "draws wireframe normals" );
  162. idCVar r_showMemory( "r_showMemory", "0", CVAR_RENDERER | CVAR_BOOL, "print frame memory utilization" );
  163. idCVar r_showCull( "r_showCull", "0", CVAR_RENDERER | CVAR_BOOL, "report sphere and box culling stats" );
  164. idCVar r_showInteractions( "r_showInteractions", "0", CVAR_RENDERER | CVAR_BOOL, "report interaction generation activity" );
  165. idCVar r_showDepth( "r_showDepth", "0", CVAR_RENDERER | CVAR_BOOL, "display the contents of the depth buffer and the depth range" );
  166. idCVar r_showSurfaces( "r_showSurfaces", "0", CVAR_RENDERER | CVAR_BOOL, "report surface/light/shadow counts" );
  167. idCVar r_showPrimitives( "r_showPrimitives", "0", CVAR_RENDERER | CVAR_INTEGER, "report drawsurf/index/vertex counts" );
  168. idCVar r_showEdges( "r_showEdges", "0", CVAR_RENDERER | CVAR_BOOL, "draw the sil edges" );
  169. idCVar r_showTexturePolarity( "r_showTexturePolarity", "0", CVAR_RENDERER | CVAR_BOOL, "shade triangles by texture area polarity" );
  170. idCVar r_showTangentSpace( "r_showTangentSpace", "0", CVAR_RENDERER | CVAR_INTEGER, "shade triangles by tangent space, 1 = use 1st tangent vector, 2 = use 2nd tangent vector, 3 = use normal vector", 0, 3, idCmdSystem::ArgCompletion_Integer<0,3> );
  171. idCVar r_showDominantTri( "r_showDominantTri", "0", CVAR_RENDERER | CVAR_BOOL, "draw lines from vertexes to center of dominant triangles" );
  172. idCVar r_showAlloc( "r_showAlloc", "0", CVAR_RENDERER | CVAR_BOOL, "report alloc/free counts" );
  173. idCVar r_showTextureVectors( "r_showTextureVectors", "0", CVAR_RENDERER | CVAR_FLOAT, " if > 0 draw each triangles texture (tangent) vectors" );
  174. idCVar r_showOverDraw( "r_showOverDraw", "0", CVAR_RENDERER | CVAR_INTEGER, "1 = geometry overdraw, 2 = light interaction overdraw, 3 = geometry and light interaction overdraw", 0, 3, idCmdSystem::ArgCompletion_Integer<0,3> );
  175. idCVar r_lockSurfaces( "r_lockSurfaces", "0", CVAR_RENDERER | CVAR_BOOL, "allow moving the view point without changing the composition of the scene, including culling" );
  176. idCVar r_useEntityCallbacks( "r_useEntityCallbacks", "1", CVAR_RENDERER | CVAR_BOOL, "if 0, issue the callback immediately at update time, rather than defering" );
  177. idCVar r_showSkel( "r_showSkel", "0", CVAR_RENDERER | CVAR_INTEGER, "draw the skeleton when model animates, 1 = draw model with skeleton, 2 = draw skeleton only", 0, 2, idCmdSystem::ArgCompletion_Integer<0,2> );
  178. idCVar r_jointNameScale( "r_jointNameScale", "0.02", CVAR_RENDERER | CVAR_FLOAT, "size of joint names when r_showskel is set to 1" );
  179. idCVar r_jointNameOffset( "r_jointNameOffset", "0.5", CVAR_RENDERER | CVAR_FLOAT, "offset of joint names when r_showskel is set to 1" );
  180. idCVar r_cgVertexProfile( "r_cgVertexProfile", "best", CVAR_RENDERER | CVAR_ARCHIVE, "arbvp1, vp20, vp30" );
  181. idCVar r_cgFragmentProfile( "r_cgFragmentProfile", "best", CVAR_RENDERER | CVAR_ARCHIVE, "arbfp1, fp30" );
  182. idCVar r_debugLineDepthTest( "r_debugLineDepthTest", "0", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_BOOL, "perform depth test on debug lines" );
  183. idCVar r_debugLineWidth( "r_debugLineWidth", "1", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_BOOL, "width of debug lines" );
  184. idCVar r_debugArrowStep( "r_debugArrowStep", "120", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER, "step size of arrow cone line rotation in degrees", 0, 120 );
  185. idCVar r_debugPolygonFilled( "r_debugPolygonFilled", "1", CVAR_RENDERER | CVAR_BOOL, "draw a filled polygon" );
  186. idCVar r_materialOverride( "r_materialOverride", "", CVAR_RENDERER, "overrides all materials", idCmdSystem::ArgCompletion_Decl<DECL_MATERIAL> );
  187. idCVar r_debugRenderToTexture( "r_debugRenderToTexture", "0", CVAR_RENDERER | CVAR_INTEGER, "" );
  188. void ( APIENTRY * qglMultiTexCoord2fARB )( GLenum texture, GLfloat s, GLfloat t );
  189. void ( APIENTRY * qglMultiTexCoord2fvARB )( GLenum texture, GLfloat *st );
  190. void ( APIENTRY * qglActiveTextureARB )( GLenum texture );
  191. void ( APIENTRY * qglClientActiveTextureARB )( GLenum texture );
  192. void ( APIENTRY *qglCombinerParameterfvNV )( GLenum pname, const GLfloat *params );
  193. void ( APIENTRY *qglCombinerParameterivNV )( GLenum pname, const GLint *params );
  194. void ( APIENTRY *qglCombinerParameterfNV )( GLenum pname, const GLfloat param );
  195. void ( APIENTRY *qglCombinerParameteriNV )( GLenum pname, const GLint param );
  196. void ( APIENTRY *qglCombinerInputNV )( GLenum stage, GLenum portion, GLenum variable, GLenum input,
  197. GLenum mapping, GLenum componentUsage );
  198. void ( APIENTRY *qglCombinerOutputNV )( GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput,
  199. GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct,
  200. GLboolean cdDotProduct, GLboolean muxSum );
  201. void ( APIENTRY *qglFinalCombinerInputNV )( GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage );
  202. void (APIENTRY *qglVertexArrayRangeNV)( GLsizei length, void *pointer );
  203. // TTimo: wgl vs glX
  204. // http://oss.sgi.com/projects/ogl-sample/registry/NV/vertex_array_range.txt
  205. // since APIs are the same anyway, let's be wgl/glX agnostic
  206. void *(APIENTRY *qAllocateMemoryNV)( GLsizei size, float readFrequency, float writeFrequency, float priority);
  207. void (APIENTRY *qFreeMemoryNV)( void *pointer );
  208. #ifdef GLX_VERSION_1_1
  209. #define Q_ALLOCATE_MEMORY_NV "glXAllocateMemoryNV"
  210. #define Q_FREE_MEMORY_NV "glXFreeMemoryNV"
  211. #else
  212. #define Q_ALLOCATE_MEMORY_NV "wglAllocateMemoryNV"
  213. #define Q_FREE_MEMORY_NV "wglFreeMemoryNV"
  214. #endif
  215. void (APIENTRY *qglTexImage3D)(GLenum, GLint, GLint, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *);
  216. void (APIENTRY * qglColorTableEXT)( int, int, int, int, int, const void * );
  217. // ATI_fragment_shader
  218. PFNGLGENFRAGMENTSHADERSATIPROC qglGenFragmentShadersATI;
  219. PFNGLBINDFRAGMENTSHADERATIPROC qglBindFragmentShaderATI;
  220. PFNGLDELETEFRAGMENTSHADERATIPROC qglDeleteFragmentShaderATI;
  221. PFNGLBEGINFRAGMENTSHADERATIPROC qglBeginFragmentShaderATI;
  222. PFNGLENDFRAGMENTSHADERATIPROC qglEndFragmentShaderATI;
  223. PFNGLPASSTEXCOORDATIPROC qglPassTexCoordATI;
  224. PFNGLSAMPLEMAPATIPROC qglSampleMapATI;
  225. PFNGLCOLORFRAGMENTOP1ATIPROC qglColorFragmentOp1ATI;
  226. PFNGLCOLORFRAGMENTOP2ATIPROC qglColorFragmentOp2ATI;
  227. PFNGLCOLORFRAGMENTOP3ATIPROC qglColorFragmentOp3ATI;
  228. PFNGLALPHAFRAGMENTOP1ATIPROC qglAlphaFragmentOp1ATI;
  229. PFNGLALPHAFRAGMENTOP2ATIPROC qglAlphaFragmentOp2ATI;
  230. PFNGLALPHAFRAGMENTOP3ATIPROC qglAlphaFragmentOp3ATI;
  231. PFNGLSETFRAGMENTSHADERCONSTANTATIPROC qglSetFragmentShaderConstantATI;
  232. // EXT_stencil_two_side
  233. PFNGLACTIVESTENCILFACEEXTPROC qglActiveStencilFaceEXT;
  234. // ATI_separate_stencil
  235. PFNGLSTENCILOPSEPARATEATIPROC qglStencilOpSeparateATI;
  236. PFNGLSTENCILFUNCSEPARATEATIPROC qglStencilFuncSeparateATI;
  237. // ARB_texture_compression
  238. PFNGLCOMPRESSEDTEXIMAGE2DARBPROC qglCompressedTexImage2DARB;
  239. PFNGLGETCOMPRESSEDTEXIMAGEARBPROC qglGetCompressedTexImageARB;
  240. // ARB_vertex_buffer_object
  241. PFNGLBINDBUFFERARBPROC qglBindBufferARB;
  242. PFNGLDELETEBUFFERSARBPROC qglDeleteBuffersARB;
  243. PFNGLGENBUFFERSARBPROC qglGenBuffersARB;
  244. PFNGLISBUFFERARBPROC qglIsBufferARB;
  245. PFNGLBUFFERDATAARBPROC qglBufferDataARB;
  246. PFNGLBUFFERSUBDATAARBPROC qglBufferSubDataARB;
  247. PFNGLGETBUFFERSUBDATAARBPROC qglGetBufferSubDataARB;
  248. PFNGLMAPBUFFERARBPROC qglMapBufferARB;
  249. PFNGLUNMAPBUFFERARBPROC qglUnmapBufferARB;
  250. PFNGLGETBUFFERPARAMETERIVARBPROC qglGetBufferParameterivARB;
  251. PFNGLGETBUFFERPOINTERVARBPROC qglGetBufferPointervARB;
  252. // ARB_vertex_program / ARB_fragment_program
  253. PFNGLVERTEXATTRIBPOINTERARBPROC qglVertexAttribPointerARB;
  254. PFNGLENABLEVERTEXATTRIBARRAYARBPROC qglEnableVertexAttribArrayARB;
  255. PFNGLDISABLEVERTEXATTRIBARRAYARBPROC qglDisableVertexAttribArrayARB;
  256. PFNGLPROGRAMSTRINGARBPROC qglProgramStringARB;
  257. PFNGLBINDPROGRAMARBPROC qglBindProgramARB;
  258. PFNGLGENPROGRAMSARBPROC qglGenProgramsARB;
  259. PFNGLPROGRAMENVPARAMETER4FVARBPROC qglProgramEnvParameter4fvARB;
  260. PFNGLPROGRAMLOCALPARAMETER4FVARBPROC qglProgramLocalParameter4fvARB;
  261. // GL_EXT_depth_bounds_test
  262. PFNGLDEPTHBOUNDSEXTPROC qglDepthBoundsEXT;
  263. /*
  264. =================
  265. R_CheckExtension
  266. =================
  267. */
  268. bool R_CheckExtension( char *name ) {
  269. if ( !strstr( glConfig.extensions_string, name ) ) {
  270. common->Printf( "X..%s not found\n", name );
  271. return false;
  272. }
  273. common->Printf( "...using %s\n", name );
  274. return true;
  275. }
  276. /*
  277. ==================
  278. R_CheckPortableExtensions
  279. ==================
  280. */
  281. static void R_CheckPortableExtensions( void ) {
  282. glConfig.glVersion = atof( glConfig.version_string );
  283. // GL_ARB_multitexture
  284. glConfig.multitextureAvailable = R_CheckExtension( "GL_ARB_multitexture" );
  285. if ( glConfig.multitextureAvailable ) {
  286. qglMultiTexCoord2fARB = (void(APIENTRY *)(GLenum, GLfloat, GLfloat))GLimp_ExtensionPointer( "glMultiTexCoord2fARB" );
  287. qglMultiTexCoord2fvARB = (void(APIENTRY *)(GLenum, GLfloat *))GLimp_ExtensionPointer( "glMultiTexCoord2fvARB" );
  288. qglActiveTextureARB = (void(APIENTRY *)(GLenum))GLimp_ExtensionPointer( "glActiveTextureARB" );
  289. qglClientActiveTextureARB = (void(APIENTRY *)(GLenum))GLimp_ExtensionPointer( "glClientActiveTextureARB" );
  290. qglGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, (GLint *)&glConfig.maxTextureUnits );
  291. if ( glConfig.maxTextureUnits > MAX_MULTITEXTURE_UNITS ) {
  292. glConfig.maxTextureUnits = MAX_MULTITEXTURE_UNITS;
  293. }
  294. if ( glConfig.maxTextureUnits < 2 ) {
  295. glConfig.multitextureAvailable = false; // shouldn't ever happen
  296. }
  297. qglGetIntegerv( GL_MAX_TEXTURE_COORDS_ARB, (GLint *)&glConfig.maxTextureCoords );
  298. qglGetIntegerv( GL_MAX_TEXTURE_IMAGE_UNITS_ARB, (GLint *)&glConfig.maxTextureImageUnits );
  299. }
  300. // GL_ARB_texture_env_combine
  301. glConfig.textureEnvCombineAvailable = R_CheckExtension( "GL_ARB_texture_env_combine" );
  302. // GL_ARB_texture_cube_map
  303. glConfig.cubeMapAvailable = R_CheckExtension( "GL_ARB_texture_cube_map" );
  304. // GL_ARB_texture_env_dot3
  305. glConfig.envDot3Available = R_CheckExtension( "GL_ARB_texture_env_dot3" );
  306. // GL_ARB_texture_env_add
  307. glConfig.textureEnvAddAvailable = R_CheckExtension( "GL_ARB_texture_env_add" );
  308. // GL_ARB_texture_non_power_of_two
  309. glConfig.textureNonPowerOfTwoAvailable = R_CheckExtension( "GL_ARB_texture_non_power_of_two" );
  310. // GL_ARB_texture_compression + GL_S3_s3tc
  311. // DRI drivers may have GL_ARB_texture_compression but no GL_EXT_texture_compression_s3tc
  312. if ( R_CheckExtension( "GL_ARB_texture_compression" ) && R_CheckExtension( "GL_EXT_texture_compression_s3tc" ) ) {
  313. glConfig.textureCompressionAvailable = true;
  314. qglCompressedTexImage2DARB = (PFNGLCOMPRESSEDTEXIMAGE2DARBPROC)GLimp_ExtensionPointer( "glCompressedTexImage2DARB" );
  315. qglGetCompressedTexImageARB = (PFNGLGETCOMPRESSEDTEXIMAGEARBPROC)GLimp_ExtensionPointer( "glGetCompressedTexImageARB" );
  316. } else {
  317. glConfig.textureCompressionAvailable = false;
  318. }
  319. // GL_EXT_texture_filter_anisotropic
  320. glConfig.anisotropicAvailable = R_CheckExtension( "GL_EXT_texture_filter_anisotropic" );
  321. if ( glConfig.anisotropicAvailable ) {
  322. qglGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glConfig.maxTextureAnisotropy );
  323. common->Printf( " maxTextureAnisotropy: %f\n", glConfig.maxTextureAnisotropy );
  324. } else {
  325. glConfig.maxTextureAnisotropy = 1;
  326. }
  327. // GL_EXT_texture_lod_bias
  328. // The actual extension is broken as specificed, storing the state in the texture unit instead
  329. // of the texture object. The behavior in GL 1.4 is the behavior we use.
  330. if ( glConfig.glVersion >= 1.4 || R_CheckExtension( "GL_EXT_texture_lod" ) ) {
  331. common->Printf( "...using %s\n", "GL_1.4_texture_lod_bias" );
  332. glConfig.textureLODBiasAvailable = true;
  333. } else {
  334. common->Printf( "X..%s not found\n", "GL_1.4_texture_lod_bias" );
  335. glConfig.textureLODBiasAvailable = false;
  336. }
  337. // GL_EXT_shared_texture_palette
  338. glConfig.sharedTexturePaletteAvailable = R_CheckExtension( "GL_EXT_shared_texture_palette" );
  339. if ( glConfig.sharedTexturePaletteAvailable ) {
  340. qglColorTableEXT = ( void ( APIENTRY * ) ( int, int, int, int, int, const void * ) ) GLimp_ExtensionPointer( "glColorTableEXT" );
  341. }
  342. // GL_EXT_texture3D (not currently used for anything)
  343. glConfig.texture3DAvailable = R_CheckExtension( "GL_EXT_texture3D" );
  344. if ( glConfig.texture3DAvailable ) {
  345. qglTexImage3D =
  346. (void (APIENTRY *)(GLenum, GLint, GLint, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *) )
  347. GLimp_ExtensionPointer( "glTexImage3D" );
  348. }
  349. // EXT_stencil_wrap
  350. // This isn't very important, but some pathological case might cause a clamp error and give a shadow bug.
  351. // Nvidia also believes that future hardware may be able to run faster with this enabled to avoid the
  352. // serialization of clamping.
  353. if ( R_CheckExtension( "GL_EXT_stencil_wrap" ) ) {
  354. tr.stencilIncr = GL_INCR_WRAP_EXT;
  355. tr.stencilDecr = GL_DECR_WRAP_EXT;
  356. } else {
  357. tr.stencilIncr = GL_INCR;
  358. tr.stencilDecr = GL_DECR;
  359. }
  360. // GL_NV_register_combiners
  361. glConfig.registerCombinersAvailable = R_CheckExtension( "GL_NV_register_combiners" );
  362. if ( glConfig.registerCombinersAvailable ) {
  363. qglCombinerParameterfvNV = (void (APIENTRY *)( GLenum pname, const GLfloat *params ))
  364. GLimp_ExtensionPointer( "glCombinerParameterfvNV" );
  365. qglCombinerParameterivNV = (void (APIENTRY *)( GLenum pname, const GLint *params ))
  366. GLimp_ExtensionPointer( "glCombinerParameterivNV" );
  367. qglCombinerParameterfNV = (void (APIENTRY *)( GLenum pname, const GLfloat param ))
  368. GLimp_ExtensionPointer( "glCombinerParameterfNV" );
  369. qglCombinerParameteriNV = (void (APIENTRY *)( GLenum pname, const GLint param ))
  370. GLimp_ExtensionPointer( "glCombinerParameteriNV" );
  371. qglCombinerInputNV = (void (APIENTRY *)( GLenum stage, GLenum portion, GLenum variable, GLenum input,
  372. GLenum mapping, GLenum componentUsage ))
  373. GLimp_ExtensionPointer( "glCombinerInputNV" );
  374. qglCombinerOutputNV = (void (APIENTRY *)( GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput,
  375. GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct,
  376. GLboolean cdDotProduct, GLboolean muxSum ))
  377. GLimp_ExtensionPointer( "glCombinerOutputNV" );
  378. qglFinalCombinerInputNV = (void (APIENTRY *)( GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage ))
  379. GLimp_ExtensionPointer( "glFinalCombinerInputNV" );
  380. }
  381. // GL_EXT_stencil_two_side
  382. glConfig.twoSidedStencilAvailable = R_CheckExtension( "GL_EXT_stencil_two_side" );
  383. if ( glConfig.twoSidedStencilAvailable ) {
  384. qglActiveStencilFaceEXT = (PFNGLACTIVESTENCILFACEEXTPROC)GLimp_ExtensionPointer( "glActiveStencilFaceEXT" );
  385. } else {
  386. glConfig.atiTwoSidedStencilAvailable = R_CheckExtension( "GL_ATI_separate_stencil" );
  387. if ( glConfig.atiTwoSidedStencilAvailable ) {
  388. qglStencilFuncSeparateATI = (PFNGLSTENCILFUNCSEPARATEATIPROC)GLimp_ExtensionPointer( "glStencilFuncSeparateATI" );
  389. qglStencilOpSeparateATI = (PFNGLSTENCILOPSEPARATEATIPROC)GLimp_ExtensionPointer( "glStencilOpSeparateATI" );
  390. }
  391. }
  392. // GL_ATI_fragment_shader
  393. glConfig.atiFragmentShaderAvailable = R_CheckExtension( "GL_ATI_fragment_shader" );
  394. if (! glConfig.atiFragmentShaderAvailable ) {
  395. // only on OSX: ATI_fragment_shader is faked through ATI_text_fragment_shader (macosx_glimp.cpp)
  396. glConfig.atiFragmentShaderAvailable = R_CheckExtension( "GL_ATI_text_fragment_shader" );
  397. }
  398. if ( glConfig.atiFragmentShaderAvailable ) {
  399. qglGenFragmentShadersATI = (PFNGLGENFRAGMENTSHADERSATIPROC)GLimp_ExtensionPointer( "glGenFragmentShadersATI" );
  400. qglBindFragmentShaderATI = (PFNGLBINDFRAGMENTSHADERATIPROC)GLimp_ExtensionPointer( "glBindFragmentShaderATI" );
  401. qglDeleteFragmentShaderATI = (PFNGLDELETEFRAGMENTSHADERATIPROC)GLimp_ExtensionPointer( "glDeleteFragmentShaderATI" );
  402. qglBeginFragmentShaderATI = (PFNGLBEGINFRAGMENTSHADERATIPROC)GLimp_ExtensionPointer( "glBeginFragmentShaderATI" );
  403. qglEndFragmentShaderATI = (PFNGLENDFRAGMENTSHADERATIPROC)GLimp_ExtensionPointer( "glEndFragmentShaderATI" );
  404. qglPassTexCoordATI = (PFNGLPASSTEXCOORDATIPROC)GLimp_ExtensionPointer( "glPassTexCoordATI" );
  405. qglSampleMapATI = (PFNGLSAMPLEMAPATIPROC)GLimp_ExtensionPointer( "glSampleMapATI" );
  406. qglColorFragmentOp1ATI = (PFNGLCOLORFRAGMENTOP1ATIPROC)GLimp_ExtensionPointer( "glColorFragmentOp1ATI" );
  407. qglColorFragmentOp2ATI = (PFNGLCOLORFRAGMENTOP2ATIPROC)GLimp_ExtensionPointer( "glColorFragmentOp2ATI" );
  408. qglColorFragmentOp3ATI = (PFNGLCOLORFRAGMENTOP3ATIPROC)GLimp_ExtensionPointer( "glColorFragmentOp3ATI" );
  409. qglAlphaFragmentOp1ATI = (PFNGLALPHAFRAGMENTOP1ATIPROC)GLimp_ExtensionPointer( "glAlphaFragmentOp1ATI" );
  410. qglAlphaFragmentOp2ATI = (PFNGLALPHAFRAGMENTOP2ATIPROC)GLimp_ExtensionPointer( "glAlphaFragmentOp2ATI" );
  411. qglAlphaFragmentOp3ATI = (PFNGLALPHAFRAGMENTOP3ATIPROC)GLimp_ExtensionPointer( "glAlphaFragmentOp3ATI" );
  412. qglSetFragmentShaderConstantATI = (PFNGLSETFRAGMENTSHADERCONSTANTATIPROC)GLimp_ExtensionPointer( "glSetFragmentShaderConstantATI" );
  413. }
  414. // ARB_vertex_buffer_object
  415. glConfig.ARBVertexBufferObjectAvailable = R_CheckExtension( "GL_ARB_vertex_buffer_object" );
  416. if(glConfig.ARBVertexBufferObjectAvailable) {
  417. qglBindBufferARB = (PFNGLBINDBUFFERARBPROC)GLimp_ExtensionPointer( "glBindBufferARB");
  418. qglDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)GLimp_ExtensionPointer( "glDeleteBuffersARB");
  419. qglGenBuffersARB = (PFNGLGENBUFFERSARBPROC)GLimp_ExtensionPointer( "glGenBuffersARB");
  420. qglIsBufferARB = (PFNGLISBUFFERARBPROC)GLimp_ExtensionPointer( "glIsBufferARB");
  421. qglBufferDataARB = (PFNGLBUFFERDATAARBPROC)GLimp_ExtensionPointer( "glBufferDataARB");
  422. qglBufferSubDataARB = (PFNGLBUFFERSUBDATAARBPROC)GLimp_ExtensionPointer( "glBufferSubDataARB");
  423. qglGetBufferSubDataARB = (PFNGLGETBUFFERSUBDATAARBPROC)GLimp_ExtensionPointer( "glGetBufferSubDataARB");
  424. qglMapBufferARB = (PFNGLMAPBUFFERARBPROC)GLimp_ExtensionPointer( "glMapBufferARB");
  425. qglUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC)GLimp_ExtensionPointer( "glUnmapBufferARB");
  426. qglGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC)GLimp_ExtensionPointer( "glGetBufferParameterivARB");
  427. qglGetBufferPointervARB = (PFNGLGETBUFFERPOINTERVARBPROC)GLimp_ExtensionPointer( "glGetBufferPointervARB");
  428. }
  429. // ARB_vertex_program
  430. glConfig.ARBVertexProgramAvailable = R_CheckExtension( "GL_ARB_vertex_program" );
  431. if (glConfig.ARBVertexProgramAvailable) {
  432. qglVertexAttribPointerARB = (PFNGLVERTEXATTRIBPOINTERARBPROC)GLimp_ExtensionPointer( "glVertexAttribPointerARB" );
  433. qglEnableVertexAttribArrayARB = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC)GLimp_ExtensionPointer( "glEnableVertexAttribArrayARB" );
  434. qglDisableVertexAttribArrayARB = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC)GLimp_ExtensionPointer( "glDisableVertexAttribArrayARB" );
  435. qglProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC)GLimp_ExtensionPointer( "glProgramStringARB" );
  436. qglBindProgramARB = (PFNGLBINDPROGRAMARBPROC)GLimp_ExtensionPointer( "glBindProgramARB" );
  437. qglGenProgramsARB = (PFNGLGENPROGRAMSARBPROC)GLimp_ExtensionPointer( "glGenProgramsARB" );
  438. qglProgramEnvParameter4fvARB = (PFNGLPROGRAMENVPARAMETER4FVARBPROC)GLimp_ExtensionPointer( "glProgramEnvParameter4fvARB" );
  439. qglProgramLocalParameter4fvARB = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC)GLimp_ExtensionPointer( "glProgramLocalParameter4fvARB" );
  440. }
  441. // ARB_fragment_program
  442. if ( r_inhibitFragmentProgram.GetBool() ) {
  443. glConfig.ARBFragmentProgramAvailable = false;
  444. } else {
  445. glConfig.ARBFragmentProgramAvailable = R_CheckExtension( "GL_ARB_fragment_program" );
  446. if (glConfig.ARBFragmentProgramAvailable) {
  447. // these are the same as ARB_vertex_program
  448. qglProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC)GLimp_ExtensionPointer( "glProgramStringARB" );
  449. qglBindProgramARB = (PFNGLBINDPROGRAMARBPROC)GLimp_ExtensionPointer( "glBindProgramARB" );
  450. qglProgramEnvParameter4fvARB = (PFNGLPROGRAMENVPARAMETER4FVARBPROC)GLimp_ExtensionPointer( "glProgramEnvParameter4fvARB" );
  451. qglProgramLocalParameter4fvARB = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC)GLimp_ExtensionPointer( "glProgramLocalParameter4fvARB" );
  452. }
  453. }
  454. // check for minimum set
  455. if ( !glConfig.multitextureAvailable || !glConfig.textureEnvCombineAvailable || !glConfig.cubeMapAvailable
  456. || !glConfig.envDot3Available ) {
  457. common->Error( common->GetLanguageDict()->GetString( "#str_06780" ) );
  458. }
  459. // GL_EXT_depth_bounds_test
  460. glConfig.depthBoundsTestAvailable = R_CheckExtension( "EXT_depth_bounds_test" );
  461. if ( glConfig.depthBoundsTestAvailable ) {
  462. qglDepthBoundsEXT = (PFNGLDEPTHBOUNDSEXTPROC)GLimp_ExtensionPointer( "glDepthBoundsEXT" );
  463. }
  464. }
  465. /*
  466. ====================
  467. R_GetModeInfo
  468. r_mode is normally a small non-negative integer that
  469. looks resolutions up in a table, but if it is set to -1,
  470. the values from r_customWidth, amd r_customHeight
  471. will be used instead.
  472. ====================
  473. */
  474. typedef struct vidmode_s {
  475. const char *description;
  476. int width, height;
  477. } vidmode_t;
  478. vidmode_t r_vidModes[] = {
  479. { "Mode 0: 320x240", 320, 240 },
  480. { "Mode 1: 400x300", 400, 300 },
  481. { "Mode 2: 512x384", 512, 384 },
  482. { "Mode 3: 640x480", 640, 480 },
  483. { "Mode 4: 800x600", 800, 600 },
  484. { "Mode 5: 1024x768", 1024, 768 },
  485. { "Mode 6: 1152x864", 1152, 864 },
  486. { "Mode 7: 1280x1024", 1280, 1024 },
  487. { "Mode 8: 1600x1200", 1600, 1200 },
  488. };
  489. static int s_numVidModes = ( sizeof( r_vidModes ) / sizeof( r_vidModes[0] ) );
  490. #if MACOS_X
  491. bool R_GetModeInfo( int *width, int *height, int mode ) {
  492. #else
  493. static bool R_GetModeInfo( int *width, int *height, int mode ) {
  494. #endif
  495. vidmode_t *vm;
  496. if ( mode < -1 ) {
  497. return false;
  498. }
  499. if ( mode >= s_numVidModes ) {
  500. return false;
  501. }
  502. if ( mode == -1 ) {
  503. *width = r_customWidth.GetInteger();
  504. *height = r_customHeight.GetInteger();
  505. return true;
  506. }
  507. vm = &r_vidModes[mode];
  508. if ( width ) {
  509. *width = vm->width;
  510. }
  511. if ( height ) {
  512. *height = vm->height;
  513. }
  514. return true;
  515. }
  516. /*
  517. ==================
  518. R_InitOpenGL
  519. This function is responsible for initializing a valid OpenGL subsystem
  520. for rendering. This is done by calling the system specific GLimp_Init,
  521. which gives us a working OGL subsystem, then setting all necessary openGL
  522. state, including images, vertex programs, and display lists.
  523. Changes to the vertex cache size or smp state require a vid_restart.
  524. If glConfig.isInitialized is false, no rendering can take place, but
  525. all renderSystem functions will still operate properly, notably the material
  526. and model information functions.
  527. ==================
  528. */
  529. void R_InitOpenGL( void ) {
  530. GLint temp;
  531. glimpParms_t parms;
  532. int i;
  533. common->Printf( "----- R_InitOpenGL -----\n" );
  534. if ( glConfig.isInitialized ) {
  535. common->FatalError( "R_InitOpenGL called while active" );
  536. }
  537. // in case we had an error while doing a tiled rendering
  538. tr.viewportOffset[0] = 0;
  539. tr.viewportOffset[1] = 0;
  540. //
  541. // initialize OS specific portions of the renderSystem
  542. //
  543. for ( i = 0 ; i < 2 ; i++ ) {
  544. // set the parameters we are trying
  545. R_GetModeInfo( &glConfig.vidWidth, &glConfig.vidHeight, r_mode.GetInteger() );
  546. parms.width = glConfig.vidWidth;
  547. parms.height = glConfig.vidHeight;
  548. parms.fullScreen = r_fullscreen.GetBool();
  549. parms.displayHz = r_displayRefresh.GetInteger();
  550. parms.multiSamples = r_multiSamples.GetInteger();
  551. parms.stereo = false;
  552. if ( GLimp_Init( parms ) ) {
  553. // it worked
  554. break;
  555. }
  556. if ( i == 1 ) {
  557. common->FatalError( "Unable to initialize OpenGL" );
  558. }
  559. // if we failed, set everything back to "safe mode"
  560. // and try again
  561. r_mode.SetInteger( 3 );
  562. r_fullscreen.SetInteger( 1 );
  563. r_displayRefresh.SetInteger( 0 );
  564. r_multiSamples.SetInteger( 0 );
  565. }
  566. // input and sound systems need to be tied to the new window
  567. Sys_InitInput();
  568. soundSystem->InitHW();
  569. // get our config strings
  570. glConfig.vendor_string = (const char *)qglGetString(GL_VENDOR);
  571. glConfig.renderer_string = (const char *)qglGetString(GL_RENDERER);
  572. glConfig.version_string = (const char *)qglGetString(GL_VERSION);
  573. glConfig.extensions_string = (const char *)qglGetString(GL_EXTENSIONS);
  574. // OpenGL driver constants
  575. qglGetIntegerv( GL_MAX_TEXTURE_SIZE, &temp );
  576. glConfig.maxTextureSize = temp;
  577. // stubbed or broken drivers may have reported 0...
  578. if ( glConfig.maxTextureSize <= 0 ) {
  579. glConfig.maxTextureSize = 256;
  580. }
  581. glConfig.isInitialized = true;
  582. // recheck all the extensions (FIXME: this might be dangerous)
  583. R_CheckPortableExtensions();
  584. // parse our vertex and fragment programs, possibly disably support for
  585. // one of the paths if there was an error
  586. R_NV10_Init();
  587. R_NV20_Init();
  588. R_R200_Init();
  589. R_ARB2_Init();
  590. cmdSystem->AddCommand( "reloadARBprograms", R_ReloadARBPrograms_f, CMD_FL_RENDERER, "reloads ARB programs" );
  591. R_ReloadARBPrograms_f( idCmdArgs() );
  592. // allocate the vertex array range or vertex objects
  593. vertexCache.Init();
  594. // select which renderSystem we are going to use
  595. r_renderer.SetModified();
  596. tr.SetBackEndRenderer();
  597. // allocate the frame data, which may be more if smp is enabled
  598. R_InitFrameData();
  599. // Reset our gamma
  600. R_SetColorMappings();
  601. #ifdef _WIN32
  602. static bool glCheck = false;
  603. if ( !glCheck && win32.osversion.dwMajorVersion == 6 ) {
  604. glCheck = true;
  605. if ( !idStr::Icmp( glConfig.vendor_string, "Microsoft" ) && idStr::FindText( glConfig.renderer_string, "OpenGL-D3D" ) != -1 ) {
  606. if ( cvarSystem->GetCVarBool( "r_fullscreen" ) ) {
  607. cmdSystem->BufferCommandText( CMD_EXEC_NOW, "vid_restart partial windowed\n" );
  608. Sys_GrabMouseCursor( false );
  609. }
  610. int ret = MessageBox( NULL, "Please install OpenGL drivers from your graphics hardware vendor to run " GAME_NAME ".\nYour OpenGL functionality is limited.",
  611. "Insufficient OpenGL capabilities", MB_OKCANCEL | MB_ICONWARNING | MB_TASKMODAL );
  612. if ( ret == IDCANCEL ) {
  613. cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "quit\n" );
  614. cmdSystem->ExecuteCommandBuffer();
  615. }
  616. if ( cvarSystem->GetCVarBool( "r_fullscreen" ) ) {
  617. cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "vid_restart\n" );
  618. }
  619. }
  620. }
  621. #endif
  622. }
  623. /*
  624. ==================
  625. GL_CheckErrors
  626. ==================
  627. */
  628. void GL_CheckErrors( void ) {
  629. int err;
  630. char s[64];
  631. int i;
  632. // check for up to 10 errors pending
  633. for ( i = 0 ; i < 10 ; i++ ) {
  634. err = qglGetError();
  635. if ( err == GL_NO_ERROR ) {
  636. return;
  637. }
  638. switch( err ) {
  639. case GL_INVALID_ENUM:
  640. strcpy( s, "GL_INVALID_ENUM" );
  641. break;
  642. case GL_INVALID_VALUE:
  643. strcpy( s, "GL_INVALID_VALUE" );
  644. break;
  645. case GL_INVALID_OPERATION:
  646. strcpy( s, "GL_INVALID_OPERATION" );
  647. break;
  648. case GL_STACK_OVERFLOW:
  649. strcpy( s, "GL_STACK_OVERFLOW" );
  650. break;
  651. case GL_STACK_UNDERFLOW:
  652. strcpy( s, "GL_STACK_UNDERFLOW" );
  653. break;
  654. case GL_OUT_OF_MEMORY:
  655. strcpy( s, "GL_OUT_OF_MEMORY" );
  656. break;
  657. default:
  658. idStr::snPrintf( s, sizeof(s), "%i", err);
  659. break;
  660. }
  661. if ( !r_ignoreGLErrors.GetBool() ) {
  662. common->Printf( "GL_CheckErrors: %s\n", s );
  663. }
  664. }
  665. }
  666. /*
  667. =====================
  668. R_ReloadSurface_f
  669. Reload the material displayed by r_showSurfaceInfo
  670. =====================
  671. */
  672. static void R_ReloadSurface_f( const idCmdArgs &args ) {
  673. modelTrace_t mt;
  674. idVec3 start, end;
  675. // start far enough away that we don't hit the player model
  676. start = tr.primaryView->renderView.vieworg + tr.primaryView->renderView.viewaxis[0] * 16;
  677. end = start + tr.primaryView->renderView.viewaxis[0] * 1000.0f;
  678. if ( !tr.primaryWorld->Trace( mt, start, end, 0.0f, false ) ) {
  679. return;
  680. }
  681. common->Printf( "Reloading %s\n", mt.material->GetName() );
  682. // reload the decl
  683. mt.material->base->Reload();
  684. // reload any images used by the decl
  685. mt.material->ReloadImages( false );
  686. }
  687. /*
  688. ==============
  689. R_ListModes_f
  690. ==============
  691. */
  692. static void R_ListModes_f( const idCmdArgs &args ) {
  693. int i;
  694. common->Printf( "\n" );
  695. for ( i = 0; i < s_numVidModes; i++ ) {
  696. common->Printf( "%s\n", r_vidModes[i].description );
  697. }
  698. common->Printf( "\n" );
  699. }
  700. /*
  701. =============
  702. R_TestImage_f
  703. Display the given image centered on the screen.
  704. testimage <number>
  705. testimage <filename>
  706. =============
  707. */
  708. void R_TestImage_f( const idCmdArgs &args ) {
  709. int imageNum;
  710. if ( tr.testVideo ) {
  711. delete tr.testVideo;
  712. tr.testVideo = NULL;
  713. }
  714. tr.testImage = NULL;
  715. if ( args.Argc() != 2 ) {
  716. return;
  717. }
  718. if ( idStr::IsNumeric( args.Argv(1) ) ) {
  719. imageNum = atoi( args.Argv(1) );
  720. if ( imageNum >= 0 && imageNum < globalImages->images.Num() ) {
  721. tr.testImage = globalImages->images[imageNum];
  722. }
  723. } else {
  724. tr.testImage = globalImages->ImageFromFile( args.Argv( 1 ), TF_DEFAULT, false, TR_REPEAT, TD_DEFAULT );
  725. }
  726. }
  727. /*
  728. =============
  729. R_TestVideo_f
  730. Plays the cinematic file in a testImage
  731. =============
  732. */
  733. void R_TestVideo_f( const idCmdArgs &args ) {
  734. if ( tr.testVideo ) {
  735. delete tr.testVideo;
  736. tr.testVideo = NULL;
  737. }
  738. tr.testImage = NULL;
  739. if ( args.Argc() < 2 ) {
  740. return;
  741. }
  742. tr.testImage = globalImages->ImageFromFile( "_scratch", TF_DEFAULT, false, TR_REPEAT, TD_DEFAULT );
  743. tr.testVideo = idCinematic::Alloc();
  744. tr.testVideo->InitFromFile( args.Argv( 1 ), true );
  745. cinData_t cin;
  746. cin = tr.testVideo->ImageForTime( 0 );
  747. if ( !cin.image ) {
  748. delete tr.testVideo;
  749. tr.testVideo = NULL;
  750. tr.testImage = NULL;
  751. return;
  752. }
  753. common->Printf( "%i x %i images\n", cin.imageWidth, cin.imageHeight );
  754. int len = tr.testVideo->AnimationLength();
  755. common->Printf( "%5.1f seconds of video\n", len * 0.001 );
  756. tr.testVideoStartTime = tr.primaryRenderView.time * 0.001;
  757. // try to play the matching wav file
  758. idStr wavString = args.Argv( ( args.Argc() == 2 ) ? 1 : 2 );
  759. wavString.StripFileExtension();
  760. wavString = wavString + ".wav";
  761. session->sw->PlayShaderDirectly( wavString.c_str() );
  762. }
  763. static int R_QsortSurfaceAreas( const void *a, const void *b ) {
  764. const idMaterial *ea, *eb;
  765. int ac, bc;
  766. ea = *(idMaterial **)a;
  767. if ( !ea->EverReferenced() ) {
  768. ac = 0;
  769. } else {
  770. ac = ea->GetSurfaceArea();
  771. }
  772. eb = *(idMaterial **)b;
  773. if ( !eb->EverReferenced() ) {
  774. bc = 0;
  775. } else {
  776. bc = eb->GetSurfaceArea();
  777. }
  778. if ( ac < bc ) {
  779. return -1;
  780. }
  781. if ( ac > bc ) {
  782. return 1;
  783. }
  784. return idStr::Icmp( ea->GetName(), eb->GetName() );
  785. }
  786. /*
  787. ===================
  788. R_ReportSurfaceAreas_f
  789. Prints a list of the materials sorted by surface area
  790. ===================
  791. */
  792. void R_ReportSurfaceAreas_f( const idCmdArgs &args ) {
  793. int i, count;
  794. idMaterial **list;
  795. count = declManager->GetNumDecls( DECL_MATERIAL );
  796. list = (idMaterial **)_alloca( count * sizeof( *list ) );
  797. for ( i = 0 ; i < count ; i++ ) {
  798. list[i] = (idMaterial *)declManager->DeclByIndex( DECL_MATERIAL, i, false );
  799. }
  800. qsort( list, count, sizeof( list[0] ), R_QsortSurfaceAreas );
  801. // skip over ones with 0 area
  802. for ( i = 0 ; i < count ; i++ ) {
  803. if ( list[i]->GetSurfaceArea() > 0 ) {
  804. break;
  805. }
  806. }
  807. for ( ; i < count ; i++ ) {
  808. // report size in "editor blocks"
  809. int blocks = list[i]->GetSurfaceArea() / 4096.0;
  810. common->Printf( "%7i %s\n", blocks, list[i]->GetName() );
  811. }
  812. }
  813. /*
  814. ===================
  815. R_ReportImageDuplication_f
  816. Checks for images with the same hash value and does a better comparison
  817. ===================
  818. */
  819. void R_ReportImageDuplication_f( const idCmdArgs &args ) {
  820. int i, j;
  821. common->Printf( "Images with duplicated contents:\n" );
  822. int count = 0;
  823. for ( i = 0 ; i < globalImages->images.Num() ; i++ ) {
  824. idImage *image1 = globalImages->images[i];
  825. if ( image1->isPartialImage ) {
  826. // ignore background loading stubs
  827. continue;
  828. }
  829. if ( image1->generatorFunction ) {
  830. // ignore procedural images
  831. continue;
  832. }
  833. if ( image1->cubeFiles != CF_2D ) {
  834. // ignore cube maps
  835. continue;
  836. }
  837. if ( image1->defaulted ) {
  838. continue;
  839. }
  840. byte *data1;
  841. int w1, h1;
  842. R_LoadImageProgram( image1->imgName, &data1, &w1, &h1, NULL );
  843. for ( j = 0 ; j < i ; j++ ) {
  844. idImage *image2 = globalImages->images[j];
  845. if ( image2->isPartialImage ) {
  846. continue;
  847. }
  848. if ( image2->generatorFunction ) {
  849. continue;
  850. }
  851. if ( image2->cubeFiles != CF_2D ) {
  852. continue;
  853. }
  854. if ( image2->defaulted ) {
  855. continue;
  856. }
  857. if ( image1->imageHash != image2->imageHash ) {
  858. continue;
  859. }
  860. if ( image2->uploadWidth != image1->uploadWidth
  861. || image2->uploadHeight != image1->uploadHeight ) {
  862. continue;
  863. }
  864. if ( !idStr::Icmp( image1->imgName, image2->imgName ) ) {
  865. // ignore same image-with-different-parms
  866. continue;
  867. }
  868. byte *data2;
  869. int w2, h2;
  870. R_LoadImageProgram( image2->imgName, &data2, &w2, &h2, NULL );
  871. if ( w2 != w1 || h2 != h1 ) {
  872. R_StaticFree( data2 );
  873. continue;
  874. }
  875. if ( memcmp( data1, data2, w1*h1*4 ) ) {
  876. R_StaticFree( data2 );
  877. continue;
  878. }
  879. R_StaticFree( data2 );
  880. common->Printf( "%s == %s\n", image1->imgName.c_str(), image2->imgName.c_str() );
  881. session->UpdateScreen( true );
  882. count++;
  883. break;
  884. }
  885. R_StaticFree( data1 );
  886. }
  887. common->Printf( "%i / %i collisions\n", count, globalImages->images.Num() );
  888. }
  889. /*
  890. ==============================================================================
  891. THROUGHPUT BENCHMARKING
  892. ==============================================================================
  893. */
  894. /*
  895. ================
  896. R_RenderingFPS
  897. ================
  898. */
  899. static float R_RenderingFPS( const renderView_t *renderView ) {
  900. qglFinish();
  901. int start = Sys_Milliseconds();
  902. static const int SAMPLE_MSEC = 1000;
  903. int end;
  904. int count = 0;
  905. while( 1 ) {
  906. // render
  907. renderSystem->BeginFrame( glConfig.vidWidth, glConfig.vidHeight );
  908. tr.primaryWorld->RenderScene( renderView );
  909. renderSystem->EndFrame( NULL, NULL );
  910. qglFinish();
  911. count++;
  912. end = Sys_Milliseconds();
  913. if ( end - start > SAMPLE_MSEC ) {
  914. break;
  915. }
  916. }
  917. float fps = count * 1000.0 / ( end - start );
  918. return fps;
  919. }
  920. /*
  921. ================
  922. R_Benchmark_f
  923. ================
  924. */
  925. void R_Benchmark_f( const idCmdArgs &args ) {
  926. float fps, msec;
  927. renderView_t view;
  928. if ( !tr.primaryView ) {
  929. common->Printf( "No primaryView for benchmarking\n" );
  930. return;
  931. }
  932. view = tr.primaryRenderView;
  933. for ( int size = 100 ; size >= 10 ; size -= 10 ) {
  934. r_screenFraction.SetInteger( size );
  935. fps = R_RenderingFPS( &view );
  936. int kpix = glConfig.vidWidth * glConfig.vidHeight * ( size * 0.01 ) * ( size * 0.01 ) * 0.001;
  937. msec = 1000.0 / fps;
  938. common->Printf( "kpix: %4i msec:%5.1f fps:%5.1f\n", kpix, msec, fps );
  939. }
  940. // enable r_singleTriangle 1 while r_screenFraction is still at 10
  941. r_singleTriangle.SetBool( 1 );
  942. fps = R_RenderingFPS( &view );
  943. msec = 1000.0 / fps;
  944. common->Printf( "single tri msec:%5.1f fps:%5.1f\n", msec, fps );
  945. r_singleTriangle.SetBool( 0 );
  946. r_screenFraction.SetInteger( 100 );
  947. // enable r_skipRenderContext 1
  948. r_skipRenderContext.SetBool( true );
  949. fps = R_RenderingFPS( &view );
  950. msec = 1000.0 / fps;
  951. common->Printf( "no context msec:%5.1f fps:%5.1f\n", msec, fps );
  952. r_skipRenderContext.SetBool( false );
  953. }
  954. /*
  955. ==============================================================================
  956. SCREEN SHOTS
  957. ==============================================================================
  958. */
  959. /*
  960. ====================
  961. R_ReadTiledPixels
  962. Allows the rendering of an image larger than the actual window by
  963. tiling it into window-sized chunks and rendering each chunk separately
  964. If ref isn't specified, the full session UpdateScreen will be done.
  965. ====================
  966. */
  967. void R_ReadTiledPixels( int width, int height, byte *buffer, renderView_t *ref = NULL ) {
  968. // include extra space for OpenGL padding to word boundaries
  969. byte *temp = (byte *)R_StaticAlloc( (glConfig.vidWidth+3) * glConfig.vidHeight * 3 );
  970. int oldWidth = glConfig.vidWidth;
  971. int oldHeight = glConfig.vidHeight;
  972. tr.tiledViewport[0] = width;
  973. tr.tiledViewport[1] = height;
  974. // disable scissor, so we don't need to adjust all those rects
  975. r_useScissor.SetBool( false );
  976. for ( int xo = 0 ; xo < width ; xo += oldWidth ) {
  977. for ( int yo = 0 ; yo < height ; yo += oldHeight ) {
  978. tr.viewportOffset[0] = -xo;
  979. tr.viewportOffset[1] = -yo;
  980. if ( ref ) {
  981. tr.BeginFrame( oldWidth, oldHeight );
  982. tr.primaryWorld->RenderScene( ref );
  983. tr.EndFrame( NULL, NULL );
  984. } else {
  985. session->UpdateScreen();
  986. }
  987. int w = oldWidth;
  988. if ( xo + w > width ) {
  989. w = width - xo;
  990. }
  991. int h = oldHeight;
  992. if ( yo + h > height ) {
  993. h = height - yo;
  994. }
  995. qglReadBuffer( GL_FRONT );
  996. qglReadPixels( 0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, temp );
  997. int row = ( w * 3 + 3 ) & ~3; // OpenGL pads to dword boundaries
  998. for ( int y = 0 ; y < h ; y++ ) {
  999. memcpy( buffer + ( ( yo + y )* width + xo ) * 3,
  1000. temp + y * row, w * 3 );
  1001. }
  1002. }
  1003. }
  1004. r_useScissor.SetBool( true );
  1005. tr.viewportOffset[0] = 0;
  1006. tr.viewportOffset[1] = 0;
  1007. tr.tiledViewport[0] = 0;
  1008. tr.tiledViewport[1] = 0;
  1009. R_StaticFree( temp );
  1010. glConfig.vidWidth = oldWidth;
  1011. glConfig.vidHeight = oldHeight;
  1012. }
  1013. /*
  1014. ==================
  1015. TakeScreenshot
  1016. Move to tr_imagefiles.c...
  1017. Will automatically tile render large screen shots if necessary
  1018. Downsample is the number of steps to mipmap the image before saving it
  1019. If ref == NULL, session->updateScreen will be used
  1020. ==================
  1021. */
  1022. void idRenderSystemLocal::TakeScreenshot( int width, int height, const char *fileName, int blends, renderView_t *ref ) {
  1023. byte *buffer;
  1024. int i, j, c, temp;
  1025. takingScreenshot = true;
  1026. int pix = width * height;
  1027. buffer = (byte *)R_StaticAlloc(pix*3 + 18);
  1028. memset (buffer, 0, 18);
  1029. if ( blends <= 1 ) {
  1030. R_ReadTiledPixels( width, height, buffer + 18, ref );
  1031. } else {
  1032. unsigned short *shortBuffer = (unsigned short *)R_StaticAlloc(pix*2*3);
  1033. memset (shortBuffer, 0, pix*2*3);
  1034. // enable anti-aliasing jitter
  1035. r_jitter.SetBool( true );
  1036. for ( i = 0 ; i < blends ; i++ ) {
  1037. R_ReadTiledPixels( width, height, buffer + 18, ref );
  1038. for ( j = 0 ; j < pix*3 ; j++ ) {
  1039. shortBuffer[j] += buffer[18+j];
  1040. }
  1041. }
  1042. // divide back to bytes
  1043. for ( i = 0 ; i < pix*3 ; i++ ) {
  1044. buffer[18+i] = shortBuffer[i] / blends;
  1045. }
  1046. R_StaticFree( shortBuffer );
  1047. r_jitter.SetBool( false );
  1048. }
  1049. // fill in the header (this is vertically flipped, which qglReadPixels emits)
  1050. buffer[2] = 2; // uncompressed type
  1051. buffer[12] = width & 255;
  1052. buffer[13] = width >> 8;
  1053. buffer[14] = height & 255;
  1054. buffer[15] = height >> 8;
  1055. buffer[16] = 24; // pixel size
  1056. // swap rgb to bgr
  1057. c = 18 + width * height * 3;
  1058. for (i=18 ; i<c ; i+=3) {
  1059. temp = buffer[i];
  1060. buffer[i] = buffer[i+2];
  1061. buffer[i+2] = temp;
  1062. }
  1063. // _D3XP adds viewnote screenie save to cdpath
  1064. if ( strstr( fileName, "viewnote" ) ) {
  1065. fileSystem->WriteFile( fileName, buffer, c, "fs_cdpath" );
  1066. } else {
  1067. fileSystem->WriteFile( fileName, buffer, c );
  1068. }
  1069. R_StaticFree( buffer );
  1070. takingScreenshot = false;
  1071. }
  1072. /*
  1073. ==================
  1074. R_ScreenshotFilename
  1075. Returns a filename with digits appended
  1076. if we have saved a previous screenshot, don't scan
  1077. from the beginning, because recording demo avis can involve
  1078. thousands of shots
  1079. ==================
  1080. */
  1081. void R_ScreenshotFilename( int &lastNumber, const char *base, idStr &fileName ) {
  1082. int a,b,c,d, e;
  1083. bool restrict = cvarSystem->GetCVarBool( "fs_restrict" );
  1084. cvarSystem->SetCVarBool( "fs_restrict", false );
  1085. lastNumber++;
  1086. if ( lastNumber > 99999 ) {
  1087. lastNumber = 99999;
  1088. }
  1089. for ( ; lastNumber < 99999 ; lastNumber++ ) {
  1090. int frac = lastNumber;
  1091. a = frac / 10000;
  1092. frac -= a*10000;
  1093. b = frac / 1000;
  1094. frac -= b*1000;
  1095. c = frac / 100;
  1096. frac -= c*100;
  1097. d = frac / 10;
  1098. frac -= d*10;
  1099. e = frac;
  1100. sprintf( fileName, "%s%i%i%i%i%i.tga", base, a, b, c, d, e );
  1101. if ( lastNumber == 99999 ) {
  1102. break;
  1103. }
  1104. int len = fileSystem->ReadFile( fileName, NULL, NULL );
  1105. if ( len <= 0 ) {
  1106. break;
  1107. }
  1108. // check again...
  1109. }
  1110. cvarSystem->SetCVarBool( "fs_restrict", restrict );
  1111. }
  1112. /*
  1113. ==================
  1114. R_BlendedScreenShot
  1115. screenshot
  1116. screenshot [filename]
  1117. screenshot [width] [height]
  1118. screenshot [width] [height] [samples]
  1119. ==================
  1120. */
  1121. #define MAX_BLENDS 256 // to keep the accumulation in shorts
  1122. void R_ScreenShot_f( const idCmdArgs &args ) {
  1123. static int lastNumber = 0;
  1124. idStr checkname;
  1125. int width = glConfig.vidWidth;
  1126. int height = glConfig.vidHeight;
  1127. int x = 0;
  1128. int y = 0;
  1129. int blends = 0;
  1130. switch ( args.Argc() ) {
  1131. case 1:
  1132. width = glConfig.vidWidth;
  1133. height = glConfig.vidHeight;
  1134. blends = 1;
  1135. R_ScreenshotFilename( lastNumber, "screenshots/shot", checkname );
  1136. break;
  1137. case 2:
  1138. width = glConfig.vidWidth;
  1139. height = glConfig.vidHeight;
  1140. blends = 1;
  1141. checkname = args.Argv( 1 );
  1142. break;
  1143. case 3:
  1144. width = atoi( args.Argv( 1 ) );
  1145. height = atoi( args.Argv( 2 ) );
  1146. blends = 1;
  1147. R_ScreenshotFilename( lastNumber, "screenshots/shot", checkname );
  1148. break;
  1149. case 4:
  1150. width = atoi( args.Argv( 1 ) );
  1151. height = atoi( args.Argv( 2 ) );
  1152. blends = atoi( args.Argv( 3 ) );
  1153. if ( blends < 1 ) {
  1154. blends = 1;
  1155. }
  1156. if ( blends > MAX_BLENDS ) {
  1157. blends = MAX_BLENDS;
  1158. }
  1159. R_ScreenshotFilename( lastNumber, "screenshots/shot", checkname );
  1160. break;
  1161. default:
  1162. common->Printf( "usage: screenshot\n screenshot <filename>\n screenshot <width> <height>\n screenshot <width> <height> <blends>\n" );
  1163. return;
  1164. }
  1165. // put the console away
  1166. console->Close();
  1167. tr.TakeScreenshot( width, height, checkname, blends, NULL );
  1168. common->Printf( "Wrote %s\n", checkname.c_str() );
  1169. }
  1170. /*
  1171. ===============
  1172. R_StencilShot
  1173. Save out a screenshot showing the stencil buffer expanded by 16x range
  1174. ===============
  1175. */
  1176. void R_StencilShot( void ) {
  1177. byte *buffer;
  1178. int i, c;
  1179. int width = tr.GetScreenWidth();
  1180. int height = tr.GetScreenHeight();
  1181. int pix = width * height;
  1182. c = pix * 3 + 18;
  1183. buffer = (byte *)Mem_Alloc(c);
  1184. memset (buffer, 0, 18);
  1185. byte *byteBuffer = (byte *)Mem_Alloc(pix);
  1186. qglReadPixels( 0, 0, width, height, GL_STENCIL_INDEX , GL_UNSIGNED_BYTE, byteBuffer );
  1187. for ( i = 0 ; i < pix ; i++ ) {
  1188. buffer[18+i*3] =
  1189. buffer[18+i*3+1] =
  1190. // buffer[18+i*3+2] = ( byteBuffer[i] & 15 ) * 16;
  1191. buffer[18+i*3+2] = byteBuffer[i];
  1192. }
  1193. // fill in the header (this is vertically flipped, which qglReadPixels emits)
  1194. buffer[2] = 2; // uncompressed type
  1195. buffer[12] = width & 255;
  1196. buffer[13] = width >> 8;
  1197. buffer[14] = height & 255;
  1198. buffer[15] = height >> 8;
  1199. buffer[16] = 24; // pixel size
  1200. fileSystem->WriteFile( "screenshots/stencilShot.tga", buffer, c, "fs_savepath" );
  1201. Mem_Free( buffer );
  1202. Mem_Free( byteBuffer );
  1203. }
  1204. /*
  1205. ==================
  1206. R_EnvShot_f
  1207. envshot <basename>
  1208. Saves out env/<basename>_ft.tga, etc
  1209. ==================
  1210. */
  1211. void R_EnvShot_f( const idCmdArgs &args ) {
  1212. idStr fullname;
  1213. const char *baseName;
  1214. int i;
  1215. idMat3 axis[6];
  1216. renderView_t ref;
  1217. viewDef_t primary;
  1218. int blends;
  1219. char *extensions[6] = { "_px.tga", "_nx.tga", "_py.tga", "_ny.tga",
  1220. "_pz.tga", "_nz.tga" };
  1221. int size;
  1222. if ( args.Argc() != 2 && args.Argc() != 3 && args.Argc() != 4 ) {
  1223. common->Printf( "USAGE: envshot <basename> [size] [blends]\n" );
  1224. return;
  1225. }
  1226. baseName = args.Argv( 1 );
  1227. blends = 1;
  1228. if ( args.Argc() == 4 ) {
  1229. size = atoi( args.Argv( 2 ) );
  1230. blends = atoi( args.Argv( 3 ) );
  1231. } else if ( args.Argc() == 3 ) {
  1232. size = atoi( args.Argv( 2 ) );
  1233. blends = 1;
  1234. } else {
  1235. size = 256;
  1236. blends = 1;
  1237. }
  1238. if ( !tr.primaryView ) {
  1239. common->Printf( "No primary view.\n" );
  1240. return;
  1241. }
  1242. primary = *tr.primaryView;
  1243. memset( &axis, 0, sizeof( axis ) );
  1244. axis[0][0][0] = 1;
  1245. axis[0][1][2] = 1;
  1246. axis[0][2][1] = 1;
  1247. axis[1][0][0] = -1;
  1248. axis[1][1][2] = -1;
  1249. axis[1][2][1] = 1;
  1250. axis[2][0][1] = 1;
  1251. axis[2][1][0] = -1;
  1252. axis[2][2][2] = -1;
  1253. axis[3][0][1] = -1;
  1254. axis[3][1][0] = -1;
  1255. axis[3][2][2] = 1;
  1256. axis[4][0][2] = 1;
  1257. axis[4][1][0] = -1;
  1258. axis[4][2][1] = 1;
  1259. axis[5][0][2] = -1;
  1260. axis[5][1][0] = 1;
  1261. axis[5][2][1] = 1;
  1262. for ( i = 0 ; i < 6 ; i++ ) {
  1263. ref = primary.renderView;
  1264. ref.x = ref.y = 0;
  1265. ref.fov_x = ref.fov_y = 90;
  1266. ref.width = glConfig.vidWidth;
  1267. ref.height = glConfig.vidHeight;
  1268. ref.viewaxis = axis[i];
  1269. sprintf( fullname, "env/%s%s", baseName, extensions[i] );
  1270. tr.TakeScreenshot( size, size, fullname, blends, &ref );
  1271. }
  1272. common->Printf( "Wrote %s, etc\n", fullname.c_str() );
  1273. }
  1274. //============================================================================
  1275. static idMat3 cubeAxis[6];
  1276. /*
  1277. ==================
  1278. R_SampleCubeMap
  1279. ==================
  1280. */
  1281. void R_SampleCubeMap( const idVec3 &dir, int size, byte *buffers[6], byte result[4] ) {
  1282. float adir[3];
  1283. int axis, x, y;
  1284. adir[0] = fabs(dir[0]);
  1285. adir[1] = fabs(dir[1]);
  1286. adir[2] = fabs(dir[2]);
  1287. if ( dir[0] >= adir[1] && dir[0] >= adir[2] ) {
  1288. axis = 0;
  1289. } else if ( -dir[0] >= adir[1] && -dir[0] >= adir[2] ) {
  1290. axis = 1;
  1291. } else if ( dir[1] >= adir[0] && dir[1] >= adir[2] ) {
  1292. axis = 2;
  1293. } else if ( -dir[1] >= adir[0] && -dir[1] >= adir[2] ) {
  1294. axis = 3;
  1295. } else if ( dir[2] >= adir[1] && dir[2] >= adir[2] ) {
  1296. axis = 4;
  1297. } else {
  1298. axis = 5;
  1299. }
  1300. float fx = (dir * cubeAxis[axis][1]) / (dir * cubeAxis[axis][0]);
  1301. float fy = (dir * cubeAxis[axis][2]) / (dir * cubeAxis[axis][0]);
  1302. fx = -fx;
  1303. fy = -fy;
  1304. x = size * 0.5 * (fx + 1);
  1305. y = size * 0.5 * (fy + 1);
  1306. if ( x < 0 ) {
  1307. x = 0;
  1308. } else if ( x >= size ) {
  1309. x = size-1;
  1310. }
  1311. if ( y < 0 ) {
  1312. y = 0;
  1313. } else if ( y >= size ) {
  1314. y = size-1;
  1315. }
  1316. result[0] = buffers[axis][(y*size+x)*4+0];
  1317. result[1] = buffers[axis][(y*size+x)*4+1];
  1318. result[2] = buffers[axis][(y*size+x)*4+2];
  1319. result[3] = buffers[axis][(y*size+x)*4+3];
  1320. }
  1321. /*
  1322. ==================
  1323. R_MakeAmbientMap_f
  1324. R_MakeAmbientMap_f <basename> [size]
  1325. Saves out env/<basename>_amb_ft.tga, etc
  1326. ==================
  1327. */
  1328. void R_MakeAmbientMap_f( const idCmdArgs &args ) {
  1329. idStr fullname;
  1330. const char *baseName;
  1331. int i;
  1332. renderView_t ref;
  1333. viewDef_t primary;
  1334. int downSample;
  1335. char *extensions[6] = { "_px.tga", "_nx.tga", "_py.tga", "_ny.tga",
  1336. "_pz.tga", "_nz.tga" };
  1337. int outSize;
  1338. byte *buffers[6];
  1339. int width, height;
  1340. if ( args.Argc() != 2 && args.Argc() != 3 ) {
  1341. common->Printf( "USAGE: ambientshot <basename> [size]\n" );
  1342. return;
  1343. }
  1344. baseName = args.Argv( 1 );
  1345. downSample = 0;
  1346. if ( args.Argc() == 3 ) {
  1347. outSize = atoi( args.Argv( 2 ) );
  1348. } else {
  1349. outSize = 32;
  1350. }
  1351. memset( &cubeAxis, 0, sizeof( cubeAxis ) );
  1352. cubeAxis[0][0][0] = 1;
  1353. cubeAxis[0][1][2] = 1;
  1354. cubeAxis[0][2][1] = 1;
  1355. cubeAxis[1][0][0] = -1;
  1356. cubeAxis[1][1][2] = -1;
  1357. cubeAxis[1][2][1] = 1;
  1358. cubeAxis[2][0][1] = 1;
  1359. cubeAxis[2][1][0] = -1;
  1360. cubeAxis[2][2][2] = -1;
  1361. cubeAxis[3][0][1] = -1;
  1362. cubeAxis[3][1][0] = -1;
  1363. cubeAxis[3][2][2] = 1;
  1364. cubeAxis[4][0][2] = 1;
  1365. cubeAxis[4][1][0] = -1;
  1366. cubeAxis[4][2][1] = 1;
  1367. cubeAxis[5][0][2] = -1;
  1368. cubeAxis[5][1][0] = 1;
  1369. cubeAxis[5][2][1] = 1;
  1370. // read all of the images
  1371. for ( i = 0 ; i < 6 ; i++ ) {
  1372. sprintf( fullname, "env/%s%s", baseName, extensions[i] );
  1373. common->Printf( "loading %s\n", fullname.c_str() );
  1374. session->UpdateScreen();
  1375. R_LoadImage( fullname, &buffers[i], &width, &height, NULL, true );
  1376. if ( !buffers[i] ) {
  1377. common->Printf( "failed.\n" );
  1378. for ( i-- ; i >= 0 ; i-- ) {
  1379. Mem_Free( buffers[i] );
  1380. }
  1381. return;
  1382. }
  1383. }
  1384. // resample with hemispherical blending
  1385. int samples = 1000;
  1386. byte *outBuffer = (byte *)_alloca( outSize * outSize * 4 );
  1387. for ( int map = 0 ; map < 2 ; map++ ) {
  1388. for ( i = 0 ; i < 6 ; i++ ) {
  1389. for ( int x = 0 ; x < outSize ; x++ ) {
  1390. for ( int y = 0 ; y < outSize ; y++ ) {
  1391. idVec3 dir;
  1392. float total[3];
  1393. dir = cubeAxis[i][0] + -( -1 + 2.0*x/(outSize-1) ) * cubeAxis[i][1] + -( -1 + 2.0*y/(outSize-1) ) * cubeAxis[i][2];
  1394. dir.Normalize();
  1395. total[0] = total[1] = total[2] = 0;
  1396. //samples = 1;
  1397. float limit = map ? 0.95 : 0.25; // small for specular, almost hemisphere for ambient
  1398. for ( int s = 0 ; s < samples ; s++ ) {
  1399. // pick a random direction vector that is inside the unit sphere but not behind dir,
  1400. // which is a robust way to evenly sample a hemisphere
  1401. idVec3 test;
  1402. while( 1 ) {
  1403. for ( int j = 0 ; j < 3 ; j++ ) {
  1404. test[j] = -1 + 2 * (rand()&0x7fff)/(float)0x7fff;
  1405. }
  1406. if ( test.Length() > 1.0 ) {
  1407. continue;
  1408. }
  1409. test.Normalize();
  1410. if ( test * dir > limit ) { // don't do a complete hemisphere
  1411. break;
  1412. }
  1413. }
  1414. byte result[4];
  1415. //test = dir;
  1416. R_SampleCubeMap( test, width, buffers, result );
  1417. total[0] += result[0];
  1418. total[1] += result[1];
  1419. total[2] += result[2];
  1420. }
  1421. outBuffer[(y*outSize+x)*4+0] = total[0] / samples;
  1422. outBuffer[(y*outSize+x)*4+1] = total[1] / samples;
  1423. outBuffer[(y*outSize+x)*4+2] = total[2] / samples;
  1424. outBuffer[(y*outSize+x)*4+3] = 255;
  1425. }
  1426. }
  1427. if ( map == 0 ) {
  1428. sprintf( fullname, "env/%s_amb%s", baseName, extensions[i] );
  1429. } else {
  1430. sprintf( fullname, "env/%s_spec%s", baseName, extensions[i] );
  1431. }
  1432. common->Printf( "writing %s\n", fullname.c_str() );
  1433. session->UpdateScreen();
  1434. R_WriteTGA( fullname, outBuffer, outSize, outSize );
  1435. }
  1436. }
  1437. for ( i = 0 ; i < 6 ; i++ ) {
  1438. if ( buffers[i] ) {
  1439. Mem_Free( buffers[i] );
  1440. }
  1441. }
  1442. }
  1443. //============================================================================
  1444. /*
  1445. ===============
  1446. R_SetColorMappings
  1447. ===============
  1448. */
  1449. void R_SetColorMappings( void ) {
  1450. int i, j;
  1451. float g, b;
  1452. int inf;
  1453. b = r_brightness.GetFloat();
  1454. g = r_gamma.GetFloat();
  1455. for ( i = 0; i < 256; i++ ) {
  1456. j = i * b;
  1457. if (j > 255) {
  1458. j = 255;
  1459. }
  1460. if ( g == 1 ) {
  1461. inf = (j<<8) | j;
  1462. } else {
  1463. inf = 0xffff * pow ( j/255.0f, 1.0f / g ) + 0.5f;
  1464. }
  1465. if (inf < 0) {
  1466. inf = 0;
  1467. }
  1468. if (inf > 0xffff) {
  1469. inf = 0xffff;
  1470. }
  1471. tr.gammaTable[i] = inf;
  1472. }
  1473. GLimp_SetGamma( tr.gammaTable, tr.gammaTable, tr.gammaTable );
  1474. }
  1475. /*
  1476. ================
  1477. GfxInfo_f
  1478. ================
  1479. */
  1480. void GfxInfo_f( const idCmdArgs &args ) {
  1481. const char *fsstrings[] =
  1482. {
  1483. "windowed",
  1484. "fullscreen"
  1485. };
  1486. common->Printf( "\nGL_VENDOR: %s\n", glConfig.vendor_string );
  1487. common->Printf( "GL_RENDERER: %s\n", glConfig.renderer_string );
  1488. common->Printf( "GL_VERSION: %s\n", glConfig.version_string );
  1489. common->Printf( "GL_EXTENSIONS: %s\n", glConfig.extensions_string );
  1490. if ( glConfig.wgl_extensions_string ) {
  1491. common->Printf( "WGL_EXTENSIONS: %s\n", glConfig.wgl_extensions_string );
  1492. }
  1493. common->Printf( "GL_MAX_TEXTURE_SIZE: %d\n", glConfig.maxTextureSize );
  1494. common->Printf( "GL_MAX_TEXTURE_UNITS_ARB: %d\n", glConfig.maxTextureUnits );
  1495. common->Printf( "GL_MAX_TEXTURE_COORDS_ARB: %d\n", glConfig.maxTextureCoords );
  1496. common->Printf( "GL_MAX_TEXTURE_IMAGE_UNITS_ARB: %d\n", glConfig.maxTextureImageUnits );
  1497. common->Printf( "\nPIXELFORMAT: color(%d-bits) Z(%d-bit) stencil(%d-bits)\n", glConfig.colorBits, glConfig.depthBits, glConfig.stencilBits );
  1498. common->Printf( "MODE: %d, %d x %d %s hz:", r_mode.GetInteger(), glConfig.vidWidth, glConfig.vidHeight, fsstrings[r_fullscreen.GetBool()] );
  1499. if ( glConfig.displayFrequency ) {
  1500. common->Printf( "%d\n", glConfig.displayFrequency );
  1501. } else {
  1502. common->Printf( "N/A\n" );
  1503. }
  1504. common->Printf( "CPU: %s\n", Sys_GetProcessorString() );
  1505. const char *active[2] = { "", " (ACTIVE)" };
  1506. common->Printf( "ARB path ENABLED%s\n", active[tr.backEndRenderer == BE_ARB] );
  1507. if ( glConfig.allowNV10Path ) {
  1508. common->Printf( "NV10 path ENABLED%s\n", active[tr.backEndRenderer == BE_NV10] );
  1509. } else {
  1510. common->Printf( "NV10 path disabled\n" );
  1511. }
  1512. if ( glConfig.allowNV20Path ) {
  1513. common->Printf( "NV20 path ENABLED%s\n", active[tr.backEndRenderer == BE_NV20] );
  1514. } else {
  1515. common->Printf( "NV20 path disabled\n" );
  1516. }
  1517. if ( glConfig.allowR200Path ) {
  1518. common->Printf( "R200 path ENABLED%s\n", active[tr.backEndRenderer == BE_R200] );
  1519. } else {
  1520. common->Printf( "R200 path disabled\n" );
  1521. }
  1522. if ( glConfig.allowARB2Path ) {
  1523. common->Printf( "ARB2 path ENABLED%s\n", active[tr.backEndRenderer == BE_ARB2] );
  1524. } else {
  1525. common->Printf( "ARB2 path disabled\n" );
  1526. }
  1527. //=============================
  1528. common->Printf( "-------\n" );
  1529. if ( r_finish.GetBool() ) {
  1530. common->Printf( "Forcing glFinish\n" );
  1531. } else {
  1532. common->Printf( "glFinish not forced\n" );
  1533. }
  1534. #ifdef _WIN32
  1535. // WGL_EXT_swap_interval
  1536. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  1537. extern PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
  1538. if ( r_swapInterval.GetInteger() && wglSwapIntervalEXT ) {
  1539. common->Printf( "Forcing swapInterval %i\n", r_swapInterval.GetInteger() );
  1540. } else {
  1541. common->Printf( "swapInterval not forced\n" );
  1542. }
  1543. #endif
  1544. bool tss = glConfig.twoSidedStencilAvailable || glConfig.atiTwoSidedStencilAvailable;
  1545. if ( !r_useTwoSidedStencil.GetBool() && tss ) {
  1546. common->Printf( "Two sided stencil available but disabled\n" );
  1547. } else if ( !tss ) {
  1548. common->Printf( "Two sided stencil not available\n" );
  1549. } else if ( tss ) {
  1550. common->Printf( "Using two sided stencil\n" );
  1551. }
  1552. if ( vertexCache.IsFast() ) {
  1553. common->Printf( "Vertex cache is fast\n" );
  1554. } else {
  1555. common->Printf( "Vertex cache is SLOW\n" );
  1556. }
  1557. }
  1558. /*
  1559. =================
  1560. R_VidRestart_f
  1561. =================
  1562. */
  1563. void R_VidRestart_f( const idCmdArgs &args ) {
  1564. int err;
  1565. // if OpenGL isn't started, do nothing
  1566. if ( !glConfig.isInitialized ) {
  1567. return;
  1568. }
  1569. bool full = true;
  1570. bool forceWindow = false;
  1571. for ( int i = 1 ; i < args.Argc() ; i++ ) {
  1572. if ( idStr::Icmp( args.Argv( i ), "partial" ) == 0 ) {
  1573. full = false;
  1574. continue;
  1575. }
  1576. if ( idStr::Icmp( args.Argv( i ), "windowed" ) == 0 ) {
  1577. forceWindow = true;
  1578. continue;
  1579. }
  1580. }
  1581. // this could take a while, so give them the cursor back ASAP
  1582. Sys_GrabMouseCursor( false );
  1583. // dump ambient caches
  1584. renderModelManager->FreeModelVertexCaches();
  1585. // free any current world interaction surfaces and vertex caches
  1586. R_FreeDerivedData();
  1587. // make sure the defered frees are actually freed
  1588. R_ToggleSmpFrame();
  1589. R_ToggleSmpFrame();
  1590. // free the vertex caches so they will be regenerated again
  1591. vertexCache.PurgeAll();
  1592. // sound and input are tied to the window we are about to destroy
  1593. if ( full ) {
  1594. // free all of our texture numbers
  1595. soundSystem->ShutdownHW();
  1596. Sys_ShutdownInput();
  1597. globalImages->PurgeAllImages();
  1598. // free the context and close the window
  1599. GLimp_Shutdown();
  1600. glConfig.isInitialized = false;
  1601. // create the new context and vertex cache
  1602. bool latch = cvarSystem->GetCVarBool( "r_fullscreen" );
  1603. if ( forceWindow ) {
  1604. cvarSystem->SetCVarBool( "r_fullscreen", false );
  1605. }
  1606. R_InitOpenGL();
  1607. cvarSystem->SetCVarBool( "r_fullscreen", latch );
  1608. // regenerate all images
  1609. globalImages->ReloadAllImages();
  1610. } else {
  1611. glimpParms_t parms;
  1612. parms.width = glConfig.vidWidth;
  1613. parms.height = glConfig.vidHeight;
  1614. parms.fullScreen = ( forceWindow ) ? false : r_fullscreen.GetBool();
  1615. parms.displayHz = r_displayRefresh.GetInteger();
  1616. parms.multiSamples = r_multiSamples.GetInteger();
  1617. parms.stereo = false;
  1618. GLimp_SetScreenParms( parms );
  1619. }
  1620. // make sure the regeneration doesn't use anything no longer valid
  1621. tr.viewCount++;
  1622. tr.viewDef = NULL;
  1623. // regenerate all necessary interactions
  1624. R_RegenerateWorld_f( idCmdArgs() );
  1625. // check for problems
  1626. err = qglGetError();
  1627. if ( err != GL_NO_ERROR ) {
  1628. common->Printf( "glGetError() = 0x%x\n", err );
  1629. }
  1630. // start sound playing again
  1631. soundSystem->SetMute( false );
  1632. }
  1633. /*
  1634. =================
  1635. R_InitMaterials
  1636. =================
  1637. */
  1638. void R_InitMaterials( void ) {
  1639. tr.defaultMaterial = declManager->FindMaterial( "_default", false );
  1640. if ( !tr.defaultMaterial ) {
  1641. common->FatalError( "_default material not found" );
  1642. }
  1643. declManager->FindMaterial( "_default", false );
  1644. // needed by R_DeriveLightData
  1645. declManager->FindMaterial( "lights/defaultPointLight" );
  1646. declManager->FindMaterial( "lights/defaultProjectedLight" );
  1647. }
  1648. /*
  1649. =================
  1650. R_SizeUp_f
  1651. Keybinding command
  1652. =================
  1653. */
  1654. static void R_SizeUp_f( const idCmdArgs &args ) {
  1655. if ( r_screenFraction.GetInteger() + 10 > 100 ) {
  1656. r_screenFraction.SetInteger( 100 );
  1657. } else {
  1658. r_screenFraction.SetInteger( r_screenFraction.GetInteger() + 10 );
  1659. }
  1660. }
  1661. /*
  1662. =================
  1663. R_SizeDown_f
  1664. Keybinding command
  1665. =================
  1666. */
  1667. static void R_SizeDown_f( const idCmdArgs &args ) {
  1668. if ( r_screenFraction.GetInteger() - 10 < 10 ) {
  1669. r_screenFraction.SetInteger( 10 );
  1670. } else {
  1671. r_screenFraction.SetInteger( r_screenFraction.GetInteger() - 10 );
  1672. }
  1673. }
  1674. /*
  1675. ===============
  1676. TouchGui_f
  1677. this is called from the main thread
  1678. ===============
  1679. */
  1680. void R_TouchGui_f( const idCmdArgs &args ) {
  1681. const char *gui = args.Argv( 1 );
  1682. if ( !gui[0] ) {
  1683. common->Printf( "USAGE: touchGui <guiName>\n" );
  1684. return;
  1685. }
  1686. common->Printf( "touchGui %s\n", gui );
  1687. session->UpdateScreen();
  1688. uiManager->Touch( gui );
  1689. }
  1690. /*
  1691. =================
  1692. R_InitCvars
  1693. =================
  1694. */
  1695. void R_InitCvars( void ) {
  1696. // update latched cvars here
  1697. }
  1698. /*
  1699. =================
  1700. R_InitCommands
  1701. =================
  1702. */
  1703. void R_InitCommands( void ) {
  1704. cmdSystem->AddCommand( "MakeMegaTexture", idMegaTexture::MakeMegaTexture_f, CMD_FL_RENDERER|CMD_FL_CHEAT, "processes giant images" );
  1705. cmdSystem->AddCommand( "sizeUp", R_SizeUp_f, CMD_FL_RENDERER, "makes the rendered view larger" );
  1706. cmdSystem->AddCommand( "sizeDown", R_SizeDown_f, CMD_FL_RENDERER, "makes the rendered view smaller" );
  1707. cmdSystem->AddCommand( "reloadGuis", R_ReloadGuis_f, CMD_FL_RENDERER, "reloads guis" );
  1708. cmdSystem->AddCommand( "listGuis", R_ListGuis_f, CMD_FL_RENDERER, "lists guis" );
  1709. cmdSystem->AddCommand( "touchGui", R_TouchGui_f, CMD_FL_RENDERER, "touches a gui" );
  1710. cmdSystem->AddCommand( "screenshot", R_ScreenShot_f, CMD_FL_RENDERER, "takes a screenshot" );
  1711. cmdSystem->AddCommand( "envshot", R_EnvShot_f, CMD_FL_RENDERER, "takes an environment shot" );
  1712. cmdSystem->AddCommand( "makeAmbientMap", R_MakeAmbientMap_f, CMD_FL_RENDERER|CMD_FL_CHEAT, "makes an ambient map" );
  1713. cmdSystem->AddCommand( "benchmark", R_Benchmark_f, CMD_FL_RENDERER, "benchmark" );
  1714. cmdSystem->AddCommand( "gfxInfo", GfxInfo_f, CMD_FL_RENDERER, "show graphics info" );
  1715. cmdSystem->AddCommand( "modulateLights", R_ModulateLights_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "modifies shader parms on all lights" );
  1716. cmdSystem->AddCommand( "testImage", R_TestImage_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "displays the given image centered on screen", idCmdSystem::ArgCompletion_ImageName );
  1717. cmdSystem->AddCommand( "testVideo", R_TestVideo_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "displays the given cinematic", idCmdSystem::ArgCompletion_VideoName );
  1718. cmdSystem->AddCommand( "reportSurfaceAreas", R_ReportSurfaceAreas_f, CMD_FL_RENDERER, "lists all used materials sorted by surface area" );
  1719. cmdSystem->AddCommand( "reportImageDuplication", R_ReportImageDuplication_f, CMD_FL_RENDERER, "checks all referenced images for duplications" );
  1720. cmdSystem->AddCommand( "regenerateWorld", R_RegenerateWorld_f, CMD_FL_RENDERER, "regenerates all interactions" );
  1721. cmdSystem->AddCommand( "showInteractionMemory", R_ShowInteractionMemory_f, CMD_FL_RENDERER, "shows memory used by interactions" );
  1722. cmdSystem->AddCommand( "showTriSurfMemory", R_ShowTriSurfMemory_f, CMD_FL_RENDERER, "shows memory used by triangle surfaces" );
  1723. cmdSystem->AddCommand( "vid_restart", R_VidRestart_f, CMD_FL_RENDERER, "restarts renderSystem" );
  1724. cmdSystem->AddCommand( "listRenderEntityDefs", R_ListRenderEntityDefs_f, CMD_FL_RENDERER, "lists the entity defs" );
  1725. cmdSystem->AddCommand( "listRenderLightDefs", R_ListRenderLightDefs_f, CMD_FL_RENDERER, "lists the light defs" );
  1726. cmdSystem->AddCommand( "listModes", R_ListModes_f, CMD_FL_RENDERER, "lists all video modes" );
  1727. cmdSystem->AddCommand( "reloadSurface", R_ReloadSurface_f, CMD_FL_RENDERER, "reloads the decl and images for selected surface" );
  1728. }
  1729. /*
  1730. ===============
  1731. idRenderSystemLocal::Clear
  1732. ===============
  1733. */
  1734. void idRenderSystemLocal::Clear( void ) {
  1735. registered = false;
  1736. frameCount = 0;
  1737. viewCount = 0;
  1738. staticAllocCount = 0;
  1739. frameShaderTime = 0.0f;
  1740. viewportOffset[0] = 0;
  1741. viewportOffset[1] = 0;
  1742. tiledViewport[0] = 0;
  1743. tiledViewport[1] = 0;
  1744. backEndRenderer = BE_BAD;
  1745. backEndRendererHasVertexPrograms = false;
  1746. backEndRendererMaxLight = 1.0f;
  1747. ambientLightVector.Zero();
  1748. sortOffset = 0;
  1749. worlds.Clear();
  1750. primaryWorld = NULL;
  1751. memset( &primaryRenderView, 0, sizeof( primaryRenderView ) );
  1752. primaryView = NULL;
  1753. defaultMaterial = NULL;
  1754. testImage = NULL;
  1755. ambientCubeImage = NULL;
  1756. viewDef = NULL;
  1757. memset( &pc, 0, sizeof( pc ) );
  1758. memset( &lockSurfacesCmd, 0, sizeof( lockSurfacesCmd ) );
  1759. memset( &identitySpace, 0, sizeof( identitySpace ) );
  1760. logFile = NULL;
  1761. stencilIncr = 0;
  1762. stencilDecr = 0;
  1763. memset( renderCrops, 0, sizeof( renderCrops ) );
  1764. currentRenderCrop = 0;
  1765. guiRecursionLevel = 0;
  1766. guiModel = NULL;
  1767. demoGuiModel = NULL;
  1768. memset( gammaTable, 0, sizeof( gammaTable ) );
  1769. takingScreenshot = false;
  1770. }
  1771. /*
  1772. ===============
  1773. idRenderSystemLocal::Init
  1774. ===============
  1775. */
  1776. void idRenderSystemLocal::Init( void ) {
  1777. common->Printf( "------- Initializing renderSystem --------\n" );
  1778. // clear all our internal state
  1779. viewCount = 1; // so cleared structures never match viewCount
  1780. // we used to memset tr, but now that it is a class, we can't, so
  1781. // there may be other state we need to reset
  1782. ambientLightVector[0] = 0.5f;
  1783. ambientLightVector[1] = 0.5f - 0.385f;
  1784. ambientLightVector[2] = 0.8925f;
  1785. ambientLightVector[3] = 1.0f;
  1786. memset( &backEnd, 0, sizeof( backEnd ) );
  1787. R_InitCvars();
  1788. R_InitCommands();
  1789. guiModel = new idGuiModel;
  1790. guiModel->Clear();
  1791. demoGuiModel = new idGuiModel;
  1792. demoGuiModel->Clear();
  1793. R_InitTriSurfData();
  1794. globalImages->Init();
  1795. idCinematic::InitCinematic( );
  1796. // build brightness translation tables
  1797. R_SetColorMappings();
  1798. R_InitMaterials();
  1799. renderModelManager->Init();
  1800. // set the identity space
  1801. identitySpace.modelMatrix[0*4+0] = 1.0f;
  1802. identitySpace.modelMatrix[1*4+1] = 1.0f;
  1803. identitySpace.modelMatrix[2*4+2] = 1.0f;
  1804. // determine which back end we will use
  1805. // ??? this is invalid here as there is not enough information to set it up correctly
  1806. SetBackEndRenderer();
  1807. common->Printf( "renderSystem initialized.\n" );
  1808. common->Printf( "--------------------------------------\n" );
  1809. }
  1810. /*
  1811. ===============
  1812. idRenderSystemLocal::Shutdown
  1813. ===============
  1814. */
  1815. void idRenderSystemLocal::Shutdown( void ) {
  1816. common->Printf( "idRenderSystem::Shutdown()\n" );
  1817. R_DoneFreeType( );
  1818. if ( glConfig.isInitialized ) {
  1819. globalImages->PurgeAllImages();
  1820. }
  1821. renderModelManager->Shutdown();
  1822. idCinematic::ShutdownCinematic( );
  1823. globalImages->Shutdown();
  1824. // close the r_logFile
  1825. if ( logFile ) {
  1826. fprintf( logFile, "*** CLOSING LOG ***\n" );
  1827. fclose( logFile );
  1828. logFile = 0;
  1829. }
  1830. // free frame memory
  1831. R_ShutdownFrameData();
  1832. // free the vertex cache, which should have nothing allocated now
  1833. vertexCache.Shutdown();
  1834. R_ShutdownTriSurfData();
  1835. RB_ShutdownDebugTools();
  1836. delete guiModel;
  1837. delete demoGuiModel;
  1838. Clear();
  1839. ShutdownOpenGL();
  1840. }
  1841. /*
  1842. ========================
  1843. idRenderSystemLocal::BeginLevelLoad
  1844. ========================
  1845. */
  1846. void idRenderSystemLocal::BeginLevelLoad( void ) {
  1847. renderModelManager->BeginLevelLoad();
  1848. globalImages->BeginLevelLoad();
  1849. }
  1850. /*
  1851. ========================
  1852. idRenderSystemLocal::EndLevelLoad
  1853. ========================
  1854. */
  1855. void idRenderSystemLocal::EndLevelLoad( void ) {
  1856. renderModelManager->EndLevelLoad();
  1857. globalImages->EndLevelLoad();
  1858. if ( r_forceLoadImages.GetBool() ) {
  1859. RB_ShowImages();
  1860. }
  1861. }
  1862. /*
  1863. ========================
  1864. idRenderSystemLocal::InitOpenGL
  1865. ========================
  1866. */
  1867. void idRenderSystemLocal::InitOpenGL( void ) {
  1868. // if OpenGL isn't started, start it now
  1869. if ( !glConfig.isInitialized ) {
  1870. int err;
  1871. R_InitOpenGL();
  1872. globalImages->ReloadAllImages();
  1873. err = qglGetError();
  1874. if ( err != GL_NO_ERROR ) {
  1875. common->Printf( "glGetError() = 0x%x\n", err );
  1876. }
  1877. }
  1878. }
  1879. /*
  1880. ========================
  1881. idRenderSystemLocal::ShutdownOpenGL
  1882. ========================
  1883. */
  1884. void idRenderSystemLocal::ShutdownOpenGL( void ) {
  1885. // free the context and close the window
  1886. R_ShutdownFrameData();
  1887. GLimp_Shutdown();
  1888. glConfig.isInitialized = false;
  1889. }
  1890. /*
  1891. ========================
  1892. idRenderSystemLocal::IsOpenGLRunning
  1893. ========================
  1894. */
  1895. bool idRenderSystemLocal::IsOpenGLRunning( void ) const {
  1896. if ( !glConfig.isInitialized ) {
  1897. return false;
  1898. }
  1899. return true;
  1900. }
  1901. /*
  1902. ========================
  1903. idRenderSystemLocal::IsFullScreen
  1904. ========================
  1905. */
  1906. bool idRenderSystemLocal::IsFullScreen( void ) const {
  1907. return glConfig.isFullscreen;
  1908. }
  1909. /*
  1910. ========================
  1911. idRenderSystemLocal::GetScreenWidth
  1912. ========================
  1913. */
  1914. int idRenderSystemLocal::GetScreenWidth( void ) const {
  1915. return glConfig.vidWidth;
  1916. }
  1917. /*
  1918. ========================
  1919. idRenderSystemLocal::GetScreenHeight
  1920. ========================
  1921. */
  1922. int idRenderSystemLocal::GetScreenHeight( void ) const {
  1923. return glConfig.vidHeight;
  1924. }
  1925. /*
  1926. ========================
  1927. idRenderSystemLocal::GetCardCaps
  1928. ========================
  1929. */
  1930. void idRenderSystemLocal::GetCardCaps( bool &oldCard, bool &nv10or20 ) {
  1931. nv10or20 = ( tr.backEndRenderer == BE_NV10 || tr.backEndRenderer == BE_NV20 );
  1932. oldCard = ( tr.backEndRenderer == BE_ARB || tr.backEndRenderer == BE_R200 || tr.backEndRenderer == BE_NV10 || tr.backEndRenderer == BE_NV20 );
  1933. }