Open Inventor Reference
|
00001 /* 00002 * 00003 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * Further, this software is distributed without any warranty that it is 00016 * free of the rightful claim of any third person regarding infringement 00017 * or the like. Any license provided herein, whether implied or 00018 * otherwise, applies only to this software file. Patent licenses, if 00019 * any, provided herein do not apply to combinations of this program with 00020 * other software, or any other product whatsoever. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this library; if not, write to the Free Software 00024 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 * 00026 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 00027 * Mountain View, CA 94043, or: 00028 * 00029 * http://www.sgi.com 00030 * 00031 * For further information regarding this notice, see: 00032 * 00033 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ 00034 * 00035 */ 00036 00037 00038 /* 00039 * Copyright (C) 1990,91 Silicon Graphics, Inc. 00040 * 00041 _______________________________________________________________________ 00042 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00043 | 00044 | $Revision: 1.2 $ 00045 | 00046 | Description: 00047 | This file defines the SoGLLazyElement class. 00048 | 00049 | Author(s) : Alan Norton, Gavin Bell 00050 | 00051 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00052 _______________________________________________________________________ 00053 */ 00054 00055 #ifndef _SO_GL_LAZY_ELEMENT 00056 #define _SO_GL_LAZY_ELEMENT 00057 00058 #include <Inventor/elements/SoLazyElement.h> 00059 #include <Inventor/actions/SoGLRenderAction.h> 00060 class SoGLRenderCache; 00061 class SoVBO; 00062 00075 00076 SoEXTENDER class INVENTOR_API SoGLLazyElement : public SoLazyElement { 00077 00078 SO_ELEMENT_HEADER(SoGLLazyElement); 00079 00080 public: 00082 virtual void init(SoState *state); 00083 00085 virtual void push(SoState *state); 00086 virtual void pop(SoState *state, const SoElement *prevTopElement); 00087 00089 static void sendAllMaterial(SoState *state) 00090 {SoGLLazyElement *le = getInstance(state); 00091 if ((le->invalidBits)||(state->isCacheOpen())) 00092 le->reallySend(state, ALL_MASK);} 00093 00094 static void sendNoMaterial(SoState *state) 00095 {SoGLLazyElement *le = getInstance(state); 00096 if ((NO_COLOR_MASK & le->invalidBits)||(state->isCacheOpen())) 00097 le->reallySend(state, NO_COLOR_MASK);} 00098 00099 static void sendOnlyDiffuseColor(SoState *state) 00100 {SoGLLazyElement *le = getInstance(state); 00101 if ((DIFFUSE_ONLY_MASK & le->invalidBits)||(state->isCacheOpen())) 00102 le->reallySend(state, DIFFUSE_ONLY_MASK);} 00103 00108 void sendDiffuseByIndex(int index) const; 00109 00111 void reset(SoState* state, uint32_t bitmask) const; 00112 00113 static SbBool isColorIndex(SoState *state) 00114 {return(getInstance(state)->colorIndex);} 00115 00119 static SoGLLazyElement * getInstance(const SoState *state) 00120 {return (SoGLLazyElement *) 00121 (state->getConstElement(classStackIndex));} 00122 00123 SoINTERNAL public: 00125 static void initClass(); 00126 00131 void send(const SoState *state, uint32_t mask) const 00132 {if ((mask & invalidBits)||(state->isCacheOpen())) 00133 ((SoGLLazyElement*)(this))->reallySend(state, mask);} 00134 00137 virtual SbBool matches(const SoElement *) const 00138 {return FALSE;} 00139 virtual SoElement *copyMatchInfo() const 00140 {return NULL;} 00141 00144 SbBool lazyMatches(uint32_t checkGLFlag, uint32_t checkIVFlag, 00145 const SoGLLazyElement* eltInState){ 00146 if (checkGLFlag || checkIVFlag || 00147 (ivState.transpType != eltInState->ivState.transpType)) 00148 return (fullLazyMatches (checkGLFlag, checkIVFlag, eltInState)); 00149 else return(TRUE); 00150 } 00151 00153 typedef struct { 00154 uint32_t GLDiffuseNodeId; 00155 uint32_t GLTranspNodeId; 00156 float GLAmbient[4]; 00157 float GLEmissive[4]; 00158 float GLSpecular[4]; 00159 float GLShininess; 00160 SbBool GLColorMaterial; 00161 int32_t GLLightModel; 00162 SbBool GLblending; 00163 int32_t GLStippleNum; 00164 } GLLazyState; 00165 00169 SoGLLazyElement* copyLazyMatchInfo(SoState* state); 00170 00174 void getCopyGL(SoGLLazyElement* cacheLazyElement, 00175 SoGLLazyElement::GLLazyState& cacheGLState); 00176 00181 void copyBackGL(SoGLLazyElement* cacheLazyElement, 00182 SoGLLazyElement::GLLazyState& cacheGLState) 00183 { if (cacheLazyElement->GLSendBits) 00184 reallyCopyBackGL(cacheLazyElement->GLSendBits, cacheGLState);} 00185 00188 void sendVPPacked(SoState* state, const unsigned char* pcolor); 00189 00191 virtual ~SoGLLazyElement(); 00192 00193 void mergeCacheInfo(SoGLRenderCache* childCache, SoGLRenderCache* 00194 parentCache, uint32_t doSendFlag, uint32_t checkIVFlag, 00195 uint32_t checkGLFlag); 00196 00198 void updateColorVBO(SoState* state, SoVBO* vbo); 00199 00200 private: 00202 void copyGLValues(uint32_t bitmask, SoGLLazyElement* cacheLazyElement); 00204 void copyIVValues(uint32_t bitmask, SoGLLazyElement* cacheLazyElement); 00205 00207 void reallySend(const SoState *state, uint32_t bitmask); 00208 00210 SbBool fullLazyMatches(uint32_t checkGLFlag, uint32_t checkIVFlag, 00211 const SoGLLazyElement* eltInState); 00212 00214 void packColors(SoColorPacker *cPacker); 00215 00218 virtual void setDiffuseElt(SoNode *node, int32_t numColors, 00219 const SbColor *colors, SoColorPacker *cPacker); 00220 00221 virtual void setTranspElt(SoNode *node, int32_t numTrans, 00222 const float *trans, SoColorPacker *cPacker); 00223 00224 virtual void setTranspTypeElt(int32_t type); 00225 virtual void setPackedElt( SoNode *node, 00226 int32_t numColors, const uint32_t *packedColors); 00227 00228 virtual void setColorIndexElt( SoNode*, int32_t numIndices, 00229 const int32_t *indices); 00230 00231 virtual void setAmbientElt(const SbColor* color); 00232 virtual void setEmissiveElt( const SbColor* color); 00233 virtual void setSpecularElt(const SbColor* color); 00234 virtual void setShininessElt( float color); 00235 virtual void setColorMaterialElt( SbBool value); 00236 virtual void setBlendingElt( SbBool value); 00237 virtual void setLightModelElt(SoState *, int32_t model); 00238 virtual void setMaterialElt(SoNode *, uint32_t bitmask, 00239 SoColorPacker *cPacker, const SoMFColor&, 00240 const SoMFFloat&, const SoMFColor&, 00241 const SoMFColor&, const SoMFColor&, const SoMFFloat&); 00242 00244 virtual void registerRedundantSet(SoState *, uint32_t bitmask); 00246 virtual void registerGetDependence(SoState *, uint32_t bitmask); 00247 00249 void reallyCopyBackGL(uint32_t bitmask, SoGLLazyElement::GLLazyState& ); 00250 00253 SoGLLazyElement::GLLazyState glState; 00254 00256 uint32_t GLSendBits; 00257 00259 SbBool colorIndex; 00260 00264 static u_char patterns[64+1][32 * 4]; 00265 00267 static SbBool patternsCreated; 00268 00271 static SbBool patternListDefined[64+1]; 00272 00274 static int patternListBase; 00275 00277 static int patternListContext; 00278 00281 SbBool cacheOpen; 00282 00284 void sendStipple(const SoState *state, int transpIndex); 00285 00288 static void createPatterns(); 00289 }; 00290 00291 #endif /* _SO_GL_LAZY_ELEMENT */