Moved to standard OSG coding style.
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
class RotateCallback: public osg::NodeCallback {
|
||||
public:
|
||||
RotateCallback(): osg::NodeCallback(), enabled_(true) {}
|
||||
void operator()(osg::Node *node, osg::NodeVisitor *nv)
|
||||
void operator()(osg::Node* node, osg::NodeVisitor *nv)
|
||||
{
|
||||
osg::MatrixTransform *xform = dynamic_cast<osg::MatrixTransform *>(node);
|
||||
if (xform && enabled_) {
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
|
||||
class KeyboardHandler: public osgGA::GUIEventHandler {
|
||||
public:
|
||||
KeyboardHandler(EffectPanel *ep): ep_(ep) {}
|
||||
KeyboardHandler(EffectPanel* ep): ep_(ep) {}
|
||||
|
||||
bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &)
|
||||
{
|
||||
@@ -94,58 +94,58 @@ public:
|
||||
|
||||
EffectPanel()
|
||||
: osgfxbrowser::Frame(),
|
||||
selected_fx_(-1),
|
||||
fxen_(true),
|
||||
root_(new osg::Group),
|
||||
hints_color_(0.75f, 0.75f, 0.75f, 1.0f),
|
||||
name_color_(1, 1, 1, 1),
|
||||
desc_color_(1, 1, 0.7f, 1)
|
||||
_selected_fx(-1),
|
||||
_fxen(true),
|
||||
_root(new osg::Group),
|
||||
_hints_color(0.75f, 0.75f, 0.75f, 1.0f),
|
||||
_name_color(1, 1, 1, 1),
|
||||
_desc_color(1, 1, 0.7f, 1)
|
||||
{
|
||||
setBackgroundColor(osg::Vec4(0.3f, 0.1f, 0.15f, 0.75f));
|
||||
|
||||
std::cout << "INFO: available osgFX effects:\n";
|
||||
osgFX::Registry::Effect_map emap = osgFX::Registry::instance()->getEffectMap();
|
||||
for (osgFX::Registry::Effect_map::const_iterator i=emap.begin(); i!=emap.end(); ++i) {
|
||||
osgFX::Registry::EffectMap emap = osgFX::Registry::instance()->getEffectMap();
|
||||
for (osgFX::Registry::EffectMap::const_iterator i=emap.begin(); i!=emap.end(); ++i) {
|
||||
std::cout << "INFO: \t" << i->first << "\n";
|
||||
osg::ref_ptr<osgFX::Effect> effect = static_cast<osgFX::Effect *>(i->second->cloneType());
|
||||
effects_.push_back(effect.get());
|
||||
_effects.push_back(effect.get());
|
||||
}
|
||||
|
||||
std::cout << "INFO: " << emap.size() << " effect(s) ready.\n";
|
||||
|
||||
if (!effects_.empty()) {
|
||||
selected_fx_ = 0;
|
||||
if (!_effects.empty()) {
|
||||
_selected_fx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline osg::Group *getRoot() { return root_.get(); }
|
||||
inline void setRoot(osg::Group *node) { root_ = node; }
|
||||
inline osg::Group* getRoot() { return _root.get(); }
|
||||
inline void setRoot(osg::Group* node) { _root = node; }
|
||||
|
||||
inline osg::Node *getScene() { return scene_.get(); }
|
||||
inline void setScene(osg::Node *node) { scene_ = node; }
|
||||
inline osg::Node* getScene() { return _scene.get(); }
|
||||
inline void setScene(osg::Node* node) { _scene = node; }
|
||||
|
||||
inline bool getEffectsEnabled() const { return fxen_; }
|
||||
inline bool getEffectsEnabled() const { return _fxen; }
|
||||
inline void setEffectsEnabled(bool v)
|
||||
{
|
||||
fxen_ = v;
|
||||
_fxen = v;
|
||||
if (getSelectedEffect()) {
|
||||
getSelectedEffect()->setEnabled(fxen_);
|
||||
getSelectedEffect()->setEnabled(_fxen);
|
||||
}
|
||||
}
|
||||
|
||||
inline int getEffectIndex() const { return selected_fx_; }
|
||||
inline int getEffectIndex() const { return _selected_fx; }
|
||||
inline void setEffectIndex(int i)
|
||||
{
|
||||
if (i >= static_cast<int>(effects_.size())) i = 0;
|
||||
if (i < 0) i = static_cast<int>(effects_.size()-1);
|
||||
selected_fx_ = i;
|
||||
if (i >= static_cast<int>(_effects.size())) i = 0;
|
||||
if (i < 0) i = static_cast<int>(_effects.size()-1);
|
||||
_selected_fx = i;
|
||||
rebuild();
|
||||
}
|
||||
|
||||
inline osgFX::Effect *getSelectedEffect()
|
||||
{
|
||||
if (selected_fx_ >= 0 && selected_fx_ < static_cast<int>(effects_.size())) {
|
||||
return effects_[selected_fx_].get();
|
||||
if (_selected_fx >= 0 && _selected_fx < static_cast<int>(_effects.size())) {
|
||||
return _effects[_selected_fx].get();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -160,7 +160,7 @@ protected:
|
||||
|
||||
osg::ref_ptr<osgText::Text> hints = new osgText::Text;
|
||||
hints->setFont(arial.get());
|
||||
hints->setColor(hints_color_);
|
||||
hints->setColor(_hints_color);
|
||||
hints->setAlignment(osgText::Text::CENTER_BOTTOM);
|
||||
hints->setCharacterSize(13);
|
||||
hints->setFontResolution(13, 13);
|
||||
@@ -171,28 +171,28 @@ protected:
|
||||
std::string effect_name = "No Effect Selected";
|
||||
std::string effect_description = "";
|
||||
|
||||
if (selected_fx_ >= 0 && selected_fx_ < static_cast<int>(effects_.size())) {
|
||||
effect_name = effects_[selected_fx_]->effectName();
|
||||
std::string author_name = effects_[selected_fx_]->effectAuthor();
|
||||
if (_selected_fx >= 0 && _selected_fx < static_cast<int>(_effects.size())) {
|
||||
effect_name = _effects[_selected_fx]->effectName();
|
||||
std::string author_name = _effects[_selected_fx]->effectAuthor();
|
||||
if (!author_name.empty()) {
|
||||
effect_description = author_name = "AUTHOR: " + std::string(effects_[selected_fx_]->effectAuthor()) + std::string("\n\n");
|
||||
effect_description = author_name = "AUTHOR: " + std::string(_effects[_selected_fx]->effectAuthor()) + std::string("\n\n");
|
||||
}
|
||||
effect_description += "DESCRIPTION:\n" + std::string(effects_[selected_fx_]->effectDescription());
|
||||
effect_description += "DESCRIPTION:\n" + std::string(_effects[_selected_fx]->effectDescription());
|
||||
|
||||
if (scene_.valid() && root_.valid()) {
|
||||
root_->removeChild(0, root_->getNumChildren());
|
||||
osg::ref_ptr<osgFX::Effect> effect = effects_[selected_fx_].get();
|
||||
effect->setEnabled(fxen_);
|
||||
if (_scene.valid() && _root.valid()) {
|
||||
_root->removeChild(0, _root->getNumChildren());
|
||||
osg::ref_ptr<osgFX::Effect> effect = _effects[_selected_fx].get();
|
||||
effect->setEnabled(_fxen);
|
||||
effect->removeChild(0, effect->getNumChildren());
|
||||
effect->addChild(scene_.get());
|
||||
effect->addChild(_scene.get());
|
||||
effect->setUpDemo();
|
||||
root_->addChild(effect.get());
|
||||
_root->addChild(effect.get());
|
||||
}
|
||||
}
|
||||
|
||||
osg::ref_ptr<osgText::Text> ename = new osgText::Text;
|
||||
ename->setFont(arial.get());
|
||||
ename->setColor(name_color_);
|
||||
ename->setColor(_name_color);
|
||||
ename->setAlignment(osgText::Text::CENTER_TOP);
|
||||
ename->setCharacterSize(32);
|
||||
ename->setFontResolution(32, 32);
|
||||
@@ -203,7 +203,7 @@ protected:
|
||||
osg::ref_ptr<osgText::Text> edesc = new osgText::Text;
|
||||
edesc->setMaximumWidth(client_rect.width() - 16);
|
||||
edesc->setFont(arial.get());
|
||||
edesc->setColor(desc_color_);
|
||||
edesc->setColor(_desc_color);
|
||||
edesc->setAlignment(osgText::Text::LEFT_TOP);
|
||||
edesc->setCharacterSize(16);
|
||||
edesc->setFontResolution(16, 16);
|
||||
@@ -213,19 +213,19 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
int selected_fx_;
|
||||
int _selected_fx;
|
||||
typedef std::vector<osg::ref_ptr<osgFX::Effect> > Effect_list;
|
||||
Effect_list effects_;
|
||||
bool fxen_;
|
||||
osg::ref_ptr<osg::Group> root_;
|
||||
osg::ref_ptr<osg::Node> scene_;
|
||||
osg::Vec4 hints_color_;
|
||||
osg::Vec4 name_color_;
|
||||
osg::Vec4 desc_color_;
|
||||
Effect_list _effects;
|
||||
bool _fxen;
|
||||
osg::ref_ptr<osg::Group> _root;
|
||||
osg::ref_ptr<osg::Node> _scene;
|
||||
osg::Vec4 _hints_color;
|
||||
osg::Vec4 _name_color;
|
||||
osg::Vec4 _desc_color;
|
||||
};
|
||||
|
||||
|
||||
osg::Group *build_hud_base(osg::Group *root)
|
||||
osg::Group* build_hud_base(osg::Group* root)
|
||||
{
|
||||
osg::ref_ptr<osg::Projection> proj = new osg::Projection(osg::Matrix::ortho2D(0, 1024, 0, 768));
|
||||
proj->setCullingActive(false);
|
||||
@@ -246,7 +246,7 @@ osg::Group *build_hud_base(osg::Group *root)
|
||||
return xform.take();
|
||||
}
|
||||
|
||||
EffectPanel *build_gui(osg::Group *root)
|
||||
EffectPanel* build_gui(osg::Group* root)
|
||||
{
|
||||
osg::ref_ptr<osg::Group> hud = build_hud_base(root);
|
||||
|
||||
@@ -259,7 +259,7 @@ EffectPanel *build_gui(osg::Group *root)
|
||||
return effect_panel.take();
|
||||
}
|
||||
|
||||
void build_world(osg::Group *root, osg::Node *scene, osgProducer::Viewer &viewer)
|
||||
void build_world(osg::Group* root, osg::Node* scene, osgProducer::Viewer& viewer)
|
||||
{
|
||||
osg::ref_ptr<EffectPanel> effect_panel = build_gui(root);
|
||||
effect_panel->setScene(scene);
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace osgFX
|
||||
class OSGFX_EXPORT AnisotropicLighting: public Effect {
|
||||
public:
|
||||
AnisotropicLighting();
|
||||
AnisotropicLighting(const AnisotropicLighting ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);
|
||||
AnisotropicLighting(const AnisotropicLighting& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Effect(osgFX, AnisotropicLighting,
|
||||
|
||||
@@ -64,13 +64,13 @@ namespace osgFX
|
||||
|
||||
|
||||
/** get the lighting map */
|
||||
inline osg::Image *getLightingMap();
|
||||
inline osg::Image* getLightingMap();
|
||||
|
||||
/** get the const lighting map */
|
||||
inline const osg::Image *getLightingMap() const;
|
||||
inline const osg::Image* getLightingMap() const;
|
||||
|
||||
/** set the lighting map */
|
||||
inline void setLightingMap(osg::Image *image);
|
||||
inline void setLightingMap(osg::Image* image);
|
||||
|
||||
/** get the OpenGL light number */
|
||||
inline int getLightNumber() const;
|
||||
@@ -80,40 +80,40 @@ namespace osgFX
|
||||
|
||||
protected:
|
||||
virtual ~AnisotropicLighting() {}
|
||||
AnisotropicLighting &operator=(const AnisotropicLighting &) { return *this; }
|
||||
AnisotropicLighting& operator=(const AnisotropicLighting&) { return *this; }
|
||||
|
||||
bool define_techniques();
|
||||
|
||||
private:
|
||||
int lightnum_;
|
||||
osg::ref_ptr<osg::Texture2D> texture_;
|
||||
int _lightnum;
|
||||
osg::ref_ptr<osg::Texture2D> _texture;
|
||||
};
|
||||
|
||||
// INLINE METHODS
|
||||
|
||||
inline osg::Image *AnisotropicLighting::getLightingMap()
|
||||
inline osg::Image* AnisotropicLighting::getLightingMap()
|
||||
{
|
||||
return texture_->getImage();
|
||||
return _texture->getImage();
|
||||
}
|
||||
|
||||
inline const osg::Image *AnisotropicLighting::getLightingMap() const
|
||||
inline const osg::Image* AnisotropicLighting::getLightingMap() const
|
||||
{
|
||||
return texture_->getImage();
|
||||
return _texture->getImage();
|
||||
}
|
||||
|
||||
inline void AnisotropicLighting::setLightingMap(osg::Image *image)
|
||||
inline void AnisotropicLighting::setLightingMap(osg::Image* image)
|
||||
{
|
||||
texture_->setImage(image);
|
||||
_texture->setImage(image);
|
||||
}
|
||||
|
||||
inline int AnisotropicLighting::getLightNumber() const
|
||||
{
|
||||
return lightnum_;
|
||||
return _lightnum;
|
||||
}
|
||||
|
||||
inline void AnisotropicLighting::setLightNumber(int n)
|
||||
{
|
||||
lightnum_ = n;
|
||||
_lightnum = n;
|
||||
dirtyTechniques();
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace osgFX
|
||||
class OSGFX_EXPORT BumpMapping: public Effect {
|
||||
public:
|
||||
BumpMapping();
|
||||
BumpMapping(const BumpMapping ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);
|
||||
BumpMapping(const BumpMapping& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Effect(osgFX, BumpMapping,
|
||||
|
||||
@@ -80,31 +80,31 @@ namespace osgFX
|
||||
inline void setNormalMapTextureUnit(int n);
|
||||
|
||||
/** get the diffuse color texture that overrides children's texture */
|
||||
inline osg::Texture2D *getOverrideDiffuseTexture();
|
||||
inline osg::Texture2D* getOverrideDiffuseTexture();
|
||||
|
||||
/** get the const diffuse color texture that overrides children's texture */
|
||||
inline const osg::Texture2D *getOverrideDiffuseTexture() const;
|
||||
inline const osg::Texture2D* getOverrideDiffuseTexture() const;
|
||||
|
||||
/** set the diffuse color texture that overrides children's texture */
|
||||
inline void setOverrideDiffuseTexture(osg::Texture2D *texture);
|
||||
inline void setOverrideDiffuseTexture(osg::Texture2D* texture);
|
||||
|
||||
/** get the normal map texture that overrides children's texture */
|
||||
inline osg::Texture2D *getOverrideNormalMapTexture();
|
||||
inline osg::Texture2D* getOverrideNormalMapTexture();
|
||||
|
||||
/** get the const normal map texture that overrides children's texture */
|
||||
inline const osg::Texture2D *getOverrideNormalMapTexture() const;
|
||||
inline const osg::Texture2D* getOverrideNormalMapTexture() const;
|
||||
|
||||
/** set the normal map texture that overrides children's texture */
|
||||
inline void setOverrideNormalMapTexture(osg::Texture2D *texture);
|
||||
inline void setOverrideNormalMapTexture(osg::Texture2D* texture);
|
||||
|
||||
/**
|
||||
prepare a Geometry for bump lighting. Tangent-space basis vectors are
|
||||
generated and attached to the geometry as vertex attribute arrays.
|
||||
*/
|
||||
void prepareGeometry(osg::Geometry *geo);
|
||||
void prepareGeometry(osg::Geometry* geo);
|
||||
|
||||
/** prepare a Node for bump lighting, calling prepareGeometry() for each Geometry */
|
||||
void prepareNode(osg::Node *node);
|
||||
void prepareNode(osg::Node* node);
|
||||
|
||||
/** prepare children for bump lighting. Actually calls prepareNode() for each child */
|
||||
void prepareChildren();
|
||||
@@ -119,77 +119,77 @@ namespace osgFX
|
||||
bool define_techniques();
|
||||
|
||||
private:
|
||||
int lightnum_;
|
||||
int diffuseunit_;
|
||||
int normalunit_;
|
||||
osg::ref_ptr<osg::Texture2D> diffuse_tex_;
|
||||
osg::ref_ptr<osg::Texture2D> normal_tex_;
|
||||
int _lightnum;
|
||||
int _diffuse_unit;
|
||||
int _normal_unit;
|
||||
osg::ref_ptr<osg::Texture2D> _diffuse_tex;
|
||||
osg::ref_ptr<osg::Texture2D> _normal_tex;
|
||||
};
|
||||
|
||||
// INLINE METHODS
|
||||
|
||||
inline int BumpMapping::getLightNumber() const
|
||||
{
|
||||
return lightnum_;
|
||||
return _lightnum;
|
||||
}
|
||||
|
||||
inline void BumpMapping::setLightNumber(int n)
|
||||
{
|
||||
lightnum_ = n;
|
||||
_lightnum = n;
|
||||
dirtyTechniques();
|
||||
}
|
||||
|
||||
inline int BumpMapping::getDiffuseTextureUnit() const
|
||||
{
|
||||
return diffuseunit_;
|
||||
return _diffuse_unit;
|
||||
}
|
||||
|
||||
inline void BumpMapping::setDiffuseTextureUnit(int n)
|
||||
{
|
||||
diffuseunit_ = n;
|
||||
_diffuse_unit = n;
|
||||
dirtyTechniques();
|
||||
}
|
||||
|
||||
inline int BumpMapping::getNormalMapTextureUnit() const
|
||||
{
|
||||
return normalunit_;
|
||||
return _normal_unit;
|
||||
}
|
||||
|
||||
inline void BumpMapping::setNormalMapTextureUnit(int n)
|
||||
{
|
||||
normalunit_ = n;
|
||||
_normal_unit = n;
|
||||
dirtyTechniques();
|
||||
}
|
||||
|
||||
inline osg::Texture2D *BumpMapping::getOverrideDiffuseTexture()
|
||||
inline osg::Texture2D* BumpMapping::getOverrideDiffuseTexture()
|
||||
{
|
||||
return diffuse_tex_.get();
|
||||
return _diffuse_tex.get();
|
||||
}
|
||||
|
||||
inline const osg::Texture2D *BumpMapping::getOverrideDiffuseTexture() const
|
||||
inline const osg::Texture2D* BumpMapping::getOverrideDiffuseTexture() const
|
||||
{
|
||||
return diffuse_tex_.get();
|
||||
return _diffuse_tex.get();
|
||||
}
|
||||
|
||||
inline void BumpMapping::setOverrideDiffuseTexture(osg::Texture2D *texture)
|
||||
inline void BumpMapping::setOverrideDiffuseTexture(osg::Texture2D* texture)
|
||||
{
|
||||
diffuse_tex_ = texture;
|
||||
_diffuse_tex = texture;
|
||||
dirtyTechniques();
|
||||
}
|
||||
|
||||
inline osg::Texture2D *BumpMapping::getOverrideNormalMapTexture()
|
||||
inline osg::Texture2D* BumpMapping::getOverrideNormalMapTexture()
|
||||
{
|
||||
return normal_tex_.get();
|
||||
return _normal_tex.get();
|
||||
}
|
||||
|
||||
inline const osg::Texture2D *BumpMapping::getOverrideNormalMapTexture() const
|
||||
inline const osg::Texture2D* BumpMapping::getOverrideNormalMapTexture() const
|
||||
{
|
||||
return normal_tex_.get();
|
||||
return _normal_tex.get();
|
||||
}
|
||||
|
||||
inline void BumpMapping::setOverrideNormalMapTexture(osg::Texture2D *texture)
|
||||
inline void BumpMapping::setOverrideNormalMapTexture(osg::Texture2D* texture)
|
||||
{
|
||||
normal_tex_ = texture;
|
||||
_normal_tex = texture;
|
||||
dirtyTechniques();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace osgFX
|
||||
class OSGFX_EXPORT Cartoon: public Effect {
|
||||
public:
|
||||
Cartoon();
|
||||
Cartoon(const Cartoon ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);
|
||||
Cartoon(const Cartoon& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
// effect class informations
|
||||
META_Effect(
|
||||
@@ -55,10 +55,10 @@ namespace osgFX
|
||||
"Marco Jez; OGLSL port by Mike Weiblen");
|
||||
|
||||
/** get the outline color */
|
||||
inline const osg::Vec4 &getOutlineColor() const;
|
||||
inline const osg::Vec4& getOutlineColor() const;
|
||||
|
||||
/** set the outline color */
|
||||
inline void setOutlineColor(const osg::Vec4 &color);
|
||||
inline void setOutlineColor(const osg::Vec4& color);
|
||||
|
||||
/** get the outline line width */
|
||||
inline float getOutlineLineWidth() const;
|
||||
@@ -74,46 +74,46 @@ namespace osgFX
|
||||
|
||||
protected:
|
||||
virtual ~Cartoon() {}
|
||||
Cartoon &operator=(const Cartoon &) { return *this; }
|
||||
Cartoon& operator=(const Cartoon&) { return *this; }
|
||||
|
||||
bool define_techniques();
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osg::Material> wf_mat_;
|
||||
osg::ref_ptr<osg::LineWidth> wf_lw_;
|
||||
int lightnum_;
|
||||
osg::ref_ptr<osg::Material> _wf_mat;
|
||||
osg::ref_ptr<osg::LineWidth> _wf_lw;
|
||||
int _lightnum;
|
||||
};
|
||||
|
||||
// INLINE METHODS
|
||||
|
||||
inline const osg::Vec4 &Cartoon::getOutlineColor() const
|
||||
inline const osg::Vec4& Cartoon::getOutlineColor() const
|
||||
{
|
||||
return wf_mat_->getEmission(osg::Material::FRONT_AND_BACK);
|
||||
return _wf_mat->getEmission(osg::Material::FRONT_AND_BACK);
|
||||
}
|
||||
|
||||
inline void Cartoon::setOutlineColor(const osg::Vec4 &color)
|
||||
inline void Cartoon::setOutlineColor(const osg::Vec4& color)
|
||||
{
|
||||
wf_mat_->setEmission(osg::Material::FRONT_AND_BACK, color);
|
||||
_wf_mat->setEmission(osg::Material::FRONT_AND_BACK, color);
|
||||
}
|
||||
|
||||
inline float Cartoon::getOutlineLineWidth() const
|
||||
{
|
||||
return wf_lw_->getWidth();
|
||||
return _wf_lw->getWidth();
|
||||
}
|
||||
|
||||
inline void Cartoon::setOutlineLineWidth(float w)
|
||||
{
|
||||
wf_lw_->setWidth(w);
|
||||
_wf_lw->setWidth(w);
|
||||
}
|
||||
|
||||
inline int Cartoon::getLightNumber() const
|
||||
{
|
||||
return lightnum_;
|
||||
return _lightnum;
|
||||
}
|
||||
|
||||
inline void Cartoon::setLightNumber(int n)
|
||||
{
|
||||
lightnum_ = n;
|
||||
_lightnum = n;
|
||||
dirtyTechniques();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
*/
|
||||
//osgFX - Copyright (C) 2003 Marco Jez
|
||||
|
||||
#ifndef OSGFX_EFFECT_
|
||||
#define OSGFX_EFFECT_
|
||||
#ifndef OSGFX__effect
|
||||
#define OSGFX__effect
|
||||
|
||||
#include <osgFX/Export>
|
||||
#include <osgFX/Technique>
|
||||
@@ -66,16 +66,16 @@ namespace osgFX
|
||||
class OSGFX_EXPORT Effect: public osg::Group {
|
||||
public:
|
||||
Effect();
|
||||
Effect(const Effect ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);
|
||||
Effect(const Effect& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
virtual inline bool isSameKindAs(const osg::Object *obj) const { return dynamic_cast<const Effect *>(obj) != NULL; }
|
||||
virtual inline const char *libraryName() const { return "osgFX"; }
|
||||
virtual inline const char *className() const { return "Effect"; }
|
||||
virtual inline bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Effect*>(obj) != NULL; }
|
||||
virtual inline const char* libraryName() const { return "osgFX"; }
|
||||
virtual inline const char* className() const { return "Effect"; }
|
||||
|
||||
/** get the name of this effect */
|
||||
/** get the name of this Effect */
|
||||
virtual const char *effectName() const = 0;
|
||||
|
||||
/** get a brief description of this effect */
|
||||
/** get a brief description of this Effect*/
|
||||
virtual const char *effectDescription() const = 0;
|
||||
|
||||
/** get the effect author's name */
|
||||
@@ -94,16 +94,16 @@ namespace osgFX
|
||||
*/
|
||||
inline virtual void setUpDemo() {}
|
||||
|
||||
/** get the number of techniques defined for this effect */
|
||||
/** get the number of techniques defined for this Effect */
|
||||
inline int getNumTechniques() const;
|
||||
|
||||
/** get the i-th technique */
|
||||
inline Technique *getTechnique(int i);
|
||||
/** get the i-th Technique */
|
||||
inline Technique* getTechnique(int i);
|
||||
|
||||
/** get the i-th const technique */
|
||||
inline const Technique *getTechnique(int i) const;
|
||||
/** get the i-th const Technique */
|
||||
inline const Technique* getTechnique(int i) const;
|
||||
|
||||
/** get the index of the currently selected technique */
|
||||
/** get the index of the currently selected Technique */
|
||||
inline int getSelectedTechnique() const;
|
||||
|
||||
enum TechniqueSelection {
|
||||
@@ -114,10 +114,10 @@ namespace osgFX
|
||||
inline void selectTechnique(int i = AUTO_DETECT);
|
||||
|
||||
/** custom traversal */
|
||||
virtual void traverse(osg::NodeVisitor &nv);
|
||||
virtual void traverse(osg::NodeVisitor& nv);
|
||||
|
||||
/** default traversal */
|
||||
inline void inherited_traverse(osg::NodeVisitor &nv);
|
||||
inline void inherited_traverse(osg::NodeVisitor& nv);
|
||||
|
||||
protected:
|
||||
virtual ~Effect();
|
||||
@@ -126,8 +126,8 @@ namespace osgFX
|
||||
/** force rebuilding of techniques on next traversal */
|
||||
inline void dirtyTechniques();
|
||||
|
||||
/** add a technique to the effect */
|
||||
inline void addTechnique(Technique *tech);
|
||||
/** add a technique to the Effect */
|
||||
inline void addTechnique(Technique* tech);
|
||||
|
||||
/**
|
||||
abstract method to be implemented in derived classes; its purpose
|
||||
@@ -140,21 +140,21 @@ namespace osgFX
|
||||
private:
|
||||
friend class Validator;
|
||||
|
||||
bool enabled_;
|
||||
bool _enabled;
|
||||
|
||||
typedef std::vector<osg::ref_ptr<Technique> > Technique_list;
|
||||
Technique_list techs_;
|
||||
Technique_list _techs;
|
||||
|
||||
mutable osg::buffered_value<int> sel_tech_;
|
||||
mutable osg::buffered_value<int> _sel_tech;
|
||||
|
||||
// use int instead of bool to avoid errors
|
||||
mutable osg::buffered_value<int> tech_selected_;
|
||||
mutable osg::buffered_value<int> _tech_selected;
|
||||
|
||||
int global_sel_tech_;
|
||||
int _global_sel_tech;
|
||||
|
||||
bool techs_defined_;
|
||||
bool _techs_defined;
|
||||
|
||||
osg::ref_ptr<osg::Geode> dummy_for_validation_;
|
||||
osg::ref_ptr<osg::Geode> _dummy_for_validation;
|
||||
|
||||
void build_dummy_node();
|
||||
};
|
||||
@@ -163,50 +163,50 @@ namespace osgFX
|
||||
|
||||
inline bool Effect::getEnabled() const
|
||||
{
|
||||
return enabled_;
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
inline void Effect::setEnabled(bool v)
|
||||
{
|
||||
enabled_ = v;
|
||||
_enabled = v;
|
||||
}
|
||||
|
||||
inline int Effect::getNumTechniques() const
|
||||
{
|
||||
return static_cast<int>(techs_.size());
|
||||
return static_cast<int>(_techs.size());
|
||||
}
|
||||
|
||||
inline Technique *Effect::getTechnique(int i)
|
||||
inline Technique* Effect::getTechnique(int i)
|
||||
{
|
||||
return techs_[i].get();
|
||||
return _techs[i].get();
|
||||
}
|
||||
|
||||
inline const Technique *Effect::getTechnique(int i) const
|
||||
inline const Technique* Effect::getTechnique(int i) const
|
||||
{
|
||||
return techs_[i].get();
|
||||
return _techs[i].get();
|
||||
}
|
||||
|
||||
inline int Effect::getSelectedTechnique() const
|
||||
{
|
||||
return global_sel_tech_;
|
||||
return _global_sel_tech;
|
||||
}
|
||||
|
||||
inline void Effect::selectTechnique(int i)
|
||||
{
|
||||
global_sel_tech_ = i;
|
||||
_global_sel_tech = i;
|
||||
}
|
||||
|
||||
inline void Effect::addTechnique(Technique *tech)
|
||||
inline void Effect::addTechnique(Technique* tech)
|
||||
{
|
||||
techs_.push_back(tech);
|
||||
_techs.push_back(tech);
|
||||
}
|
||||
|
||||
inline void Effect::dirtyTechniques()
|
||||
{
|
||||
techs_defined_ = false;
|
||||
_techs_defined = false;
|
||||
}
|
||||
|
||||
inline void Effect::inherited_traverse(osg::NodeVisitor &nv)
|
||||
inline void Effect::inherited_traverse(osg::NodeVisitor& nv)
|
||||
{
|
||||
typedef osg::Group inherited;
|
||||
inherited::traverse(nv);
|
||||
|
||||
@@ -26,23 +26,24 @@
|
||||
namespace osgFX
|
||||
{
|
||||
|
||||
class OSGFX_EXPORT Registry : public osg::Referenced{
|
||||
class OSGFX_EXPORT Registry : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
struct Proxy {
|
||||
Proxy(const Effect *effect)
|
||||
Proxy(const Effect* effect)
|
||||
{
|
||||
Registry::instance()->registerEffect(effect);
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<std::string, osg::ref_ptr<const Effect> > Effect_map;
|
||||
typedef std::map<std::string, osg::ref_ptr<const Effect> > EffectMap;
|
||||
|
||||
static Registry *instance();
|
||||
static Registry* instance();
|
||||
|
||||
inline void registerEffect(const Effect *effect);
|
||||
inline void registerEffect(const Effect* effect);
|
||||
|
||||
inline const Effect_map &getEffectMap() const;
|
||||
inline const EffectMap& getEffectMap() const;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -51,21 +52,21 @@ namespace osgFX
|
||||
~Registry() {}
|
||||
|
||||
private:
|
||||
Effect_map effects_;
|
||||
EffectMap _effects;
|
||||
};
|
||||
|
||||
// INLINE METHODS
|
||||
|
||||
|
||||
|
||||
inline const Registry::Effect_map &Registry::getEffectMap() const
|
||||
inline const Registry::EffectMap& Registry::getEffectMap() const
|
||||
{
|
||||
return effects_;
|
||||
return _effects;
|
||||
}
|
||||
|
||||
inline void Registry::registerEffect(const Effect *effect)
|
||||
inline void Registry::registerEffect(const Effect* effect)
|
||||
{
|
||||
effects_[effect->effectName()] = effect;
|
||||
_effects[effect->effectName()] = effect;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace osgFX
|
||||
class OSGFX_EXPORT Scribe: public Effect {
|
||||
public:
|
||||
Scribe();
|
||||
Scribe(const Scribe ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);
|
||||
Scribe(const Scribe& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
// effect class informations
|
||||
META_Effect(
|
||||
@@ -52,10 +52,10 @@ namespace osgFX
|
||||
"Marco Jez");
|
||||
|
||||
/** get the wireframe color */
|
||||
inline const osg::Vec4 &getWireframeColor() const;
|
||||
inline const osg::Vec4& getWireframeColor() const;
|
||||
|
||||
/** set the wireframe color */
|
||||
inline void setWireframeColor(const osg::Vec4 &color);
|
||||
inline void setWireframeColor(const osg::Vec4& color);
|
||||
|
||||
/** get the wireframe line width */
|
||||
inline float getWireframeLineWidth() const;
|
||||
@@ -65,35 +65,35 @@ namespace osgFX
|
||||
|
||||
protected:
|
||||
virtual ~Scribe() {}
|
||||
Scribe &operator=(const Scribe &) { return *this; }
|
||||
Scribe& operator=(const Scribe&) { return *this; }
|
||||
|
||||
bool define_techniques();
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osg::Material> wf_mat_;
|
||||
osg::ref_ptr<osg::LineWidth> wf_lw_;
|
||||
osg::ref_ptr<osg::Material> _wf_mat;
|
||||
osg::ref_ptr<osg::LineWidth> _wf_lw;
|
||||
};
|
||||
|
||||
// INLINE METHODS
|
||||
|
||||
inline const osg::Vec4 &Scribe::getWireframeColor() const
|
||||
inline const osg::Vec4& Scribe::getWireframeColor() const
|
||||
{
|
||||
return wf_mat_->getEmission(osg::Material::FRONT_AND_BACK);
|
||||
return _wf_mat->getEmission(osg::Material::FRONT_AND_BACK);
|
||||
}
|
||||
|
||||
inline void Scribe::setWireframeColor(const osg::Vec4 &color)
|
||||
inline void Scribe::setWireframeColor(const osg::Vec4& color)
|
||||
{
|
||||
wf_mat_->setEmission(osg::Material::FRONT_AND_BACK, color);
|
||||
_wf_mat->setEmission(osg::Material::FRONT_AND_BACK, color);
|
||||
}
|
||||
|
||||
inline float Scribe::getWireframeLineWidth() const
|
||||
{
|
||||
return wf_lw_->getWidth();
|
||||
return _wf_lw->getWidth();
|
||||
}
|
||||
|
||||
inline void Scribe::setWireframeLineWidth(float w)
|
||||
{
|
||||
wf_lw_->setWidth(w);
|
||||
_wf_lw->setWidth(w);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace osgFX
|
||||
class OSGFX_EXPORT SpecularHighlights: public Effect {
|
||||
public:
|
||||
SpecularHighlights();
|
||||
SpecularHighlights(const SpecularHighlights ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);
|
||||
SpecularHighlights(const SpecularHighlights& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Effect(osgFX, SpecularHighlights,
|
||||
|
||||
@@ -63,10 +63,10 @@ namespace osgFX
|
||||
inline void setTextureUnit(int n);
|
||||
|
||||
/** get the specular color */
|
||||
inline const osg::Vec4 &getSpecularColor() const;
|
||||
inline const osg::Vec4& getSpecularColor() const;
|
||||
|
||||
/** set the specular color */
|
||||
inline void setSpecularColor(const osg::Vec4 &color);
|
||||
inline void setSpecularColor(const osg::Vec4& color);
|
||||
|
||||
/** get the specular exponent */
|
||||
inline float getSpecularExponent() const;
|
||||
@@ -76,60 +76,60 @@ namespace osgFX
|
||||
|
||||
protected:
|
||||
virtual ~SpecularHighlights() {}
|
||||
SpecularHighlights &operator=(const SpecularHighlights &) { return *this; }
|
||||
SpecularHighlights& operator=(const SpecularHighlights&) { return *this; }
|
||||
|
||||
bool define_techniques();
|
||||
|
||||
private:
|
||||
int lightnum_;
|
||||
int unit_;
|
||||
osg::Vec4 color_;
|
||||
float sexp_;
|
||||
int _lightnum;
|
||||
int _unit;
|
||||
osg::Vec4 _color;
|
||||
float _sexp;
|
||||
};
|
||||
|
||||
// INLINE METHODS
|
||||
|
||||
inline int SpecularHighlights::getLightNumber() const
|
||||
{
|
||||
return lightnum_;
|
||||
return _lightnum;
|
||||
}
|
||||
|
||||
inline void SpecularHighlights::setLightNumber(int n)
|
||||
{
|
||||
lightnum_ = n;
|
||||
_lightnum = n;
|
||||
dirtyTechniques();
|
||||
}
|
||||
|
||||
inline int SpecularHighlights::getTextureUnit() const
|
||||
{
|
||||
return unit_;
|
||||
return _unit;
|
||||
}
|
||||
|
||||
inline void SpecularHighlights::setTextureUnit(int n)
|
||||
{
|
||||
unit_ = n;
|
||||
_unit = n;
|
||||
dirtyTechniques();
|
||||
}
|
||||
|
||||
inline const osg::Vec4 &SpecularHighlights::getSpecularColor() const
|
||||
inline const osg::Vec4& SpecularHighlights::getSpecularColor() const
|
||||
{
|
||||
return color_;
|
||||
return _color;
|
||||
}
|
||||
|
||||
inline void SpecularHighlights::setSpecularColor(const osg::Vec4 &color)
|
||||
inline void SpecularHighlights::setSpecularColor(const osg::Vec4& color)
|
||||
{
|
||||
color_ = color;
|
||||
_color = color;
|
||||
dirtyTechniques();
|
||||
}
|
||||
|
||||
inline float SpecularHighlights::getSpecularExponent() const
|
||||
{
|
||||
return sexp_;
|
||||
return _sexp;
|
||||
}
|
||||
|
||||
inline void SpecularHighlights::setSpecularExponent(float e)
|
||||
{
|
||||
sexp_ = e;
|
||||
_sexp = e;
|
||||
dirtyTechniques();
|
||||
}
|
||||
|
||||
|
||||
@@ -123,29 +123,29 @@ namespace osgFX
|
||||
|
||||
private:
|
||||
typedef std::vector<osg::ref_ptr<osg::StateSet> > Pass_list;
|
||||
Pass_list passes_;
|
||||
Pass_list _passes;
|
||||
};
|
||||
|
||||
// INLINE METHODS
|
||||
|
||||
inline int Technique::getNumPasses() const
|
||||
{
|
||||
return static_cast<int>(passes_.size());
|
||||
return static_cast<int>(_passes.size());
|
||||
}
|
||||
|
||||
inline osg::StateSet *Technique::getPassStateSet(int i)
|
||||
{
|
||||
return passes_[i].get();
|
||||
return _passes[i].get();
|
||||
}
|
||||
|
||||
inline const osg::StateSet *Technique::getPassStateSet(int i) const
|
||||
{
|
||||
return passes_[i].get();
|
||||
return _passes[i].get();
|
||||
}
|
||||
|
||||
inline void Technique::dirtyPasses()
|
||||
{
|
||||
passes_.clear();
|
||||
_passes.clear();
|
||||
}
|
||||
|
||||
inline void Technique::traverse(osg::NodeVisitor &nv, Effect *fx)
|
||||
|
||||
@@ -36,36 +36,36 @@ namespace osgFX
|
||||
public:
|
||||
|
||||
Validator();
|
||||
Validator(Effect *effect);
|
||||
Validator(const Validator ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);
|
||||
Validator(Effect* effect);
|
||||
Validator(const Validator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_StateAttribute(osgFX, Validator, VALIDATOR);
|
||||
|
||||
void apply(osg::State &state) const;
|
||||
void compileGLObjects(osg::State &state) const;
|
||||
void apply(osg::State& state) const;
|
||||
void compileGLObjects(osg::State& state) const;
|
||||
|
||||
inline int compare(const osg::StateAttribute &sa) const;
|
||||
inline int compare(const osg::StateAttribute& sa) const;
|
||||
|
||||
inline void disable() { effect_ = 0; }
|
||||
inline void disable() { _effect = 0; }
|
||||
|
||||
protected:
|
||||
virtual ~Validator() {}
|
||||
Validator &operator=(const Validator &) { return *this; }
|
||||
Validator& operator=(const Validator&) { return *this; }
|
||||
|
||||
private:
|
||||
mutable Effect *effect_;
|
||||
mutable Effect* _effect;
|
||||
};
|
||||
|
||||
// INLINE METHODS
|
||||
|
||||
inline int Validator::compare(const osg::StateAttribute &sa) const
|
||||
inline int Validator::compare(const osg::StateAttribute& sa) const
|
||||
{
|
||||
// check the types are equal and then create the rhs variable
|
||||
//used by the COMPARE_StateAttribute_Paramter macro's below.
|
||||
COMPARE_StateAttribute_Types(Validator,sa)
|
||||
|
||||
// compare parameters
|
||||
COMPARE_StateAttribute_Parameter(effect_)
|
||||
COMPARE_StateAttribute_Parameter(_effect)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -24,25 +24,25 @@ namespace
|
||||
public:
|
||||
ViewMatrixExtractor()
|
||||
: osg::StateAttribute(),
|
||||
vp_(0),
|
||||
param_(0),
|
||||
first_context_(-1)
|
||||
_vp(0),
|
||||
_param(0),
|
||||
_first_context(-1)
|
||||
{
|
||||
}
|
||||
|
||||
ViewMatrixExtractor(const ViewMatrixExtractor ©, const osg::CopyOp ©op)
|
||||
ViewMatrixExtractor(const ViewMatrixExtractor& copy, const osg::CopyOp& copyop)
|
||||
: osg::StateAttribute(copy, copyop),
|
||||
vp_(static_cast<osg::VertexProgram *>(copyop(copy.vp_.get()))),
|
||||
param_(copy.param_),
|
||||
first_context_(-1)
|
||||
_vp(static_cast<osg::VertexProgram *>(copyop(copy._vp.get()))),
|
||||
_param(copy._param),
|
||||
_first_context(-1)
|
||||
{
|
||||
}
|
||||
|
||||
ViewMatrixExtractor(osg::VertexProgram *vp, int param)
|
||||
: osg::StateAttribute(),
|
||||
vp_(vp),
|
||||
param_(param),
|
||||
first_context_(-1)
|
||||
_vp(vp),
|
||||
_param(param),
|
||||
_first_context(-1)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -51,31 +51,31 @@ namespace
|
||||
int compare(const osg::StateAttribute &sa) const
|
||||
{
|
||||
COMPARE_StateAttribute_Types(ViewMatrixExtractor, sa);
|
||||
if (vp_.get() != rhs.vp_.get()) return -1;
|
||||
if (param_ < rhs.param_) return -1;
|
||||
if (param_ > rhs.param_) return 1;
|
||||
if (_vp.get() != rhs._vp.get()) return -1;
|
||||
if (_param < rhs._param) return -1;
|
||||
if (_param > rhs._param) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void apply(osg::State &state) const
|
||||
void apply(osg::State& state) const
|
||||
{
|
||||
if (first_context_ == -1) {
|
||||
first_context_ = state.getContextID();
|
||||
if (_first_context == -1) {
|
||||
_first_context = state.getContextID();
|
||||
}
|
||||
if (state.getContextID() == (unsigned int)first_context_) {
|
||||
if (vp_.valid()) {
|
||||
if (state.getContextID() == (unsigned int)_first_context) {
|
||||
if (_vp.valid()) {
|
||||
osg::Matrix M = state.getInitialInverseViewMatrix();
|
||||
for (int i=0; i<4; ++i) {
|
||||
vp_->setProgramLocalParameter(param_+i, osg::Vec4(M(0, i), M(1, i), M(2, i), M(3, i)));
|
||||
_vp->setProgramLocalParameter(_param+i, osg::Vec4(M(0, i), M(1, i), M(2, i), M(3, i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
mutable osg::ref_ptr<osg::VertexProgram> vp_;
|
||||
int param_;
|
||||
mutable int first_context_;
|
||||
mutable osg::ref_ptr<osg::VertexProgram> _vp;
|
||||
int _param;
|
||||
mutable int _first_context;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -83,15 +83,15 @@ namespace
|
||||
namespace
|
||||
{
|
||||
|
||||
osg::Image *create_default_image()
|
||||
osg::Image* create_default_image()
|
||||
{
|
||||
const int texture_size = 16;
|
||||
const int _texturesize = 16;
|
||||
osg::ref_ptr<osg::Image> image = new osg::Image;
|
||||
image->setImage(texture_size, texture_size, 1, 3, GL_RGB, GL_UNSIGNED_BYTE, new unsigned char[3*texture_size*texture_size], osg::Image::USE_NEW_DELETE);
|
||||
for (int i=0; i<texture_size; ++i) {
|
||||
for (int j=0; j<texture_size; ++j) {
|
||||
float s = static_cast<float>(j) / (texture_size-1);
|
||||
float t = static_cast<float>(i) / (texture_size-1);
|
||||
image->setImage(_texturesize, _texturesize, 1, 3, GL_RGB, GL_UNSIGNED_BYTE, new unsigned char[3*_texturesize*_texturesize], osg::Image::USE_NEW_DELETE);
|
||||
for (int i=0; i<_texturesize; ++i) {
|
||||
for (int j=0; j<_texturesize; ++j) {
|
||||
float s = static_cast<float>(j) / (_texturesize-1);
|
||||
float t = static_cast<float>(i) / (_texturesize-1);
|
||||
float lum = t * 0.75f;
|
||||
float red = lum + 0.2f * powf(cosf(s*10), 3.0f);
|
||||
float green = lum;
|
||||
@@ -120,12 +120,12 @@ namespace
|
||||
|
||||
DefaultTechnique(int lightnum, osg::Texture2D *texture)
|
||||
: Technique(),
|
||||
lightnum_(lightnum),
|
||||
texture_(texture)
|
||||
_lightnum(lightnum),
|
||||
_texture(texture)
|
||||
{
|
||||
}
|
||||
|
||||
void getRequiredExtensions(std::vector<std::string> &extensions) const
|
||||
void getRequiredExtensions(std::vector<std::string>& extensions) const
|
||||
{
|
||||
extensions.push_back("GL_ARB_vertex_program");
|
||||
}
|
||||
@@ -143,7 +143,7 @@ namespace
|
||||
"ATTRIB v18 = vertex.normal;"
|
||||
"ATTRIB v16 = vertex.position;"
|
||||
"PARAM s259[4] = { state.matrix.mvp };"
|
||||
"PARAM s18 = state.light[" << lightnum_ << "].position;"
|
||||
"PARAM s18 = state.light[" << _lightnum << "].position;"
|
||||
"PARAM s223[4] = { state.matrix.modelview };"
|
||||
"PARAM c0[4] = { program.local[0..3] };"
|
||||
" DP4 result.position.x, s259[0], v16;"
|
||||
@@ -210,7 +210,7 @@ namespace
|
||||
|
||||
ss->setAttributeAndModes(new ViewMatrixExtractor(vp.get(), 0), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
ss->setTextureAttributeAndModes(0, texture_.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
ss->setTextureAttributeAndModes(0, _texture.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
osg::ref_ptr<osg::TexEnv> texenv = new osg::TexEnv;
|
||||
texenv->setMode(osg::TexEnv::DECAL);
|
||||
@@ -222,8 +222,8 @@ namespace
|
||||
}
|
||||
|
||||
private:
|
||||
int lightnum_;
|
||||
osg::ref_ptr<osg::Texture2D> texture_;
|
||||
int _lightnum;
|
||||
osg::ref_ptr<osg::Texture2D> _texture;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -231,23 +231,23 @@ namespace
|
||||
|
||||
AnisotropicLighting::AnisotropicLighting()
|
||||
: Effect(),
|
||||
lightnum_(0),
|
||||
texture_(new osg::Texture2D)
|
||||
_lightnum(0),
|
||||
_texture(new osg::Texture2D)
|
||||
{
|
||||
texture_->setImage(create_default_image());
|
||||
texture_->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP);
|
||||
texture_->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP);
|
||||
_texture->setImage(create_default_image());
|
||||
_texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP);
|
||||
_texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP);
|
||||
}
|
||||
|
||||
AnisotropicLighting::AnisotropicLighting(const AnisotropicLighting ©, const osg::CopyOp ©op)
|
||||
AnisotropicLighting::AnisotropicLighting(const AnisotropicLighting& copy, const osg::CopyOp& copyop)
|
||||
: Effect(copy, copyop),
|
||||
lightnum_(copy.lightnum_),
|
||||
texture_(static_cast<osg::Texture2D *>(copyop(copy.texture_.get())))
|
||||
_lightnum(copy._lightnum),
|
||||
_texture(static_cast<osg::Texture2D *>(copyop(copy._texture.get())))
|
||||
{
|
||||
}
|
||||
|
||||
bool AnisotropicLighting::define_techniques()
|
||||
{
|
||||
addTechnique(new DefaultTechnique(lightnum_, texture_.get()));
|
||||
addTechnique(new DefaultTechnique(_lightnum, _texture.get()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -29,19 +29,19 @@ namespace
|
||||
// basis vectors
|
||||
class TsgVisitor: public NodeVisitor {
|
||||
public:
|
||||
TsgVisitor(BumpMapping *bm): NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN), bm_(bm) {}
|
||||
void apply(osg::Geode &geode)
|
||||
TsgVisitor(BumpMapping* bm): NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN), _bm(bm) {}
|
||||
void apply(osg::Geode& geode)
|
||||
{
|
||||
for (unsigned i=0; i<geode.getNumDrawables(); ++i) {
|
||||
osg::Geometry *geo = dynamic_cast<osg::Geometry *>(geode.getDrawable(i));
|
||||
osg::Geometry* geo = dynamic_cast<osg::Geometry* >(geode.getDrawable(i));
|
||||
if (geo) {
|
||||
bm_->prepareGeometry(geo);
|
||||
_bm->prepareGeometry(geo);
|
||||
}
|
||||
}
|
||||
NodeVisitor::apply(geode);
|
||||
}
|
||||
private:
|
||||
BumpMapping *bm_;
|
||||
BumpMapping* _bm;
|
||||
};
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace
|
||||
class TexCoordGenerator: public osg::NodeVisitor {
|
||||
public:
|
||||
TexCoordGenerator(int du, int nu): NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN), du_(du), nu_(nu) {}
|
||||
void apply(osg::Geode &geode)
|
||||
void apply(osg::Geode& geode)
|
||||
{
|
||||
const osg::BoundingSphere &bsphere = geode.getBound();
|
||||
float scale = 10;
|
||||
@@ -58,7 +58,7 @@ namespace
|
||||
scale = 5 / bsphere.radius();
|
||||
}
|
||||
for (unsigned i=0; i<geode.getNumDrawables(); ++i) {
|
||||
osg::Geometry *geo = dynamic_cast<osg::Geometry *>(geode.getDrawable(i));
|
||||
osg::Geometry* geo = dynamic_cast<osg::Geometry* >(geode.getDrawable(i));
|
||||
if (geo) {
|
||||
osg::ref_ptr<osg::Vec2Array> tc = generate_coords(geo->getVertexArray(), geo->getNormalArray(), scale);
|
||||
geo->setTexCoordArray(du_, tc.get());
|
||||
@@ -69,14 +69,14 @@ namespace
|
||||
}
|
||||
|
||||
protected:
|
||||
osg::Vec2Array *generate_coords(osg::Array *vx, osg::Array *nx, float scale)
|
||||
osg::Vec2Array* generate_coords(osg::Array* vx, osg::Array* nx, float scale)
|
||||
{
|
||||
osg::Vec2Array *v2a = dynamic_cast<osg::Vec2Array *>(vx);
|
||||
osg::Vec3Array *v3a = dynamic_cast<osg::Vec3Array *>(vx);
|
||||
osg::Vec4Array *v4a = dynamic_cast<osg::Vec4Array *>(vx);
|
||||
osg::Vec2Array *n2a = dynamic_cast<osg::Vec2Array *>(nx);
|
||||
osg::Vec3Array *n3a = dynamic_cast<osg::Vec3Array *>(nx);
|
||||
osg::Vec4Array *n4a = dynamic_cast<osg::Vec4Array *>(nx);
|
||||
osg::Vec2Array* v2a = dynamic_cast<osg::Vec2Array*>(vx);
|
||||
osg::Vec3Array* v3a = dynamic_cast<osg::Vec3Array*>(vx);
|
||||
osg::Vec4Array* v4a = dynamic_cast<osg::Vec4Array*>(vx);
|
||||
osg::Vec2Array* n2a = dynamic_cast<osg::Vec2Array*>(nx);
|
||||
osg::Vec3Array* n3a = dynamic_cast<osg::Vec3Array*>(nx);
|
||||
osg::Vec4Array* n4a = dynamic_cast<osg::Vec4Array*>(nx);
|
||||
|
||||
osg::ref_ptr<osg::Vec2Array> tc = new osg::Vec2Array;
|
||||
for (unsigned i=0; i<vx->getNumElements(); ++i) {
|
||||
@@ -135,58 +135,58 @@ namespace
|
||||
|
||||
ViewMatrixExtractor()
|
||||
: osg::StateAttribute(),
|
||||
vp_(0),
|
||||
param_(0),
|
||||
first_context_(NO_VALID_CONTEXT)
|
||||
_vp(0),
|
||||
_param(0),
|
||||
_first_context(NO_VALID_CONTEXT)
|
||||
{
|
||||
}
|
||||
|
||||
ViewMatrixExtractor(const ViewMatrixExtractor ©, const osg::CopyOp ©op)
|
||||
ViewMatrixExtractor(const ViewMatrixExtractor& copy, const osg::CopyOp& copyop)
|
||||
: osg::StateAttribute(copy, copyop),
|
||||
vp_(static_cast<osg::VertexProgram *>(copyop(copy.vp_.get()))),
|
||||
param_(copy.param_),
|
||||
first_context_(NO_VALID_CONTEXT)
|
||||
_vp(static_cast<osg::VertexProgram* >(copyop(copy._vp.get()))),
|
||||
_param(copy._param),
|
||||
_first_context(NO_VALID_CONTEXT)
|
||||
{
|
||||
}
|
||||
|
||||
ViewMatrixExtractor(osg::VertexProgram *vp, int param)
|
||||
ViewMatrixExtractor(osg::VertexProgram* vp, int param)
|
||||
: osg::StateAttribute(),
|
||||
vp_(vp),
|
||||
param_(param),
|
||||
first_context_(NO_VALID_CONTEXT)
|
||||
_vp(vp),
|
||||
_param(param),
|
||||
_first_context(NO_VALID_CONTEXT)
|
||||
{
|
||||
}
|
||||
|
||||
META_StateAttribute(osgFX, ViewMatrixExtractor, VIEWMATRIXEXTRACTOR);
|
||||
|
||||
int compare(const osg::StateAttribute &sa) const
|
||||
int compare(const osg::StateAttribute& sa) const
|
||||
{
|
||||
COMPARE_StateAttribute_Types(ViewMatrixExtractor, sa);
|
||||
if (vp_.get() != rhs.vp_.get()) return -1;
|
||||
if (param_ < rhs.param_) return -1;
|
||||
if (param_ > rhs.param_) return 1;
|
||||
if (_vp.get() != rhs._vp.get()) return -1;
|
||||
if (_param < rhs._param) return -1;
|
||||
if (_param > rhs._param) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void apply(osg::State &state) const
|
||||
void apply(osg::State& state) const
|
||||
{
|
||||
if (first_context_ == NO_VALID_CONTEXT) {
|
||||
first_context_ = state.getContextID();
|
||||
if (_first_context == NO_VALID_CONTEXT) {
|
||||
_first_context = state.getContextID();
|
||||
}
|
||||
if (state.getContextID() == first_context_) {
|
||||
if (vp_.valid()) {
|
||||
if (state.getContextID() == _first_context) {
|
||||
if (_vp.valid()) {
|
||||
osg::Matrix M = state.getInitialInverseViewMatrix();
|
||||
for (int i=0; i<4; ++i) {
|
||||
vp_->setProgramLocalParameter(param_+i, osg::Vec4(M(0, i), M(1, i), M(2, i), M(3, i)));
|
||||
_vp->setProgramLocalParameter(_param+i, osg::Vec4(M(0, i), M(1, i), M(2, i), M(3, i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
mutable osg::ref_ptr<osg::VertexProgram> vp_;
|
||||
int param_;
|
||||
mutable unsigned int first_context_;
|
||||
mutable osg::ref_ptr<osg::VertexProgram> _vp;
|
||||
int _param;
|
||||
mutable unsigned int _first_context;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -208,13 +208,13 @@ namespace
|
||||
class FullArbTechnique: public Technique {
|
||||
public:
|
||||
|
||||
FullArbTechnique(int lightnum, int diffuseunit, int normalunit, osg::Texture2D *diffuse_tex, osg::Texture2D *normal_tex)
|
||||
FullArbTechnique(int lightnum, int diffuseunit, int normalunit, osg::Texture2D* diffuse_tex, osg::Texture2D* normal_tex)
|
||||
: Technique(),
|
||||
lightnum_(lightnum),
|
||||
diffuseunit_(diffuseunit),
|
||||
normalunit_(normalunit),
|
||||
diffuse_tex_(diffuse_tex),
|
||||
normal_tex_(normal_tex)
|
||||
_lightnum(lightnum),
|
||||
_diffuse_unit(diffuseunit),
|
||||
_normal_unit(normalunit),
|
||||
_diffuse_tex(diffuse_tex),
|
||||
_normal_tex(normal_tex)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ namespace
|
||||
"Single-pass technique, requires ARB_vertex_program and ARB_fragment_program."
|
||||
);
|
||||
|
||||
void getRequiredExtensions(std::vector<std::string> &extensions) const
|
||||
void getRequiredExtensions(std::vector<std::string>& extensions) const
|
||||
{
|
||||
extensions.push_back("GL_ARB_vertex_program");
|
||||
extensions.push_back("GL_ARB_fragment_program");
|
||||
@@ -234,7 +234,7 @@ namespace
|
||||
void define_passes()
|
||||
{
|
||||
int freeunit;
|
||||
for (freeunit=0; freeunit==diffuseunit_||freeunit==normalunit_; ++freeunit) {}
|
||||
for (freeunit=0; freeunit==_diffuse_unit||freeunit==_normal_unit; ++freeunit) {}
|
||||
|
||||
// vertex program
|
||||
std::ostringstream vp_oss;
|
||||
@@ -247,8 +247,8 @@ namespace
|
||||
"ATTRIB v5 = vertex.attrib[15];"
|
||||
"ATTRIB v4 = vertex.attrib[7];"
|
||||
"ATTRIB v3 = vertex.attrib[6];"
|
||||
"ATTRIB v25 = vertex.texcoord[" << diffuseunit_ << "];"
|
||||
"ATTRIB v24 = vertex.texcoord[" << normalunit_ << "];"
|
||||
"ATTRIB v25 = vertex.texcoord[" << _diffuse_unit << "];"
|
||||
"ATTRIB v24 = vertex.texcoord[" << _normal_unit << "];"
|
||||
"ATTRIB v18 = vertex.normal;"
|
||||
"ATTRIB v16 = vertex.position;"
|
||||
"PARAM s259[4] = { state.matrix.mvp };"
|
||||
@@ -260,10 +260,10 @@ namespace
|
||||
"PARAM c0[4] = { program.local[0..3] };"
|
||||
" MOV result.texcoord[" << freeunit << "].xyz, s75.xyzx;"
|
||||
" MOV result.texcoord[" << freeunit << "].w, s4.x;"
|
||||
" MOV result.texcoord[" << normalunit_ << "].zw, s77.zwzw;"
|
||||
" MOV result.texcoord[" << normalunit_ << "].xy, v24;"
|
||||
" MOV result.texcoord[" << diffuseunit_ << "].zw, s77.xyxy;"
|
||||
" MOV result.texcoord[" << diffuseunit_ << "].xy, v25;"
|
||||
" MOV result.texcoord[" << _normal_unit << "].zw, s77.zwzw;"
|
||||
" MOV result.texcoord[" << _normal_unit << "].xy, v24;"
|
||||
" MOV result.texcoord[" << _diffuse_unit << "].zw, s77.xyxy;"
|
||||
" MOV result.texcoord[" << _diffuse_unit << "].xy, v25;"
|
||||
" MOV R5, c0[0];"
|
||||
" MUL R0, R5.y, s223[1];"
|
||||
" MAD R0, R5.x, s223[0], R0;"
|
||||
@@ -341,8 +341,8 @@ namespace
|
||||
"TEMP R0;"
|
||||
"TEMP R1;"
|
||||
"TEMP R2;"
|
||||
"TEX R0, fragment.texcoord[" << normalunit_ << "], texture[" << normalunit_ << "], 2D;"
|
||||
"TEX R1, fragment.texcoord[" << diffuseunit_ << "], texture[" << diffuseunit_ << "], 2D;"
|
||||
"TEX R0, fragment.texcoord[" << _normal_unit << "], texture[" << _normal_unit << "], 2D;"
|
||||
"TEX R1, fragment.texcoord[" << _diffuse_unit << "], texture[" << _diffuse_unit << "], 2D;"
|
||||
"ADD R0, R0, -c0.z;"
|
||||
"MUL R0.xyz, c0.y, R0;"
|
||||
"ADD R2.xyz, fragment.color.primary, -c0.z;"
|
||||
@@ -360,8 +360,8 @@ namespace
|
||||
"MUL R1.xyz, R1, R2;"
|
||||
"MOV_SAT R0.y, fragment.color.secondary.w;"
|
||||
"MUL R0.xyz, R0.y, R0.x;"
|
||||
"MOV R2.xy, fragment.texcoord[" << diffuseunit_ << "].zwzz;"
|
||||
"MOV R2.z, fragment.texcoord[" << normalunit_ << "].z;"
|
||||
"MOV R2.xy, fragment.texcoord[" << _diffuse_unit << "].zwzz;"
|
||||
"MOV R2.z, fragment.texcoord[" << _normal_unit << "].z;"
|
||||
"MUL R2.xyz, R0, R2;"
|
||||
"ADD R2.xyz, R1, R2;"
|
||||
"MOV result.color.xyz, R2;"
|
||||
@@ -380,23 +380,23 @@ namespace
|
||||
|
||||
ss->setAttributeAndModes(new ViewMatrixExtractor(vp.get(), 0), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
if (diffuse_tex_.valid()) {
|
||||
ss->setTextureAttributeAndModes(diffuseunit_, diffuse_tex_.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
if (_diffuse_tex.valid()) {
|
||||
ss->setTextureAttributeAndModes(_diffuse_unit, _diffuse_tex.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
if (normal_tex_.valid()) {
|
||||
ss->setTextureAttributeAndModes(normalunit_, normal_tex_.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
if (_normal_tex.valid()) {
|
||||
ss->setTextureAttributeAndModes(_normal_unit, _normal_tex.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
addPass(ss.get());
|
||||
}
|
||||
|
||||
private:
|
||||
int lightnum_;
|
||||
int diffuseunit_;
|
||||
int normalunit_;
|
||||
osg::ref_ptr<osg::Texture2D> diffuse_tex_;
|
||||
osg::ref_ptr<osg::Texture2D> normal_tex_;
|
||||
int _lightnum;
|
||||
int _diffuse_unit;
|
||||
int _normal_unit;
|
||||
osg::ref_ptr<osg::Texture2D> _diffuse_tex;
|
||||
osg::ref_ptr<osg::Texture2D> _normal_tex;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -409,32 +409,32 @@ namespace
|
||||
// component is required as well as a normal map texture.
|
||||
class ArbVpTechnique: public Technique {
|
||||
public:
|
||||
ArbVpTechnique(int lightnum, int diffuseunit, int normalunit, osg::Texture2D *diffuse_tex, osg::Texture2D *normal_tex)
|
||||
ArbVpTechnique(int lightnum, int diffuseunit, int normalunit, osg::Texture2D* diffuse_tex, osg::Texture2D* normal_tex)
|
||||
: Technique(),
|
||||
lightnum_(lightnum),
|
||||
diffuseunit_(diffuseunit),
|
||||
normalunit_(normalunit),
|
||||
diffuse_tex_(diffuse_tex),
|
||||
normal_tex_(normal_tex)
|
||||
_lightnum(lightnum),
|
||||
_diffuse_unit(diffuseunit),
|
||||
_normal_unit(normalunit),
|
||||
_diffuse_tex(diffuse_tex),
|
||||
_normal_tex(normal_tex)
|
||||
{
|
||||
}
|
||||
|
||||
META_Technique(
|
||||
"ArbVpTechnique",
|
||||
"Two-passes technique, requires ARB_vertex_program and ARB_texture_env_dot3."
|
||||
"Two-passes technique, requires ARB_vertex_program and ARB__textureenv_dot3."
|
||||
"Only diffuse lighting, no ambient, no specularity."
|
||||
);
|
||||
|
||||
void getRequiredExtensions(std::vector<std::string> &extensions) const
|
||||
void getRequiredExtensions(std::vector<std::string>& extensions) const
|
||||
{
|
||||
extensions.push_back("GL_ARB_vertex_program");
|
||||
extensions.push_back("GL_ARB_texture_env_dot3");
|
||||
extensions.push_back("GL_ARB__textureenv_dot3");
|
||||
}
|
||||
|
||||
void define_passes()
|
||||
{
|
||||
if (diffuseunit_ != (normalunit_ + 1)) {
|
||||
osg::notify(osg::WARN) << "Warning: osgFX::BumpMapping: this technique (ArbVpTechnique) requires that diffuse_unit == (normal_unit + 1). Effect may not show up properly.\n";
|
||||
if (_diffuse_unit != (_normal_unit + 1)) {
|
||||
osg::notify(osg::WARN) << "Warning: osgFX::BumpMapping: this technique (ArbVpTechnique) requires that _diffuse_unit == (_normal_unit + 1). Effect may not show up properly.\n";
|
||||
}
|
||||
|
||||
// first pass, diffuse bump
|
||||
@@ -448,15 +448,15 @@ namespace
|
||||
"ATTRIB v5 = vertex.attrib[15];"
|
||||
"ATTRIB v4 = vertex.attrib[7];"
|
||||
"ATTRIB v3 = vertex.attrib[6];"
|
||||
"ATTRIB v24 = vertex.texcoord[" << normalunit_ << "];"
|
||||
"ATTRIB v25 = vertex.texcoord[" << diffuseunit_ << "];"
|
||||
"ATTRIB v24 = vertex.texcoord[" << _normal_unit << "];"
|
||||
"ATTRIB v25 = vertex.texcoord[" << _diffuse_unit << "];"
|
||||
"ATTRIB v18 = vertex.normal;"
|
||||
"ATTRIB v16 = vertex.position;"
|
||||
"PARAM s259[4] = { state.matrix.mvp };"
|
||||
"PARAM s18 = state.light[" << lightnum_ << "].position;"
|
||||
"PARAM s18 = state.light[" << _lightnum << "].position;"
|
||||
"PARAM s223[4] = { state.matrix.modelview };"
|
||||
" MOV result.texcoord[" << diffuseunit_ << "].xy, v25;"
|
||||
" MOV result.texcoord[" << normalunit_ << "].xy, v24;"
|
||||
" MOV result.texcoord[" << _diffuse_unit << "].xy, v25;"
|
||||
" MOV result.texcoord[" << _normal_unit << "].xy, v24;"
|
||||
" DP3 R0.y, s223[0].xyzx, v3.xyzx;"
|
||||
" DP3 R0.z, s223[1].xyzx, v3.xyzx;"
|
||||
" DP3 R0.w, s223[2].xyzx, v3.xyzx;"
|
||||
@@ -482,23 +482,23 @@ namespace
|
||||
vp->setVertexProgram(vp_oss.str());
|
||||
ss->setAttributeAndModes(vp.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
if (diffuse_tex_.valid()) {
|
||||
ss->setTextureAttributeAndModes(diffuseunit_, diffuse_tex_.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
if (_diffuse_tex.valid()) {
|
||||
ss->setTextureAttributeAndModes(_diffuse_unit, _diffuse_tex.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
if (normal_tex_.valid()) {
|
||||
ss->setTextureAttributeAndModes(normalunit_, normal_tex_.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
if (_normal_tex.valid()) {
|
||||
ss->setTextureAttributeAndModes(_normal_unit, _normal_tex.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::TexEnvCombine> tec = new osg::TexEnvCombine;
|
||||
tec->setCombine_RGB(osg::TexEnvCombine::DOT3_RGB);
|
||||
tec->setSource0_RGB(osg::TexEnvCombine::PRIMARY_COLOR);
|
||||
tec->setSource1_RGB(osg::TexEnvCombine::TEXTURE);
|
||||
ss->setTextureAttributeAndModes(normalunit_, tec.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
ss->setTextureAttributeAndModes(_normal_unit, tec.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
osg::ref_ptr<osg::TexEnv> te = new osg::TexEnv;
|
||||
te->setMode(osg::TexEnv::MODULATE);
|
||||
ss->setTextureAttributeAndModes(diffuseunit_, te.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
ss->setTextureAttributeAndModes(_diffuse_unit, te.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
addPass(ss.get());
|
||||
}
|
||||
@@ -516,7 +516,7 @@ namespace
|
||||
"ATTRIB v18 = vertex.normal;"
|
||||
"ATTRIB v16 = vertex.position;"
|
||||
"PARAM s259[4] = { state.matrix.mvp };"
|
||||
"PARAM s18 = state.light[" << lightnum_ << "].position;"
|
||||
"PARAM s18 = state.light[" << _lightnum << "].position;"
|
||||
"PARAM s631[4] = { state.matrix.modelview.invtrans };"
|
||||
" DP4 R0.x, s631[0], v18;"
|
||||
" DP4 R0.y, s631[1], v18;"
|
||||
@@ -542,8 +542,8 @@ namespace
|
||||
bf->setFunction(osg::BlendFunc::DST_COLOR, osg::BlendFunc::ZERO);
|
||||
ss->setAttributeAndModes(bf.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
ss->setTextureMode(diffuseunit_, GL_TEXTURE_2D, osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
|
||||
ss->setTextureMode(normalunit_, GL_TEXTURE_2D, osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
|
||||
ss->setTextureMode(_diffuse_unit, GL_TEXTURE_2D, osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
|
||||
ss->setTextureMode(_normal_unit, GL_TEXTURE_2D, osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
|
||||
|
||||
addPass(ss.get());
|
||||
}
|
||||
@@ -551,11 +551,11 @@ namespace
|
||||
}
|
||||
|
||||
protected:
|
||||
int lightnum_;
|
||||
int diffuseunit_;
|
||||
int normalunit_;
|
||||
osg::ref_ptr<osg::Texture2D> diffuse_tex_;
|
||||
osg::ref_ptr<osg::Texture2D> normal_tex_;
|
||||
int _lightnum;
|
||||
int _diffuse_unit;
|
||||
int _normal_unit;
|
||||
osg::ref_ptr<osg::Texture2D> _diffuse_tex;
|
||||
osg::ref_ptr<osg::Texture2D> _normal_tex;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -563,33 +563,33 @@ namespace
|
||||
|
||||
BumpMapping::BumpMapping()
|
||||
: Effect(),
|
||||
lightnum_(0),
|
||||
diffuseunit_(1),
|
||||
normalunit_(0)
|
||||
_lightnum(0),
|
||||
_diffuse_unit(1),
|
||||
_normal_unit(0)
|
||||
{
|
||||
}
|
||||
|
||||
BumpMapping::BumpMapping(const BumpMapping ©, const osg::CopyOp ©op)
|
||||
BumpMapping::BumpMapping(const BumpMapping& copy, const osg::CopyOp& copyop)
|
||||
: Effect(copy, copyop),
|
||||
lightnum_(copy.lightnum_),
|
||||
diffuseunit_(copy.diffuseunit_),
|
||||
normalunit_(copy.normalunit_),
|
||||
diffuse_tex_(static_cast<osg::Texture2D *>(copyop(copy.diffuse_tex_.get()))),
|
||||
normal_tex_(static_cast<osg::Texture2D *>(copyop(copy.normal_tex_.get())))
|
||||
_lightnum(copy._lightnum),
|
||||
_diffuse_unit(copy._diffuse_unit),
|
||||
_normal_unit(copy._normal_unit),
|
||||
_diffuse_tex(static_cast<osg::Texture2D* >(copyop(copy._diffuse_tex.get()))),
|
||||
_normal_tex(static_cast<osg::Texture2D* >(copyop(copy._normal_tex.get())))
|
||||
{
|
||||
}
|
||||
|
||||
bool BumpMapping::define_techniques()
|
||||
{
|
||||
addTechnique(new FullArbTechnique(lightnum_, diffuseunit_, normalunit_, diffuse_tex_.get(), normal_tex_.get()));
|
||||
addTechnique(new ArbVpTechnique(lightnum_, diffuseunit_, normalunit_, diffuse_tex_.get(), normal_tex_.get()));
|
||||
addTechnique(new FullArbTechnique(_lightnum, _diffuse_unit, _normal_unit, _diffuse_tex.get(), _normal_tex.get()));
|
||||
addTechnique(new ArbVpTechnique(_lightnum, _diffuse_unit, _normal_unit, _diffuse_tex.get(), _normal_tex.get()));
|
||||
return true;
|
||||
}
|
||||
|
||||
void BumpMapping::prepareGeometry(osg::Geometry *geo)
|
||||
void BumpMapping::prepareGeometry(osg::Geometry* geo)
|
||||
{
|
||||
osg::ref_ptr<osgUtil::TangentSpaceGenerator> tsg = new osgUtil::TangentSpaceGenerator;
|
||||
tsg->generate(geo, normalunit_);
|
||||
tsg->generate(geo, _normal_unit);
|
||||
if (!geo->getVertexAttribArray(6))
|
||||
geo->setVertexAttribData(6, osg::Geometry::ArrayData(tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX,GL_FALSE));
|
||||
if (!geo->getVertexAttribArray(7))
|
||||
@@ -598,7 +598,7 @@ void BumpMapping::prepareGeometry(osg::Geometry *geo)
|
||||
geo->setVertexAttribData(15, osg::Geometry::ArrayData(tsg->getNormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE));
|
||||
}
|
||||
|
||||
void BumpMapping::prepareNode(osg::Node *node)
|
||||
void BumpMapping::prepareNode(osg::Node* node)
|
||||
{
|
||||
osg::ref_ptr<TsgVisitor> tv = new TsgVisitor(this);
|
||||
node->accept(*tv.get());
|
||||
@@ -613,30 +613,30 @@ void BumpMapping::prepareChildren()
|
||||
void BumpMapping::setUpDemo()
|
||||
{
|
||||
// generate texture coordinates
|
||||
TexCoordGenerator tcg(diffuseunit_, normalunit_);
|
||||
TexCoordGenerator tcg(_diffuse_unit, _normal_unit);
|
||||
for (unsigned i=0; i<getNumChildren(); ++i)
|
||||
getChild(i)->accept(tcg);
|
||||
|
||||
// set up diffuse texture
|
||||
if (!diffuse_tex_.valid()) {
|
||||
diffuse_tex_ = new osg::Texture2D;
|
||||
diffuse_tex_->setImage(osgDB::readImageFile("Images/whitemetal_diffuse.jpg"));
|
||||
diffuse_tex_->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
|
||||
diffuse_tex_->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
|
||||
diffuse_tex_->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
|
||||
diffuse_tex_->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
|
||||
diffuse_tex_->setMaxAnisotropy(8);
|
||||
if (!_diffuse_tex.valid()) {
|
||||
_diffuse_tex = new osg::Texture2D;
|
||||
_diffuse_tex->setImage(osgDB::readImageFile("Images/whitemetal_diffuse.jpg"));
|
||||
_diffuse_tex->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
|
||||
_diffuse_tex->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
|
||||
_diffuse_tex->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
|
||||
_diffuse_tex->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
|
||||
_diffuse_tex->setMaxAnisotropy(8);
|
||||
}
|
||||
|
||||
// set up normal map texture
|
||||
if (!normal_tex_.valid()) {
|
||||
normal_tex_ = new osg::Texture2D;
|
||||
normal_tex_->setImage(osgDB::readImageFile("Images/whitemetal_normal.jpg"));
|
||||
normal_tex_->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
|
||||
normal_tex_->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
|
||||
normal_tex_->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
|
||||
normal_tex_->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
|
||||
normal_tex_->setMaxAnisotropy(8);
|
||||
if (!_normal_tex.valid()) {
|
||||
_normal_tex = new osg::Texture2D;
|
||||
_normal_tex->setImage(osgDB::readImageFile("Images/whitemetal_normal.jpg"));
|
||||
_normal_tex->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
|
||||
_normal_tex->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
|
||||
_normal_tex->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
|
||||
_normal_tex->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
|
||||
_normal_tex->setMaxAnisotropy(8);
|
||||
}
|
||||
|
||||
// generate tangent-space basis vector
|
||||
|
||||
@@ -21,7 +21,7 @@ using namespace osgFX;
|
||||
namespace
|
||||
{
|
||||
|
||||
osg::Image *create_sharp_lighting_map(int levels = 4, int texture_size = 16)
|
||||
osg::Image* create_sharp_lighting_map(int levels = 4, int texture_size = 16)
|
||||
{
|
||||
osg::ref_ptr<osg::Image> image = new osg::Image;
|
||||
image->setImage(texture_size, 1, 1, 4, GL_RGBA, GL_UNSIGNED_BYTE, new unsigned char[4*texture_size], osg::Image::USE_NEW_DELETE);
|
||||
@@ -48,10 +48,10 @@ namespace
|
||||
// default technique class
|
||||
class DefaultTechnique: public Technique {
|
||||
public:
|
||||
DefaultTechnique(osg::Material *wf_mat, osg::LineWidth *wf_lw, int lightnum)
|
||||
: Technique(), wf_mat_(wf_mat), wf_lw_(wf_lw), lightnum_(lightnum) {}
|
||||
DefaultTechnique(osg::Material* wf_mat, osg::LineWidth *wf_lw, int lightnum)
|
||||
: Technique(), _wf_mat(wf_mat), _wf_lw(wf_lw), _lightnum(lightnum) {}
|
||||
|
||||
void getRequiredExtensions(std::vector<std::string> &extensions) const
|
||||
void getRequiredExtensions(std::vector<std::string>& extensions) const
|
||||
{
|
||||
extensions.push_back("GL_ARB_vertex_program");
|
||||
}
|
||||
@@ -69,8 +69,8 @@ namespace
|
||||
"PARAM c0 = { 0, 0, 0, 0 };"
|
||||
"TEMP R0, R1;"
|
||||
"ATTRIB v18 = vertex.normal;"
|
||||
"PARAM s18 = state.light[" << lightnum_ << "].position;"
|
||||
"PARAM s16 = state.light[" << lightnum_ << "].diffuse;"
|
||||
"PARAM s18 = state.light[" << _lightnum << "].position;"
|
||||
"PARAM s16 = state.light[" << _lightnum << "].diffuse;"
|
||||
"PARAM s1 = state.material.diffuse;"
|
||||
"PARAM s631[4] = { state.matrix.modelview.invtrans };"
|
||||
"MOV R0, s1;"
|
||||
@@ -123,15 +123,15 @@ namespace
|
||||
cf->setMode(osg::CullFace::FRONT);
|
||||
ss->setAttributeAndModes(cf.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
wf_lw_->setWidth(2);
|
||||
ss->setAttributeAndModes(wf_lw_.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
|
||||
_wf_lw->setWidth(2);
|
||||
ss->setAttributeAndModes(_wf_lw.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
|
||||
|
||||
wf_mat_->setColorMode(osg::Material::OFF);
|
||||
wf_mat_->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
wf_mat_->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
wf_mat_->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
wf_mat_->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
ss->setAttributeAndModes(wf_mat_.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
_wf_mat->setColorMode(osg::Material::OFF);
|
||||
_wf_mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
_wf_mat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
_wf_mat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
_wf_mat->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
ss->setAttributeAndModes(_wf_mat.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
ss->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
ss->setTextureMode(0, GL_TEXTURE_1D, osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
|
||||
@@ -143,9 +143,9 @@ namespace
|
||||
}
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osg::Material> wf_mat_;
|
||||
osg::ref_ptr<osg::LineWidth> wf_lw_;
|
||||
int lightnum_;
|
||||
osg::ref_ptr<osg::Material> _wf_mat;
|
||||
osg::ref_ptr<osg::LineWidth> _wf_lw;
|
||||
int _lightnum;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -161,10 +161,10 @@ namespace
|
||||
{
|
||||
class OGLSL_Technique : public Technique {
|
||||
public:
|
||||
OGLSL_Technique(osg::Material *wf_mat, osg::LineWidth *wf_lw, int lightnum)
|
||||
: Technique(), wf_mat_(wf_mat), wf_lw_(wf_lw), lightnum_(lightnum) {}
|
||||
OGLSL_Technique(osg::Material* wf_mat, osg::LineWidth *wf_lw, int lightnum)
|
||||
: Technique(), _wf_mat(wf_mat), _wf_lw(wf_lw), _lightnum(lightnum) {}
|
||||
|
||||
void getRequiredExtensions(std::vector<std::string> &extensions) const
|
||||
void getRequiredExtensions(std::vector<std::string>& extensions) const
|
||||
{
|
||||
extensions.push_back( "GL_ARB_shader_objects" );
|
||||
extensions.push_back( "GL_ARB_vertex_shader" );
|
||||
@@ -236,15 +236,15 @@ namespace
|
||||
cf->setMode(osg::CullFace::FRONT);
|
||||
ss->setAttributeAndModes(cf.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
wf_lw_->setWidth(2);
|
||||
ss->setAttributeAndModes(wf_lw_.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
|
||||
_wf_lw->setWidth(2);
|
||||
ss->setAttributeAndModes(_wf_lw.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
|
||||
|
||||
wf_mat_->setColorMode(osg::Material::OFF);
|
||||
wf_mat_->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
wf_mat_->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
wf_mat_->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
wf_mat_->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
ss->setAttributeAndModes(wf_mat_.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
_wf_mat->setColorMode(osg::Material::OFF);
|
||||
_wf_mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
_wf_mat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
_wf_mat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
_wf_mat->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
|
||||
ss->setAttributeAndModes(_wf_mat.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
ss->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
ss->setTextureMode(0, GL_TEXTURE_1D, osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
|
||||
@@ -256,9 +256,9 @@ namespace
|
||||
}
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osg::Material> wf_mat_;
|
||||
osg::ref_ptr<osg::LineWidth> wf_lw_;
|
||||
int lightnum_;
|
||||
osg::ref_ptr<osg::Material> _wf_mat;
|
||||
osg::ref_ptr<osg::LineWidth> _wf_lw;
|
||||
int _lightnum;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -267,23 +267,23 @@ namespace
|
||||
|
||||
Cartoon::Cartoon()
|
||||
: Effect(),
|
||||
wf_mat_(new osg::Material),
|
||||
wf_lw_(new osg::LineWidth),
|
||||
lightnum_(0)
|
||||
_wf_mat(new osg::Material),
|
||||
_wf_lw(new osg::LineWidth),
|
||||
_lightnum(0)
|
||||
{
|
||||
}
|
||||
|
||||
Cartoon::Cartoon(const Cartoon ©, const osg::CopyOp ©op)
|
||||
Cartoon::Cartoon(const Cartoon& copy, const osg::CopyOp& copyop)
|
||||
: Effect(copy, copyop),
|
||||
wf_mat_(static_cast<osg::Material *>(copyop(copy.wf_mat_.get()))),
|
||||
wf_lw_(static_cast<osg::LineWidth *>(copyop(copy.wf_lw_.get()))),
|
||||
lightnum_(copy.lightnum_)
|
||||
_wf_mat(static_cast<osg::Material* >(copyop(copy._wf_mat.get()))),
|
||||
_wf_lw(static_cast<osg::LineWidth *>(copyop(copy._wf_lw.get()))),
|
||||
_lightnum(copy._lightnum)
|
||||
{
|
||||
}
|
||||
|
||||
bool Cartoon::define_techniques()
|
||||
{
|
||||
addTechnique(new DefaultTechnique(wf_mat_.get(), wf_lw_.get(), lightnum_));
|
||||
addTechnique(new OGLSL_Technique(wf_mat_.get(), wf_lw_.get(), lightnum_));
|
||||
addTechnique(new DefaultTechnique(_wf_mat.get(), _wf_lw.get(), _lightnum));
|
||||
addTechnique(new OGLSL_Technique(_wf_mat.get(), _wf_lw.get(), _lightnum));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -12,18 +12,18 @@ using namespace osgFX;
|
||||
|
||||
Effect::Effect()
|
||||
: osg::Group(),
|
||||
enabled_(true),
|
||||
global_sel_tech_(AUTO_DETECT),
|
||||
techs_defined_(false)
|
||||
_enabled(true),
|
||||
_global_sel_tech(AUTO_DETECT),
|
||||
_techs_defined(false)
|
||||
{
|
||||
build_dummy_node();
|
||||
}
|
||||
|
||||
Effect::Effect(const Effect ©, const osg::CopyOp ©op)
|
||||
Effect::Effect(const Effect& copy, const osg::CopyOp& copyop)
|
||||
: osg::Group(copy, copyop),
|
||||
enabled_(copy.enabled_),
|
||||
global_sel_tech_(copy.global_sel_tech_),
|
||||
techs_defined_(false)
|
||||
_enabled(copy._enabled),
|
||||
_global_sel_tech(copy._global_sel_tech),
|
||||
_techs_defined(false)
|
||||
{
|
||||
build_dummy_node();
|
||||
}
|
||||
@@ -32,8 +32,8 @@ Effect::~Effect()
|
||||
{
|
||||
// disable the validator for safety, so it won't try to access us
|
||||
// even if it stays alive for some reason
|
||||
if (dummy_for_validation_.valid()) {
|
||||
osg::StateSet *ss = dummy_for_validation_->getStateSet();
|
||||
if (_dummy_for_validation.valid()) {
|
||||
osg::StateSet* ss = _dummy_for_validation->getStateSet();
|
||||
if (ss) {
|
||||
Validator *validator = dynamic_cast<Validator *>(ss->getAttribute(Validator::VALIDATOR));
|
||||
if (validator) {
|
||||
@@ -43,37 +43,37 @@ Effect::~Effect()
|
||||
}
|
||||
}
|
||||
|
||||
void Effect::traverse(osg::NodeVisitor &nv)
|
||||
void Effect::traverse(osg::NodeVisitor& nv)
|
||||
{
|
||||
// if this effect is not enabled, then go for default traversal
|
||||
if (!enabled_) {
|
||||
if (!_enabled) {
|
||||
inherited_traverse(nv);
|
||||
return;
|
||||
}
|
||||
|
||||
// ensure that at least one technique is defined
|
||||
if (!techs_defined_) {
|
||||
if (!_techs_defined) {
|
||||
|
||||
// clear existing techniques
|
||||
techs_.clear();
|
||||
_techs.clear();
|
||||
|
||||
// clear technique selection indices
|
||||
sel_tech_.clear();
|
||||
_sel_tech.clear();
|
||||
|
||||
// clear technique selection flags
|
||||
tech_selected_.clear();
|
||||
_tech_selected.clear();
|
||||
|
||||
// define new techniques
|
||||
techs_defined_ = define_techniques();
|
||||
_techs_defined = define_techniques();
|
||||
|
||||
// check for errors, return on failure
|
||||
if (!techs_defined_) {
|
||||
if (!_techs_defined) {
|
||||
osg::notify(osg::WARN) << "Warning: osgFX::Effect: could not define techniques for effect " << className() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// ensure that at least one technique has been defined
|
||||
if (techs_.empty()) {
|
||||
if (_techs.empty()) {
|
||||
osg::notify(osg::WARN) << "Warning: osgFX::Effect: no techniques defined for effect " << className() << std::endl;
|
||||
return;
|
||||
}
|
||||
@@ -83,12 +83,12 @@ void Effect::traverse(osg::NodeVisitor &nv)
|
||||
|
||||
// if the selection mode is set to AUTO_DETECT then we have to
|
||||
// choose the active technique!
|
||||
if (global_sel_tech_ == AUTO_DETECT) {
|
||||
if (_global_sel_tech == AUTO_DETECT) {
|
||||
|
||||
// test whether at least one technique has been selected
|
||||
bool none_selected = true;
|
||||
for (unsigned i=0; i<tech_selected_.size(); ++i) {
|
||||
if (tech_selected_[i] != 0) {
|
||||
for (unsigned i=0; i<_tech_selected.size(); ++i) {
|
||||
if (_tech_selected[i] != 0) {
|
||||
none_selected = false;
|
||||
break;
|
||||
}
|
||||
@@ -97,29 +97,29 @@ void Effect::traverse(osg::NodeVisitor &nv)
|
||||
// no techniques selected, traverse a dummy node that
|
||||
// contains the Validator (it will select a technique)
|
||||
if (none_selected) {
|
||||
dummy_for_validation_->accept(nv);
|
||||
_dummy_for_validation->accept(nv);
|
||||
}
|
||||
|
||||
// find the highest priority technique that could be validated
|
||||
// in all active rendering contexts
|
||||
int max_index = -1;
|
||||
for (unsigned j=0; j<sel_tech_.size(); ++j) {
|
||||
if (tech_selected_[j] != 0) {
|
||||
if (sel_tech_[j] > max_index) {
|
||||
max_index = sel_tech_[j];
|
||||
for (unsigned j=0; j<_sel_tech.size(); ++j) {
|
||||
if (_tech_selected[j] != 0) {
|
||||
if (_sel_tech[j] > max_index) {
|
||||
max_index = _sel_tech[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// found a valid technique?
|
||||
if (max_index >= 0) {
|
||||
tech = techs_[max_index].get();
|
||||
tech = _techs[max_index].get();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// the active technique was selected manually
|
||||
tech = techs_[global_sel_tech_].get();
|
||||
tech = _techs[_global_sel_tech].get();
|
||||
}
|
||||
|
||||
// if we could find an active technique, then continue with traversal,
|
||||
@@ -137,8 +137,8 @@ void Effect::traverse(osg::NodeVisitor &nv)
|
||||
|
||||
void Effect::build_dummy_node()
|
||||
{
|
||||
dummy_for_validation_ = new osg::Geode;
|
||||
_dummy_for_validation = new osg::Geode;
|
||||
osg::ref_ptr<osg::Geometry> geo = new osg::Geometry;
|
||||
dummy_for_validation_->addDrawable(geo.get());
|
||||
dummy_for_validation_->getOrCreateStateSet()->setAttribute(new Validator(this));
|
||||
_dummy_for_validation->addDrawable(geo.get());
|
||||
_dummy_for_validation->getOrCreateStateSet()->setAttribute(new Validator(this));
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
using namespace osgFX;
|
||||
|
||||
|
||||
Registry *Registry::instance()
|
||||
Registry* Registry::instance()
|
||||
{
|
||||
static osg::ref_ptr<Registry> s_instance = new Registry;
|
||||
return s_instance.get();
|
||||
|
||||
@@ -21,10 +21,10 @@ namespace
|
||||
// default technique class
|
||||
class DefaultTechnique: public Technique {
|
||||
public:
|
||||
DefaultTechnique(osg::Material *wf_mat, osg::LineWidth *wf_lw)
|
||||
: Technique(), wf_mat_(wf_mat), wf_lw_(wf_lw) {}
|
||||
DefaultTechnique(osg::Material* wf_mat, osg::LineWidth* wf_lw)
|
||||
: Technique(), _wf_mat(wf_mat), _wf_lw(wf_lw) {}
|
||||
|
||||
bool validate(osg::State &) const
|
||||
bool validate(osg::State& ) const
|
||||
{
|
||||
return strncmp((const char*)glGetString(GL_VERSION), "1.1", 3) >= 0;
|
||||
}
|
||||
@@ -53,9 +53,9 @@ namespace
|
||||
polymode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
|
||||
ss->setAttributeAndModes(polymode.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
ss->setAttributeAndModes(wf_lw_.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
ss->setAttributeAndModes(_wf_lw.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
ss->setAttributeAndModes(wf_mat_.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
ss->setAttributeAndModes(_wf_mat.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
ss->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
ss->setTextureMode(0, GL_TEXTURE_1D, osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
|
||||
@@ -66,35 +66,35 @@ namespace
|
||||
}
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osg::Material> wf_mat_;
|
||||
osg::ref_ptr<osg::LineWidth> wf_lw_;
|
||||
osg::ref_ptr<osg::Material> _wf_mat;
|
||||
osg::ref_ptr<osg::LineWidth> _wf_lw;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Scribe::Scribe()
|
||||
: Effect(),
|
||||
wf_mat_(new osg::Material),
|
||||
wf_lw_(new osg::LineWidth)
|
||||
_wf_mat(new osg::Material),
|
||||
_wf_lw(new osg::LineWidth)
|
||||
{
|
||||
wf_lw_->setWidth(1.0f);
|
||||
_wf_lw->setWidth(1.0f);
|
||||
|
||||
wf_mat_->setColorMode(osg::Material::OFF);
|
||||
wf_mat_->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
wf_mat_->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
wf_mat_->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
wf_mat_->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
_wf_mat->setColorMode(osg::Material::OFF);
|
||||
_wf_mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
_wf_mat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
_wf_mat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
_wf_mat->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
}
|
||||
|
||||
Scribe::Scribe(const Scribe ©, const osg::CopyOp ©op)
|
||||
Scribe::Scribe(const Scribe& copy, const osg::CopyOp& copyop)
|
||||
: Effect(copy, copyop),
|
||||
wf_mat_(static_cast<osg::Material *>(copyop(copy.wf_mat_.get()))),
|
||||
wf_lw_(static_cast<osg::LineWidth *>(copyop(copy.wf_lw_.get())))
|
||||
_wf_mat(static_cast<osg::Material*>(copyop(copy._wf_mat.get()))),
|
||||
_wf_lw(static_cast<osg::LineWidth*>(copyop(copy._wf_lw.get())))
|
||||
{
|
||||
}
|
||||
|
||||
bool Scribe::define_techniques()
|
||||
{
|
||||
addTechnique(new DefaultTechnique(wf_mat_.get(), wf_lw_.get()));
|
||||
addTechnique(new DefaultTechnique(_wf_mat.get(), _wf_lw.get()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -17,22 +17,22 @@ namespace
|
||||
public:
|
||||
AutoTextureMatrix()
|
||||
: osg::StateAttribute(),
|
||||
lightnum_(0),
|
||||
active_(false)
|
||||
_lightnum(0),
|
||||
_active(false)
|
||||
{
|
||||
}
|
||||
|
||||
AutoTextureMatrix(const AutoTextureMatrix ©, const osg::CopyOp ©op)
|
||||
AutoTextureMatrix(const AutoTextureMatrix& copy, const osg::CopyOp& copyop)
|
||||
: osg::StateAttribute(copy, copyop),
|
||||
lightnum_(copy.lightnum_),
|
||||
active_(copy.active_)
|
||||
_lightnum(copy._lightnum),
|
||||
_active(copy._active)
|
||||
{
|
||||
}
|
||||
|
||||
AutoTextureMatrix(int lightnum, bool active = true)
|
||||
: osg::StateAttribute(),
|
||||
lightnum_(lightnum),
|
||||
active_(active)
|
||||
_lightnum(lightnum),
|
||||
_active(active)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -43,23 +43,23 @@ namespace
|
||||
int compare(const osg::StateAttribute &sa) const
|
||||
{
|
||||
COMPARE_StateAttribute_Types(AutoTextureMatrix, sa);
|
||||
if (lightnum_ < rhs.lightnum_) return -1;
|
||||
if (lightnum_ > rhs.lightnum_) return 1;
|
||||
if (_lightnum < rhs._lightnum) return -1;
|
||||
if (_lightnum > rhs._lightnum) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void apply(osg::State &state) const
|
||||
void apply(osg::State& state) const
|
||||
{
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
|
||||
if (active_) {
|
||||
if (_active) {
|
||||
osg::Matrix M = state.getInitialViewMatrix();
|
||||
M(3, 0) = 0; M(3, 1) = 0; M(3, 2) = 0;
|
||||
M(3, 3) = 1; M(0, 3) = 0; M(1, 3) = 0;
|
||||
M(2, 3) = 0;
|
||||
|
||||
osg::Vec4 lightvec;
|
||||
glGetLightfv(GL_LIGHT0+lightnum_, GL_POSITION, lightvec._v);
|
||||
glGetLightfv(GL_LIGHT0+_lightnum, GL_POSITION, lightvec._v);
|
||||
|
||||
osg::Vec3 eye_light_ref = osg::Vec3(0, 0, 1) * M;
|
||||
|
||||
@@ -77,8 +77,8 @@ namespace
|
||||
}
|
||||
|
||||
private:
|
||||
int lightnum_;
|
||||
bool active_;
|
||||
int _lightnum;
|
||||
bool _active;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -91,21 +91,21 @@ namespace
|
||||
class DefaultTechnique: public Technique {
|
||||
public:
|
||||
|
||||
DefaultTechnique(int lightnum, int unit, const osg::Vec4 &color, float sexp)
|
||||
DefaultTechnique(int lightnum, int unit, const osg::Vec4& color, float sexp)
|
||||
: Technique(),
|
||||
lightnum_(lightnum),
|
||||
unit_(unit),
|
||||
color_(color),
|
||||
sexp_(sexp)
|
||||
_lightnum(lightnum),
|
||||
_unit(unit),
|
||||
_color(color),
|
||||
_sexp(sexp)
|
||||
{
|
||||
}
|
||||
|
||||
void getRequiredExtensions(std::vector<std::string> &extensions)
|
||||
void getRequiredExtensions(std::vector<std::string>& extensions)
|
||||
{
|
||||
extensions.push_back("GL_ARB_texture_env_add");
|
||||
}
|
||||
|
||||
bool validate(osg::State &state) const
|
||||
bool validate(osg::State& state) const
|
||||
{
|
||||
if (!Technique::validate(state)) return false;
|
||||
|
||||
@@ -123,9 +123,9 @@ namespace
|
||||
{
|
||||
osg::ref_ptr<osg::StateSet> ss = new osg::StateSet;
|
||||
|
||||
ss->setTextureAttributeAndModes(unit_, new AutoTextureMatrix(lightnum_), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
ss->setTextureAttributeAndModes(_unit, new AutoTextureMatrix(_lightnum), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
osg::ref_ptr<osgUtil::HighlightMapGenerator> hmg = new osgUtil::HighlightMapGenerator(osg::Vec3(0, 0, -1), color_, sexp_);
|
||||
osg::ref_ptr<osgUtil::HighlightMapGenerator> hmg = new osgUtil::HighlightMapGenerator(osg::Vec3(0, 0, -1), _color, _sexp);
|
||||
hmg->generateMap(false);
|
||||
|
||||
osg::ref_ptr<osg::TextureCubeMap> texture = new osg::TextureCubeMap;
|
||||
@@ -138,24 +138,24 @@ namespace
|
||||
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
||||
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
||||
texture->setWrap(osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_EDGE);
|
||||
ss->setTextureAttributeAndModes(unit_, texture.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
ss->setTextureAttributeAndModes(_unit, texture.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
osg::ref_ptr<osg::TexGen> texgen = new osg::TexGen;
|
||||
texgen->setMode(osg::TexGen::REFLECTION_MAP);
|
||||
ss->setTextureAttributeAndModes(unit_, texgen.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
ss->setTextureAttributeAndModes(_unit, texgen.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
osg::ref_ptr<osg::TexEnv> texenv = new osg::TexEnv;
|
||||
texenv->setMode(osg::TexEnv::ADD);
|
||||
ss->setTextureAttributeAndModes(unit_, texenv.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
ss->setTextureAttributeAndModes(_unit, texenv.get(), osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||
|
||||
addPass(ss.get());
|
||||
}
|
||||
|
||||
private:
|
||||
int lightnum_;
|
||||
int unit_;
|
||||
osg::Vec4 color_;
|
||||
float sexp_;
|
||||
int _lightnum;
|
||||
int _unit;
|
||||
osg::Vec4 _color;
|
||||
float _sexp;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -163,24 +163,24 @@ namespace
|
||||
|
||||
SpecularHighlights::SpecularHighlights()
|
||||
: Effect(),
|
||||
lightnum_(0),
|
||||
unit_(0),
|
||||
color_(1, 1, 1, 1),
|
||||
sexp_(16)
|
||||
_lightnum(0),
|
||||
_unit(0),
|
||||
_color(1, 1, 1, 1),
|
||||
_sexp(16)
|
||||
{
|
||||
}
|
||||
|
||||
SpecularHighlights::SpecularHighlights(const SpecularHighlights ©, const osg::CopyOp ©op)
|
||||
SpecularHighlights::SpecularHighlights(const SpecularHighlights& copy, const osg::CopyOp& copyop)
|
||||
: Effect(copy, copyop),
|
||||
lightnum_(copy.lightnum_),
|
||||
unit_(copy.unit_),
|
||||
color_(copy.color_),
|
||||
sexp_(copy.sexp_)
|
||||
_lightnum(copy._lightnum),
|
||||
_unit(copy._unit),
|
||||
_color(copy._color),
|
||||
_sexp(copy._sexp)
|
||||
{
|
||||
}
|
||||
|
||||
bool SpecularHighlights::define_techniques()
|
||||
{
|
||||
addTechnique(new DefaultTechnique(lightnum_, unit_, color_, sexp_));
|
||||
addTechnique(new DefaultTechnique(_lightnum, _unit, _color, _sexp));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ Technique::Technique()
|
||||
{
|
||||
}
|
||||
|
||||
void Technique::addPass(osg::StateSet *ss)
|
||||
void Technique::addPass(osg::StateSet* ss)
|
||||
{
|
||||
if (ss) {
|
||||
passes_.push_back(ss);
|
||||
ss->setRenderBinDetails(static_cast<int>(passes_.size()), "RenderBin");
|
||||
_passes.push_back(ss);
|
||||
ss->setRenderBinDetails(static_cast<int>(_passes.size()), "RenderBin");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,10 +34,10 @@ bool Technique::validate(osg::State& state) const
|
||||
return true;
|
||||
}
|
||||
|
||||
void Technique::traverse_implementation(osg::NodeVisitor &nv, Effect *fx)
|
||||
void Technique::traverse_implementation(osg::NodeVisitor& nv, Effect* fx)
|
||||
{
|
||||
// define passes if necessary
|
||||
if (passes_.empty()) {
|
||||
if (_passes.empty()) {
|
||||
define_passes();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ void Technique::traverse_implementation(osg::NodeVisitor &nv, Effect *fx)
|
||||
|
||||
// push the i-th pass' StateSet if necessary
|
||||
if (cv) {
|
||||
cv->pushStateSet(passes_[i].get());
|
||||
cv->pushStateSet(_passes[i].get());
|
||||
}
|
||||
|
||||
// traverse the override node if defined, otherwise
|
||||
|
||||
@@ -7,38 +7,38 @@ using namespace osgFX;
|
||||
|
||||
Validator::Validator()
|
||||
: osg::StateAttribute(),
|
||||
effect_(0)
|
||||
_effect(0)
|
||||
{
|
||||
}
|
||||
|
||||
Validator::Validator(Effect *effect)
|
||||
Validator::Validator(Effect* effect)
|
||||
: osg::StateAttribute(),
|
||||
effect_(effect)
|
||||
_effect(effect)
|
||||
{
|
||||
}
|
||||
|
||||
Validator::Validator(const Validator ©, const osg::CopyOp ©op)
|
||||
Validator::Validator(const Validator& copy, const osg::CopyOp& copyop)
|
||||
: osg::StateAttribute(copy, copyop),
|
||||
effect_(static_cast<Effect *>(copyop(copy.effect_)))
|
||||
_effect(static_cast<Effect*>(copyop(copy._effect)))
|
||||
{
|
||||
}
|
||||
|
||||
void Validator::compileGLObjects(osg::State &state) const
|
||||
void Validator::compileGLObjects(osg::State& state) const
|
||||
{
|
||||
apply(state);
|
||||
}
|
||||
|
||||
void Validator::apply(osg::State &state) const
|
||||
void Validator::apply(osg::State& state) const
|
||||
{
|
||||
if (!effect_) return;
|
||||
if (!_effect) return;
|
||||
|
||||
if (effect_->tech_selected_[state.getContextID()] == 0) {
|
||||
if (_effect->_tech_selected[state.getContextID()] == 0) {
|
||||
Effect::Technique_list::iterator i;
|
||||
int j = 0;
|
||||
for (i=effect_->techs_.begin(); i!=effect_->techs_.end(); ++i, ++j) {
|
||||
for (i=_effect->_techs.begin(); i!=_effect->_techs.end(); ++i, ++j) {
|
||||
if ((*i)->validate(state)) {
|
||||
effect_->sel_tech_[state.getContextID()] = j;
|
||||
effect_->tech_selected_[state.getContextID()] = 1;
|
||||
_effect->_sel_tech[state.getContextID()] = j;
|
||||
_effect->_tech_selected[state.getContextID()] = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user