]> git.cworth.org Git - apitrace/commitdiff
Create glretrace specific context.
authorJames Benton <jbenton@vmware.com>
Thu, 9 Aug 2012 13:23:44 +0000 (14:23 +0100)
committerJames Benton <jbenton@vmware.com>
Thu, 9 Aug 2012 15:42:02 +0000 (16:42 +0100)
This allows us to store per context variables whilst retracing.
Altered the various glretrace window system implementations to use this new context.
Updated the "activeProgram" tracking for profiling to use this.

retrace/glretrace.hpp
retrace/glretrace.py
retrace/glretrace_cgl.cpp
retrace/glretrace_egl.cpp
retrace/glretrace_glx.cpp
retrace/glretrace_main.cpp
retrace/glretrace_wgl.cpp
retrace/glretrace_ws.cpp

index 322f06cdfdbbe38355dc9945dd38763df43a85a3..76f47dbcd6aed38d0d733220d6307f9cad48ca0b 100644 (file)
 
 namespace glretrace {
 
+struct Context {
+    Context(glws::Context* context)
+        : wsContext(context),
+          activeProgram(0)
+    {
+    }
+
+    ~Context()
+    {
+        delete wsContext;
+    }
+
+    glws::Context* wsContext;
+    GLuint activeProgram;
+};
 
 extern bool insideList;
 extern bool insideGlBeginEnd;
 
 
 extern glws::Drawable *currentDrawable;
-extern glws::Context *currentContext;
+extern Context *currentContext;
 
 glws::Drawable *
 createDrawable(glws::Profile profile);
@@ -46,14 +61,14 @@ createDrawable(glws::Profile profile);
 glws::Drawable *
 createDrawable(void);
 
-glws::Context *
-createContext(glws::Context *shareContext, glws::Profile profile);
+Context *
+createContext(Context *shareContext, glws::Profile profile);
 
-glws::Context *
-createContext(glws::Context *shareContext = 0);
+Context *
+createContext(Context *shareContext = 0);
 
 bool
-makeCurrent(trace::Call &call, glws::Drawable *drawable, glws::Context *context);
+makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context);
 
 
 void
@@ -74,7 +89,6 @@ void flushQueries();
 void beginProfile(trace::Call &call);
 void endProfile(trace::Call &call);
 
-void setActiveProgram(GLuint program);
 } /* namespace glretrace */
 
 
index be30616d590295705da87b0e4942e27bb69063af..879f3e4b786118ca5d46dde56b4670739e025bc2 100644 (file)
@@ -299,7 +299,9 @@ class GlRetracer(Retracer):
         )
 
         if function.name in ('glUseProgram', 'glUseProgramObjectARB'):
-            print r'    glretrace::setActiveProgram((call.arg(0)).toUInt());'
+            print r'    if (glretrace::currentContext) {'
+            print r'        glretrace::currentContext->activeProgram = call.arg(0).toUInt();'
+            print r'    }'
 
         # Only profile if not inside a list as the queries get inserted into list
         if function.name == 'glNewList':
index 0c91ba27fccb7a46d5e1a19e78e4c6295cb64e2e..76b62fb4f9f856191ee9cefebbd12eacff2015ac 100644 (file)
@@ -35,10 +35,10 @@ using namespace glretrace;
 
 
 typedef std::map<unsigned long long, glws::Drawable *> DrawableMap;
-typedef std::map<unsigned long long, glws::Context *> ContextMap;
+typedef std::map<unsigned long long, Context *> ContextMap;
 static DrawableMap drawable_map;
 static ContextMap context_map;
-static glws::Context *sharedContext = NULL;
+static Context *sharedContext = NULL;
 
 
 static glws::Drawable *
@@ -60,7 +60,7 @@ getDrawable(unsigned long drawable_id) {
 }
 
 
