]> git.saurik.com Git - wxWidgets.git/blame - src/osx/glcanvas_osx.cpp
minor fixes; replace references to Windows95 with references to wxMSW where possible
[wxWidgets.git] / src / osx / glcanvas_osx.cpp
CommitLineData
524c47aa
SC
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
42wxGLContext::wxGLContext(wxGLCanvas *win, const wxGLContext *other)
43{
44 m_glContext = WXGLCreateContext(win->GetWXGLPixelFormat(),
45 other ? other->m_glContext : NULL);
46}
47
48wxGLContext::~wxGLContext()
49{
50 if ( m_glContext )
51 {
52 WXGLDestroyContext(m_glContext);
53 }
54}
55
56// ----------------------------------------------------------------------------
57// wxGLCanvas
58// ----------------------------------------------------------------------------
59
60IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
61
62BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
01a33e96 63#if wxOSX_USE_CARBON
524c47aa 64 EVT_SIZE(wxGLCanvas::OnSize)
01a33e96 65#endif
524c47aa
SC
66END_EVENT_TABLE()
67
68wxGLCanvas::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
82wxGLCanvas::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
95wxGLCanvas::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
109wxGLCanvas::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 */
126bool 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 */
136bool 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
148bool wxGLCanvas::SwapBuffers()
149{
150 WXGLContext context = WXGLGetCurrentContext();
151 wxCHECK_MSG(context, false, _T("should have current context"));
152
153 WXGLSwapBuffers(context);
154 return true;
155}
156
157bool wxGLCanvasBase::IsExtensionSupported(const char *extension)
158{
159 // we need a valid context to query for extensions.
160 WXGLPixelFormat fmt = WXGLChoosePixelFormat(NULL);
161 WXGLContext ctx = WXGLCreateContext(fmt, NULL);
162 if ( !ctx )
163 return false;
164
165 wxString extensions = wxString::FromAscii(glGetString(GL_EXTENSIONS));
166
167 WXGLDestroyPixelFormat(fmt);
168 WXGLDestroyContext(ctx);
169
e6ba3887 170 return IsExtensionInList(extensions.ToAscii(), extension);
524c47aa
SC
171}
172
173// ----------------------------------------------------------------------------
174// wxGLApp
175// ----------------------------------------------------------------------------
176
177bool wxGLApp::InitGLVisual(const int *attribList)
178{
179 WXGLPixelFormat fmt = WXGLChoosePixelFormat(attribList);
180 if ( !fmt )
181 return false;
182
183 WXGLDestroyPixelFormat(fmt);
184 return true;
185}
186
187#endif // wxUSE_GLCANVAS