Commit f126da63 authored by nadro's avatar nadro

- Added support for Burning's Video and Software Drivers in MacOSX.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4111 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 65e3d8b4
...@@ -235,8 +235,9 @@ namespace irr ...@@ -235,8 +235,9 @@ namespace irr
int ScreenWidth; int ScreenWidth;
int ScreenHeight; int ScreenHeight;
u32 MouseButtonStates; u32 MouseButtonStates;
u32 SoftwareRendererType;
bool IsFullscreen;
bool IsActive; bool IsActive;
bool IsSoftwareRenderer;
bool IsShiftDown; bool IsShiftDown;
bool IsControlDown; bool IsControlDown;
bool IsResizable; bool IsResizable;
......
...@@ -478,9 +478,8 @@ namespace irr ...@@ -478,9 +478,8 @@ namespace irr
CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param) CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
: CIrrDeviceStub(param), Window(NULL), CGLContext(NULL), OGLContext(NULL), : CIrrDeviceStub(param), Window(NULL), CGLContext(NULL), OGLContext(NULL),
SoftwareDriverTarget(0), DeviceWidth(0), DeviceHeight(0), SoftwareDriverTarget(0), DeviceWidth(0), DeviceHeight(0),
ScreenWidth(0), ScreenHeight(0), MouseButtonStates(0), ScreenWidth(0), ScreenHeight(0), MouseButtonStates(0), SoftwareRendererType(0),
IsActive(true), IsSoftwareRenderer(false), IsActive(true), IsFullscreen(false), IsShiftDown(false), IsControlDown(false), IsResizable(false)
IsShiftDown(false), IsControlDown(false), IsResizable(false)
{ {
struct utsname name; struct utsname name;
NSString *path; NSString *path;
...@@ -518,12 +517,14 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param) ...@@ -518,12 +517,14 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
bool success = true; bool success = true;
if (CreationParams.DriverType != video::EDT_NULL) if (CreationParams.DriverType != video::EDT_NULL)
success = createWindow(); success = createWindow();
// in case of failure, one can check VideoDriver for initialization // in case of failure, one can check VideoDriver for initialization
if (!success) if (!success)
return; return;
setResizable(false); setResizable(false);
CursorControl = new CCursorControl(CreationParams.WindowSize, this); CursorControl = new CCursorControl(CreationParams.WindowSize, this);
createDriver(); createDriver();
createGUIAndScene(); createGUIAndScene();
} }
...@@ -562,6 +563,9 @@ void CIrrDeviceMacOSX::closeDevice() ...@@ -562,6 +563,9 @@ void CIrrDeviceMacOSX::closeDevice()
[Window setReleasedWhenClosed:TRUE]; [Window setReleasedWhenClosed:TRUE];
[Window release]; [Window release];
Window = NULL; Window = NULL;
if (IsFullscreen)
CGReleaseAllDisplays();
} }
else else
{ {
...@@ -583,6 +587,7 @@ void CIrrDeviceMacOSX::closeDevice() ...@@ -583,6 +587,7 @@ void CIrrDeviceMacOSX::closeDevice()
} }
} }
IsFullscreen = false;
IsActive = false; IsActive = false;
CGLContext = NULL; CGLContext = NULL;
} }
...@@ -618,10 +623,14 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -618,10 +623,14 @@ bool CIrrDeviceMacOSX::createWindow()
{ {
if(!CreationParams.WindowId) //create another window when WindowId is null 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]; NSBackingStoreType type = (CreationParams.DriverType == video::EDT_OPENGL) ? NSBackingStoreBuffered : NSBackingStoreNonretained;
Window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:type defer:FALSE];
} }
if (Window != NULL || CreationParams.WindowId) if (Window != NULL || CreationParams.WindowId)
{
if (CreationParams.DriverType == video::EDT_OPENGL)
{ {
NSOpenGLPixelFormatAttribute windowattribs[] = NSOpenGLPixelFormatAttribute windowattribs[] =
{ {
...@@ -704,22 +713,28 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -704,22 +713,28 @@ bool CIrrDeviceMacOSX::createWindow()
OGLContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL]; OGLContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL];
[format release]; [format release];
} }
}
if (OGLContext != NULL) if (OGLContext != NULL || CreationParams.DriverType != video::EDT_OPENGL)
{ {
if (!CreationParams.WindowId) if (!CreationParams.WindowId)
{ {
[Window center]; [Window center];
[Window setDelegate:[NSApp delegate]]; [Window setDelegate:[NSApp delegate]];
if(CreationParams.DriverType == video::EDT_OPENGL)
[OGLContext setView:[Window contentView]]; [OGLContext setView:[Window contentView]];
[Window setAcceptsMouseMovedEvents:TRUE]; [Window setAcceptsMouseMovedEvents:TRUE];
[Window setIsVisible:TRUE]; [Window setIsVisible:TRUE];
[Window makeKeyAndOrderFront:nil]; [Window makeKeyAndOrderFront:nil];
} }
else //use another window for drawing else if(CreationParams.DriverType == video::EDT_OPENGL) //use another window for drawing
[OGLContext setView:(NSView*)CreationParams.WindowId]; [OGLContext setView:(NSView*)CreationParams.WindowId];
if (CreationParams.DriverType == video::EDT_OPENGL)
CGLContext = (CGLContextObj) [OGLContext CGLContextObj]; CGLContext = (CGLContextObj) [OGLContext CGLContextObj];
DeviceWidth = CreationParams.WindowSize.Width; DeviceWidth = CreationParams.WindowSize.Width;
DeviceHeight = CreationParams.WindowSize.Height; DeviceHeight = CreationParams.WindowSize.Height;
result = true; result = true;
...@@ -728,6 +743,8 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -728,6 +743,8 @@ bool CIrrDeviceMacOSX::createWindow()
} }
else else
{ {
IsFullscreen = true;
#ifdef __MAC_10_6 #ifdef __MAC_10_6
displaymode = CGDisplayCopyDisplayMode(display); displaymode = CGDisplayCopyDisplayMode(display);
...@@ -779,6 +796,8 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -779,6 +796,8 @@ bool CIrrDeviceMacOSX::createWindow()
#endif #endif
if (error == CGDisplayNoErr) if (error == CGDisplayNoErr)
{
if (CreationParams.DriverType == video::EDT_OPENGL)
{ {
CGLPixelFormatAttribute fullattribs[] = CGLPixelFormatAttribute fullattribs[] =
{ {
...@@ -820,6 +839,22 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -820,6 +839,22 @@ bool CIrrDeviceMacOSX::createWindow()
result = true; result = true;
} }
} }
else
{
Window = [[NSWindow alloc] initWithContentRect:[[NSScreen mainScreen] frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreNonretained defer:NO screen:[NSScreen mainScreen]];
[Window setLevel: CGShieldingWindowLevel()];
[Window setAcceptsMouseMovedEvents:TRUE];
[Window setIsVisible:TRUE];
[Window makeKeyAndOrderFront:nil];
displayRect = CGDisplayBounds(display);
ScreenWidth = DeviceWidth = (int)displayRect.size.width;
ScreenHeight = DeviceHeight = (int)displayRect.size.height;
CreationParams.WindowSize.set(ScreenWidth, ScreenHeight);
result = true;
}
}
if (!result) if (!result)
CGReleaseAllDisplays(); CGReleaseAllDisplays();
} }
...@@ -842,13 +877,11 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -842,13 +877,11 @@ bool CIrrDeviceMacOSX::createWindow()
SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
#endif #endif
if(CreationParams.DriverType == video::EDT_OPENGL)
{
CGLSetCurrentContext(CGLContext); CGLSetCurrentContext(CGLContext);
newSwapInterval = (CreationParams.Vsync) ? 1 : 0; newSwapInterval = (CreationParams.Vsync) ? 1 : 0;
CGLSetParameter(CGLContext,kCGLCPSwapInterval,&newSwapInterval); CGLSetParameter(CGLContext,kCGLCPSwapInterval,&newSwapInterval);
if (IsSoftwareRenderer && CreationParams.DriverType != video::EDT_NULL)
{
GLint order = -1; // below window
CGLSetParameter(CGLContext, kCGLCPSurfaceOrder, &order);
} }
} }
...@@ -862,6 +895,7 @@ void CIrrDeviceMacOSX::setResize(int width, int height) ...@@ -862,6 +895,7 @@ void CIrrDeviceMacOSX::setResize(int width, int height)
DeviceHeight = height; DeviceHeight = height;
// update the size of the opengl rendering context // update the size of the opengl rendering context
if(OGLContext);
[OGLContext update]; [OGLContext update];
// resize the driver to the inner pane size // resize the driver to the inner pane size
...@@ -872,6 +906,7 @@ void CIrrDeviceMacOSX::setResize(int width, int height) ...@@ -872,6 +906,7 @@ void CIrrDeviceMacOSX::setResize(int width, int height)
} }
else else
getVideoDriver()->OnResize(core::dimension2d<u32>( (s32)width, (s32)height)); getVideoDriver()->OnResize(core::dimension2d<u32>( (s32)width, (s32)height));
if (CreationParams.WindowId && OGLContext) if (CreationParams.WindowId && OGLContext)
[(NSOpenGLContext *)OGLContext update]; [(NSOpenGLContext *)OGLContext update];
} }
...@@ -884,7 +919,7 @@ void CIrrDeviceMacOSX::createDriver() ...@@ -884,7 +919,7 @@ void CIrrDeviceMacOSX::createDriver()
case video::EDT_SOFTWARE: case video::EDT_SOFTWARE:
#ifdef _IRR_COMPILE_WITH_SOFTWARE_ #ifdef _IRR_COMPILE_WITH_SOFTWARE_
VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this); VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
IsSoftwareRenderer = true; SoftwareRendererType = 2;
#else #else
os::Printer::log("No Software driver support compiled in.", ELL_ERROR); os::Printer::log("No Software driver support compiled in.", ELL_ERROR);
#endif #endif
...@@ -893,7 +928,7 @@ void CIrrDeviceMacOSX::createDriver() ...@@ -893,7 +928,7 @@ void CIrrDeviceMacOSX::createDriver()
case video::EDT_BURNINGSVIDEO: case video::EDT_BURNINGSVIDEO:
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_ #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
VideoDriver = video::createBurningVideoDriver(CreationParams, FileSystem, this); VideoDriver = video::createBurningVideoDriver(CreationParams, FileSystem, this);
IsSoftwareRenderer = true; SoftwareRendererType = 1;
#else #else
os::Printer::log("Burning's video driver was not compiled in.", ELL_ERROR); os::Printer::log("Burning's video driver was not compiled in.", ELL_ERROR);
#endif #endif
...@@ -933,14 +968,14 @@ void CIrrDeviceMacOSX::flush() ...@@ -933,14 +968,14 @@ void CIrrDeviceMacOSX::flush()
bool CIrrDeviceMacOSX::run() bool CIrrDeviceMacOSX::run()
{ {
NSAutoreleasePool* Pool = [[NSAutoreleasePool alloc] init];
NSEvent *event; NSEvent *event;
irr::SEvent ievent; irr::SEvent ievent;
os::Timer::tick(); os::Timer::tick();
storeMouseLocation(); storeMouseLocation();
NSAutoreleasePool* Pool = [[NSAutoreleasePool alloc] init];
event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES]; event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
if (event != nil) if (event != nil)
{ {
...@@ -1478,7 +1513,7 @@ bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rec ...@@ -1478,7 +1513,7 @@ bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rec
if (!surface) if (!surface)
return false; return false;
if (IsSoftwareRenderer) if (SoftwareRendererType > 0)
{ {
const u32 colorSamples=3; const u32 colorSamples=3;
// do we need to change the size? // do we need to change the size?
...@@ -1520,14 +1555,25 @@ bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rec ...@@ -1520,14 +1555,25 @@ bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rec
const u32 minWidth = core::min_(surface->getDimension().Width, (u32)areaRect.size.width); const u32 minWidth = core::min_(surface->getDimension().Width, (u32)areaRect.size.width);
for (u32 y=0; y!=srcheight; ++y) for (u32 y=0; y!=srcheight; ++y)
{ {
#if 0 if(SoftwareRendererType == 2)
{
if (surface->getColorFormat() == video::ECF_A8R8G8B8) if (surface->getColorFormat() == video::ECF_A8R8G8B8)
video::CColorConverter::convert_A8R8G8B8toB8G8R8(srcdata, minWidth, destData); video::CColorConverter::convert_A8R8G8B8toB8G8R8(srcdata, minWidth, destData);
else else if (surface->getColorFormat() == video::ECF_A1R5G5B5)
video::CColorConverter::convert_A1R5G5B5toB8G8R8(srcdata, minWidth, destData); video::CColorConverter::convert_A1R5G5B5toB8G8R8(srcdata, minWidth, destData);
#else else
video::CColorConverter::convert_viaFormat(srcdata, surface->getColorFormat(), minWidth, destData, video::ECF_R8G8B8); video::CColorConverter::convert_viaFormat(srcdata, surface->getColorFormat(), minWidth, destData, video::ECF_R8G8B8);
#endif }
else
{
if (surface->getColorFormat() == video::ECF_A8R8G8B8)
video::CColorConverter::convert_A8R8G8B8toR8G8B8(srcdata, minWidth, destData);
else if (surface->getColorFormat() == video::ECF_A1R5G5B5)
video::CColorConverter::convert_A1R5G5B5toR8G8B8(srcdata, minWidth, destData);
else
video::CColorConverter::convert_viaFormat(srcdata, surface->getColorFormat(), minWidth, destData, video::ECF_R8G8B8);
}
srcdata += srcPitch; srcdata += srcPitch;
destData += destPitch; destData += destPitch;
} }
......
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