BsGLTexture.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 BansheeEngine
  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, TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps,
  36. PixelFormat format, int usage, bool hwGamma, UINT32 multisampleCount, UINT32 numArraySlices, const SPtr<PixelData>& initialData);
  37. /** @copydoc TextureCore::initialize */
  38. void initialize() override;
  39. /** @copydoc TextureCore::lock */
  40. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0) override;
  41. /** @copydoc TextureCore::unlock */
  42. void unlockImpl() override;
  43. /** @copydoc TextureCore::copyImpl */
  44. void copyImpl(UINT32 srcFace, UINT32 srcMipLevel, UINT32 destFace, UINT32 destMipLevel, const SPtr<TextureCore>& target) override;
  45. /** @copydoc TextureCore::readData */
  46. void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0) override;
  47. /** @copydoc TextureCore::writeData */
  48. void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false) override;
  49. /** Creates pixel buffers for each face and mip level. Texture must have been created previously. */
  50. void createSurfaceList();
  51. private:
  52. GLuint mTextureID;
  53. GLenum mGLFormat;
  54. GLSupport& mGLSupport;
  55. SPtr<GLPixelBuffer> mLockedBuffer;
  56. Vector<SPtr<GLPixelBuffer>>mSurfaceList;
  57. };
  58. /** @} */
  59. }