BsGLTexture.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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
  8. {
  9. /** @addtogroup GL
  10. * @{
  11. */
  12. /** OpenGL implementation of a texture. */
  13. class BS_RSGL_EXPORT GLTextureCore : public TextureCore
  14. {
  15. public:
  16. virtual ~GLTextureCore();
  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 GLTextureCoreManager;
  35. GLTextureCore(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 destFace, UINT32 destMipLevel,
  46. const SPtr<TextureCore>& target, UINT32 queueIdx = 0) override;
  47. /** @copydoc TextureCore::readData */
  48. void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0, UINT32 deviceIdx = 0,
  49. UINT32 queueIdx = 0) override;
  50. /** @copydoc TextureCore::writeData */
  51. void writeData(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. GLSupport& mGLSupport;
  59. SPtr<GLPixelBuffer> mLockedBuffer;
  60. Vector<SPtr<GLPixelBuffer>>mSurfaceList;
  61. };
  62. /** @} */
  63. }