TextureManager.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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 _TEXTURE_MANAGER_H_
  23. #define _TEXTURE_MANAGER_H_
  24. #ifndef _PLATFORM_H_
  25. #include "platform/platform.h"
  26. #endif
  27. #ifndef _PLATFORMGL_H_
  28. #include "platform/platformAssert.h"
  29. #include "platform/platformGL.h"
  30. #endif
  31. #ifndef _TEXTURE_OBJECT_H_
  32. #include "graphics/TextureObject.h"
  33. #endif
  34. #ifndef _TEXTURE_DICTIONARY_H_
  35. #include "graphics/TextureDictionary.h"
  36. #endif
  37. //-----------------------------------------------------------------------------
  38. #define MaximumProductSupportedTextureWidth 2048
  39. #define MaximumProductSupportedTextureHeight MaximumProductSupportedTextureWidth
  40. class TextureManager
  41. {
  42. friend class TextureHandle;
  43. friend class TextureDictionary;
  44. public:
  45. /// Texture manager event codes.
  46. enum TextureEventCode
  47. {
  48. BeginZombification,
  49. BeginResurrection,
  50. EndResurrection,
  51. };
  52. typedef void (*TextureEventCallback)(const TextureEventCode eventCode, void *userData);
  53. /// Textrue manager state.
  54. enum ManagerState
  55. {
  56. NotInitialized = 0,
  57. Alive,
  58. Dead,
  59. Resurrecting,
  60. };
  61. private:
  62. static S32 mMasterTextureKeyIndex;
  63. static ManagerState mManagerState;
  64. static S32 mTextureResidentWasteSize;
  65. static S32 mTextureResidentSize;
  66. static S32 mTextureResidentCount;
  67. static S32 mBitmapResidentSize;
  68. static bool mForce16BitTexture;
  69. static bool mAllowTextureCompression;
  70. static bool mDisableTextureSubImageUpdates;
  71. public:
  72. static bool mDGLRender;
  73. static GLenum mTextureCompressionHint;
  74. public:
  75. static void create();
  76. static void destroy();
  77. static ManagerState getManagerState( void ) { return mManagerState; }
  78. static void killManager();
  79. static void resurrectManager();
  80. static void flush();
  81. static void refresh( const char *textureName );
  82. static S32 getBitmapResidentSize( void ) { return mBitmapResidentSize; }
  83. static S32 getTextureResidentSize( void ) { return mTextureResidentSize; }
  84. static S32 getTextureResidentWasteSize( void ) { return mTextureResidentWasteSize; }
  85. static S32 getTextureResidentCount( void ) { return mTextureResidentCount; }
  86. static U32 registerEventCallback(TextureEventCallback, void *userData);
  87. static void unregisterEventCallback(const U32 callbackKey);
  88. static StringTableEntry getUniqueTextureKey( void );
  89. static void dumpMetrics( void );
  90. private:
  91. static void postTextureEvent(const TextureEventCode eventCode);
  92. static void createGLName( TextureObject* pTextureObject );
  93. static TextureObject* registerTexture(const char *textureName, GBitmap* pNewBitmap, TextureHandle::TextureHandleType type, bool clampToEdge);
  94. static TextureObject* loadTexture(const char *textureName, TextureHandle::TextureHandleType type, bool clampToEdge, bool checkOnly = false, bool force16Bit = false );
  95. static void freeTexture( TextureObject* pTextureObject );
  96. static void refresh(TextureObject* pTextureObject);
  97. static GBitmap* loadBitmap(const char *textureName, bool recurse = true, bool nocompression = false);
  98. static GBitmap* createPowerOfTwoBitmap( GBitmap* pBitmap );
  99. static U16* create16BitBitmap( GBitmap *pDL, U8 *in_source8, GBitmap::BitmapFormat alpha_info, GLint *GLformat, GLint *GLdata_type, U32 width, U32 height );
  100. static void getSourceDestByteFormat(GBitmap *pBitmap, U32 *sourceFormat, U32 *destFormat, U32 *byteFormat, U32* texelSize);
  101. static F32 getResidentFraction( void );
  102. };
  103. #endif // _TEXTURE_MANAGER_H_