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 wxWindowID winid, const wxPoint& pos, const wxSize& size,
33 long style, const wxString& name,
34 int *attribList, const wxPalette& palette)
36 Create(parent,winid,pos,size,style,name);
39 wxGLCanvas::wxGLCanvas(wxWindow *parent,
40 const wxGLContext *shared,
41 wxWindowID winid, const wxPoint& pos, const wxSize& size,
42 long style, const wxString& name,
43 int *attribList, const wxPalette& palette)
45 Create(parent,winid,pos,size,style,name);
48 wxGLCanvas::wxGLCanvas(wxWindow *parent,
49 const wxGLCanvas *shared,
50 wxWindowID winid, const wxPoint& pos, const wxSize& size,
51 long style, const wxString& name,
52 int *attribList, const wxPalette& palette)
54 Create(parent,winid,pos,size,style,name);
57 bool wxGLCanvas::Create(wxWindow *parent, wxWindowID winid,
63 wxAutoNSAutoreleasePool pool;
64 if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name))
66 SetNSView([[NSOpenGLView alloc] initWithFrame: MakeDefaultNSRect(size)
67 pixelFormat:[NSOpenGLView defaultPixelFormat]]);
68 [m_cocoaNSView release];
70 m_parent->CocoaAddChild(this);
71 SetInitialFrameRect(pos,size);
76 wxGLCanvas::~wxGLCanvas()
80 void wxGLCanvas::SetCurrent()
82 [[(NSOpenGLView*)m_cocoaNSView openGLContext] makeCurrentContext];
85 void wxGLCanvas::SwapBuffers()
87 [[(NSOpenGLView*)m_cocoaNSView openGLContext] flushBuffer];
90 #endif // wxUSE_GLCANVAS