Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoLazyElement.h
Go to the documentation of this file.
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Alan Norton (MMM yyyy)
25** Modified by : Gavin Bell (MMM yyyy)
26**=======================================================================*/
27/*=======================================================================
28 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
29 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
30 *** ***
31 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
32 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
33 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
34 *** ***
35 *** RESTRICTED RIGHTS LEGEND ***
36 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
37 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
38 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
39 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
40 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
41 *** ***
42 *** COPYRIGHT (C) 1996-2018 BY FEI S.A.S, ***
43 *** BORDEAUX, FRANCE ***
44 *** ALL RIGHTS RESERVED ***
45**=======================================================================*/
46/*=======================================================================
47** Modified by : VSG (MMM YYYY)
48**=======================================================================*/
49
50
51#ifndef _SO_LAZY_ELEMENT
52#define _SO_LAZY_ELEMENT
53
54#include <Inventor/SbBasic.h>
55#include <Inventor/SbColor.h>
59#include <math.h>
61
62class SoMFFloat;
63class SoMFColor;
64class SoColorPacker;
65class SbThreadMutex;
66
70#define SO_LAZY_SHINY_THRESHOLD 0.005
71
75#define SO_LAZY_NUM_COMPONENTS 12
76class SoDEPRECATED SoLazyElement : public SoElement{
106
108
109 public:
119 enum cases {
121 LIGHT_MODEL_CASE = 0,
123 COLOR_MATERIAL_CASE = 1,
125 DIFFUSE_CASE = 2,
127 AMBIENT_CASE = 3,
129 EMISSIVE_CASE = 4,
131 SPECULAR_CASE = 5,
133 SHININESS_CASE = 6,
135 BLENDING_CASE = 7,
137 TRANSPARENCY_CASE = 8,
139 PATTERN_CASE = 9,
141 SMOOTHING_CASE = 10,
143 LINE_WIDTH_CASE = 11
144 };
145
147 enum masks {
149 LIGHT_MODEL_MASK = 1 << LIGHT_MODEL_CASE,
151 COLOR_MATERIAL_MASK = 1 << COLOR_MATERIAL_CASE,
153 DIFFUSE_MASK = 1 << DIFFUSE_CASE,
155 AMBIENT_MASK = 1 << AMBIENT_CASE,
157 EMISSIVE_MASK = 1 << EMISSIVE_CASE,
159 SPECULAR_MASK = 1 << SPECULAR_CASE,
161 SHININESS_MASK = 1 << SHININESS_CASE,
163 TRANSPARENCY_MASK = 1 << TRANSPARENCY_CASE,
165 BLENDING_MASK = 1 << BLENDING_CASE,
167 SMOOTHING_MASK = 1 << SMOOTHING_CASE,
169 ALL_MASK = (1 << SO_LAZY_NUM_COMPONENTS)-1,
171 PATTERN_MASK = 1 << PATTERN_CASE,
173 LINE_WIDTH_MASK = 1 << LINE_WIDTH_CASE
174 };
175
182 static void setDiffuse(SoState *state,
183 SoNode *node,
184 int32_t numColors,
185 const SbColor *colors,
186 SoColorPacker *cPacker);
193 static void setTransparency(SoState *state,
194 SoNode *node,
195 int32_t numTransp,
196 const float *transp,
197 SoColorPacker *cPacker);
204 static void setPacked(SoState *state,
205 SoNode *node,
206 SoColorPacker *cPacker,
207 int32_t numColors,
208 const uint32_t *colors);
215 static void setColorIndices(SoState *state,
216 SoNode *node,
217 int32_t numIndices,
218 const int32_t *indices);
219
220#if 1 SoDEPRECATED
226 static void setAmbient(SoState *state, SoNode* node, const SbColor *color)
227 { setAmbient(state, node, *color); }SoDEPRECATED
232 static void setEmissive(SoState *state, SoNode* node, const SbColor *color)
233 { setEmissive(state, node, *color); }SoDEPRECATED
238 static void setSpecular(SoState *state, SoNode* node, const SbColor *color)
239 { setSpecular(state, node, *color); }
240
241#endif
243 static void setAmbient(SoState *state, SoNode* node, const SbColor &color);
244 static void setEmissive(SoState *state, SoNode* node, const SbColor &color);
245 static void setSpecular(SoState *state, SoNode* node, const SbColor &color);
246
247 static void setShininess(SoState *state, SoNode* node, float value);
248 static void setColorMaterial(SoState *state, SoNode* node, SbBool value);
249 static void setBlending(SoState *state, SbBool value);
250 static void setSmoothing(SoState *state, SbBool value);
251 static void setLightModel(SoState *state, const int32_t model);
252
258 static SbColor getDiffuse(SoState *state, int index);
264 static float getTransparency(SoState *, int index);
269 static const uint32_t *getPackedColors(SoState *state);
274 static const int32_t *getColorIndices(SoState *state);
275 static int32_t getColorIndex(SoState *, int num);
279 static float getShininess(SoState *);
283 static int32_t getLightModel(SoState *);
284
288 int32_t getNumDiffuse() const {
289 return ivState.numDiffuseColors;
290 }
294 int32_t getNumTransparencies() const {
295 return ivState.numTransparencies;
296 }
300 int32_t getNumColorIndices() const {
301 return (ivState.colorIndices ? ivState.numDiffuseColors : 0);
302 }
306 SbBool isPacked() const {
307 return ivState.packed;
308 }
313
325 return (SoLazyElement *)(state->getElementNoPush(SoLazyElement::getClassTypeId(), getClassStackIndex()));
326 }
331 return 0.2F;
332 }
333
338 return SbColor(0.8F, 0.8F, 0.8F);
339 }
344 return SbColor(0.2F, 0.2F, 0.2F);
345 }
350 return SbColor(0.0F, 0.0F, 0.0F);
351 }
356 return SbColor(0.0F, 0.0F, 0.0F);
357 }
361 static float getDefaultShininess() {
362 return 0.2F;
363 }
367 static uint32_t getDefaultPackedInternal();
371 static uint32_t getDefaultPacked() {
372 return (0xccccccff);
373 }
377 static float getDefaultTransparency() {
378 return 0.0F;
379 }
383 static int32_t getDefaultLightModel() {
385 }
389 static int32_t getDefaultColorIndex() {
390 return 1;
391 }
395 static float getDefaultLineWidth() {
396 return 0.0f;
397 }
399 virtual void push(SoState *state);
400
402 virtual void print(FILE *fp) const;
403
404private:
405
407 virtual void commonInit();
408
410 virtual void init(SoState *state);
411
418 virtual SbBool matches(const SoElement *) const;
419
425 virtual SoElement* copyMatchInfo() const;
426
427 private:
428
429 // set method for use in SoMaterial nodes:
430 static void setMaterials(SoState *state,
431 SoNode *node,
432 uint32_t bitmask,
433 SoColorPacker *cPacker,
434 const SoMFColor &diffuse,
435 const SoMFFloat &transp,
436 const SoMFColor &ambient,
437 const SoMFColor &emissive,
438 const SoMFColor &specular,
439 const SoMFFloat &shininess);
440
441 // set method for use in SoMaterial nodes:
442 static void setMaterials(SoState *state,
443 SoNode *node,
444 uint32_t bitmask,
445 SoColorPacker *cPacker,
446 SoMFColor *diffuse,
447 SoMFFloat *transp,
448 SoMFColor *ambient,
449 SoMFColor *emissive,
450 SoMFColor *specular,
451 SoMFFloat *shininess);
452
453 //Get a Writable instance, so will force a push if needed:
454 static SoLazyElement *getWInstance(SoState *state) {
455 return state->getElement<SoLazyElement>();
456 }
457
458 // Initializes the SoLazyElement class
459 static void initClass();
460 static void exitClass();
461
462 //Following SoINTERNAL get() methods do NOT cause cache dependency, should
463 //only be invoked by nodes that use the reallySend method on SoGLLazyElement
464 //to establish correct cache dependencies by tracking what was actually
465 //sent to GL.
466 const uint32_t *getPackedPointer() const {
467 return ivState.packedColors.empty() ? NULL : &ivState.packedColors[0];
468 }
469 const SbColor *getDiffusePointer() const {
470 return ivState.diffuseColors;
471 }
472 const int32_t *getColorIndexPointer() const {
473 return ivState.colorIndices;
474 }
475 const float *getTransparencyPointer() const {
476 return ivState.transparencies;
477 }
478
479 static void setHasTransparency( SoState* state, int hasTransparency );
480
481 // set method for transparency type is SoINTERNAL, because it should
482 // only be invoked by SoGLRenderAction
483 static void setTransparencyType(SoState *state, int32_t type);
484
485 // return true if the transparency is usefull in the current pass
486 // and the current ivState has some transparency
487 // only invoked by node before sendAllMaterial to avoid unnecessary GL calls (ie. SoMaterial)
488 static bool shouldSendMaterial(SoState *state);
489
490 // set method for usePattern is SoINTERNAL, because it should
491 // only be invoked by SoPatternElement
492 static void setPatternFlag(SoState *state, SbBool flag);
493
494 // set method for lineWidth is SoINTERNAL because it should only be
495 // invoked by SoLineWidthElement.
496 static void setLineWidth(SoState *state, float width);
497
498 enum internalMasks {
499 OTHER_COLOR_MASK = AMBIENT_MASK|EMISSIVE_MASK|SPECULAR_MASK|SHININESS_MASK,
500 ALL_COLOR_MASK = OTHER_COLOR_MASK|DIFFUSE_MASK,
501 NO_COLOR_MASK = ALL_MASK & (~ALL_COLOR_MASK),
502 ALL_BUT_DIFFUSE_MASK = ALL_MASK &(~ DIFFUSE_MASK),
503 DIFFUSE_ONLY_MASK = ALL_MASK &(~ OTHER_COLOR_MASK)
504 };
505
506 // method to register dependence due to get().
507 // only the GL version does any work
508 virtual void registerGetDependence(SoState *, uint32_t);
509
510 // little endian encode in SoColorPacker
511 void leEncodeColorPacker( SoColorPacker *cPacker ) const;
512
513private:
514
515 // method to tell the cache that a redundant set was issued.
516 // only the GL version does any work.
517 virtual void registerRedundantSet(SoState *, uint32_t);
518
519 //Struct to hold the inventor state:
520 class __ivstate {
521 public:
522 __ivstate()
523 : diffuseNodeId(0)
524 , transpNodeId(0)
525 , ambientColor(0,0,0)
526 , emissiveColor(0,0,0)
527 , specularColor(0,0,0)
528 , shininess(0)
529 , colorMaterial(0)
530 , blending(0)
531 , smoothing(0)
532 , lightModel(0)
533 , lineWidth(0.0f)
534 , packed(false)
535 , packedTransparent(false)
536 , numDiffuseColors(0)
537 , numTransparencies(0)
538 , diffuseColors(0)
539 , transparencies(0)
540 , colorIndices(0)
541 , transpType(0)
542 , cacheLevelSetBits(0)
543 , cacheLevelSendBits(0)
544 , patternStippleNum(0)
545 {
546 }
547
548 // keep nodeID to compare diffuse GL and diffuse inventor state:
549 // 0 is initial value, 1 is invalid
550 uint64_t diffuseNodeId;
551
552 // for transparency, keep either nodeid, or 0 if opaque. Value of
553 // 1 indicates invalid.
554 uint64_t transpNodeId;
555
556 // store a value of each color component; ambient, emissive,
557 // specular, shininess, or appropriate info to identify state.
558 SbColor ambientColor;
559 SbColor emissiveColor;
560 SbColor specularColor;
561 float shininess;
562 int32_t colorMaterial;
563 int32_t blending;
564 int32_t smoothing;
565 int32_t lightModel;
566 float lineWidth;
567
568 // following are not used for matching GL & IV, but must
569 // be copied on push:
570 SbBool packed;
571 SbBool packedTransparent;
572 int32_t numDiffuseColors;
573 int32_t numTransparencies;
574 const SbColor *diffuseColors;
575 const float *transparencies;
576 std::vector<uint32_t> packedColors;
577 std::vector<uint32_t> packedColors2;
578 const int32_t *colorIndices;
579 int32_t transpType;
580 uint32_t cacheLevelSetBits;
581 uint32_t cacheLevelSendBits;
582 int32_t patternStippleNum;
583 };
584 __ivstate ivState;
585
586 virtual ~SoLazyElement();
587
588 // This is more convenient here, but might logically be kept with
589 // SoGLLazyElement. This is a bitmask indicating what components
590 // have not been sent to GL.
591 uint32_t invalidBits;
592
593 // store pointers to the default color, transp so that we can set
594 // point to them if no other color or transp has been set.
595 static SbColor *defaultDiffuseColor;
596 static float *defaultTransparency;
597 static int32_t *defaultColorIndices;
598 static uint32_t *defaultPackedColor;
599
600 // Returns number of transparency levels supported with stipple
601 // patterns. (Add one - solid - that is not included in this number.)
602 static int getNumPatterns() {
603 return 64;
604 }
605 // -1 = don't know yet, 0 = no transp, 1 = has transp
606 int m_hasTransparency;
607
608 private:
609 // Virtual setElt methods, to be overridden by GL versions.
610 virtual void setDiffuseElt(SoNode *,
611 int32_t numColors,
612 const SbColor *colors,
613 SoColorPacker *cPacker);
614 virtual void setPackedElt(SoNode *,
615 int32_t numColors,
616 const uint32_t *colors,
617 SoColorPacker *cPacker);
618 virtual void setColorIndexElt(SoNode *,
619 int32_t numIndices,
620 const int32_t *indices);
621 virtual void setTranspElt(SoNode *,
622 int32_t numTrans,
623 const float *trans,
624 SoColorPacker *cPacker);
625 virtual void setPatternFlagElt(SbBool flag);
626 virtual void setTranspTypeElt(int32_t type);
627 virtual void setAmbientElt(const SbColor *color);
628 virtual void setEmissiveElt(const SbColor *color);
629 virtual void setSpecularElt(const SbColor *color);
630 virtual void setShininessElt(float value);
631 virtual void setColorMaterialElt(SbBool value);
632 virtual void setBlendingElt(SbBool value);
633 virtual void setSmoothingElt(SbBool value);
634 virtual void setLightModelElt(SoState *state, int32_t model);
635 virtual void setLineWidthElt(float lineWidth);
636 virtual void setMaterialElt(SoNode *,
637 uint32_t bitmask,
638 SoColorPacker *cPacker,
639 const SoMFColor &,
640 const SoMFFloat &,
641 const SoMFColor &,
642 const SoMFColor &,
643 const SoMFColor &,
644 const SoMFFloat &);
645 virtual void setMaterialElt(SoNode *,
646 uint32_t bitmask,
647 SoColorPacker *cPacker,
648 SoMFColor *,
649 SoMFFloat *,
650 SoMFColor *,
651 SoMFColor *,
652 SoMFColor *,
653 SoMFFloat *);
654};
655
656#endif /* _SO_LAZY_ELEMENT */
657
static int getClassStackIndex()
Returns the stack id for this element.
#define SO_LAZY_NUM_COMPONENTS
Number of components (subelements) in this element:
static void init()
#define SO_ELEMENT_HEADER(className)
Color vector class.
Definition SbColor.h:82
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
Stores packed colors.
Abstract base class for all state elements.
Definition SoElement.h:102
Manages several properties that need to be lazily tracked for OpenGL.
static float getDefaultLineWidth()
Specify Open Inventor defaults for colors, etc.
static const int32_t * getColorIndices(SoState *state)
static void setPacked(SoState *state, SoNode *node, SoColorPacker *cPacker, int32_t numColors, const uint32_t *colors)
Static set method.
static int32_t getColorIndex(SoState *, int num)
static void setColorMaterial(SoState *state, SoNode *node, SbBool value)
static void setShininess(SoState *state, SoNode *node, float value)
static float getTransparency(SoState *, int index)
get() methods get value from Inventor state.
cases
Following masks and cases define the components of the lazy element.
static const uint32_t * getPackedColors(SoState *state)
int32_t getNumDiffuse() const
Method to inquire about current colors.
static SbColor getDefaultEmissive()
Specify Open Inventor defaults for colors, etc.
static SoDEPRECATED void setEmissive(SoState *state, SoNode *node, const SbColor *color)
static SbColor getDefaultSpecular()
Specify Open Inventor defaults for colors, etc.
static SbColor getDefaultAmbient()
Specify Open Inventor defaults for colors, etc.
static void setEmissive(SoState *state, SoNode *node, const SbColor &color)
static SoLazyElement * getInstance(SoState *state)
Returns the top (current) instance of the element in the state Note that the cache dependencies assoc...
static uint32_t getDefaultPacked()
Specify Open Inventor defaults for colors, etc.
static SoType getClassTypeId()
Returns the type identifier for this class.
static void setSpecular(SoState *state, SoNode *node, const SbColor &color)
static void setLightModel(SoState *state, const int32_t model)
static void setSmoothing(SoState *state, SbBool value)
static SbBool getColorMaterial(SoState *)
static void setColorIndices(SoState *state, SoNode *node, int32_t numIndices, const int32_t *indices)
Static set method.
SbBool isTransparent() const
Method to inquire about current colors.
static void setBlending(SoState *state, SbBool value)
static uint32_t getDefaultPackedInternal()
Specify Open Inventor defaults for colors, etc.
static void setTransparency(SoState *state, SoNode *node, int32_t numTransp, const float *transp, SoColorPacker *cPacker)
Static set method.
static float getDefaultShininess()
Specify Open Inventor defaults for colors, etc.
static SbColor getDiffuse(SoState *state, int index)
get() methods get value from Inventor state.
static SbColor getSpecular(SoState *)
static void setAmbient(SoState *state, SoNode *node, const SbColor &color)
virtual void print(FILE *fp) const
Prints element (for debugging).
static int32_t getDefaultLightModel()
Specify Open Inventor defaults for colors, etc.
SbBool isPacked() const
Method to inquire about current colors.
int32_t getNumColorIndices() const
Method to inquire about current colors.
static float getDefaultAmbientIntensity()
Specify Open Inventor defaults for colors, etc.
virtual void push(SoState *state)
push (for non-GL elements)
static SbBool getSmoothing(SoState *)
static SbColor getAmbient(SoState *)
static void setDiffuse(SoState *state, SoNode *node, int32_t numColors, const SbColor *colors, SoColorPacker *cPacker)
Static set method.
static SbBool getBlending(SoState *)
static int32_t getDefaultColorIndex()
Specify Open Inventor defaults for colors, etc.
static SbColor getEmissive(SoState *)
static float getDefaultTransparency()
Specify Open Inventor defaults for colors, etc.
static SoDEPRECATED void setAmbient(SoState *state, SoNode *node, const SbColor *color)
int32_t getNumTransparencies() const
Method to inquire about current colors.
static int32_t getLightModel(SoState *)
static SoDEPRECATED void setSpecular(SoState *state, SoNode *node, const SbColor *color)
static SbColor getDefaultDiffuse()
Specify Open Inventor defaults for colors, etc.
static float getShininess(SoState *)
@ PER_VERTEX_PHONG
Per-vertex Phong lighting.
Multiple-value field containing any number of RGB colors stored as three floats.
Definition SoMFColor.h:98
Multiple-value field containing any number of floating point values.
Definition SoMFFloat.h:90
Abstract base class for all database nodes.
Definition SoNode.h:145
Traversal state.
Definition SoState.h:74
T * getElement()
Returns a writable instance of the element on the top of the stack with the given type.
Definition SoState.h:95
int SbBool
Boolean type.
Definition SbBase.h:87