]> git.saurik.com Git - wxWidgets.git/blob - src/osx/glcanvas_osx.cpp
Test whether GTK+ is 2.18 or newer in configure.
[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 // ----------------------------------------------------------------------------
39 // wxGLCanvas
40 // ----------------------------------------------------------------------------
41
42 wxGLContext::wxGLContext(wxGLCanvas *win, const wxGLContext *other)
43 {
44 m_glContext = WXGLCreateContext(win->GetWXGLPixelFormat(),
45 other ? other->m_glContext : NULL);
46 }
47
48 wxGLContext::~wxGLContext()
49 {
50 if ( m_glContext )
51 {
52 WXGLDestroyContext(m_glContext);
53 }
54 }
55
56 // ----------------------------------------------------------------------------
57 // wxGLCanvas
58 // ----------------------------------------------------------------------------
59
60 IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
61
62 BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
63 #if wxOSX_USE_CARBON
64 EVT_SIZE(wxGLCanvas::OnSize)
65 #endif
66 END_EVENT_TABLE()
67
68 wxGLCanvas::wxGLCanvas(wxWindow *parent,
69 wxWindowID id,
70 const int *attribList,
71 const wxPoint& pos,
72 const wxSize& size,
73 long style,
74 const wxString& name,
75 const wxPalette& palette)
76 {
77 Create(parent, id, pos, size, style, name, attribList, palette);
78 }
79
80 #if WXWIN_COMPATIBILITY_2_8
81
82 wxGLCanvas::wxGLCanvas(wxWindow *parent,
83 wxWindowID id,
84 const wxPoint& pos,
85 const wxSize& size,
86 long style,
87 const wxString& name,
88 const int *attribList,
89 const wxPalette& palette)
90 {
91 if ( Create(parent, id, pos, size, style, name, attribList, palette) )
92 m_glContext = new wxGLContext(this);
93 }
94
95 wxGLCanvas::wxGLCanvas(wxWindow *parent,
96 const wxGLContext *shared,
97 wxWindowID id,
98 const wxPoint& pos,
99 const wxSize& size,
100 long style,
101 const wxString& name,
102 const int *attribList,
103 const wxPalette& palette)
104 {
105 if ( Create(parent, id, pos, size, style, name, attribList, palette) )
106 m_glContext = new wxGLContext(this, shared);
107 }
108
109 wxGLCanvas::wxGLCanvas(wxWindow *parent,
110 const wxGLCanvas *shared,
111 wxWindowID id,
112 const wxPoint& pos,
113 const wxSize& size,
114 long style,
115 const wxString& name,
116 const int *attribList,
117 const wxPalette& palette)
118 {
119 if ( Create(parent, id, pos, size, style, name, attribList, palette) )
120 m_glContext = new wxGLContext(this, shared ? shared->m_glContext : NULL);
121 }
122
123 #endif // WXWIN_COMPATIBILITY_2_8
124
125 /* static */
126 bool wxGLCanvas::IsAGLMultiSampleAvailable()
127 {
128 static int s_isMultiSampleAvailable = -1;
129 if ( s_isMultiSampleAvailable == -1 )
130 s_isMultiSampleAvailable = IsExtensionSupported("GL_ARB_multisample");
131
132 return s_isMultiSampleAvailable != 0;
133 }
134
135 /* static */
136 bool wxGLCanvasBase::IsDisplaySupported(const int *attribList)
137 {
138 WXGLPixelFormat glFormat = WXGLChoosePixelFormat(attribList);
139
140 if ( !glFormat )
141 return false;
142
143 WXGLDestroyPixelFormat(glFormat);
144
145 return true;
146 }
147
148 bool wxGLCanvasBase::IsExtensionSupported(const char *extension)
149 {
150 // we need a valid context to query for extensions.
151 WXGLPixelFormat fmt = WXGLChoosePixelFormat(NULL);
152 WXGLContext ctx = WXGLCreateContext(fmt, NULL);
153 if ( !ctx )
154 return false;
155
156 WXGLContext ctxOld = WXGLGetCurrentContext();
157 WXGLSetCurrentContext(ctx);
158
159 wxString extensions = wxString::FromAscii(glGetString(GL_EXTENSIONS));
160
161 WXGLSetCurrentContext(ctxOld);
162 WXGLDestroyPixelFormat(fmt);
163 WXGLDestroyContext(ctx);
164
165 return IsExtensionInList(extensions.ToAscii(), extension);
166 }
167
168 // ----------------------------------------------------------------------------
169 // wxGLApp
170 // ----------------------------------------------------------------------------
171
172 bool wxGLApp::InitGLVisual(const int *attribList)
173 {
174 WXGLPixelFormat fmt = WXGLChoosePixelFormat(attribList);
175 if ( !fmt )
176 return false;
177
178 WXGLDestroyPixelFormat(fmt);
179 return true;
180 }
181
182 #endif // wxUSE_GLCANVAS