OgreGLFBORenderTexture.h
Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef __OgreGLFBORTT_H__
00029 #define __OgreGLFBORTT_H__
00030 
00031 #include "OgreGLRenderTexture.h"
00032 #include "OgreGLContext.h"
00033 #include "OgreGLFrameBufferObject.h"
00034 
00036 #define GL_DEPTH24_STENCIL8_EXT                           0x88F0
00037 
00038 
00039 namespace Ogre {
00040     class GLFBOManager;
00041 
00044     class _OgreGLExport GLFBORenderTexture: public GLRenderTexture
00045     {
00046     public:
00047         GLFBORenderTexture(GLFBOManager *manager, const String &name, const GLSurfaceDesc &target, bool writeGamma, uint fsaa);
00048 
00049         virtual void getCustomAttribute(const String& name, void* pData);
00050 
00052         virtual void swapBuffers(bool waitForVSync = true);
00053 
00055         virtual bool attachDepthBuffer( DepthBuffer *depthBuffer );
00056         virtual void detachDepthBuffer();
00057         virtual void _detachDepthBuffer();
00058     protected:
00059         GLFrameBufferObject mFB;
00060     };
00061     
00064     class _OgreGLExport GLFBOManager: public GLRTTManager
00065     {
00066     public:
00067         GLFBOManager(bool atimode);
00068         ~GLFBOManager();
00069         
00073         void bind(RenderTarget *target);
00074         
00077         void unbind(RenderTarget *target) {};
00078         
00081         void getBestDepthStencil(GLenum internalFormat, GLenum *depthFormat, GLenum *stencilFormat);
00082         
00085         virtual GLFBORenderTexture *createRenderTexture(const String &name, 
00086             const GLSurfaceDesc &target, bool writeGamma, uint fsaa);
00087 
00090         virtual MultiRenderTarget* createMultiRenderTarget(const String & name);
00091         
00094         GLSurfaceDesc requestRenderBuffer(GLenum format, size_t width, size_t height, uint fsaa);
00098         void requestRenderBuffer(const GLSurfaceDesc &surface);
00101         void releaseRenderBuffer(const GLSurfaceDesc &surface);
00102         
00105         bool checkFormat(PixelFormat format) { return mProps[format].valid; }
00106         
00109         GLuint getTemporaryFBO() { return mTempFBO; }
00110     private:
00113         struct FormatProperties
00114         {
00115             bool valid; // This format can be used as RTT (FBO)
00116             
00119             struct Mode
00120             {
00121                 size_t depth;     // Depth format (0=no depth)
00122                 size_t stencil;   // Stencil format (0=no stencil)
00123             };
00124             
00125             vector<Mode>::type modes;
00126         };
00129         FormatProperties mProps[PF_COUNT];
00130         
00135         struct RBFormat
00136         {
00137             RBFormat(GLenum inFormat, size_t inWidth, size_t inHeight, uint fsaa):
00138                 format(inFormat), width(inWidth), height(inHeight), samples(fsaa)
00139             {}
00140             GLenum format;
00141             size_t width;
00142             size_t height;
00143             uint samples;
00144             // Overloaded comparison operator for usage in map
00145             bool operator < (const RBFormat &other) const
00146             {
00147                 if(format < other.format)
00148                 {
00149                     return true;
00150                 }
00151                 else if(format == other.format)
00152                 {
00153                     if(width < other.width)
00154                     {
00155                         return true;
00156                     }
00157                     else if(width == other.width)
00158                     {
00159                         if(height < other.height)
00160                             return true;
00161                         else if (height == other.height)
00162                         {
00163                             if (samples < other.samples)
00164                                 return true;
00165                         }
00166                     }
00167                 }
00168                 return false;
00169             }
00170         };
00171         struct RBRef
00172         {
00173             RBRef(){}
00174             RBRef(GLRenderBuffer *inBuffer):
00175                 buffer(inBuffer), refcount(1)
00176             { }
00177             GLRenderBuffer *buffer;
00178             size_t refcount;
00179         };
00180         typedef map<RBFormat, RBRef>::type RenderBufferMap;
00181         RenderBufferMap mRenderBufferMap;
00182         // map(format, sizex, sizey) -> [GLSurface*,refcount]
00183         
00186         GLuint mTempFBO;
00187         
00189         bool mATIMode;
00190         
00192         void detectFBOFormats();
00193         GLuint _tryFormat(GLenum depthFormat, GLenum stencilFormat);
00194         bool _tryPackedFormat(GLenum packedFormat);
00195     };
00196     
00197 
00198 }
00199 
00200 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:21