gfxStringEnumTranslate.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. #include "core/strings/stringFunctions.h"
  23. #include "gfx/gfxStringEnumTranslate.h"
  24. #include "gfx/gfxAPI.h"
  25. #include "console/console.h"
  26. //------------------------------------------------------------------------------
  27. const char *GFXStringTextureFormat[GFXFormat_COUNT];
  28. const char *GFXStringTiledTextureFormat[GFXFormat_COUNT];
  29. const char *GFXStringRenderTargetFormat[GFXFormat_COUNT];
  30. const char *GFXStringTextureFilter[GFXTextureFilter_COUNT];
  31. const char *GFXStringBlend[GFXBlend_COUNT];
  32. const char *GFXStringBlendOp[GFXBlendOp_COUNT];
  33. const char *GFXStringStencilOp[GFXStencilOp_COUNT];
  34. const char *GFXStringCmpFunc[GFXCmp_COUNT];
  35. const char *GFXStringCullMode[GFXCull_COUNT];
  36. const char *GFXStringPrimType[GFXPT_COUNT];
  37. const char *GFXStringTextureAddress[GFXAddress_COUNT];
  38. const char *GFXStringFillMode[GFXFill_COUNT];
  39. //------------------------------------------------------------------------------
  40. const char *defaultStringValueLookup( const U32 &value )
  41. {
  42. static char retbuffer[256];
  43. dSprintf( retbuffer, sizeof( retbuffer ), "%d", value );
  44. return retbuffer;
  45. }
  46. #define _STRING_VALUE_LOOKUP_FXN( table ) \
  47. const char * table##_lookup( const U32 &value ) { return table[value]; }
  48. _STRING_VALUE_LOOKUP_FXN(GFXStringTextureAddress);
  49. _STRING_VALUE_LOOKUP_FXN(GFXStringTextureFilter);
  50. _STRING_VALUE_LOOKUP_FXN(GFXStringBlend);
  51. _STRING_VALUE_LOOKUP_FXN(GFXStringCmpFunc);
  52. _STRING_VALUE_LOOKUP_FXN(GFXStringStencilOp);
  53. _STRING_VALUE_LOOKUP_FXN(GFXStringCullMode);
  54. _STRING_VALUE_LOOKUP_FXN(GFXStringBlendOp);
  55. //------------------------------------------------------------------------------
  56. #define INIT_LOOKUPTABLE( tablearray, enumprefix, type ) \
  57. for( S32 i = enumprefix##_FIRST; i < enumprefix##_COUNT; i++ ) \
  58. tablearray[i] = (type)(uintptr_t)GFX_UNINIT_VAL;
  59. #define INIT_LOOKUPTABLE_EX( tablearray, enumprefix, type, typeTable ) \
  60. for( S32 i = enumprefix##_FIRST; i < enumprefix##_COUNT; i++ ) \
  61. {\
  62. tablearray[i] = (type)(uintptr_t)GFX_UNINIT_VAL;\
  63. typeTable[i] = &defaultStringValueLookup;\
  64. }
  65. #define VALIDATE_LOOKUPTABLE( tablearray, enumprefix ) \
  66. for( S32 i = enumprefix##_FIRST; i < enumprefix##_COUNT; i++ ) \
  67. if( (intptr_t)tablearray[i] == GFX_UNINIT_VAL ) \
  68. Con::warnf( "GFXStringEnumTranslate: Unassigned value in " #tablearray ": %i", i ); \
  69. else if( (intptr_t)tablearray[i] == GFX_UNSUPPORTED_VAL ) \
  70. Con::warnf( "GFXStringEnumTranslate: Unsupported value in " #tablearray ": %i", i );
  71. //------------------------------------------------------------------------------
  72. #define GFX_STRING_ASSIGN_MACRO( table, indexEnum ) table[indexEnum] = #indexEnum;
  73. #define GFX_STRING_ASSIGN_MACRO_EX( table, indexEnum, typeTable ) table[indexEnum] = #indexEnum; table##ValueLookup[indexEnum] = &typeTable##_lookup;
  74. void GFXStringEnumTranslate::init()
  75. {
  76. static bool sInitCalled = false;
  77. if( sInitCalled )
  78. return;
  79. sInitCalled = true;
  80. //------------------------------------------------------------------------------
  81. //------------------------------------------------------------------------------
  82. INIT_LOOKUPTABLE( GFXStringTextureFormat, GFXFormat, const char * );
  83. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR8G8B8 );
  84. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR8G8B8A8 );
  85. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR8G8B8A8_SRGB);
  86. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR8G8B8X8 );
  87. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatB8G8R8A8 );
  88. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR32F );
  89. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR5G6B5 );
  90. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR5G5B5A1 );
  91. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR5G5B5X1 );
  92. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatA4L4 );
  93. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatA8L8 );
  94. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatA8 );
  95. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatL8 );
  96. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatBC1 );
  97. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatBC2 );
  98. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatBC3 );
  99. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatBC4 );
  100. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatBC5 );
  101. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatD32 );
  102. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatD24X8 );
  103. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatD24S8 );
  104. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatD24FS8 );
  105. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatD16 );
  106. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR32G32B32A32F );
  107. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR16G16B16A16F );
  108. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatL16 );
  109. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR16G16B16A16 );
  110. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR16G16 );
  111. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR16F );
  112. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR16G16F );
  113. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR10G10B10A2 );
  114. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR11G11B10);
  115. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR8G8B8_SRGB );
  116. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatR8G8B8A8_LINEAR_FORCE );
  117. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatBC1_SRGB );
  118. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatBC2_SRGB );
  119. GFX_STRING_ASSIGN_MACRO( GFXStringTextureFormat, GFXFormatBC3_SRGB );
  120. VALIDATE_LOOKUPTABLE( GFXStringTextureFormat, GFXFormat);
  121. //------------------------------------------------------------------------------
  122. //------------------------------------------------------------------------------
  123. INIT_LOOKUPTABLE( GFXStringBlend, GFXBlend, const char * );
  124. GFX_STRING_ASSIGN_MACRO( GFXStringBlend, GFXBlendZero );
  125. GFX_STRING_ASSIGN_MACRO( GFXStringBlend, GFXBlendOne );
  126. GFX_STRING_ASSIGN_MACRO( GFXStringBlend, GFXBlendSrcColor );
  127. GFX_STRING_ASSIGN_MACRO( GFXStringBlend, GFXBlendInvSrcColor );
  128. GFX_STRING_ASSIGN_MACRO( GFXStringBlend, GFXBlendSrcAlpha );
  129. GFX_STRING_ASSIGN_MACRO( GFXStringBlend, GFXBlendInvSrcAlpha );
  130. GFX_STRING_ASSIGN_MACRO( GFXStringBlend, GFXBlendDestAlpha );
  131. GFX_STRING_ASSIGN_MACRO( GFXStringBlend, GFXBlendInvDestAlpha );
  132. GFX_STRING_ASSIGN_MACRO( GFXStringBlend, GFXBlendDestColor );
  133. GFX_STRING_ASSIGN_MACRO( GFXStringBlend, GFXBlendInvDestColor );
  134. GFX_STRING_ASSIGN_MACRO( GFXStringBlend, GFXBlendSrcAlphaSat );
  135. VALIDATE_LOOKUPTABLE( GFXStringBlend, GFXBlend );
  136. //------------------------------------------------------------------------------
  137. //------------------------------------------------------------------------------
  138. INIT_LOOKUPTABLE( GFXStringBlendOp, GFXBlendOp, const char * );
  139. GFX_STRING_ASSIGN_MACRO( GFXStringBlendOp, GFXBlendOpAdd );
  140. GFX_STRING_ASSIGN_MACRO( GFXStringBlendOp, GFXBlendOpSubtract );
  141. GFX_STRING_ASSIGN_MACRO( GFXStringBlendOp, GFXBlendOpRevSubtract );
  142. GFX_STRING_ASSIGN_MACRO( GFXStringBlendOp, GFXBlendOpMin );
  143. GFX_STRING_ASSIGN_MACRO( GFXStringBlendOp, GFXBlendOpMax );
  144. VALIDATE_LOOKUPTABLE( GFXStringBlendOp, GFXBlendOp );
  145. //------------------------------------------------------------------------------
  146. //------------------------------------------------------------------------------
  147. INIT_LOOKUPTABLE( GFXStringStencilOp, GFXStencilOp, const char * );
  148. GFX_STRING_ASSIGN_MACRO( GFXStringStencilOp, GFXStencilOpKeep );
  149. GFX_STRING_ASSIGN_MACRO( GFXStringStencilOp, GFXStencilOpZero );
  150. GFX_STRING_ASSIGN_MACRO( GFXStringStencilOp, GFXStencilOpReplace );
  151. GFX_STRING_ASSIGN_MACRO( GFXStringStencilOp, GFXStencilOpIncrSat );
  152. GFX_STRING_ASSIGN_MACRO( GFXStringStencilOp, GFXStencilOpDecrSat );
  153. GFX_STRING_ASSIGN_MACRO( GFXStringStencilOp, GFXStencilOpInvert );
  154. GFX_STRING_ASSIGN_MACRO( GFXStringStencilOp, GFXStencilOpIncr );
  155. GFX_STRING_ASSIGN_MACRO( GFXStringStencilOp, GFXStencilOpDecr );
  156. VALIDATE_LOOKUPTABLE( GFXStringStencilOp, GFXStencilOp );
  157. //------------------------------------------------------------------------------
  158. //------------------------------------------------------------------------------
  159. INIT_LOOKUPTABLE( GFXStringCmpFunc, GFXCmp, const char * );
  160. GFX_STRING_ASSIGN_MACRO( GFXStringCmpFunc, GFXCmpNever );
  161. GFX_STRING_ASSIGN_MACRO( GFXStringCmpFunc, GFXCmpLess );
  162. GFX_STRING_ASSIGN_MACRO( GFXStringCmpFunc, GFXCmpEqual );
  163. GFX_STRING_ASSIGN_MACRO( GFXStringCmpFunc, GFXCmpLessEqual );
  164. GFX_STRING_ASSIGN_MACRO( GFXStringCmpFunc, GFXCmpGreater );
  165. GFX_STRING_ASSIGN_MACRO( GFXStringCmpFunc, GFXCmpNotEqual );
  166. GFX_STRING_ASSIGN_MACRO( GFXStringCmpFunc, GFXCmpGreaterEqual );
  167. GFX_STRING_ASSIGN_MACRO( GFXStringCmpFunc, GFXCmpAlways );
  168. VALIDATE_LOOKUPTABLE( GFXStringCmpFunc, GFXCmp );
  169. //------------------------------------------------------------------------------
  170. //------------------------------------------------------------------------------
  171. INIT_LOOKUPTABLE( GFXStringCullMode, GFXCull, const char * );
  172. GFX_STRING_ASSIGN_MACRO( GFXStringCullMode, GFXCullNone );
  173. GFX_STRING_ASSIGN_MACRO( GFXStringCullMode, GFXCullCW );
  174. GFX_STRING_ASSIGN_MACRO( GFXStringCullMode, GFXCullCCW );
  175. VALIDATE_LOOKUPTABLE( GFXStringCullMode, GFXCull );
  176. //------------------------------------------------------------------------------
  177. //------------------------------------------------------------------------------
  178. INIT_LOOKUPTABLE( GFXStringPrimType, GFXPT, const char * );
  179. GFX_STRING_ASSIGN_MACRO( GFXStringPrimType, GFXPointList );
  180. GFX_STRING_ASSIGN_MACRO( GFXStringPrimType, GFXLineList );
  181. GFX_STRING_ASSIGN_MACRO( GFXStringPrimType, GFXLineStrip );
  182. GFX_STRING_ASSIGN_MACRO( GFXStringPrimType, GFXTriangleList );
  183. GFX_STRING_ASSIGN_MACRO( GFXStringPrimType, GFXTriangleStrip );
  184. VALIDATE_LOOKUPTABLE( GFXStringPrimType, GFXPT );
  185. //------------------------------------------------------------------------------
  186. //------------------------------------------------------------------------------
  187. INIT_LOOKUPTABLE( GFXStringTextureAddress, GFXAddress, const char * );
  188. GFX_STRING_ASSIGN_MACRO( GFXStringTextureAddress, GFXAddressWrap );
  189. GFX_STRING_ASSIGN_MACRO( GFXStringTextureAddress, GFXAddressMirror );
  190. GFX_STRING_ASSIGN_MACRO( GFXStringTextureAddress, GFXAddressClamp );
  191. GFX_STRING_ASSIGN_MACRO( GFXStringTextureAddress, GFXAddressBorder );
  192. GFX_STRING_ASSIGN_MACRO( GFXStringTextureAddress, GFXAddressMirrorOnce );
  193. VALIDATE_LOOKUPTABLE(GFXStringTextureAddress, GFXAddress );
  194. //------------------------------------------------------------------------------
  195. //------------------------------------------------------------------------------
  196. INIT_LOOKUPTABLE( GFXStringFillMode, GFXFill, const char * );
  197. GFX_STRING_ASSIGN_MACRO( GFXStringFillMode, GFXFillPoint );
  198. GFX_STRING_ASSIGN_MACRO( GFXStringFillMode, GFXFillWireframe );
  199. GFX_STRING_ASSIGN_MACRO( GFXStringFillMode, GFXFillSolid );
  200. VALIDATE_LOOKUPTABLE( GFXStringFillMode, GFXFill );
  201. }