-static glws::Context *
+static Context *
 getContext(unsigned long long ctx) {
     if (ctx == 0) {
         return NULL;
@@ -69,7 +69,7 @@ getContext(unsigned long long ctx) {
     ContextMap::const_iterator it;
     it = context_map.find(ctx);
     if (it == context_map.end()) {
-        glws::Context *context;
+        Context *context;
         context_map[ctx] = context = glretrace::createContext(sharedContext);
         if (!sharedContext) {
             sharedContext = context;
@@ -85,7 +85,7 @@ static void retrace_CGLSetCurrentContext(trace::Call &call) {
     unsigned long long ctx = call.arg(0).toUIntPtr();
 
     glws::Drawable *new_drawable = getDrawable(ctx);
-    glws::Context *new_context = getContext(ctx);
+    Context *new_context = getContext(ctx);
 
     glretrace::makeCurrent(call, new_drawable, new_context);
 }
index 43e8169836b257c73c08a75fc61f5a77b813b92f..3f83f55b41c734a44cd34f747209f85696584fa0 100644 (file)
@@ -46,7 +46,7 @@ using namespace glretrace;
 
 
 typedef std::map<unsigned long long, glws::Drawable *> DrawableMap;
-typedef std::map<unsigned long long, glws::Context *> ContextMap;
+typedef std::map<unsigned long long, Context *> ContextMap;
 typedef std::map<unsigned long long, glws::Profile> ProfileMap;
 static DrawableMap drawable_map;
 static ContextMap context_map;
@@ -77,7 +77,7 @@ getDrawable(unsigned long long surface_ptr) {
     return (it != drawable_map.end()) ? it->second : NULL;
 }
 
-static glws::Context *
+static Context *
 getContext(unsigned long long context_ptr) {
     if (context_ptr == 0) {
         return NULL;
@@ -142,7 +142,7 @@ static void retrace_eglBindAPI(trace::Call &call) {
 static void retrace_eglCreateContext(trace::Call &call) {
     unsigned long long orig_context = call.ret->toUIntPtr();
     unsigned long long orig_config = call.arg(1).toUIntPtr();
-    glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
+    Context *share_context = getContext(call.arg(2).toUIntPtr());
     trace::Array *attrib_array = dynamic_cast<trace::Array *>(&call.arg(3));
     glws::Profile profile;
 
@@ -168,7 +168,7 @@ static void retrace_eglCreateContext(trace::Call &call) {
     }
 
 
-    glws::Context *context = glretrace::createContext(share_context, profile);
+    Context *context = glretrace::createContext(share_context, profile);
     if (!context) {
         const char *name;
         switch (profile) {
@@ -209,7 +209,7 @@ static void retrace_eglDestroyContext(trace::Call &call) {
 
 static void retrace_eglMakeCurrent(trace::Call &call) {
     glws::Drawable *new_drawable = getDrawable(call.arg(1).toUIntPtr());
-    glws::Context *new_context = getContext(call.arg(3).toUIntPtr());
+    Context *new_context = getContext(call.arg(3).toUIntPtr());
 
     glretrace::makeCurrent(call, new_drawable, new_context);
 }
index 9d1b5e5099d015941ff3adfd52716a78e4af7fb7..bc63063d5a0c6394e885f6491300c86e3e7d2b80 100644 (file)
@@ -33,7 +33,7 @@ using namespace glretrace;
 
 
 typedef std::map<unsigned long, glws::Drawable *> DrawableMap;
-typedef std::map<unsigned long long, glws::Context *> ContextMap;
+typedef std::map<unsigned long long, Context *> ContextMap;
 static DrawableMap drawable_map;
 static ContextMap context_map;
 
@@ -53,7 +53,7 @@ getDrawable(unsigned long drawable_id) {
     return it->second;
 }
 
-static glws::Context *
+static Context *
 getContext(unsigned long long context_ptr) {
     if (context_ptr == 0) {
         return NULL;
@@ -70,30 +70,30 @@ getContext(unsigned long long context_ptr) {
 
 static void retrace_glXCreateContext(trace::Call &call) {
     unsigned long long orig_context = call.ret->toUIntPtr();
-    glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
+    Context *share_context = getContext(call.arg(2).toUIntPtr());
 
-    glws::Context *context = glretrace::createContext(share_context);
+    Context *context = glretrace::createContext(share_context);
     context_map[orig_context] = context;
 }
 
 static void retrace_glXCreateContextAttribsARB(trace::Call &call) {
     unsigned long long orig_context = call.ret->toUIntPtr();
-    glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
+    Context *share_context = getContext(call.arg(2).toUIntPtr());
 
-    glws::Context *context = glretrace::createContext(share_context);
+    Context *context = glretrace::createContext(share_context);
     context_map[orig_context] = context;
 }
 
 static void retrace_glXMakeCurrent(trace::Call &call) {
     glws::Drawable *new_drawable = getDrawable(call.arg(1).toUInt());
-    glws::Context *new_context = getContext(call.arg(2).toUIntPtr());
+    Context *new_context = getContext(call.arg(2).toUIntPtr());
 
     glretrace::makeCurrent(call, new_drawable, new_context);
 }
 
 
 static void retrace_glXDestroyContext(trace::Call &call) {
-    glws::Context *context = getContext(call.arg(1).toUIntPtr());
+    Context *context = getContext(call.arg(1).toUIntPtr());
 
     if (!context) {
         return;
@@ -113,15 +113,15 @@ static void retrace_glXSwapBuffers(trace::Call &call) {
 
 static void retrace_glXCreateNewContext(trace::Call &call) {
     unsigned long long orig_context = call.ret->toUIntPtr();
-    glws::Context *share_context = getContext(call.arg(3).toUIntPtr());
+    Context *share_context = getContext(call.arg(3).toUIntPtr());
 
-    glws::Context *context = glretrace::createContext(share_context);
+    Context *context = glretrace::createContext(share_context);
     context_map[orig_context] = context;
 }
 
 static void retrace_glXMakeContextCurrent(trace::Call &call) {
     glws::Drawable *new_drawable = getDrawable(call.arg(1).toUInt());
-    glws::Context *new_context = getContext(call.arg(3).toUIntPtr());
+    Context *new_context = getContext(call.arg(3).toUIntPtr());
 
     glretrace::makeCurrent(call, new_drawable, new_context);
 }
index cbfc67f84dcb32b3ddcf6584b6c407e9def34d17..ca7f9b7b6874654751ee894b62a533dbcc8d98c5 100644 (file)
@@ -54,7 +54,6 @@ static bool supportsOcclusion = true;
 
 static bool firstFrame = true;
 static std::list<CallQuery> callQueries;
-static std::map<glws::Context*, GLuint> activePrograms;
 
 
 void
@@ -160,22 +159,6 @@ flushQueries() {
     callQueries.clear();
 }
 
-void setActiveProgram(GLuint program)
-{
-    activePrograms[glretrace::currentContext] = program;
-}
-
-static GLuint
-getActiveProgram()
-{
-    std::map<glws::Context*, GLuint>::iterator it;
-    it = activePrograms.find(glretrace::currentContext);
-    if (it == activePrograms.end())
-        return 0;
-
-    return it->second;
-}
-
 void
 beginProfile(trace::Call &call) {
     if (firstFrame) {
@@ -213,7 +196,7 @@ beginProfile(trace::Call &call) {
     CallQuery query;
     query.call = call.no;
     query.sig = call.sig;
-    query.program = getActiveProgram();
+    query.program = glretrace::currentContext ? glretrace::currentContext->activeProgram : 0;
 
     glGenQueries(3, query.ids);
 
index c3e109657846c03fda5e127b5fccfd5ee76fa3c0..52fdcf46605cdc485707d1b7ce7fbbd6492f3ea7 100644 (file)
@@ -33,7 +33,7 @@ using namespace glretrace;
 
 
 typedef std::map<unsigned long long, glws::Drawable *> DrawableMap;
-typedef std::map<unsigned long long, glws::Context *> ContextMap;
+typedef std::map<unsigned long long, Context *> ContextMap;
 static DrawableMap drawable_map;
 static DrawableMap pbuffer_map;
 static ContextMap context_map;
@@ -56,7 +56,7 @@ getDrawable(unsigned long long hdc) {
 
 static void retrace_wglCreateContext(trace::Call &call) {
     unsigned long long orig_context = call.ret->toUIntPtr();
-    glws::Context *context = glretrace::createContext();
+    Context *context = glretrace::createContext();
     context_map[orig_context] = context;
 }
 
@@ -65,7 +65,7 @@ static void retrace_wglDeleteContext(trace::Call &call) {
 
 static void retrace_wglMakeCurrent(trace::Call &call) {
     glws::Drawable *new_drawable = getDrawable(call.arg(0).toUIntPtr());
-    glws::Context *new_context = context_map[call.arg(1).toUIntPtr()];
+    Context *new_context = context_map[call.arg(1).toUIntPtr()];
 
     glretrace::makeCurrent(call, new_drawable, new_context);
 }
@@ -95,10 +95,10 @@ static void retrace_wglShareLists(trace::Call &call) {
     unsigned long long hglrc1 = call.arg(0).toUIntPtr();
     unsigned long long hglrc2 = call.arg(1).toUIntPtr();
 
-    glws::Context *share_context = context_map[hglrc1];
-    glws::Context *old_context = context_map[hglrc2];
+    Context *share_context = context_map[hglrc1];
+    Context *old_context = context_map[hglrc2];
 
-    glws::Context *new_context = glretrace::createContext(share_context);
+    Context *new_context = glretrace::createContext(share_context);
     if (new_context) {
         if (currentContext == old_context) {
             glretrace::makeCurrent(call, currentDrawable, new_context);
@@ -201,13 +201,13 @@ static void retrace_wglSetPbufferAttribARB(trace::Call &call) {
 
 static void retrace_wglCreateContextAttribsARB(trace::Call &call) {
     unsigned long long orig_context = call.ret->toUIntPtr();
-    glws::Context *share_context = NULL;
+    Context *share_context = NULL;
 
     if (call.arg(1).toPointer()) {
         share_context = context_map[call.arg(1).toUIntPtr()];
     }
 
-    glws::Context *context = glretrace::createContext(share_context);
+    Context *context = glretrace::createContext(share_context);
     context_map[orig_context] = context;
 }
 
index fcaa2129dd13b3839427a623c985a128c0a19fd2..ffba52499e14bc34e22021ec9c6ea11b6e336a82 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;
@@ -123,7 +124,7 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, glws::Context *context)
 
     flushQueries();
 
-    bool success = glws::makeCurrent(drawable, context);
+    bool success = glws::makeCurrent(drawable, context ? context->wsContext : NULL);
 
     if (!success) {
         std::cerr << "error: failed to make current OpenGL context and drawable\n";