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 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. int numTextures(TextureStorage s = TextureStorage::GAME);
  47. /*!
  48. * \brief Binds the texture for use in GL
  49. * \param n valid texture index
  50. * \param s Which TextureStorage should be accessed
  51. */
  52. void bindTextureId(unsigned int n, TextureStorage s = TextureStorage::GAME);
  53. /*!
  54. * \brief Loads Buffer as texture
  55. * \param image pixmap matching other params
  56. * \param width width of image
  57. * \param height height of image
  58. * \param mode mode of image
  59. * \param bpp bits per pixel of image
  60. * \param s Which TextureStorage should be accessed
  61. * \param slot slot (ID) of image
  62. * \param filter if the texture should be mipmap filtered
  63. * \returns texture ID or < 0 on error
  64. */
  65. int loadBufferSlot(unsigned char* image,
  66. unsigned int width, unsigned int height,
  67. ColorMode mode, unsigned int bpp,
  68. TextureStorage s = TextureStorage::GAME,
  69. int slot = -1, bool filter = true);
  70. int loadImage(const char* filename, TextureStorage s = TextureStorage::GAME, int slot = -1);
  71. void addTile(TextureTile* t);
  72. int numTiles();
  73. TextureTile& getTile(int index);
  74. private:
  75. std::vector<unsigned int>& getIds(TextureStorage s);
  76. int loadTGA(const char* filename, TextureStorage s, int slot);
  77. int loadPCX(const char* filename, TextureStorage s, int slot);
  78. int loadPNG(const char* filename, TextureStorage s, int slot);
  79. std::vector<unsigned int> mTextureIdsGame;
  80. std::vector<unsigned int> mTextureIdsSystem;
  81. std::vector<TextureTile*> tiles;
  82. };
  83. TextureManager& getTextureManager();
  84. #endif