gfxCardProfile.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GFXCARDPROFILE_H_
  23. #define _GFXCARDPROFILE_H_
  24. #ifndef _TDICTIONARY_H_
  25. #include "core/util/tDictionary.h"
  26. #endif
  27. #ifndef _GFXDEVICE_H_
  28. #include "gfx/gfxDevice.h"
  29. #endif
  30. #ifndef _TORQUE_STRING_H_
  31. #include "core/util/str.h"
  32. #endif
  33. /// GFXCardProfiler provides a device independent wrapper around both the
  34. /// capabilities reported by the card/drivers and the exceptions recorded
  35. /// in various scripts.
  36. ///
  37. /// See the Torque Scripting Manual for more details.
  38. ///
  39. class GFXCardProfiler
  40. {
  41. /// @name icpi Internal Card Profile Interface
  42. ///
  43. /// This is the interface implemented by subclasses of this class in order
  44. /// to provide implementation-specific information about the current
  45. /// card/drivers.
  46. ///
  47. /// Basically, the implementation needs to provide some unique strings:
  48. /// - mVersionString indicating the current driver version of the
  49. /// card in question. (For instance, "53.36")
  50. /// - mCardDescription indicating the name of the card ("Radeon 8500")
  51. /// - getRendererString() indicating the name of the renderer ("DX9", "GL1.2").
  52. /// Each card profiler subclass must return a unique constant so we can keep
  53. /// data separate. Bear in mind that punctuation is stripped from filenames.
  54. ///
  55. /// The profiler also needs to implement setupCardCapabilities(), which is responsible
  56. /// for querying the active device and setting defaults based on the reported capabilities,
  57. /// and _queryCardCap, which is responsible for recognizing and responding to
  58. /// device-specific capability queries.
  59. ///
  60. /// @{
  61. public:
  62. ///
  63. const String &getVersionString() const { return mVersionString; }
  64. const String &getCardString() const { return mCardDescription; }
  65. const String &getChipString() const { return mChipSet; }
  66. U32 getVideoMemoryInMB() const { return mVideoMemory; }
  67. virtual const String &getRendererString() const = 0;
  68. protected:
  69. String mVersionString;
  70. String mCardDescription;
  71. String mChipSet;
  72. U32 mVideoMemory;
  73. virtual void setupCardCapabilities()=0;
  74. /// Implementation specific query code.
  75. ///
  76. /// This function is meant to be overridden by the specific implementation class.
  77. ///
  78. /// Some query strings are handled by the external implementation while others must
  79. /// be done by the specific implementation. This is given first chance to return
  80. /// a result, then the generic rules are applied.
  81. ///
  82. /// @param query Capability being queried.
  83. /// @param foundResult Result to return to the caller. If the function returns true
  84. /// then this value is returned as the result of the query.
  85. virtual bool _queryCardCap(const String &query, U32 &foundResult)=0;
  86. virtual bool _queryFormat( const GFXFormat fmt, const GFXTextureProfile *profile, bool &inOutAutogenMips ) = 0;
  87. /// @}
  88. /// @name helpergroup Helper Functions
  89. ///
  90. /// Various helper functions.
  91. /// Load a specified script file from the profiles directory, if it exists.
  92. void loadProfileScript(const char* scriptName);
  93. /// Load the script files in order for the specified card profile tuple.
  94. void loadProfileScripts(const String& render, const String& vendor, const String& card, const String& version);
  95. String strippedString(const char*string);
  96. /// @}
  97. /// Capability dictionary.
  98. Map<String, U32> mCapDictionary;
  99. public:
  100. /// @name ecpi External Card Profile Interface
  101. ///
  102. /// @{
  103. /// Called for a profile for a given device.
  104. GFXCardProfiler();
  105. virtual ~GFXCardProfiler();
  106. /// Set load script files and generally initialize things.
  107. virtual void init()=0;
  108. /// Called to query a capability. Given a query string it returns a
  109. /// bool indicating whether or not the capability holds. If you call
  110. /// this and cap isn't recognized then it returns false and prints
  111. /// a console error.
  112. U32 queryProfile(const String &cap);
  113. /// Same as queryProfile(), but a default can be specified to indicate
  114. /// what value should be returned if the profiler doesn't know anything
  115. /// about it. If cap is not recognized, defaultValue is returned and
  116. /// no error is reported.
  117. U32 queryProfile(const String &cap, U32 defaultValue);
  118. /// Set the specified capability to the specified value.
  119. void setCapability(const String &cap, U32 value);
  120. /// Queries support for the specified texture format, and texture profile
  121. bool checkFormat( const GFXFormat fmt, const GFXTextureProfile *profile, bool &inOutAutogenMips );
  122. /// @}
  123. };
  124. #endif