diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 148: CanvasX11: Check GL version string to ensure that OpenGL(ES) 2.0 is really supported.

Message ID 20110929130812.5097.48910.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org Sept. 29, 2011, 1:08 p.m. UTC
------------------------------------------------------------
revno: 148
fixes bug: https://launchpad.net/bugs/842279
committer: Alexandros Frantzis <alexandros.frantzis@linaro.org>
branch nick: lp-842279
timestamp: Thu 2011-09-29 16:05:21 +0300
message:
  CanvasX11: Check GL version string to ensure that OpenGL(ES) 2.0 is really supported.
  
  When running glmark2 on older hardware (OpenGL 1.x compatible) leads to a
  crash.  This commit checks that OpenGL(ES) 2.0 is really supported before
  trying to execute any OpenGL(ES) 2.0 only code and fails gracefully if it's not
  supported (LP #842279).
modified:
  src/canvas-x11.cpp
  src/canvas-x11.h


--
lp:glmark2
https://code.launchpad.net/~glmark2-dev/glmark2/trunk

You are subscribed to branch lp:glmark2.
To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'src/canvas-x11.cpp'
--- src/canvas-x11.cpp	2011-09-09 11:24:17 +0000
+++ src/canvas-x11.cpp	2011-09-29 13:05:21 +0000
@@ -22,6 +22,7 @@ 
 #include "canvas-x11.h"
 #include "log.h"
 #include "options.h"
+#include "util.h"
 
 #include <X11/keysym.h>
 #include <fstream>
@@ -84,6 +85,13 @@ 
     if (!make_current())
         return false;
 
+    if (!supports_gl2()) {
+        Log::error("Glmark2 needs OpenGL(ES) version >= 2.0 to run"
+                   " (but version string is: '%s')!\n",
+                   glGetString(GL_VERSION));
+        return false;
+    }
+
     glEnable(GL_DEPTH_TEST);
     glDepthFunc(GL_LEQUAL);
     glEnable(GL_CULL_FACE);
@@ -212,3 +220,28 @@ 
     mProjection = LibMatrix::Mat4::perspective(60.0, mWidth / (float)mHeight,
                                                1.0, 1024.0);
 }
+
+bool
+CanvasX11::supports_gl2()
+{ 
+    std::string gl_version_str(reinterpret_cast<const char*>(glGetString(GL_VERSION)));
+    int gl_major(0);
+
+    size_t point_pos(gl_version_str.find('.'));
+
+    if (point_pos != std::string::npos) {
+        point_pos--;
+
+        size_t start_pos(gl_version_str.rfind(' ', point_pos));
+        if (start_pos == std::string::npos)
+            start_pos = 0;
+        else
+            start_pos++;
+
+        std::stringstream ss;
+        ss << gl_version_str.substr(start_pos, point_pos - start_pos + 1);
+        ss >> gl_major;
+    }
+
+    return gl_major >= 2;
+}

=== modified file 'src/canvas-x11.h'
--- src/canvas-x11.h	2011-08-09 10:51:03 +0000
+++ src/canvas-x11.h	2011-09-29 13:05:21 +0000
@@ -48,6 +48,7 @@ 
     virtual XVisualInfo *get_xvisualinfo() = 0;
     virtual bool make_current() = 0;
     virtual void swap_buffers() = 0;
+    bool supports_gl2();
 
     Window xwin_;
     Display *xdpy_;