MLRTexturePool.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #pragma once
  5. #define MLR_MLRTEXTUREPOOL_HPP
  6. #if !defined(MLR_MLR_HPP)
  7. #include <MLR\MLR.hpp>
  8. #endif
  9. #if !defined(MLR_GOSIMAGEPOOL_HPP)
  10. #include <MLR\GOSImagePool.hpp>
  11. #endif
  12. namespace MidLevelRenderer {
  13. class MLRTexturePool:
  14. public Stuff::RegisteredClass
  15. {
  16. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  17. // Initialization
  18. //
  19. public:
  20. static void
  21. InitializeClass();
  22. static void
  23. TerminateClass();
  24. static ClassData
  25. *DefaultData;
  26. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. // Constructors/Destructors
  28. //
  29. protected:
  30. MLRTexturePool(Stuff::MemoryStream *stream);
  31. public:
  32. // insDep == nr of lower bits used for image instancing
  33. MLRTexturePool(GOSImagePool *image_pool, int insDep=3);
  34. ~MLRTexturePool();
  35. static MLRTexturePool*
  36. Make(Stuff::MemoryStream *stream);
  37. void
  38. Save(Stuff::MemoryStream *stream);
  39. MLRTexture*
  40. Add(const char *textureName, int instance=0);
  41. MLRTexture*
  42. Add(GOSImage*);
  43. MLRTexture*
  44. Add(const char* imageName, gos_TextureFormat format, int size, gos_TextureHints hints)
  45. { return Add(imagePool->GetImage(imageName, format, size, hints) ); }
  46. // only removes the texture from the texture pool, it doesnt destroy the texture
  47. void
  48. Remove(MLRTexture*);
  49. unsigned
  50. LoadImages();
  51. MLRTexture*
  52. operator() (const char *name, int=0);
  53. MLRTexture*
  54. operator[] (int index)
  55. { Check_Object(this); Verify(index-1 < MLRState::TextureMask); return textureArray[index-1]; }
  56. MLRTexture*
  57. operator[] (const MLRState *state)
  58. { Check_Object(this); return textureArray[state->GetTextureHandle()-1]; }
  59. GOSImage*
  60. GetImage(const char* imageName)
  61. { Check_Object(this); return imagePool->GetImage(imageName); }
  62. const GOSImagePool*
  63. GetGOSImagePool()
  64. { Check_Object(this); return imagePool; }
  65. unsigned
  66. GetLastHandle()
  67. {Check_Object(this); return lastHandle;}
  68. void Stop (void);
  69. void Restart (void);
  70. unsigned
  71. GetNumStoredTextures()
  72. {Check_Object(this); return storedTextures;}
  73. int
  74. GetInstanceDepth() const
  75. { Check_Object(this); return instanceDepth; }
  76. static MLRTexturePool
  77. *Instance;
  78. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79. // Testing
  80. //
  81. public:
  82. void
  83. TestInstance() const
  84. {}
  85. protected:
  86. bool
  87. unLoadedImages;
  88. int instanceDepth, // bits used for image instancing
  89. instanceMax; // max for image instancing
  90. int handleDepth, // bits used for image instancing
  91. handleMax; // max for image instancing
  92. int lastHandle;
  93. int storedTextures;
  94. Stuff::StaticArrayOf<MLRTexture*, MLRState::TextureMask+1> textureArray;
  95. int *freeHandle;
  96. int firstFreeHandle;
  97. int lastFreeHandle;
  98. GOSImagePool
  99. *imagePool;
  100. };
  101. }