BsGLTexture.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "Image/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 GLTexture : public Texture
  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. /**
  34. * Generates an OpenGL texture target based on the texture type, number of samples per pixel, and number of faces.
  35. */
  36. static GLenum getGLTextureTarget(TextureType type, UINT32 numSamples, UINT32 numFaces);
  37. protected:
  38. friend class GLTextureManager;
  39. GLTexture(GLSupport& support, const TEXTURE_DESC& desc, const SPtr<PixelData>& initialData,
  40. GpuDeviceFlags deviceMask);
  41. /** @copydoc Texture::initialize */
  42. void initialize() override;
  43. /** @copydoc Texture::lock */
  44. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0, UINT32 deviceIdx = 0,
  45. UINT32 queueIdx = 0) override;
  46. /** @copydoc Texture::unlock */
  47. void unlockImpl() override;
  48. /** @copydoc Texture::copyImpl */
  49. void copyImpl(const SPtr<Texture>& target, const TEXTURE_COPY_DESC& desc,
  50. const SPtr<CommandBuffer>& commandBuffer) override;
  51. /** @copydoc Texture::readData */
  52. void readDataImpl(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0, UINT32 deviceIdx = 0,
  53. UINT32 queueIdx = 0) override;
  54. /** @copydoc Texture::writeData */
  55. void writeDataImpl(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false,
  56. UINT32 queueIdx = 0) override;
  57. /** Creates pixel buffers for each face and mip level. Texture must have been created previously. */
  58. void createSurfaceList();
  59. /** Creates an empty and uninitialized texture view object. */
  60. SPtr<TextureView> createView(const TEXTURE_VIEW_DESC& desc) override;
  61. private:
  62. GLuint mTextureID;
  63. GLenum mGLFormat;
  64. PixelFormat mInternalFormat;
  65. GLSupport& mGLSupport;
  66. SPtr<GLPixelBuffer> mLockedBuffer;
  67. Vector<SPtr<GLPixelBuffer>>mSurfaceList;
  68. };
  69. /** @} */
  70. }}