object_collection_manager: replace deprecated bgl module #104547

Closed
Oxicid wants to merge 4 commits from (deleted):oxicid-cm-bgl into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 15 additions and 25 deletions

View File

@ -6,8 +6,8 @@ bl_info = {
"name": "Collection Manager", "name": "Collection Manager",
"description": "Manage collections and their objects", "description": "Manage collections and their objects",
"author": "Ryan Inch", "author": "Ryan Inch",
"version": (2, 24, 4), "version": (2, 24, 5),
"blender": (2, 80, 0), "blender": (2, 93, 0),
Imaginer marked this conversation as resolved Outdated

I like to keep this to the minimum version of Blender the add-on will work with, which from my tests just now on Linux seems to be 2.93. So unless this is different on other platforms could you please set it to 2.93?

I like to keep this to the minimum version of Blender the add-on will work with, which from my tests just now on Linux seems to be 2.93. So unless this is different on other platforms could you please set it to 2.93?

I looked more closely, everything is involved.
About the minimum version, I just do not know which version introduced new methods for gpu module, and decided to set it to 3.4 for sure. To be sure I checked with 2.93, everything works

I looked more closely, everything is involved. About the minimum version, I just do not know which version introduced new methods for gpu module, and decided to set it to 3.4 for sure. To be sure I checked with 2.93, everything works

Ah, okay. Makes sense. Thanks for changing it and the additional checking.

Ah, okay. Makes sense. Thanks for changing it and the additional checking.
"location": "View3D - Object Mode (Shortcut - M)", "location": "View3D - Object Mode (Shortcut - M)",
"warning": '', # used for warning icon and text in addons panel "warning": '', # used for warning icon and text in addons panel
"doc_url": "{BLENDER_MANUAL_URL}/addons/interface/collection_manager.html", "doc_url": "{BLENDER_MANUAL_URL}/addons/interface/collection_manager.html",

View File

@ -764,7 +764,7 @@ class CMSendReport(Operator):
if length > max_len: if length > max_len:
max_len = length max_len = length
return wm.invoke_popup(self, width=(30 + (max_len*5.5))) return wm.invoke_popup(self, width=int(30 + (max_len*5.5)))
def execute(self, context): def execute(self, context):
self.report({'INFO'}, self.message) self.report({'INFO'}, self.message)

View File

@ -5,7 +5,6 @@
import time import time
from math import cos, sin, pi, floor from math import cos, sin, pi, floor
import bpy import bpy
import bgl
import blf import blf
import gpu import gpu
from gpu_extras.batch import batch_for_shader from gpu_extras.batch import batch_for_shader
@ -91,15 +90,13 @@ def draw_rounded_rect(area, shader, color, tl=5, tr=5, bl=5, br=5, outline=False
bl = round(bl * scale_factor()) bl = round(bl * scale_factor())
br = round(br * scale_factor()) br = round(br * scale_factor())
bgl.glEnable(bgl.GL_BLEND) gpu.state.blend_set('ALPHA')
if outline: if outline:
thickness = round(2 * scale_factor()) thickness = round(2 * scale_factor())
thickness = max(thickness, 2) thickness = max(thickness, 2)
bgl.glLineWidth(thickness) gpu.state.line_width_set(thickness)

line_width_set should no longer be used.

`line_width_set` should no longer be used.
bgl.glEnable(bgl.GL_LINE_SMOOTH)
bgl.glHint(bgl.GL_LINE_SMOOTH_HINT, bgl.GL_NICEST)
draw_type = 'TRI_FAN' if not outline else 'LINE_STRIP' draw_type = 'TRI_FAN' if not outline else 'LINE_STRIP'
@ -296,9 +293,8 @@ def draw_rounded_rect(area, shader, color, tl=5, tr=5, bl=5, br=5, outline=False
batch = batch_for_shader(shader, 'LINE_STRIP', {"pos": vertices}) batch = batch_for_shader(shader, 'LINE_STRIP', {"pos": vertices})
batch.draw(shader) batch.draw(shader)
bgl.glDisable(bgl.GL_LINE_SMOOTH)
bgl.glDisable(bgl.GL_BLEND) gpu.state.blend_set('NONE')
def mouse_in_area(mouse_pos, area, buf = 0): def mouse_in_area(mouse_pos, area, buf = 0):
x = mouse_pos[0] x = mouse_pos[0]
@ -844,11 +840,11 @@ def draw_callback_px(self, context):
shader.uniform_float("color", icon_color[:] + (1,)) shader.uniform_float("color", icon_color[:] + (1,))
batch = batch_for_shader(shader, 'TRI_FAN', {"pos": vertices}) batch = batch_for_shader(shader, 'TRI_FAN', {"pos": vertices})
bgl.glEnable(bgl.GL_BLEND) gpu.state.blend_set('ALPHA')
batch.draw(shader) batch.draw(shader)
bgl.glDisable(bgl.GL_BLEND) gpu.state.blend_set('NONE')
# SELECTED OBJECTS # SELECTED OBJECTS
elif not set(selected_objects).isdisjoint(collection_objects): elif not set(selected_objects).isdisjoint(collection_objects):
@ -859,15 +855,12 @@ def draw_callback_px(self, context):
shader.uniform_float("color", icon_color[:] + (alpha,)) shader.uniform_float("color", icon_color[:] + (alpha,))
batch = batch_for_shader(shader, 'LINE_STRIP', {"pos": vertices}) batch = batch_for_shader(shader, 'LINE_STRIP', {"pos": vertices})
bgl.glLineWidth(2 * scale_factor()) gpu.state.line_width_set(2 * scale_factor())
bgl.glEnable(bgl.GL_BLEND) gpu.state.blend_set('ALPHA')
bgl.glEnable(bgl.GL_LINE_SMOOTH)
bgl.glHint(bgl.GL_LINE_SMOOTH_HINT, bgl.GL_NICEST)
batch.draw(shader) batch.draw(shader)
bgl.glDisable(bgl.GL_LINE_SMOOTH) gpu.state.blend_set('NONE')
bgl.glDisable(bgl.GL_BLEND)
# OBJECTS # OBJECTS
elif collection_objects: elif collection_objects:
@ -878,11 +871,11 @@ def draw_callback_px(self, context):
shader.uniform_float("color", icon_color[:] + (alpha,)) shader.uniform_float("color", icon_color[:] + (alpha,))
batch = batch_for_shader(shader, 'TRIS', {"pos": vertices}, indices=indices) batch = batch_for_shader(shader, 'TRIS', {"pos": vertices}, indices=indices)
bgl.glEnable(bgl.GL_BLEND) gpu.state.blend_set('ALPHA')
batch.draw(shader) batch.draw(shader)
bgl.glDisable(bgl.GL_BLEND) gpu.state.blend_set('NONE')
# X ICON # X ICON
@ -894,14 +887,11 @@ def draw_callback_px(self, context):
shader.uniform_float("color", X_icon_color[:] + (1,)) shader.uniform_float("color", X_icon_color[:] + (1,))
batch = batch_for_shader(shader, 'TRIS', {"pos": vertices}, indices=indices) batch = batch_for_shader(shader, 'TRIS', {"pos": vertices}, indices=indices)
bgl.glEnable(bgl.GL_BLEND) gpu.state.blend_set('ALPHA')
bgl.glEnable(bgl.GL_POLYGON_SMOOTH)
bgl.glHint(bgl.GL_POLYGON_SMOOTH_HINT, bgl.GL_NICEST)
batch.draw(shader) batch.draw(shader)
bgl.glDisable(bgl.GL_POLYGON_SMOOTH) gpu.state.blend_set('NONE')
bgl.glDisable(bgl.GL_BLEND)
if in_tooltip_area: if in_tooltip_area:
if self.draw_tooltip: if self.draw_tooltip: