]> git.cworth.org Git - apitrace/commitdiff
Add initContext to glretrace.
authorJames Benton <jbenton@vmware.com>
Thu, 9 Aug 2012 13:22:24 +0000 (14:22 +0100)
committerJames Benton <jbenton@vmware.com>
Thu, 9 Aug 2012 15:42:02 +0000 (16:42 +0100)
Used to do per context setup.
Moved the extension support checking to initContext.

retrace/glretrace.hpp
retrace/glretrace_main.cpp
retrace/glretrace_ws.cpp

index 76f47dbcd6aed38d0d733220d6307f9cad48ca0b..27085d4886a645101aff02ed26417b7684269078 100644 (file)
@@ -35,7 +35,8 @@ namespace glretrace {
 struct Context {
     Context(glws::Context* context)
         : wsContext(context),
-          activeProgram(0)
+          activeProgram(0),
+          used(false)
     {
     }
 
@@ -46,6 +47,7 @@ struct Context {
 
     glws::Context* wsContext;
     GLuint activeProgram;
+    bool used;
 };
 
 extern bool insideList;
@@ -82,6 +84,8 @@ extern const retrace::Entry egl_callbacks[];
 
 void frame_start();
 void frame_complete(trace::Call &call);
+void initContext();
+
 
 void updateDrawable(int width, int height);
 
index ca7f9b7b6874654751ee894b62a533dbcc8d98c5..9d551af2890819b17d1789f65c2e70e577483632 100644 (file)
@@ -162,33 +162,6 @@ flushQueries() {
 void
 beginProfile(trace::Call &call) {
     if (firstFrame) {
-        /* Check for extension support */
-        const char* extensions = (const char*)glGetString(GL_EXTENSIONS);
-        GLint bits;
-
-        supportsTimestamp = glws::checkExtension("GL_ARB_timer_query", extensions);
-        supportsElapsed   = glws::checkExtension("GL_EXT_timer_query", extensions) || supportsTimestamp;
-        supportsOcclusion = glws::checkExtension("GL_ARB_occlusion_query", extensions);
-
-        if (retrace::profilingGpuTimes) {
-            if (!supportsTimestamp && !supportsElapsed) {
-                std::cout << "Error: Cannot run profile, GL_EXT_timer_query extension is not supported." << std::endl;
-                exit(-1);
-            }
-
-            glGetQueryiv(GL_TIME_ELAPSED, GL_QUERY_COUNTER_BITS, &bits);
-
-            if (!bits) {
-                std::cout << "Error: Cannot run profile, GL_QUERY_COUNTER_BITS == 0." << std::endl;
-                exit(-1);
-            }
-        }
-
-        if (retrace::profilingPixelsDrawn && !supportsOcclusion) {
-            std::cout << "Error: Cannot run profile, GL_ARB_occlusion_query extension is not supported." << std::endl;
-            exit(-1);
-        }
-
         frame_start();
     }
 
@@ -237,6 +210,36 @@ endProfile(trace::Call &call) {
     }
 }
 
+void
+initContext() {
+    /* Check for extension support */
+    const char* extensions = (const char*)glGetString(GL_EXTENSIONS);
+    GLint bits;
+
+    supportsTimestamp = glws::checkExtension("GL_ARB_timer_query", extensions);
+    supportsElapsed   = glws::checkExtension("GL_EXT_timer_query", extensions) || supportsTimestamp;
+    supportsOcclusion = glws::checkExtension("GL_ARB_occlusion_query", extensions);
+
+    if (retrace::profilingGpuTimes) {
+        if (!supportsTimestamp && !supportsElapsed) {
+            std::cout << "Error: Cannot run profile, GL_EXT_timer_query extension is not supported." << std::endl;
+            exit(-1);
+        }
+
+        glGetQueryiv(GL_TIME_ELAPSED, GL_QUERY_COUNTER_BITS, &bits);
+
+        if (!bits) {
+            std::cout << "Error: Cannot run profile, GL_QUERY_COUNTER_BITS == 0." << std::endl;
+            exit(-1);
+        }
+    }
+
+    if (retrace::profilingPixelsDrawn && !supportsOcclusion) {
+        std::cout << "Error: Cannot run profile, GL_ARB_occlusion_query extension is not supported." << std::endl;
+        exit(-1);
+    }
+}
+
 void
 frame_start() {
     firstFrame = false;
index ffba52499e14bc34e22021ec9c6ea11b6e336a82..bead54ee10ea0566a471604e2a37c423f1eeb181 100644 (file)
@@ -132,6 +132,13 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
         return false;
     }
 
+    if (context) {
+        if (!context->used) {
+            initContext();
+            context->used = true;
+        }
+    }
+
     if (drawable && context) {
         currentDrawable = drawable;
         currentContext = context;