MeasureIt: replace deprecated bgl module

Part of T80730
This commit is contained in:
Germano Cavalcante 2022-07-28 12:03:49 -03:00
parent 547adaa4ed
commit a1424dc87f
Notes: blender-bot 2024-02-26 14:24:26 +01:00
Referenced by issue #80730, BGL deprecation
4 changed files with 13 additions and 17 deletions

View File

@ -11,8 +11,8 @@ bl_info = {
"name": "MeasureIt",
"author": "Antonio Vazquez (antonioya)",
"location": "View3D > Sidebar > View Tab",
"version": (1, 8, 1),
"blender": (2, 80, 0),
"version": (1, 8, 2),
"blender": (3, 0, 0),
"description": "Tools for measuring objects.",
"doc_url": "{BLENDER_MANUAL_URL}/addons/3d_view/measureit.html",
"category": "3D View"

View File

@ -17,7 +17,6 @@ from bpy_extras import view3d_utils, mesh_utils
import bpy_extras.object_utils as object_utils
from sys import exc_info
# GPU
import bgl
import gpu
from gpu_extras.batch import batch_for_shader
@ -477,7 +476,7 @@ def draw_segments(context, myobj, op, region, rv3d):
# ------------------------------------
# Draw lines
# ------------------------------------
bgl.glEnable(bgl.GL_BLEND)
gpu.state.blend_set('ALPHA')
if ms.gltype == 1: # Segment
draw_line(screen_point_ap1, screen_point_v11, rgba)
@ -1175,7 +1174,7 @@ def draw_faces(context, myobj, region, rv3d):
a_p2 = (a_p1[0] + normal[0] * ln, a_p1[1] + normal[1] * ln, a_p1[2] + normal[2] * ln)
# line setup
bgl.glEnable(bgl.GL_BLEND)
gpu.state.blend_set('ALPHA')
imm_set_line_width(th)
# converting to screen coordinates
txtpoint2d = get_2d_point(region, rv3d, a_p1)
@ -1185,7 +1184,7 @@ def draw_faces(context, myobj, region, rv3d):
draw_text(myobj, txtpoint2d, str(f.index), rgba, fsize)
# Draw Normal
if scene.measureit_debug_normals is True:
bgl.glEnable(bgl.GL_BLEND)
gpu.state.blend_set('ALPHA')
draw_arrow(txtpoint2d, point2, rgba, 10, "99", "1")
if len(obverts) > 2 and scene.measureit_debug_normal_details is True:

View File

@ -11,7 +11,6 @@ import bpy
import bmesh
from bmesh import from_edit_mesh
# noinspection PyUnresolvedReferences
import bgl
from bpy.types import PropertyGroup, Panel, Object, Operator, SpaceView3D
from bpy.props import IntProperty, CollectionProperty, FloatVectorProperty, BoolProperty, StringProperty, \
FloatProperty, EnumProperty
@ -1933,8 +1932,8 @@ def draw_main(context):
else:
objlist = context.view_layer.objects
# Enable GL drawing
bgl.glEnable(bgl.GL_BLEND)
# Enable drawing
gpu.state.blend_set('ALPHA')
# ---------------------------------------
# Generate all OpenGL calls for measures
# ---------------------------------------
@ -1964,9 +1963,9 @@ def draw_main(context):
draw_faces(context, myobj, region, rv3d)
# -----------------------
# restore opengl defaults
# restore defaults
# -----------------------
bgl.glDisable(bgl.GL_BLEND)
gpu.state.blend_set('NONE')
# -------------------------------------------------------------

View File

@ -8,7 +8,6 @@
# noinspection PyUnresolvedReferences
import bpy
import gpu
import bgl
# noinspection PyUnresolvedReferences
import blf
from os import path, remove
@ -54,8 +53,8 @@ def render_main(self, context, animation=False):
[0, 0, 0, 1]])
with offscreen.bind():
bgl.glClearColor(0.0, 0.0, 0.0, 0.0)
bgl.glClear(bgl.GL_COLOR_BUFFER_BIT)
fb = gpu.state.active_framebuffer_get()
fb.clear(color=(0.0, 0.0, 0.0, 0.0))
gpu.matrix.reset()
gpu.matrix.load_matrix(view_matrix)
gpu.matrix.load_projection_matrix(Matrix.Identity(4))
@ -101,9 +100,8 @@ def render_main(self, context, animation=False):
y2 = height - y1
draw_rectangle((x1, y1), (x2, y2), rfcolor)
buffer = bgl.Buffer(bgl.GL_BYTE, width * height * 4)
bgl.glReadBuffer(bgl.GL_COLOR_ATTACHMENT0)
bgl.glReadPixels(0, 0, width, height, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, buffer)
buffer = fb.read_color(0, 0, width, height, 4, 0, 'UBYTE')
buffer.dimensions = width * height * 4
offscreen.free()