]> git.cworth.org Git - apitrace/blobdiff - retrace/glws_glx.cpp
glretrace: reapply fix for #178 to original GLX code
[apitrace] / retrace / glws_glx.cpp
index c151db1c07fb91914c070699cc79fec4bc49f076..d150aa609c5a2acb53c71633c9b97fb0ab77a351 100644 (file)
@@ -60,7 +60,8 @@ public:
 };
 
 
-static void describeEvent(const XEvent &event) {
+static void
+processEvent(XEvent &event) {
     if (0) {
         switch (event.type) {
         case ConfigureNotify:
@@ -83,6 +84,19 @@ static void describeEvent(const XEvent &event) {
         }
         std::cerr << " " << event.xany.window << "\n";
     }
+
+    switch (event.type) {
+    case KeyPress:
+        {
+            char buffer[32];
+            KeySym keysym;
+            XLookupString(&event.xkey, buffer, sizeof buffer - 1, &keysym, NULL);
+            if (keysym == XK_Escape) {
+                exit(0);
+            }
+        }
+        break;
+    }
 }
 
 class GlxDrawable : public Drawable
@@ -90,8 +104,8 @@ class GlxDrawable : public Drawable
 public:
     Window window;
 
-    GlxDrawable(const Visual *vis, int w, int h) :
-        Drawable(vis, w, h)
+    GlxDrawable(const Visual *vis, int w, int h, bool pbuffer) :
+        Drawable(vis, w, h, pbuffer)
     {
         XVisualInfo *visinfo = static_cast<const GlxVisual *>(visual)->visinfo;
 
@@ -102,7 +116,7 @@ public:
         attr.background_pixel = 0;
         attr.border_pixel = 0;
         attr.colormap = XCreateColormap(display, root, visinfo->visual, AllocNone);
-        attr.event_mask = StructureNotifyMask;
+        attr.event_mask = StructureNotifyMask | KeyPressMask;
 
         unsigned long mask;
         mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
@@ -135,11 +149,18 @@ public:
         glXWaitX();
     }
 
+    void processKeys(void) {
+        XEvent event;
+        while (XCheckWindowEvent(display, window, StructureNotifyMask | KeyPressMask, &event)) {
+            processEvent(event);
+        }
+    }
+
     void waitForEvent(int type) {
         XEvent event;
         do {
-            XWindowEvent(display, window, StructureNotifyMask, &event);
-            describeEvent(event);
+            XWindowEvent(display, window, StructureNotifyMask | KeyPressMask, &event);
+            processEvent(event);
         } while (event.type != type);
     }
 
@@ -162,8 +183,6 @@ public:
 
         Drawable::resize(w, h);
 
-        XResizeWindow(display, window, w, h);
-
         // Tell the window manager to respect the requested size
         XSizeHints size_hints;
         size_hints.max_width  = size_hints.min_width  = w;
@@ -171,6 +190,8 @@ public:
         size_hints.flags = PMinSize | PMaxSize;
         XSetWMNormalHints(display, window, &size_hints);
 
+        XResizeWindow(display, window, w, h);
+
         waitForEvent(ConfigureNotify);
 
         glXWaitX();
@@ -194,6 +215,8 @@ public:
 
     void swapBuffers(void) {
         glXSwapBuffers(display, window);
+
+        processKeys();
     }
 };
 
@@ -215,6 +238,8 @@ public:
 
 void
 init(void) {
+    XInitThreads();
+
     display = XOpenDisplay(NULL);
     if (!display) {
         std::cerr << "error: unable to open display " << XDisplayName(NULL) << "\n";
@@ -242,7 +267,8 @@ cleanup(void) {
 Visual *
 createVisual(bool doubleBuffer, Profile profile) {
     if (profile != PROFILE_COMPAT &&
-        profile != PROFILE_CORE) {
+        profile != PROFILE_CORE &&
+        profile != PROFILE_ES2) {
         return NULL;
     }
 
@@ -290,13 +316,13 @@ createVisual(bool doubleBuffer, Profile profile) {
 }
 
 Drawable *
-createDrawable(const Visual *visual, int width, int height)
+createDrawable(const Visual *visual, int width, int height, bool pbuffer)
 {
-    return new GlxDrawable(visual, width, height);
+    return new GlxDrawable(visual, width, height, pbuffer);
 }
 
 Context *
-createContext(const Visual *_visual, Context *shareContext, Profile profile)
+createContext(const Visual *_visual, Context *shareContext, Profile profile, bool debug)
 {
     const GlxVisual *visual = static_cast<const GlxVisual *>(_visual);
     GLXContext share_context = NULL;
@@ -317,6 +343,9 @@ createContext(const Visual *_visual, Context *shareContext, Profile profile)
         switch (profile) {
         case PROFILE_COMPAT:
             break;
+        case PROFILE_ES2:
+            attribs.add(GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EXT);
+            break;
         case PROFILE_CORE:
             // XXX: This will invariable return a 3.2 context, when supported.
             // We probably should have a PROFILE_CORE_XX per version.
@@ -368,7 +397,7 @@ processEvents(void) {
     while (XPending(display) > 0) {
         XEvent event;
         XNextEvent(display, &event);
-        describeEvent(event);
+        processEvent(event);
     }
     return true;
 }