1 /**************************************************************************\
2  * Copyright (c) Kongsberg Oil & Gas Technologies AS
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32 
33 /*!
34   \class SoGLShapeHintsElement Inventor/elements/SoGLShapeHintsElement.h
35   \brief The SoGLShapeHintsElement class is yet to be documented.
36 
37   \ingroup elements
38 
39   FIXME: write doc.
40 */
41 
42 //
43 // handling of cases (from the original oiv man-pages):
44 //
45 // 1) ordered, solid   :   backface culling, ! twoside lighting
46 // 2) ordered, ! solid : ! backface culling,   twoside lighting
47 // 3) ! ordered        : ! backface culling, ! twoside lighting
48 //
49 // (this table of rendering rules is duplicated in the SoShapeHints
50 // classdoc)
51 
52 //
53 // I find this strategy quite odd. My gut-feeling says that
54 // when vertexordering is unknown, two-side-lighting should be
55 // enabled, since it will be difficult to know if a normal
56 // points in or out of a polygon...
57 //
58 
59 //
60 // nodes with automatically generated normals should probably
61 // force two-side lighting when vertexordering is unknown, since
62 // it is impossible to know if normals are pointing in or out.
63 //
64 // use SoGLShapeHintsElement::forceSend(twoside) for this purpose
65 //
66 
67 #include <Inventor/elements/SoGLShapeHintsElement.h>
68 #include <Inventor/elements/SoGLLazyElement.h>
69 
70 
71 #ifdef HAVE_CONFIG_H
72 #include <config.h>
73 #endif // HAVE_CONFIG_H
74 
75 #include <Inventor/system/gl.h>
76 
77 #include <cassert>
78 
79 SO_ELEMENT_SOURCE(SoGLShapeHintsElement);
80 
81 /*!
82   This static method initializes static data for the
83   SoGLShapeHintsElement class.
84 */
85 
86 void
initClass(void)87 SoGLShapeHintsElement::initClass(void)
88 {
89   SO_ELEMENT_INIT_CLASS(SoGLShapeHintsElement, inherited);
90 }
91 
92 /*!
93   The destructor.
94 */
95 
~SoGLShapeHintsElement(void)96 SoGLShapeHintsElement::~SoGLShapeHintsElement(void)
97 {
98 }
99 
100 //! FIXME: write doc.
101 
102 void
init(SoState * stateptr)103 SoGLShapeHintsElement::init(SoState * stateptr)
104 {
105   inherited::init(stateptr);
106   this->state = stateptr;
107 }
108 
109 //! FIXME: write doc.
110 
111 void
push(SoState * stateptr)112 SoGLShapeHintsElement::push(SoState * stateptr)
113 {
114   inherited::push(stateptr);
115   SoGLShapeHintsElement * prev =
116     (SoGLShapeHintsElement *) this->getNextInStack();
117   this->state = prev->state;
118 }
119 
120 //! FIXME: write doc.
121 
122 void
pop(SoState * stateptr,const SoElement * prevTopElement)123 SoGLShapeHintsElement::pop(SoState * stateptr,
124                            const SoElement * prevTopElement)
125 {
126   inherited::pop(stateptr, prevTopElement);
127 }
128 
129 //! FIXME: write doc.
130 
131 void
setElt(VertexOrdering vertexOrderingarg,ShapeType shapeTypearg,FaceType faceTypearg)132 SoGLShapeHintsElement::setElt(VertexOrdering vertexOrderingarg,
133                               ShapeType shapeTypearg,
134                               FaceType faceTypearg)
135 {
136   inherited::setElt(vertexOrderingarg, shapeTypearg, faceTypearg);
137   // do nothing since GL stuff is handled by SoGLLazyElement
138 }
139 
140 /*!
141   Update gl state. Use this is you only want to modify the
142   twoside lighting feature.
143 */
144 
145 void
forceSend(SoState * const state,const SbBool twoside)146 SoGLShapeHintsElement::forceSend(SoState * const state,
147                                  const SbBool twoside)
148 {
149   SoGLLazyElement::sendTwosideLighting(state, twoside);
150 }
151 
152 /*!
153   Update GL state. Use this if you don't care about the two-side
154   lighting state.
155 */
156 
157 void
forceSend(SoState * const state,const SbBool ccw,const SbBool cull)158 SoGLShapeHintsElement::forceSend(SoState * const state,
159                                  const SbBool ccw, const SbBool cull)
160 {
161   SoGLLazyElement::sendVertexOrdering(state, ccw ? SoLazyElement::CCW : SoLazyElement::CW);
162   SoGLLazyElement::sendBackfaceCulling(state, cull);
163 }
164 
165 //! FIXME: write doc.
166 
167 void
forceSend(SoState * const state,const SbBool ccw,const SbBool cull,const SbBool twoside)168 SoGLShapeHintsElement::forceSend(SoState * const state,
169                                  const SbBool ccw, const SbBool cull,
170                                  const SbBool twoside)
171 {
172   SoGLLazyElement::sendVertexOrdering(state, ccw ? SoLazyElement::CCW : SoLazyElement::CW);
173   SoGLLazyElement::sendBackfaceCulling(state, cull);
174   SoGLLazyElement::sendTwosideLighting(state, twoside);
175 }
176