BsGLTexture.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. class BS_RSGL_EXPORT GLTexture : public Texture
  10. {
  11. public:
  12. virtual ~GLTexture();
  13. // Takes the engine texture type (1d/2d/3d/cube) and returns the appropriate GL one
  14. GLenum getGLTextureTarget(void) const;
  15. GLuint getGLID() const;
  16. /** Return hardware pixel buffer for a surface. This buffer can then
  17. be used to copy data from and to a particular level of the texture.
  18. @param face Face number, in case of a cubemap texture. Must be 0
  19. for other types of textures.
  20. For cubemaps, this is one of
  21. +X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5)
  22. @param mipmap Mipmap level. This goes from 0 for the first, largest
  23. mipmap level to getNumMipmaps()-1 for the smallest.
  24. @returns A shared pointer to a hardware pixel buffer
  25. @remarks The buffer is invalidated when the resource is unloaded or destroyed.
  26. Do not use it after the lifetime of the containing texture.
  27. */
  28. std::shared_ptr<GLPixelBuffer> getBuffer(UINT32 face, UINT32 mipmap);
  29. protected:
  30. friend class GLTextureManager;
  31. // Constructor
  32. GLTexture(GLSupport& support);
  33. /**
  34. * @copydoc Texture::initialize_internal()
  35. */
  36. void initialize_internal();
  37. /**
  38. * @copydoc Texture::destroy_internal()
  39. */
  40. void destroy_internal();
  41. /**
  42. * @copydoc Texture::lock
  43. */
  44. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0);
  45. /**
  46. * @copydoc Texture::unlock
  47. */
  48. void unlockImpl();
  49. /**
  50. * @copydoc Texture::copy
  51. */
  52. void copyImpl(TexturePtr& target);
  53. /**
  54. * @copydoc Texture::readData
  55. */
  56. void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0);
  57. /**
  58. * @copydoc Texture::writeData
  59. */
  60. void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false);
  61. /** internal method, create GLHardwarePixelBuffers for every face and
  62. mipmap level. This method must be called after the GL texture object was created,
  63. the number of mipmaps was set (GL_TEXTURE_MAX_LEVEL) and glTexImageXD was called to
  64. actually allocate the buffer
  65. */
  66. void createSurfaceList();
  67. private:
  68. GLuint mTextureID;
  69. GLSupport& mGLSupport;
  70. std::shared_ptr<GLPixelBuffer> mLockedBuffer;
  71. /// Vector of pointers to subsurfaces
  72. typedef Vector<std::shared_ptr<GLPixelBuffer>> SurfaceList;
  73. SurfaceList mSurfaceList;
  74. };
  75. typedef std::shared_ptr<GLTexture> GLTexturePtr;
  76. }