X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=glws_cocoa.mm;h=7f696fa0f36b9b0f8c48a4f822bc6df930f9f1f0;hb=7f56e7df8e8ff136d970ad4fb8a3f94739b981a3;hp=315c6bca591ef742898e00f265a7839835be7261;hpb=d56c5318f7ba4855ee79b0deaf4549212f3e4780;p=apitrace diff --git a/glws_cocoa.mm b/glws_cocoa.mm index 315c6bc..7f696fa 100644 --- a/glws_cocoa.mm +++ b/glws_cocoa.mm @@ -75,7 +75,7 @@ public: Drawable(vis, w, h), currentContext(nil) { - NSOpenGLPixelFormat *pixelFormat = dynamic_cast(visual)->pixelFormat; + NSOpenGLPixelFormat *pixelFormat = static_cast(visual)->pixelFormat; NSRect winRect = NSMakeRect(0, 0, w, h); @@ -143,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) {} @@ -171,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 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]; @@ -206,16 +210,17 @@ createDrawable(const Visual *visual, int width, int height) Context * createContext(const Visual *visual, Context *shareContext, Profile profile) { - NSOpenGLPixelFormat *pixelFormat = dynamic_cast(visual)->pixelFormat; + NSOpenGLPixelFormat *pixelFormat = static_cast(visual)->pixelFormat; NSOpenGLContext *share_context = nil; NSOpenGLContext *context; - if (profile != PROFILE_COMPAT) { + if (profile != PROFILE_COMPAT && + profile != PROFILE_CORE) { return nil; } if (shareContext) { - share_context = dynamic_cast(shareContext)->context; + share_context = static_cast(shareContext)->context; } context = [[NSOpenGLContext alloc] @@ -223,7 +228,7 @@ createContext(const Visual *visual, Context *shareContext, Profile profile) shareContext:share_context]; assert(context != nil); - return new CocoaContext(visual, context); + return new CocoaContext(visual, profile, context); } bool @@ -232,8 +237,8 @@ makeCurrent(Drawable *drawable, Context *context) if (!drawable || !context) { [NSOpenGLContext clearCurrentContext]; } else { - CocoaDrawable *cocoaDrawable = dynamic_cast(drawable); - CocoaContext *cocoaContext = dynamic_cast(context); + CocoaDrawable *cocoaDrawable = static_cast(drawable); + CocoaContext *cocoaContext = static_cast(context); [cocoaDrawable->window makeKeyAndOrderFront:nil]; [cocoaContext->context setView:[cocoaDrawable->window contentView]];