Eliminate SGMaterial::get_state function.
Use Effect in BVH visitor, ocean tile generation, and airport signs.
}
}
-osg::StateSet *
-SGMaterial::get_state (int n)
-{
- if (_status.size() == 0) {
- SG_LOG( SG_GENERAL, SG_WARN, "No state available.");
- return NULL;
- }
-
- int i = n >= 0 ? n : _current_ptr;
-
- if(!_status[i].texture_loaded)
- {
- assignTexture(_status[i].state.get(), _status[i].texture_path,
- wrapu, wrapv, mipmap);
- _status[i].texture_loaded = true;
- }
- osg::StateSet *st = _status[i].state.get();
-
- _current_ptr += 1;
- if (_current_ptr >= _status.size())
- _current_ptr = 0;
-
- return st;
-}
-
Effect* SGMaterial::get_effect(int n)
{
if (_status.size() == 0) {
/**
* Get the textured state.
*/
- osg::StateSet *get_state (int n = -1);
simgear::Effect *get_effect(int n = -1);
/**
}
const SGMaterial*
-SGMaterialLib::findMaterial(const osg::StateSet* stateSet)
+SGMaterialLib::findMaterial(const simgear::Effect* effect)
{
- if (!stateSet)
- return 0;
-
- const osg::Referenced* base = stateSet->getUserData();
- if (!base)
+ if (!effect)
return 0;
const SGMaterialUserData* matUserData
- = dynamic_cast<const SGMaterialUserData*>(base);
+ = dynamic_cast<const SGMaterialUserData*>(effect->getUserData());
if (!matUserData)
return 0;
-
- return matUserData->getMaterial();
+ else
+ return matUserData->getMaterial();
}
using std::vector;
using std::less;
+namespace simgear
+{
+class Effect;
+}
+
// Material management class
class SGMaterialLib {
material_map_iterator end() { return matlib.end(); }
const_material_map_iterator end() const { return matlib.end(); }
- static const SGMaterial* findMaterial(const osg::StateSet* stateSet);
+ static const SGMaterial* findMaterial(const simgear::Effect* effect);
// Destructor
~SGMaterialLib ( void );
#include <osg/Transform>
#include <osg/TriangleFunctor>
+#include <simgear/scene/material/Effect.hxx>
+#include <simgear/scene/material/EffectGeode.hxx>
#include <simgear/scene/material/mat.hxx>
#include <simgear/scene/material/matlib.hxx>
#include <simgear/scene/util/SGNodeMasks.hxx>
{
}
- const SGMaterial* pushMaterial(osg::StateSet* stateSet)
+ const SGMaterial* pushMaterial(Effect* effect)
{
const SGMaterial* oldMaterial = _primitiveFunctor.getCurrentMaterial();
- const SGMaterial* material = SGMaterialLib::findMaterial(stateSet);
+ const SGMaterial* material = SGMaterialLib::findMaterial(effect);
if (material)
_primitiveFunctor.setCurrentMaterial(material);
return oldMaterial;
void fillWith(osg::Drawable* drawable)
{
- const SGMaterial* oldMaterial = pushMaterial(drawable->getStateSet());
drawable->accept(_primitiveFunctor);
- _primitiveFunctor.setCurrentMaterial(oldMaterial);
}
virtual void apply(osg::Geode& geode)
if (hasBoundingVolumeTree(geode))
return;
- const SGMaterial* oldMaterial = pushMaterial(geode.getStateSet());
+ const SGMaterial* oldMaterial = 0;
+
+ EffectGeode *eg = dynamic_cast<EffectGeode*>(&geode);
+ if (eg)
+ oldMaterial = pushMaterial(eg->getEffect());
bool flushHere = getNodePath().size() <= 1 || _dumpIntoLeafs;
if (flushHere) {
for(unsigned i = 0; i < geode.getNumDrawables(); ++i)
fillWith(geode.getDrawable(i));
}
-
- _primitiveFunctor.setCurrentMaterial(oldMaterial);
+ if (eg)
+ _primitiveFunctor.setCurrentMaterial(oldMaterial);
}
virtual void apply(osg::Group& group)
if (hasBoundingVolumeTree(node))
return;
- const SGMaterial* oldMaterial = pushMaterial(node.getStateSet());
-
// push the current active primitive list
PFunctor previousPrimitives;
_primitiveFunctor.swap(previousPrimitives);
// pop the current active primitive list
_primitiveFunctor.swap(previousPrimitives);
-
- _primitiveFunctor.setCurrentMaterial(oldMaterial);
}
void traverseAndCollect(osg::Node& node)
// Note that we do not need to push the already collected list of
// primitives, since we are now in the topmost node ...
- const SGMaterial* oldMaterial = pushMaterial(node.getStateSet());
-
// walk the children
traverse(node);
-
- _primitiveFunctor.setCurrentMaterial(oldMaterial);
}
void addBoundingVolumeTreeToNode(osg::Node& node)
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/math/sg_types.hxx>
#include <simgear/misc/texcoord.hxx>
+#include <simgear/scene/material/Effect.hxx>
+#include <simgear/scene/material/EffectGeode.hxx>
#include <simgear/scene/material/mat.hxx>
#include <simgear/scene/material/matlib.hxx>
+
#include <simgear/scene/util/VectorArrayAdapter.hxx>
using namespace simgear;
osg::Node* SGOceanTile(const SGBucket& b, SGMaterialLib *matlib)
{
- osg::StateSet *stateSet = 0;
+ Effect *effect = 0;
double tex_width = 1000.0;
tex_width = mat->get_xsize();
// set OSG State
- stateSet = mat->get_state();
+ effect = mat->get_effect();
} else {
SG_LOG( SG_TERRAIN, SG_ALERT, "Ack! unknown use material name = Ocean");
}
+ 2 * (latPoints - 1)));
fillDrawElementsWithApron(latPoints, lonPoints, drawElements->begin());
geometry->addPrimitiveSet(drawElements);
- geometry->setStateSet(stateSet);
- osg::Geode* geode = new osg::Geode;
+ EffectGeode* geode = new EffectGeode;
geode->setName("Ocean tile");
+ geode->setEffect(effect);
geode->addDrawable(geometry);
osg::MatrixTransform* transform = new osg::MatrixTransform;
#include <simgear/debug/logstream.hxx>
#include <simgear/math/sg_types.hxx>
+#include <simgear/scene/material/Effect.hxx>
+#include <simgear/scene/material/EffectGeode.hxx>
#include <simgear/scene/material/mat.hxx>
#include <simgear/scene/material/matlib.hxx>
#define RWY "OBJECT_RUNWAY_SIGN: "
using std::vector;
+using namespace simgear;
// for temporary storage of sign elements
struct element_info {
- element_info(SGMaterial *m, osg::StateSet *s, SGMaterialGlyph *g, double h)
+ element_info(SGMaterial *m, Effect *s, SGMaterialGlyph *g, double h)
: material(m), state(s), glyph(g), height(h)
{
scale = h * m->get_xsize()
/ (m->get_ysize() < 0.001 ? 1.0 : m->get_ysize());
}
SGMaterial *material;
- osg::StateSet *state;
+ Effect *state;
SGMaterialGlyph *glyph;
double height;
double scale;
object->setName(content);
SGMaterial *material;
- osg::StateSet *lighted_state;
- osg::StateSet *unlighted_state;
+ Effect *lighted_state;
+ Effect *unlighted_state;
// Part I: parse & measure
for (const char *s = content.data(); *s; s++) {
}
// set material states (lighted & unlighted)
- lighted_state = material->get_state();
+ lighted_state = material->get_effect();
string u = newmat + ".unlighted";
SGMaterial *m = matlib->find(u);
if (m) {
- unlighted_state = m->get_state();
+ unlighted_state = m->get_effect();
} else {
SG_LOG(SG_TERRAIN, SG_ALERT, SIGN "ignoring unknown material `" << u << '\'');
unlighted_state = lighted_state;
}
// in managed mode push frame stop and frame start first
- osg::StateSet *state = lighted ? lighted_state : unlighted_state;
+ Effect *state = lighted ? lighted_state : unlighted_state;
element_info *e;
if (newtype && newtype != oldtype) {
if (close) {
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
geometry->setTexCoordArray(0, tl);
geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, vl->size()));
- osg::Geode* geode = new osg::Geode;
+ EffectGeode* geode = new EffectGeode;
geode->addDrawable(geometry);
- geode->setStateSet(element->state);
+ geode->setEffect(element->state);
object->addChild(geode);
hpos += abswidth;
geometry->setNormalArray(nl);
geometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, vl->size()));
- osg::Geode* geode = new osg::Geode;
+ EffectGeode* geode = new EffectGeode;
geode->addDrawable(geometry);
SGMaterial *mat = matlib->find("BlackSign");
if (mat)
- geode->setStateSet(mat->get_state());
+ geode->setEffect(mat->get_effect());
object->addChild(geode);
return object;
osg::Vec3 heightVec(0, 0, 1);
osg::Geometry* geometry;
geometry = osg::createTexturedQuadGeometry(corner, widthVec, heightVec);
-
- SGMaterial *mat = matlib->find(name);
- if (mat)
- geometry->setStateSet(mat->get_state());
-
- osg::Geode* geode = new osg::Geode;
+ EffectGeode* geode = new EffectGeode;
geode->setName(name);
geode->addDrawable(geometry);
+ SGMaterial *mat = matlib->find(name);
+ if (mat)
+ geode->setEffect(mat->get_effect());
return geode;
}