Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoGLLazyElement.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-2017 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_GL_LAZY_ELEMENT
52#define _SO_GL_LAZY_ELEMENT
53
54
55#include <Inventor/elements/SoLazyElement.h>
56#include <Inventor/actions/SoGLRenderAction.h>
57class SoGLRenderCache;
58class SoGLLazyState;
59
60
77SoEXTENDER_Documented class SoGLLazyElement : public SoLazyElement
78{
79
80 SO_ELEMENT_HEADER(SoGLLazyElement);
81
82 public:
86 virtual void push(SoState *state);
90 virtual void pop(SoState *state, const SoElement *prevTopElement);
91
95 static void sendAllMaterial(SoState *state) {
96 SoGLLazyElement *le = getInstance(state);
97 if ((le->invalidBits)||(state->isCacheOpen()))
98 le->reallySend(state, ALL_MASK|PATTERN_MASK);
99 }
100
104 static void sendNoMaterial(SoState *state) {
105 SoGLLazyElement *le = getInstance(state);
106 if ((NO_COLOR_MASK & le->invalidBits)||(state->isCacheOpen()))
107 le->reallySend(state, NO_COLOR_MASK);
108 }
109
113 static void sendOnlyDiffuseColor(SoState *state) {
114 SoGLLazyElement *le = getInstance(state);
115 if ((DIFFUSE_ONLY_MASK & le->invalidBits)||(state->isCacheOpen()))
116 le->reallySend(state, DIFFUSE_ONLY_MASK);
117 }
118
125 void sendDiffuseByIndex(int index) const;
126
130 void reset(SoState* state, uint32_t bitmask) const;
131
137 static SoGLLazyElement * getInstance(const SoState *state) {
138 return const_cast<SoGLLazyElement*>(state->getConstElement<SoGLLazyElement>());
139 }
140
141private:
142
144 virtual void commonInit();
145
147 virtual void init(SoState *state);
148
150 virtual SbBool matches(const SoElement *) const;
151
153 virtual SoElement* copyMatchInfo() const;
154
156 virtual void registerRedundantSet(SoState *, uint32_t bitmask);
157
158 private:
159
160 typedef SoGLLazyState GLLazyState;
161
162 // Initializes the SoGLLazyElement class
163 static void initClass();
164 static void exitClass();
165
166 // Sends indicated component(s) to GL:
167 // Only sends if value is not already in GL.
168 // note: has side effects, cannot really be const.
169 // however will not necessarily cause cache dependency.
170 void send(const SoState *state, uint32_t mask) const {
171 if ((mask & invalidBits)||(state->isCacheOpen()))
172 (const_cast<SoGLLazyElement*>(this))->reallySend(state, mask);
173 }
174
175 // Replace matches() for this element:
176 // matches "this" element GL or IV state with values in eltInState
177 SbBool lazyMatches(uint32_t checkGLFlag, uint32_t checkIVFlag,
178 const SoGLLazyElement *eltInState) {
179 if (checkGLFlag || checkIVFlag ||
180 ivState.transpType != eltInState->ivState.transpType)
181 return fullLazyMatches(checkGLFlag, checkIVFlag, eltInState);
182 else
183 return TRUE;
184 }
185
191 void setOverrideBlending(bool value){ m_overrideBlending = value; }
192
193 //
194 bool isColorMaterialMode() const;
195
197 const GLLazyState& getGLState() const;
198
199 // Replaces copyMatchInfo for this element:
200 // makes a GLLazyElement with some initialization.
201 // also initializes cacheSetBits to zero.
202 SoGLLazyElement *copyLazyMatchInfo(SoState *state) const;
203
204 // method that makes a copy of GL state at cache close().
205 // goes from state="this" to cacheGLState
206 // only copies if bitmask (GLSend of cache lazy element) is set.
207 void getCopyGL(SoGLLazyElement *cacheLazyElement,
208 SoGLLazyElement::GLLazyState& cacheGLState);
209
210 // method that copies GL state back into "this" element
211 // after cache has been called.
212 // only copies if bit in bitmask is set.
213 // also sets invalidBits to FALSE for these components.
214 void copyBackGL(SoGLLazyElement *cacheLazyElement,
215 SoGLLazyElement::GLLazyState& cacheGLState) {
216 if (cacheLazyElement->GLSendBits)
217 reallyCopyBackGL(cacheLazyElement->GLSendBits, cacheGLState);
218 }
219
220 // Send a packed color (not in state). Send transparency
221 // as stipple if necessary.
222 void sendVPPacked(SoState *state, const unsigned char *pcolor);
223
224 // Note: destructor is public, so cache can delete its copy.
225 virtual ~SoGLLazyElement();
226
227 void mergeCacheInfo(SoGLRenderCache * childCache,
228 SoGLRenderCache *parentCache,
229 uint32_t doSendFlag,
230 uint32_t checkIVFlag,
231 uint32_t checkGLFlag);
232
233 // Make copy of IV values into cacheLazyElement
234 void copyIVValues(uint32_t bitmask, SoGLLazyElement *cacheLazyElement);
235
236 //register a get() with the cache:
237 virtual void registerGetDependence(SoState *, uint32_t bitmask);
238
239 private:
240 // Make copy of GL values into cacheLazyElement
241 void copyGLValues(uint32_t bitmask, SoGLLazyElement *cacheLazyElement);
242
243 // non-inline send when something has to be sent:
244 void reallySend(const SoState *state, uint32_t bitmask);
245
246 // private version of lazyMatches, does actual work when needed:
247 SbBool fullLazyMatches(uint32_t checkGLFlag, uint32_t checkIVFlag,
248 const SoGLLazyElement* eltInState);
249
250 // Pack the current diffuse and transparency into an SoColorPacker
251 void packColors(SoColorPacker *cPacker);
252 void packColors2(SoColorPacker *cPacker);
253
254 // virtual set() methods that track GL state
255 // as well as inventor state
256 virtual void setDiffuseElt(SoNode *node, int32_t numColors,
257 const SbColor *colors,
258 SoColorPacker *cPacker);
259
260 virtual void setTranspElt(SoNode *node, int32_t numTrans,
261 const float *trans,
262 SoColorPacker *cPacker);
263
264 virtual void setTranspTypeElt(int32_t type);
265 virtual void setPatternFlagElt(SbBool flag);
266 virtual void setPackedElt(SoNode *node,
267 int32_t numColors,
268 const uint32_t *packedColors,
269 SoColorPacker *cPacker);
270
271 virtual void setAmbientElt(const SbColor *color);
272 virtual void setEmissiveElt(const SbColor *color);
273 virtual void setSpecularElt(const SbColor *color);
274 virtual void setShininessElt(float color);
275 virtual void setColorMaterialElt(SbBool value);
276 virtual void setBlendingElt(SbBool value);
277 virtual void setSmoothingElt(SbBool value);
278 virtual void setLightModelElt(SoState *, int32_t model);
279 virtual void setMaterialElt(SoNode *, uint32_t bitmask,
280 SoColorPacker *cPacker,
281 const SoMFColor &, const SoMFFloat &,
282 const SoMFColor &, const SoMFColor &,
283 const SoMFColor &, const SoMFFloat &);
284 virtual void setMaterialElt(SoNode *, uint32_t bitmask,
285 SoColorPacker *cPacker, SoMFColor *,
286 SoMFFloat *, SoMFColor *,
288 virtual void setLineWidthElt(float lineWidth);
289
290 //really does the copying of GL state (invoked by copyBackGL)
291 void reallyCopyBackGL(uint32_t bitmask, SoGLLazyElement::GLLazyState &);
292
293 // Copy of what has been sent to GL:
294 SoGLLazyElement::GLLazyState* glState;
295
296 // BitMap indicating what GL sends have been made:
297 uint32_t GLSendBits;
298
299
300 // Private storage associated with stipple patterns:
301 // Holds defined 32x32 bit stipple patterns. Each is defined as 32
302 // rows of 4 bytes (32 bits) each.
303 static u_char patterns[64+1][32 * 4];
304
305 // Indicates whether patterns were created and stored yet
306 static SbBool patternsCreated;
307
308 // Holds flags to indicate whether we defined a display list for
309 // the corresponding stipple pattern
310 static SbBool patternListDefined[64+1];
311
312 // Stores base display list index for patterns
313 static int patternListBase;
314
315 // Stores cache context in which display lists were created
316 static int patternListContext;
317
318 // Set to TRUE in getInstance()??? if a cache is currently being
319 // built, meaning we can't build a new display list
320 SbBool cacheOpen;
321
322 // Creates and sends the stipple pattern to GL
323 void sendStipple(const SoState *state, int transpIndex);
324
325 // Fills in "patterns" arrays with polygon stipples that simulate
326 // transparency levels, using a standard dither matrix
327 static void createPatterns();
328
329 // hold envvar OIV_NEW_STIPPLE_BEHAVIOR
330 static bool s_useNewStippleBehavior;
331
332 // Sends the line width to GL
333 void sendLineWidth(const SoState *state);
334
335 // All glstate's nodeid (*not* ivstate's nodeid) must
336 // be initialized with this value
337 static uint64_t GLSTATE_INVALID_NODEID;
338
339 // see SoPrefrences OIV_LINE_WIDTH var
340 static bool s_forceLineWidth;
341
343 bool m_overrideBlending;
344};
345
346#endif /* _SO_GL_LAZY_ELEMENT */
347
348
Color vector class.
Definition SbColor.h:82
Stores packed colors.
Abstract base class for all state elements.
Definition SoElement.h:102
Manages the GL state for the SoLazyElement.
static void sendAllMaterial(SoState *state)
Static send, always send top-of-stack.
void reset(SoState *state, uint32_t bitmask) const
Destroys knowledge of GL state.
virtual void push(SoState *state)
Overrides push() method to maintain GL state.
static void sendNoMaterial(SoState *state)
Static send, always send top-of-stack.
virtual void pop(SoState *state, const SoElement *prevTopElement)
Overrides pop() method to maintain GL state.
static SoGLLazyElement * getInstance(const SoState *state)
Returns the top (current) instance of the element in the state Note it does NOT cause cache dependenc...
void sendDiffuseByIndex(int index) const
Sends diffuse color and transparency, by index.
static void sendOnlyDiffuseColor(SoState *state)
Static send, always send top-of-stack.
Manages several properties that need to be lazily tracked for OpenGL.
@ ALL_MASK
All masks.
@ PATTERN_MASK
Pattern mask.
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
const T * getConstElement() const
Returns the top (read-only) instance of the given element.
Definition SoState.h:112
int SbBool
Boolean type.
Definition SbBase.h:87