Open Inventor Reference
SoGLLazyElement.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37
38/*
39 * Copyright (C) 1990,91 Silicon Graphics, Inc.
40 *
41 _______________________________________________________________________
42 ______________ S I L I C O N G R A P H I C S I N C . ____________
43 |
44 | $Revision: 1.2 $
45 |
46 | Description:
47 | This file defines the SoGLLazyElement class.
48 |
49 | Author(s) : Alan Norton, Gavin Bell
50 |
51 ______________ S I L I C O N G R A P H I C S I N C . ____________
52 _______________________________________________________________________
53 */
54
55#ifndef _SO_GL_LAZY_ELEMENT
56#define _SO_GL_LAZY_ELEMENT
57
60class SoGLRenderCache;
61class SoVBO;
62
75
77
79
80 public:
82 virtual void init(SoState *state);
83
85 virtual void push(SoState *state);
86 virtual void pop(SoState *state, const SoElement *prevTopElement);
87
89 static void sendAllMaterial(SoState *state)
90 {SoGLLazyElement *le = getInstance(state);
91 if ((le->invalidBits)||(state->isCacheOpen()))
92 le->reallySend(state, ALL_MASK);}
93
94 static void sendNoMaterial(SoState *state)
95 {SoGLLazyElement *le = getInstance(state);
96 if ((NO_COLOR_MASK & le->invalidBits)||(state->isCacheOpen()))
97 le->reallySend(state, NO_COLOR_MASK);}
98
99 static void sendOnlyDiffuseColor(SoState *state)
100 {SoGLLazyElement *le = getInstance(state);
101 if ((DIFFUSE_ONLY_MASK & le->invalidBits)||(state->isCacheOpen()))
102 le->reallySend(state, DIFFUSE_ONLY_MASK);}
103
108 void sendDiffuseByIndex(int index) const;
109
111 void reset(SoState* state, uint32_t bitmask) const;
112
116 static SoGLLazyElement * getInstance(const SoState *state)
117 {return (SoGLLazyElement *)
118 (state->getConstElement(classStackIndex));}
119
120 SoINTERNAL public:
122 static void initClass();
123
128 void send(const SoState *state, uint32_t mask) const
129 {if ((mask & invalidBits)||(state->isCacheOpen()))
130 ((SoGLLazyElement*)(this))->reallySend(state, mask);}
131
134 virtual bool matches(const SoElement *) const
135 {return FALSE;}
136 virtual SoElement *copyMatchInfo() const
137 {return NULL;}
138
141 bool lazyMatches(uint32_t checkGLFlag, uint32_t checkIVFlag,
142 const SoGLLazyElement* eltInState){
143 if (checkGLFlag || checkIVFlag ||
144 (ivState.transpType != eltInState->ivState.transpType))
145 return (fullLazyMatches (checkGLFlag, checkIVFlag, eltInState));
146 else return(TRUE);
147 }
148
150 typedef struct {
153 float GLAmbient[4];
154 float GLEmissive[4];
155 float GLSpecular[4];
161 } GLLazyState;
162
167
171 void getCopyGL(SoGLLazyElement* cacheLazyElement,
172 SoGLLazyElement::GLLazyState& cacheGLState);
173
178 void copyBackGL(SoGLLazyElement* cacheLazyElement,
179 SoGLLazyElement::GLLazyState& cacheGLState)
180 { if (cacheLazyElement->GLSendBits)
181 reallyCopyBackGL(cacheLazyElement->GLSendBits, cacheGLState);}
182
185 void sendVPPacked(SoState* state, const unsigned char* pcolor);
186
189
191 parentCache, uint32_t doSendFlag, uint32_t checkIVFlag,
192 uint32_t checkGLFlag);
193
195 void updateColorVBO(SoState* state, SoVBO* vbo);
196
197 private:
199 void copyGLValues(uint32_t bitmask, SoGLLazyElement* cacheLazyElement);
201 void copyIVValues(uint32_t bitmask, SoGLLazyElement* cacheLazyElement);
202
204 void reallySend(const SoState *state, uint32_t bitmask);
205
207 bool fullLazyMatches(uint32_t checkGLFlag, uint32_t checkIVFlag,
208 const SoGLLazyElement* eltInState);
209
211 void packColors(SoColorPacker *cPacker);
212
215 virtual void setDiffuseElt(SoNode *node, int32_t numColors,
216 const SbColor *colors, SoColorPacker *cPacker);
217
218 virtual void setTranspElt(SoNode *node, int32_t numTrans,
219 const float *trans, SoColorPacker *cPacker);
220
221 virtual void setTranspTypeElt(int32_t type);
222 virtual void setPackedElt( SoNode *node,
223 int32_t numColors, const uint32_t *packedColors);
224
225 virtual void setAmbientElt(const SbColor* color);
226 virtual void setEmissiveElt( const SbColor* color);
227 virtual void setSpecularElt(const SbColor* color);
228 virtual void setShininessElt( float color);
229 virtual void setColorMaterialElt( bool value);
230 virtual void setBlendingElt( bool value);
231 virtual void setLightModelElt(SoState *, int32_t model);
232 virtual void setMaterialElt(SoNode *, uint32_t bitmask,
233 SoColorPacker *cPacker, const SoMFColor&,
234 const SoMFFloat&, const SoMFColor&,
235 const SoMFColor&, const SoMFColor&, const SoMFFloat&);
236
238 virtual void registerRedundantSet(SoState *, uint32_t bitmask);
240 virtual void registerGetDependence(SoState *, uint32_t bitmask);
241
243 void reallyCopyBackGL(uint32_t bitmask, SoGLLazyElement::GLLazyState& );
244
248
250 uint32_t GLSendBits;
251
255 static u_char patterns[64+1][32 * 4];
256
258 static bool patternsCreated;
259
262 static bool patternListDefined[64+1];
263
265 static int patternListBase;
266
268 static int patternListContext;
269
272 bool cacheOpen;
273
275 void sendStipple(const SoState *state, int transpIndex);
276
279 static void createPatterns();
280};
281
282#endif /* _SO_GL_LAZY_ELEMENT */
#define SoEXTENDER
Provide inline template functions for abs, swap, min, max, and clamp.
Definition SbBasic.h:154
#define TRUE
Definition SbBasic.h:76
#define FALSE
Definition SbBasic.h:79
#define SoINTERNAL
Definition SbBasic.h:155
size_t SbNodeIdType
Type of unique ids of SoNode, used in the notification/change detection handling.
Definition SbBasic.h:90
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition SbSystem.h:77
unsigned int uint32_t
Definition SbTypeDefs.h:44
signed int int32_t
Definition SbTypeDefs.h:43
#define SO_ELEMENT_HEADER(className)
This one is for non-abstract element classes.
Color vector class.
Definition SbColor.h:84
This class is meant to be used by all property nodes that set either a diffuse color or transparency ...
This is the abstract base class for all state elements.
Definition SoElement.h:96
Element that manages the GL state for the SoLazyElement.
static void sendAllMaterial(SoState *state)
Static sends, always send top-of-stack. Intended for extender use.
void reset(SoState *state, uint32_t bitmask) const
Destroy knowledge of GL state.
virtual void push(SoState *state)
Override push() and pop() methods to maintain GL state.
void copyBackGL(SoGLLazyElement *cacheLazyElement, SoGLLazyElement::GLLazyState &cacheGLState)
method that copies GL state back into "this" element after cache has been called.
virtual SoElement * copyMatchInfo() const
Create a copy that we can put in a cache used list and call matches() on later.
static void sendNoMaterial(SoState *state)
SoGLLazyElement * copyLazyMatchInfo(SoState *state)
Replaces copyMatchInfo for this element: makes a GLLazyElement with some initialization.
void updateColorVBO(SoState *state, SoVBO *vbo)
Update the passed VBO with the packed colors if the diffuse/transparency node ids do not match.
virtual void pop(SoState *state, const SoElement *prevTopElement)
static SoGLLazyElement * getInstance(const SoState *state)
Return the top (current) instance of the element in the state Note it does NOT cause cache dependency...
void sendVPPacked(SoState *state, const unsigned char *pcolor)
Send a packed color (not in state).
virtual ~SoGLLazyElement()
Note: destructor is public, so cache can delete its copy.
virtual bool matches(const SoElement *) const
note: matches, copyMatchinfo not used by this element.
virtual void init(SoState *state)
Initializes element.
void send(const SoState *state, uint32_t mask) const
Sends indicated component(s) to GL: Only sends if value is not already in GL.
void sendDiffuseByIndex(int index) const
Send diffuse color and transparency, by index Included for compatibility with SoMaterialBundle To be ...
void mergeCacheInfo(SoGLRenderCache *childCache, SoGLRenderCache *parentCache, uint32_t doSendFlag, uint32_t checkIVFlag, uint32_t checkGLFlag)
static void initClass()
Initializes the SoGLLazyElement class.
bool lazyMatches(uint32_t checkGLFlag, uint32_t checkIVFlag, const SoGLLazyElement *eltInState)
Replace matches() for this element: matches "this" element GL or IV state with values in eltInState.
void getCopyGL(SoGLLazyElement *cacheLazyElement, SoGLLazyElement::GLLazyState &cacheGLState)
method that makes a copy of GL state at cache close().
static void sendOnlyDiffuseColor(SoState *state)
Element that manages several properties such as colors, that need to be lazily tracked by GL.
virtual void registerRedundantSet(SoState *, uint32_t)
method to tell the cache that a redundant set was issued.
ivStateStruct ivState
static SoLazyElement * getInstance(SoState *state)
Returns the top (current) instance of the element in the state Note that the cache dependencies assoc...
virtual void registerGetDependence(SoState *, uint32_t)
method to register dependence due to get().
uint32_t invalidBits
This is more convenient here, but might logically be kept with SoGLLazyElement.
Multiple-value field containing any number of RGB colors stored as three floats.
Definition SoMFColor.h:88
Multiple-value field containing any number of floating point values.
Definition SoMFFloat.h:82
Abstract base class for all database nodes.
Definition SoNode.h:103
An SoState collects and holds state while traversing a scene graph.
Definition SoState.h:82
const SoElement * getConstElement(int stackIndex) const
Returns the top (read-only) instance of the given element stack.
Definition SoState.h:100
bool isCacheOpen() const
Definition SoState.h:129
SoVBO is used to manage OpenGL vertex buffer objects.
Definition SoVBO.h:52
provide a public typedef for GLLazyState, so that GLRenderCache can use it: