BsGLTexture.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsGLPrerequisites.h"
  6. #include "BsRenderTexture.h"
  7. #include "BsTexture.h"
  8. #include "BsGLSupport.h"
  9. #include "BsPixelBuffer.h"
  10. namespace BansheeEngine
  11. {
  12. /**
  13. * @brief OpenGL implementation of a texture.
  14. */
  15. class BS_RSGL_EXPORT GLTexture : public Texture
  16. {
  17. public:
  18. virtual ~GLTexture();
  19. /**
  20. * @brief Returns OpenGL texture target type
  21. */
  22. GLenum getGLTextureTarget() const;
  23. /**
  24. * @brief Returns internal OpenGL texture handle.
  25. */
  26. GLuint getGLID() const;
  27. /**
  28. * @brief Returns a hardware pixel buffer for a certain face and level of the texture.
  29. *
  30. * @param face Index of the texture face, if texture has more than one. Array index for
  31. * texture arrays and a cube face for cube textures.
  32. * @param mipmap Index of the mip level. 0 being the largest mip level.
  33. *
  34. * @note Cube face indices: +X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5)
  35. */
  36. std::shared_ptr<GLPixelBuffer> getBuffer(UINT32 face, UINT32 mipmap);
  37. protected:
  38. friend class GLTextureManager;
  39. GLTexture(GLSupport& support);
  40. /**
  41. * @copydoc Texture::initialize_internal
  42. */
  43. void initialize_internal();
  44. /**
  45. * @copydoc Texture::destroy_internal
  46. */
  47. void destroy_internal();
  48. /**
  49. * @copydoc Texture::lock
  50. */
  51. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0);
  52. /**
  53. * @copydoc Texture::unlock
  54. */
  55. void unlockImpl();
  56. /**
  57. * @copydoc Texture::copy
  58. */
  59. void copyImpl(TexturePtr& target);
  60. /**
  61. * @copydoc Texture::readData
  62. */
  63. void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0);
  64. /**
  65. * @copydoc Texture::writeData
  66. */
  67. void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false);
  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. GLSupport& mGLSupport;
  76. std::shared_ptr<GLPixelBuffer> mLockedBuffer;
  77. Vector<std::shared_ptr<GLPixelBuffer>>mSurfaceList;
  78. };
  79. typedef std::shared_ptr<GLTexture> GLTexturePtr;
  80. }