]> git.cworth.org Git - apitrace/blobdiff - wrappers/gltrace_state.cpp
retrace: Implement glxCopySubBufferMESA
[apitrace] / wrappers / gltrace_state.cpp
index 5c7ad1bf66ae242cfe1092ecf8459dcc80814f3a..a8476b04c1bb247b9fb1131eb2c81852f7723896 100644 (file)
@@ -34,8 +34,9 @@
 #include <tr1/memory>
 #endif
 
-#include <gltrace.hpp>
 #include <os_thread.hpp>
+#include <glproc.hpp>
+#include <gltrace.hpp>
 
 namespace gltrace {
 
@@ -57,15 +58,13 @@ public:
     }
 };
 
-static os::thread_specific_ptr<ThreadState> thread_state;
+static OS_THREAD_SPECIFIC_PTR(ThreadState) thread_state;
 
 static ThreadState *get_ts(void)
 {
-    ThreadState *ts = thread_state.get();
-
+    ThreadState *ts = thread_state;
     if (!ts) {
-        ts = new ThreadState;
-        thread_state.reset(ts);
+        thread_state = ts = new ThreadState;
     }
 
     return ts;
@@ -96,7 +95,7 @@ static bool _releaseContext(context_ptr_t ctx)
  */
 bool releaseContext(uintptr_t context_id)
 {
-    bool res;
+    bool res = false;
 
     context_map_mutex.lock();
     /*
@@ -144,6 +143,29 @@ void setContext(uintptr_t context_id)
     context_map_mutex.unlock();
 
     ts->current_context = ctx;
+
+    if (!ctx->bound) {
+        ctx->bound = true;
+
+        /*
+         * The default viewport and scissor state is set when a context is
+         * first made current, with values matching the bound drawable.  Many
+         * applications never thouch the default state ever again.
+         *
+         * Since we currently don't trace window sizes, and rely on viewport
+         * calls to deduct, emit fake calls here so that viewport/scissor state
+         * can be deducated.
+         *
+         * FIXME: don't call the real functions here -- just emit the fake
+         * calls.
+         */
+        GLint viewport[4] = {0, 0, 0, 0};
+        GLint scissor_box[4] = {0, 0, 0, 0};
+        _glGetIntegerv(GL_VIEWPORT, viewport);
+        _glGetIntegerv(GL_SCISSOR_BOX, scissor_box);
+        glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
+        glScissor(scissor_box[0], scissor_box[1], scissor_box[2], scissor_box[3]);
+    }
 }
 
 void clearContext(void)