OgreGLESFBORenderTexture.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 __OgreGLESFBORTT_H__
00029 #define __OgreGLESFBORTT_H__
00030 
00031 #include "OgreGLESRenderTexture.h"
00032 #include "OgreGLESContext.h"
00033 #include "OgreGLESFrameBufferObject.h"
00034 #include "OgreGLESManagedResource.h"
00035 
00036 namespace Ogre {
00037     class GLESFBOManager;
00038     class GLESRenderBuffer;
00039 
00042     class _OgreGLESExport GLESFBORenderTexture: public GLESRenderTexture MANAGED_RESOURCE
00043     {
00044     public:
00045         GLESFBORenderTexture(GLESFBOManager *manager, const String &name, const GLESSurfaceDesc &target, bool writeGamma, uint fsaa);
00046 
00047         virtual void getCustomAttribute(const String& name, void* pData);
00048 
00050         virtual void swapBuffers();
00051 
00053         virtual bool attachDepthBuffer( DepthBuffer *depthBuffer );
00054         virtual void detachDepthBuffer();
00055         virtual void _detachDepthBuffer();
00056     protected:
00057         GLESFrameBufferObject mFB;
00058         
00059 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
00060 
00061         virtual void notifyOnContextLost();
00062         
00064         virtual void notifyOnContextReset();
00065 #endif
00066     };
00067     
00070     class _OgreGLESExport GLESFBOManager: public GLESRTTManager
00071     {
00072     public:
00073         GLESFBOManager();
00074         ~GLESFBOManager();
00075         
00079         void bind(RenderTarget *target);
00080         
00083         void unbind(RenderTarget *target) {};
00084         
00087         void getBestDepthStencil(GLenum internalFormat, GLenum *depthFormat, GLenum *stencilFormat);
00088         
00091         virtual GLESFBORenderTexture *createRenderTexture(const String &name, 
00092             const GLESSurfaceDesc &target, bool writeGamma, uint fsaa);
00093 
00096         virtual MultiRenderTarget* createMultiRenderTarget(const String & name);
00097         
00100         GLESSurfaceDesc requestRenderBuffer(GLenum format, size_t width, size_t height, uint fsaa);
00104         void requestRenderBuffer(const GLESSurfaceDesc &surface);
00107         void releaseRenderBuffer(const GLESSurfaceDesc &surface);
00108         
00111         bool checkFormat(PixelFormat format) { return mProps[format].valid; }
00112         
00115         GLuint getTemporaryFBO() { return mTempFBO; }
00116         
00118         void _reload();
00119         
00120     private:
00123         struct FormatProperties
00124         {
00125             bool valid; // This format can be used as RTT (FBO)
00126             
00129             struct Mode
00130             {
00131                 size_t depth;     // Depth format (0=no depth)
00132                 size_t stencil;   // Stencil format (0=no stencil)
00133             };
00134             
00135             vector<Mode>::type modes;
00136         };
00139         FormatProperties mProps[PF_COUNT];
00140         
00145         struct RBFormat
00146         {
00147             RBFormat(GLenum inFormat, size_t inWidth, size_t inHeight, uint fsaa):
00148                 format(inFormat), width(inWidth), height(inHeight), samples(fsaa)
00149             {}
00150             GLenum format;
00151             size_t width;
00152             size_t height;
00153             uint samples;
00154             // Overloaded comparison operator for usage in map
00155             bool operator < (const RBFormat &other) const
00156             {
00157                 if(format < other.format)
00158                 {
00159                     return true;
00160                 }
00161                 else if(format == other.format)
00162                 {
00163                     if(width < other.width)
00164                     {
00165                         return true;
00166                     }
00167                     else if(width == other.width)
00168                     {
00169                         if(height < other.height)
00170                             return true;
00171                         else if (height == other.height)
00172                         {
00173                             if (samples < other.samples)
00174                                 return true;
00175                         }
00176                     }
00177                 }
00178                 return false;
00179             }
00180         };
00181         struct RBRef
00182         {
00183             RBRef(){}
00184             RBRef(GLESRenderBuffer *inBuffer):
00185                 buffer(inBuffer), refcount(1)
00186             { }
00187             GLESRenderBuffer *buffer;
00188             size_t refcount;
00189         };
00190         typedef map<RBFormat, RBRef>::type RenderBufferMap;
00191         RenderBufferMap mRenderBufferMap;
00192         // map(format, sizex, sizey) -> [GLSurface*,refcount]
00193         
00196         GLuint mTempFBO;
00197         
00199         void detectFBOFormats();
00200         GLuint _tryFormat(GLenum depthFormat, GLenum stencilFormat);
00201         bool _tryPackedFormat(GLenum packedFormat);
00202     };
00203 }
00204 
00205 #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