Moved to standard OSG coding style.

This commit is contained in:
Robert Osfield
2005-04-29 06:32:13 +00:00
parent 178a0b5c7e
commit 98126f1706
19 changed files with 528 additions and 527 deletions

View File

@@ -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 &copy, const osg::CopyOp &copyop)
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 &copy, const osg::CopyOp &copyop)
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;
}

View File

@@ -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 &copy, const osg::CopyOp &copyop)
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 &copy, const osg::CopyOp &copyop)
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

View File

@@ -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 &copy, const osg::CopyOp &copyop)
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;
}

View File

@@ -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 &copy, const osg::CopyOp &copyop)
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));
}

View File

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

View File

@@ -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 &copy, const osg::CopyOp &copyop)
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;
}

View File

@@ -17,22 +17,22 @@ namespace
public:
AutoTextureMatrix()
: osg::StateAttribute(),
lightnum_(0),
active_(false)
_lightnum(0),
_active(false)
{
}
AutoTextureMatrix(const AutoTextureMatrix &copy, const osg::CopyOp &copyop)
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 &copy, const osg::CopyOp &copyop)
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;
}

View File

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

View File

@@ -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 &copy, const osg::CopyOp &copyop)
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;
}
}