Coin Logo http://www.coin3d.org/
http://www.kongsberg.com/kogt/

SoGLLazyElement.h
1 #ifndef COIN_SOGLLAZYELEMENT_H
2 #define COIN_SOGLLAZYELEMENT_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <Inventor/elements/SoLazyElement.h>
37 #include <Inventor/C/glue/gl.h>
38 
39 class SoGLRenderCache;
40 class SoGLLazyElementP;
41 class SoVBO;
42 
43 class COIN_DLL_API SoGLLazyElement : public SoLazyElement {
44  typedef SoLazyElement inherited;
45 
46  SO_ELEMENT_HEADER(SoGLLazyElement);
47 
48 public:
49  static void initClass();
50 protected:
51  ~SoGLLazyElement();
52 public:
53 
54  virtual void init(SoState *state);
55  virtual void push(SoState *state);
56  virtual void pop(SoState *state, const SoElement * prevtopelement);
57 
58  static void sendAllMaterial(SoState * state);
59  static void sendNoMaterial(SoState * state);
60  static void sendOnlyDiffuseColor(SoState * state);
61  static void sendLightModel(SoState * state, const int32_t model);
62  static void sendPackedDiffuse(SoState * state, const uint32_t diffuse);
63  static void sendFlatshading(SoState * state, const SbBool onoff);
64  static void sendVertexOrdering(SoState * state, const VertexOrdering ordering);
65  static void sendTwosideLighting(SoState * state, const SbBool onoff);
66  static void sendBackfaceCulling(SoState * state, const SbBool onoff);
67 
68  void sendDiffuseByIndex(const int index) const;
69  static SbBool isColorIndex(SoState *state);
70  static SoGLLazyElement * getInstance(const SoState *state);
71  void send(const SoState *state, uint32_t mask) const;
72 
73  void sendVPPacked(SoState* state, const unsigned char* pcolor);
74 
75  void reset(SoState* state, uint32_t bitmask) const;
76 
77  typedef struct COIN_DLL_API {
78  uint32_t cachebitmask;
79  uint32_t diffuse;
80  SbColor ambient;
81  SbColor emissive;
82  SbColor specular;
83  float shininess;
84  int32_t lightmodel;
85  int32_t blending;
86  int32_t blend_sfactor;
87  int32_t blend_dfactor;
88  int32_t alpha_blend_sfactor;
89  int32_t alpha_blend_dfactor;
90  int32_t stipplenum;
91  int32_t vertexordering;
92  int32_t culling;
93  int32_t twoside;
94  int32_t flatshading;
95  int32_t alphatestfunc;
96  float alphatestvalue;
97  uint32_t diffusenodeid;
98  uint32_t transpnodeid;
99  uint32_t reserved[4];
100  } GLState;
101 
102  virtual void setDiffuseElt(SoNode*, int32_t numcolors,
103  const SbColor * colors, SoColorPacker * packer);
104  virtual void setPackedElt(SoNode * node, int32_t numcolors,
105  const uint32_t * colors, const SbBool packedtransparency);
106  virtual void setColorIndexElt(SoNode * node, int32_t numindices,
107  const int32_t * indices);
108  virtual void setTranspElt(SoNode * node, int32_t numtransp,
109  const float * transp, SoColorPacker * packer);
110 
111  virtual void setTranspTypeElt(int32_t type);
112  virtual void setAmbientElt(const SbColor* color);
113  virtual void setEmissiveElt(const SbColor* color);
114  virtual void setSpecularElt(const SbColor* color);
115  virtual void setShininessElt(float value);
116  virtual void setColorMaterialElt(SbBool value);
117  virtual void enableBlendingElt(int sfactor, int dfactor, int alpha_sfactor, int alpha_dfactor);
118  virtual void disableBlendingElt(void);
119  virtual void setLightModelElt(SoState *state, int32_t model);
120  virtual void setMaterialElt(SoNode * node, uint32_t bitmask,
121  SoColorPacker * packer,
122  const SbColor * diffuse, const int numdiffuse,
123  const float * transp, const int numtransp,
124  const SbColor & ambient,
125  const SbColor & emissive,
126  const SbColor & specular,
127  const float shininess,
128  const SbBool istransparent);
129  virtual void setVertexOrderingElt(VertexOrdering ordering);
130  virtual void setBackfaceCullingElt(SbBool onoff);
131  virtual void setTwosideLightingElt(SbBool onoff);
132  virtual void setShadeModelElt(SbBool flatshading);
133  virtual void setAlphaTestElt(int func, float value);
134 
135  static void beginCaching(SoState * state,
136  SoGLLazyElement::GLState * prestate,
137  SoGLLazyElement::GLState * poststate);
138  static void endCaching(SoState * state);
139 
140  static SbBool preCacheCall(const SoState * state, const SoGLLazyElement::GLState * prestate);
141  static void postCacheCall(const SoState * state, const SoGLLazyElement::GLState * poststate);
142 
143  static void mergeCacheInfo(SoState * state,
144  SoGLLazyElement::GLState * childprestate,
145  SoGLLazyElement::GLState * childpoststate);
146 
147  void updateColorVBO(SoVBO * vbo);
148 
149 protected:
150  virtual void lazyDidSet(uint32_t mask);
151  virtual void lazyDidntSet(uint32_t mask);
152 
153 private:
154  void sendPackedDiffuse(const uint32_t diffuse) const;
155  void sendAmbient(const SbColor & color) const;
156  void sendEmissive(const SbColor & color) const;
157  void sendSpecular(const SbColor & specular) const;
158  void sendShininess(const float shininess) const;
159  void sendTransparency(const int stipplenum) const;
160  void enableBlending(const int sfactor, const int dfactor) const;
161  void enableSeparateBlending(const cc_glglue * glue,
162  const int sfactor, const int dfactor,
163  const int alpha_sfactor, const int alpha_dfactor) const;
164  void disableBlending(void) const;
165 
166  void sendLightModel(const int32_t model) const;
167  void sendFlatshading(const SbBool onoff) const;
168  void sendVertexOrdering(const VertexOrdering ordering) const;
169  void sendTwosideLighting(const SbBool onoff) const;
170  void sendBackfaceCulling(const SbBool onoff) const;
171  void sendAlphaTest(int func, float value) const;
172  void initGL(void);
173  void packColors(SoColorPacker * packer) const;
174 
175  mutable uint32_t didsetbitmask;
176  mutable uint32_t didntsetbitmask;
177  mutable uint32_t cachebitmask;
178  mutable uint32_t opencacheflags;
179 
180  mutable GLState glstate;
181  GLState * postcachestate;
182  GLState * precachestate;
183  SbBool colorindex;
184  mutable SoColorPacker * colorpacker;
185  mutable const uint32_t * packedpointer;
186  uint32_t transpmask;
187  SoState * state;
188  SoGLLazyElementP * pimpl; // for future use
189 };
190 
191 #endif // !COIN_SOGLLAZYELEMENT_H
The SbColor class contains the red, green and blue components which make up a color value...
Definition: SbColor.h:39
The SoNode class is the base class for nodes used in scene graphs.Coin is a retained mode 3D visualiz...
Definition: SoNode.h:56
SoElement is the abstract base class for all elements.
Definition: SoElement.h:43
virtual void push(SoState *state)
Definition: SoLazyElement.cpp:196
The SoState class manages the Coin scenegraph traversal state data.The SoState class is used by actio...
Definition: SoState.h:44
The SoGLLazyElement class is meant to optimize GL rendering.This is just a wrap-around implementation...
Definition: SoGLLazyElement.h:43
static void initClass()
Definition: SoLazyElement.cpp:132
virtual void init(SoState *state)
Definition: SoLazyElement.cpp:161
The SoLazyElement class is used to handle material and shape properties.So[GL]LazyElement is...
Definition: SoLazyElement.h:48
The SoGLRenderCache class is used to cache OpenGL calls.
Definition: SoGLRenderCache.h:43
virtual void pop(SoState *state, const SoElement *prevTopElement)
Definition: SoElement.cpp:584

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

Generated for Coin by Doxygen