Commit b1dbec84 authored by Luke Campagnola's avatar Luke Campagnola
Browse files

Added checks for OpenGL version and 3D texture size limits

Added script for reporting GL version info
parent 6d01aa2b
...@@ -29,12 +29,18 @@ class GLViewWidget(QtOpenGL.QGLWidget): ...@@ -29,12 +29,18 @@ class GLViewWidget(QtOpenGL.QGLWidget):
self.keysPressed = {} self.keysPressed = {}
self.keyTimer = QtCore.QTimer() self.keyTimer = QtCore.QTimer()
self.keyTimer.timeout.connect(self.evalKeyState) self.keyTimer.timeout.connect(self.evalKeyState)
self.makeCurrent()
def addItem(self, item): def addItem(self, item):
self.items.append(item) self.items.append(item)
if hasattr(item, 'initializeGL'): if hasattr(item, 'initializeGL'):
self.makeCurrent() self.makeCurrent()
item.initializeGL() try:
item.initializeGL()
except:
self.checkOpenGLVersion('Error while adding item %s to GLViewWidget.' % str(item))
item._setView(self) item._setView(self)
#print "set view", item, self, item.view() #print "set view", item, self, item.view()
self.update() self.update()
...@@ -100,9 +106,15 @@ class GLViewWidget(QtOpenGL.QGLWidget): ...@@ -100,9 +106,15 @@ class GLViewWidget(QtOpenGL.QGLWidget):
glPushAttrib(GL_ALL_ATTRIB_BITS) glPushAttrib(GL_ALL_ATTRIB_BITS)
i.paint() i.paint()
except: except:
import sys import pyqtgraph.debug
sys.excepthook(*sys.exc_info()) pyqtgraph.debug.printExc()
print("Error while drawing item", i) msg = "Error while drawing item %s." % str(item)
ver = glGetString(GL_VERSION).split()[0]
if int(ver.split('.')[0]) < 2:
print(msg + " The original exception is printed above; however, pyqtgraph requires OpenGL version 2.0 or greater for many of its 3D features and your OpenGL version is %s. Installing updated display drivers may resolve this issue." % ver)
else:
print(msg)
finally: finally:
glPopAttrib(GL_ALL_ATTRIB_BITS) glPopAttrib(GL_ALL_ATTRIB_BITS)
else: else:
...@@ -237,4 +249,15 @@ class GLViewWidget(QtOpenGL.QGLWidget): ...@@ -237,4 +249,15 @@ class GLViewWidget(QtOpenGL.QGLWidget):
else: else:
self.keyTimer.stop() self.keyTimer.stop()
def checkOpenGLVersion(self, msg):
## Only to be called from within exception handler.
ver = glGetString(GL_VERSION).split()[0]
if int(ver.split('.')[0]) < 2:
import pyqtgraph.debug
pyqtgraph.debug.printExc()
raise Exception(msg + " The original exception is printed above; however, pyqtgraph requires OpenGL version 2.0 or greater for many of its 3D features and your OpenGL version is %s. Installing updated display drivers may resolve this issue." % ver)
else:
raise
\ No newline at end of file
from pyqtgraph.Qt import QtCore, QtGui, QtOpenGL
from OpenGL.GL import *
app = QtGui.QApplication([])
class GLTest(QtOpenGL.QGLWidget):
def __init__(self):
QtOpenGL.QGLWidget.__init__(self)
self.makeCurrent()
print "GL version:", glGetString(GL_VERSION)
print "MAX_TEXTURE_SIZE:", glGetIntegerv(GL_MAX_TEXTURE_SIZE)
print "MAX_3D_TEXTURE_SIZE:", glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE)
print "Extensions:", glGetString(GL_EXTENSIONS)
GLTest()
...@@ -43,6 +43,11 @@ class GLVolumeItem(GLGraphicsItem): ...@@ -43,6 +43,11 @@ class GLVolumeItem(GLGraphicsItem):
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER) glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER)
shape = self.data.shape shape = self.data.shape
## Test texture dimensions first
glTexImage3D(GL_PROXY_TEXTURE_3D, 0, GL_RGBA, shape[0], shape[1], shape[2], 0, GL_RGBA, GL_UNSIGNED_BYTE, None)
if glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH) == 0:
raise Exception("OpenGL failed to create 3D texture (%dx%dx%d); too large for this hardware." % shape[:3])
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, shape[0], shape[1], shape[2], 0, GL_RGBA, GL_UNSIGNED_BYTE, self.data.transpose((2,1,0,3))) glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, shape[0], shape[1], shape[2], 0, GL_RGBA, GL_UNSIGNED_BYTE, self.data.transpose((2,1,0,3)))
glDisable(GL_TEXTURE_3D) glDisable(GL_TEXTURE_3D)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment