]>
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"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 wxGLContext::wxGLContext(wxGLCanvas
*win
, const wxGLContext
*other
)
44 m_glContext
= WXGLCreateContext(win
->GetWXGLPixelFormat(),
45 other
? other
->m_glContext
: NULL
);
48 wxGLContext::~wxGLContext()
52 WXGLDestroyContext(m_glContext
);
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 IMPLEMENT_CLASS(wxGLCanvas
, wxWindow
)
62 BEGIN_EVENT_TABLE(wxGLCanvas
, wxWindow
)
63 EVT_SIZE(wxGLCanvas::OnSize
)
66 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
68 const int *attribList
,
73 const wxPalette
& palette
)
75 Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
);
78 #if WXWIN_COMPATIBILITY_2_8
80 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
86 const int *attribList
,
87 const wxPalette
& palette
)
89 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
90 m_glContext
= new wxGLContext(this);
93 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
94 const wxGLContext
*shared
,
100 const int *attribList
,
101 const wxPalette
& palette
)
103 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
104 m_glContext
= new wxGLContext(this, shared
);
107 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
108 const wxGLCanvas
*shared
,
113 const wxString
& name
,
114 const int *attribList
,
115 const wxPalette
& palette
)
117 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
118 m_glContext
= new wxGLContext(this, shared
? shared
->m_glContext
: NULL
);
121 #endif // WXWIN_COMPATIBILITY_2_8
124 bool wxGLCanvas::IsAGLMultiSampleAvailable()
126 static int s_isMultiSampleAvailable
= -1;
127 if ( s_isMultiSampleAvailable
== -1 )
128 s_isMultiSampleAvailable
= IsExtensionSupported("GL_ARB_multisample");
130 return s_isMultiSampleAvailable
!= 0;
134 bool wxGLCanvasBase::IsDisplaySupported(const int *attribList
)
136 WXGLPixelFormat glFormat
= WXGLChoosePixelFormat(attribList
);
141 WXGLDestroyPixelFormat(glFormat
);
146 bool wxGLCanvas::SwapBuffers()
148 WXGLContext context
= WXGLGetCurrentContext();
149 wxCHECK_MSG(context
, false, _T("should have current context"));
151 WXGLSwapBuffers(context
);
155 bool wxGLCanvasBase::IsExtensionSupported(const char *extension
)
157 // we need a valid context to query for extensions.
158 WXGLPixelFormat fmt
= WXGLChoosePixelFormat(NULL
);
159 WXGLContext ctx
= WXGLCreateContext(fmt
, NULL
);
163 wxString extensions
= wxString::FromAscii(glGetString(GL_EXTENSIONS
));
165 WXGLDestroyPixelFormat(fmt
);
166 WXGLDestroyContext(ctx
);
168 return IsExtensionInList(extensions
, extension
);
171 // ----------------------------------------------------------------------------
173 // ----------------------------------------------------------------------------
175 bool wxGLApp::InitGLVisual(const int *attribList
)
177 WXGLPixelFormat fmt
= WXGLChoosePixelFormat(attribList
);
181 WXGLDestroyPixelFormat(fmt
);
185 #endif // wxUSE_GLCANVAS