From 1cf1f9aad7a56839ac2d9274f29fddf75f9475e5 Mon Sep 17 00:00:00 2001 From: QiuJiangkun Date: Fri, 13 Nov 2020 17:48:06 +0800 Subject: [PATCH 1/2] precise rendering for markers --- mplopengl/renderergl.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mplopengl/renderergl.py b/mplopengl/renderergl.py index 86df371..5eb89d3 100644 --- a/mplopengl/renderergl.py +++ b/mplopengl/renderergl.py @@ -15,7 +15,7 @@ from matplotlib.backends import backend_agg from matplotlib.font_manager import findfont, get_font from matplotlib.mathtext import MathTextParser -from matplotlib.path import get_paths_extents +from matplotlib.path import get_path_collection_extents from matplotlib.transforms import Affine2D MIN_LINE_WIDTH = 1.5 @@ -496,6 +496,7 @@ def __init__(self, width, height, dpi): self.particle_shader = Shader(vertexShaderSource, fragmentShaderSource, {"pos": 0, "shift": 4}, ["color", "trans"]) + self.gpu_marker_rendering_threshold = 10000 def option_image_nocomposite(self): return False @@ -606,13 +607,17 @@ def draw_markers(self, gc, marker_path, marker_trans, path, marker_path = marker_trans.transform_path(marker_path) polygons = self.path_to_poly(marker_path, rgbFace is not None) + precision = positions.shape[0] < self.gpu_marker_rendering_threshold + if precision: + positions = trans.transform(positions) arr_data = numpy.array(positions).astype(numpy.float32).tobytes() pos_vbo = self._gpu_cache(self.context, hash(arr_data), VBO, arr_data) with ObjectContext(self.particle_shader) as program, ClippingContext(gc): program.bind_attr_vbo("shift", pos_vbo) - program.set_uniform3m("trans", trans.get_matrix(), transpose=True) + program.set_uniform3m("trans", trans.get_matrix() if precision else Affine2D().get_matrix(), transpose=True) + program.set_attr_divisor("pos", 0) program.set_attr_divisor("shift", 1) From f828d17cd7b68856f92958e909456ebb6043445e Mon Sep 17 00:00:00 2001 From: QiuJiangkun Date: Fri, 13 Nov 2020 18:08:22 +0800 Subject: [PATCH 2/2] Bugfix --- mplopengl/renderergl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mplopengl/renderergl.py b/mplopengl/renderergl.py index 5eb89d3..a90e7cc 100644 --- a/mplopengl/renderergl.py +++ b/mplopengl/renderergl.py @@ -616,7 +616,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path, with ObjectContext(self.particle_shader) as program, ClippingContext(gc): program.bind_attr_vbo("shift", pos_vbo) - program.set_uniform3m("trans", trans.get_matrix() if precision else Affine2D().get_matrix(), transpose=True) + program.set_uniform3m("trans", Affine2D().get_matrix() if precision else trans.get_matrix(), transpose=True) program.set_attr_divisor("pos", 0) program.set_attr_divisor("shift", 1)