Changeset View
Changeset View
Standalone View
Standalone View
intern/ghost/intern/GHOST_ContextCGL.mm
| Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | GHOST_ContextCGL::GHOST_ContextCGL( | ||||
| int contextMinorVersion, | int contextMinorVersion, | ||||
| int contextFlags, | int contextFlags, | ||||
| int contextResetNotificationStrategy) | int contextResetNotificationStrategy) | ||||
| : GHOST_Context(stereoVisual, numOfAASamples), | : GHOST_Context(stereoVisual, numOfAASamples), | ||||
| m_openGLView(openGLView), | m_openGLView(openGLView), | ||||
| m_openGLContext(nil), | m_openGLContext(nil), | ||||
| m_debug(contextFlags) | m_debug(contextFlags) | ||||
| { | { | ||||
| assert(openGLView != nil); | |||||
| // for now be very strict about OpenGL version requested | // for now be very strict about OpenGL version requested | ||||
| switch (contextMajorVersion) { | switch (contextMajorVersion) { | ||||
| case 2: | case 2: | ||||
| assert(contextMinorVersion == 1); | assert(contextMinorVersion == 1); | ||||
| assert(contextProfileMask == 0); | assert(contextProfileMask == 0); | ||||
| m_coreProfile = false; | m_coreProfile = false; | ||||
| break; | break; | ||||
| case 3: | case 3: | ||||
| // Apple didn't implement 3.0 or 3.1 | // Apple didn't implement 3.0 or 3.1 | ||||
| assert(contextMinorVersion == 2); | assert(contextMinorVersion == 2); | ||||
| assert(contextProfileMask == GL_CONTEXT_CORE_PROFILE_BIT); | assert(contextProfileMask == GL_CONTEXT_CORE_PROFILE_BIT); | ||||
| m_coreProfile = true; | m_coreProfile = true; | ||||
| break; | break; | ||||
| default: | default: | ||||
| assert(false); | assert(false); | ||||
| } | } | ||||
| } | } | ||||
| GHOST_ContextCGL::~GHOST_ContextCGL() | GHOST_ContextCGL::~GHOST_ContextCGL() | ||||
| { | { | ||||
| if (m_openGLContext != nil) { | if (m_openGLContext != nil) { | ||||
| if (m_openGLContext == [NSOpenGLContext currentContext]) { | if (m_openGLContext == [NSOpenGLContext currentContext]) { | ||||
| [NSOpenGLContext clearCurrentContext]; | [NSOpenGLContext clearCurrentContext]; | ||||
| if(m_openGLView) { | |||||
| [m_openGLView clearGLContext]; | [m_openGLView clearGLContext]; | ||||
| } | } | ||||
| } | |||||
| if (m_openGLContext != s_sharedOpenGLContext || s_sharedCount == 1) { | if (m_openGLContext != s_sharedOpenGLContext || s_sharedCount == 1) { | ||||
| assert(s_sharedCount > 0); | assert(s_sharedCount > 0); | ||||
| s_sharedCount--; | s_sharedCount--; | ||||
| if (s_sharedCount == 0) | if (s_sharedCount == 0) | ||||
| s_sharedOpenGLContext = nil; | s_sharedOpenGLContext = nil; | ||||
| ▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | |||||
| GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext() | GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext() | ||||
| { | { | ||||
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||||
| std::vector<NSOpenGLPixelFormatAttribute> attribs; | std::vector<NSOpenGLPixelFormatAttribute> attribs; | ||||
| attribs.reserve(40); | attribs.reserve(40); | ||||
| NSOpenGLContext *prev_openGLContext = [m_openGLView openGLContext]; | NSOpenGLContext *prev_openGLContext = (m_openGLView) ? [m_openGLView openGLContext] : NULL; | ||||
| #ifdef GHOST_OPENGL_ALPHA | #ifdef GHOST_OPENGL_ALPHA | ||||
| static const bool needAlpha = true; | static const bool needAlpha = true; | ||||
| #else | #else | ||||
| static const bool needAlpha = false; | static const bool needAlpha = false; | ||||
| #endif | #endif | ||||
| #ifdef GHOST_OPENGL_STENCIL | #ifdef GHOST_OPENGL_STENCIL | ||||
| ▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | #ifdef GHOST_WAIT_FOR_VSYNC | ||||
| GLint swapInt = 1; | GLint swapInt = 1; | ||||
| /* wait for vsync, to avoid tearing artifacts */ | /* wait for vsync, to avoid tearing artifacts */ | ||||
| [m_openGLContext setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; | [m_openGLContext setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; | ||||
| } | } | ||||
| #endif | #endif | ||||
| initContextGLEW(); | initContextGLEW(); | ||||
| if (m_openGLView) { | |||||
| [m_openGLView setOpenGLContext:m_openGLContext]; | [m_openGLView setOpenGLContext:m_openGLContext]; | ||||
| [m_openGLContext setView:m_openGLView]; | [m_openGLContext setView:m_openGLView]; | ||||
| } | |||||
| if (s_sharedCount == 0) | if (s_sharedCount == 0) | ||||
| s_sharedOpenGLContext = m_openGLContext; | s_sharedOpenGLContext = m_openGLContext; | ||||
| s_sharedCount++; | s_sharedCount++; | ||||
| initClearGL(); | initClearGL(); | ||||
| [m_openGLContext flushBuffer]; | [m_openGLContext flushBuffer]; | ||||
| [pool drain]; | [pool drain]; | ||||
| return GHOST_kSuccess; | return GHOST_kSuccess; | ||||
| error: | error: | ||||
| if (m_openGLView) { | |||||
| [m_openGLView setOpenGLContext:prev_openGLContext]; | [m_openGLView setOpenGLContext:prev_openGLContext]; | ||||
| } | |||||
| [pixelFormat release]; | [pixelFormat release]; | ||||
| [pool drain]; | [pool drain]; | ||||
| return GHOST_kFailure; | return GHOST_kFailure; | ||||
| } | } | ||||
| GHOST_TSuccess GHOST_ContextCGL::releaseNativeHandles() | GHOST_TSuccess GHOST_ContextCGL::releaseNativeHandles() | ||||
| { | { | ||||
| m_openGLContext = NULL; | m_openGLContext = NULL; | ||||
| m_openGLView = NULL; | m_openGLView = NULL; | ||||
| return GHOST_kSuccess; | return GHOST_kSuccess; | ||||
| } | } | ||||