]> git.cworth.org Git - apitrace/blobdiff - glws_glx.cpp
Use call number instead of frame number for snapshot filenames.
[apitrace] / glws_glx.cpp
index be0a82beb8e2c9d65715b9a757719378a703762e..67a88290b7988804bb0f3c4c16c30fc083d6451a 100644 (file)
 namespace glws {
 
 
-class XlibVisual : public Visual
+class GlxVisual : public Visual
 {
 public:
     XVisualInfo *visinfo;
 
-    XlibVisual(XVisualInfo *vi) :
+    GlxVisual(XVisualInfo *vi) :
         visinfo(vi)
     {}
 
-    ~XlibVisual() {
+    ~GlxVisual() {
         XFree(visinfo);
     }
 };
 
 
-class XlibDrawable : public Drawable
+class GlxDrawable : public Drawable
 {
 public:
     Display *display;
     Window window;
 
-    XlibDrawable(const Visual *vis, Display *dpy, Window win) :
+    GlxDrawable(const Visual *vis, Display *dpy, Window win) :
         Drawable(vis),
         display(dpy), 
         window(win)
     {}
 
-    ~XlibDrawable() {
+    ~GlxDrawable() {
         XDestroyWindow(display, window);
     }
     
@@ -73,40 +73,37 @@ public:
 };
 
 
-class XlibContext : public Context
+class GlxContext : public Context
 {
 public:
     Display *display;
     GLXContext context;
     
-    XlibContext(const Visual *vis, Display *dpy, GLXContext ctx) :
+    GlxContext(const Visual *vis, Display *dpy, GLXContext ctx) :
         Context(vis),
         display(dpy), 
         context(ctx)
     {}
 
-    ~XlibContext() {
+    ~GlxContext() {
         glXDestroyContext(display, context);
     }
 };
 
 
-class XlibWindowSystem : public WindowSystem
+class GlxWindowSystem : public WindowSystem
 {
 private:
     Display *display;
     int screen;
 
 public:
-    Drawable *currentDrawable;
-    Context *currentContext;
-
-    XlibWindowSystem() {
-       display = XOpenDisplay(NULL);
-       screen = DefaultScreen(display);
+    GlxWindowSystem() {
+        display = XOpenDisplay(NULL);
+        screen = DefaultScreen(display);
     }
 
-    ~XlibWindowSystem() {
+    ~GlxWindowSystem() {
         XCloseDisplay(display);
     }
 
@@ -118,6 +115,7 @@ public:
             GLX_GREEN_SIZE, 1,
             GLX_BLUE_SIZE, 1,
             GLX_DEPTH_SIZE, 1,
+            GLX_STENCIL_SIZE, 1,
             None
         };
 
@@ -128,6 +126,7 @@ public:
             GLX_BLUE_SIZE, 1,
             GLX_DOUBLEBUFFER,
             GLX_DEPTH_SIZE, 1,
+            GLX_STENCIL_SIZE, 1,
             None
         };
 
@@ -135,13 +134,13 @@ public:
         
         visinfo = glXChooseVisual(display, screen, doubleBuffer ? double_attribs : single_attribs);
 
-        return new XlibVisual(visinfo);
+        return new GlxVisual(visinfo);
     }
     
     Drawable *
     createDrawable(const Visual *visual)
     {
-        XVisualInfo *visinfo = dynamic_cast<const XlibVisual *>(visual)->visinfo;
+        XVisualInfo *visinfo = dynamic_cast<const GlxVisual *>(visual)->visinfo;
 
         Window root = RootWindow(display, screen);
 
@@ -182,50 +181,44 @@ public:
 
         XMapWindow(display, window);
         
-        return new XlibDrawable(visual, display, window);
+        return new GlxDrawable(visual, display, window);
     }
 
     Context *
     createContext(const Visual *visual)
     {
-        XVisualInfo *visinfo = dynamic_cast<const XlibVisual *>(visual)->visinfo;
+        XVisualInfo *visinfo = dynamic_cast<const GlxVisual *>(visual)->visinfo;
         GLXContext context = glXCreateContext(display, visinfo, NULL, True);
-        return new XlibContext(visual, display, context);
+        return new GlxContext(visual, display, context);
     }
 
     bool
     makeCurrent(Drawable *drawable, Context *context)
     {
-        Window win = drawable ? dynamic_cast<XlibDrawable *>(drawable)->window : NULL;
-        GLXContext ctx = context ? dynamic_cast<XlibContext *>(context)->context : NULL;
-
-        bool ret = glXMakeCurrent(display, win, ctx);
-
-        if (drawable && context && ret) {
-            currentDrawable = drawable;
-            currentContext = context;
+        if (!drawable || !context) {
+            return glXMakeCurrent(display, None, NULL);
         } else {
-            currentDrawable = NULL;
-            currentContext = NULL;
-        }
+            GlxDrawable *glxDrawable = dynamic_cast<GlxDrawable *>(drawable);
+            GlxContext *glxContext = dynamic_cast<GlxContext *>(context);
 
-        return ret;
+            return glXMakeCurrent(display, glxDrawable->window, glxContext->context);
+        }
     }
 
     bool
     processEvents(void) {
-      while (XPending(display) > 0) {
-         XEvent event;
-         XNextEvent(display, &event);
-         // TODO
-      }
-      return true;
+        while (XPending(display) > 0) {
+            XEvent event;
+            XNextEvent(display, &event);
+            // TODO
+        }
+        return true;
     }
 };
 
 
 WindowSystem *createNativeWindowSystem(void) {
-    return new XlibWindowSystem();
+    return new GlxWindowSystem();
 }