]> git.cworth.org Git - apitrace/blobdiff - retrace/glretrace_ws.cpp
stash: Trace and replay of glx-tfp works
[apitrace] / retrace / glretrace_ws.cpp
index 47fe0d697f342125e447250cdf6e8dda3cf225ce..03e1fc1db7655ecf4b66e170d6d6caf539b1966a 100644 (file)
@@ -50,6 +50,10 @@ getVisual(glws::Profile profile) {
     glws::Visual * & visual = visuals[profile];
     if (!visual) {
         visual = glws::createVisual(retrace::doubleBuffer, profile);
+        if (!visual) {
+            std::cerr << "error: failed to create OpenGL visual\n";
+            exit(1);
+        }
     }
     return visual;
 }
@@ -68,11 +72,11 @@ getDefaultProfile(void)
 
 static glws::Drawable *
 createDrawableHelper(glws::Profile profile, int width = 32, int height = 32, bool pbuffer = false) {
-    glws::Drawable *draw = glws::createDrawable(getVisual(profile), width, height, pbuffer);
+    glws::Visual *visual = getVisual(profile);
+    glws::Drawable *draw = glws::createDrawable(visual, width, height, pbuffer);
     if (!draw) {
         std::cerr << "error: failed to create OpenGL drawable\n";
         exit(1);
-        return NULL;
     }
 
     return draw;
@@ -99,8 +103,9 @@ createPbuffer(int width, int height) {
 
 Context *
 createContext(Context *shareContext, glws::Profile profile) {
+    glws::Visual *visual = getVisual(profile);
     glws::Context *shareWsContext = shareContext ? shareContext->wsContext : NULL;
-    glws::Context *ctx = glws::createContext(getVisual(profile), shareWsContext, profile, retrace::debug);
+    glws::Context *ctx = glws::createContext(visual, shareWsContext, profile, retrace::debug);
     if (!ctx) {
         std::cerr << "error: failed to create OpenGL context\n";
         exit(1);
@@ -117,14 +122,23 @@ createContext(Context *shareContext) {
 }
 
 
-static os::thread_specific_ptr<Context>
+Context::~Context()
+{
+    //assert(this != getCurrentContext());
+    if (this != getCurrentContext()) {
+        delete wsContext;
+    }
+}
+
+
+static thread_specific Context *
 currentContextPtr;
 
 
 bool
 makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
 {
-    Context *currentContext = currentContextPtr.release();
+    Context *currentContext = currentContextPtr;
     glws::Drawable *currentDrawable = currentContext ? currentContext->drawable : NULL;
 
     if (drawable == currentDrawable && context == currentContext) {
@@ -148,13 +162,10 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
         return false;
     }
 
-    if (currentContext) {
-        currentContext->drawable = NULL;
-    }
+    currentContextPtr = context;
 
     if (drawable && context) {
         context->drawable = drawable;
-        currentContextPtr.reset(context);
         
         if (!context->used) {
             initContext();
@@ -168,7 +179,7 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
 
 Context *
 getCurrentContext(void) {
-    return currentContextPtr.get();
+    return currentContextPtr;
 }
 
 
@@ -238,5 +249,65 @@ parseAttrib(const trace::Value *attribs, int param, int default_ = 0) {
     return default_;
 }
 
+void
+createWindow(glws::Drawable *window)
+{
+    glws::Visual *visual = getVisual(getDefaultProfile());
+
+    glws::createWindow(window, visual);
+}
+
+void
+destroyWindow(glws::Drawable *window)
+{
+    glws::destroyWindow(window);
+}
+
+glws::Drawable *
+createPixmap(unsigned width, unsigned height, unsigned depth)
+{
+    return glws::createPixmap(width, height, depth);
+}
+
+glws::Drawable *
+createGLPixmap(GLXFBConfig fbconfig, glws::Drawable *pixmap,
+               unsigned width, unsigned height, int *attrib_list)
+{
+    return glws::createGLPixmap(fbconfig, pixmap, width, height, attrib_list);
+}
+
+void
+bindTexImage(glws::Drawable *pixmap, int buffer)
+{
+    glws::bindTexImage(pixmap, buffer);
+}
+
+void
+releaseTexImage(glws::Drawable *pixmap, int buffer)
+{
+    glws::releaseTexImage(pixmap, buffer);
+}
+
+void
+copySubBuffer(glws::Drawable *drawable, int x, int y, int width, int height)
+{
+    glws::copySubBuffer(drawable, x, y, width, height);
+}
+
+void
+putImageData(glws::Drawable *drawable, char *data,
+             int width, int height, int depth,
+             int bits_per_pixel, int bytes_per_line, int byte_order)
+{
+    glws::putImageData(drawable, data, width, height, depth,
+                       bits_per_pixel, bytes_per_line, byte_order);
+}
+
+GLXFBConfig
+chooseConfig(int *attrib_list)
+{
+    return glws::chooseConfig(attrib_list);
+}
+
 
 } /* namespace glretrace */