[Bf-extensions-cvs] [708255a8] master: Carver: replace deprecated bgl module

Germano Cavalcante noreply at git.blender.org
Thu Sep 22 03:45:10 CEST 2022


Commit: 708255a88f2ba5284479046d39384f95e851a22e
Author: Germano Cavalcante
Date:   Wed Sep 21 20:56:01 2022 -0300
Branches: master
https://developer.blender.org/rBA708255a88f2ba5284479046d39384f95e851a22e

Carver: replace deprecated bgl module

Part of T80730

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

M	object_carver/__init__.py
M	object_carver/carver_draw.py
M	object_carver/carver_utils.py

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

diff --git a/object_carver/__init__.py b/object_carver/__init__.py
index 7c86c2fe..253c3aaf 100644
--- a/object_carver/__init__.py
+++ b/object_carver/__init__.py
@@ -4,8 +4,8 @@ bl_info = {
     "name": "Carver",
     "author": "Pixivore, Cedric LEPILLER, Ted Milker, Clarkx",
     "description": "Multiple tools to carve or to create objects",
-    "version": (1, 2, 0),
-    "blender": (2, 80, 0),
+    "version": (1, 2, 1),
+    "blender": (3, 4, 0),
     "location": "3D View > Ctrl/Shift/x",
     "warning": "",
     "doc_url": "{BLENDER_MANUAL_URL}/addons/object/carver.html",
diff --git a/object_carver/carver_draw.py b/object_carver/carver_draw.py
index c7000787..f5d227f4 100644
--- a/object_carver/carver_draw.py
+++ b/object_carver/carver_draw.py
@@ -1,7 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 import bpy
-import bgl
 import blf
 import bpy_extras
 import numpy as np
@@ -444,7 +443,7 @@ def draw_callback_px(self, context):
             mat = ob.matrix_world
 
             # 50% alpha, 2 pixel width line
-            bgl.glEnable(bgl.GL_BLEND)
+            gpu.state.blend_set('ALPHA')
 
             bbox = [mat @ Vector(b) for b in ob.bound_box]
             objBBDiagonal = objDiagonal(self.CurrentSelection[0])
@@ -497,5 +496,4 @@ def draw_callback_px(self, context):
                         self.ProfileBrush.rotation_mode = 'XYZ'
 
     # Opengl defaults
-    bgl.glLineWidth(1)
-    bgl.glDisable(bgl.GL_BLEND)
+    gpu.state.blend_set('NONE')
diff --git a/object_carver/carver_utils.py b/object_carver/carver_utils.py
index 0ac4c991..a0f1eddd 100644
--- a/object_carver/carver_utils.py
+++ b/object_carver/carver_utils.py
@@ -1,7 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 import bpy
-import bgl
 import gpu
 from gpu_extras.batch import batch_for_shader
 import math
@@ -918,25 +917,23 @@ def mini_grid(self, context, color):
 
 def draw_shader(self, color, alpha, type, coords, size=1, indices=None):
     """ Create a batch for a draw type """
-    bgl.glEnable(bgl.GL_BLEND)
-    bgl.glEnable(bgl.GL_LINE_SMOOTH)
+    gpu.state.blend_set('ALPHA')
     if type =='POINTS':
-        bgl.glPointSize(size)
+        gpu.state.program_point_size_set(False)
+        gpu.state.point_size_set(size)
+        shader = gpu.shader.from_builtin('UNIFORM_COLOR')
     else:
-        bgl.glLineWidth(size)
+        shader = gpu.shader.from_builtin('POLYLINE_UNIFORM_COLOR')
+        shader.uniform_float("viewportSize", gpu.state.viewport_get()[2:])
+        shader.uniform_float("lineWidth", 1.0)
+
     try:
-        if len(coords[0])>2:
-            shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
-        else:
-            shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
-        batch = batch_for_shader(shader, type, {"pos": coords}, indices=indices)
-        shader.bind()
         shader.uniform_float("color", (color[0], color[1], color[2], alpha))
+        batch = batch_for_shader(shader, type, {"pos": coords}, indices=indices)
         batch.draw(shader)
-        bgl.glLineWidth(1)
-        bgl.glPointSize(1)
-        bgl.glDisable(bgl.GL_LINE_SMOOTH)
-        bgl.glDisable(bgl.GL_BLEND)
     except:
         exc_type, exc_value, exc_traceback = sys.exc_info()
         self.report({'ERROR'}, str(exc_value))
+
+    gpu.state.point_size_set(1.0)
+    gpu.state.blend_set('NONE')



More information about the Bf-extensions-cvs mailing list