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]
BlitFramebuffer.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 BlitFramebuffer_INCLUDE_ONCE
33 #define BlitFramebuffer_INCLUDE_ONCE
34 
37 
38 namespace vl
39 {
45  {
47 
48  public:
50  {
51  VL_DEBUG_SET_OBJECT_NAME()
52  setSrcRect(0,0,640,480);
53  setDstRect(0,0,640,480);
54  mBufferMask = 0;
57  }
58 
60  void copyPixels()
61  {
62  if (Has_GL_EXT_framebuffer_blit||Has_GL_ARB_framebuffer_object)
63  {
64  VL_CHECK_OGL()
65 
66  // save FBOs
67  GLint read_fbo = 0;
68  GLint draw_fbo = 0;
69  glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &read_fbo); VL_CHECK_OGL()
70  glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &draw_fbo); VL_CHECK_OGL()
71 
72  // initializes the source render target
74 
75  // override read buffer specified by readFramebuffer()->activate() with the one specified by the user here
76  glReadBuffer(mReadBuffer); VL_CHECK_OGL()
77 
78  // activate destination render target
80 
81  // note: keep the draw-buffers as specified by drawFramebuffer()->activate()
82  // ...
83 
84  // performs the blit
85  VL_glBlitFramebuffer( mSrcRect[0], mSrcRect[1], mSrcRect[2], mSrcRect[3],
86  mDstRect[0], mDstRect[1], mDstRect[2], mDstRect[3],
88  mLinearFilteringEnabled ? GL_LINEAR : GL_NEAREST);
89  VL_CHECK_OGL()
90 
91  // restore FBOs
92  VL_glBindFramebuffer( GL_READ_FRAMEBUFFER_EXT, read_fbo );
93  VL_CHECK_OGL()
94  VL_glBindFramebuffer( GL_DRAW_FRAMEBUFFER_EXT, draw_fbo );
95  VL_CHECK_OGL()
96  }
97  }
98 
100  {
101  copyPixels();
102  return true;
103  }
104 
106  {
107  copyPixels();
108  return true;
109  }
110 
111  virtual bool onRendererStarted(const RendererAbstract*)
112  {
113  copyPixels();
114  return true;
115  }
116 
118  {
119  copyPixels();
120  return true;
121  }
122 
125 
127  const Framebuffer* readFramebuffer() const { return mReadFramebuffer.get(); }
128 
131 
133  void setReadBuffer(EReadDrawBuffer read_buffer) { mReadBuffer = read_buffer; }
134 
137 
140 
142  const Framebuffer* drawFramebuffer() const { return mDrawFramebuffer.get(); }
143 
146 
147  void setSrcRect(int x0, int y0, int x1, int y1)
148  {
149  mSrcRect[0] = x0;
150  mSrcRect[1] = y0;
151  mSrcRect[2] = x1;
152  mSrcRect[3] = y1;
153  }
154 
155  void setDstRect(int x0, int y0, int x1, int y1)
156  {
157  mDstRect[0] = x0;
158  mDstRect[1] = y0;
159  mDstRect[2] = x1;
160  mDstRect[3] = y1;
161  }
162 
163  const int* srcRect() const { return mSrcRect; }
164  const int* dstRect() const { return mDstRect; }
165 
167  void setBufferMask(int buffer_mask) { mBufferMask = buffer_mask; }
168  int bufferMask() const { return mBufferMask; }
169 
170  void setLinearFilteringEnabled( bool enable_linear_filtering ) { mLinearFilteringEnabled = enable_linear_filtering; }
172 
173  protected:
176  int mSrcRect[4];
177  int mDstRect[4];
181  };
182 };
183 
184 #endif
virtual bool onRenderingFinished(const RenderingAbstract *)
Reimplement to react to this event.
const Framebuffer * drawFramebuffer() const
The render-target used as destination during blitting.
void setReadFramebuffer(Framebuffer *fbo)
The render-target used as source during blitting.
virtual bool onRendererStarted(const RendererAbstract *)
Reimplement to react to this event.
The RenderingAbstract class is the base of all the rendering related sub-classes. ...
const int * dstRect() const
A RenderEventCallback that can be used to copy pixels from a framebuffer to another as described in G...
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
bool linearFilteringEnabled() const
EReadDrawBuffer
Visualization Library main namespace.
An abstract class used to react to rendering events.
EReadDrawBuffer mReadBuffer
Framebuffer * readFramebuffer()
The render-target used as source during blitting.
void setReadBuffer(EReadDrawBuffer read_buffer)
The read-buffer of the read-render-target used as pixel source during blitting.
void setDrawFramebuffer(Framebuffer *fbo)
The render-target used as destination during blitting.
Base class providing all the basic funtionalities of a Renderer.
void setLinearFilteringEnabled(bool enable_linear_filtering)
void activate(EFramebufferBind target=FBB_FRAMEBUFFER)
Activates the Framebuffer by calling bindFramebuffer() and bindDrawBuffers()
Definition: Framebuffer.hpp:87
void setSrcRect(int x0, int y0, int x1, int y1)
const int * srcRect() const
const Framebuffer * readFramebuffer() const
The render-target used as source during blitting.
virtual bool onRendererFinished(const RendererAbstract *)
Reimplement to react to this event.
#define VL_CHECK_OGL()
Definition: OpenGL.hpp:156
void setBufferMask(int buffer_mask)
takes a bitmask combination of EBufferBits
void copyPixels()
Performs the actual pixel copy from the read framebuffer to the draw framebuffer. ...
ref< Framebuffer > mReadFramebuffer
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
Framebuffer * drawFramebuffer()
The render-target used as destination during blitting.
void setDstRect(int x0, int y0, int x1, int y1)
virtual bool onRenderingStarted(const RenderingAbstract *)
Reimplement to react to this event.
EReadDrawBuffer readBuffer() const
The read-buffer of the read-render-target used as pixel source during blitting.
The Framebuffer class defines an abstract &#39;surface&#39; where OpenGL can render into. ...
Definition: Framebuffer.hpp:49
ref< Framebuffer > mDrawFramebuffer