Coin Logo http://www.sim.no/
http://www.coin3d.org/

SoLazyElement.h
1 #ifndef COIN_SOLAZYELEMENT_H
2 #define COIN_SOLAZYELEMENT_H
3 
4 /**************************************************************************\
5  *
6  * This file is part of the Coin 3D visualization library.
7  * Copyright (C) by Kongsberg Oil & Gas Technologies.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * ("GPL") version 2 as published by the Free Software Foundation.
12  * See the file LICENSE.GPL at the root directory of this source
13  * distribution for additional information about the GNU GPL.
14  *
15  * For using Coin with software that can not be combined with the GNU
16  * GPL, and for taking advantage of the additional benefits of our
17  * support services, please contact Kongsberg Oil & Gas Technologies
18  * about acquiring a Coin Professional Edition License.
19  *
20  * See http://www.coin3d.org/ for more information.
21  *
22  * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
23  * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24  *
25 \**************************************************************************/
26 
27 #include <Inventor/elements/SoElement.h>
28 #include <Inventor/elements/SoSubElement.h>
29 #include <Inventor/SbColor.h>
30 
31 class SoMFFloat;
32 class SoMFColor;
33 class SoColorPacker;
34 class SoLazyElementP;
35 class SoGLImage;
36 
37 #define SO_LAZY_SHINY_THRESHOLD 0.005f
38 
39 
40 class COIN_DLL_API SoLazyElement : public SoElement {
41  typedef SoElement inherited;
42 
43  SO_ELEMENT_HEADER(SoLazyElement);
44 
45 public:
46  static void initClass();
47 protected:
48  ~SoLazyElement();
49 public:
50  enum cases {
51  LIGHT_MODEL_CASE = 0,
52  COLOR_MATERIAL_CASE,
53  DIFFUSE_CASE,
54  AMBIENT_CASE,
55  EMISSIVE_CASE,
56  SPECULAR_CASE,
57  SHININESS_CASE,
58  BLENDING_CASE,
59  TRANSPARENCY_CASE,
60  VERTEXORDERING_CASE,
61  TWOSIDE_CASE,
62  CULLING_CASE,
63  SHADE_MODEL_CASE,
64  GLIMAGE_CASE,
65  ALPHATEST_CASE,
66  LAZYCASES_LAST // must be last
67  };
68  enum masks{
69  LIGHT_MODEL_MASK = 1 << LIGHT_MODEL_CASE, // 0x0001
70  COLOR_MATERIAL_MASK = 1 << COLOR_MATERIAL_CASE, // 0x0002
71  DIFFUSE_MASK = 1 << DIFFUSE_CASE, // 0x0004
72  AMBIENT_MASK = 1 << AMBIENT_CASE, // 0x0008
73  EMISSIVE_MASK = 1<<EMISSIVE_CASE, // 0x0010
74  SPECULAR_MASK = 1 << SPECULAR_CASE, // 0x0020
75  SHININESS_MASK = 1 << SHININESS_CASE, // 0x0040
76  TRANSPARENCY_MASK = 1 << TRANSPARENCY_CASE, // 0x0080
77  BLENDING_MASK = 1 << BLENDING_CASE, // 0x0100
78  VERTEXORDERING_MASK = 1 << VERTEXORDERING_CASE, // 0x0200
79  TWOSIDE_MASK = 1 << TWOSIDE_CASE, // 0x0400
80  CULLING_MASK = 1 << CULLING_CASE, // 0x0800
81  SHADE_MODEL_MASK = 1 << SHADE_MODEL_CASE, // 0x1000
82  GLIMAGE_MASK = 1 << GLIMAGE_CASE, // 0x2000
83  ALPHATEST_MASK = 1 << ALPHATEST_CASE, // 0x4000
84  ALL_MASK = (1 << LAZYCASES_LAST)-1
85  };
86 
87  enum internalMasks{
88  OTHER_COLOR_MASK = AMBIENT_MASK|EMISSIVE_MASK|SPECULAR_MASK|SHININESS_MASK,
89  ALL_COLOR_MASK = OTHER_COLOR_MASK|DIFFUSE_MASK,
90  NO_COLOR_MASK = ALL_MASK & (~ALL_COLOR_MASK),
91  ALL_BUT_DIFFUSE_MASK = ALL_MASK &(~ DIFFUSE_MASK),
92  DIFFUSE_ONLY_MASK = ALL_MASK &(~ OTHER_COLOR_MASK)
93  };
94 
95  enum LightModel {
96  BASE_COLOR,
97  PHONG
98  };
99 
100  enum VertexOrdering {
101  CW,
102  CCW
103  };
104 
105  virtual void init(SoState *state);
106  virtual void push(SoState *state);
107  virtual SbBool matches(const SoElement *) const;
108  virtual SoElement *copyMatchInfo(void) const;
109 
110  static void setToDefault(SoState * state);
111  static void setDiffuse(SoState * state, SoNode * node, int32_t numcolors,
112  const SbColor * colors, SoColorPacker * packer);
113  static void setTransparency(SoState *state, SoNode *node, int32_t numvalues,
114  const float * transparency, SoColorPacker * packer);
115  static void setPacked(SoState * state, SoNode * node,
116  int32_t numcolors, const uint32_t * colors,
117  const SbBool packedtransparency = FALSE);
118  static void setColorIndices(SoState *state, SoNode *node,
119  int32_t numindices, const int32_t *indices);
120  static void setAmbient(SoState *state, const SbColor * color);
121  static void setEmissive(SoState *state, const SbColor * color);
122  static void setSpecular(SoState *state, const SbColor * color);
123  static void setShininess(SoState *state, float value);
124  static void setColorMaterial(SoState *state, SbBool value);
125  static void enableBlending(SoState *state,
126  int sfactor,
127  int dfactor);
128  static void enableSeparateBlending(SoState *state,
129  int sfactor,
130  int dfactor,
131  int alpha_sfactor,
132  int alpha_dfactor);
133 
134  static void disableBlending(SoState * state);
135  static void setLightModel(SoState *state, const int32_t model);
136  static void setVertexOrdering(SoState * state, VertexOrdering ordering);
137  static void setBackfaceCulling(SoState * state, SbBool onoff);
138  static void setTwosideLighting(SoState * state, SbBool onoff);
139  static void setShadeModel(SoState * state, SbBool flatshading);
140  static void setGLImageId(SoState * state, uint32_t glimageid, SbBool alphatest);
141  static void setAlphaTest(SoState * state, SbBool onoff);
142 
143  static const SbColor & getDiffuse(SoState* state, int index);
144  static float getTransparency(SoState*, int index);
145  static const uint32_t * getPackedColors(SoState*);
146  static const int32_t * getColorIndices(SoState*);
147  static int32_t getColorIndex(SoState*, int num);
148  static const SbColor & getAmbient(SoState *);
149  static const SbColor & getEmissive(SoState *);
150  static const SbColor & getSpecular(SoState *);
151  static float getShininess(SoState*);
152  static SbBool getColorMaterial(SoState*);
153  static SbBool getBlending(SoState *,
154  int & sfactor, int & dfactor);
155  static SbBool getAlphaBlending(SoState *,
156  int & sfactor, int & dfactor);
157 
158  static int32_t getLightModel(SoState*);
159  static SbBool getAlphaTest(SoState * state);
160 
161  int32_t getNumDiffuse(void) const;
162  int32_t getNumTransparencies(void) const;
163  int32_t getNumColorIndices(void) const;
164  SbBool isPacked(void) const;
165  SbBool isTransparent(void) const;
166  static SoLazyElement * getInstance(SoState *state);
167  static float getDefaultAmbientIntensity(void);
168 
169  static SbColor getDefaultDiffuse(void);
170  static SbColor getDefaultAmbient(void);
171  static SbColor getDefaultSpecular(void);
172  static SbColor getDefaultEmissive(void);
173  static float getDefaultShininess(void);
174  static uint32_t getDefaultPacked(void);
175  static float getDefaultTransparency(void);
176  static int32_t getDefaultLightModel(void);
177  static int32_t getDefaultColorIndex(void);
178 
179  static void setMaterials(SoState * state, SoNode *node, uint32_t bitmask,
180  SoColorPacker * cPacker,
181  const SbColor * diffuse,
182  const int numdiffuse,
183  const float * transp,
184  const int numtransp,
185  const SbColor & ambient,
186  const SbColor & emissive,
187  const SbColor & specular,
188  const float shininess,
189  const SbBool istransparent);
190 
191  static SoLazyElement * getWInstance(SoState *state);
192 
193  const uint32_t * getPackedPointer(void) const;
194  const SbColor * getDiffusePointer(void) const;
195  const int32_t * getColorIndexPointer(void) const;
196 
197  const float * getTransparencyPointer(void) const;
198  static void setTransparencyType(SoState * state, int32_t type);
199 
200 protected:
201 
202  struct COIN_DLL_API CoinState {
203  SbColor ambient;
204  SbColor specular;
205  SbColor emissive;
206  float shininess;
207  SbBool blending;
208  int blend_sfactor;
209  int blend_dfactor;
210  int alpha_blend_sfactor;
211  int alpha_blend_dfactor;
212  int32_t lightmodel;
213  SbBool packeddiffuse;
214  int32_t numdiffuse;
215  int32_t numtransp;
216  const SbColor * diffusearray;
217  const uint32_t * packedarray;
218  const float * transparray;
219  const int32_t * colorindexarray;
220  int32_t transptype;
221  SbBool istransparent;
222  uint32_t diffusenodeid;
223  uint32_t transpnodeid;
224  int32_t stipplenum;
225  VertexOrdering vertexordering;
226  SbBool twoside;
227  SbBool culling;
228  SbBool flatshading;
229  uint32_t glimageid;
230  SoGLImage * glimage;
231  SbBool alphatest;
232  SbBool glimageusealphatest;
233  uint32_t reserved[4];
234  } coinstate;
235 
236 protected:
237  virtual void lazyDidSet(uint32_t mask);
238  virtual void lazyDidntSet(uint32_t mask);
239 
240  virtual void setDiffuseElt(SoNode*, int32_t numcolors,
241  const SbColor * colors, SoColorPacker * packer);
242  virtual void setPackedElt(SoNode * node, int32_t numcolors,
243  const uint32_t * colors, const SbBool packedtransparency);
244  virtual void setColorIndexElt(SoNode * node, int32_t numindices,
245  const int32_t * indices);
246  virtual void setTranspElt(SoNode * node, int32_t numtransp,
247  const float * transp, SoColorPacker * packer);
248 
249  virtual void setTranspTypeElt(int32_t type);
250  virtual void setAmbientElt(const SbColor* color);
251  virtual void setEmissiveElt(const SbColor* color);
252  virtual void setSpecularElt(const SbColor* color);
253  virtual void setShininessElt(float value);
254  virtual void setColorMaterialElt(SbBool value);
255  virtual void enableBlendingElt(int sfactor, int dfactor, int alpha_sfactor, int alpha_dfactor);
256  virtual void disableBlendingElt(void);
257  virtual void setLightModelElt(SoState *state, int32_t model);
258  virtual void setMaterialElt(SoNode * node, uint32_t bitmask,
259  SoColorPacker * packer,
260  const SbColor * diffuse, const int numdiffuse,
261  const float * transp, const int numtransp,
262  const SbColor & ambient,
263  const SbColor & emissive,
264  const SbColor & specular,
265  const float shininess,
266  const SbBool istransparent);
267  virtual void setVertexOrderingElt(VertexOrdering ordering);
268  virtual void setBackfaceCullingElt(SbBool onoff);
269  virtual void setTwosideLightingElt(SbBool onoff);
270  virtual void setShadeModelElt(SbBool flatshading);
271  virtual void setGLImageIdElt(uint32_t glimageid, SbBool alphatest);
272  virtual void setAlphaTestElt(SbBool onoff);
273 
274 private:
275  SoLazyElementP * pimpl; // for future use
276 
277 };
278 
279 class COIN_DLL_API SoColorPacker {
280 public:
281  SoColorPacker(void);
282  ~SoColorPacker();
283 
284  uint32_t * getPackedColors(void) const {
285  return this->array;
286  }
287  SbBool diffuseMatch(const uint32_t nodeid) const {
288  return nodeid == this->diffuseid;
289  }
290  SbBool transpMatch(const uint32_t nodeid) const {
291  return nodeid == this->transpid;
292  }
293  void setNodeIds(const uint32_t diffuse, const uint32_t transp) {
294  this->diffuseid = diffuse;
295  this->transpid = transp;
296  }
297  int32_t getSize(void) const {
298  return this->arraysize;
299  }
300  void reallocate(const int32_t size);
301 
302  uint32_t getDiffuseId(void) const {
303  return this->diffuseid;
304  }
305  uint32_t getTranspId(void) const {
306  return this->transpid;
307  }
308 private:
309  uint32_t transpid;
310  uint32_t diffuseid;
311  uint32_t * array;
312  int32_t arraysize;
313 };
314 
315 #endif // !COIN_SOLAZYELEMENT_H
The SoMFFloat class is a container for floating point values.This field is used where nodes...
Definition: SoMFFloat.h:30
The SbColor class contains the red, green and blue components which make up a color value...
Definition: SbColor.h:30
The SoMFColor class is a container for SbColor values.This field is used where nodes, engines or other field containers needs to store multiple color values (i.e. &quot;Red Green Blue&quot; triplets).
Definition: SoMFColor.h:31
static void initClass(void)
Definition: SoElement.cpp:507
virtual SbBool matches(const SoElement *element) const =0
Definition: SoElement.cpp:609
virtual void push(SoState *state)
Definition: SoElement.cpp:570
The SoNode class is the base class for nodes used in scene graphs.Coin is a retained mode 3D visualiz...
Definition: SoNode.h:47
SoElement is the abstract base class for all elements.
Definition: SoElement.h:34
The SoState class manages the Coin scenegraph traversal state data.The SoState class is used by actio...
Definition: SoState.h:35
virtual void init(SoState *state)
Definition: SoElement.cpp:553
virtual SoElement * copyMatchInfo(void) const =0
The SoGLImage class is used to handle OpenGL 2D/3D textures.
Definition: SoGLImage.h:44
The SoLazyElement class is used to handle material and shape properties.So[GL]LazyElement is...
Definition: SoLazyElement.h:40

Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.

Generated on Fri Sep 9 2016 for Coin by Doxygen 1.8.5.