[692] | 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-2005 The OGRE Team
|
---|
| 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 | */
|
---|
| 25 | #ifndef __OgreGLFBORTT_H__
|
---|
| 26 | #define __OgreGLFBORTT_H__
|
---|
| 27 |
|
---|
| 28 | #include "OgreGLRenderTexture.h"
|
---|
| 29 | #include "OgreGLContext.h"
|
---|
| 30 | #include "OgreGLFrameBufferObject.h"
|
---|
| 31 |
|
---|
| 32 | /// Extra GL constants
|
---|
| 33 | #define GL_DEPTH24_STENCIL8_EXT 0x88F0
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | namespace Ogre {
|
---|
| 37 | class GLFBOManager;
|
---|
| 38 |
|
---|
| 39 | /** RenderTexture for GL FBO
|
---|
| 40 | */
|
---|
| 41 | class GLFBORenderTexture: public GLRenderTexture
|
---|
| 42 | {
|
---|
| 43 | public:
|
---|
| 44 | GLFBORenderTexture(GLFBOManager *manager, const String &name, const GLSurfaceDesc &target);
|
---|
| 45 |
|
---|
| 46 | virtual void getCustomAttribute(const String& name, void* pData);
|
---|
| 47 | protected:
|
---|
| 48 | GLFrameBufferObject mFB;
|
---|
| 49 | };
|
---|
| 50 |
|
---|
| 51 | /** Factory for GL Frame Buffer Objects, and related things.
|
---|
| 52 | */
|
---|
| 53 | class GLFBOManager: public GLRTTManager
|
---|
| 54 | {
|
---|
| 55 | public:
|
---|
| 56 | GLFBOManager(bool atimode);
|
---|
| 57 | ~GLFBOManager();
|
---|
| 58 |
|
---|
| 59 | /** Bind a certain render target if it is a FBO. If it is not a FBO, bind the
|
---|
| 60 | main frame buffer.
|
---|
| 61 | */
|
---|
| 62 | void bind(RenderTarget *target);
|
---|
| 63 |
|
---|
| 64 | /** Unbind a certain render target. No-op for FBOs.
|
---|
| 65 | */
|
---|
| 66 | void unbind(RenderTarget *target) {};
|
---|
| 67 |
|
---|
| 68 | /** Get best depth and stencil supported for given internalFormat
|
---|
| 69 | */
|
---|
| 70 | void getBestDepthStencil(GLenum internalFormat, GLenum *depthFormat, GLenum *stencilFormat);
|
---|
| 71 |
|
---|
| 72 | /** Create a texture rendertarget object
|
---|
| 73 | */
|
---|
| 74 | virtual GLFBORenderTexture *createRenderTexture(const String &name, const GLSurfaceDesc &target);
|
---|
| 75 |
|
---|
| 76 | /** Create a multi render target
|
---|
| 77 | */
|
---|
| 78 | virtual MultiRenderTarget* createMultiRenderTarget(const String & name);
|
---|
| 79 |
|
---|
| 80 | /** Create a framebuffer object
|
---|
| 81 | */
|
---|
| 82 | GLFrameBufferObject *createFrameBufferObject();
|
---|
| 83 |
|
---|
| 84 | /** Destroy a framebuffer object
|
---|
| 85 | */
|
---|
| 86 | void destroyFrameBufferObject(GLFrameBufferObject *);
|
---|
| 87 |
|
---|
| 88 | /** Request a render buffer. If format is GL_NONE, return a zero buffer.
|
---|
| 89 | */
|
---|
| 90 | GLSurfaceDesc requestRenderBuffer(GLenum format, size_t width, size_t height);
|
---|
| 91 | /** Release a render buffer. Ignore silently if surface.buffer is 0.
|
---|
| 92 | */
|
---|
| 93 | void releaseRenderBuffer(const GLSurfaceDesc &surface);
|
---|
| 94 |
|
---|
| 95 | /** Check if a certain format is usable as FBO rendertarget format
|
---|
| 96 | */
|
---|
| 97 | bool checkFormat(PixelFormat format) { return mProps[format].valid; }
|
---|
| 98 |
|
---|
| 99 | /** Get a FBO without depth/stencil for temporary use, like blitting between textures.
|
---|
| 100 | */
|
---|
| 101 | GLuint getTemporaryFBO() { return mTempFBO; }
|
---|
| 102 | private:
|
---|
| 103 | /** Frame Buffer Object properties for a certain texture format.
|
---|
| 104 | */
|
---|
| 105 | struct FormatProperties
|
---|
| 106 | {
|
---|
| 107 | bool valid; // This format can be used as RTT (FBO)
|
---|
| 108 |
|
---|
| 109 | /** Allowed modes/properties for this pixel format
|
---|
| 110 | */
|
---|
| 111 | struct Mode
|
---|
| 112 | {
|
---|
| 113 | size_t depth; // Depth format (0=no depth)
|
---|
| 114 | size_t stencil; // Stencil format (0=no stencil)
|
---|
| 115 | };
|
---|
| 116 |
|
---|
| 117 | std::vector<Mode> modes;
|
---|
| 118 | };
|
---|
| 119 | /** Properties for all internal formats defined by OGRE
|
---|
| 120 | */
|
---|
| 121 | FormatProperties mProps[PF_COUNT];
|
---|
| 122 |
|
---|
| 123 | /** Stencil and depth renderbuffers of the same format are re-used between surfaces of the
|
---|
| 124 | same size and format. This can save a lot of memory when a large amount of rendertargets
|
---|
| 125 | are used.
|
---|
| 126 | */
|
---|
| 127 | struct RBFormat
|
---|
| 128 | {
|
---|
| 129 | RBFormat(GLenum format, size_t width, size_t height):
|
---|
| 130 | format(format), width(width), height(height)
|
---|
| 131 | {}
|
---|
| 132 | GLenum format;
|
---|
| 133 | size_t width;
|
---|
| 134 | size_t height;
|
---|
| 135 | // Overloaded comparison operator for usage in map
|
---|
| 136 | bool operator < (const RBFormat &other) const
|
---|
| 137 | {
|
---|
| 138 | if(format < other.format)
|
---|
| 139 | {
|
---|
| 140 | return true;
|
---|
| 141 | }
|
---|
| 142 | else if(format == other.format)
|
---|
| 143 | {
|
---|
| 144 | if(width < other.width)
|
---|
| 145 | {
|
---|
| 146 | return true;
|
---|
| 147 | }
|
---|
| 148 | else if(width == other.width)
|
---|
| 149 | {
|
---|
| 150 | if(height < other.height)
|
---|
| 151 | return true;
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
| 154 | return false;
|
---|
| 155 | }
|
---|
| 156 | };
|
---|
| 157 | struct RBRef
|
---|
| 158 | {
|
---|
| 159 | RBRef(){}
|
---|
| 160 | RBRef(GLRenderBuffer *buffer):
|
---|
| 161 | buffer(buffer), refcount(1)
|
---|
| 162 | { }
|
---|
| 163 | GLRenderBuffer *buffer;
|
---|
| 164 | size_t refcount;
|
---|
| 165 | };
|
---|
| 166 | typedef std::map<RBFormat, RBRef> RenderBufferMap;
|
---|
| 167 | RenderBufferMap mRenderBufferMap;
|
---|
| 168 | // map(format, sizex, sizey) -> [GLSurface*,refcount]
|
---|
| 169 |
|
---|
| 170 | /** Temporary FBO identifier
|
---|
| 171 | */
|
---|
| 172 | GLuint mTempFBO;
|
---|
| 173 |
|
---|
| 174 | /// Buggy ATI driver?
|
---|
| 175 | bool mATIMode;
|
---|
| 176 |
|
---|
| 177 | /** Detect allowed FBO formats */
|
---|
| 178 | void detectFBOFormats();
|
---|
| 179 | GLuint _tryFormat(GLenum depthFormat, GLenum stencilFormat);
|
---|
| 180 | };
|
---|
| 181 |
|
---|
| 182 |
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | #endif
|
---|