From a383330ae4788df03ee026c7bf3679c1799c9d10 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 10 Nov 2004 09:56:03 +0000 Subject: [PATCH] From Mike Weiblen, fix to the state leakage. --- examples/osgshaders/GL2Scene.cpp | 28 ++++++---------------------- include/osgGL2/ProgramObject | 8 ++++---- src/osgGL2/ProgramObject.cpp | 7 ++++++- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/examples/osgshaders/GL2Scene.cpp b/examples/osgshaders/GL2Scene.cpp index e7d05051c..1255210f7 100644 --- a/examples/osgshaders/GL2Scene.cpp +++ b/examples/osgshaders/GL2Scene.cpp @@ -1,5 +1,5 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield - * Copyright (C) 2003 3Dlabs Inc. Ltd. +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield + * Copyright (C) 2003-2004 3Dlabs Inc. Ltd. * * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commericial and non commericial applications, @@ -11,7 +11,7 @@ */ /* file: examples/osgshaders/GL2Scene.cpp - * author: Mike Weiblen 2004-09-15 + * author: Mike Weiblen 2004-11-09 * * Compose a scene of several instances of a model, with a different * OpenGL Shading Language shader applied to each. @@ -220,15 +220,12 @@ static osgGL2::ShaderObject* MarbleVertObj; static osgGL2::ShaderObject* MarbleFragObj; /////////////////////////////////////////////////////////////////////////// +// for demo simplicity, this one callback animates all the shaders. -// TODO encapsulate inside an osgFX effect. class AnimateCallback: public osg::NodeCallback { public: - AnimateCallback( osgGL2::ProgramObject* /*progObj*/ ) : - osg::NodeCallback(), - _enabled(true) - {} + AnimateCallback() : osg::NodeCallback(), _enabled(true) {} virtual void operator() ( osg::Node* node, osg::NodeVisitor* nv ) { @@ -267,21 +264,8 @@ GL2Scene::buildScene() osg::Texture1D* sineTexture = make1DSineTexture( 32 /*1024*/ ); // the root of our scenegraph. - // attach an "empty" ProgramObject to the rootNode, which will act as - // the default StateAttribute. An empty ProgramObject (ie without any - // attached ShaderObjects) is a special case, which means to use the - // OpenGL 1.x "fixed functionality" rendering pipeline. rootNode = new osg::Group; - rootNode->setUpdateCallback( new AnimateCallback(0) ); - { - // TODO this definition of a "default ProgramObject state" will not - // be necessary when the OSG core has proper support for the unique - // requirements of ProgramObject. - osg::StateSet* ss = rootNode->getOrCreateStateSet(); - osgGL2::ProgramObject* progObj = new osgGL2::ProgramObject; - _progObjList.push_back( progObj ); - ss->setAttributeAndModes(progObj, osg::StateAttribute::ON); - } + rootNode->setUpdateCallback( new AnimateCallback ); // the simple Microshader (its source appears earlier in this file) { diff --git a/include/osgGL2/ProgramObject b/include/osgGL2/ProgramObject index ffc3c69a8..0cb24d75e 100644 --- a/include/osgGL2/ProgramObject +++ b/include/osgGL2/ProgramObject @@ -1,5 +1,5 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield - * Copyright (C) 2003 3Dlabs Inc. Ltd. +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield + * Copyright (C) 2003-2004 3Dlabs Inc. Ltd. * * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commericial and non commericial @@ -11,7 +11,7 @@ */ /* file: include/osgGL2/ProgramObject - * author: Mike Weiblen 2003-12-28 + * author: Mike Weiblen 2004-11-09 * * See http://www.3dlabs.com/opengl2/ for more information regarding * the OpenGL Shading Language. @@ -75,7 +75,7 @@ class OSGGL2_EXPORT ProgramObject : public osg::StateAttribute * be pending. */ virtual void apply(osg::State& state) const; - virtual void compileGLObjects(osg::State& state) const { apply(state); } + virtual void compileGLObjects(osg::State& state) const; /** release an OpenGL objects in specified graphics context if State object is passed, otherwise release OpenGL objexts for all graphics context if diff --git a/src/osgGL2/ProgramObject.cpp b/src/osgGL2/ProgramObject.cpp index b9d08f4b8..289afd651 100644 --- a/src/osgGL2/ProgramObject.cpp +++ b/src/osgGL2/ProgramObject.cpp @@ -12,7 +12,7 @@ */ /* file: src/osgGL2/ProgramObject.cpp - * author: Mike Weiblen 2004-07-08 + * author: Mike Weiblen 2004-11-09 * * See http://www.3dlabs.com/opengl2/ for more information regarding * the OpenGL Shading Language. @@ -208,6 +208,11 @@ int ProgramObject::compare(const osg::StateAttribute& sa) const } +void ProgramObject::compileGLObjects(osg::State& state) const +{ +} + + // mark all PCPOs as needing a relink void ProgramObject::dirtyProgramObject() {