From e28ba6b98c25199d9e60defbae30865c33efd166 Mon Sep 17 00:00:00 2001 From: mano-wii Date: Sat, 25 May 2019 09:41:29 -0300 Subject: mesh_snap_utilities_line: Fix point size drawing. --- mesh_snap_utilities_line/__init__.py | 2 +- mesh_snap_utilities_line/drawing_utilities.py | 20 ++++++++++---------- mesh_snap_utilities_line/snap_context_l/__init__.py | 12 ++++++++++-- 3 files changed, 21 insertions(+), 13 deletions(-) (limited to 'mesh_snap_utilities_line') diff --git a/mesh_snap_utilities_line/__init__.py b/mesh_snap_utilities_line/__init__.py index 0092ebe6..14c149d8 100644 --- a/mesh_snap_utilities_line/__init__.py +++ b/mesh_snap_utilities_line/__init__.py @@ -22,7 +22,7 @@ bl_info = { "name": "Snap_Utilities_Line", "author": "Germano Cavalcante", - "version": (5, 9, 12), + "version": (5, 9, 14), "blender": (2, 80, 0), "location": "View3D > TOOLS > Line Tool", "description": "Extends Blender Snap controls", diff --git a/mesh_snap_utilities_line/drawing_utilities.py b/mesh_snap_utilities_line/drawing_utilities.py index 0ce679c6..c2e7dab2 100644 --- a/mesh_snap_utilities_line/drawing_utilities.py +++ b/mesh_snap_utilities_line/drawing_utilities.py @@ -33,6 +33,7 @@ class SnapDrawn(): 'axis_z_color', '_format_pos', '_format_pos_and_color', + '_is_point_size_enabled', '_program_unif_col', '_program_smooth_col', '_batch_point', @@ -69,7 +70,6 @@ class SnapDrawn(): self._batch_point = None - def batch_line_strip_create(self, coords): from gpu.types import ( GPUVertBuf, @@ -118,8 +118,7 @@ class SnapDrawn(): def draw(self, type, location, list_verts_co, vector_constrain, prevloc): import gpu - # draw 3d point OpenGL in the 3D View - bgl.glEnable(bgl.GL_BLEND) + self._gl_state_push() gpu.matrix.push() self._program_unif_col.bind() @@ -139,7 +138,7 @@ class SnapDrawn(): point_batch = self.batch_point_get() if vector_constrain: if prevloc: - bgl.glPointSize(5) + bgl.glPointSize(5.0) gpu.matrix.translate(prevloc) self._program_unif_col.uniform_float("color", (1.0, 1.0, 1.0, 0.5)) point_batch.draw(self._program_unif_col) @@ -169,7 +168,7 @@ class SnapDrawn(): else: # type == None Color4f = self.out_color - bgl.glPointSize(10) + bgl.glPointSize(10.0) gpu.matrix.translate(location) self._program_unif_col.uniform_float("color", Color4f) @@ -180,9 +179,9 @@ class SnapDrawn(): bgl.glPointSize(1.0) bgl.glLineWidth(1.0) bgl.glEnable(bgl.GL_DEPTH_TEST) - bgl.glDisable(bgl.GL_BLEND) gpu.matrix.pop() + self._gl_state_restore() def draw_elem(self, snap_obj, bm, elem): #TODO: Cache coords (because antialiasing) @@ -192,11 +191,11 @@ class SnapDrawn(): BMEdge, BMFace, ) - # draw 3d point OpenGL in the 3D View - bgl.glEnable(bgl.GL_BLEND) - bgl.glDisable(bgl.GL_DEPTH_TEST) with gpu.matrix.push_pop(): + self._gl_state_push() + bgl.glDisable(bgl.GL_DEPTH_TEST) + gpu.matrix.multiply_matrix(snap_obj.mat) if isinstance(elem, BMVert): @@ -239,4 +238,5 @@ class SnapDrawn(): # restore opengl defaults bgl.glEnable(bgl.GL_DEPTH_TEST) - bgl.glDisable(bgl.GL_BLEND) + + self._gl_state_restore() diff --git a/mesh_snap_utilities_line/snap_context_l/__init__.py b/mesh_snap_utilities_line/snap_context_l/__init__.py index aed904f6..9d879a82 100644 --- a/mesh_snap_utilities_line/snap_context_l/__init__.py +++ b/mesh_snap_utilities_line/snap_context_l/__init__.py @@ -507,6 +507,12 @@ class SnapContext(): #bgl.glDisable(bgl.GL_MULTISAMPLE) bgl.glEnable(bgl.GL_DEPTH_TEST) + is_point_size_enabled = bgl.glIsEnabled(bgl.GL_PROGRAM_POINT_SIZE) + if is_point_size_enabled: + bgl.glDisable(bgl.GL_PROGRAM_POINT_SIZE) + + bgl.glPointSize(4.0) + proj_mat = self.rv3d.perspective_matrix.copy() if self.proj_mat != proj_mat: self.proj_mat = proj_mat @@ -570,10 +576,12 @@ class SnapContext(): if snap_obj: ret = self._get_loc(snap_obj, index) - bgl.glDisable(bgl.GL_DEPTH_TEST) + if is_point_size_enabled: + bgl.glEnable(bgl.GL_PROGRAM_POINT_SIZE) - self._offscreen.unbind() + bgl.glDisable(bgl.GL_DEPTH_TEST) _Internal.gpu_Indices_restore_state() + self._offscreen.unbind() return (snap_obj, *ret) -- cgit v1.2.3