BsGLTexture.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. /** OpenGL implementation of a texture. */
  10. class BS_RSGL_EXPORT GLTextureCore : public TextureCore
  11. {
  12. public:
  13. virtual ~GLTextureCore();
  14. /** Returns OpenGL texture target type. */
  15. GLenum getGLTextureTarget() const;
  16. /** Returns internal OpenGL texture handle. */
  17. GLuint getGLID() const;
  18. /** Returns the internal OpenGL format used by the texture. */
  19. GLenum getGLFormat() const { return mGLFormat; }
  20. /**
  21. * Returns a hardware pixel buffer for a certain face and level of the texture.
  22. *
  23. * @param[in] face Index of the texture face, if texture has more than one. Array index for texture arrays and
  24. * a cube face for cube textures.
  25. * @param[in] mipmap Index of the mip level. 0 being the largest mip level.
  26. *
  27. * @note Cube face indices: +X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5)
  28. */
  29. std::shared_ptr<GLPixelBuffer> getBuffer(UINT32 face, UINT32 mipmap);
  30. protected:
  31. friend class GLTextureCoreManager;
  32. GLTextureCore(GLSupport& support, TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps,
  33. PixelFormat format, int usage, bool hwGamma, UINT32 multisampleCount, const PixelDataPtr& initialData);
  34. /** @copydoc TextureCore::initialize */
  35. void initialize() override;
  36. /** @copydoc TextureCore::lock */
  37. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0) override;
  38. /** @copydoc TextureCore::unlock */
  39. void unlockImpl() override;
  40. /** @copydoc TextureCore::copy */
  41. void copyImpl(UINT32 srcFace, UINT32 srcMipLevel, UINT32 destFace, UINT32 destMipLevel, const SPtr<TextureCore>& target) override;
  42. /** @copydoc TextureCore::readData */
  43. void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0) override;
  44. /** @copydoc TextureCore::writeData */
  45. void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false) override;
  46. /** Creates pixel buffers for each face and mip level. Texture must have been created previously. */
  47. void createSurfaceList();
  48. private:
  49. GLuint mTextureID;
  50. GLenum mGLFormat;
  51. GLSupport& mGLSupport;
  52. std::shared_ptr<GLPixelBuffer> mLockedBuffer;
  53. Vector<std::shared_ptr<GLPixelBuffer>>mSurfaceList;
  54. };
  55. }