[Bf-blender-cvs] [cd7a1042bf8] cycles_texture_cache: Python GPU: Replace a few calls of the bgl module with gpu

Germano Cavalcante noreply at git.blender.org
Thu May 6 11:25:35 CEST 2021


Commit: cd7a1042bf8c2cc372b7e01055bde28c0f8ecc68
Author: Germano Cavalcante
Date:   Sat May 1 11:59:54 2021 -0300
Branches: cycles_texture_cache
https://developer.blender.org/rBcd7a1042bf8c2cc372b7e01055bde28c0f8ecc68

Python GPU: Replace a few calls of the bgl module with gpu

Concludes these files:
[x]bpy_types.py
[x]operator_modal_draw.py

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D11129

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

M	release/scripts/modules/bpy_types.py
M	release/scripts/templates_py/operator_modal_draw.py

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

diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index 4ea8c88e8d9..aa540eeb23b 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -657,16 +657,14 @@ class Gizmo(StructRNA):
             use_blend = color[3] < 1.0
 
         if use_blend:
-            # TODO: wrap GPU_blend from GPU state.
-            from bgl import glEnable, glDisable, GL_BLEND
-            glEnable(GL_BLEND)
+            gpu.state.blend_set('ALPHA')
 
         with gpu.matrix.push_pop():
             gpu.matrix.multiply_matrix(matrix)
             batch.draw()
 
         if use_blend:
-            glDisable(GL_BLEND)
+            gpu.state.blend_set('NONE')
 
     @staticmethod
     def new_custom_shape(type, verts):
diff --git a/release/scripts/templates_py/operator_modal_draw.py b/release/scripts/templates_py/operator_modal_draw.py
index 1e185ecfe2b..16c6f6dbe22 100644
--- a/release/scripts/templates_py/operator_modal_draw.py
+++ b/release/scripts/templates_py/operator_modal_draw.py
@@ -1,5 +1,4 @@
 import bpy
-import bgl
 import blf
 import gpu
 from gpu_extras.batch import batch_for_shader
@@ -17,16 +16,16 @@ def draw_callback_px(self, context):
 
     # 50% alpha, 2 pixel width line
     shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
-    bgl.glEnable(bgl.GL_BLEND)
-    bgl.glLineWidth(2)
+    gpu.state.blend_set('ALPHA')
+    gpu.state.line_width_set(2.0)
     batch = batch_for_shader(shader, 'LINE_STRIP', {"pos": self.mouse_path})
     shader.bind()
     shader.uniform_float("color", (0.0, 0.0, 0.0, 0.5))
     batch.draw(shader)
 
     # restore opengl defaults
-    bgl.glLineWidth(1)
-    bgl.glDisable(bgl.GL_BLEND)
+    gpu.state.line_width_set(1.0)
+    gpu.state.blend_set('NONE')
 
 
 class ModalDrawOperator(bpy.types.Operator):



More information about the Bf-blender-cvs mailing list