# 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.cpp

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 #include <vlGraphics/Framebuffer.hpp>
    00033 #include <vlCore/Log.hpp>
    00034 #include <vlCore/Say.hpp>
    00035
    00036 #include <map>
    00037 #include <set>
    00038
    00039 using namespace vl;
    00040
    00041 //-----------------------------------------------------------------------------
    00042 // Framebuffer
    00043 //-----------------------------------------------------------------------------
    00044 bool Framebuffer::checkDrawBuffers() const
    00045 {
    00046   std::map<int, const char*> fbo_attachments;
    00047
    00048   fbo_attachments[GL_NONE]        = "GL_NONE";
    00049   fbo_attachments[GL_BACK_LEFT]   = "GL_BACK_LEFT";
    00050   fbo_attachments[GL_BACK_RIGHT]  = "GL_BACK_RIGHT";
    00051   fbo_attachments[GL_FRONT_LEFT]  = "GL_FRONT_LEFT";
    00052   fbo_attachments[GL_FRONT_RIGHT] = "GL_FRONT_RIGHT";
    00053   fbo_attachments[GL_AUX0] = "GL_AUX0";
    00054   fbo_attachments[GL_AUX1] = "GL_AUX1";
    00055   fbo_attachments[GL_AUX2] = "GL_AUX2";
    00056   fbo_attachments[GL_AUX3] = "GL_AUX3";
    00057   fbo_attachments[GL_COLOR_ATTACHMENT0]  = "GL_COLOR_ATTACHMENT0";
    00058   fbo_attachments[GL_COLOR_ATTACHMENT1]  = "GL_COLOR_ATTACHMENT1";
    00059   fbo_attachments[GL_COLOR_ATTACHMENT2]  = "GL_COLOR_ATTACHMENT2";
    00060   fbo_attachments[GL_COLOR_ATTACHMENT3]  = "GL_COLOR_ATTACHMENT3";
    00061   fbo_attachments[GL_COLOR_ATTACHMENT4]  = "GL_COLOR_ATTACHMENT4";
    00062   fbo_attachments[GL_COLOR_ATTACHMENT5]  = "GL_COLOR_ATTACHMENT5";
    00063   fbo_attachments[GL_COLOR_ATTACHMENT6]  = "GL_COLOR_ATTACHMENT6";
    00064   fbo_attachments[GL_COLOR_ATTACHMENT7]  = "GL_COLOR_ATTACHMENT7";
    00065   fbo_attachments[GL_COLOR_ATTACHMENT8]  = "GL_COLOR_ATTACHMENT8";
    00066   fbo_attachments[GL_COLOR_ATTACHMENT9]  = "GL_COLOR_ATTACHMENT9";
    00067   fbo_attachments[GL_COLOR_ATTACHMENT10] = "GL_COLOR_ATTACHMENT10";
    00068   fbo_attachments[GL_COLOR_ATTACHMENT11] = "GL_COLOR_ATTACHMENT11";
    00069   fbo_attachments[GL_COLOR_ATTACHMENT12] = "GL_COLOR_ATTACHMENT12";
    00070   fbo_attachments[GL_COLOR_ATTACHMENT13] = "GL_COLOR_ATTACHMENT13";
    00071   fbo_attachments[GL_COLOR_ATTACHMENT14] = "GL_COLOR_ATTACHMENT14";
    00072   fbo_attachments[GL_COLOR_ATTACHMENT15] = "GL_COLOR_ATTACHMENT15";
    00073
    00074   int fbo = 0;
    00075   if (Has_GL_EXT_framebuffer_object||Has_GL_ARB_framebuffer_object)
    00076     glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);
    00077
    00078   if (fbo)
    00079   {
    00080     std::set<GLenum> legal;
    00081     legal.insert(GL_NONE);
    00082     legal.insert(GL_COLOR_ATTACHMENT0);
    00083     legal.insert(GL_COLOR_ATTACHMENT1);
    00084     legal.insert(GL_COLOR_ATTACHMENT2);
    00085     legal.insert(GL_COLOR_ATTACHMENT3);
    00086     legal.insert(GL_COLOR_ATTACHMENT4);
    00087     legal.insert(GL_COLOR_ATTACHMENT5);
    00088     legal.insert(GL_COLOR_ATTACHMENT6);
    00089     legal.insert(GL_COLOR_ATTACHMENT7);
    00090     legal.insert(GL_COLOR_ATTACHMENT8);
    00091     legal.insert(GL_COLOR_ATTACHMENT9);
    00092     legal.insert(GL_COLOR_ATTACHMENT10);
    00093     legal.insert(GL_COLOR_ATTACHMENT11);
    00094     legal.insert(GL_COLOR_ATTACHMENT12);
    00095     legal.insert(GL_COLOR_ATTACHMENT13);
    00096     legal.insert(GL_COLOR_ATTACHMENT14);
    00097     legal.insert(GL_COLOR_ATTACHMENT15);
    00098     for(unsigned i=0; i<mDrawBuffers.size(); ++i)
    00099     {
    00100       if(legal.find(mDrawBuffers[i]) == legal.end())
    00101       {
    00102         Log::error(Say("FBO bound but Framebuffer::setDrawBuffers() called with non FBO compatible draw buffer '%s'.\n") << fbo_attachments[mDrawBuffers[i]]);
    00103         return false;
    00104       }
    00105     }
    00106   }
    00107   else
    00108   {
    00109     std::set<GLenum> legal;
    00110     legal.insert(GL_NONE);
    00111     legal.insert(GL_BACK_LEFT);
    00112     legal.insert(GL_BACK_RIGHT);
    00113     legal.insert(GL_FRONT_LEFT);
    00114     legal.insert(GL_FRONT_RIGHT);
    00115     legal.insert(GL_AUX0);
    00116     legal.insert(GL_AUX1);
    00117     legal.insert(GL_AUX2);
    00118     legal.insert(GL_AUX3);
    00119     for(unsigned i=0; i<mDrawBuffers.size(); ++i)
    00120     {
    00121       if(legal.find(mDrawBuffers[i]) == legal.end())
    00122       {
    00123         Log::error(Say("FBO not bound or not supported but Framebuffer::setDrawBuffers() called with FBO specific draw buffer '%s'.\n") << fbo_attachments[mDrawBuffers[i]]);
    00124         return false;
    00125       }
    00126     }
    00127   }
    00128   return true;
    00129 }
    00130 //-----------------------------------------------------------------------------
    00131 void Framebuffer::bindDrawBuffers() const
    00132 {
    00133   VL_CHECK_OGL()
    00134
    00135   VL_CHECK(!mDrawBuffers.empty())
    00136
    00137   #ifndef NDEBUG
    00138     checkDrawBuffers();
    00139   #endif
    00140
    00141   if (mDrawBuffers.size() > 1 && (Has_GL_ARB_draw_buffers||Has_GL_Version_2_0))
    00142   {
    00143     glDrawBuffers( (GLsizei)mDrawBuffers.size(), (const GLenum*)&mDrawBuffers[0] );
    00144     VL_CHECK_OGL() // If you are using RDB_BACK_LEFT/RIGHT make sure sure you have a double buffered gl context.
    00145                    // Otherwise use Framebuffer::setDrawBuffer(RDB_FRONT_LEFT).
    00146   }
    00147   else
    00148   {
    00149     glDrawBuffer( mDrawBuffers[0] );
    00150     VL_CHECK_OGL() // If you are using RDB_BACK_LEFT/RIGHT make sure sure you have a double buffered gl context.
    00151                    // Otherwise use Framebuffer::setDrawBuffer(RDB_FRONT_LEFT).
    00152     if ( mDrawBuffers.size() > 1 )
    00153     {
    00154       Log::error( "Framebuffer::bindDrawBuffers() error:\nglDrawBuffers() not supported by the current OpenGL driver. GL_ARB_draw_buffers or OpenGL 2.0 required.\n" );
    00155     }
    00156   }
    00157 }
    00158 //-----------------------------------------------------------------------------
    00159 void Framebuffer::bindReadBuffer()
    00160 {
    00161   VL_CHECK_OGL();
    00162
    00163   glReadBuffer( readBuffer() );
    00164
    00165   VL_CHECK_OGL();
    00166 }
    00167 //-----------------------------------------------------------------------------
    00168

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.