]> git.cworth.org Git - apitrace/blobdiff - retrace/glretrace_ws.cpp
Use EGLAttribArray all the time.
[apitrace] / retrace / glretrace_ws.cpp
index de9fe08c2c7ed4c471019502eb9dd19a5355ff91..d1e85f824d08815d4a511c06197725051e85062d 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <string.h>
 
+#include "os_thread.hpp"
 #include "retrace.hpp"
 #include "glproc.hpp"
 #include "glstate.hpp"
@@ -40,9 +41,6 @@
 namespace glretrace {
 
 
-Context *currentContext = NULL;
-
-
 static glws::Visual *
 visuals[glws::PROFILE_MAX];
 
@@ -124,9 +122,23 @@ createContext(Context *shareContext) {
 }
 
 
+Context::~Context()
+{
+    //assert(this != getCurrentContext());
+    if (this != getCurrentContext()) {
+        delete wsContext;
+    }
+}
+
+
+static OS_THREAD_SPECIFIC_PTR(Context)
+currentContextPtr;
+
+
 bool
 makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
 {
+    Context *currentContext = currentContextPtr;
     glws::Drawable *currentDrawable = currentContext ? currentContext->drawable : NULL;
 
     if (drawable == currentDrawable && context == currentContext) {
@@ -150,26 +162,25 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
         return false;
     }
 
-    if (currentContext) {
-        currentContext->drawable = NULL;
-    }
+    currentContextPtr = context;
 
     if (drawable && context) {
-        currentContext = context;
-        currentContext->drawable = drawable;
+        context->drawable = drawable;
         
         if (!context->used) {
             initContext();
             context->used = true;
         }
-    } else {
-        currentContext = NULL;
     }
 
     return true;
 }
 
 
+Context *
+getCurrentContext(void) {
+    return currentContextPtr;
+}
 
 
 /**
@@ -180,6 +191,7 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
  */
 void
 updateDrawable(int width, int height) {
+    Context *currentContext = getCurrentContext();
     if (!currentContext) {
         return;
     }
@@ -202,6 +214,9 @@ updateDrawable(int width, int height) {
         return;
     }
 
+    width  = std::max(width,  currentDrawable->width);
+    height = std::max(height, currentDrawable->height);
+
     // Check for bound framebuffer last, as this may have a performance impact.
     GLint draw_framebuffer = 0;
     glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &draw_framebuffer);
@@ -218,7 +233,7 @@ 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);
+    const trace::Array *attribs_ = attribs ? attribs->toArray() : NULL;
 
     if (attribs_) {
         for (size_t i = 0; i + 1 < attribs_->values.size(); i += 2) {