From 0015a31de8b77df9935f989edd3c4630139cc898 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 13 Apr 2005 14:12:06 +0000 Subject: [PATCH] Added basic support for applying uniforms to programs, non lazy state updating is yet applied though. --- examples/osgshaders/GL2Scene.cpp | 2 +- include/osg/Program | 6 ++++++ src/osg/Program.cpp | 13 ++++--------- src/osg/State.cpp | 22 ++++++++++++++++------ 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/examples/osgshaders/GL2Scene.cpp b/examples/osgshaders/GL2Scene.cpp index 2fac04cb9..d0634b2ed 100644 --- a/examples/osgshaders/GL2Scene.cpp +++ b/examples/osgshaders/GL2Scene.cpp @@ -376,7 +376,7 @@ GL2Scene::~GL2Scene() void GL2Scene::reloadShaderSource() { - osg::notify(osg::WARN) << "reloadShaderSource()" << std::endl; + osg::notify(osg::INFO) << "reloadShaderSource()" << std::endl; LoadShaderSource( BlockyVertObj, "shaders/blocky.vert" ); LoadShaderSource( BlockyFragObj, "shaders/blocky.frag" ); diff --git a/include/osg/Program b/include/osg/Program index 085d82b07..24e5f3934 100644 --- a/include/osg/Program +++ b/include/osg/Program @@ -389,6 +389,12 @@ class OSG_EXPORT Program : public osg::StateAttribute void getInfoLog( std::string& infoLog ) const; void useProgram() const; + + void apply(const Uniform& uniform) const + { + GLint location = getUniformLocation(uniform.getName()); + if (location>=0) uniform.apply(_extensions.get(),location); + } inline GLint getUniformLocation( const std::string& name ) const { NameLocationMap::const_iterator itr = _uniformLocationMap.find(name); return (itr!=_uniformLocationMap.end()) ? itr->second : -1; } inline GLint getAttribLocation( const std::string& name ) const { NameLocationMap::const_iterator itr = _attribLocationMap.find(name); return (itr!=_attribLocationMap.end()) ? itr->second : -1; } diff --git a/src/osg/Program.cpp b/src/osg/Program.cpp index 8f3a76739..2dc7dc3bb 100644 --- a/src/osg/Program.cpp +++ b/src/osg/Program.cpp @@ -2155,8 +2155,6 @@ void Program::PerContextProgram::linkProgram() return; } - notify(NOTICE)<<"Program "<glGetActiveUniform( _glProgramHandle, i, maxLen, 0, &size, &type, name ); - GLint loc = getUniformLocation( name ); + + GLint loc = _extensions->glGetUniformLocation( _glProgramHandle, name ); if( loc != -1 ) { - notify(NOTICE)<<" Active uniform "<glGetActiveAttrib( _glProgramHandle, i, maxLen, 0, &size, &type, name ); - GLint loc = getUniformLocation( name ); + + GLint loc = _extensions->glGetAttribLocation( _glProgramHandle, name ); if( loc != -1 ) { - notify(NOTICE)<<" Active attribute "<getUniformList(); + for(StateSet::UniformList::const_iterator itr=uniformList.begin(); + itr!=uniformList.end(); + ++itr) + { + _lastAppliedProgramObject->apply(*(itr->second.first)); + } } - - } else { @@ -319,9 +323,15 @@ void State::apply() } } - if (_lastAppliedProgramObject) + if (_lastAppliedProgramObject && !_stateStateStack.empty()) { - osg::notify(osg::NOTICE)<<"Ready to apply uniforms B"<getUniformList(); + for(StateSet::UniformList::const_iterator itr=uniformList.begin(); + itr!=uniformList.end(); + ++itr) + { + _lastAppliedProgramObject->apply(*(itr->second.first)); + } } if (_reportGLErrors) checkGLErrors("end of State::apply()");