[1] | 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 | |
---|
| 7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
| 8 | Also see acknowledgements in Readme.html |
---|
| 9 | |
---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
| 13 | version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
| 18 | |
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
| 23 | |
---|
| 24 | You may alternatively use this source under the terms of a specific version of |
---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 26 | Torus Knot Software Ltd. |
---|
| 27 | ----------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | #ifndef __GLPIXELBUFFER_H__ |
---|
| 30 | #define __GLPIXELBUFFER_H__ |
---|
| 31 | |
---|
| 32 | #include "OgreGLPrerequisites.h" |
---|
| 33 | #include "OgreHardwarePixelBuffer.h" |
---|
| 34 | |
---|
| 35 | namespace Ogre { |
---|
| 36 | class _OgrePrivate GLHardwarePixelBuffer: public HardwarePixelBuffer |
---|
| 37 | { |
---|
| 38 | protected: |
---|
| 39 | /// Lock a box |
---|
| 40 | PixelBox lockImpl(const Image::Box lockBox, LockOptions options); |
---|
| 41 | |
---|
| 42 | /// Unlock a box |
---|
| 43 | void unlockImpl(void); |
---|
| 44 | |
---|
| 45 | // Internal buffer; either on-card or in system memory, freed/allocated on demand |
---|
| 46 | // depending on buffer usage |
---|
| 47 | PixelBox mBuffer; |
---|
| 48 | GLenum mGLInternalFormat; // GL internal format |
---|
| 49 | LockOptions mCurrentLockOptions; |
---|
| 50 | |
---|
| 51 | // Buffer allocation/freeage |
---|
| 52 | void allocateBuffer(); |
---|
| 53 | void freeBuffer(); |
---|
| 54 | // Upload a box of pixels to this buffer on the card |
---|
| 55 | virtual void upload(const PixelBox &data); |
---|
| 56 | // Download a box of pixels from the card |
---|
| 57 | virtual void download(const PixelBox &data); |
---|
| 58 | public: |
---|
| 59 | /// Should be called by HardwareBufferManager |
---|
| 60 | GLHardwarePixelBuffer(size_t mWidth, size_t mHeight, size_t mDepth, |
---|
| 61 | PixelFormat mFormat, |
---|
| 62 | HardwareBuffer::Usage usage); |
---|
| 63 | |
---|
| 64 | /// @copydoc HardwarePixelBuffer::blitFromMemory |
---|
| 65 | void blitFromMemory(const PixelBox &src, const Image::Box &dstBox); |
---|
| 66 | |
---|
| 67 | /// @copydoc HardwarePixelBuffer::blitToMemory |
---|
| 68 | void blitToMemory(const Image::Box &srcBox, const PixelBox &dst); |
---|
| 69 | |
---|
| 70 | ~GLHardwarePixelBuffer(); |
---|
| 71 | |
---|
| 72 | /** Bind surface to frame buffer. Needs FBO extension. |
---|
| 73 | */ |
---|
| 74 | virtual void bindToFramebuffer(GLenum attachment, size_t zoffset); |
---|
| 75 | GLenum getGLFormat() { return mGLInternalFormat; } |
---|
| 76 | }; |
---|
| 77 | |
---|
| 78 | /** Texture surface. |
---|
| 79 | */ |
---|
| 80 | class _OgrePrivate GLTextureBuffer: public GLHardwarePixelBuffer |
---|
| 81 | { |
---|
| 82 | public: |
---|
| 83 | /** Texture constructor */ |
---|
| 84 | GLTextureBuffer(const String &baseName, GLenum target, GLuint id, GLint face, GLint level, Usage usage, |
---|
| 85 | bool softwareMipmap); |
---|
| 86 | ~GLTextureBuffer(); |
---|
| 87 | |
---|
| 88 | /// @copydoc GLHardwarePixelBuffer::bindToFramebuffer |
---|
| 89 | virtual void bindToFramebuffer(GLenum attachment, size_t zoffset); |
---|
| 90 | /// @copydoc ardwarePixelBuffer::getRenderTarget |
---|
| 91 | RenderTexture* getRenderTarget(size_t); |
---|
| 92 | // Upload a box of pixels to this buffer on the card |
---|
| 93 | virtual void upload(const PixelBox &data); |
---|
| 94 | // Download a box of pixels from the card |
---|
| 95 | virtual void download(const PixelBox &data); |
---|
| 96 | |
---|
| 97 | // Hardware implementation of blitFromMemory |
---|
| 98 | virtual void blitFromMemory(const PixelBox &src_orig, const Image::Box &dstBox); |
---|
| 99 | |
---|
| 100 | // Notify TextureBuffer of destruction of render target |
---|
| 101 | void _clearSliceRTT(size_t zoffset) |
---|
| 102 | { |
---|
| 103 | mSliceTRT[zoffset] = 0; |
---|
| 104 | } |
---|
| 105 | // Copy from framebuffer |
---|
| 106 | void copyFromFramebuffer(size_t zoffset); |
---|
| 107 | /// @copydoc HardwarePixelBuffer::blit |
---|
| 108 | void blit(const HardwarePixelBufferSharedPtr &src, const Image::Box &srcBox, const Image::Box &dstBox); |
---|
| 109 | // Blitting implementation |
---|
| 110 | void blitFromTexture(GLTextureBuffer *src, const Image::Box &srcBox, const Image::Box &dstBox); |
---|
| 111 | protected: |
---|
| 112 | // In case this is a texture level |
---|
| 113 | GLenum mTarget; |
---|
| 114 | GLenum mFaceTarget; // same as mTarget in case of GL_TEXTURE_xD, but cubemap face for cubemaps |
---|
| 115 | GLuint mTextureID; |
---|
| 116 | GLint mFace; |
---|
| 117 | GLint mLevel; |
---|
| 118 | bool mSoftwareMipmap; // Use GLU for mip mapping |
---|
| 119 | |
---|
| 120 | typedef std::vector<RenderTexture*> SliceTRT; |
---|
| 121 | SliceTRT mSliceTRT; |
---|
| 122 | }; |
---|
| 123 | /** Renderbuffer surface. Needs FBO extension. |
---|
| 124 | */ |
---|
| 125 | class _OgrePrivate GLRenderBuffer: public GLHardwarePixelBuffer |
---|
| 126 | { |
---|
| 127 | public: |
---|
| 128 | GLRenderBuffer(GLenum format, size_t width, size_t height); |
---|
| 129 | ~GLRenderBuffer(); |
---|
| 130 | |
---|
| 131 | /// @copydoc GLHardwarePixelBuffer::bindToFramebuffer |
---|
| 132 | virtual void bindToFramebuffer(GLenum attachment, size_t zoffset); |
---|
| 133 | protected: |
---|
| 134 | // In case this is a render buffer |
---|
| 135 | GLuint mRenderbufferID; |
---|
| 136 | }; |
---|
| 137 | }; |
---|
| 138 | |
---|
| 139 | #endif |
---|