Visualization Library 2.1.0

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
GeometryLoadCallback.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 GeometryLoadCallback_INCLUDE_ONCE
33 #define GeometryLoadCallback_INCLUDE_ONCE
34 
35 #include <vlGraphics/Geometry.hpp>
39 
40 namespace vl
41 {
46  {
48 
49  public:
51  {
52  mMakeGLESFriendly = false;
53  mComputeNormals = true;
54  mUseBufferObjects = true;
55  mUseDisplayLists = false;
56  mTransformGeometry = false;
58  mRemoveDoubles = false;
59  mSortVertices = false;
60  mStripfy = false;
61  mConvertToDrawArrays = false;
62  }
63 
65  {
66  if (stripfy())
67  setRemoveDoubles(true);
68 
69  std::vector< vl::ref<vl::Geometry> > geom;
70  db->get<Geometry>(geom);
71  for(unsigned int i=0; i<geom.size(); ++i)
72  {
74  geom[i]->setNormalArray(NULL);
75 
76  if (computeNormals() && !geom[i]->normalArray())
77  geom[i]->computeNormals();
78 
79  if (removeDoubles())
80  DoubleVertexRemover().removeDoubles(geom[i].get());
81 
82  if (sortVertices())
83  geom[i]->sortVertices();
84 
85  if (stripfy())
86  TriangleStripGenerator().stripfy(geom[i].get(), 22, true, false, true);
87 
88  if (convertToDrawArrays())
89  geom[i]->convertDrawCallToDrawArrays();
90 
91  geom[i]->setDisplayListEnabled(useDisplayLists());
92  geom[i]->setBufferObjectEnabled(useBufferObjects());
93 
94  if (transformGeometry())
95  geom[i]->transform(transformMatrix(),true);
96 
97  if (makeGLESFriendly())
98  geom[i]->makeGLESFriendly();
99  }
100  }
101 
106 
108  bool computeNormals() const { return mComputeNormals; }
110  void setComputeNormals(bool cn) { mComputeNormals = cn; }
111 
113  bool removeDoubles() const { return mRemoveDoubles; }
115  void setRemoveDoubles(bool rd) { mRemoveDoubles = rd; }
116 
118  void setSortVertices(bool on) { mSortVertices = on; }
120  bool sortVertices() const { return mSortVertices; }
121 
123  void setStripfy(bool on) { mStripfy = on; }
125  bool stripfy() const { return mStripfy; }
126 
128  bool convertToDrawArrays() const { return mConvertToDrawArrays; }
131 
133  void setUseDisplayLists(bool on) { mUseDisplayLists = on; }
135  bool useDisplayLists() const { return mUseDisplayLists; }
136 
138  void setUseBufferObjects(bool on) { mUseBufferObjects = on; }
140  bool useBufferObjects() const { return mUseBufferObjects; }
141 
142  const mat4& transformMatrix() const { return mMatrix; }
143  void setTransformMatrix(const mat4& m) { mMatrix = m; }
144 
146  bool transformGeometry() const { return mTransformGeometry; }
148  void setTransformGeometry(bool on) { mTransformGeometry = on; }
149 
151  bool makeGLESFriendly() const { return mMakeGLESFriendly; }
153  void setMakeGLESFriendly(bool on) { mMakeGLESFriendly = on; }
154 
155  protected:
162  bool mStripfy;
167  };
168 }
169 
170 #endif
bool transformGeometry() const
Transforms the Geometries using transformMatrix().
void setUseDisplayLists(bool on)
Enable display lists usage (overrides BufferObjects)
Defines a set of actions to be executed to a Geometry as soon as it is loaded.
The TriangleStripGenerator class is used to substitute lists of triangles or quads with triangle stri...
Defines an operation to be exectued to a ResourceDatabase as soon as its loaded, see also LoadWriterM...
bool sortVertices() const
Sorts the mesh&#39;s vertices for better performances.
void setComputeNormals(bool cn)
Compute normals if not present.
void setConvertToDrawArrays(bool on)
Converts the Geometry DrawCall into DrawArrays. Useful in conjuction with setStripfy(true).
static void stripfy(Geometry *geom, int cache_size=22, bool merge_strips=true, bool remove_doubles=true, bool substitute_quads=true)
bool makeGLESFriendly() const
If true calls Geometry::makeGLESFriendly()
Removes from a Geometry the vertices with the same attributes.
void removeDoubles(Geometry *geom)
void setMakeGLESFriendly(bool on)
If true calls Geometry::makeGLESFriendly()
bool convertToDrawArrays() const
Converts the Geometry DrawCall into DrawArrays. Useful in conjuction with setStripfy(true).
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
void setUseBufferObjects(bool on)
Enable BufferObject usage if display lists are disabled.
The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points.
Definition: Geometry.hpp:66
void operator()(ResourceDatabase *db)
Visualization Library main namespace.
void setTransformGeometry(bool on)
Transforms the Geometries using transformMatrix().
void setRemoveDoubles(bool rd)
Remove duplicated vertices.
bool useBufferObjects() const
Enable BufferObject usage if display lists are disabled.
const mat4 & transformMatrix() const
void get(std::vector< ref< T > > &resources, bool clear_vector=true)
Returns all the objects of the specified type in the given vector.
bool stripfy() const
Convert mesh into a set of triangle strips if possible.
#define NULL
Definition: OpenGLDefs.hpp:81
void setSortVertices(bool on)
Sorts the mesh&#39;s vertices for better performances.
void setTransformMatrix(const mat4 &m)
void setDiscardOriginalNormals(bool on)
Discards the original normals.
void setStripfy(bool on)
Convert mesh into a set of triangle strips if possible.
bool discardOriginalNormals() const
Discards the original normals.
bool removeDoubles() const
Remove duplicated vertices.
bool useDisplayLists() const
Enable display lists usage (overrides BufferObjects)
The ResourceDatabase class contains and manipulates a set of resources.
bool computeNormals() const
Compute normals if not present.