]> git.cworth.org Git - apitrace/commitdiff
Take drawable geometry on creation.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 6 May 2011 19:43:48 +0000 (20:43 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 6 May 2011 19:43:48 +0000 (20:43 +0100)
glws.hpp
glws_glx.cpp
glws_wgl.cpp

index 7f4b52d9db9526bc9e8d8b78321d86be6751b4a8..23de839da1260681e8fa42c7ed563291327065cc 100644 (file)
--- a/glws.hpp
+++ b/glws.hpp
@@ -51,17 +51,19 @@ class Drawable
 {
 public:
     const Visual *visual;
-    unsigned width;
-    unsigned height;
+    int width;
+    int height;
 
-    Drawable(const Visual *vis) :
-        visual(vis)
+    Drawable(const Visual *vis, int w, int h) :
+        visual(vis),
+        width(w),
+        height(h)
     {}
 
     virtual ~Drawable() {}
     
     virtual void
-    resize(unsigned w, unsigned h) {
+    resize(int w, int h) {
         width = w;
         height = h;
     }
@@ -92,7 +94,7 @@ public:
     createVisual(bool doubleBuffer = false) = 0;
     
     virtual Drawable *
-    createDrawable(const Visual *visual) = 0;
+    createDrawable(const Visual *visual, int width = 256, int height = 256) = 0;
 
     virtual Context *
     createContext(const Visual *visual) = 0;
index 64f8ce129a41089a75f702c39b6f0359533171d8..39e0c4682ddbf0498e45bbed8b7956e405d2e549 100644 (file)
@@ -33,6 +33,9 @@
 namespace glws {
 
 
+static Display *display = NULL;
+static int screen = 0;
+
 class GlxVisual : public Visual
 {
 public:
@@ -51,21 +54,59 @@ public:
 class GlxDrawable : public Drawable
 {
 public:
-    Display *display;
     Window window;
 
-    GlxDrawable(const Visual *vis, Display *dpy, Window win) :
-        Drawable(vis),
-        display(dpy), 
-        window(win)
-    {}
+    GlxDrawable(const Visual *vis, int w, int h) :
+        Drawable(vis, w, h)
+    {
+        XVisualInfo *visinfo = dynamic_cast<const GlxVisual *>(visual)->visinfo;
+
+        Window root = RootWindow(display, screen);
+
+        /* window attributes */
+        XSetWindowAttributes attr;
+        attr.background_pixel = 0;
+        attr.border_pixel = 0;
+        attr.colormap = XCreateColormap(display, root, visinfo->visual, AllocNone);
+        attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+
+        unsigned long mask;
+        mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+        int x = 0, y = 0;
+
+        window = XCreateWindow(
+            display, root,
+            x, y, width, height,
+            0,
+            visinfo->depth,
+            InputOutput,
+            visinfo->visual,
+            mask,
+            &attr);
+
+        XSizeHints sizehints;
+        sizehints.x = x;
+        sizehints.y = y;
+        sizehints.width  = width;
+        sizehints.height = height;
+        sizehints.flags = USSize | USPosition;
+        XSetNormalHints(display, window, &sizehints);
+
+        const char *name = "glretrace";
+        XSetStandardProperties(
+            display, window, name, name,
+            None, (char **)NULL, 0, &sizehints);
+
+        XMapWindow(display, window);
+    }
 
     ~GlxDrawable() {
         XDestroyWindow(display, window);
     }
-    
+
     void
-    resize(unsigned w, unsigned h) {
+    resize(int w, int h) {
         glXWaitGL();
         Drawable::resize(w, h);
         XResizeWindow(display, window, w, h);
@@ -81,12 +122,10 @@ public:
 class GlxContext : public Context
 {
 public:
-    Display *display;
     GLXContext context;
-    
-    GlxContext(const Visual *vis, Display *dpy, GLXContext ctx) :
+
+    GlxContext(const Visual *vis, GLXContext ctx) :
         Context(vis),
-        display(dpy), 
         context(ctx)
     {}
 
@@ -98,18 +137,16 @@ public:
 
 class GlxWindowSystem : public WindowSystem
 {
-private:
-    Display *display;
-    int screen;
-
 public:
     GlxWindowSystem() {
-        display = XOpenDisplay(NULL);
-       if (!display) {
-            std::cerr << "error: unable to open display " << XDisplayName(NULL) << "\n";
-            exit(1);
+        if (!display) {
+            display = XOpenDisplay(NULL);
+            if (!display) {
+                std::cerr << "error: unable to open display " << XDisplayName(NULL) << "\n";
+                exit(1);
+            }
+            screen = DefaultScreen(display);
         }
-        screen = DefaultScreen(display);
     }
 
     ~GlxWindowSystem() {
@@ -140,57 +177,16 @@ public:
         };
 
         XVisualInfo *visinfo;
-        
+
         visinfo = glXChooseVisual(display, screen, doubleBuffer ? double_attribs : single_attribs);
 
         return new GlxVisual(visinfo);
     }
-    
+
     Drawable *
-    createDrawable(const Visual *visual)
+    createDrawable(const Visual *visual, int width, int height)
     {
-        XVisualInfo *visinfo = dynamic_cast<const GlxVisual *>(visual)->visinfo;
-
-        Window root = RootWindow(display, screen);
-
-        /* window attributes */
-        XSetWindowAttributes attr;
-        attr.background_pixel = 0;
-        attr.border_pixel = 0;
-        attr.colormap = XCreateColormap(display, root, visinfo->visual, AllocNone);
-        attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
-        
-        unsigned long mask;
-        mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
-
-        int x = 0, y = 0, width = 256, height = 256;
-
-        Window window = XCreateWindow(
-            display, root, 
-            x, y, width, height,
-            0, 
-            visinfo->depth, 
-            InputOutput,
-            visinfo->visual, 
-            mask, 
-            &attr);
-
-        XSizeHints sizehints;
-        sizehints.x = x;
-        sizehints.y = y;
-        sizehints.width  = width;
-        sizehints.height = height;
-        sizehints.flags = USSize | USPosition;
-        XSetNormalHints(display, window, &sizehints);
-        
-        const char *name = "glretrace";
-        XSetStandardProperties(
-            display, window, name, name,
-            None, (char **)NULL, 0, &sizehints);
-
-        XMapWindow(display, window);
-        
-        return new GlxDrawable(visual, display, window);
+        return new GlxDrawable(visual, width, height);
     }
 
     Context *
@@ -198,7 +194,7 @@ public:
     {
         XVisualInfo *visinfo = dynamic_cast<const GlxVisual *>(visual)->visinfo;
         GLXContext context = glXCreateContext(display, visinfo, NULL, True);
-        return new GlxContext(visual, display, context);
+        return new GlxContext(visual, context);
     }
 
     bool
index bc4dd27132b97025945ff4edce94b94209ce105d..b1e274b5f9314f27e2394f1ea362b70f0a4d3cb9 100644 (file)
@@ -61,8 +61,8 @@ public:
     PIXELFORMATDESCRIPTOR pfd;
     int iPixelFormat;
 
-    WglDrawable(const Visual *vis) :
-        Drawable(vis)
+    WglDrawable(const Visual *vis, int width, int height) :
+        Drawable(vis, width, height)
     {
         static bool first = TRUE;
         RECT rect;
@@ -83,7 +83,7 @@ public:
         dwExStyle = 0;
         dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE | WS_OVERLAPPEDWINDOW;
 
-        int x = 0, y = 0, width = 256, height = 256;
+        int x = 0, y = 0;
 
         rect.left = x;
         rect.top = y;
@@ -134,7 +134,7 @@ public:
     }
     
     void
-    resize(unsigned w, unsigned h) {
+    resize(int w, int h) {
         Drawable::resize(w, h);
         RECT rClient, rWindow;
         GetClientRect(hWnd, &rClient);
@@ -181,9 +181,9 @@ public:
     }
     
     Drawable *
-    createDrawable(const Visual *visual)
+    createDrawable(const Visual *visual, int width, int height)
     {
-        return new WglDrawable(visual);
+        return new WglDrawable(visual, width, height);
     }
 
     Context *