Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

TextureManager.h 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*!
  2. * \file include/TextureManager.h
  3. * \brief Texture registry
  4. *
  5. * \author Mongoose
  6. * \author xythobuz
  7. */
  8. #ifndef _TEXTURE_MANAGER_H
  9. #define _TEXTURE_MANAGER_H
  10. #include <vector>
  11. // These are loaded into TextureStorage::SYSTEM by initialize()!
  12. #define TEXTURE_WHITE 0
  13. #define TEXTURE_SPLASH 1
  14. class TextureTileVertex {
  15. public:
  16. TextureTileVertex(int xc, int xp, int yc, int yp)
  17. : xCoordinate(xc), xPixel(xp), yCoordinate(yc), yPixel(yp) { }
  18. int xCoordinate, xPixel;
  19. int yCoordinate, yPixel;
  20. };
  21. class TextureTile {
  22. public:
  23. TextureTile(unsigned int a, unsigned int t) : attribute(a), texture(t) { }
  24. void add(TextureTileVertex t) { vertices.push_back(t); }
  25. unsigned int getTexture() { return texture; }
  26. glm::vec2 getUV(unsigned int i);
  27. private:
  28. unsigned int attribute;
  29. unsigned int texture;
  30. std::vector<TextureTileVertex> vertices;
  31. };
  32. enum class ColorMode {
  33. RGB,
  34. RGBA,
  35. ARGB,
  36. BGR,
  37. BGRA
  38. };
  39. enum class TextureStorage {
  40. GAME,
  41. SYSTEM
  42. };
  43. class BufferManager {
  44. public:
  45. BufferManager(int t, TextureStorage s) : texture(t), storage(s) { }
  46. int getTextureID() { return texture; }
  47. TextureStorage getTextureStorage() { return storage; }
  48. private:
  49. int texture;
  50. TextureStorage storage;
  51. };
  52. class TextureManager {
  53. public:
  54. static int initialize();
  55. static int initializeSplash();
  56. static void shutdown();
  57. static void clear();
  58. static int numTextures(TextureStorage s = TextureStorage::GAME);
  59. /*!
  60. * \brief Bind texture to next free texture unit.
  61. * \param n ID of texture to bind
  62. * \param s Place where texture is stored
  63. * \returns ID of GL texture unit to which this texture is bound.
  64. */
  65. static int bindTexture(unsigned int n, TextureStorage s);
  66. /*!
  67. * \brief Loads Buffer as texture
  68. * \param image pixmap matching other params
  69. * \param width width of image
  70. * \param height height of image
  71. * \param mode mode of image
  72. * \param bpp bits per pixel of image
  73. * \param s Which TextureStorage should be accessed
  74. * \param slot slot (ID) of image
  75. * \param filter if the texture should be mipmap filtered
  76. * \returns texture ID or < 0 on error
  77. */
  78. static int loadBufferSlot(unsigned char* image = nullptr,
  79. unsigned int width = 256, unsigned int height = 256,
  80. ColorMode mode = ColorMode::RGBA, unsigned int bpp = 32,
  81. TextureStorage s = TextureStorage::GAME,
  82. int slot = -1, bool filter = true);
  83. static int loadImage(std::string filename, TextureStorage s = TextureStorage::GAME, int slot = -1);
  84. static void addTile(TextureTile* t);
  85. static int numTiles();
  86. static TextureTile& getTile(int index);
  87. static void addAnimatedTile(int index, int tile);
  88. static int numAnimatedTiles();
  89. static int getFirstTileAnimation(int index);
  90. static int getNextTileAnimation(int index, int tile);
  91. static BufferManager* getBufferManager(int tex, TextureStorage store);
  92. static void display();
  93. static unsigned int getTextureID(int n, TextureStorage s);
  94. private:
  95. static std::vector<unsigned int>& getIds(TextureStorage s);
  96. static std::vector<int>& getUnits(TextureStorage s);
  97. static void bindTextureId(unsigned int n, TextureStorage s, unsigned int unit);
  98. static int loadPCX(std::string filename, TextureStorage s, int slot);
  99. static std::vector<unsigned int> mTextureIdsGame;
  100. static std::vector<unsigned int> mTextureIdsSystem;
  101. static std::vector<TextureTile*> tiles;
  102. static std::vector<std::vector<int>> animations;
  103. static std::vector<int> gameUnits;
  104. static std::vector<int> systemUnits;
  105. static unsigned int nextFreeTextureUnit;
  106. static std::vector<BufferManager> gameBuffers;
  107. static std::vector<BufferManager> systemBuffers;
  108. };
  109. #endif