diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2022-09-22 02:56:01 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2022-09-22 04:38:34 +0300 |
commit | 708255a88f2ba5284479046d39384f95e851a22e (patch) | |
tree | d012ababf97dd02ee7ed3ff5d36d084d9fc9be45 | |
parent | 5578ae83b3f318c9f40f55aed12fd2dbca514eaa (diff) |
Carver: replace deprecated bgl module
Part of T80730
-rw-r--r-- | object_carver/__init__.py | 4 | ||||
-rw-r--r-- | object_carver/carver_draw.py | 6 | ||||
-rw-r--r-- | object_carver/carver_utils.py | 27 |
3 files changed, 16 insertions, 21 deletions
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') |