BsGLTexture.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsGLPrerequisites.h"
  5. #include "BsTexture.h"
  6. #include "BsGLSupport.h"
  7. namespace bs { namespace ct
  8. {
  9. /** @addtogroup GL
  10. * @{
  11. */
  12. /** OpenGL implementation of a texture. */
  13. class BS_RSGL_EXPORT GLTexture : public TextureCore
  14. {
  15. public:
  16. virtual ~GLTexture();
  17. /** Returns OpenGL texture target type. */
  18. GLenum getGLTextureTarget() const;
  19. /** Returns internal OpenGL texture handle. */
  20. GLuint getGLID() const;
  21. /** Returns the internal OpenGL format used by the texture. */
  22. GLenum getGLFormat() const { return mGLFormat; }
  23. /**
  24. * Returns a hardware pixel buffer for a certain face and level of the texture.
  25. *
  26. * @param[in] face Index of the texture face, if texture has more than one. Array index for texture arrays and
  27. * a cube face for cube textures.
  28. * @param[in] mipmap Index of the mip level. 0 being the largest mip level.
  29. *
  30. * @note Cube face indices: +X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5)
  31. */
  32. SPtr<GLPixelBuffer> getBuffer(UINT32 face, UINT32 mipmap);
  33. protected:
  34. friend class GLTextureManager;
  35. GLTexture(GLSupport& support, const TEXTURE_DESC& desc, const SPtr<PixelData>& initialData,
  36. GpuDeviceFlags deviceMask);
  37. /** @copydoc TextureCore::initialize */
  38. void initialize() override;
  39. /** @copydoc TextureCore::lock */
  40. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0, UINT32 deviceIdx = 0,
  41. UINT32 queueIdx = 0) override;
  42. /** @copydoc TextureCore::unlock */
  43. void unlockImpl() override;
  44. /** @copydoc TextureCore::copyImpl */
  45. void copyImpl(UINT32 srcFace, UINT32 srcMipLevel, UINT32 dstFace, UINT32 dstMipLevel,
  46. const SPtr<TextureCore>& target, UINT32 queueIdx = 0) override;
  47. /** @copydoc TextureCore::readData */
  48. void readDataImpl(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0, UINT32 deviceIdx = 0,
  49. UINT32 queueIdx = 0) override;
  50. /** @copydoc TextureCore::writeData */
  51. void writeDataImpl(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false,
  52. UINT32 queueIdx = 0) override;
  53. /** Creates pixel buffers for each face and mip level. Texture must have been created previously. */
  54. void createSurfaceList();
  55. private:
  56. GLuint mTextureID;
  57. GLenum mGLFormat;
  58. PixelFormat mInternalFormat;
  59. GLSupport& mGLSupport;
  60. SPtr<GLPixelBuffer> mLockedBuffer;
  61. Vector<SPtr<GLPixelBuffer>>mSurfaceList;
  62. };
  63. /** @} */
  64. }}