Torque3D Documentation / _generateds / gfxCardProfile.cpp

gfxCardProfile.cpp

Engine/source/gfx/gfxCardProfile.cpp

More...

Public Functions

ConsoleDoc("@class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFXCardProfilerAPI\n</a>" "@brief This class is the interface between TorqueScript and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFXCardProfiler.\n\n</a>" "You will not actually declare GFXCardProfilerAPI in TorqueScript. It exists solely " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> give access <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/class/classgfxcardprofiler/">GFXCardProfiler</a>'s querying functions)
DECLARE_SCOPE(GFXCardProfilerAPI )
DefineEngineStaticMethod(GFXCardProfilerAPI , getBestDepthFormat , String , () , "Returns the card name." )
DefineEngineStaticMethod(GFXCardProfilerAPI , getCard , String , () , "Returns the card name." )
DefineEngineStaticMethod(GFXCardProfilerAPI , getRenderer , String , () , "Returns the renderer name. For example <a href="/coding/file/gfxd3d11device_8h/#gfxd3d11device_8h_1a60ee39488fe07edb777dba8df63fdc23">D3D11</a> or OpenGL." )
DefineEngineStaticMethod(GFXCardProfilerAPI , getVendor , String , () , "Returns the card vendor name." )
DefineEngineStaticMethod(GFXCardProfilerAPI , getVersion , String , () , "Returns the driver version string." )
DefineEngineStaticMethod(GFXCardProfilerAPI , getVideoMemoryMB , S32 , () , "Returns the amount of video memory in megabytes." )
DefineEngineStaticMethod(GFXCardProfilerAPI , queryProfile , S32 , (const char *name, S32 defaultValue) , "Used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> query the <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> specific card <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">capability.\n</a>" "@param name The name of the capability being <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">queried.\n</a>" "@param <a href="/coding/file/pointer_8h/#pointer_8h_1a3db30c1795eb39d4452f8698f4a67f05">defaultValue</a> The <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> return <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the capability is not defined." )
DefineEngineStaticMethod(GFXCardProfilerAPI , setCapability , void , (const char *name, S32 value) , "Used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set the <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> specific card <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">capability.\n</a>" "@param name The name of the capability being <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">set.\n</a>" "@param <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> The <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> that capability." )
IMPLEMENT_SCOPE(GFXCardProfilerAPI , GFXCardProfiler , "" )

Detailed Description

Public Functions

ConsoleDoc("@class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFXCardProfilerAPI\n</a>" "@brief This class is the interface between TorqueScript and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GFXCardProfiler.\n\n</a>" "You will not actually declare GFXCardProfilerAPI in TorqueScript. It exists solely " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> give access <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the <a href="/coding/class/classgfxcardprofiler/">GFXCardProfiler</a>'s querying functions)

DECLARE_SCOPE(GFXCardProfilerAPI )

DefineEngineStaticMethod(GFXCardProfilerAPI , getBestDepthFormat , String , () , "Returns the card name." )

DefineEngineStaticMethod(GFXCardProfilerAPI , getCard , String , () , "Returns the card name." )

DefineEngineStaticMethod(GFXCardProfilerAPI , getRenderer , String , () , "Returns the renderer name. For example <a href="/coding/file/gfxd3d11device_8h/#gfxd3d11device_8h_1a60ee39488fe07edb777dba8df63fdc23">D3D11</a> or OpenGL." )

DefineEngineStaticMethod(GFXCardProfilerAPI , getVendor , String , () , "Returns the card vendor name." )

DefineEngineStaticMethod(GFXCardProfilerAPI , getVersion , String , () , "Returns the driver version string." )

DefineEngineStaticMethod(GFXCardProfilerAPI , getVideoMemoryMB , S32 , () , "Returns the amount of video memory in megabytes." )

DefineEngineStaticMethod(GFXCardProfilerAPI , queryProfile , S32 , (const char *name, S32 defaultValue) , "Used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> query the <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> specific card <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">capability.\n</a>" "@param name The name of the capability being <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">queried.\n</a>" "@param <a href="/coding/file/pointer_8h/#pointer_8h_1a3db30c1795eb39d4452f8698f4a67f05">defaultValue</a> The <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> return <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the capability is not defined." )

DefineEngineStaticMethod(GFXCardProfilerAPI , setCapability , void , (const char *name, S32 value) , "Used <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set the <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> specific card <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">capability.\n</a>" "@param name The name of the capability being <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">set.\n</a>" "@param <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> The <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> that capability." )

IMPLEMENT_SCOPE(GFXCardProfilerAPI , GFXCardProfiler , "" )

  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/gfxCardProfile.h"
 26
 27#include "console/console.h"
 28#include "console/engineAPI.h"
 29#include "core/volume.h"
 30
 31// NOTE: The script class docs are in 
 32// Documentation\scriptDocs\docs\classGFXCardProfiler.txt
 33
 34
 35void GFXCardProfiler::loadProfileScript(const char* aScriptName)
 36{
 37   const String   profilePath = Con::getVariable( "$pref::Video::profilePath" );
 38   String scriptName = !profilePath.isEmpty() ? profilePath.c_str() : "profile";
 39   scriptName += "/";
 40   scriptName += aScriptName;
 41   
 42   void  *data = NULL;
 43   U32   dataSize = 0;
 44
 45   
 46   Torque::FS::ReadFile( scriptName.c_str(), data, dataSize, true );
 47
 48   if(data == NULL)
 49   {
 50#if TORQUE_DEBUG
 51      Con::warnf("      - No card profile %s exists", scriptName.c_str());
 52#endif
 53      return;
 54   }
 55
 56   const char  *script = static_cast<const char *>(data);
 57
 58#if TORQUE_DEBUG
 59   Con::printf("      - Loaded card profile %s", scriptName.c_str());
 60#endif
 61
 62   Con::evaluate(script, false, NULL);
 63   delete[] script;
 64}
 65
 66void GFXCardProfiler::loadProfileScripts(const String& render, const String& vendor, const String& card, const String& version)
 67{
 68   String script = render + "." TORQUE_SCRIPT_EXTENSION;
 69   loadProfileScript(script);
 70
 71   script = render + "." + vendor + "." TORQUE_SCRIPT_EXTENSION;
 72   loadProfileScript(script);
 73
 74   script = render + "." + vendor + "." + card + "." TORQUE_SCRIPT_EXTENSION;
 75   loadProfileScript(script);
 76
 77   script = render + "." + vendor + "." + card + "." + version + "." TORQUE_SCRIPT_EXTENSION;
 78   loadProfileScript(script);
 79}
 80
 81GFXCardProfiler::GFXCardProfiler() : mVideoMemory( 0 )
 82{
 83}
 84
 85GFXCardProfiler::~GFXCardProfiler()
 86{
 87   mCapDictionary.clear();
 88}
 89
 90String GFXCardProfiler::strippedString(const char *string)
 91{
 92   String res = "";
 93
 94   // And fill it with the stripped string...
 95   const char *a=string;
 96   while(*a)
 97   {
 98      if(isalnum(*a))
 99      {
100         res += *a;
101      }
102      a++;
103   }
104
105   return res;
106}
107
108void GFXCardProfiler::init()
109{
110   // Spew a bit...
111   Con::printf("Initializing GFXCardProfiler (%s)", getRendererString().c_str());
112   Con::printf("   o Chipset : '%s'", getChipString().c_str());
113   Con::printf("   o Card    : '%s'", getCardString().c_str());
114   Con::printf("   o Version : '%s'", getVersionString().c_str());
115   Con::printf("   o VRAM    : %d MB", getVideoMemoryInMB());
116
117   // Do card-specific setup...
118   Con::printf("   - Scanning card capabilities...");
119
120   setupCardCapabilities();
121
122   // And finally, load stuff up...
123   String render  = strippedString(getRendererString());
124   String chipset  = strippedString(getChipString());
125   String card    = strippedString(getCardString());
126   String version = strippedString(getVersionString());
127
128   Con::printf("   - Loading card profiles...");
129   loadProfileScripts(render, chipset, card, version);
130}
131
132U32 GFXCardProfiler::queryProfile(const String &cap)
133{
134   U32 res;
135   if( _queryCardCap( cap, res ) )
136      return res;
137
138   if(mCapDictionary.contains(cap))
139      return mCapDictionary[cap];
140
141   Con::errorf( "GFXCardProfiler (%s) - Unknown capability '%s'.", getRendererString().c_str(), cap.c_str() );
142   return 0;
143}
144
145U32 GFXCardProfiler::queryProfile(const String &cap, U32 defaultValue)
146{
147   PROFILE_SCOPE( GFXCardProfiler_queryProfile );
148
149   U32 res;
150   if( _queryCardCap( cap, res ) )
151      return res;
152
153   if( mCapDictionary.contains( cap ) )
154      return mCapDictionary[cap];
155   else
156      return defaultValue;
157}
158
159void GFXCardProfiler::setCapability(const String &cap, U32 value)
160{
161   // Check for dups.
162   if( mCapDictionary.contains( cap ) )
163   {
164      Con::warnf( "GFXCardProfiler (%s) - Setting capability '%s' multiple times.", getRendererString().c_str(), cap.c_str() );
165      mCapDictionary[cap] = value;
166      return;
167   }
168
169   // Insert value as necessary.
170   Con::printf( "GFXCardProfiler (%s) - Setting capability '%s' to %d.", getRendererString().c_str(), cap.c_str(), value );
171   mCapDictionary.insert( cap, value );
172}
173
174bool GFXCardProfiler::checkFormat( const GFXFormat fmt, const GFXTextureProfile *profile, bool &inOutAutogenMips )
175{
176   return _queryFormat( fmt, profile, inOutAutogenMips );
177}
178
179DECLARE_SCOPE( GFXCardProfilerAPI );
180IMPLEMENT_SCOPE( GFXCardProfilerAPI, GFXCardProfiler,, "");
181ConsoleDoc(
182   "@class GFXCardProfilerAPI\n"
183   "@brief This class is the interface between TorqueScript and GFXCardProfiler.\n\n"
184   "You will not actually declare GFXCardProfilerAPI in TorqueScript. It exists solely "
185   "to give access to the GFXCardProfiler's querying functions, such as GFXCardProfiler::getRenderer.\n\n"
186   "@tsexample\n"
187   "// Example of accessing GFXCardProfiler function from script\n"
188   "// Notice you are not using the API version\n"
189   "%videoMem = GFXCardProfiler::getVideoMemoryMB();\n"
190   "@endtsexample\n\n"
191   "@see GFXCardProfiler for more information\n\n"
192   "@ingroup GFX\n"
193);
194
195DefineEngineStaticMethod( GFXCardProfilerAPI, getVersion, String, (),, 
196   "Returns the driver version string." )
197{
198   return GFX->getCardProfiler()->getVersionString();
199}
200
201DefineEngineStaticMethod( GFXCardProfilerAPI, getCard, String, (),,
202   "Returns the card name." )
203{
204   return GFX->getCardProfiler()->getCardString();
205}
206
207DefineEngineStaticMethod( GFXCardProfilerAPI, getVendor, String, (),,
208   "Returns the card vendor name." )
209{
210   // TODO: Fix all of this vendor crap, it's not consistent
211   return GFX->getCardProfiler()->getChipString();
212}
213
214DefineEngineStaticMethod( GFXCardProfilerAPI, getRenderer, String, (),,
215   "Returns the renderer name.  For example D3D11 or OpenGL." )
216{
217   return GFX->getCardProfiler()->getRendererString();
218}
219
220DefineEngineStaticMethod( GFXCardProfilerAPI, getVideoMemoryMB, S32, (),,
221   "Returns the amount of video memory in megabytes." )
222{
223   return GFX->getCardProfiler()->getVideoMemoryInMB();
224}
225
226DefineEngineStaticMethod( GFXCardProfilerAPI, setCapability, void, ( const char *name, S32 value ),,
227   "Used to set the value for a specific card capability.\n"
228   "@param name The name of the capability being set.\n"
229   "@param value The value to set for that capability." )
230{
231   GFX->getCardProfiler()->setCapability( name, (U32)value );
232}
233
234DefineEngineStaticMethod( GFXCardProfilerAPI, queryProfile, S32, ( const char *name, S32 defaultValue ),,
235   "Used to query the value of a specific card capability.\n"
236   "@param name The name of the capability being queried.\n"
237   "@param defaultValue The value to return if the capability is not defined." )
238{
239   return (S32)GFX->getCardProfiler()->queryProfile( name, (U32)defaultValue );
240}
241
242
243DefineEngineStaticMethod( GFXCardProfilerAPI, getBestDepthFormat, String, (),,
244                         "Returns the card name." )
245{
246    if (GFX->getCardProfiler()->queryProfile("GL::Workaround::intel_mac_depth", false))
247        return "GFXFormatD16";
248    else
249        return "GFXFormatD24S8";
250}
251
252