Debian Codegraph @

lib/database/src/so/elements/SoGLLineWidthElement.c++

raw
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 * Copyright (C) 1990,91 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | $Revision: 1.1.1.1 $
44 |
45 | Classes:
46 | SoGLLineWidthElement
47 |
48 | Author(s) : Paul S. Strauss
49 |
50 ______________ S I L I C O N G R A P H I C S I N C . ____________
51 _______________________________________________________________________
52 */
53
54 #include <GL/gl.h>
55 #include <Inventor/actions/SoGLRenderAction.h>
56 #include <Inventor/elements/SoGLLineWidthElement.h>
57 #include <Inventor/elements/SoViewportRegionElement.h>
58 #include <Inventor/misc/SoState.h>
59
60 SO_ELEMENT_SOURCE(SoGLLineWidthElement);
61
62 ////////////////////////////////////////////////////////////////////////
63 //
64 // Description:
65 // Destructor.
66 //
67 // Use: private
68
69 SoGLLineWidthElement::~SoGLLineWidthElement()
70 //
71 ////////////////////////////////////////////////////////////////////////
72 {
73 }
74
75 ////////////////////////////////////////////////////////////////////////
76 //
77 // Description:
78 // Initializes element.
79 //
80 // Use: public
81
82 void
83 SoGLLineWidthElement::init(SoState *_state)
84 //
85 ////////////////////////////////////////////////////////////////////////
86 {
87 // Initialize base class stuff
88 SoLineWidthElement::init(_state);
89
90 copiedFromParent = FALSE;
91
92 // Save the state so we can get the SoViewportRegionElement when
93 // we send the line width to GL
94 state = _state;
95
96 }
97
98 ////////////////////////////////////////////////////////////////////////
99 //
100 // Description:
101 // Pushes element, copying data from previous element
102 //
103 // Use: public
104
105 void
106 SoGLLineWidthElement::push(SoState *_state)
107 //
108 ////////////////////////////////////////////////////////////////////////
109 {
110 const SoGLLineWidthElement *prevElt =
111 (const SoGLLineWidthElement *) getNextInStack();
112
113 data = prevElt->data;
114
115 copiedFromParent = TRUE;
116 state = _state;
117 }
118
119 ////////////////////////////////////////////////////////////////////////
120 //
121 // Description:
122 // Pops element, causing side effects in GL.
123 //
124 // Use: public
125
126 void
127 SoGLLineWidthElement::pop(SoState *state, const SoElement *childElt)
128 //
129 ////////////////////////////////////////////////////////////////////////
130 {
131 // Since popping this element has GL side effects, make sure any
132 // open caches capture it. We may not send any GL commands, but
133 // the cache dependency must exist even if we don't send any GL
134 // commands, because if the element changes, the _lack_ of GL
135 // commands here is a bug (remember, GL commands issued here are
136 // put inside the cache).
137 capture(state);
138 copiedFromParent = FALSE;
139
140 // If the previous element didn't have the same value...
141 const SoGLLineWidthElement *child =
142 (const SoGLLineWidthElement *)childElt;
143
144 // Restore previous line width
145 if (data != child->data)
146 send();
147 }
148
149 ////////////////////////////////////////////////////////////////////////
150 //
151 // Description:
152 // Sets line width in element.
153 //
154 // Use: protected, virtual
155
156 void
157 SoGLLineWidthElement::setElt(float width)
158 //
159 ////////////////////////////////////////////////////////////////////////
160 {
161 // Optimization: on push, we copy the value from the previous
162 // element. If the element is set to the same value, we don't
163 // bother sending it, but do add a cache dependency on the
164 // previous element.
165
166 if (data != width) {
167 data = width;
168 send();
169 copiedFromParent = FALSE;
170 }
171 else if (copiedFromParent) {
172 SoGLLineWidthElement *parent =
173 (SoGLLineWidthElement *) getNextInStack();
174 parent->capture(state);
175 }
176 }
177
178 ////////////////////////////////////////////////////////////////////////
179 //
180 // Description:
181 // Sends line width in element to GL.
182 //
183 // Use: private
184
185 void
186 SoGLLineWidthElement::send()
187 //
188 ////////////////////////////////////////////////////////////////////////
189 {
190 float width;
191
192 // If line width is 0 (the default), use the default GL value of 1.0
193 if (data == 0.0)
194 width = 1.0;
195
196 // Otherwise, compute the line width to be the appropriate number
197 // of pixels, based on the current viewport region data
198 else
199 width = data * SoViewportRegionElement::get(state).getPixelsPerPoint();
200
201 glLineWidth(width);
202 }