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.

Texture.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 Dumps a screenshot to disk.
  51. *
  52. * Avoids overwriting files with same base name.
  53. * \param base base filename
  54. * \param width viewport width
  55. * \param height viewport height
  56. */
  57. void glScreenShot(char *base, unsigned int width, unsigned int height);
  58. /*!
  59. * \brief Sets up multitexture rendering with passed ids
  60. * \param texture0 first texture for multitexture
  61. * \param texture1 second texture for multitexture
  62. */
  63. void bindMultiTexture(int texture0, int texture1);
  64. /*!
  65. * \brief Binds the texture for use in GL
  66. * \param n valid texture index
  67. */
  68. void bindTextureId(unsigned int n);
  69. /*!
  70. * \brief Clears an option flag
  71. * \param flag flag to clear
  72. */
  73. void clearFlag(TextureFlag flag);
  74. void disableMultiTexture();
  75. /*!
  76. * \brief Loads Buffer as texture
  77. * \param image pixmap matching other params
  78. * \param width width of image
  79. * \param height height of image
  80. * \param mode mode of image
  81. * \param bpp bits per pixel of image
  82. * \returns texture ID or < 0 on error
  83. */
  84. int loadBuffer(unsigned char *image,
  85. unsigned int width, unsigned int height,
  86. ColorMode mode, unsigned int bpp);
  87. /*!
  88. * \brief Loads Buffer as texture
  89. * \param image pixmap matching other params
  90. * \param width width of image
  91. * \param height height of image
  92. * \param mode mode of image
  93. * \param bpp bits per pixel of image
  94. * \param slot slot (ID) of image
  95. * \returns texture ID or < 0 on error
  96. */
  97. int loadBufferSlot(unsigned char *image,
  98. unsigned int width, unsigned int height,
  99. ColorMode mode, unsigned int bpp,
  100. unsigned int slot);
  101. /*!
  102. * \brief Generates and loads a solid color texture.
  103. * \param rgba color for new texture
  104. * \param width width of new texture
  105. * \param height height of new texture
  106. * \returns texture ID or -1 on error
  107. */
  108. int loadColorTexture(unsigned char rgba[4],
  109. unsigned int width, unsigned int height);
  110. /*!
  111. * \brief Loads TGA file as texture
  112. * \param filename Existing TGA file
  113. * \returns ID of new texture or -1 on error
  114. */
  115. int loadTGA(const char *filename);
  116. /*!
  117. * \brief Resets all texture data
  118. */
  119. void reset();
  120. /*!
  121. * \brief Sets an option flag
  122. * \param flag flag to set
  123. */
  124. void setFlag(TextureFlag flag);
  125. /*!
  126. * \brief Sets up GL texturing.
  127. *
  128. * Must be called as first setup step!
  129. * \param n maximum number of textures you wish to allow
  130. */
  131. void setMaxTextureCount(unsigned int n);
  132. void useMultiTexture(float u, float v);
  133. void useMultiTexture(float aU, float aV, float bU, float bV);
  134. private:
  135. int nextPower(int seed);
  136. unsigned char *scaleBuffer(unsigned char *image, int width, int height,
  137. int components);
  138. unsigned int *mTextureIds; //!< GL texture list
  139. unsigned int mTextureCount; //!< Texture counter
  140. unsigned int mTextureLimit; //!< The texture limit
  141. unsigned int mFlags; //!< Class options
  142. int mTextureId; //!< Currently bound texture id
  143. int mTextureId2; //!< Multitexture Texture Id
  144. };
  145. #endif