]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/glcanvas.mm
Correct format specifiers used to show wxIPV4address.
[wxWidgets.git] / src / osx / cocoa / glcanvas.mm
index b00ff4a23507c805013b19f026a92426bc525350..bebcdcefdbb829dc17b158c674ef96d10857cebd 100644 (file)
@@ -35,7 +35,6 @@
 
 #include "wx/osx/private.h"
 
-
 WXGLContext WXGLCreateContext( WXGLPixelFormat pixelFormat, WXGLContext shareContext )
 {
     WXGLContext context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext: shareContext];
@@ -62,6 +61,13 @@ WXGLContext WXGLGetCurrentContext()
     return [NSOpenGLContext currentContext];
 }
 
+bool WXGLSetCurrentContext(WXGLContext context)
+{
+    [context makeCurrentContext];
+
+    return true;
+}
+
 void WXGLDestroyPixelFormat( WXGLPixelFormat pixelFormat )
 {
     if ( pixelFormat )
@@ -77,6 +83,10 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList)
     const NSOpenGLPixelFormatAttribute defaultAttribs[] =
     {
         NSOpenGLPFADoubleBuffer,
+        NSOpenGLPFAMinimumPolicy,
+        NSOpenGLPFAColorSize,(NSOpenGLPixelFormatAttribute)8,
+        NSOpenGLPFAAlphaSize,(NSOpenGLPixelFormatAttribute)0,
+        NSOpenGLPFADepthSize,(NSOpenGLPixelFormatAttribute)8,
         (NSOpenGLPixelFormatAttribute)nil
     };
 
@@ -118,12 +128,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:
@@ -138,22 +148,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,7 +191,7 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList)
                     }
 
                     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,7 +208,7 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList)
                     }
 
                     data[p++] = NSOpenGLPFASamples;
-                    data[p++] = attribList[arg++];
+                    data[p++] = (NSOpenGLPixelFormatAttribute) attribList[arg++];
                     break;
             }
         }
@@ -208,56 +218,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 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
-{
-    return impl;
-}
-
-- (BOOL) isFlipped
++ (void)initialize
 {
-    return YES;
+    static BOOL initialized = NO;
+    if (!initialized)
+    {
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
+    }
 }
 
 - (BOOL)isOpaque
@@ -280,22 +260,47 @@ bool wxGLCanvas::Create(wxWindow *parent,
     if ( !m_glFormat )
         return false;
 
-    m_macIsUserPane = false ;
+   // m_macIsUserPane = false ;
 
     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;
+}
+
+wxGLCanvas::~wxGLCanvas()
+{
+    if ( m_glFormat )
+        WXGLDestroyPixelFormat(m_glFormat);
+}
 
+bool wxGLCanvas::SwapBuffers()
+{
+    WXGLContext context = WXGLGetCurrentContext();
+    wxCHECK_MSG(context, false, wxT("should have current context"));
+
+    [context flushBuffer];
+
+    return true;
+}
+
+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;
 }