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 <math.h>
00059
00060 class SoMFFloat;
00061 class SoMFColor;
00062 class SoColorPacker;
00063 class SbThreadMutex;
00064
00068 #define SO_LAZY_SHINY_THRESHOLD 0.005
00069
00073 #define SO_LAZY_NUM_COMPONENTS 12
00074
00103 SoEXTENDER_Documented class SoLazyElement : public SoElement {
00104
00105 SO_ELEMENT_HEADER(SoLazyElement);
00106
00107 public:
00117 enum cases {
00119 LIGHT_MODEL_CASE = 0,
00121 COLOR_MATERIAL_CASE = 1,
00123 DIFFUSE_CASE = 2,
00125 AMBIENT_CASE = 3,
00127 EMISSIVE_CASE = 4,
00129 SPECULAR_CASE = 5,
00131 SHININESS_CASE = 6,
00133 BLENDING_CASE = 7,
00135 TRANSPARENCY_CASE = 8,
00137 PATTERN_CASE = 9,
00139 SMOOTHING_CASE = 10,
00141 LINE_WIDTH_CASE = 11
00142 };
00143
00145 enum masks {
00147 LIGHT_MODEL_MASK = 1 << LIGHT_MODEL_CASE,
00149 COLOR_MATERIAL_MASK = 1 << COLOR_MATERIAL_CASE,
00151 DIFFUSE_MASK = 1 << DIFFUSE_CASE,
00153 AMBIENT_MASK = 1 << AMBIENT_CASE,
00155 EMISSIVE_MASK = 1 << EMISSIVE_CASE,
00157 SPECULAR_MASK = 1 << SPECULAR_CASE,
00159 SHININESS_MASK = 1 << SHININESS_CASE,
00161 TRANSPARENCY_MASK = 1 << TRANSPARENCY_CASE,
00163 BLENDING_MASK = 1 << BLENDING_CASE,
00165 SMOOTHING_MASK = 1 << SMOOTHING_CASE,
00167 ALL_MASK = (1 << SO_LAZY_NUM_COMPONENTS)-1,
00169 PATTERN_MASK = 1 << PATTERN_CASE,
00171 LINE_WIDTH_MASK = 1 << LINE_WIDTH_CASE
00172 };
00173
00177 enum LightModel {
00179 BASE_COLOR = 0,
00181 PHONG = 1
00182 };
00183
00190 static void setDiffuse(SoState *state,
00191 SoNode *node,
00192 int32_t numColors,
00193 const SbColor *colors,
00194 SoColorPacker *cPacker);
00201 static void setTransparency(SoState *state,
00202 SoNode *node,
00203 int32_t numTransp,
00204 const float *transp,
00205 SoColorPacker *cPacker);
00212 static void setPacked(SoState *state,
00213 SoNode *node,
00214 SoColorPacker *cPacker,
00215 int32_t numColors,
00216 const uint32_t *colors);
00223 static void setColorIndices(SoState *state,
00224 SoNode *node,
00225 int32_t numIndices,
00226 const int32_t *indices);
00227
00228 #if 1 SoDEPRECATED
00234 static void setAmbient(SoState *state, const SbColor *color)
00235 { setAmbient(state,*color); }SoDEPRECATED
00240 static void setEmissive(SoState *state, const SbColor *color)
00241 { setEmissive(state,*color); }SoDEPRECATED
00246 static void setSpecular(SoState *state, const SbColor *color)
00247 { setSpecular(state,*color); }
00248
00249 #endif
00251 static void setAmbient(SoState *state, const SbColor &color);
00252 static void setEmissive(SoState *state, const SbColor &color);
00253 static void setSpecular(SoState *state, const SbColor &color);
00254
00255 static void setShininess(SoState *state, float value);
00256 static void setColorMaterial(SoState *state, SbBool value);
00257 static void setBlending(SoState *state, SbBool value);
00258 static void setSmoothing(SoState *state, SbBool value);
00259 static void setLightModel(SoState *state, const int32_t model);
00260
00266 static const SbColor &getDiffuse(SoState *state, int index);
00272 static float getTransparency(SoState *, int index);
00277 static const uint32_t *getPackedColors(SoState *state);
00282 static const int32_t *getColorIndices(SoState *state);
00283 static int32_t getColorIndex(SoState *, int num);
00284 static const SbColor &getAmbient(SoState *);
00285 static const SbColor &getEmissive(SoState *);
00286 static const SbColor &getSpecular(SoState *);
00287 static float getShininess(SoState *);
00288 static SbBool getColorMaterial(SoState *);
00289 static SbBool getBlending(SoState *);
00290 static SbBool getSmoothing(SoState *);
00291 static int32_t getLightModel(SoState *);
00292
00296 int32_t getNumDiffuse() const {
00297 return ivState.numDiffuseColors;
00298 }
00302 int32_t getNumTransparencies() const {
00303 return ivState.numTransparencies;
00304 }
00308 int32_t getNumColorIndices() const {
00309 return (ivState.colorIndices ? ivState.numDiffuseColors : 0);
00310 }
00314 SbBool isPacked() const {
00315 return ivState.packed;
00316 }
00320 SbBool isTransparent() const;
00321
00332 static SoLazyElement *getInstance(SoState *state) {
00333 return (SoLazyElement *)(state->getElementNoPush(SoLazyElement::getClassTypeId(), getClassStackIndex()));
00334 }
00338 static float getDefaultAmbientIntensity() {
00339 return 0.2F;
00340 }
00341
00345 static SbColor getDefaultDiffuse() {
00346 return SbColor(0.8F, 0.8F, 0.8F);
00347 }
00351 static SbColor getDefaultAmbient() {
00352 return SbColor(0.2F, 0.2F, 0.2F);
00353 }
00357 static SbColor getDefaultSpecular() {
00358 return SbColor(0.0F, 0.0F, 0.0F);
00359 }
00363 static SbColor getDefaultEmissive() {
00364 return SbColor(0.0F, 0.0F, 0.0F);
00365 }
00369 static float getDefaultShininess() {
00370 return 0.2F;
00371 }
00375 static uint32_t getDefaultPackedInternal();
00379 static uint32_t getDefaultPacked() {
00380 return (0xccccccff);
00381 }
00385 static float getDefaultTransparency() {
00386 return 0.0F;
00387 }
00391 static int32_t getDefaultLightModel() {
00392 return PHONG;
00393 }
00397 static int32_t getDefaultColorIndex() {
00398 return 1;
00399 }
00403 static float getDefaultLineWidth() {
00404 return 0.0f;
00405 }
00407 virtual void push(SoState *state);
00408
00409 private:
00410
00412 virtual void commonInit();
00413
00415 virtual void init(SoState *state);
00416
00423 virtual SbBool matches(const SoElement *) const;
00424
00430 virtual SoElement* copyMatchInfo() const;
00431
00432 private:
00433
00434
00435 static void setMaterials(SoState *state,
00436 SoNode *node,
00437 uint32_t bitmask,
00438 SoColorPacker *cPacker,
00439 const SoMFColor &diffuse,
00440 const SoMFFloat &transp,
00441 const SoMFColor &ambient,
00442 const SoMFColor &emissive,
00443 const SoMFColor &specular,
00444 const SoMFFloat &shininess);
00445
00446
00447 static void setMaterials(SoState *state,
00448 SoNode *node,
00449 uint32_t bitmask,
00450 SoColorPacker *cPacker,
00451 SoMFColor *diffuse,
00452 SoMFFloat *transp,
00453 SoMFColor *ambient,
00454 SoMFColor *emissive,
00455 SoMFColor *specular,
00456 SoMFFloat *shininess);
00457
00458
00459 static SoLazyElement *getWInstance(SoState *state) {
00460 return state->getElement<SoLazyElement>();
00461 }
00462
00463
00464 virtual void print(FILE *fp) const;
00465
00466
00467 static void initClass();
00468 static void exitClass();
00469
00470
00471
00472
00473
00474 const uint32_t *getPackedPointer() const {
00475 return ivState.packedColors;
00476 }
00477 const SbColor *getDiffusePointer() const {
00478 return ivState.diffuseColors;
00479 }
00480 const int32_t *getColorIndexPointer() const {
00481 return ivState.colorIndices;
00482 }
00483 const float *getTransparencyPointer() const {
00484 return ivState.transparencies;
00485 }
00486
00487
00488
00489 static void setTransparencyType(SoState *state, int32_t type);
00490
00491
00492
00493
00494 static bool shouldSendMaterial(SoState *state);
00495
00496
00497
00498 static void setPatternFlag(SoState *state, SbBool flag);
00499
00500
00501
00502 static void setLineWidth(SoState *state, float width);
00503
00504 enum internalMasks {
00505 OTHER_COLOR_MASK = AMBIENT_MASK|EMISSIVE_MASK|SPECULAR_MASK|SHININESS_MASK,
00506 ALL_COLOR_MASK = OTHER_COLOR_MASK|DIFFUSE_MASK,
00507 NO_COLOR_MASK = ALL_MASK & (~ALL_COLOR_MASK),
00508 ALL_BUT_DIFFUSE_MASK = ALL_MASK &(~ DIFFUSE_MASK),
00509 DIFFUSE_ONLY_MASK = ALL_MASK &(~ OTHER_COLOR_MASK)
00510 };
00511
00512
00513
00514 virtual void registerGetDependence(SoState *, uint32_t);
00515
00516
00517 void leEncodeColorPacker( SoColorPacker *cPacker ) const;
00518
00519 private:
00520
00521
00522
00523 virtual void registerRedundantSet(SoState *, uint32_t);
00524
00525
00526 class __ivstate {
00527 public:
00528 __ivstate()
00529 : diffuseNodeId(0)
00530 , transpNodeId(0)
00531 , ambientColor(0,0,0)
00532 , emissiveColor(0,0,0)
00533 , specularColor(0,0,0)
00534 , shininess(0)
00535 , colorMaterial(0)
00536 , blending(0)
00537 , smoothing(0)
00538 , lightModel(0)
00539 , stippleNum(0)
00540 , lineWidth(0.0f)
00541 , packed(false)
00542 , packedTransparent(false)
00543 , numDiffuseColors(0)
00544 , numTransparencies(0)
00545 , diffuseColors(0)
00546 , transparencies(0)
00547 , packedColors(0)
00548 , packedColors2(0)
00549 , colorIndices(0)
00550 , transpType(0)
00551 , cacheLevelSetBits(0)
00552 , cacheLevelSendBits(0)
00553 , patternStippleNum(0)
00554 {
00555 }
00556
00557
00558
00559 uint64_t diffuseNodeId;
00560
00561
00562
00563 uint64_t transpNodeId;
00564
00565
00566
00567 SbColor ambientColor;
00568 SbColor emissiveColor;
00569 SbColor specularColor;
00570 float shininess;
00571 int32_t colorMaterial;
00572 int32_t blending;
00573 int32_t smoothing;
00574 int32_t lightModel;
00575 int32_t stippleNum;
00576 float lineWidth;
00577
00578
00579
00580 SbBool packed;
00581 SbBool packedTransparent;
00582 int32_t numDiffuseColors;
00583 int32_t numTransparencies;
00584 const SbColor *diffuseColors;
00585 const float *transparencies;
00586 const uint32_t *packedColors;
00587 const uint32_t *packedColors2;
00588 const int32_t *colorIndices;
00589 int32_t transpType;
00590 uint32_t cacheLevelSetBits;
00591 uint32_t cacheLevelSendBits;
00592 int32_t patternStippleNum;
00593 };
00594 __ivstate ivState;
00595
00596 virtual ~SoLazyElement();
00597
00598
00599
00600
00601 uint32_t invalidBits;
00602
00603
00604
00605 static SbColor *defaultDiffuseColor;
00606 static float *defaultTransparency;
00607 static int32_t *defaultColorIndices;
00608 static uint32_t *defaultPackedColor;
00609
00610
00611
00612 static int getNumPatterns() {
00613 return 64;
00614 }
00615
00616 int m_hasTransparency;
00617
00618 private:
00619
00620 virtual void setDiffuseElt(SoNode *,
00621 int32_t numColors,
00622 const SbColor *colors,
00623 SoColorPacker *cPacker);
00624 virtual void setPackedElt(SoNode *,
00625 int32_t numColors,
00626 const uint32_t *colors,
00627 SoColorPacker *cPacker);
00628 virtual void setColorIndexElt(SoNode *,
00629 int32_t numIndices,
00630 const int32_t *indices);
00631 virtual void setTranspElt(SoNode *,
00632 int32_t numTrans,
00633 const float *trans,
00634 SoColorPacker *cPacker);
00635 virtual void setPatternFlagElt(SbBool flag);
00636 virtual void setTranspTypeElt(int32_t type);
00637 virtual void setAmbientElt(const SbColor *color);
00638 virtual void setEmissiveElt(const SbColor *color);
00639 virtual void setSpecularElt(const SbColor *color);
00640 virtual void setShininessElt(float value);
00641 virtual void setColorMaterialElt(SbBool value);
00642 virtual void setBlendingElt(SbBool value);
00643 virtual void setSmoothingElt(SbBool value);
00644 virtual void setLightModelElt(SoState *state, int32_t model);
00645 virtual void setLineWidthElt(float lineWidth);
00646 virtual void setMaterialElt(SoNode *,
00647 uint32_t bitmask,
00648 SoColorPacker *cPacker,
00649 const SoMFColor &,
00650 const SoMFFloat &,
00651 const SoMFColor &,
00652 const SoMFColor &,
00653 const SoMFColor &,
00654 const SoMFFloat &);
00655 virtual void setMaterialElt(SoNode *,
00656 uint32_t bitmask,
00657 SoColorPacker *cPacker,
00658 SoMFColor *,
00659 SoMFFloat *,
00660 SoMFColor *,
00661 SoMFColor *,
00662 SoMFColor *,
00663 SoMFFloat *);
00664 };
00665
00667
00668
00669
00670
00671
00672
00674
00675 class SoColorPacker {
00676
00677 public:
00678
00679
00680 SoColorPacker();
00681
00682
00683 ~SoColorPacker();
00684
00689 uint32_t *getPackedColors() const {
00690 return packedColors;
00691 }
00692 SbBool diffuseMatch(uint64_t nodeId) {
00693 return (nodeId == diffuseNodeId);
00694 }
00695 SbBool transpMatch(uint64_t nodeId) {
00696 return (nodeId == transpNodeId);
00697 }
00698 void setNodeIds(uint64_t diffNodeId, uint64_t tNodeId) {
00699 diffuseNodeId = diffNodeId;
00700 transpNodeId = tNodeId;
00701 }
00702 int32_t getSize() {
00703 return packedArraySize;
00704 }
00705 void reallocate(int32_t size);
00706
00707 static void exitClass();
00708
00709 private:
00710
00711
00712 uint64_t transpNodeId;
00713 uint64_t diffuseNodeId;
00714
00715 uint32_t *packedColors;
00716
00717 int32_t packedArraySize;
00718
00719 static SbThreadMutex *m_mutex;
00720
00721 };
00722
00723 #endif
00724
00725