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]
EdgeRenderer.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 EdgeRenderer_INCLUDE_ONCE
33 #define EdgeRenderer_INCLUDE_ONCE
34 
35 #include <vlGraphics/Renderer.hpp>
38 
39 namespace vl
40 {
56  {
58 
59  class WFInfo: public Object
60  {
61  public:
62  WFInfo(): mColor( vl::black ) {}
63  fvec4 mColor;
64  ref<Geometry> mGeometry;
65  ref<EdgeUpdateCallback> mEdgeCallback;
66  };
67 
68  public:
69  EdgeRenderer(): mLineWidth(1.0f), mPolygonOffsetFactor(1.0f), mPolygonOffsetUnits(1.0f), mCreaseAngle(44.0f), mShowHiddenLines(true), mShowCreases(true), mSmoothLines(true)
70  {
71  VL_DEBUG_SET_OBJECT_NAME()
72  }
73 
74  const RenderQueue* render(const RenderQueue* in_render_queue, Camera* camera, real frame_clock);
75 
77  WFInfo* declareActor(Actor* act, const fvec4& color);
79  WFInfo* declareActor(Actor* act);
80 
84  void clearCache() { mActorCache.clear(); }
85 
89  void setActorDirty(Actor* actor) { mActorCache.erase(actor); }
90 
92  void setShowHiddenLines(bool show) { mShowHiddenLines = show; }
94  bool showHiddenLines() const { return mShowHiddenLines; }
95 
97  void setShowCreases(bool show) { mShowCreases = show; }
99  bool showCreases() const { return mShowCreases; }
100 
102  void setCreaseAngle(float degrees) { mCreaseAngle = degrees; }
104  float creaseAngle() const { return mCreaseAngle; }
105 
107  void setSmoothLines(bool smooth) { mSmoothLines = smooth; }
109  bool smoothLines() const { return mSmoothLines; }
110 
112  void setLineWidth(float width) { mLineWidth = width; }
114  float lineWidth() const { return mLineWidth; }
115 
117  void setDefaultLineColor(const fvec4& c) { mDefaultLineColor = c; }
119  const fvec4& defaultLineColor() const { return mDefaultLineColor; }
120 
122  void setPolygonOffsetFactor(float factor) { mPolygonOffsetFactor = factor; }
124  float polygonOffsetFactor() const { return mPolygonOffsetFactor; }
126  void setPolygonOffsetUnits(float units) { mPolygonOffsetUnits = units; }
128  float polygonOffsetUnits() const { return mPolygonOffsetUnits; }
129 
130  protected:
131  void renderSolids(Camera* camera, real frame_clock);
132  void renderLines(Camera* camera);
133 
134  protected:
135  std::map< ref<Actor>, ref<WFInfo> > mActorCache;
136  std::map< ref<Actor>, ref<WFInfo> > mVisibleActors;
138  float mLineWidth;
145  };
146 
147 }
148 
149 #endif
Associates a Renderable object to an Effect and Transform.
Definition: Actor.hpp:130
void setPolygonOffsetFactor(float factor)
Defines the factor parameter used to render the lines over the polygons. See also http://www...
float creaseAngle() const
The minimum angle (in degrees) considered to generate crease-edges (default is 44 degrees)...
The Renderer class executes the actual rendering on the given RenderQueue.
Definition: Renderer.hpp:48
T degrees(T radians)
Definition: glsl_math.hpp:173
The EdgeRenderer class implements a special Renderer that automatically extracts and renders the edge...
std::map< ref< Actor >, ref< WFInfo > > mVisibleActors
std::map< ref< Actor >, ref< WFInfo > > mActorCache
float lineWidth() const
Defines the width of the rendered edges.
float polygonOffsetFactor() const
Defines the factor parameter used to render the lines over the polygons. See also http://www...
bool showCreases() const
If set to true shows not only the edges that define the silhouette of an object but also the crease e...
float polygonOffsetUnits() const
Defines the units parameter used to render the lines over the polygons. See also http://www.opengl.org/sdk/docs/man/xhtml/glPolygonOffset.xml for more information.
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
void setDefaultLineColor(const fvec4 &c)
Defines the default color of the rendered edges. You can also define a per-Actor color using the decl...
Visualization Library main namespace.
void setLineWidth(float width)
Defines the width of the rendered edges.
bool smoothLines() const
If set to true the lines will be rendered using antialiasing.
void setPolygonOffsetUnits(float units)
Defines the units parameter used to render the lines over the polygons. See also http://www.opengl.org/sdk/docs/man/xhtml/glPolygonOffset.xml for more information.
const fvec4 & defaultLineColor() const
Defines the default color of the rendered edges. You can also define a per-Actor color using the decl...
The base class for all the reference counted objects.
Definition: Object.hpp:158
void setCreaseAngle(float degrees)
The minimum angle (in degrees) considered to generate crease-edges (default is 44 degrees)...
void setShowCreases(bool show)
If set to true shows not only the edges that define the silhouette of an object but also the crease e...
void setShowHiddenLines(bool show)
If set to true shows also the hidden lines with a dashed pattern.
bool showHiddenLines() const
If set to true shows also the hidden lines with a dashed pattern.
The RenderQueue class collects a list of RenderToken objects to be sorted and rendered.
Definition: RenderQueue.hpp:45
void clearCache()
Clears the cache containing the Actor and edge information.
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
void setActorDirty(Actor *actor)
Removes all the edge/rendering information relative to the specified Actor from the cache...
void setSmoothLines(bool smooth)
If set to true the lines will be rendered using antialiasing.