Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/RenderSystems/GL/include/OgreGLFBORenderTexture.h @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 6.5 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#ifndef __OgreGLFBORTT_H__
30#define __OgreGLFBORTT_H__
31
32#include "OgreGLRenderTexture.h"
33#include "OgreGLContext.h"
34#include "OgreGLFrameBufferObject.h"
35
36/// Extra GL constants
37#define GL_DEPTH24_STENCIL8_EXT                           0x88F0
38
39
40namespace Ogre {
41    class GLFBOManager;
42
43    /** RenderTexture for GL FBO
44    */
45    class _OgrePrivate GLFBORenderTexture: public GLRenderTexture
46    {
47    public:
48        GLFBORenderTexture(GLFBOManager *manager, const String &name, const GLSurfaceDesc &target);
49
50        virtual void getCustomAttribute(const String& name, void* pData);
51    protected:
52        GLFrameBufferObject mFB;
53    };
54   
55    /** Factory for GL Frame Buffer Objects, and related things.
56    */
57    class _OgrePrivate GLFBOManager: public GLRTTManager
58    {
59    public:
60        GLFBOManager(bool atimode);
61                ~GLFBOManager();
62       
63        /** Bind a certain render target if it is a FBO. If it is not a FBO, bind the
64            main frame buffer.
65        */
66        void bind(RenderTarget *target);
67       
68        /** Unbind a certain render target. No-op for FBOs.
69        */
70        void unbind(RenderTarget *target) {};
71       
72        /** Get best depth and stencil supported for given internalFormat
73        */
74        void getBestDepthStencil(GLenum internalFormat, GLenum *depthFormat, GLenum *stencilFormat);
75       
76        /** Create a texture rendertarget object
77        */
78        virtual GLFBORenderTexture *createRenderTexture(const String &name, const GLSurfaceDesc &target);
79
80                /** Create a multi render target
81                */
82                virtual MultiRenderTarget* createMultiRenderTarget(const String & name);
83       
84        /** Create a framebuffer object
85        */
86        GLFrameBufferObject *createFrameBufferObject();
87       
88        /** Destroy a framebuffer object
89        */
90        void destroyFrameBufferObject(GLFrameBufferObject *);
91       
92        /** Request a render buffer. If format is GL_NONE, return a zero buffer.
93        */
94        GLSurfaceDesc requestRenderBuffer(GLenum format, size_t width, size_t height);
95        /** Request the specify render buffer in case shared somewhere. Ignore
96            silently if surface.buffer is 0.
97        */
98        void requestRenderBuffer(const GLSurfaceDesc &surface);
99        /** Release a render buffer. Ignore silently if surface.buffer is 0.
100        */
101        void releaseRenderBuffer(const GLSurfaceDesc &surface);
102       
103        /** Check if a certain format is usable as FBO rendertarget format
104        */
105        bool checkFormat(PixelFormat format) { return mProps[format].valid; }
106       
107        /** Get a FBO without depth/stencil for temporary use, like blitting between textures.
108        */
109        GLuint getTemporaryFBO() { return mTempFBO; }
110    private:
111        /** Frame Buffer Object properties for a certain texture format.
112        */
113        struct FormatProperties
114        {
115            bool valid; // This format can be used as RTT (FBO)
116           
117            /** Allowed modes/properties for this pixel format
118            */
119            struct Mode
120            {
121                size_t depth;     // Depth format (0=no depth)
122                size_t stencil;   // Stencil format (0=no stencil)
123            };
124           
125            std::vector<Mode> modes;
126        };
127        /** Properties for all internal formats defined by OGRE
128        */
129        FormatProperties mProps[PF_COUNT];
130       
131        /** Stencil and depth renderbuffers of the same format are re-used between surfaces of the
132            same size and format. This can save a lot of memory when a large amount of rendertargets
133            are used.
134        */
135        struct RBFormat
136        {
137            RBFormat(GLenum format, size_t width, size_t height):
138                format(format), width(width), height(height)
139            {}
140            GLenum format;
141            size_t width;
142            size_t height;
143            // Overloaded comparison operator for usage in map
144            bool operator < (const RBFormat &other) const
145            {
146                if(format < other.format)
147                {
148                    return true;
149                }
150                else if(format == other.format)
151                {
152                    if(width < other.width)
153                    {
154                        return true;
155                    }
156                    else if(width == other.width)
157                    {
158                        if(height < other.height)
159                            return true;
160                    }
161                }
162                return false;
163            }
164        };
165        struct RBRef
166        {
167            RBRef(){}
168            RBRef(GLRenderBuffer *buffer):
169                buffer(buffer), refcount(1)
170            { }
171            GLRenderBuffer *buffer;
172            size_t refcount;
173        };
174        typedef std::map<RBFormat, RBRef> RenderBufferMap;
175        RenderBufferMap mRenderBufferMap;
176        // map(format, sizex, sizey) -> [GLSurface*,refcount]
177       
178        /** Temporary FBO identifier
179         */
180        GLuint mTempFBO;
181       
182                /// Buggy ATI driver?
183                bool mATIMode;
184       
185        /** Detect allowed FBO formats */
186        void detectFBOFormats();
187        GLuint _tryFormat(GLenum depthFormat, GLenum stencilFormat);
188        bool _tryPackedFormat(GLenum packedFormat);
189    };
190   
191
192}
193
194#endif
Note: See TracBrowser for help on using the repository browser.