00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #ifndef _SO_LAZY_ELEMENT
00052 #define _SO_LAZY_ELEMENT
00053
00054 #include <Inventor/SbBasic.h>
00055 #include <Inventor/SbColor.h>
00056 #include <Inventor/elements/SoElement.h>
00057 #include <Inventor/elements/SoSubElement.h>
00058 #include <Inventor/elements/SoLightModelElement.h>
00059 #include <math.h>
00060 #include <Inventor/misc/SoColorPacker.h>
00061
00062 class SoMFFloat;
00063 class SoMFColor;
00064 class SoColorPacker;
00065 class SbThreadMutex;
00066
00070 #define SO_LAZY_SHINY_THRESHOLD 0.005
00071
00075 #define SO_LAZY_NUM_COMPONENTS 12
00076 class SoDEPRECATED SoLazyElement : public SoElement{
00106
00107 SO_ELEMENT_HEADER(SoLazyElement);
00108
00109 public:
00119 enum cases {
00121 LIGHT_MODEL_CASE = 0,
00123 COLOR_MATERIAL_CASE = 1,
00125 DIFFUSE_CASE = 2,
00127 AMBIENT_CASE = 3,
00129 EMISSIVE_CASE = 4,
00131 SPECULAR_CASE = 5,
00133 SHININESS_CASE = 6,
00135 BLENDING_CASE = 7,
00137 TRANSPARENCY_CASE = 8,
00139 PATTERN_CASE = 9,
00141 SMOOTHING_CASE = 10,
00143 LINE_WIDTH_CASE = 11
00144 };
00145
00147 enum masks {
00149 LIGHT_MODEL_MASK = 1 << LIGHT_MODEL_CASE,
00151 COLOR_MATERIAL_MASK = 1 << COLOR_MATERIAL_CASE,
00153 DIFFUSE_MASK = 1 << DIFFUSE_CASE,
00155 AMBIENT_MASK = 1 << AMBIENT_CASE,
00157 EMISSIVE_MASK = 1 << EMISSIVE_CASE,
00159 SPECULAR_MASK = 1 << SPECULAR_CASE,
00161 SHININESS_MASK = 1 << SHININESS_CASE,
00163 TRANSPARENCY_MASK = 1 << TRANSPARENCY_CASE,
00165 BLENDING_MASK = 1 << BLENDING_CASE,
00167 SMOOTHING_MASK = 1 << SMOOTHING_CASE,
00169 ALL_MASK = (1 << SO_LAZY_NUM_COMPONENTS)-1,
00171 PATTERN_MASK = 1 << PATTERN_CASE,
00173 LINE_WIDTH_MASK = 1 << LINE_WIDTH_CASE
00174 };
00175
00182 static void setDiffuse(SoState *state,
00183 SoNode *node,
00184 int32_t numColors,
00185 const SbColor *colors,
00186 SoColorPacker *cPacker);
00193 static void setTransparency(SoState *state,
00194 SoNode *node,
00195 int32_t numTransp,
00196 const float *transp,
00197 SoColorPacker *cPacker);
00204 static void setPacked(SoState *state,
00205 SoNode *node,
00206 SoColorPacker *cPacker,
00207 int32_t numColors,
00208 const uint32_t *colors);
00215 static void setColorIndices(SoState *state,
00216 SoNode *node,
00217 int32_t numIndices,
00218 const int32_t *indices);
00219
00220 #if 1 SoDEPRECATED
00226 static void setAmbient(SoState *state, SoNode* node, const SbColor *color)
00227 { setAmbient(state, node, *color); }SoDEPRECATED
00232 static void setEmissive(SoState *state, SoNode* node, const SbColor *color)
00233 { setEmissive(state, node, *color); }SoDEPRECATED
00238 static void setSpecular(SoState *state, SoNode* node, const SbColor *color)
00239 { setSpecular(state, node, *color); }
00240
00241 #endif
00243 static void setAmbient(SoState *state, SoNode* node, const SbColor &color);
00244 static void setEmissive(SoState *state, SoNode* node, const SbColor &color);
00245 static void setSpecular(SoState *state, SoNode* node, const SbColor &color);
00246
00247 static void setShininess(SoState *state, SoNode* node, float value);
00248 static void setColorMaterial(SoState *state, SoNode* node, SbBool value);
00249 static void setBlending(SoState *state, SbBool value);
00250 static void setSmoothing(SoState *state, SbBool value);
00251 static void setLightModel(SoState *state, const int32_t model);
00252
00258 static SbColor getDiffuse(SoState *state, int index);
00264 static float getTransparency(SoState *, int index);
00269 static const uint32_t *getPackedColors(SoState *state);
00274 static const int32_t *getColorIndices(SoState *state);
00275 static int32_t getColorIndex(SoState *, int num);
00276 static SbColor getAmbient(SoState *);
00277 static SbColor getEmissive(SoState *);
00278 static SbColor getSpecular(SoState *);
00279 static float getShininess(SoState *);
00280 static SbBool getColorMaterial(SoState *);
00281 static SbBool getBlending(SoState *);
00282 static SbBool getSmoothing(SoState *);
00283 static int32_t getLightModel(SoState *);
00284
00288 int32_t getNumDiffuse() const {
00289 return ivState.numDiffuseColors;
00290 }
00294 int32_t getNumTransparencies() const {
00295 return ivState.numTransparencies;
00296 }
00300 int32_t getNumColorIndices() const {
00301 return (ivState.colorIndices ? ivState.numDiffuseColors : 0);
00302 }
00306 SbBool isPacked() const {
00307 return ivState.packed;
00308 }
00312 SbBool isTransparent() const;
00313
00324 static SoLazyElement *getInstance(SoState *state) {
00325 return (SoLazyElement *)(state->getElementNoPush(SoLazyElement::getClassTypeId(), getClassStackIndex()));
00326 }
00330 static float getDefaultAmbientIntensity() {
00331 return 0.2F;
00332 }
00333
00337 static SbColor getDefaultDiffuse() {
00338 return SbColor(0.8F, 0.8F, 0.8F);
00339 }
00343 static SbColor getDefaultAmbient() {
00344 return SbColor(0.2F, 0.2F, 0.2F);
00345 }
00349 static SbColor getDefaultSpecular() {
00350 return SbColor(0.0F, 0.0F, 0.0F);
00351 }
00355 static SbColor getDefaultEmissive() {
00356 return SbColor(0.0F, 0.0F, 0.0F);
00357 }
00361 static float getDefaultShininess() {
00362 return 0.2F;
00363 }
00367 static uint32_t getDefaultPackedInternal();
00371 static uint32_t getDefaultPacked() {
00372 return (0xccccccff);
00373 }
00377 static float getDefaultTransparency() {
00378 return 0.0F;
00379 }
00383 static int32_t getDefaultLightModel() {
00384 return SoLightModelElement::PER_VERTEX_PHONG;
00385 }
00389 static int32_t getDefaultColorIndex() {
00390 return 1;
00391 }
00395 static float getDefaultLineWidth() {
00396 return 0.0f;
00397 }
00399 virtual void push(SoState *state);
00400
00402 virtual void print(FILE *fp) const;
00403
00404 private:
00405
00407 virtual void commonInit();
00408
00410 virtual void init(SoState *state);
00411
00418 virtual SbBool matches(const SoElement *) const;
00419
00425 virtual SoElement* copyMatchInfo() const;
00426
00427 private:
00428
00429
00430 static void setMaterials(SoState *state,
00431 SoNode *node,
00432 uint32_t bitmask,
00433 SoColorPacker *cPacker,
00434 const SoMFColor &diffuse,
00435 const SoMFFloat &transp,
00436 const SoMFColor &ambient,
00437 const SoMFColor &emissive,
00438 const SoMFColor &specular,
00439 const SoMFFloat &shininess);
00440
00441
00442 static void setMaterials(SoState *state,
00443 SoNode *node,
00444 uint32_t bitmask,
00445 SoColorPacker *cPacker,
00446 SoMFColor *diffuse,
00447 SoMFFloat *transp,
00448 SoMFColor *ambient,
00449 SoMFColor *emissive,
00450 SoMFColor *specular,
00451 SoMFFloat *shininess);
00452
00453
00454 static SoLazyElement *getWInstance(SoState *state) {
00455 return state->getElement<SoLazyElement>();
00456 }
00457
00458
00459 static void initClass();
00460 static void exitClass();
00461
00462
00463
00464
00465
00466 const uint32_t *getPackedPointer() const {
00467 return ivState.packedColors.empty() ? NULL : &ivState.packedColors[0];
00468 }
00469 const SbColor *getDiffusePointer() const {
00470 return ivState.diffuseColors;
00471 }
00472 const int32_t *getColorIndexPointer() const {
00473 return ivState.colorIndices;
00474 }
00475 const float *getTransparencyPointer() const {
00476 return ivState.transparencies;
00477 }
00478
00479 static void setHasTransparency( SoState* state, int hasTransparency );
00480
00481
00482
00483 static void setTransparencyType(SoState *state, int32_t type);
00484
00485
00486
00487
00488 static bool shouldSendMaterial(SoState *state);
00489
00490
00491
00492 static void setPatternFlag(SoState *state, SbBool flag);
00493
00494
00495
00496 static void setLineWidth(SoState *state, float width);
00497
00498 enum internalMasks {
00499 OTHER_COLOR_MASK = AMBIENT_MASK|EMISSIVE_MASK|SPECULAR_MASK|SHININESS_MASK,
00500 ALL_COLOR_MASK = OTHER_COLOR_MASK|DIFFUSE_MASK,
00501 NO_COLOR_MASK = ALL_MASK & (~ALL_COLOR_MASK),
00502 ALL_BUT_DIFFUSE_MASK = ALL_MASK &(~ DIFFUSE_MASK),
00503 DIFFUSE_ONLY_MASK = ALL_MASK &(~ OTHER_COLOR_MASK)
00504 };
00505
00506
00507
00508 virtual void registerGetDependence(SoState *, uint32_t);
00509
00510
00511 void leEncodeColorPacker( SoColorPacker *cPacker ) const;
00512
00513 private:
00514
00515
00516
00517 virtual void registerRedundantSet(SoState *, uint32_t);
00518
00519
00520 class __ivstate {
00521 public:
00522 __ivstate()
00523 : diffuseNodeId(0)
00524 , transpNodeId(0)
00525 , ambientColor(0,0,0)
00526 , emissiveColor(0,0,0)
00527 , specularColor(0,0,0)
00528 , shininess(0)
00529 , colorMaterial(0)
00530 , blending(0)
00531 , smoothing(0)
00532 , lightModel(0)
00533 , lineWidth(0.0f)
00534 , packed(false)
00535 , packedTransparent(false)
00536 , numDiffuseColors(0)
00537 , numTransparencies(0)
00538 , diffuseColors(0)
00539 , transparencies(0)
00540 , colorIndices(0)
00541 , transpType(0)
00542 , cacheLevelSetBits(0)
00543 , cacheLevelSendBits(0)
00544 , patternStippleNum(0)
00545 {
00546 }
00547
00548
00549
00550 uint64_t diffuseNodeId;
00551
00552
00553
00554 uint64_t transpNodeId;
00555
00556
00557
00558 SbColor ambientColor;
00559 SbColor emissiveColor;
00560 SbColor specularColor;
00561 float shininess;
00562 int32_t colorMaterial;
00563 int32_t blending;
00564 int32_t smoothing;
00565 int32_t lightModel;
00566 float lineWidth;
00567
00568
00569
00570 SbBool packed;
00571 SbBool packedTransparent;
00572 int32_t numDiffuseColors;
00573 int32_t numTransparencies;
00574 const SbColor *diffuseColors;
00575 const float *transparencies;
00576 std::vector<uint32_t> packedColors;
00577 std::vector<uint32_t> packedColors2;
00578 const int32_t *colorIndices;
00579 int32_t transpType;
00580 uint32_t cacheLevelSetBits;
00581 uint32_t cacheLevelSendBits;
00582 int32_t patternStippleNum;
00583 };
00584 __ivstate ivState;
00585
00586 virtual ~SoLazyElement();
00587
00588
00589
00590
00591 uint32_t invalidBits;
00592
00593
00594
00595 static SbColor *defaultDiffuseColor;
00596 static float *defaultTransparency;
00597 static int32_t *defaultColorIndices;
00598 static uint32_t *defaultPackedColor;
00599
00600
00601
00602 static int getNumPatterns() {
00603 return 64;
00604 }
00605
00606 int m_hasTransparency;
00607
00608 private:
00609
00610 virtual void setDiffuseElt(SoNode *,
00611 int32_t numColors,
00612 const SbColor *colors,
00613 SoColorPacker *cPacker);
00614 virtual void setPackedElt(SoNode *,
00615 int32_t numColors,
00616 const uint32_t *colors,
00617 SoColorPacker *cPacker);
00618 virtual void setColorIndexElt(SoNode *,
00619 int32_t numIndices,
00620 const int32_t *indices);
00621 virtual void setTranspElt(SoNode *,
00622 int32_t numTrans,
00623 const float *trans,
00624 SoColorPacker *cPacker);
00625 virtual void setPatternFlagElt(SbBool flag);
00626 virtual void setTranspTypeElt(int32_t type);
00627 virtual void setAmbientElt(const SbColor *color);
00628 virtual void setEmissiveElt(const SbColor *color);
00629 virtual void setSpecularElt(const SbColor *color);
00630 virtual void setShininessElt(float value);
00631 virtual void setColorMaterialElt(SbBool value);
00632 virtual void setBlendingElt(SbBool value);
00633 virtual void setSmoothingElt(SbBool value);
00634 virtual void setLightModelElt(SoState *state, int32_t model);
00635 virtual void setLineWidthElt(float lineWidth);
00636 virtual void setMaterialElt(SoNode *,
00637 uint32_t bitmask,
00638 SoColorPacker *cPacker,
00639 const SoMFColor &,
00640 const SoMFFloat &,
00641 const SoMFColor &,
00642 const SoMFColor &,
00643 const SoMFColor &,
00644 const SoMFFloat &);
00645 virtual void setMaterialElt(SoNode *,
00646 uint32_t bitmask,
00647 SoColorPacker *cPacker,
00648 SoMFColor *,
00649 SoMFFloat *,
00650 SoMFColor *,
00651 SoMFColor *,
00652 SoMFColor *,
00653 SoMFFloat *);
00654 };
00655
00656 #endif
00657
00658