From 5578ae83b3f318c9f40f55aed12fd2dbca514eaa Mon Sep 17 00:00:00 2001
From: Germano Cavalcante <germano.costa@ig.com.br>
Date: Wed, 21 Sep 2022 20:25:59 -0300
Subject: [PATCH] UV Layout: replace deprecated bgl module

Part of T80730
---
 io_mesh_uv_layout/__init__.py      |  2 +-
 io_mesh_uv_layout/export_uv_png.py | 18 +++++++-----------
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/io_mesh_uv_layout/__init__.py b/io_mesh_uv_layout/__init__.py
index bb7e45849..7145384cc 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 2c40abdfe..ad1b2284f 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)
 
 
-- 
GitLab