]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/glcanvas.mm
Add wxTimer::StartOnce().
[wxWidgets.git] / src / osx / cocoa / glcanvas.mm
index fa9a2e5f0400034d8676daa6efd3520664d35b59..f9ff2a81bff03c08302115f3a4af2d9f5d367235 100644 (file)
@@ -4,7 +4,7 @@
 // Author:      Stefan Csomor
 // Modified by:
 // Created:     1998-01-01
-// RCS-ID:      $Id: glcanvas.cpp 54129 2008-06-11 19:30:52Z SC $
+// RCS-ID:      $Id$
 // Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "wx/osx/private.h"
 
-
 WXGLContext WXGLCreateContext( WXGLPixelFormat pixelFormat, WXGLContext shareContext )
 {
     WXGLContext context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext: shareContext];
     if ( !context )
+    {
         wxFAIL_MSG("NSOpenGLContext creation failed");
+    }
     return context ;
 }
 
@@ -62,6 +63,13 @@ WXGLContext WXGLGetCurrentContext()
     return [NSOpenGLContext currentContext];
 }
 
+bool WXGLSetCurrentContext(WXGLContext context)
+{
+    [context makeCurrentContext];
+
+    return true;
+}
+
 void WXGLDestroyPixelFormat( WXGLPixelFormat pixelFormat )
 {
     if ( pixelFormat )
@@ -78,9 +86,9 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList)
     {
         NSOpenGLPFADoubleBuffer,
         NSOpenGLPFAMinimumPolicy,
-        NSOpenGLPFAColorSize,8,
-        NSOpenGLPFAAlphaSize,0,
-        NSOpenGLPFADepthSize,8,
+        NSOpenGLPFAColorSize,(NSOpenGLPixelFormatAttribute)8,
+        NSOpenGLPFAAlphaSize,(NSOpenGLPixelFormatAttribute)0,
+        NSOpenGLPFADepthSize,(NSOpenGLPixelFormatAttribute)8,
         (NSOpenGLPixelFormatAttribute)nil
     };
 
@@ -122,12 +130,12 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList)
 
                 case WX_GL_AUX_BUFFERS:
                     data[p++] = NSOpenGLPFAAuxBuffers;
-                    data[p++] = attribList[arg++];
+                    data[p++] = (NSOpenGLPixelFormatAttribute) attribList[arg++];
                     break;
 
                 case WX_GL_MIN_RED:
                     data[p++] = NSOpenGLPFAColorSize;
-                    data[p++] = attribList[arg++];
+                    data[p++] = (NSOpenGLPixelFormatAttribute) attribList[arg++];
                     break;
 
                 case WX_GL_MIN_GREEN:
@@ -142,22 +150,22 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList)
 
                 case WX_GL_MIN_ALPHA:
                     data[p++] = NSOpenGLPFAAlphaSize;
-                    data[p++] = attribList[arg++];
+                    data[p++] = (NSOpenGLPixelFormatAttribute) attribList[arg++];
                     break;
 
                 case WX_GL_DEPTH_SIZE:
                     data[p++] = NSOpenGLPFADepthSize;
-                    data[p++] = attribList[arg++];
+                    data[p++] = (NSOpenGLPixelFormatAttribute) attribList[arg++];
                     break;
 
                 case WX_GL_STENCIL_SIZE:
                     data[p++] = NSOpenGLPFAStencilSize;
-                    data[p++] = attribList[arg++];
+                    data[p++] = (NSOpenGLPixelFormatAttribute) attribList[arg++];
                     break;
 
                 case WX_GL_MIN_ACCUM_RED:
                     data[p++] = NSOpenGLPFAAccumSize;
-                    data[p++] = attribList[arg++];
+                    data[p++] = (NSOpenGLPixelFormatAttribute) attribList[arg++];
                     break;
 
                 case WX_GL_MIN_ACCUM_GREEN:
@@ -181,11 +189,11 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList)
                         if ( !attribList[arg++] )
                             break;
 
-                        return false;
+                        return nil;
                     }
 
                     data[p++] = NSOpenGLPFASampleBuffers;
-                    if ( (data[p++] = attribList[arg++]) == true )
+                    if ( (data[p++] = (NSOpenGLPixelFormatAttribute) attribList[arg++]) == true )
                     {
                         // don't use software fallback
                         data[p++] = NSOpenGLPFANoRecovery;
@@ -198,11 +206,11 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList)
                         if ( !attribList[arg++] )
                             break;
 
