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.

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