[higan] 01/01: Replace OpenGL version check by X error handler.

Tobias Hansen thansen at moszumanska.debian.org
Sun Jun 28 11:42:05 UTC 2015


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository higan.

commit 8801b2cfbfff3779cca9a3fa604e33b578487f29
Author: Tobias Hansen <thansen at localhost.localdomain>
Date:   Sun Jun 28 13:39:18 2015 +0200

    Replace OpenGL version check by X error handler.
---
 debian/changelog                           | 11 ++++-
 debian/patches/check-opengl-version.patch  | 45 ---------------------
 debian/patches/handle-opengl-x-error.patch | 64 ++++++++++++++++++++++++++++++
 debian/patches/series                      |  2 +-
 4 files changed, 74 insertions(+), 48 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index d92dd22..6e3dfbb 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,8 +1,15 @@
 higan (094-6) UNRELEASED; urgency=medium
 
   * Create debian/watch.
-
- -- Tobias Hansen <thansen at debian.org>  Sun, 02 Nov 2014 01:22:00 +0100
+  * Instead of checking for the available OpenGL version,
+    try creating an OpenGL 3.2 context and handle possible X errors.
+    The previous check would find the OpenGL compatibility profile version
+    which can be lower than the core profile version (e.g. when using Mesa)
+    leading to false positives.
+    - Remove check-opengl-version.patch
+    - Add handle-opengl-x-error.patch
+
+ -- Tobias Hansen <thansen at debian.org>  Sun, 28 Jun 2015 12:43:15 +0200
 
 higan (094-5) unstable; urgency=medium
 
diff --git a/debian/patches/check-opengl-version.patch b/debian/patches/check-opengl-version.patch
deleted file mode 100644
index ac2c7b6..0000000
--- a/debian/patches/check-opengl-version.patch
+++ /dev/null
@@ -1,45 +0,0 @@
-Description: Check OpenGL version
- Without this higan just crashes when the
- driver does not support OpenGL 3.2.
- Code to extract the version from the
- version string taken from cairo-gl-info.c
-Author: Tobias Hansen <thansen at debian.org>
-
---- a/ruby/video/glx.cpp
-+++ b/ruby/video/glx.cpp
-@@ -1,4 +1,6 @@
- #include "opengl/opengl.hpp"
-+#include "emulator/emulator.hpp"
-+#include "target-ethos/interface/interface.hpp"
- 
- #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
- #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
-@@ -174,6 +176,28 @@
-     glxcontext = glXCreateContext(display, vi, /* sharelist = */ 0, /* direct = */ GL_TRUE);
-     glXMakeCurrent(display, glxwindow = xwindow, glxcontext);
- 
-+    int major, minor;
-+    const char *version = (const char *) glGetString (GL_VERSION);
-+    const char *dot = version == NULL ? NULL : strchr (version, '.');
-+    const char *major_start = dot;
-+
-+    /* Sanity check */
-+    if (dot == NULL || dot == version || *(dot + 1) == '\0') {
-+        major = 0;
-+        minor = 0;
-+    } else {
-+    /* Find the start of the major version in the string */
-+    while (major_start > version && *major_start != ' ')
-+           --major_start;
-+        major = strtol (major_start, NULL, 10);
-+        minor = strtol (dot + 1, NULL, 10);
-+    }
-+
-+    if(major < 3 || (major == 3 && minor < 2)) {
-+        interface->notify("Error: OpenGL 3.2 is not available. Select another video driver on the Advanced Configuration tab and restart higan.\n");
-+        return false;
-+    }
-+
-     glXCreateContextAttribs = (GLXContext (*)(Display*, GLXFBConfig, GLXContext, int, const int*))glGetProcAddress("glXCreateContextAttribsARB");
-     glXSwapInterval = (int (*)(int))glGetProcAddress("glXSwapIntervalSGI");
-     if(!glXSwapInterval) glXSwapInterval = (int (*)(int))glGetProcAddress("glXSwapIntervalMESA");
diff --git a/debian/patches/handle-opengl-x-error.patch b/debian/patches/handle-opengl-x-error.patch
new file mode 100644
index 0000000..cb73ffb
--- /dev/null
+++ b/debian/patches/handle-opengl-x-error.patch
@@ -0,0 +1,64 @@
+Description: Handle possible X error when creating OpenGL context
+ Without this higan just crashes when the driver does
+ not support OpenGL 3.2 and context creation fails. 
+Author: Tobias Hansen <thansen at debian.org>
+
+--- a/ruby/video/glx.cpp
++++ b/ruby/video/glx.cpp
+@@ -1,10 +1,19 @@
+ #include "opengl/opengl.hpp"
++#include "emulator/emulator.hpp"
++#include "target-ethos/interface/interface.hpp"
+ 
+ #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
+ #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
+ 
+ namespace ruby {
+ 
++static bool ctxErrorOccurred = false;
++static int ctxErrorHandler( Display *dpy, XErrorEvent *ev )
++{
++    ctxErrorOccurred = true;
++    return 0;
++}
++
+ struct pVideoGLX : OpenGL {
+   GLXContext (*glXCreateContextAttribs)(Display*, GLXFBConfig, GLXContext, int, const int*) = nullptr;
+   int (*glXSwapInterval)(int) = nullptr;
+@@ -171,6 +180,10 @@
+       XNextEvent(display, &event);
+     }
+ 
++    // Install X error handler to prevent a crash in case context creation fails.
++    ctxErrorOccurred = false;
++    int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&ctxErrorHandler);
++
+     glxcontext = glXCreateContext(display, vi, /* sharelist = */ 0, /* direct = */ GL_TRUE);
+     glXMakeCurrent(display, glxwindow = xwindow, glxcontext);
+ 
+@@ -185,13 +198,24 @@
+         None
+       };
+       GLXContext context = glXCreateContextAttribs(display, fbConfig[0], nullptr, true, attributes);
+-      if(context) {
++
++      // Sync to ensure any errors generated are processed.
++      XSync( display, False );
++      if ( !ctxErrorOccurred && context ) {
+         glXMakeCurrent(display, 0, nullptr);
+         glXDestroyContext(display, glxcontext);
+         glXMakeCurrent(display, glxwindow, glxcontext = context);
+       }
+     }
+ 
++    XSync( display, False );
++    // Restore the original error handler.
++    XSetErrorHandler( oldHandler );
++    if ( ctxErrorOccurred ) {
++        interface->notify("Error: Creation of an OpenGL 3.2 context failed. Select another video driver on the Advanced Configuration tab and restart higan.\n");
++        return false;
++    }
++
+     if(glXSwapInterval) {
+       glXSwapInterval(settings.synchronize);
+     }
diff --git a/debian/patches/series b/debian/patches/series
index d1ad2b1..8fd4f61 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -3,9 +3,9 @@ makefile-fixes.patch
 load-private-libraries.patch
 desktop-file.patch
 force-button-images.patch
-check-opengl-version.patch
 sjlj-declare-xopen-source.patch
 noopt-nostrip.patch
 fc-heuristic-error.patch
 dt_lnk-dt_unknown.patch
 use-XDG_CONFIG_HOME.patch
+handle-opengl-x-error.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/higan.git



More information about the Pkg-games-commits mailing list