-                        return false;
+                        return nil;
                     }
 
                     data[p++] = NSOpenGLPFASamples;
-                    data[p++] = attribList[arg++];
+                    data[p++] = (NSOpenGLPixelFormatAttribute) attribList[arg++];
                     break;
             }
         }
@@ -212,57 +220,26 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList)
         attribs = data;
     }
 
-    return [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
-}
-
-bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
-{
-    if ( !m_glContext )
-        return false;  
-
-    [m_glContext setView: win.GetHandle() ];
-    [m_glContext update];
-    
-    [m_glContext makeCurrentContext];
-    
-    return true;
+    return [[NSOpenGLPixelFormat alloc] initWithAttributes:(NSOpenGLPixelFormatAttribute*) attribs];
 }
 
 @interface wxNSCustomOpenGLView : NSView
 {
-    wxWidgetImpl* impl;
     NSOpenGLContext* context;
 }
 
-- (id)initWithFrame:(NSRect)frame;
-- (void)setImplementation: (wxWidgetImpl *) theImplementation;
-- (wxWidgetImpl*) implementation;
-- (BOOL) isFlipped;
-
 @end
 
 @implementation wxNSCustomOpenGLView
 
-- (id)initWithFrame:(NSRect)frame
-{
-    [super initWithFrame:frame];
-    impl = NULL;
-    return self;
-}
-
-- (void)setImplementation: (wxWidgetImpl *) theImplementation
-{
-    impl = theImplementation;
-}
-
-- (wxWidgetImpl*) implementation
++ (void)initialize
 {
-    return impl;
-}
-
-- (BOOL) isFlipped
-{
-    return YES;
+    static BOOL initialized = NO;
+    if (!initialized)
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
+    }
 }
 
 - (BOOL)isOpaque
@@ -285,63 +262,48 @@ bool wxGLCanvas::Create(wxWindow *parent,
     if ( !m_glFormat )
         return false;
 
-   // m_macIsUserPane = false ;
-
+    // DontCreatePeer();
+    
     if ( !wxWindow::Create(parent, id, pos, size, style, name) )
         return false;
 
 /*
-    NSView* sv = (parent->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( this, pos , size ) ;
     wxNSCustomOpenGLView* v = [[wxNSCustomOpenGLView alloc] initWithFrame:r];
-    [sv addSubview:v];
     m_peer = new wxWidgetCocoaImpl( this, v );
-    [v setImplementation:m_peer];
 
     MacPostControlCreate(pos, size) ;
 */
     return true;
 }
 
-bool wxGLCanvas::Create(wxWindow *parent,
-                        wxWindowID id,
-                        const wxPoint& pos,
-                        const wxSize& size,
-                        long style,
-                        const wxString& name,
-                        const int *attribList,
-                        const wxPalette& WXUNUSED(palette))
+wxGLCanvas::~wxGLCanvas()
 {
-    m_needsUpdate = false;
-    m_macCanvasIsShown = false;
-
-    m_glFormat = WXGLChoosePixelFormat(attribList);
-    if ( !m_glFormat )
-        return false;
-
-    if ( !wxWindow::Create(parent, id, pos, size, style, name) )
-        return false;
-
-    m_dummyContext = WXGLCreateContext(m_glFormat, NULL);
+    if ( m_glFormat )
+        WXGLDestroyPixelFormat(m_glFormat);
+}
 
-    static GLint gCurrentBufferName = 1;
-    m_bufferName = gCurrentBufferName++;
-    aglSetInteger (m_dummyContext, AGL_BUFFER_NAME, &m_bufferName); 
-    
-    AGLDrawable drawable = (AGLDrawable)GetWindowPort(MAC_WXHWND(MacGetTopLevelWindowRef()));
-    aglSetDrawable(m_dummyContext, drawable);
+bool wxGLCanvas::SwapBuffers()
+{
+    WXGLContext context = WXGLGetCurrentContext();
+    wxCHECK_MSG(context, false, wxT("should have current context"));
 
-    m_macCanvasIsShown = true;
+    [context flushBuffer];
 
     return true;
 }
 
-wxGLCanvas::~wxGLCanvas()
+bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
 {
-    if ( m_glFormat )
-        WXGLDestroyPixelFormat(m_glFormat);
-}
+    if ( !m_glContext )
+        return false;  
 
+    [m_glContext setView: win.GetHandle() ];
+    [m_glContext update];
+    
+    [m_glContext makeCurrentContext];
+    
+    return true;
+}
 
 #endif // wxUSE_GLCANVAS