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

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