Skip to content

Commit

Permalink
StandardStyle : Avoid enabling GL_BLEND for selection
Browse files Browse the repository at this point in the history
Enabling `GL_BLEND` on Intel graphics hardware leads to corrupted ids in the selection buffer.
  • Loading branch information
murraystevenson committed Mar 16, 2024
1 parent 1cc2e2f commit 8849cdf
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/GafferUI/StandardStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,6 @@ void StandardStyle::bind( const Style *currentStyle ) const
return;
}

glEnable( GL_BLEND );
glBlendFuncSeparate( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
glUseProgram( shader()->program() );

if( IECoreGL::Selector *selector = IECoreGL::Selector::currentSelector() )
Expand All @@ -592,6 +590,13 @@ void StandardStyle::bind( const Style *currentStyle ) const
selector->pushIDShader( shader() );
}
}
else
{
// Enable blending only for non-selection renders as it can
// corrupt the selection buffer on some graphics hardware.
glEnable( GL_BLEND );
glBlendFuncSeparate( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
}
}

Imath::Box3f StandardStyle::characterBound( TextType textType ) const
Expand Down Expand Up @@ -1129,8 +1134,6 @@ void StandardStyle::renderImage( const Imath::Box2f &box, const IECoreGL::Textur
{
glPushAttrib( GL_COLOR_BUFFER_BIT );

// As the image is already pre-multiplied we need to change our blend mode.
glEnable( GL_BLEND );
if( !IECoreGL::Selector::currentSelector() )
{
// Some users have reported crashes that were traced back to this call
Expand All @@ -1139,6 +1142,9 @@ void StandardStyle::renderImage( const Imath::Box2f &box, const IECoreGL::Textur
// didn't correspond to actual gadgets.
// Don't change it when rendering the selection pass since
// blending should not be applied to an integer buffer anyways.

// As the image is already pre-multiplied we need to change our blend mode.
glEnable( GL_BLEND );
glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
}

Expand Down

0 comments on commit 8849cdf

Please sign in to comment.