Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/iJunkie22/mcedit2
Browse files Browse the repository at this point in the history
  • Loading branch information
iJunkie22 committed Oct 3, 2020
2 parents ddb22ea + 9e822f6 commit 480bf71
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 26 deletions.
46 changes: 46 additions & 0 deletions src/mcedit2/util/directories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
import sys
try:
assert sys.platform == "win32"
# If sys.platform is "win32", win32api is needed and expected
import win32api
except AssertionError as _ae:
# If sys.platform is not "win32", do not try to import win32api
win32api = None

def getUserFilesDirectory():
if sys.platform == "win32":
# On Windows, sys.executable is codepage-encoded.
# It cannot represent all possible filenames, so get the exe filename
# using this wide-character API, which returns a `unicode`
exe = win32api.GetModuleFileNameW(None)
else:
# On OS X, the FS encoding is always UTF-8
# OS X filenames are defined to be UTF-8 encoded.
# On Linux, the FS encoding is given by the current locale
# Linux filenames are defined to be bytestrings.
exe = sys.executable.decode(sys.getfilesystemencoding())

assert os.path.exists(exe), "%r does not exist" % exe
if hasattr(sys, 'frozen'):
folder = os.path.dirname(exe)
else:
if exe.endswith("python") or exe.endswith("python.exe"):
script = sys.argv[0]
# assert the source checkout is not in a non-representable path...
assert os.path.exists(script), "Source checkout path cannot be represented with 'mbcs' encoding. Put the source checkout somewhere else."
folder = os.path.dirname(os.path.dirname(os.path.dirname(script))) # from src/mcedit, ../../
else:
folder = os.path.dirname(exe)

dataDir = os.path.join(folder, "MCEdit User Data")

if not os.path.exists(dataDir):
os.makedirs(dataDir)
return dataDir

def getUserSchematicsDirectory():
return os.path.join(getUserFilesDirectory(), "schematics")

def getUserPluginsDirectory():
return os.path.join(getUserFilesDirectory(), "plugins")
59 changes: 33 additions & 26 deletions src/mcedit2/util/qglcontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,66 @@
from OpenGL import GL
from PySide import QtOpenGL, QtGui
import logging
import re
from sys import platform

log = logging.getLogger(__name__)

_lastAcquiredContextInfo = None

def getContextInfo():
return _lastAcquiredContextInfo

def setDefaultFormat():
oglFormat = QtOpenGL.QGLFormat()
oglFormat.setVersion(1, 3)
oglFormat.setDirectRendering(True)
QtOpenGL.QGLFormat.setDefaultFormat(oglFormat)

def validateWidgetQGLContext(widget):
context = widget.context()
def validateQGLContext(context):
context.makeCurrent()
versionFlags = QtOpenGL.QGLFormat.openGLVersionFlags()
log.info("OpenGL Version Info:")
for flag in (
QtOpenGL.QGLFormat.OpenGL_Version_1_1,
QtOpenGL.QGLFormat.OpenGL_Version_1_2,
QtOpenGL.QGLFormat.OpenGL_Version_1_3,
QtOpenGL.QGLFormat.OpenGL_Version_1_4,
QtOpenGL.QGLFormat.OpenGL_Version_1_5,
QtOpenGL.QGLFormat.OpenGL_Version_2_0,
QtOpenGL.QGLFormat.OpenGL_Version_3_0,
QtOpenGL.QGLFormat.OpenGL_Version_3_1,
QtOpenGL.QGLFormat.OpenGL_Version_3_2,
QtOpenGL.QGLFormat.OpenGL_Version_3_3,
QtOpenGL.QGLFormat.OpenGL_Version_4_0,
):
if flag & versionFlags:
log.info(str(flag))

actualFormat = context.format()
""":type : QtOpenGL.QGLFormat"""

# Qt 4.8.6 on OS X always returns (1, 0) for the QGLFormat's major and minor versions.
# (QTBUG-40415)
# Check GL_VERSION instead.

version = GL.glGetString(GL.GL_VERSION)
match = re.match(r'^(\d+)\.(\d+)', version)
major, minor = match.groups()
major = int(major)
minor = int(minor)
def getmajor():
return int(str(GL.glGetString(GL.GL_VERSION)).split()[0].partition(".")[0])

def getminor():
return int(str(GL.glGetString(GL.GL_VERSION)).split()[0].partition(".")[2])

if platform == 'darwin':
actualFormat.majorVersion = getmajor
actualFormat.minorVersion = getminor

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 += "Rendering profile: %s\n" % (actualFormat.profile(), )
detailedText += "\n"
detailedText += "Driver info:\n"
detailedText += "GL_VERSION: %s (%s, %s)\n" % (version, major, minor)
detailedText += "GL_VENDOR: %r\n" % GL.glGetString(GL.GL_VENDOR)
detailedText += "GL_RENDERER: %r\n" % GL.glGetString(GL.GL_RENDERER)
detailedText += "GL_VERSION: %s\n" % GL.glGetString(GL.GL_VERSION)
detailedText += "GL_VENDOR: %s\n" % GL.glGetString(GL.GL_VENDOR)
detailedText += "GL_RENDERER: %s\n" % GL.glGetString(GL.GL_RENDERER)

log.info("%s", detailedText)
global _lastAcquiredContextInfo
_lastAcquiredContextInfo = detailedText
versionFlags = QtOpenGL.QGLFormat.openGLVersionFlags()


if (not context.isValid() or not actualFormat.directRendering()
or not versionFlags & QtOpenGL.QGLFormat.OpenGL_Version_1_3
or (major, minor) < (1, 3)):
or (actualFormat.majorVersion(), actualFormat.minorVersion()) < (1, 3)):
msgBox = QtGui.QMessageBox()
msgBox.setWindowTitle(QtGui.qApp.tr("OpenGL Error"))
msgBox.setStandardButtons(QtGui.QMessageBox.Close)
Expand Down

0 comments on commit 480bf71

Please sign in to comment.