]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/glcanvas_osx.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/glcanvas_osx.cpp
3 // Purpose: wxGLCanvas, for using OpenGL with wxWidgets under Macintosh
4 // Author: Stefan Csomor
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
)
64 EVT_SIZE(wxGLCanvas::OnSize
)
68 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
70 const int *attribList
,
75 const wxPalette
& palette
)
77 Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
);
80 #if WXWIN_COMPATIBILITY_2_8
82 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
88 const int *attribList
,
89 const wxPalette
& palette
)
91 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
92 m_glContext
= new wxGLContext(this);
95 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
96 const wxGLContext
*shared
,
101 const wxString
& name
,
102 const int *attribList
,
103 const wxPalette
& palette
)
105 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
106 m_glContext
= new wxGLContext(this, shared
);
109 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
110 const wxGLCanvas
*shared
,
115 const wxString
& name
,
116 const int *attribList
,
117 const wxPalette
& palette
)
119 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
120 m_glContext
= new wxGLContext(this, shared
? shared
->m_glContext
: NULL
);
123 #endif // WXWIN_COMPATIBILITY_2_8
126 bool wxGLCanvas::IsAGLMultiSampleAvailable()
128 static int s_isMultiSampleAvailable
= -1;
129 if ( s_isMultiSampleAvailable
== -1 )
130 s_isMultiSampleAvailable
= IsExtensionSupported("GL_ARB_multisample");
132 return s_isMultiSampleAvailable
!= 0;
136 bool wxGLCanvasBase::IsDisplaySupported(const int *attribList
)
138 WXGLPixelFormat glFormat
= WXGLChoosePixelFormat(attribList
);
143 WXGLDestroyPixelFormat(glFormat
);
148 bool wxGLCanvasBase::IsExtensionSupported(const char *extension
)
150 // we need a valid context to query for extensions.
151 WXGLPixelFormat fmt
= WXGLChoosePixelFormat(NULL
);
152 WXGLContext ctx
= WXGLCreateContext(fmt
, NULL
);
156 WXGLContext ctxOld
= WXGLGetCurrentContext();
157 WXGLSetCurrentContext(ctx
);
159 wxString extensions
= wxString::FromAscii(glGetString(GL_EXTENSIONS
));
161 WXGLSetCurrentContext(ctxOld
);
162 WXGLDestroyPixelFormat(fmt
);
163 WXGLDestroyContext(ctx
);
165 return IsExtensionInList(extensions
.ToAscii(), extension
);
168 // ----------------------------------------------------------------------------
170 // ----------------------------------------------------------------------------
172 bool wxGLApp::InitGLVisual(const int *attribList
)
174 WXGLPixelFormat fmt
= WXGLChoosePixelFormat(attribList
);
178 WXGLDestroyPixelFormat(fmt
);
182 #endif // wxUSE_GLCANVAS