CmGLTexture.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 "CmGLPrerequisites.h"
  27. #include "CmRenderTexture.h"
  28. #include "CmTexture.h"
  29. #include "CmGLSupport.h"
  30. #include "CmPixelBuffer.h"
  31. namespace CamelotFramework {
  32. class CM_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. PixelBufferPtr 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. PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel, UINT32 face);
  65. void unlockImpl();
  66. void copyImpl(TexturePtr& target);
  67. /** internal method, create GLHardwarePixelBuffers for every face and
  68. mipmap level. This method must be called after the GL texture object was created,
  69. the number of mipmaps was set (GL_TEXTURE_MAX_LEVEL) and glTexImageXD was called to
  70. actually allocate the buffer
  71. */
  72. void createSurfaceList();
  73. private:
  74. GLuint mTextureID;
  75. GLSupport& mGLSupport;
  76. PixelBufferPtr mLockedBuffer;
  77. /// Vector of pointers to subsurfaces
  78. typedef vector<PixelBufferPtr>::type SurfaceList;
  79. SurfaceList mSurfaceList;
  80. };
  81. typedef std::shared_ptr<GLTexture> GLTexturePtr;
  82. }
  83. #endif // __GLTEXTURE_H__