Added basic support for applying uniforms to programs, non lazy state updating

is yet applied though.
This commit is contained in:
Robert Osfield 2005-04-13 14:12:06 +00:00
parent 2e10cffb4d
commit 0015a31de8
4 changed files with 27 additions and 16 deletions

View File

@ -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" );

View File

@ -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; }

View File

@ -2155,8 +2155,6 @@ void Program::PerContextProgram::linkProgram()
return;
}
notify(NOTICE)<<"Program "<<std::endl;
// build ActiveUniformList
GLint numUniforms = 0;
GLsizei maxLen = 0;
@ -2172,11 +2170,11 @@ void Program::PerContextProgram::linkProgram()
{
_extensions->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 "<<name<<std::endl;
_uniformLocationMap[name] = loc;
}
}
@ -2197,19 +2195,16 @@ void Program::PerContextProgram::linkProgram()
{
_extensions->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 "<<name<<std::endl;
_attribLocationMap[name] = loc;
}
}
delete [] name;
}
notify(NOTICE)<<"Program "<<std::endl;
}
void Program::PerContextProgram::getInfoLog( std::string& infoLog ) const

View File

@ -28,7 +28,7 @@ State::State()
_modelView = _identity;
_abortRenderingPtr = false;
_reportGLErrors = true;
_reportGLErrors = false;
_currentActiveTextureUnit=0;
_currentClientActiveTextureUnit=0;
@ -282,10 +282,14 @@ void State::apply(const StateSet* dstate)
if (_lastAppliedProgramObject)
{
osg::notify(osg::NOTICE)<<"Ready to apply uniforms A"<<std::endl;
const StateSet::UniformList& uniformList = dstate->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"<<std::endl;
const StateSet::UniformList& uniformList = _stateStateStack.back()->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()");