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

@ -38,7 +38,13 @@ namespace osgAnimation
META_Object(osgAnimation,MorphTransformHardware); META_Object(osgAnimation,MorphTransformHardware);
virtual void operator()(MorphGeometry&); virtual void operator()(MorphGeometry&);
void setShader(osg::Shader*);
inline void setShader(osg::Shader*s){_shader=s;}
inline osg::Shader * getShader()const{return _shader;}
///texture unit reserved for morphtarget TBO default is 7
void setReservedTextureUnit(unsigned int t){_reservedTextureUnit=t;}
unsigned int getReservedTextureUnit() const {return _reservedTextureUnit;}
protected: protected:
@ -49,6 +55,7 @@ namespace osgAnimation
osg::ref_ptr<osg::Shader> _shader; osg::ref_ptr<osg::Shader> _shader;
bool _needInit; bool _needInit;
unsigned int _reservedTextureUnit;
}; };
} }

View File

@ -43,12 +43,16 @@ namespace osgAnimation
typedef std::map<std::string, unsigned int> BoneNamePaletteIndex; typedef std::map<std::string, unsigned int> BoneNamePaletteIndex;
typedef std::vector<osg::Matrix> MatrixPalette; typedef std::vector<osg::Matrix> MatrixPalette;
osg::Vec4Array* getVertexAttrib(unsigned int index); ///set the first Vertex Attribute Array index of the rig generated by this technic (default:11)
unsigned int getNumVertexAttrib() const {return _boneWeightAttribArrays.size();} void setFirstVertexAttributeTarget(unsigned int i){ _minAttribIndex=i;}
unsigned int getFirstVertexAttributeTarget()const { return _minAttribIndex;}
void setShader(osg::Shader* shader) { _shader = shader; } void setShader(osg::Shader* shader) { _shader = shader; }
osg::Shader* getShader() const { return _shader; } osg::Shader* getShader() const { return _shader; }
osg::Vec4Array* getVertexAttrib(unsigned int index);
unsigned int getNumVertexAttrib() const {return _boneWeightAttribArrays.size();}
const unsigned int &getNumBonesPerVertex() const{ return _bonesPerVertex; } const unsigned int &getNumBonesPerVertex() const{ return _bonesPerVertex; }
const unsigned int &getNumVertexes() const { return _nbVertexes; } const unsigned int &getNumVertexes() const { return _nbVertexes; }
@ -74,7 +78,7 @@ namespace osgAnimation
osg::ref_ptr<osg::Shader> _shader; osg::ref_ptr<osg::Shader> _shader;
bool _needInit; bool _needInit;
unsigned int _minAttribIndex;
bool buildPalette(const BoneMap& boneMap ,const RigGeometry& rig); bool buildPalette(const BoneMap& boneMap ,const RigGeometry& rig);
}; };

View File

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

View File

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