Changed osgFX::MultiTextureControl so that it uses an osg::FloatArray internally to enable sharing with osg::Uniform.
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14675 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
@@ -23,11 +23,12 @@ MultiTextureControl::MultiTextureControl():
|
||||
_useTexEnvCombine(true),
|
||||
_useTextureWeightsUniform(true)
|
||||
{
|
||||
_textureWeights = new TextureWeights;
|
||||
}
|
||||
|
||||
MultiTextureControl::MultiTextureControl(const MultiTextureControl& copy, const osg::CopyOp& copyop):
|
||||
Group(copy,copyop),
|
||||
_textureWeightList(copy._textureWeightList),
|
||||
_textureWeights(osg::clone(copy._textureWeights.get(), osg::CopyOp::DEEP_COPY_ALL)),
|
||||
_useTexEnvCombine(copy._useTexEnvCombine),
|
||||
_useTextureWeightsUniform(copy._useTextureWeightsUniform)
|
||||
{
|
||||
@@ -36,11 +37,11 @@ MultiTextureControl::MultiTextureControl(const MultiTextureControl& copy, const
|
||||
|
||||
void MultiTextureControl::setTextureWeight(unsigned int unit, float weight)
|
||||
{
|
||||
if (unit >= _textureWeightList.size())
|
||||
if (unit >= _textureWeights->size())
|
||||
{
|
||||
_textureWeightList.resize(unit+1,0.0f);
|
||||
_textureWeights->resize(unit+1,0.0f);
|
||||
}
|
||||
_textureWeightList[unit] = weight;
|
||||
(*_textureWeights)[unit] = weight;
|
||||
|
||||
updateStateSet();
|
||||
}
|
||||
@@ -53,16 +54,16 @@ void MultiTextureControl::updateStateSet()
|
||||
{
|
||||
unsigned int numTextureUnitsOn = 0;
|
||||
unsigned int unit;
|
||||
for(unit=0;unit<_textureWeightList.size();++unit)
|
||||
for(unit=0;unit<_textureWeights->size();++unit)
|
||||
{
|
||||
if (_textureWeightList[unit]>0.0f) ++numTextureUnitsOn;
|
||||
if ((*_textureWeights)[unit]>0.0f) ++numTextureUnitsOn;
|
||||
}
|
||||
|
||||
if (numTextureUnitsOn<=1)
|
||||
{
|
||||
for(unit=0;unit<_textureWeightList.size();++unit)
|
||||
for(unit=0;unit<_textureWeights->size();++unit)
|
||||
{
|
||||
if (_textureWeightList[unit]>0.0f)
|
||||
if ((*_textureWeights)[unit]>0.0f)
|
||||
{
|
||||
osg::TexEnv* texenv = new osg::TexEnv(osg::TexEnv::MODULATE);
|
||||
stateset->setTextureAttribute(unit, texenv);
|
||||
@@ -75,7 +76,7 @@ void MultiTextureControl::updateStateSet()
|
||||
}
|
||||
|
||||
}
|
||||
else if (_textureWeightList.size()==2)
|
||||
else if (_textureWeights->size()==2)
|
||||
{
|
||||
{
|
||||
osg::TexEnvCombine* texenv = new osg::TexEnvCombine;
|
||||
@@ -87,7 +88,7 @@ void MultiTextureControl::updateStateSet()
|
||||
texenv->setSource2_RGB(osg::TexEnvCombine::CONSTANT);
|
||||
texenv->setOperand2_RGB(osg::TexEnvCombine::SRC_COLOR);
|
||||
|
||||
float r = _textureWeightList[0]/(_textureWeightList[0]+_textureWeightList[1]);
|
||||
float r = (*_textureWeights)[0]/((*_textureWeights)[0]+(*_textureWeights)[1]);
|
||||
texenv->setConstantColor(osg::Vec4(r,r,r,r));
|
||||
|
||||
stateset->setTextureAttribute(0, texenv);
|
||||
@@ -104,10 +105,10 @@ void MultiTextureControl::updateStateSet()
|
||||
stateset->setTextureAttribute(1, texenv);
|
||||
}
|
||||
}
|
||||
else if (_textureWeightList.size()==3)
|
||||
else if (_textureWeights->size()==3)
|
||||
{
|
||||
float b = (_textureWeightList[0]+_textureWeightList[1])/(_textureWeightList[0]+_textureWeightList[1]+_textureWeightList[2]);
|
||||
float a = _textureWeightList[0]/(_textureWeightList[0]+_textureWeightList[1]);
|
||||
float b = ((*_textureWeights)[0]+(*_textureWeights)[1])/((*_textureWeights)[0]+(*_textureWeights)[1]+(*_textureWeights)[2]);
|
||||
float a = (*_textureWeights)[0]/((*_textureWeights)[0]+(*_textureWeights)[1]);
|
||||
|
||||
{
|
||||
osg::TexEnvCombine* texenv = new osg::TexEnvCombine;
|
||||
@@ -152,13 +153,17 @@ void MultiTextureControl::updateStateSet()
|
||||
}
|
||||
}
|
||||
|
||||
if (_useTextureWeightsUniform && _textureWeightList.size()>0)
|
||||
if (_useTextureWeightsUniform && _textureWeights->size()>0)
|
||||
{
|
||||
osg::ref_ptr<osg::Uniform> uniform = new osg::Uniform(osg::Uniform::FLOAT, "TextureWeights", _textureWeightList.size());
|
||||
for(unsigned int i=0; i<_textureWeightList.size(); ++i)
|
||||
osg::ref_ptr<osg::Uniform> uniform = new osg::Uniform(osg::Uniform::FLOAT, "TextureWeights", _textureWeights->size());
|
||||
#if 1
|
||||
uniform->setArray(_textureWeights.get());
|
||||
#else
|
||||
for(unsigned int i=0; i<_textureWeights->size(); ++i)
|
||||
{
|
||||
uniform->setElement(i, _textureWeightList[i]);
|
||||
uniform->setElement(i, (*_textureWeights)[i]);
|
||||
}
|
||||
#endif
|
||||
stateset->addUniform(uniform.get());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user