materials use only simgear::Effect
Eliminate SGMaterial::get_state function. Use Effect in BVH visitor, ocean tile generation, and airport signs.
This commit is contained in:
@@ -231,31 +231,6 @@ SGMaterial::init ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
Effect* SGMaterial::get_effect(int n)
|
||||||
{
|
{
|
||||||
if (_status.size() == 0) {
|
if (_status.size() == 0) {
|
||||||
|
|||||||
@@ -120,7 +120,6 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Get the textured state.
|
* Get the textured state.
|
||||||
*/
|
*/
|
||||||
osg::StateSet *get_state (int n = -1);
|
|
||||||
simgear::Effect *get_effect(int n = -1);
|
simgear::Effect *get_effect(int n = -1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -135,19 +135,15 @@ SGMaterialLib::~SGMaterialLib ( void ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const SGMaterial*
|
const SGMaterial*
|
||||||
SGMaterialLib::findMaterial(const osg::StateSet* stateSet)
|
SGMaterialLib::findMaterial(const simgear::Effect* effect)
|
||||||
{
|
{
|
||||||
if (!stateSet)
|
if (!effect)
|
||||||
return 0;
|
|
||||||
|
|
||||||
const osg::Referenced* base = stateSet->getUserData();
|
|
||||||
if (!base)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const SGMaterialUserData* matUserData
|
const SGMaterialUserData* matUserData
|
||||||
= dynamic_cast<const SGMaterialUserData*>(base);
|
= dynamic_cast<const SGMaterialUserData*>(effect->getUserData());
|
||||||
if (!matUserData)
|
if (!matUserData)
|
||||||
return 0;
|
return 0;
|
||||||
|
else
|
||||||
return matUserData->getMaterial();
|
return matUserData->getMaterial();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,11 @@ using std::map;
|
|||||||
using std::vector;
|
using std::vector;
|
||||||
using std::less;
|
using std::less;
|
||||||
|
|
||||||
|
namespace simgear
|
||||||
|
{
|
||||||
|
class Effect;
|
||||||
|
}
|
||||||
|
|
||||||
// Material management class
|
// Material management class
|
||||||
class SGMaterialLib {
|
class SGMaterialLib {
|
||||||
|
|
||||||
@@ -77,7 +82,7 @@ public:
|
|||||||
material_map_iterator end() { return matlib.end(); }
|
material_map_iterator end() { return matlib.end(); }
|
||||||
const_material_map_iterator end() const { 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
|
// Destructor
|
||||||
~SGMaterialLib ( void );
|
~SGMaterialLib ( void );
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
#include <osg/Transform>
|
#include <osg/Transform>
|
||||||
#include <osg/TriangleFunctor>
|
#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/mat.hxx>
|
||||||
#include <simgear/scene/material/matlib.hxx>
|
#include <simgear/scene/material/matlib.hxx>
|
||||||
#include <simgear/scene/util/SGNodeMasks.hxx>
|
#include <simgear/scene/util/SGNodeMasks.hxx>
|
||||||
@@ -384,10 +386,10 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const SGMaterial* pushMaterial(osg::StateSet* stateSet)
|
const SGMaterial* pushMaterial(Effect* effect)
|
||||||
{
|
{
|
||||||
const SGMaterial* oldMaterial = _primitiveFunctor.getCurrentMaterial();
|
const SGMaterial* oldMaterial = _primitiveFunctor.getCurrentMaterial();
|
||||||
const SGMaterial* material = SGMaterialLib::findMaterial(stateSet);
|
const SGMaterial* material = SGMaterialLib::findMaterial(effect);
|
||||||
if (material)
|
if (material)
|
||||||
_primitiveFunctor.setCurrentMaterial(material);
|
_primitiveFunctor.setCurrentMaterial(material);
|
||||||
return oldMaterial;
|
return oldMaterial;
|
||||||
@@ -395,9 +397,7 @@ public:
|
|||||||
|
|
||||||
void fillWith(osg::Drawable* drawable)
|
void fillWith(osg::Drawable* drawable)
|
||||||
{
|
{
|
||||||
const SGMaterial* oldMaterial = pushMaterial(drawable->getStateSet());
|
|
||||||
drawable->accept(_primitiveFunctor);
|
drawable->accept(_primitiveFunctor);
|
||||||
_primitiveFunctor.setCurrentMaterial(oldMaterial);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void apply(osg::Geode& geode)
|
virtual void apply(osg::Geode& geode)
|
||||||
@@ -405,7 +405,11 @@ public:
|
|||||||
if (hasBoundingVolumeTree(geode))
|
if (hasBoundingVolumeTree(geode))
|
||||||
return;
|
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;
|
bool flushHere = getNodePath().size() <= 1 || _dumpIntoLeafs;
|
||||||
if (flushHere) {
|
if (flushHere) {
|
||||||
@@ -426,8 +430,8 @@ public:
|
|||||||
for(unsigned i = 0; i < geode.getNumDrawables(); ++i)
|
for(unsigned i = 0; i < geode.getNumDrawables(); ++i)
|
||||||
fillWith(geode.getDrawable(i));
|
fillWith(geode.getDrawable(i));
|
||||||
}
|
}
|
||||||
|
if (eg)
|
||||||
_primitiveFunctor.setCurrentMaterial(oldMaterial);
|
_primitiveFunctor.setCurrentMaterial(oldMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void apply(osg::Group& group)
|
virtual void apply(osg::Group& group)
|
||||||
@@ -453,8 +457,6 @@ public:
|
|||||||
if (hasBoundingVolumeTree(node))
|
if (hasBoundingVolumeTree(node))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const SGMaterial* oldMaterial = pushMaterial(node.getStateSet());
|
|
||||||
|
|
||||||
// push the current active primitive list
|
// push the current active primitive list
|
||||||
PFunctor previousPrimitives;
|
PFunctor previousPrimitives;
|
||||||
_primitiveFunctor.swap(previousPrimitives);
|
_primitiveFunctor.swap(previousPrimitives);
|
||||||
@@ -469,8 +471,6 @@ public:
|
|||||||
|
|
||||||
// pop the current active primitive list
|
// pop the current active primitive list
|
||||||
_primitiveFunctor.swap(previousPrimitives);
|
_primitiveFunctor.swap(previousPrimitives);
|
||||||
|
|
||||||
_primitiveFunctor.setCurrentMaterial(oldMaterial);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void traverseAndCollect(osg::Node& node)
|
void traverseAndCollect(osg::Node& node)
|
||||||
@@ -488,12 +488,8 @@ public:
|
|||||||
// Note that we do not need to push the already collected list of
|
// Note that we do not need to push the already collected list of
|
||||||
// primitives, since we are now in the topmost node ...
|
// primitives, since we are now in the topmost node ...
|
||||||
|
|
||||||
const SGMaterial* oldMaterial = pushMaterial(node.getStateSet());
|
|
||||||
|
|
||||||
// walk the children
|
// walk the children
|
||||||
traverse(node);
|
traverse(node);
|
||||||
|
|
||||||
_primitiveFunctor.setCurrentMaterial(oldMaterial);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void addBoundingVolumeTreeToNode(osg::Node& node)
|
void addBoundingVolumeTreeToNode(osg::Node& node)
|
||||||
|
|||||||
@@ -37,8 +37,11 @@
|
|||||||
#include <simgear/math/sg_geodesy.hxx>
|
#include <simgear/math/sg_geodesy.hxx>
|
||||||
#include <simgear/math/sg_types.hxx>
|
#include <simgear/math/sg_types.hxx>
|
||||||
#include <simgear/misc/texcoord.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/mat.hxx>
|
||||||
#include <simgear/scene/material/matlib.hxx>
|
#include <simgear/scene/material/matlib.hxx>
|
||||||
|
|
||||||
#include <simgear/scene/util/VectorArrayAdapter.hxx>
|
#include <simgear/scene/util/VectorArrayAdapter.hxx>
|
||||||
|
|
||||||
using namespace simgear;
|
using namespace simgear;
|
||||||
@@ -254,7 +257,7 @@ void fillDrawElementsWithApron(short height, short width,
|
|||||||
|
|
||||||
osg::Node* SGOceanTile(const SGBucket& b, SGMaterialLib *matlib)
|
osg::Node* SGOceanTile(const SGBucket& b, SGMaterialLib *matlib)
|
||||||
{
|
{
|
||||||
osg::StateSet *stateSet = 0;
|
Effect *effect = 0;
|
||||||
|
|
||||||
double tex_width = 1000.0;
|
double tex_width = 1000.0;
|
||||||
|
|
||||||
@@ -266,7 +269,7 @@ osg::Node* SGOceanTile(const SGBucket& b, SGMaterialLib *matlib)
|
|||||||
tex_width = mat->get_xsize();
|
tex_width = mat->get_xsize();
|
||||||
|
|
||||||
// set OSG State
|
// set OSG State
|
||||||
stateSet = mat->get_state();
|
effect = mat->get_effect();
|
||||||
} else {
|
} else {
|
||||||
SG_LOG( SG_TERRAIN, SG_ALERT, "Ack! unknown use material name = Ocean");
|
SG_LOG( SG_TERRAIN, SG_ALERT, "Ack! unknown use material name = Ocean");
|
||||||
}
|
}
|
||||||
@@ -302,10 +305,10 @@ osg::Node* SGOceanTile(const SGBucket& b, SGMaterialLib *matlib)
|
|||||||
+ 2 * (latPoints - 1)));
|
+ 2 * (latPoints - 1)));
|
||||||
fillDrawElementsWithApron(latPoints, lonPoints, drawElements->begin());
|
fillDrawElementsWithApron(latPoints, lonPoints, drawElements->begin());
|
||||||
geometry->addPrimitiveSet(drawElements);
|
geometry->addPrimitiveSet(drawElements);
|
||||||
geometry->setStateSet(stateSet);
|
|
||||||
|
|
||||||
osg::Geode* geode = new osg::Geode;
|
EffectGeode* geode = new EffectGeode;
|
||||||
geode->setName("Ocean tile");
|
geode->setName("Ocean tile");
|
||||||
|
geode->setEffect(effect);
|
||||||
geode->addDrawable(geometry);
|
geode->addDrawable(geometry);
|
||||||
|
|
||||||
osg::MatrixTransform* transform = new osg::MatrixTransform;
|
osg::MatrixTransform* transform = new osg::MatrixTransform;
|
||||||
|
|||||||
@@ -33,6 +33,8 @@
|
|||||||
|
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
#include <simgear/math/sg_types.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/mat.hxx>
|
||||||
#include <simgear/scene/material/matlib.hxx>
|
#include <simgear/scene/material/matlib.hxx>
|
||||||
|
|
||||||
@@ -42,17 +44,18 @@
|
|||||||
#define RWY "OBJECT_RUNWAY_SIGN: "
|
#define RWY "OBJECT_RUNWAY_SIGN: "
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using namespace simgear;
|
||||||
|
|
||||||
// for temporary storage of sign elements
|
// for temporary storage of sign elements
|
||||||
struct element_info {
|
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)
|
: material(m), state(s), glyph(g), height(h)
|
||||||
{
|
{
|
||||||
scale = h * m->get_xsize()
|
scale = h * m->get_xsize()
|
||||||
/ (m->get_ysize() < 0.001 ? 1.0 : m->get_ysize());
|
/ (m->get_ysize() < 0.001 ? 1.0 : m->get_ysize());
|
||||||
}
|
}
|
||||||
SGMaterial *material;
|
SGMaterial *material;
|
||||||
osg::StateSet *state;
|
Effect *state;
|
||||||
SGMaterialGlyph *glyph;
|
SGMaterialGlyph *glyph;
|
||||||
double height;
|
double height;
|
||||||
double scale;
|
double scale;
|
||||||
@@ -104,8 +107,8 @@ SGMakeSign(SGMaterialLib *matlib, const string& path, const string& content)
|
|||||||
object->setName(content);
|
object->setName(content);
|
||||||
|
|
||||||
SGMaterial *material;
|
SGMaterial *material;
|
||||||
osg::StateSet *lighted_state;
|
Effect *lighted_state;
|
||||||
osg::StateSet *unlighted_state;
|
Effect *unlighted_state;
|
||||||
|
|
||||||
// Part I: parse & measure
|
// Part I: parse & measure
|
||||||
for (const char *s = content.data(); *s; s++) {
|
for (const char *s = content.data(); *s; s++) {
|
||||||
@@ -224,12 +227,12 @@ SGMakeSign(SGMaterialLib *matlib, const string& path, const string& content)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set material states (lighted & unlighted)
|
// set material states (lighted & unlighted)
|
||||||
lighted_state = material->get_state();
|
lighted_state = material->get_effect();
|
||||||
string u = newmat + ".unlighted";
|
string u = newmat + ".unlighted";
|
||||||
|
|
||||||
SGMaterial *m = matlib->find(u);
|
SGMaterial *m = matlib->find(u);
|
||||||
if (m) {
|
if (m) {
|
||||||
unlighted_state = m->get_state();
|
unlighted_state = m->get_effect();
|
||||||
} else {
|
} else {
|
||||||
SG_LOG(SG_TERRAIN, SG_ALERT, SIGN "ignoring unknown material `" << u << '\'');
|
SG_LOG(SG_TERRAIN, SG_ALERT, SIGN "ignoring unknown material `" << u << '\'');
|
||||||
unlighted_state = lighted_state;
|
unlighted_state = lighted_state;
|
||||||
@@ -244,7 +247,7 @@ SGMakeSign(SGMaterialLib *matlib, const string& path, const string& content)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// in managed mode push frame stop and frame start first
|
// 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;
|
element_info *e;
|
||||||
if (newtype && newtype != oldtype) {
|
if (newtype && newtype != oldtype) {
|
||||||
if (close) {
|
if (close) {
|
||||||
@@ -319,9 +322,9 @@ SGMakeSign(SGMaterialLib *matlib, const string& path, const string& content)
|
|||||||
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
|
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
|
||||||
geometry->setTexCoordArray(0, tl);
|
geometry->setTexCoordArray(0, tl);
|
||||||
geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, vl->size()));
|
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->addDrawable(geometry);
|
||||||
geode->setStateSet(element->state);
|
geode->setEffect(element->state);
|
||||||
|
|
||||||
object->addChild(geode);
|
object->addChild(geode);
|
||||||
hpos += abswidth;
|
hpos += abswidth;
|
||||||
@@ -344,11 +347,11 @@ SGMakeSign(SGMaterialLib *matlib, const string& path, const string& content)
|
|||||||
geometry->setNormalArray(nl);
|
geometry->setNormalArray(nl);
|
||||||
geometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
|
geometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
|
||||||
geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, vl->size()));
|
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->addDrawable(geometry);
|
||||||
SGMaterial *mat = matlib->find("BlackSign");
|
SGMaterial *mat = matlib->find("BlackSign");
|
||||||
if (mat)
|
if (mat)
|
||||||
geode->setStateSet(mat->get_state());
|
geode->setEffect(mat->get_effect());
|
||||||
object->addChild(geode);
|
object->addChild(geode);
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
@@ -367,14 +370,12 @@ SGMakeRunwaySign(SGMaterialLib *matlib, const string& path, const string& name)
|
|||||||
osg::Vec3 heightVec(0, 0, 1);
|
osg::Vec3 heightVec(0, 0, 1);
|
||||||
osg::Geometry* geometry;
|
osg::Geometry* geometry;
|
||||||
geometry = osg::createTexturedQuadGeometry(corner, widthVec, heightVec);
|
geometry = osg::createTexturedQuadGeometry(corner, widthVec, heightVec);
|
||||||
|
EffectGeode* geode = new EffectGeode;
|
||||||
SGMaterial *mat = matlib->find(name);
|
|
||||||
if (mat)
|
|
||||||
geometry->setStateSet(mat->get_state());
|
|
||||||
|
|
||||||
osg::Geode* geode = new osg::Geode;
|
|
||||||
geode->setName(name);
|
geode->setName(name);
|
||||||
geode->addDrawable(geometry);
|
geode->addDrawable(geometry);
|
||||||
|
SGMaterial *mat = matlib->find(name);
|
||||||
|
if (mat)
|
||||||
|
geode->setEffect(mat->get_effect());
|
||||||
|
|
||||||
return geode;
|
return geode;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user