Visualization Library v1.0.3A lightweight C++ OpenGL middleware for 2D/3D graphics |
[Download] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://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 public: 00057 Framebuffer(OpenGLContext* ctx, int w, int h, EReadDrawBuffer draw_buffer, EReadDrawBuffer read_buffer): 00058 mOpenGLContext(ctx), mWidth(w), mHeight(h) 00059 { 00060 VL_DEBUG_SET_OBJECT_NAME() 00061 setDrawBuffer(draw_buffer); 00062 setReadBuffer(read_buffer); 00063 } 00064 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 #if defined(VL_OPENGL) 00104 // bind draw buffers 00105 if (target == FBB_FRAMEBUFFER || target == FBB_DRAW_FRAMEBUFFER) { 00106 bindDrawBuffers(); 00107 } 00108 00109 // bind read buffer 00110 if (target == FBB_FRAMEBUFFER || target == FBB_READ_FRAMEBUFFER) { 00111 bindReadBuffer(); 00112 } 00113 #endif 00114 00115 VL_CHECK_OGL() 00116 } 00117 00119 void bindReadBuffer(); 00120 00122 void bindDrawBuffers() const; 00123 00125 bool checkDrawBuffers() const; 00126 00128 void setDrawBuffer(EReadDrawBuffer draw_buffer) 00129 { 00130 mDrawBuffers.clear(); 00131 mDrawBuffers.push_back(draw_buffer); 00132 } 00133 00135 void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2) 00136 { 00137 mDrawBuffers.clear(); 00138 mDrawBuffers.push_back(draw_buffer1); 00139 mDrawBuffers.push_back(draw_buffer2); 00140 } 00141 00143 void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2, EReadDrawBuffer draw_buffer3) 00144 { 00145 mDrawBuffers.clear(); 00146 mDrawBuffers.push_back(draw_buffer1); 00147 mDrawBuffers.push_back(draw_buffer2); 00148 mDrawBuffers.push_back(draw_buffer3); 00149 } 00150 00152 void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2, EReadDrawBuffer draw_buffer3, EReadDrawBuffer draw_buffer4) 00153 { 00154 mDrawBuffers.clear(); 00155 mDrawBuffers.push_back(draw_buffer1); 00156 mDrawBuffers.push_back(draw_buffer2); 00157 mDrawBuffers.push_back(draw_buffer3); 00158 mDrawBuffers.push_back(draw_buffer4); 00159 } 00160 00162 void setDrawBuffers(const std::vector< EReadDrawBuffer >& draw_buffers) { mDrawBuffers = draw_buffers; } 00163 00165 const std::vector< EReadDrawBuffer >& drawBuffers() { return mDrawBuffers; } 00166 00168 EReadDrawBuffer readBuffer() const { return mReadBuffer; } 00169 00171 void setReadBuffer(EReadDrawBuffer read_buffer) { mReadBuffer = read_buffer; } 00172 00173 private: 00174 std::vector< EReadDrawBuffer > mDrawBuffers; 00175 EReadDrawBuffer mReadBuffer; 00176 OpenGLContext* mOpenGLContext; 00177 int mWidth; 00178 int mHeight; 00179 }; 00180 //------------------------------------------------------------------------------ 00181 } 00182 00183 #endif