From c147b6308285be052a1ddf17985ea73d5be72b9c Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 15 May 2012 12:58:20 +0200 Subject: [PATCH] Changed: #1275 Compilation under Mac OS X --- code/nel/src/3d/driver/opengl/driver_opengl.h | 14 +++---- .../opengl/mac/cocoa_application_delegate.h | 16 ++++---- .../opengl/mac/cocoa_application_delegate.mm | 37 +++++++++---------- .../3d/driver/opengl/mac/cocoa_opengl_view.h | 27 ++++++++++++-- .../3d/driver/opengl/mac/cocoa_opengl_view.m | 16 +++----- .../driver/opengl/mac/cocoa_window_delegate.h | 16 ++++---- .../opengl/mac/cocoa_window_delegate.mm | 27 ++++++-------- 7 files changed, 83 insertions(+), 70 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.h b/code/nel/src/3d/driver/opengl/driver_opengl.h index 3890e1b69..660955083 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl/driver_opengl.h @@ -679,26 +679,28 @@ public: virtual void stencilOp(TStencilOp fail, TStencilOp zfail, TStencilOp zpass); virtual void stencilMask(uint mask); + GfxMode _CurrentMode; + sint32 _WindowX; + sint32 _WindowY; +#ifdef NL_OS_MAC + NLMISC::CCocoaEventEmitter _EventEmitter; +#endif private: virtual class IVertexBufferHardGL *createVertexBufferHard(uint size, uint numVertices, CVertexBuffer::TPreferredMemory vbType, CVertexBuffer *vb); friend class CTextureDrvInfosGL; friend class CVertexProgamDrvInfosGL; - private: // Version of the driver. Not the interface version!! Increment when implementation of the driver change. static const uint32 ReleaseVersion; // Windows nlWindow _win; - sint32 _WindowX; - sint32 _WindowY; bool _WindowVisible; bool _DestroyWindow; bool _Maximized; - GfxMode _CurrentMode; uint _Interval; bool _Resizable; @@ -790,11 +792,7 @@ private: #elif defined(NL_OS_MAC) friend bool GlWndProc(CDriverGL*, const void*); - friend void windowDidMove(NSWindow*, CDriverGL*); - friend void viewDidResize(NSView*, CDriverGL*); - friend NSApplicationTerminateReply applicationShouldTerminate(CDriverGL*); - NLMISC::CCocoaEventEmitter _EventEmitter; CocoaOpenGLView* _glView; NSAutoreleasePool* _autoreleasePool; uint16 _backBufferHeight; diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_application_delegate.h b/code/nel/src/3d/driver/opengl/mac/cocoa_application_delegate.h index 1cb5e82c9..668e61a50 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_application_delegate.h +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_application_delegate.h @@ -16,21 +16,23 @@ #import -namespace NL3D -{ - class CDriverGL; - NSApplicationTerminateReply applicationShouldTerminate(CDriverGL*); -} +#ifdef NL_STATIC +#ifdef USE_OPENGLES +using NL3D::NLDRIVERGLES::CDriverGL; +#else +using NL3D::NLDRIVERGL::CDriverGL; +#endif +#endif @interface CocoaApplicationDelegate : NSObject #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 #endif { - NL3D::CDriverGL* _driver; + CDriverGL* _driver; } --(id)initWithDriver:(NL3D::CDriverGL*)driver; +-(id)initWithDriver:(CDriverGL*)driver; -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; @end diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_application_delegate.mm b/code/nel/src/3d/driver/opengl/mac/cocoa_application_delegate.mm index 95d6879db..8fe0045b6 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_application_delegate.mm +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_application_delegate.mm @@ -20,32 +20,29 @@ #include "cocoa_application_delegate.h" #include "cocoa_event_emitter.h" -namespace NL3D +static NSApplicationTerminateReply applicationShouldTerminate(CDriverGL* driver) { - NSApplicationTerminateReply applicationShouldTerminate(CDriverGL* driver) + // cancel if there is a driver and a custom exit handler set up + if(driver && driver->ExitFunc) { - // cancel if there is a driver and a custom exit handler set up - if(driver && driver->ExitFunc) - { - driver->ExitFunc(); - return NSTerminateCancel; - } - - NLMISC::CCocoaEventEmitter* eventEmitter = - NLMISC::safe_cast(&(driver->_EventEmitter)); - - // cancel if there is a driver and cocoa event emitter handles the quit - if(driver && eventEmitter && eventEmitter->handleQuitRequest()) - return NSTerminateCancel; - - // just let the app terminate if no custom quit handling worked - return NSTerminateNow; + driver->ExitFunc(); + return NSTerminateCancel; } + + NLMISC::CCocoaEventEmitter* eventEmitter = + NLMISC::safe_cast(&(driver->_EventEmitter)); + + // cancel if there is a driver and cocoa event emitter handles the quit + if(driver && eventEmitter && eventEmitter->handleQuitRequest()) + return NSTerminateCancel; + + // just let the app terminate if no custom quit handling worked + return NSTerminateNow; } @implementation CocoaApplicationDelegate --(id)initWithDriver:(NL3D::CDriverGL*)driver +-(id)initWithDriver:(CDriverGL*)driver { if((self = [super init])) { @@ -57,7 +54,7 @@ namespace NL3D -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender { - return NL3D::applicationShouldTerminate(_driver); + return applicationShouldTerminate(_driver); } @end diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.h b/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.h index 8017433ec..b2b123274 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.h +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.h @@ -18,21 +18,42 @@ namespace NL3D { + +#ifdef NL_STATIC +#ifdef USE_OPENGLES +namespace NLDRIVERGLES { +#else +namespace NLDRIVERGL { +#endif +#endif + class CDriverGL; - void viewDidResize(NSView*, CDriverGL*); + +#ifdef NL_STATIC +} // NLDRIVERGL/ES +#endif + } +#ifdef NL_STATIC +#ifdef USE_OPENGLES +using NL3D::NLDRIVERGLES::CDriverGL; +#else +using NL3D::NLDRIVERGL::CDriverGL; +#endif +#endif + @interface CocoaOpenGLView : NSOpenGLView { NSMutableAttributedString* _characterStorage; NSRange _markedRange; - NL3D::CDriverGL* _driver; + CDriverGL* _driver; } -(id)initWithFrame:(NSRect)frame; -(void)dealloc; -(void)keyDown:(NSEvent*)event; --(void)setDriver:(NL3D::CDriverGL*)driver; +-(void)setDriver:(CDriverGL*)driver; -(void)resizeWithOldSuperviewSize:(NSSize)oldBoundsSize; @end diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.m b/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.m index 763b16aef..17500389c 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.m +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_opengl_view.m @@ -19,17 +19,13 @@ #import "cocoa_opengl_view.h" -namespace NL3D +static void viewDidResize(NSView* view, CDriverGL* driver) { - void viewDidResize(NSView* view, CDriverGL* driver) - { - NSRect rect = [[view superview] frame]; - driver->_CurrentMode.Height = rect.size.height; - driver->_CurrentMode.Width = rect.size.width; - } + NSRect rect = [[view superview] frame]; + driver->_CurrentMode.Height = rect.size.height; + driver->_CurrentMode.Width = rect.size.width; } - @implementation CocoaOpenGLView -(id)initWithFrame:(NSRect)frame @@ -56,7 +52,7 @@ namespace NL3D #endif } --(void)setDriver:(NL3D::CDriverGL*)driver +-(void)setDriver:(CDriverGL*)driver { _driver = driver; } @@ -68,7 +64,7 @@ namespace NL3D if(!_driver) return; - NL3D::viewDidResize(self, _driver); + viewDidResize(self, _driver); } /******************************************************************************/ diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_window_delegate.h b/code/nel/src/3d/driver/opengl/mac/cocoa_window_delegate.h index 4d3710b34..d35b162d6 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_window_delegate.h +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_window_delegate.h @@ -17,21 +17,23 @@ #import #include "AvailabilityMacros.h" -namespace NL3D -{ - class CDriverGL; - void windowDidMove(NSWindow*, NL3D::CDriverGL*); -} +#ifdef NL_STATIC +#ifdef USE_OPENGLES +using NL3D::NLDRIVERGLES::CDriverGL; +#else +using NL3D::NLDRIVERGL::CDriverGL; +#endif +#endif @interface CocoaWindowDelegate : NSObject #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 #endif { - NL3D::CDriverGL* _driver; + CDriverGL* _driver; } -- (id)initWithDriver:(NL3D::CDriverGL*)driver; +- (id)initWithDriver:(CDriverGL*)driver; - (void)windowDidMove:(NSNotification*)notification; @end diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_window_delegate.mm b/code/nel/src/3d/driver/opengl/mac/cocoa_window_delegate.mm index c11fb55d0..a2eb54a6b 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_window_delegate.mm +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_window_delegate.mm @@ -19,28 +19,25 @@ #import "cocoa_window_delegate.h" -namespace NL3D +static void windowDidMove(NSWindow* window, CDriverGL* driver) { - void windowDidMove(NSWindow* window, NL3D::CDriverGL* driver) - { - // get the rect (position, size) of the screen with menu bar - NSRect screenRect = [[[NSScreen screens] objectAtIndex:0] frame]; + // get the rect (position, size) of the screen with menu bar + NSRect screenRect = [[[NSScreen screens] objectAtIndex:0] frame]; - // get the rect (position, size) of the window - NSRect windowRect = [window frame]; + // get the rect (position, size) of the window + NSRect windowRect = [window frame]; - // set x in driver - driver->_WindowX = windowRect.origin.x; + // set x in driver + driver->_WindowX = windowRect.origin.x; - // map y from cocoa to NeL coordinates before setting in driver - driver->_WindowY = - screenRect.size.height - windowRect.size.height - windowRect.origin.y; - } + // map y from cocoa to NeL coordinates before setting in driver + driver->_WindowY = + screenRect.size.height - windowRect.size.height - windowRect.origin.y; } @implementation CocoaWindowDelegate --(id)initWithDriver:(NL3D::CDriverGL*)driver +-(id)initWithDriver:(CDriverGL*)driver { if((self = [super init])) { @@ -56,7 +53,7 @@ namespace NL3D if(!_driver) return; - NL3D::windowDidMove([notification object], _driver); + windowDidMove([notification object], _driver); } @end