From c3af88dfc1df0fb77489ebc4e87c94a092433828 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Sun, 2 Jun 2013 23:32:53 +0200 Subject: [PATCH] Canvas: set blend function for elements and prevent autoresize --- simgear/canvas/Canvas.cxx | 1 - simgear/canvas/ODGauge.cxx | 1 + simgear/canvas/elements/CanvasElement.cxx | 22 ++++++++++++++++++++-- simgear/canvas/elements/CanvasElement.hxx | 3 ++- simgear/canvas/elements/CanvasImage.cxx | 1 + simgear/canvas/elements/CanvasPath.cxx | 1 - 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/simgear/canvas/Canvas.cxx b/simgear/canvas/Canvas.cxx index 58528100..4e425557 100644 --- a/simgear/canvas/Canvas.cxx +++ b/simgear/canvas/Canvas.cxx @@ -31,7 +31,6 @@ #include #include -#include namespace simgear { diff --git a/simgear/canvas/ODGauge.cxx b/simgear/canvas/ODGauge.cxx index a95581a1..ce49eb31 100644 --- a/simgear/canvas/ODGauge.cxx +++ b/simgear/canvas/ODGauge.cxx @@ -201,6 +201,7 @@ namespace canvas if( !texture ) { texture = new osg::Texture2D; + texture->setResizeNonPowerOfTwoHint(false); texture->setTextureSize(_size_x, _size_y); texture->setInternalFormat(GL_RGBA); } diff --git a/simgear/canvas/elements/CanvasElement.cxx b/simgear/canvas/elements/CanvasElement.cxx index cb186342..e581e514 100644 --- a/simgear/canvas/elements/CanvasElement.cxx +++ b/simgear/canvas/elements/CanvasElement.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -134,6 +135,20 @@ namespace canvas // Update bounding box on manual update (manual updates pass zero dt) if( dt == 0 && _drawable ) _drawable->getBound(); + + if( _attributes_dirty & BLEND_FUNC ) + { + parseBlendFunc( + _transform->getOrCreateStateSet(), + _node->getChild("blend-source"), + _node->getChild("blend-destination"), + _node->getChild("blend-source-rgb"), + _node->getChild("blend-destination-rgb"), + _node->getChild("blend-source-alpha"), + _node->getChild("blend-destination-alpha") + ); + _attributes_dirty &= ~BLEND_FUNC; + } } //---------------------------------------------------------------------------- @@ -300,13 +315,16 @@ namespace canvas SGPropertyNode *parent = child->getParent(); if( parent == _node ) { + const std::string& name = child->getNameString(); if( setStyle(child) ) return; - else if( child->getNameString() == "update" ) + else if( name == "update" ) return update(0); - else if( child->getNameString() == "visible" ) + else if( name == "visible" ) // TODO check if we need another nodemask return _transform->setNodeMask( child->getBoolValue() ? 0xffffffff : 0 ); + else if( boost::starts_with(name, "blend-") ) + return (void)(_attributes_dirty |= BLEND_FUNC); } else if( parent->getParent() == _node && parent->getNameString() == NAME_TRANSFORM ) diff --git a/simgear/canvas/elements/CanvasElement.hxx b/simgear/canvas/elements/CanvasElement.hxx index 65e84dbf..146cd0d4 100644 --- a/simgear/canvas/elements/CanvasElement.hxx +++ b/simgear/canvas/elements/CanvasElement.hxx @@ -133,7 +133,8 @@ namespace canvas enum Attributes { - LAST_ATTRIBUTE = 0x0001 + BLEND_FUNC = 0x0001, + LAST_ATTRIBUTE = BLEND_FUNC << 1 }; enum TransformType diff --git a/simgear/canvas/elements/CanvasImage.cxx b/simgear/canvas/elements/CanvasImage.cxx index d472a6ae..5cd5ddc3 100644 --- a/simgear/canvas/elements/CanvasImage.cxx +++ b/simgear/canvas/elements/CanvasImage.cxx @@ -378,6 +378,7 @@ namespace canvas // remove canvas... setSrcCanvas( CanvasPtr() ); + _texture->setResizeNonPowerOfTwoHint(false); _texture->setImage(img); _texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); _texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT); diff --git a/simgear/canvas/elements/CanvasPath.cxx b/simgear/canvas/elements/CanvasPath.cxx index 5e9efa08..e2281905 100644 --- a/simgear/canvas/elements/CanvasPath.cxx +++ b/simgear/canvas/elements/CanvasPath.cxx @@ -20,7 +20,6 @@ #include #include -#include #include #include -- 2.39.5