| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907 |
- /*
- ** Command & Conquer Generals(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** 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 ***
- ***********************************************************************************************
- * *
- * Project Name : WW3D *
- * *
- * $Archive:: /VSS_Sync/ww3d2/ww3d.cpp $*
- * *
- * Author:: Greg_h *
- * *
- * $Modtime:: 8/29/01 7:29p $*
- * *
- * $Revision:: 82 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * WW3D::Init -- Initialize the WW3D Library *
- * WW3D::Shutdown -- shutdown the WW3D Library *
- * WW3D::Set_Render_Device -- set the render device being currently used *
- * WW3D::Set_Next_Render_Device -- just go to the next device in the list *
- * WW3D::Set_Device_Resolution -- set the current resolution and bitdepth *
- * WW3D::Get_Render_Device -- Get the index of the current render device *
- * WW3D::Get_Render_Device_Desc -- returns description of the current render device *
- * WW3D::Get_Render_Device_Count -- returns the number of render devices available *
- * WW3D::Get_Render_Device_Name -- returns the name of the n-th render device *
- * WW3D::Get_Render_Target_Resolution -- get the resolution and bitdepth of the current target*
- * WW3D::Get_Device_Resolution -- get the current resolution and bitdepth *
- * WW3D::Begin_Render -- mark the start of rendering for a new frame *
- * WW3D::Render -- Render a 3D Scene using the given camera *
- * WW3D::Render -- Render a single render object *
- * WW3D::End_Render -- Mark the completion of a frame *
- * WW3D::Sync -- Time sychronization *
- * WW3D::Set_Ext_Swap_Interval -- Sets the swap interval the device should aim sync for. *
- * WW3D::Get_Ext_Swap_Interval -- Queries the swap interval the device is aiming sync for. *
- * WW3D::Set_Polygon_Mode -- set the drawing mode *
- * WW3D::Get_Polygon_Mode -- returns the current rendering mode *
- * WW3D::Set_Collision_Box_Display_Mask -- control rendering of collision boxes *
- * WW3D::Get_Collision_Box_Display_Mask -- returns the current display mask for collision bo *
- * WW3D::Normalize_Coordinates -- Convert pixel coords to normalized screen coords 0..1 *
- * WW3D::Update_Render_Device_Description -- updates the description of the current render d *
- * WW3D::Make_Screen_Shot -- saves a screenshot with the given base filename *
- * WW3D::Start_Movie_Capture -- begins dumping frames to a movie *
- * WW3D::Stop_Movie_Capture -- ends dumping frames to a movie *
- * WW3D::Toggle_Movie_Capture -- toggles movie capture... *
- * WW3D::Start_Single_Frame_Movie_Capture -- starts capturing a single frame movie *
- * WW3D::Capture_Next_Movie_Frame -- tells ww3d to grab another frame for the movie *
- * WW3D::Pause_Movie -- pauses/unpauses movie capturing *
- * WW3D::Is_Movie_Paused -- returns whether the movie capture system is paused *
- * WW3D::Is_Recording_Next_Frame -- returns whether the next frame will be dumped to a movie *
- * WW3D::Is_Movie_Ready -- returns whether the movie capture system is ready *
- * WW3D::Update_Movie_Capture -- dumps the current frame into the movie *
- * WW3D::Get_Movie_Capture_Frame_Rate -- returns the framerate at which the movie is being c *
- * WW3D::Set_Texture_Reduction -- sets the (hacky) texture reduction factor *
- * WW3D::Get_Texture_Reduction -- gets the (hacky) texture reduction factor *
- * WW3D::Flush_Texture_Cache -- dump all textures from the texture cache *
- * WW3D::Allocate_Debug_Resources -- allocates the debug resources *
- * WW3D::Release_Debug_Resources -- releases the debug resources *
- * WW3D::Get_Last_Frame_Poly_Count -- returns the number of polys submitted in the previous *
- * WW3D::Flush -- Process all pending rendering tasks *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "ww3d.h"
- #include "rinfo.h"
- #include "assetmgr.h"
- #include "boxrobj.h"
- #include "predlod.h"
- #include "camera.h"
- #include "scene.h"
- #include "texfcach.h"
- #include "registry.h"
- #include "segline.h"
- #include "shader.h"
- #include "vertmaterial.h"
- #include "wwdebug.h"
- #include "wwprofile.h"
- #include "wwmemlog.h"
- #include "shattersystem.h"
- #include "textureloader.h"
- #include "statistics.h"
- #include "pointgr.h"
- #include "ffactory.h"
- #include "ini.h"
- #include "dazzle.h"
- #include "meshmdl.h"
- #include "dx8renderer.h"
- #include "render2d.h"
- #include "bound.h"
- #include "rddesc.h"
- #include "vector3i.h"
- #include <cstdio>
- #include "dx8wrapper.h"
- #include "targa.h"
- #include "sortingrenderer.h"
- #include "thread.h"
- #include "cpudetect.h"
- #include "dx8texman.h"
- #include "formconv.h"
- #ifndef _UNIX
- #include "framgrab.h"
- #endif
- const char* DAZZLE_INI_FILENAME="DAZZLE.INI";
- #define DEFAULT_DEBUG_SHADER_BITS ( SHADE_CNST(\
- ShaderClass::PASS_LEQUAL,\
- ShaderClass::DEPTH_WRITE_ENABLE,\
- ShaderClass::COLOR_WRITE_ENABLE,\
- ShaderClass::SRCBLEND_ONE,\
- ShaderClass::DSTBLEND_ZERO,\
- ShaderClass::FOG_DISABLE,\
- ShaderClass::GRADIENT_MODULATE,\
- ShaderClass::SECONDARY_GRADIENT_DISABLE,\
- ShaderClass::TEXTURING_DISABLE,\
- ShaderClass::ALPHATEST_DISABLE,\
- ShaderClass::CULL_MODE_ENABLE, \
- ShaderClass::DETAILCOLOR_DISABLE,\
- ShaderClass::DETAILALPHA_DISABLE) )
- #define LIGHTMAP_DEBUG_SHADER_BITS ( SHADE_CNST(\
- ShaderClass::PASS_LEQUAL,\
- ShaderClass::DEPTH_WRITE_ENABLE,\
- ShaderClass::COLOR_WRITE_ENABLE,\
- ShaderClass::SRCBLEND_ONE,\
- ShaderClass::DSTBLEND_ZERO,\
- ShaderClass::FOG_DISABLE,\
- ShaderClass::GRADIENT_DISABLE,\
- ShaderClass::SECONDARY_GRADIENT_DISABLE,\
- ShaderClass::TEXTURING_ENABLE,\
- ShaderClass::ALPHATEST_DISABLE,\
- ShaderClass::CULL_MODE_ENABLE, \
- ShaderClass::DETAILCOLOR_DISABLE,\
- ShaderClass::DETAILALPHA_DISABLE) )
- /**********************************************************************************
- **
- ** WW3D Static Globals
- **
- ***********************************************************************************/
- unsigned int WW3D::SyncTime = 0;
- unsigned int WW3D::PreviousSyncTime = 0;
- bool WW3D::IsSortingEnabled = true;
- float WW3D::PixelCenterX = 0.0f;
- float WW3D::PixelCenterY = 0.0f;
- bool WW3D::IsInitted = false;
- bool WW3D::IsRendering = false;
- bool WW3D::IsCapturing = false;
- bool WW3D::IsScreenUVBiased = false;
- bool WW3D::AreDecalsEnabled = true;
- float WW3D::DecalRejectionDistance = 1000000.0f;
- bool WW3D::AreStaticSortListsEnabled = false;
- bool WW3D::MungeSortOnLoad = false;
- FrameGrabClass * WW3D::Movie = NULL;
- bool WW3D::PauseRecord;
- bool WW3D::RecordNextFrame;
- int WW3D::FrameCount = 0;
- long WW3D::UserStat0 = 0;
- long WW3D::UserStat1 = 0;
- long WW3D::UserStat2 = 0;
- float WW3D::DefaultNativeScreenSize = 1.0f;
- RefRenderObjListClass * WW3D::DefaultStaticSortLists = NULL;
- RefRenderObjListClass * WW3D::CurrentStaticSortLists = NULL;
- unsigned int WW3D::MinStaticSortLevel = 1; // The 0 list is not used
- unsigned int WW3D::MaxStaticSortLevel = MAX_SORT_LEVEL;
- VertexMaterialClass * WW3D::DefaultDebugMaterial = NULL;
- ShaderClass WW3D::DefaultDebugShader(DEFAULT_DEBUG_SHADER_BITS);
- ShaderClass WW3D::LightmapDebugShader(LIGHTMAP_DEBUG_SHADER_BITS);
- WW3D::PrelitModeEnum WW3D::PrelitMode = PRELIT_MODE_LIGHTMAP_MULTI_PASS;
- bool WW3D::ExposePrelit = false;
- bool WW3D::SnapshotActivated=false;
- WW3D::MeshDrawModeEnum WW3D::MeshDrawMode = MESH_DRAW_MODE_OLD;
- WW3D::TextureThumbnailModeEnum WW3D::TextureThumbnailMode = TEXTURE_THUMBNAIL_MODE_ON;
- WW3D::TextureCompressionModeEnum WW3D::TextureCompressionMode = TEXTURE_COMPRESSION_ENABLE;
- WW3D::NPatchesGapFillingModeEnum WW3D::NPatchesGapFillingMode = NPATCHES_GAP_FILLING_ENABLED;
- unsigned WW3D::NPatchesLevel=1;
- bool WW3D::IsTexturingEnabled=true;
- unsigned int WW3D::IsColoringEnabled=0x00000000;
- static HWND _Hwnd = NULL; // Not a member to hide windows from WW3D users
- static int _TextureReduction = 0;
- static int _TextureMinMipLevels = 1;
- int WW3D::LastFrameMemoryAllocations;
- int WW3D::LastFrameMemoryFrees;
- /**********************************************************************************
- **
- ** WW3D Static Functions
- **
- ***********************************************************************************/
- void WW3D::Set_Texture_Compression_Mode(TextureCompressionModeEnum mode)
- {
- if (TextureCompressionMode!=mode) {
- TextureCompressionMode = mode;
- _Invalidate_Textures();
- }
- }
- void WW3D::Set_NPatches_Gap_Filling_Mode(NPatchesGapFillingModeEnum mode)
- {
- if (NPatchesGapFillingMode!=mode) {
- NPatchesGapFillingMode=mode;
- TheDX8MeshRenderer.Invalidate();
- }
- }
- void WW3D::Set_NPatches_Level(unsigned level)
- {
- if (level>8) level=8;
- if (level<1) level=1;
- if (NPatchesLevel==1 && level>1) TheDX8MeshRenderer.Invalidate();
- if (NPatchesLevel>1 && level==1) TheDX8MeshRenderer.Invalidate();
- NPatchesLevel = level;
- }
- void WW3D::Set_Texture_Thumbnail_Mode (TextureThumbnailModeEnum mode)
- {
- if (TextureThumbnailMode!=mode) {
- TextureThumbnailMode = mode;
- _Invalidate_Textures();
- }
- }
- /***********************************************************************************************
- * WW3D::Init -- Initialize the WW3D Library *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/24/98 GTH : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Init(void *hwnd, char *defaultpal)
- {
- assert(IsInitted == false);
- WWDEBUG_SAY(("WW3D::Init hwnd = %p\n",hwnd));
- _Hwnd = (HWND)hwnd;
- /*
- ** Initialize d3d, this also enumerates the available devices and resolutions.
- */
- Init_D3D_To_WW3_Conversion();
- if (!DX8Wrapper::Init(_Hwnd))
- return WW3D_ERROR_INITIALIZATION_FAILED;
- Allocate_Debug_Resources();
- MMRESULT r=timeBeginPeriod(1);
- WWASSERT(r==TIMERR_NOERROR);
- /*
- ** Initialize the dazzle system
- */
- FileClass * dazzle_ini_file = _TheFileFactory->Get_File(DAZZLE_INI_FILENAME);
- if (dazzle_ini_file) {
- INIClass dazzle_ini(*dazzle_ini_file);
- DazzleRenderObjClass::Init_From_INI(&dazzle_ini);
- _TheFileFactory->Return_File(dazzle_ini_file);
- }
- /*
- ** Initialize the default static sort lists
- ** Note that DefaultStaticSortLists[0] is unused.
- */
- DefaultStaticSortLists = W3DNEWARRAY RefRenderObjListClass[MAX_SORT_LEVEL + 1];
- Reset_Current_Static_Sort_Lists_To_Default();
- IsInitted = true;
- return WW3D_ERROR_OK;
- }
- /***********************************************************************************************
- * WW3D::Shutdown -- shutdown the WW3D Library *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/24/98 GTH : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Shutdown(void)
- {
- assert(IsInitted == true);
- // WWDEBUG_SAY(("WW3D::Shutdown\n"));
- #ifdef WW3D_DX8
- if (IsCapturing) {
- Stop_Movie_Capture();
- }
- #endif //WW3D_DX8
- //restore the previous timer resolution
- MMRESULT r=timeEndPeriod(1);
- WWASSERT(r==TIMERR_NOERROR);
- /*
- ** Free memory in predictive LOD optimizer
- */
- PredictiveLODOptimizerClass::Free();
- /*
- ** Free the DazzleRenderObject class stuff. Whatever it is. ST - 6/11/2001 8:20PM
- */
- DazzleRenderObjClass::Deinit ();
- /*
- ** Release all of our assets
- */
- Release_Debug_Resources();
- if (WW3DAssetManager::Get_Instance()) {
- WW3DAssetManager::Get_Instance()->Free_Assets();
- }
- DX8TextureManagerClass::Shutdown();
- DX8Wrapper::Shutdown();
- /*
- ** Clear the default static sort lists
- */
- delete [] DefaultStaticSortLists;
- IsInitted = false;
- return WW3D_ERROR_OK;
- }
- /***********************************************************************************************
- * WW3D::Set_Render_Device -- set the render device being currently used *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/24/98 GTH : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Set_Render_Device( const char * dev_name, int width, int height, int bits, int windowed, bool resize_window )
- {
- bool success = DX8Wrapper::Set_Render_Device(dev_name,width,height,bits,windowed,resize_window);
- if (success) {
- return WW3D_ERROR_OK;
- } else {
- return WW3D_ERROR_INITIALIZATION_FAILED;
- }
- }
- /***********************************************************************************************
- * WW3D::Set_Any_Render_Device -- set any render device you can find *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/24/98 GTH : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Set_Any_Render_Device( void )
- {
- bool success = DX8Wrapper::Set_Any_Render_Device();
- if (success) {
- return WW3D_ERROR_OK;
- } else {
- return WW3D_ERROR_INITIALIZATION_FAILED;
- }
- }
- /***********************************************************************************************
- * WW3D::Set_Render_Device -- set the render device being currently used *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/24/98 GTH : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Set_Render_Device(int dev, int width, int height, int bits, int windowed, bool resize_window, bool reset_device, bool restore_assets )
- {
- bool success = DX8Wrapper::Set_Render_Device(dev,width,height,bits,windowed,resize_window,reset_device, restore_assets );
- if (success) {
- return WW3D_ERROR_OK;
- } else {
- return WW3D_ERROR_INITIALIZATION_FAILED;
- }
- }
- /***********************************************************************************************
- * WW3D::Set_Next_Render_Device -- just go to the next device in the list *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/26/98 GTH : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Set_Next_Render_Device(void)
- {
- bool success = DX8Wrapper::Set_Next_Render_Device();
- if (success) {
- return WW3D_ERROR_OK;
- } else {
- return WW3D_ERROR_INITIALIZATION_FAILED;
- }
- }
- /***********************************************************************************************
- * WW3D::Get_Window -- returns the handle of the render window. *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/28/2001 pds : Created. *
- *=============================================================================================*/
- void *WW3D::Get_Window( void )
- {
- return _Hwnd;
- }
- /***********************************************************************************************
- * WW3D::Is_Windowed -- returns wether we are currently in a windowed mode *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/26/2001 gth : Created. *
- *=============================================================================================*/
- bool WW3D::Is_Windowed( void )
- {
- return DX8Wrapper::Is_Windowed();
- }
- /***********************************************************************************************
- * WW3D::Toggle_Windowed -- Toggle the current render device between fullscreen and windowed *
- * mode. Note: Its called '_Windowed' to be consistent with the *
- * other references inside WW3D, a more descriptive name would *
- * be Toggle_Fullscreen. *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 1/11/99 PDS : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Toggle_Windowed (void)
- {
- bool success = DX8Wrapper::Toggle_Windowed();
- if (success) {
- return WW3D_ERROR_OK;
- } else {
- return WW3D_ERROR_INITIALIZATION_FAILED;
- }
- }
- /***********************************************************************************************
- * WW3D::Get_Render_Device -- Get the index of the current render device *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/24/98 GTH : Created. *
- * 1/25/2001 gth : converted to dx8 *
- *=============================================================================================*/
- int WW3D::Get_Render_Device(void)
- {
- return DX8Wrapper::Get_Render_Device();
- }
- /***********************************************************************************************
- * WW3D::Get_Render_Device_Desc -- returns description of the current render device *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/26/98 GTH : Created. *
- * 1/25/2001 gth : converted to dx8 *
- *=============================================================================================*/
- const RenderDeviceDescClass & WW3D::Get_Render_Device_Desc(int deviceidx)
- {
- return DX8Wrapper::Get_Render_Device_Desc(deviceidx);
- }
- /***********************************************************************************************
- * WW3D::Get_Render_Device_Count -- returns the number of render devices available *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- * 1/25/2001 gth : converted to DX8 *
- *=============================================================================================*/
- const int WW3D::Get_Render_Device_Count(void)
- {
- return DX8Wrapper::Get_Render_Device_Count();
- }
- /***********************************************************************************************
- * WW3D::Get_Render_Device_Name -- returns the name of the n-th render device *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- * 1/25/2001 gth : converted to dx8 *
- *=============================================================================================*/
- const char * WW3D::Get_Render_Device_Name(int device_index)
- {
- return DX8Wrapper::Get_Render_Device_Name(device_index);
- }
- /***********************************************************************************************
- * WW3D::Set_Device_Resolution -- set the current resolution and bitdepth *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/24/98 GTH : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Set_Device_Resolution(int width,int height,int bits,int windowed, bool resize_window)
- {
- bool success = DX8Wrapper::Set_Device_Resolution(width,height,bits,windowed,resize_window);
- if (success) {
- return WW3D_ERROR_OK;
- } else {
- return WW3D_ERROR_INITIALIZATION_FAILED;
- }
- }
- /***********************************************************************************************
- * WW3D::Get_Render_Target_Resolution -- get the resolution and bitdepth of the current target *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/24/98 GTH : Created. *
- * 1/25/2001 gth : converted to dx8 *
- *=============================================================================================*/
- void WW3D::Get_Render_Target_Resolution(int & set_w,int & set_h,int & set_bits,bool & set_windowed)
- {
- DX8Wrapper::Get_Render_Target_Resolution(set_w,set_h,set_bits,set_windowed);
- }
- /***********************************************************************************************
- * WW3D::Get_Device_Resolution -- get the current resolution and bitdepth *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/24/98 GTH : Created. *
- * 1/25/2001 gth : converted to dx8 *
- *=============================================================================================*/
- void WW3D::Get_Device_Resolution(int & set_w,int & set_h,int & set_bits,bool & set_windowed)
- {
- DX8Wrapper::Get_Device_Resolution(set_w,set_h,set_bits,set_windowed);
- }
- /***********************************************************************************************
- * WW3D::Registry_Save_Render_Device -- Saves settings to Registry
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 12/3/98 BMG : Created. *
- * 1/25/2001 gth : converted to dx8 *
- *=============================================================================================*/
- WW3DErrorType WW3D::Registry_Save_Render_Device( const char * sub_key )
- {
- bool success = DX8Wrapper::Registry_Save_Render_Device(sub_key);
- if (success) {
- return WW3D_ERROR_OK;
- } else {
- return WW3D_ERROR_INITIALIZATION_FAILED;
- }
- }
- /***********************************************************************************************
- * WW3D::Registry_Save_Render_Device -- Saves settings to Registry
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 12/3/98 BMG : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Registry_Save_Render_Device( const char *sub_key, int device, int width, int height, int depth, bool windowed, int texture_depth )
- {
- bool success = DX8Wrapper::Registry_Save_Render_Device(sub_key,device,width,height,depth,windowed,texture_depth);
- if (success) {
- return WW3D_ERROR_OK;
- } else {
- return WW3D_ERROR_INITIALIZATION_FAILED;
- }
- }
- /***********************************************************************************************
- * WW3D::Registry_Load_Render_Device -- Loads settings from Registry
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 12/3/98 BMG : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Registry_Load_Render_Device( const char * sub_key, bool resize_window )
- {
- bool success = DX8Wrapper::Registry_Load_Render_Device(sub_key,resize_window);
- if (success) {
- return WW3D_ERROR_OK;
- } else {
- return WW3D_ERROR_INITIALIZATION_FAILED;
- }
- }
- 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)
- {
- return DX8Wrapper::Registry_Load_Render_Device(sub_key,device,device_len,width,height,depth,windowed,texture_depth);
- }
- void WW3D::_Invalidate_Mesh_Cache()
- {
- TheDX8MeshRenderer.Invalidate();
- }
- void WW3D::_Invalidate_Textures()
- {
- TextureLoader::Flush_Pending_Load_Tasks();
- HashTemplateIterator<StringClass,TextureClass*> ite(WW3DAssetManager::Get_Instance()->Texture_Hash());
- // Loop through all the textures in the manager
- for (ite.First();!ite.Is_Done();ite.Next()) {
- // Get the current texture
- TextureClass* tex=ite.Peek_Value();
- tex->Invalidate();
- }
- }
- /***********************************************************************************************
- * WW3D::Begin_Render -- mark the start of rendering for a new frame *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/24/98 GTH : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Begin_Render(bool clear,bool clearz,const Vector3 & color, float dest_alpha)
- {
- WWPROFILE("WW3D::Begin_Render");
- WWASSERT(IsInitted);
- HRESULT hr;
- if (DX8Wrapper::_Get_D3D_Device8() && (hr=DX8Wrapper::_Get_D3D_Device8()->TestCooperativeLevel()) != D3D_OK)
- {
- // If the device was lost, do not render until we get it back
- if( D3DERR_DEVICELOST == hr )
- return WW3D_ERROR_GENERIC; //other app has the device
- // Check if the device needs to be reset
- if( D3DERR_DEVICENOTRESET == hr )
- {
- DX8Wrapper::Reset_Device();
- }
- return WW3D_ERROR_GENERIC;
- }
- // Memory allocation statistics
- LastFrameMemoryAllocations=WWMemoryLogClass::Get_Allocate_Count();
- LastFrameMemoryFrees=WWMemoryLogClass::Get_Free_Count();
- WWMemoryLogClass::Reset_Counters();
- TextureLoader::Update();
- // TextureClass::_Reset_Time_Stamp();
- DynamicVBAccessClass::_Reset(true);
- DynamicIBAccessClass::_Reset(true);
- #ifdef WW3D_DX8
- TextureFileClass::Update_Texture_Flash();
- #endif //WW3D_DX8
- Debug_Statistics::Begin_Statistics();
- if (IsCapturing && (!PauseRecord || RecordNextFrame)) {
- Update_Movie_Capture();
- RecordNextFrame = false;
- }
- WWASSERT(!IsRendering);
- IsRendering = true;
- // If we want to clear the screen, we need to set the viewport to include the entire screen:
- if (clear || clearz) {
- D3DVIEWPORT8 vp;
- int width, height, bits;
- bool windowed;
- WW3D::Get_Render_Target_Resolution(width, height, bits, windowed);
- vp.X = 0;
- vp.Y = 0;
- vp.Width = width;
- vp.Height = height;
- vp.MinZ = 0.0f;;
- vp.MaxZ = 1.0f;
- DX8Wrapper::Set_Viewport(&vp);
- DX8Wrapper::Clear(clear, clearz, color, dest_alpha);
- }
- // Notify D3D that we are beginning to render the frame
- DX8Wrapper::Begin_Scene();
- return WW3D_ERROR_OK;
- }
- /***********************************************************************************************
- * WW3D::Render -- Render a list of layers, starting at the back. *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 4/2/98 EHC : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Render(const LayerListClass &LayerList)
- {
- WWASSERT(IsRendering);
- LayerClass *layer = LayerList.Last();
- while (layer->Is_Valid()) {
- WW3DErrorType result = Render(*layer);
- if (result != WW3D_ERROR_OK) {
- return result;
- }
- layer = layer->Prev();
- }
- return WW3D_ERROR_OK;
- }
- /***********************************************************************************************
- * WW3D::Render -- Render a Layer *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 4/2/98 EHC : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Render(const LayerClass &Layer)
- {
- WWASSERT(IsRendering);
- return Render(Layer.Scene, Layer.Camera, Layer.Clear, Layer.ClearZ, Layer.ClearColor);
- }
- /***********************************************************************************************
- * WW3D::Render -- Render a 3D Scene using the given camera *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/24/98 GTH : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Render(SceneClass * scene,CameraClass * cam,bool clear,bool clearz,const Vector3 & color)
- {
- WWPROFILE("WW3D::Render");
- WWMEMLOG(MEM_GAMEDATA);
- WWASSERT(IsInitted);
- WWASSERT(IsRendering);
- WWASSERT(scene);
- WWASSERT(cam);
- cam->On_Frame_Update();
- RenderInfoClass rinfo(*cam);
- // Apply the camera and viewport (including depth range)
- cam->Apply();
- // Clear the viewport
- if (clear || clearz) {
- DX8Wrapper::Clear(clear, clearz, color);
- }
- // set the rendering mode
- switch(scene->Get_Polygon_Mode()) {
- case SceneClass::POINT:
- DX8Wrapper::Set_DX8_Render_State(D3DRS_FILLMODE,D3DFILL_POINT);
- break;
- case SceneClass::LINE:
- DX8Wrapper::Set_DX8_Render_State(D3DRS_FILLMODE,D3DFILL_WIREFRAME);
- break;
- case SceneClass::FILL:
- DX8Wrapper::Set_DX8_Render_State(D3DRS_FILLMODE,D3DFILL_SOLID);
- break;
- }
- // Set the global ambient light value here. If the scene is using the LightEnvironment system
- // this setting will get overriden.
- Vector3 ambient = scene->Get_Ambient_Light();
- DX8Wrapper::Set_DX8_Render_State(D3DRS_AMBIENT, DX8Wrapper::Convert_Color(ambient,0.0f));
- // render the scene
- TheDX8MeshRenderer.Set_Camera(&rinfo.Camera);
- scene->Render(rinfo);
- Flush(rinfo);
- return WW3D_ERROR_OK;
- }
- /***********************************************************************************************
- * WW3D::Render -- Render a single render object *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 4/4/2001 gth : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::Render(
- RenderObjClass & obj,
- RenderInfoClass & rinfo
- )
- {
- WWPROFILE("WW3D::Render");
- WWASSERT(IsInitted);
- WWASSERT(IsRendering);
- {
- WWPROFILE("On_Frame_Update");
- rinfo.Camera.On_Frame_Update();
- }
- // Apply the camera and viewport (including depth range)
- rinfo.Camera.Apply();
- // set the rendering mode
- DX8Wrapper::Set_DX8_Render_State(D3DRS_FILLMODE,D3DFILL_SOLID);
- // Install the lighting environment if one is supplied
- if (rinfo.light_environment != NULL) {
- DX8Wrapper::Set_Light_Environment(rinfo.light_environment);
- }
- // Render the object
- TheDX8MeshRenderer.Set_Camera(&rinfo.Camera);
- obj.Render(rinfo);
- Flush(rinfo);
- return WW3D_ERROR_OK;
- }
- /***********************************************************************************************
- * WW3D::Flush -- Process all pending rendering tasks *
- * *
- * NOTE: This normally happens AUTOMATICALLY. The user should almost *NEVER* have to call *
- * this function. Anyway, this function causes all of the deferred rendering systems to *
- * actually perform all of their rendering tasks. This includes the DX8MeshRenderer and *
- * the sorting system. *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * Don't call this unless you know what you're doing *
- * *
- * HISTORY: *
- * 4/17/2001 gth : Created. *
- *=============================================================================================*/
- void WW3D::Flush(RenderInfoClass & rinfo)
- {
- TheDX8MeshRenderer.Flush();
- WW3D::Render_And_Clear_Static_Sort_Lists(rinfo); //draws things like water
- SortingRendererClass::Flush();
- TheDX8MeshRenderer.Clear_Pending_Delete_Lists();
- }
- /***********************************************************************************************
- * WW3D::End_Render -- Mark the completion of a frame *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/24/98 GTH : Created. *
- *=============================================================================================*/
- WW3DErrorType WW3D::End_Render(bool flip_frame)
- {
- WWPROFILE("WW3D::End_Render");
- assert(IsRendering);
- assert(IsInitted);
- // If sorting renderer flush isn't called from within any of the render functions
- // the sorting arrays will overflow!
- SortingRendererClass::Flush();
- IsRendering = false;
- DX8Wrapper::End_Scene(flip_frame);
- FrameCount++;
- Debug_Statistics::End_Statistics();
- Activate_Snapshot(false);
- return WW3D_ERROR_OK;
- }
- /***********************************************************************************************
- * WW3D::Flip_To_Primary *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 6/20/01 DEL : Created. *
- *=============================================================================================*/
- void WW3D::Flip_To_Primary(void)
- {
- DX8Wrapper::Flip_To_Primary();
- }
- /***********************************************************************************************
- * WW3D::Get_Last_Frame_Poly_Count -- returns the number of polys submitted in the previous fr *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/28/99 GTH : Created. *
- *=============================================================================================*/
- unsigned int WW3D::Get_Last_Frame_Poly_Count(void)
- {
- return Debug_Statistics::Get_DX8_Polygons();
- }
- unsigned int WW3D::Get_Last_Frame_Vertex_Count(void)
- {
- return Debug_Statistics::Get_DX8_Vertices();
- }
- /***********************************************************************************************
- * WW3D::Sync -- Time sychronization *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/24/98 GTH : Created. *
- *=============================================================================================*/
- void WW3D::Sync(unsigned int sync_time)
- {
- PreviousSyncTime = SyncTime;
- SyncTime = sync_time;
- }
- /***********************************************************************************************
- * WW3D::Set_Ext_Swap_Interval -- Sets the swap interval the device should aim sync for. *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: Not supported by all rendering devices. *
- * *
- * HISTORY: *
- * 5/07/98 NH : Created. *
- *=============================================================================================*/
- void WW3D::Set_Ext_Swap_Interval(long swap)
- {
- DX8Wrapper::Set_Swap_Interval(swap);
- }
- /***********************************************************************************************
- * WW3D::Get_Ext_Swap_Interval -- Queries the swap interval the device is aiming sync for. *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: Not supported by all rendering devices. *
- * *
- * HISTORY: *
- * 5/07/98 NH : Created. *
- *=============================================================================================*/
- long WW3D::Get_Ext_Swap_Interval(void)
- {
- return DX8Wrapper::Get_Swap_Interval();
- }
- /***********************************************************************************************
- * WW3D::Set_Collision_Box_Display_Mask -- control rendering of collision boxes *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 3/17/99 GTH : Created. *
- *=============================================================================================*/
- void WW3D::Set_Collision_Box_Display_Mask(int mask)
- {
- BoxRenderObjClass::Set_Box_Display_Mask(mask);
- }
- /***********************************************************************************************
- * WW3D::Get_Collision_Box_Display_Mask -- returns the current display mask for collision boxe *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 6/1/99 GTH : Created. *
- *=============================================================================================*/
- int WW3D::Get_Collision_Box_Display_Mask(void)
- {
- return BoxRenderObjClass::Get_Box_Display_Mask();
- }
- /***********************************************************************************************
- * WW3D::Normalize_Coordinates -- Convert pixel coords to normalized screen coords 0..1 *
- * *
- * *
- * *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/27/99 EHC : Created. *
- *=============================================================================================*/
- void WW3D::Normalize_Coordinates(int x, int y, float &fx, float &fy)
- {
- // clip the coordinates back into the resolution of the screen
- x = Bound(x, 0, DX8Wrapper::Get_Device_Resolution_Width());
- y = Bound(y, 0, DX8Wrapper::Get_Device_Resolution_Height());
- // now that the coordinates are clipped convert them to their normalized values.
- fx = (float)x / DX8Wrapper::Get_Device_Resolution_Width();
- fy = (float)y / DX8Wrapper::Get_Device_Resolution_Height();
- }
- /***********************************************************************************************
- * WW3D::Make_Screen_Shot -- saves a screenshot with the given base filename *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- * 2/26/2001 hy : Updated to DX8 *
- *=============================================================================================*/
- void WW3D::Make_Screen_Shot( const char * filename_base )
- {
- WWASSERT(!IsRendering);
- char filename[80];
- static int frame_number = 1;
- bool done = false;
- while (!done) {
- sprintf( filename, "%s%.2d.tga", filename_base, frame_number++);
- FileClass*file=_TheFileFactory->Get_File( filename );
- if ( file ) {
- file->Open();
- done = !file->Is_Available();
- _TheFileFactory->Return_File( file );
- } else {
- done = true;
- }
- }
- WWDEBUG_SAY(( "Creating Screen Shot %s\n", filename ));
- // Lock front buffer and copy
- IDirect3DSurface8 *fb;
- fb=DX8Wrapper::_Get_DX8_Front_Buffer();
- D3DSURFACE_DESC desc;
- fb->GetDesc(&desc);
- RECT bounds;
- GetWindowRect(_Hwnd,&bounds);
- D3DLOCKED_RECT lrect;
- DX8_ErrorCode(fb->LockRect(&lrect,&bounds,D3DLOCK_READONLY));
- unsigned int x,y,index,index2,width,height;
- width=bounds.right-bounds.left;
- height=bounds.bottom-bounds.top;
- char *image=W3DNEWARRAY char[3*width*height];
- for (y=0; y<height; y++)
- {
- for (x=0; x<width; x++)
- {
- // index for image
- index=3*(x+y*width);
- // index for fb
- index2=y*lrect.Pitch+4*x;
- image[index]=*((char *) lrect.pBits + index2+2);
- image[index+1]=*((char *) lrect.pBits + index2+1);
- image[index+2]=*((char *) lrect.pBits + index2+0);
- }
- }
- fb->Release();
- Targa targ;
- memset(&targ.Header,0,sizeof(targ.Header));
- targ.Header.Width=width;
- targ.Header.Height=height;
- targ.Header.PixelDepth=24;
- targ.Header.ImageType=TGA_TRUECOLOR;
- targ.SetImage(image);
- targ.YFlip();
- RawFileClass*file=(RawFileClass*)_TheWritingFileFactory->Get_File( filename );
- if ( file ) {
- file->Create();
- file->Close();
- _TheWritingFileFactory->Return_File( file );
- }
- targ.Save(filename,TGAF_IMAGE,false);
- delete [] image;
- }
- /***********************************************************************************************
- * WW3D::Start_Movie_Capture -- begins dumping frames to a movie *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- * 2/26/2001 hy : updated to dx8 *
- *=============================================================================================*/
- void WW3D::Start_Movie_Capture( const char * filename_base, float frame_rate )
- {
- #ifdef _WINDOWS
- if (IsCapturing) {
- Stop_Movie_Capture();
- }
- WWASSERT( !IsCapturing);
- IsCapturing = true;
- RECT bounds;
- GetWindowRect(_Hwnd,&bounds);
- int height=bounds.bottom-bounds.top;
- int width=bounds.right-bounds.left;
- int depth=24;
- WWASSERT( Movie == NULL);
- if (frame_rate == 0.0f) {
- frame_rate = 1.0f;
- PauseRecord = true;
- } else {
- PauseRecord = false;
- }
- Movie = W3DNEW FrameGrabClass( filename_base, FrameGrabClass::AVI, width, height, depth, frame_rate);
- WWDEBUG_SAY(( "Starting Movie %s\n", filename_base ));
- #endif
- }
- /***********************************************************************************************
- * WW3D::Stop_Movie_Capture -- ends dumping frames to a movie *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- *=============================================================================================*/
- void WW3D::Stop_Movie_Capture( void )
- {
- #ifdef _WINDOWS
- if (IsCapturing) {
- IsCapturing = false;
- WWDEBUG_SAY(( "Stoping Movie\n" ));
- WWASSERT( Movie != NULL);
- delete Movie;
- Movie = NULL;
- }
- #endif
- }
- /***********************************************************************************************
- * WW3D::Toggle_Movie_Capture -- toggles movie capture... *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- *=============================================================================================*/
- void WW3D::Toggle_Movie_Capture( const char * filename_base, float frame_rate )
- {
- if (IsCapturing) {
- Stop_Movie_Capture();
- } else {
- Start_Movie_Capture( filename_base, frame_rate);
- }
- }
- /***********************************************************************************************
- * WW3D::Start_Single_Frame_Movie_Capture -- starts capturing a single frame movie *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- *=============================================================================================*/
- void WW3D::Start_Single_Frame_Movie_Capture(const char *filename_base)
- {
- Start_Movie_Capture(filename_base, 0.0f);
- }
- /***********************************************************************************************
- * WW3D::Capture_Next_Movie_Frame -- tells ww3d to grab another frame for the movie *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- *=============================================================================================*/
- void WW3D::Capture_Next_Movie_Frame()
- {
- RecordNextFrame = true;
- }
- /***********************************************************************************************
- * WW3D::Pause_Movie -- pauses/unpauses movie capturing *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- *=============================================================================================*/
- void WW3D::Pause_Movie(bool mode)
- {
- PauseRecord = mode;
- }
- /***********************************************************************************************
- * WW3D::Is_Movie_Paused -- returns whether the movie capture system is paused *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- *=============================================================================================*/
- bool WW3D::Is_Movie_Paused()
- {
- return PauseRecord;
- }
- /***********************************************************************************************
- * WW3D::Is_Recording_Next_Frame -- returns whether the next frame will be dumped to a movie *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- *=============================================================================================*/
- bool WW3D::Is_Recording_Next_Frame()
- {
- return (Movie != 0) && (!PauseRecord || RecordNextFrame);
- }
- /***********************************************************************************************
- * WW3D::Is_Movie_Ready -- returns whether the movie capture system is ready *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- *=============================================================================================*/
- bool WW3D::Is_Movie_Ready()
- {
- return Movie != 0;
- }
- /***********************************************************************************************
- * WW3D::Update_Movie_Capture -- dumps the current frame into the movie *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- * 2/26/2001 hy : Updated to dx8 *
- *=============================================================================================*/
- void WW3D::Update_Movie_Capture( void )
- {
- #ifdef _WINDOWS
- WWASSERT( IsCapturing);
- WWPROFILE("WW3D::Update_Movie_Capture");
- WWDEBUG_SAY(( "Updating\n"));
- // Lock front buffer and copy
- IDirect3DSurface8 *fb;
- fb=DX8Wrapper::_Get_DX8_Front_Buffer();
- D3DSURFACE_DESC desc;
- fb->GetDesc(&desc);
- RECT bounds;
- GetWindowRect(_Hwnd,&bounds);
- D3DLOCKED_RECT lrect;
- DX8_ErrorCode(fb->LockRect(&lrect,&bounds,D3DLOCK_READONLY));
- unsigned int x,y,index,index2,width,height;
- width=bounds.right-bounds.left;
- height=bounds.bottom-bounds.top;
- char *image=(char *)Movie->GetBuffer();
- for (y=0; y<height; y++)
- {
- for (x=0; x<width; x++)
- {
- // index for image
- index=3*(x+(height-y-1)*width);
- // index for fb
- index2=y*lrect.Pitch+4*x;
- image[index]=*((char *) lrect.pBits + index2+0);
- image[index+1]=*((char *) lrect.pBits + index2+1);
- image[index+2]=*((char *) lrect.pBits + index2+2);
- }
- }
- fb->Release();
- Movie->Grab(image);
- #endif
- }
- /***********************************************************************************************
- * WW3D::Get_Movie_Capture_Frame_Rate -- returns the framerate at which the movie is being cap *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- *=============================================================================================*/
- float WW3D::Get_Movie_Capture_Frame_Rate( void )
- {
- #ifdef _WINDOWS
- if (IsCapturing) {
- return Movie->GetFrameRate();
- }
- #endif
- return 0;
- }
- /***********************************************************************************************
- * WW3D::Set_Texture_Reduction -- sets the (hacky) texture reduction factor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 5/19/99 GTH : Created. *
- *=============================================================================================*/
- void WW3D::Set_Texture_Reduction( int value, int min_mip_levels )
- {
- _TextureReduction=value;
- _TextureMinMipLevels=min_mip_levels;
- _Invalidate_Textures();
- }
- void WW3D::Enable_Texturing(bool b)
- {
- if (b==IsTexturingEnabled) return;
- IsTexturingEnabled=b;
- // _Invalidate_Textures();
- }
- void WW3D::Enable_Coloring(unsigned int color)
- {
- IsColoringEnabled = color;
- }
- /***********************************************************************************************
- * WW3D::Get_Texture_Reduction -- gets the (hacky) texture reduction factor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 11/25/99 TSS : Created. *
- *=============================================================================================*/
- int WW3D::Get_Texture_Reduction( void )
- {
- return _TextureReduction;
- }
- /***********************************************************************************************
- * WW3D::Get_Texture_Min_Mip_Levels -- gets the minimum number of mip levels permitted *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 11/25/99 TSS : Created. *
- *=============================================================================================*/
- int WW3D::Get_Texture_Min_Mip_Levels( void )
- {
- return _TextureMinMipLevels;
- }
- /***********************************************************************************************
- * WW3D::Peek_Default_Debug_Material -- returns a pointer to the default debug mtl *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/21/99 GTH : Created. *
- *=============================================================================================*/
- VertexMaterialClass * WW3D::Peek_Default_Debug_Material(void)
- {
- #ifdef WWDEBUG
- WWASSERT(DefaultDebugMaterial);
- return DefaultDebugMaterial;
- #else
- return NULL;
- #endif
- }
- /***********************************************************************************************
- * WW3D::Peek_Default_Debug_Shader -- returns the default shader for debugging. *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/21/99 GTH : Created. *
- *=============================================================================================*/
- ShaderClass WW3D::Peek_Default_Debug_Shader(void)
- {
- return DefaultDebugShader;
- }
- /***********************************************************************************************
- * WW3D::Peek_Lightmap_Debug_Shader -- returns the shader for lightmap debugging. *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/21/99 GTH : Created. *
- *=============================================================================================*/
- ShaderClass WW3D::Peek_Lightmap_Debug_Shader(void)
- {
- return LightmapDebugShader;
- }
- /***********************************************************************************************
- * WW3D::Allocate_Debug_Resources -- allocates the debug resources *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/21/99 GTH : Created. *
- *=============================================================================================*/
- void WW3D::Allocate_Debug_Resources(void)
- {
- #ifdef WWDEBUG
- WWASSERT(DefaultDebugMaterial == NULL);
- DefaultDebugMaterial = W3DNEW VertexMaterialClass;
- DefaultDebugMaterial->Set_Shininess(0.0f);
- DefaultDebugMaterial->Set_Opacity(1.0f);
- DefaultDebugMaterial->Set_Ambient(0,0,0);
- DefaultDebugMaterial->Set_Diffuse(0,0,0);
- DefaultDebugMaterial->Set_Specular(0,0,0);
- DefaultDebugMaterial->Set_Emissive(0,0,0);
- #endif
- }
- /***********************************************************************************************
- * WW3D::Release_Debug_Resources -- releases the debug resources *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/21/99 GTH : Created. *
- *=============================================================================================*/
- void WW3D::Release_Debug_Resources(void)
- {
- #ifdef WWDEBUG
- WWASSERT(DefaultDebugMaterial);
- REF_PTR_RELEASE(DefaultDebugMaterial);
- #endif
- }
- WW3DErrorType WW3D::On_Deactivate_App(void)
- {
- #ifdef WW3D_DX8
- assert(!IsRendering);
- if ( Gerd == NULL )
- return WW3D_ERROR_OK;
- if ( IsWindowed )
- return WW3D_ERROR_OK;
- if ( !Gerd->isWindowOpen() )
- return WW3D_ERROR_OK;
- Gerd->closeWindow();
- #endif //WW3D_DX8
- return WW3D_ERROR_OK;
- }
- WW3DErrorType WW3D::On_Activate_App(void)
- {
- #ifdef WW3D_DX8
- if ( Gerd == NULL)
- return WW3D_ERROR_OK;
- if ( IsWindowed )
- return WW3D_ERROR_OK;
- assert( !Gerd->isWindowOpen() );
- srGERD::DisplayMode disp_mode;
- disp_mode = Gerd->getDisplayMode(ResolutionWidth,ResolutionHeight,BitDepth);
- if (Gerd->openWindow(disp_mode) != srGERD::ERROR_NONE) {
- return WW3D_ERROR_WINDOW_NOT_OPEN;
- }
- #endif //WW3D_DX8
- return WW3D_ERROR_OK;
- }
- void WW3D::Get_Pixel_Center(float &x, float &y)
- {
- x = PixelCenterX; y = PixelCenterY;
- }
- void WW3D::Update_Pixel_Center(void)
- {
- #ifdef WW3D_DX8
- const char *name = _RenderDeviceShortNameTable.getString(CurRenderDevice);
- if ( strstr(name, "OpenGL") ) {
- PixelCenterX = 0.0f; PixelCenterY = 0.0f;
- } else if ( strstr(name, "Glide") ) {
- PixelCenterX = 0.0f; PixelCenterY = 0.0f;
- } else if ( strstr(name, "DirectX") ) {
- PixelCenterX = 0.5f; PixelCenterY = 0.5f;
- } else if ( strstr(name, "Software") ) {
- PixelCenterX = 0.0f; PixelCenterY = 0.0f;
- } else if ( strstr(name, "Null") ) {
- PixelCenterX = 0.0f; PixelCenterY = 0.0f;
- } else {
- // unknown device
- PixelCenterX = 0.0f; PixelCenterY = 0.0f;
- }
- #endif //WW3D_DX8
- }
- void WW3D::Set_Texture_Bitdepth(int bitdepth)
- {
- DX8Wrapper::Set_Texture_Bitdepth(bitdepth);
- }
- int WW3D::Get_Texture_Bitdepth()
- {
- return DX8Wrapper::Get_Texture_Bitdepth();
- }
- void WW3D::Add_To_Static_Sort_List(RenderObjClass *robj, unsigned int sort_level)
- {
- if(sort_level < 1 || sort_level > MAX_SORT_LEVEL) {
- WWASSERT(0);
- return;
- }
- CurrentStaticSortLists[sort_level].Add_Tail(robj, false);
- }
- void WW3D::Render_And_Clear_Static_Sort_Lists(RenderInfoClass & rinfo)
- {
- // The ststic sort lists need to be disabled while we are rendering from them otherwise the
- // Render() function will just dump the objects right back on the same lists.
- bool old_enable = AreStaticSortListsEnabled;
- AreStaticSortListsEnabled = false;
- // We go from higher sort level to lower, since lower sort level means higher priority (in
- // front), so lower sort level meshes need to be rendered later.
- for(unsigned int sort_level = MaxStaticSortLevel; sort_level >= MinStaticSortLevel; sort_level--)
- {
- bool render=false;
- for ( RenderObjClass *robj = CurrentStaticSortLists[sort_level].Remove_Head(); robj;
- robj->Release_Ref(), robj = CurrentStaticSortLists[sort_level].Remove_Head())
- {
- robj->Render(rinfo);
- render=true;
- }
- if (render) TheDX8MeshRenderer.Flush();
- }
- AreStaticSortListsEnabled = old_enable;
- }
- void WW3D::Enable_Sorting(bool onoff)
- {
- IsSortingEnabled = onoff;
- // Have to invalidate mesh rendering system because
- // meshes are put into different fvfs depending on their sort state
- TheDX8MeshRenderer.Invalidate();
- }
- void WW3D::Override_Current_Static_Sort_Lists(RefRenderObjListClass *sort_list, unsigned int min_sort, unsigned int max_sort)
- {
- CurrentStaticSortLists = sort_list;
- if (min_sort <= max_sort) {
- MinStaticSortLevel = min_sort;
- MaxStaticSortLevel = max_sort;
- } else {
- WWASSERT(0);
- MinStaticSortLevel = max_sort;
- MaxStaticSortLevel = min_sort;
- }
- }
- void WW3D::Reset_Current_Static_Sort_Lists_To_Default(void)
- {
- CurrentStaticSortLists = DefaultStaticSortLists;
- MinStaticSortLevel = 1; // The 0 list is not used
- MaxStaticSortLevel = MAX_SORT_LEVEL;
- }
|