Debian Codegraph @

lib/database/src/so/nodes/SoMaterial.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.2 $
44 |
45 | Classes:
46 | SoMaterial
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/actions/SoCallbackAction.h>
55 #include <Inventor/actions/SoGLRenderAction.h>
56 #include <Inventor/elements/SoGLLazyElement.h>
57 #include <Inventor/elements/SoOverrideElement.h>
58 #include <Inventor/nodes/SoMaterial.h>
59
60 SO_NODE_SOURCE(SoMaterial);
61
62 ////////////////////////////////////////////////////////////////////////
63 //
64 // Description:
65 // Constructor
66 //
67 // Use: public
68
69 SoMaterial::SoMaterial()
70 //
71 ////////////////////////////////////////////////////////////////////////
72 {
73 SO_NODE_CONSTRUCTOR(SoMaterial);
74
75 SO_NODE_ADD_FIELD(ambientColor, (SoLazyElement::getDefaultAmbient()));
76 SO_NODE_ADD_FIELD(diffuseColor, (SoLazyElement::getDefaultDiffuse()));
77 SO_NODE_ADD_FIELD(specularColor,(SoLazyElement::getDefaultSpecular()));
78 SO_NODE_ADD_FIELD(emissiveColor,(SoLazyElement::getDefaultEmissive()));
79 SO_NODE_ADD_FIELD(shininess, (SoLazyElement::getDefaultShininess()));
80 SO_NODE_ADD_FIELD(transparency, (SoLazyElement::getDefaultTransparency()));
81 isBuiltIn = TRUE;
82 colorPacker = new SoColorPacker;
83 }
84
85 ////////////////////////////////////////////////////////////////////////
86 //
87 // Description:
88 // This initializes the SoMaterial class.
89 //
90 // Use: internal
91
92 void
93 SoMaterial::initClass()
94 //
95 ////////////////////////////////////////////////////////////////////////
96 {
97 SO__NODE_INIT_CLASS(SoMaterial, "Material", SoNode);
98
99 // Enable elements:
100 SO_ENABLE(SoCallbackAction, SoLazyElement);
101 SO_ENABLE(SoGLRenderAction, SoGLLazyElement);
102 }
103 ////////////////////////////////////////////////////////////////////////
104 //
105 // Description:
106 // Destructor (necessary since inline destructor is too complex)
107 //
108 // Use: private
109
110 SoMaterial::~SoMaterial()
111 //
112 ////////////////////////////////////////////////////////////////////////
113 {
114 delete colorPacker;
115 }
116
117 ////////////////////////////////////////////////////////////////////////
118 //
119 // Description:
120 // Performs accumulation of state for actions.
121 //
122 // Use: extender
123
124 void
125 SoMaterial::doAction(SoAction *action)
126 //
127 ////////////////////////////////////////////////////////////////////////
128 {
129 SoState *state = action->getState();
130 register uint32_t bitmask = 0;
131
132 // Set all non-ignored components
133
134 if (! ambientColor.isIgnored() && ambientColor.getNum() > 0
135 && ! SoOverrideElement::getAmbientColorOverride(state)) {
136 if (isOverride()) {
137 SoOverrideElement::setAmbientColorOverride(state, this, TRUE);
138 }
139 bitmask |= SoLazyElement::AMBIENT_MASK;
140 }
141
142 if (! diffuseColor.isIgnored() && diffuseColor.getNum() > 0
143 && ! SoOverrideElement::getDiffuseColorOverride(state)) {
144 if (isOverride()) {
145 SoOverrideElement::setDiffuseColorOverride(state, this, TRUE);
146 // Diffuse color and transparency share override state
147 if (! transparency.isIgnored() && transparency.getNum() > 0)
148 bitmask |= SoLazyElement::TRANSPARENCY_MASK;
149 }
150 bitmask |= SoLazyElement::DIFFUSE_MASK;
151 }
152
153 if (! transparency.isIgnored() && transparency.getNum() > 0
154 && ! SoOverrideElement::getTransparencyOverride(state)) {
155 if (isOverride()) {
156 SoOverrideElement::setTransparencyOverride(state, this, TRUE);
157 // Diffuse color and transparency share override state
158 if (! diffuseColor.isIgnored() && diffuseColor.getNum() > 0)
159 bitmask |= SoLazyElement::DIFFUSE_MASK;
160 }
161 bitmask |= SoLazyElement::TRANSPARENCY_MASK;
162 }
163 if (! specularColor.isIgnored() && specularColor.getNum() > 0
164 && ! SoOverrideElement::getSpecularColorOverride(state)) {
165 if (isOverride()) {
166 SoOverrideElement::setSpecularColorOverride(state, this, TRUE);
167 }
168 bitmask |= SoLazyElement::SPECULAR_MASK;
169 }
170
171 if (! emissiveColor.isIgnored() && emissiveColor.getNum() > 0
172 && ! SoOverrideElement::getEmissiveColorOverride(state)) {
173 if (isOverride()) {
174 SoOverrideElement::setEmissiveColorOverride(state, this, TRUE);
175 }
176 bitmask |= SoLazyElement::EMISSIVE_MASK;
177 }
178
179 if (! shininess.isIgnored() && shininess.getNum() > 0
180 && ! SoOverrideElement::getShininessOverride(state)) {
181 if (isOverride()) {
182 SoOverrideElement::setShininessOverride(state, this, TRUE);
183 }
184 bitmask |= SoLazyElement::SHININESS_MASK;
185 }
186 SoLazyElement::setMaterials(state, this, bitmask, colorPacker,
187 diffuseColor, transparency, ambientColor,
188 emissiveColor, specularColor, shininess);
189
190 }
191
192 ////////////////////////////////////////////////////////////////////////
193 //
194 // Description:
195 // Method for callback action
196 //
197 // Use: extender
198
199 void
200 SoMaterial::callback(SoCallbackAction *action)
201 //
202 ////////////////////////////////////////////////////////////////////////
203 {
204 SoMaterial::doAction(action);
205 }
206
207 ////////////////////////////////////////////////////////////////////////
208 //
209 // Description:
210 // Method for GL rendering
211 //
212 // Use: extender
213
214 void
215 SoMaterial::GLRender(SoGLRenderAction *action)
216 //
217 ////////////////////////////////////////////////////////////////////////
218 {
219 SoMaterial::doAction(action);
220
221 // If there's only one color, we might as well send it now. This
222 // prevents cache dependencies in some cases that were
223 // specifically optimized for Inventor 2.0.
224 if (diffuseColor.getNum() == 1 && !diffuseColor.isIgnored())
225 SoGLLazyElement::sendAllMaterial(action->getState());
226 }