diff --git a/pyqtgraph/opengl/GLGraphicsItem.py b/pyqtgraph/opengl/GLGraphicsItem.py index a2c2708a..bf9de81a 100644 --- a/pyqtgraph/opengl/GLGraphicsItem.py +++ b/pyqtgraph/opengl/GLGraphicsItem.py @@ -1,8 +1,7 @@ from OpenGL.GL import * from OpenGL import GL -from ..Qt import QtGui, QtCore +from ..Qt import QtCore from .. import Transform3D -from ..python2_3 import basestring GLOptions = { @@ -42,6 +41,7 @@ class GLGraphicsItem(QtCore.QObject): self.__children = set() self.__transform = Transform3D() self.__visible = True + self.__initialized = False self.setParentItem(parentItem) self.setDepthValue(0) self.__glOpts = {} @@ -91,7 +91,7 @@ class GLGraphicsItem(QtCore.QObject): """ - if isinstance(opts, basestring): + if isinstance(opts, str): opts = GLOptions[opts] self.__glOpts = opts.copy() self.update() @@ -228,6 +228,11 @@ class GLGraphicsItem(QtCore.QObject): view, as it may be obscured or outside of the current view area.""" return self.__visible + def setInitialized(self, init=True): + self.__initialized = init + + def initialized(self): + return self.__initialized def initializeGL(self): """ @@ -235,7 +240,7 @@ class GLGraphicsItem(QtCore.QObject): The widget's GL context is made current before this method is called. (So this would be an appropriate time to generate lists, upload textures, etc.) """ - pass + self.setInitialized() def setupGLState(self): """ @@ -245,7 +250,7 @@ class GLGraphicsItem(QtCore.QObject): for k,v in self.__glOpts.items(): if v is None: continue - if isinstance(k, basestring): + if isinstance(k, str): func = getattr(GL, k) func(*v) else: diff --git a/pyqtgraph/opengl/GLViewWidget.py b/pyqtgraph/opengl/GLViewWidget.py index 8896bdc0..61a7d445 100644 --- a/pyqtgraph/opengl/GLViewWidget.py +++ b/pyqtgraph/opengl/GLViewWidget.py @@ -8,7 +8,6 @@ import warnings from math import cos, sin, tan, radians ##Vector = QtGui.QVector3D -ShareWidget = None class GLViewWidget(QtWidgets.QOpenGLWidget): @@ -99,10 +98,12 @@ class GLViewWidget(QtWidgets.QOpenGLWidget): def addItem(self, item): self.items.append(item) - if hasattr(item, 'initializeGL'): + + if self.isValid(): self.makeCurrent() try: item.initializeGL() + item.setInitialized() except: self.checkOpenGLVersion('Error while adding item %s to GLViewWidget.' % str(item)) @@ -128,7 +129,10 @@ class GLViewWidget(QtWidgets.QOpenGLWidget): self.update() def initializeGL(self): - self.resizeGL(self.width(), self.height()) + for item in self.items: + if not item.initialized(): + item.initializeGL() + item.setInitialized() def setBackgroundColor(self, *args, **kwds): """