From 86ad54f67102e32b7d07213f8adeb3d1549d2dda Mon Sep 17 00:00:00 2001 From: Julien Valentin Date: Wed, 30 Aug 2017 17:07:11 +0200 Subject: [PATCH] add parameter to XXXTranformHW to customize reserved texture attribs and vertex attribs --- include/osgAnimation/MorphTransformHardware | 9 ++++++++- include/osgAnimation/RigTransformHardware | 10 +++++++--- src/osgAnimation/MorphTransformHardware.cpp | 18 ++++++------------ src/osgAnimation/RigTransformHardware.cpp | 8 +++++--- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/include/osgAnimation/MorphTransformHardware b/include/osgAnimation/MorphTransformHardware index fde644a96..b061cccae 100644 --- a/include/osgAnimation/MorphTransformHardware +++ b/include/osgAnimation/MorphTransformHardware @@ -38,7 +38,13 @@ namespace osgAnimation META_Object(osgAnimation,MorphTransformHardware); 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: @@ -49,6 +55,7 @@ namespace osgAnimation osg::ref_ptr _shader; bool _needInit; + unsigned int _reservedTextureUnit; }; } diff --git a/include/osgAnimation/RigTransformHardware b/include/osgAnimation/RigTransformHardware index cbb825e16..91c586d33 100644 --- a/include/osgAnimation/RigTransformHardware +++ b/include/osgAnimation/RigTransformHardware @@ -43,12 +43,16 @@ namespace osgAnimation typedef std::map BoneNamePaletteIndex; typedef std::vector MatrixPalette; - osg::Vec4Array* getVertexAttrib(unsigned int index); - unsigned int getNumVertexAttrib() const {return _boneWeightAttribArrays.size();} + ///set the first Vertex Attribute Array index of the rig generated by this technic (default:11) + void setFirstVertexAttributeTarget(unsigned int i){ _minAttribIndex=i;} + unsigned int getFirstVertexAttributeTarget()const { return _minAttribIndex;} void setShader(osg::Shader* shader) { _shader = 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 &getNumVertexes() const { return _nbVertexes; } @@ -74,7 +78,7 @@ namespace osgAnimation osg::ref_ptr _shader; bool _needInit; - + unsigned int _minAttribIndex; bool buildPalette(const BoneMap& boneMap ,const RigGeometry& rig); }; diff --git a/src/osgAnimation/MorphTransformHardware.cpp b/src/osgAnimation/MorphTransformHardware.cpp index 86df7b465..f0915bbf1 100644 --- a/src/osgAnimation/MorphTransformHardware.cpp +++ b/src/osgAnimation/MorphTransformHardware.cpp @@ -19,29 +19,23 @@ #include ///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(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 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())); diff --git a/src/osgAnimation/RigTransformHardware.cpp b/src/osgAnimation/RigTransformHardware.cpp index fb51cb177..ae2e0dfa6 100644 --- a/src/osgAnimation/RigTransformHardware.cpp +++ b/src/osgAnimation/RigTransformHardware.cpp @@ -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;