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.

Texture.h 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. int loadPCX(const char *filename);
  108. /*!
  109. * \brief Resets all texture data
  110. */
  111. void reset();
  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. int nextPower(int seed);
  128. unsigned char *scaleBuffer(unsigned char *image, int width, int height,
  129. int components);
  130. unsigned int *mTextureIds; //!< GL texture list
  131. unsigned int mTextureCount; //!< Texture counter
  132. unsigned int mTextureLimit; //!< The texture limit
  133. unsigned int mFlags; //!< Class options
  134. int mTextureId; //!< Currently bound texture id
  135. int mTextureId2; //!< Multitexture Texture Id
  136. };
  137. #endif