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 SoTextureOverrideElement Inventor/elements/SoTextureOverrideElement.h
35 \brief The SoTextureOverrideElement makes it possible to override texture elements.
36
37 \ingroup elements
38 */
39
40
41 #include <Inventor/elements/SoTextureOverrideElement.h>
42
43 #include "coindefs.h"
44 #include "SbBasicP.h"
45
46 #include <cassert>
47
48 SO_ELEMENT_SOURCE(SoTextureOverrideElement);
49
50 /*!
51 This static method initializes static data for the
52 SoTextureOverrideElement class.
53 */
54
55 void
initClass(void)56 SoTextureOverrideElement::initClass(void)
57 {
58 SO_ELEMENT_INIT_CLASS(SoTextureOverrideElement, inherited);
59 }
60
61 /*!
62 The destructor.
63 */
64
~SoTextureOverrideElement(void)65 SoTextureOverrideElement::~SoTextureOverrideElement(void)
66 {
67 }
68
69 //!
70
71 SbBool
matches(const SoElement * element) const72 SoTextureOverrideElement::matches(const SoElement *element) const
73 {
74 return coin_assert_cast<const SoTextureOverrideElement *>(element)->flags == this->flags;
75 }
76
77 //!
78
79 SoElement *
copyMatchInfo() const80 SoTextureOverrideElement::copyMatchInfo() const
81 {
82 SoTextureOverrideElement * elem =
83 static_cast<SoTextureOverrideElement *>(this->getTypeId().createInstance());
84 elem->flags = this->flags;
85 return elem;
86 }
87
88 //!
89
90 void
init(SoState * COIN_UNUSED_ARG (state))91 SoTextureOverrideElement::init(SoState * COIN_UNUSED_ARG(state))
92 {
93 this->flags = 0;
94 }
95
96 //!
97
98 void
push(SoState * state)99 SoTextureOverrideElement::push(SoState *state)
100 {
101 inherited::push(state);
102 const SoTextureOverrideElement * prev =
103 coin_assert_cast<SoTextureOverrideElement *>
104 (
105 this->getNextInStack()
106 );
107 this->flags = prev->flags;
108 }
109
110 //!
111
112 SbBool
getQualityOverride(SoState * state)113 SoTextureOverrideElement::getQualityOverride(SoState *state)
114 {
115 const SoTextureOverrideElement * const element =
116 coin_assert_cast<const SoTextureOverrideElement *>
117 (
118 getConstElement(state, classStackIndex)
119 );
120 return (element->flags & TEXTURE_QUALITY) != 0;
121 }
122
123 //!
124
125 SbBool
getImageOverride(SoState * state)126 SoTextureOverrideElement::getImageOverride(SoState *state)
127 {
128 const SoTextureOverrideElement * const element =
129 coin_assert_cast<const SoTextureOverrideElement *>
130 (
131 getConstElement(state, classStackIndex)
132 );
133 return (element->flags & TEXTURE_IMAGE) != 0;
134 }
135
136 SbBool
getBumpMapOverride(SoState * state)137 SoTextureOverrideElement::getBumpMapOverride(SoState *state)
138 {
139 const SoTextureOverrideElement * const element =
140 coin_assert_cast<const SoTextureOverrideElement *>
141 (
142 getConstElement(state, classStackIndex)
143 );
144 return (element->flags & BUMP_MAP) != 0;
145 }
146
147 //!
148
149 void
setQualityOverride(SoState * state,const SbBool value)150 SoTextureOverrideElement::setQualityOverride(SoState *state, const SbBool value)
151 {
152 SoTextureOverrideElement * const element =
153 coin_safe_cast<SoTextureOverrideElement *>
154 (
155 getElement(state, classStackIndex)
156 );
157 if (element) {
158 if (value)
159 element->flags |= TEXTURE_QUALITY;
160 else
161 element->flags &= ~TEXTURE_QUALITY;
162 }
163 }
164
165 //!
166
167 void
setImageOverride(SoState * state,const SbBool value)168 SoTextureOverrideElement::setImageOverride(SoState *state, const SbBool value)
169 {
170 SoTextureOverrideElement * const element =
171 coin_safe_cast<SoTextureOverrideElement *>(getElement(state, classStackIndex));
172 if (element) {
173 if (value)
174 element->flags |= TEXTURE_IMAGE;
175 else
176 element->flags &= ~TEXTURE_IMAGE;
177 }
178 }
179
180 //!
181
182 void
setBumpMapOverride(SoState * state,const SbBool value)183 SoTextureOverrideElement::setBumpMapOverride(SoState *state, const SbBool value)
184 {
185 SoTextureOverrideElement * const element =
186 coin_safe_cast<SoTextureOverrideElement *>(getElement(state, classStackIndex));
187 if (element) {
188 if (value)
189 element->flags |= BUMP_MAP;
190 else
191 element->flags &= ~BUMP_MAP;
192 }
193 }
194
195 //!
196 void
print(FILE * fp) const197 SoTextureOverrideElement::print(FILE *fp) const
198 {
199 fprintf(fp, "SoTextureOverrideElement::flags: 0x%x\n", this->flags);
200 }
201