-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndexedTessellator.h
166 lines (134 loc) · 7.74 KB
/
IndexedTessellator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**************************************************************************************/
/* */
/* Visualization Library */
/* http://visualizationlibrary.org */
/* */
/* Copyright (c) 2005-2020, Michele Bosi */
/* All rights reserved. */
/* */
/* Redistribution and use in source and binary forms, with or without modification, */
/* are permitted provided that the following conditions are met: */
/* */
/* - Redistributions of source code must retain the above copyright notice, this */
/* list of conditions and the following disclaimer. */
/* */
/* - Redistributions in binary form must reproduce the above copyright notice, this */
/* list of conditions and the following disclaimer in the documentation and/or */
/* other materials provided with the distribution. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
/* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
/* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* */
/**************************************************************************************/
#ifndef IndexedTessellator_INCLUDE_ONCE
#define IndexedTessellator_INCLUDE_ONCE
#include <vlGraphics/OpenGL.hpp>
#include <vlGraphics/Geometry.hpp>
#include <vlCore/Vector3.hpp>
#include <vector>
#ifndef CALLBACK
#define CALLBACK
#endif
namespace vl
{
/**
* Tessellates a complex polygon defined by a set of outlines into a set of triangles that can be rendered by Visualization Library.
* For more information see the OpenGL Programmer's Guide chapter #11 "Tessellators and Quadrics".
*/
class VLGRAPHICS_EXPORT IndexedTessellator: public Object
{
VL_INSTRUMENT_CLASS(vl::Tessellator, Object)
typedef void (CALLBACK *callback_type)(void);
public:
//! Constructor.
IndexedTessellator();
//! Destructor
~IndexedTessellator();
//! The contours that specify the complex polygon to be tessellated.
const std::vector<dvec3>& contourVerts() const { return mContourVerts; }
//! The contours that specify the complex polygon to be tessellated.
std::vector<dvec3>& contourVerts() { return mContourVerts; }
//! The indices of the contour vertices.
const std::vector<int>& indices() const { return mIndices; }
//! The indices of the contour vertices.
std::vector<int>& indices() { return mIndices; }
//! The contours that specify the complex polygon to be tessellated.
const std::vector<int>& contours() const { return mContours; }
//! The contours that specify the complex polygon to be tessellated.
std::vector<int>& contours() { return mContours; }
//! A set of triangles representing the tessellated polygon.
const std::vector<int>& tessellatedTris() const { return mTessellatedTris; }
//! A set of triangles representing the tessellated polygon.
std::vector<int>& tessellatedTris() { return mTessellatedTris; }
//! Newly generated vertices.
const std::vector<vl::fvec3>& combinedVerts() const { return mCombinedVertices; }
//! Newly generated vertices.
std::vector<vl::fvec3>& combinedVerts() { return mCombinedVertices; }
//! See gluTessNormal documentation.
void setTessNormal(const fvec3& normal) { mTessNormal = normal; }
//! See gluTessNormal documentation.
const fvec3& tessNormal() const { return mTessNormal; }
//! See gluTessProperty documentation (GLU_TESS_BOUNDARY_ONLY)
void setBoundaryOnly(bool on) { mBoundaryOnly = on; }
//! See gluTessProperty documentation (GLU_TESS_BOUNDARY_ONLY)
bool boundaryOnly() const { return mBoundaryOnly; }
//! See gluTessProperty documentation (GLU_TESS_TOLERANCE)
double tolerance() const { return mTolerance; }
//! See gluTessProperty documentation (GLU_TESS_TOLERANCE)
void setTolerance(double tolerance) { mTolerance = tolerance; }
//! See gluTessProperty documentation (GLU_TESS_WINDING_RULE)
ETessellationWinding windingRule() const { return mWindingRule; }
//! See gluTessProperty documentation (GLU_TESS_WINDING_RULE)
void setWindingRule(ETessellationWinding rule) { mWindingRule = rule; }
/*
* Tessellates the specified polygon.
* If \p append_tessellated_tris equals \p true then the previously tessellated triangles are kept and the newly
* generated triangles are appended to them. This is useful when one has to tessellate several triangles and
* the result should be accumulated in a single triangle set.
*
* After the function is called the contours() and contourVerts() are cleared.
*/
bool tessellate(bool append_tessellated_tris=false);
void setTessellateIntoSinglePolygon(bool on) { mTessellateIntoSinglePolygon = on; }
bool tessellateIntoSinglePolygon() const { return mTessellateIntoSinglePolygon; }
protected:
static void CALLBACK tessBeginData( GLenum type, IndexedTessellator* tessellator );
static void CALLBACK tessVertexData( int vec, IndexedTessellator* tessellator );
static void CALLBACK tessCombineData( GLdouble coords[3], dvec3 *d[4], GLfloat w[4], void **dataOut, IndexedTessellator* tessellator );
static void CALLBACK tessEnd(void);
static void CALLBACK tessError( GLenum errno );
void freeCombinedVertices();
protected:
// input
std::vector<int> mContours;
std::vector<dvec3> mContourVerts;
std::vector<int> mIndices;
// output
std::vector<int> mTessellatedTris;
// intermediate data
std::vector< std::vector<int> > mFans;
std::vector< std::vector<int> > mTriStrips;
std::vector< std::vector<int> > mLineLoops;
std::vector<fvec3> mCombinedVertices;
GLenum mPrimitiveType;
// see gluTessNorml()
fvec3 mTessNormal;
// see GLU_TESS_BOUNDARY_ONLY
bool mBoundaryOnly;
// see GLU_TESS_TOLERANCE
double mTolerance;
// see GLU_TESS_WINDING_RULE
ETessellationWinding mWindingRule;
// tessellate into a single polygon
bool mTessellateIntoSinglePolygon;
};
}
#endif