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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. bool isTriangle();
  27. void display(float x, float y, float w, float h, float z);
  28. private:
  29. void displayTriangle(float x, float y, float w, float h, float z);
  30. void displayRectangle(float x, float y, float w, float h, float z);
  31. uint16_t attribute;
  32. uint16_t texture;
  33. std::vector<TextureTileVertex*> vertices;
  34. };
  35. /*!
  36. * \brief Texture registry
  37. */
  38. class TextureManager {
  39. public:
  40. enum class TextureStorage {
  41. GAME,
  42. SYSTEM
  43. };
  44. ~TextureManager();
  45. int initialize();
  46. void clear();
  47. int numTextures(TextureStorage s = TextureStorage::GAME);
  48. /*!
  49. * \brief Binds the texture for use in GL
  50. * \param n valid texture index
  51. * \param s Which TextureStorage should be accessed
  52. */
  53. void bindTextureId(unsigned int n, TextureStorage s = TextureStorage::GAME);
  54. /*!
  55. * \brief Loads Buffer as texture
  56. * \param image pixmap matching other params
  57. * \param width width of image
  58. * \param height height of image
  59. * \param mode mode of image
  60. * \param bpp bits per pixel of image
  61. * \param s Which TextureStorage should be accessed
  62. * \param slot slot (ID) of image
  63. * \param filter if the texture should be mipmap filtered
  64. * \returns texture ID or < 0 on error
  65. */
  66. int loadBufferSlot(unsigned char* image,
  67. unsigned int width, unsigned int height,
  68. ColorMode mode, unsigned int bpp,
  69. TextureStorage s = TextureStorage::GAME,
  70. int slot = -1, bool filter = true);
  71. int loadImage(const char* filename, TextureStorage s = TextureStorage::GAME, int slot = -1);
  72. void addTile(TextureTile* t);
  73. int numTiles();
  74. TextureTile& getTile(int index);
  75. void addAnimatedTile(int index, int tile);
  76. int numAnimatedTiles();
  77. int getFirstTileAnimation(int index);
  78. int getNextTileAnimation(int tile);
  79. private:
  80. std::vector<unsigned int>& getIds(TextureStorage s);
  81. int loadTGA(const char* filename, TextureStorage s, int slot);
  82. int loadPCX(const char* filename, TextureStorage s, int slot);
  83. int loadPNG(const char* filename, TextureStorage s, int slot);
  84. std::vector<unsigned int> mTextureIdsGame;
  85. std::vector<unsigned int> mTextureIdsSystem;
  86. std::vector<TextureTile*> tiles;
  87. std::vector<std::vector<int>> animations;
  88. };
  89. TextureManager& getTextureManager();
  90. #endif