1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/glcanvas.mm
3 // Purpose: wxGLContext, wxGLCanvas
4 // Author: David Elliott
8 // Copyright: (c) 2004 David Elliott
9 // Licence: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
19 #include "wx/glcanvas.h"
21 #include "wx/cocoa/autorelease.h"
23 #import <AppKit/NSOpenGL.h>
24 #import <AppKit/NSOpenGLView.h>
26 IMPLEMENT_DYNAMIC_CLASS(wxGLCanvas, wxWindow)
27 BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
29 // WX_IMPLEMENT_COCOA_OWNER(wxGLCanvas,NSOpenGLView,NSView,NSView)
31 wxGLCanvas::wxGLCanvas(wxWindow *parent,
32 const wxGLContext *shared,
33 wxWindowID winid, const wxPoint& pos, const wxSize& size,
34 long style, const wxString& name,
35 int *attribList, const wxPalette& palette)
37 Create(parent,winid,pos,size,style,name);
40 wxGLCanvas::wxGLCanvas(wxWindow *parent,
41 const wxGLCanvas *shared,
42 wxWindowID winid, const wxPoint& pos, const wxSize& size,
43 long style, const wxString& name,
44 int *attribList, const wxPalette& palette)
46 Create(parent,winid,pos,size,style,name);
49 bool wxGLCanvas::Create(wxWindow *parent, wxWindowID winid,
55 wxAutoNSAutoreleasePool pool;
56 if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name))
58 SetNSView([[NSOpenGLView alloc] initWithFrame: MakeDefaultNSRect(size)
59 pixelFormat:[NSOpenGLView defaultPixelFormat]]);
60 [m_cocoaNSView release];
62 m_parent->CocoaAddChild(this);
63 SetInitialFrameRect(pos,size);
68 wxGLCanvas::~wxGLCanvas()
72 void wxGLCanvas::SetCurrent()
74 [[(NSOpenGLView*)m_cocoaNSView openGLContext] makeCurrentContext];
77 void wxGLCanvas::SwapBuffers()
79 [[(NSOpenGLView*)m_cocoaNSView openGLContext] flushBuffer];
82 #endif // wxUSE_GLCANVAS