ww3d.cpp 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program 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. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/ww3d.cpp $*
  25. * *
  26. * Org Author:: Greg_h *
  27. * *
  28. * Author : Kenny Mitchell *
  29. * *
  30. * $Modtime:: 08/05/02 10:03a $*
  31. * *
  32. * $Revision:: 98 $*
  33. * *
  34. * 07/01/02 KM Scalable shader library integration *
  35. * 08/05/02 KM Texture class redesign
  36. *---------------------------------------------------------------------------------------------*
  37. * Functions: *
  38. * WW3D::Init -- Initialize the WW3D Library *
  39. * WW3D::Shutdown -- shutdown the WW3D Library *
  40. * WW3D::Set_Render_Device -- set the render device being currently used *
  41. * WW3D::Set_Next_Render_Device -- just go to the next device in the list *
  42. * WW3D::Set_Device_Resolution -- set the current resolution and bitdepth *
  43. * WW3D::Get_Render_Device -- Get the index of the current render device *
  44. * WW3D::Get_Render_Device_Desc -- returns description of the current render device *
  45. * WW3D::Get_Render_Device_Count -- returns the number of render devices available *
  46. * WW3D::Get_Render_Device_Name -- returns the name of the n-th render device *
  47. * WW3D::Get_Render_Target_Resolution -- get the resolution and bitdepth of the current target*
  48. * WW3D::Get_Device_Resolution -- get the current resolution and bitdepth *
  49. * WW3D::Begin_Render -- mark the start of rendering for a new frame *
  50. * WW3D::Render -- Render a 3D Scene using the given camera *
  51. * WW3D::Render -- Render a single render object *
  52. * WW3D::End_Render -- Mark the completion of a frame *
  53. * WW3D::Sync -- Time sychronization *
  54. * WW3D::Set_Ext_Swap_Interval -- Sets the swap interval the device should aim sync for. *
  55. * WW3D::Get_Ext_Swap_Interval -- Queries the swap interval the device is aiming sync for. *
  56. * WW3D::Get_Polygon_Mode -- returns the current rendering mode *
  57. * WW3D::Set_Collision_Box_Display_Mask -- control rendering of collision boxes *
  58. * WW3D::Get_Collision_Box_Display_Mask -- returns the current display mask for collision bo *
  59. * WW3D::Normalize_Coordinates -- Convert pixel coords to normalized screen coords 0..1 *
  60. * WW3D::Update_Render_Device_Description -- updates the description of the current render d *
  61. * WW3D::Make_Screen_Shot -- saves a screenshot with the given base filename *
  62. * WW3D::Start_Movie_Capture -- begins dumping frames to a movie *
  63. * WW3D::Stop_Movie_Capture -- ends dumping frames to a movie *
  64. * WW3D::Toggle_Movie_Capture -- toggles movie capture... *
  65. * WW3D::Start_Single_Frame_Movie_Capture -- starts capturing a single frame movie *
  66. * WW3D::Capture_Next_Movie_Frame -- tells ww3d to grab another frame for the movie *
  67. * WW3D::Pause_Movie -- pauses/unpauses movie capturing *
  68. * WW3D::Is_Movie_Paused -- returns whether the movie capture system is paused *
  69. * WW3D::Is_Recording_Next_Frame -- returns whether the next frame will be dumped to a movie *
  70. * WW3D::Is_Movie_Ready -- returns whether the movie capture system is ready *
  71. * WW3D::Update_Movie_Capture -- dumps the current frame into the movie *
  72. * WW3D::Get_Movie_Capture_Frame_Rate -- returns the framerate at which the movie is being c *
  73. * WW3D::Set_Texture_Reduction -- sets the (hacky) texture reduction factor *
  74. * WW3D::Get_Texture_Reduction -- gets the (hacky) texture reduction factor *
  75. * WW3D::Flush_Texture_Cache -- dump all textures from the texture cache *
  76. * WW3D::Allocate_Debug_Resources -- allocates the debug resources *
  77. * WW3D::Release_Debug_Resources -- releases the debug resources *
  78. * WW3D::Get_Last_Frame_Poly_Count -- returns the number of polys submitted in the previous *
  79. * WW3D::Flush -- Process all pending rendering tasks *
  80. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  81. #include "ww3d.h"
  82. #include "rinfo.h"
  83. #include "assetmgr.h"
  84. #include "boxrobj.h"
  85. #include "predlod.h"
  86. #include "camera.h"
  87. #include "scene.h"
  88. #include "texfcach.h"
  89. #include "registry.h"
  90. #include "segline.h"
  91. #include "shader.h"
  92. #include "vertmaterial.h"
  93. #include "wwdebug.h"
  94. #include "wwprofile.h"
  95. #include "wwmemlog.h"
  96. #include "shattersystem.h"
  97. #include "textureloader.h"
  98. #include "statistics.h"
  99. #include "pointgr.h"
  100. #include "ffactory.h"
  101. #include "ini.h"
  102. #include "dazzle.h"
  103. #include "meshmdl.h"
  104. #include "dx8renderer.h"
  105. #include "render2d.h"
  106. #include "bound.h"
  107. #include "rddesc.h"
  108. #include "vector3i.h"
  109. #include <cstdio>
  110. #include "dx8wrapper.h"
  111. #include "targa.h"
  112. #include "sortingrenderer.h"
  113. #include "thread.h"
  114. #include "cpudetect.h"
  115. #include "dx8texman.h"
  116. #include "formconv.h"
  117. #include "animatedsoundmgr.h"
  118. #include "static_sort_list.h"
  119. #include "shdlib.h"
  120. #ifndef _UNIX
  121. #include "framgrab.h"
  122. #endif
  123. const char* DAZZLE_INI_FILENAME="DAZZLE.INI";
  124. #define DEFAULT_DEBUG_SHADER_BITS ( SHADE_CNST(\
  125. ShaderClass::PASS_LEQUAL,\
  126. ShaderClass::DEPTH_WRITE_ENABLE,\
  127. ShaderClass::COLOR_WRITE_ENABLE,\
  128. ShaderClass::SRCBLEND_ONE,\
  129. ShaderClass::DSTBLEND_ZERO,\
  130. ShaderClass::FOG_DISABLE,\
  131. ShaderClass::GRADIENT_MODULATE,\
  132. ShaderClass::SECONDARY_GRADIENT_DISABLE,\
  133. ShaderClass::TEXTURING_DISABLE,\
  134. ShaderClass::ALPHATEST_DISABLE,\
  135. ShaderClass::CULL_MODE_ENABLE, \
  136. ShaderClass::DETAILCOLOR_DISABLE,\
  137. ShaderClass::DETAILALPHA_DISABLE) )
  138. #define LIGHTMAP_DEBUG_SHADER_BITS ( SHADE_CNST(\
  139. ShaderClass::PASS_LEQUAL,\
  140. ShaderClass::DEPTH_WRITE_ENABLE,\
  141. ShaderClass::COLOR_WRITE_ENABLE,\
  142. ShaderClass::SRCBLEND_ONE,\
  143. ShaderClass::DSTBLEND_ZERO,\
  144. ShaderClass::FOG_DISABLE,\
  145. ShaderClass::GRADIENT_DISABLE,\
  146. ShaderClass::SECONDARY_GRADIENT_DISABLE,\
  147. ShaderClass::TEXTURING_ENABLE,\
  148. ShaderClass::ALPHATEST_DISABLE,\
  149. ShaderClass::CULL_MODE_ENABLE, \
  150. ShaderClass::DETAILCOLOR_DISABLE,\
  151. ShaderClass::DETAILALPHA_DISABLE) )
  152. /**********************************************************************************
  153. **
  154. ** WW3D Static Globals
  155. **
  156. ***********************************************************************************/
  157. unsigned int WW3D::SyncTime = 0;
  158. unsigned int WW3D::PreviousSyncTime = 0;
  159. bool WW3D::IsSortingEnabled = true;
  160. float WW3D::PixelCenterX = 0.0f;
  161. float WW3D::PixelCenterY = 0.0f;
  162. bool WW3D::IsInitted = false;
  163. bool WW3D::IsRendering = false;
  164. bool WW3D::IsCapturing = false;
  165. bool WW3D::IsScreenUVBiased = false;
  166. bool WW3D::AreDecalsEnabled = true;
  167. float WW3D::DecalRejectionDistance = 1000000.0f;
  168. bool WW3D::AreStaticSortListsEnabled = false;
  169. bool WW3D::MungeSortOnLoad = false;
  170. bool WW3D::OverbrightModifyOnLoad = false;
  171. FrameGrabClass * WW3D::Movie = NULL;
  172. bool WW3D::PauseRecord;
  173. bool WW3D::RecordNextFrame;
  174. int WW3D::FrameCount = 0;
  175. long WW3D::UserStat0 = 0;
  176. long WW3D::UserStat1 = 0;
  177. long WW3D::UserStat2 = 0;
  178. float WW3D::DefaultNativeScreenSize = 1.0f;
  179. StaticSortListClass * WW3D::DefaultStaticSortLists = NULL;
  180. StaticSortListClass * WW3D::CurrentStaticSortLists = NULL;
  181. VertexMaterialClass * WW3D::DefaultDebugMaterial = NULL;
  182. ShaderClass WW3D::DefaultDebugShader(DEFAULT_DEBUG_SHADER_BITS);
  183. ShaderClass WW3D::LightmapDebugShader(LIGHTMAP_DEBUG_SHADER_BITS);
  184. WW3D::PrelitModeEnum WW3D::PrelitMode = PRELIT_MODE_LIGHTMAP_MULTI_PASS;
  185. bool WW3D::ExposePrelit = false;
  186. bool WW3D::SnapshotActivated=false;
  187. bool WW3D::ThumbnailEnabled=true;
  188. WW3D::MeshDrawModeEnum WW3D::MeshDrawMode = MESH_DRAW_MODE_OLD;
  189. WW3D::NPatchesGapFillingModeEnum WW3D::NPatchesGapFillingMode = NPATCHES_GAP_FILLING_ENABLED;
  190. unsigned WW3D::NPatchesLevel=1;
  191. bool WW3D::IsTexturingEnabled=true;
  192. bool WW3D::IsColoringEnabled=false;
  193. static HWND _Hwnd = NULL; // Not a member to hide windows from WW3D users
  194. static int _TextureReduction = 0;
  195. static int _TextureMinDim = 1;
  196. static bool _LargeTextureExtraReductionEnabled = false;
  197. int WW3D::LastFrameMemoryAllocations;
  198. int WW3D::LastFrameMemoryFrees;
  199. int WW3D::TextureFilter = 0;
  200. bool WW3D::Lite = false;
  201. /**********************************************************************************
  202. **
  203. ** WW3D Static Functions
  204. **
  205. ***********************************************************************************/
  206. void WW3D::Set_NPatches_Gap_Filling_Mode(NPatchesGapFillingModeEnum mode)
  207. {
  208. if (NPatchesGapFillingMode!=mode) {
  209. NPatchesGapFillingMode=mode;
  210. TheDX8MeshRenderer.Invalidate();
  211. }
  212. }
  213. void WW3D::Set_NPatches_Level(unsigned level)
  214. {
  215. if (level>8) level=8;
  216. if (level<1) level=1;
  217. if (NPatchesLevel==1 && level>1) TheDX8MeshRenderer.Invalidate();
  218. if (NPatchesLevel>1 && level==1) TheDX8MeshRenderer.Invalidate();
  219. NPatchesLevel = level;
  220. }
  221. /***********************************************************************************************
  222. * WW3D::Init -- Initialize the WW3D Library *
  223. * *
  224. * INPUT: *
  225. * *
  226. * OUTPUT: *
  227. * *
  228. * WARNINGS: *
  229. * *
  230. * HISTORY: *
  231. * 3/24/98 GTH : Created. *
  232. *=============================================================================================*/
  233. WW3DErrorType WW3D::Init(void *hwnd, char *defaultpal, bool lite)
  234. {
  235. assert(IsInitted == false);
  236. WWDEBUG_SAY(("WW3D::Init hwnd = %p\n",hwnd));
  237. _Hwnd = (HWND)hwnd;
  238. Lite = lite;
  239. /*
  240. ** Initialize d3d, this also enumerates the available devices and resolutions.
  241. */
  242. Init_D3D_To_WW3_Conversion();
  243. WWDEBUG_SAY(("Init DX8Wrapper\n"));
  244. if (!DX8Wrapper::Init(_Hwnd, lite)) {
  245. return(WW3D_ERROR_INITIALIZATION_FAILED);
  246. }
  247. WWDEBUG_SAY(("Allocate Debug Resources\n"));
  248. Allocate_Debug_Resources();
  249. MMRESULT r=timeBeginPeriod(1);
  250. WWASSERT(r==TIMERR_NOERROR);
  251. /*
  252. ** Initialize the dazzle system
  253. */
  254. if (!lite) {
  255. WWDEBUG_SAY(("Init Dazzles\n"));
  256. FileClass * dazzle_ini_file = _TheFileFactory->Get_File(DAZZLE_INI_FILENAME);
  257. if (dazzle_ini_file) {
  258. INIClass dazzle_ini(*dazzle_ini_file);
  259. DazzleRenderObjClass::Init_From_INI(&dazzle_ini);
  260. _TheFileFactory->Return_File(dazzle_ini_file);
  261. }
  262. }
  263. /*
  264. ** Initialize the default static sort lists
  265. ** Note that DefaultStaticSortLists[0] is unused.
  266. */
  267. DefaultStaticSortLists = W3DNEW DefaultStaticSortListClass();
  268. Reset_Current_Static_Sort_Lists_To_Default();
  269. /*
  270. ** Initialize the animation-triggered sound system
  271. */
  272. if (!lite) {
  273. AnimatedSoundMgrClass::Initialize ();
  274. IsInitted = true;
  275. }
  276. WWDEBUG_SAY(("WW3D Init completed\n"));
  277. return WW3D_ERROR_OK;
  278. }
  279. /***********************************************************************************************
  280. * WW3D::Shutdown -- shutdown the WW3D Library *
  281. * *
  282. * INPUT: *
  283. * *
  284. * OUTPUT: *
  285. * *
  286. * WARNINGS: *
  287. * *
  288. * HISTORY: *
  289. * 3/24/98 GTH : Created. *
  290. *=============================================================================================*/
  291. WW3DErrorType WW3D::Shutdown(void)
  292. {
  293. assert(Lite || IsInitted == true);
  294. // WWDEBUG_SAY(("WW3D::Shutdown\n"));
  295. #ifdef WW3D_DX8
  296. if (IsCapturing) {
  297. Stop_Movie_Capture();
  298. }
  299. #endif //WW3D_DX8
  300. //restore the previous timer resolution
  301. MMRESULT r=timeEndPeriod(1);
  302. WWASSERT(r==TIMERR_NOERROR);
  303. /*
  304. ** Free memory in predictive LOD optimizer
  305. */
  306. PredictiveLODOptimizerClass::Free();
  307. /*
  308. ** Free the DazzleRenderObject class stuff. Whatever it is. ST - 6/11/2001 8:20PM
  309. */
  310. if (!Lite) {
  311. DazzleRenderObjClass::Deinit ();
  312. }
  313. /*
  314. ** Release all of our assets
  315. */
  316. Release_Debug_Resources();
  317. if (WW3DAssetManager::Get_Instance()) {
  318. WW3DAssetManager::Get_Instance()->Free_Assets();
  319. }
  320. DX8TextureManagerClass::Shutdown();
  321. if (!Lite) {
  322. DX8Wrapper::Shutdown();
  323. }
  324. /*
  325. ** Clear the default static sort lists
  326. */
  327. delete DefaultStaticSortLists;
  328. /*
  329. ** Release the animation-triggered sound data
  330. */
  331. AnimatedSoundMgrClass::Shutdown ();
  332. IsInitted = false;
  333. return WW3D_ERROR_OK;
  334. }
  335. /***********************************************************************************************
  336. * WW3D::Set_Render_Device -- set the render device being currently used *
  337. * *
  338. * INPUT: *
  339. * *
  340. * OUTPUT: *
  341. * *
  342. * WARNINGS: *
  343. * *
  344. * HISTORY: *
  345. * 3/24/98 GTH : Created. *
  346. *=============================================================================================*/
  347. WW3DErrorType WW3D::Set_Render_Device( const char * dev_name, int width, int height, int bits, int windowed, bool resize_window )
  348. {
  349. bool success = DX8Wrapper::Set_Render_Device(dev_name,width,height,bits,windowed,resize_window);
  350. if (success) {
  351. return WW3D_ERROR_OK;
  352. } else {
  353. return WW3D_ERROR_INITIALIZATION_FAILED;
  354. }
  355. }
  356. /***********************************************************************************************
  357. * WW3D::Set_Any_Render_Device -- set any render device you can find *
  358. * *
  359. * INPUT: *
  360. * *
  361. * OUTPUT: *
  362. * *
  363. * WARNINGS: *
  364. * *
  365. * HISTORY: *
  366. * 3/24/98 GTH : Created. *
  367. *=============================================================================================*/
  368. WW3DErrorType WW3D::Set_Any_Render_Device( void )
  369. {
  370. bool success = DX8Wrapper::Set_Any_Render_Device();
  371. if (success) {
  372. return WW3D_ERROR_OK;
  373. } else {
  374. return WW3D_ERROR_INITIALIZATION_FAILED;
  375. }
  376. }
  377. /***********************************************************************************************
  378. * WW3D::Set_Render_Device -- set the render device being currently used *
  379. * *
  380. * INPUT: *
  381. * *
  382. * OUTPUT: *
  383. * *
  384. * WARNINGS: *
  385. * *
  386. * HISTORY: *
  387. * 3/24/98 GTH : Created. *
  388. *=============================================================================================*/
  389. WW3DErrorType WW3D::Set_Render_Device(int dev, int width, int height, int bits, int windowed, bool resize_window, bool reset_device, bool restore_assets )
  390. {
  391. bool success = DX8Wrapper::Set_Render_Device(dev,width,height,bits,windowed,resize_window,reset_device, restore_assets );
  392. if (success) {
  393. return WW3D_ERROR_OK;
  394. } else {
  395. return WW3D_ERROR_INITIALIZATION_FAILED;
  396. }
  397. }
  398. /***********************************************************************************************
  399. * WW3D::Set_Next_Render_Device -- just go to the next device in the list *
  400. * *
  401. * INPUT: *
  402. * *
  403. * OUTPUT: *
  404. * *
  405. * WARNINGS: *
  406. * *
  407. * HISTORY: *
  408. * 3/26/98 GTH : Created. *
  409. *=============================================================================================*/
  410. WW3DErrorType WW3D::Set_Next_Render_Device(void)
  411. {
  412. bool success = DX8Wrapper::Set_Next_Render_Device();
  413. if (success) {
  414. return WW3D_ERROR_OK;
  415. } else {
  416. return WW3D_ERROR_INITIALIZATION_FAILED;
  417. }
  418. }
  419. /***********************************************************************************************
  420. * WW3D::Get_Window -- returns the handle of the render window. *
  421. * *
  422. * INPUT: *
  423. * *
  424. * OUTPUT: *
  425. * *
  426. * WARNINGS: *
  427. * *
  428. * HISTORY: *
  429. * 3/28/2001 pds : Created. *
  430. *=============================================================================================*/
  431. void *WW3D::Get_Window( void )
  432. {
  433. return _Hwnd;
  434. }
  435. /***********************************************************************************************
  436. * WW3D::Is_Windowed -- returns wether we are currently in a windowed mode *
  437. * *
  438. * INPUT: *
  439. * *
  440. * OUTPUT: *
  441. * *
  442. * WARNINGS: *
  443. * *
  444. * HISTORY: *
  445. * 1/26/2001 gth : Created. *
  446. *=============================================================================================*/
  447. bool WW3D::Is_Windowed( void )
  448. {
  449. return DX8Wrapper::Is_Windowed();
  450. }
  451. /***********************************************************************************************
  452. * WW3D::Toggle_Windowed -- Toggle the current render device between fullscreen and windowed *
  453. * mode. Note: Its called '_Windowed' to be consistent with the *
  454. * other references inside WW3D, a more descriptive name would *
  455. * be Toggle_Fullscreen. *
  456. * *
  457. * INPUT: *
  458. * *
  459. * OUTPUT: *
  460. * *
  461. * WARNINGS: *
  462. * *
  463. * HISTORY: *
  464. * 1/11/99 PDS : Created. *
  465. *=============================================================================================*/
  466. WW3DErrorType WW3D::Toggle_Windowed (void)
  467. {
  468. bool success = DX8Wrapper::Toggle_Windowed();
  469. if (success) {
  470. return WW3D_ERROR_OK;
  471. } else {
  472. return WW3D_ERROR_INITIALIZATION_FAILED;
  473. }
  474. }
  475. /***********************************************************************************************
  476. * WW3D::Get_Render_Device -- Get the index of the current render device *
  477. * *
  478. * INPUT: *
  479. * *
  480. * OUTPUT: *
  481. * *
  482. * WARNINGS: *
  483. * *
  484. * HISTORY: *
  485. * 3/24/98 GTH : Created. *
  486. * 1/25/2001 gth : converted to dx8 *
  487. *=============================================================================================*/
  488. int WW3D::Get_Render_Device(void)
  489. {
  490. return DX8Wrapper::Get_Render_Device();
  491. }
  492. /***********************************************************************************************
  493. * WW3D::Get_Render_Device_Desc -- returns description of the current render device *
  494. * *
  495. * INPUT: *
  496. * *
  497. * OUTPUT: *
  498. * *
  499. * WARNINGS: *
  500. * *
  501. * HISTORY: *
  502. * 3/26/98 GTH : Created. *
  503. * 1/25/2001 gth : converted to dx8 *
  504. *=============================================================================================*/
  505. const RenderDeviceDescClass & WW3D::Get_Render_Device_Desc(int deviceidx)
  506. {
  507. return DX8Wrapper::Get_Render_Device_Desc(deviceidx);
  508. }
  509. /***********************************************************************************************
  510. * WW3D::Get_Render_Device_Count -- returns the number of render devices available *
  511. * *
  512. * INPUT: *
  513. * *
  514. * OUTPUT: *
  515. * *
  516. * WARNINGS: *
  517. * *
  518. * HISTORY: *
  519. * 5/19/99 GTH : Created. *
  520. * 1/25/2001 gth : converted to DX8 *
  521. *=============================================================================================*/
  522. const int WW3D::Get_Render_Device_Count(void)
  523. {
  524. return DX8Wrapper::Get_Render_Device_Count();
  525. }
  526. /***********************************************************************************************
  527. * WW3D::Get_Render_Device_Name -- returns the name of the n-th render device *
  528. * *
  529. * INPUT: *
  530. * *
  531. * OUTPUT: *
  532. * *
  533. * WARNINGS: *
  534. * *
  535. * HISTORY: *
  536. * 5/19/99 GTH : Created. *
  537. * 1/25/2001 gth : converted to dx8 *
  538. *=============================================================================================*/
  539. const char * WW3D::Get_Render_Device_Name(int device_index)
  540. {
  541. return DX8Wrapper::Get_Render_Device_Name(device_index);
  542. }
  543. /***********************************************************************************************
  544. * WW3D::Set_Device_Resolution -- set the current resolution and bitdepth *
  545. * *
  546. * INPUT: *
  547. * *
  548. * OUTPUT: *
  549. * *
  550. * WARNINGS: *
  551. * *
  552. * HISTORY: *
  553. * 3/24/98 GTH : Created. *
  554. *=============================================================================================*/
  555. WW3DErrorType WW3D::Set_Device_Resolution(int width,int height,int bits,int windowed, bool resize_window)
  556. {
  557. bool success = DX8Wrapper::Set_Device_Resolution(width,height,bits,windowed,resize_window);
  558. if (success) {
  559. return WW3D_ERROR_OK;
  560. } else {
  561. return WW3D_ERROR_INITIALIZATION_FAILED;
  562. }
  563. }
  564. /***********************************************************************************************
  565. * WW3D::Get_Render_Target_Resolution -- get the resolution and bitdepth of the current target *
  566. * *
  567. * INPUT: *
  568. * *
  569. * OUTPUT: *
  570. * *
  571. * WARNINGS: *
  572. * *
  573. * HISTORY: *
  574. * 3/24/98 GTH : Created. *
  575. * 1/25/2001 gth : converted to dx8 *
  576. *=============================================================================================*/
  577. void WW3D::Get_Render_Target_Resolution(int & set_w,int & set_h,int & set_bits,bool & set_windowed)
  578. {
  579. DX8Wrapper::Get_Render_Target_Resolution(set_w,set_h,set_bits,set_windowed);
  580. }
  581. /***********************************************************************************************
  582. * WW3D::Get_Device_Resolution -- get the current resolution and bitdepth *
  583. * *
  584. * INPUT: *
  585. * *
  586. * OUTPUT: *
  587. * *
  588. * WARNINGS: *
  589. * *
  590. * HISTORY: *
  591. * 3/24/98 GTH : Created. *
  592. * 1/25/2001 gth : converted to dx8 *
  593. *=============================================================================================*/
  594. void WW3D::Get_Device_Resolution(int & set_w,int & set_h,int & set_bits,bool & set_windowed)
  595. {
  596. DX8Wrapper::Get_Device_Resolution(set_w,set_h,set_bits,set_windowed);
  597. }
  598. /***********************************************************************************************
  599. * WW3D::Registry_Save_Render_Device -- Saves settings to Registry
  600. * *
  601. * INPUT: *
  602. * *
  603. * OUTPUT: *
  604. * *
  605. * WARNINGS: *
  606. * *
  607. * HISTORY: *
  608. * 12/3/98 BMG : Created. *
  609. * 1/25/2001 gth : converted to dx8 *
  610. *=============================================================================================*/
  611. WW3DErrorType WW3D::Registry_Save_Render_Device( const char * sub_key )
  612. {
  613. bool success = DX8Wrapper::Registry_Save_Render_Device(sub_key);
  614. if (success) {
  615. return WW3D_ERROR_OK;
  616. } else {
  617. return WW3D_ERROR_INITIALIZATION_FAILED;
  618. }
  619. }
  620. /***********************************************************************************************
  621. * WW3D::Registry_Save_Render_Device -- Saves settings to Registry
  622. * *
  623. * INPUT: *
  624. * *
  625. * OUTPUT: *
  626. * *
  627. * WARNINGS: *
  628. * *
  629. * HISTORY: *
  630. * 12/3/98 BMG : Created. *
  631. *=============================================================================================*/
  632. WW3DErrorType WW3D::Registry_Save_Render_Device( const char *sub_key, int device, int width, int height, int depth, bool windowed, int texture_depth )
  633. {
  634. bool success = DX8Wrapper::Registry_Save_Render_Device(sub_key,device,width,height,depth,windowed,texture_depth);
  635. if (success) {
  636. return WW3D_ERROR_OK;
  637. } else {
  638. return WW3D_ERROR_INITIALIZATION_FAILED;
  639. }
  640. }
  641. /***********************************************************************************************
  642. * WW3D::Registry_Load_Render_Device -- Loads settings from Registry
  643. * *
  644. * INPUT: *
  645. * *
  646. * OUTPUT: *
  647. * *
  648. * WARNINGS: *
  649. * *
  650. * HISTORY: *
  651. * 12/3/98 BMG : Created. *
  652. *=============================================================================================*/
  653. WW3DErrorType WW3D::Registry_Load_Render_Device( const char * sub_key, bool resize_window )
  654. {
  655. bool success = DX8Wrapper::Registry_Load_Render_Device(sub_key,resize_window);
  656. if (success) {
  657. return WW3D_ERROR_OK;
  658. } else {
  659. return WW3D_ERROR_INITIALIZATION_FAILED;
  660. }
  661. }
  662. bool WW3D::Registry_Load_Render_Device( const char * sub_key, char *device, int device_len, int &width, int &height, int &depth, int &windowed, int &texture_depth)
  663. {
  664. return DX8Wrapper::Registry_Load_Render_Device(sub_key,device,device_len,width,height,depth,windowed,texture_depth);
  665. }
  666. void WW3D::_Invalidate_Mesh_Cache()
  667. {
  668. TheDX8MeshRenderer.Invalidate();
  669. }
  670. void WW3D::_Invalidate_Textures()
  671. {
  672. if (!WW3DAssetManager::Get_Instance()) return;
  673. TextureLoader::Flush_Pending_Load_Tasks();
  674. HashTemplateIterator<StringClass,TextureClass*> ite(WW3DAssetManager::Get_Instance()->Texture_Hash());
  675. // Loop through all the textures in the manager
  676. for (ite.First();!ite.Is_Done();ite.Next()) {
  677. // Get the current texture
  678. TextureClass* tex=ite.Peek_Value();
  679. tex->Invalidate();
  680. }
  681. }
  682. void WW3D::Set_Texture_Filter(int texture_filter)
  683. {
  684. if (texture_filter<0) texture_filter=0;
  685. if (texture_filter>TextureFilterClass::TEXTURE_FILTER_ANISOTROPIC) texture_filter=TextureFilterClass::TEXTURE_FILTER_ANISOTROPIC;
  686. TextureFilter=texture_filter;
  687. TextureFilterClass::_Init_Filters((TextureFilterClass::TextureFilterMode)TextureFilter);
  688. }
  689. /***********************************************************************************************
  690. * WW3D::Begin_Render -- mark the start of rendering for a new frame *
  691. * *
  692. * INPUT: *
  693. * *
  694. * OUTPUT: *
  695. * *
  696. * WARNINGS: *
  697. * *
  698. * HISTORY: *
  699. * 3/24/98 GTH : Created. *
  700. *=============================================================================================*/
  701. WW3DErrorType WW3D::Begin_Render(bool clear,bool clearz,const Vector3 & color, float dest_alpha, void(*network_callback)(void))
  702. {
  703. if (!IsInitted) {
  704. return(WW3D_ERROR_OK);
  705. }
  706. WWPROFILE("WW3D::Begin_Render");
  707. WWASSERT(IsInitted);
  708. HRESULT hr;
  709. SNAPSHOT_SAY(("==========================================\r\n"));
  710. SNAPSHOT_SAY(("========== WW3D::Begin_Render ============\r\n"));
  711. SNAPSHOT_SAY(("==========================================\r\n\r\n"));
  712. if (DX8Wrapper::_Get_D3D_Device8() && (hr=DX8Wrapper::_Get_D3D_Device8()->TestCooperativeLevel()) != D3D_OK)
  713. {
  714. // If the device was lost, do not render until we get it back
  715. if( D3DERR_DEVICELOST == hr )
  716. return WW3D_ERROR_GENERIC; //other app has the device
  717. // Check if the device needs to be reset
  718. if( D3DERR_DEVICENOTRESET == hr )
  719. {
  720. DX8Wrapper::Reset_Device();
  721. }
  722. return WW3D_ERROR_GENERIC;
  723. }
  724. // Memory allocation statistics
  725. LastFrameMemoryAllocations=WWMemoryLogClass::Get_Allocate_Count();
  726. LastFrameMemoryFrees=WWMemoryLogClass::Get_Free_Count();
  727. WWMemoryLogClass::Reset_Counters();
  728. TextureLoader::Update(network_callback);
  729. // TextureClass::_Reset_Time_Stamp();
  730. DynamicVBAccessClass::_Reset(true);
  731. DynamicIBAccessClass::_Reset(true);
  732. #ifdef WW3D_DX8
  733. TextureFileClass::Update_Texture_Flash();
  734. #endif //WW3D_DX8
  735. Debug_Statistics::Begin_Statistics();
  736. if (IsCapturing && (!PauseRecord || RecordNextFrame)) {
  737. Update_Movie_Capture();
  738. RecordNextFrame = false;
  739. }
  740. WWASSERT(!IsRendering);
  741. IsRendering = true;
  742. // If we want to clear the screen, we need to set the viewport to include the entire screen:
  743. if (clear || clearz) {
  744. D3DVIEWPORT8 vp;
  745. int width, height, bits;
  746. bool windowed;
  747. WW3D::Get_Render_Target_Resolution(width, height, bits, windowed);
  748. vp.X = 0;
  749. vp.Y = 0;
  750. vp.Width = width;
  751. vp.Height = height;
  752. vp.MinZ = 0.0f;;
  753. vp.MaxZ = 1.0f;
  754. DX8Wrapper::Set_Viewport(&vp);
  755. DX8Wrapper::Clear(clear, clearz, color, dest_alpha);
  756. }
  757. // Notify D3D that we are beginning to render the frame
  758. DX8Wrapper::Begin_Scene();
  759. return WW3D_ERROR_OK;
  760. }
  761. /***********************************************************************************************
  762. * WW3D::Render -- Render a list of layers, starting at the back. *
  763. * *
  764. * INPUT: *
  765. * *
  766. * OUTPUT: *
  767. * *
  768. * WARNINGS: *
  769. * *
  770. * HISTORY: *
  771. * 4/2/98 EHC : Created. *
  772. *=============================================================================================*/
  773. WW3DErrorType WW3D::Render(const LayerListClass &LayerList)
  774. {
  775. if (!IsInitted) {
  776. return(WW3D_ERROR_OK);
  777. }
  778. WWASSERT(IsRendering);
  779. LayerClass *layer = LayerList.Last();
  780. while (layer->Is_Valid()) {
  781. WW3DErrorType result = Render(*layer);
  782. if (result != WW3D_ERROR_OK) {
  783. return result;
  784. }
  785. layer = layer->Prev();
  786. }
  787. return WW3D_ERROR_OK;
  788. }
  789. /***********************************************************************************************
  790. * WW3D::Render -- Render a Layer *
  791. * *
  792. * INPUT: *
  793. * *
  794. * OUTPUT: *
  795. * *
  796. * WARNINGS: *
  797. * *
  798. * HISTORY: *
  799. * 4/2/98 EHC : Created. *
  800. *=============================================================================================*/
  801. WW3DErrorType WW3D::Render(const LayerClass &Layer)
  802. {
  803. if (!IsInitted) {
  804. return(WW3D_ERROR_OK);
  805. }
  806. WWASSERT(IsRendering);
  807. return Render(Layer.Scene, Layer.Camera, Layer.Clear, Layer.ClearZ, Layer.ClearColor);
  808. }
  809. /***********************************************************************************************
  810. * WW3D::Render -- Render a 3D Scene using the given camera *
  811. * *
  812. * INPUT: *
  813. * *
  814. * OUTPUT: *
  815. * *
  816. * WARNINGS: *
  817. * *
  818. * HISTORY: *
  819. * 3/24/98 GTH : Created. *
  820. *=============================================================================================*/
  821. WW3DErrorType WW3D::Render(SceneClass * scene,CameraClass * cam,bool clear,bool clearz,const Vector3 & color)
  822. {
  823. if (!IsInitted) {
  824. return(WW3D_ERROR_OK);
  825. }
  826. WWPROFILE("WW3D::Render");
  827. WWMEMLOG(MEM_GAMEDATA);
  828. WWASSERT(IsInitted);
  829. WWASSERT(IsRendering);
  830. WWASSERT(scene);
  831. WWASSERT(cam);
  832. cam->On_Frame_Update();
  833. RenderInfoClass rinfo(*cam);
  834. // Apply the camera and viewport (including depth range)
  835. cam->Apply();
  836. // Clear the viewport
  837. if (clear || clearz) {
  838. DX8Wrapper::Clear(clear, clearz, color);
  839. }
  840. // set the rendering mode
  841. switch(scene->Get_Polygon_Mode()) {
  842. case SceneClass::POINT:
  843. DX8Wrapper::Set_DX8_Render_State(D3DRS_FILLMODE,D3DFILL_POINT);
  844. break;
  845. case SceneClass::LINE:
  846. DX8Wrapper::Set_DX8_Render_State(D3DRS_FILLMODE,D3DFILL_WIREFRAME);
  847. break;
  848. case SceneClass::FILL:
  849. DX8Wrapper::Set_DX8_Render_State(D3DRS_FILLMODE,D3DFILL_SOLID);
  850. break;
  851. }
  852. // Set the global ambient light value here. If the scene is using the LightEnvironment system
  853. // this setting will get overriden.
  854. DX8Wrapper::Set_Ambient(scene->Get_Ambient_Light());
  855. // render the scene
  856. TheDX8MeshRenderer.Set_Camera(&rinfo.Camera);
  857. scene->Render(rinfo);
  858. Flush(rinfo);
  859. return WW3D_ERROR_OK;
  860. }
  861. /***********************************************************************************************
  862. * WW3D::Render -- Render a single render object *
  863. * *
  864. * INPUT: *
  865. * *
  866. * OUTPUT: *
  867. * *
  868. * WARNINGS: *
  869. * *
  870. * HISTORY: *
  871. * 4/4/2001 gth : Created. *
  872. *=============================================================================================*/
  873. WW3DErrorType WW3D::Render(
  874. RenderObjClass & obj,
  875. RenderInfoClass & rinfo
  876. )
  877. {
  878. if (!IsInitted) {
  879. return(WW3D_ERROR_OK);
  880. }
  881. WWPROFILE("WW3D::Render");
  882. WWASSERT(IsInitted);
  883. WWASSERT(IsRendering);
  884. {
  885. WWPROFILE("On_Frame_Update");
  886. rinfo.Camera.On_Frame_Update();
  887. }
  888. // Apply the camera and viewport (including depth range)
  889. rinfo.Camera.Apply();
  890. // set the rendering mode
  891. DX8Wrapper::Set_DX8_Render_State(D3DRS_FILLMODE,D3DFILL_SOLID);
  892. // Install the lighting environment if one is supplied
  893. if (rinfo.light_environment != NULL) {
  894. DX8Wrapper::Set_Light_Environment(rinfo.light_environment);
  895. }
  896. // Render the object
  897. TheDX8MeshRenderer.Set_Camera(&rinfo.Camera);
  898. obj.Render(rinfo);
  899. Flush(rinfo);
  900. return WW3D_ERROR_OK;
  901. }
  902. /***********************************************************************************************
  903. * WW3D::Flush -- Process all pending rendering tasks *
  904. * *
  905. * NOTE: This normally happens AUTOMATICALLY. The user should almost *NEVER* have to call *
  906. * this function. Anyway, this function causes all of the deferred rendering systems to *
  907. * actually perform all of their rendering tasks. This includes the DX8MeshRenderer and *
  908. * the sorting system. *
  909. * *
  910. * INPUT: *
  911. * *
  912. * OUTPUT: *
  913. * *
  914. * WARNINGS: *
  915. * Don't call this unless you know what you're doing *
  916. * *
  917. * HISTORY: *
  918. * 4/17/2001 gth : Created. *
  919. * 07/01/02 KM Scalable shader library integration *
  920. *=============================================================================================*/
  921. void WW3D::Flush(RenderInfoClass & rinfo)
  922. {
  923. TheDX8MeshRenderer.Flush();
  924. SHD_FLUSH;
  925. WW3D::Render_And_Clear_Static_Sort_Lists(rinfo); //draws things like water
  926. SortingRendererClass::Flush();
  927. TheDX8MeshRenderer.Clear_Pending_Delete_Lists();
  928. }
  929. /***********************************************************************************************
  930. * WW3D::End_Render -- Mark the completion of a frame *
  931. * *
  932. * INPUT: *
  933. * *
  934. * OUTPUT: *
  935. * *
  936. * WARNINGS: *
  937. * *
  938. * HISTORY: *
  939. * 3/24/98 GTH : Created. *
  940. *=============================================================================================*/
  941. WW3DErrorType WW3D::End_Render(bool flip_frame)
  942. {
  943. if (!IsInitted) {
  944. return(WW3D_ERROR_OK);
  945. }
  946. WWPROFILE("WW3D::End_Render");
  947. WWASSERT(IsRendering);
  948. WWASSERT(IsInitted);
  949. // If sorting renderer flush isn't called from within any of the render functions
  950. // the sorting arrays will overflow!
  951. SortingRendererClass::Flush();
  952. IsRendering = false;
  953. {
  954. WWPROFILE("DX8Wrapper::End_Scene");
  955. DX8Wrapper::End_Scene(flip_frame);
  956. }
  957. FrameCount++;
  958. {
  959. WWPROFILE("End_Statistics");
  960. Debug_Statistics::End_Statistics();
  961. }
  962. SNAPSHOT_SAY(("==========================================\r\n"));
  963. SNAPSHOT_SAY(("========== WW3D::End_Render ==============\r\n"));
  964. SNAPSHOT_SAY(("==========================================\r\n\r\n"));
  965. Activate_Snapshot(false);
  966. // (gth) I've found some cases where its not safe to rely on our "shadow" copy (of
  967. // matrices for example) across multiple frames. So even though this is slightly
  968. // less "optimal", lets just reset the caches each frame.
  969. DX8Wrapper::Invalidate_Cached_Render_States();
  970. return WW3D_ERROR_OK;
  971. }
  972. /***********************************************************************************************
  973. * WW3D::Flip_To_Primary *
  974. * *
  975. * INPUT: *
  976. * *
  977. * OUTPUT: *
  978. * *
  979. * WARNINGS: *
  980. * *
  981. * HISTORY: *
  982. * 6/20/01 DEL : Created. *
  983. *=============================================================================================*/
  984. void WW3D::Flip_To_Primary(void)
  985. {
  986. DX8Wrapper::Flip_To_Primary();
  987. }
  988. /***********************************************************************************************
  989. * WW3D::Get_Last_Frame_Poly_Count -- returns the number of polys submitted in the previous fr *
  990. * *
  991. * INPUT: *
  992. * *
  993. * OUTPUT: *
  994. * *
  995. * WARNINGS: *
  996. * *
  997. * HISTORY: *
  998. * 7/28/99 GTH : Created. *
  999. *=============================================================================================*/
  1000. unsigned int WW3D::Get_Last_Frame_Poly_Count(void)
  1001. {
  1002. return Debug_Statistics::Get_DX8_Polygons();
  1003. }
  1004. unsigned int WW3D::Get_Last_Frame_Vertex_Count(void)
  1005. {
  1006. return Debug_Statistics::Get_DX8_Vertices();
  1007. }
  1008. /***********************************************************************************************
  1009. * WW3D::Sync -- Time sychronization *
  1010. * *
  1011. * INPUT: *
  1012. * *
  1013. * OUTPUT: *
  1014. * *
  1015. * WARNINGS: *
  1016. * *
  1017. * HISTORY: *
  1018. * 3/24/98 GTH : Created. *
  1019. *=============================================================================================*/
  1020. void WW3D::Sync(unsigned int sync_time)
  1021. {
  1022. PreviousSyncTime = SyncTime;
  1023. SyncTime = sync_time;
  1024. }
  1025. /***********************************************************************************************
  1026. * WW3D::Set_Ext_Swap_Interval -- Sets the swap interval the device should aim sync for. *
  1027. * *
  1028. * INPUT: *
  1029. * *
  1030. * OUTPUT: *
  1031. * *
  1032. * WARNINGS: Not supported by all rendering devices. *
  1033. * *
  1034. * HISTORY: *
  1035. * 5/07/98 NH : Created. *
  1036. *=============================================================================================*/
  1037. void WW3D::Set_Ext_Swap_Interval(long swap)
  1038. {
  1039. DX8Wrapper::Set_Swap_Interval(swap);
  1040. }
  1041. /***********************************************************************************************
  1042. * WW3D::Get_Ext_Swap_Interval -- Queries the swap interval the device is aiming sync for. *
  1043. * *
  1044. * INPUT: *
  1045. * *
  1046. * OUTPUT: *
  1047. * *
  1048. * WARNINGS: Not supported by all rendering devices. *
  1049. * *
  1050. * HISTORY: *
  1051. * 5/07/98 NH : Created. *
  1052. *=============================================================================================*/
  1053. long WW3D::Get_Ext_Swap_Interval(void)
  1054. {
  1055. return DX8Wrapper::Get_Swap_Interval();
  1056. }
  1057. /***********************************************************************************************
  1058. * WW3D::Set_Collision_Box_Display_Mask -- control rendering of collision boxes *
  1059. * *
  1060. * INPUT: *
  1061. * *
  1062. * OUTPUT: *
  1063. * *
  1064. * WARNINGS: *
  1065. * *
  1066. * HISTORY: *
  1067. * 3/17/99 GTH : Created. *
  1068. *=============================================================================================*/
  1069. void WW3D::Set_Collision_Box_Display_Mask(int mask)
  1070. {
  1071. BoxRenderObjClass::Set_Box_Display_Mask(mask);
  1072. }
  1073. /***********************************************************************************************
  1074. * WW3D::Get_Collision_Box_Display_Mask -- returns the current display mask for collision boxe *
  1075. * *
  1076. * INPUT: *
  1077. * *
  1078. * OUTPUT: *
  1079. * *
  1080. * WARNINGS: *
  1081. * *
  1082. * HISTORY: *
  1083. * 6/1/99 GTH : Created. *
  1084. *=============================================================================================*/
  1085. int WW3D::Get_Collision_Box_Display_Mask(void)
  1086. {
  1087. return BoxRenderObjClass::Get_Box_Display_Mask();
  1088. }
  1089. /***********************************************************************************************
  1090. * WW3D::Normalize_Coordinates -- Convert pixel coords to normalized screen coords 0..1 *
  1091. * *
  1092. * *
  1093. * *
  1094. * *
  1095. * INPUT: *
  1096. * *
  1097. * OUTPUT: *
  1098. * *
  1099. * WARNINGS: *
  1100. * *
  1101. * HISTORY: *
  1102. * 7/27/99 EHC : Created. *
  1103. *=============================================================================================*/
  1104. void WW3D::Normalize_Coordinates(int x, int y, float &fx, float &fy)
  1105. {
  1106. // clip the coordinates back into the resolution of the screen
  1107. x = Bound(x, 0, DX8Wrapper::Get_Device_Resolution_Width());
  1108. y = Bound(y, 0, DX8Wrapper::Get_Device_Resolution_Height());
  1109. // now that the coordinates are clipped convert them to their normalized values.
  1110. fx = (float)x / DX8Wrapper::Get_Device_Resolution_Width();
  1111. fy = (float)y / DX8Wrapper::Get_Device_Resolution_Height();
  1112. }
  1113. /***********************************************************************************************
  1114. * WW3D::Make_Screen_Shot -- saves a screenshot with the given base filename *
  1115. * *
  1116. * INPUT: *
  1117. * *
  1118. * OUTPUT: *
  1119. * *
  1120. * WARNINGS: *
  1121. * *
  1122. * HISTORY: *
  1123. * 5/19/99 GTH : Created. *
  1124. * 2/26/2001 hy : Updated to DX8 *
  1125. *=============================================================================================*/
  1126. void WW3D::Make_Screen_Shot( const char * filename_base , const float gamma, const ScreenShotFormatEnum format)
  1127. {
  1128. WWASSERT(!IsRendering);
  1129. char filename[80];
  1130. char ext[4];
  1131. switch (format) {
  1132. case TGA:
  1133. sprintf(ext,"tga");
  1134. break;
  1135. case BMP:
  1136. sprintf(ext,"bmp");
  1137. break;
  1138. default:
  1139. WWASSERT(0);
  1140. return;
  1141. break;
  1142. }
  1143. static int frame_number = 1;
  1144. bool done = false;
  1145. while (!done) {
  1146. sprintf( filename, "%s%.2d.%s", filename_base, frame_number++, ext);
  1147. FileClass*file=_TheFileFactory->Get_File( filename );
  1148. if ( file ) {
  1149. file->Open();
  1150. done = !file->Is_Available();
  1151. _TheFileFactory->Return_File( file );
  1152. } else {
  1153. done = true;
  1154. }
  1155. }
  1156. WWDEBUG_SAY(( "Creating Screen Shot %s\n", filename ));
  1157. // make the gamma look up table
  1158. int i;
  1159. unsigned char gamma_lut[256];
  1160. float recip = 1.0f;
  1161. if (gamma > WWMATH_EPSILON) {
  1162. recip = 1.0f / gamma;
  1163. }
  1164. for (i = 0; i < 256; i++) {
  1165. gamma_lut[i] = (unsigned char) (256.0f * powf(i / 256.0f, recip));
  1166. }
  1167. // Lock front buffer and copy
  1168. IDirect3DSurface8 *fb;
  1169. fb=DX8Wrapper::_Get_DX8_Front_Buffer();
  1170. D3DSURFACE_DESC desc;
  1171. fb->GetDesc(&desc);
  1172. RECT bounds;
  1173. GetWindowRect(_Hwnd,&bounds);
  1174. D3DLOCKED_RECT lrect;
  1175. DX8_ErrorCode(fb->LockRect(&lrect,&bounds,D3DLOCK_READONLY));
  1176. unsigned int x,y,index,index2,width,height;
  1177. width=bounds.right-bounds.left;
  1178. height=bounds.bottom-bounds.top;
  1179. unsigned char *image=W3DNEWARRAY unsigned char[3*width*height];
  1180. for (y=0; y<height; y++)
  1181. {
  1182. for (x=0; x<width; x++)
  1183. {
  1184. // index for image
  1185. index=3*(x+y*width);
  1186. // index for fb
  1187. index2=y*lrect.Pitch+4*x;
  1188. image[index] = gamma_lut[*((unsigned char *) lrect.pBits + index2+2)];
  1189. image[index+1] = gamma_lut[*((unsigned char *) lrect.pBits + index2+1)];
  1190. image[index+2] = gamma_lut[*((unsigned char *) lrect.pBits + index2+0)];
  1191. }
  1192. }
  1193. fb->Release();
  1194. switch (format) {
  1195. case TGA:
  1196. {
  1197. Targa targ;
  1198. memset(&targ.Header,0,sizeof(targ.Header));
  1199. targ.Header.Width=width;
  1200. targ.Header.Height=height;
  1201. targ.Header.PixelDepth=24;
  1202. targ.Header.ImageType=TGA_TRUECOLOR;
  1203. targ.SetImage((char *) image);
  1204. targ.YFlip();
  1205. FileClass*file=_TheWritingFileFactory->Get_File( filename );
  1206. if ( file ) {
  1207. file->Create();
  1208. file->Close();
  1209. _TheWritingFileFactory->Return_File( file );
  1210. }
  1211. targ.Save(filename,TGAF_IMAGE,false);
  1212. }
  1213. break;
  1214. case BMP:
  1215. {
  1216. BITMAPFILEHEADER fileheader;
  1217. BITMAPINFOHEADER header;
  1218. memset(&header, 0, sizeof(BITMAPINFOHEADER));
  1219. header.biSize = sizeof(BITMAPINFOHEADER);
  1220. header.biWidth = width;
  1221. header.biHeight = height;
  1222. header.biPlanes = 1;
  1223. header.biBitCount = 24;
  1224. header.biCompression = BI_RGB;
  1225. header.biXPelsPerMeter = 0xB12;
  1226. header.biYPelsPerMeter = 0xB12;
  1227. int len = ((width * 24 +31) & ~31) /8;
  1228. memset(&fileheader, 0, sizeof(BITMAPFILEHEADER));
  1229. fileheader.bfType = 19778; // BM
  1230. fileheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
  1231. fileheader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 3 * len * height * sizeof(char);
  1232. FileClass *file = _TheWritingFileFactory->Get_File( filename );
  1233. if ( file ) {
  1234. file->Create();
  1235. file->Open(FileClass::WRITE);
  1236. int num;
  1237. num = file->Write(&fileheader, sizeof(BITMAPFILEHEADER));
  1238. WWASSERT(num == sizeof(BITMAPFILEHEADER));
  1239. num = file->Write(&header, sizeof(BITMAPINFOHEADER));
  1240. WWASSERT(num == sizeof(BITMAPINFOHEADER));
  1241. char *temp = new char [3 * len];
  1242. memset(temp, 0, 3 * len * sizeof(char));
  1243. // invert image, pad and swap R and B
  1244. for (y = 0; y < (int) height; y++) {
  1245. memcpy(&temp[0], &image[ 3 * width * (height - y - 1)], 3 * width * sizeof(char));
  1246. for (x = 0; x < width; x++) {
  1247. char t2 = temp[3 * x];
  1248. temp[3 * x] = temp[3 * x + 2];
  1249. temp[3 * x + 2] = t2;
  1250. }
  1251. num = file->Write(&temp[0], len * sizeof(char));
  1252. WWASSERT(num == len * (int)sizeof(char));
  1253. }
  1254. delete [] temp;
  1255. file->Close();
  1256. _TheWritingFileFactory->Return_File( file );
  1257. }
  1258. }
  1259. break;
  1260. }
  1261. delete [] image;
  1262. }
  1263. /***********************************************************************************************
  1264. * WW3D::Start_Movie_Capture -- begins dumping frames to a movie *
  1265. * *
  1266. * INPUT: *
  1267. * *
  1268. * OUTPUT: *
  1269. * *
  1270. * WARNINGS: *
  1271. * *
  1272. * HISTORY: *
  1273. * 5/19/99 GTH : Created. *
  1274. * 2/26/2001 hy : updated to dx8 *
  1275. *=============================================================================================*/
  1276. void WW3D::Start_Movie_Capture( const char * filename_base, float frame_rate )
  1277. {
  1278. #ifdef _WINDOWS
  1279. if (IsCapturing) {
  1280. Stop_Movie_Capture();
  1281. }
  1282. WWASSERT( !IsCapturing);
  1283. IsCapturing = true;
  1284. RECT bounds;
  1285. GetWindowRect(_Hwnd,&bounds);
  1286. int height=bounds.bottom-bounds.top;
  1287. int width=bounds.right-bounds.left;
  1288. int depth=24;
  1289. WWASSERT( Movie == NULL);
  1290. if (frame_rate == 0.0f) {
  1291. frame_rate = 1.0f;
  1292. PauseRecord = true;
  1293. } else {
  1294. PauseRecord = false;
  1295. }
  1296. Movie = W3DNEW FrameGrabClass( filename_base, FrameGrabClass::AVI, width, height, depth, frame_rate);
  1297. WWDEBUG_SAY(( "Starting Movie %s\n", filename_base ));
  1298. #endif
  1299. }
  1300. /***********************************************************************************************
  1301. * WW3D::Stop_Movie_Capture -- ends dumping frames to a movie *
  1302. * *
  1303. * INPUT: *
  1304. * *
  1305. * OUTPUT: *
  1306. * *
  1307. * WARNINGS: *
  1308. * *
  1309. * HISTORY: *
  1310. * 5/19/99 GTH : Created. *
  1311. *=============================================================================================*/
  1312. void WW3D::Stop_Movie_Capture( void )
  1313. {
  1314. #ifdef _WINDOWS
  1315. if (IsCapturing) {
  1316. IsCapturing = false;
  1317. WWDEBUG_SAY(( "Stoping Movie\n" ));
  1318. WWASSERT( Movie != NULL);
  1319. delete Movie;
  1320. Movie = NULL;
  1321. }
  1322. #endif
  1323. }
  1324. /***********************************************************************************************
  1325. * WW3D::Toggle_Movie_Capture -- toggles movie capture... *
  1326. * *
  1327. * INPUT: *
  1328. * *
  1329. * OUTPUT: *
  1330. * *
  1331. * WARNINGS: *
  1332. * *
  1333. * HISTORY: *
  1334. * 5/19/99 GTH : Created. *
  1335. *=============================================================================================*/
  1336. void WW3D::Toggle_Movie_Capture( const char * filename_base, float frame_rate )
  1337. {
  1338. if (IsCapturing) {
  1339. Stop_Movie_Capture();
  1340. } else {
  1341. Start_Movie_Capture( filename_base, frame_rate);
  1342. }
  1343. }
  1344. /***********************************************************************************************
  1345. * WW3D::Start_Single_Frame_Movie_Capture -- starts capturing a single frame movie *
  1346. * *
  1347. * INPUT: *
  1348. * *
  1349. * OUTPUT: *
  1350. * *
  1351. * WARNINGS: *
  1352. * *
  1353. * HISTORY: *
  1354. * 5/19/99 GTH : Created. *
  1355. *=============================================================================================*/
  1356. void WW3D::Start_Single_Frame_Movie_Capture(const char *filename_base)
  1357. {
  1358. Start_Movie_Capture(filename_base, 0.0f);
  1359. }
  1360. /***********************************************************************************************
  1361. * WW3D::Capture_Next_Movie_Frame -- tells ww3d to grab another frame for the movie *
  1362. * *
  1363. * INPUT: *
  1364. * *
  1365. * OUTPUT: *
  1366. * *
  1367. * WARNINGS: *
  1368. * *
  1369. * HISTORY: *
  1370. * 5/19/99 GTH : Created. *
  1371. *=============================================================================================*/
  1372. void WW3D::Capture_Next_Movie_Frame()
  1373. {
  1374. RecordNextFrame = true;
  1375. }
  1376. /***********************************************************************************************
  1377. * WW3D::Pause_Movie -- pauses/unpauses movie capturing *
  1378. * *
  1379. * INPUT: *
  1380. * *
  1381. * OUTPUT: *
  1382. * *
  1383. * WARNINGS: *
  1384. * *
  1385. * HISTORY: *
  1386. * 5/19/99 GTH : Created. *
  1387. *=============================================================================================*/
  1388. void WW3D::Pause_Movie(bool mode)
  1389. {
  1390. PauseRecord = mode;
  1391. }
  1392. /***********************************************************************************************
  1393. * WW3D::Is_Movie_Paused -- returns whether the movie capture system is paused *
  1394. * *
  1395. * INPUT: *
  1396. * *
  1397. * OUTPUT: *
  1398. * *
  1399. * WARNINGS: *
  1400. * *
  1401. * HISTORY: *
  1402. * 5/19/99 GTH : Created. *
  1403. *=============================================================================================*/
  1404. bool WW3D::Is_Movie_Paused()
  1405. {
  1406. return PauseRecord;
  1407. }
  1408. /***********************************************************************************************
  1409. * WW3D::Is_Recording_Next_Frame -- returns whether the next frame will be dumped to a movie *
  1410. * *
  1411. * INPUT: *
  1412. * *
  1413. * OUTPUT: *
  1414. * *
  1415. * WARNINGS: *
  1416. * *
  1417. * HISTORY: *
  1418. * 5/19/99 GTH : Created. *
  1419. *=============================================================================================*/
  1420. bool WW3D::Is_Recording_Next_Frame()
  1421. {
  1422. return (Movie != 0) && (!PauseRecord || RecordNextFrame);
  1423. }
  1424. /***********************************************************************************************
  1425. * WW3D::Is_Movie_Ready -- returns whether the movie capture system is ready *
  1426. * *
  1427. * INPUT: *
  1428. * *
  1429. * OUTPUT: *
  1430. * *
  1431. * WARNINGS: *
  1432. * *
  1433. * HISTORY: *
  1434. * 5/19/99 GTH : Created. *
  1435. *=============================================================================================*/
  1436. bool WW3D::Is_Movie_Ready()
  1437. {
  1438. return Movie != 0;
  1439. }
  1440. /***********************************************************************************************
  1441. * WW3D::Update_Movie_Capture -- dumps the current frame into the movie *
  1442. * *
  1443. * INPUT: *
  1444. * *
  1445. * OUTPUT: *
  1446. * *
  1447. * WARNINGS: *
  1448. * *
  1449. * HISTORY: *
  1450. * 5/19/99 GTH : Created. *
  1451. * 2/26/2001 hy : Updated to dx8 *
  1452. *=============================================================================================*/
  1453. void WW3D::Update_Movie_Capture( void )
  1454. {
  1455. #ifdef _WINDOWS
  1456. WWASSERT( IsCapturing);
  1457. WWPROFILE("WW3D::Update_Movie_Capture");
  1458. WWDEBUG_SAY(( "Updating\n"));
  1459. // Lock front buffer and copy
  1460. IDirect3DSurface8 *fb;
  1461. fb=DX8Wrapper::_Get_DX8_Front_Buffer();
  1462. D3DSURFACE_DESC desc;
  1463. fb->GetDesc(&desc);
  1464. RECT bounds;
  1465. GetWindowRect(_Hwnd,&bounds);
  1466. D3DLOCKED_RECT lrect;
  1467. DX8_ErrorCode(fb->LockRect(&lrect,&bounds,D3DLOCK_READONLY));
  1468. unsigned int x,y,index,index2,width,height;
  1469. width=bounds.right-bounds.left;
  1470. height=bounds.bottom-bounds.top;
  1471. char *image=(char *)Movie->GetBuffer();
  1472. for (y=0; y<height; y++)
  1473. {
  1474. for (x=0; x<width; x++)
  1475. {
  1476. // index for image
  1477. index=3*(x+(height-y-1)*width);
  1478. // index for fb
  1479. index2=y*lrect.Pitch+4*x;
  1480. image[index]=*((char *) lrect.pBits + index2+0);
  1481. image[index+1]=*((char *) lrect.pBits + index2+1);
  1482. image[index+2]=*((char *) lrect.pBits + index2+2);
  1483. }
  1484. }
  1485. fb->Release();
  1486. Movie->Grab(image);
  1487. #endif
  1488. }
  1489. /***********************************************************************************************
  1490. * WW3D::Get_Movie_Capture_Frame_Rate -- returns the framerate at which the movie is being cap *
  1491. * *
  1492. * INPUT: *
  1493. * *
  1494. * OUTPUT: *
  1495. * *
  1496. * WARNINGS: *
  1497. * *
  1498. * HISTORY: *
  1499. * 5/19/99 GTH : Created. *
  1500. *=============================================================================================*/
  1501. float WW3D::Get_Movie_Capture_Frame_Rate( void )
  1502. {
  1503. #ifdef _WINDOWS
  1504. if (IsCapturing) {
  1505. return Movie->GetFrameRate();
  1506. }
  1507. #endif
  1508. return 0;
  1509. }
  1510. /***********************************************************************************************
  1511. * WW3D::Set_Texture_Reduction -- sets the (hacky) texture reduction factor *
  1512. * *
  1513. * INPUT: *
  1514. * *
  1515. * OUTPUT: *
  1516. * *
  1517. * WARNINGS: *
  1518. * *
  1519. * HISTORY: *
  1520. * 5/19/99 GTH : Created. *
  1521. *=============================================================================================*/
  1522. void WW3D::Set_Texture_Reduction( int value, int minDim )
  1523. {
  1524. if (_TextureReduction != value || _TextureMinDim != minDim) {
  1525. _TextureReduction=value;
  1526. _TextureMinDim=minDim;
  1527. _Invalidate_Textures();
  1528. }
  1529. }
  1530. void WW3D::Enable_Texturing(bool b)
  1531. {
  1532. if (b==IsTexturingEnabled) return;
  1533. IsTexturingEnabled=b;
  1534. // _Invalidate_Textures();
  1535. }
  1536. void WW3D::Enable_Coloring(unsigned int color)
  1537. {
  1538. IsColoringEnabled = (color == 0) ? false : true;
  1539. }
  1540. /***********************************************************************************************
  1541. * WW3D::Get_Texture_Reduction -- gets the (hacky) texture reduction factor *
  1542. * *
  1543. * INPUT: *
  1544. * *
  1545. * OUTPUT: *
  1546. * *
  1547. * WARNINGS: *
  1548. * *
  1549. * HISTORY: *
  1550. * 11/25/99 TSS : Created. *
  1551. *=============================================================================================*/
  1552. int WW3D::Get_Texture_Reduction( void )
  1553. {
  1554. return _TextureReduction;
  1555. }
  1556. /***********************************************************************************************
  1557. * WW3D::Get_Texture_Min_Mip_Levels -- gets the minimum number of mip levels permitted *
  1558. * *
  1559. * INPUT: *
  1560. * *
  1561. * OUTPUT: *
  1562. * *
  1563. * WARNINGS: *
  1564. * *
  1565. * HISTORY: *
  1566. * 11/25/99 TSS : Created. *
  1567. *=============================================================================================*/
  1568. int WW3D::Get_Texture_Min_Dimension( void )
  1569. {
  1570. return _TextureMinDim;
  1571. }
  1572. void WW3D::Enable_Large_Texture_Extra_Reduction(bool onoff)
  1573. {
  1574. if (_LargeTextureExtraReductionEnabled != onoff) {
  1575. _LargeTextureExtraReductionEnabled = onoff;
  1576. _Invalidate_Textures();
  1577. }
  1578. }
  1579. bool WW3D::Is_Large_Texture_Extra_Reduction_Enabled(void)
  1580. {
  1581. return _LargeTextureExtraReductionEnabled;
  1582. }
  1583. /***********************************************************************************************
  1584. * WW3D::Peek_Default_Debug_Material -- returns a pointer to the default debug mtl *
  1585. * *
  1586. * INPUT: *
  1587. * *
  1588. * OUTPUT: *
  1589. * *
  1590. * WARNINGS: *
  1591. * *
  1592. * HISTORY: *
  1593. * 7/21/99 GTH : Created. *
  1594. *=============================================================================================*/
  1595. VertexMaterialClass * WW3D::Peek_Default_Debug_Material(void)
  1596. {
  1597. #ifdef WWDEBUG
  1598. WWASSERT(DefaultDebugMaterial);
  1599. return DefaultDebugMaterial;
  1600. #else
  1601. return NULL;
  1602. #endif
  1603. }
  1604. /***********************************************************************************************
  1605. * WW3D::Peek_Default_Debug_Shader -- returns the default shader for debugging. *
  1606. * *
  1607. * INPUT: *
  1608. * *
  1609. * OUTPUT: *
  1610. * *
  1611. * WARNINGS: *
  1612. * *
  1613. * HISTORY: *
  1614. * 7/21/99 GTH : Created. *
  1615. *=============================================================================================*/
  1616. ShaderClass WW3D::Peek_Default_Debug_Shader(void)
  1617. {
  1618. return DefaultDebugShader;
  1619. }
  1620. /***********************************************************************************************
  1621. * WW3D::Peek_Lightmap_Debug_Shader -- returns the shader for lightmap debugging. *
  1622. * *
  1623. * INPUT: *
  1624. * *
  1625. * OUTPUT: *
  1626. * *
  1627. * WARNINGS: *
  1628. * *
  1629. * HISTORY: *
  1630. * 7/21/99 GTH : Created. *
  1631. *=============================================================================================*/
  1632. ShaderClass WW3D::Peek_Lightmap_Debug_Shader(void)
  1633. {
  1634. return LightmapDebugShader;
  1635. }
  1636. /***********************************************************************************************
  1637. * WW3D::Allocate_Debug_Resources -- allocates the debug resources *
  1638. * *
  1639. * INPUT: *
  1640. * *
  1641. * OUTPUT: *
  1642. * *
  1643. * WARNINGS: *
  1644. * *
  1645. * HISTORY: *
  1646. * 7/21/99 GTH : Created. *
  1647. *=============================================================================================*/
  1648. void WW3D::Allocate_Debug_Resources(void)
  1649. {
  1650. #ifdef WWDEBUG
  1651. WWASSERT(DefaultDebugMaterial == NULL);
  1652. DefaultDebugMaterial = W3DNEW VertexMaterialClass;
  1653. DefaultDebugMaterial->Set_Shininess(0.0f);
  1654. DefaultDebugMaterial->Set_Opacity(1.0f);
  1655. DefaultDebugMaterial->Set_Ambient(0,0,0);
  1656. DefaultDebugMaterial->Set_Diffuse(0,0,0);
  1657. DefaultDebugMaterial->Set_Specular(0,0,0);
  1658. DefaultDebugMaterial->Set_Emissive(0,0,0);
  1659. #endif
  1660. }
  1661. /***********************************************************************************************
  1662. * WW3D::Release_Debug_Resources -- releases the debug resources *
  1663. * *
  1664. * INPUT: *
  1665. * *
  1666. * OUTPUT: *
  1667. * *
  1668. * WARNINGS: *
  1669. * *
  1670. * HISTORY: *
  1671. * 7/21/99 GTH : Created. *
  1672. *=============================================================================================*/
  1673. void WW3D::Release_Debug_Resources(void)
  1674. {
  1675. #ifdef WWDEBUG
  1676. WWASSERT(DefaultDebugMaterial);
  1677. REF_PTR_RELEASE(DefaultDebugMaterial);
  1678. #endif
  1679. }
  1680. WW3DErrorType WW3D::On_Deactivate_App(void)
  1681. {
  1682. _Invalidate_Textures();
  1683. _Invalidate_Mesh_Cache();
  1684. return WW3D_ERROR_OK;
  1685. }
  1686. WW3DErrorType WW3D::On_Activate_App(void)
  1687. {
  1688. return WW3D_ERROR_OK;
  1689. }
  1690. void WW3D::Get_Pixel_Center(float &x, float &y)
  1691. {
  1692. x = PixelCenterX; y = PixelCenterY;
  1693. }
  1694. void WW3D::Update_Pixel_Center(void)
  1695. {
  1696. #ifdef WW3D_DX8
  1697. const char *name = _RenderDeviceShortNameTable.getString(CurRenderDevice);
  1698. if ( strstr(name, "OpenGL") ) {
  1699. PixelCenterX = 0.0f; PixelCenterY = 0.0f;
  1700. } else if ( strstr(name, "Glide") ) {
  1701. PixelCenterX = 0.0f; PixelCenterY = 0.0f;
  1702. } else if ( strstr(name, "DirectX") ) {
  1703. PixelCenterX = 0.5f; PixelCenterY = 0.5f;
  1704. } else if ( strstr(name, "Software") ) {
  1705. PixelCenterX = 0.0f; PixelCenterY = 0.0f;
  1706. } else if ( strstr(name, "Null") ) {
  1707. PixelCenterX = 0.0f; PixelCenterY = 0.0f;
  1708. } else {
  1709. // unknown device
  1710. PixelCenterX = 0.0f; PixelCenterY = 0.0f;
  1711. }
  1712. #endif //WW3D_DX8
  1713. }
  1714. void WW3D::Set_Texture_Bitdepth(int bitdepth)
  1715. {
  1716. DX8Wrapper::Set_Texture_Bitdepth(bitdepth);
  1717. }
  1718. int WW3D::Get_Texture_Bitdepth()
  1719. {
  1720. return DX8Wrapper::Get_Texture_Bitdepth();
  1721. }
  1722. void WW3D::Add_To_Static_Sort_List(RenderObjClass *robj, unsigned int sort_level)
  1723. {
  1724. CurrentStaticSortLists->Add_To_List(robj, sort_level);
  1725. }
  1726. void WW3D::Render_And_Clear_Static_Sort_Lists(RenderInfoClass & rinfo)
  1727. {
  1728. // The ststic sort lists need to be disabled while we are rendering from them otherwise the
  1729. // Render() function will just dump the objects right back on the same lists.
  1730. bool old_enable = AreStaticSortListsEnabled;
  1731. AreStaticSortListsEnabled = false;
  1732. CurrentStaticSortLists->Render_And_Clear(rinfo);
  1733. AreStaticSortListsEnabled = old_enable;
  1734. }
  1735. void WW3D::Enable_Sorting(bool onoff)
  1736. {
  1737. IsSortingEnabled = onoff;
  1738. // Have to invalidate mesh rendering system because
  1739. // meshes are put into different fvfs depending on their sort state
  1740. TheDX8MeshRenderer.Invalidate();
  1741. }
  1742. void WW3D::Override_Current_Static_Sort_Lists(StaticSortListClass * sort_list)
  1743. {
  1744. if (sort_list) {
  1745. CurrentStaticSortLists = sort_list;
  1746. } else {
  1747. WWASSERT(sort_list);
  1748. }
  1749. }
  1750. void WW3D::Reset_Current_Static_Sort_Lists_To_Default(void)
  1751. {
  1752. CurrentStaticSortLists = DefaultStaticSortLists;
  1753. }
  1754. void WW3D::Set_Gamma(float gamma,float bright,float contrast,bool calibrate)
  1755. {
  1756. DX8Wrapper::Set_Gamma(gamma,bright,contrast,calibrate);
  1757. }