Visualization Library 2.0.0-b3

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
RendererAbstract.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2017, 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 RendererAbstract_INCLUDE_ONCE
33 #define RendererAbstract_INCLUDE_ONCE
34 
36 #include <vlCore/Collection.hpp>
38 
39 namespace vl
40 {
41  class Camera;
42  class RenderQueue;
43  class Framebuffer;
44 
45  //-----------------------------------------------------------------------------
46  // RendererAbstract
47  //-----------------------------------------------------------------------------
52  {
54 
55  public:
57  {
58  VL_DEBUG_SET_OBJECT_NAME()
59  mOnStartedCallbacks = new Collection<RenderEventCallback>;
60  mOnFinishedCallbacks = new Collection<RenderEventCallback>;
61  mClearFlags = CF_CLEAR_COLOR_DEPTH;
62  mEnableMask = 0xFFFFFFFF;
63  mRenderTick = 0;
64  mFrameClock = 0;
65  }
66 
68  {
69  *mOnStartedCallbacks = *other.mOnStartedCallbacks;
70  *mOnFinishedCallbacks = *other.mOnFinishedCallbacks;
71  mClearFlags = other.mClearFlags;
72  mEnableMask = other.mEnableMask;
73  /* mRenderTick = other.mRenderTick; */ // render-tick remains local
74  /* mFrameClock = other.mFrameClock; */ // update time remains local
75  return *this;
76  }
77 
80  virtual const RenderQueue* render(const RenderQueue* in_render_queue, Camera* camera, real frame_clock) = 0;
81 
83  virtual const Framebuffer* framebuffer() const = 0;
84 
86  virtual Framebuffer* framebuffer() = 0;
87 
90  {
91  Collection<RenderEventCallback>& cb = *mOnStartedCallbacks;
92  for(int i=0; i<cb.size(); ++i)
93  {
94  if ( cb[i]->isEnabled() && cb[i]->onRendererStarted(this) && cb[i]->removeAfterCall() )
95  {
96  onStartedCallbacks()->eraseAt( i );
97  --i;
98  }
99  }
100  }
101 
104  {
105  Collection<RenderEventCallback>& cb = *mOnFinishedCallbacks;
106  for(int i=0; i<cb.size(); ++i)
107  {
108  if ( cb[i]->isEnabled() && cb[i]->onRendererFinished(this) && cb[i]->removeAfterCall() )
109  {
110  onFinishedCallbacks()->eraseAt( i );
111  --i;
112  }
113  }
114  }
115 
117  Collection<RenderEventCallback>* onFinishedCallbacks() { return mOnFinishedCallbacks.get(); }
118 
120  const Collection<RenderEventCallback>* onFinishedCallbacks() const { return mOnFinishedCallbacks.get(); }
121 
123  Collection<RenderEventCallback>* onStartedCallbacks() { return mOnStartedCallbacks.get(); }
124 
126  const Collection<RenderEventCallback>* onStartedCallbacks() const { return mOnStartedCallbacks.get(); }
127 
129  unsigned long renderTick() const { return mRenderTick; }
130 
132  void incrementRenderTick() { ++mRenderTick; }
133 
135  void setClearFlags(EClearFlags clear_flags) { mClearFlags = clear_flags; }
136 
138  EClearFlags clearFlags() const { return mClearFlags; }
139 
141  void setEnableMask(unsigned int mask) { mEnableMask = mask; }
142 
144  unsigned int enableMask() const { return mEnableMask; }
145 
147  void setFrameClock(real t) { mFrameClock = t; }
148 
150  real frameClock() const { return mFrameClock; }
151 
152  protected:
155  unsigned long mRenderTick;
156  unsigned int mEnableMask;
159  };
160  //------------------------------------------------------------------------------
161 }
162 
163 #endif
Collection< RenderEventCallback > * onStartedCallbacks()
Returns the list of RenderEventCallback objects registered to onRendererStarted() event notification...
void eraseAt(int index)
Definition: Collection.hpp:159
int size() const
Definition: Collection.hpp:82
void setClearFlags(EClearFlags clear_flags)
The clear flags used to clear the viewport.
ref< Collection< RenderEventCallback > > mOnFinishedCallbacks
void dispatchOnRendererFinished()
Dispatches the onRendererFinished() event to the registered RenderEventCallback objects.
Visualization Library main namespace.
void setFrameClock(real t)
The current rendring frame time.
ref< Collection< RenderEventCallback > > mOnStartedCallbacks
RendererAbstract & operator=(const RendererAbstract &other)
The base class for all the reference counted objects.
Definition: Object.hpp:158
void incrementRenderTick()
Increments the rendering tick count.
Base class providing all the basic funtionalities of a Renderer.
Collection< RenderEventCallback > * onFinishedCallbacks()
Returns the list of RenderEventCallback objects registered to onRendererFinished() event notification...
unsigned long renderTick() const
The current render tick number, equivalent to the number or calls made to the render() method...
EClearFlags
The RenderQueue class collects a list of RenderToken objects to be sorted and rendered.
Definition: RenderQueue.hpp:45
void setEnableMask(unsigned int mask)
Enable mask used to enable/disable the rendering of matching Actors.
#define VL_INSTRUMENT_ABSTRACT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:145
It&#39;s basically an std::vector for Objects that is itself an Object so it can be reference counted and...
Definition: Collection.hpp:49
const Collection< RenderEventCallback > * onStartedCallbacks() const
Returns the list of RenderEventCallback objects registered to onRendererStarted() event notification...
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
Represents a virtual camera defining, among other things, the point of view from which scenes can be ...
Definition: Camera.hpp:50
real frameClock() const
The current rendring frame time.
unsigned int enableMask() const
Enable mask used to enable/disable the rendering of matching Actors.
The Framebuffer class defines an abstract &#39;surface&#39; where OpenGL can render into. ...
Definition: Framebuffer.hpp:49
EClearFlags clearFlags() const
The clear flags used to clear the viewport.
void dispatchOnRendererStarted()
Dispatches the onRendererStarted() event to the registered RenderEventCallback objects.
const Collection< RenderEventCallback > * onFinishedCallbacks() const
Returns the list of RenderEventCallback objects registered to onRendererFinished() event notification...