]> git.mxchange.org Git - simgear.git/commitdiff
add a transparent texture for effects
authorTim Moore <timoore@redhat.com>
Mon, 16 Nov 2009 21:42:46 +0000 (22:42 +0100)
committerTim Moore <timoore@redhat.com>
Mon, 16 Nov 2009 21:42:46 +0000 (22:42 +0100)
This is used as a default texture for the chrome animation.

Also, fix a typo in creating combiners.

simgear/scene/material/TextureBuilder.cxx
simgear/scene/util/StateAttributeFactory.cxx
simgear/scene/util/StateAttributeFactory.hxx

index d7382e9219ad969d1a1c14d09d8de3b01eed8152..c1f353ce3fe832da153af59782f5f3faf6cc7635 100644 (file)
@@ -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<const Texture2D*>(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();
index 6e121c073d0d7765c102bccddfc32311ccbffe5d..76124da06b1b1e8df83ca8f024928d979f91ff38 100644 (file)
@@ -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);
index 18b1a59d811099aff1671d6071d6866c53ebaf2c..0076fa510e6befa8f07c37edc2cadf2e6a95eeab 100644 (file)
@@ -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<osg::BlendFunc> _standardBlendFunc;
     osg::ref_ptr<osg::TexEnv> _standardTexEnv;
     osg::ref_ptr<osg::Texture2D> _whiteTexture;
+    osg::ref_ptr<osg::Texture2D> _transparentTexture;
     osg::ref_ptr<osg::Vec4Array> _white;
     osg::ref_ptr<osg::CullFace> _cullFaceFront;
     osg::ref_ptr<osg::CullFace> _cullFaceBack;