add a transparent texture for effects
This is used as a default texture for the chrome animation. Also, fix a typo in creating combiners.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user