]> git.cworth.org Git - apitrace/blobdiff - retrace/glretrace_main.cpp
qapitrace: Adjust PATH only once and for all.
[apitrace] / retrace / glretrace_main.cpp
index 4471121d9effc59a75b1e05d83e96f1fba769efc..1418ca3d0fcc9bd54326263af35763136dd656c8 100755 (executable)
@@ -174,12 +174,14 @@ flushQueries() {
 
 void
 beginProfile(trace::Call &call, bool isDraw) {
+    glretrace::Context *currentContext = glretrace::getCurrentContext();
+
     /* Create call query */
     CallQuery query;
     query.isDraw = isDraw;
     query.call = call.no;
     query.sig = call.sig;
-    query.program = glretrace::currentContext ? glretrace::currentContext->activeProgram : 0;
+    query.program = currentContext ? currentContext->activeProgram : 0;
 
     /* GPU profiling only for draw calls */
     if (isDraw) {
@@ -230,6 +232,8 @@ endProfile(trace::Call &call, bool isDraw) {
 
 void
 initContext() {
+    glretrace::Context *currentContext = glretrace::getCurrentContext();
+
     /* Ensure we have adequate extension support */
     assert(currentContext);
     supportsTimestamp   = currentContext->hasExtension("GL_ARB_timer_query");
@@ -261,6 +265,7 @@ initContext() {
 
     /* Setup debug message call back */
     if (retrace::debug && supportsDebugOutput) {
+        glretrace::Context *currentContext = glretrace::getCurrentContext();
         glDebugMessageCallbackARB(&debugOutputCallback, currentContext);
 
         if (DEBUG_OUTPUT_SYNCHRONOUS) {
@@ -309,11 +314,13 @@ frame_complete(trace::Call &call) {
 
     retrace::frameComplete(call);
 
-    if (!currentDrawable) {
+    glretrace::Context *currentContext = glretrace::getCurrentContext();
+    if (!currentContext) {
         return;
     }
 
-    if (retrace::debug && !currentDrawable->visible) {
+    assert(currentContext->drawable);
+    if (retrace::debug && !currentContext->drawable->visible) {
         retrace::warning(call) << "could not infer drawable size (glViewport never called)\n";
     }
 }
@@ -384,9 +391,35 @@ debugOutputCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsi
 } /* namespace glretrace */
 
 
+class GLDumper : public retrace::Dumper {
+public:
+    image::Image *
+    getSnapshot(void) {
+        if (!glretrace::getCurrentContext()) {
+            return NULL;
+        }
+        return glstate::getDrawBufferImage();
+    }
+
+    bool
+    dumpState(std::ostream &os) {
+        glretrace::Context *currentContext = glretrace::getCurrentContext();
+        if (glretrace::insideGlBeginEnd ||
+            !currentContext) {
+            return false;
+        }
+        glstate::dumpCurrentContext(os);
+        return true;
+    }
+};
+
+static GLDumper glDumper;
+
+
 void
 retrace::setUp(void) {
     glws::init();
+    dumper = &glDumper;
 }
 
 
@@ -401,34 +434,13 @@ retrace::addCallbacks(retrace::Retracer &retracer)
 }
 
 
-image::Image *
-retrace::getSnapshot(void) {
-    if (!glretrace::currentDrawable) {
-        return NULL;
-    }
-
-    return glstate::getDrawBufferImage();
-}
-
-
-bool
-retrace::dumpState(std::ostream &os)
-{
-    if (glretrace::insideGlBeginEnd ||
-        !glretrace::currentDrawable ||
-        !glretrace::currentContext) {
-        return false;
-    }
-
-    glstate::dumpCurrentContext(os);
-
-    return true;
-}
-
 void
 retrace::flushRendering(void) {
-    glretrace::flushQueries();
-    glFlush();
+    glretrace::Context *currentContext = glretrace::getCurrentContext();
+    if (currentContext) {
+        glretrace::flushQueries();
+        glFlush();
+    }
 }
 
 void