Open Inventor Reference
SoShape.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37
38/*
39 * Copyright (C) 1990,91 Silicon Graphics, Inc.
40 *
41 _______________________________________________________________________
42 ______________ S I L I C O N G R A P H I C S I N C . ____________
43 |
44 | $Revision: 1.1.1.1 $
45 |
46 | Description:
47 | This file defines the SoShape node class.
48 |
49 | Author(s) : Paul S. Strauss
50 |
51 ______________ S I L I C O N G R A P H I C S I N C . ____________
52 _______________________________________________________________________
53 */
54
55#ifndef _SO_SHAPE_
56#define _SO_SHAPE_
57
58#include <Inventor/SbLinear.h>
60
62#include <Inventor/misc/SoVBO.h>
63
64class SoCube;
65class SoDetail;
66class SoFaceDetail;
68class SoPickedPoint;
69class SoPointDetail;
71class SoState;
72
73
75#ifndef gluTESSELATOR
76#if (defined(__glu_h__) || defined(GLU_H)) && defined(GLU_VERSION_1_2)
77#define gluTESSELATOR GLUtesselator
78#else
79#define gluTESSELATOR GLUtriangulatorObj
80extern "C" struct GLUtriangulatorObj;
81#endif
82#endif
83
84
85
88
100
102
104
105 public:
107 virtual bool affectsState() const;
108
109 SoINTERNAL public:
110 static void initClass();
111
118 POLYGON
119 };
120
121 SoEXTENDER public:
125
128 virtual void GLRender(SoGLRenderAction *action);
129
133 virtual void rayPick(SoRayPickAction *action);
134
137 virtual void callback(SoCallbackAction *action);
138
143 static void getScreenSize(SoState *state,
144 const SbBox3f &boundingBox,
145 SbVec2s &rectSize);
146
152 virtual void computeBBox(SoAction *action, SbBox3f &box,
153 SbVec3f &center) = 0;
154
155 public:
157 typedef void VertexArrayRenderingCB(SoNode* shape, SoGLRenderAction*, bool useVbo, uint32_t numVertices);
158
160 static void setPreVertexArrayRenderingCallback(VertexArrayRenderingCB* cb);
162 static void setPostVertexArrayRenderingCallback(VertexArrayRenderingCB* cb);
163
167
168 void drawArrays(SoShape* shape, SoGLRenderAction* action, GLenum primitiveType);
169
171
173
175
177
182
186 };
187
188 protected:
191
195 virtual void generatePrimitives(SoAction *action) = 0;
196
200 virtual bool shouldGLRender(SoGLRenderAction *action);
201
205
212
221 const SbMatrix &matrix);
222
231 const SoPrimitiveVertex *v1,
232 const SoPrimitiveVertex *v2,
233 const SoPrimitiveVertex *v3,
234 SoPickedPoint *pp);
236 const SoPrimitiveVertex *v1,
237 const SoPrimitiveVertex *v2,
238 SoPickedPoint *pp);
240 const SoPrimitiveVertex *v,
241 SoPickedPoint *pp);
242
250 const SoPrimitiveVertex *v1,
251 const SoPrimitiveVertex *v2,
252 const SoPrimitiveVertex *v3);
254 const SoPrimitiveVertex *v1,
255 const SoPrimitiveVertex *v2);
257 const SoPrimitiveVertex *v);
258
279 void beginShape(SoAction *action, TriangleShape shapeType,
280 SoFaceDetail *faceDetail = NULL);
282 void endShape();
283
284 virtual ~SoShape();
285
289
290 private:
291
296 static SoGetBoundingBoxAction *bboxAct;
297 static SoCube *bboxCube;
298
302 static bool sendTexCoords;
303 static SoMaterialBundle *matlBundle;
304
306 static TriangleShape primShapeType;
307 static SoFaceDetail *faceDetail;
308 static int nestLevel;
309 static SoAction *primAction;
310 static int primVertNum;
311 static int polyVertNum;
312 static SoShape *primShape;
313
316 static SoPrimitiveVertex *primVerts;
317 static SoPointDetail *vertDetails;
318 static SoPrimitiveVertex *polyVerts;
319 static SoPointDetail *polyDetails;
320 static int numPolyVertsAllocated;
321 static GLUtriangulatorObj *tobj;
322
325 void GLRenderTriangle(SoGLRenderAction *action,
326 const SoPrimitiveVertex *v1,
327 const SoPrimitiveVertex *v2,
328 const SoPrimitiveVertex *v3);
329 void GLRenderLineSegment(SoGLRenderAction *action,
330 const SoPrimitiveVertex *v1,
331 const SoPrimitiveVertex *v2);
332 void GLRenderPoint(SoGLRenderAction *action,
333 const SoPrimitiveVertex *v);
334
337 void rayPickTriangle(SoRayPickAction *action,
338 const SoPrimitiveVertex *v1,
339 const SoPrimitiveVertex *v2,
340 const SoPrimitiveVertex *v3);
341 void rayPickLineSegment(SoRayPickAction *action,
342 const SoPrimitiveVertex *v1,
343 const SoPrimitiveVertex *v2);
344 void rayPickPoint(SoRayPickAction *action,
345 const SoPrimitiveVertex *v);
346
349 void rayPickBoundingBox(SoRayPickAction *action);
350
352 void triangleVertex(const SoPrimitiveVertex *v,
353 int vertToReplace);
354
356 void allocateVerts();
357
359 static void CALLBACK beginCB(GLenum primType);
360 static void CALLBACK vtxCB(void *vertex);
361 static void CALLBACK endCB();
362 static void CALLBACK errorCB(GLenum err);
363
364protected:
365 static VertexArrayRenderingCB* _preVertexArrayRenderingCB;
366 static VertexArrayRenderingCB* _postVertexArrayRenderingCB;
367};
368
369#endif /* _SO_SHAPE_ */
#define SoEXTENDER
Provide inline template functions for abs, swap, min, max, and clamp.
Definition SbBasic.h:154
#define SoINTERNAL
Definition SbBasic.h:155
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition SbSystem.h:77
unsigned int uint32_t
Definition SbTypeDefs.h:44
#define SO_NODE_ABSTRACT_HEADER(className)
Macros to be called within the class definition header for a node subclass:
Definition SoSubNode.h:150
3D box class.
Definition SbBox.h:81
4x4 matrix class.
Definition SbLinear.h:823
2D vector class.
Definition SbLinear.h:354
3D vector class.
Definition SbLinear.h:120
Abstract base class for all actions.
Definition SoAction.h:179
Performs a generic traversal of the scene graph.
Cube shape node.
Definition SoCube.h:119
Base class for describing detail information about a shape node.
Definition SoDetail.h:78
Stores detail information about vertex-based shapes made of faces.
Renders a scene graph using OpenGL.
Computes bounding box of a scene.
Bundle that allows shapes to deal with materials more easily.
Abstract base class for all database nodes.
Definition SoNode.h:103
Represents point on surface of picked object.
Stores detail information about vertex-based shapes made of points.
Represents a vertex of a generated primitive.
Intersects objects with a ray cast into scene.
Abstract base class for all shape nodes.
Definition SoShape.h:101
void computeObjectSpaceRay(SoRayPickAction *action, const SbMatrix &matrix)
virtual void callback(SoCallbackAction *action)
Implements primitive generation for all shapes.
void endSolidShape(SoGLRenderAction *action)
static void setPostVertexArrayRenderingCallback(VertexArrayRenderingCB *cb)
register global post callback for vertex array rendering (MeVis ONLY)
static void setPreVertexArrayRenderingCallback(VertexArrayRenderingCB *cb)
register global pre callback for vertex array rendering (MeVis ONLY)
void computeObjectSpaceRay(SoRayPickAction *action)
Computes a picking ray in the object space of the shape instance.
void beginShape(SoAction *action, TriangleShape shapeType, SoFaceDetail *faceDetail=NULL)
These methods can be used by subclasses to generate triangles more easily when those triangles are pa...
static void initClass()
void beginSolidShape(SoGLRenderAction *action)
These can be used by solid shapes to indicate so during rendering.
virtual void GLRender(SoGLRenderAction *action)
Implements rendering by rendering each primitive generated by subclass.
virtual bool affectsState() const
Overrides default method on SoNode.
virtual bool shouldGLRender(SoGLRenderAction *action)
Returns TRUE if the shape should be rendered.
virtual SoDetail * createPointDetail(SoRayPickAction *action, const SoPrimitiveVertex *v, SoPickedPoint *pp)
void endShape()
virtual SoDetail * createLineSegmentDetail(SoRayPickAction *action, const SoPrimitiveVertex *v1, const SoPrimitiveVertex *v2, SoPickedPoint *pp)
static VertexArrayRenderingCB * _preVertexArrayRenderingCB
Definition SoShape.h:365
virtual SoDetail * createTriangleDetail(SoRayPickAction *action, const SoPrimitiveVertex *v1, const SoPrimitiveVertex *v2, const SoPrimitiveVertex *v3, SoPickedPoint *pp)
These methods are called during picking to create details representing extra info about a pick inters...
virtual void generatePrimitives(SoAction *action)=0
This method MUST be defined by each subclass to generate primitives (triangles, line segments,...
virtual void getBoundingBox(SoGetBoundingBoxAction *action)
Implements bounding box method using virtual computeBBox() method.
TriangleShape
This type is used by the triangle shape generation methods (beginShape, etc.)
Definition SoShape.h:114
@ TRIANGLE_FAN
Definition SoShape.h:116
@ TRIANGLES
Definition SoShape.h:117
@ TRIANGLE_STRIP
Definition SoShape.h:115
SoShape()
Constructor.
virtual ~SoShape()
void GLRenderBoundingBox(SoGLRenderAction *action)
Applies GLRender action to the bounding box surrounding the shape.
void invokeLineSegmentCallbacks(SoAction *action, const SoPrimitiveVertex *v1, const SoPrimitiveVertex *v2)
void shapeVertex(const SoPrimitiveVertex *v)
virtual void computeBBox(SoAction *action, SbBox3f &box, SbVec3f &center)=0
Computes bounding box for subclass using information in the given action (which may not necessarily b...
static VertexArrayRenderingCB * _postVertexArrayRenderingCB
Definition SoShape.h:366
void invokePointCallbacks(SoAction *action, const SoPrimitiveVertex *v)
bool shouldRayPick(SoRayPickAction *action)
Returns TRUE if the shape may be picked.
static void getScreenSize(SoState *state, const SbBox3f &boundingBox, SbVec2s &rectSize)
This can be used by subclasses when the complexity type is SCREEN_SPACE to determine how many window ...
void VertexArrayRenderingCB(SoNode *shape, SoGLRenderAction *, bool useVbo, uint32_t numVertices)
callback used for pre/post vertex array rendering on SoVertexShapes (MeVis ONLY)
Definition SoShape.h:157
void invokeTriangleCallbacks(SoAction *action, const SoPrimitiveVertex *v1, const SoPrimitiveVertex *v2, const SoPrimitiveVertex *v3)
These methods invoke whatever callbacks are registered with the primitive generation procedures.
virtual void rayPick(SoRayPickAction *action)
Implements picking along a ray by intersecting the ray with each primitive generated by subclass.
An SoState collects and holds state while traversing a scene graph.
Definition SoState.h:82
SoVBO is used to manage OpenGL vertex buffer objects.
Definition SoVBO.h:52
Helper struct used by primitive types like cube, sphere, ...
Definition SoShape.h:165
void drawArrays(SoShape *shape, SoGLRenderAction *action, GLenum primitiveType)
void enableVertexAttributes(SoState *state)
void disableVertexAttributes(SoState *state)