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

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