OgreGL3PlusFBORenderTexture.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-2013 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 __OgreGL3PlusFBORTT_H__
00029 #define __OgreGL3PlusFBORTT_H__
00030 
00031 #include "OgreGL3PlusRenderTexture.h"
00032 #include "OgreGL3PlusContext.h"
00033 #include "OgreGL3PlusFrameBufferObject.h"
00034 
00035 namespace Ogre {
00036     class GL3PlusFBOManager;
00037     class GL3PlusRenderBuffer;
00038 
00041     class _OgreGL3PlusExport GL3PlusFBORenderTexture: public GL3PlusRenderTexture
00042     {
00043     public:
00044         GL3PlusFBORenderTexture(GL3PlusFBOManager *manager, const String &name, const GL3PlusSurfaceDesc &target, bool writeGamma, uint fsaa);
00045 
00046         virtual void getCustomAttribute(const String& name, void* pData);
00047 
00049         virtual void swapBuffers();
00050 
00052         virtual bool attachDepthBuffer( DepthBuffer *depthBuffer );
00053         virtual void detachDepthBuffer();
00054         virtual void _detachDepthBuffer();
00055     protected:
00056         GL3PlusFrameBufferObject mFB;
00057     };
00058     
00061     class _OgreGL3PlusExport GL3PlusFBOManager: public GL3PlusRTTManager
00062     {
00063     public:
00064         GL3PlusFBOManager();
00065         ~GL3PlusFBOManager();
00066         
00070         void bind(RenderTarget *target);
00071         
00074         void unbind(RenderTarget *target) {};
00075         
00078         void getBestDepthStencil(GLenum internalFormat, GLenum *depthFormat, GLenum *stencilFormat);
00079         
00082         virtual GL3PlusFBORenderTexture *createRenderTexture(const String &name, 
00083             const GL3PlusSurfaceDesc &target, bool writeGamma, uint fsaa);
00084 
00087         virtual MultiRenderTarget* createMultiRenderTarget(const String & name);
00088         
00091         GL3PlusSurfaceDesc requestRenderBuffer(GLenum format, uint32 width, uint32 height, uint fsaa);
00095         void requestRenderBuffer(const GL3PlusSurfaceDesc &surface);
00098         void releaseRenderBuffer(const GL3PlusSurfaceDesc &surface);
00099         
00102         bool checkFormat(PixelFormat format) { return mProps[format].valid; }
00103         
00106         GLuint getTemporaryFBO() { return mTempFBO; }
00107     private:
00110         struct FormatProperties
00111         {
00112             bool valid; // This format can be used as RTT (FBO)
00113             
00116             struct Mode
00117             {
00118                 size_t depth;     // Depth format (0=no depth)
00119                 size_t stencil;   // Stencil format (0=no stencil)
00120             };
00121             
00122             vector<Mode>::type modes;
00123         };
00126         FormatProperties mProps[PF_COUNT];
00127         
00132         struct RBFormat
00133         {
00134             RBFormat(GLenum inFormat, size_t inWidth, size_t inHeight, uint fsaa):
00135                 format(inFormat), width(inWidth), height(inHeight), samples(fsaa)
00136             {}
00137             RBFormat() {}
00138             GLenum format;
00139             size_t width;
00140             size_t height;
00141             uint samples;
00142             // Overloaded comparison operator for usage in map
00143             bool operator < (const RBFormat &other) const
00144             {
00145                 if(format < other.format)
00146                 {
00147                     return true;
00148                 }
00149                 else if(format == other.format)
00150                 {
00151                     if(width < other.width)
00152                     {
00153                         return true;
00154                     }
00155                     else if(width == other.width)
00156                     {
00157                         if(height < other.height)
00158                             return true;
00159                         else if (height == other.height)
00160                         {
00161                             if (samples < other.samples)
00162                                 return true;
00163                         }
00164                     }
00165                 }
00166                 return false;
00167             }
00168         };
00169         struct RBRef
00170         {
00171             RBRef(){}
00172             RBRef(GL3PlusRenderBuffer *inBuffer):
00173                 buffer(inBuffer), refcount(1)
00174             { }
00175             GL3PlusRenderBuffer *buffer;
00176             size_t refcount;
00177         };
00178         typedef map<RBFormat, RBRef>::type RenderBufferMap;
00179         RenderBufferMap mRenderBufferMap;
00180         
00183         GLuint mTempFBO;
00184         
00186         void detectFBOFormats();
00187         GLuint _tryFormat(GLenum depthFormat, GLenum stencilFormat);
00188         bool _tryPackedFormat(GLenum packedFormat);
00189         void _createTempFramebuffer(int ogreFormat, GLuint internalFormat, GLuint fmt, GLenum dataType, GLuint &fb, GLuint &tid);
00190     };
00191 }
00192 
00193 #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 Mon Jul 27 2020 13:40:42