attached patch adds the test that GLX works before intializing the TMU model. 
Prevents QEMU from crashing if the system has no OpenGL support whatsoever.
S.
diff --git a/hw/milkymist-hw.h b/hw/milkymist-hw.h
index 80cfed7..9ae76fc 100644
--- a/hw/milkymist-hw.h
+++ b/hw/milkymist-hw.h
@@ -99,6 +99,13 @@ milkymist_pfpu_create(target_phys_addr_t base, qemu_irq irq)
 
 #ifdef CONFIG_OPENGL
 #include <X11/Xlib.h>
+#include <GL/glx.h>
+static const int glx_fbconfig_attr[] = {
+    GLX_GREEN_SIZE, 5,
+    GLX_GREEN_SIZE, 6,
+    GLX_BLUE_SIZE, 5,
+    None
+};
 #endif
 static inline DeviceState *
 milkymist_tmu2_create(target_phys_addr_t base, qemu_irq irq)
@@ -106,15 +113,22 @@ milkymist_tmu2_create(target_phys_addr_t base, qemu_irq irq)
 #ifdef CONFIG_OPENGL
     DeviceState *dev;
     Display *d;
+    GLXFBConfig *configs;
+    int nelements;
 
     if (display_type == DT_NOGRAPHIC)
-		return NULL;
+      return NULL;
 
-	/* check if we can access the X server */
+    /* check if we can access the X server and get a GLX config */
     d = XOpenDisplay(NULL);
-	if (d == NULL)
-		return NULL;
-
+    if (d == NULL)
+      return NULL;
+    configs = glXChooseFBConfig(d, 0, glx_fbconfig_attr, &nelements);
+    if (configs == NULL) {
+      XCloseDisplay(d);
+      return NULL;
+    }
+    XFree(configs);
     XCloseDisplay(d);
 
     dev = qdev_create(NULL, "milkymist,tmu2");
_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkym...@freenode
Webchat: www.milkymist.org/irc.html
Wiki: www.milkymist.org/wiki

Reply via email to