]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/glcanvas.mm
fix for bug 1371386, with some minor mods and cleanup
[wxWidgets.git] / src / cocoa / glcanvas.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/glcanvas.mm
3 // Purpose: wxGLContext, wxGLCanvas
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2004/09/29
7 // RCS-ID: $Id$
8 // Copyright: (c) 2004 David Elliott
9 // Licence: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_GLCANVAS
15
16 #ifndef WX_PRECOMP
17 #include "wx/app.h"
18 #endif //WX_PRECOMP
19 #include "wx/glcanvas.h"
20
21 #include "wx/cocoa/autorelease.h"
22
23 #import <AppKit/NSOpenGL.h>
24 #import <AppKit/NSOpenGLView.h>
25
26 IMPLEMENT_DYNAMIC_CLASS(wxGLCanvas, wxWindow)
27 BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
28 END_EVENT_TABLE()
29 // WX_IMPLEMENT_COCOA_OWNER(wxGLCanvas,NSOpenGLView,NSView,NSView)
30
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)
36 {
37 Create(parent,winid,pos,size,style,name);
38 }
39
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)
45 {
46 Create(parent,winid,pos,size,style,name);
47 }
48
49 bool wxGLCanvas::Create(wxWindow *parent, wxWindowID winid,
50 const wxPoint& pos,
51 const wxSize& size,
52 long style,
53 const wxString& name)
54 {
55 wxAutoNSAutoreleasePool pool;
56 if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name))
57 return false;
58 SetNSView([[NSOpenGLView alloc] initWithFrame: MakeDefaultNSRect(size)
59 pixelFormat:[NSOpenGLView defaultPixelFormat]]);
60 [m_cocoaNSView release];
61 if(m_parent)
62 m_parent->CocoaAddChild(this);
63 SetInitialFrameRect(pos,size);
64
65 return true;
66 }
67
68 wxGLCanvas::~wxGLCanvas()
69 {
70 }
71
72 void wxGLCanvas::SetCurrent()
73 {
74 [[(NSOpenGLView*)m_cocoaNSView openGLContext] makeCurrentContext];
75 }
76
77 void wxGLCanvas::SwapBuffers()
78 {
79 [[(NSOpenGLView*)m_cocoaNSView openGLContext] flushBuffer];
80 }
81
82 #endif // wxUSE_GLCANVAS