Open Source Tomb Raider Engine
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Texture.h 4.7KB

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