FrameBufferObject.h
Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // File : FramebufferObject.h
00003 //------------------------------------------------------------------------------
00004 // Copyright (c) 2006 Gordon Wetzstein [gordon.wetzstein@medien.uni-weimar.de]
00005 //---------------------------------------------------------------------------
00006 // This software is provided 'as-is', without any express or implied
00007 // warranty. In no event will the authors be held liable for any
00008 // damages arising from the use of this software.
00009 //
00010 // Permission is granted to anyone to use this software for any
00011 // purpose, including commercial applications, and to alter it and
00012 // redistribute it freely, subject to the following restrictions:
00013 //
00014 // 1. The origin of this software must not be misrepresented; you
00015 //    must not claim that you wrote the original software. If you use
00016 //    this software in a product, an acknowledgment in the product
00017 //    documentation would be appreciated but is not required.
00018 //
00019 // 2. Altered source versions must be plainly marked as such, and
00020 //    must not be misrepresented as being the original software.
00021 //
00022 // 3. This notice may not be removed or altered from any source
00023 //    distribution.
00024 //
00025 // -----------------------------------------------------------------------------
00026 //
00027 // Credits:
00028 // Original RenderTexture code: Mark J. Harris
00029 //      parts of the code are used from the original RenderTexture  
00030 //
00031 // -----------------------------------------------------------------------------
00032 /*
00033 * The pixel format for the pbuffer is controlled by the mode string passed
00034 * into the FramebufferObject constructor. This string can have the 
00035 *       following attributes:
00036 *
00037 * To specify the pixel format, use the following syntax.
00038 *   <channels>=<bits>
00039 * <channels> must match one of the following.
00040 *
00041 *       rgba=n[t]               - currently only RGBA and RGB color attachments are supported, 
00042 *                                                               n=8, 16 or 32; 16 and 32 are half-float / float buffers,
00043 *                                                               t for RenderTexture support
00044 *
00045 * The following other attributes are supported.
00046 *
00047 * depth=n[t]    - must have n-bit depth buffer, omit n for default (24 bits),
00048 *                                                               n can be 16, 24 or 32 whereas 16 did not work on my machine,
00049 *                                                               t for RenderTexture support!            
00050 *
00051 * stencil[=t]   - stencil buffer attachment are currently only supported in 
00052 *                                                               combination with depth buffer attachment [both must be either
00053 *                                                               textures or buffers], the depth attachment is set to 24 Bit.
00054 *                                                               This is because most OpenGL driver implementations have no
00055 *                                                               separate stencil or depth buffer - See 
00056 *                                                               EXT_packed_depth_stencil specifications for details!
00057 *
00058 *       -----------------------------------------------------------------------------
00059 *       TODO:
00060 *       
00061 *       - support 32 Bit color attachments
00062 *       - support more stencil buffer attachment combinations
00063 *       - support more color attachment formats [rg, r, g, b etc.]
00064 *       - test ATI support
00065 *       - float depth buffer
00066 *       
00067 */
00068 
00069 #ifndef __FRAMEBUFFER_OBJECT__
00070 #define __FRAMEBUFFER_OBJECT__
00071 
00072 // -----------------------------------------------------------------------------
00073 
00074 #ifdef WIN32
00075         #include <windows.h>
00076 #endif
00077 
00078 //#include <gl/gl.h>
00079 //#include <gl/glext.h>
00080 
00082 //#include <glh/glh_extensions.h>
00083 
00084 #include <GL/glew.h>
00085 
00086 #include <iostream>
00087 #include <vector>
00088 
00089 // -----------------------------------------------------------------------------
00090 
00091 #define MAX_COLOR_COMPONENTS 16
00092 
00093 // -----------------------------------------------------------------------------
00094 
00095 class FramebufferObject {
00096 
00097 public:
00098 
00099         // ---------------------------------------------------------------------------
00100 
00101         enum ColorAttachmentType {
00102                 
00103                 RGB_8   = 0,
00104                 RGB_16,
00105                 RGB_32,
00106 
00107                 RGBA_8,
00108                 RGBA_16,
00109                 RGBA_32,
00110         };
00111 
00112         // ---------------------------------------------------------------------------
00113 
00114         FramebufferObject(const char *strMode="rgba=3x8t depth=24t");
00115         ~FramebufferObject();
00116 
00118         bool                                            initialize(     unsigned int width, unsigned int height );
00119         bool                                            reInitialize(   unsigned int width, unsigned int height, const char *strMode="rgb=16t depth=24t" );
00120 
00128         void                                            beginCapture(bool bEnablePassThroughShader=true);
00129         
00137         void                                            endCapture(bool bDisablePassThroughShader=true);
00138 
00140         void                                            bind(int index=0);
00141 
00143         void                                            bindDepth(void);
00144 
00146         GLuint                                          getColorAttachmentID(int index = 0);
00147 
00149         GLuint                                          getDepthAttachmentID(void);
00150 
00152         GLuint                                          getStencilAttachmentID(void);
00153 
00155         GLenum                                          getTextureTarget(void) { return _textureTarget; }
00156 
00158         unsigned int                            getWidth(void);
00160         unsigned int                            getHeight(void);
00161 
00163         bool                                            checkFramebufferStatus(void);
00164         void                                            printFramebufferStatus(void);
00165 
00167         void                                            enableTextureTarget(void) { glEnable(_textureTarget); }
00169         void                                            disableTextureTarget(void) { glDisable(_textureTarget); }
00170 
00172         void                                            setMinFilter(GLint      minFilter);
00173 
00175         void                                            setMagFilter(GLint      magFilter);
00176 
00178         void                                            setWrapS(GLint  wrapS);
00179 
00181         void                                            setWrapT(GLint  wrapT);
00182 
00183 protected:
00184 
00186         GLenum                                                                          _textureTarget;
00187 
00189         GLint                                                                           _colorFormat;
00191         GLint                                                                           _internalColorFormat;
00193         GLenum                                                                          _colorType;
00194 
00196         ColorAttachmentType                                                     _colorAttachmentDepth;
00197 
00199         GLenum                                                                          _depthFormat;
00202         GLenum                                                                          _internalDepthFormat;
00204         GLenum                                                                          _depthType;
00205 
00207         GLint                                                                           _wrapS;
00209         GLint                                                                           _wrapT;
00210         
00212         GLint                                                                           _minFilter;
00214         GLint                                                                           _magFilter;
00215 
00217         int                                                                                     _width;
00219         int                                                                                     _height;
00220 
00222         bool                                                                            _bFBOSupported;
00223 
00225         bool                                                                            _bInitialized;
00226 
00228         bool                                                                            _bColorAttachment;
00230         bool                                                                            _bColorAttachmentRenderTexture;
00231 
00233         bool                                                                            _bDepthAttachment;
00235         bool                                                                            _bDepthAttachmentRenderTexture;
00236 
00238         bool                                                                            _bStencilAttachment;
00240         bool                                                                            _bStencilAttachmentRenderTexture;
00242         int                                                                                     _stencilDepth;
00244         GLint                                                                           _internalStencilFormat;
00245 
00247         bool                                                                            _bPassThroughProgramInitialized;
00248 
00250         GLuint                                                                          _frameBufferID;
00251 
00253         GLuint                                                                          _colorAttachmentID[MAX_COLOR_COMPONENTS];
00254 
00256         int                                                                                     _numColorAttachments;
00257 
00259         int                                                                                     _maxNumDrawBuffers;
00260 
00262         GLuint                                                                          _depthAttachmentID;
00263 
00265         GLuint                                                                          _stencilAttachmentID;
00266 
00269         GLint                                                                           _viewport[4];
00270 
00272   
00273   GLenum _passthrough_program;
00274   GLenum _passthrough_fragment_shader;
00275         GLuint                                                                          _passThroughProgram;
00276         
00278         bool                                                                            _bFloatColorBuffer;
00279 
00280 private:
00281 
00283         void                                                                            parseModeString(const char *modeString);
00284 
00285         typedef std::pair<std::string, std::string> KeyVal;
00287         KeyVal                                                                          getKeyValuePair(std::string token);
00288 
00289 
00290 };
00291 
00292 #endif


realtime_urdf_filter
Author(s): Nico Blodow
autogenerated on Mon Oct 6 2014 04:04:44