# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/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   protected:
    00057     Framebuffer(): mWidth(0), mHeight(0), mOpenGLContext(NULL)
    00058     {
    00059       VL_DEBUG_SET_OBJECT_NAME()
    00060       setDrawBuffer(RDB_BACK_LEFT);
    00061       setReadBuffer(RDB_BACK_LEFT);
    00062     }
    00063
    00065     Framebuffer(OpenGLContext* ctx, int w, int h): mWidth(w), mHeight(h), mOpenGLContext(ctx)
    00066     {
    00067       VL_DEBUG_SET_OBJECT_NAME()
    00068       setDrawBuffer(RDB_BACK_LEFT);
    00069       setReadBuffer(RDB_BACK_LEFT);
    00070     }
    00071
    00072   public:
    00074     OpenGLContext* openglContext() { return mOpenGLContext; }
    00075
    00077     const OpenGLContext* openglContext() const { return mOpenGLContext; }
    00078
    00080     int width() const { return mWidth; }
    00081
    00083     int height() const { return mHeight; }
    00084
    00086     void setWidth(int width) { mWidth = width; }
    00087
    00089     void setHeight(int height) { mHeight = height; }
    00090
    00092     virtual GLuint handle() const { return 0; }
    00093
    00095     void activate(EFramebufferBind target = FBB_FRAMEBUFFER)
    00096     {
    00097       bindFramebuffer(target);
    00098     }
    00099
    00104     virtual void bindFramebuffer(EFramebufferBind target = FBB_FRAMEBUFFER)
    00105     {
    00106       VL_CHECK_OGL()
    00107
    00108       // the base render target is the framebuffer 0, that is, the normal OpenGL buffers
    00109       VL_glBindFramebuffer(target, 0); VL_CHECK_OGL()
    00110
    00111 #if defined(VL_OPENGL)
    00112       // bind draw buffers
    00113       bindDrawBuffers();
    00114
    00115       // bind read buffer
    00116       bindReadBuffer();
    00117 #endif
    00118
    00119       VL_CHECK_OGL()
    00120     }
    00121
    00123     void bindReadBuffer();
    00124
    00126     void bindDrawBuffers() const;
    00127
    00129     bool checkDrawBuffers() const;
    00130
    00132     void setDrawBuffer(EReadDrawBuffer draw_buffer)
    00133     {
    00134       mDrawBuffers.clear();
    00135       mDrawBuffers.push_back(draw_buffer);
    00136     }
    00137
    00139     void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2)
    00140     {
    00141       mDrawBuffers.clear();
    00142       mDrawBuffers.push_back(draw_buffer1);
    00143       mDrawBuffers.push_back(draw_buffer2);
    00144     }
    00145
    00147     void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2, EReadDrawBuffer draw_buffer3)
    00148     {
    00149       mDrawBuffers.clear();
    00150       mDrawBuffers.push_back(draw_buffer1);
    00151       mDrawBuffers.push_back(draw_buffer2);
    00152       mDrawBuffers.push_back(draw_buffer3);
    00153     }
    00154
    00156     void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2, EReadDrawBuffer draw_buffer3, EReadDrawBuffer draw_buffer4)
    00157     {
    00158       mDrawBuffers.clear();
    00159       mDrawBuffers.push_back(draw_buffer1);
    00160       mDrawBuffers.push_back(draw_buffer2);
    00161       mDrawBuffers.push_back(draw_buffer3);
    00162       mDrawBuffers.push_back(draw_buffer4);
    00163     }
    00164
    00166     void setDrawBuffers(const std::vector< EReadDrawBuffer >& draw_buffers) { mDrawBuffers = draw_buffers; }
    00167
    00169     const std::vector< EReadDrawBuffer >& drawBuffers() { return mDrawBuffers; }
    00170
    00172     EReadDrawBuffer readBuffer() const { return mReadBuffer; }
    00173
    00175     void setReadBuffer(EReadDrawBuffer read_buffer) { mReadBuffer = read_buffer; }
    00176
    00177   private:
    00178     std::vector< EReadDrawBuffer > mDrawBuffers;
    00179     EReadDrawBuffer mReadBuffer;
    00180     int mWidth;
    00181     int mHeight;
    00182     OpenGLContext* mOpenGLContext;
    00183   };
    00184   //------------------------------------------------------------------------------
    00185 }
    00186
    00187 #endif

Visualization Library v2011.09.1162 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu Jan 26 2012 00:43:38.
Permission is granted to use this page to write and publish articles regarding Visualization Library.