# Visualization Library

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

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

- Main Page
- 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.com                                               */
    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   public:
    00047     BlitFramebuffer()
    00048     {
    00049       VL_DEBUG_SET_OBJECT_NAME()
    00050       setSrcRect(0,0,640,480);
    00051       setDstRect(0,0,640,480);
    00052       mBufferMask = 0;
    00053       mLinearFilteringEnabled = false;
    00054       mReadBuffer = RDB_COLOR_ATTACHMENT0;
    00055     }
    00056     virtual const char* className() { return "vl::BlitFramebuffer"; }
    00057
    00059     void copyPixels()
    00060     {
    00061       if (GLEW_EXT_framebuffer_blit||GLEW_ARB_framebuffer_object)
    00062       {
    00063         VL_CHECK_OGL()
    00064
    00065         // save FBOs
    00066         GLint read_fbo = 0;
    00067         GLint draw_fbo = 0;
    00068         glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &read_fbo); VL_CHECK_OGL()
    00069         glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &draw_fbo); VL_CHECK_OGL()
    00070
    00071         // initializes the source render target
    00072         readRenderTarget()->activate(FBB_READ_FRAMEBUFFER); VL_CHECK_OGL()
    00073
    00074         // override read buffer specified by readRenderTarget()->activate() with the one specified by the user here
    00075         glReadBuffer(mReadBuffer); VL_CHECK_OGL()
    00076
    00077         // activate destination render target
    00078         drawRenderTarget()->activate(FBB_DRAW_FRAMEBUFFER); VL_CHECK_OGL()
    00079
    00080         // note: keep the draw-buffers as specified by drawRenderTarget()->activate()
    00081         // ...
    00082
    00083         // performs the blit
    00084         VL_glBlitFramebuffer( mSrcRect[0], mSrcRect[1], mSrcRect[2], mSrcRect[3],
    00085                               mDstRect[0], mDstRect[1], mDstRect[2], mDstRect[3],
    00086                               mBufferMask,
    00087                               mLinearFilteringEnabled ? GL_LINEAR : GL_NEAREST);
    00088         VL_CHECK_OGL()
    00089
    00090         // restore FBOs
    00091         VL_glBindFramebuffer( GL_READ_FRAMEBUFFER_EXT, read_fbo );
    00092         VL_CHECK_OGL()
    00093         VL_glBindFramebuffer( GL_DRAW_FRAMEBUFFER_EXT, draw_fbo );
    00094         VL_CHECK_OGL()
    00095       }
    00096     }
    00097
    00098     virtual bool onRenderingStarted(const RenderingAbstract*)
    00099     {
    00100       copyPixels();
    00101       return true;
    00102     }
    00103
    00104     virtual bool onRenderingFinished(const RenderingAbstract*)
    00105     {
    00106       copyPixels();
    00107       return true;
    00108     }
    00109
    00110     virtual bool onRendererStarted(const RendererAbstract*)
    00111     {
    00112       copyPixels();
    00113       return true;
    00114     }
    00115
    00116     virtual bool onRendererFinished(const RendererAbstract*)
    00117     {
    00118       copyPixels();
    00119       return true;
    00120     }
    00121
    00123     void setReadRenderTarget(RenderTarget* fbo) { mReadRenderTarget = fbo; }
    00124
    00126     RenderTarget* readRenderTarget() const { return mReadRenderTarget.get(); }
    00127
    00129     void setReadBuffer(EReadDrawBuffer read_buffer) { mReadBuffer = read_buffer; }
    00130
    00132     EReadDrawBuffer readBuffer() const { return mReadBuffer; }
    00133
    00135     void setDrawRenderTarget(RenderTarget* fbo) { mDrawRenderTarget = fbo; }
    00136
    00138     RenderTarget* drawRenderTarget() const { return mDrawRenderTarget.get(); }
    00139
    00140     void setSrcRect(int x0, int y0, int x1, int y1)
    00141     {
    00142       mSrcRect[0] = x0;
    00143       mSrcRect[1] = y0;
    00144       mSrcRect[2] = x1;
    00145       mSrcRect[3] = y1;
    00146     }
    00147
    00148     void setDstRect(int x0, int y0, int x1, int y1)
    00149     {
    00150       mDstRect[0] = x0;
    00151       mDstRect[1] = y0;
    00152       mDstRect[2] = x1;
    00153       mDstRect[3] = y1;
    00154     }
    00155
    00156     const int* srcRect() const { return mSrcRect; }
    00157     const int* dstRect() const { return mDstRect; }
    00158
    00160     void setBufferMask(int buffer_mask) { mBufferMask = buffer_mask; }
    00161     int bufferMask() const { return mBufferMask; }
    00162
    00163     void setLinearFilteringEnabled( bool enable_linear_filtering ) { mLinearFilteringEnabled = enable_linear_filtering; }
    00164     bool linearFilteringEnabled() const { return mLinearFilteringEnabled; }
    00165
    00166   protected:
    00167     ref<RenderTarget> mReadRenderTarget;
    00168     ref<RenderTarget> mDrawRenderTarget;
    00169     int mSrcRect[4];
    00170     int mDstRect[4];
    00171     int mBufferMask;
    00172     EReadDrawBuffer mReadBuffer;
    00173     bool mLinearFilteringEnabled;
    00174   };
    00175 };
    00176
    00177 #endif

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:22.
Permission is granted to use this page to write and publish articles regarding Visualization Library.