]> git.cworth.org Git - apitrace/commitdiff
Basic multi context & puffer support for WGL.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 5 May 2011 20:12:54 +0000 (21:12 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 5 May 2011 20:12:54 +0000 (21:12 +0100)
glretrace_glx.cpp
glretrace_wgl.cpp
wglapi.py

index 540d7cb753b256f95b50fbc0150f2034b6435399..5f2645dd0e0a64b40015d2e53af43c9991a000be 100644 (file)
@@ -66,9 +66,11 @@ 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(static_cast<unsigned long>(call.arg(1)));
index 13445d742da6647db9a51d5fda14355e6d3c5047..fd76dbb8b0683c2883e03fdaa1a5ab815f60b350 100644 (file)
 using namespace glretrace;
 
 
+typedef std::map<void *, glws::Drawable *> DrawableMap;
+typedef std::map<void *, glws::Context *> ContextMap;
+static DrawableMap drawable_map;
+static DrawableMap pbuffer_map;
+static ContextMap context_map;
+
+
+static glws::Drawable *
+getDrawable(void * hdc) {
+    if (hdc == NULL) {
+        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) {
+    void * orig_context = call.ret->blob();
+    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).blob());
+    glws::Context *new_context = context_map[call.arg(1).blob()];
+
+    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;
     }
 }
 
@@ -118,6 +158,23 @@ static void retrace_wglMakeContextCurrentARB(Trace::Call &call) {
 }
 
 static void retrace_wglCreatePbufferARB(Trace::Call &call) {
+    unsigned iWidth = call.arg(2);
+    unsigned iHeight = call.arg(3);
+
+    void * orig_pbuffer = call.ret->blob();
+    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).blob()];
+
+    void * orig_hdc = call.ret->blob();
+
+    drawable_map[orig_hdc] = pbuffer;
 }
 
 static void retrace_wglReleasePbufferDCARB(Trace::Call &call) {
@@ -633,6 +690,7 @@ 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
+                                        retrace_wglGetPbufferDCARB(call);
                                         return;
                                     }
                                     break;
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")]),