CmGLPixelBuffer.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 "CmPixelBuffer.h"
  28. namespace CamelotEngine {
  29. class CM_RSGL_EXPORT GLPixelBuffer: public PixelBuffer
  30. {
  31. protected:
  32. /// Lock a box
  33. PixelData lockImpl(const Box lockBox, GpuLockOptions 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. GpuLockOptions 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. GLPixelBuffer(UINT32 mWidth, UINT32 mHeight, UINT32 mDepth,
  51. PixelFormat mFormat,
  52. GpuBufferUsage 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. ~GLPixelBuffer();
  58. /** Bind surface to frame buffer. Needs FBO extension.
  59. */
  60. virtual void bindToFramebuffer(GLenum attachment, UINT32 zoffset);
  61. GLenum getGLFormat() { return mGLInternalFormat; }
  62. };
  63. /** Texture surface.
  64. */
  65. class CM_RSGL_EXPORT GLTextureBuffer: public GLPixelBuffer
  66. {
  67. public:
  68. /** Texture constructor */
  69. GLTextureBuffer(const String &baseName, GLenum target, GLuint id, GLint face,
  70. GLint level, GpuBufferUsage usage, bool softwareMipmap, bool writeGamma, UINT32 fsaa);
  71. ~GLTextureBuffer();
  72. /// @copydoc HardwarePixelBuffer::bindToFramebuffer
  73. virtual void bindToFramebuffer(GLenum attachment, UINT32 zoffset);
  74. /// Upload a box of pixels to this buffer on the card
  75. virtual void upload(const PixelData &data, const Box &dest);
  76. // Download a box of pixels from the card
  77. virtual void download(const PixelData &data);
  78. /// Hardware implementation of blitFromMemory
  79. virtual void blitFromMemory(const PixelData &src_orig, const Box &dstBox);
  80. /// Copy from framebuffer
  81. void copyFromFramebuffer(UINT32 zoffset);
  82. /// @copydoc HardwarePixelBuffer::blit
  83. void blit(const PixelBufferPtr &src, const Box &srcBox, const Box &dstBox);
  84. // Blitting implementation
  85. void blitFromTexture(GLTextureBuffer *src, const Box &srcBox, const Box &dstBox);
  86. protected:
  87. // In case this is a texture level
  88. GLenum mTarget;
  89. GLenum mFaceTarget; // same as mTarget in case of GL_TEXTURE_xD, but cubemap face for cubemaps
  90. GLuint mTextureID;
  91. GLint mFace;
  92. GLint mLevel;
  93. bool mSoftwareMipmap; // Use GLU for mip mapping
  94. };
  95. /** Renderbuffer surface. Needs FBO extension.
  96. */
  97. class CM_RSGL_EXPORT GLRenderBuffer: public GLPixelBuffer
  98. {
  99. public:
  100. GLRenderBuffer(GLenum format, UINT32 width, UINT32 height, GLsizei numSamples);
  101. ~GLRenderBuffer();
  102. /// @copydoc GLHardwarePixelBuffer::bindToFramebuffer
  103. virtual void bindToFramebuffer(GLenum attachment, UINT32 zoffset);
  104. protected:
  105. // In case this is a render buffer
  106. GLuint mRenderbufferID;
  107. };
  108. };
  109. #endif