]> git.cworth.org Git - apitrace/commitdiff
Simplify glws class hierarchy.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 9 Oct 2011 09:36:44 +0000 (10:36 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 9 Oct 2011 09:36:44 +0000 (10:36 +0100)
glretrace.hpp
glretrace_cgl.cpp
glretrace_glx.cpp
glretrace_main.cpp
glretrace_wgl.cpp
glws.hpp
glws_glx.cpp
glws_wgl.cpp

index 9cf615e1ba029e6b025ba18bd68cb80f8aab60d2..3a44f2c4fdb9dadb24885cbec492eeea203ca76f 100644 (file)
@@ -37,7 +37,6 @@ namespace glretrace {
 extern bool double_buffer;
 extern bool insideGlBeginEnd;
 extern Trace::Parser parser;
-extern glws::WindowSystem *ws;
 extern glws::Visual *visual;
 extern glws::Drawable *drawable;
 extern glws::Context *context;
index 411706b664f06dff7ca681dd9e879b1255278851..e7f42589100040fe66a67da5f016f9e38d018291 100644 (file)
@@ -53,7 +53,7 @@ getDrawable(unsigned long drawable_id) {
     DrawableMap::const_iterator it;
     it = drawable_map.find(drawable_id);
     if (it == drawable_map.end()) {
-        return (drawable_map[drawable_id] = ws->createDrawable(visual));
+        return (drawable_map[drawable_id] = glws::createDrawable(visual));
     }
 
     return it->second;
@@ -70,7 +70,7 @@ getContext(unsigned long long ctx) {
     it = context_map.find(ctx);
     if (it == context_map.end()) {
         glws::Context *context;
-        context_map[ctx] = context = ws->createContext(visual, sharedContext);
+        context_map[ctx] = context = glws::createContext(visual, sharedContext);
         if (!sharedContext) {
             sharedContext = context;
         }
@@ -87,7 +87,7 @@ static void retrace_CGLSetCurrentContext(Trace::Call &call) {
     glws::Drawable *new_drawable = getDrawable(ctx);
     glws::Context *new_context = getContext(ctx);
 
-    bool result = ws->makeCurrent(new_drawable, new_context);
+    bool result = glws::makeCurrent(new_drawable, new_context);
 
     if (new_drawable && new_context && result) {
         drawable = new_drawable;
index 72357ed7a0f0f01b6b3c46bf55eefb07df7796b8..8e2e4692afb33fc3eaadb296859e7d9108661811 100644 (file)
@@ -47,7 +47,7 @@ getDrawable(unsigned long drawable_id) {
     DrawableMap::const_iterator it;
     it = drawable_map.find(drawable_id);
     if (it == drawable_map.end()) {
-        return (drawable_map[drawable_id] = ws->createDrawable(visual));
+        return (drawable_map[drawable_id] = glws::createDrawable(visual));
     }
 
     return it->second;
@@ -62,7 +62,7 @@ getContext(unsigned long long context_ptr) {
     ContextMap::const_iterator it;
     it = context_map.find(context_ptr);
     if (it == context_map.end()) {
-        return (context_map[context_ptr] = ws->createContext(visual, NULL));
+        return (context_map[context_ptr] = glws::createContext(visual, NULL));
     }
 
     return it->second;
@@ -72,7 +72,7 @@ static void retrace_glXCreateContext(Trace::Call &call) {
     unsigned long long orig_context = call.ret->toUIntPtr();
     glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
 
-    glws::Context *context = ws->createContext(glretrace::visual, share_context);
+    glws::Context *context = glws::createContext(glretrace::visual, share_context);
     context_map[orig_context] = context;
 }
 
@@ -80,7 +80,7 @@ static void retrace_glXCreateContextAttribsARB(Trace::Call &call) {
     unsigned long long orig_context = call.ret->toUIntPtr();
     glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
 
-    glws::Context *context = ws->createContext(glretrace::visual, share_context);
+    glws::Context *context = glws::createContext(glretrace::visual, share_context);
     context_map[orig_context] = context;
 }
 
@@ -99,7 +99,7 @@ static void retrace_glXMakeCurrent(Trace::Call &call) {
         }
     }
 
-    bool result = ws->makeCurrent(new_drawable, new_context);
+    bool result = glws::makeCurrent(new_drawable, new_context);
 
     if (new_drawable && new_context && result) {
         drawable = new_drawable;
@@ -134,7 +134,7 @@ static void retrace_glXCreateNewContext(Trace::Call &call) {
     unsigned long long orig_context = call.ret->toUIntPtr();
     glws::Context *share_context = getContext(call.arg(3).toUIntPtr());
 
-    glws::Context *context = ws->createContext(glretrace::visual, share_context);
+    glws::Context *context = glws::createContext(glretrace::visual, share_context);
     context_map[orig_context] = context;
 }
 
@@ -153,7 +153,7 @@ static void retrace_glXMakeContextCurrent(Trace::Call &call) {
         }
     }
 
-    bool result = ws->makeCurrent(new_drawable, new_context);
+    bool result = glws::makeCurrent(new_drawable, new_context);
 
     if (new_drawable && new_context && result) {
         drawable = new_drawable;
index fb98b615aa9625dcc6159a4126041b6982a31f0f..dc022762fc35d439eb358cbff18eed2b77cdc2cc 100644 (file)
@@ -38,7 +38,6 @@ namespace glretrace {
 bool double_buffer = true;
 bool insideGlBeginEnd = false;
 Trace::Parser parser;
-glws::WindowSystem *ws = NULL;
 glws::Visual *visual = NULL;
 glws::Drawable *drawable = NULL;
 glws::Context *context = NULL;
@@ -227,7 +226,7 @@ static void display(void) {
     }
 
     if (wait) {
-        while (ws->processEvents()) {}
+        while (glws::processEvents()) {}
     } else {
         exit(0);
     }
@@ -317,8 +316,8 @@ int main(int argc, char **argv)
         }
     }
 
-    ws = glws::createNativeWindowSystem();
-    visual = ws->createVisual(double_buffer);
+    glws::init();
+    visual = glws::createVisual(double_buffer);
 
     for ( ; i < argc; ++i) {
         if (!parser.open(argv[i])) {
@@ -330,6 +329,9 @@ int main(int argc, char **argv)
 
         parser.close();
     }
+    
+    delete visual;
+    glws::cleanup();
 
     return 0;
 }
index d88f27abebe3f7d042c2516708f7266285ba2db5..7df2485e0737982327785dc8343b67727ed3dde2 100644 (file)
@@ -48,7 +48,7 @@ getDrawable(unsigned long long hdc) {
     DrawableMap::const_iterator it;
     it = drawable_map.find(hdc);
     if (it == drawable_map.end()) {
-        return (drawable_map[hdc] = ws->createDrawable(visual));
+        return (drawable_map[hdc] = glws::createDrawable(visual));
     }
 
     return it->second;
@@ -56,7 +56,7 @@ getDrawable(unsigned long long hdc) {
 
 static void retrace_wglCreateContext(Trace::Call &call) {
     unsigned long long orig_context = call.ret->toUIntPtr();
-    glws::Context *context = ws->createContext(glretrace::visual);
+    glws::Context *context = glws::createContext(glretrace::visual);
     context_map[orig_context] = context;
 }
 
@@ -74,7 +74,7 @@ static void retrace_wglMakeCurrent(Trace::Call &call) {
     glws::Drawable *new_drawable = getDrawable(call.arg(0).toUIntPtr());
     glws::Context *new_context = context_map[call.arg(1).toUIntPtr()];
 
-    bool result = ws->makeCurrent(new_drawable, new_context);
+    bool result = glws::makeCurrent(new_drawable, new_context);
 
     if (new_drawable && new_context && result) {
         drawable = new_drawable;
@@ -114,7 +114,7 @@ static void retrace_wglShareLists(Trace::Call &call) {
     glws::Context *old_context = context_map[hglrc2];
 
     glws::Context *new_context =
-        ws->createContext(old_context->visual, share_context);
+        glws::createContext(old_context->visual, share_context);
     if (new_context) {
         delete old_context;
         context_map[hglrc2] = new_context;
@@ -176,7 +176,7 @@ static void retrace_wglCreatePbufferARB(Trace::Call &call) {
     int iHeight = call.arg(3).toUInt();
 
     unsigned long long orig_pbuffer = call.ret->toUIntPtr();
-    glws::Drawable *drawable = ws->createDrawable(glretrace::visual);
+    glws::Drawable *drawable = glws::createDrawable(glretrace::visual);
 
     drawable->resize(iWidth, iHeight);
 
@@ -217,7 +217,7 @@ static void retrace_wglCreateContextAttribsARB(Trace::Call &call) {
         share_context = context_map[call.arg(1).toUIntPtr()];
     }
 
-    glws::Context *context = ws->createContext(glretrace::visual, share_context);
+    glws::Context *context = glws::createContext(glretrace::visual, share_context);
     context_map[orig_context] = context;
 }
 
index 05654200f7d966d9f443b696a13c8ab8ffde68f6..12e53f3e8f93e5fd5f5c0f5de39eaa579ad48782 100644 (file)
--- a/glws.hpp
+++ b/glws.hpp
@@ -92,29 +92,26 @@ public:
 };
 
 
-class WindowSystem
-{
-public:
-    virtual ~WindowSystem() {}
+void
+init(void);
 
-    virtual Visual *
-    createVisual(bool doubleBuffer = false) = 0;
-    
-    virtual Drawable *
-    createDrawable(const Visual *visual, int width = 32, int height = 32) = 0;
+void
+cleanup(void);
 
-    virtual Context *
-    createContext(const Visual *visual, Context *shareContext = NULL) = 0;
-    
-    virtual bool
-    makeCurrent(Drawable *drawable, Context *context) = 0;
+Visual *
+createVisual(bool doubleBuffer = false);
 
-    virtual bool
-    processEvents(void) = 0;
-};
+Drawable *
+createDrawable(const Visual *visual, int width = 32, int height = 32);
+
+Context *
+createContext(const Visual *visual, Context *shareContext = NULL);
 
+bool
+makeCurrent(Drawable *drawable, Context *context);
 
-WindowSystem *createNativeWindowSystem(void);
+bool
+processEvents(void);
 
 
 } /* namespace glws */
index 95cdab078951eef107b8936d8a56fa34f3df58b4..1c73564d0ccb7ccab6ce586ab9e722535b2e5998 100644 (file)
@@ -203,108 +203,103 @@ public:
     }
 };
 
-
-class GlxWindowSystem : public WindowSystem
-{
-public:
-    GlxWindowSystem() {
+void
+init(void) {
+    if (!display) {
+        display = XOpenDisplay(NULL);
         if (!display) {
-            display = XOpenDisplay(NULL);
-            if (!display) {
-                std::cerr << "error: unable to open display " << XDisplayName(NULL) << "\n";
-                exit(1);
-            }
-            screen = DefaultScreen(display);
+            std::cerr << "error: unable to open display " << XDisplayName(NULL) << "\n";
+            exit(1);
         }
+        screen = DefaultScreen(display);
     }
+}
 
-    ~GlxWindowSystem() {
+void
+cleanup(void) {
+    if (display) {
         XCloseDisplay(display);
+        display = NULL;
     }
+}
 
-    Visual *
-    createVisual(bool doubleBuffer) {
-        int single_attribs[] = {
-            GLX_RGBA,
-            GLX_RED_SIZE, 1,
-            GLX_GREEN_SIZE, 1,
-            GLX_BLUE_SIZE, 1,
-            GLX_ALPHA_SIZE, 1,
-            GLX_DEPTH_SIZE, 1,
-            GLX_STENCIL_SIZE, 1,
-            None
-        };
-
-        int double_attribs[] = {
-            GLX_RGBA,
-            GLX_RED_SIZE, 1,
-            GLX_GREEN_SIZE, 1,
-            GLX_BLUE_SIZE, 1,
-            GLX_ALPHA_SIZE, 1,
-            GLX_DOUBLEBUFFER,
-            GLX_DEPTH_SIZE, 1,
-            GLX_STENCIL_SIZE, 1,
-            None
-        };
-
-        XVisualInfo *visinfo;
-
-        visinfo = glXChooseVisual(display, screen, doubleBuffer ? double_attribs : single_attribs);
-
-        return new GlxVisual(visinfo);
-    }
+Visual *
+createVisual(bool doubleBuffer) {
+    int single_attribs[] = {
+        GLX_RGBA,
+        GLX_RED_SIZE, 1,
+        GLX_GREEN_SIZE, 1,
+        GLX_BLUE_SIZE, 1,
+        GLX_ALPHA_SIZE, 1,
+        GLX_DEPTH_SIZE, 1,
+        GLX_STENCIL_SIZE, 1,
+        None
+    };
+
+    int double_attribs[] = {
+        GLX_RGBA,
+        GLX_RED_SIZE, 1,
+        GLX_GREEN_SIZE, 1,
+        GLX_BLUE_SIZE, 1,
+        GLX_ALPHA_SIZE, 1,
+        GLX_DOUBLEBUFFER,
+        GLX_DEPTH_SIZE, 1,
+        GLX_STENCIL_SIZE, 1,
+        None
+    };
 
-    Drawable *
-    createDrawable(const Visual *visual, int width, int height)
-    {
-        return new GlxDrawable(visual, width, height);
-    }
+    XVisualInfo *visinfo;
 
-    Context *
-    createContext(const Visual *visual, Context *shareContext)
-    {
-        XVisualInfo *visinfo = dynamic_cast<const GlxVisual *>(visual)->visinfo;
-        GLXContext share_context = NULL;
-        GLXContext context;
+    visinfo = glXChooseVisual(display, screen, doubleBuffer ? double_attribs : single_attribs);
 
-        if (shareContext) {
-            share_context = dynamic_cast<GlxContext*>(shareContext)->context;
-        }
+    return new GlxVisual(visinfo);
+}
 
-        context = glXCreateContext(display, visinfo,
-                                   share_context, True);
-        return new GlxContext(visual, context);
-    }
+Drawable *
+createDrawable(const Visual *visual, int width, int height)
+{
+    return new GlxDrawable(visual, width, height);
+}
 
-    bool
-    makeCurrent(Drawable *drawable, Context *context)
-    {
-        if (!drawable || !context) {
-            return glXMakeCurrent(display, None, NULL);
-        } else {
-            GlxDrawable *glxDrawable = dynamic_cast<GlxDrawable *>(drawable);
-            GlxContext *glxContext = dynamic_cast<GlxContext *>(context);
+Context *
+createContext(const Visual *visual, Context *shareContext)
+{
+    XVisualInfo *visinfo = dynamic_cast<const GlxVisual *>(visual)->visinfo;
+    GLXContext share_context = NULL;
+    GLXContext context;
 
-            return glXMakeCurrent(display, glxDrawable->window, glxContext->context);
-        }
+    if (shareContext) {
+        share_context = dynamic_cast<GlxContext*>(shareContext)->context;
     }
 
-    bool
-    processEvents(void) {
-        XFlush(display);
-        while (XPending(display) > 0) {
-            XEvent event;
-            XNextEvent(display, &event);
-            describeEvent(event);
-        }
-        return true;
-    }
-};
+    context = glXCreateContext(display, visinfo,
+                               share_context, True);
+    return new GlxContext(visual, context);
+}
 
+bool
+makeCurrent(Drawable *drawable, Context *context)
+{
+    if (!drawable || !context) {
+        return glXMakeCurrent(display, None, NULL);
+    } else {
+        GlxDrawable *glxDrawable = dynamic_cast<GlxDrawable *>(drawable);
+        GlxContext *glxContext = dynamic_cast<GlxContext *>(context);
+
+        return glXMakeCurrent(display, glxDrawable->window, glxContext->context);
+    }
+}
 
-WindowSystem *createNativeWindowSystem(void) {
-    return new GlxWindowSystem();
+bool
+processEvents(void) {
+    XFlush(display);
+    while (XPending(display) > 0) {
+        XEvent event;
+        XNextEvent(display, &event);
+        describeEvent(event);
+    }
+    return true;
 }
 
 
-} /* namespace glretrace */
+} /* namespace glws */
index 9e8f1e036432a81298b135004c835e790a1e773f..adc99578e3b7aa9cd885c2de41458301856dec52 100644 (file)
@@ -179,65 +179,64 @@ public:
 };
 
 
-class WglWindowSystem : public WindowSystem
-{
-public:
-    Visual *
-    createVisual(bool doubleBuffer) {
-        Visual *visual = new Visual();
+void
+init(void) {
+}
 
-        visual->doubleBuffer = doubleBuffer;
+void
+cleanup(void) {
+}
 
-        return visual;
-    }
-    
-    Drawable *
-    createDrawable(const Visual *visual, int width, int height)
-    {
-        return new WglDrawable(visual, width, height);
-    }
+Visual *
+createVisual(bool doubleBuffer) {
+    Visual *visual = new Visual();
 
-    Context *
-    createContext(const Visual *visual, Context *shareContext)
-    {
-        return new WglContext(visual, dynamic_cast<WglContext *>(shareContext));
-    }
+    visual->doubleBuffer = doubleBuffer;
 
-    bool
-    makeCurrent(Drawable *drawable, Context *context)
-    {
-        if (!drawable || !context) {
-            return wglMakeCurrent(NULL, NULL);
-        } else {
-            WglDrawable *wglDrawable = dynamic_cast<WglDrawable *>(drawable);
-            WglContext *wglContext = dynamic_cast<WglContext *>(context);
+    return visual;
+}
 
+Drawable *
+createDrawable(const Visual *visual, int width, int height)
+{
+    return new WglDrawable(visual, width, height);
+}
+
+Context *
+createContext(const Visual *visual, Context *shareContext)
+{
+    return new WglContext(visual, dynamic_cast<WglContext *>(shareContext));
+}
+
+bool
+makeCurrent(Drawable *drawable, Context *context)
+{
+    if (!drawable || !context) {
+        return wglMakeCurrent(NULL, NULL);
+    } else {
+        WglDrawable *wglDrawable = dynamic_cast<WglDrawable *>(drawable);
+        WglContext *wglContext = dynamic_cast<WglContext *>(context);
+
+        if (!wglContext->hglrc) {
+            wglContext->hglrc = wglCreateContext(wglDrawable->hDC);
             if (!wglContext->hglrc) {
-                wglContext->hglrc = wglCreateContext(wglDrawable->hDC);
-                if (!wglContext->hglrc) {
-                    return false;
-                }
-                if (wglContext->shareContext) {
-                    wglShareLists(wglContext->shareContext->hglrc,
-                                  wglContext->hglrc);
-                }
+                return false;
+            }
+            if (wglContext->shareContext) {
+                wglShareLists(wglContext->shareContext->hglrc,
+                              wglContext->hglrc);
             }
-
-            return wglMakeCurrent(wglDrawable->hDC, wglContext->hglrc);
         }
-    }
 
-    bool
-    processEvents(void) {
-        // TODO
-        return true;
+        return wglMakeCurrent(wglDrawable->hDC, wglContext->hglrc);
     }
-};
-
+}
 
-WindowSystem *createNativeWindowSystem(void) {
-    return new WglWindowSystem();
+bool
+processEvents(void) {
+    // TODO
+    return true;
 }
 
 
-} /* namespace glretrace */
+} /* namespace glws */