BsGLTexture.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #include "BsGLPrerequisites.h"
  3. #include "BsRenderTexture.h"
  4. #include "BsTexture.h"
  5. #include "BsGLSupport.h"
  6. #include "BsPixelBuffer.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * @brief OpenGL implementation of a texture.
  11. */
  12. class BS_RSGL_EXPORT GLTextureCore : public TextureCore
  13. {
  14. public:
  15. virtual ~GLTextureCore();
  16. /**
  17. * @brief Returns OpenGL texture target type
  18. */
  19. GLenum getGLTextureTarget() const;
  20. /**
  21. * @brief Returns internal OpenGL texture handle.
  22. */
  23. GLuint getGLID() const;
  24. /**
  25. * @brief Returns the internal OpenGL format used by the texture.
  26. */
  27. GLenum getGLFormat() const { return mGLFormat; }
  28. /**
  29. * @brief Returns a hardware pixel buffer for a certain face and level of the texture.
  30. *
  31. * @param face Index of the texture face, if texture has more than one. Array index for
  32. * texture arrays and a cube face for cube textures.
  33. * @param mipmap Index of the mip level. 0 being the largest mip level.
  34. *
  35. * @note Cube face indices: +X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5)
  36. */
  37. std::shared_ptr<GLPixelBuffer> getBuffer(UINT32 face, UINT32 mipmap);
  38. protected:
  39. friend class GLTextureCoreManager;
  40. GLTextureCore(GLSupport& support, TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps,
  41. PixelFormat format, int usage, bool hwGamma, UINT32 multisampleCount);
  42. /**
  43. * @copydoc TextureCore::initialize
  44. */
  45. void initialize() override;
  46. /**
  47. * @copydoc TextureCore::lock
  48. */
  49. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0) override;
  50. /**
  51. * @copydoc TextureCore::unlock
  52. */
  53. void unlockImpl() override;
  54. /**
  55. * @copydoc TextureCore::copy
  56. */
  57. void copyImpl(UINT32 srcFace, UINT32 srcMipLevel, UINT32 destFace, UINT32 destMipLevel, const SPtr<TextureCore>& target) override;
  58. /**
  59. * @copydoc TextureCore::readData
  60. */
  61. void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0) override;
  62. /**
  63. * @copydoc TextureCore::writeData
  64. */
  65. void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false) override;
  66. /**
  67. * @brief Creates pixel buffers for each face and mip level. Texture must
  68. * have been created previously.
  69. */
  70. void createSurfaceList();
  71. private:
  72. GLuint mTextureID;
  73. GLenum mGLFormat;
  74. GLSupport& mGLSupport;
  75. std::shared_ptr<GLPixelBuffer> mLockedBuffer;
  76. Vector<std::shared_ptr<GLPixelBuffer>>mSurfaceList;
  77. };
  78. }