From 355a9a40182a5cab64c9cfdea2f2b5b268bf3546 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Sat, 23 May 2015 13:37:55 -1000 Subject: [PATCH] Validate GL format only when creating a QGLWidget. QGLContext cannot be created on its own without using deprecated APIs to bind its output to a widget (or an offscreen render buffer, or a texture in an existing context...). So, allow QGLWidget to create the context and then validate it afterward. This also sets the default QGLFormat to require OpenGL 1.3 and hardware rendering (called "direct rendering" in QGLFormat) --- src/mcedit2/editorapp.py | 10 +++++----- src/mcedit2/util/qglcontext.py | 14 ++++++++------ src/mcedit2/worldview/worldview.py | 3 +++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/mcedit2/editorapp.py b/src/mcedit2/editorapp.py index 1f89edd..e1b46d6 100644 --- a/src/mcedit2/editorapp.py +++ b/src/mcedit2/editorapp.py @@ -20,7 +20,7 @@ from mcedit2.util.dialogs import NotImplementedYet from mcedit2.util.directories import getUserFilesDirectory, getUserPluginsDirectory from mcedit2.util.load_ui import load_ui from mcedit2.util.objgraphwidget import ObjGraphWidget -from mcedit2.util.qglcontext import validateQGLContext +from mcedit2.util.qglcontext import setDefaultFormat from mcedit2.util.resources import resourcePath from mcedit2.util.worldloader import LoaderTimer from mcedit2.widgets import prefsdialog, configureblocksdialog @@ -105,10 +105,6 @@ class MCEditApp(QtGui.QApplication): log.info("Loaded stylesheet.") - # --- OpenGL --- - - validateQGLContext() - # --- Main Window --- self.mainWindow = mainWindow = MCEditMainWindow() @@ -121,6 +117,10 @@ class MCEditApp(QtGui.QApplication): log.info("Loaded main window.") + # --- OpenGL --- + + setDefaultFormat() + # --- Sessions --- self._currentSession = None diff --git a/src/mcedit2/util/qglcontext.py b/src/mcedit2/util/qglcontext.py index fc72c2f..633f136 100644 --- a/src/mcedit2/util/qglcontext.py +++ b/src/mcedit2/util/qglcontext.py @@ -8,12 +8,13 @@ import logging log = logging.getLogger(__name__) - -def validateQGLContext(): +def setDefaultFormat(): oglFormat = QtOpenGL.QGLFormat() oglFormat.setVersion(1, 3) + oglFormat.setDirectRendering(True) QtOpenGL.QGLFormat.setDefaultFormat(oglFormat) - context = QtOpenGL.QGLContext(oglFormat) + +def validateQGLContext(context): context.makeCurrent() versionFlags = QtOpenGL.QGLFormat.openGLVersionFlags() log.info("OpenGL Version Info:") @@ -35,8 +36,8 @@ def validateQGLContext(): actualFormat = context.format() """:type : QtOpenGL.QGLFormat""" - - if (not versionFlags & QtOpenGL.QGLFormat.OpenGL_Version_1_3 + if (not context.isValid() or not actualFormat.directRendering() + or not versionFlags & QtOpenGL.QGLFormat.OpenGL_Version_1_3 or (actualFormat.majorVersion(), actualFormat.minorVersion()) < (1, 3)): msgBox = QtGui.QMessageBox() msgBox.setWindowTitle(QtGui.qApp.tr("OpenGL Error")) @@ -48,10 +49,11 @@ def validateQGLContext(): ) detailedText = "Obtained a GL context with this format:\n" + detailedText += "Valid: %s\n" % (context.isValid(),) detailedText += "Version: %s.%s\n" % (actualFormat.majorVersion(), actualFormat.minorVersion()) + detailedText += "Hardware Accelerated: %s\n" % (actualFormat.directRendering(), ) detailedText += "Depth buffer: %s, %s\n" % (actualFormat.depth(), actualFormat.depthBufferSize()) detailedText += "Double buffer: %s\n" % (actualFormat.doubleBuffer(), ) - detailedText += "Direct render: %s\n" % (actualFormat.directRendering(), ) detailedText += "\n" detailedText += "Driver info:\n" detailedText += "GL_VERSION: %s\n" % GL.glGetString(GL.GL_VERSION) diff --git a/src/mcedit2/worldview/worldview.py b/src/mcedit2/worldview/worldview.py index bf3f51f..4b0e169 100644 --- a/src/mcedit2/worldview/worldview.py +++ b/src/mcedit2/worldview/worldview.py @@ -23,6 +23,7 @@ from mcedit2.rendering.textureatlas import TextureAtlas from mcedit2.rendering.vertexarraybuffer import VertexArrayBuffer from mcedit2.rendering import scenegraph, rendergraph from mcedit2.util import profiler, raycast +from mcedit2.util.qglcontext import validateQGLContext from mcedit2.util.settings import Settings from mcedit2.widgets.infopanel import InfoPanel from mceditlib import faces, exceptions @@ -89,6 +90,8 @@ class WorldView(QGLWidget): :rtype: """ QGLWidget.__init__(self, shareWidget=sharedGLWidget) + validateQGLContext(self.context()) + self.setSizePolicy(QtGui.QSizePolicy.Policy.Expanding, QtGui.QSizePolicy.Policy.Expanding) self.setFocusPolicy(Qt.ClickFocus)