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.
--- /dev/null
+#include <simgear/scene/material/GLPredicate.hxx>
+
+#include <algorithm>
+#include <boost/bind.hpp>
+
+#include <osg/GLExtensions>
+#include <osg/Math>
+
+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<float>(majorVersion) * 10.0f
+ + static_cast<float>(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());
+}
+}
--- /dev/null
+#ifndef SIMGEAR_GLPREDICATE_HXX
+#define SIMGEAR_GLPREDICATE_HXX 1
+
+#include <vector>
+#include <string>
+
+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<const std::string *> extensions;
+};
+}
+#endif
Effect.hxx \
EffectCullVisitor.hxx \
EffectGeode.hxx \
+ GLPredicate.hxx \
Pass.hxx \
Technique.hxx \
mat.hxx \
Effect.cxx \
EffectCullVisitor.cxx \
EffectGeode.cxx \
+ GLPredicate.cxx \
Pass.cxx \
Technique.cxx \
mat.cxx \
#include "Pass.hxx"
-#include <simgear/structure/OSGUtils.hxx>
-
-#include <osg/StateSet>
-#include <osgDB/Registry>
-#include <osgDB/Input>
-#include <osgDB/ParameterOutput>
-
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<const Pass&>(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
- );
}
}
#define SIMGEAR_PASS_HXX 1
#include <osg/ref_ptr>
-#include <osg/Object>
-
-namespace osg
-{
-class StateSet;
-}
+#include <osg/StateSet>
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<osg::StateSet> _stateSet;
};
}
EffectGeode::DrawablesIterator drawablesEnd = itr;
BOOST_FOREACH(ref_ptr<Pass>& 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)
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;
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;
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;
commands.hxx \
exception.hxx \
event_mgr.hxx \
+ intern.hxx \
subsystem_mgr.hxx \
OSGUtils.hxx \
OSGVersion.hxx \
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)
--- /dev/null
+#include "StringTable.hxx"
+
+#include <OpenThreads/ScopedLock>
+
+namespace simgear
+{
+using namespace std;
+
+const string* StringTable::insert(const string& str)
+{
+ using namespace OpenThreads;
+ ScopedLock<Mutex> lock(_mutex);
+ StringContainer::iterator it = _strings.insert(str).first;
+ return &*it;
+}
+}
--- /dev/null
+#ifndef SIMGEAR_STRINGTABLE_HXX
+#define SIMGEAR_STRINGTABLE_HXX 1
+
+#include <string>
+
+#include <OpenThreads/Mutex>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/hashed_index.hpp>
+#include <boost/multi_index/identity.hpp>
+
+namespace simgear
+{
+typedef boost::multi_index_container<
+ std::string,
+ boost::multi_index::indexed_by<
+ boost::multi_index::hashed_unique<
+ boost::multi_index::identity<std::string> > > >
+StringContainer;
+
+class StringTable
+{
+ const std::string* insert(const std::string& str);
+private:
+ OpenThreads::Mutex _mutex;
+ StringContainer _strings;
+};
+}
+#endif
--- /dev/null
+#include <simgear/structure/intern.hxx>
+
+#include <simgear/structure/StringTable.hxx>
+#include <simgear/structure/Singleton.hxx>
+
+namespace
+{
+class GlobalStringTable : public StringTable,
+ public Singleton<GlobalStringTable>
+{
+};
+}
+
+namespace simgear
+{
+const std::string* intern(const std::string& str)
+{
+ return GlobalStringTable::instance()->insert(str);
+}
+}
--- /dev/null
+#ifndef SIMGEAR_INTERN_HXX
+#define SIMGEAR_INTERN_HXX 1
+
+#include <string>
+
+namespace simgear
+{
+/**
+ * Return a pointer to a single string object for a given string.
+ */
+
+const std::string* intern(const std::string& str);
+}
+#endif