]> git.mxchange.org Git - simgear.git/commitdiff
Work in progress for Technique validation
authortimoore <timoore>
Wed, 15 Jul 2009 23:09:58 +0000 (23:09 +0000)
committerTim Moore <timoore@redhat.com>
Thu, 16 Jul 2009 10:09:44 +0000 (12:09 +0200)
14 files changed:
simgear/scene/material/Effect.cxx
simgear/scene/material/GLPredicate.cxx [new file with mode: 0644]
simgear/scene/material/GLPredicate.hxx [new file with mode: 0644]
simgear/scene/material/Makefile.am
simgear/scene/material/Pass.cxx
simgear/scene/material/Pass.hxx
simgear/scene/material/Technique.cxx
simgear/scene/material/mat.cxx
simgear/scene/sky/cloud.cxx
simgear/structure/Makefile.am
simgear/structure/StringTable.cxx [new file with mode: 0644]
simgear/structure/StringTable.hxx [new file with mode: 0644]
simgear/structure/intern.cxx [new file with mode: 0644]
simgear/structure/intern.hxx [new file with mode: 0644]

index 9625fb3bd80747a473364863516b498abc3ca225..6e8fd9317181a5919180c39858adbc16e106cf27 100644 (file)
@@ -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 (file)
index 0000000..2ff5fda
--- /dev/null
@@ -0,0 +1,28 @@
+#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());
+}
+}
diff --git a/simgear/scene/material/GLPredicate.hxx b/simgear/scene/material/GLPredicate.hxx
new file mode 100644 (file)
index 0000000..9e90834
--- /dev/null
@@ -0,0 +1,25 @@
+#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
index 95cab757c6356edce58de93303f81d1b150cec5f..eca5aa479c0956676fd447ef493ec3dca937d36a 100644 (file)
@@ -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 \
index 210a8506dfc5c35a50dcbe5e03e65f9952a8020d..9c1aafcea1882cc869e267a5bb4441a07b7ebc51 100644 (file)
@@ -1,50 +1,10 @@
 #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
-    );
 }
 }
index cb343fcc4126dbfd4886ca047622d8def319b63d..869dabd9df0107bf99bb1bd5d4b6f26d4014223e 100644 (file)
 #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;
 };
 
 }
index d800f0cc6cd6a750119d1b6637eb2920f5a409bb..d56d262a6e86c26081361bd03a3ee72d00520edd 100644 (file)
@@ -145,7 +145,7 @@ Technique::processDrawables(const EffectGeode::DrawablesIterator& begin,
     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)
index 8230107a1b3bb2cc9d68e7ee19f72581046b8ebf..d65893a97a55918ad0b38396c4d63ef67c4fda97 100644 (file)
@@ -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;
index 55f10f5d2dae2571403aa55312012003f12ca97d..3420b80b1137e6db34d2a38787653c5322ef8d42 100644 (file)
@@ -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;
index 0f54669b2dae6cc1283f0c9404f5a411fd73b86e..7311a5403fabefc0309370c55e8f154ee88d1523 100644 (file)
@@ -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 (file)
index 0000000..81afc69
--- /dev/null
@@ -0,0 +1,16 @@
+#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;
+}
+}
diff --git a/simgear/structure/StringTable.hxx b/simgear/structure/StringTable.hxx
new file mode 100644 (file)
index 0000000..9e5700d
--- /dev/null
@@ -0,0 +1,28 @@
+#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
diff --git a/simgear/structure/intern.cxx b/simgear/structure/intern.cxx
new file mode 100644 (file)
index 0000000..1928aff
--- /dev/null
@@ -0,0 +1,20 @@
+#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);
+}
+}
diff --git a/simgear/structure/intern.hxx b/simgear/structure/intern.hxx
new file mode 100644 (file)
index 0000000..5a1c0e4
--- /dev/null
@@ -0,0 +1,14 @@
+#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