[Bf-blender-cvs] [daf7f423642] master: Fix line width broken for consecutive line draw calls

Julian Eisel noreply at git.blender.org
Wed Feb 24 11:18:25 CET 2021


Commit: daf7f423642cad3e807ac35d669a404eac39a640
Author: Julian Eisel
Date:   Wed Feb 24 11:16:51 2021 +0100
Branches: master
https://developer.blender.org/rBdaf7f423642cad3e807ac35d669a404eac39a640

Fix line width broken for consecutive line draw calls

D9054 did multiple consecutive `immBegin()`/`immEnd()` draw calls to draw
multiple lines at varying thickness. This would only work for the first line,
then they'd all get a 1px thickness (at least on macOS).

Issue was that `wide_line_workaround_end()` called `immBindShader()` directly
to restore the old shader (which the workaround overrides). However this
doesn't set `imm->builtin_shader_bound` which has to be done for the workaround
to work on the next `immBegin()` call. Instead `immBindBuiltinProgram()` can be
called.

Differential Revision: https://developer.blender.org/D10520

Reviewed by: Clément Foucault

===================================================================

M	source/blender/gpu/intern/gpu_immediate.cc
M	source/blender/gpu/intern/gpu_immediate_private.hh

===================================================================

diff --git a/source/blender/gpu/intern/gpu_immediate.cc b/source/blender/gpu/intern/gpu_immediate.cc
index 95718391165..e56dcd16528 100644
--- a/source/blender/gpu/intern/gpu_immediate.cc
+++ b/source/blender/gpu/intern/gpu_immediate.cc
@@ -166,7 +166,7 @@ static void wide_line_workaround_start(GPUPrimType prim_type)
       return;
   }
 
-  imm->prev_shader = imm->shader;
+  imm->prev_builtin_shader = imm->builtin_shader_bound;
 
   immUnbindProgram();
 
@@ -194,15 +194,15 @@ static void wide_line_workaround_start(GPUPrimType prim_type)
 
 static void wide_line_workaround_end()
 {
-  if (imm->prev_shader) {
+  if (imm->prev_builtin_shader) {
     if (GPU_blend_get() == GPU_BLEND_NONE) {
       /* Restore default. */
       immUniform1i("lineSmooth", 1);
     }
     immUnbindProgram();
 
-    immBindShader(imm->prev_shader);
-    imm->prev_shader = nullptr;
+    immBindBuiltinProgram(imm->prev_builtin_shader);
+    imm->prev_builtin_shader = GPU_SHADER_TEXT;
   }
 }
 
diff --git a/source/blender/gpu/intern/gpu_immediate_private.hh b/source/blender/gpu/intern/gpu_immediate_private.hh
index 98399897ea9..382f70eeec4 100644
--- a/source/blender/gpu/intern/gpu_immediate_private.hh
+++ b/source/blender/gpu/intern/gpu_immediate_private.hh
@@ -58,7 +58,7 @@ class Immediate {
   /** Wide Line workaround. */
 
   /** Previously bound shader to restore after drawing. */
-  GPUShader *prev_shader = NULL;
+  eGPUBuiltinShader prev_builtin_shader = GPU_SHADER_TEXT;
   /** Builtin shader index. Used to test if the workaround can be done. */
   eGPUBuiltinShader builtin_shader_bound = GPU_SHADER_TEXT;
   /** Uniform color: Kept here to update the wide-line shader just before #immBegin. */



More information about the Bf-blender-cvs mailing list