Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics
[Home] [Tutorials] [All Classes] [Grouped Classes]

X:/dropbox/visualizationlibrary/src/vlGraphics/Framebuffer.hpp

Go to the documentation of this file.
00001 /**************************************************************************************/
00002 /*                                                                                    */
00003 /*  Visualization Library                                                             */
00004 /*  http://www.visualizationlibrary.org                                               */
00005 /*                                                                                    */
00006 /*  Copyright (c) 2005-2011, Michele Bosi                                             */
00007 /*  All rights reserved.                                                              */
00008 /*                                                                                    */
00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
00010 /*  are permitted provided that the following conditions are met:                     */
00011 /*                                                                                    */
00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
00013 /*  list of conditions and the following disclaimer.                                  */
00014 /*                                                                                    */
00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
00017 /*  other materials provided with the distribution.                                   */
00018 /*                                                                                    */
00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
00029 /*                                                                                    */
00030 /**************************************************************************************/
00031 
00032 #ifndef Framebuffer_INCLUDE_ONCE
00033 #define Framebuffer_INCLUDE_ONCE
00034 
00035 #include <vlCore/vlnamespace.hpp>
00036 #include <vlCore/Object.hpp>
00037 #include <vlGraphics/OpenGL.hpp>
00038 #include <vector>
00039 
00040 namespace vl
00041 {
00042   class OpenGLContext;
00043   //-----------------------------------------------------------------------------
00044   // Framebuffer
00045   //-----------------------------------------------------------------------------
00049   class VLGRAPHICS_EXPORT Framebuffer: public Object
00050   {
00051     VL_INSTRUMENT_CLASS(vl::Framebuffer, Object)
00052 
00053     friend class OpenGLContext;
00054 
00055   public:
00057     Framebuffer(OpenGLContext* ctx, int w, int h, EReadDrawBuffer draw_buffer, EReadDrawBuffer read_buffer):
00058     mOpenGLContext(ctx), mWidth(w), mHeight(h)
00059     {
00060       VL_DEBUG_SET_OBJECT_NAME()
00061       setDrawBuffer(draw_buffer);
00062       setReadBuffer(read_buffer);
00063     }
00064 
00066     OpenGLContext* openglContext() { return mOpenGLContext; }
00067     
00069     const OpenGLContext* openglContext() const { return mOpenGLContext; }
00070 
00072     int width() const { return mWidth; }
00073     
00075     int height() const { return mHeight; }
00076     
00078     void setWidth(int width) { mWidth = width; }
00079     
00081     void setHeight(int height) { mHeight = height; }
00082 
00084     virtual GLuint handle() const { return 0; }
00085 
00087     void activate(EFramebufferBind target = FBB_FRAMEBUFFER)
00088     {
00089       bindFramebuffer(target);
00090     }
00091 
00096     virtual void bindFramebuffer(EFramebufferBind target = FBB_FRAMEBUFFER)
00097     {
00098       VL_CHECK_OGL()
00099 
00100       // the base render target is the framebuffer 0, that is, the normal OpenGL buffers
00101       VL_glBindFramebuffer(target, 0); VL_CHECK_OGL()
00102 
00103 #if defined(VL_OPENGL)
00104       // bind draw buffers
00105       bindDrawBuffers();
00106 
00107       // bind read buffer
00108       bindReadBuffer();
00109 #endif
00110       
00111       VL_CHECK_OGL()
00112     }
00113 
00115     void bindReadBuffer();
00116 
00118     void bindDrawBuffers() const;
00119 
00121     bool checkDrawBuffers() const;
00122 
00124     void setDrawBuffer(EReadDrawBuffer draw_buffer)
00125     {
00126       mDrawBuffers.clear();
00127       mDrawBuffers.push_back(draw_buffer);
00128     }
00129 
00131     void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2)
00132     {
00133       mDrawBuffers.clear();
00134       mDrawBuffers.push_back(draw_buffer1);
00135       mDrawBuffers.push_back(draw_buffer2);
00136     }
00137 
00139     void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2, EReadDrawBuffer draw_buffer3)
00140     {
00141       mDrawBuffers.clear();
00142       mDrawBuffers.push_back(draw_buffer1);
00143       mDrawBuffers.push_back(draw_buffer2);
00144       mDrawBuffers.push_back(draw_buffer3);
00145     }
00146 
00148     void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2, EReadDrawBuffer draw_buffer3, EReadDrawBuffer draw_buffer4)
00149     {
00150       mDrawBuffers.clear();
00151       mDrawBuffers.push_back(draw_buffer1);
00152       mDrawBuffers.push_back(draw_buffer2);
00153       mDrawBuffers.push_back(draw_buffer3);
00154       mDrawBuffers.push_back(draw_buffer4);
00155     }
00156 
00158     void setDrawBuffers(const std::vector< EReadDrawBuffer >& draw_buffers) { mDrawBuffers = draw_buffers; }
00159 
00161     const std::vector< EReadDrawBuffer >& drawBuffers() { return mDrawBuffers; }
00162 
00164     EReadDrawBuffer readBuffer() const { return mReadBuffer; }
00165     
00167     void setReadBuffer(EReadDrawBuffer read_buffer) { mReadBuffer = read_buffer; }
00168 
00169   private:
00170     std::vector< EReadDrawBuffer > mDrawBuffers;
00171     EReadDrawBuffer mReadBuffer;
00172     OpenGLContext* mOpenGLContext;
00173     int mWidth;
00174     int mHeight;
00175   };
00176   //------------------------------------------------------------------------------
00177 }
00178 
00179 #endif

Visualization Library 2011.09.1160 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 2 2013 13:40:37.
Permission is granted to use this page to write and publish articles regarding Visualization Library.