]> git.cworth.org Git - apitrace/blobdiff - glws_cocoa.mm
Move tracers to wrappers subdirectory.
[apitrace] / glws_cocoa.mm
index a35dcf506370d0d8215305572897b9576f8694ee..7f696fa0f36b9b0f8c48a4f822bc6df930f9f1f0 100644 (file)
@@ -75,7 +75,7 @@ public:
         Drawable(vis, w, h),
         currentContext(nil)
     {
-        NSOpenGLPixelFormat *pixelFormat = dynamic_cast<const CocoaVisual *>(visual)->pixelFormat;
+        NSOpenGLPixelFormat *pixelFormat = static_cast<const CocoaVisual *>(visual)->pixelFormat;
 
         NSRect winRect = NSMakeRect(0, 0, w, h);
 
@@ -104,7 +104,9 @@ public:
 
     void
     resize(int w, int h) {
-        Drawable::resize(w, h);
+        if (w == width && h == height) {
+            return;
+        }
 
         [window setContentSize:NSMakeSize(w, h)];
 
@@ -114,13 +116,18 @@ public:
             [currentContext setView:[window contentView]];
             [currentContext makeCurrentContext];
         }
+
+        Drawable::resize(w, h);
     }
 
     void show(void) {
-        if (!visible) {
-            // TODO
-            Drawable::show();
+        if (visible) {
+            return;
         }
+
+        // TODO
+
+        Drawable::show();
     }
 
     void swapBuffers(void) {
@@ -136,8 +143,8 @@ class CocoaContext : public Context
 public:
     NSOpenGLContext *context;
 
-    CocoaContext(const Visual *vis, NSOpenGLContext *ctx) :
-        Context(vis),
+    CocoaContext(const Visual *vis, Profile prof, NSOpenGLContext *ctx) :
+        Context(vis, prof),
         context(ctx)
     {}
 
@@ -164,25 +171,29 @@ cleanup(void) {
 
 
 Visual *
-createVisual(bool doubleBuffer) {
-    NSOpenGLPixelFormatAttribute single_attribs[] = {
-        NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)1,
-        NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24,
-        NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)1,
-        NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)1,
-        (NSOpenGLPixelFormatAttribute)0
-    };
-
-    NSOpenGLPixelFormatAttribute double_attribs[] = {
-        NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)1,
-        NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24,
-        NSOpenGLPFADoubleBuffer,
-        NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)1,
-        NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)1,
-        (NSOpenGLPixelFormatAttribute)0
-    };
-
-    NSOpenGLPixelFormatAttribute *attribs = doubleBuffer ? double_attribs : single_attribs;
+createVisual(bool doubleBuffer, Profile profile) {
+    if (profile != PROFILE_COMPAT &&
+        profile != PROFILE_CORE) {
+        return nil;
+    }
+
+    Attributes<NSOpenGLPixelFormatAttribute> attribs;
+
+    attribs.add(NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)1);
+    attribs.add(NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24);
+    if (doubleBuffer) {
+        attribs.add(NSOpenGLPFADoubleBuffer);
+    }
+    attribs.add(NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)1);
+    attribs.add(NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)1);
+    if (profile == PROFILE_CORE) {
+#if CGL_VERSION_1_3
+        attribs.add(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
+#else
+       return NULL;
+#endif
+    }
+    attribs.end();
 
     NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc]
                                      initWithAttributes:attribs];
@@ -197,14 +208,19 @@ createDrawable(const Visual *visual, int width, int height)
 }
 
 Context *
-createContext(const Visual *visual, Context *shareContext)
+createContext(const Visual *visual, Context *shareContext, Profile profile)
 {
-    NSOpenGLPixelFormat *pixelFormat = dynamic_cast<const CocoaVisual *>(visual)->pixelFormat;
+    NSOpenGLPixelFormat *pixelFormat = static_cast<const CocoaVisual *>(visual)->pixelFormat;
     NSOpenGLContext *share_context = nil;
     NSOpenGLContext *context;
 
+    if (profile != PROFILE_COMPAT &&
+        profile != PROFILE_CORE) {
+        return nil;
+    }
+
     if (shareContext) {
-        share_context = dynamic_cast<CocoaContext*>(shareContext)->context;
+        share_context = static_cast<CocoaContext*>(shareContext)->context;
     }
 
     context = [[NSOpenGLContext alloc]
@@ -212,7 +228,7 @@ createContext(const Visual *visual, Context *shareContext)
                shareContext:share_context];
     assert(context != nil);
 
-    return new CocoaContext(visual, context);
+    return new CocoaContext(visual, profile, context);
 }
 
 bool
@@ -221,8 +237,8 @@ makeCurrent(Drawable *drawable, Context *context)
     if (!drawable || !context) {
         [NSOpenGLContext clearCurrentContext];
     } else {
-        CocoaDrawable *cocoaDrawable = dynamic_cast<CocoaDrawable *>(drawable);
-        CocoaContext *cocoaContext = dynamic_cast<CocoaContext *>(context);
+        CocoaDrawable *cocoaDrawable = static_cast<CocoaDrawable *>(drawable);
+        CocoaContext *cocoaContext = static_cast<CocoaContext *>(context);
 
         [cocoaDrawable->window makeKeyAndOrderFront:nil];
         [cocoaContext->context setView:[cocoaDrawable->window contentView]];