# 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/RenderTarget.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 RenderTarget_INCLUDE_ONCE
    00033 #define RenderTarget_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   // RenderTarget
    00045   //-----------------------------------------------------------------------------
    00049   class VLGRAPHICS_EXPORT RenderTarget: public Object
    00050   {
    00051     friend class OpenGLContext;
    00052
    00053   protected:
    00054     virtual const char* className() { return "vl::RenderTarget"; }
    00055
    00057     RenderTarget(OpenGLContext* ctx, int w, int h): mWidth(w), mHeight(h), mOpenGLContext(ctx)
    00058     {
    00059       VL_DEBUG_SET_OBJECT_NAME()
    00060       setDrawBuffer(RDB_BACK_LEFT);
    00061       setReadBuffer(RDB_BACK_LEFT);
    00062     }
    00063
    00064   public:
    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       // bind draw buffers
    00104       bindDrawBuffers();
    00105
    00106       // bind read buffer
    00107       bindReadBuffer();
    00108
    00109       VL_CHECK_OGL()
    00110     }
    00111
    00113     void bindReadBuffer();
    00114
    00116     void bindDrawBuffers() const;
    00117
    00119     bool checkDrawBuffers() const;
    00120
    00122     void setDrawBuffer(EReadDrawBuffer draw_buffer)
    00123     {
    00124       mDrawBuffers.clear();
    00125       mDrawBuffers.push_back(draw_buffer);
    00126     }
    00127
    00129     void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2)
    00130     {
    00131       mDrawBuffers.clear();
    00132       mDrawBuffers.push_back(draw_buffer1);
    00133       mDrawBuffers.push_back(draw_buffer2);
    00134     }
    00135
    00137     void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2, EReadDrawBuffer draw_buffer3)
    00138     {
    00139       mDrawBuffers.clear();
    00140       mDrawBuffers.push_back(draw_buffer1);
    00141       mDrawBuffers.push_back(draw_buffer2);
    00142       mDrawBuffers.push_back(draw_buffer3);
    00143     }
    00144
    00146     void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2, EReadDrawBuffer draw_buffer3, EReadDrawBuffer draw_buffer4)
    00147     {
    00148       mDrawBuffers.clear();
    00149       mDrawBuffers.push_back(draw_buffer1);
    00150       mDrawBuffers.push_back(draw_buffer2);
    00151       mDrawBuffers.push_back(draw_buffer3);
    00152       mDrawBuffers.push_back(draw_buffer4);
    00153     }
    00154
    00156     void setDrawBuffers(const std::vector< EReadDrawBuffer >& draw_buffers) { mDrawBuffers = draw_buffers; }
    00157
    00159     const std::vector< EReadDrawBuffer >& drawBuffers() { return mDrawBuffers; }
    00160
    00162     EReadDrawBuffer readBuffer() const { return mReadBuffer; }
    00163
    00165     void setReadBuffer(EReadDrawBuffer read_buffer) { mReadBuffer = read_buffer; }
    00166
    00167   private:
    00168     std::vector< EReadDrawBuffer > mDrawBuffers;
    00169     EReadDrawBuffer mReadBuffer;
    00170     int mWidth;
    00171     int mHeight;
    00172     OpenGLContext* mOpenGLContext;
    00173   };
    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:25.
Permission is granted to use this page to write and publish articles regarding Visualization Library.