]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/glcanvas.mm
replaced run-time tests for wxRICHTEXT_USE_TOOLBOOK with compile-time ones to avoid...
[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 wxWindowID winid, const wxPoint& pos, const wxSize& size,
33 long style, const wxString& name,
34 int *attribList, const wxPalette& palette)
35 {
36 Create(parent,winid,pos,size,style,name);
37 }
38
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)
44 {
45 Create(parent,winid,pos,size,style,name);
46 }
47
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)
53 {
54 Create(parent,winid,pos,size,style,name);
55 }
56
57 bool wxGLCanvas::Create(wxWindow *parent, wxWindowID winid,
58 const wxPoint& pos,
59 const wxSize& size,
60 long style,
61 const wxString& name)
62 {
63 wxAutoNSAutoreleasePool pool;
64 if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name))
65 return false;
66 SetNSView([[NSOpenGLView alloc] initWithFrame: MakeDefaultNSRect(size)
67 pixelFormat:[NSOpenGLView defaultPixelFormat]]);
68 [m_cocoaNSView release];
69 if(m_parent)
70 m_parent->CocoaAddChild(this);
71 SetInitialFrameRect(pos,size);
72
73 return true;
74 }
75
76 wxGLCanvas::~wxGLCanvas()
77 {
78 }
79
80 void wxGLCanvas::SetCurrent()
81 {
82 [[(NSOpenGLView*)m_cocoaNSView openGLContext] makeCurrentContext];
83 }
84
85 void wxGLCanvas::SwapBuffers()
86 {
87 [[(NSOpenGLView*)m_cocoaNSView openGLContext] flushBuffer];
88 }
89
90 #endif // wxUSE_GLCANVAS