OgreGLES2FBORenderTexture.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 __OgreGLES2FBORTT_H__
    00029 #define __OgreGLES2FBORTT_H__
    00030
    00031 #include "OgreGLES2RenderTexture.h"
    00032 #include "OgreGLES2Context.h"
    00033 #include "OgreGLES2FrameBufferObject.h"
    00034
    00035 namespace Ogre {
    00036     class GLES2FBOManager;
    00037     class GLES2RenderBuffer;
    00038
    00041     class _OgreGLES2Export GLES2FBORenderTexture: public GLES2RenderTexture
    00042     {
    00043     public:
    00044         GLES2FBORenderTexture(GLES2FBOManager *manager, const String &name, const GLES2SurfaceDesc &target, bool writeGamma, uint fsaa);
    00045
    00046         virtual void getCustomAttribute(const String& name, void* pData);
    00047
    00049         virtual void swapBuffers(bool waitForVSync = true);
    00050
    00052         virtual bool attachDepthBuffer( DepthBuffer *depthBuffer );
    00053         virtual void detachDepthBuffer();
    00054         virtual void _detachDepthBuffer();
    00055     protected:
    00056         GLES2FrameBufferObject mFB;
    00057     };
    00058
    00061     class _OgreGLES2Export GLES2FBOManager: public GLES2RTTManager
    00062     {
    00063     public:
    00064         GLES2FBOManager();
    00065         ~GLES2FBOManager();
    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 GLES2FBORenderTexture *createRenderTexture(const String &name,
    00083             const GLES2SurfaceDesc &target, bool writeGamma, uint fsaa);
    00084
    00087         virtual MultiRenderTarget* createMultiRenderTarget(const String & name);
    00088
    00091         GLES2SurfaceDesc requestRenderBuffer(GLenum format, size_t width, size_t height, uint fsaa);
    00095         void requestRenderBuffer(const GLES2SurfaceDesc &surface);
    00098         void releaseRenderBuffer(const GLES2SurfaceDesc &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             GLenum format;
    00138             size_t width;
    00139             size_t height;
    00140             uint samples;
    00141             // Overloaded comparison operator for usage in map
    00142             bool operator < (const RBFormat &other) const
    00143             {
    00144                 if(format < other.format)
    00145                 {
    00146                     return true;
    00147                 }
    00148                 else if(format == other.format)
    00149                 {
    00150                     if(width < other.width)
    00151                     {
    00152                         return true;
    00153                     }
    00154                     else if(width == other.width)
    00155                     {
    00156                         if(height < other.height)
    00157                             return true;
    00158                         else if (height == other.height)
    00159                         {
    00160                             if (samples < other.samples)
    00161                                 return true;
    00162                         }
    00163                     }
    00164                 }
    00165                 return false;
    00166             }
    00167         };
    00168         struct RBRef
    00169         {
    00170             RBRef(){}
    00171             RBRef(GLES2RenderBuffer *inBuffer):
    00172                 buffer(inBuffer), refcount(1)
    00173             { }
    00174             GLES2RenderBuffer *buffer;
    00175             size_t refcount;
    00176         };
    00177         typedef map<RBFormat, RBRef>::type RenderBufferMap;
    00178         RenderBufferMap mRenderBufferMap;
    00179         // map(format, sizex, sizey) -> [GLSurface*,refcount]
    00180
    00183         GLuint mTempFBO;
    00184
    00186         void detectFBOFormats();
    00187         GLuint _tryFormat(GLenum depthFormat, GLenum stencilFormat);
    00188         bool _tryPackedFormat(GLenum packedFormat);
    00189     };
    00190 }
    00191
    00192 #endif

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