BsGLTexture.h 2.9 KB

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