BsGLPixelBuffer.h 4.5 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 __GLPIXELBUFFER_H__
  25. #define __GLPIXELBUFFER_H__
  26. #include "BsGLPrerequisites.h"
  27. #include "BsPixelBuffer.h"
  28. namespace BansheeEngine
  29. {
  30. class GLTextureBuffer;
  31. class BS_RSGL_EXPORT GLPixelBuffer: public PixelBuffer
  32. {
  33. public:
  34. // Upload a box of pixels to this buffer on the card
  35. virtual void upload(const PixelData &data, const PixelVolume &dest);
  36. // Download a box of pixels from the card
  37. virtual void download(const PixelData &data);
  38. virtual void blitFromTexture(GLTextureBuffer *src);
  39. virtual void blitFromTexture(GLTextureBuffer *src, const PixelVolume &srcBox, const PixelVolume &dstBox);
  40. protected:
  41. /// Lock a box
  42. PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options);
  43. /// Unlock a box
  44. void unlockImpl(void);
  45. // Internal buffer; either on-card or in system memory, freed/allocated on demand
  46. // depending on buffer usage
  47. PixelData mBuffer;
  48. GLenum mGLInternalFormat; // GL internal format
  49. GpuLockOptions mCurrentLockOptions;
  50. // Buffer allocation/freeage
  51. void allocateBuffer();
  52. void freeBuffer();
  53. public:
  54. /// Should be called by HardwareBufferManager
  55. GLPixelBuffer(UINT32 mWidth, UINT32 mHeight, UINT32 mDepth,
  56. PixelFormat mFormat,
  57. GpuBufferUsage usage);
  58. ~GLPixelBuffer();
  59. /** Bind surface to frame buffer. Needs FBO extension.
  60. */
  61. virtual void bindToFramebuffer(GLenum attachment, UINT32 zoffset);
  62. GLenum getGLFormat() { return mGLInternalFormat; }
  63. };
  64. /** Texture surface.
  65. */
  66. class BS_RSGL_EXPORT GLTextureBuffer: public GLPixelBuffer
  67. {
  68. public:
  69. /** Texture constructor */
  70. GLTextureBuffer(const String &baseName, GLenum target, GLuint id, GLint face,
  71. GLint level, GpuBufferUsage usage, bool softwareMipmap, bool writeGamma, UINT32 multisampleCount);
  72. ~GLTextureBuffer();
  73. /// @copydoc HardwarePixelBuffer::bindToFramebuffer
  74. virtual void bindToFramebuffer(GLenum attachment, UINT32 zoffset);
  75. /// Upload a box of pixels to this buffer on the card
  76. virtual void upload(const PixelData &data, const PixelVolume &dest);
  77. // Download a box of pixels from the card
  78. virtual void download(const PixelData &data);
  79. /// Copy from framebuffer
  80. void copyFromFramebuffer(UINT32 zoffset);
  81. void blitFromTexture(GLTextureBuffer *src, const PixelVolume &srcBox, const PixelVolume &dstBox);
  82. protected:
  83. // In case this is a texture level
  84. GLenum mTarget;
  85. GLenum mFaceTarget; // same as mTarget in case of GL_TEXTURE_xD, but cubemap face for cubemaps
  86. GLuint mTextureID;
  87. GLint mFace;
  88. GLint mLevel;
  89. bool mSoftwareMipmap; // Use GLU for mip mapping
  90. };
  91. /** Renderbuffer surface. Needs FBO extension.
  92. */
  93. class BS_RSGL_EXPORT GLRenderBuffer: public GLPixelBuffer
  94. {
  95. public:
  96. GLRenderBuffer(GLenum format, UINT32 width, UINT32 height, GLsizei numSamples);
  97. ~GLRenderBuffer();
  98. /// @copydoc GLHardwarePixelBuffer::bindToFramebuffer
  99. virtual void bindToFramebuffer(GLenum attachment, UINT32 zoffset);
  100. protected:
  101. // In case this is a render buffer
  102. GLuint mRenderbufferID;
  103. };
  104. };
  105. #endif