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
int ScreenWidth;
int ScreenHeight;
u32 MouseButtonStates;
u32 SoftwareRendererType;
bool IsFullscreen;
bool IsActive;
bool IsSoftwareRenderer;
bool IsShiftDown;
bool IsControlDown;
bool IsResizable;
......
......@@ -478,9 +478,8 @@ namespace irr
CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
: CIrrDeviceStub(param), Window(NULL), CGLContext(NULL), OGLContext(NULL),
SoftwareDriverTarget(0), DeviceWidth(0), DeviceHeight(0),
ScreenWidth(0), ScreenHeight(0), MouseButtonStates(0),
IsActive(true), IsSoftwareRenderer(false),
IsShiftDown(false), IsControlDown(false), IsResizable(false)
ScreenWidth(0), ScreenHeight(0), MouseButtonStates(0), SoftwareRendererType(0),
IsActive(true), IsFullscreen(false), IsShiftDown(false), IsControlDown(false), IsResizable(false)
{
struct utsname name;
NSString *path;
......@@ -518,12 +517,14 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
bool success = true;
if (CreationParams.DriverType != video::EDT_NULL)
success = createWindow();
// in case of failure, one can check VideoDriver for initialization
if (!success)
return;
setResizable(false);
CursorControl = new CCursorControl(CreationParams.WindowSize, this);
createDriver();
createGUIAndScene();
}
......@@ -562,6 +563,9 @@ void CIrrDeviceMacOSX::closeDevice()
[Window setReleasedWhenClosed:TRUE];
[Window release];
Window = NULL;
if (IsFullscreen)
CGReleaseAllDisplays();
}
else
{
......@@ -583,6 +587,7 @@ void CIrrDeviceMacOSX::closeDevice()
}
}
IsFullscreen = false;
IsActive = false;
CGLContext = NULL;
}
......@@ -618,10 +623,14 @@ bool CIrrDeviceMacOSX::createWindow()
{
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 (CreationParams.DriverType == video::EDT_OPENGL)
{
NSOpenGLPixelFormatAttribute windowattribs[] =
{
......@@ -704,22 +713,28 @@ bool CIrrDeviceMacOSX::createWindow()
OGLContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL];
[format release];
}
}
if (OGLContext != NULL)
if (OGLContext != NULL || CreationParams.DriverType != video::EDT_OPENGL)
{
if (!CreationParams.WindowId)
{
[Window center];
[Window setDelegate:[NSApp delegate]];
if(CreationParams.DriverType == video::EDT_OPENGL)
[OGLContext setView:[Window contentView]];
[Window setAcceptsMouseMovedEvents:TRUE];
[Window setIsVisible:TRUE];
[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];
if (CreationParams.DriverType == video::EDT_OPENGL)
CGLContext = (CGLContextObj) [OGLContext CGLContextObj];
DeviceWidth = CreationParams.WindowSize.Width;
DeviceHeight = CreationParams.WindowSize.Height;
result = true;
......@@ -728,6 +743,8 @@ bool CIrrDeviceMacOSX::createWindow()
}
else
{
IsFullscreen = true;
#ifdef __MAC_10_6
displaymode = CGDisplayCopyDisplayMode(display);
......@@ -779,6 +796,8 @@ bool CIrrDeviceMacOSX::createWindow()
#endif
if (error == CGDisplayNoErr)
{
if (CreationParams.DriverType == video::EDT_OPENGL)
{
CGLPixelFormatAttribute fullattribs[] =
{
......@@ -820,6 +839,22 @@ bool CIrrDeviceMacOSX::createWindow()
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)
CGReleaseAllDisplays();
}
......@@ -842,13 +877,11 @@ bool CIrrDeviceMacOSX::createWindow()
SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
#endif
if(CreationParams.DriverType == video::EDT_OPENGL)
{
CGLSetCurrentContext(CGLContext);
newSwapInterval = (CreationParams.Vsync) ? 1 : 0;
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)
DeviceHeight = height;
// update the size of the opengl rendering context
if(OGLContext);
[OGLContext update];
// resize the driver to the inner pane size
......@@ -872,6 +906,7 @@ void CIrrDeviceMacOSX::setResize(int width, int height)
}
else
getVideoDriver()->OnResize(core::dimension2d<u32>( (s32)width, (s32)height));
if (CreationParams.WindowId && OGLContext)
[(NSOpenGLContext *)OGLContext update];
}
......@@ -884,7 +919,7 @@ void CIrrDeviceMacOSX::createDriver()
case video::EDT_SOFTWARE:
#ifdef _IRR_COMPILE_WITH_SOFTWARE_
VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
IsSoftwareRenderer = true;
SoftwareRendererType = 2;
#else
os::Printer::log("No Software driver support compiled in.", ELL_ERROR);
#endif
......@@ -893,7 +928,7 @@ void CIrrDeviceMacOSX::createDriver()
case video::EDT_BURNINGSVIDEO:
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
VideoDriver = video::createBurningVideoDriver(CreationParams, FileSystem, this);
IsSoftwareRenderer = true;
SoftwareRendererType = 1;
#else
os::Printer::log("Burning's video driver was not compiled in.", ELL_ERROR);
#endif
......@@ -933,14 +968,14 @@ void CIrrDeviceMacOSX::flush()
bool CIrrDeviceMacOSX::run()
{
NSAutoreleasePool* Pool = [[NSAutoreleasePool alloc] init];
NSEvent *event;
irr::SEvent ievent;
os::Timer::tick();
storeMouseLocation();
NSAutoreleasePool* Pool = [[NSAutoreleasePool alloc] init];
event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
if (event != nil)
{
......@@ -1478,7 +1513,7 @@ bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rec
if (!surface)
return false;
if (IsSoftwareRenderer)
if (SoftwareRendererType > 0)
{
const u32 colorSamples=3;
// do we need to change the size?
......@@ -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);
for (u32 y=0; y!=srcheight; ++y)
{
#if 0
if(SoftwareRendererType == 2)
{
if (surface->getColorFormat() == video::ECF_A8R8G8B8)
video::CColorConverter::convert_A8R8G8B8toB8G8R8(srcdata, minWidth, destData);
else
else if (surface->getColorFormat() == video::ECF_A1R5G5B5)
video::CColorConverter::convert_A1R5G5B5toB8G8R8(srcdata, minWidth, destData);
#else
else
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;
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