Request hardware accelerated GL under OS X only if it's available.

Otherwise wxGLCanvas creation just fails completely when it isn't, e.g. when
running inside a VM.

Closes #16555.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77701 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2014-09-14 23:08:30 +00:00
parent 6d0f27a4cc
commit 3d09a6efc2

View File

@ -81,28 +81,48 @@ void WXGLDestroyPixelFormat( WXGLPixelFormat pixelFormat )
WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList)
{
NSOpenGLPixelFormatAttribute data[512];
const NSOpenGLPixelFormatAttribute defaultAttribs[] =
unsigned p = 0;
data[p++] = NSOpenGLPFAMinimumPolicy; // make _SIZE tags behave more like GLX
// Test if we support hardware acceleration, we always want to use it if it
// is available and, apparently, in spite of the Apple docs explicitly
// saying the contrary:
//
// If present, this attribute indicates that only hardware-accelerated
// renderers are considered. If not present, accelerated renderers are
// still preferred.
//
// hardware acceleration is not always used without it, so we do need to
// specify it. But we shouldn't do it if acceleration is really not
// available.
const NSOpenGLPixelFormatAttribute
attrsAccel[] = { NSOpenGLPFAAccelerated, 0 };
WXGLPixelFormat testFormat = [NSOpenGLPixelFormat alloc];
if ( [testFormat initWithAttributes: attrsAccel] )
{
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAMinimumPolicy,
NSOpenGLPFAColorSize,(NSOpenGLPixelFormatAttribute)8,
NSOpenGLPFAAlphaSize,(NSOpenGLPixelFormatAttribute)0,
NSOpenGLPFADepthSize,(NSOpenGLPixelFormatAttribute)8,
NSOpenGLPFAAccelerated, // use hardware accelerated context
0
};
// Hardware acceleration is available, use it.
data[p++] = NSOpenGLPFAAccelerated;
}
[testFormat release];
const NSOpenGLPixelFormatAttribute *attribs;
if ( !attribList )
{
attribs = defaultAttribs;
// Default attributes
data[p++] = NSOpenGLPFADoubleBuffer;
data[p++] = NSOpenGLPFAColorSize;
data[p++] = (NSOpenGLPixelFormatAttribute)8;
data[p++] = NSOpenGLPFAAlphaSize;
data[p++] = (NSOpenGLPixelFormatAttribute)0;
data[p++] = NSOpenGLPFADepthSize;
data[p++] = (NSOpenGLPixelFormatAttribute)8;
data[p] = 0;
attribs = data;
}
else
{
unsigned p = 0;
data[p++] = NSOpenGLPFAMinimumPolicy; // make _SIZE tags behave more like GLX
data[p++] = NSOpenGLPFAAccelerated; // use hardware accelerated context
for ( unsigned arg = 0; attribList[arg] !=0 && p < WXSIZEOF(data); )
{
switch ( attribList[arg++] )