1919bl_info = {
2020 "name" : "Depth of Field Utilities" ,
2121 "author" : "Christian Brinkmann (p2or)" ,
22- "description" : "Displays depth of field in 3D view port ." ,
23- "version" : (0 , 1 , 1 ),
24- "blender" : (2 , 80 , 0 ),
22+ "description" : "Displays depth of field in 3D viewport ." ,
23+ "version" : (0 , 1 , 2 ),
24+ "blender" : (3 , 5 , 0 ),
2525 "location" : "3d View > Properties Panel (N) > Depth of Field Utilities" ,
2626 "doc_url" : "https://github.com/p2or/blender-dof-utils" ,
2727 "tracker_url" : "https://github.com/p2or/blender-dof-utils/issues" ,
2828 "category" : "Render"
2929}
3030
3131import bpy
32- import bgl
3332import blf
3433import gpu
3534from gpu_extras .batch import batch_for_shader
@@ -225,25 +224,25 @@ def draw_callback_3d(operator, context):
225224 dofu .limits = (d , near_limit , far_limit )
226225
227226 # 80% alpha, 2 pixel width line
228- bgl .glEnable (bgl .GL_BLEND )
229- bgl .glEnable (bgl .GL_LINE_SMOOTH )
230- bgl .glEnable (bgl .GL_DEPTH_TEST )
231-
227+ gpu . state . blend_set ( 'ALPHA' ) # bgl.glEnable(bgl.GL_BLEND)
228+ # bgl.glEnable(bgl.GL_LINE_SMOOTH) # -> No replacement gpu.shader.from_builtin('POLYLINE_SMOOTH_COLOR' )
229+ gpu . state . depth_test_set ( "LESS" ) # bgl.glEnable(bgl.GL_DEPTH_TEST)
230+
232231 # check overlay
233232 if dofu .overlay :
234- bgl .glDisable (bgl .GL_DEPTH_TEST )
233+ gpu . state . depth_test_set ( "NONE" ) # bgl.glDisable(bgl.GL_DEPTH_TEST)
235234 else :
236- bgl .glEnable (bgl .GL_DEPTH_TEST )
235+ gpu . state . depth_test_set ( "LESS" ) # bgl.glEnable(bgl.GL_DEPTH_TEST)
237236
238237 # set line width
239- bgl .glLineWidth (2 )
238+ gpu . state . line_width_set ( 2 ) # bgl.glLineWidth(2)
240239
241240 def line (color , start , end ):
242241 vertices = [start ,end ]
243242 shader = gpu .shader .from_builtin ('3D_UNIFORM_COLOR' )
244243 batch = batch_for_shader (shader ,'LINE_STRIP' , {"pos" : vertices })
245244 shader .bind ()
246- shader .uniform_float ("color" ,color )
245+ shader .uniform_float ("color" , color )
247246 batch .draw (shader )
248247 #bgl.glColor4f(*color)
249248 #bgl.glBegin(bgl.GL_LINES)
@@ -274,22 +273,18 @@ def line(color, start, end):
274273 size = dofu .size_limits * 1.7 ,
275274 color = (dofu .color_limits [0 ], dofu .color_limits [1 ], dofu .color_limits [2 ], dofu .opacity_limits ))
276275
277- # restore opengl defaults
278- bgl .glLineWidth (1 )
279- bgl .glDisable (bgl .GL_BLEND )
280- bgl .glDisable (bgl .GL_LINE_SMOOTH )
281- bgl .glEnable (bgl .GL_DEPTH_TEST )
282- #bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
283-
276+ # restore defaults
277+ gpu .state .line_width_set (1.0 )
278+ gpu .state .blend_set ('NONE' )
284279
285280def draw_string (x , y , packed_strings ):
286281 font_id = 0
287- blf .size (font_id , 17 , 70 )
282+ blf .size (font_id , 17 * ( bpy . context . preferences . system . dpi / 72 ))
288283 x_offset = 0
289284 for pstr , pcol in packed_strings :
290- #bgl.glColor4f(*pcol)
291285 text_width , text_height = blf .dimensions (font_id , pstr )
292286 blf .position (font_id , (x + x_offset ), y , 0 )
287+ blf .color (font_id , * pcol )
293288 blf .draw (font_id , pstr )
294289 x_offset += text_width
295290
@@ -314,7 +309,7 @@ def draw_poly(coords, color, width):
314309 # Create batch process
315310 batch = batch_for_shader (shader ,'LINE_STRIP' , {"pos" : coords })
316311 # Set the line width
317- bgl .glLineWidth (width )
312+ gpu . state . line_width_set ( width ) # bgl.glLineWidth(width)
318313 shader .bind ()
319314 # Set color
320315 shader .uniform_float ("color" ,color )
0 commit comments