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 SoGLViewportRegionElement Inventor/elements/SoGLViewportRegionElement.h
35 \brief The SoGLViewportRegionElement class is yet to be documented.
36
37 \ingroup elements
38
39 FIXME: write doc.
40 */
41
42 #include <Inventor/elements/SoGLViewportRegionElement.h>
43
44
45 #include <cassert>
46 #ifdef HAVE_CONFIG_H
47 #include <config.h>
48 #endif // HAVE_CONFIG_H
49
50 #include <Inventor/system/gl.h>
51
52 #if COIN_DEBUG
53 #include <Inventor/errors/SoDebugError.h>
54 #endif // COIN_DEBUG
55
56 SO_ELEMENT_SOURCE(SoGLViewportRegionElement);
57
58 /*!
59 This static method initializes static data for the
60 SoGLViewportRegionElement class.
61 */
62
63 void
initClass(void)64 SoGLViewportRegionElement::initClass(void)
65 {
66 SO_ELEMENT_INIT_CLASS(SoGLViewportRegionElement, inherited);
67 }
68
69 /*!
70 The destructor.
71 */
72
~SoGLViewportRegionElement()73 SoGLViewportRegionElement::~SoGLViewportRegionElement()
74 {
75 }
76
77 //! FIXME: write doc.
78
79 void
init(SoState * state)80 SoGLViewportRegionElement::init(SoState * state)
81 {
82 inherited::init(state);
83 this->initialized = FALSE;
84 }
85
86 //! FIXME: write doc.
87
88 void
push(SoState * state)89 SoGLViewportRegionElement::push(SoState * state)
90 {
91 inherited::push(state);
92 SoGLViewportRegionElement * prev = (SoGLViewportRegionElement*)
93 this->getNextInStack();
94 this->viewportRegion = prev->viewportRegion;
95 this->initialized = TRUE;
96 }
97
98 //! FIXME: write doc.
99
100 void
pop(SoState * state,const SoElement * prevTopElement)101 SoGLViewportRegionElement::pop(SoState * state,
102 const SoElement * prevTopElement)
103 {
104 SoGLViewportRegionElement * prev =
105 (SoGLViewportRegionElement *)prevTopElement;
106 if (!(this->viewportRegion == prev->viewportRegion))
107 this->updategl();
108 prev->capture(state);
109 }
110
111 //! FIXME: write doc.
112
113 void
setElt(const SbViewportRegion & viewportRegionarg)114 SoGLViewportRegionElement::setElt(const SbViewportRegion & viewportRegionarg)
115 {
116 this->viewportRegion = viewportRegionarg;
117 this->initialized = TRUE;
118 this->updategl();
119 }
120
121 //! FIXME: write doc.
122
123 void
updategl() const124 SoGLViewportRegionElement::updategl() const
125 {
126 if (this->initialized) {
127 SbVec2s origin = this->viewportRegion.getViewportOriginPixels();
128 SbVec2s size = this->viewportRegion.getViewportSizePixels();
129 glViewport(origin[0], origin[1], size[0], size[1]);
130
131 #if COIN_DEBUG && 0 // debug
132 SoDebugError::postInfo("SoGLViewportRegionElement::updategl",
133 "glViewport: %d %d %d %d",
134 origin[0], origin[1], size[0], size[1]);
135 #endif // debug
136 }
137 }
138