add parameter to XXXTranformHW to customize reserved texture attribs and vertex attribs

This commit is contained in:
Julien Valentin
2017-08-30 17:07:11 +02:00
parent 705695b41d
commit 86ad54f671
4 changed files with 26 additions and 19 deletions

View File

@@ -19,29 +19,23 @@
#include <sstream>
///texture unit reserved for morphtarget TBO
#define MORPHTEXTUREUNIT 7
#define DEFAULTMORPHTEXTUREUNIT 7
using namespace osgAnimation;
MorphTransformHardware::MorphTransformHardware()
MorphTransformHardware::MorphTransformHardware():_needInit(true),_reservedTextureUnit(DEFAULTMORPHTEXTUREUNIT)
{
_needInit = true;
}
MorphTransformHardware::MorphTransformHardware(const MorphTransformHardware& rth, const osg::CopyOp& copyop):
MorphTransform(rth, copyop),
_uniformTargetsWeight(rth._uniformTargetsWeight),
_shader(rth._shader),
_needInit(rth._needInit)
_needInit(rth._needInit),
_reservedTextureUnit(rth._reservedTextureUnit)
{
}
void MorphTransformHardware::setShader(osg::Shader* shader)
{
_shader = shader;
}
bool MorphTransformHardware::init(MorphGeometry& morphGeometry)
{
osg::Vec3Array* pos = dynamic_cast<osg::Vec3Array*>(morphGeometry.getVertexArray());
@@ -104,7 +98,7 @@ bool MorphTransformHardware::init(MorphGeometry& morphGeometry)
//create TBO Texture handle
osg::Uniform * morphTBOHandle=new osg::Uniform(osg::Uniform::SAMPLER_BUFFER,"morphTargets");
morphTBOHandle->set(MORPHTEXTUREUNIT);
morphTBOHandle->set(_reservedTextureUnit);
//create dynamic uniform for morphtargets animation weights
_uniformTargetsWeight=new osg::Uniform(osg::Uniform::FLOAT,"morphWeights",morphlist.size());
@@ -174,7 +168,7 @@ bool MorphTransformHardware::init(MorphGeometry& morphGeometry)
osg::ref_ptr<osg::StateSet> ss = morphGeometry.getOrCreateStateSet();
ss->addUniform(_uniformTargetsWeight);
ss->setTextureAttribute(MORPHTEXTUREUNIT,morphTargetsTBO);
ss->setTextureAttribute(_reservedTextureUnit,morphTargetsTBO);
ss->addUniform( morphTBOHandle);
ss->addUniform(new osg::Uniform("nbMorphVertex", morphGeometry.getVertexArray()->getNumElements()));

View File

@@ -20,12 +20,13 @@
using namespace osgAnimation;
#define DEFAULT_FIRST_VERTATTRIB_TARGETTED 11
RigTransformHardware::RigTransformHardware()
{
_needInit = true;
_bonesPerVertex = 0;
_nbVertexes = 0;
_minAttribIndex = DEFAULT_FIRST_VERTATTRIB_TARGETTED;
}
RigTransformHardware::RigTransformHardware(const RigTransformHardware& rth, const osg::CopyOp& copyop):
@@ -37,7 +38,8 @@ RigTransformHardware::RigTransformHardware(const RigTransformHardware& rth, cons
_boneWeightAttribArrays(rth._boneWeightAttribArrays),
_uniformMatrixPalette(rth._uniformMatrixPalette),
_shader(rth._shader),
_needInit(rth._needInit)
_needInit(rth._needInit),
_minAttribIndex(rth._minAttribIndex)
{
}
@@ -198,7 +200,7 @@ bool RigTransformHardware::prepareData(RigGeometry& rig)
OSG_INFO << "Shader " << str << std::endl;
}
unsigned int attribIndex = 11;
unsigned int attribIndex = _minAttribIndex;
unsigned int nbAttribs = getNumVertexAttrib();
if(nbAttribs==0)
OSG_WARN << "nbAttribs== " << nbAttribs << std::endl;