]> git.cworth.org Git - apitrace/blobdiff - retrace/glretrace_ws.cpp
Determine core32 from the traces.
[apitrace] / retrace / glretrace_ws.cpp
index ceb5d7f3db9f292c93450334b84a4fea69863c93..97762eda10edb41a77091b9a3fc81dd8458cf6f8 100644 (file)
@@ -41,7 +41,7 @@ namespace glretrace {
 
 
 glws::Drawable *currentDrawable = NULL;
-glws::Context *currentContext = NULL;
+Context *currentContext = NULL;
 
 
 static glws::Visual *
@@ -88,27 +88,28 @@ createDrawable(void) {
 }
 
 
-glws::Context *
-createContext(glws::Context *shareContext, glws::Profile profile) {
-    glws::Context *ctx = glws::createContext(getVisual(profile), shareContext, profile, retrace::debug);
+Context *
+createContext(Context *shareContext, glws::Profile profile) {
+    glws::Context *shareWsContext = shareContext ? shareContext->wsContext : NULL;
+    glws::Context *ctx = glws::createContext(getVisual(profile), shareWsContext, profile, retrace::debug);
     if (!ctx) {
         std::cerr << "error: failed to create OpenGL context\n";
         exit(1);
         return NULL;
     }
 
-    return ctx;
+    return new Context(ctx);
 }
 
 
-glws::Context *
-createContext(glws::Context *shareContext) {
+Context *
+createContext(Context *shareContext) {
     return createContext(shareContext, getDefaultProfile());
 }
 
 
 bool
-makeCurrent(trace::Call &call, glws::Drawable *drawable, glws::Context *context)
+makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
 {
     if (drawable == currentDrawable && context == currentContext) {
         return true;
@@ -121,7 +122,9 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, glws::Context *context)
         }
     }
 
-    bool success = glws::makeCurrent(drawable, context);
+    flushQueries();
+
+    bool success = glws::makeCurrent(drawable, context ? context->wsContext : NULL);
 
     if (!success) {
         std::cerr << "error: failed to make current OpenGL context and drawable\n";
@@ -132,6 +135,11 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, glws::Context *context)
     if (drawable && context) {
         currentDrawable = drawable;
         currentContext = context;
+        
+        if (!context->used) {
+            initContext();
+            context->used = true;
+        }
     } else {
         currentDrawable = NULL;
         currentContext = NULL;
@@ -180,4 +188,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 */