///////////////////////////////////////////////////////////////////////////////
#include <OpenGL/OpenGL.h>
+namespace {
CGLContextObj createGLContext() {
GLint major, minor;
CGLGetVersion(&major, &minor);
CGLSetCurrentContext(ctx);
return ctx;
}
+}
- (void)viewDidMoveToWindow {
[super viewDidMoveToWindow];
}
- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType {
if (nil == fGLContext) {
- fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:createGLContext()];
+ CGLContextObj ctx = createGLContext();
+ fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx];
+ CGLReleaseContext(ctx);
if (NULL == fGLContext) {
return false;
}
+ [fGLContext setView:self];
}
[fGLContext makeCurrentContext];
}
- (void)detach {
- [fGLContext clearDrawable];
+ [fGLContext release];
+ fGLContext = nil;
}
- (void)present {
- [fGLContext flushBuffer];
+ if (nil != fGLContext) {
+ [fGLContext flushBuffer];
+ }
}
@end