|
| 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 | +#include "SoRenderPlacementElement.h" |
| 34 | + |
| 35 | +#include <cassert> |
| 36 | + |
| 37 | +SO_ELEMENT_SOURCE(SoRenderPlacementElement); |
| 38 | + |
| 39 | +void |
| 40 | +SoRenderPlacementElement::initClass(void) |
| 41 | +{ |
| 42 | + SO_ELEMENT_INIT_CLASS(SoRenderPlacementElement, inherited); |
| 43 | +} |
| 44 | + |
| 45 | +SoRenderPlacementElement::~SoRenderPlacementElement() |
| 46 | +{ |
| 47 | +} |
| 48 | + |
| 49 | +void |
| 50 | +SoRenderPlacementElement::init(SoState * state) |
| 51 | +{ |
| 52 | + inherited::init(state); |
| 53 | + this->layer = MAIN; |
| 54 | + this->viewportOverride = FALSE; |
| 55 | + this->viewportX = 0; |
| 56 | + this->viewportY = 0; |
| 57 | + this->viewportWidth = 0; |
| 58 | + this->viewportHeight = 0; |
| 59 | + this->clearDepth = FALSE; |
| 60 | + this->commandMatricesOverride = FALSE; |
| 61 | +} |
| 62 | + |
| 63 | +void |
| 64 | +SoRenderPlacementElement::push(SoState * state) |
| 65 | +{ |
| 66 | + inherited::push(state); |
| 67 | + const SoRenderPlacementElement * prev = |
| 68 | + static_cast<const SoRenderPlacementElement *>(this->getNextInStack()); |
| 69 | + this->layer = prev->layer; |
| 70 | + this->viewportOverride = prev->viewportOverride; |
| 71 | + this->viewportX = prev->viewportX; |
| 72 | + this->viewportY = prev->viewportY; |
| 73 | + this->viewportWidth = prev->viewportWidth; |
| 74 | + this->viewportHeight = prev->viewportHeight; |
| 75 | + this->clearDepth = prev->clearDepth; |
| 76 | + this->commandMatricesOverride = prev->commandMatricesOverride; |
| 77 | +} |
| 78 | + |
| 79 | +void |
| 80 | +SoRenderPlacementElement::pop(SoState * state, |
| 81 | + const SoElement * prevTopElement) |
| 82 | +{ |
| 83 | + inherited::pop(state, prevTopElement); |
| 84 | + |
| 85 | + // A depth-clear request is consumed while traversing a child. Propagate that |
| 86 | + // consumption to the parent state so sibling separators do not turn one |
| 87 | + // render-layer clear into one clear per emitted command. |
| 88 | + const SoRenderPlacementElement * previous = |
| 89 | + static_cast<const SoRenderPlacementElement *>(prevTopElement); |
| 90 | + if (previous && !previous->clearDepth) { |
| 91 | + this->clearDepth = FALSE; |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +SbBool |
| 96 | +SoRenderPlacementElement::matches(const SoElement * /* element */) const |
| 97 | +{ |
| 98 | + assert(0 && "should never be called."); |
| 99 | + return TRUE; |
| 100 | +} |
| 101 | + |
| 102 | +SoElement * |
| 103 | +SoRenderPlacementElement::copyMatchInfo(void) const |
| 104 | +{ |
| 105 | + assert(0 && "should never be called."); |
| 106 | + return NULL; |
| 107 | +} |
| 108 | + |
| 109 | +void |
| 110 | +SoRenderPlacementElement::setLayer(SoState * state, Layer layer) |
| 111 | +{ |
| 112 | + SoRenderPlacementElement * elem = |
| 113 | + static_cast<SoRenderPlacementElement *> |
| 114 | + (SoElement::getElement(state, classStackIndex)); |
| 115 | + if (elem) { |
| 116 | + elem->layer = layer; |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +void |
| 121 | +SoRenderPlacementElement::setViewport(SoState * state, |
| 122 | + int x, int y, int width, int height) |
| 123 | +{ |
| 124 | + SoRenderPlacementElement * elem = |
| 125 | + static_cast<SoRenderPlacementElement *> |
| 126 | + (SoElement::getElement(state, classStackIndex)); |
| 127 | + if (elem) { |
| 128 | + elem->viewportOverride = TRUE; |
| 129 | + elem->viewportX = x; |
| 130 | + elem->viewportY = y; |
| 131 | + elem->viewportWidth = width; |
| 132 | + elem->viewportHeight = height; |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +void |
| 137 | +SoRenderPlacementElement::setClearDepth(SoState * state, SbBool clearDepth) |
| 138 | +{ |
| 139 | + SoRenderPlacementElement * elem = |
| 140 | + static_cast<SoRenderPlacementElement *> |
| 141 | + (SoElement::getElement(state, classStackIndex)); |
| 142 | + if (elem) { |
| 143 | + elem->clearDepth = clearDepth; |
| 144 | + } |
| 145 | +} |
| 146 | + |
| 147 | +void |
| 148 | +SoRenderPlacementElement::setCommandMatricesOverride(SoState * state, |
| 149 | + SbBool enabled) |
| 150 | +{ |
| 151 | + SoRenderPlacementElement * elem = |
| 152 | + static_cast<SoRenderPlacementElement *>( |
| 153 | + SoElement::getElement(state, classStackIndex)); |
| 154 | + if (elem) { |
| 155 | + elem->commandMatricesOverride = enabled; |
| 156 | + } |
| 157 | +} |
| 158 | + |
| 159 | +SoRenderPlacementElement::Layer |
| 160 | +SoRenderPlacementElement::getLayer(SoState * state) |
| 161 | +{ |
| 162 | + const SoRenderPlacementElement * elem = |
| 163 | + static_cast<const SoRenderPlacementElement *> |
| 164 | + (SoElement::getConstElement(state, classStackIndex)); |
| 165 | + return elem->layer; |
| 166 | +} |
| 167 | + |
| 168 | +SbBool |
| 169 | +SoRenderPlacementElement::getViewport(SoState * state, |
| 170 | + int & x, int & y, |
| 171 | + int & width, int & height) |
| 172 | +{ |
| 173 | + const SoRenderPlacementElement * elem = |
| 174 | + static_cast<const SoRenderPlacementElement *> |
| 175 | + (SoElement::getConstElement(state, classStackIndex)); |
| 176 | + x = elem->viewportX; |
| 177 | + y = elem->viewportY; |
| 178 | + width = elem->viewportWidth; |
| 179 | + height = elem->viewportHeight; |
| 180 | + return elem->viewportOverride; |
| 181 | +} |
| 182 | + |
| 183 | +SbBool |
| 184 | +SoRenderPlacementElement::consumeClearDepth(SoState * state) |
| 185 | +{ |
| 186 | + SoRenderPlacementElement * elem = |
| 187 | + static_cast<SoRenderPlacementElement *> |
| 188 | + (SoElement::getElement(state, classStackIndex)); |
| 189 | + if (!elem || !elem->clearDepth) return FALSE; |
| 190 | + elem->clearDepth = FALSE; |
| 191 | + return TRUE; |
| 192 | +} |
| 193 | + |
| 194 | +SbBool |
| 195 | +SoRenderPlacementElement::getCommandMatricesOverride(SoState * state) |
| 196 | +{ |
| 197 | + const SoRenderPlacementElement * elem = |
| 198 | + static_cast<const SoRenderPlacementElement *>( |
| 199 | + SoElement::getConstElement(state, classStackIndex)); |
| 200 | + return elem ? elem->commandMatricesOverride : FALSE; |
| 201 | +} |
0 commit comments