]>
git.saurik.com Git - wxWidgets.git/blob - 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
7 // RCS-ID: $Id: glcanvas.cpp 54129 2008-06-11 19:30:52Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
22 #if defined(__BORLANDC__)
28 #include "wx/glcanvas.h"
33 #include "wx/settings.h"
36 #include "wx/osx/private.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 wxGLContext::wxGLContext(wxGLCanvas
*win
, const wxGLContext
*other
)
46 m_glContext
= WXGLCreateContext(win
->GetWXGLPixelFormat(),
47 other
? other
->m_glContext
: NULL
);
50 wxGLContext::~wxGLContext()
54 WXGLDestroyContext(m_glContext
);
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 IMPLEMENT_CLASS(wxGLCanvas
, wxWindow
)
64 BEGIN_EVENT_TABLE(wxGLCanvas
, wxWindow
)
66 EVT_SIZE(wxGLCanvas::OnSize
)
70 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
72 const int *attribList
,
77 const wxPalette
& palette
)
79 Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
);
82 #if WXWIN_COMPATIBILITY_2_8
84 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
90 const int *attribList
,
91 const wxPalette
& palette
)
93 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
94 m_glContext
= new wxGLContext(this);
97 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
98 const wxGLContext
*shared
,
103 const wxString
& name
,
104 const int *attribList
,
105 const wxPalette
& palette
)
107 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
108 m_glContext
= new wxGLContext(this, shared
);
111 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
112 const wxGLCanvas
*shared
,
117 const wxString
& name
,
118 const int *attribList
,
119 const wxPalette
& palette
)
121 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
122 m_glContext
= new wxGLContext(this, shared
? shared
->m_glContext
: NULL
);
125 #endif // WXWIN_COMPATIBILITY_2_8
128 bool wxGLCanvas::IsAGLMultiSampleAvailable()
130 static int s_isMultiSampleAvailable
= -1;
131 if ( s_isMultiSampleAvailable
== -1 )
132 s_isMultiSampleAvailable
= IsExtensionSupported("GL_ARB_multisample");
134 return s_isMultiSampleAvailable
!= 0;
138 bool wxGLCanvasBase::IsDisplaySupported(const int *attribList
)
140 WXGLPixelFormat glFormat
= WXGLChoosePixelFormat(attribList
);
145 WXGLDestroyPixelFormat(glFormat
);
150 bool wxGLCanvas::SwapBuffers()
152 WXGLContext context
= WXGLGetCurrentContext();
153 wxCHECK_MSG(context
, false, _T("should have current context"));
155 WXGLSwapBuffers(context
);
159 bool wxGLCanvasBase::IsExtensionSupported(const char *extension
)
161 // we need a valid context to query for extensions.
162 WXGLPixelFormat fmt
= WXGLChoosePixelFormat(NULL
);
163 WXGLContext ctx
= WXGLCreateContext(fmt
, NULL
);
167 WXGLContext ctxOld
= WXGLGetCurrentContext();
168 WXGLSetCurrentContext(ctx
);
170 wxString extensions
= wxString::FromAscii(glGetString(GL_EXTENSIONS
));
172 WXGLSetCurrentContext(ctxOld
);
173 WXGLDestroyPixelFormat(fmt
);
174 WXGLDestroyContext(ctx
);
176 return IsExtensionInList(extensions
.ToAscii(), extension
);
179 // ----------------------------------------------------------------------------
181 // ----------------------------------------------------------------------------
183 bool wxGLApp::InitGLVisual(const int *attribList
)
185 WXGLPixelFormat fmt
= WXGLChoosePixelFormat(attribList
);
189 WXGLDestroyPixelFormat(fmt
);
193 #endif // wxUSE_GLCANVAS