| 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 | * |
| 39 | _______________________________________________________________________ |
| 40 | ______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 41 | | |
| 42 | | $Revision: 1.2 $ |
| 43 | | |
| 44 | | Classes: |
| 45 | | Decal |
| 46 | | |
| 47 | | Author(s) : Ajay Sreekanth, Gavin Bell |
| 48 | | |
| 49 | ______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 50 | _______________________________________________________________________ |
| 51 | */ |
| 52 | |
| 53 | #include <GL/gl.h> |
| 54 | #include <Inventor/actions/SoGLRenderAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoGLRenderAction.h`/ |
| 55 | #include <Inventor/elements/SoGLCacheContextElement.h>cxx . . $ `<file>/lib/database/include/Inventor/elements/SoGLCacheContextElement.h`/ |
| 56 | #include <Inventor/misc/SoChildList.h>cxx . . $ `<file>/lib/database/include/Inventor/misc/SoChildList.h`/ |
| 57 | |
| 58 | #include "Decal.h"cxx . . $ `<file>/apps/nodes/Decal/Decal.h`/ |
| 59 | |
| 60 | |
| 61 | SO_NODE_SOURCEcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:241:9`!(Decal); |
| 62 | |
| 63 | ////////////////////////////////////////////////////////////////////// |
| 64 | // |
| 65 | // Decal class: Draws coplanar polygons correctly ordered |
| 66 | // |
| 67 | ////////////////////////////////////////////////////////////////////// |
| 68 | |
| 69 | |
| 70 | //////////////////////////////////////////////////////////////////////// |
| 71 | // |
| 72 | // Description: |
| 73 | // This initializes the Decal class. |
| 74 | // |
| 75 | // Use: internal |
| 76 | |
| 77 | void |
| 78 | Decalcxx . . $ Decal#::initClasscxx . . $ Decal#initClass(49f6e7a06ebc5aa8).() |
| 79 | // |
| 80 | //////////////////////////////////////////////////////////////////////// |
| 81 | { |
| 82 | SO_NODE_INIT_CLASScxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:283:9`!(Decal, SoSeparator, "Separator"); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | //////////////////////////////////////////////////////////////////////// |
| 87 | // |
| 88 | // Description: |
| 89 | // Constructor |
| 90 | // |
| 91 | // Use: public |
| 92 | |
| 93 | Decalcxx . . $ Decal#::Decalcxx . . $ Decal#Decal(49f6e7a06ebc5aa8).() |
| 94 | // |
| 95 | //////////////////////////////////////////////////////////////////////// |
| 96 | { |
| 97 | SO_NODE_CONSTRUCTORcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:309:9`!(Decal); |
| 98 | } |
| 99 | |
| 100 | //////////////////////////////////////////////////////////////////////// |
| 101 | // |
| 102 | // Description: |
| 103 | // Destructor |
| 104 | // |
| 105 | // Use: private |
| 106 | |
| 107 | Decalcxx . . $ Decal#::~cxx . . $ Decal#`~Decal`(49f6e7a06ebc5aa8).Decalcxx . . $ Decal#() |
| 108 | // |
| 109 | //////////////////////////////////////////////////////////////////////// |
| 110 | { |
| 111 | } |
| 112 | |
| 113 | ////////////////////////////////////////////////////////////////// |
| 114 | // |
| 115 | // Description: |
| 116 | // Traversal for GL rendering. |
| 117 | // |
| 118 | // The polygon offset extension makes this really simple; we just |
| 119 | // draw the on-top layers with a bigger and bigger offset. |
| 120 | // |
| 121 | // If you don't have the polygon offset extension, this can be made |
| 122 | // to work for planar decal with the following two-pass algorithm: |
| 123 | // First the depth buffer update is turned off and the base is |
| 124 | // rendered followed by the layers in order. Depth testing is |
| 125 | // left on as is the color buffer update, thus producing the |
| 126 | // correct display. In the second pass, depth buffer update |
| 127 | // is turned back on, while color buffer update is turned off. |
| 128 | // The base is now rendered correctly updating the depth buffer |
| 129 | // |
| 130 | // Use: extender |
| 131 | |
| 132 | void |
| 133 | Decalcxx . . $ Decal#::GLRenderBelowPathcxx . . $ Decal#GLRenderBelowPath(5c806c737f468e18).(SoGLRenderActioncxx . . $ SoGLRenderAction# *action) |
| 134 | // |
| 135 | //////////////////////////////////////////////////////////////////////// |
| 136 | { |
| 137 | SoChildListcxx . . $ SoChildList# *childList = getChildrencxx . . $ SoGroup#getChildren(ab7c10c4b6f38fa1).(); |
| 138 | if (! getNumChildrencxx . . $ SoGroup#getNumChildren(455f465bc33b4cdf).()) return; |
| 139 | |
| 140 | SoStatecxx . . $ SoState# *state = action->getStatecxx . . $ SoAction#getState(5c8eb8fe6550a03).(); |
| 141 | state->pushcxx . . $ SoState#push(49f6e7a06ebc5aa8).(); |
| 142 | |
| 143 | #ifdef GL_EXT_polygon_offsetcxx . . $ `<external>/13868558256673015710/glext.h:7961:9`! |
| 144 | // See the comments in the |
| 145 | // /usr/include/Inventor/elements/SoGLCacheContextElement for more |
| 146 | // details on this-- it is the correct way to determine whether or |
| 147 | // not an OpenGL extension is available: |
| 148 | static int offsetExtInt = -1; |
| 149 | if (offsetExtInt == -1) { |
| 150 | offsetExtInt = |
| 151 | SoGLCacheContextElementcxx . . $ SoGLCacheContextElement#::getExtIDcxx . . $ SoGLCacheContextElement#getExtID(5c4306d8553b3696).("GL_EXT_polygon_offset"); |
| 152 | } |
| 153 | if (SoGLCacheContextElementcxx . . $ SoGLCacheContextElement#::extSupportedcxx . . $ SoGLCacheContextElement#extSupported(581edbcffb1fd3ad).(state, offsetExtInt)) { |
| 154 | |
| 155 | #ifdef GL_VERSION_1_1cxx . . $ `<external>/11565930711847777359/gl.h:107:9`! |
| 156 | glEnable(GL_POLYGON_OFFSET_FILLcxx . . $ `<external>/11565930711847777359/gl.h:249:9`!); |
| 157 | glEnable(GL_POLYGON_OFFSET_LINEcxx . . $ `<external>/11565930711847777359/gl.h:248:9`!); |
| 158 | glEnable(GL_POLYGON_OFFSET_POINTcxx . . $ `<external>/11565930711847777359/gl.h:247:9`!); |
| 159 | #else |
| 160 | glEnable(GL_POLYGON_OFFSET_EXT); |
| 161 | #endif |
| 162 | |
| 163 | float offset = 0; |
| 164 | |
| 165 | for (int i=0; i < childList->getLengthcxx . . $ SbPList#getLength(455f465bc33b4cdf).(); i++) { |
| 166 | #ifdef GL_VERSION_1_1cxx . . $ `<external>/11565930711847777359/gl.h:107:9`! |
| 167 | glPolygonOffset(offset, 0); |
| 168 | #else |
| 169 | glPolygonOffsetEXT(offset, 0); |
| 170 | #endif |
| 171 | childList->traversecxx . . $ SoChildList#traverse(26b22d80ec04e930).(action, i); |
| 172 | |
| 173 | offset -= 0.1; |
| 174 | } |
| 175 | |
| 176 | #ifdef GL_VERSION_1_1cxx . . $ `<external>/11565930711847777359/gl.h:107:9`! |
| 177 | glDisable(GL_POLYGON_OFFSET_FILLcxx . . $ `<external>/11565930711847777359/gl.h:249:9`!); |
| 178 | glDisable(GL_POLYGON_OFFSET_LINEcxx . . $ `<external>/11565930711847777359/gl.h:248:9`!); |
| 179 | glDisable(GL_POLYGON_OFFSET_POINTcxx . . $ `<external>/11565930711847777359/gl.h:247:9`!); |
| 180 | #else |
| 181 | glDisable(GL_POLYGON_OFFSET_EXT); |
| 182 | #endif |
| 183 | |
| 184 | } else { |
| 185 | |
| 186 | #endif |
| 187 | // Extension not supported at compile time or at run-time: |
| 188 | |
| 189 | // first pass |
| 190 | // turn off depth update, leaving color update on |
| 191 | GLboolean oldDepthMask; |
| 192 | glGetBooleanv(GL_DEPTH_WRITEMASKcxx . . $ `<external>/11565930711847777359/gl.h:272:9`!, &oldDepthMask); |
| 193 | if (oldDepthMask) |
| 194 | glDepthMask(GL_FALSEcxx . . $ `<external>/11565930711847777359/gl.h:139:9`!); |
| 195 | // render base followed by layers in order |
| 196 | childList->traversecxx . . $ SoChildList#traverse(967167263c8a77b7).(action); |
| 197 | if (oldDepthMask) |
| 198 | glDepthMask(oldDepthMask); |
| 199 | |
| 200 | state->popcxx . . $ SoState#pop(49f6e7a06ebc5aa8).(); // Pop and push state between passes to avoid |
| 201 | state->pushcxx . . $ SoState#push(49f6e7a06ebc5aa8).(); // problems with non-Separator children |
| 202 | |
| 203 | // second pass |
| 204 | // turn off color update leaving depth update on |
| 205 | GLboolean colorMode; |
| 206 | glGetBooleanv(GL_RGBA_MODEcxx . . $ `<external>/11565930711847777359/gl.h:510:9`!, &colorMode); |
| 207 | if (colorMode) { // RGBA mode |
| 208 | GLboolean oldColorMask[4]; |
| 209 | glGetBooleanv(GL_COLOR_WRITEMASKcxx . . $ `<external>/11565930711847777359/gl.h:490:9`!, oldColorMask); |
| 210 | GLboolean anyMask = (oldColorMask[0] || oldColorMask[1] || |
| 211 | oldColorMask[2] || oldColorMask[3]); |
| 212 | if (anyMask) |
| 213 | glColorMask(GL_FALSEcxx . . $ `<external>/11565930711847777359/gl.h:139:9`!, GL_FALSEcxx . . $ `<external>/11565930711847777359/gl.h:139:9`!, GL_FALSEcxx . . $ `<external>/11565930711847777359/gl.h:139:9`!, GL_FALSEcxx . . $ `<external>/11565930711847777359/gl.h:139:9`!); |
| 214 | // only render base |
| 215 | childList->traversecxx . . $ SoChildList#traverse(26b22d80ec04e930).(action, 0); |
| 216 | if (anyMask) |
| 217 | glColorMask(oldColorMask[0], oldColorMask[1], |
| 218 | oldColorMask[2], oldColorMask[3]); |
| 219 | } |
| 220 | else { // color index mode |
| 221 | GLint oldMask; |
| 222 | glGetIntegerv(GL_INDEX_WRITEMASKcxx . . $ `<external>/11565930711847777359/gl.h:503:9`!, &oldMask); |
| 223 | if (oldMask) |
| 224 | glIndexMask(0x0); |
| 225 | // only render base |
| 226 | childList->traversecxx . . $ SoChildList#traverse(26b22d80ec04e930).(action, 0); |
| 227 | if (oldMask) |
| 228 | glIndexMask(oldMask); |
| 229 | } |
| 230 | #ifdef GL_EXT_polygon_offsetcxx . . $ `<external>/13868558256673015710/glext.h:7961:9`! |
| 231 | } |
| 232 | #endif |
| 233 | state->popcxx . . $ SoState#pop(49f6e7a06ebc5aa8).(); |
| 234 | } |