From: timoore Date: Wed, 15 Jul 2009 23:09:58 +0000 (+0000) Subject: Work in progress for Technique validation X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b5a59ea6f95ce12de0f5db76d90d066b5cb6b41a;p=simgear.git Work in progress for Technique validation --- diff --git a/simgear/scene/material/Effect.cxx b/simgear/scene/material/Effect.cxx index 9625fb3b..6e8fd931 100644 --- a/simgear/scene/material/Effect.cxx +++ b/simgear/scene/material/Effect.cxx @@ -46,9 +46,7 @@ StateSet* Effect::getDefaultStateSet() if (!tniq) return 0; Pass* pass = tniq->passes.front().get(); - if (!pass) - return 0; - return pass->getStateSet(); + return pass; } // There should always be a valid technique in an effect. diff --git a/simgear/scene/material/GLPredicate.cxx b/simgear/scene/material/GLPredicate.cxx new file mode 100644 index 00000000..2ff5fdaa --- /dev/null +++ b/simgear/scene/material/GLPredicate.cxx @@ -0,0 +1,28 @@ +#include + +#include +#include + +#include +#include + +namespace simgear +{ +using namespace std; +using namespace osg; +using namespace boost; + +bool GLPredicate::operator ()(unsigned int contextID) +{ + float versionNumber = getGLVersionNumber() * 10.0f; + float required = (static_cast(majorVersion) * 10.0f + + static_cast(minorVersion)); + if (versionNumber < required + && !osg::equivalent(versionNumber, required)) + return false; + return (find_if(extensions.begin(), extensions.end(), + !bind(isGLExtensionSupported, contextID, + bind(&string::c_str, _1))) + == extensions.end()); +} +} diff --git a/simgear/scene/material/GLPredicate.hxx b/simgear/scene/material/GLPredicate.hxx new file mode 100644 index 00000000..9e90834d --- /dev/null +++ b/simgear/scene/material/GLPredicate.hxx @@ -0,0 +1,25 @@ +#ifndef SIMGEAR_GLPREDICATE_HXX +#define SIMGEAR_GLPREDICATE_HXX 1 + +#include +#include + +namespace simgear +{ + +struct GLPredicate +{ + GLPredicate() : majorVersion(0),minorVersion(0) {} + GLPredicate(int majorVersion_, int minorVersion_) : + majorVersion(majorVersion_), minorVersion(minorVersion_) + { + } + /** Does OpenGL support the required version and extensions? + */ + bool operator ()(unsigned int contextID); + int majorVersion; + int minorVersion; + std::vector extensions; +}; +} +#endif diff --git a/simgear/scene/material/Makefile.am b/simgear/scene/material/Makefile.am index 95cab757..eca5aa47 100644 --- a/simgear/scene/material/Makefile.am +++ b/simgear/scene/material/Makefile.am @@ -8,6 +8,7 @@ include_HEADERS = \ Effect.hxx \ EffectCullVisitor.hxx \ EffectGeode.hxx \ + GLPredicate.hxx \ Pass.hxx \ Technique.hxx \ mat.hxx \ @@ -18,6 +19,7 @@ libsgmaterial_a_SOURCES = \ Effect.cxx \ EffectCullVisitor.cxx \ EffectGeode.cxx \ + GLPredicate.cxx \ Pass.cxx \ Technique.cxx \ mat.cxx \ diff --git a/simgear/scene/material/Pass.cxx b/simgear/scene/material/Pass.cxx index 210a8506..9c1aafce 100644 --- a/simgear/scene/material/Pass.cxx +++ b/simgear/scene/material/Pass.cxx @@ -1,50 +1,10 @@ #include "Pass.hxx" -#include - -#include -#include -#include -#include - namespace simgear { Pass::Pass(const Pass& rhs, const osg::CopyOp& copyop) : - _stateSet(clone_ref(rhs._stateSet, copyop)) -{ -} - -void Pass::resizeGLObjectBuffers(unsigned int maxSize) -{ - if (_stateSet.valid()) - _stateSet->resizeGLObjectBuffers(maxSize); -} - -void Pass::releaseGLObjects(osg::State* state) const -{ - if (_stateSet.valid()) - _stateSet->releaseGLObjects(state); -} - -bool Pass_writeLocalData(const osg::Object& obj, osgDB::Output& fw) -{ - const Pass& pass = static_cast(obj); - - fw.indent() << "stateSet\n"; - fw.writeObject(*pass.getStateSet()); - return true; -} - -namespace + osg::StateSet(rhs, copyop) { -osgDB::RegisterDotOsgWrapperProxy passProxy -( - new Pass, - "simgear::Pass", - "Object simgear::Pass", - 0, - &Pass_writeLocalData - ); } } diff --git a/simgear/scene/material/Pass.hxx b/simgear/scene/material/Pass.hxx index cb343fcc..869dabd9 100644 --- a/simgear/scene/material/Pass.hxx +++ b/simgear/scene/material/Pass.hxx @@ -18,30 +18,18 @@ #define SIMGEAR_PASS_HXX 1 #include -#include - -namespace osg -{ -class StateSet; -} +#include namespace simgear { -class Pass : public osg::Object +class Pass : public osg::StateSet { public: META_Object(simgear,Pass); Pass() {} Pass(const Pass& rhs, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); - osg::StateSet* getStateSet() { return _stateSet.get(); } - const osg::StateSet* getStateSet() const { return _stateSet.get(); } - void setStateSet(osg::StateSet* stateSet) { _stateSet = stateSet; } - virtual void resizeGLObjectBuffers(unsigned int maxSize); - virtual void releaseGLObjects(osg::State* state = 0) const; -protected: - osg::ref_ptr _stateSet; }; } diff --git a/simgear/scene/material/Technique.cxx b/simgear/scene/material/Technique.cxx index d800f0cc..d56d262a 100644 --- a/simgear/scene/material/Technique.cxx +++ b/simgear/scene/material/Technique.cxx @@ -145,7 +145,7 @@ Technique::processDrawables(const EffectGeode::DrawablesIterator& begin, EffectGeode::DrawablesIterator drawablesEnd = itr; BOOST_FOREACH(ref_ptr& pass, passes) { - cv->pushStateSet(pass->getStateSet()); + 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/mat.cxx b/simgear/scene/material/mat.cxx index 8230107a..d65893a9 100644 --- a/simgear/scene/material/mat.cxx +++ b/simgear/scene/material/mat.cxx @@ -280,14 +280,14 @@ SGMaterial::build_state( bool defer_tex_load ) SGMaterialUserData* user = new SGMaterialUserData(this); for (unsigned int i = 0; i < _status.size(); i++) { - osg::StateSet *stateSet = new osg::StateSet; - stateSet->setUserData(user); + Pass *pass = new Pass; + pass->setUserData(user); // Set up the textured state - stateSet->setAttribute(attrFact->getSmoothShadeModel()); - stateSet->setAttributeAndModes(attrFact->getCullFaceBack()); + pass->setAttribute(attrFact->getSmoothShadeModel()); + pass->setAttributeAndModes(attrFact->getCullFaceBack()); - stateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON); + pass->setMode(GL_LIGHTING, osg::StateAttribute::ON); _status[i].texture_loaded = false; @@ -298,22 +298,20 @@ SGMaterial::build_state( bool defer_tex_load ) material->setSpecular(osg::Material::FRONT_AND_BACK, specular.osg()); material->setEmission(osg::Material::FRONT_AND_BACK, emission.osg()); material->setShininess(osg::Material::FRONT_AND_BACK, shininess ); - stateSet->setAttribute(material); + pass->setAttribute(material); if (ambient[3] < 1 || diffuse[3] < 1 || specular[3] < 1 || emission[3] < 1) { - stateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - stateSet->setMode(GL_BLEND, osg::StateAttribute::ON); - stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON); + pass->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); + pass->setMode(GL_BLEND, osg::StateAttribute::ON); + pass->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON); } else { - stateSet->setRenderingHint(osg::StateSet::OPAQUE_BIN); - stateSet->setMode(GL_BLEND, osg::StateAttribute::OFF); - stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF); + pass->setRenderingHint(osg::StateSet::OPAQUE_BIN); + pass->setMode(GL_BLEND, osg::StateAttribute::OFF); + pass->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF); } - _status[i].state = stateSet; - Pass* pass = new Pass; - pass->setStateSet(_status[i].state.get()); + _status[i].state = pass; Technique* tniq = new Technique(true); tniq->passes.push_back(pass); Effect* effect = new Effect; diff --git a/simgear/scene/sky/cloud.cxx b/simgear/scene/sky/cloud.cxx index 55f10f5d..3420b80b 100644 --- a/simgear/scene/sky/cloud.cxx +++ b/simgear/scene/sky/cloud.cxx @@ -485,7 +485,7 @@ SGCloudLayer::rebuild() layer_states[SG_CLOUD_CLEAR] = 0; layer_states2[SG_CLOUD_CLEAR] = 0; -#if 0 +#if 1 // experimental optimization that may not make any difference // at all :/ osg::CopyOp copyOp; diff --git a/simgear/structure/Makefile.am b/simgear/structure/Makefile.am index 0f54669b..7311a540 100644 --- a/simgear/structure/Makefile.am +++ b/simgear/structure/Makefile.am @@ -7,6 +7,7 @@ include_HEADERS = \ commands.hxx \ exception.hxx \ event_mgr.hxx \ + intern.hxx \ subsystem_mgr.hxx \ OSGUtils.hxx \ OSGVersion.hxx \ @@ -19,18 +20,21 @@ include_HEADERS = \ SGSmplstat.hxx \ SGWeakPtr.hxx \ SGWeakReferenced.hxx \ - Singleton.hxx + Singleton.hxx \ + StringTable.hxx libsgstructure_a_SOURCES = \ commands.cxx \ exception.cxx \ event_mgr.cxx\ + intern.hxx \ subsystem_mgr.cxx \ SGAtomic.cxx \ SGBinding.cxx \ SGExpression.cxx \ SGSmplhist.cxx \ - SGSmplstat.cxx + SGSmplstat.cxx \ + StringTable.cxx INCLUDES = -I$(top_srcdir) diff --git a/simgear/structure/StringTable.cxx b/simgear/structure/StringTable.cxx new file mode 100644 index 00000000..81afc69b --- /dev/null +++ b/simgear/structure/StringTable.cxx @@ -0,0 +1,16 @@ +#include "StringTable.hxx" + +#include + +namespace simgear +{ +using namespace std; + +const string* StringTable::insert(const string& str) +{ + using namespace OpenThreads; + ScopedLock lock(_mutex); + StringContainer::iterator it = _strings.insert(str).first; + return &*it; +} +} diff --git a/simgear/structure/StringTable.hxx b/simgear/structure/StringTable.hxx new file mode 100644 index 00000000..9e5700d3 --- /dev/null +++ b/simgear/structure/StringTable.hxx @@ -0,0 +1,28 @@ +#ifndef SIMGEAR_STRINGTABLE_HXX +#define SIMGEAR_STRINGTABLE_HXX 1 + +#include + +#include +#include +#include +#include + +namespace simgear +{ +typedef boost::multi_index_container< + std::string, + boost::multi_index::indexed_by< + boost::multi_index::hashed_unique< + boost::multi_index::identity > > > +StringContainer; + +class StringTable +{ + const std::string* insert(const std::string& str); +private: + OpenThreads::Mutex _mutex; + StringContainer _strings; +}; +} +#endif diff --git a/simgear/structure/intern.cxx b/simgear/structure/intern.cxx new file mode 100644 index 00000000..1928aff2 --- /dev/null +++ b/simgear/structure/intern.cxx @@ -0,0 +1,20 @@ +#include + +#include +#include + +namespace +{ +class GlobalStringTable : public StringTable, + public Singleton +{ +}; +} + +namespace simgear +{ +const std::string* intern(const std::string& str) +{ + return GlobalStringTable::instance()->insert(str); +} +} diff --git a/simgear/structure/intern.hxx b/simgear/structure/intern.hxx new file mode 100644 index 00000000..5a1c0e47 --- /dev/null +++ b/simgear/structure/intern.hxx @@ -0,0 +1,14 @@ +#ifndef SIMGEAR_INTERN_HXX +#define SIMGEAR_INTERN_HXX 1 + +#include + +namespace simgear +{ +/** + * Return a pointer to a single string object for a given string. + */ + +const std::string* intern(const std::string& str); +} +#endif