Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TextureManager.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. /*!
  44. * \brief Texture registry
  45. */
  46. class TextureManager {
  47. public:
  48. static int initialize();
  49. static int initializeSplash();
  50. static void shutdown();
  51. static void clear();
  52. static int numTextures(TextureStorage s = TextureStorage::GAME);
  53. /*!
  54. * \brief Bind texture to next free texture unit.
  55. * \param n ID of texture to bind
  56. * \param s Place where texture is stored
  57. * \returns ID of GL texture unit to which this texture is bound.
  58. */
  59. static int bindTexture(unsigned int n, TextureStorage s);
  60. /*!
  61. * \brief Loads Buffer as texture
  62. * \param image pixmap matching other params
  63. * \param width width of image
  64. * \param height height of image
  65. * \param mode mode of image
  66. * \param bpp bits per pixel of image
  67. * \param s Which TextureStorage should be accessed
  68. * \param slot slot (ID) of image
  69. * \param filter if the texture should be mipmap filtered
  70. * \returns texture ID or < 0 on error
  71. */
  72. static int loadBufferSlot(unsigned char* image = nullptr,
  73. unsigned int width = 256, unsigned int height = 256,
  74. ColorMode mode = ColorMode::RGBA, unsigned int bpp = 32,
  75. TextureStorage s = TextureStorage::GAME,
  76. int slot = -1, bool filter = true);
  77. static int loadImage(std::string filename, TextureStorage s = TextureStorage::GAME, int slot = -1);
  78. static void addTile(TextureTile* t);
  79. static int numTiles();
  80. static TextureTile& getTile(int index);
  81. static void addAnimatedTile(int index, int tile);
  82. static int numAnimatedTiles();
  83. static int getFirstTileAnimation(int index);
  84. static int getNextTileAnimation(int tile);
  85. private:
  86. static std::vector<unsigned int>& getIds(TextureStorage s);
  87. static std::vector<int>& getUnits(TextureStorage s);
  88. static void bindTextureId(unsigned int n, TextureStorage s, unsigned int unit);
  89. static int loadPCX(std::string filename, TextureStorage s, int slot);
  90. static std::vector<unsigned int> mTextureIdsGame;
  91. static std::vector<unsigned int> mTextureIdsSystem;
  92. static std::vector<TextureTile*> tiles;
  93. static std::vector<std::vector<int>> animations;
  94. static std::vector<int> gameUnits;
  95. static std::vector<int> systemUnits;
  96. static unsigned int nextFreeTextureUnit;
  97. };
  98. #endif