Developer Documentation
Loading...
Searching...
No Matches
GLPrimitives.hh
1
/*===========================================================================*\
2
* *
3
* OpenFlipper *
4
* Copyright (c) 2001-2015, RWTH-Aachen University *
5
* Department of Computer Graphics and Multimedia *
6
* All rights reserved. *
7
* www.openflipper.org *
8
* *
9
*---------------------------------------------------------------------------*
10
* This file is part of OpenFlipper. *
11
*---------------------------------------------------------------------------*
12
* *
13
* Redistribution and use in source and binary forms, with or without *
14
* modification, are permitted provided that the following conditions *
15
* are met: *
16
* *
17
* 1. Redistributions of source code must retain the above copyright notice, *
18
* this list of conditions and the following disclaimer. *
19
* *
20
* 2. Redistributions in binary form must reproduce the above copyright *
21
* notice, this list of conditions and the following disclaimer in the *
22
* documentation and/or other materials provided with the distribution. *
23
* *
24
* 3. Neither the name of the copyright holder nor the names of its *
25
* contributors may be used to endorse or promote products derived from *
26
* this software without specific prior written permission. *
27
* *
28
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39
* *
40
\*===========================================================================*/
41
42
43
44
45
46
//=============================================================================
47
//
48
// CLASS GLPrimitive
49
//
50
//=============================================================================
51
52
#ifndef ACG_GLPRIMITIVES_HH
53
#define ACG_GLPRIMITIVES_HH
54
55
56
//== INCLUDES =================================================================
57
58
59
#include <ACG/Config/ACGDefines.hh>
60
#include <ACG/GL/GLState.hh>
61
#include <ACG/Math/VectorT.hh>
62
#include <ACG/GL/VertexDeclaration.hh>
63
64
65
//== NAMESPACES ===============================================================
66
67
namespace
ACG
{
68
69
//== CLASS DEFINITION =========================================================
70
71
72
class
ACGDLLEXPORT
GLPrimitive
{
73
public
:
74
GLPrimitive
();
75
virtual
~GLPrimitive
();
76
77
// bind vbo + gl draw call (fixed function mode)
78
// use this function in compatibility profile
79
void
draw_primitive();
80
81
// activate vertex declaration + gl draw call (shader mode)
82
// _program may be nullptr, in that case the attribute locations are as follows.
83
// 0 : float3 position
84
// 1 : float3 normal
85
// 2 : float2 texcoord
86
void
draw_primitive(
GLSL::Program
* _program);
87
88
// add to deferred draw call to renderer
89
void
addToRenderer_primitive(
class
IRenderer
* _renderer,
struct
RenderObject
* _ro);
90
91
// Triangle or line count must be known before updateVBO.
92
// A GLPrimitive can consist of either only lines or only triangles.
93
// If getNumTriangles returns nonzero, its assumed to consist of tris only.
94
// Otherwise, getNumLines has to return nonzero and GLPrimitive is treated as a line-list.
95
virtual
int
getNumTriangles() = 0;
96
virtual
int
getNumLines() {
return
0;}
97
98
// get opengl vbo id
99
unsigned
int
getVBO();
100
101
const
VertexDeclaration
* getVertexDecl()
const
;
102
103
enum
NormalOrientation {OUTSIDE, INSIDE};
104
105
protected
:
106
107
// calls addTriangleToVBO to fill vertex buffer
108
virtual
void
updateVBO() = 0;
109
110
void
addTriangleToVBO(
const
ACG::Vec3f
* _p,
const
ACG::Vec3f
* _n,
const
ACG::Vec2f
* _tex);
111
void
addLineToVBO(
const
ACG::Vec3f
* _p,
const
ACG::Vec3f
* _n,
const
ACG::Vec2f
* _tex);
112
113
void
bindVBO();
114
115
bool
checkVBO();
116
117
void
unBindVBO();
118
119
bool
vboDataInvalid_;
120
121
NormalOrientation normalOrientation_;
122
123
private
:
124
125
void
updateVBOData();
126
127
int
numTris_;
128
int
numLines_;
129
float
* vboData_;
130
int
curTriPtr_;
131
132
VertexDeclaration
vertexDecl_;
133
134
unsigned
int
vbo_;
135
};
136
137
//------------------------------------------------------------------------
138
139
class
ACGDLLEXPORT
GLSphere
:
public
GLPrimitive
{
140
public
:
141
142
GLSphere
(
int
_slices,
int
_stacks);
143
~GLSphere
();
144
145
void
draw(
GLState
& _state,
float
_radius,
const
ACG::Vec3f
& _center =
ACG::Vec3f
(0.0f, 0.0f, 0.0f));
146
147
void
addToRenderer(
class
IRenderer
* _renderer,
const
struct
RenderObject
* _base,
float
_radius,
const
ACG::Vec3f
& _center =
ACG::Vec3f
(0.0f, 0.0f, 0.0f));
148
149
int
getNumTriangles()
override
;
150
151
private
:
152
153
void
updateVBO()
override
;
154
155
void
addTriangle(
int
sl0,
int
st0,
int
sl1,
int
st1,
int
sl2,
int
st2);
156
157
ACG::Vec3f
positionOnSphere(
int
_sliceNumber,
int
_stackNumber);
158
ACG::Vec2f
texCoordOnSphere(
int
_sliceNumber,
int
_stackNumber);
159
160
private
:
161
162
int
slices_;
163
int
stacks_;
164
165
};
166
167
//------------------------------------------------------------------------
168
169
class
ACGDLLEXPORT
GLCone
:
public
GLPrimitive
{
170
public
:
171
172
GLCone
(
int
_slices,
int
_stacks,
float
_bottomRadius,
float
_topRadius,
bool
_bottomCap_,
bool
_topCap);
173
~GLCone
();
174
175
void
draw(
176
GLState
& _state,
177
float
_height,
178
const
ACG::Vec3f
& _center =
ACG::Vec3f
(0.0f, 0.0f, 0.0f),
179
ACG::Vec3f
_upDir =
ACG::Vec3f
(0.0f, 0.0f, 1.0f));
180
181
182
void
addToRenderer(
class
IRenderer
* _renderer,
const
struct
RenderObject
* _base,
183
float
_height,
184
const
ACG::Vec3f
& _center =
ACG::Vec3f
(0.0f, 0.0f, 0.0f),
185
ACG::Vec3f
_upDir =
ACG::Vec3f
(0.0f, 0.0f, 1.0f),
186
float
_radiusScale = 1.0f);
187
188
int
getNumTriangles()
override
;
189
190
void
updateVBO()
override
;
191
void
setBottomRadius(
float
_bottomRadius);
192
void
setTopRadius(
float
_topRadius);
193
void
setNormalOrientation(NormalOrientation orienation);
194
195
private
:
196
197
void
addTriangle(
int
sl0,
int
st0,
int
sl1,
int
st1,
int
sl2,
int
st2);
198
199
ACG::Vec3f
positionOnCone(
int
_sliceNumber,
int
_stackNumber);
200
ACG::Vec2f
texCoordOnCone(
int
_sliceNumber,
int
_stackNumber);
201
ACG::Vec3f
normalOnCone(
int
_sliceNumber,
int
_stackNumber);
202
203
private
:
204
205
int
slices_;
206
int
stacks_;
207
208
float
bottomRadius_;
209
float
topRadius_;
210
211
bool
bottomCap_;
212
bool
topCap_;
213
214
};
215
216
//------------------------------------------------------------------------
217
218
class
ACGDLLEXPORT
GLCylinder
:
public
GLCone
{
219
public
:
220
GLCylinder
(
int
_slices,
int
_stacks,
float
_radius,
bool
_bottomCap,
bool
_topCap);
221
};
222
223
//------------------------------------------------------------------------
224
225
class
ACGDLLEXPORT
GLPartialDisk
:
public
GLPrimitive
{
226
public
:
227
GLPartialDisk
(
int
_slices,
int
_loops,
float
_innerRadius,
float
_outerRadius,
float
_startAngle,
float
_sweepAngle);
228
229
void
setInnerRadius(
float
_innerRadius);
230
void
setOuterRadius(
float
_outerRadius);
231
int
getNumTriangles()
override
;
232
233
void
draw(
234
GLState
& _state,
235
const
ACG::Vec3f
& _center =
ACG::Vec3f
(0.0f, 0.0f, 0.0f),
236
ACG::Vec3f
_upDir =
ACG::Vec3f
(0.0f, 0.0f, 1.0f));
237
238
protected
:
239
void
updateVBO()
override
;
240
241
private
:
242
int
slices_;
243
int
loops_;
244
float
innerRadius_;
245
float
outerRadius_;
246
float
startAngle_;
247
float
sweepAngle_;
248
};
249
250
//------------------------------------------------------------------------
251
252
class
ACGDLLEXPORT
GLDisk
:
public
GLPartialDisk
{
253
public
:
254
GLDisk
(
int
_slices,
int
_loops,
float
_innerRadius,
float
_outerRadius);
255
};
256
257
//------------------------------------------------------------------------
258
259
// axis-aligned unit cube centered at origin
260
class
ACGDLLEXPORT
GLBox
:
public
GLPrimitive
{
261
public
:
262
263
GLBox
();
264
~GLBox
();
265
266
int
getNumTriangles()
override
;
267
268
private
:
269
270
void
updateVBO()
override
;
271
};
272
273
//------------------------------------------------------------------------
274
275
// axis-aligned unit cube centered at origin, only lines
276
class
ACGDLLEXPORT
GLLineBox
:
public
GLPrimitive
{
277
public
:
278
279
GLLineBox
();
280
~GLLineBox
();
281
282
int
getNumTriangles()
override
;
283
int
getNumLines()
override
;
284
285
private
:
286
287
void
updateVBO()
override
;
288
};
289
290
//------------------------------------------------------------------------
291
292
// axis-aligned Dodecahedron centered at origin
293
class
ACGDLLEXPORT
GLDodecahedron
:
public
GLPrimitive
{
294
public
:
295
296
GLDodecahedron
();
297
~GLDodecahedron
();
298
299
int
getNumTriangles()
override
;
300
301
private
:
302
303
void
updateVBO()
override
;
304
};
305
306
//------------------------------------------------------------------------
307
308
// axis-aligned Icosahedron centered at origin
309
class
ACGDLLEXPORT
GLIcosahedron
:
public
GLPrimitive
{
310
public
:
311
312
GLIcosahedron
();
313
~GLIcosahedron
();
314
315
int
getNumTriangles()
override
;
316
317
private
:
318
319
void
updateVBO()
override
;
320
};
321
322
//------------------------------------------------------------------------
323
324
// axis-aligned Icosahedron centered at origin
325
class
ACGDLLEXPORT
GLOctahedron
:
public
GLPrimitive
{
326
public
:
327
328
GLOctahedron
();
329
~GLOctahedron
();
330
331
int
getNumTriangles()
override
;
332
333
private
:
334
335
void
updateVBO()
override
;
336
};
337
338
//------------------------------------------------------------------------
339
340
// axis-aligned Icosahedron centered at origin
341
class
ACGDLLEXPORT
GLTetrahedron
:
public
GLPrimitive
{
342
public
:
343
344
GLTetrahedron
();
345
~GLTetrahedron
();
346
347
int
getNumTriangles()
override
;
348
349
private
:
350
351
void
updateVBO()
override
;
352
};
353
354
//------------------------------------------------------------------------
355
356
// axis-aligned Torus centered at origin
357
class
ACGDLLEXPORT
GLTorus
:
public
GLPrimitive
{
358
public
:
359
360
GLTorus
(GLdouble innerRadius,
361
GLdouble outerRadius,
362
GLint nsides, GLint rings);
363
~GLTorus
();
364
365
int
getNumTriangles()
override
;
366
367
private
:
368
369
void
updateVBO()
override
;
370
371
int
rings_;
372
int
nsides_;
373
float
innerRadius_;
374
float
outerRadius_;
375
376
};
377
378
//------------------------------------------------------------------------
379
380
}
// namespace ACG
381
382
#endif
// ACG_GLPRIMITIVES_HH defined
ACG::GLBox
Definition
GLPrimitives.hh:260
ACG::GLCone
Definition
GLPrimitives.hh:169
ACG::GLCylinder
Definition
GLPrimitives.hh:218
ACG::GLDisk
Definition
GLPrimitives.hh:252
ACG::GLDodecahedron
Definition
GLPrimitives.hh:293
ACG::GLIcosahedron
Definition
GLPrimitives.hh:309
ACG::GLLineBox
Definition
GLPrimitives.hh:276
ACG::GLOctahedron
Definition
GLPrimitives.hh:325
ACG::GLPartialDisk
Definition
GLPrimitives.hh:225
ACG::GLPrimitive
Definition
GLPrimitives.hh:72
ACG::GLSphere
Definition
GLPrimitives.hh:139
ACG::GLState
Definition
GLState.hh:214
ACG::GLTetrahedron
Definition
GLPrimitives.hh:341
ACG::GLTorus
Definition
GLPrimitives.hh:357
ACG::IRenderer
Definition
IRenderer.hh:79
ACG::VertexDeclaration
Class to define the vertex input layout.
Definition
VertexDeclaration.hh:269
GLSL::Program
GLSL program class.
Definition
GLSLShader.hh:211
OpenMesh::VectorT
Definition
Vector11T.hh:83
ACG
Namespace providing different geometric functions concerning angles.
Definition
BaseObjectData.hh:68
ACG::RenderObject
Interface class between scenegraph and renderer.
Definition
RenderObject.hh:99
OpenFlipper
libs_required
ACG
GL
GLPrimitives.hh
Generated on Wed Jul 16 2025 14:44:31 for Developer Documentation by
1.9.8