# 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/BlitFramebuffer.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.org                                               */
    00005 /*                                                                                    */
    00006 /*  Copyright (c) 2005-2010, 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 BlitFramebuffer_INCLUDE_ONCE
    00033 #define BlitFramebuffer_INCLUDE_ONCE
    00034
    00035 #include <vlGraphics/RenderEventCallback.hpp>
    00036 #include <vlGraphics/FramebufferObject.hpp>
    00037
    00038 namespace vl
    00039 {
    00044   class BlitFramebuffer: public RenderEventCallback
    00045   {
    00046     VL_INSTRUMENT_CLASS(vl::BlitFramebuffer, RenderEventCallback)
    00047
    00048   public:
    00049     BlitFramebuffer()
    00050     {
    00051       VL_DEBUG_SET_OBJECT_NAME()
    00052       setSrcRect(0,0,640,480);
    00053       setDstRect(0,0,640,480);
    00054       mBufferMask = 0;
    00055       mLinearFilteringEnabled = false;
    00056       mReadBuffer = RDB_COLOR_ATTACHMENT0;
    00057     }
    00058
    00060     void copyPixels()
    00061     {
    00062       if (Has_GL_EXT_framebuffer_blit||Has_GL_ARB_framebuffer_object)
    00063       {
    00064         VL_CHECK_OGL()
    00065
    00066         // save FBOs
    00067         GLint read_fbo = 0;
    00068         GLint draw_fbo = 0;
    00069         glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &read_fbo); VL_CHECK_OGL()
    00070         glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &draw_fbo); VL_CHECK_OGL()
    00071
    00072         // initializes the source render target
    00073         readFramebuffer()->activate(FBB_READ_FRAMEBUFFER); VL_CHECK_OGL()
    00074
    00075         // override read buffer specified by readFramebuffer()->activate() with the one specified by the user here
    00076         glReadBuffer(mReadBuffer); VL_CHECK_OGL()
    00077
    00078         // activate destination render target
    00079         drawFramebuffer()->activate(FBB_DRAW_FRAMEBUFFER); VL_CHECK_OGL()
    00080
    00081         // note: keep the draw-buffers as specified by drawFramebuffer()->activate()
    00082         // ...
    00083
    00084         // performs the blit
    00085         VL_glBlitFramebuffer( mSrcRect[0], mSrcRect[1], mSrcRect[2], mSrcRect[3],
    00086                               mDstRect[0], mDstRect[1], mDstRect[2], mDstRect[3],
    00087                               mBufferMask,
    00088                               mLinearFilteringEnabled ? GL_LINEAR : GL_NEAREST);
    00089         VL_CHECK_OGL()
    00090
    00091         // restore FBOs
    00092         VL_glBindFramebuffer( GL_READ_FRAMEBUFFER_EXT, read_fbo );
    00093         VL_CHECK_OGL()
    00094         VL_glBindFramebuffer( GL_DRAW_FRAMEBUFFER_EXT, draw_fbo );
    00095         VL_CHECK_OGL()
    00096       }
    00097     }
    00098
    00099     virtual bool onRenderingStarted(const RenderingAbstract*)
    00100     {
    00101       copyPixels();
    00102       return true;
    00103     }
    00104
    00105     virtual bool onRenderingFinished(const RenderingAbstract*)
    00106     {
    00107       copyPixels();
    00108       return true;
    00109     }
    00110
    00111     virtual bool onRendererStarted(const RendererAbstract*)
    00112     {
    00113       copyPixels();
    00114       return true;
    00115     }
    00116
    00117     virtual bool onRendererFinished(const RendererAbstract*)
    00118     {
    00119       copyPixels();
    00120       return true;
    00121     }
    00122
    00124     void setReadFramebuffer(Framebuffer* fbo) { mReadFramebuffer = fbo; }
    00125
    00127     const Framebuffer* readFramebuffer() const { return mReadFramebuffer.get(); }
    00128
    00130     Framebuffer* readFramebuffer() { return mReadFramebuffer.get(); }
    00131
    00133     void setReadBuffer(EReadDrawBuffer read_buffer) { mReadBuffer = read_buffer; }
    00134
    00136     EReadDrawBuffer readBuffer() const { return mReadBuffer; }
    00137
    00139     void setDrawFramebuffer(Framebuffer* fbo) { mDrawFramebuffer = fbo; }
    00140
    00142     const Framebuffer* drawFramebuffer() const { return mDrawFramebuffer.get(); }
    00143
    00145     Framebuffer* drawFramebuffer() { return mDrawFramebuffer.get(); }
    00146
    00147     void setSrcRect(int x0, int y0, int x1, int y1)
    00148     {
    00149       mSrcRect[0] = x0;
    00150       mSrcRect[1] = y0;
    00151       mSrcRect[2] = x1;
    00152       mSrcRect[3] = y1;
    00153     }
    00154
    00155     void setDstRect(int x0, int y0, int x1, int y1)
    00156     {
    00157       mDstRect[0] = x0;
    00158       mDstRect[1] = y0;
    00159       mDstRect[2] = x1;
    00160       mDstRect[3] = y1;
    00161     }
    00162
    00163     const int* srcRect() const { return mSrcRect; }
    00164     const int* dstRect() const { return mDstRect; }
    00165
    00167     void setBufferMask(int buffer_mask) { mBufferMask = buffer_mask; }
    00168     int bufferMask() const { return mBufferMask; }
    00169
    00170     void setLinearFilteringEnabled( bool enable_linear_filtering ) { mLinearFilteringEnabled = enable_linear_filtering; }
    00171     bool linearFilteringEnabled() const { return mLinearFilteringEnabled; }
    00172
    00173   protected:
    00174     ref<Framebuffer> mReadFramebuffer;
    00175     ref<Framebuffer> mDrawFramebuffer;
    00176     int mSrcRect[4];
    00177     int mDstRect[4];
    00178     int mBufferMask;
    00179     EReadDrawBuffer mReadBuffer;
    00180     bool mLinearFilteringEnabled;
    00181   };
    00182 };
    00183
    00184 #endif

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