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)
This commit is contained in:
David Vierra 2015-05-23 13:37:55 -10:00
parent 747e936de6
commit 355a9a4018
3 changed files with 16 additions and 11 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)