Commit 0109e06c authored by hybrid's avatar hybrid

Add some more tries for window creation on OSX.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2086 dfc29bdd-3216-0410-991c-e03cc46cb475
parent a139a973
...@@ -414,15 +414,12 @@ void CIrrDeviceMacOSX::closeDevice() ...@@ -414,15 +414,12 @@ void CIrrDeviceMacOSX::closeDevice()
bool CIrrDeviceMacOSX::createWindow() bool CIrrDeviceMacOSX::createWindow()
{ {
int index;
CGDisplayErr error; CGDisplayErr error;
bool result; bool result;
NSOpenGLPixelFormat *format;
CGDirectDisplayID display; CGDirectDisplayID display;
CGLPixelFormatObj pixelFormat; CGLPixelFormatObj pixelFormat;
CGRect displayRect; CGRect displayRect;
CGLPixelFormatAttribute fullattribs[32]; CGLPixelFormatAttribute fullattribs[32];
NSOpenGLPixelFormatAttribute windowattribs[32];
CFDictionaryRef displaymode,olddisplaymode; CFDictionaryRef displaymode,olddisplaymode;
GLint numPixelFormats,newSwapInterval; GLint numPixelFormats,newSwapInterval;
int alphaSize = CreationParams.WithAlphaChannel?4:0, depthSize = CreationParams.ZBufferBits; int alphaSize = CreationParams.WithAlphaChannel?4:0, depthSize = CreationParams.ZBufferBits;
...@@ -442,33 +439,80 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -442,33 +439,80 @@ bool CIrrDeviceMacOSX::createWindow()
_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:NSBackingStoreBuffered defer:FALSE]; _window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:NSBackingStoreBuffered defer:FALSE];
if (_window != NULL) if (_window != NULL)
{ {
index = 0; NSOpenGLPixelFormatAttribute windowattribs[] = {
windowattribs[index++] = NSOpenGLPFANoRecovery; NSOpenGLPFANoRecovery,
windowattribs[index++] = NSOpenGLPFADoubleBuffer; NSOpenGLPFAAccelerated,
windowattribs[index++] = NSOpenGLPFAAccelerated; NSOpenGLPFADepthSize, depthSize,
windowattribs[index++] = NSOpenGLPFADepthSize; NSOpenGLPFAColorSize, CreationParams.Bits,
windowattribs[index++] = (NSOpenGLPixelFormatAttribute)depthSize; NSOpenGLPFAAlphaSize, alphaSize,
windowattribs[index++] = NSOpenGLPFAColorSize; NSOpenGLPFASampleBuffers, 1,
windowattribs[index++] = (NSOpenGLPixelFormatAttribute)CreationParams.Bits; NSOpenGLPFASamples, CreationParams.AntiAlias,
windowattribs[index++] = NSOpenGLPFAAlphaSize; NSOpenGLPFAStencilSize, CreationParams.Stencilbuffer?1:0,
windowattribs[index++] = (NSOpenGLPixelFormatAttribute)alphaSize; NSOpenGLPFADoubleBuffer,
(NSOpenGLPixelFormatAttribute)nil
if (CreationParams.AntiAlias) { };
windowattribs[index++] = NSOpenGLPFASampleBuffers;
windowattribs[index++] = (NSOpenGLPixelFormatAttribute)1; if (CreationParams.AntiAlias<2)
windowattribs[index++] = NSOpenGLPFASamples; {
windowattribs[index++] = (NSOpenGLPixelFormatAttribute)2; windowattribs[9] = 0;
windowattribs[11] = 0;
} }
if (CreationParams.Stencilbuffer) NSOpenGLPixelFormat *format;
for (int i=0; i<3; ++i)
{ {
windowattribs[index++] = NSOpenGLPFAStencilSize; if (1==i)
windowattribs[index++] = (NSOpenGLPixelFormatAttribute)1; {
} // Second try without stencilbuffer
if (CreationParams.Stencilbuffer)
{
windowattribs[13]=0;
}
else
continue;
}
else if (2==i)
{
// Third try without Doublebuffer
os::Printer::log("No doublebuffering available.", ELL_WARNING);
windowattribs[14]=(NSOpenGLPixelFormatAttribute)nil;
}
windowattribs[index++] = (NSOpenGLPixelFormatAttribute)NULL; format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
if (format == NULL)
{
if (CreationParams.AntiAlias>1)
{
while (!format && windowattribs[12]>1)
{
windowattribs -= 1;
format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
}
if (!format)
{
windowattribs[9] = 0;
windowattribs[11] = 0;
format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
if (!format)
{
// reset values for next try
windowattribs[9] = 1;
windowattribs[11] = CreationParams.AntiAlias;
}
else
{
os::Printer::log("No FSAA available.", ELL_WARNING);
}
}
}
}
else
break;
}
CreationParams.AntiAlias=windowattribs[11];
CreationParams.Stencilbuffer=(windowattribs[13]==1);
format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
if (format != NULL) if (format != NULL)
{ {
_oglcontext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL]; _oglcontext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL];
...@@ -506,7 +550,7 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -506,7 +550,7 @@ bool CIrrDeviceMacOSX::createWindow()
pixelFormat = NULL; pixelFormat = NULL;
numPixelFormats = 0; numPixelFormats = 0;
index = 0; int index = 0;
fullattribs[index++] = kCGLPFAFullScreen; fullattribs[index++] = kCGLPFAFullScreen;
fullattribs[index++] = kCGLPFADisplayMask; fullattribs[index++] = kCGLPFADisplayMask;
fullattribs[index++] = (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display); fullattribs[index++] = (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display);
...@@ -523,7 +567,7 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -523,7 +567,7 @@ bool CIrrDeviceMacOSX::createWindow()
fullattribs[index++] = kCGLPFASampleBuffers; fullattribs[index++] = kCGLPFASampleBuffers;
fullattribs[index++] = (CGLPixelFormatAttribute)1; fullattribs[index++] = (CGLPixelFormatAttribute)1;
fullattribs[index++] = kCGLPFASamples; fullattribs[index++] = kCGLPFASamples;
fullattribs[index++] = (CGLPixelFormatAttribute)2; fullattribs[index++] = (CGLPixelFormatAttribute)CreationParams.AntiAlias;
} }
if (CreationParams.Stencilbuffer) if (CreationParams.Stencilbuffer)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment