- Timestamp:
- 03/19/03 13:06:29 (10 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgtexture3D/osgtexture3D.cpp
r1697 r1717 25 25 26 26 27 class ConstructStateCallback : public osg ::NodeCallback27 class ConstructStateCallback : public osgProducer::OsgCameraGroup::RealizeCallback 28 28 { 29 29 public: 30 ConstructStateCallback( ) {}30 ConstructStateCallback(osg::Node* node):_node(node),_initialized(false) {} 31 31 32 32 osg::StateSet* constructState() … … 83 83 texture3D->setFilter(osg::Texture3D::MIN_FILTER,osg::Texture3D::LINEAR); 84 84 texture3D->setFilter(osg::Texture3D::MAG_FILTER,osg::Texture3D::LINEAR); 85 texture3D->setWrap(osg::Texture3D::WRAP_R,osg::Texture3D::REPEAT); 85 86 texture3D->setImage(image_3d); 86 87 … … 104 105 } 105 106 107 virtual void operator()(const Producer::RenderSurface&, osgProducer::OsgCameraGroup* , osgProducer::OsgSceneHandler* sh) 108 { 109 if (!_initialized) 110 { 111 // only initialize state once, only need for cases where multiple graphics contexts are 112 // if which case this callback can get called multiple times. 113 _initialized = true; 114 115 if (_node) _node->setStateSet(constructState()); 116 } 117 // now safe to con 118 sh->init(); 119 120 } 121 122 123 osg::Node* _node; 124 bool _initialized; 125 126 }; 127 128 class UpdateStateCallback : public osg::NodeCallback 129 { 130 public: 131 UpdateStateCallback() {} 132 106 133 void animateState(osg::StateSet* stateset) 107 134 { … … 114 141 texgen->getPlane(osg::TexGen::R)[3] += 0.001f; 115 142 } 116 143 117 144 } 118 145 … … 125 152 // we have an exisitng stateset, so lets animate it. 126 153 animateState(stateset); 127 }128 else129 {130 // no state exist yet, so we must be in the first131 // pass, so lets create our stateset with all the132 // textures in it.133 stateset = constructState();134 if (stateset) node->setStateSet(stateset);135 154 } 136 155 … … 190 209 // osg::Image::copySubImage() without using GLU which will get round 191 210 // this current limitation. 192 geode->setUpdateCallback(new ConstructStateCallback());211 geode->setUpdateCallback(new UpdateStateCallback()); 193 212 194 213 return geode; … … 242 261 // set the scene to render 243 262 viewer.setSceneData(rootNode); 263 264 // the construct state uses gl commands to resize images so we are forced 265 // to only call it once a valid graphics context has been established, 266 // for that we use a realize callback. 267 viewer.setRealizeCallback(new ConstructStateCallback(rootNode)); 244 268 245 269 // create the windows and run the threads.
