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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 <cstdint>
  11. #include <vector>
  12. // These are loaded into TextureStorage::SYSTEM by initialize()!
  13. #define TEXTURE_WHITE 0
  14. #define TEXTURE_SPLASH 1
  15. class TextureTileVertex {
  16. public:
  17. TextureTileVertex(uint8_t xc, uint8_t xp, uint8_t yc, uint8_t yp);
  18. uint8_t xCoordinate, xPixel;
  19. uint8_t yCoordinate, yPixel;
  20. };
  21. class TextureTile {
  22. public:
  23. TextureTile(uint16_t a, uint16_t t) : attribute(a), texture(t) { }
  24. ~TextureTile();
  25. void add(TextureTileVertex* t);
  26. void displayTriangle(float a[3], float b[3], float c[3]);
  27. void displayRectangle(float a[3], float b[3], float c[3], float d[3]);
  28. private:
  29. uint16_t attribute;
  30. uint16_t texture;
  31. std::vector<TextureTileVertex*> vertices;
  32. };
  33. /*!
  34. * \brief Texture registry
  35. */
  36. class TextureManager {
  37. public:
  38. enum class ColorMode {
  39. RGB,
  40. RGBA,
  41. ARGB,
  42. BGR,
  43. BGRA
  44. };
  45. enum class TextureStorage {
  46. GAME,
  47. SYSTEM
  48. };
  49. ~TextureManager();
  50. int initialize();
  51. int initializeSplash();
  52. void clear();
  53. int numTextures(TextureStorage s = TextureStorage::GAME);
  54. /*!
  55. * \brief Binds the texture for use in GL
  56. * \param n valid texture index
  57. * \param s Which TextureStorage should be accessed
  58. * \param unit Which GL texture unit should be used
  59. */
  60. void bindTextureId(unsigned int n, TextureStorage s = TextureStorage::GAME, unsigned int unit = 0);
  61. /*!
  62. * \brief Loads Buffer as texture
  63. * \param image pixmap matching other params
  64. * \param width width of image
  65. * \param height height of image
  66. * \param mode mode of image
  67. * \param bpp bits per pixel of image
  68. * \param s Which TextureStorage should be accessed
  69. * \param slot slot (ID) of image
  70. * \param filter if the texture should be mipmap filtered
  71. * \returns texture ID or < 0 on error
  72. */
  73. int loadBufferSlot(unsigned char* image = nullptr,
  74. unsigned int width = 256, unsigned int height = 256,
  75. ColorMode mode = ColorMode::RGBA, unsigned int bpp = 32,
  76. TextureStorage s = TextureStorage::GAME,
  77. int slot = -1, bool filter = true);
  78. int loadImage(const char* filename, TextureStorage s = TextureStorage::GAME, int slot = -1);
  79. void addTile(TextureTile* t);
  80. int numTiles();
  81. TextureTile& getTile(int index);
  82. void addAnimatedTile(int index, int tile);
  83. int numAnimatedTiles();
  84. int getFirstTileAnimation(int index);
  85. int getNextTileAnimation(int tile);
  86. private:
  87. std::vector<unsigned int>& getIds(TextureStorage s);
  88. int loadTGA(const char* filename, TextureStorage s, int slot);
  89. int loadPCX(const char* filename, TextureStorage s, int slot);
  90. int loadPNG(const char* filename, TextureStorage s, int slot);
  91. std::vector<unsigned int> mTextureIdsGame;
  92. std::vector<unsigned int> mTextureIdsSystem;
  93. std::vector<TextureTile*> tiles;
  94. std::vector<std::vector<int>> animations;
  95. };
  96. TextureManager& getTextureManager();
  97. #endif