]> git.saurik.com Git - wxWidgets.git/blame - src/osx/glcanvas_osx.cpp
replace the static control in wxMessageDialog with an edit control with a vertical...
[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)
63 EVT_SIZE(wxGLCanvas::OnSize)
64END_EVENT_TABLE()
65
66wxGLCanvas::wxGLCanvas(wxWindow *parent,
67 wxWindowID id,
68 const int *attribList,
69 const wxPoint& pos,
70 const wxSize& size,
71 long style,
72 const wxString& name,
73 const wxPalette& palette)
74{
75 Create(parent, id, pos, size, style, name, attribList, palette);
76}
77
78#if WXWIN_COMPATIBILITY_2_8
79
80wxGLCanvas::wxGLCanvas(wxWindow *parent,
81 wxWindowID id,
82 const wxPoint& pos,
83 const wxSize& size,
84 long style,
85 const wxString& name,
86 const int *attribList,
87 const wxPalette& palette)
88{
89 if ( Create(parent, id, pos, size, style, name, attribList, palette) )
90 m_glContext = new wxGLContext(this);
91}
92
93wxGLCanvas::wxGLCanvas(wxWindow *parent,
94 const wxGLContext *shared,
95 wxWindowID id,
96 const wxPoint& pos,
97 const wxSize& size,
98 long style,
99 const wxString& name,
100 const int *attribList,
101 const wxPalette& palette)
102{
103 if ( Create(parent, id, pos, size, style, name, attribList, palette) )
104 m_glContext = new wxGLContext(this, shared);
105}
106
107wxGLCanvas::wxGLCanvas(wxWindow *parent,
108 const wxGLCanvas *shared,
109 wxWindowID id,
110 const wxPoint& pos,
111 const wxSize& size,
112 long style,
113 const wxString& name,
114 const int *attribList,
115 const wxPalette& palette)
116{
117 if ( Create(parent, id, pos, size, style, name, attribList, palette) )
118 m_glContext = new wxGLContext(this, shared ? shared->m_glContext : NULL);
119}
120
121#endif // WXWIN_COMPATIBILITY_2_8
122
123/* static */
124bool wxGLCanvas::IsAGLMultiSampleAvailable()
125{
126 static int s_isMultiSampleAvailable = -1;
127 if ( s_isMultiSampleAvailable == -1 )
128 s_isMultiSampleAvailable = IsExtensionSupported("GL_ARB_multisample");
129
130 return s_isMultiSampleAvailable != 0;
131}
132
133/* static */
134bool wxGLCanvasBase::IsDisplaySupported(const int *attribList)
135{
136 WXGLPixelFormat glFormat = WXGLChoosePixelFormat(attribList);
137
138 if ( !glFormat )
139 return false;
140
141 WXGLDestroyPixelFormat(glFormat);
142
143 return true;
144}
145
146bool wxGLCanvas::SwapBuffers()
147{
148 WXGLContext context = WXGLGetCurrentContext();
149 wxCHECK_MSG(context, false, _T("should have current context"));
150
151 WXGLSwapBuffers(context);
152 return true;
153}
154
155bool wxGLCanvasBase::IsExtensionSupported(const char *extension)
156{
157 // we need a valid context to query for extensions.
158 WXGLPixelFormat fmt = WXGLChoosePixelFormat(NULL);
159 WXGLContext ctx = WXGLCreateContext(fmt, NULL);
160 if ( !ctx )
161 return false;
162
163 wxString extensions = wxString::FromAscii(glGetString(GL_EXTENSIONS));
164
165 WXGLDestroyPixelFormat(fmt);
166 WXGLDestroyContext(ctx);
167
168 return IsExtensionInList(extensions, extension);
169}
170
171// ----------------------------------------------------------------------------
172// wxGLApp
173// ----------------------------------------------------------------------------
174
175bool wxGLApp::InitGLVisual(const int *attribList)
176{
177 WXGLPixelFormat fmt = WXGLChoosePixelFormat(attribList);
178 if ( !fmt )
179 return false;
180
181 WXGLDestroyPixelFormat(fmt);
182 return true;
183}
184
185#endif // wxUSE_GLCANVAS