Work in progress for Technique validation
This commit is contained in:
@@ -46,9 +46,7 @@ StateSet* Effect::getDefaultStateSet()
|
|||||||
if (!tniq)
|
if (!tniq)
|
||||||
return 0;
|
return 0;
|
||||||
Pass* pass = tniq->passes.front().get();
|
Pass* pass = tniq->passes.front().get();
|
||||||
if (!pass)
|
return pass;
|
||||||
return 0;
|
|
||||||
return pass->getStateSet();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// There should always be a valid technique in an effect.
|
// There should always be a valid technique in an effect.
|
||||||
|
|||||||
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -8,6 +8,7 @@ include_HEADERS = \
|
|||||||
Effect.hxx \
|
Effect.hxx \
|
||||||
EffectCullVisitor.hxx \
|
EffectCullVisitor.hxx \
|
||||||
EffectGeode.hxx \
|
EffectGeode.hxx \
|
||||||
|
GLPredicate.hxx \
|
||||||
Pass.hxx \
|
Pass.hxx \
|
||||||
Technique.hxx \
|
Technique.hxx \
|
||||||
mat.hxx \
|
mat.hxx \
|
||||||
@@ -18,6 +19,7 @@ libsgmaterial_a_SOURCES = \
|
|||||||
Effect.cxx \
|
Effect.cxx \
|
||||||
EffectCullVisitor.cxx \
|
EffectCullVisitor.cxx \
|
||||||
EffectGeode.cxx \
|
EffectGeode.cxx \
|
||||||
|
GLPredicate.cxx \
|
||||||
Pass.cxx \
|
Pass.cxx \
|
||||||
Technique.cxx \
|
Technique.cxx \
|
||||||
mat.cxx \
|
mat.cxx \
|
||||||
|
|||||||
@@ -1,50 +1,10 @@
|
|||||||
#include "Pass.hxx"
|
#include "Pass.hxx"
|
||||||
|
|
||||||
#include <simgear/structure/OSGUtils.hxx>
|
|
||||||
|
|
||||||
#include <osg/StateSet>
|
|
||||||
#include <osgDB/Registry>
|
|
||||||
#include <osgDB/Input>
|
|
||||||
#include <osgDB/ParameterOutput>
|
|
||||||
|
|
||||||
namespace simgear
|
namespace simgear
|
||||||
{
|
{
|
||||||
|
|
||||||
Pass::Pass(const Pass& rhs, const osg::CopyOp& copyop) :
|
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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,30 +18,18 @@
|
|||||||
#define SIMGEAR_PASS_HXX 1
|
#define SIMGEAR_PASS_HXX 1
|
||||||
|
|
||||||
#include <osg/ref_ptr>
|
#include <osg/ref_ptr>
|
||||||
#include <osg/Object>
|
#include <osg/StateSet>
|
||||||
|
|
||||||
namespace osg
|
|
||||||
{
|
|
||||||
class StateSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace simgear
|
namespace simgear
|
||||||
{
|
{
|
||||||
|
|
||||||
class Pass : public osg::Object
|
class Pass : public osg::StateSet
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
META_Object(simgear,Pass);
|
META_Object(simgear,Pass);
|
||||||
Pass() {}
|
Pass() {}
|
||||||
Pass(const Pass& rhs,
|
Pass(const Pass& rhs,
|
||||||
const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ Technique::processDrawables(const EffectGeode::DrawablesIterator& begin,
|
|||||||
EffectGeode::DrawablesIterator drawablesEnd = itr;
|
EffectGeode::DrawablesIterator drawablesEnd = itr;
|
||||||
BOOST_FOREACH(ref_ptr<Pass>& pass, passes)
|
BOOST_FOREACH(ref_ptr<Pass>& pass, passes)
|
||||||
{
|
{
|
||||||
cv->pushStateSet(pass->getStateSet());
|
cv->pushStateSet(pass.get());
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (itr = begin; itr != drawablesEnd; ++itr, ++i) {
|
for (itr = begin; itr != drawablesEnd; ++itr, ++i) {
|
||||||
if (depth[i] != FLT_MAX)
|
if (depth[i] != FLT_MAX)
|
||||||
|
|||||||
@@ -280,14 +280,14 @@ SGMaterial::build_state( bool defer_tex_load )
|
|||||||
SGMaterialUserData* user = new SGMaterialUserData(this);
|
SGMaterialUserData* user = new SGMaterialUserData(this);
|
||||||
for (unsigned int i = 0; i < _status.size(); i++)
|
for (unsigned int i = 0; i < _status.size(); i++)
|
||||||
{
|
{
|
||||||
osg::StateSet *stateSet = new osg::StateSet;
|
Pass *pass = new Pass;
|
||||||
stateSet->setUserData(user);
|
pass->setUserData(user);
|
||||||
|
|
||||||
// Set up the textured state
|
// Set up the textured state
|
||||||
stateSet->setAttribute(attrFact->getSmoothShadeModel());
|
pass->setAttribute(attrFact->getSmoothShadeModel());
|
||||||
stateSet->setAttributeAndModes(attrFact->getCullFaceBack());
|
pass->setAttributeAndModes(attrFact->getCullFaceBack());
|
||||||
|
|
||||||
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);
|
pass->setMode(GL_LIGHTING, osg::StateAttribute::ON);
|
||||||
|
|
||||||
_status[i].texture_loaded = false;
|
_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->setSpecular(osg::Material::FRONT_AND_BACK, specular.osg());
|
||||||
material->setEmission(osg::Material::FRONT_AND_BACK, emission.osg());
|
material->setEmission(osg::Material::FRONT_AND_BACK, emission.osg());
|
||||||
material->setShininess(osg::Material::FRONT_AND_BACK, shininess );
|
material->setShininess(osg::Material::FRONT_AND_BACK, shininess );
|
||||||
stateSet->setAttribute(material);
|
pass->setAttribute(material);
|
||||||
|
|
||||||
if (ambient[3] < 1 || diffuse[3] < 1 ||
|
if (ambient[3] < 1 || diffuse[3] < 1 ||
|
||||||
specular[3] < 1 || emission[3] < 1) {
|
specular[3] < 1 || emission[3] < 1) {
|
||||||
stateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
pass->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
||||||
stateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
|
pass->setMode(GL_BLEND, osg::StateAttribute::ON);
|
||||||
stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
|
pass->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
|
||||||
} else {
|
} else {
|
||||||
stateSet->setRenderingHint(osg::StateSet::OPAQUE_BIN);
|
pass->setRenderingHint(osg::StateSet::OPAQUE_BIN);
|
||||||
stateSet->setMode(GL_BLEND, osg::StateAttribute::OFF);
|
pass->setMode(GL_BLEND, osg::StateAttribute::OFF);
|
||||||
stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF);
|
pass->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
_status[i].state = stateSet;
|
_status[i].state = pass;
|
||||||
Pass* pass = new Pass;
|
|
||||||
pass->setStateSet(_status[i].state.get());
|
|
||||||
Technique* tniq = new Technique(true);
|
Technique* tniq = new Technique(true);
|
||||||
tniq->passes.push_back(pass);
|
tniq->passes.push_back(pass);
|
||||||
Effect* effect = new Effect;
|
Effect* effect = new Effect;
|
||||||
|
|||||||
@@ -485,7 +485,7 @@ SGCloudLayer::rebuild()
|
|||||||
|
|
||||||
layer_states[SG_CLOUD_CLEAR] = 0;
|
layer_states[SG_CLOUD_CLEAR] = 0;
|
||||||
layer_states2[SG_CLOUD_CLEAR] = 0;
|
layer_states2[SG_CLOUD_CLEAR] = 0;
|
||||||
#if 0
|
#if 1
|
||||||
// experimental optimization that may not make any difference
|
// experimental optimization that may not make any difference
|
||||||
// at all :/
|
// at all :/
|
||||||
osg::CopyOp copyOp;
|
osg::CopyOp copyOp;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ include_HEADERS = \
|
|||||||
commands.hxx \
|
commands.hxx \
|
||||||
exception.hxx \
|
exception.hxx \
|
||||||
event_mgr.hxx \
|
event_mgr.hxx \
|
||||||
|
intern.hxx \
|
||||||
subsystem_mgr.hxx \
|
subsystem_mgr.hxx \
|
||||||
OSGUtils.hxx \
|
OSGUtils.hxx \
|
||||||
OSGVersion.hxx \
|
OSGVersion.hxx \
|
||||||
@@ -19,18 +20,21 @@ include_HEADERS = \
|
|||||||
SGSmplstat.hxx \
|
SGSmplstat.hxx \
|
||||||
SGWeakPtr.hxx \
|
SGWeakPtr.hxx \
|
||||||
SGWeakReferenced.hxx \
|
SGWeakReferenced.hxx \
|
||||||
Singleton.hxx
|
Singleton.hxx \
|
||||||
|
StringTable.hxx
|
||||||
|
|
||||||
libsgstructure_a_SOURCES = \
|
libsgstructure_a_SOURCES = \
|
||||||
commands.cxx \
|
commands.cxx \
|
||||||
exception.cxx \
|
exception.cxx \
|
||||||
event_mgr.cxx\
|
event_mgr.cxx\
|
||||||
|
intern.hxx \
|
||||||
subsystem_mgr.cxx \
|
subsystem_mgr.cxx \
|
||||||
SGAtomic.cxx \
|
SGAtomic.cxx \
|
||||||
SGBinding.cxx \
|
SGBinding.cxx \
|
||||||
SGExpression.cxx \
|
SGExpression.cxx \
|
||||||
SGSmplhist.cxx \
|
SGSmplhist.cxx \
|
||||||
SGSmplstat.cxx
|
SGSmplstat.cxx \
|
||||||
|
StringTable.cxx
|
||||||
|
|
||||||
INCLUDES = -I$(top_srcdir)
|
INCLUDES = -I$(top_srcdir)
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user