Make version.opengl_vendor() work with an existing context

This makes it possible to use it in :debug-console
This commit is contained in:
Florian Bruhin 2017-06-04 23:05:23 +02:00
parent a858611bb9
commit 4d64bcc852

View File

@ -391,7 +391,9 @@ def opengl_vendor(): # pragma: no cover
from PyQt5.QtGui import (QOpenGLContext, QOpenGLVersionProfile,
QOffscreenSurface)
assert QApplication.instance()
assert QOpenGLContext.currentContext() is None
old_context = QOpenGLContext.currentContext()
old_surface = None if old_context is None else old_context.surface()
surface = QOffscreenSurface()
surface.create()
@ -418,4 +420,7 @@ def opengl_vendor(): # pragma: no cover
vendor = vf.glGetString(vf.GL_VENDOR)
ctx.doneCurrent()
if old_context and old_surface:
old_context.makeCurrent(old_surface)
return vendor