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