| 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 2.0 $ |
| 44 |
| |
| 45 |
| Classes: |
| 46 |
| SoLazyElement, SoColorPacker |
| 47 |
| |
| 48 |
| Author(s) : Alan Norton, Gavin Bell |
| 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/elements/SoLazyElement.h> |
| 55 |
#include <Inventor/errors/SoDebugError.h> |
| 56 |
#include <Inventor/elements/SoSubElement.h> |
| 57 |
#include <Inventor/elements/SoShapeStyleElement.h> |
| 58 |
#include <Inventor/nodes/SoPackedColor.h> |
| 59 |
#include <Inventor/actions/SoGLRenderAction.h> |
| 60 |
#include <Inventor/fields/SoMFFloat.h> |
| 61 |
#include <Inventor/fields/SoMFColor.h> |
| 62 |
|
| 63 |
SO_ELEMENT_SOURCE(SoLazyElement); |
| 64 |
static SbColor unpacker(0, 0, 0); |
| 65 |
|
| 66 |
SbColor *SoLazyElement::defaultDiffuseColor = NULL; |
| 67 |
float *SoLazyElement::defaultTransparency = NULL; |
| 68 |
int32_t *SoLazyElement::defaultColorIndices = NULL; |
| 69 |
uint32_t *SoLazyElement::defaultPackedColor = NULL; |
| 70 |
//////////////////////////////////////////////////////////////////////// |
| 71 |
// |
| 72 |
// Description: |
| 73 |
// Destructor. |
| 74 |
// |
| 75 |
// Use: private |
| 76 |
//////////////////////////////////////////////////////////////////////// |
| 77 |
|
| 78 |
SoLazyElement::~SoLazyElement() |
| 79 |
|
| 80 |
{ |
| 81 |
} |
| 82 |
|
| 83 |
//////////////////////////////////////////////////////////////////////// |
| 84 |
// |
| 85 |
// Description: |
| 86 |
// Initializes element. |
| 87 |
// |
| 88 |
// Use: public |
| 89 |
//////////////////////////////////////////////////////////////////////// |
| 90 |
void |
| 91 |
SoLazyElement::init(SoState *) |
| 92 |
|
| 93 |
{ |
| 94 |
// Set to GL defaults: |
| 95 |
ivState.ambientColor = getDefaultAmbient(); |
| 96 |
ivState.emissiveColor = getDefaultEmissive(); |
| 97 |
ivState.specularColor = getDefaultSpecular(); |
| 98 |
ivState.shininess = getDefaultShininess(); |
| 99 |
ivState.colorMaterial = FALSE; |
| 100 |
ivState.blending = FALSE; |
| 101 |
ivState.lightModel = PHONG; |
| 102 |
|
| 103 |
// Initialize default color storage if not already done |
| 104 |
if (defaultDiffuseColor == NULL) { |
| 105 |
defaultDiffuseColor = new SbColor; |
| 106 |
*defaultDiffuseColor = getDefaultDiffuse(); |
| 107 |
defaultTransparency = new float; |
| 108 |
*defaultTransparency = getDefaultTransparency(); |
| 109 |
defaultColorIndices = new int32_t; |
| 110 |
*defaultColorIndices = getDefaultColorIndex(); |
| 111 |
defaultPackedColor = new uint32_t; |
| 112 |
*defaultPackedColor = getDefaultPacked(); |
| 113 |
} |
| 114 |
|
| 115 |
//following value will be matched with the default color, must |
| 116 |
//differ from 1 (invalid) and any legitimate nodeid. |
| 117 |
ivState.diffuseNodeId = 0; |
| 118 |
ivState.transpNodeId = 0; |
| 119 |
//zero corresponds to transparency off (default). |
| 120 |
ivState.stippleNum = 0; |
| 121 |
ivState.diffuseColors = defaultDiffuseColor; |
| 122 |
ivState.transparencies = defaultTransparency; |
| 123 |
ivState.colorIndices = defaultColorIndices; |
| 124 |
ivState.packedColors = defaultPackedColor; |
| 125 |
|
| 126 |
ivState.numDiffuseColors = 1; |
| 127 |
ivState.numTransparencies = 1; |
| 128 |
ivState.packed = FALSE; |
| 129 |
ivState.packedTransparent = FALSE; |
| 130 |
ivState.transpType = SoGLRenderAction::SCREEN_DOOR; |
| 131 |
ivState.cacheLevelSetBits = 0; |
| 132 |
ivState.cacheLevelSendBits = 0; |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
//////////////////////////////////////////////////////////////////////// |
| 137 |
// |
| 138 |
// Description: |
| 139 |
// get the indexed diffuse color in the element |
| 140 |
// |
| 141 |
// Use: public, static |
| 142 |
//////////////////////////////////////////////////////////////////////// |
| 143 |
const SbColor & |
| 144 |
SoLazyElement::getDiffuse(SoState* state, int index) |
| 145 |
{ |
| 146 |
SoLazyElement* curElt = getInstance(state); |
| 147 |
if(state->isCacheOpen()) curElt->registerGetDependence(state, DIFFUSE_MASK); |
| 148 |
#ifdef DEBUG |
| 149 |
if (index > curElt->ivState.numDiffuseColors || index < 0){ |
| 150 |
SoDebugError::post("SoLazyElement::getDiffuse", |
| 151 |
"invalid index"); |
| 152 |
return(*defaultDiffuseColor); |
| 153 |
} |
| 154 |
#endif |
| 155 |
if (!curElt->ivState.packed) return (curElt->ivState.diffuseColors[index]); |
| 156 |
unpacker = SbColor( |
| 157 |
((curElt->ivState.packedColors[index] & 0xff000000) >> 24) * 1.0/255, |
| 158 |
((curElt->ivState.packedColors[index] & 0xff0000) >> 16) * 1.0/255, |
| 159 |
((curElt->ivState.packedColors[index] & 0xff00)>> 8) * 1.0/255); |
| 160 |
return unpacker; |
| 161 |
|
| 162 |
} |
| 163 |
//////////////////////////////////////////////////////////////////////// |
| 164 |
// |
| 165 |
// Description: |
| 166 |
// get the indexed transparency in the element |
| 167 |
// |
| 168 |
// Use: public, static |
| 169 |
//////////////////////////////////////////////////////////////////////// |
| 170 |
float |
| 171 |
SoLazyElement::getTransparency(SoState* state, int index) |
| 172 |
{ |
| 173 |
SoLazyElement* curElt = getInstance(state); |
| 174 |
if(state->isCacheOpen()) curElt->registerGetDependence(state, DIFFUSE_MASK); |
| 175 |
#ifdef DEBUG |
| 176 |
if (index > curElt->ivState.numTransparencies || index < 0){ |
| 177 |
SoDebugError::post("SoLazyElement::getTransparency", |
| 178 |
"invalid index"); |
| 179 |
return(*curElt->defaultTransparency); |
| 180 |
} |
| 181 |
#endif |
| 182 |
if (!curElt->ivState.packed) return (curElt->ivState.transparencies[index]); |
| 183 |
return( 1.0 - ((curElt->ivState.packedColors[index] & 0xff) * 1.0/255)); |
| 184 |
|
| 185 |
} |
| 186 |
//////////////////////////////////////////////////////////////////////// |
| 187 |
// |
| 188 |
// Description: |
| 189 |
// get the color index from the element |
| 190 |
// |
| 191 |
// Use: public, static |
| 192 |
//////////////////////////////////////////////////////////////////////// |
| 193 |
int32_t |
| 194 |
SoLazyElement::getColorIndex(SoState* state, int index) |
| 195 |
{ |
| 196 |
SoLazyElement* curElt = getInstance(state); |
| 197 |
if(state->isCacheOpen()) curElt->registerGetDependence(state, DIFFUSE_MASK); |
| 198 |
#ifdef DEBUG |
| 199 |
if (index > curElt->ivState.numDiffuseColors || index < 0){ |
| 200 |
SoDebugError::post("SoLazyElement::getColorIndex", |
| 201 |
"invalid index"); |
| 202 |
return(curElt->getDefaultColorIndex()); |
| 203 |
} |
| 204 |
#endif |
| 205 |
return (curElt->ivState.colorIndices[index]); |
| 206 |
|
| 207 |
} |
| 208 |
//////////////////////////////////////////////////////////////////////// |
| 209 |
// |
| 210 |
// Description: |
| 211 |
// get the packed color from the element |
| 212 |
// |
| 213 |
// Use: public, static |
| 214 |
//////////////////////////////////////////////////////////////////////// |
| 215 |
const uint32_t* |
| 216 |
SoLazyElement::getPackedColors(SoState* state) |
| 217 |
{ |
| 218 |
SoLazyElement* curElt = getInstance(state); |
| 219 |
if(state->isCacheOpen()) curElt->registerGetDependence(state, DIFFUSE_MASK); |
| 220 |
return curElt->ivState.packedColors; |
| 221 |
} |
| 222 |
//////////////////////////////////////////////////////////////////////// |
| 223 |
// |
| 224 |
// Description: |
| 225 |
// get the color index from the element |
| 226 |
// |
| 227 |
// Use: public, static |
| 228 |
//////////////////////////////////////////////////////////////////////// |
| 229 |
const int32_t * |
| 230 |
SoLazyElement::getColorIndices(SoState* state) |
| 231 |
{ |
| 232 |
SoLazyElement* curElt = getInstance(state); |
| 233 |
if(state->isCacheOpen()) curElt->registerGetDependence(state, DIFFUSE_MASK); |
| 234 |
return curElt->ivState.colorIndices; |
| 235 |
} |
| 236 |
//////////////////////////////////////////////////////////////////////// |
| 237 |
// |
| 238 |
// Description: |
| 239 |
// get the ambient color from the element |
| 240 |
// |
| 241 |
// Use: public, static |
| 242 |
//////////////////////////////////////////////////////////////////////// |
| 243 |
const SbColor& |
| 244 |
SoLazyElement::getAmbient(SoState* state) |
| 245 |
{ |
| 246 |
SoLazyElement* curElt = getInstance(state); |
| 247 |
if(state->isCacheOpen()) curElt->registerGetDependence(state, AMBIENT_MASK); |
| 248 |
return curElt->ivState.ambientColor; |
| 249 |
} |
| 250 |
//////////////////////////////////////////////////////////////////////// |
| 251 |
// |
| 252 |
// Description: |
| 253 |
// get the emissive color from the element |
| 254 |
// |
| 255 |
// Use: public, static |
| 256 |
//////////////////////////////////////////////////////////////////////// |
| 257 |
const SbColor& |
| 258 |
SoLazyElement::getEmissive(SoState* state) |
| 259 |
{ |
| 260 |
SoLazyElement* curElt = getInstance(state); |
| 261 |
if(state->isCacheOpen()) curElt->registerGetDependence(state, EMISSIVE_MASK); |
| 262 |
return curElt->ivState.emissiveColor; |
| 263 |
} |
| 264 |
//////////////////////////////////////////////////////////////////////// |
| 265 |
// |
| 266 |
// Description: |
| 267 |
// get the specular color from the element |
| 268 |
// |
| 269 |
// Use: public, static |
| 270 |
//////////////////////////////////////////////////////////////////////// |
| 271 |
const SbColor& |
| 272 |
SoLazyElement::getSpecular(SoState* state) |
| 273 |
{ |
| 274 |
SoLazyElement* curElt = getInstance(state); |
| 275 |
if(state->isCacheOpen()) curElt->registerGetDependence(state, SPECULAR_MASK); |
| 276 |
return curElt->ivState.specularColor; |
| 277 |
} |
| 278 |
//////////////////////////////////////////////////////////////////////// |
| 279 |
// |
| 280 |
// Description: |
| 281 |
// get the shininess from the element |
| 282 |
// |
| 283 |
// Use: public, static |
| 284 |
//////////////////////////////////////////////////////////////////////// |
| 285 |
float |
| 286 |
SoLazyElement::getShininess(SoState* state) |
| 287 |
{ |
| 288 |
SoLazyElement* curElt = getInstance(state); |
| 289 |
if(state->isCacheOpen()) |
| 290 |
curElt->registerGetDependence(state, SHININESS_MASK); |
| 291 |
return curElt->ivState.shininess; |
| 292 |
} |
| 293 |
//////////////////////////////////////////////////////////////////////// |
| 294 |
// |
| 295 |
// Description: |
| 296 |
// get the color material state from the element |
| 297 |
// |
| 298 |
// Use: public, static |
| 299 |
//////////////////////////////////////////////////////////////////////// |
| 300 |
SbBool |
| 301 |
SoLazyElement::getColorMaterial(SoState* state) |
| 302 |
{ |
| 303 |
SoLazyElement* curElt = getInstance(state); |
| 304 |
if(state->isCacheOpen()) |
| 305 |
curElt->registerGetDependence(state, COLOR_MATERIAL_MASK); |
| 306 |
return curElt->ivState.colorMaterial; |
| 307 |
} |
| 308 |
//////////////////////////////////////////////////////////////////////// |
| 309 |
// |
| 310 |
// Description: |
| 311 |
// get the blending state from the element |
| 312 |
// |
| 313 |
// Use: public, static |
| 314 |
//////////////////////////////////////////////////////////////////////// |
| 315 |
SbBool |
| 316 |
SoLazyElement::getBlending(SoState* state) |
| 317 |
{ |
| 318 |
SoLazyElement* curElt = getInstance(state); |
| 319 |
if(state->isCacheOpen()) curElt->registerGetDependence(state, BLENDING_MASK); |
| 320 |
return curElt->ivState.blending; |
| 321 |
} |
| 322 |
//////////////////////////////////////////////////////////////////////// |
| 323 |
// |
| 324 |
// Description: |
| 325 |
// get the light model from the element |
| 326 |
// |
| 327 |
// Use: public, static |
| 328 |
//////////////////////////////////////////////////////////////////////// |
| 329 |
int32_t |
| 330 |
SoLazyElement::getLightModel(SoState* state) |
| 331 |
{ |
| 332 |
SoLazyElement* curElt = getInstance(state); |
| 333 |
if(state->isCacheOpen()) |
| 334 |
curElt->registerGetDependence(state, LIGHT_MODEL_MASK); |
| 335 |
return curElt->ivState.lightModel; |
| 336 |
} |
| 337 |
|
| 338 |
/////////////////////////////////////////////////////////////////////// |
| 339 |
// |
| 340 |
// Description: static set() method for diffuse color |
| 341 |
// |
| 342 |
// use: public, SoEXTENDER, static |
| 343 |
// |
| 344 |
/////////////////////////////////////////////////////////////////////// |
| 345 |
void |
| 346 |
SoLazyElement::setDiffuse(SoState *state, SoNode *node, int32_t numColors, |
| 347 |
const SbColor *colors, SoColorPacker *cPacker) |
| 348 |
{ |
| 349 |
SoLazyElement *curElt = SoLazyElement::getInstance(state); |
| 350 |
//Because we are getting the transparency value from state, there |
| 351 |
//is a get-dependence |
| 352 |
if(state->isCacheOpen())curElt->registerGetDependence(state, DIFFUSE_MASK); |
| 353 |
if (curElt->ivState.diffuseNodeId != node->getNodeId() || |
| 354 |
(!cPacker->transpMatch(curElt->ivState.transpNodeId))){ |
| 355 |
getWInstance(state)->setDiffuseElt(node, numColors, colors, cPacker); |
| 356 |
} |
| 357 |
else if (state->isCacheOpen()){ |
| 358 |
curElt->registerRedundantSet(state, DIFFUSE_MASK); |
| 359 |
} |
| 360 |
} |
| 361 |
/////////////////////////////////////////////////////////////////////// |
| 362 |
// |
| 363 |
// Description: static set() method for transparency |
| 364 |
// |
| 365 |
// use: public, SoEXTENDER, static |
| 366 |
// |
| 367 |
/////////////////////////////////////////////////////////////////////// |
| 368 |
void |
| 369 |
SoLazyElement::setTransparency(SoState *state, SoNode *node, int32_t numTransp, |
| 370 |
const float *transp, SoColorPacker *cPacker) |
| 371 |
{ |
| 372 |
SoLazyElement *curElt = SoLazyElement::getInstance(state); |
| 373 |
//Because we are getting the diffuse value from state, there |
| 374 |
//is a get-dependence |
| 375 |
if(state->isCacheOpen())curElt->registerGetDependence(state, DIFFUSE_MASK); |
| 376 |
|
| 377 |
uint32_t testNodeId; |
| 378 |
if(numTransp == 1 && transp[0] == 0.0) testNodeId = 0; |
| 379 |
else testNodeId = node->getNodeId(); |
| 380 |
|
| 381 |
if ((curElt->ivState.transpNodeId != testNodeId) || |
| 382 |
(!cPacker->diffuseMatch(curElt->ivState.diffuseNodeId))) |
| 383 |
getWInstance(state)->setTranspElt(node, numTransp, transp, cPacker); |
| 384 |
else if (state->isCacheOpen()) |
| 385 |
curElt->registerRedundantSet(state, TRANSPARENCY_MASK|DIFFUSE_MASK); |
| 386 |
} |
| 387 |
/////////////////////////////////////////////////////////////////////// |
| 388 |
// |
| 389 |
// Description: static set() method for color indices |
| 390 |
// |
| 391 |
// use: public, SoEXTENDER, static |
| 392 |
// |
| 393 |
/////////////////////////////////////////////////////////////////////// |
| 394 |
void |
| 395 |
SoLazyElement::setColorIndices(SoState *state, SoNode *node, int32_t numIndices, |
| 396 |
const int32_t *indices) |
| 397 |
{ |
| 398 |
SoLazyElement *curElt = SoLazyElement::getInstance(state); |
| 399 |
if (curElt->ivState.diffuseNodeId != node->getNodeId()) |
| 400 |
getWInstance(state)->setColorIndexElt(node, numIndices, indices); |
| 401 |
else if (state->isCacheOpen()) |
| 402 |
curElt->registerRedundantSet(state, DIFFUSE_MASK); |
| 403 |
} |
| 404 |
/////////////////////////////////////////////////////////////////////// |
| 405 |
// |
| 406 |
// Description: static set() method for transparencyType |
| 407 |
// |
| 408 |
// use: public, SoINTERNAL, static |
| 409 |
// |
| 410 |
/////////////////////////////////////////////////////////////////////// |
| 411 |
void |
| 412 |
SoLazyElement::setTransparencyType(SoState *state, int32_t type) |
| 413 |
{ |
| 414 |
SoLazyElement *curElt = SoLazyElement::getInstance(state); |
| 415 |
if (curElt->ivState.transpType != type) |
| 416 |
curElt->setTranspTypeElt( type); |
| 417 |
} |
| 418 |
/////////////////////////////////////////////////////////////////////// |
| 419 |
// |
| 420 |
// Description: static set() method for packed colors |
| 421 |
// |
| 422 |
// use: public, SoEXTERNAL, static |
| 423 |
// |
| 424 |
/////////////////////////////////////////////////////////////////////// |
| 425 |
void |
| 426 |
SoLazyElement::setPacked(SoState *state, SoNode *node, |
| 427 |
int32_t numColors, const uint32_t *colors) |
| 428 |
{ |
| 429 |
SoLazyElement *curElt = SoLazyElement::getInstance(state); |
| 430 |
if (curElt->ivState.diffuseNodeId != (node->getNodeId()) || |
| 431 |
(!(curElt->ivState.packed)) || |
| 432 |
(curElt->ivState.packedColors != colors)){ |
| 433 |
getWInstance(state)->setPackedElt( node, numColors, colors); |
| 434 |
} |
| 435 |
else if (state->isCacheOpen()) |
| 436 |
curElt->registerRedundantSet(state, DIFFUSE_MASK|TRANSPARENCY_MASK); |
| 437 |
} |
| 438 |
/////////////////////////////////////////////////////////////////////// |
| 439 |
// |
| 440 |
// Description: static set() method for ambient color |
| 441 |
// |
| 442 |
// use: public, SoEXTERNAL, static |
| 443 |
// |
| 444 |
/////////////////////////////////////////////////////////////////////// |
| 445 |
void |
| 446 |
SoLazyElement::setAmbient(SoState *state, const SbColor* color) |
| 447 |
{ |
| 448 |
SoLazyElement *curElt = SoLazyElement::getInstance(state); |
| 449 |
if (*color != curElt->ivState.ambientColor){ |
| 450 |
getWInstance(state)->setAmbientElt(color); |
| 451 |
} |
| 452 |
else if (state->isCacheOpen()){ |
| 453 |
curElt->registerRedundantSet(state, AMBIENT_MASK); |
| 454 |
} |
| 455 |
} |
| 456 |
/////////////////////////////////////////////////////////////////////// |
| 457 |
// |
| 458 |
// Description: static set() method for emissive color |
| 459 |
// |
| 460 |
// use: public, SoEXTERNAL, static |
| 461 |
// |
| 462 |
/////////////////////////////////////////////////////////////////////// |
| 463 |
void |
| 464 |
SoLazyElement::setEmissive(SoState *state, const SbColor* color) |
| 465 |
{ |
| 466 |
SoLazyElement *curElt = SoLazyElement::getInstance(state); |
| 467 |
if (*color != curElt->ivState.emissiveColor) |
| 468 |
getWInstance(state)->setEmissiveElt(color); |
| 469 |
else if (state->isCacheOpen()) |
| 470 |
curElt->registerRedundantSet(state, EMISSIVE_MASK); |
| 471 |
} |
| 472 |
/////////////////////////////////////////////////////////////////////// |
| 473 |
// |
| 474 |
// Description: static set() method for specular color |
| 475 |
// |
| 476 |
// use: public, SoEXTERNAL, static |
| 477 |
// |
| 478 |
/////////////////////////////////////////////////////////////////////// |
| 479 |
void |
| 480 |
SoLazyElement::setSpecular(SoState *state, const SbColor* color) |
| 481 |
{ |
| 482 |
SoLazyElement *curElt = SoLazyElement::getInstance(state); |
| 483 |
if (*color != curElt->ivState.specularColor) |
| 484 |
getWInstance(state)->setSpecularElt(color); |
| 485 |
else if (state->isCacheOpen()) |
| 486 |
curElt->registerRedundantSet(state, SPECULAR_MASK); |
| 487 |
} |
| 488 |
/////////////////////////////////////////////////////////////////////// |
| 489 |
// |
| 490 |
// Description: static set() method for shininess |
| 491 |
// |
| 492 |
// use: public, SoEXTERNAL, static |
| 493 |
// |
| 494 |
/////////////////////////////////////////////////////////////////////// |
| 495 |
void |
| 496 |
SoLazyElement::setShininess(SoState *state, float value) |
| 497 |
{ |
| 498 |
SoLazyElement *curElt = SoLazyElement::getInstance(state); |
| 499 |
if (fabsf(value - curElt->ivState.shininess)> SO_LAZY_SHINY_THRESHOLD) |
| 500 |
getWInstance(state)->setShininessElt(value); |
| 501 |
else if (state->isCacheOpen()) |
| 502 |
curElt->registerRedundantSet(state, SHININESS_MASK); |
| 503 |
} |
| 504 |
/////////////////////////////////////////////////////////////////////// |
| 505 |
// |
| 506 |
// Description: static set() method for blending |
| 507 |
// |
| 508 |
// use: public, SoEXTERNAL, static |
| 509 |
// |
| 510 |
/////////////////////////////////////////////////////////////////////// |
| 511 |
void |
| 512 |
SoLazyElement::setBlending(SoState *state, SbBool value) |
| 513 |
{ |
| 514 |
SoLazyElement *curElt = SoLazyElement::getInstance(state); |
| 515 |
if (value != curElt->ivState.blending) |
| 516 |
getWInstance(state)->setBlendingElt( value); |
| 517 |
else if (state->isCacheOpen()) |
| 518 |
curElt->registerRedundantSet(state, BLENDING_MASK); |
| 519 |
} |
| 520 |
/////////////////////////////////////////////////////////////////////// |
| 521 |
// |
| 522 |
// Description: static set() method for light model |
| 523 |
// |
| 524 |
// use: public, SoEXTERNAL, static |
| 525 |
// |
| 526 |
/////////////////////////////////////////////////////////////////////// |
| 527 |
void |
| 528 |
SoLazyElement::setLightModel(SoState *state, const int32_t model) |
| 529 |
{ |
| 530 |
SoLazyElement *curElt = SoLazyElement::getInstance(state); |
| 531 |
if (model != curElt->ivState.lightModel) |
| 532 |
getWInstance(state)->setLightModelElt(state, model); |
| 533 |
else if (state->isCacheOpen()) |
| 534 |
curElt->registerRedundantSet(state, LIGHT_MODEL_MASK); |
| 535 |
} |
| 536 |
/////////////////////////////////////////////////////////////////////// |
| 537 |
// |
| 538 |
// Description: static set() method for color material |
| 539 |
// |
| 540 |
// use: public, SoEXTERNAL, static |
| 541 |
// |
| 542 |
/////////////////////////////////////////////////////////////////////// |
| 543 |
void |
| 544 |
SoLazyElement::setColorMaterial(SoState *state, SbBool value) |
| 545 |
{ |
| 546 |
SoLazyElement *curElt = SoLazyElement::getInstance(state); |
| 547 |
if (value != curElt->ivState.colorMaterial) |
| 548 |
getWInstance(state)->setColorMaterialElt(value); |
| 549 |
else if (state->isCacheOpen()) |
| 550 |
curElt->registerRedundantSet(state, COLOR_MATERIAL_MASK); |
| 551 |
} |
| 552 |
/////////////////////////////////////////////////////////////////////// |
| 553 |
// |
| 554 |
// Description: static set() method for all materials |
| 555 |
// |
| 556 |
// use: public, SoEXTERNAL, static |
| 557 |
// |
| 558 |
/////////////////////////////////////////////////////////////////////// |
| 559 |
void |
| 560 |
SoLazyElement::setMaterials(SoState *state, SoNode* node, |
| 561 |
uint32_t bitmask, SoColorPacker *cPacker, |
| 562 |
const SoMFColor& diffuse, const SoMFFloat& transp, const SoMFColor& ambient, |
| 563 |
const SoMFColor& emissive, const SoMFColor& specular, |
| 564 |
const SoMFFloat& shininess) |
| 565 |
{ |
| 566 |
uint32_t realSet = 0; |
| 567 |
SoLazyElement *curElt = SoLazyElement::getInstance(state); |
| 568 |
|
| 569 |
// If we are setting transparency and not diffuse, or vice-versa, |
| 570 |
// then there is a get-dependence: |
| 571 |
if(state->isCacheOpen()){ |
| 572 |
uint32_t tempMask = bitmask & (DIFFUSE_MASK | TRANSPARENCY_MASK); |
| 573 |
if (tempMask && tempMask != (DIFFUSE_MASK | TRANSPARENCY_MASK)) |
| 574 |
curElt->registerGetDependence(state, DIFFUSE_MASK); |
| 575 |
} |
| 576 |
// build a mask (realSet) indicating what really will be set in the state: |
| 577 |
if ((bitmask & EMISSIVE_MASK)&&(emissive[0] != curElt->ivState.emissiveColor)) |
| 578 |
realSet |= EMISSIVE_MASK; |
| 579 |
if ((bitmask & SPECULAR_MASK)&&(specular[0] != curElt->ivState.specularColor)) |
| 580 |
realSet |= SPECULAR_MASK; |
| 581 |
if ((bitmask & AMBIENT_MASK)&&(ambient[0] != curElt->ivState.ambientColor)) |
| 582 |
realSet |= AMBIENT_MASK; |
| 583 |
if ((bitmask & SHININESS_MASK) && |
| 584 |
fabsf(shininess[0] - curElt->ivState.shininess)> |
| 585 |
SO_LAZY_SHINY_THRESHOLD) realSet |= SHININESS_MASK; |
| 586 |
|
| 587 |
uint32_t nodeId = node->getNodeId(); |
| 588 |
if ((bitmask & DIFFUSE_MASK) && |
| 589 |
nodeId != curElt->ivState.diffuseNodeId) realSet |= DIFFUSE_MASK; |
| 590 |
|
| 591 |
//For transparency nodeid, opaque nodes are identified as nodeId = 0: |
| 592 |
if(transp.getNum() == 1 && transp[0] == 0.0) nodeId = 0; |
| 593 |
|
| 594 |
if (curElt->ivState.transpNodeId != nodeId && (bitmask & TRANSPARENCY_MASK)) |
| 595 |
realSet |= TRANSPARENCY_MASK; |
| 596 |
|
| 597 |
if (realSet){ |
| 598 |
curElt = getWInstance(state); |
| 599 |
curElt->setMaterialElt(node, realSet, cPacker, |
| 600 |
diffuse, transp, ambient, emissive, specular, shininess); |
| 601 |
} |
| 602 |
//Indicate redundant set for colors that matched the one in the state: |
| 603 |
if (state->isCacheOpen()){ |
| 604 |
uint32_t notRealSet = bitmask & (~realSet); |
| 605 |
if(notRealSet) curElt->registerRedundantSet(state, notRealSet); |
| 606 |
} |
| 607 |
|
| 608 |
} |
| 609 |
//////////////////////////////////////////////////////////////////////// |
| 610 |
// |
| 611 |
// Description: |
| 612 |
// set the Diffuse color in the element |
| 613 |
// virtual, to be overridden |
| 614 |
// |
| 615 |
// Use: protected |
| 616 |
//////////////////////////////////////////////////////////////////////// |
| 617 |
|
| 618 |
void |
| 619 |
SoLazyElement::setDiffuseElt(SoNode * node, int32_t numColors, |
| 620 |
const SbColor *colors, SoColorPacker*) |
| 621 |
{ |
| 622 |
|
| 623 |
ivState.diffuseNodeId = node->getNodeId(); |
| 624 |
ivState.diffuseColors = colors; |
| 625 |
ivState.numDiffuseColors = numColors; |
| 626 |
|
| 627 |
ivState.packed=FALSE; |
| 628 |
ivState.packedTransparent = FALSE; |
| 629 |
} |
| 630 |
//////////////////////////////////////////////////////////////////////// |
| 631 |
// |
| 632 |
// Description: |
| 633 |
// set the transparency in the element |
| 634 |
// virtual, to be overridden |
| 635 |
// |
| 636 |
// Use: protected |
| 637 |
//////////////////////////////////////////////////////////////////////// |
| 638 |
|
| 639 |
void |
| 640 |
SoLazyElement::setTranspElt(SoNode *node, int32_t numTrans, |
| 641 |
const float *transpar, SoColorPacker* ) |
| 642 |
{ |
| 643 |
|
| 644 |
ivState.numTransparencies = numTrans; |
| 645 |
ivState.transparencies = transpar; |
| 646 |
ivState.stippleNum = 0; |
| 647 |
if (transpar[0] > 0.0) { |
| 648 |
if (ivState.transpType == SoGLRenderAction::SCREEN_DOOR){ |
| 649 |
ivState.stippleNum = |
| 650 |
(int)(transpar[0]*getNumPatterns()); |
| 651 |
} |
| 652 |
} |
| 653 |
if (numTrans == 1 && transpar[0] == 0.0) ivState.transpNodeId = 0; |
| 654 |
else ivState.transpNodeId = node->getNodeId(); |
| 655 |
ivState.packed=FALSE; |
| 656 |
ivState.packedTransparent = FALSE; |
| 657 |
|
| 658 |
|
| 659 |
} |
| 660 |
//////////////////////////////////////////////////////////////////////// |
| 661 |
// |
| 662 |
// Description: |
| 663 |
// set the color indices in the element |
| 664 |
// virtual, to be overridden |
| 665 |
// |
| 666 |
// Use: protected |
| 667 |
//////////////////////////////////////////////////////////////////////// |
| 668 |
|
| 669 |
void |
| 670 |
SoLazyElement::setColorIndexElt( SoNode * node, int32_t numIndices, |
| 671 |
const int32_t *indices) |
| 672 |
{ |
| 673 |
|
| 674 |
ivState.diffuseNodeId = node->getNodeId(); |
| 675 |
ivState.numDiffuseColors = numIndices; |
| 676 |
ivState.colorIndices = indices; |
| 677 |
ivState.packed=FALSE; |
| 678 |
ivState.packedTransparent = FALSE; |
| 679 |
|
| 680 |
} |
| 681 |
//////////////////////////////////////////////////////////////////////// |
| 682 |
// |
| 683 |
// Description: |
| 684 |
// set the transparency type in the element |
| 685 |
// (not virtual) |
| 686 |
// |
| 687 |
// Use: protected |
| 688 |
//////////////////////////////////////////////////////////////////////// |
| 689 |
|
| 690 |
void |
| 691 |
SoLazyElement::setTranspTypeElt( int32_t type) |
| 692 |
|
| 693 |
{ |
| 694 |
ivState.transpType = type; |
| 695 |
} |
| 696 |
|
| 697 |
//////////////////////////////////////////////////////////////////////// |
| 698 |
// |
| 699 |
// Description: |
| 700 |
// set the packed diffuse color in the element |
| 701 |
// virtual, to be overridden |
| 702 |
// |
| 703 |
// Use: protected |
| 704 |
//////////////////////////////////////////////////////////////////////// |
| 705 |
|
| 706 |
void |
| 707 |
SoLazyElement::setPackedElt( SoNode *node, int32_t numColors, |
| 708 |
const uint32_t* colors) |
| 709 |
{ |
| 710 |
ivState.diffuseNodeId = node->getNodeId(); |
| 711 |
ivState.numDiffuseColors = numColors; |
| 712 |
ivState.numTransparencies = numColors; |
| 713 |
ivState.stippleNum = 0; |
| 714 |
if ((ivState.transpType == SoGLRenderAction::SCREEN_DOOR) && |
| 715 |
((colors[0]&0xff) != 0xff)){ |
| 716 |
ivState.stippleNum = (int)(getNumPatterns()* |
| 717 |
(1.-(colors[0] & 0xff)*(1./255.))); |
| 718 |
} |
| 719 |
ivState.packedColors = colors; |
| 720 |
ivState.packed = TRUE; |
| 721 |
ivState.packedTransparent = ((SoPackedColor*)node)->isTransparent(); |
| 722 |
} |
| 723 |
//////////////////////////////////////////////////////////////////////// |
| 724 |
// |
| 725 |
// Description: |
| 726 |
// set the Ambient color in the element |
| 727 |
// virtual, to be overridden |
| 728 |
// |
| 729 |
// Use: protected |
| 730 |
//////////////////////////////////////////////////////////////////////// |
| 731 |
|
| 732 |
void |
| 733 |
SoLazyElement::setAmbientElt(const SbColor* color ) |
| 734 |
|
| 735 |
{ |
| 736 |
ivState.ambientColor.setValue((float*)color); |
| 737 |
} |
| 738 |
|
| 739 |
//////////////////////////////////////////////////////////////////////// |
| 740 |
// |
| 741 |
// Description: |
| 742 |
// set the Emissive color in the element |
| 743 |
// virtual, to be overridden |
| 744 |
// |
| 745 |
// Use: protected |
| 746 |
//////////////////////////////////////////////////////////////////////// |
| 747 |
|
| 748 |
void |
| 749 |
SoLazyElement::setEmissiveElt(const SbColor* color ) |
| 750 |
|
| 751 |
{ |
| 752 |
ivState.emissiveColor.setValue((float*)color); |
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
//////////////////////////////////////////////////////////////////////// |
| 757 |
// |
| 758 |
// Description: |
| 759 |
// set the Specular color in the element |
| 760 |
// Virtual, to be overridden |
| 761 |
// |
| 762 |
// Use: protected |
| 763 |
//////////////////////////////////////////////////////////////////////// |
| 764 |
|
| 765 |
void |
| 766 |
SoLazyElement::setSpecularElt(const SbColor* color ) |
| 767 |
// |
| 768 |
{ |
| 769 |
ivState.specularColor.setValue((float*)color); |
| 770 |
} |
| 771 |
|
| 772 |
//////////////////////////////////////////////////////////////////////// |
| 773 |
// |
| 774 |
// Description: |
| 775 |
// set the Shininess in the element |
| 776 |
// virtual, to be overridden |
| 777 |
// |
| 778 |
// Use: protected |
| 779 |
//////////////////////////////////////////////////////////////////////// |
| 780 |
|
| 781 |
void |
| 782 |
SoLazyElement::setShininessElt(float value ) |
| 783 |
|
| 784 |
{ |
| 785 |
ivState.shininess = value; |
| 786 |
} |
| 787 |
//////////////////////////////////////////////////////////////////////// |
| 788 |
// |
| 789 |
// Description: |
| 790 |
// set the ColorMaterial in the element |
| 791 |
// virtual, to be overridden |
| 792 |
// |
| 793 |
// Use: protected |
| 794 |
//////////////////////////////////////////////////////////////////////// |
| 795 |
|
| 796 |
void |
| 797 |
SoLazyElement::setColorMaterialElt( SbBool value ) |
| 798 |
|
| 799 |
{ |
| 800 |
if (ivState.lightModel == BASE_COLOR) value = FALSE; |
| 801 |
ivState.colorMaterial = value; |
| 802 |
} |
| 803 |
//////////////////////////////////////////////////////////////////////// |
| 804 |
// |
| 805 |
// Description: |
| 806 |
// set the blending enablement in the element |
| 807 |
// virtual, to be overridden |
| 808 |
// |
| 809 |
// Use: protected |
| 810 |
//////////////////////////////////////////////////////////////////////// |
| 811 |
|
| 812 |
void |
| 813 |
SoLazyElement::setBlendingElt(SbBool value ) |
| 814 |
|
| 815 |
{ |
| 816 |
ivState.blending = value; |
| 817 |
} |
| 818 |
|
| 819 |
//////////////////////////////////////////////////////////////////////// |
| 820 |
// |
| 821 |
// Description: |
| 822 |
// set the light model in the element |
| 823 |
// virtual, to be overridden |
| 824 |
// |
| 825 |
// Use: protected |
| 826 |
//////////////////////////////////////////////////////////////////////// |
| 827 |
|
| 828 |
void |
| 829 |
SoLazyElement::setLightModelElt(SoState *state, int32_t model) |
| 830 |
|
| 831 |
{ |
| 832 |
ivState.lightModel = model; |
| 833 |
// also set the shapestyle version of this: |
| 834 |
SoShapeStyleElement::setLightModel(state, model); |
| 835 |
if (model == BASE_COLOR) setColorMaterialElt(FALSE); |
| 836 |
} |
| 837 |
//////////////////////////////////////////////////////////////////////// |
| 838 |
// |
| 839 |
// Description: |
| 840 |
// set all materials in the element |
| 841 |
// virtual, to be overridden |
| 842 |
// |
| 843 |
// Use: protected |
| 844 |
//////////////////////////////////////////////////////////////////////// |
| 845 |
|
| 846 |
void |
| 847 |
SoLazyElement::setMaterialElt(SoNode* node, uint32_t mask, SoColorPacker*, |
| 848 |
const SoMFColor& diffuse, const SoMFFloat& transp, |
| 849 |
const SoMFColor& ambient, const SoMFColor& emissive, |
| 850 |
const SoMFColor& specular, const SoMFFloat& shininess) |
| 851 |
{ |
| 852 |
if (mask & DIFFUSE_MASK){ |
| 853 |
ivState.diffuseNodeId = node->getNodeId(); |
| 854 |
ivState.diffuseColors = diffuse.getValues(0); |
| 855 |
ivState.numDiffuseColors = diffuse.getNum(); |
| 856 |
ivState.packed=FALSE; |
| 857 |
ivState.packedTransparent = FALSE; |
| 858 |
} |
| 859 |
if (mask&TRANSPARENCY_MASK){ |
| 860 |
ivState.numTransparencies = transp.getNum(); |
| 861 |
ivState.transparencies = transp.getValues(0); |
| 862 |
ivState.stippleNum = 0; |
| 863 |
if ((ivState.transparencies[0]> 0.0) && |
| 864 |
(ivState.transpType == SoGLRenderAction::SCREEN_DOOR)) { |
| 865 |
ivState.stippleNum = |
| 866 |
(int)(ivState.transparencies[0]*getNumPatterns()); |
| 867 |
} |
| 868 |
ivState.packed=FALSE; |
| 869 |
ivState.packedTransparent = FALSE; |
| 870 |
} |
| 871 |
if (mask&AMBIENT_MASK) |
| 872 |
ivState.ambientColor = ambient[0]; |
| 873 |
|
| 874 |
if (mask&EMISSIVE_MASK) |
| 875 |
ivState.emissiveColor = emissive[0]; |
| 876 |
|
| 877 |
if (mask&SPECULAR_MASK) |
| 878 |
ivState.specularColor = specular[0]; |
| 879 |
|
| 880 |
if (mask&SHININESS_MASK) |
| 881 |
ivState.shininess = shininess[0]; |
| 882 |
} |
| 883 |
//////////////////////////////////////////////////////////////////////// |
| 884 |
// |
| 885 |
// Description: |
| 886 |
// Pushes element, copies inventor state |
| 887 |
// |
| 888 |
// public, virtual |
| 889 |
//////////////////////////////////////////////////////////////////////// |
| 890 |
|
| 891 |
void |
| 892 |
SoLazyElement::push(SoState *) |
| 893 |
{ |
| 894 |
SoLazyElement *prevElt = (SoLazyElement*)getNextInStack(); |
| 895 |
|
| 896 |
ivState = prevElt->ivState; |
| 897 |
|
| 898 |
} |
| 899 |
|
| 900 |
|
| 901 |
//////////////////////////////////////////////////////////////////////// |
| 902 |
// |
| 903 |
// Description: |
| 904 |
// Prints element for debugging. |
| 905 |
// |
| 906 |
// Use: public |
| 907 |
// |
| 908 |
//////////////////////////////////////////////////////////////////////// |
| 909 |
|
| 910 |
#ifdef DEBUG |
| 911 |
void |
| 912 |
SoLazyElement::print(FILE *fp) const |
| 913 |
{ |
| 914 |
SoElement::print(fp); |
| 915 |
} |
| 916 |
#else /* DEBUG */ |
| 917 |
void |
| 918 |
SoLazyElement::print(FILE *) const |
| 919 |
{ |
| 920 |
} |
| 921 |
#endif /* DEBUG */ |
| 922 |
///////////////////////////////////////////////////////////////////////// |
| 923 |
// |
| 924 |
// Description: |
| 925 |
// matches is not used by this element: |
| 926 |
// |
| 927 |
///////////////////////////////////////////////////////////////////////// |
| 928 |
SbBool |
| 929 |
SoLazyElement::matches(const SoElement*) const |
| 930 |
{ |
| 931 |
#ifdef DEBUG |
| 932 |
SoDebugError::post("SoLazyElement::matches", |
| 933 |
"Should never be called\n"); |
| 934 |
#endif |
| 935 |
return TRUE; |
| 936 |
} |
| 937 |
///////////////////////////////////////////////////////////////////////// |
| 938 |
// |
| 939 |
// Description: |
| 940 |
// copyMatchInfo is not used by this element: |
| 941 |
// |
| 942 |
///////////////////////////////////////////////////////////////////////// |
| 943 |
SoElement* |
| 944 |
SoLazyElement::copyMatchInfo() const |
| 945 |
{ |
| 946 |
#ifdef DEBUG |
| 947 |
SoDebugError::post("SoLazyElement::copyMatchInfo", |
| 948 |
"Should never be called\n"); |
| 949 |
#endif |
| 950 |
return NULL; |
| 951 |
} |
| 952 |
///////////////////////////////////////////////////////////////////////////// |
| 953 |
// |
| 954 |
// Description: |
| 955 |
// |
| 956 |
// virtual method does no work (GL version does more) |
| 957 |
// |
| 958 |
//////////////////////////////////////////////////////////////////////////// |
| 959 |
void |
| 960 |
SoLazyElement::registerRedundantSet(SoState* , uint32_t) |
| 961 |
{ |
| 962 |
} |
| 963 |
///////////////////////////////////////////////////////////////////////////// |
| 964 |
// |
| 965 |
// Description: |
| 966 |
// |
| 967 |
// virtual method does no work (GL version does more) |
| 968 |
// |
| 969 |
//////////////////////////////////////////////////////////////////////////// |
| 970 |
void |
| 971 |
SoLazyElement::registerGetDependence(SoState* , uint32_t) |
| 972 |
{ |
| 973 |
} |
| 974 |
/////////////////////////////////////////////////////////////////////////// |
| 975 |
// |
| 976 |
// class: SoColorPacker |
| 977 |
// |
| 978 |
// Maintains a packed color array to store current colors. Intended to |
| 979 |
// be used by all property nodes that can issue setDiffuse or setTransparency |
| 980 |
///////////////////////////////////////////////////////////////////////////// |
| 981 |
//////////////////////////////////////////////////////////////////////////// |
| 982 |
// |
| 983 |
// Description: |
| 984 |
// constructor for SoColorPacker |
| 985 |
// |
| 986 |
// use: public |
| 987 |
// |
| 988 |
//////////////////////////////////////////////////////////////////////////// |
| 989 |
SoColorPacker:: |
| 990 |
SoColorPacker() |
| 991 |
{ |
| 992 |
packedColors = NULL; |
| 993 |
packedArraySize = 0; |
| 994 |
//Assign nodeids that can never occur in practice: |
| 995 |
diffuseNodeId = transpNodeId = 2; |
| 996 |
} |
| 997 |
|
| 998 |
///////////////////////////////////////////////////////////////////////////// |
| 999 |
// |
| 1000 |
// Description: |
| 1001 |
// destructor |
| 1002 |
// |
| 1003 |
// use: public |
| 1004 |
//////////////////////////////////////////////////////////////////////////// |
| 1005 |
SoColorPacker::~SoColorPacker() |
| 1006 |
{ |
| 1007 |
if(packedColors != NULL) delete [] packedColors; |
| 1008 |
} |
| 1009 |
|
| 1010 |
//////////////////////////////////////////////////////////////////////////// |
| 1011 |
// |
| 1012 |
// Description: |
| 1013 |
// |
| 1014 |
// reallocate packed color array for SoColorPacker |
| 1015 |
// |
| 1016 |
// use: public, SoINTERNAL |
| 1017 |
// |
| 1018 |
//////////////////////////////////////////////////////////////////////////// |
| 1019 |
void |
| 1020 |
SoColorPacker::reallocate(int32_t size) |
| 1021 |
{ |
| 1022 |
if (packedColors != NULL) delete [] packedColors; |
| 1023 |
packedColors = new uint32_t[size]; |
| 1024 |
packedArraySize = size; |
| 1025 |
} |