[waffle] [PATCH 2/2] examples/gl_basic: Make GL symbol queries more robust

Chad Versace chad.versace at intel.com
Tue Jun 14 21:12:40 UTC 2016


Analagous to the previous patch to tests/functional/gl_basic_test.c.

Suggested-by: Emil Velikov <emil.l.velikov at collabora.co.uk>
Signed-off-by: Chad Versace <chad.versace at intel.com>
---
 examples/gl_basic.c | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/examples/gl_basic.c b/examples/gl_basic.c
index 80794a0..1b8a313 100644
--- a/examples/gl_basic.c
+++ b/examples/gl_basic.c
@@ -37,6 +37,7 @@
 #define WAFFLE_API_VERSION 0x0106
 #define WAFFLE_API_EXPERIMENTAL
 
+#include <assert.h>
 #include <getopt.h>
 #include <stdarg.h>
 #include <stdbool.h>
@@ -425,6 +426,29 @@ error_unrecognized_arg:
     usage_error_printf("unrecognized option '%s'", optarg);
 }
 
+// The rules that dictate how to properly query a GL symbol are complex. The
+// rules depend on the OS, on the winsys API, and even on the particular driver
+// being used. The rules differ between EGL 1.4 and EGL 1.5; differ between
+// Linux, Windows, and Mac; and differ between Mesa and Mali.
+//
+// This function hides that complexity with a naive heuristic: try, then try
+// again.
+static void *
+get_gl_symbol(const struct options *opts, const const char *name)
+{
+    void *sym = NULL;
+
+    if (waffle_dl_can_open(opts->dl)) {
+        sym = waffle_dl_sym(opts->dl, name);
+    }
+
+    if (!sym) {
+        sym = waffle_get_proc_address(name);
+    }
+
+    return sym;
+}
+
 static bool
 draw(struct waffle_window *window, bool resize)
 {
@@ -615,27 +639,27 @@ main(int argc, char **argv)
                      waffle_enum_to_string(opts.context_api));
     }
 
-    glClear = waffle_dl_sym(opts.dl, "glClear");
+    glClear = get_gl_symbol(&opts, "glClear");
     if (!glClear)
         error_get_gl_symbol("glClear");
 
-    glClearColor = waffle_dl_sym(opts.dl, "glClearColor");
+    glClearColor = get_gl_symbol(&opts, "glClearColor");
     if (!glClearColor)
         error_get_gl_symbol("glClearColor");
 
-    glGetError = waffle_dl_sym(opts.dl, "glGetError");
+    glGetError = get_gl_symbol(&opts, "glGetError");
     if (!glGetError)
         error_get_gl_symbol("glGetError");
 
-    glGetIntegerv = waffle_dl_sym(opts.dl, "glGetIntegerv");
+    glGetIntegerv = get_gl_symbol(&opts, "glGetIntegerv");
     if (!glGetIntegerv)
         error_get_gl_symbol("glGetIntegerv");
 
-    glReadPixels = waffle_dl_sym(opts.dl, "glReadPixels");
+    glReadPixels = get_gl_symbol(&opts, "glReadPixels");
     if (!glReadPixels)
         error_get_gl_symbol("glReadPixels");
 
-    glViewport = waffle_dl_sym(opts.dl, "glViewport");
+    glViewport = get_gl_symbol(&opts, "glViewport");
     if (!glViewport)
         error_get_gl_symbol("glViewport");
 
-- 
2.9.0.rc2



More information about the waffle mailing list