Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: source/Irrlicht/Irrlicht.cpp
- ===================================================================
- --- source/Irrlicht/Irrlicht.cpp (revision 3409)
- +++ source/Irrlicht/Irrlicht.cpp (working copy)
- @@ -3,6 +3,7 @@
- // For conditions of distribution and use, see copyright notice in irrlicht.h
- #include "IrrCompileConfig.h"
- +#include <stdexcept>
- static const char* const copyright = "Irrlicht Engine (c) 2002-2009 Nikolaus Gebhardt";
- @@ -74,7 +75,16 @@
- #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
- if (params.DeviceType == EIDT_OSX || (!dev && params.DeviceType == EIDT_BEST))
- - dev = new CIrrDeviceMacOSX(params);
- + {
- + try
- + {
- + dev = new CIrrDeviceMacOSX(params);
- + }
- + catch (std::runtime_error& e)
- + {
- + return NULL;
- + }
- + }
- #endif
- #ifdef _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_
- Index: source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm
- ===================================================================
- --- source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm (revision 3409)
- +++ source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm (working copy)
- @@ -9,6 +9,7 @@
- #import <Cocoa/Cocoa.h>
- #import <OpenGL/gl.h>
- #import <Carbon/Carbon.h>
- +#include <stdexcept>
- #include "CIrrDeviceMacOSX.h"
- #include "IEventReceiver.h"
- @@ -370,7 +371,13 @@
- initKeycodes();
- if (CreationParams.DriverType != video::EDT_NULL)
- - createWindow();
- + {
- + const bool success = createWindow();
- + if (!success)
- + {
- + throw std::runtime_error("Cannot create video device");
- + }
- + }
- setResizable(false);
- @@ -458,171 +465,180 @@
- VideoModeList.setDesktop(CreationParams.Bits, core::dimension2d<u32>(ScreenWidth, ScreenHeight));
- - if (!CreationParams.Fullscreen)
- - {
- - if(!CreationParams.WindowId) //create another window when WindowId is null
- - {
- - Window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:NSBackingStoreBuffered defer:FALSE];
- - }
- + @try
- + {
- + if (!CreationParams.Fullscreen)
- + {
- + if(!CreationParams.WindowId) //create another window when WindowId is null
- + {
- + Window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:NSBackingStoreBuffered defer:FALSE];
- + }
- - if (Window != NULL || CreationParams.WindowId)
- - {
- - NSOpenGLPixelFormatAttribute windowattribs[] =
- - {
- - NSOpenGLPFANoRecovery,
- - NSOpenGLPFAAccelerated,
- - NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)depthSize,
- - NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)CreationParams.Bits,
- - NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)alphaSize,
- - NSOpenGLPFASampleBuffers, (NSOpenGLPixelFormatAttribute)1,
- - NSOpenGLPFASamples, (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias,
- - NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
- - NSOpenGLPFADoubleBuffer,
- - (NSOpenGLPixelFormatAttribute)nil
- - };
- + if (Window != NULL || CreationParams.WindowId)
- + {
- + NSOpenGLPixelFormatAttribute windowattribs[] =
- + {
- + NSOpenGLPFANoRecovery,
- + NSOpenGLPFAAccelerated,
- + NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)depthSize,
- + NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)CreationParams.Bits,
- + NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)alphaSize,
- + NSOpenGLPFASampleBuffers, (NSOpenGLPixelFormatAttribute)1,
- + NSOpenGLPFASamples, (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias,
- + NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
- + NSOpenGLPFADoubleBuffer,
- + (NSOpenGLPixelFormatAttribute)nil
- + };
- - if (CreationParams.AntiAlias<2)
- - {
- - windowattribs[ 9] = (NSOpenGLPixelFormatAttribute)0;
- - windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
- - }
- + if (CreationParams.AntiAlias<2)
- + {
- + windowattribs[ 9] = (NSOpenGLPixelFormatAttribute)0;
- + windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
- + }
- - NSOpenGLPixelFormat *format;
- - for (int i=0; i<3; ++i)
- - {
- - if (1==i)
- - {
- - // Second try without stencilbuffer
- - if (CreationParams.Stencilbuffer)
- - {
- - windowattribs[13]=(NSOpenGLPixelFormatAttribute)0;
- - }
- - else
- - continue;
- - }
- - else if (2==i)
- - {
- - // Third try without Doublebuffer
- - os::Printer::log("No doublebuffering available.", ELL_WARNING);
- - windowattribs[14]=(NSOpenGLPixelFormatAttribute)nil;
- - }
- + NSOpenGLPixelFormat *format;
- + for (int i=0; i<3; ++i)
- + {
- + if (1==i)
- + {
- + // Second try without stencilbuffer
- + if (CreationParams.Stencilbuffer)
- + {
- + windowattribs[13]=(NSOpenGLPixelFormatAttribute)0;
- + }
- + else
- + continue;
- + }
- + else if (2==i)
- + {
- + // Third try without Doublebuffer
- + os::Printer::log("No doublebuffering available.", ELL_WARNING);
- + windowattribs[14]=(NSOpenGLPixelFormatAttribute)nil;
- + }
- - format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
- - if (format == NULL)
- - {
- - if (CreationParams.AntiAlias>1)
- - {
- - while (!format && windowattribs[12]>1)
- - {
- - windowattribs[12] = (NSOpenGLPixelFormatAttribute)((int)windowattribs[12]-1);
- - format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
- - }
- + format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
- + if (format == NULL)
- + {
- + if (CreationParams.AntiAlias>1)
- + {
- + while (!format && windowattribs[12]>1)
- + {
- + windowattribs[12] = (NSOpenGLPixelFormatAttribute)((int)windowattribs[12]-1);
- + format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
- + }
- - if (!format)
- - {
- - windowattribs[9] = (NSOpenGLPixelFormatAttribute)0;
- - windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
- - format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
- - if (!format)
- - {
- - // reset values for next try
- - windowattribs[9] = (NSOpenGLPixelFormatAttribute)1;
- - windowattribs[11] = (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias;
- - }
- - else
- - {
- - os::Printer::log("No FSAA available.", ELL_WARNING);
- - }
- + if (!format)
- + {
- + windowattribs[9] = (NSOpenGLPixelFormatAttribute)0;
- + windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
- + format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
- + if (!format)
- + {
- + // reset values for next try
- + windowattribs[9] = (NSOpenGLPixelFormatAttribute)1;
- + windowattribs[11] = (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias;
- + }
- + else
- + {
- + os::Printer::log("No FSAA available.", ELL_WARNING);
- + }
- - }
- - }
- - }
- - else
- - break;
- - }
- - CreationParams.AntiAlias = windowattribs[11];
- - CreationParams.Stencilbuffer=(windowattribs[13]==1);
- + }
- + }
- + }
- + else
- + break;
- + }
- + CreationParams.AntiAlias = windowattribs[11];
- + CreationParams.Stencilbuffer=(windowattribs[13]==1);
- - if (format != NULL)
- - {
- - OGLContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL];
- - [format release];
- - }
- + if (format != NULL)
- + {
- + OGLContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL];
- + [format release];
- + }
- - if (OGLContext != NULL)
- - {
- - if (!CreationParams.WindowId)
- - {
- - [Window center];
- - [Window setDelegate:[NSApp delegate]];
- - [OGLContext setView:[Window contentView]];
- - [Window setAcceptsMouseMovedEvents:TRUE];
- - [Window setIsVisible:TRUE];
- - [Window makeKeyAndOrderFront:nil];
- - }
- - else //use another window for drawing
- - [OGLContext setView:(NSView*)CreationParams.WindowId];
- + if (OGLContext != NULL)
- + {
- + if (!CreationParams.WindowId)
- + {
- + [Window center];
- + [Window setDelegate:[NSApp delegate]];
- + [OGLContext setView:[Window contentView]];
- + [Window setAcceptsMouseMovedEvents:TRUE];
- + [Window setIsVisible:TRUE];
- + [Window makeKeyAndOrderFront:nil];
- + }
- + else //use another window for drawing
- + [OGLContext setView:(NSView*)CreationParams.WindowId];
- - CGLContext = (CGLContextObj) [OGLContext CGLContextObj];
- - DeviceWidth = CreationParams.WindowSize.Width;
- - DeviceHeight = CreationParams.WindowSize.Height;
- - result = true;
- - }
- - }
- - }
- - else
- - {
- - displaymode = CGDisplayBestModeForParameters(display,CreationParams.Bits,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height,NULL);
- - if (displaymode != NULL)
- - {
- - olddisplaymode = CGDisplayCurrentMode(display);
- - error = CGCaptureAllDisplays();
- - if (error == CGDisplayNoErr)
- - {
- - error = CGDisplaySwitchToMode(display,displaymode);
- - if (error == CGDisplayNoErr)
- - {
- - pixelFormat = NULL;
- - numPixelFormats = 0;
- + CGLContext = (CGLContextObj) [OGLContext CGLContextObj];
- + DeviceWidth = CreationParams.WindowSize.Width;
- + DeviceHeight = CreationParams.WindowSize.Height;
- + result = true;
- + }
- + }
- + }
- + else
- + {
- + displaymode = CGDisplayBestModeForParameters(display,CreationParams.Bits,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height,NULL);
- + if (displaymode != NULL)
- + {
- + olddisplaymode = CGDisplayCurrentMode(display);
- + error = CGCaptureAllDisplays();
- + if (error == CGDisplayNoErr)
- + {
- + error = CGDisplaySwitchToMode(display,displaymode);
- + if (error == CGDisplayNoErr)
- + {
- + pixelFormat = NULL;
- + numPixelFormats = 0;
- - int index = 0;
- - CGLPixelFormatAttribute fullattribs[] =
- - {
- - kCGLPFAFullScreen,
- - kCGLPFADisplayMask, (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display),
- - kCGLPFADoubleBuffer,
- - kCGLPFAAccelerated,
- - kCGLPFADepthSize, (CGLPixelFormatAttribute)depthSize,
- - kCGLPFAColorSize, (CGLPixelFormatAttribute)CreationParams.Bits,
- - kCGLPFAAlphaSize, (CGLPixelFormatAttribute)alphaSize,
- - kCGLPFASampleBuffers, (CGLPixelFormatAttribute)(CreationParams.AntiAlias?1:0),
- - kCGLPFASamples, (CGLPixelFormatAttribute)CreationParams.AntiAlias,
- - kCGLPFAStencilSize, (CGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
- - (CGLPixelFormatAttribute)NULL
- - };
- + int index = 0;
- + CGLPixelFormatAttribute fullattribs[] =
- + {
- + kCGLPFAFullScreen,
- + kCGLPFADisplayMask, (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display),
- + kCGLPFADoubleBuffer,
- + kCGLPFAAccelerated,
- + kCGLPFADepthSize, (CGLPixelFormatAttribute)depthSize,
- + kCGLPFAColorSize, (CGLPixelFormatAttribute)CreationParams.Bits,
- + kCGLPFAAlphaSize, (CGLPixelFormatAttribute)alphaSize,
- + kCGLPFASampleBuffers, (CGLPixelFormatAttribute)(CreationParams.AntiAlias?1:0),
- + kCGLPFASamples, (CGLPixelFormatAttribute)CreationParams.AntiAlias,
- + kCGLPFAStencilSize, (CGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
- + (CGLPixelFormatAttribute)NULL
- + };
- - CGLChoosePixelFormat(fullattribs,&pixelFormat,&numPixelFormats);
- + CGLChoosePixelFormat(fullattribs,&pixelFormat,&numPixelFormats);
- - if (pixelFormat != NULL)
- - {
- - CGLCreateContext(pixelFormat,NULL,&CGLContext);
- - CGLDestroyPixelFormat(pixelFormat);
- - }
- + if (pixelFormat != NULL)
- + {
- + CGLCreateContext(pixelFormat,NULL,&CGLContext);
- + CGLDestroyPixelFormat(pixelFormat);
- + }
- - if (CGLContext != NULL)
- - {
- - CGLSetFullScreen(CGLContext);
- - displayRect = CGDisplayBounds(display);
- - ScreenWidth = DeviceWidth = (int)displayRect.size.width;
- - ScreenHeight = DeviceHeight = (int)displayRect.size.height;
- - CreationParams.WindowSize.set(ScreenWidth, ScreenHeight);
- - result = true;
- - }
- - }
- - }
- - }
- - }
- + if (CGLContext != NULL)
- + {
- + CGLSetFullScreen(CGLContext);
- + displayRect = CGDisplayBounds(display);
- + ScreenWidth = DeviceWidth = (int)displayRect.size.width;
- + ScreenHeight = DeviceHeight = (int)displayRect.size.height;
- + CreationParams.WindowSize.set(ScreenWidth, ScreenHeight);
- + result = true;
- + }
- + }
- + }
- + }
- + }
- + }
- + @catch (NSException *exception)
- + {
- + // FIXME: cleanup may be needed here
- + return false;
- + }
- +
- if (result)
- {
- // fullscreen?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement