Debian Codegraph @

lib/database/src/so/nodes/SoVertexShape.c++

raw symbols SCIP
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 * Copyright (C) 1990,91 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | $Revision: 1.1.1.1 $
44 |
45 | Classes:
46 | SoVertexShape
47 |
48 | Author(s) : Paul S. Strauss
49 |
50 ______________ S I L I C O N G R A P H I C S I N C . ____________
51 _______________________________________________________________________
52 */
53
54 #include <Inventor/caches/SoNormalCache.h>
55 #include <Inventor/elements/SoCoordinateElement.h>
56 #include <Inventor/elements/SoCreaseAngleElement.h>
57 #include <Inventor/elements/SoShapeHintsElement.h>
58 #include <Inventor/nodes/SoVertexShape.h>
59 #include <Inventor/elements/SoDrawStyleElement.h>
60 #include <Inventor/elements/SoComplexityTypeElement.h>
61 #include <Inventor/actions/SoGLRenderAction.h>
62
63 SO_NODE_ABSTRACT_SOURCE(SoVertexShape);
64
65 ////////////////////////////////////////////////////////////////////////
66 //
67 // Description:
68 // Constructor
69 //
70 // Use: protected
71
72 SoVertexShape::SoVertexShape()
73 //
74 ////////////////////////////////////////////////////////////////////////
75 {
76 SO_NODE_CONSTRUCTOR(SoVertexShape);
77 SO_NODE_ADD_FIELD(vertexProperty, (NULL));
78
79 normalCache = NULL;
80 }
81
82 ////////////////////////////////////////////////////////////////////////
83 //
84 // Description:
85 // Destructor
86 //
87 // Use: private
88
89 SoVertexShape::~SoVertexShape()
90 //
91 ////////////////////////////////////////////////////////////////////////
92 {
93 if (normalCache != NULL)
94 delete normalCache;
95 }
96
97 ////////////////////////////////////////////////////////////////////////
98 //
99 // Description:
100 // Subclasses may define this method to generate normals to use
101 // when the normal binding is DEFAULT and there aren't enough
102 // normals in the state. This should use the given SoNormalBundle
103 // to generate the normals. Returns TRUE if normals were generated.
104 //
105 // The default method returns TRUE.
106 //
107 // Use: extender, virtual
108
109 SbBool
110 SoVertexShape::generateDefaultNormals(SoState *, SoNormalBundle *)
111 //
112 ////////////////////////////////////////////////////////////////////////
113 {
114 return FALSE;
115 }
116
117 ////////////////////////////////////////////////////////////////////////
118 //
119 // Description:
120 // Sets up a cache to hold normals. This assumes the cache depends
121 // on only the current coordinates, shape hints, and crease angle.
122 //
123 // Use: protected
124
125 void
126 SoVertexShape::setNormalCache(SoState *state,
127 int numNormals, const SbVec3f *normals)
128 //
129 ////////////////////////////////////////////////////////////////////////
130 {
131 if (normalCache != NULL)
132 normalCache->unref();
133
134 normalCache = new SoNormalCache(state);
135 normalCache->ref();
136
137 normalCache->set(numNormals, normals);
138
139 // Set up the dependencies
140 #define ADD_DEPENDENCY(elt) \
141 normalCache->addElement(state->getConstElement(elt::getClassStackIndex()))
142
143 ADD_DEPENDENCY(SoCoordinateElement);
144 ADD_DEPENDENCY(SoCreaseAngleElement);
145 ADD_DEPENDENCY(SoShapeHintsElement);
146
147 #undef ADD_DEPENDENCY
148 }
149
150 ////////////////////////////////////////////////////////////////////////
151 //
152 // Description:
153 // Passes on notification after invalidating any caches.
154 //
155 // Use: internal
156
157 void
158 SoVertexShape::notify(SoNotList *list)
159 //
160 ////////////////////////////////////////////////////////////////////////
161 {
162 // Destroy cache, if present
163 if (normalCache != NULL) {
164 normalCache->unref();
165 normalCache = NULL;
166 }
167 vpCache.invalidate();
168
169 // Then do the usual stuff
170 SoShape::notify(list);
171 }
172
173 ////////////////////////////////////////////////////////////////////////
174 //
175 // Description:
176 // Returns TRUE if the shape should be rendered now. Does more then
177 // the method in SoShape, because of possible transparency in vertex
178 // property node.
179 //
180 // Use: protected
181 //
182 //////////////////////////////////////////////////////////////////////////
183 SbBool
184 SoVertexShape::shouldGLRender(SoGLRenderAction *action)
185 //
186 ////////////////////////////////////////////////////////////////////////
187 {
188
189 // Check if the shape is invisible
190 if (SoDrawStyleElement::get(action->getState()) ==
191 SoDrawStyleElement::INVISIBLE)
192 return FALSE;
193
194 // If the shape is transparent and transparent objects are being
195 // delayed, don't render now
196 // if there is transparency in the vertex property node, the object is
197 // transparent. If there are no colors in the vertexProperty node,
198 // we have to check the state.
199 if (!vpCache.colorIsInVtxProp()){
200 if (action->handleTransparency())
201 return FALSE;
202 }
203 else if (vpCache.transpIsInVtxProp()){
204 if (action->handleTransparency(TRUE))
205 return FALSE;
206 }
207 else
208 SoLazyElement::setBlending(action->getState(), FALSE);
209
210 // If the current complexity is BOUNDING_BOX, just render the
211 // cuboid surrounding the shape and tell the shape to stop
212 if (SoComplexityTypeElement::get(action->getState()) ==
213 SoComplexityTypeElement::BOUNDING_BOX) {
214 GLRenderBoundingBox(action);
215 return FALSE;
216 }
217
218 // Otherwise, go ahead and render the object
219 return TRUE;
220 }