From Michael Platings, To address performance bottleneck that occurs when using large number of uniforms introduced a name to uniqued ID scheme for Uniforms so comparisons can be done on a uint rather than a string.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <osg/Program>
|
||||
#include <osg/StateSet>
|
||||
|
||||
#include <limits.h>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace osg;
|
||||
@@ -30,13 +31,13 @@ using namespace osg;
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Uniform::Uniform() :
|
||||
_type(UNDEFINED), _numElements(0), _modifiedCount(0)
|
||||
_type(UNDEFINED), _numElements(0), _nameID(UINT_MAX), _modifiedCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Uniform::Uniform( Type type, const std::string& name, int numElements ) :
|
||||
_type(type), _numElements(0), _modifiedCount(0)
|
||||
_type(type), _numElements(0), _nameID(UINT_MAX), _modifiedCount(0)
|
||||
{
|
||||
setName(name);
|
||||
setNumElements(numElements);
|
||||
@@ -88,6 +89,7 @@ void Uniform::setName( const std::string& name )
|
||||
return;
|
||||
}
|
||||
_name = name;
|
||||
_nameID = getNameID(name);
|
||||
}
|
||||
|
||||
void Uniform::setNumElements( unsigned int numElements )
|
||||
@@ -255,6 +257,7 @@ void Uniform::copyData(const Uniform& rhs)
|
||||
{
|
||||
// caller must ensure that _type==rhs._type
|
||||
_numElements = rhs._numElements;
|
||||
_nameID = rhs._nameID;
|
||||
if (rhs._floatArray.valid() || rhs._intArray.valid() || rhs._uintArray.valid()) allocateDataArray();
|
||||
if( _floatArray.valid() && rhs._floatArray.valid() ) *_floatArray = *rhs._floatArray;
|
||||
if( _intArray.valid() && rhs._intArray.valid() ) *_intArray = *rhs._intArray;
|
||||
@@ -601,6 +604,24 @@ GLenum Uniform::getInternalArrayType( Type t )
|
||||
}
|
||||
|
||||
|
||||
unsigned int Uniform::getNameID(const std::string& name)
|
||||
{
|
||||
typedef std::map<std::string, unsigned int> UniformNameIDMap;
|
||||
static OpenThreads::Mutex s_mutex_uniformNameIDMap;
|
||||
static UniformNameIDMap s_uniformNameIDMap;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_uniformNameIDMap);
|
||||
UniformNameIDMap::iterator it = s_uniformNameIDMap.find(name);
|
||||
if (it != s_uniformNameIDMap.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
unsigned int id = s_uniformNameIDMap.size();
|
||||
s_uniformNameIDMap.insert(UniformNameIDMap::value_type(name, id));
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// value constructors for single-element (ie: non-array) uniforms
|
||||
|
||||
@@ -1388,6 +1409,11 @@ bool Uniform::getElement( unsigned int index, bool& b0, bool& b1, bool& b2, bool
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int Uniform::getNameID() const
|
||||
{
|
||||
return _nameID;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Uniform::apply(const GL2Extensions* ext, GLint location) const
|
||||
|
||||
Reference in New Issue
Block a user