Cocoa : fix secondary window display bug issue
authorDamien Plisson <damien.plisson@yahoo.fr>
Mon, 12 Oct 2009 16:51:36 +0000 (16:51 +0000)
committerDamien Plisson <damien.plisson@yahoo.fr>
Mon, 12 Oct 2009 16:51:36 +0000 (16:51 +0000)
intern/ghost/intern/GHOST_WindowCocoa.h
intern/ghost/intern/GHOST_WindowCocoa.mm

index bc0dd9db13dd274b5e4aba2aa70c51bc97c45442..d6c154535a9f4e549c062bbd3d887c0dd42e6848 100644 (file)
@@ -275,6 +275,9 @@ protected:
        /** The mother SystemCocoa class to send events */
        GHOST_SystemCocoa *m_systemCocoa;
                        
+       /** The first created OpenGL context (for sharing display lists) */
+       static NSOpenGLContext *s_firstOpenGLcontext;
+       
        NSCursor*       m_customCursor;
 
        GHOST_TabletData m_tablet;
index 95c5207b986f205600ef09117ba0cfdea99488ed..fd68b6200eefef220e1e276649f620a8781207bb 100644 (file)
@@ -149,6 +149,8 @@ static const NSOpenGLPixelFormatAttribute pixelFormatAttrsWindow[] =
 
 #pragma mark initialization / finalization
 
+NSOpenGLContext* GHOST_WindowCocoa::s_firstOpenGLcontext = nil;
+
 GHOST_WindowCocoa::GHOST_WindowCocoa(
        GHOST_SystemCocoa *systemCocoa,
        const STR_String& title,
@@ -197,7 +199,7 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
        
        [pixelFormat release];
        
-       m_openGLContext = [m_openGLView openGLContext];
+       m_openGLContext = [m_openGLView openGLContext]; //This context will be replaced by the proper one just after
        
        [m_window setContentView:m_openGLView];
        [m_window setInitialFirstResponder:m_openGLView];
@@ -229,9 +231,6 @@ GHOST_WindowCocoa::~GHOST_WindowCocoa()
 {
        if (m_customCursor) delete m_customCursor;
 
-       /*if(ugly_hack==m_windowRef) ugly_hack= NULL;
-       
-       if(ugly_hack==NULL) setDrawingContextType(GHOST_kDrawingContextTypeNone);*/
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        [m_openGLView release];
        
@@ -670,12 +669,15 @@ GHOST_TSuccess GHOST_WindowCocoa::installDrawingContext(GHOST_TDrawingContextTyp
                case GHOST_kDrawingContextTypeOpenGL:
                        if (!getValid()) break;
                                        
-                               pixelFormat = [m_openGLView pixelFormat];
-                               tmpOpenGLContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat
-                                                                                                                         shareContext:m_openGLContext];
-                               if (tmpOpenGLContext == nil)
-                                       success = GHOST_kFailure;
-                                       break;
+                       pixelFormat = [m_openGLView pixelFormat];
+                       tmpOpenGLContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat
+                                                                                                                         shareContext:s_firstOpenGLcontext];
+                       if (tmpOpenGLContext == nil) {
+                               success = GHOST_kFailure;
+                               break;
+                       }
+                       
+                       if (!s_firstOpenGLcontext) s_firstOpenGLcontext = tmpOpenGLContext;
 #ifdef WAIT_FOR_VSYNC
                                /* wait for vsync, to avoid tearing artifacts */
                                [tmpOpenGLContext setValues:1 forParameter:NSOpenGLCPSwapInterval];
@@ -683,7 +685,6 @@ GHOST_TSuccess GHOST_WindowCocoa::installDrawingContext(GHOST_TDrawingContextTyp
                                [m_openGLView setOpenGLContext:tmpOpenGLContext];
                                [tmpOpenGLContext setView:m_openGLView];
                                
-                               [m_openGLContext release];
                                m_openGLContext = tmpOpenGLContext;
                        break;
                
@@ -704,7 +705,12 @@ GHOST_TSuccess GHOST_WindowCocoa::removeDrawingContext()
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        switch (m_drawingContextType) {
                case GHOST_kDrawingContextTypeOpenGL:
-                       [m_openGLView clearGLContext];
+                       if (m_openGLContext)
+                       {
+                               [m_openGLView clearGLContext];
+                               if (s_firstOpenGLcontext == m_openGLContext) s_firstOpenGLcontext = nil;
+                               m_openGLContext = nil;
+                       }
                        [pool drain];
                        return GHOST_kSuccess;
                case GHOST_kDrawingContextTypeNone: