Added support for osg_FrameNumber, osg_FrameTime, osg_ViewMatrix, osg_InverseViewMatrix
into SceneView, controlled via a setActiveUniforms(.) method.
This commit is contained in:
@@ -923,6 +923,25 @@ Uniform* StateSet::getUniform(const std::string& name)
|
||||
else return 0;
|
||||
}
|
||||
|
||||
Uniform* StateSet::getOrCreateUniform(const std::string& name, Uniform::Type type)
|
||||
{
|
||||
// for look for an appropriate uniform.
|
||||
UniformList::iterator itr = _uniformList.find(name);
|
||||
if (itr!=_uniformList.end() &&
|
||||
itr->second.first->getType()==type)
|
||||
{
|
||||
return itr->second.first.get();
|
||||
}
|
||||
|
||||
// no uniform found matching name so create it..
|
||||
|
||||
Uniform* uniform = new Uniform(name,type);
|
||||
addUniform(uniform);
|
||||
|
||||
return uniform;
|
||||
}
|
||||
|
||||
|
||||
const Uniform* StateSet::getUniform(const std::string& name) const
|
||||
{
|
||||
UniformList::const_iterator itr = _uniformList.find(name);
|
||||
|
||||
@@ -34,7 +34,7 @@ Uniform::Uniform() :
|
||||
}
|
||||
|
||||
|
||||
Uniform::Uniform( const char* name, Type type ) :
|
||||
Uniform::Uniform( const std::string& name, Type type ) :
|
||||
_name(name), _type(type),_modifiedCount(0)
|
||||
{
|
||||
setDataVariance(STATIC);
|
||||
@@ -89,6 +89,8 @@ void Uniform::removeParent(osg::StateSet* object)
|
||||
|
||||
bool Uniform::setType( Type t )
|
||||
{
|
||||
if (_type==t) return true;
|
||||
|
||||
if( _type != UNDEFINED )
|
||||
{
|
||||
osg::notify(osg::WARN) << "cannot change Uniform type" << std::endl;
|
||||
@@ -721,6 +723,7 @@ bool Uniform::get( bool& b0, bool& b1, bool& b2, bool& b3 ) const
|
||||
|
||||
void Uniform::apply(const GL2Extensions* ext, GLint location) const
|
||||
{
|
||||
// osg::notify(osg::NOTICE) << "uniform at "<<location<<" "<<_name<< std::endl;
|
||||
switch( getGlApiType(getType()) )
|
||||
{
|
||||
case FLOAT:
|
||||
|
||||
@@ -52,6 +52,8 @@ SceneView::SceneView(DisplaySettings* ds)
|
||||
_drawBufferValue = GL_BACK;
|
||||
|
||||
_requiresFlush = true;
|
||||
|
||||
_activeUniforms = DEFAULT_UNIFORMS;
|
||||
}
|
||||
|
||||
|
||||
@@ -163,11 +165,6 @@ void SceneView::init()
|
||||
|
||||
void SceneView::update()
|
||||
{
|
||||
// comment out since the init traversal by default with do OpenGL calls,
|
||||
// which you definately don't want to call during update().
|
||||
// if (!_initCalled) init();
|
||||
|
||||
|
||||
if (_sceneData.valid() && _updateVisitor.valid())
|
||||
{
|
||||
_updateVisitor->reset();
|
||||
@@ -188,8 +185,41 @@ void SceneView::update()
|
||||
// multi-threaded.
|
||||
_sceneData->getBound();
|
||||
}
|
||||
}
|
||||
|
||||
void SceneView::updateUniforms()
|
||||
{
|
||||
if (!_localStateSet)
|
||||
{
|
||||
_localStateSet = new osg::StateSet;
|
||||
}
|
||||
|
||||
if (!_localStateSet) return;
|
||||
|
||||
if ((_activeUniforms & FRAME_NUMBER_UNIFORM) && _frameStamp.valid())
|
||||
{
|
||||
osg::Uniform* uniform = _localStateSet->getOrCreateUniform("osg_FrameNumber",osg::Uniform::INT);
|
||||
uniform->set(_frameStamp->getFrameNumber());
|
||||
}
|
||||
|
||||
if ((_activeUniforms & FRAME_TIME_UNIFORM) && _frameStamp.valid())
|
||||
{
|
||||
osg::Uniform* uniform = _localStateSet->getOrCreateUniform("osg_FrameTime",osg::Uniform::FLOAT);
|
||||
uniform->set(static_cast<float>(_frameStamp->getReferenceTime()));
|
||||
}
|
||||
|
||||
if (_activeUniforms & VIEW_MATRIX_UNIFORM)
|
||||
{
|
||||
osg::Uniform* uniform = _localStateSet->getOrCreateUniform("osg_ViewMatrix",osg::Uniform::FLOAT_MAT4);
|
||||
uniform->set(_viewMatrix);
|
||||
}
|
||||
|
||||
if (_activeUniforms & INVERSE_VIEW_MATRIX_UNIFORM)
|
||||
{
|
||||
osg::Uniform* uniform = _localStateSet->getOrCreateUniform("osg_InverseViewMatrix",osg::Uniform::FLOAT_MAT4);
|
||||
uniform->set(osg::Matrix::inverse(_viewMatrix));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
osg::Matrixd SceneView::computeLeftEyeProjectionImplementation(const osg::Matrixd& projection) const
|
||||
@@ -324,6 +354,8 @@ osg::Matrixd SceneView::computeRightEyeViewImplementation(const osg::Matrixd& vi
|
||||
|
||||
void SceneView::cull()
|
||||
{
|
||||
// update the active uniforms
|
||||
updateUniforms();
|
||||
|
||||
if (!_state)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user