]> git.saurik.com Git - wxWidgets.git/blob - src/osx/glcanvas_osx.cpp
Rename wxRendererNative::DrawRadioButton() to DrawRadioBitmap().
[wxWidgets.git] / src / osx / glcanvas_osx.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/glcanvas.cpp
3 // Purpose: wxGLCanvas, for using OpenGL with wxWidgets under Macintosh
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id: glcanvas.cpp 54129 2008-06-11 19:30:52Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/wxprec.h"
21
22 #if defined(__BORLANDC__)
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_GLCANVAS
27
28 #include "wx/glcanvas.h"
29
30 #ifndef WX_PRECOMP
31 #include "wx/frame.h"
32 #include "wx/log.h"
33 #include "wx/settings.h"
34 #endif
35
36 #include "wx/osx/private.h"
37
38 #include <AGL/agl.h>
39
40 // ----------------------------------------------------------------------------
41 // wxGLCanvas
42 // ----------------------------------------------------------------------------
43
44 wxGLContext::wxGLContext(wxGLCanvas *win, const wxGLContext *other)
45 {
46 m_glContext = WXGLCreateContext(win->GetWXGLPixelFormat(),
47 other ? other->m_glContext : NULL);
48 }
49
50 wxGLContext::~wxGLContext()
51 {
52 if ( m_glContext )
53 {
54 WXGLDestroyContext(m_glContext);
55 }
56 }
57
58 // ----------------------------------------------------------------------------
59 // wxGLCanvas
60 // ----------------------------------------------------------------------------
61
62 IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
63
64 BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
65 #if wxOSX_USE_CARBON
66 EVT_SIZE(wxGLCanvas::OnSize)
67 #endif
68 END_EVENT_TABLE()
69
70 wxGLCanvas::wxGLCanvas(wxWindow *parent,
71 wxWindowID id,
72 const int *attribList,
73 const wxPoint& pos,
74 const wxSize& size,
75 long style,
76 const wxString& name,
77 const wxPalette& palette)
78 {
79 Create(parent, id, pos, size, style, name, attribList, palette);
80 }
81
82 #if WXWIN_COMPATIBILITY_2_8
83
84 wxGLCanvas::wxGLCanvas(wxWindow *parent,
85 wxWindowID id,
86 const wxPoint& pos,
87 const wxSize& size,
88 long style,
89 const wxString& name,
90 const int *attribList,
91 const wxPalette& palette)
92 {
93 if ( Create(parent, id, pos, size, style, name, attribList, palette) )
94 m_glContext = new wxGLContext(this);
95 }
96
97 wxGLCanvas::wxGLCanvas(wxWindow *parent,
98 const wxGLContext *shared,
99 wxWindowID id,
100 const wxPoint& pos,
101 const wxSize& size,
102 long style,
103 const wxString& name,
104 const int *attribList,
105 const wxPalette& palette)
106 {
107 if ( Create(parent, id, pos, size, style, name, attribList, palette) )
108 m_glContext = new wxGLContext(this, shared);
109 }
110
111 wxGLCanvas::wxGLCanvas(wxWindow *parent,
112 const wxGLCanvas *shared,
113 wxWindowID id,
114 const wxPoint& pos,
115 const wxSize& size,
116 long style,
117 const wxString& name,
118 const int *attribList,
119 const wxPalette& palette)
120 {
121 if ( Create(parent, id, pos, size, style, name, attribList, palette) )
122 m_glContext = new wxGLContext(this, shared ? shared->m_glContext : NULL);
123 }
124
125 #endif // WXWIN_COMPATIBILITY_2_8
126
127 /* static */
128 bool wxGLCanvas::IsAGLMultiSampleAvailable()
129 {
130 static int s_isMultiSampleAvailable = -1;
131 if ( s_isMultiSampleAvailable == -1 )
132 s_isMultiSampleAvailable = IsExtensionSupported("GL_ARB_multisample");
133
134 return s_isMultiSampleAvailable != 0;
135 }
136
137 /* static */
138 bool wxGLCanvasBase::IsDisplaySupported(const int *attribList)
139 {
140 WXGLPixelFormat glFormat = WXGLChoosePixelFormat(attribList);
141
142 if ( !glFormat )
143 return false;
144
145 WXGLDestroyPixelFormat(glFormat);
146
147 return true;
148 }
149
150 bool wxGLCanvas::SwapBuffers()
151 {
152 WXGLContext context = WXGLGetCurrentContext();
153 wxCHECK_MSG(context, false, wxT("should have current context"));
154
155 WXGLSwapBuffers(context);
156 return true;
157 }
158
159 bool wxGLCanvasBase::IsExtensionSupported(const char *extension)
160 {
161 // we need a valid context to query for extensions.
162 WXGLPixelFormat fmt = WXGLChoosePixelFormat(NULL);
163 WXGLContext ctx = WXGLCreateContext(fmt, NULL);
164 if ( !ctx )
165 return false;
166
167 WXGLContext ctxOld = WXGLGetCurrentContext();
168 WXGLSetCurrentContext(ctx);
169
170 wxString extensions = wxString::FromAscii(glGetString(GL_EXTENSIONS));
171
172 WXGLSetCurrentContext(ctxOld);
173 WXGLDestroyPixelFormat(fmt);
174 WXGLDestroyContext(ctx);
175
176 return IsExtensionInList(extensions.ToAscii(), extension);
177 }
178
179 // ----------------------------------------------------------------------------
180 // wxGLApp
181 // ----------------------------------------------------------------------------
182
183 bool wxGLApp::InitGLVisual(const int *attribList)
184 {
185 WXGLPixelFormat fmt = WXGLChoosePixelFormat(attribList);
186 if ( !fmt )
187 return false;
188
189 WXGLDestroyPixelFormat(fmt);
190 return true;
191 }
192
193 #endif // wxUSE_GLCANVAS