BsGLTexture.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 a hardware pixel buffer for a certain face and level of the texture.
  26. *
  27. * @param face Index of the texture face, if texture has more than one. Array index for
  28. * texture arrays and a cube face for cube textures.
  29. * @param mipmap Index of the mip level. 0 being the largest mip level.
  30. *
  31. * @note Cube face indices: +X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5)
  32. */
  33. std::shared_ptr<GLPixelBuffer> getBuffer(UINT32 face, UINT32 mipmap);
  34. protected:
  35. friend class GLTextureManager;
  36. GLTexture(GLSupport& support);
  37. /**
  38. * @copydoc Texture::initialize_internal
  39. */
  40. void initialize_internal();
  41. /**
  42. * @copydoc Texture::destroy_internal
  43. */
  44. void destroy_internal();
  45. /**
  46. * @copydoc Texture::lock
  47. */
  48. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0);
  49. /**
  50. * @copydoc Texture::unlock
  51. */
  52. void unlockImpl();
  53. /**
  54. * @copydoc Texture::copy
  55. */
  56. void copyImpl(TexturePtr& target);
  57. /**
  58. * @copydoc Texture::readData
  59. */
  60. void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0);
  61. /**
  62. * @copydoc Texture::writeData
  63. */
  64. void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false);
  65. /**
  66. * @brief Creates pixel buffers for each face and mip level. Texture must
  67. * have been created previously.
  68. */
  69. void createSurfaceList();
  70. private:
  71. GLuint mTextureID;
  72. GLSupport& mGLSupport;
  73. std::shared_ptr<GLPixelBuffer> mLockedBuffer;
  74. Vector<std::shared_ptr<GLPixelBuffer>>mSurfaceList;
  75. };
  76. typedef std::shared_ptr<GLTexture> GLTexturePtr;
  77. }