Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TextureManager.h 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. /*!
  11. * \brief Texture registry
  12. */
  13. class TextureManager {
  14. public:
  15. enum ColorMode {
  16. GREYSCALE,
  17. RGB,
  18. RGBA,
  19. ARGB,
  20. BGR,
  21. BGRA
  22. };
  23. enum TextureFlag {
  24. fUseMultiTexture = (1 << 0),
  25. };
  26. /*!
  27. * \brief Constructs an object of Texture
  28. */
  29. TextureManager();
  30. /*!
  31. * \brief Deconstructs an object of Texture
  32. */
  33. ~TextureManager();
  34. /*!
  35. * \brief Resets all texture data
  36. */
  37. void reset();
  38. /*!
  39. * \brief Generates a texture buffer with (width * height * 4) bytes.
  40. * \param rgba 32bpp RGBA color to fill into buffer
  41. * \param width width of newly allocated buffer, power of 2, pref same as height
  42. * \param height height of newly allocated buffer, power of 2, pref same as width
  43. * \returns newly allocated texture buffer filled with specified color
  44. */
  45. static unsigned char *generateColorTexture(const unsigned char rgba[4],
  46. unsigned int width,
  47. unsigned int height);
  48. /*!
  49. * \brief Get number of textures in use
  50. * \returns used texture count, or -1 on error (uninitialized)
  51. */
  52. int getTextureCount();
  53. /*!
  54. * \brief Sets up multitexture rendering with passed ids
  55. * \param texture0 first texture for multitexture
  56. * \param texture1 second texture for multitexture
  57. */
  58. void bindMultiTexture(int texture0, int texture1);
  59. /*!
  60. * \brief Binds the texture for use in GL
  61. * \param n valid texture index
  62. */
  63. void bindTextureId(unsigned int n);
  64. /*!
  65. * \brief Clears an option flag
  66. * \param flag flag to clear
  67. */
  68. void clearFlag(TextureFlag flag);
  69. void disableMultiTexture();
  70. /*!
  71. * \brief Loads Buffer as texture
  72. * \param image pixmap matching other params
  73. * \param width width of image
  74. * \param height height of image
  75. * \param mode mode of image
  76. * \param bpp bits per pixel of image
  77. * \returns texture ID or < 0 on error
  78. */
  79. int loadBuffer(unsigned char *image,
  80. unsigned int width, unsigned int height,
  81. ColorMode mode, unsigned int bpp);
  82. /*!
  83. * \brief Loads Buffer as texture
  84. * \param image pixmap matching other params
  85. * \param width width of image
  86. * \param height height of image
  87. * \param mode mode of image
  88. * \param bpp bits per pixel of image
  89. * \param slot slot (ID) of image
  90. * \returns texture ID or < 0 on error
  91. */
  92. int loadBufferSlot(unsigned char *image,
  93. unsigned int width, unsigned int height,
  94. ColorMode mode, unsigned int bpp,
  95. unsigned int slot);
  96. /*!
  97. * \brief Generates and loads a solid color texture.
  98. * \param rgba color for new texture
  99. * \param width width of new texture
  100. * \param height height of new texture
  101. * \returns texture ID or -1 on error
  102. */
  103. int loadColorTexture(const unsigned char rgba[4],
  104. unsigned int width, unsigned int height);
  105. /*!
  106. * \brief Loads TGA file as texture
  107. * \param filename Existing TGA file
  108. * \returns ID of new texture or -1 on error
  109. */
  110. int loadTGA(const char *filename);
  111. int loadPCX(const char *filename);
  112. /*!
  113. * \brief Sets an option flag
  114. * \param flag flag to set
  115. */
  116. void setFlag(TextureFlag flag);
  117. /*!
  118. * \brief Sets up GL texturing.
  119. *
  120. * Must be called as first setup step!
  121. * \param n maximum number of textures you wish to allow
  122. */
  123. void setMaxTextureCount(unsigned int n);
  124. void useMultiTexture(float u, float v);
  125. void useMultiTexture(float aU, float aV, float bU, float bV);
  126. private:
  127. unsigned int *mTextureIds; //!< GL texture list
  128. unsigned int mTextureCount; //!< Texture counter
  129. unsigned int mTextureLimit; //!< The texture limit
  130. unsigned int mFlags; //!< Class options
  131. };
  132. #endif