![]() |
http://www.sim.no/ http://www.coin3d.org/ |
00001 #ifndef COIN_SOLAZYELEMENT_H 00002 #define COIN_SOLAZYELEMENT_H 00003 00004 /**************************************************************************\ 00005 * 00006 * This file is part of the Coin 3D visualization library. 00007 * Copyright (C) by Kongsberg Oil & Gas Technologies. 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU General Public License 00011 * ("GPL") version 2 as published by the Free Software Foundation. 00012 * See the file LICENSE.GPL at the root directory of this source 00013 * distribution for additional information about the GNU GPL. 00014 * 00015 * For using Coin with software that can not be combined with the GNU 00016 * GPL, and for taking advantage of the additional benefits of our 00017 * support services, please contact Kongsberg Oil & Gas Technologies 00018 * about acquiring a Coin Professional Edition License. 00019 * 00020 * See http://www.coin3d.org/ for more information. 00021 * 00022 * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY. 00023 * http://www.sim.no/ sales@sim.no coin-support@coin3d.org 00024 * 00025 \**************************************************************************/ 00026 00027 #include <Inventor/elements/SoElement.h> 00028 #include <Inventor/elements/SoSubElement.h> 00029 #include <Inventor/SbColor.h> 00030 00031 class SoMFFloat; 00032 class SoMFColor; 00033 class SoColorPacker; 00034 class SoLazyElementP; 00035 class SoGLImage; 00036 00037 #define SO_LAZY_SHINY_THRESHOLD 0.005f 00038 00039 00040 class COIN_DLL_API SoLazyElement : public SoElement { 00041 typedef SoElement inherited; 00042 00043 SO_ELEMENT_HEADER(SoLazyElement); 00044 00045 public: 00046 static void initClass(); 00047 protected: 00048 ~SoLazyElement(); 00049 public: 00050 enum cases { 00051 LIGHT_MODEL_CASE = 0, 00052 COLOR_MATERIAL_CASE, 00053 DIFFUSE_CASE, 00054 AMBIENT_CASE, 00055 EMISSIVE_CASE, 00056 SPECULAR_CASE, 00057 SHININESS_CASE, 00058 BLENDING_CASE, 00059 TRANSPARENCY_CASE, 00060 VERTEXORDERING_CASE, 00061 TWOSIDE_CASE, 00062 CULLING_CASE, 00063 SHADE_MODEL_CASE, 00064 GLIMAGE_CASE, 00065 ALPHATEST_CASE, 00066 LAZYCASES_LAST // must be last 00067 }; 00068 enum masks{ 00069 LIGHT_MODEL_MASK = 1 << LIGHT_MODEL_CASE, // 0x0001 00070 COLOR_MATERIAL_MASK = 1 << COLOR_MATERIAL_CASE, // 0x0002 00071 DIFFUSE_MASK = 1 << DIFFUSE_CASE, // 0x0004 00072 AMBIENT_MASK = 1 << AMBIENT_CASE, // 0x0008 00073 EMISSIVE_MASK = 1<<EMISSIVE_CASE, // 0x0010 00074 SPECULAR_MASK = 1 << SPECULAR_CASE, // 0x0020 00075 SHININESS_MASK = 1 << SHININESS_CASE, // 0x0040 00076 TRANSPARENCY_MASK = 1 << TRANSPARENCY_CASE, // 0x0080 00077 BLENDING_MASK = 1 << BLENDING_CASE, // 0x0100 00078 VERTEXORDERING_MASK = 1 << VERTEXORDERING_CASE, // 0x0200 00079 TWOSIDE_MASK = 1 << TWOSIDE_CASE, // 0x0400 00080 CULLING_MASK = 1 << CULLING_CASE, // 0x0800 00081 SHADE_MODEL_MASK = 1 << SHADE_MODEL_CASE, // 0x1000 00082 GLIMAGE_MASK = 1 << GLIMAGE_CASE, // 0x2000 00083 ALPHATEST_MASK = 1 << ALPHATEST_CASE, // 0x4000 00084 ALL_MASK = (1 << LAZYCASES_LAST)-1 00085 }; 00086 00087 enum internalMasks{ 00088 OTHER_COLOR_MASK = AMBIENT_MASK|EMISSIVE_MASK|SPECULAR_MASK|SHININESS_MASK, 00089 ALL_COLOR_MASK = OTHER_COLOR_MASK|DIFFUSE_MASK, 00090 NO_COLOR_MASK = ALL_MASK & (~ALL_COLOR_MASK), 00091 ALL_BUT_DIFFUSE_MASK = ALL_MASK &(~ DIFFUSE_MASK), 00092 DIFFUSE_ONLY_MASK = ALL_MASK &(~ OTHER_COLOR_MASK) 00093 }; 00094 00095 enum LightModel { 00096 BASE_COLOR, 00097 PHONG 00098 }; 00099 00100 enum VertexOrdering { 00101 CW, 00102 CCW 00103 }; 00104 00105 virtual void init(SoState *state); 00106 virtual void push(SoState *state); 00107 virtual SbBool matches(const SoElement *) const; 00108 virtual SoElement *copyMatchInfo(void) const; 00109 00110 static void setToDefault(SoState * state); 00111 static void setDiffuse(SoState * state, SoNode * node, int32_t numcolors, 00112 const SbColor * colors, SoColorPacker * packer); 00113 static void setTransparency(SoState *state, SoNode *node, int32_t numvalues, 00114 const float * transparency, SoColorPacker * packer); 00115 static void setPacked(SoState * state, SoNode * node, 00116 int32_t numcolors, const uint32_t * colors, 00117 const SbBool packedtransparency = FALSE); 00118 static void setColorIndices(SoState *state, SoNode *node, 00119 int32_t numindices, const int32_t *indices); 00120 static void setAmbient(SoState *state, const SbColor * color); 00121 static void setEmissive(SoState *state, const SbColor * color); 00122 static void setSpecular(SoState *state, const SbColor * color); 00123 static void setShininess(SoState *state, float value); 00124 static void setColorMaterial(SoState *state, SbBool value); 00125 static void enableBlending(SoState *state, 00126 int sfactor, 00127 int dfactor); 00128 static void enableSeparateBlending(SoState *state, 00129 int sfactor, 00130 int dfactor, 00131 int alpha_sfactor, 00132 int alpha_dfactor); 00133 00134 static void disableBlending(SoState * state); 00135 static void setLightModel(SoState *state, const int32_t model); 00136 static void setVertexOrdering(SoState * state, VertexOrdering ordering); 00137 static void setBackfaceCulling(SoState * state, SbBool onoff); 00138 static void setTwosideLighting(SoState * state, SbBool onoff); 00139 static void setShadeModel(SoState * state, SbBool flatshading); 00140 static void setGLImageId(SoState * state, uint32_t glimageid, SbBool alphatest); 00141 static void setAlphaTest(SoState * state, SbBool onoff); 00142 00143 static const SbColor & getDiffuse(SoState* state, int index); 00144 static float getTransparency(SoState*, int index); 00145 static const uint32_t * getPackedColors(SoState*); 00146 static const int32_t * getColorIndices(SoState*); 00147 static int32_t getColorIndex(SoState*, int num); 00148 static const SbColor & getAmbient(SoState *); 00149 static const SbColor & getEmissive(SoState *); 00150 static const SbColor & getSpecular(SoState *); 00151 static float getShininess(SoState*); 00152 static SbBool getColorMaterial(SoState*); 00153 static SbBool getBlending(SoState *, 00154 int & sfactor, int & dfactor); 00155 static SbBool getAlphaBlending(SoState *, 00156 int & sfactor, int & dfactor); 00157 00158 static int32_t getLightModel(SoState*); 00159 static SbBool getAlphaTest(SoState * state); 00160 00161 int32_t getNumDiffuse(void) const; 00162 int32_t getNumTransparencies(void) const; 00163 int32_t getNumColorIndices(void) const; 00164 SbBool isPacked(void) const; 00165 SbBool isTransparent(void) const; 00166 static SoLazyElement * getInstance(SoState *state); 00167 static float getDefaultAmbientIntensity(void); 00168 00169 static SbColor getDefaultDiffuse(void); 00170 static SbColor getDefaultAmbient(void); 00171 static SbColor getDefaultSpecular(void); 00172 static SbColor getDefaultEmissive(void); 00173 static float getDefaultShininess(void); 00174 static uint32_t getDefaultPacked(void); 00175 static float getDefaultTransparency(void); 00176 static int32_t getDefaultLightModel(void); 00177 static int32_t getDefaultColorIndex(void); 00178 00179 static void setMaterials(SoState * state, SoNode *node, uint32_t bitmask, 00180 SoColorPacker * cPacker, 00181 const SbColor * diffuse, 00182 const int numdiffuse, 00183 const float * transp, 00184 const int numtransp, 00185 const SbColor & ambient, 00186 const SbColor & emissive, 00187 const SbColor & specular, 00188 const float shininess, 00189 const SbBool istransparent); 00190 00191 static SoLazyElement * getWInstance(SoState *state); 00192 00193 const uint32_t * getPackedPointer(void) const; 00194 const SbColor * getDiffusePointer(void) const; 00195 const int32_t * getColorIndexPointer(void) const; 00196 00197 const float * getTransparencyPointer(void) const; 00198 static void setTransparencyType(SoState * state, int32_t type); 00199 00200 protected: 00201 00202 struct COIN_DLL_API CoinState { 00203 SbColor ambient; 00204 SbColor specular; 00205 SbColor emissive; 00206 float shininess; 00207 SbBool blending; 00208 int blend_sfactor; 00209 int blend_dfactor; 00210 int alpha_blend_sfactor; 00211 int alpha_blend_dfactor; 00212 int32_t lightmodel; 00213 SbBool packeddiffuse; 00214 int32_t numdiffuse; 00215 int32_t numtransp; 00216 const SbColor * diffusearray; 00217 const uint32_t * packedarray; 00218 const float * transparray; 00219 const int32_t * colorindexarray; 00220 int32_t transptype; 00221 SbBool istransparent; 00222 uint32_t diffusenodeid; 00223 uint32_t transpnodeid; 00224 int32_t stipplenum; 00225 VertexOrdering vertexordering; 00226 SbBool twoside; 00227 SbBool culling; 00228 SbBool flatshading; 00229 uint32_t glimageid; 00230 SoGLImage * glimage; 00231 SbBool alphatest; 00232 SbBool glimageusealphatest; 00233 uint32_t reserved[4]; 00234 } coinstate; 00235 00236 protected: 00237 virtual void lazyDidSet(uint32_t mask); 00238 virtual void lazyDidntSet(uint32_t mask); 00239 00240 virtual void setDiffuseElt(SoNode*, int32_t numcolors, 00241 const SbColor * colors, SoColorPacker * packer); 00242 virtual void setPackedElt(SoNode * node, int32_t numcolors, 00243 const uint32_t * colors, const SbBool packedtransparency); 00244 virtual void setColorIndexElt(SoNode * node, int32_t numindices, 00245 const int32_t * indices); 00246 virtual void setTranspElt(SoNode * node, int32_t numtransp, 00247 const float * transp, SoColorPacker * packer); 00248 00249 virtual void setTranspTypeElt(int32_t type); 00250 virtual void setAmbientElt(const SbColor* color); 00251 virtual void setEmissiveElt(const SbColor* color); 00252 virtual void setSpecularElt(const SbColor* color); 00253 virtual void setShininessElt(float value); 00254 virtual void setColorMaterialElt(SbBool value); 00255 virtual void enableBlendingElt(int sfactor, int dfactor, int alpha_sfactor, int alpha_dfactor); 00256 virtual void disableBlendingElt(void); 00257 virtual void setLightModelElt(SoState *state, int32_t model); 00258 virtual void setMaterialElt(SoNode * node, uint32_t bitmask, 00259 SoColorPacker * packer, 00260 const SbColor * diffuse, const int numdiffuse, 00261 const float * transp, const int numtransp, 00262 const SbColor & ambient, 00263 const SbColor & emissive, 00264 const SbColor & specular, 00265 const float shininess, 00266 const SbBool istransparent); 00267 virtual void setVertexOrderingElt(VertexOrdering ordering); 00268 virtual void setBackfaceCullingElt(SbBool onoff); 00269 virtual void setTwosideLightingElt(SbBool onoff); 00270 virtual void setShadeModelElt(SbBool flatshading); 00271 virtual void setGLImageIdElt(uint32_t glimageid, SbBool alphatest); 00272 virtual void setAlphaTestElt(SbBool onoff); 00273 00274 private: 00275 SoLazyElementP * pimpl; // for future use 00276 00277 }; 00278 00279 class COIN_DLL_API SoColorPacker { 00280 public: 00281 SoColorPacker(void); 00282 ~SoColorPacker(); 00283 00284 uint32_t * getPackedColors(void) const { 00285 return this->array; 00286 } 00287 SbBool diffuseMatch(const uint32_t nodeid) const { 00288 return nodeid == this->diffuseid; 00289 } 00290 SbBool transpMatch(const uint32_t nodeid) const { 00291 return nodeid == this->transpid; 00292 } 00293 void setNodeIds(const uint32_t diffuse, const uint32_t transp) { 00294 this->diffuseid = diffuse; 00295 this->transpid = transp; 00296 } 00297 int32_t getSize(void) const { 00298 return this->arraysize; 00299 } 00300 void reallocate(const int32_t size); 00301 00302 uint32_t getDiffuseId(void) const { 00303 return this->diffuseid; 00304 } 00305 uint32_t getTranspId(void) const { 00306 return this->transpid; 00307 } 00308 private: 00309 uint32_t transpid; 00310 uint32_t diffuseid; 00311 uint32_t * array; 00312 int32_t arraysize; 00313 }; 00314 00315 #endif // !COIN_SOLAZYELEMENT_H
Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.
Generated on 19 Dec 2016 for Coin by Doxygen 1.6.1.