From 68bb67312e417fc6d93bf8856609587114a380c6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 13 Feb 2018 12:12:34 +0000 Subject: [PATCH] Improved handling of updates to the Texture target that require the texture to be reapplied. Used State for applying Texture target to work better with lazy state updating. --- src/osg/BindImageTexture.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/osg/BindImageTexture.cpp b/src/osg/BindImageTexture.cpp index 592ffa2fb..14d71151a 100644 --- a/src/osg/BindImageTexture.cpp +++ b/src/osg/BindImageTexture.cpp @@ -15,17 +15,19 @@ int BindImageTexture::compare(const osg::StateAttribute &sa) const return 0; } -void BindImageTexture::apply(osg::State&state) const +void BindImageTexture::apply(osg::State& state) const { if(_target.valid()) { - osg::Texture::TextureObject *to = _target->getTextureObject( state.getContextID() ); - if( !to ) + unsigned int contextID = state.getContextID(); + osg::Texture::TextureObject *to = _target->getTextureObject( contextID ); + if( !to || _target->isDirty( contextID )) { - // _target never been applied yet - _target->apply(state); - to = _target->getTextureObject( state.getContextID() ); + // _target never been applied yet or is dirty + state.applyTextureAttribute( state.getActiveTextureUnit(), _target.get()); + to = _target->getTextureObject( contextID ); } + state.get()->glBindImageTexture(_imageunit, to->id(), _level, _layered, _layer, _access, _format); }