]>
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
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 #include "wx/wxprec.h"
21 #if defined(__BORLANDC__)
27 #include "wx/glcanvas.h"
32 #include "wx/settings.h"
35 #include "wx/osx/private.h"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 wxGLContext::wxGLContext(wxGLCanvas
*win
, const wxGLContext
*other
)
43 m_glContext
= WXGLCreateContext(win
->GetWXGLPixelFormat(),
44 other
? other
->m_glContext
: NULL
);
47 wxGLContext::~wxGLContext()
51 WXGLDestroyContext(m_glContext
);
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 IMPLEMENT_CLASS(wxGLCanvas
, wxWindow
)
61 BEGIN_EVENT_TABLE(wxGLCanvas
, wxWindow
)
63 EVT_SIZE(wxGLCanvas::OnSize
)
67 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
69 const int *attribList
,
74 const wxPalette
& palette
)
76 Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
);
79 #if WXWIN_COMPATIBILITY_2_8
81 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
87 const int *attribList
,
88 const wxPalette
& palette
)
90 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
91 m_glContext
= new wxGLContext(this);
94 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
95 const wxGLContext
*shared
,
100 const wxString
& name
,
101 const int *attribList
,
102 const wxPalette
& palette
)
104 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
105 m_glContext
= new wxGLContext(this, shared
);
108 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
109 const wxGLCanvas
*shared
,
114 const wxString
& name
,
115 const int *attribList
,
116 const wxPalette
& palette
)
118 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
119 m_glContext
= new wxGLContext(this, shared
? shared
->m_glContext
: NULL
);
122 #endif // WXWIN_COMPATIBILITY_2_8
125 bool wxGLCanvas::IsAGLMultiSampleAvailable()
127 static int s_isMultiSampleAvailable
= -1;
128 if ( s_isMultiSampleAvailable
== -1 )
129 s_isMultiSampleAvailable
= IsExtensionSupported("GL_ARB_multisample");
131 return s_isMultiSampleAvailable
!= 0;
135 bool wxGLCanvasBase::IsDisplaySupported(const int *attribList
)
137 WXGLPixelFormat glFormat
= WXGLChoosePixelFormat(attribList
);
142 WXGLDestroyPixelFormat(glFormat
);
147 bool wxGLCanvasBase::IsExtensionSupported(const char *extension
)
149 // we need a valid context to query for extensions.
150 WXGLPixelFormat fmt
= WXGLChoosePixelFormat(NULL
);
151 WXGLContext ctx
= WXGLCreateContext(fmt
, NULL
);
155 WXGLContext ctxOld
= WXGLGetCurrentContext();
156 WXGLSetCurrentContext(ctx
);
158 wxString extensions
= wxString::FromAscii(glGetString(GL_EXTENSIONS
));
160 WXGLSetCurrentContext(ctxOld
);
161 WXGLDestroyPixelFormat(fmt
);
162 WXGLDestroyContext(ctx
);
164 return IsExtensionInList(extensions
.ToAscii(), extension
);
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
171 bool wxGLApp::InitGLVisual(const int *attribList
)
173 WXGLPixelFormat fmt
= WXGLChoosePixelFormat(attribList
);
177 WXGLDestroyPixelFormat(fmt
);
181 #endif // wxUSE_GLCANVAS