Skip to content

Commit

Permalink
ViewportGadget : Avoid rendering selection ids with GL_BLEND enabled
Browse files Browse the repository at this point in the history
Enabling GL_BLEND for selection renders on Intel graphics hardware leads to corrupted ids in the selection buffer, so we now ensure it is disabled for selection renders in `renderInternal`.

We also consolidate the enabling of GL_BLEND so it only occurs in `renderInternal`, rather than in various parts of StandardStyle and in `ViewportGadget::render`.

This fixes GafferHQ#901 and GafferHQ#2788 on the Intel graphics hardware we have available to test with.
  • Loading branch information
murraystevenson committed Apr 3, 2024
1 parent 9f520f2 commit 53fcf3b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Fixes
- Dispatcher : Fixed shutdown crashes caused by Python slots connected to the dispatch signals [^1].
- Display : Fixed shutdown crashes caused by Python slots connected to `driverCreatedSignal()` and `imageReceivedSignal()` [^1].
- LightPositionTool : Fixed crash when changing the tool mode with nothing selected [^1].
- ViewportGadget : Fixed selection issues with Intel GPUs (#901, #2788).

API
---
Expand Down
2 changes: 0 additions & 2 deletions src/GafferUI/StandardStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +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() );

Expand Down Expand Up @@ -1130,7 +1129,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 Down
8 changes: 5 additions & 3 deletions src/GafferUI/ViewportGadget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,6 @@ void ViewportGadget::render() const
glClearColor( 0.26f, 0.26f, 0.26f, 0.0f );
glClearDepth( 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnable( GL_BLEND );

// Set up the camera to world matrix in gl_TextureMatrix[0] so that we can
// reference world space positions in shaders
Expand Down Expand Up @@ -1288,13 +1287,16 @@ void ViewportGadget::renderInternal( RenderReason reason, Gadget::Layer filterLa
if( reason != RenderReason::Draw )
{
// We're doing selection so post-processing doesn't matter. Just
// render direct to output buffer.
// render direct to output buffer without blending as that can
// corrupt the selection buffer on some graphics hardware.
glDisable( GL_BLEND );
renderLayerInternal( reason, layer, viewTransform, bound, selector );
continue;
}

// Render to intemediate framebuffer.
// Render to intermediate framebuffer.

glEnable( GL_BLEND );
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, acquireFramebuffer() );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
Expand Down

0 comments on commit 53fcf3b

Please sign in to comment.