From 6c172869bba6c0009e3558c4273dc9d29b1c2ed4 Mon Sep 17 00:00:00 2001 From: p2or <512368+p2or@users.noreply.github.com> Date: Sat, 8 Apr 2023 09:15:42 +0200 Subject: [PATCH 1/5] bgl replacements --- dof-utils.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/dof-utils.py b/dof-utils.py index 54cf9b1..bad5d90 100644 --- a/dof-utils.py +++ b/dof-utils.py @@ -19,8 +19,8 @@ bl_info = { "name": "Depth of Field Utilities", "author": "Christian Brinkmann (p2or)", - "description": "Displays depth of field in 3D view port.", - "version": (0, 1, 1), + "description": "Displays depth of field in 3D viewport.", + "version": (0, 1, 0), "blender": (2, 80, 0), "location": "3d View > Properties Panel (N) > Depth of Field Utilities", "doc_url": "https://github.com/p2or/blender-dof-utils", @@ -29,7 +29,6 @@ } import bpy -import bgl import blf import gpu from gpu_extras.batch import batch_for_shader @@ -225,18 +224,22 @@ def draw_callback_3d(operator, context): dofu.limits = (d, near_limit, far_limit) # 80% alpha, 2 pixel width line - bgl.glEnable(bgl.GL_BLEND) - bgl.glEnable(bgl.GL_LINE_SMOOTH) - bgl.glEnable(bgl.GL_DEPTH_TEST) + gpu.state.blend_set('ALPHA') # bgl.glEnable(bgl.GL_BLEND) + #bgl.glEnable(bgl.GL_LINE_SMOOTH) + gpu.state.depth_mask_set(True) # check overlay if dofu.overlay: - bgl.glDisable(bgl.GL_DEPTH_TEST) + gpu.state.depth_mask_set(True) #bgl.glEnable(bgl.GL_DEPTH_TEST) + #gpu.state.blend_set('NONE') # bgl.glDisable(bgl.GL_DEPTH_TEST) + #if not gpu.state.depth_mask_get(): + #gpu.state.depth_mask_set(True) else: - bgl.glEnable(bgl.GL_DEPTH_TEST) + gpu.state.depth_mask_set(False) + gpu.state.blend_set('NONE') # set line width - bgl.glLineWidth(2) + gpu.state.line_width_set(2) # bgl.glLineWidth(2) def line(color, start, end): vertices = [start,end] @@ -275,12 +278,10 @@ def line(color, start, end): color=(dofu.color_limits[0], dofu.color_limits[1], dofu.color_limits[2], dofu.opacity_limits)) # restore opengl defaults - bgl.glLineWidth(1) - bgl.glDisable(bgl.GL_BLEND) - bgl.glDisable(bgl.GL_LINE_SMOOTH) - bgl.glEnable(bgl.GL_DEPTH_TEST) - #bgl.glColor4f(0.0, 0.0, 0.0, 1.0) - + gpu.state.blend_set('ALPHA') # bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(1) + #bgl.glDisable(bgl.GL_BLEND) + #bgl.glDisable(bgl.GL_LINE_SMOOTH) + #bgl.glEnable(bgl.GL_DEPTH_TEST) def draw_string(x, y, packed_strings): font_id = 0 @@ -314,7 +315,7 @@ def draw_poly(coords, color, width): # Create batch process batch = batch_for_shader(shader,'LINE_STRIP', {"pos": coords}) # Set the line width - bgl.glLineWidth(width) + gpu.state.line_width_set(width) # bgl.glLineWidth(width) shader.bind() # Set color shader.uniform_float("color",color) From 129bf571aeaa48da09807e75233062856e32682b Mon Sep 17 00:00:00 2001 From: p2or <512368+p2or@users.noreply.github.com> Date: Sat, 8 Apr 2023 10:16:28 +0200 Subject: [PATCH 2/5] overlay limits - gpu depth test --- dof-utils.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/dof-utils.py b/dof-utils.py index bad5d90..e4a5a71 100644 --- a/dof-utils.py +++ b/dof-utils.py @@ -225,18 +225,14 @@ def draw_callback_3d(operator, context): # 80% alpha, 2 pixel width line gpu.state.blend_set('ALPHA') # bgl.glEnable(bgl.GL_BLEND) - #bgl.glEnable(bgl.GL_LINE_SMOOTH) - gpu.state.depth_mask_set(True) - + #bgl.glEnable(bgl.GL_LINE_SMOOTH) # -> No replacement gpu.shader.from_builtin('POLYLINE_SMOOTH_COLOR') + gpu.state.depth_test_set("LESS") # bgl.glEnable(bgl.GL_DEPTH_TEST) + # check overlay if dofu.overlay: - gpu.state.depth_mask_set(True) #bgl.glEnable(bgl.GL_DEPTH_TEST) - #gpu.state.blend_set('NONE') # bgl.glDisable(bgl.GL_DEPTH_TEST) - #if not gpu.state.depth_mask_get(): - #gpu.state.depth_mask_set(True) + gpu.state.depth_test_set("NONE") # bgl.glDisable(bgl.GL_DEPTH_TEST) else: - gpu.state.depth_mask_set(False) - gpu.state.blend_set('NONE') + gpu.state.depth_test_set("LESS") # bgl.glEnable(bgl.GL_DEPTH_TEST) # set line width gpu.state.line_width_set(2) # bgl.glLineWidth(2) @@ -246,7 +242,7 @@ def line(color, start, end): shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR') batch = batch_for_shader(shader,'LINE_STRIP', {"pos": vertices}) shader.bind() - shader.uniform_float("color",color) + shader.uniform_float("color", color) batch.draw(shader) #bgl.glColor4f(*color) #bgl.glBegin(bgl.GL_LINES) From 0a17ae1aed974a89a9c1945ab0d6ad0bb42e01d3 Mon Sep 17 00:00:00 2001 From: p2or <512368+p2or@users.noreply.github.com> Date: Sat, 8 Apr 2023 10:53:33 +0200 Subject: [PATCH 3/5] type - color and size --- dof-utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dof-utils.py b/dof-utils.py index e4a5a71..738437d 100644 --- a/dof-utils.py +++ b/dof-utils.py @@ -281,12 +281,12 @@ def line(color, start, end): def draw_string(x, y, packed_strings): font_id = 0 - blf.size(font_id, 17, 70) + blf.size(font_id, 17*(bpy.context.preferences.system.dpi/72)) x_offset = 0 for pstr, pcol in packed_strings: - #bgl.glColor4f(*pcol) text_width, text_height = blf.dimensions(font_id, pstr) blf.position(font_id, (x + x_offset), y, 0) + blf.color(font_id, *pcol) blf.draw(font_id, pstr) x_offset += text_width From 7d1f2d9693b1bc12052222a9d9798eb3d5e4bc2c Mon Sep 17 00:00:00 2001 From: p2or <512368+p2or@users.noreply.github.com> Date: Sat, 8 Apr 2023 11:00:33 +0200 Subject: [PATCH 4/5] proper defaults --- dof-utils.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/dof-utils.py b/dof-utils.py index 738437d..a55ced8 100644 --- a/dof-utils.py +++ b/dof-utils.py @@ -273,11 +273,9 @@ def line(color, start, end): size=dofu.size_limits * 1.7, color=(dofu.color_limits[0], dofu.color_limits[1], dofu.color_limits[2], dofu.opacity_limits)) - # restore opengl defaults - gpu.state.blend_set('ALPHA') # bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(1) - #bgl.glDisable(bgl.GL_BLEND) - #bgl.glDisable(bgl.GL_LINE_SMOOTH) - #bgl.glEnable(bgl.GL_DEPTH_TEST) + # restore defaults + gpu.state.line_width_set(1.0) + gpu.state.blend_set('NONE') def draw_string(x, y, packed_strings): font_id = 0 From a13fb03af0f1ad5942d68593c93e6cdd2126569c Mon Sep 17 00:00:00 2001 From: p2or <512368+p2or@users.noreply.github.com> Date: Sat, 8 Apr 2023 11:11:49 +0200 Subject: [PATCH 5/5] bl_info - blender version min, add-on version bump --- dof-utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dof-utils.py b/dof-utils.py index a55ced8..16b1053 100644 --- a/dof-utils.py +++ b/dof-utils.py @@ -20,8 +20,8 @@ "name": "Depth of Field Utilities", "author": "Christian Brinkmann (p2or)", "description": "Displays depth of field in 3D viewport.", - "version": (0, 1, 0), - "blender": (2, 80, 0), + "version": (0, 1, 2), + "blender": (3, 5, 0), "location": "3d View > Properties Panel (N) > Depth of Field Utilities", "doc_url": "https://github.com/p2or/blender-dof-utils", "tracker_url": "https://github.com/p2or/blender-dof-utils/issues",