BsGLTexture.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. #include "BsGLPrerequisites.h"
  3. #include "BsRenderTexture.h"
  4. #include "BsTexture.h"
  5. #include "BsGLSupport.h"
  6. #include "BsPixelBuffer.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * @brief OpenGL implementation of a texture.
  11. */
  12. class BS_RSGL_EXPORT GLTexture : public Texture
  13. {
  14. public:
  15. virtual ~GLTexture();
  16. /**
  17. * @brief Returns OpenGL texture target type
  18. */
  19. GLenum getGLTextureTarget() const;
  20. /**
  21. * @brief Returns internal OpenGL texture handle.
  22. */
  23. GLuint getGLID() const;
  24. /**
  25. * @brief Returns the internal OpenGL format used by the texture.
  26. */
  27. GLenum getGLFormat() const { return mGLFormat; }
  28. /**
  29. * @brief Returns a hardware pixel buffer for a certain face and level of the texture.
  30. *
  31. * @param face Index of the texture face, if texture has more than one. Array index for
  32. * texture arrays and a cube face for cube textures.
  33. * @param mipmap Index of the mip level. 0 being the largest mip level.
  34. *
  35. * @note Cube face indices: +X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5)
  36. */
  37. std::shared_ptr<GLPixelBuffer> getBuffer(UINT32 face, UINT32 mipmap);
  38. protected:
  39. friend class GLTextureManager;
  40. GLTexture(GLSupport& support);
  41. /**
  42. * @copydoc Texture::initialize_internal
  43. */
  44. void initialize_internal();
  45. /**
  46. * @copydoc Texture::destroy_internal
  47. */
  48. void destroy_internal();
  49. /**
  50. * @copydoc Texture::lock
  51. */
  52. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0);
  53. /**
  54. * @copydoc Texture::unlock
  55. */
  56. void unlockImpl();
  57. /**
  58. * @copydoc Texture::copy
  59. */
  60. void copyImpl(UINT32 srcFace, UINT32 srcMipLevel, UINT32 destFace, UINT32 destMipLevel, TexturePtr& target);
  61. /**
  62. * @copydoc Texture::readData
  63. */
  64. void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0);
  65. /**
  66. * @copydoc Texture::writeData
  67. */
  68. void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false);
  69. /**
  70. * @brief Creates pixel buffers for each face and mip level. Texture must
  71. * have been created previously.
  72. */
  73. void createSurfaceList();
  74. private:
  75. GLuint mTextureID;
  76. GLenum mGLFormat;
  77. GLSupport& mGLSupport;
  78. std::shared_ptr<GLPixelBuffer> mLockedBuffer;
  79. Vector<std::shared_ptr<GLPixelBuffer>>mSurfaceList;
  80. };
  81. typedef std::shared_ptr<GLTexture> GLTexturePtr;
  82. }