gfxDevice.cpp

Engine/source/gfx/gfxDevice.cpp

More...

Classes:

Public Variables

Public Functions

DefineConsoleFunction(ResetGFX , void , () , "forces the gbuffer <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be reinitialized in cases of improper/lack of buffer clears." )
DefineEngineFunction(clearGFXResourceFlags , void , () , "Clears the flagged state on all allocated <a href="/coding/file/gfxdevice_8h/#gfxdevice_8h_1afd23debb5edac4f53e564f02e6964c62">GFX</a> resources. " "See flagCurrentGFXResources <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> usage <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">details.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" "@see flagCurrentGFXResources, listGFXResources , describeGFXResources" )
DefineEngineFunction(describeGFXResources , void , (const char *resourceTypes, const char *filePath, bool unflaggedOnly) , (false) , "@brief Dumps a description of <a href="/coding/file/gfxdevice_8h/#gfxdevice_8h_1afd23debb5edac4f53e564f02e6964c62">GFX</a> resources <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> a <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> or the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">console.\n</a>" "@param resourceTypes A space seperated list of resource types or an empty string <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> all <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">resources.\n</a>" "@param filePath A <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> dump the list <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> or an empty string <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> write <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">console.\n</a>" "@param unflaggedOnly If true only unflagged resources are dumped. See <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">flagCurrentGFXResources.\n</a>" "@note The resource types can be one or more of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">following:\n\n</a>" " - <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">texture\n</a>" " - texture <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">target\n</a>" " - window <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">target\n</a>" " - vertex <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">buffers\n</a>" " - primitive <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">buffers\n</a>" " - <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">fences\n</a>" " - <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cubemaps\n</a>" " - <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">shaders\n</a>" " - <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stateblocks\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )
DefineEngineFunction(describeGFXStateBlocks , void , (const char *filePath) , "Dumps a description of all state <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">blocks.\n</a>" "@param filePath A <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> dump the state blocks <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> or an empty string <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> write <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">console.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )
DefineEngineFunction(flagCurrentGFXResources , void , () , "@brief <a href="/coding/file/d3dx9functions_8h/#d3dx9functions_8h_1a3e6d39690905fb8e4a7f6235a12af940">Flags</a> all currently allocated <a href="/coding/file/gfxdevice_8h/#gfxdevice_8h_1afd23debb5edac4f53e564f02e6964c62">GFX</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">resources.\n</a>" "Used <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> resource allocation and leak tracking by flagging " "current resources then dumping a list of unflagged resources " "at some later point in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">execution.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" "@see listGFXResources, clearGFXResourceFlags , describeGFXResources" )
DefineEngineFunction(getBestHDRFormat , GFXFormat , () , "Returns the best texture format <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> storage of HDR data <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the active <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">device.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )
DefineEngineFunction(getDisplayDeviceInformation , const char * , () , "Get the string describing the active <a href="/coding/file/gfxdevice_8h/#gfxdevice_8h_1afd23debb5edac4f53e564f02e6964c62">GFX</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">device.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )
DefineEngineFunction(getDisplayDeviceList , String , () , "Returns a tab-seperated string of the detected devices across all <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">adapters.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )
DefineEngineFunction(getPixelShaderVersion , F32 , () , "Returns the pixel shader version <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the active <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">device.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )
DefineEngineFunction(listGFXResources , void , (bool unflaggedOnly) , (false) , "Returns a list of the unflagged <a href="/coding/file/gfxdevice_8h/#gfxdevice_8h_1afd23debb5edac4f53e564f02e6964c62">GFX</a> resources. See flagCurrentGFXResources <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> usage <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">details.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" "@see flagCurrentGFXResources, clearGFXResourceFlags , describeGFXResources" )
DefineEngineFunction(setPixelShaderVersion , void , (F32 version) , "@brief Sets the pixel shader version <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the active <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">device.\n</a>" "This can be used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> force a lower pixel shader version than is supported by " "the device <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> testing or performance <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">optimization.\n</a>" "@param version The floating point shader version <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">number.\n</a>" "@note This will only affect shaders/materials created after the call " "and should be used before the game <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">begins.\n</a>" "@see $<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">pref::Video::forcedPixVersion\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )

Detailed Description

Public Variables

bool gDisassembleAllShaders 

Public Functions

DefineConsoleFunction(ResetGFX , void , () , "forces the gbuffer <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be reinitialized in cases of improper/lack of buffer clears." )

DefineEngineFunction(clearGFXResourceFlags , void , () , "Clears the flagged state on all allocated <a href="/coding/file/gfxdevice_8h/#gfxdevice_8h_1afd23debb5edac4f53e564f02e6964c62">GFX</a> resources. " "See flagCurrentGFXResources <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> usage <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">details.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" "@see flagCurrentGFXResources, listGFXResources , describeGFXResources" )

DefineEngineFunction(describeGFXResources , void , (const char *resourceTypes, const char *filePath, bool unflaggedOnly) , (false) , "@brief Dumps a description of <a href="/coding/file/gfxdevice_8h/#gfxdevice_8h_1afd23debb5edac4f53e564f02e6964c62">GFX</a> resources <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> a <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> or the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">console.\n</a>" "@param resourceTypes A space seperated list of resource types or an empty string <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> all <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">resources.\n</a>" "@param filePath A <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> dump the list <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> or an empty string <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> write <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">console.\n</a>" "@param unflaggedOnly If true only unflagged resources are dumped. See <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">flagCurrentGFXResources.\n</a>" "@note The resource types can be one or more of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">following:\n\n</a>" " - <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">texture\n</a>" " - texture <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">target\n</a>" " - window <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">target\n</a>" " - vertex <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">buffers\n</a>" " - primitive <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">buffers\n</a>" " - <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">fences\n</a>" " - <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cubemaps\n</a>" " - <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">shaders\n</a>" " - <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">stateblocks\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )

DefineEngineFunction(describeGFXStateBlocks , void , (const char *filePath) , "Dumps a description of all state <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">blocks.\n</a>" "@param filePath A <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> dump the state blocks <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> or an empty string <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> write <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">console.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )

DefineEngineFunction(flagCurrentGFXResources , void , () , "@brief <a href="/coding/file/d3dx9functions_8h/#d3dx9functions_8h_1a3e6d39690905fb8e4a7f6235a12af940">Flags</a> all currently allocated <a href="/coding/file/gfxdevice_8h/#gfxdevice_8h_1afd23debb5edac4f53e564f02e6964c62">GFX</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">resources.\n</a>" "Used <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> resource allocation and leak tracking by flagging " "current resources then dumping a list of unflagged resources " "at some later point in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">execution.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" "@see listGFXResources, clearGFXResourceFlags , describeGFXResources" )

DefineEngineFunction(getBestHDRFormat , GFXFormat , () , "Returns the best texture format <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> storage of HDR data <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the active <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">device.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )

DefineEngineFunction(getDisplayDeviceInformation , const char * , () , "Get the string describing the active <a href="/coding/file/gfxdevice_8h/#gfxdevice_8h_1afd23debb5edac4f53e564f02e6964c62">GFX</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">device.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )

DefineEngineFunction(getDisplayDeviceList , String , () , "Returns a tab-seperated string of the detected devices across all <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">adapters.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )

DefineEngineFunction(getPixelShaderVersion , F32 , () , "Returns the pixel shader version <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the active <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">device.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )

DefineEngineFunction(listGFXResources , void , (bool unflaggedOnly) , (false) , "Returns a list of the unflagged <a href="/coding/file/gfxdevice_8h/#gfxdevice_8h_1afd23debb5edac4f53e564f02e6964c62">GFX</a> resources. See flagCurrentGFXResources <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> usage <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">details.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" "@see flagCurrentGFXResources, clearGFXResourceFlags , describeGFXResources" )

DefineEngineFunction(setPixelShaderVersion , void , (F32 version) , "@brief Sets the pixel shader version <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the active <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">device.\n</a>" "This can be used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> force a lower pixel shader version than is supported by " "the device <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> testing or performance <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">optimization.\n</a>" "@param version The floating point shader version <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">number.\n</a>" "@note This will only affect shaders/materials created after the call " "and should be used before the game <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">begins.\n</a>" "@see $<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">pref::Video::forcedPixVersion\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFX\n</a>" )

   1
   2//-----------------------------------------------------------------------------
   3// Copyright (c) 2012 GarageGames, LLC
   4//
   5// Permission is hereby granted, free of charge, to any person obtaining a copy
   6// of this software and associated documentation files (the "Software"), to
   7// deal in the Software without restriction, including without limitation the
   8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
   9// sell copies of the Software, and to permit persons to whom the Software is
  10// furnished to do so, subject to the following conditions:
  11//
  12// The above copyright notice and this permission notice shall be included in
  13// all copies or substantial portions of the Software.
  14//
  15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21// IN THE SOFTWARE.
  22//-----------------------------------------------------------------------------
  23
  24#include "platform/platform.h"
  25#include "gfx/gfxDevice.h"
  26
  27#include "gfx/gfxInit.h"
  28#include "gfx/gfxCubemap.h"
  29#include "gfx/primBuilder.h"
  30#include "gfx/gfxDrawUtil.h"
  31#include "gfx/gfxFence.h"
  32#include "gfx/gfxFontRenderBatcher.h"
  33#include "gfx/gfxPrimitiveBuffer.h"
  34#include "gfx/gfxShader.h"
  35#include "gfx/gfxStateBlock.h"
  36#include "gfx/screenshot.h"
  37#include "gfx/gfxStringEnumTranslate.h"
  38#include "gfx/gfxTextureManager.h"
  39
  40#include "core/frameAllocator.h"
  41#include "core/stream/fileStream.h"
  42#include "core/strings/unicode.h"
  43#include "core/util/journal/process.h"
  44#include "core/util/safeDelete.h"
  45#include "math/util/frustum.h"
  46#include "console/consoleTypes.h"
  47#include "console/engineAPI.h"
  48
  49GFXDevice * GFXDevice::smGFXDevice = NULL;
  50bool GFXDevice::smWireframe = false;
  51bool GFXDevice::smDisableVSync = true;
  52F32 GFXDevice::smForcedPixVersion = -1.0f;
  53bool GFXDevice::smDisableOcclusionQuery = false;
  54bool gDisassembleAllShaders = false;
  55
  56
  57void GFXDevice::initConsole()
  58{
  59   GFXStringEnumTranslate::init();
  60
  61   Con::addVariable( "$gfx::wireframe", TypeBool, &smWireframe,
  62      "Used to toggle wireframe rendering at runtime.\n"
  63      "@ingroup GFX\n" );
  64
  65   Con::addVariable( "$gfx::disassembleAllShaders", TypeBool, &gDisassembleAllShaders,
  66      "On supported devices this will dump shader disassembly to the "
  67      "procedural shader folder.\n"
  68      "@ingroup GFX\n" );
  69
  70   Con::addVariable( "$gfx::disableOcclusionQuery", TypeBool, &smDisableOcclusionQuery,
  71      "Debug helper that disables all hardware occlusion queries causing "
  72      "them to return only the visibile state.\n"
  73      "@ingroup GFX\n" );
  74
  75   Con::addVariable( "$pref::Video::disableVerticalSync", TypeBool, &smDisableVSync,
  76      "Disables vertical sync on the active device.\n"
  77      "@note The video mode must be reset for the change to take affect.\n"
  78      "@ingroup GFX\n" );
  79
  80   Con::addVariable( "$pref::Video::forcedPixVersion", TypeF32, &smForcedPixVersion,
  81      "Will force the shader model if the value is positive and less than the "
  82      "shader model supported by the active device.  Use 0 for fixed function.\n"
  83      "@note The graphics device must be reset for the change to take affect.\n"
  84      "@ingroup GFX\n" );
  85}
  86
  87GFXDevice::DeviceEventSignal& GFXDevice::getDeviceEventSignal()
  88{
  89   static DeviceEventSignal theSignal;
  90   return theSignal;
  91}
  92
  93GFXDevice::GFXDevice() 
  94{    
  95   VECTOR_SET_ASSOCIATION( mVideoModes );
  96   VECTOR_SET_ASSOCIATION( mRTStack );
  97
  98   mWorldMatrixDirty = false;
  99   mWorldStackSize = 0;
 100   mProjectionMatrixDirty = false;
 101   mViewMatrixDirty = false;
 102   mTextureMatrixCheckDirty = false;
 103
 104   mViewMatrix.identity();
 105   mProjectionMatrix.identity();
 106   
 107   for( S32 i = 0; i < WORLD_STACK_MAX; i++ )
 108      mWorldMatrix[i].identity();
 109   
 110   AssertFatal(smGFXDevice == NULL, "Already a GFXDevice created! Bad!");
 111   smGFXDevice = this;
 112      
 113   // Vertex buffer cache
 114   mCurrVertexDecl = NULL;
 115   mVertexDeclDirty = false;
 116   for ( U32 i=0; i < VERTEX_STREAM_COUNT; i++ )
 117   {
 118      mVertexBufferDirty[i] = false;
 119      mVertexBufferFrequency[i] = 0;
 120      mVertexBufferFrequencyDirty[i] = false;
 121   }
 122
 123   // Primitive buffer cache
 124   mPrimitiveBufferDirty = false;
 125   mTexturesDirty = false;
 126   
 127   // Use of TEXTURE_STAGE_COUNT in initialization is okay [7/2/2007 Pat]
 128   for(U32 i = 0; i < TEXTURE_STAGE_COUNT; i++)
 129   {
 130      mTextureDirty[i] = false;
 131      mCurrentTexture[i] = NULL;
 132      mNewTexture[i] = NULL;
 133      mCurrentCubemap[i] = NULL;
 134      mNewCubemap[i] = NULL;
 135      mTexType[i] = GFXTDT_Normal;
 136
 137      mTextureMatrix[i].identity();
 138      mTextureMatrixDirty[i] = false;
 139   }
 140
 141   mLightsDirty = false;
 142   for(U32 i = 0; i < LIGHT_STAGE_COUNT; i++)
 143   {
 144      mLightDirty[i] = false;
 145      mCurrentLightEnable[i] = false;
 146   }
 147
 148   mGlobalAmbientColorDirty = false;
 149   mGlobalAmbientColor = ColorF(0.0f, 0.0f, 0.0f, 1.0f);
 150
 151   mLightMaterialDirty = false;
 152   dMemset(&mCurrentLightMaterial, 0, sizeof(GFXLightMaterial));
 153
 154   // State block 
 155   mStateBlockDirty = false;
 156   mCurrentStateBlock = NULL;
 157   mNewStateBlock = NULL;
 158
 159   mCurrentShaderConstBuffer = NULL;
 160
 161   // misc
 162   mAllowRender = true;
 163   mCurrentRenderStyle = RS_Standard;
 164   mCurrentStereoTarget = -1;
 165   mStereoHeadTransform = MatrixF(1);
 166   mCanCurrentlyRender = false;
 167   mInitialized = false;
 168   
 169   mRTDirty = false;
 170   mViewport = RectI::Zero;
 171   mViewportDirty = false;
 172
 173   mCurrentFrontBufferIdx = 0;
 174
 175   mDeviceSwizzle32 = NULL;
 176   mDeviceSwizzle24 = NULL;
 177
 178   mResourceListHead = NULL;
 179
 180   mCardProfiler = NULL;   
 181
 182   // Initialize our drawing utility.
 183   mDrawer = NULL;
 184   mFrameTime = PlatformTimer::create();
 185   // Add a few system wide shader macros.
 186   GFXShader::addGlobalMacro( "TORQUE", "1" );
 187   GFXShader::addGlobalMacro( "TORQUE_VERSION", String::ToString(getVersionNumber()) );
 188   #if defined TORQUE_OS_WIN
 189      GFXShader::addGlobalMacro( "TORQUE_OS_WIN" );
 190   #elif defined TORQUE_OS_MAC
 191      GFXShader::addGlobalMacro( "TORQUE_OS_MAC" );
 192   #elif defined TORQUE_OS_LINUX
 193      GFXShader::addGlobalMacro( "TORQUE_OS_LINUX" );      
 194   #elif defined TORQUE_OS_XENON
 195      GFXShader::addGlobalMacro( "TORQUE_OS_XENON" );
 196   #elif defined TORQUE_OS_XBOX
 197      GFXShader::addGlobalMacro( "TORQUE_OS_XBOX" );      
 198   #elif defined TORQUE_OS_PS3
 199      GFXShader::addGlobalMacro( "TORQUE_OS_PS3" );            
 200   #endif
 201
 202   mStereoTargets[0] = NULL;
 203   mStereoTargets[1] = NULL;
 204}
 205
 206GFXDrawUtil* GFXDevice::getDrawUtil()
 207{
 208   if (!mDrawer)
 209   {
 210      mDrawer = new GFXDrawUtil(this);
 211   }
 212   return mDrawer;
 213}
 214
 215void GFXDevice::deviceInited()
 216{
 217   getDeviceEventSignal().trigger(deInit);
 218   mDeviceStatistics.setPrefix("$GFXDeviceStatistics::");
 219
 220   // Initialize the static helper textures.
 221   GBitmap temp( 2, 2, false, GFXFormatR8G8B8A8 );
 222   temp.fill( ColorI::ONE );
 223   GFXTexHandle::ONE.set( &temp, &GFXDefaultStaticDiffuseProfile, false, "GFXTexHandle::ONE" ); 
 224   temp.fill( ColorI::ZERO );
 225   GFXTexHandle::ZERO.set( &temp, &GFXDefaultStaticDiffuseProfile, false, "GFXTexHandle::ZERO" ); 
 226   temp.fill( ColorI( 128, 128, 255 ) );
 227   GFXTexHandle::ZUP.set( &temp, &GFXDefaultStaticNormalMapProfile, false, "GFXTexHandle::ZUP" ); 
 228}
 229
 230bool GFXDevice::destroy()
 231{
 232   // Cleanup the static helper textures.
 233   GFXTexHandle::ONE.free();
 234   GFXTexHandle::ZERO.free();
 235   GFXTexHandle::ZUP.free();
 236
 237   // Make this release its buffer.
 238   PrimBuild::shutdown();
 239
 240   // Let people know we are shutting down
 241   getDeviceEventSignal().trigger(deDestroy);
 242
 243   if(smGFXDevice)
 244      smGFXDevice->preDestroy();
 245   SAFE_DELETE(smGFXDevice);
 246
 247   return true;
 248}
 249
 250void GFXDevice::preDestroy()
 251{
 252   // Delete draw util
 253   SAFE_DELETE( mDrawer );
 254}
 255
 256GFXDevice::~GFXDevice()
 257{ 
 258   smGFXDevice = NULL;
 259
 260   // Clean up our current buffers.
 261   mCurrentPrimitiveBuffer = NULL;
 262   for ( U32 i=0; i < VERTEX_STREAM_COUNT; i++ )
 263      mCurrentVertexBuffer[i] = NULL;
 264
 265   // Clear out our current texture references
 266   for (U32 i = 0; i < TEXTURE_STAGE_COUNT; i++)
 267   {
 268      mCurrentTexture[i] = NULL;
 269      mNewTexture[i] = NULL;
 270      mCurrentCubemap[i] = NULL;
 271      mNewCubemap[i] = NULL;
 272   }
 273
 274   mCurrentRT = NULL;
 275
 276   // Release all the unreferenced textures in the cache.
 277   mTextureManager->cleanupCache();
 278
 279   // Check for resource leaks
 280#ifdef TORQUE_DEBUG
 281   AssertFatal( GFXTextureObject::dumpActiveTOs() == 0, "There is a texture object leak, check the log for more details." );
 282   GFXPrimitiveBuffer::dumpActivePBs();
 283#endif
 284
 285   SAFE_DELETE( mTextureManager );
 286   SAFE_DELETE( mFrameTime );
 287
 288   // Clear out our state block references
 289   mCurrentStateBlocks.clear();
 290   mNewStateBlock = NULL;
 291   mCurrentStateBlock = NULL;
 292
 293   mCurrentShaderConstBuffer = NULL;
 294   /// End Block above BTR
 295
 296   // -- Clear out resource list
 297   // Note: our derived class destructor will have already released resources.
 298   // Clearing this list saves us from having our resources (which are not deleted
 299   // just released) turn around and try to remove themselves from this list.
 300   while (mResourceListHead)
 301   {
 302      GFXResource * head = mResourceListHead;
 303      mResourceListHead = head->mNextResource;
 304      
 305      head->mPrevResource = NULL;
 306      head->mNextResource = NULL;
 307      head->mOwningDevice = NULL;
 308   }
 309}
 310
 311GFXStateBlockRef GFXDevice::createStateBlock(const GFXStateBlockDesc& desc)
 312{
 313   PROFILE_SCOPE( GFXDevice_CreateStateBlock );
 314
 315   U32 hashValue = desc.getHashValue();
 316   if (mCurrentStateBlocks[hashValue])
 317      return mCurrentStateBlocks[hashValue];
 318
 319   GFXStateBlockRef result = createStateBlockInternal(desc);
 320   result->registerResourceWithDevice(this);   
 321   mCurrentStateBlocks[hashValue] = result;
 322   return result;
 323}
 324
 325void GFXDevice::setStateBlock(GFXStateBlock* block)
 326{
 327   AssertFatal(block, "NULL state block!");
 328   AssertFatal(block->getOwningDevice() == this, "This state doesn't apply to this device!");
 329
 330   if (block != mCurrentStateBlock)
 331   {
 332      mStateDirty = true;
 333      mStateBlockDirty = true;
 334      mNewStateBlock = block;
 335   } else {
 336      mStateBlockDirty = false;
 337      mNewStateBlock = mCurrentStateBlock;
 338   }
 339}
 340
 341void GFXDevice::setStateBlockByDesc( const GFXStateBlockDesc &desc )
 342{
 343   PROFILE_SCOPE( GFXDevice_SetStateBlockByDesc );
 344   GFXStateBlock *block = createStateBlock( desc );
 345   setStateBlock( block );
 346}
 347
 348void GFXDevice::setShaderConstBuffer(GFXShaderConstBuffer* buffer)
 349{
 350   mCurrentShaderConstBuffer = buffer;
 351}
 352
 353void GFXDevice::updateStates(bool forceSetAll /*=false*/)
 354{
 355   PROFILE_SCOPE(GFXDevice_updateStates);
 356
 357   if(forceSetAll)
 358   {
 359      bool rememberToEndScene = false;
 360      if(!canCurrentlyRender())
 361      {
 362         if (!beginScene())
 363         {
 364            AssertFatal(false, "GFXDevice::updateStates:  Unable to beginScene!");
 365         }
 366         rememberToEndScene = true;
 367      }
 368
 369      setMatrix( GFXMatrixProjection, mProjectionMatrix );
 370      setMatrix( GFXMatrixWorld, mWorldMatrix[mWorldStackSize] );
 371      setMatrix( GFXMatrixView, mViewMatrix );
 372
 373      setVertexDecl( mCurrVertexDecl );
 374
 375      for ( U32 i=0; i < VERTEX_STREAM_COUNT; i++ )
 376      {
 377         setVertexStream( i, mCurrentVertexBuffer[i] );
 378         setVertexStreamFrequency( i, mVertexBufferFrequency[i] );
 379      }
 380
 381      if( mCurrentPrimitiveBuffer.isValid() ) // This could be NULL when the device is initalizing
 382         mCurrentPrimitiveBuffer->prepare();
 383
 384      /// Stateblocks
 385      if ( mNewStateBlock )
 386         setStateBlockInternal(mNewStateBlock, true);
 387      mCurrentStateBlock = mNewStateBlock;
 388
 389      for(U32 i = 0; i < getNumSamplers(); i++)
 390      {
 391         switch (mTexType[i])
 392         {
 393            case GFXTDT_Normal :
 394               {
 395                  mCurrentTexture[i] = mNewTexture[i];
 396                  setTextureInternal(i, mCurrentTexture[i]);
 397               }  
 398               break;
 399            case GFXTDT_Cube :
 400               {
 401                  mCurrentCubemap[i] = mNewCubemap[i];
 402                  if (mCurrentCubemap[i])
 403                     mCurrentCubemap[i]->setToTexUnit(i);
 404                  else
 405                     setTextureInternal(i, NULL);
 406               }
 407               break;
 408            default:
 409               AssertFatal(false, "Unknown texture type!");
 410               break;
 411         }
 412      }
 413
 414      // Set our material
 415      setLightMaterialInternal(mCurrentLightMaterial);
 416
 417      // Set our lights
 418      for(U32 i = 0; i < LIGHT_STAGE_COUNT; i++)
 419      {
 420         setLightInternal(i, mCurrentLight[i], mCurrentLightEnable[i]);
 421      }
 422
 423       _updateRenderTargets();
 424
 425      if(rememberToEndScene)
 426         endScene();
 427
 428      return;
 429   }
 430
 431   if (!mStateDirty)
 432      return;
 433
 434   // Normal update logic begins here.
 435   mStateDirty = false;
 436
 437   // Update Projection Matrix
 438   if( mProjectionMatrixDirty )
 439   {
 440      setMatrix( GFXMatrixProjection, mProjectionMatrix );
 441      mProjectionMatrixDirty = false;
 442   }
 443   
 444   // Update World Matrix
 445   if( mWorldMatrixDirty )
 446   {
 447      setMatrix( GFXMatrixWorld, mWorldMatrix[mWorldStackSize] );
 448      mWorldMatrixDirty = false;
 449   }
 450   
 451   // Update View Matrix
 452   if( mViewMatrixDirty )
 453   {
 454      setMatrix( GFXMatrixView, mViewMatrix );
 455      mViewMatrixDirty = false;
 456   }
 457
 458
 459   if( mTextureMatrixCheckDirty )
 460   {
 461      for( S32 i = 0; i < getNumSamplers(); i++ )
 462      {
 463         if( mTextureMatrixDirty[i] )
 464         {
 465            mTextureMatrixDirty[i] = false;
 466            setMatrix( (GFXMatrixType)(GFXMatrixTexture + i), mTextureMatrix[i] );
 467         }
 468      }
 469
 470      mTextureMatrixCheckDirty = false;
 471   }
 472
 473   // Update the vertex declaration.
 474   if ( mVertexDeclDirty )
 475   {
 476      setVertexDecl( mCurrVertexDecl );
 477      mVertexDeclDirty = false;
 478   }
 479
 480   // Update the vertex buffers.
 481   for ( U32 i=0; i < VERTEX_STREAM_COUNT; i++ )
 482   {
 483      if ( mVertexBufferDirty[i] )
 484      {
 485         setVertexStream( i, mCurrentVertexBuffer[i] );
 486         mVertexBufferDirty[i] = false;
 487      }
 488
 489      if ( mVertexBufferFrequencyDirty[i] )
 490      {
 491         setVertexStreamFrequency( i, mVertexBufferFrequency[i] );
 492         mVertexBufferFrequencyDirty[i] = false;
 493      }
 494   }
 495
 496   // Update primitive buffer
 497   //
 498   // NOTE: It is very important to set the primitive buffer AFTER the vertex buffer
 499   // because in order to draw indexed primitives in DX8, the call to SetIndicies
 500   // needs to include the base vertex offset, and the DX8 GFXDevice relies on
 501   // having mCurrentVB properly assigned before the call to setIndices -patw
 502   if( mPrimitiveBufferDirty )
 503   {
 504      if( mCurrentPrimitiveBuffer.isValid() ) // This could be NULL when the device is initalizing
 505         mCurrentPrimitiveBuffer->prepare();
 506      mPrimitiveBufferDirty = false;
 507   }
 508
 509   // NOTE: With state blocks, it's now important to update state before setting textures
 510   // some devices (e.g. OpenGL) set states on the texture and we need that information before
 511   // the texture is activated.
 512   if (mStateBlockDirty)
 513   {
 514      setStateBlockInternal(mNewStateBlock, false);
 515      mCurrentStateBlock = mNewStateBlock;
 516      mStateBlockDirty = false;
 517   }
 518
 519   _updateRenderTargets();
 520
 521   if( mTexturesDirty )
 522   {
 523      mTexturesDirty = false;
 524      for(U32 i = 0; i < getNumSamplers(); i++)
 525      {
 526         if(!mTextureDirty[i])
 527            continue;
 528         mTextureDirty[i] = false;
 529
 530         switch (mTexType[i])
 531         {
 532         case GFXTDT_Normal :
 533            {
 534               mCurrentTexture[i] = mNewTexture[i];
 535               setTextureInternal(i, mCurrentTexture[i]);
 536            }  
 537            break;
 538         case GFXTDT_Cube :
 539            {
 540               mCurrentCubemap[i] = mNewCubemap[i];
 541               if (mCurrentCubemap[i])
 542                  mCurrentCubemap[i]->setToTexUnit(i);
 543               else
 544                  setTextureInternal(i, NULL);
 545            }
 546            break;
 547         default:
 548            AssertFatal(false, "Unknown texture type!");
 549            break;
 550         }
 551      }
 552   }
 553   
 554   // Set light material
 555   if(mLightMaterialDirty)
 556   {
 557      setLightMaterialInternal(mCurrentLightMaterial);
 558      mLightMaterialDirty = false;
 559   }
 560
 561   // Set our lights
 562   if(mLightsDirty)
 563   {
 564      mLightsDirty = false;
 565      for(U32 i = 0; i < LIGHT_STAGE_COUNT; i++)
 566      {
 567         if(!mLightDirty[i])
 568            continue;
 569
 570         mLightDirty[i] = false;
 571         setLightInternal(i, mCurrentLight[i], mCurrentLightEnable[i]);
 572      }
 573   }
 574
 575   _updateRenderTargets();
 576
 577#ifdef TORQUE_DEBUG_RENDER
 578   doParanoidStateCheck();
 579#endif
 580}
 581
 582void GFXDevice::setPrimitiveBuffer( GFXPrimitiveBuffer *buffer )
 583{
 584   if( buffer == mCurrentPrimitiveBuffer )
 585      return;
 586   
 587   mCurrentPrimitiveBuffer = buffer;
 588   mPrimitiveBufferDirty = true;
 589   mStateDirty = true;
 590}
 591
 592void GFXDevice::drawPrimitive( U32 primitiveIndex )
 593{
 594   AssertFatal( mCurrentPrimitiveBuffer.isValid(), "Trying to call drawPrimitive with no current primitive buffer, call setPrimitiveBuffer()" );
 595   AssertFatal( primitiveIndex < mCurrentPrimitiveBuffer->mPrimitiveCount, "Out of range primitive index.");
 596   drawPrimitive( mCurrentPrimitiveBuffer->mPrimitiveArray[primitiveIndex] );
 597}
 598
 599void GFXDevice::drawPrimitive( const GFXPrimitive &prim )
 600{
 601   // Do NOT add index buffer offset to this call, it will be added by drawIndexedPrimitive
 602   drawIndexedPrimitive(   prim.type, 
 603                           prim.startVertex,
 604                           prim.minIndex, 
 605                           prim.numVertices, 
 606                           prim.startIndex, 
 607                           prim.numPrimitives );
 608}
 609
 610void GFXDevice::drawPrimitives()
 611{
 612   AssertFatal( mCurrentPrimitiveBuffer.isValid(), "Trying to call drawPrimitive with no current primitive buffer, call setPrimitiveBuffer()" );
 613
 614   GFXPrimitive *info = NULL;
 615   
 616   for( U32 i = 0; i < mCurrentPrimitiveBuffer->mPrimitiveCount; i++ ) {
 617      info = &mCurrentPrimitiveBuffer->mPrimitiveArray[i];
 618
 619      // Do NOT add index buffer offset to this call, it will be added by drawIndexedPrimitive
 620      drawIndexedPrimitive(   info->type, 
 621                              info->startVertex,
 622                              info->minIndex, 
 623                              info->numVertices, 
 624                              info->startIndex, 
 625                              info->numPrimitives );
 626   }
 627}
 628
 629DefineEngineFunction( getDisplayDeviceList, String, (),,
 630   "Returns a tab-seperated string of the detected devices across all adapters.\n"
 631   "@ingroup GFX\n" )
 632{
 633   Vector<GFXAdapter*> adapters;
 634   GFXInit::getAdapters(&adapters);
 635
 636   StringBuilder str;
 637   for (S32 i=0; i<adapters.size(); i++)
 638   {
 639      if (i)
 640         str.append( '\t' );
 641      str.append(adapters[i]->mName);
 642   }
 643
 644   return str.end();
 645}
 646
 647void GFXDevice::setFrustum(   F32 left, 
 648                              F32 right, 
 649                              F32 bottom, 
 650                              F32 top, 
 651                              F32 nearPlane, 
 652                              F32 farPlane,
 653                              bool bRotate )
 654{
 655   // store values
 656   mFrustum.set(false, left, right, top, bottom, nearPlane, farPlane);
 657   
 658   // compute matrix
 659   MatrixF projection;
 660   mFrustum.getProjectionMatrix(&projection, bRotate);
 661   setProjectionMatrix( projection );
 662}
 663
 664void GFXDevice::setFrustum( const Frustum& frust, bool bRotate )
 665{
 666   // store values
 667   mFrustum = frust;
 668   
 669   // compute matrix
 670   MatrixF projection;
 671   mFrustum.getProjectionMatrix(&projection, bRotate);
 672   setProjectionMatrix( projection );
 673}
 674
 675
 676void GFXDevice::getFrustum( F32 *left, F32 *right, F32 *bottom, F32 *top, F32 *nearPlane, F32 *farPlane, bool *isOrtho ) const
 677{   
 678   if ( left )       *left       = mFrustum.getNearLeft();
 679   if ( right )      *right      = mFrustum.getNearRight();
 680   if ( bottom )     *bottom     = mFrustum.getNearBottom();
 681   if ( top )        *top        = mFrustum.getNearTop();
 682   if ( nearPlane )  *nearPlane  = mFrustum.getNearDist();
 683   if ( farPlane )   *farPlane   = mFrustum.getFarDist();
 684   if ( isOrtho )    *isOrtho    = mFrustum.isOrtho();
 685}
 686
 687void GFXDevice::setOrtho(  F32 left, 
 688                           F32 right, 
 689                           F32 bottom, 
 690                           F32 top, 
 691                           F32 nearPlane, 
 692                           F32 farPlane,
 693                           bool doRotate )
 694{
 695   // store values
 696   mFrustum.set(true, left, right, top, bottom, nearPlane, farPlane);
 697
 698   // compute matrix
 699   MatrixF projection;
 700   mFrustum.getProjectionMatrix(&projection, doRotate);  
 701
 702   setProjectionMatrix( projection );
 703}
 704
 705Point2F GFXDevice::getWorldToScreenScale() const
 706{
 707   Point2F scale;
 708
 709   const RectI &viewport = getViewport();
 710
 711   if ( mFrustum.isOrtho() )
 712      scale.set(  viewport.extent.x / mFrustum.getWidth(),
 713                  viewport.extent.y / mFrustum.getHeight() );
 714   else
 715      scale.set(  ( mFrustum.getNearDist() * viewport.extent.x ) / mFrustum.getWidth(),
 716                  ( mFrustum.getNearDist() * viewport.extent.y ) / mFrustum.getHeight() );
 717
 718   return scale;
 719}
 720
 721//-----------------------------------------------------------------------------
 722// Set Light
 723//-----------------------------------------------------------------------------
 724void GFXDevice::setLight(U32 stage, GFXLightInfo* light)
 725{
 726   AssertFatal(stage < LIGHT_STAGE_COUNT, "GFXDevice::setLight - out of range stage!");
 727
 728   if(!mLightDirty[stage])
 729   {
 730      mStateDirty = true;
 731      mLightsDirty = true;
 732      mLightDirty[stage] = true;
 733   }
 734   mCurrentLightEnable[stage] = (light != NULL);
 735   if(mCurrentLightEnable[stage])
 736      mCurrentLight[stage] = *light;
 737}
 738
 739//-----------------------------------------------------------------------------
 740// Set Light Material
 741//-----------------------------------------------------------------------------
 742void GFXDevice::setLightMaterial(const GFXLightMaterial& mat)
 743{
 744   mCurrentLightMaterial = mat;
 745   mLightMaterialDirty = true;
 746   mStateDirty = true;
 747}
 748
 749void GFXDevice::setGlobalAmbientColor(const ColorF& color)
 750{
 751   if(mGlobalAmbientColor != color)
 752   {
 753      mGlobalAmbientColor = color;
 754      mGlobalAmbientColorDirty = true;
 755   }
 756}
 757
 758//-----------------------------------------------------------------------------
 759// Set texture
 760//-----------------------------------------------------------------------------
 761void GFXDevice::setTexture( U32 stage, GFXTextureObject *texture )
 762{
 763   AssertFatal(stage < getNumSamplers(), "GFXDevice::setTexture - out of range stage!");
 764
 765   if (  mTexType[stage] == GFXTDT_Normal &&
 766         (  ( mTextureDirty[stage] && mNewTexture[stage].getPointer() == texture ) ||
 767            ( !mTextureDirty[stage] && mCurrentTexture[stage].getPointer() == texture ) ) )
 768      return;
 769
 770   mStateDirty = true;
 771   mTexturesDirty = true;
 772   mTextureDirty[stage] = true;
 773
 774   mNewTexture[stage] = texture;
 775   mTexType[stage] = GFXTDT_Normal;
 776
 777   // Clear out the cubemaps
 778   mNewCubemap[stage] = NULL;
 779   mCurrentCubemap[stage] = NULL;
 780}
 781
 782//-----------------------------------------------------------------------------
 783// Set cube texture
 784//-----------------------------------------------------------------------------
 785void GFXDevice::setCubeTexture( U32 stage, GFXCubemap *texture )
 786{
 787   AssertFatal(stage < getNumSamplers(), "GFXDevice::setTexture - out of range stage!");
 788
 789   if (  mTexType[stage] == GFXTDT_Cube &&
 790         (  ( mTextureDirty[stage] && mNewCubemap[stage].getPointer() == texture ) ||
 791            ( !mTextureDirty[stage] && mCurrentCubemap[stage].getPointer() == texture ) ) )
 792      return;
 793
 794   mStateDirty = true;
 795   mTexturesDirty = true;
 796   mTextureDirty[stage] = true;
 797
 798   mNewCubemap[stage] = texture;
 799   mTexType[stage] = GFXTDT_Cube;
 800
 801   // Clear out the normal textures
 802   mNewTexture[stage] = NULL;
 803   mCurrentTexture[stage] = NULL;
 804}
 805
 806//------------------------------------------------------------------------------
 807
 808inline bool GFXDevice::beginScene()
 809{
 810   AssertFatal( mCanCurrentlyRender == false, "GFXDevice::beginScene() - The scene has already begun!" );
 811
 812   mDeviceStatistics.clear();
 813
 814   // Send the start of frame signal.
 815   getDeviceEventSignal().trigger( GFXDevice::deStartOfFrame );
 816   mFrameTime->reset();
 817   return beginSceneInternal();
 818}
 819
 820inline void GFXDevice::endScene()
 821{
 822   AssertFatal( mCanCurrentlyRender == true, "GFXDevice::endScene() - The scene has already ended!" );
 823   
 824   // End frame signal
 825   getDeviceEventSignal().trigger( GFXDevice::deEndOfFrame );
 826
 827   endSceneInternal();
 828   mDeviceStatistics.exportToConsole();
 829}
 830
 831inline void GFXDevice::beginField()
 832{
 833   AssertFatal( mCanCurrentlyRender == true, "GFXDevice::beginField() - The scene has not yet begun!" );
 834
 835   // Send the start of field signal.
 836   getDeviceEventSignal().trigger( GFXDevice::deStartOfField );
 837}
 838
 839inline void GFXDevice::endField()
 840{
 841   AssertFatal( mCanCurrentlyRender == true, "GFXDevice::endField() - The scene has not yet begun!" );
 842
 843   // Send the end of field signal.
 844   getDeviceEventSignal().trigger( GFXDevice::deEndOfField );
 845}
 846
 847void GFXDevice::setViewport( const RectI &inRect ) 
 848{
 849   // Clip the rect against the renderable size.
 850   Point2I size = mCurrentRT->getSize();
 851   RectI maxRect(Point2I(0,0), size);
 852   RectI rect = inRect;
 853   rect.intersect(maxRect);
 854
 855   if ( mViewport != rect )
 856   {
 857      mViewport = rect;
 858      mViewportDirty = true;
 859   }   
 860}
 861
 862void GFXDevice::pushActiveRenderTarget()
 863{
 864   // Push the current target on to the stack.
 865   mRTStack.push_back( mCurrentRT );
 866}
 867
 868void GFXDevice::popActiveRenderTarget()
 869{
 870   AssertFatal( mRTStack.size() > 0, "GFXDevice::popActiveRenderTarget() - stack is empty!" );
 871
 872   // Restore the last item on the stack and pop.
 873   setActiveRenderTarget( mRTStack.last() );
 874   mRTStack.pop_back();
 875}
 876
 877void GFXDevice::setActiveRenderTarget( GFXTarget *target, bool updateViewport )
 878{
 879   AssertFatal( target, 
 880      "GFXDevice::setActiveRenderTarget - must specify a render target!" );
 881
 882   if ( target == mCurrentRT )
 883      return;
 884   
 885   // If we're not dirty then store the 
 886   // current RT for deactivation later.
 887   if ( !mRTDirty )
 888   {
 889      // Deactivate the target queued for deactivation
 890      if(mRTDeactivate)
 891         mRTDeactivate->deactivate();
 892
 893      mRTDeactivate = mCurrentRT;
 894   }
 895
 896   mRTDirty = true;
 897   mCurrentRT = target;
 898
 899   // When a target changes we also change the viewport
 900   // to match it.  This causes problems when the viewport
 901   // has been modified for clipping to a GUI bounds.
 902   //
 903   // We should consider removing this and making it the
 904   // responsibility of the caller to set a proper viewport
 905   // when the target is changed.   
 906   if ( updateViewport )
 907   {
 908      setViewport( RectI( Point2I::Zero, mCurrentRT->getSize() ) );
 909   }
 910}
 911
 912/// Helper class for GFXDevice::describeResources.
 913class DescriptionOutputter
 914{
 915   /// Are we writing to a file?
 916   bool mWriteToFile;
 917
 918   /// File if we are writing to a file
 919   FileStream mFile;
 920public:
 921   DescriptionOutputter(const char* file)
 922   {
 923      mWriteToFile = false;
 924      // If we've been given what could be a valid file path, open it.
 925      if(file && file[0] != '\0')
 926      {
 927         mWriteToFile = mFile.open(file, Torque::FS::File::Write);
 928
 929         // Note that it is safe to retry.  If this is hit, we'll just write to the console instead of to the file.
 930         AssertFatal(mWriteToFile, avar("DescriptionOutputter::DescriptionOutputter - could not open file %s", file));
 931      }
 932   }
 933
 934   ~DescriptionOutputter()
 935   {
 936      // Close the file
 937      if(mWriteToFile)
 938         mFile.close();
 939   }
 940
 941   /// Writes line to the file or to the console, depending on what we want.
 942   void write(const char* line)
 943   {
 944      if(mWriteToFile)
 945         mFile.writeLine((const U8*)line);
 946      else
 947         Con::printf(line);
 948   }
 949};
 950
 951#ifndef TORQUE_SHIPPING
 952void GFXDevice::dumpStates( const char *fileName ) const
 953{
 954   DescriptionOutputter output(fileName);
 955
 956   output.write("Current state");
 957   if (!mCurrentStateBlock.isNull())
 958      output.write(mCurrentStateBlock->getDesc().describeSelf().c_str());
 959   else
 960      output.write("No state!");
 961
 962   output.write("\nAll states:\n");
 963   GFXResource* walk = mResourceListHead;
 964   while(walk)
 965   {
 966      const GFXStateBlock* sb = dynamic_cast<const GFXStateBlock*>(walk);
 967      if (sb)
 968      {
 969         output.write(sb->getDesc().describeSelf().c_str());
 970      }
 971      walk = walk->getNextResource();
 972   }
 973}
 974#endif
 975
 976void GFXDevice::listResources(bool unflaggedOnly)
 977{
 978   U32 numTextures = 0, numShaders = 0, numRenderToTextureTargs = 0, numWindowTargs = 0;
 979   U32 numCubemaps = 0, numVertexBuffers = 0, numPrimitiveBuffers = 0, numFences = 0;
 980   U32 numStateBlocks = 0;
 981
 982   GFXResource* walk = mResourceListHead;
 983   while(walk)
 984   {
 985      if(unflaggedOnly && walk->isFlagged())
 986      {
 987         walk = walk->getNextResource();
 988         continue;
 989      }
 990
 991      if(dynamic_cast<GFXTextureObject*>(walk))
 992         numTextures++;
 993      else if(dynamic_cast<GFXShader*>(walk))
 994         numShaders++;
 995      else if(dynamic_cast<GFXTextureTarget*>(walk))
 996         numRenderToTextureTargs++;
 997      else if(dynamic_cast<GFXWindowTarget*>(walk))
 998         numWindowTargs++;
 999      else if(dynamic_cast<GFXCubemap*>(walk))
1000         numCubemaps++;
1001      else if(dynamic_cast<GFXVertexBuffer*>(walk))
1002         numVertexBuffers++;
1003      else if(dynamic_cast<GFXPrimitiveBuffer*>(walk))
1004         numPrimitiveBuffers++;
1005      else if(dynamic_cast<GFXFence*>(walk))
1006         numFences++;
1007      else if (dynamic_cast<GFXStateBlock*>(walk))
1008         numStateBlocks++;
1009      else
1010         Con::warnf("Unknown resource: %x", walk);
1011
1012      walk = walk->getNextResource();
1013   }
1014   const char* flag = unflaggedOnly ? "unflagged" : "allocated";
1015
1016   Con::printf("GFX currently has:");
1017   Con::printf("   %i %s textures", numTextures, flag);
1018   Con::printf("   %i %s shaders", numShaders, flag);
1019   Con::printf("   %i %s texture targets", numRenderToTextureTargs, flag);
1020   Con::printf("   %i %s window targets", numWindowTargs, flag);
1021   Con::printf("   %i %s cubemaps", numCubemaps, flag);
1022   Con::printf("   %i %s vertex buffers", numVertexBuffers, flag);
1023   Con::printf("   %i %s primitive buffers", numPrimitiveBuffers, flag);
1024   Con::printf("   %i %s fences", numFences, flag);
1025   Con::printf("   %i %s state blocks", numStateBlocks, flag);
1026}
1027
1028void GFXDevice::fillResourceVectors(const char* resNames, bool unflaggedOnly, Vector<GFXResource*> &textureObjects,
1029                                 Vector<GFXResource*> &textureTargets, Vector<GFXResource*> &windowTargets, Vector<GFXResource*> &vertexBuffers, 
1030                                 Vector<GFXResource*> &primitiveBuffers, Vector<GFXResource*> &fences, Vector<GFXResource*> &cubemaps, 
1031                                 Vector<GFXResource*> &shaders, Vector<GFXResource*> &stateblocks)
1032{
1033   bool describeTexture = true, describeTextureTarget = true, describeWindowTarget = true, describeVertexBuffer = true, 
1034      describePrimitiveBuffer = true, describeFence = true, describeCubemap = true, describeShader = true,
1035      describeStateBlock = true;
1036
1037   // If we didn't specify a string of names, we'll print all of them
1038   if(resNames && resNames[0] != '\0')
1039   {
1040      // If we did specify a string of names, determine which names
1041      describeTexture =          (dStrstr(resNames, "GFXTextureObject")    != NULL);
1042      describeTextureTarget =    (dStrstr(resNames, "GFXTextureTarget")    != NULL);
1043      describeWindowTarget =     (dStrstr(resNames, "GFXWindowTarget")     != NULL);
1044      describeVertexBuffer =     (dStrstr(resNames, "GFXVertexBuffer")     != NULL);
1045      describePrimitiveBuffer =  (dStrstr(resNames, "GFXPrimitiveBuffer")   != NULL);
1046      describeFence =            (dStrstr(resNames, "GFXFence")            != NULL);
1047      describeCubemap =          (dStrstr(resNames, "GFXCubemap")          != NULL);
1048      describeShader =           (dStrstr(resNames, "GFXShader")           != NULL);
1049      describeStateBlock =       (dStrstr(resNames, "GFXStateBlock")           != NULL);
1050   }
1051
1052   // Start going through the list
1053   GFXResource* walk = mResourceListHead;
1054   while(walk)
1055   {
1056      // If we only want unflagged resources, skip all flagged resources
1057      if(unflaggedOnly && walk->isFlagged())
1058      {
1059         walk = walk->getNextResource();
1060         continue;
1061      }
1062
1063      // All of the following checks go through the same logic.
1064      // if(describingThisResource) 
1065      // {
1066      //    ResourceType* type = dynamic_cast<ResourceType*>(walk)
1067      //    if(type)
1068      //    {
1069      //       typeVector.push_back(type);
1070      //       walk = walk->getNextResource();
1071      //       continue;
1072      //    }
1073      // }
1074
1075      if(describeTexture)
1076      {
1077         GFXTextureObject* tex = dynamic_cast<GFXTextureObject*>(walk);
1078         {
1079            if(tex)
1080            {
1081               textureObjects.push_back(tex);
1082               walk = walk->getNextResource();
1083               continue;
1084            }
1085         }
1086      }
1087      if(describeShader)
1088      {
1089         GFXShader* shd = dynamic_cast<GFXShader*>(walk);
1090         if(shd)
1091         {
1092            shaders.push_back(shd);
1093            walk = walk->getNextResource();
1094            continue;
1095         }
1096      }
1097      if(describeVertexBuffer)
1098      {
1099         GFXVertexBuffer* buf = dynamic_cast<GFXVertexBuffer*>(walk);
1100         if(buf)
1101         {
1102            vertexBuffers.push_back(buf);
1103            walk = walk->getNextResource();
1104            continue;
1105         }
1106      }
1107      if(describePrimitiveBuffer)
1108      {
1109         GFXPrimitiveBuffer* buf = dynamic_cast<GFXPrimitiveBuffer*>(walk);
1110         if(buf)
1111         {
1112            primitiveBuffers.push_back(buf);
1113            walk = walk->getNextResource();
1114            continue;
1115         }
1116      }
1117      if(describeTextureTarget)
1118      {
1119         GFXTextureTarget* targ = dynamic_cast<GFXTextureTarget*>(walk);
1120         if(targ)
1121         {
1122            textureTargets.push_back(targ);
1123            walk = walk->getNextResource();
1124            continue;
1125         }
1126      }
1127      if(describeWindowTarget)
1128      {
1129         GFXWindowTarget* targ = dynamic_cast<GFXWindowTarget*>(walk);
1130         if(targ)
1131         {
1132            windowTargets.push_back(targ);
1133            walk = walk->getNextResource();
1134            continue;
1135         }
1136      }
1137      if(describeCubemap)
1138      {
1139         GFXCubemap* cube = dynamic_cast<GFXCubemap*>(walk);
1140         if(cube)
1141         {
1142            cubemaps.push_back(cube);
1143            walk = walk->getNextResource();
1144            continue;
1145         }
1146      }
1147      if(describeFence)
1148      {
1149         GFXFence* fence = dynamic_cast<GFXFence*>(walk);
1150         if(fence)
1151         {
1152            fences.push_back(fence);
1153            walk = walk->getNextResource();
1154            continue;
1155         }
1156      }
1157      if (describeStateBlock)
1158      {
1159         GFXStateBlock* sb = dynamic_cast<GFXStateBlock*>(walk);
1160         if (sb)
1161         {
1162            stateblocks.push_back(sb);
1163            walk = walk->getNextResource();
1164            continue;
1165         }
1166      }
1167      // Wasn't something we were looking for
1168      walk = walk->getNextResource();
1169   }
1170}
1171
1172void GFXDevice::describeResources(const char* resNames, const char* filePath, bool unflaggedOnly)
1173{
1174   const U32 numResourceTypes = 9;
1175   Vector<GFXResource*> resVectors[numResourceTypes];
1176   const char* reslabels[numResourceTypes] = { "texture", "texture target", "window target", "vertex buffers", "primitive buffers", "fences", "cubemaps", "shaders", "stateblocks" };   
1177
1178   // Fill the vectors with the right resources
1179   fillResourceVectors(resNames, unflaggedOnly, resVectors[0], resVectors[1], resVectors[2], resVectors[3], 
1180      resVectors[4], resVectors[5], resVectors[6], resVectors[7], resVectors[8]);
1181
1182   // Helper object
1183   DescriptionOutputter output(filePath);
1184
1185   // Print the info to the file
1186   // Note that we check if we have any objects of that type.
1187   for (U32 i = 0; i < numResourceTypes; i++)
1188   {
1189      if (resVectors[i].size())
1190      {
1191         // Header
1192         String header = String::ToString("--------Dumping GFX %s descriptions...----------", reslabels[i]);
1193         output.write(header);
1194         // Data
1195         for (U32 j = 0; j < resVectors[i].size(); j++)
1196         {
1197            GFXResource* resource = resVectors[i][j];
1198            String dataline = String::ToString("Addr: %x %s", resource, resource->describeSelf().c_str());
1199            output.write(dataline.c_str());
1200         }
1201         // Footer
1202         output.write("--------------------Done---------------------");
1203         output.write("");
1204      }
1205   }
1206}
1207
1208void GFXDevice::flagCurrentResources()
1209{
1210   GFXResource* walk = mResourceListHead;
1211   while(walk)
1212   {
1213      walk->setFlag();
1214      walk = walk->getNextResource();
1215   }
1216}
1217
1218void GFXDevice::clearResourceFlags()
1219{
1220   GFXResource* walk = mResourceListHead;
1221   while(walk)
1222   {
1223      walk->clearFlag();
1224      walk = walk->getNextResource();
1225   }
1226}
1227
1228DefineEngineFunction( listGFXResources, void, ( bool unflaggedOnly ), ( false ),
1229   "Returns a list of the unflagged GFX resources. See flagCurrentGFXResources for usage details.\n"
1230   "@ingroup GFX\n"
1231   "@see flagCurrentGFXResources, clearGFXResourceFlags, describeGFXResources" )
1232{
1233   GFX->listResources(unflaggedOnly);
1234}
1235
1236DefineEngineFunction( flagCurrentGFXResources, void, (),,
1237   "@brief Flags all currently allocated GFX resources.\n"
1238   "Used for resource allocation and leak tracking by flagging "
1239   "current resources then dumping a list of unflagged resources "
1240   "at some later point in execution.\n"
1241   "@ingroup GFX\n"
1242   "@see listGFXResources, clearGFXResourceFlags, describeGFXResources" )
1243{
1244   GFX->flagCurrentResources();
1245}
1246
1247DefineEngineFunction( clearGFXResourceFlags, void, (),,
1248   "Clears the flagged state on all allocated GFX resources. "
1249   "See flagCurrentGFXResources for usage details.\n"
1250   "@ingroup GFX\n"
1251   "@see flagCurrentGFXResources, listGFXResources, describeGFXResources" )
1252{
1253   GFX->clearResourceFlags();
1254}
1255
1256DefineEngineFunction( describeGFXResources, void, ( const char *resourceTypes, const char *filePath, bool unflaggedOnly ), ( false ),
1257   "@brief Dumps a description of GFX resources to a file or the console.\n"
1258   "@param resourceTypes A space seperated list of resource types or an empty string for all resources.\n"
1259   "@param filePath A file to dump the list to or an empty string to write to the console.\n"
1260   "@param unflaggedOnly If true only unflagged resources are dumped. See flagCurrentGFXResources.\n"
1261   "@note The resource types can be one or more of the following:\n\n"
1262   "  - texture\n"
1263   "  - texture target\n"
1264   "  - window target\n"
1265   "  - vertex buffers\n"
1266   "  - primitive buffers\n"
1267   "  - fences\n"
1268   "  - cubemaps\n"
1269   "  - shaders\n"
1270   "  - stateblocks\n\n"
1271   "@ingroup GFX\n" )
1272{
1273   GFX->describeResources( resourceTypes, filePath, unflaggedOnly );
1274}
1275
1276DefineEngineFunction( describeGFXStateBlocks, void, ( const char *filePath ),,
1277   "Dumps a description of all state blocks.\n"     
1278   "@param filePath A file to dump the state blocks to or an empty string to write to the console.\n"
1279   "@ingroup GFX\n" )
1280{
1281   GFX->dumpStates( filePath );   
1282}
1283
1284DefineEngineFunction( getPixelShaderVersion, F32, (),,
1285   "Returns the pixel shader version for the active device.\n"
1286   "@ingroup GFX\n" )
1287{
1288   return GFX->getPixelShaderVersion();
1289}   
1290
1291DefineEngineFunction( setPixelShaderVersion, void, ( F32 version ),,
1292   "@brief Sets the pixel shader version for the active device.\n"
1293   "This can be used to force a lower pixel shader version than is supported by "
1294   "the device for testing or performance optimization.\n"
1295   "@param version The floating point shader version number.\n"
1296   "@note This will only affect shaders/materials created after the call "
1297   "and should be used before the game begins.\n"
1298   "@see $pref::Video::forcedPixVersion\n"
1299   "@ingroup GFX\n" )
1300{
1301   GFX->setPixelShaderVersion( version );
1302}
1303
1304DefineEngineFunction( getDisplayDeviceInformation, const char*, (),,
1305   "Get the string describing the active GFX device.\n"
1306   "@ingroup GFX\n" )
1307{
1308   if (!GFXDevice::devicePresent())
1309      return "(no device)";
1310
1311   const GFXAdapter& adapter = GFX->getAdapter();
1312   return adapter.getName();
1313}
1314
1315DefineEngineFunction( getBestHDRFormat, GFXFormat, (),,
1316   "Returns the best texture format for storage of HDR data for the active device.\n"
1317   "@ingroup GFX\n" )
1318{
1319   // TODO: Maybe expose GFX::selectSupportedFormat() so that this
1320   // specialized method can be moved to script.
1321
1322   // Figure out the best HDR format.  This is the smallest
1323   // format which supports blending and filtering.
1324   Vector<GFXFormat> formats;
1325   //formats.push_back( GFXFormatR10G10B10A2 ); TODO: replace with SRGB format once DX9 is gone - BJR
1326   formats.push_back( GFXFormatR16G16B16A16F );
1327   formats.push_back( GFXFormatR16G16B16A16 );    
1328   GFXFormat format = GFX->selectSupportedFormat(  &GFXDefaultRenderTargetProfile,
1329                                                   formats, 
1330                                                   true,
1331                                                   true,
1332                                                   true );
1333
1334   return format;
1335}
1336
1337DefineConsoleFunction(ResetGFX, void, (), , "forces the gbuffer to be reinitialized in cases of improper/lack of buffer clears.")
1338{
1339   GFX->beginReset();
1340}
1341