diff options
Diffstat (limited to 'silx/gui/plot/backends/glutils/GLText.py')
-rw-r--r-- | silx/gui/plot/backends/glutils/GLText.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/silx/gui/plot/backends/glutils/GLText.py b/silx/gui/plot/backends/glutils/GLText.py index 3d262bc..725c12c 100644 --- a/silx/gui/plot/backends/glutils/GLText.py +++ b/silx/gui/plot/backends/glutils/GLText.py @@ -1,7 +1,7 @@ # coding: utf-8 # /*########################################################################## # -# Copyright (c) 2014-2018 European Synchrotron Radiation Facility +# Copyright (c) 2014-2019 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -33,9 +33,11 @@ __date__ = "03/04/2017" from collections import OrderedDict +import weakref + import numpy -from ...._glutils import font, gl, getGLContext, Program, Texture +from ...._glutils import font, gl, Context, Program, Texture from .GLSupport import mat4Translate @@ -128,7 +130,7 @@ class Text2D(object): attrib0='position') # Discard texture objects when removed from the cache - _textures = _Cache(callback=lambda key, value: value[0].discard()) + _textures = weakref.WeakKeyDictionary() """Cache already created textures""" _sizes = _Cache() @@ -159,15 +161,20 @@ class Text2D(object): self._rotate = numpy.radians(rotate) def _getTexture(self, text): - key = getGLContext(), text - - if key not in self._textures: + # Retrieve/initialize texture cache for current context + context = Context.getCurrent() + if context not in self._textures: + self._textures[context] = _Cache( + callback=lambda key, value: value[0].discard()) + textures = self._textures[context] + + if text not in textures: image, offset = font.rasterText(text, font.getDefaultFontFamily()) if text not in self._sizes: self._sizes[text] = image.shape[1], image.shape[0] - self._textures[key] = ( + textures[text] = ( Texture(gl.GL_RED, data=image, minFilter=gl.GL_NEAREST, @@ -176,7 +183,7 @@ class Text2D(object): gl.GL_CLAMP_TO_EDGE)), offset) - return self._textures[key] + return textures[text] @property def text(self): |