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