]> git.cworth.org Git - apitrace/blobdiff - retrace/glretrace_ws.cpp
Don't show pbuffers in windows.
[apitrace] / retrace / glretrace_ws.cpp
index bead54ee10ea0566a471604e2a37c423f1eeb181..c49b47228c9bddf5d503851dd88e9e51186e8596 100644 (file)
@@ -40,7 +40,6 @@
 namespace glretrace {
 
 
-glws::Drawable *currentDrawable = NULL;
 Context *currentContext = NULL;
 
 
@@ -69,9 +68,9 @@ getDefaultProfile(void)
 }
 
 
-glws::Drawable *
-createDrawable(glws::Profile profile) {
-    glws::Drawable *draw = glws::createDrawable(getVisual(profile));
+static glws::Drawable *
+createDrawableHelper(glws::Profile profile, int width = 32, int height = 32, bool pbuffer = false) {
+    glws::Drawable *draw = glws::createDrawable(getVisual(profile), width, height, pbuffer);
     if (!draw) {
         std::cerr << "error: failed to create OpenGL drawable\n";
         exit(1);
@@ -82,9 +81,21 @@ createDrawable(glws::Profile profile) {
 }
 
 
+glws::Drawable *
+createDrawable(glws::Profile profile) {
+    return createDrawableHelper(profile);
+}
+
+
 glws::Drawable *
 createDrawable(void) {
-    return glretrace::createDrawable(getDefaultProfile());
+    return createDrawable(getDefaultProfile());
+}
+
+
+glws::Drawable *
+createPbuffer(int width, int height) {
+    return createDrawableHelper(getDefaultProfile(), width, height, true);
 }
 
 
@@ -111,11 +122,13 @@ createContext(Context *shareContext) {
 bool
 makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
 {
+    glws::Drawable *currentDrawable = currentContext ? currentContext->drawable : NULL;
+
     if (drawable == currentDrawable && context == currentContext) {
         return true;
     }
 
-    if (currentDrawable && currentContext) {
+    if (currentContext) {
         glFlush();
         if (!retrace::doubleBuffer) {
             frame_complete(call);
@@ -132,18 +145,19 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
         return false;
     }
 
-    if (context) {
-        if (!context->used) {
-            initContext();
-            context->used = true;
-        }
+    if (currentContext) {
+        currentContext->drawable = NULL;
     }
 
     if (drawable && context) {
-        currentDrawable = drawable;
         currentContext = context;
+        currentContext->drawable = drawable;
+        
+        if (!context->used) {
+            initContext();
+            context->used = true;
+        }
     } else {
-        currentDrawable = NULL;
         currentContext = NULL;
     }
 
@@ -161,7 +175,14 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
  */
 void
 updateDrawable(int width, int height) {
-    if (!currentDrawable) {
+    if (!currentContext) {
+        return;
+    }
+
+    glws::Drawable *currentDrawable = currentContext->drawable;
+    assert(currentDrawable);
+
+    if (currentDrawable->pbuffer) {
         return;
     }
 
@@ -190,4 +211,26 @@ updateDrawable(int width, int height) {
 }
 
 
+int
+parseAttrib(const trace::Value *attribs, int param, int default_ = 0) {
+    const trace::Array *attribs_ = dynamic_cast<const trace::Array *>(attribs);
+
+    if (attribs_) {
+        for (size_t i = 0; i + 1 < attribs_->values.size(); i += 2) {
+            int param_i = attribs_->values[i]->toSInt();
+            if (param_i == 0) {
+                break;
+            }
+
+            if (param_i == param) {
+                int value = attribs_->values[i + 1]->toSInt();
+                return value;
+            }
+        }
+    }
+
+    return default_;
+}
+
+
 } /* namespace glretrace */