BsGLTexture.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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();
  46. /**
  47. * @copydoc TextureCore::destroy
  48. */
  49. void destroy();
  50. /**
  51. * @copydoc TextureCore::lock
  52. */
  53. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0);
  54. /**
  55. * @copydoc TextureCore::unlock
  56. */
  57. void unlockImpl();
  58. /**
  59. * @copydoc TextureCore::copy
  60. */
  61. void copyImpl(UINT32 srcFace, UINT32 srcMipLevel, UINT32 destFace, UINT32 destMipLevel, const SPtr<TextureCore>& target);
  62. /**
  63. * @copydoc TextureCore::readData
  64. */
  65. void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0);
  66. /**
  67. * @copydoc TextureCore::writeData
  68. */
  69. void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false);
  70. /**
  71. * @brief Creates pixel buffers for each face and mip level. Texture must
  72. * have been created previously.
  73. */
  74. void createSurfaceList();
  75. private:
  76. GLuint mTextureID;
  77. GLenum mGLFormat;
  78. GLSupport& mGLSupport;
  79. std::shared_ptr<GLPixelBuffer> mLockedBuffer;
  80. Vector<std::shared_ptr<GLPixelBuffer>>mSurfaceList;
  81. };
  82. }