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

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