2
0

BsGLTexture.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __GLTEXTURE_H__
  25. #define __GLTEXTURE_H__
  26. #include "BsGLPrerequisites.h"
  27. #include "BsRenderTexture.h"
  28. #include "BsTexture.h"
  29. #include "BsGLSupport.h"
  30. #include "BsPixelBuffer.h"
  31. namespace BansheeEngine {
  32. class BS_RSGL_EXPORT GLTexture : public Texture
  33. {
  34. public:
  35. virtual ~GLTexture();
  36. // Takes the engine texture type (1d/2d/3d/cube) and returns the appropriate GL one
  37. GLenum getGLTextureTarget(void) const;
  38. GLuint getGLID() const;
  39. /** Return hardware pixel buffer for a surface. This buffer can then
  40. be used to copy data from and to a particular level of the texture.
  41. @param face Face number, in case of a cubemap texture. Must be 0
  42. for other types of textures.
  43. For cubemaps, this is one of
  44. +X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5)
  45. @param mipmap Mipmap level. This goes from 0 for the first, largest
  46. mipmap level to getNumMipmaps()-1 for the smallest.
  47. @returns A shared pointer to a hardware pixel buffer
  48. @remarks The buffer is invalidated when the resource is unloaded or destroyed.
  49. Do not use it after the lifetime of the containing texture.
  50. */
  51. std::shared_ptr<GLPixelBuffer> getBuffer(UINT32 face, UINT32 mipmap);
  52. protected:
  53. friend class GLTextureManager;
  54. // Constructor
  55. GLTexture(GLSupport& support);
  56. /**
  57. * @copydoc Texture::initialize_internal()
  58. */
  59. void initialize_internal();
  60. /**
  61. * @copydoc Texture::destroy_internal()
  62. */
  63. void destroy_internal();
  64. /**
  65. * @copydoc Texture::lock
  66. */
  67. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0);
  68. /**
  69. * @copydoc Texture::unlock
  70. */
  71. void unlockImpl();
  72. /**
  73. * @copydoc Texture::copy
  74. */
  75. void copyImpl(TexturePtr& target);
  76. /**
  77. * @copydoc Texture::readData
  78. */
  79. void readData(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0);
  80. /**
  81. * @copydoc Texture::writeData
  82. */
  83. void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false);
  84. /** internal method, create GLHardwarePixelBuffers for every face and
  85. mipmap level. This method must be called after the GL texture object was created,
  86. the number of mipmaps was set (GL_TEXTURE_MAX_LEVEL) and glTexImageXD was called to
  87. actually allocate the buffer
  88. */
  89. void createSurfaceList();
  90. private:
  91. GLuint mTextureID;
  92. GLSupport& mGLSupport;
  93. std::shared_ptr<GLPixelBuffer> mLockedBuffer;
  94. /// Vector of pointers to subsurfaces
  95. typedef Vector<std::shared_ptr<GLPixelBuffer>> SurfaceList;
  96. SurfaceList mSurfaceList;
  97. };
  98. typedef std::shared_ptr<GLTexture> GLTexturePtr;
  99. }
  100. #endif // __GLTEXTURE_H__