]> git.cworth.org Git - apitrace/commitdiff
Merge branch 'master' into multi-context
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Mon, 9 May 2011 20:27:02 +0000 (21:27 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Mon, 9 May 2011 20:27:02 +0000 (21:27 +0100)
Conflicts:
glretrace.hpp
glretrace_main.cpp

18 files changed:
TODO
glretrace.hpp
glretrace.py
glretrace_glx.cpp
glretrace_main.cpp
glretrace_wgl.cpp
glstate.py
glws.hpp
glws_glx.cpp
glws_wgl.cpp
gui/saverthread.cpp
retrace.py
stdapi.py
trace_model.cpp
trace_model.hpp
trace_write.cpp
trace_write.hpp
wglapi.py

diff --git a/TODO b/TODO
index 35cf95354b5949b2c1b0e38d0cd7eab6e0bab1a2..d2977a974770545e45610a2523012df2b001dceb 100644 (file)
--- a/TODO
+++ b/TODO
@@ -33,7 +33,7 @@ Retracing:
 * Use visuals that best match those used in the trace; specially auto
   detect single/double buffer visuals.
 
-* Support multiple contexts
+* Respect multiple context sharing of the traces.
 
 * Support multiple threads
 
index 11098f39d7e1483ebd6867a570aa47be4fc1d021..5a55edb5faa77db06348f228835fba2bcd9c2a50 100644 (file)
@@ -43,9 +43,6 @@ extern glws::Visual *visual;
 extern glws::Drawable *drawable;
 extern glws::Context *context;
 
-extern int window_width;
-extern int window_height;
-
 extern unsigned frame;
 extern long long startTime;
 extern bool wait;
index 1674a79de0646c59191ad68b3a249c6ce35d932a..706dbb44d78f3d9da5be6c41f99105e501404e44 100644 (file)
@@ -136,19 +136,13 @@ class GlRetracer(Retracer):
 
     def call_function(self, function):
         if function.name == "glViewport":
-            print '    bool reshape_window = false;'
-            print '    if (x + width > glretrace::window_width) {'
-            print '        glretrace::window_width = x + width;'
-            print '        reshape_window = true;'
-            print '    }'
-            print '    if (y + height > glretrace::window_height) {'
-            print '        glretrace::window_height = y + height;'
-            print '        reshape_window = true;'
-            print '    }'
-            print '    if (reshape_window) {'
-            print '        // XXX: does not always work'
-            print '        glretrace::drawable->resize(glretrace::window_width, glretrace::window_height);'
-            print '        reshape_window = false;'
+            print '    if (glretrace::drawable) {'
+            print '        int drawable_width  = x + width;'
+            print '        int drawable_height = y + height;'
+            print '        if (drawable_width  > (int)glretrace::drawable->width ||'
+            print '            drawable_height > (int)glretrace::drawable->height) {'
+            print '            glretrace::drawable->resize(drawable_width, drawable_height);'
+            print '        }'
             print '    }'
 
         if function.name == "glEnd":
@@ -220,11 +214,11 @@ class GlRetracer(Retracer):
 
     def extract_arg(self, function, arg, arg_type, lvalue, rvalue):
         if function.name in self.array_pointer_function_names and arg.name == 'pointer':
-            print '    %s = static_cast<%s>(%s.blob());' % (lvalue, arg_type, rvalue)
+            print '    %s = static_cast<%s>(%s.toPointer());' % (lvalue, arg_type, rvalue)
             return
 
         if function.name in self.draw_elements_function_names and arg.name == 'indices':
-            print '    %s = %s.blob();' % (lvalue, rvalue)
+            print '    %s = %s.toPointer();' % (lvalue, rvalue)
             return
 
         if arg.type is glapi.GLlocation \
index 11465eaa29c2cd47e69ade2b7b400d072db04c23..463de0a0ca8508182ed4dcfd5b2f528ad1f9fb1d 100644 (file)
 using namespace glretrace;
 
 
+typedef std::map<unsigned long, glws::Drawable *> DrawableMap;
+typedef std::map<void *, glws::Context *> ContextMap;
+static DrawableMap drawable_map;
+static ContextMap context_map;
+
+
+static glws::Drawable *
+getDrawable(unsigned long drawable_id) {
+    if (drawable_id == 0) {
+        return NULL;
+    }
+
+    DrawableMap::const_iterator it;
+    it = drawable_map.find(drawable_id);
+    if (it == drawable_map.end()) {
+        return (drawable_map[drawable_id] = ws->createDrawable(visual));
+    }
+
+    return it->second;
+}
+
 static void retrace_glXChooseVisual(Trace::Call &call) {
 }
 
 static void retrace_glXCreateContext(Trace::Call &call) {
+    void * orig_context = call.ret->toPointer();
+    glws::Context *share_context = NULL;
+
+    if (call.arg(2).toPointer()) {
+        share_context = context_map[call.arg(2).toPointer()];
+    }
+
+    glws::Context *context = ws->createContext(glretrace::visual, share_context);
+    context_map[orig_context] = context;
 }
 
 static void retrace_glXDestroyContext(Trace::Call &call) {
 }
 
 static void retrace_glXMakeCurrent(Trace::Call &call) {
-    glFlush();
-    if (!double_buffer) {
-        frame_complete(call.no);
+    if (drawable && context) {
+        glFlush();
+        if (!double_buffer) {
+            frame_complete(call.no);
+        }
+    }
+
+    glws::Drawable *new_drawable = getDrawable(call.arg(1).toUInt());
+    glws::Context *new_context = context_map[call.arg(2).toPointer()];
+
+    bool result = ws->makeCurrent(new_drawable, new_context);
+
+    if (new_drawable && new_context && result) {
+        drawable = new_drawable;
+        context = new_context;
+    } else {
+        drawable = NULL;
+        context = NULL;
     }
 }
 
@@ -130,9 +175,37 @@ static void retrace_glXQueryDrawable(Trace::Call &call) {
 }
 
 static void retrace_glXCreateNewContext(Trace::Call &call) {
+    void * orig_context = call.ret->toPointer();
+    glws::Context *share_context = NULL;
+
+    if (call.arg(3).toPointer()) {
+        share_context = context_map[call.arg(3).toPointer()];
+    }
+
+    glws::Context *context = ws->createContext(glretrace::visual, share_context);
+    context_map[orig_context] = context;
 }
 
 static void retrace_glXMakeContextCurrent(Trace::Call &call) {
+    if (drawable && context) {
+        glFlush();
+        if (!double_buffer) {
+            frame_complete(call.no);
+        }
+    }
+
+    glws::Drawable *new_drawable = getDrawable(call.arg(1).toUInt());
+    glws::Context *new_context = context_map[call.arg(3).toPointer()];
+
+    bool result = ws->makeCurrent(new_drawable, new_context);
+
+    if (new_drawable && new_context && result) {
+        drawable = new_drawable;
+        context = new_context;
+    } else {
+        drawable = NULL;
+        context = NULL;
+    }
 }
 
 static void retrace_glXGetCurrentReadDrawable(Trace::Call &call) {
index 14fd459c4768b3da55cfb6b89e4f7d2ac8e5ba90..9144de6c1ba1580fafde9ab795c3d1a34bce772a 100644 (file)
@@ -42,8 +42,6 @@ glws::Visual *visual = NULL;
 glws::Drawable *drawable = NULL;
 glws::Context *context = NULL;
 
-int window_width = 256, window_height = 256;
-
 unsigned frame = 0;
 long long startTime = 0;
 bool wait = false;
@@ -122,7 +120,8 @@ static void snapshot(Image::Image &image) {
 void frame_complete(unsigned call_no) {
     ++frame;
     
-    if (snapshot_prefix || compare_prefix) {
+    if (drawable &&
+        (snapshot_prefix || compare_prefix)) {
         Image::Image *ref = NULL;
         if (compare_prefix) {
             char filename[PATH_MAX];
@@ -135,7 +134,7 @@ void frame_complete(unsigned call_no) {
                 std::cout << "Read " << filename << "\n";
         }
         
-        Image::Image src(window_width, window_height, true);
+        Image::Image src(drawable->width, drawable->height, true);
         snapshot(src);
 
         if (snapshot_prefix) {
@@ -175,7 +174,9 @@ static void display(void) {
             retrace::retrace_call(*call);
         }
 
-        if (!insideGlBeginEnd && call->no >= dump_state) {
+        if (!insideGlBeginEnd &&
+            drawable && context &&
+            call->no >= dump_state) {
             state_dump(std::cout);
             exit(0);
         }
@@ -260,10 +261,6 @@ int main(int argc, char **argv)
 
     ws = glws::createNativeWindowSystem();
     visual = ws->createVisual(double_buffer);
-    drawable = ws->createDrawable(visual);
-    drawable->resize(window_width, window_height);
-    context = ws->createContext(visual);
-    ws->makeCurrent(drawable, context);
 
     for ( ; i < argc; ++i) {
         if (parser.open(argv[i])) {
index 9aace48b3eff821813efc7a4e1abe9195603422f..a7185f76b4c0fa5e7df63d3bdd5589dda6a5178f 100644 (file)
 using namespace glretrace;
 
 
+typedef std::map<unsigned long long, glws::Drawable *> DrawableMap;
+typedef std::map<unsigned long long, glws::Context *> ContextMap;
+static DrawableMap drawable_map;
+static DrawableMap pbuffer_map;
+static ContextMap context_map;
+
+
+static glws::Drawable *
+getDrawable(unsigned long long hdc) {
+    if (hdc == 0) {
+        return NULL;
+    }
+
+    DrawableMap::const_iterator it;
+    it = drawable_map.find(hdc);
+    if (it == drawable_map.end()) {
+        return (drawable_map[hdc] = ws->createDrawable(visual));
+    }
+
+    return it->second;
+}
+
 static void retrace_wglCreateContext(Trace::Call &call) {
+    unsigned long long orig_context = call.ret->toUIntPtr();
+    glws::Context *context = ws->createContext(glretrace::visual);
+    context_map[orig_context] = context;
 }
 
 static void retrace_wglDeleteContext(Trace::Call &call) {
 }
 
 static void retrace_wglMakeCurrent(Trace::Call &call) {
-    glFlush();
-    if (!double_buffer) {
-        frame_complete(call.no);
+    if (drawable && context) {
+        glFlush();
+        if (!double_buffer) {
+            frame_complete(call.no);
+        }
+    }
+    
+    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);
+
+    if (new_drawable && new_context && result) {
+        drawable = new_drawable;
+        context = new_context;
+    } else {
+        drawable = NULL;
+        context = NULL;
     }
 }
 
@@ -67,9 +107,22 @@ static void retrace_wglSwapBuffers(Trace::Call &call) {
 }
 
 static void retrace_wglShareLists(Trace::Call &call) {
+    unsigned long long hglrc1 = call.arg(0).toUIntPtr();
+    unsigned long long hglrc2 = call.arg(1).toUIntPtr();
+
+    glws::Context *share_context = context_map[hglrc1];
+    glws::Context *old_context = context_map[hglrc2];
+
+    glws::Context *new_context =
+        ws->createContext(old_context->visual, share_context);
+    if (new_context) {
+        delete old_context;
+        context_map[hglrc2] = new_context;
+    }
 }
 
 static void retrace_wglCreateLayerContext(Trace::Call &call) {
+    retrace_wglCreateContext(call);
 }
 
 static void retrace_wglDescribeLayerPlane(Trace::Call &call) {
@@ -82,6 +135,7 @@ static void retrace_wglRealizeLayerPalette(Trace::Call &call) {
 }
 
 static void retrace_wglSwapLayerBuffers(Trace::Call &call) {
+    retrace_wglSwapBuffers(call);
 }
 
 static void retrace_wglUseFontBitmapsA(Trace::Call &call) {
@@ -118,6 +172,23 @@ static void retrace_wglMakeContextCurrentARB(Trace::Call &call) {
 }
 
 static void retrace_wglCreatePbufferARB(Trace::Call &call) {
+    int iWidth = call.arg(2).toUInt();
+    int iHeight = call.arg(3).toUInt();
+
+    unsigned long long orig_pbuffer = call.ret->toUIntPtr();
+    glws::Drawable *drawable = ws->createDrawable(glretrace::visual);
+
+    drawable->resize(iWidth, iHeight);
+
+    pbuffer_map[orig_pbuffer] = drawable;
+}
+
+static void retrace_wglGetPbufferDCARB(Trace::Call &call) {
+    glws::Drawable *pbuffer = pbuffer_map[call.arg(0).toUIntPtr()];
+
+    unsigned long long orig_hdc = call.ret->toUIntPtr();
+
+    drawable_map[orig_hdc] = pbuffer;
 }
 
 static void retrace_wglReleasePbufferDCARB(Trace::Call &call) {
@@ -139,6 +210,15 @@ static void retrace_wglSetPbufferAttribARB(Trace::Call &call) {
 }
 
 static void retrace_wglCreateContextAttribsARB(Trace::Call &call) {
+    unsigned long long orig_context = call.ret->toUIntPtr();
+    glws::Context *share_context = NULL;
+
+    if (call.arg(1).toPointer()) {
+        share_context = context_map[call.arg(1).toUIntPtr()];
+    }
+
+    glws::Context *context = ws->createContext(glretrace::visual, share_context);
+    context_map[orig_context] = context;
 }
 
 static void retrace_wglMakeContextCurrentEXT(Trace::Call &call) {
@@ -169,8 +249,8 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
     case 'g':
         if (name[1] == 'l' && name[2] == 'A' && name[3] == 'd' && name[4] == 'd' && name[5] == 'S' && name[6] == 'w' && name[7] == 'a' && name[8] == 'p' && name[9] == 'H' && name[10] == 'i' && name[11] == 'n' && name[12] == 't' && name[13] == 'R' && name[14] == 'e' && name[15] == 'c' && name[16] == 't' && name[17] == 'W' && name[18] == 'I' && name[19] == 'N' && name[20] == '\0') {
             // glAddSwapHintRectWIN
-        retrace_glAddSwapHintRectWIN(call);
-        return;
+            retrace_glAddSwapHintRectWIN(call);
+            return;
         }
         break;
     case 'w':
@@ -182,15 +262,15 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                 case 'A':
                     if (name[4] == 'l' && name[5] == 'l' && name[6] == 'o' && name[7] == 'c' && name[8] == 'a' && name[9] == 't' && name[10] == 'e' && name[11] == 'M' && name[12] == 'e' && name[13] == 'm' && name[14] == 'o' && name[15] == 'r' && name[16] == 'y' && name[17] == 'N' && name[18] == 'V' && name[19] == '\0') {
                         // wglAllocateMemoryNV
-        retrace_wglAllocateMemoryNV(call);
-        return;
+                        retrace_wglAllocateMemoryNV(call);
+                        return;
                     }
                     break;
                 case 'B':
                     if (name[4] == 'i' && name[5] == 'n' && name[6] == 'd' && name[7] == 'T' && name[8] == 'e' && name[9] == 'x' && name[10] == 'I' && name[11] == 'm' && name[12] == 'a' && name[13] == 'g' && name[14] == 'e' && name[15] == 'A' && name[16] == 'R' && name[17] == 'B' && name[18] == '\0') {
                         // wglBindTexImageARB
-        retrace_wglBindTexImageARB(call);
-        return;
+                        retrace_wglBindTexImageARB(call);
+                        return;
                     }
                     break;
                 case 'C':
@@ -229,21 +309,21 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                                                                     switch (name[20]) {
                                                                                     case '\0':
                                                                                         // wglChoosePixelFormat
-        retrace_wglChoosePixelFormat(call);
-        return;
+                                                                                        retrace_wglChoosePixelFormat(call);
+                                                                                        return;
                                                                                         break;
                                                                                     case 'A':
                                                                                         if (name[21] == 'R' && name[22] == 'B' && name[23] == '\0') {
                                                                                             // wglChoosePixelFormatARB
-        retrace_wglChoosePixelFormatARB(call);
-        return;
+                                                                                            retrace_wglChoosePixelFormatARB(call);
+                                                                                            return;
                                                                                         }
                                                                                         break;
                                                                                     case 'E':
                                                                                         if (name[21] == 'X' && name[22] == 'T' && name[23] == '\0') {
                                                                                             // wglChoosePixelFormatEXT
-        retrace_wglChoosePixelFormatEXT(call);
-        return;
+                                                                                            retrace_wglChoosePixelFormatEXT(call);
+                                                                                            return;
                                                                                         }
                                                                                         break;
                                                                                     }
@@ -281,8 +361,8 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                     case 'o':
                         if (name[5] == 'p' && name[6] == 'y' && name[7] == 'C' && name[8] == 'o' && name[9] == 'n' && name[10] == 't' && name[11] == 'e' && name[12] == 'x' && name[13] == 't' && name[14] == '\0') {
                             // wglCopyContext
-        retrace_wglCopyContext(call);
-        return;
+                            retrace_wglCopyContext(call);
+                            return;
                         }
                         break;
                     case 'r':
@@ -298,8 +378,8 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                         case 'B':
                                             if (name[10] == 'u' && name[11] == 'f' && name[12] == 'f' && name[13] == 'e' && name[14] == 'r' && name[15] == 'R' && name[16] == 'e' && name[17] == 'g' && name[18] == 'i' && name[19] == 'o' && name[20] == 'n' && name[21] == 'A' && name[22] == 'R' && name[23] == 'B' && name[24] == '\0') {
                                                 // wglCreateBufferRegionARB
-        retrace_wglCreateBufferRegionARB(call);
-        return;
+                                                retrace_wglCreateBufferRegionARB(call);
+                                                return;
                                             }
                                             break;
                                         case 'C':
@@ -318,14 +398,14 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                                                     switch (name[16]) {
                                                                     case '\0':
                                                                         // wglCreateContext
-        retrace_wglCreateContext(call);
-        return;
+                                                                        retrace_wglCreateContext(call);
+                                                                        return;
                                                                         break;
                                                                     case 'A':
                                                                         if (name[17] == 't' && name[18] == 't' && name[19] == 'r' && name[20] == 'i' && name[21] == 'b' && name[22] == 's' && name[23] == 'A' && name[24] == 'R' && name[25] == 'B' && name[26] == '\0') {
                                                                             // wglCreateContextAttribsARB
-        retrace_wglCreateContextAttribsARB(call);
-        return;
+                                                                            retrace_wglCreateContextAttribsARB(call);
+                                                                            return;
                                                                         }
                                                                         break;
                                                                     }
@@ -345,15 +425,15 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                         case 'L':
                                             if (name[10] == 'a' && name[11] == 'y' && name[12] == 'e' && name[13] == 'r' && name[14] == 'C' && name[15] == 'o' && name[16] == 'n' && name[17] == 't' && name[18] == 'e' && name[19] == 'x' && name[20] == 't' && name[21] == '\0') {
                                                 // wglCreateLayerContext
-        retrace_wglCreateLayerContext(call);
-        return;
+                                                retrace_wglCreateLayerContext(call);
+                                                return;
                                             }
                                             break;
                                         case 'P':
                                             if (name[10] == 'b' && name[11] == 'u' && name[12] == 'f' && name[13] == 'f' && name[14] == 'e' && name[15] == 'r' && name[16] == 'A' && name[17] == 'R' && name[18] == 'B' && name[19] == '\0') {
                                                 // wglCreatePbufferARB
-        retrace_wglCreatePbufferARB(call);
-        return;
+                                                retrace_wglCreatePbufferARB(call);
+                                                return;
                                             }
                                             break;
                                         }
@@ -383,15 +463,15 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                         case 'B':
                                             if (name[10] == 'u' && name[11] == 'f' && name[12] == 'f' && name[13] == 'e' && name[14] == 'r' && name[15] == 'R' && name[16] == 'e' && name[17] == 'g' && name[18] == 'i' && name[19] == 'o' && name[20] == 'n' && name[21] == 'A' && name[22] == 'R' && name[23] == 'B' && name[24] == '\0') {
                                                 // wglDeleteBufferRegionARB
-        retrace_wglDeleteBufferRegionARB(call);
-        return;
+                                                retrace_wglDeleteBufferRegionARB(call);
+                                                return;
                                             }
                                             break;
                                         case 'C':
                                             if (name[10] == 'o' && name[11] == 'n' && name[12] == 't' && name[13] == 'e' && name[14] == 'x' && name[15] == 't' && name[16] == '\0') {
                                                 // wglDeleteContext
-        retrace_wglDeleteContext(call);
-        return;
+                                                retrace_wglDeleteContext(call);
+                                                return;
                                             }
                                             break;
                                         }
@@ -417,15 +497,15 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                                 case 'L':
                                                     if (name[12] == 'a' && name[13] == 'y' && name[14] == 'e' && name[15] == 'r' && name[16] == 'P' && name[17] == 'l' && name[18] == 'a' && name[19] == 'n' && name[20] == 'e' && name[21] == '\0') {
                                                         // wglDescribeLayerPlane
-        retrace_wglDescribeLayerPlane(call);
-        return;
+                                                        retrace_wglDescribeLayerPlane(call);
+                                                        return;
                                                     }
                                                     break;
                                                 case 'P':
                                                     if (name[12] == 'i' && name[13] == 'x' && name[14] == 'e' && name[15] == 'l' && name[16] == 'F' && name[17] == 'o' && name[18] == 'r' && name[19] == 'm' && name[20] == 'a' && name[21] == 't' && name[22] == '\0') {
                                                         // wglDescribePixelFormat
-        retrace_wglDescribePixelFormat(call);
-        return;
+                                                        retrace_wglDescribePixelFormat(call);
+                                                        return;
                                                     }
                                                     break;
                                                 }
@@ -441,8 +521,8 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                             case 't':
                                 if (name[7] == 'r' && name[8] == 'o' && name[9] == 'y' && name[10] == 'P' && name[11] == 'b' && name[12] == 'u' && name[13] == 'f' && name[14] == 'f' && name[15] == 'e' && name[16] == 'r' && name[17] == 'A' && name[18] == 'R' && name[19] == 'B' && name[20] == '\0') {
                                     // wglDestroyPbufferARB
-        retrace_wglDestroyPbufferARB(call);
-        return;
+                                    retrace_wglDestroyPbufferARB(call);
+                                    return;
                                 }
                                 break;
                             }
@@ -454,8 +534,8 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                 case 'F':
                     if (name[4] == 'r' && name[5] == 'e' && name[6] == 'e' && name[7] == 'M' && name[8] == 'e' && name[9] == 'm' && name[10] == 'o' && name[11] == 'r' && name[12] == 'y' && name[13] == 'N' && name[14] == 'V' && name[15] == '\0') {
                         // wglFreeMemoryNV
-        retrace_wglFreeMemoryNV(call);
-        return;
+                        retrace_wglFreeMemoryNV(call);
+                        return;
                     }
                     break;
                 case 'G':
@@ -481,13 +561,13 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                                         case 'C':
                                                             if (name[14] == 'o' && name[15] == 'n' && name[16] == 't' && name[17] == 'e' && name[18] == 'x' && name[19] == 't' && name[20] == '\0') {
                                                                 // wglGetCurrentContext
-        return;
+                                                                return;
                                                             }
                                                             break;
                                                         case 'D':
                                                             if (name[14] == 'C' && name[15] == '\0') {
                                                                 // wglGetCurrentDC
-        return;
+                                                                return;
                                                             }
                                                             break;
                                                         case 'R':
@@ -505,13 +585,13 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                                                                 case 'A':
                                                                                     if (name[20] == 'R' && name[21] == 'B' && name[22] == '\0') {
                                                                                         // wglGetCurrentReadDCARB
-        return;
+                                                                                        return;
                                                                                     }
                                                                                     break;
                                                                                 case 'E':
                                                                                     if (name[20] == 'X' && name[21] == 'T' && name[22] == '\0') {
                                                                                         // wglGetCurrentReadDCEXT
-        return;
+                                                                                        return;
                                                                                     }
                                                                                     break;
                                                                                 }
@@ -543,7 +623,7 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                             case 'D':
                                 if (name[7] == 'e' && name[8] == 'f' && name[9] == 'a' && name[10] == 'u' && name[11] == 'l' && name[12] == 't' && name[13] == 'P' && name[14] == 'r' && name[15] == 'o' && name[16] == 'c' && name[17] == 'A' && name[18] == 'd' && name[19] == 'd' && name[20] == 'r' && name[21] == 'e' && name[22] == 's' && name[23] == 's' && name[24] == '\0') {
                                     // wglGetDefaultProcAddress
-        return;
+                                    return;
                                 }
                                 break;
                             case 'E':
@@ -581,13 +661,13 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                                                                             case 'A':
                                                                                                 if (name[23] == 'R' && name[24] == 'B' && name[25] == '\0') {
                                                                                                     // wglGetExtensionsStringARB
-        return;
+                                                                                                    return;
                                                                                                 }
                                                                                                 break;
                                                                                             case 'E':
                                                                                                 if (name[23] == 'X' && name[24] == 'T' && name[25] == '\0') {
                                                                                                     // wglGetExtensionsStringEXT
-        return;
+                                                                                                    return;
                                                                                                 }
                                                                                                 break;
                                                                                             }
@@ -625,7 +705,7 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                             case 'L':
                                 if (name[7] == 'a' && name[8] == 'y' && name[9] == 'e' && name[10] == 'r' && name[11] == 'P' && name[12] == 'a' && name[13] == 'l' && name[14] == 'e' && name[15] == 't' && name[16] == 't' && name[17] == 'e' && name[18] == 'E' && name[19] == 'n' && name[20] == 't' && name[21] == 'r' && name[22] == 'i' && name[23] == 'e' && name[24] == 's' && name[25] == '\0') {
                                     // wglGetLayerPaletteEntries
-        return;
+                                    return;
                                 }
                                 break;
                             case 'P':
@@ -633,7 +713,8 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                 case 'b':
                                     if (name[8] == 'u' && name[9] == 'f' && name[10] == 'f' && name[11] == 'e' && name[12] == 'r' && name[13] == 'D' && name[14] == 'C' && name[15] == 'A' && name[16] == 'R' && name[17] == 'B' && name[18] == '\0') {
                                         // wglGetPbufferDCARB
-        return;
+                                        retrace_wglGetPbufferDCARB(call);
+                                        return;
                                     }
                                     break;
                                 case 'i':
@@ -658,7 +739,7 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                                                         switch (name[17]) {
                                                                         case '\0':
                                                                             // wglGetPixelFormat
-        return;
+                                                                            return;
                                                                             break;
                                                                         case 'A':
                                                                             switch (name[18]) {
@@ -679,13 +760,13 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                                                                                         case 'A':
                                                                                                             if (name[26] == 'R' && name[27] == 'B' && name[28] == '\0') {
                                                                                                                 // wglGetPixelFormatAttribfvARB
-        return;
+                                                                                                                return;
                                                                                                             }
                                                                                                             break;
                                                                                                         case 'E':
                                                                                                             if (name[26] == 'X' && name[27] == 'T' && name[28] == '\0') {
                                                                                                                 // wglGetPixelFormatAttribfvEXT
-        return;
+                                                                                                                return;
                                                                                                             }
                                                                                                             break;
                                                                                                         }
@@ -699,13 +780,13 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                                                                                         case 'A':
                                                                                                             if (name[26] == 'R' && name[27] == 'B' && name[28] == '\0') {
                                                                                                                 // wglGetPixelFormatAttribivARB
-        return;
+                                                                                                                return;
                                                                                                             }
                                                                                                             break;
                                                                                                         case 'E':
                                                                                                             if (name[26] == 'X' && name[27] == 'T' && name[28] == '\0') {
                                                                                                                 // wglGetPixelFormatAttribivEXT
-        return;
+                                                                                                                return;
                                                                                                             }
                                                                                                             break;
                                                                                                         }
@@ -747,8 +828,8 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                 case 'r':
                                     if (name[8] == 'o' && name[9] == 'c' && name[10] == 'A' && name[11] == 'd' && name[12] == 'd' && name[13] == 'r' && name[14] == 'e' && name[15] == 's' && name[16] == 's' && name[17] == '\0') {
                                         // wglGetProcAddress
-        retrace_wglGetProcAddress(call);
-        return;
+                                        retrace_wglGetProcAddress(call);
+                                        return;
                                     }
                                     break;
                                 }
@@ -756,7 +837,7 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                             case 'S':
                                 if (name[7] == 'w' && name[8] == 'a' && name[9] == 'p' && name[10] == 'I' && name[11] == 'n' && name[12] == 't' && name[13] == 'e' && name[14] == 'r' && name[15] == 'v' && name[16] == 'a' && name[17] == 'l' && name[18] == 'E' && name[19] == 'X' && name[20] == 'T' && name[21] == '\0') {
                                     // wglGetSwapIntervalEXT
-        return;
+                                    return;
                                 }
                                 break;
                             }
@@ -804,15 +885,15 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                                                                         case 'A':
                                                                                             if (name[22] == 'R' && name[23] == 'B' && name[24] == '\0') {
                                                                                                 // wglMakeContextCurrentARB
-        retrace_wglMakeContextCurrentARB(call);
-        return;
+                                                                                                retrace_wglMakeContextCurrentARB(call);
+                                                                                                return;
                                                                                             }
                                                                                             break;
                                                                                         case 'E':
                                                                                             if (name[22] == 'X' && name[23] == 'T' && name[24] == '\0') {
                                                                                                 // wglMakeContextCurrentEXT
-        retrace_wglMakeContextCurrentEXT(call);
-        return;
+                                                                                                retrace_wglMakeContextCurrentEXT(call);
+                                                                                                return;
                                                                                             }
                                                                                             break;
                                                                                         }
@@ -844,8 +925,8 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                     case 'u':
                                         if (name[9] == 'r' && name[10] == 'r' && name[11] == 'e' && name[12] == 'n' && name[13] == 't' && name[14] == '\0') {
                                             // wglMakeCurrent
-        retrace_wglMakeCurrent(call);
-        return;
+                                            retrace_wglMakeCurrent(call);
+                                            return;
                                         }
                                         break;
                                     }
@@ -861,8 +942,8 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                 case 'Q':
                     if (name[4] == 'u' && name[5] == 'e' && name[6] == 'r' && name[7] == 'y' && name[8] == 'P' && name[9] == 'b' && name[10] == 'u' && name[11] == 'f' && name[12] == 'f' && name[13] == 'e' && name[14] == 'r' && name[15] == 'A' && name[16] == 'R' && name[17] == 'B' && name[18] == '\0') {
                         // wglQueryPbufferARB
-        retrace_wglQueryPbufferARB(call);
-        return;
+                        retrace_wglQueryPbufferARB(call);
+                        return;
                     }
                     break;
                 case 'R':
@@ -872,8 +953,8 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                         case 'a':
                             if (name[6] == 'l' && name[7] == 'i' && name[8] == 'z' && name[9] == 'e' && name[10] == 'L' && name[11] == 'a' && name[12] == 'y' && name[13] == 'e' && name[14] == 'r' && name[15] == 'P' && name[16] == 'a' && name[17] == 'l' && name[18] == 'e' && name[19] == 't' && name[20] == 't' && name[21] == 'e' && name[22] == '\0') {
                                 // wglRealizeLayerPalette
-        retrace_wglRealizeLayerPalette(call);
-        return;
+                                retrace_wglRealizeLayerPalette(call);
+                                return;
                             }
                             break;
                         case 'l':
@@ -889,15 +970,15 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                             case 'P':
                                                 if (name[11] == 'b' && name[12] == 'u' && name[13] == 'f' && name[14] == 'f' && name[15] == 'e' && name[16] == 'r' && name[17] == 'D' && name[18] == 'C' && name[19] == 'A' && name[20] == 'R' && name[21] == 'B' && name[22] == '\0') {
                                                     // wglReleasePbufferDCARB
-        retrace_wglReleasePbufferDCARB(call);
-        return;
+                                                    retrace_wglReleasePbufferDCARB(call);
+                                                    return;
                                                 }
                                                 break;
                                             case 'T':
                                                 if (name[11] == 'e' && name[12] == 'x' && name[13] == 'I' && name[14] == 'm' && name[15] == 'a' && name[16] == 'g' && name[17] == 'e' && name[18] == 'A' && name[19] == 'R' && name[20] == 'B' && name[21] == '\0') {
                                                     // wglReleaseTexImageARB
-        retrace_wglReleaseTexImageARB(call);
-        return;
+                                                    retrace_wglReleaseTexImageARB(call);
+                                                    return;
                                                 }
                                                 break;
                                             }
@@ -913,8 +994,8 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                         case 's':
                             if (name[6] == 't' && name[7] == 'o' && name[8] == 'r' && name[9] == 'e' && name[10] == 'B' && name[11] == 'u' && name[12] == 'f' && name[13] == 'f' && name[14] == 'e' && name[15] == 'r' && name[16] == 'R' && name[17] == 'e' && name[18] == 'g' && name[19] == 'i' && name[20] == 'o' && name[21] == 'n' && name[22] == 'A' && name[23] == 'R' && name[24] == 'B' && name[25] == '\0') {
                                 // wglRestoreBufferRegionARB
-        retrace_wglRestoreBufferRegionARB(call);
-        return;
+                                retrace_wglRestoreBufferRegionARB(call);
+                                return;
                             }
                             break;
                         }
@@ -926,8 +1007,8 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                     case 'a':
                         if (name[5] == 'v' && name[6] == 'e' && name[7] == 'B' && name[8] == 'u' && name[9] == 'f' && name[10] == 'f' && name[11] == 'e' && name[12] == 'r' && name[13] == 'R' && name[14] == 'e' && name[15] == 'g' && name[16] == 'i' && name[17] == 'o' && name[18] == 'n' && name[19] == 'A' && name[20] == 'R' && name[21] == 'B' && name[22] == '\0') {
                             // wglSaveBufferRegionARB
-        retrace_wglSaveBufferRegionARB(call);
-        return;
+                            retrace_wglSaveBufferRegionARB(call);
+                            return;
                         }
                         break;
                     case 'e':
@@ -937,8 +1018,8 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                             case 'L':
                                 if (name[7] == 'a' && name[8] == 'y' && name[9] == 'e' && name[10] == 'r' && name[11] == 'P' && name[12] == 'a' && name[13] == 'l' && name[14] == 'e' && name[15] == 't' && name[16] == 't' && name[17] == 'e' && name[18] == 'E' && name[19] == 'n' && name[20] == 't' && name[21] == 'r' && name[22] == 'i' && name[23] == 'e' && name[24] == 's' && name[25] == '\0') {
                                     // wglSetLayerPaletteEntries
-        retrace_wglSetLayerPaletteEntries(call);
-        return;
+                                    retrace_wglSetLayerPaletteEntries(call);
+                                    return;
                                 }
                                 break;
                             case 'P':
@@ -946,15 +1027,15 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                 case 'b':
                                     if (name[8] == 'u' && name[9] == 'f' && name[10] == 'f' && name[11] == 'e' && name[12] == 'r' && name[13] == 'A' && name[14] == 't' && name[15] == 't' && name[16] == 'r' && name[17] == 'i' && name[18] == 'b' && name[19] == 'A' && name[20] == 'R' && name[21] == 'B' && name[22] == '\0') {
                                         // wglSetPbufferAttribARB
-        retrace_wglSetPbufferAttribARB(call);
-        return;
+                                        retrace_wglSetPbufferAttribARB(call);
+                                        return;
                                     }
                                     break;
                                 case 'i':
                                     if (name[8] == 'x' && name[9] == 'e' && name[10] == 'l' && name[11] == 'F' && name[12] == 'o' && name[13] == 'r' && name[14] == 'm' && name[15] == 'a' && name[16] == 't' && name[17] == '\0') {
                                         // wglSetPixelFormat
-        retrace_wglSetPixelFormat(call);
-        return;
+                                        retrace_wglSetPixelFormat(call);
+                                        return;
                                     }
                                     break;
                                 }
@@ -966,8 +1047,8 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                     case 'h':
                         if (name[5] == 'a' && name[6] == 'r' && name[7] == 'e' && name[8] == 'L' && name[9] == 'i' && name[10] == 's' && name[11] == 't' && name[12] == 's' && name[13] == '\0') {
                             // wglShareLists
-        retrace_wglShareLists(call);
-        return;
+                            retrace_wglShareLists(call);
+                            return;
                         }
                         break;
                     case 'w':
@@ -979,29 +1060,29 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                 case 'B':
                                     if (name[8] == 'u' && name[9] == 'f' && name[10] == 'f' && name[11] == 'e' && name[12] == 'r' && name[13] == 's' && name[14] == '\0') {
                                         // wglSwapBuffers
-        retrace_wglSwapBuffers(call);
-        return;
+                                        retrace_wglSwapBuffers(call);
+                                        return;
                                     }
                                     break;
                                 case 'I':
                                     if (name[8] == 'n' && name[9] == 't' && name[10] == 'e' && name[11] == 'r' && name[12] == 'v' && name[13] == 'a' && name[14] == 'l' && name[15] == 'E' && name[16] == 'X' && name[17] == 'T' && name[18] == '\0') {
                                         // wglSwapIntervalEXT
-        retrace_wglSwapIntervalEXT(call);
-        return;
+                                        retrace_wglSwapIntervalEXT(call);
+                                        return;
                                     }
                                     break;
                                 case 'L':
                                     if (name[8] == 'a' && name[9] == 'y' && name[10] == 'e' && name[11] == 'r' && name[12] == 'B' && name[13] == 'u' && name[14] == 'f' && name[15] == 'f' && name[16] == 'e' && name[17] == 'r' && name[18] == 's' && name[19] == '\0') {
                                         // wglSwapLayerBuffers
-        retrace_wglSwapLayerBuffers(call);
-        return;
+                                        retrace_wglSwapLayerBuffers(call);
+                                        return;
                                     }
                                     break;
                                 case 'M':
                                     if (name[8] == 'u' && name[9] == 'l' && name[10] == 't' && name[11] == 'i' && name[12] == 'p' && name[13] == 'l' && name[14] == 'e' && name[15] == 'B' && name[16] == 'u' && name[17] == 'f' && name[18] == 'f' && name[19] == 'e' && name[20] == 'r' && name[21] == 's' && name[22] == '\0') {
                                         // wglSwapMultipleBuffers
-        retrace_wglSwapMultipleBuffers(call);
-        return;
+                                        retrace_wglSwapMultipleBuffers(call);
+                                        return;
                                     }
                                     break;
                                 }
@@ -1043,15 +1124,15 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                                                         case 'A':
                                                                             if (name[18] == '\0') {
                                                                                 // wglUseFontBitmapsA
-        retrace_wglUseFontBitmapsA(call);
-        return;
+                                                                                retrace_wglUseFontBitmapsA(call);
+                                                                                return;
                                                                             }
                                                                             break;
                                                                         case 'W':
                                                                             if (name[18] == '\0') {
                                                                                 // wglUseFontBitmapsW
-        retrace_wglUseFontBitmapsW(call);
-        return;
+                                                                                retrace_wglUseFontBitmapsW(call);
+                                                                                return;
                                                                             }
                                                                             break;
                                                                         }
@@ -1087,15 +1168,15 @@ void glretrace::retrace_call_wgl(Trace::Call &call) {
                                                                             case 'A':
                                                                                 if (name[19] == '\0') {
                                                                                     // wglUseFontOutlinesA
-        retrace_wglUseFontOutlinesA(call);
-        return;
+                                                                                    retrace_wglUseFontOutlinesA(call);
+                                                                                    return;
                                                                                 }
                                                                                 break;
                                                                             case 'W':
                                                                                 if (name[19] == '\0') {
                                                                                     // wglUseFontOutlinesW
-        retrace_wglUseFontOutlinesW(call);
-        return;
+                                                                                    retrace_wglUseFontOutlinesW(call);
+                                                                                    return;
                                                                                 }
                                                                                 break;
                                                                             }
index f45216f8205040cb70614aaf2eebec5538e461df..34405a5e454bbf83450031bbd51e400448057645 100644 (file)
@@ -430,14 +430,14 @@ writeTextureImage(JSONWriter &json, GLenum target, GLint level)
 static inline void
 writeDrawBufferImage(JSONWriter &json, GLenum format)
 {
-    GLint width  = glretrace::window_width;
-    GLint height = glretrace::window_height;
-
     GLint channels = __gl_format_channels(format);
 
-    if (!width || !height) {
+    if (!glretrace::drawable) {
         json.writeNull();
     } else {
+        GLint width  = glretrace::drawable->width;
+        GLint height = glretrace::drawable->height;
+
         json.beginObject();
 
         // Tell the GUI this is no ordinary object, but an image
index 7f4b52d9db9526bc9e8d8b78321d86be6751b4a8..bfd34480613e4713ddb24a77e9a7ee85f38a3715 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,10 +94,10 @@ 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;
+    createContext(const Visual *visual, Context *shareContext = NULL) = 0;
     
     virtual bool
     makeCurrent(Drawable *drawable, Context *context) = 0;
index 64f8ce129a41089a75f702c39b6f0359533171d8..732f33d150671430b473546e0c5accee898d35a7 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,65 +177,32 @@ 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 *
-    createContext(const Visual *visual)
+    createContext(const Visual *visual, Context *shareContext)
     {
         XVisualInfo *visinfo = dynamic_cast<const GlxVisual *>(visual)->visinfo;
-        GLXContext context = glXCreateContext(display, visinfo, NULL, True);
-        return new GlxContext(visual, display, context);
+        GLXContext share_context = NULL;
+        GLXContext context;
+
+        if (shareContext) {
+            share_context = dynamic_cast<GlxContext*>(shareContext)->context;
+        }
+
+        context = glXCreateContext(display, visinfo,
+                                   share_context, True);
+        return new GlxContext(visual, context);
     }
 
     bool
index bc4dd27132b97025945ff4edce94b94209ce105d..b20374362a01f3301685b2152b4045b7367d2571 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);
@@ -154,10 +154,12 @@ class WglContext : public Context
 {
 public:
     HGLRC hglrc;
-    
-    WglContext(const Visual *vis) :
+    WglContext *shareContext;
+
+    WglContext(const Visual *vis, WglContext *share) :
         Context(vis),
-        hglrc(0)
+        hglrc(0),
+        shareContext(share)
     {}
 
     ~WglContext() {
@@ -181,15 +183,15 @@ 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 *
-    createContext(const Visual *visual)
+    createContext(const Visual *visual, Context *shareContext)
     {
-        return new WglContext(visual);
+        return new WglContext(visual, dynamic_cast<WglContext *>(shareContext));
     }
 
     bool
@@ -206,6 +208,10 @@ public:
                 if (!wglContext->hglrc) {
                     return false;
                 }
+                if (wglContext->shareContext) {
+                    wglShareLists(wglContext->shareContext->hglrc,
+                                  wglContext->hglrc);
+                }
             }
 
             return wglMakeCurrent(wglDrawable->hDC, wglContext->hglrc);
index 14f10b8b29ad19f0eaad9026641a317c9c87eb96..b16a7708f561b6b062d47675766eebaf219f7c77 100644 (file)
@@ -137,7 +137,7 @@ writeValue(const QVariant &var, unsigned &id)
     }
         break;
     case QVariant::Double:
-        Trace::LiteralFloat(var.toDouble());
+        Trace::LiteralDouble(var.toDouble());
         break;
     case QMetaType::Float:
         Trace::LiteralFloat(var.toFloat());
index f931c88988760b883d9cb70b6c54d840274a5cb6..81652e5eddb1afd0bf9ec9ffab8be71fe4552c35 100644 (file)
@@ -51,10 +51,8 @@ def handle_entry(handle, value):
 class ValueExtractor(stdapi.Visitor):
 
     def visit_literal(self, literal, lvalue, rvalue):
-        if literal.format == 'Bool':
-            print '    %s = static_cast<bool>(%s);' % (lvalue, rvalue)
-        else:
-            print '    %s = %s;' % (lvalue, rvalue)
+        #if literal.format in ('Bool', 'UInt'):
+        print '    %s = (%s).to%s();' % (lvalue, rvalue, literal.format)
 
     def visit_const(self, const, lvalue, rvalue):
         self.visit(const.type, lvalue, rvalue)
@@ -63,7 +61,7 @@ class ValueExtractor(stdapi.Visitor):
         self.visit(alias.type, lvalue, rvalue)
     
     def visit_enum(self, enum, lvalue, rvalue):
-        print '    %s = %s;' % (lvalue, rvalue)
+        print '    %s = (%s).toSInt();' % (lvalue, rvalue)
 
     def visit_bitmask(self, bitmask, lvalue, rvalue):
         self.visit(bitmask.type, lvalue, rvalue)
@@ -102,10 +100,10 @@ class ValueExtractor(stdapi.Visitor):
         print '    %s = %s;' % (lvalue, new_lvalue)
     
     def visit_blob(self, blob, lvalue, rvalue):
-        print '    %s = static_cast<%s>((%s).blob());' % (lvalue, blob, rvalue)
+        print '    %s = static_cast<%s>((%s).toPointer());' % (lvalue, blob, rvalue)
     
     def visit_string(self, string, lvalue, rvalue):
-        print '    %s = (%s)((%s).string());' % (lvalue, string.expr, rvalue)
+        print '    %s = (%s)((%s).toString());' % (lvalue, string.expr, rvalue)
 
 
 class OpaqueValueExtractor(ValueExtractor):
@@ -115,7 +113,7 @@ class OpaqueValueExtractor(ValueExtractor):
     in the context of handles.'''
 
     def visit_opaque(self, opaque, lvalue, rvalue):
-        print '    %s = static_cast<%s>((%s).blob());' % (lvalue, opaque, rvalue)
+        print '    %s = static_cast<%s>((%s).toPointer());' % (lvalue, opaque, rvalue)
 
 
 class ValueWrapper(stdapi.Visitor):
index 586d2d36a66fee36450dbdbc35f914e134ebc4e8..8a2756641663c265e7290432c21cec4409ecdf00 100644 (file)
--- a/stdapi.py
+++ b/stdapi.py
@@ -562,7 +562,7 @@ UInt = Literal("unsigned int", "UInt")
 ULong = Literal("unsigned long", "UInt")
 ULongLong = Literal("unsigned long long", "UInt")
 Float = Literal("float", "Float")
-Double = Literal("double", "Float")
+Double = Literal("double", "Double")
 SizeT = Literal("size_t", "UInt")
 WString = Literal("wchar_t *", "WString")
 
index a817b39ea91c55c48ef1e47e485b0ddd1124d09d..2821cc557a08a0db770a062b1c8da66d3cfb27c1 100644 (file)
@@ -63,54 +63,76 @@ Blob::~Blob() {
 
 
 // bool cast
-Null   ::operator bool(void) const { return false; }
-Bool   ::operator bool(void) const { return value; }
-SInt   ::operator bool(void) const { return value != 0; }
-UInt   ::operator bool(void) const { return value != 0; }
-Float  ::operator bool(void) const { return value != 0; }
-String ::operator bool(void) const { return true; }
-Enum   ::operator bool(void) const { return static_cast<bool>(*sig->second); }
-Struct ::operator bool(void) const { return true; }
-Array  ::operator bool(void) const { return true; }
-Blob   ::operator bool(void) const { return true; }
-Pointer::operator bool(void) const { return value != 0; }
+bool Null   ::toBool(void) const { return false; }
+bool Bool   ::toBool(void) const { return value; }
+bool SInt   ::toBool(void) const { return value != 0; }
+bool UInt   ::toBool(void) const { return value != 0; }
+bool Float  ::toBool(void) const { return value != 0; }
+bool String ::toBool(void) const { return true; }
+bool Enum   ::toBool(void) const { return sig->second->toBool(); }
+bool Struct ::toBool(void) const { return true; }
+bool Array  ::toBool(void) const { return true; }
+bool Blob   ::toBool(void) const { return true; }
+bool Pointer::toBool(void) const { return value != 0; }
 
 
 // signed integer cast
-Value  ::operator signed long long (void) const { assert(0); return 0; }
-Null   ::operator signed long long (void) const { return 0; }
-Bool   ::operator signed long long (void) const { return static_cast<signed long long>(value); }
-SInt   ::operator signed long long (void) const { return value; }
-UInt   ::operator signed long long (void) const { assert(static_cast<signed long long>(value) >= 0); return static_cast<signed long long>(value); }
-Float  ::operator signed long long (void) const { return static_cast<signed long long>(value); }
-Enum   ::operator signed long long (void) const { return static_cast<signed long long>(*sig->second); }
+signed long long Value  ::toSInt(void) const { assert(0); return 0; }
+signed long long Null   ::toSInt(void) const { return 0; }
+signed long long Bool   ::toSInt(void) const { return static_cast<signed long long>(value); }
+signed long long SInt   ::toSInt(void) const { return value; }
+signed long long UInt   ::toSInt(void) const { assert(static_cast<signed long long>(value) >= 0); return static_cast<signed long long>(value); }
+signed long long Float  ::toSInt(void) const { return static_cast<signed long long>(value); }
+signed long long Enum   ::toSInt(void) const { return sig->second->toSInt(); }
 
 
 // unsigned integer cast
-Value  ::operator unsigned long long (void) const { assert(0); return 0; }
-Null   ::operator unsigned long long (void) const { return 0; }
-Bool   ::operator unsigned long long (void) const { return static_cast<unsigned long long>(value); }
-SInt   ::operator unsigned long long (void) const { assert(value >= 0); return static_cast<signed long long>(value); }
-UInt   ::operator unsigned long long (void) const { return value; }
-Float  ::operator unsigned long long (void) const { return static_cast<unsigned long long>(value); }
-Enum   ::operator unsigned long long (void) const { return static_cast<unsigned long long>(*sig->second); }
+unsigned long long Value  ::toUInt(void) const { assert(0); return 0; }
+unsigned long long Null   ::toUInt(void) const { return 0; }
+unsigned long long Bool   ::toUInt(void) const { return static_cast<unsigned long long>(value); }
+unsigned long long SInt   ::toUInt(void) const { assert(value >= 0); return static_cast<signed long long>(value); }
+unsigned long long UInt   ::toUInt(void) const { return value; }
+unsigned long long Float  ::toUInt(void) const { return static_cast<unsigned long long>(value); }
+unsigned long long Enum   ::toUInt(void) const { return sig->second->toUInt(); }
 
 
 // floating point cast
-Value  ::operator double (void) const { assert(0); return 0; }
-Null   ::operator double (void) const { return 0; }
-Bool   ::operator double (void) const { return static_cast<double>(value); }
-SInt   ::operator double (void) const { return static_cast<double>(value); }
-UInt   ::operator double (void) const { return static_cast<double>(value); }
-Float  ::operator double (void) const { return value; }
-Enum   ::operator double (void) const { return static_cast<unsigned long long>(*sig->second); }
+float Value  ::toFloat(void) const { assert(0); return 0; }
+float Null   ::toFloat(void) const { return 0; }
+float Bool   ::toFloat(void) const { return static_cast<float>(value); }
+float SInt   ::toFloat(void) const { return static_cast<float>(value); }
+float UInt   ::toFloat(void) const { return static_cast<float>(value); }
+float Float  ::toFloat(void) const { return value; }
+float Enum   ::toFloat(void) const { return sig->second->toFloat(); }
 
 
-// blob cast
-void * Value  ::blob(void) const { assert(0); return NULL; }
-void * Null   ::blob(void) const { return NULL; }
-void * Blob   ::blob(void) const { return buf; }
-void * Pointer::blob(void) const { return (void *)value; }
+// floating point cast
+double Value  ::toDouble(void) const { assert(0); return 0; }
+double Null   ::toDouble(void) const { return 0; }
+double Bool   ::toDouble(void) const { return static_cast<double>(value); }
+double SInt   ::toDouble(void) const { return static_cast<double>(value); }
+double UInt   ::toDouble(void) const { return static_cast<double>(value); }
+double Float  ::toDouble(void) const { return value; }
+double Enum   ::toDouble(void) const { return sig->second->toDouble(); }
+
+
+// pointer cast
+void * Value  ::toPointer(void) const { assert(0); return NULL; }
+void * Null   ::toPointer(void) const { return NULL; }
+void * Blob   ::toPointer(void) const { return buf; }
+void * Pointer::toPointer(void) const { return (void *)value; }
+
+
+// pointer cast
+unsigned long long Value  ::toUIntPtr(void) const { assert(0); return 0; }
+unsigned long long Null   ::toUIntPtr(void) const { return 0; }
+unsigned long long Pointer::toUIntPtr(void) const { return value; }
+
+
+// string cast
+const char * Value ::toString(void) const { assert(0); return NULL; }
+const char * Null  ::toString(void) const { return NULL; }
+const char * String::toString(void) const { return value.c_str(); }
 
 
 // virtual Value::visit()
@@ -337,17 +359,6 @@ const Value & Value::operator[](size_t index) const {
     return null;
 }
 
-const char * Value::string(void) const {
-    const String *string = dynamic_cast<const String *>(unwrap(this));
-    if (string)
-        return string->value.c_str();
-    const Null *null = dynamic_cast<const Null *>(unwrap(this));
-    if (null)
-        return NULL;
-    assert(0);
-    return NULL;
-}
-
 std::ostream & operator <<(std::ostream &os, Call &call) {
     Dumper d(os);
     os << call.no << " ";
index 68f6626d5d0fb08c73662e7db2cede2b6c94b6a2..5e0a09d55319d61c1c22df530d2b0330a157afb5 100644 (file)
@@ -54,49 +54,15 @@ public:
     virtual ~Value() {}
     virtual void visit(Visitor &visitor) = 0;
 
-    virtual operator bool (void) const = 0;
-    virtual operator signed long long (void) const;
-    virtual operator unsigned long long (void) const;
-    virtual operator double (void) const;
+    virtual bool toBool(void) const = 0;
+    virtual signed long long toSInt(void) const;
+    virtual unsigned long long toUInt(void) const;
+    virtual float toFloat(void) const;
+    virtual double toDouble(void) const;
 
-    virtual void *blob(void) const;
-    const char *string(void) const;
-
-    inline operator signed char (void) const { 
-        return static_cast<signed long long>(*this);
-    }
-
-    inline operator unsigned char (void) const { 
-        return static_cast<signed long long>(*this);
-    }
-
-    inline operator signed short (void) const { 
-        return static_cast<signed long long>(*this);
-    }
-
-    inline operator unsigned short (void) const { 
-        return static_cast<unsigned long long>(*this);
-    }
-
-    inline operator signed (void) const { 
-        return static_cast<signed long long>(*this);
-    }
-
-    inline operator unsigned (void) const { 
-        return static_cast<unsigned long long>(*this);
-    }
-
-    inline operator signed long (void) const { 
-        return static_cast<signed long long>(*this);
-    }
-
-    inline operator unsigned long (void) const { 
-        return static_cast<unsigned long long>(*this);
-    }
-
-    inline operator float (void) const { 
-        return static_cast<double>(*this);
-    }
+    virtual void *toPointer(void) const;
+    virtual unsigned long long toUIntPtr(void) const;
+    virtual const char *toString(void) const;
 
     const Value & operator[](size_t index) const;
 };
@@ -105,11 +71,14 @@ public:
 class Null : public Value
 {
 public:
-    operator bool (void) const;
-    operator signed long long (void) const;
-    operator unsigned long long (void) const;
-    operator double (void) const;
-    void *blob(void) const;
+    bool toBool(void) const;
+    signed long long toSInt(void) const;
+    unsigned long long toUInt(void) const;
+    virtual float toFloat(void) const;
+    virtual double toDouble(void) const;
+    void *toPointer(void) const;
+    unsigned long long toUIntPtr(void) const;
+    const char *toString(void) const;
     void visit(Visitor &visitor);
 };
 
@@ -119,10 +88,11 @@ class Bool : public Value
 public:
     Bool(bool _value) : value(_value) {}
 
-    operator bool (void) const;
-    operator signed long long (void) const;
-    operator unsigned long long (void) const;
-    operator double (void) const;
+    bool toBool(void) const;
+    signed long long toSInt(void) const;
+    unsigned long long toUInt(void) const;
+    virtual float toFloat(void) const;
+    virtual double toDouble(void) const;
     void visit(Visitor &visitor);
 
     bool value;
@@ -134,10 +104,11 @@ class SInt : public Value
 public:
     SInt(signed long long _value) : value(_value) {}
 
-    operator bool (void) const;
-    operator signed long long (void) const;
-    operator unsigned long long (void) const;
-    operator double (void) const;
+    bool toBool(void) const;
+    signed long long toSInt(void) const;
+    unsigned long long toUInt(void) const;
+    virtual float toFloat(void) const;
+    virtual double toDouble(void) const;
     void visit(Visitor &visitor);
 
     signed long long value;
@@ -149,10 +120,11 @@ class UInt : public Value
 public:
     UInt(unsigned long long _value) : value(_value) {}
 
-    operator bool (void) const;
-    operator signed long long (void) const;
-    operator unsigned long long (void) const;
-    operator double (void) const;
+    bool toBool(void) const;
+    signed long long toSInt(void) const;
+    unsigned long long toUInt(void) const;
+    virtual float toFloat(void) const;
+    virtual double toDouble(void) const;
     void visit(Visitor &visitor);
 
     unsigned long long value;
@@ -164,10 +136,11 @@ class Float : public Value
 public:
     Float(double _value) : value(_value) {}
 
-    operator bool (void) const;
-    operator signed long long (void) const;
-    operator unsigned long long (void) const;
-    operator double (void) const;
+    bool toBool(void) const;
+    signed long long toSInt(void) const;
+    unsigned long long toUInt(void) const;
+    virtual float toFloat(void) const;
+    virtual double toDouble(void) const;
     void visit(Visitor &visitor);
 
     double value;
@@ -179,7 +152,8 @@ class String : public Value
 public:
     String(std::string _value) : value(_value) {}
 
-    operator bool (void) const;
+    bool toBool(void) const;
+    const char *toString(void) const;
     void visit(Visitor &visitor);
 
     std::string value;
@@ -205,10 +179,11 @@ public:
 
     Enum(const Signature *_sig) : sig(_sig) {}
 
-    operator bool (void) const;
-    operator signed long long (void) const;
-    operator unsigned long long (void) const;
-    operator double (void) const;
+    bool toBool(void) const;
+    signed long long toSInt(void) const;
+    unsigned long long toUInt(void) const;
+    virtual float toFloat(void) const;
+    virtual double toDouble(void) const;
     void visit(Visitor &visitor);
 
     const Signature *sig;
@@ -240,7 +215,7 @@ public:
     Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { }
     ~Struct();
 
-    operator bool (void) const;
+    bool toBool(void) const;
     void visit(Visitor &visitor);
 
     const Signature *sig;
@@ -254,7 +229,7 @@ public:
     Array(size_t len) : values(len) {}
     ~Array();
 
-    operator bool (void) const;
+    bool toBool(void) const;
     void visit(Visitor &visitor);
 
     std::vector<Value *> values;
@@ -271,8 +246,8 @@ public:
 
     ~Blob();
 
-    operator bool (void) const;
-    void *blob(void) const;
+    bool toBool(void) const;
+    void *toPointer(void) const;
     void visit(Visitor &visitor);
 
     size_t size;
@@ -285,8 +260,9 @@ class Pointer : public UInt
 public:
     Pointer(unsigned long long value) : UInt(value) {}
 
-    operator bool (void) const;
-    void *blob(void) const;
+    bool toBool(void) const;
+    void *toPointer(void) const;
+    unsigned long long toUIntPtr(void) const;
     void visit(Visitor &visitor);
 };
 
@@ -319,11 +295,6 @@ protected:
 std::ostream & operator <<(std::ostream &os, Value *value);
 
 
-signed long long asSInt(const Value &node);
-unsigned long long asUInt(const Value &node);
-double asFloat(const Value &node);
-
-
 class Call
 {
 public:
index 617983aeafe80c7baebc8e9626f8d0d377c692dc..4dfba8adeb0ece46dd1c8849842d84dee60cd278 100644 (file)
@@ -259,7 +259,7 @@ void LiteralFloat(float value) {
     WriteFloat(value);
 }
 
-void LiteralFloat(double value) {
+void LiteralDouble(double value) {
     WriteByte(Trace::TYPE_DOUBLE);
     WriteDouble(value);
 }
index 7ba1154655c0ee5c2368de4e9be752e961cfb705..8797e56f835c667dbd7754d70b8ef96891064e20 100644 (file)
@@ -95,7 +95,7 @@ namespace Trace {
     void LiteralSInt(signed long long value);
     void LiteralUInt(unsigned long long value);
     void LiteralFloat(float value);
-    void LiteralFloat(double value);
+    void LiteralDouble(double value);
     void LiteralString(const char *str);
     void LiteralString(const char *str, size_t size);
     void LiteralWString(const wchar_t *str);
index cfaa1ca8bf914f66e7f9c9cd13b5e8c0d49a359c..1f1a78cd5e09d4d1bc16ec71b1098f5c0809681e 100644 (file)
--- a/wglapi.py
+++ b/wglapi.py
@@ -188,10 +188,10 @@ wglapi.add_functions([
 
     # WGL_ARB_pbuffer
     StdFunction(HPBUFFERARB, "wglCreatePbufferARB", [(HDC, "hDC"), (Int, "iPixelFormat"), (Int, "iWidth"), (Int, "iHeight"), (Const(Array(WGLenum, "__AttribList_size(piAttribList)")), "piAttribList")]),
-    StdFunction(HDC, "wglGetPbufferDCARB", [(HPBUFFERARB, "hPbuffer")], sideeffects=False),
+    StdFunction(HDC, "wglGetPbufferDCARB", [(HPBUFFERARB, "hPbuffer")]),
     StdFunction(Int, "wglReleasePbufferDCARB", [(HPBUFFERARB, "hPbuffer"), (HDC, "hDC")]),
     StdFunction(BOOL, "wglDestroyPbufferARB", [(HPBUFFERARB, "hPbuffer")]),
-    StdFunction(BOOL, "wglQueryPbufferARB", [(HPBUFFERARB, "hPbuffer"), (WGLenum, "iAttribute"), Out(Pointer(Int), "piValue")]),
+    StdFunction(BOOL, "wglQueryPbufferARB", [(HPBUFFERARB, "hPbuffer"), (WGLenum, "iAttribute"), Out(Pointer(Int), "piValue")], sideeffects=False),
 
     # WGL_ARB_render_texture
     StdFunction(BOOL, "wglBindTexImageARB", [(HPBUFFERARB, "hPbuffer"), (Int, "iBuffer")]),