From fb34b22e34e3eece698ac3a7a24e33ba658ea547 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 11 May 2005 11:41:44 +0000 Subject: [PATCH] Cleaned up API of BindAttributeLocation, added deletion of shader objects. --- include/osg/Program | 7 ++++++- src/osg/Program.cpp | 8 +++++++- src/osgPlugins/osg/Program.cpp | 20 +++++++++++++++----- src/osgUtil/SceneView.cpp | 3 +++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/include/osg/Program b/include/osg/Program index d49dc84fb..9ef51b5c5 100644 --- a/include/osg/Program +++ b/include/osg/Program @@ -340,8 +340,13 @@ class OSG_EXPORT Program : public osg::StateAttribute bool removeShader( Shader* shader ); /** Add an attribute location binding. */ - void bindAttribLocation( GLuint index, const char* name ); + void addBindAttribLocation( const std::string& name, GLuint index ); + + /** Add an attribute location binding. */ + void removeBindAttribLocation( const std::string& name ); + typedef std::map AttribBindingList; + const AttribBindingList& getAttribBindingList() const { return _attribBindingList; } /** Return true if this Program represents "fixed-functionality" rendering */ diff --git a/src/osg/Program.cpp b/src/osg/Program.cpp index a5d1d935c..91121e0a8 100644 --- a/src/osg/Program.cpp +++ b/src/osg/Program.cpp @@ -2034,12 +2034,18 @@ bool Program::removeShader( Shader* shader ) } -void Program::bindAttribLocation( GLuint index, const char* name ) +void Program::addBindAttribLocation( const std::string& name, GLuint index ) { _attribBindingList[name] = index; dirtyProgram(); } +void Program::removeBindAttribLocation( const std::string& name ) +{ + _attribBindingList.erase(name); + dirtyProgram(); +} + void Program::apply( osg::State& state ) const { diff --git a/src/osgPlugins/osg/Program.cpp b/src/osgPlugins/osg/Program.cpp index 9b9538298..238ec9f1c 100644 --- a/src/osgPlugins/osg/Program.cpp +++ b/src/osgPlugins/osg/Program.cpp @@ -37,11 +37,21 @@ bool Program_readLocalData(Object& obj, Input& fr) iteratorAdvanced = true; } - while(fr[0].matchWord("AttribBindingLocation")) + while(fr.matchSequence("AttribBindingLocation %i %w")) { - int index; - fr[1].getInt(index); - program.bindAttribLocation(index,fr[2].getStr()); + unsigned int index; + fr[1].getUInt(index); + program.addBindAttribLocation(fr[2].getStr(), index); + fr += 3; + iteratorAdvanced = true; + } + + + while(fr.matchSequence("AttribBindingLocation %w %i")) + { + unsigned int index; + fr[2].getUInt(index); + program.addBindAttribLocation(fr[1].getStr(), index); fr += 3; iteratorAdvanced = true; } @@ -76,7 +86,7 @@ bool Program_writeLocalData(const Object& obj,Output& fw) Program::AttribBindingList::const_iterator i; for(i=abl.begin(); i!=abl.end(); i++) { - fw.indent() << "AttribBindingLocation " << (*i).second << " " << (*i).first << std::endl; + fw.indent() << "AttribBindingLocation " << (*i).first << " " << (*i).second << std::endl; } fw.indent() << "num_shaders " << program.getNumShaders() << std::endl; diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index c990f6393..d34e65bc8 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -658,6 +659,7 @@ void SceneView::flushAllDeletedGLObjects() osg::VertexProgram::flushDeletedVertexProgramObjects(_state->getContextID(),currentTime,availableTime); osg::FragmentProgram::flushDeletedFragmentProgramObjects(_state->getContextID(),currentTime,availableTime); osg::Program::flushDeletedGlPrograms(_state->getContextID(),currentTime,availableTime); + osg::Shader::flushDeletedGlShaders(_state->getContextID(),currentTime,availableTime); } void SceneView::flushDeletedGLObjects(double& availableTime) @@ -671,6 +673,7 @@ void SceneView::flushDeletedGLObjects(double& availableTime) osg::VertexProgram::flushDeletedVertexProgramObjects(_state->getContextID(),currentTime,availableTime); osg::FragmentProgram::flushDeletedFragmentProgramObjects(_state->getContextID(),currentTime,availableTime); osg::Program::flushDeletedGlPrograms(_state->getContextID(),currentTime,availableTime); + osg::Shader::flushDeletedGlShaders(_state->getContextID(),currentTime,availableTime); } void SceneView::draw()