Visualization Library 2.0.0

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Framebuffer.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef Framebuffer_INCLUDE_ONCE
33 #define Framebuffer_INCLUDE_ONCE
34 
35 #include <vlCore/vlnamespace.hpp>
36 #include <vlCore/Object.hpp>
37 #include <vlGraphics/OpenGL.hpp>
38 #include <vector>
39 
40 namespace vl
41 {
42  class OpenGLContext;
43  //-----------------------------------------------------------------------------
44  // Framebuffer
45  //-----------------------------------------------------------------------------
50  {
52 
53  friend class OpenGLContext;
54 
55  public:
57  Framebuffer(OpenGLContext* ctx, int w, int h, EReadDrawBuffer draw_buffer, EReadDrawBuffer read_buffer):
58  mOpenGLContext(ctx), mWidth(w), mHeight(h)
59  {
60  VL_DEBUG_SET_OBJECT_NAME()
61  setDrawBuffer(draw_buffer);
62  setReadBuffer(read_buffer);
63  }
64 
66  OpenGLContext* openglContext() { return mOpenGLContext; }
67 
69  const OpenGLContext* openglContext() const { return mOpenGLContext; }
70 
72  int width() const { return mWidth; }
73 
75  int height() const { return mHeight; }
76 
78  void setWidth(int width) { mWidth = width; }
79 
81  void setHeight(int height) { mHeight = height; }
82 
84  virtual GLuint handle() const { return 0; }
85 
88  {
89  bindFramebuffer(target);
90  }
91 
97  {
98  VL_CHECK_OGL()
99 
100  // the base render target is the framebuffer 0, that is, the normal OpenGL buffers
101  VL_glBindFramebuffer(target, 0); VL_CHECK_OGL()
102 
103 #if defined(VL_OPENGL)
104  // bind draw buffers
105  if (target == FBB_FRAMEBUFFER || target == FBB_DRAW_FRAMEBUFFER) {
106  bindDrawBuffers();
107  }
108 
109  // bind read buffer
110  if (target == FBB_FRAMEBUFFER || target == FBB_READ_FRAMEBUFFER) {
111  bindReadBuffer();
112  }
113 #endif
114 
115  VL_CHECK_OGL()
116  }
117 
119  void bindReadBuffer();
120 
122  void bindDrawBuffers() const;
123 
125  bool checkDrawBuffers() const;
126 
128  void setDrawBuffer(EReadDrawBuffer draw_buffer)
129  {
130  mDrawBuffers.clear();
131  mDrawBuffers.push_back(draw_buffer);
132  }
133 
135  void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2)
136  {
137  mDrawBuffers.clear();
138  mDrawBuffers.push_back(draw_buffer1);
139  mDrawBuffers.push_back(draw_buffer2);
140  }
141 
143  void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2, EReadDrawBuffer draw_buffer3)
144  {
145  mDrawBuffers.clear();
146  mDrawBuffers.push_back(draw_buffer1);
147  mDrawBuffers.push_back(draw_buffer2);
148  mDrawBuffers.push_back(draw_buffer3);
149  }
150 
152  void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2, EReadDrawBuffer draw_buffer3, EReadDrawBuffer draw_buffer4)
153  {
154  mDrawBuffers.clear();
155  mDrawBuffers.push_back(draw_buffer1);
156  mDrawBuffers.push_back(draw_buffer2);
157  mDrawBuffers.push_back(draw_buffer3);
158  mDrawBuffers.push_back(draw_buffer4);
159  }
160 
162  void setDrawBuffers(const std::vector< EReadDrawBuffer >& draw_buffers) { mDrawBuffers = draw_buffers; }
163 
165  const std::vector< EReadDrawBuffer >& drawBuffers() { return mDrawBuffers; }
166 
168  EReadDrawBuffer readBuffer() const { return mReadBuffer; }
169 
171  void setReadBuffer(EReadDrawBuffer read_buffer) { mReadBuffer = read_buffer; }
172 
173  private:
174  std::vector< EReadDrawBuffer > mDrawBuffers;
175  EReadDrawBuffer mReadBuffer;
176  OpenGLContext* mOpenGLContext;
177  int mWidth;
178  int mHeight;
179  };
180  //------------------------------------------------------------------------------
181 }
182 
183 #endif
virtual GLuint handle() const
The framebuffer object id as used by glBindFramebuffer, Framebuffer::handle() always returns 0...
Definition: Framebuffer.hpp:84
const std::vector< EReadDrawBuffer > & drawBuffers()
The color buffers to be drawn into.
void setWidth(int width)
The width of a render target.
Definition: Framebuffer.hpp:78
EReadDrawBuffer readBuffer() const
The read-buffer bound when the render target is activated.
int width() const
The width of a render target.
Definition: Framebuffer.hpp:72
void setReadBuffer(EReadDrawBuffer read_buffer)
The read-buffer bound when the render target is activated.
Represents an OpenGL context, possibly a widget or a pbuffer, which can also respond to keyboard...
void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2)
Specifies a list of color buffers to be drawn into.
void setDrawBuffers(const std::vector< EReadDrawBuffer > &draw_buffers)
Specifies a list of color buffers to be drawn into.
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
EReadDrawBuffer
Visualization Library main namespace.
int height() const
The height of a render target.
Definition: Framebuffer.hpp:75
The base class for all the reference counted objects.
Definition: Object.hpp:158
virtual void bindFramebuffer(EFramebufferBind target=FBB_FRAMEBUFFER)
Calls glBindFramebuffer(target, 0) thus activating the the framebuffer 0, that is, the normal OpenGL buffers.
Definition: Framebuffer.hpp:96
void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2, EReadDrawBuffer draw_buffer3)
Specifies a list of color buffers to be drawn into.
void setDrawBuffers(EReadDrawBuffer draw_buffer1, EReadDrawBuffer draw_buffer2, EReadDrawBuffer draw_buffer3, EReadDrawBuffer draw_buffer4)
Specifies a list of color buffers to be drawn into.
void activate(EFramebufferBind target=FBB_FRAMEBUFFER)
Activates the Framebuffer by calling bindFramebuffer() and bindDrawBuffers()
Definition: Framebuffer.hpp:87
OpenGLContext * openglContext()
The OpenGLContext bound to a render target.
Definition: Framebuffer.hpp:66
void setDrawBuffer(EReadDrawBuffer draw_buffer)
Specifies the color buffer to be drawn into.
EFramebufferBind
#define VL_CHECK_OGL()
Definition: OpenGL.hpp:156
void setHeight(int height)
The height of a render target.
Definition: Framebuffer.hpp:81
Visualization Library&#39;s enums in the &#39;vl&#39; namespace.
The Framebuffer class defines an abstract &#39;surface&#39; where OpenGL can render into. ...
Definition: Framebuffer.hpp:49
const OpenGLContext * openglContext() const
The OpenGLContext bound to a render target.
Definition: Framebuffer.hpp:69