diff --git a/simgear/scene/material/Effect.cxx b/simgear/scene/material/Effect.cxx index e5b3f5fa..b85cdcfe 100644 --- a/simgear/scene/material/Effect.cxx +++ b/simgear/scene/material/Effect.cxx @@ -1044,7 +1044,6 @@ struct UniformBuilder :public PassAttributeBuilder return; SGConstPropertyNode_ptr nameProp = prop->getChild("name"); SGConstPropertyNode_ptr typeProp = prop->getChild("type"); - SGConstPropertyNode_ptr positionedProp = prop->getChild("positioned"); SGConstPropertyNode_ptr valProp = prop->getChild("value"); string name; Uniform::Type uniformType = Uniform::FLOAT; @@ -1105,11 +1104,6 @@ struct UniformBuilder :public PassAttributeBuilder // REVIEW: Memory Leak - 144,400 bytes in 38 blocks are indirectly lost // Leak occurs within OSG, likely caused by passing a raw pointer pass->addUniform(uniform.get()); - if (positionedProp && positionedProp->getBoolValue() && uniformType == Uniform::FLOAT_VEC4) { - osg::Vec4 offset; - uniform->get(offset); - pass->addPositionedUniform( name, offset ); - } } }; diff --git a/simgear/scene/material/EffectBuilder.hxx b/simgear/scene/material/EffectBuilder.hxx index d1bb9031..6420fa25 100644 --- a/simgear/scene/material/EffectBuilder.hxx +++ b/simgear/scene/material/EffectBuilder.hxx @@ -56,16 +56,16 @@ class EffectBuilder : public SGReferenced { public: virtual ~EffectBuilder() {} - virtual T* build(Effect* effect, Pass* pass, const SGPropertyNode*, + virtual T* build(Effect* effect, const SGPropertyNode*, const SGReaderWriterOptions* options) = 0; - static T* buildFromType(Effect* effect, Pass* pass, const std::string& type, + static T* buildFromType(Effect* effect, const std::string& type, const SGPropertyNode*props, const SGReaderWriterOptions* options) { BuilderMap& builderMap = getMap(); typename BuilderMap::iterator iter = builderMap.find(type); if (iter != builderMap.end()) - return iter->second->build(effect, pass, props, options); + return iter->second->build(effect, props, options); else return 0; } diff --git a/simgear/scene/material/EffectCullVisitor.cxx b/simgear/scene/material/EffectCullVisitor.cxx index c4fbfa07..165c95c5 100644 --- a/simgear/scene/material/EffectCullVisitor.cxx +++ b/simgear/scene/material/EffectCullVisitor.cxx @@ -19,9 +19,6 @@ #endif #include -#include - -#include #include "EffectCullVisitor.hxx" @@ -29,8 +26,6 @@ #include "Effect.hxx" #include "Technique.hxx" -#include - namespace simgear { @@ -104,19 +99,4 @@ void EffectCullVisitor::reset() osgUtil::CullVisitor::reset(); } -void EffectCullVisitor::clearBufferList() -{ - _bufferList.clear(); -} - -void EffectCullVisitor::addBuffer(std::string b, osg::Texture2D* tex) -{ - _bufferList.insert(std::make_pair(b,tex)); -} - -osg::Texture2D* EffectCullVisitor::getBuffer(std::string b) -{ - return _bufferList[b]; -} - } diff --git a/simgear/scene/material/EffectCullVisitor.hxx b/simgear/scene/material/EffectCullVisitor.hxx index 3669126b..9bf48b70 100644 --- a/simgear/scene/material/EffectCullVisitor.hxx +++ b/simgear/scene/material/EffectCullVisitor.hxx @@ -19,14 +19,11 @@ #include -#include - #include namespace osg { class Geode; -class Texture2D; } namespace simgear @@ -44,14 +41,9 @@ public: virtual void apply(osg::Geode& node); virtual void reset(); - void clearBufferList(); - void addBuffer(std::string b, osg::Texture2D* tex); - osg::Texture2D* getBuffer(std::string b); - SGLightList getLightList() const { return _lightList; } private: - std::map > _bufferList; SGLightList _lightList; bool _collectLights; std::string _effScheme; diff --git a/simgear/scene/material/Pass.hxx b/simgear/scene/material/Pass.hxx index 7b5bb3e4..869dabd9 100644 --- a/simgear/scene/material/Pass.hxx +++ b/simgear/scene/material/Pass.hxx @@ -26,23 +26,10 @@ namespace simgear class Pass : public osg::StateSet { public: - typedef std::list > BufferUnitList; - typedef std::map PositionedUniformMap; - META_Object(simgear,Pass); Pass() {} Pass(const Pass& rhs, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); - - void setBufferUnit( int unit, std::string buffer ) { _bufferUnitList.push_back( std::make_pair(unit,buffer) ); } - const BufferUnitList& getBufferUnitList() const { return _bufferUnitList; } - - void addPositionedUniform( const std::string& name, const osg::Vec4& offset ) { _positionedUniforms[name] = offset; } - const PositionedUniformMap& getPositionedUniformMap() const { return _positionedUniforms; } - -private: - BufferUnitList _bufferUnitList; - PositionedUniformMap _positionedUniforms; }; } diff --git a/simgear/scene/material/Technique.cxx b/simgear/scene/material/Technique.cxx index 2e41fca4..66758f39 100644 --- a/simgear/scene/material/Technique.cxx +++ b/simgear/scene/material/Technique.cxx @@ -5,7 +5,6 @@ #include "Technique.hxx" #include "Pass.hxx" -#include "EffectCullVisitor.hxx" #include #include @@ -14,8 +13,6 @@ #include #include #include -#include -#include #include #include @@ -168,36 +165,9 @@ Technique::processDrawables(const EffectGeode::DrawablesIterator& begin, if( isNaN(depth[i]) ) depth[i] = FLT_MAX; } - EffectCullVisitor* ecv = dynamic_cast( cv ); EffectGeode::DrawablesIterator drawablesEnd = itr; for (auto& pass : passes) { - osg::ref_ptr ss = pass; - if (ecv && ( ! pass->getBufferUnitList().empty() || ! pass->getPositionedUniformMap().empty() ) ) { - ss = static_cast( - pass->clone( osg::CopyOp( ( ! pass->getBufferUnitList().empty() ? - osg::CopyOp::DEEP_COPY_TEXTURES : - osg::CopyOp::SHALLOW_COPY ) | - ( ! pass->getPositionedUniformMap().empty() ? - osg::CopyOp::DEEP_COPY_UNIFORMS : - osg::CopyOp::SHALLOW_COPY ) ) - ) - ); - for (Pass::BufferUnitList::const_iterator ii = pass->getBufferUnitList().begin(); - ii != pass->getBufferUnitList().end(); - ++ii) { - osg::Texture2D* tex = ecv->getBuffer(ii->second); - if (tex != 0) - ss->setTextureAttributeAndModes( ii->first, tex ); - } - for (Pass::PositionedUniformMap::const_iterator ii = pass->getPositionedUniformMap().begin(); - ii != pass->getPositionedUniformMap().end(); - ++ii) { - osg::RefMatrix* mv = cv->getModelViewMatrix(); - osg::Vec4 v = ii->second * *mv; - ss->getUniform(ii->first)->set( v ); - } - } - cv->pushStateSet(ss); + cv->pushStateSet(pass.get()); int i = 0; for (itr = begin; itr != drawablesEnd; ++itr, ++i) { if (depth[i] != FLT_MAX) diff --git a/simgear/scene/material/TextureBuilder.cxx b/simgear/scene/material/TextureBuilder.cxx index 3535ab40..f4ed63c9 100644 --- a/simgear/scene/material/TextureBuilder.cxx +++ b/simgear/scene/material/TextureBuilder.cxx @@ -64,12 +64,12 @@ TexEnvCombine* buildTexEnvCombine(Effect* effect, TexGen* buildTexGen(Effect* Effect, const SGPropertyNode* tgenProp); // Hack to force inclusion of TextureBuilder.cxx in library -osg::Texture* TextureBuilder::buildFromType(Effect* effect, Pass* pass, const string& type, +osg::Texture* TextureBuilder::buildFromType(Effect* effect, const string& type, const SGPropertyNode*props, const SGReaderWriterOptions* options) { - return EffectBuilder::buildFromType(effect, pass, type, props, options); + return EffectBuilder::buildFromType(effect, type, props, options); } typedef std::tuplegetStringValue(); Texture* texture = 0; try { - texture = TextureBuilder::buildFromType(effect, pass, type, prop, + texture = TextureBuilder::buildFromType(effect, type, prop, options); } catch (BuilderException& e) { @@ -312,7 +312,7 @@ class TexBuilder : public TextureBuilder { public: TexBuilder(const string& texType) : _type(texType) {} - Texture* build(Effect* effect, Pass* pass, const SGPropertyNode*, + Texture* build(Effect* effect, const SGPropertyNode*, const SGReaderWriterOptions* options); protected: typedef map > TexMap; @@ -321,7 +321,7 @@ protected: }; template -Texture* TexBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode* props, +Texture* TexBuilder::build(Effect* effect, const SGPropertyNode* props, const SGReaderWriterOptions* options) { TexTuple attrs = makeTexTuple(effect, props, options, _type); @@ -356,11 +356,11 @@ TextureBuilder::Registrar install2D("2d", new TexBuilder("2d")); class WhiteTextureBuilder : public TextureBuilder { public: - Texture* build(Effect* effect, Pass* pass, const SGPropertyNode*, + Texture* build(Effect* effect, const SGPropertyNode*, const SGReaderWriterOptions* options); }; -Texture* WhiteTextureBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode*, +Texture* WhiteTextureBuilder::build(Effect* effect, const SGPropertyNode*, const SGReaderWriterOptions* options) { return StateAttributeFactory::instance()->getWhiteTexture(); @@ -374,11 +374,11 @@ TextureBuilder::Registrar installWhite("white", new WhiteTextureBuilder); class TransparentTextureBuilder : public TextureBuilder { public: - Texture* build(Effect* effect, Pass* pass, const SGPropertyNode*, + Texture* build(Effect* effect, const SGPropertyNode*, const SGReaderWriterOptions* options); }; -Texture* TransparentTextureBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode*, +Texture* TransparentTextureBuilder::build(Effect* effect, const SGPropertyNode*, const SGReaderWriterOptions* options) { return StateAttributeFactory::instance()->getTransparentTexture(); @@ -393,14 +393,14 @@ TextureBuilder::Registrar installTransparent("transparent", class NoiseBuilder : public TextureBuilder { public: - Texture* build(Effect* effect, Pass* pass, const SGPropertyNode*, + Texture* build(Effect* effect, const SGPropertyNode*, const SGReaderWriterOptions* options); protected: typedef map > NoiseMap; NoiseMap _noises; }; -Texture* NoiseBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode* props, +Texture* NoiseBuilder::build(Effect* effect, const SGPropertyNode* props, const SGReaderWriterOptions* options) { int texSize = 64; @@ -420,7 +420,7 @@ TextureBuilder::Registrar installNoise("noise", new NoiseBuilder); class LightSpriteBuilder : public TextureBuilder { public: - Texture* build(Effect* effect, Pass* pass, const SGPropertyNode*, + Texture* build(Effect* effect, const SGPropertyNode*, const SGReaderWriterOptions* options); protected: Mutex lightMutex; @@ -429,7 +429,7 @@ protected: osg::Image* getPointSpriteImage(int logResolution); }; -Texture* LightSpriteBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode* props, +Texture* LightSpriteBuilder::build(Effect* effect, const SGPropertyNode* props, const SGReaderWriterOptions* options) { ScopedLock lock(lightMutex); @@ -547,7 +547,7 @@ CubeMapTuple makeCubeMapTuple(Effect* effect, const SGPropertyNode* props) class CubeMapBuilder : public TextureBuilder { public: - Texture* build(Effect* effect, Pass* pass, const SGPropertyNode*, + Texture* build(Effect* effect, const SGPropertyNode*, const SGReaderWriterOptions* options); protected: typedef map > CubeMap; @@ -570,7 +570,7 @@ void copySubImage(const osg::Image* srcImage, int src_s, int src_t, int width, i } -Texture* CubeMapBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode* props, +Texture* CubeMapBuilder::build(Effect* effect, const SGPropertyNode* props, const SGReaderWriterOptions* options) { // First check that there is a tag @@ -763,14 +763,14 @@ Tex2DArraySignature makeTex2DArraySignature(Effect *effect, class Texture2DArrayBuilder : public TextureBuilder { public: - Texture* build(Effect* effect, Pass* pass, const SGPropertyNode*, + Texture* build(Effect* effect, const SGPropertyNode*, const SGReaderWriterOptions* options); protected: typedef map> TexMap; TexMap texMap; }; -Texture* Texture2DArrayBuilder::build(Effect* effect, Pass* pass, +Texture* Texture2DArrayBuilder::build(Effect* effect, const SGPropertyNode* props, const SGReaderWriterOptions* options) { @@ -823,14 +823,14 @@ TextureBuilder::Registrar install2DArray("2d-array", new Texture2DArrayBuilder); class Texture3DBuilder : public TextureBuilder { public: - Texture* build(Effect* effect, Pass* pass, const SGPropertyNode*, + Texture* build(Effect* effect, const SGPropertyNode*, const SGReaderWriterOptions* options); protected: typedef map > TexMap; TexMap texMap; }; -Texture* Texture3DBuilder::build(Effect* effect, Pass* pass, +Texture* Texture3DBuilder::build(Effect* effect, const SGPropertyNode* props, const SGReaderWriterOptions* options) { @@ -1131,79 +1131,4 @@ bool makeTextureParameters(SGPropertyNode* paramRoot, const StateSet* ss) return true; } -class GBufferBuilder : public TextureBuilder -{ -public: - GBufferBuilder() {} - Texture* build(Effect* effect, Pass* pass, const SGPropertyNode*, - const SGReaderWriterOptions* options); -private: - string buffer; -}; - -class BufferNameChangeListener : public SGPropertyChangeListener, - public DeferredPropertyListener { -public: - BufferNameChangeListener(Pass* p, int u, const std::string& pn) : pass(p), unit(u) - { - propName = new std::string(pn); - } - ~BufferNameChangeListener() - { - delete propName; - propName = 0; - } - void valueChanged(SGPropertyNode* node) - { - const char* buffer = node->getStringValue(); - pass->setBufferUnit(unit, buffer); - } - void activate(SGPropertyNode* propRoot) - { - SGPropertyNode* listenProp = makeNode(propRoot, *propName); - delete propName; - propName = 0; - if (listenProp) - listenProp->addChangeListener(this, true); - } - -private: - ref_ptr pass; - int unit; - std::string* propName; -}; - -Texture* GBufferBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterOptions* options) -{ - int unit = 0; - const SGPropertyNode* pUnit = prop->getChild("unit"); - if (pUnit) { - unit = pUnit->getValue(); - } else { - SG_LOG(SG_INPUT, SG_ALERT, "no texture unit"); - } - const SGPropertyNode* nameProp = getEffectPropertyChild(effect, prop, - "name"); - if (!nameProp) - return 0; - - if (nameProp->nChildren() == 0) { - buffer = nameProp->getStringValue(); - pass->setBufferUnit( unit, buffer ); - } else { - std::string propName = getGlobalProperty(nameProp, options); - BufferNameChangeListener* listener = new BufferNameChangeListener(pass, unit, propName); - effect->addDeferredPropertyListener(listener); - } - - // Return white for now. Would be overridden in Technique::ProcessDrawable - return StateAttributeFactory::instance()->getWhiteTexture(); -} - -namespace -{ - TextureBuilder::Registrar installBuffer("buffer", new GBufferBuilder); -} - } diff --git a/simgear/scene/material/TextureBuilder.hxx b/simgear/scene/material/TextureBuilder.hxx index c4225a21..c8105e75 100644 --- a/simgear/scene/material/TextureBuilder.hxx +++ b/simgear/scene/material/TextureBuilder.hxx @@ -27,7 +27,7 @@ class TextureBuilder : public EffectBuilder { public: // Hack to force inclusion of TextureBuilder.cxx in library - static osg::Texture* buildFromType(Effect* effect, Pass* pass, const std::string& type, + static osg::Texture* buildFromType(Effect* effect, const std::string& type, const SGPropertyNode*props, const SGReaderWriterOptions* options); };