CmGLHardwarePixelBuffer.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 __GLPIXELBUFFER_H__
  25. #define __GLPIXELBUFFER_H__
  26. #include "CmGLPrerequisites.h"
  27. #include "CmHardwarePixelBuffer.h"
  28. namespace CamelotEngine {
  29. class _OgreGLExport GLHardwarePixelBuffer: public HardwarePixelBuffer
  30. {
  31. protected:
  32. /// Lock a box
  33. PixelData lockImpl(const Box lockBox, LockOptions options);
  34. /// Unlock a box
  35. void unlockImpl(void);
  36. // Internal buffer; either on-card or in system memory, freed/allocated on demand
  37. // depending on buffer usage
  38. PixelData mBuffer;
  39. GLenum mGLInternalFormat; // GL internal format
  40. LockOptions mCurrentLockOptions;
  41. // Buffer allocation/freeage
  42. void allocateBuffer();
  43. void freeBuffer();
  44. // Upload a box of pixels to this buffer on the card
  45. virtual void upload(const PixelData &data, const Box &dest);
  46. // Download a box of pixels from the card
  47. virtual void download(const PixelData &data);
  48. public:
  49. /// Should be called by HardwareBufferManager
  50. GLHardwarePixelBuffer(size_t mWidth, size_t mHeight, size_t mDepth,
  51. PixelFormat mFormat,
  52. HardwareBuffer::Usage usage);
  53. /// @copydoc HardwarePixelBuffer::blitFromMemory
  54. void blitFromMemory(const PixelData &src, const Box &dstBox);
  55. /// @copydoc HardwarePixelBuffer::blitToMemory
  56. void blitToMemory(const Box &srcBox, const PixelData &dst);
  57. ~GLHardwarePixelBuffer();
  58. /** Bind surface to frame buffer. Needs FBO extension.
  59. */
  60. virtual void bindToFramebuffer(GLenum attachment, size_t zoffset);
  61. GLenum getGLFormat() { return mGLInternalFormat; }
  62. };
  63. /** Texture surface.
  64. */
  65. class _OgreGLExport GLTextureBuffer: public GLHardwarePixelBuffer
  66. {
  67. public:
  68. /** Texture constructor */
  69. GLTextureBuffer(const String &baseName, GLenum target, GLuint id, GLint face,
  70. GLint level, Usage usage, bool softwareMipmap, bool writeGamma, UINT32 fsaa);
  71. ~GLTextureBuffer();
  72. /// @copydoc HardwarePixelBuffer::bindToFramebuffer
  73. virtual void bindToFramebuffer(GLenum attachment, size_t zoffset);
  74. /// @copydoc HardwarePixelBuffer::getRenderTarget
  75. RenderTexture* getRenderTarget(size_t);
  76. /// Upload a box of pixels to this buffer on the card
  77. virtual void upload(const PixelData &data, const Box &dest);
  78. // Download a box of pixels from the card
  79. virtual void download(const PixelData &data);
  80. /// Hardware implementation of blitFromMemory
  81. virtual void blitFromMemory(const PixelData &src_orig, const Box &dstBox);
  82. /// Notify TextureBuffer of destruction of render target
  83. void _clearSliceRTT(size_t zoffset)
  84. {
  85. mSliceTRT[zoffset] = 0;
  86. }
  87. /// Copy from framebuffer
  88. void copyFromFramebuffer(size_t zoffset);
  89. /// @copydoc HardwarePixelBuffer::blit
  90. void blit(const HardwarePixelBufferPtr &src, const Box &srcBox, const Box &dstBox);
  91. // Blitting implementation
  92. void blitFromTexture(GLTextureBuffer *src, const Box &srcBox, const Box &dstBox);
  93. protected:
  94. // In case this is a texture level
  95. GLenum mTarget;
  96. GLenum mFaceTarget; // same as mTarget in case of GL_TEXTURE_xD, but cubemap face for cubemaps
  97. GLuint mTextureID;
  98. GLint mFace;
  99. GLint mLevel;
  100. bool mSoftwareMipmap; // Use GLU for mip mapping
  101. typedef vector<RenderTexture*>::type SliceTRT;
  102. SliceTRT mSliceTRT;
  103. };
  104. /** Renderbuffer surface. Needs FBO extension.
  105. */
  106. class _OgreGLExport GLRenderBuffer: public GLHardwarePixelBuffer
  107. {
  108. public:
  109. GLRenderBuffer(GLenum format, size_t width, size_t height, GLsizei numSamples);
  110. ~GLRenderBuffer();
  111. /// @copydoc GLHardwarePixelBuffer::bindToFramebuffer
  112. virtual void bindToFramebuffer(GLenum attachment, size_t zoffset);
  113. protected:
  114. // In case this is a render buffer
  115. GLuint mRenderbufferID;
  116. };
  117. };
  118. #endif