]> git.cworth.org Git - apitrace/blobdiff - glws_glx.cpp
Add "apitrace trim" command.
[apitrace] / glws_glx.cpp
index 3c49de81309dd25983da7a3eca51efee5d14f3a1..c151db1c07fb91914c070699cc79fec4bc49f076 100644 (file)
@@ -28,9 +28,8 @@
 
 #include <iostream>
 
-#include "glws.hpp"
-
 #include "glproc.hpp"
+#include "glws.hpp"
 
 
 namespace glws {
@@ -57,7 +56,6 @@ public:
 
     ~GlxVisual() {
         XFree(visinfo);
-        XFree(fbconfig);
     }
 };
 
@@ -95,7 +93,7 @@ public:
     GlxDrawable(const Visual *vis, int w, int h) :
         Drawable(vis, w, h)
     {
-        XVisualInfo *visinfo = dynamic_cast<const GlxVisual *>(visual)->visinfo;
+        XVisualInfo *visinfo = static_cast<const GlxVisual *>(visual)->visinfo;
 
         Window root = RootWindow(display, screen);
 
@@ -205,8 +203,8 @@ class GlxContext : public Context
 public:
     GLXContext context;
 
-    GlxContext(const Visual *vis, GLXContext ctx) :
-        Context(vis),
+    GlxContext(const Visual *vis, Profile prof, GLXContext ctx) :
+        Context(vis, prof),
         context(ctx)
     {}
 
@@ -242,7 +240,12 @@ cleanup(void) {
 }
 
 Visual *
-createVisual(bool doubleBuffer) {
+createVisual(bool doubleBuffer, Profile profile) {
+    if (profile != PROFILE_COMPAT &&
+        profile != PROFILE_CORE) {
+        return NULL;
+    }
+
     GlxVisual *visual = new GlxVisual;
 
     if (glxVersion >= 0x0103) {
@@ -293,33 +296,58 @@ createDrawable(const Visual *visual, int width, int height)
 }
 
 Context *
-createContext(const Visual *_visual, Context *shareContext)
+createContext(const Visual *_visual, Context *shareContext, Profile profile)
 {
-    const GlxVisual *visual = dynamic_cast<const GlxVisual *>(_visual);
+    const GlxVisual *visual = static_cast<const GlxVisual *>(_visual);
     GLXContext share_context = NULL;
     GLXContext context;
 
     if (shareContext) {
-        share_context = dynamic_cast<GlxContext*>(shareContext)->context;
+        share_context = static_cast<GlxContext*>(shareContext)->context;
     }
 
     if (glxVersion >= 0x0104 && has_GLX_ARB_create_context) {
         Attributes<int> attribs;
+        
         attribs.add(GLX_RENDER_TYPE, GLX_RGBA_TYPE);
         if (debug) {
             attribs.add(GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB);
         }
+
+        switch (profile) {
+        case PROFILE_COMPAT:
+            break;
+        case PROFILE_CORE:
+            // XXX: This will invariable return a 3.2 context, when supported.
+            // We probably should have a PROFILE_CORE_XX per version.
+            attribs.add(GLX_CONTEXT_MAJOR_VERSION_ARB, 3);
+            attribs.add(GLX_CONTEXT_MINOR_VERSION_ARB, 2);
+            attribs.add(GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB);
+            break;
+        default:
+            return NULL;
+        }
+        
         attribs.end();
 
         context = glXCreateContextAttribsARB(display, visual->fbconfig, share_context, True, attribs);
-    } else 
-           if (glxVersion >= 0x103) {
-        context = glXCreateNewContext(display, visual->fbconfig, GLX_RGBA_TYPE, share_context, True);
     } else {
-        context = glXCreateContext(display, visual->visinfo, share_context, True);
+        if (profile != PROFILE_COMPAT) {
+            return NULL;
+        }
+
+        if (glxVersion >= 0x103) {
+            context = glXCreateNewContext(display, visual->fbconfig, GLX_RGBA_TYPE, share_context, True);
+        } else {
+            context = glXCreateContext(display, visual->visinfo, share_context, True);
+        }
+    }
+
+    if (!context) {
+        return NULL;
     }
 
-    return new GlxContext(visual, context);
+    return new GlxContext(visual, profile, context);
 }
 
 bool
@@ -328,8 +356,8 @@ makeCurrent(Drawable *drawable, Context *context)
     if (!drawable || !context) {
         return glXMakeCurrent(display, None, NULL);
     } else {
-        GlxDrawable *glxDrawable = dynamic_cast<GlxDrawable *>(drawable);
-        GlxContext *glxContext = dynamic_cast<GlxContext *>(context);
+        GlxDrawable *glxDrawable = static_cast<GlxDrawable *>(drawable);
+        GlxContext *glxContext = static_cast<GlxContext *>(context);
 
         return glXMakeCurrent(display, glxDrawable->window, glxContext->context);
     }