Work in progress for Technique validation

This commit is contained in:
timoore
2009-07-15 23:09:58 +00:00
committed by Tim Moore
parent c6b2124129
commit b5a59ea6f9
14 changed files with 158 additions and 77 deletions

View 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.

View File

@@ -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());
}
}

View File

@@ -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

View 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 \

View 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))
osg::StateSet(rhs, 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
{
osgDB::RegisterDotOsgWrapperProxy passProxy
(
new Pass,
"simgear::Pass",
"Object simgear::Pass",
0,
&Pass_writeLocalData
);
}
}

View File

@@ -18,30 +18,18 @@
#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;
};
}

View 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)

View 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;

View 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;

View 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)

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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