Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SoLazyElement.h
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-2024 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>
56#include <Inventor/elements/SoElement.h>
57#include <Inventor/elements/SoSubElement.h>
58#include <Inventor/elements/SoLightModelElement.h>
59#include <math.h>
60#include <Inventor/misc/SoColorPacker.h>
61
62class SoMFFloat;
63class SoMFColor;
64class SoColorPacker;
65class SbThreadMutex;
66
70#define SO_LAZY_SHINY_THRESHOLD 0.005
71
77#define SO_LAZY_NUM_COMPONENTS 12
78class SoDEPRECATED SoLazyElement : public SoElement{
108
109 SO_ELEMENT_HEADER(SoLazyElement);
110
111 public:
121 enum cases {
123 LIGHT_MODEL_CASE = 0,
125 COLOR_MATERIAL_CASE = 1,
127 DIFFUSE_CASE = 2,
129 AMBIENT_CASE = 3,
131 EMISSIVE_CASE = 4,
133 SPECULAR_CASE = 5,
135 SHININESS_CASE = 6,
137 BLENDING_CASE = 7,
139 TRANSPARENCY_CASE = 8,
141 PATTERN_CASE = 9,
143 SMOOTHING_CASE = 10,
145 LINE_WIDTH_CASE = 11
146 };
147
149 enum masks {
151 LIGHT_MODEL_MASK = 1 << LIGHT_MODEL_CASE,
153 COLOR_MATERIAL_MASK = 1 << COLOR_MATERIAL_CASE,
155 DIFFUSE_MASK = 1 << DIFFUSE_CASE,
157 AMBIENT_MASK = 1 << AMBIENT_CASE,
159 EMISSIVE_MASK = 1 << EMISSIVE_CASE,
161 SPECULAR_MASK = 1 << SPECULAR_CASE,
163 SHININESS_MASK = 1 << SHININESS_CASE,
165 TRANSPARENCY_MASK = 1 << TRANSPARENCY_CASE,
167 BLENDING_MASK = 1 << BLENDING_CASE,
169 SMOOTHING_MASK = 1 << SMOOTHING_CASE,
171 ALL_MASK = (1 << SO_LAZY_NUM_COMPONENTS)-1,
173 PATTERN_MASK = 1 << PATTERN_CASE,
175 LINE_WIDTH_MASK = 1 << LINE_WIDTH_CASE
176 };
177
184 static void setDiffuse(SoState *state,
185 SoNode *node,
186 int32_t numColors,
187 const SbColor *colors,
188 SoColorPacker *cPacker);
195 static void setTransparency(SoState *state,
196 SoNode *node,
197 int32_t numTransp,
198 const float *transp,
199 SoColorPacker *cPacker);
206 static void setPacked(SoState *state,
207 SoNode *node,
208 SoColorPacker *cPacker,
209 int32_t numColors,
210 const uint32_t *colors);
217 static void setColorIndices(SoState *state,
218 SoNode *node,
219 int32_t numIndices,
220 const int32_t *indices);
221
222#if 1 SoDEPRECATED
228 static void setAmbient(SoState *state, SoNode* node, const SbColor *color)
229 { setAmbient(state, node, *color); }SoDEPRECATED
234 static void setEmissive(SoState *state, SoNode* node, const SbColor *color)
235 { setEmissive(state, node, *color); }SoDEPRECATED
240 static void setSpecular(SoState *state, SoNode* node, const SbColor *color)
241 { setSpecular(state, node, *color); }
242
243#endif
245 static void setAmbient(SoState *state, SoNode* node, const SbColor &color);
246 static void setEmissive(SoState *state, SoNode* node, const SbColor &color);
247 static void setSpecular(SoState *state, SoNode* node, const SbColor &color);
248
249 static void setShininess(SoState *state, SoNode* node, float value);
250 static void setColorMaterial(SoState *state, SoNode* node, SbBool value);
251 static void setBlending(SoState *state, SbBool value);
252 static void setSmoothing(SoState *state, SbBool value);
253 static void setLightModel(SoState *state, const int32_t model);
254
260 static SbColor getDiffuse(SoState *state, int index);
266 static float getTransparency(SoState *, int index);
271 static const uint32_t *getPackedColors(SoState *state);
276 static const int32_t *getColorIndices(SoState *state);
277 static int32_t getColorIndex(SoState *, int num);
281 static float getShininess(SoState *);
285 static int32_t getLightModel(SoState *);
286
290 int32_t getNumDiffuse() const {
291 return ivState.numDiffuseColors;
292 }
296 int32_t getNumTransparencies() const {
297 return ivState.numTransparencies;
298 }
302 int32_t getNumColorIndices() const {
303 return (ivState.colorIndices ? ivState.numDiffuseColors : 0);
304 }
308 SbBool isPacked() const {
309 return ivState.packed;
310 }
315
327 return (SoLazyElement *)(state->getElementNoPush(SoLazyElement::getClassTypeId(), getClassStackIndex()));
328 }
333 return 0.2F;
334 }
335
340 return SbColor(0.8F, 0.8F, 0.8F);
341 }
346 return SbColor(0.2F, 0.2F, 0.2F);
347 }
352 return SbColor(0.0F, 0.0F, 0.0F);
353 }
358 return SbColor(0.0F, 0.0F, 0.0F);
359 }
363 static float getDefaultShininess() {
364 return 0.2F;
365 }
369 static uint32_t getDefaultPackedInternal();
373 static uint32_t getDefaultPacked() {
374 return (0xccccccff);
375 }
379 static float getDefaultTransparency() {
380 return 0.0F;
381 }
385 static int32_t getDefaultLightModel() {
387 }
391 static int32_t getDefaultColorIndex() {
392 return 1;
393 }
397 static float getDefaultLineWidth() {
398 return 0.0f;
399 }
401 virtual void push(SoState *state);
402
404 virtual void print(FILE *fp) const;
405
406private:
407
409 virtual void commonInit();
410
412 virtual void init(SoState *state);
413
420 virtual SbBool matches(const SoElement *) const;
421
427 virtual SoElement* copyMatchInfo() const;
428
429 private:
430
431 // set method for use in SoMaterial nodes:
432 static void setMaterials(SoState *state,
433 SoNode *node,
434 uint32_t bitmask,
435 SoColorPacker *cPacker,
436 const SoMFColor &diffuse,
437 const SoMFFloat &transp,
438 const SoMFColor &ambient,
439 const SoMFColor &emissive,
440 const SoMFColor &specular,
441 const SoMFFloat &shininess);
442
443 // set method for use in SoMaterial nodes:
444 static void setMaterials(SoState *state,
445 SoNode *node,
446 uint32_t bitmask,
447 SoColorPacker *cPacker,
448 SoMFColor *diffuse,
449 SoMFFloat *transp,
450 SoMFColor *ambient,
451 SoMFColor *emissive,
452 SoMFColor *specular,
453 SoMFFloat *shininess);
454
455 //Get a Writable instance, so will force a push if needed:
456 static SoLazyElement *getWInstance(SoState *state) {
457 return state->getElement<SoLazyElement>();
458 }
459
460 // Initializes the SoLazyElement class
461 static void initClass();
462 static void exitClass();
463
464 //Following SoINTERNAL get() methods do NOT cause cache dependency, should
465 //only be invoked by nodes that use the reallySend method on SoGLLazyElement
466 //to establish correct cache dependencies by tracking what was actually
467 //sent to GL.
468 const uint32_t *getPackedPointer() const {
469 return ivState.packedColors.empty() ? NULL : &ivState.packedColors[0];
470 }
471 const SbColor *getDiffusePointer() const {
472 return ivState.diffuseColors;
473 }
474 const int32_t *getColorIndexPointer() const {
475 return ivState.colorIndices;
476 }
477 const float *getTransparencyPointer() const {
478 return ivState.transparencies;
479 }
480
481 static void setHasTransparency( SoState* state, int hasTransparency );
482
483 // set method for transparency type is SoINTERNAL, because it should
484 // only be invoked by SoGLRenderAction
485 static void setTransparencyType(SoState *state, int32_t type);
486
487 // return true if the transparency is usefull in the current pass
488 // and the current ivState has some transparency
489 // only invoked by node before sendAllMaterial to avoid unnecessary GL calls (ie. SoMaterial)
490 static bool shouldSendMaterial(SoState *state);
491
492 // set method for usePattern is SoINTERNAL, because it should
493 // only be invoked by SoPatternElement
494 static void setPatternFlag(SoState *state, SbBool flag);
495
496 // set method for lineWidth is SoINTERNAL because it should only be
497 // invoked by SoLineWidthElement.
498 static void setLineWidth(SoState *state, float width);
499
500 enum internalMasks {
501 OTHER_COLOR_MASK = AMBIENT_MASK|EMISSIVE_MASK|SPECULAR_MASK|SHININESS_MASK,
502 ALL_COLOR_MASK = OTHER_COLOR_MASK|DIFFUSE_MASK,
503 NO_COLOR_MASK = ALL_MASK & (~ALL_COLOR_MASK),
504 ALL_BUT_DIFFUSE_MASK = ALL_MASK &(~ DIFFUSE_MASK),
505 DIFFUSE_ONLY_MASK = ALL_MASK &(~ OTHER_COLOR_MASK)
506 };
507
508 // method to register dependence due to get().
509 // only the GL version does any work
510 virtual void registerGetDependence(SoState *, uint32_t);
511
512 // little endian encode in SoColorPacker
513 void leEncodeColorPacker( SoColorPacker *cPacker ) const;
514
515private:
516
517 // method to tell the cache that a redundant set was issued.
518 // only the GL version does any work.
519 virtual void registerRedundantSet(SoState *, uint32_t);
520
521 //Struct to hold the inventor state:
522 class __ivstate {
523 public:
524 __ivstate()
525 : diffuseNodeId(0)
526 , transpNodeId(0)
527 , ambientColor(0,0,0)
528 , emissiveColor(0,0,0)
529 , specularColor(0,0,0)
530 , shininess(0)
531 , colorMaterial(0)
532 , blending(0)
533 , smoothing(0)
534 , lightModel(0)
535 , lineWidth(0.0f)
536 , packed(false)
537 , packedTransparent(false)
538 , numDiffuseColors(0)
539 , numTransparencies(0)
540 , diffuseColors(0)
541 , transparencies(0)
542 , colorIndices(0)
543 , transpType(0)
544 , cacheLevelSetBits(0)
545 , cacheLevelSendBits(0)
546 , patternStippleNum(0)
547 {
548 }
549
550 // keep nodeID to compare diffuse GL and diffuse inventor state:
551 // 0 is initial value, 1 is invalid
552 uint64_t diffuseNodeId;
553
554 // for transparency, keep either nodeid, or 0 if opaque. Value of
555 // 1 indicates invalid.
556 uint64_t transpNodeId;
557
558 // store a value of each color component; ambient, emissive,
559 // specular, shininess, or appropriate info to identify state.
560 SbColor ambientColor;
561 SbColor emissiveColor;
562 SbColor specularColor;
563 float shininess;
564 int32_t colorMaterial;
565 int32_t blending;
566 int32_t smoothing;
567 int32_t lightModel;
568 float lineWidth;
569
570 // following are not used for matching GL & IV, but must
571 // be copied on push:
572 SbBool packed;
573 SbBool packedTransparent;
574 int32_t numDiffuseColors;
575 int32_t numTransparencies;
576 const SbColor *diffuseColors;
577 const float *transparencies;
578 std::vector<uint32_t> packedColors;
579 std::vector<uint32_t> packedColors2;
580 const int32_t *colorIndices;
581 int32_t transpType;
582 uint32_t cacheLevelSetBits;
583 uint32_t cacheLevelSendBits;
584 int32_t patternStippleNum;
585 };
586 __ivstate ivState;
587
588 virtual ~SoLazyElement();
589
590 // This is more convenient here, but might logically be kept with
591 // SoGLLazyElement. This is a bitmask indicating what components
592 // have not been sent to GL.
593 uint32_t invalidBits;
594
595 // store pointers to the default color, transp so that we can set
596 // point to them if no other color or transp has been set.
597 static SbColor *defaultDiffuseColor;
598 static float *defaultTransparency;
599 static int32_t *defaultColorIndices;
600 static uint32_t *defaultPackedColor;
601
602 // Returns number of transparency levels supported with stipple
603 // patterns. (Add one - solid - that is not included in this number.)
604 static int getNumPatterns() {
605 return 64;
606 }
607 // -1 = don't know yet, 0 = no transp, 1 = has transp
608 int m_hasTransparency;
609
610 private:
611 // Virtual setElt methods, to be overridden by GL versions.
612 virtual void setDiffuseElt(SoNode *,
613 int32_t numColors,
614 const SbColor *colors,
615 SoColorPacker *cPacker);
616 virtual void setPackedElt(SoNode *,
617 int32_t numColors,
618 const uint32_t *colors,
619 SoColorPacker *cPacker);
620 virtual void setColorIndexElt(SoNode *,
621 int32_t numIndices,
622 const int32_t *indices);
623 virtual void setTranspElt(SoNode *,
624 int32_t numTrans,
625 const float *trans,
626 SoColorPacker *cPacker);
627 virtual void setPatternFlagElt(SbBool flag);
628 virtual void setTranspTypeElt(int32_t type);
629 virtual void setAmbientElt(const SbColor *color);
630 virtual void setEmissiveElt(const SbColor *color);
631 virtual void setSpecularElt(const SbColor *color);
632 virtual void setShininessElt(float value);
633 virtual void setColorMaterialElt(SbBool value);
634 virtual void setBlendingElt(SbBool value);
635 virtual void setSmoothingElt(SbBool value);
636 virtual void setLightModelElt(SoState *state, int32_t model);
637 virtual void setLineWidthElt(float lineWidth);
638 virtual void setMaterialElt(SoNode *,
639 uint32_t bitmask,
640 SoColorPacker *cPacker,
641 const SoMFColor &,
642 const SoMFFloat &,
643 const SoMFColor &,
644 const SoMFColor &,
645 const SoMFColor &,
646 const SoMFFloat &);
647 virtual void setMaterialElt(SoNode *,
648 uint32_t bitmask,
649 SoColorPacker *cPacker,
650 SoMFColor *,
651 SoMFFloat *,
652 SoMFColor *,
653 SoMFColor *,
654 SoMFColor *,
655 SoMFFloat *);
656};
657
658#endif /* _SO_LAZY_ELEMENT */
659
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