[Bf-extensions-cvs] [5578ae83] master: UV Layout: replace deprecated bgl module

Germano Cavalcante noreply at git.blender.org
Thu Sep 22 01:39:06 CEST 2022


Commit: 5578ae83b3f318c9f40f55aed12fd2dbca514eaa
Author: Germano Cavalcante
Date:   Wed Sep 21 20:25:59 2022 -0300
Branches: master
https://developer.blender.org/rBA5578ae83b3f318c9f40f55aed12fd2dbca514eaa

UV Layout: replace deprecated bgl module

Part of T80730

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

M	io_mesh_uv_layout/__init__.py
M	io_mesh_uv_layout/export_uv_png.py

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

diff --git a/io_mesh_uv_layout/__init__.py b/io_mesh_uv_layout/__init__.py
index bb7e4584..7145384c 100644
--- a/io_mesh_uv_layout/__init__.py
+++ b/io_mesh_uv_layout/__init__.py
@@ -3,7 +3,7 @@
 bl_info = {
     "name": "UV Layout",
     "author": "Campbell Barton, Matt Ebb",
-    "version": (1, 1, 4),
+    "version": (1, 1, 5),
     "blender": (3, 0, 0),
     "location": "UV Editor > UV > Export UV Layout",
     "description": "Export the UV layout as a 2D graphic",
diff --git a/io_mesh_uv_layout/export_uv_png.py b/io_mesh_uv_layout/export_uv_png.py
index 2c40abdf..ad1b2284 100644
--- a/io_mesh_uv_layout/export_uv_png.py
+++ b/io_mesh_uv_layout/export_uv_png.py
@@ -2,7 +2,6 @@
 
 import bpy
 import gpu
-import bgl
 from mathutils import Vector, Matrix
 from mathutils.geometry import tessellate_polygon
 from gpu_extras.batch import batch_for_shader
@@ -26,10 +25,7 @@ def export(filepath, face_data, colors, width, height, opacity):
 
 
 def draw_image(face_data, opacity):
-    bgl.glLineWidth(1)
-    bgl.glEnable(bgl.GL_BLEND)
-    bgl.glEnable(bgl.GL_LINE_SMOOTH)
-    bgl.glHint(bgl.GL_LINE_SMOOTH_HINT, bgl.GL_NICEST)
+    gpu.state.blend_set('ALPHA')
 
     with gpu.matrix.push_pop():
         gpu.matrix.load_matrix(get_normalize_uvs_matrix())
@@ -38,8 +34,7 @@ def draw_image(face_data, opacity):
         draw_background_colors(face_data, opacity)
         draw_lines(face_data)
 
-    bgl.glDisable(bgl.GL_BLEND)
-    bgl.glDisable(bgl.GL_LINE_SMOOTH)
+    gpu.state.blend_set('NONE')
 
 
 def get_normalize_uvs_matrix():
@@ -85,11 +80,12 @@ def draw_lines(face_data):
             coords.append((start[0], start[1]))
             coords.append((end[0], end[1]))
 
-    shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
-    shader.bind()
-    shader.uniform_float("color", (0, 0, 0, 1))
-    batch = batch_for_shader(shader, 'LINES', {"pos": coords})
+    shader = gpu.shader.from_builtin('POLYLINE_UNIFORM_COLOR')
+    shader.uniform_float("viewportSize", gpu.state.viewport_get()[2:])
+    shader.uniform_float("lineWidth", 1.0)
+    shader.uniform_float("color", (0.0, 0.0, 0.0, 1.0))
 
+    batch = batch_for_shader(shader, 'LINES', {"pos": coords})
     batch.draw(shader)



More information about the Bf-extensions-cvs mailing list