From cadecdcab7f63d543522c41114dead90cad58918 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Mon, 16 Nov 2009 22:42:46 +0100 Subject: [PATCH] add a transparent texture for effects This is used as a default texture for the chrome animation. Also, fix a typo in creating combiners. --- simgear/scene/material/TextureBuilder.cxx | 23 ++++++++++++++++++-- simgear/scene/util/StateAttributeFactory.cxx | 11 ++++++++++ simgear/scene/util/StateAttributeFactory.hxx | 6 +++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/simgear/scene/material/TextureBuilder.cxx b/simgear/scene/material/TextureBuilder.cxx index d7382e92..c1f353ce 100644 --- a/simgear/scene/material/TextureBuilder.cxx +++ b/simgear/scene/material/TextureBuilder.cxx @@ -297,6 +297,25 @@ namespace TextureBuilder::Registrar installWhite("white", new WhiteTextureBuilder); } +class TransparentTextureBuilder : public TextureBuilder +{ +public: + Texture* build(Effect* effect, const SGPropertyNode*, + const osgDB::ReaderWriter::Options* options); +}; + +Texture* TransparentTextureBuilder::build(Effect* effect, const SGPropertyNode*, + const osgDB::ReaderWriter::Options* options) +{ + return StateAttributeFactory::instance()->getTransparentTexture(); +} + +namespace +{ +TextureBuilder::Registrar installTransparent("transparent", + new TransparentTextureBuilder); +} + osg::Image* make3DNoiseImage(int texSize) { osg::Image* image = new osg::Image; @@ -435,7 +454,7 @@ TexEnvCombine* buildTexEnvCombine(Effect* effect, const SGPropertyNode* envProp) if ((p = getEffectPropertyChild(effect, envProp, "combine-alpha"))) { TexEnvCombine::CombineParam calpha = TexEnvCombine::MODULATE; findAttr(combineParams, p, calpha); - result->setCombine_RGB(calpha); + result->setCombine_Alpha(calpha); } if ((p = getEffectPropertyChild(effect, envProp, "source0-rgb"))) { TexEnvCombine::SourceParam source = TexEnvCombine::TEXTURE; @@ -577,8 +596,8 @@ bool makeTextureParameters(SGPropertyNode* paramRoot, const StateSet* ss) const Texture2D* texture = dynamic_cast(tex); makeChild(texUnit, "unit")->setValue(0); if (!tex) { + // The default shader-based technique ignores active makeChild(texUnit, "active")->setValue(false); - makeChild(texUnit, "type")->setValue("white"); return false; } const Image* image = texture->getImage(); diff --git a/simgear/scene/util/StateAttributeFactory.cxx b/simgear/scene/util/StateAttributeFactory.cxx index 6e121c07..76124da0 100644 --- a/simgear/scene/util/StateAttributeFactory.cxx +++ b/simgear/scene/util/StateAttributeFactory.cxx @@ -64,6 +64,17 @@ StateAttributeFactory::StateAttributeFactory() _whiteTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); _whiteTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT); _whiteTexture->setDataVariance(osg::Object::STATIC); + // And now the transparent texture + dummyImage = new osg::Image; + dummyImage->allocateImage(1, 1, 1, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE); + imageBytes = dummyImage->data(0, 0); + imageBytes[0] = 255; + imageBytes[1] = 0; + _transparentTexture = new osg::Texture2D; + _transparentTexture->setImage(dummyImage); + _transparentTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); + _transparentTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT); + _transparentTexture->setDataVariance(osg::Object::STATIC); _white = new Vec4Array(1); (*_white)[0].set(1.0f, 1.0f, 1.0f, 1.0f); _white->setDataVariance(Object::STATIC); diff --git a/simgear/scene/util/StateAttributeFactory.hxx b/simgear/scene/util/StateAttributeFactory.hxx index 18b1a59d..0076fa51 100644 --- a/simgear/scene/util/StateAttributeFactory.hxx +++ b/simgear/scene/util/StateAttributeFactory.hxx @@ -57,6 +57,11 @@ public: osg::Texture2D* getWhiteTexture() { return _whiteTexture.get(); } // White color osg::Vec4Array* getWhiteColor() {return _white.get(); } + // A white, completely transparent texture + osg::Texture2D* getTransparentTexture() + { + return _transparentTexture.get(); + } // cull front and back facing polygons osg::CullFace* getCullFaceFront() { return _cullFaceFront.get(); } osg::CullFace* getCullFaceBack() { return _cullFaceBack.get(); } @@ -70,6 +75,7 @@ protected: osg::ref_ptr _standardBlendFunc; osg::ref_ptr _standardTexEnv; osg::ref_ptr _whiteTexture; + osg::ref_ptr _transparentTexture; osg::ref_ptr _white; osg::ref_ptr _cullFaceFront; osg::ref_ptr _cullFaceBack; -- 2.39.5