Coin Logo http://www.sim.no/
http://www.coin3d.org/

SoGLLazyElement.h
00001 #ifndef COIN_SOGLLAZYELEMENT_H
00002 #define COIN_SOGLLAZYELEMENT_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/SoLazyElement.h>
00028 #include <Inventor/C/glue/gl.h>
00029 
00030 class SoGLRenderCache;
00031 class SoGLLazyElementP;
00032 class SoVBO;
00033 
00034 class COIN_DLL_API SoGLLazyElement : public SoLazyElement {
00035   typedef SoLazyElement inherited;
00036 
00037   SO_ELEMENT_HEADER(SoGLLazyElement);
00038 
00039 public:
00040   static void initClass();
00041 protected:
00042   ~SoGLLazyElement();
00043 public:
00044 
00045   virtual void init(SoState *state);
00046   virtual void push(SoState *state);
00047   virtual void pop(SoState *state, const SoElement * prevtopelement);
00048 
00049   static void sendAllMaterial(SoState * state);
00050   static void sendNoMaterial(SoState * state);
00051   static void sendOnlyDiffuseColor(SoState * state);
00052   static void sendLightModel(SoState * state, const int32_t model);
00053   static void sendPackedDiffuse(SoState * state, const uint32_t diffuse);
00054   static void sendFlatshading(SoState * state, const SbBool onoff);
00055   static void sendVertexOrdering(SoState * state, const VertexOrdering ordering);
00056   static void sendTwosideLighting(SoState * state, const SbBool onoff);
00057   static void sendBackfaceCulling(SoState * state, const SbBool onoff);
00058 
00059   void sendDiffuseByIndex(const int index) const;
00060   static SbBool isColorIndex(SoState *state);
00061   static SoGLLazyElement * getInstance(const SoState *state);
00062   void send(const SoState *state, uint32_t mask) const;
00063 
00064   void sendVPPacked(SoState* state, const unsigned char* pcolor);
00065 
00066   void reset(SoState* state, uint32_t bitmask) const;
00067 
00068   typedef struct COIN_DLL_API {
00069     uint32_t cachebitmask;
00070     uint32_t diffuse;
00071     SbColor ambient;
00072     SbColor emissive;
00073     SbColor specular;
00074     float shininess;
00075     int32_t lightmodel;
00076     int32_t blending;
00077     int32_t blend_sfactor;
00078     int32_t blend_dfactor;
00079     int32_t alpha_blend_sfactor;
00080     int32_t alpha_blend_dfactor;
00081     int32_t stipplenum;
00082     int32_t vertexordering;
00083     int32_t culling;
00084     int32_t twoside;
00085     int32_t flatshading;
00086     int32_t glimageid;
00087     int32_t alphatest;
00088     uint32_t diffusenodeid;
00089     uint32_t transpnodeid;
00090     uint32_t reserved[4];
00091   } GLState;
00092 
00093   virtual void setDiffuseElt(SoNode*,  int32_t numcolors,
00094                              const SbColor * colors, SoColorPacker * packer);
00095   virtual void setPackedElt(SoNode * node, int32_t numcolors,
00096                             const uint32_t * colors, const SbBool packedtransparency);
00097   virtual void setColorIndexElt(SoNode * node, int32_t numindices,
00098                                 const int32_t * indices);
00099   virtual void setTranspElt(SoNode * node, int32_t numtransp,
00100                             const float * transp, SoColorPacker * packer);
00101 
00102   virtual void setTranspTypeElt(int32_t type);
00103   virtual void setAmbientElt(const SbColor* color);
00104   virtual void setEmissiveElt(const SbColor* color);
00105   virtual void setSpecularElt(const SbColor* color);
00106   virtual void setShininessElt(float value);
00107   virtual void setColorMaterialElt(SbBool value);
00108   virtual void enableBlendingElt(int sfactor, int dfactor, int alpha_sfactor, int alpha_dfactor);
00109   virtual void disableBlendingElt(void);
00110   virtual void setLightModelElt(SoState *state, int32_t model);
00111   virtual void setMaterialElt(SoNode * node, uint32_t bitmask,
00112                               SoColorPacker * packer,
00113                               const SbColor * diffuse, const int numdiffuse,
00114                               const float * transp, const int numtransp,
00115                               const SbColor & ambient,
00116                               const SbColor & emissive,
00117                               const SbColor & specular,
00118                               const float shininess,
00119                               const SbBool istransparent);
00120   virtual void setVertexOrderingElt(VertexOrdering ordering);
00121   virtual void setBackfaceCullingElt(SbBool onoff);
00122   virtual void setTwosideLightingElt(SbBool onoff);
00123   virtual void setShadeModelElt(SbBool flatshading);
00124   virtual void setGLImageIdElt(uint32_t glimageid, SbBool alphatest);
00125   virtual void setAlphaTestElt(SbBool onoff);
00126 
00127   static void beginCaching(SoState * state,
00128                            SoGLLazyElement::GLState * prestate,
00129                            SoGLLazyElement::GLState * poststate);
00130   static void endCaching(SoState * state);
00131 
00132   static SbBool preCacheCall(SoState * state, SoGLLazyElement::GLState * prestate);
00133   static void postCacheCall(SoState * state, SoGLLazyElement::GLState * poststate);
00134 
00135   static void mergeCacheInfo(SoState * state,
00136                              SoGLLazyElement::GLState * childprestate,
00137                              SoGLLazyElement::GLState * childpoststate);
00138 
00139   void updateColorVBO(SoVBO * vbo);
00140 
00141 protected:
00142   virtual void lazyDidSet(uint32_t mask);
00143   virtual void lazyDidntSet(uint32_t mask);
00144 
00145 private:
00146   void sendPackedDiffuse(const uint32_t diffuse) const;
00147   void sendAmbient(const SbColor & color) const;
00148   void sendEmissive(const SbColor & color) const;
00149   void sendSpecular(const SbColor & specular) const;
00150   void sendShininess(const float shininess) const;
00151   void sendTransparency(const int stipplenum) const;
00152   void enableBlending(const int sfactor, const int dfactor) const;
00153   void enableSeparateBlending(const cc_glglue * glue,
00154                               const int sfactor, const int dfactor,
00155                               const int alpha_sfactor, const int alpha_dfactor) const;
00156   void disableBlending(void) const;
00157 
00158   void sendLightModel(const int32_t model) const;
00159   void sendFlatshading(const SbBool onoff) const;
00160   void sendVertexOrdering(const VertexOrdering ordering) const;
00161   void sendTwosideLighting(const SbBool onoff) const;
00162   void sendBackfaceCulling(const SbBool onoff) const;
00163   void sendGLImage(const uint32_t glimageid) const;
00164   void sendAlphaTest(const SbBool onoff) const;
00165   void initGL(void);
00166   void packColors(SoColorPacker * packer) const;
00167 
00168   uint32_t didsetbitmask;
00169   uint32_t didntsetbitmask;
00170   uint32_t cachebitmask;
00171   uint32_t opencacheflags;
00172 
00173   GLState glstate;
00174   GLState * postcachestate;
00175   GLState * precachestate;
00176   SbBool colorindex;
00177   SoColorPacker * colorpacker;
00178   const uint32_t * packedpointer;
00179   uint32_t transpmask;
00180   SoState * state;
00181   SoGLLazyElementP * pimpl; // for future use
00182 };
00183 
00184 #endif // !COIN_SOGLLAZYELEMENT_H

Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.

Generated on Thu Apr 28 2011 03:43:04 for Coin by Doxygen 1.7.4.