|
|
@ -35,52 +35,59 @@ |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
@interface GLFWWindowDelegate : NSObject |
|
|
|
@interface GLFWWindowDelegate : NSObject |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_GLFWwindow* window; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (id)initWithRats:(_GLFWwindow*)initWndow; |
|
|
|
|
|
|
|
|
|
|
|
@end |
|
|
|
@end |
|
|
|
|
|
|
|
|
|
|
|
@implementation GLFWWindowDelegate |
|
|
|
@implementation GLFWWindowDelegate |
|
|
|
|
|
|
|
|
|
|
|
- (BOOL)windowShouldClose:(id)window |
|
|
|
- (id)initWithRats:(_GLFWwindow*)initWindow |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
self = [super init]; |
|
|
|
|
|
|
|
if (self != nil) |
|
|
|
|
|
|
|
window = initWindow; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return self; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (BOOL)windowShouldClose:(id)sender |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( _glfwWin.windowCloseCallback ) |
|
|
|
if (window->windowCloseCallback) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( !_glfwWin.windowCloseCallback() ) |
|
|
|
if (!window->windowCloseCallback(window)) |
|
|
|
{ |
|
|
|
|
|
|
|
return NO; |
|
|
|
return NO; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// This is horribly ugly, but it works |
|
|
|
window->closed = GL_TRUE; |
|
|
|
glfwCloseWindow(); |
|
|
|
|
|
|
|
return NO; |
|
|
|
return NO; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)windowDidResize:(NSNotification *)notification |
|
|
|
- (void)windowDidResize:(NSNotification *)notification |
|
|
|
{ |
|
|
|
{ |
|
|
|
[_glfwWin.context update]; |
|
|
|
[window->NSGL.context update]; |
|
|
|
|
|
|
|
|
|
|
|
NSRect contentRect = |
|
|
|
NSRect contentRect = |
|
|
|
[_glfwWin.window contentRectForFrameRect:[_glfwWin.window frame]]; |
|
|
|
[window->NS.window contentRectForFrameRect:[window->NS.window frame]]; |
|
|
|
_glfwWin.width = contentRect.size.width; |
|
|
|
window->width = contentRect.size.width; |
|
|
|
_glfwWin.height = contentRect.size.height; |
|
|
|
window->height = contentRect.size.height; |
|
|
|
|
|
|
|
|
|
|
|
if( _glfwWin.windowSizeCallback ) |
|
|
|
if (window->windowSizeCallback) |
|
|
|
{ |
|
|
|
window->windowSizeCallback(window, window->width, window->height); |
|
|
|
_glfwWin.windowSizeCallback( _glfwWin.width, _glfwWin.height ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender |
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( _glfwWin.windowCloseCallback ) |
|
|
|
if (window->windowCloseCallback) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( !_glfwWin.windowCloseCallback() ) |
|
|
|
if (!window->windowCloseCallback(window)) |
|
|
|
{ |
|
|
|
|
|
|
|
return NSTerminateCancel; |
|
|
|
return NSTerminateCancel; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// This is horribly ugly, but it works |
|
|
|
window->closed = GL_TRUE; |
|
|
|
glfwCloseWindow(); |
|
|
|
|
|
|
|
return NSTerminateCancel; |
|
|
|
return NSTerminateCancel; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -223,12 +230,10 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] = |
|
|
|
// Converts a Mac OS X keycode to a GLFW keycode |
|
|
|
// Converts a Mac OS X keycode to a GLFW keycode |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
static int convertMacKeyCode( unsigned int macKeyCode ) |
|
|
|
static int convertMacKeyCode(unsigned int macKeyCode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( macKeyCode >= 128 ) |
|
|
|
if (macKeyCode >= 128) |
|
|
|
{ |
|
|
|
|
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This treats keycodes as *positional*; that is, we'll return 'a' |
|
|
|
// This treats keycodes as *positional*; that is, we'll return 'a' |
|
|
|
// for the key left of 's', even on an AZERTY keyboard. The charInput |
|
|
|
// for the key left of 's', even on an AZERTY keyboard. The charInput |
|
|
@ -241,10 +246,25 @@ static int convertMacKeyCode( unsigned int macKeyCode ) |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
@interface GLFWContentView : NSView |
|
|
|
@interface GLFWContentView : NSView |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_GLFWwindow* window; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (id)initWithRats:(_GLFWwindow*)initWindow; |
|
|
|
|
|
|
|
|
|
|
|
@end |
|
|
|
@end |
|
|
|
|
|
|
|
|
|
|
|
@implementation GLFWContentView |
|
|
|
@implementation GLFWContentView |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (id)initWithRats:(_GLFWwindow*)initWindow |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
self = [super init]; |
|
|
|
|
|
|
|
if (self != nil) |
|
|
|
|
|
|
|
window = initWindow; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return self; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (BOOL)isOpaque |
|
|
|
- (BOOL)isOpaque |
|
|
|
{ |
|
|
|
{ |
|
|
|
return YES; |
|
|
|
return YES; |
|
|
@ -262,7 +282,7 @@ static int convertMacKeyCode( unsigned int macKeyCode ) |
|
|
|
|
|
|
|
|
|
|
|
- (void)mouseDown:(NSEvent *)event |
|
|
|
- (void)mouseDown:(NSEvent *)event |
|
|
|
{ |
|
|
|
{ |
|
|
|
_glfwInputMouseClick( GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS ); |
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)mouseDragged:(NSEvent *)event |
|
|
|
- (void)mouseDragged:(NSEvent *)event |
|
|
@ -272,34 +292,32 @@ static int convertMacKeyCode( unsigned int macKeyCode ) |
|
|
|
|
|
|
|
|
|
|
|
- (void)mouseUp:(NSEvent *)event |
|
|
|
- (void)mouseUp:(NSEvent *)event |
|
|
|
{ |
|
|
|
{ |
|
|
|
_glfwInputMouseClick( GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE ); |
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)mouseMoved:(NSEvent *)event |
|
|
|
- (void)mouseMoved:(NSEvent *)event |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( _glfwWin.mouseLock ) |
|
|
|
if (window == _glfwLibrary.cursorLockWindow) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_glfwInput.MousePosX += [event deltaX]; |
|
|
|
window->mousePosX += [event deltaX]; |
|
|
|
_glfwInput.MousePosY += [event deltaY]; |
|
|
|
window->mousePosY += [event deltaY]; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
NSPoint p = [event locationInWindow]; |
|
|
|
NSPoint p = [event locationInWindow]; |
|
|
|
|
|
|
|
|
|
|
|
// Cocoa coordinate system has origin at lower left |
|
|
|
// Cocoa coordinate system has origin at lower left |
|
|
|
_glfwInput.MousePosX = p.x; |
|
|
|
window->mousePosX = p.x; |
|
|
|
_glfwInput.MousePosY = [[_glfwWin.window contentView] bounds].size.height - p.y; |
|
|
|
window->mousePosY = [[window->NS.window contentView] bounds].size.height - p.y; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if( _glfwWin.mousePosCallback ) |
|
|
|
if (window->mousePosCallback) |
|
|
|
{ |
|
|
|
window->mousePosCallback(window, window->mousePosX, window->mousePosY); |
|
|
|
_glfwWin.mousePosCallback( _glfwInput.MousePosX, _glfwInput.MousePosY ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)rightMouseDown:(NSEvent *)event |
|
|
|
- (void)rightMouseDown:(NSEvent *)event |
|
|
|
{ |
|
|
|
{ |
|
|
|
_glfwInputMouseClick( GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS ); |
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)rightMouseDragged:(NSEvent *)event |
|
|
|
- (void)rightMouseDragged:(NSEvent *)event |
|
|
@ -309,12 +327,12 @@ static int convertMacKeyCode( unsigned int macKeyCode ) |
|
|
|
|
|
|
|
|
|
|
|
- (void)rightMouseUp:(NSEvent *)event |
|
|
|
- (void)rightMouseUp:(NSEvent *)event |
|
|
|
{ |
|
|
|
{ |
|
|
|
_glfwInputMouseClick( GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE ); |
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)otherMouseDown:(NSEvent *)event |
|
|
|
- (void)otherMouseDown:(NSEvent *)event |
|
|
|
{ |
|
|
|
{ |
|
|
|
_glfwInputMouseClick( [event buttonNumber], GLFW_PRESS ); |
|
|
|
_glfwInputMouseClick(window, [event buttonNumber], GLFW_PRESS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)otherMouseDragged:(NSEvent *)event |
|
|
|
- (void)otherMouseDragged:(NSEvent *)event |
|
|
@ -324,86 +342,64 @@ static int convertMacKeyCode( unsigned int macKeyCode ) |
|
|
|
|
|
|
|
|
|
|
|
- (void)otherMouseUp:(NSEvent *)event |
|
|
|
- (void)otherMouseUp:(NSEvent *)event |
|
|
|
{ |
|
|
|
{ |
|
|
|
_glfwInputMouseClick( [event buttonNumber], GLFW_RELEASE ); |
|
|
|
_glfwInputMouseClick(window, [event buttonNumber], GLFW_RELEASE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)keyDown:(NSEvent *)event |
|
|
|
- (void)keyDown:(NSEvent *)event |
|
|
|
{ |
|
|
|
{ |
|
|
|
NSUInteger length; |
|
|
|
NSUInteger i, length; |
|
|
|
NSString* characters; |
|
|
|
NSString* characters; |
|
|
|
int i, code = convertMacKeyCode( [event keyCode] ); |
|
|
|
int code = convertMacKeyCode([event keyCode]); |
|
|
|
|
|
|
|
|
|
|
|
if( code != -1 ) |
|
|
|
if (code != -1) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_glfwInputKey( code, GLFW_PRESS ); |
|
|
|
_glfwInputKey(window, code, GLFW_PRESS); |
|
|
|
|
|
|
|
|
|
|
|
if( [event modifierFlags] & NSCommandKeyMask ) |
|
|
|
if ([event modifierFlags] & NSCommandKeyMask) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( !_glfwWin.sysKeysDisabled ) |
|
|
|
if (!window->sysKeysDisabled) |
|
|
|
{ |
|
|
|
|
|
|
|
[super keyDown:event]; |
|
|
|
[super keyDown:event]; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
characters = [event characters]; |
|
|
|
characters = [event characters]; |
|
|
|
length = [characters length]; |
|
|
|
length = [characters length]; |
|
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < length; i++ ) |
|
|
|
for (i = 0; i < length; i++) |
|
|
|
{ |
|
|
|
_glfwInputChar(window, [characters characterAtIndex:i]); |
|
|
|
_glfwInputChar( [characters characterAtIndex:i], GLFW_PRESS ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)flagsChanged:(NSEvent *)event |
|
|
|
- (void)flagsChanged:(NSEvent *)event |
|
|
|
{ |
|
|
|
{ |
|
|
|
unsigned int newModifierFlags = [event modifierFlags] | NSDeviceIndependentModifierFlagsMask; |
|
|
|
|
|
|
|
int mode; |
|
|
|
int mode; |
|
|
|
|
|
|
|
unsigned int newModifierFlags = |
|
|
|
|
|
|
|
[event modifierFlags] | NSDeviceIndependentModifierFlagsMask; |
|
|
|
|
|
|
|
|
|
|
|
if( newModifierFlags > _glfwWin.modifierFlags ) |
|
|
|
if (newModifierFlags > window->NS.modifierFlags) |
|
|
|
{ |
|
|
|
|
|
|
|
mode = GLFW_PRESS; |
|
|
|
mode = GLFW_PRESS; |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
|
|
|
|
mode = GLFW_RELEASE; |
|
|
|
mode = GLFW_RELEASE; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_glfwWin.modifierFlags = newModifierFlags; |
|
|
|
window->NS.modifierFlags = newModifierFlags; |
|
|
|
_glfwInputKey( MAC_TO_GLFW_KEYCODE_MAPPING[[event keyCode]], mode ); |
|
|
|
_glfwInputKey(window, MAC_TO_GLFW_KEYCODE_MAPPING[[event keyCode]], mode); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)keyUp:(NSEvent *)event |
|
|
|
- (void)keyUp:(NSEvent *)event |
|
|
|
{ |
|
|
|
{ |
|
|
|
NSUInteger length; |
|
|
|
int code = convertMacKeyCode([event keyCode]); |
|
|
|
NSString* characters; |
|
|
|
if (code != -1) |
|
|
|
int i, code = convertMacKeyCode( [event keyCode] ); |
|
|
|
_glfwInputKey(window, code, GLFW_RELEASE); |
|
|
|
|
|
|
|
|
|
|
|
if( code != -1 ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_glfwInputKey( code, GLFW_RELEASE ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
characters = [event characters]; |
|
|
|
|
|
|
|
length = [characters length]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < length; i++ ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_glfwInputChar( [characters characterAtIndex:i], GLFW_RELEASE ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)scrollWheel:(NSEvent *)event |
|
|
|
- (void)scrollWheel:(NSEvent *)event |
|
|
|
{ |
|
|
|
{ |
|
|
|
_glfwInput.WheelPosFloating += [event deltaY]; |
|
|
|
window->NS.wheelPosFloating += [event deltaY]; |
|
|
|
_glfwInput.WheelPos = lrint(_glfwInput.WheelPosFloating); |
|
|
|
window->wheelPos = lrint(window->NS.wheelPosFloating); |
|
|
|
|
|
|
|
|
|
|
|
if( _glfwWin.mouseWheelCallback ) |
|
|
|
if (window->mouseWheelCallback) |
|
|
|
{ |
|
|
|
window->mouseWheelCallback(window, window->wheelPos); |
|
|
|
_glfwWin.mouseWheelCallback( _glfwInput.WheelPos ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@end |
|
|
|
@end |
|
|
@ -417,43 +413,37 @@ static int convertMacKeyCode( unsigned int macKeyCode ) |
|
|
|
// created |
|
|
|
// created |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
int _glfwPlatformOpenWindow( int width, int height, |
|
|
|
int _glfwPlatformOpenWindow(_GLFWwindow* window, |
|
|
|
const _GLFWwndconfig *wndconfig, |
|
|
|
const _GLFWwndconfig *wndconfig, |
|
|
|
const _GLFWfbconfig *fbconfig ) |
|
|
|
const _GLFWfbconfig *fbconfig) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int colorBits; |
|
|
|
window->NS.window = nil; |
|
|
|
|
|
|
|
window->NS.delegate = nil; |
|
|
|
_glfwWin.pixelFormat = nil; |
|
|
|
window->NSGL.pixelFormat = nil; |
|
|
|
_glfwWin.window = nil; |
|
|
|
window->NSGL.context = nil; |
|
|
|
_glfwWin.context = nil; |
|
|
|
|
|
|
|
_glfwWin.delegate = nil; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fail if OpenGL 3.0 or above was requested |
|
|
|
// Fail if OpenGL 3.0 or above was requested |
|
|
|
if( wndconfig->glMajor > 2 ) |
|
|
|
if (wndconfig->glMajor > 2) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_glfwPlatformCloseWindow(); |
|
|
|
_glfwSetError(GLFW_UNAVAILABLE_VERSION); |
|
|
|
return GL_FALSE; |
|
|
|
return GL_FALSE; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_glfwWin.delegate = [[GLFWWindowDelegate alloc] init]; |
|
|
|
window->NS.delegate = [[GLFWWindowDelegate alloc] initWithRats:window]; |
|
|
|
if( _glfwWin.delegate == nil ) |
|
|
|
if (window->NS.delegate == nil) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_glfwPlatformCloseWindow(); |
|
|
|
_glfwSetError(GLFW_INTERNAL_ERROR); |
|
|
|
return GL_FALSE; |
|
|
|
return GL_FALSE; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[NSApp setDelegate:_glfwWin.delegate]; |
|
|
|
[NSApp setDelegate:window->NS.delegate]; |
|
|
|
|
|
|
|
|
|
|
|
// Mac OS X needs non-zero color size, so set resonable values |
|
|
|
// Mac OS X needs non-zero color size, so set resonable values |
|
|
|
colorBits = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits; |
|
|
|
int colorBits = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits; |
|
|
|
if( colorBits == 0 ) |
|
|
|
if (colorBits == 0) |
|
|
|
{ |
|
|
|
|
|
|
|
colorBits = 24; |
|
|
|
colorBits = 24; |
|
|
|
} |
|
|
|
else if (colorBits < 15) |
|
|
|
else if( colorBits < 15 ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
colorBits = 15; |
|
|
|
colorBits = 15; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ignored hints: |
|
|
|
// Ignored hints: |
|
|
|
// OpenGLMajor, OpenGLMinor, OpenGLForward: |
|
|
|
// OpenGLMajor, OpenGLMinor, OpenGLForward: |
|
|
@ -465,55 +455,55 @@ int _glfwPlatformOpenWindow( int width, int height, |
|
|
|
// Aux buffers probably aren't accelerated either |
|
|
|
// Aux buffers probably aren't accelerated either |
|
|
|
|
|
|
|
|
|
|
|
CFDictionaryRef fullscreenMode = NULL; |
|
|
|
CFDictionaryRef fullscreenMode = NULL; |
|
|
|
if( wndconfig->mode == GLFW_FULLSCREEN ) |
|
|
|
if (wndconfig->mode == GLFW_FULLSCREEN) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
// I think it's safe to pass 0 to the refresh rate for this function |
|
|
|
|
|
|
|
// rather than conditionalizing the code to call the version which |
|
|
|
|
|
|
|
// doesn't specify refresh... |
|
|
|
fullscreenMode = |
|
|
|
fullscreenMode = |
|
|
|
// I think it's safe to pass 0 to the refresh rate for this function |
|
|
|
|
|
|
|
// rather than conditionalizing the code to call the version which |
|
|
|
|
|
|
|
// doesn't specify refresh... |
|
|
|
|
|
|
|
CGDisplayBestModeForParametersAndRefreshRateWithProperty( |
|
|
|
CGDisplayBestModeForParametersAndRefreshRateWithProperty( |
|
|
|
CGMainDisplayID(), |
|
|
|
CGMainDisplayID(), |
|
|
|
colorBits + fbconfig->alphaBits, |
|
|
|
colorBits + fbconfig->alphaBits, |
|
|
|
width, |
|
|
|
window->width, window->height, |
|
|
|
height, |
|
|
|
wndconfig->refreshRate, |
|
|
|
wndconfig->refreshRate, |
|
|
|
// Controversial, see macosx_fullscreen.m for discussion |
|
|
|
// Controversial, see macosx_fullscreen.m for discussion |
|
|
|
kCGDisplayModeIsSafeForHardware, |
|
|
|
kCGDisplayModeIsSafeForHardware, |
|
|
|
NULL); |
|
|
|
NULL); |
|
|
|
|
|
|
|
|
|
|
|
window->width = [[(id)fullscreenMode objectForKey:(id)kCGDisplayWidth] intValue]; |
|
|
|
width = [[(id)fullscreenMode objectForKey:(id)kCGDisplayWidth] intValue]; |
|
|
|
window->height = [[(id)fullscreenMode objectForKey:(id)kCGDisplayHeight] intValue]; |
|
|
|
height = [[(id)fullscreenMode objectForKey:(id)kCGDisplayHeight] intValue]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned int styleMask = 0; |
|
|
|
unsigned int styleMask = 0; |
|
|
|
if( wndconfig->mode == GLFW_WINDOW ) |
|
|
|
|
|
|
|
|
|
|
|
if (wndconfig->mode == GLFW_WINDOWED) |
|
|
|
{ |
|
|
|
{ |
|
|
|
styleMask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask; |
|
|
|
styleMask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask; |
|
|
|
|
|
|
|
|
|
|
|
if( !wndconfig->windowNoResize ) |
|
|
|
if (!wndconfig->windowNoResize) |
|
|
|
{ |
|
|
|
|
|
|
|
styleMask |= NSResizableWindowMask; |
|
|
|
styleMask |= NSResizableWindowMask; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
|
|
|
|
styleMask = NSBorderlessWindowMask; |
|
|
|
styleMask = NSBorderlessWindowMask; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_glfwWin.window = [[NSWindow alloc] |
|
|
|
window->NS.window = [[NSWindow alloc] |
|
|
|
initWithContentRect:NSMakeRect(0, 0, width, height) |
|
|
|
initWithContentRect:NSMakeRect(0, 0, window->width, window->height) |
|
|
|
styleMask:styleMask |
|
|
|
styleMask:styleMask |
|
|
|
backing:NSBackingStoreBuffered |
|
|
|
backing:NSBackingStoreBuffered |
|
|
|
defer:NO]; |
|
|
|
defer:NO]; |
|
|
|
[_glfwWin.window setContentView:[[GLFWContentView alloc] init]]; |
|
|
|
|
|
|
|
[_glfwWin.window setDelegate:_glfwWin.delegate]; |
|
|
|
|
|
|
|
[_glfwWin.window setAcceptsMouseMovedEvents:YES]; |
|
|
|
|
|
|
|
[_glfwWin.window center]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( wndconfig->mode == GLFW_FULLSCREEN ) |
|
|
|
[window->NS.window setTitle:[NSString stringWithCString:wndconfig->title |
|
|
|
|
|
|
|
encoding:NSISOLatin1StringEncoding]]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[window->NS.window setContentView:[[GLFWContentView alloc] initWithRats:window]]; |
|
|
|
|
|
|
|
[window->NS.window setDelegate:window->NS.delegate]; |
|
|
|
|
|
|
|
[window->NS.window setAcceptsMouseMovedEvents:YES]; |
|
|
|
|
|
|
|
[window->NS.window center]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (wndconfig->mode == GLFW_FULLSCREEN) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CGCaptureAllDisplays(); |
|
|
|
CGCaptureAllDisplays(); |
|
|
|
CGDisplaySwitchToMode( CGMainDisplayID(), fullscreenMode ); |
|
|
|
CGDisplaySwitchToMode(CGMainDisplayID(), fullscreenMode); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned int attribute_count = 0; |
|
|
|
unsigned int attribute_count = 0; |
|
|
@ -522,123 +512,125 @@ int _glfwPlatformOpenWindow( int width, int height, |
|
|
|
#define MAX_ATTRS 24 // urgh |
|
|
|
#define MAX_ATTRS 24 // urgh |
|
|
|
NSOpenGLPixelFormatAttribute attributes[MAX_ATTRS]; |
|
|
|
NSOpenGLPixelFormatAttribute attributes[MAX_ATTRS]; |
|
|
|
|
|
|
|
|
|
|
|
ADD_ATTR( NSOpenGLPFADoubleBuffer ); |
|
|
|
ADD_ATTR(NSOpenGLPFADoubleBuffer); |
|
|
|
|
|
|
|
|
|
|
|
if( wndconfig->mode == GLFW_FULLSCREEN ) |
|
|
|
if (wndconfig->mode == GLFW_FULLSCREEN) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ADD_ATTR( NSOpenGLPFAFullScreen ); |
|
|
|
ADD_ATTR(NSOpenGLPFAFullScreen); |
|
|
|
ADD_ATTR( NSOpenGLPFANoRecovery ); |
|
|
|
ADD_ATTR(NSOpenGLPFANoRecovery); |
|
|
|
ADD_ATTR2( NSOpenGLPFAScreenMask, |
|
|
|
ADD_ATTR2(NSOpenGLPFAScreenMask, |
|
|
|
CGDisplayIDToOpenGLDisplayMask( CGMainDisplayID() ) ); |
|
|
|
CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ADD_ATTR2( NSOpenGLPFAColorSize, colorBits ); |
|
|
|
ADD_ATTR2(NSOpenGLPFAColorSize, colorBits); |
|
|
|
|
|
|
|
|
|
|
|
if( fbconfig->alphaBits > 0) |
|
|
|
if (fbconfig->alphaBits > 0) |
|
|
|
{ |
|
|
|
ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits); |
|
|
|
ADD_ATTR2( NSOpenGLPFAAlphaSize, fbconfig->alphaBits ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( fbconfig->depthBits > 0) |
|
|
|
if (fbconfig->depthBits > 0) |
|
|
|
{ |
|
|
|
ADD_ATTR2(NSOpenGLPFADepthSize, fbconfig->depthBits); |
|
|
|
ADD_ATTR2( NSOpenGLPFADepthSize, fbconfig->depthBits ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( fbconfig->stencilBits > 0) |
|
|
|
if (fbconfig->stencilBits > 0) |
|
|
|
{ |
|
|
|
ADD_ATTR2(NSOpenGLPFAStencilSize, fbconfig->stencilBits); |
|
|
|
ADD_ATTR2( NSOpenGLPFAStencilSize, fbconfig->stencilBits ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int accumBits = fbconfig->accumRedBits + fbconfig->accumGreenBits + |
|
|
|
int accumBits = fbconfig->accumRedBits + fbconfig->accumGreenBits + |
|
|
|
fbconfig->accumBlueBits + fbconfig->accumAlphaBits; |
|
|
|
fbconfig->accumBlueBits + fbconfig->accumAlphaBits; |
|
|
|
|
|
|
|
|
|
|
|
if( accumBits > 0) |
|
|
|
if (accumBits > 0) |
|
|
|
{ |
|
|
|
ADD_ATTR2(NSOpenGLPFAAccumSize, accumBits); |
|
|
|
ADD_ATTR2( NSOpenGLPFAAccumSize, accumBits ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( fbconfig->auxBuffers > 0) |
|
|
|
if (fbconfig->auxBuffers > 0) |
|
|
|
{ |
|
|
|
ADD_ATTR2(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers); |
|
|
|
ADD_ATTR2( NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( fbconfig->stereo) |
|
|
|
if (fbconfig->stereo) |
|
|
|
{ |
|
|
|
ADD_ATTR(NSOpenGLPFAStereo ); |
|
|
|
ADD_ATTR( NSOpenGLPFAStereo ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( fbconfig->samples > 0) |
|
|
|
if (fbconfig->samples > 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ADD_ATTR2( NSOpenGLPFASampleBuffers, 1 ); |
|
|
|
ADD_ATTR2(NSOpenGLPFASampleBuffers, 1); |
|
|
|
ADD_ATTR2( NSOpenGLPFASamples, fbconfig->samples ); |
|
|
|
ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ADD_ATTR(0); |
|
|
|
ADD_ATTR(0); |
|
|
|
|
|
|
|
|
|
|
|
_glfwWin.pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; |
|
|
|
window->NSGL.pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; |
|
|
|
if( _glfwWin.pixelFormat == nil ) |
|
|
|
if (window->NSGL.pixelFormat == nil) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_glfwPlatformCloseWindow(); |
|
|
|
_glfwSetError(GLFW_NO_PIXEL_FORMAT); |
|
|
|
return GL_FALSE; |
|
|
|
return GL_FALSE; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_glfwWin.context = [[NSOpenGLContext alloc] initWithFormat:_glfwWin.pixelFormat |
|
|
|
window->NSGL.context = [[NSOpenGLContext alloc] initWithFormat:window->NSGL.pixelFormat |
|
|
|
shareContext:nil]; |
|
|
|
shareContext:nil]; |
|
|
|
if( _glfwWin.context == nil ) |
|
|
|
if (window->NSGL.context == nil) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_glfwPlatformCloseWindow(); |
|
|
|
_glfwSetError(GLFW_INTERNAL_ERROR); |
|
|
|
return GL_FALSE; |
|
|
|
return GL_FALSE; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[_glfwWin.window makeKeyAndOrderFront:nil]; |
|
|
|
[window->NS.window makeKeyAndOrderFront:nil]; |
|
|
|
[_glfwWin.context setView:[_glfwWin.window contentView]]; |
|
|
|
[window->NSGL.context setView:[window->NS.window contentView]]; |
|
|
|
|
|
|
|
|
|
|
|
if( wndconfig->mode == GLFW_FULLSCREEN ) |
|
|
|
if (wndconfig->mode == GLFW_FULLSCREEN) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// TODO: Make this work on pre-Leopard systems |
|
|
|
// TODO: Make this work on pre-Leopard systems |
|
|
|
[[_glfwWin.window contentView] enterFullScreenMode:[NSScreen mainScreen] |
|
|
|
[[window->NS.window contentView] enterFullScreenMode:[NSScreen mainScreen] |
|
|
|
withOptions:nil]; |
|
|
|
withOptions:nil]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[_glfwWin.context makeCurrentContext]; |
|
|
|
glfwMakeWindowCurrent(window); |
|
|
|
|
|
|
|
|
|
|
|
NSPoint point = [[NSCursor currentCursor] hotSpot]; |
|
|
|
NSPoint point = [[NSCursor currentCursor] hotSpot]; |
|
|
|
_glfwInput.MousePosX = point.x; |
|
|
|
window->mousePosX = point.x; |
|
|
|
_glfwInput.MousePosY = point.y; |
|
|
|
window->mousePosY = point.y; |
|
|
|
|
|
|
|
|
|
|
|
return GL_TRUE; |
|
|
|
return GL_TRUE; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
// Make the OpenGL context associated with the specified window current |
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformMakeWindowCurrent(_GLFWwindow* window) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (window) |
|
|
|
|
|
|
|
[window->NSGL.context makeCurrentContext]; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
[NSOpenGLContext clearCurrentContext]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
// Properly kill the window / video display |
|
|
|
// Properly kill the window / video display |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformCloseWindow( void ) |
|
|
|
void _glfwPlatformCloseWindow(_GLFWwindow* window) |
|
|
|
{ |
|
|
|
{ |
|
|
|
[_glfwWin.window orderOut:nil]; |
|
|
|
[window->NS.window orderOut:nil]; |
|
|
|
|
|
|
|
|
|
|
|
if( _glfwWin.fullscreen ) |
|
|
|
if (window->mode == GLFW_FULLSCREEN) |
|
|
|
{ |
|
|
|
{ |
|
|
|
[[_glfwWin.window contentView] exitFullScreenModeWithOptions:nil]; |
|
|
|
[[window->NS.window contentView] exitFullScreenModeWithOptions:nil]; |
|
|
|
CGDisplaySwitchToMode( CGMainDisplayID(), |
|
|
|
|
|
|
|
(CFDictionaryRef)_glfwLibrary.DesktopMode ); |
|
|
|
CGDisplaySwitchToMode(CGMainDisplayID(), |
|
|
|
|
|
|
|
(CFDictionaryRef) _glfwLibrary.NS.desktopMode); |
|
|
|
CGReleaseAllDisplays(); |
|
|
|
CGReleaseAllDisplays(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[_glfwWin.pixelFormat release]; |
|
|
|
[window->NSGL.pixelFormat release]; |
|
|
|
_glfwWin.pixelFormat = nil; |
|
|
|
window->NSGL.pixelFormat = nil; |
|
|
|
|
|
|
|
|
|
|
|
[NSOpenGLContext clearCurrentContext]; |
|
|
|
[NSOpenGLContext clearCurrentContext]; |
|
|
|
[_glfwWin.context release]; |
|
|
|
[window->NSGL.context release]; |
|
|
|
_glfwWin.context = nil; |
|
|
|
window->NSGL.context = nil; |
|
|
|
|
|
|
|
|
|
|
|
[_glfwWin.window setDelegate:nil]; |
|
|
|
[window->NS.window setDelegate:nil]; |
|
|
|
[NSApp setDelegate:nil]; |
|
|
|
[NSApp setDelegate:nil]; |
|
|
|
[_glfwWin.delegate release]; |
|
|
|
[window->NS.delegate release]; |
|
|
|
_glfwWin.delegate = nil; |
|
|
|
window->NS.delegate = nil; |
|
|
|
|
|
|
|
|
|
|
|
[_glfwWin.window close]; |
|
|
|
[window->NS.window close]; |
|
|
|
_glfwWin.window = nil; |
|
|
|
window->NS.window = nil; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: Probably more cleanup |
|
|
|
// TODO: Probably more cleanup |
|
|
|
} |
|
|
|
} |
|
|
@ -647,37 +639,37 @@ void _glfwPlatformCloseWindow( void ) |
|
|
|
// Set the window title |
|
|
|
// Set the window title |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowTitle( const char *title ) |
|
|
|
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title) |
|
|
|
{ |
|
|
|
{ |
|
|
|
[_glfwWin.window setTitle:[NSString stringWithCString:title |
|
|
|
[window->NS.window setTitle:[NSString stringWithCString:title |
|
|
|
encoding:NSISOLatin1StringEncoding]]; |
|
|
|
encoding:NSISOLatin1StringEncoding]]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
// Set the window size |
|
|
|
// Set the window size |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowSize( int width, int height ) |
|
|
|
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) |
|
|
|
{ |
|
|
|
{ |
|
|
|
[_glfwWin.window setContentSize:NSMakeSize(width, height)]; |
|
|
|
[window->NS.window setContentSize:NSMakeSize(width, height)]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
// Set the window position |
|
|
|
// Set the window position |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowPos( int x, int y ) |
|
|
|
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
NSRect contentRect = [_glfwWin.window contentRectForFrameRect:[_glfwWin.window frame]]; |
|
|
|
NSRect contentRect = [window->NS.window contentRectForFrameRect:[window->NS.window frame]]; |
|
|
|
|
|
|
|
|
|
|
|
// We assume here that the client code wants to position the window within the |
|
|
|
// We assume here that the client code wants to position the window within the |
|
|
|
// screen the window currently occupies |
|
|
|
// screen the window currently occupies |
|
|
|
NSRect screenRect = [[_glfwWin.window screen] visibleFrame]; |
|
|
|
NSRect screenRect = [[window->NS.window screen] visibleFrame]; |
|
|
|
contentRect.origin = NSMakePoint(screenRect.origin.x + x, |
|
|
|
contentRect.origin = NSMakePoint(screenRect.origin.x + x, |
|
|
|
screenRect.origin.y + screenRect.size.height - |
|
|
|
screenRect.origin.y + screenRect.size.height - |
|
|
|
y - contentRect.size.height); |
|
|
|
y - contentRect.size.height); |
|
|
|
|
|
|
|
|
|
|
|
[_glfwWin.window setFrame:[_glfwWin.window frameRectForContentRect:contentRect] |
|
|
|
[window->NS.window setFrame:[window->NS.window frameRectForContentRect:contentRect] |
|
|
|
display:YES]; |
|
|
|
display:YES]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -685,117 +677,122 @@ void _glfwPlatformSetWindowPos( int x, int y ) |
|
|
|
// Iconify the window |
|
|
|
// Iconify the window |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformIconifyWindow( void ) |
|
|
|
void _glfwPlatformIconifyWindow(_GLFWwindow* window) |
|
|
|
{ |
|
|
|
{ |
|
|
|
[_glfwWin.window miniaturize:nil]; |
|
|
|
[window->NS.window miniaturize:nil]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
// Restore (un-iconify) the window |
|
|
|
// Restore (un-iconify) the window |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformRestoreWindow( void ) |
|
|
|
void _glfwPlatformRestoreWindow(_GLFWwindow* window) |
|
|
|
{ |
|
|
|
{ |
|
|
|
[_glfwWin.window deminiaturize:nil]; |
|
|
|
[window->NS.window deminiaturize:nil]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
// Swap buffers |
|
|
|
// Swap buffers |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformSwapBuffers( void ) |
|
|
|
void _glfwPlatformSwapBuffers(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
_GLFWwindow* window = _glfwLibrary.currentWindow; |
|
|
|
|
|
|
|
|
|
|
|
// ARP appears to be unnecessary, but this is future-proof |
|
|
|
// ARP appears to be unnecessary, but this is future-proof |
|
|
|
[_glfwWin.context flushBuffer]; |
|
|
|
[window->NSGL.context flushBuffer]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
// Set double buffering swap interval |
|
|
|
// Set double buffering swap interval |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformSwapInterval( int interval ) |
|
|
|
void _glfwPlatformSwapInterval(int interval) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
_GLFWwindow* window = _glfwLibrary.currentWindow; |
|
|
|
|
|
|
|
|
|
|
|
GLint sync = interval; |
|
|
|
GLint sync = interval; |
|
|
|
[_glfwWin.context setValues:&sync forParameter:NSOpenGLCPSwapInterval]; |
|
|
|
[window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
// Write back window parameters into GLFW window structure |
|
|
|
// Write back window parameters into GLFW window structure |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformRefreshWindowParams( void ) |
|
|
|
void _glfwPlatformRefreshWindowParams(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
GLint value; |
|
|
|
GLint value; |
|
|
|
|
|
|
|
_GLFWwindow* window = _glfwLibrary.currentWindow; |
|
|
|
|
|
|
|
|
|
|
|
// Since GLFW 2.x doesn't understand screens, we use virtual screen zero |
|
|
|
// Since GLFW doesn't understand screens, we use virtual screen zero |
|
|
|
|
|
|
|
|
|
|
|
[_glfwWin.pixelFormat getValues:&value |
|
|
|
[window->NSGL.pixelFormat getValues:&value |
|
|
|
forAttribute:NSOpenGLPFAAccelerated |
|
|
|
forAttribute:NSOpenGLPFAAccelerated |
|
|
|
forVirtualScreen:0]; |
|
|
|
forVirtualScreen:0]; |
|
|
|
_glfwWin.accelerated = value; |
|
|
|
window->accelerated = value; |
|
|
|
|
|
|
|
|
|
|
|
[_glfwWin.pixelFormat getValues:&value |
|
|
|
[window->NSGL.pixelFormat getValues:&value |
|
|
|
forAttribute:NSOpenGLPFAAlphaSize |
|
|
|
forAttribute:NSOpenGLPFAAlphaSize |
|
|
|
forVirtualScreen:0]; |
|
|
|
forVirtualScreen:0]; |
|
|
|
_glfwWin.alphaBits = value; |
|
|
|
window->alphaBits = value; |
|
|
|
|
|
|
|
|
|
|
|
// It seems that the color size includes the size of the alpha channel |
|
|
|
// It seems that the color size includes the size of the alpha channel |
|
|
|
[_glfwWin.pixelFormat getValues:&value |
|
|
|
[window->NSGL.pixelFormat getValues:&value |
|
|
|
forAttribute:NSOpenGLPFAColorSize |
|
|
|
forAttribute:NSOpenGLPFAColorSize |
|
|
|
forVirtualScreen:0]; |
|
|
|
forVirtualScreen:0]; |
|
|
|
value -= _glfwWin.alphaBits; |
|
|
|
value -= window->alphaBits; |
|
|
|
_glfwWin.redBits = value / 3; |
|
|
|
window->redBits = value / 3; |
|
|
|
_glfwWin.greenBits = value / 3; |
|
|
|
window->greenBits = value / 3; |
|
|
|
_glfwWin.blueBits = value / 3; |
|
|
|
window->blueBits = value / 3; |
|
|
|
|
|
|
|
|
|
|
|
[_glfwWin.pixelFormat getValues:&value |
|
|
|
[window->NSGL.pixelFormat getValues:&value |
|
|
|
forAttribute:NSOpenGLPFADepthSize |
|
|
|
forAttribute:NSOpenGLPFADepthSize |
|
|
|
forVirtualScreen:0]; |
|
|
|
forVirtualScreen:0]; |
|
|
|
_glfwWin.depthBits = value; |
|
|
|
window->depthBits = value; |
|
|
|
|
|
|
|
|
|
|
|
[_glfwWin.pixelFormat getValues:&value |
|
|
|
[window->NSGL.pixelFormat getValues:&value |
|
|
|
forAttribute:NSOpenGLPFAStencilSize |
|
|
|
forAttribute:NSOpenGLPFAStencilSize |
|
|
|
forVirtualScreen:0]; |
|
|
|
forVirtualScreen:0]; |
|
|
|
_glfwWin.stencilBits = value; |
|
|
|
window->stencilBits = value; |
|
|
|
|
|
|
|
|
|
|
|
[_glfwWin.pixelFormat getValues:&value |
|
|
|
[window->NSGL.pixelFormat getValues:&value |
|
|
|
forAttribute:NSOpenGLPFAAccumSize |
|
|
|
forAttribute:NSOpenGLPFAAccumSize |
|
|
|
forVirtualScreen:0]; |
|
|
|
forVirtualScreen:0]; |
|
|
|
_glfwWin.accumRedBits = value / 3; |
|
|
|
window->accumRedBits = value / 3; |
|
|
|
_glfwWin.accumGreenBits = value / 3; |
|
|
|
window->accumGreenBits = value / 3; |
|
|
|
_glfwWin.accumBlueBits = value / 3; |
|
|
|
window->accumBlueBits = value / 3; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: Figure out what to set this value to |
|
|
|
// TODO: Figure out what to set this value to |
|
|
|
_glfwWin.accumAlphaBits = 0; |
|
|
|
window->accumAlphaBits = 0; |
|
|
|
|
|
|
|
|
|
|
|
[_glfwWin.pixelFormat getValues:&value |
|
|
|
[window->NSGL.pixelFormat getValues:&value |
|
|
|
forAttribute:NSOpenGLPFAAuxBuffers |
|
|
|
forAttribute:NSOpenGLPFAAuxBuffers |
|
|
|
forVirtualScreen:0]; |
|
|
|
forVirtualScreen:0]; |
|
|
|
_glfwWin.auxBuffers = value; |
|
|
|
window->auxBuffers = value; |
|
|
|
|
|
|
|
|
|
|
|
[_glfwWin.pixelFormat getValues:&value |
|
|
|
[window->NSGL.pixelFormat getValues:&value |
|
|
|
forAttribute:NSOpenGLPFAStereo |
|
|
|
forAttribute:NSOpenGLPFAStereo |
|
|
|
forVirtualScreen:0]; |
|
|
|
forVirtualScreen:0]; |
|
|
|
_glfwWin.stereo = value; |
|
|
|
window->stereo = value; |
|
|
|
|
|
|
|
|
|
|
|
[_glfwWin.pixelFormat getValues:&value |
|
|
|
[window->NSGL.pixelFormat getValues:&value |
|
|
|
forAttribute:NSOpenGLPFASamples |
|
|
|
forAttribute:NSOpenGLPFASamples |
|
|
|
forVirtualScreen:0]; |
|
|
|
forVirtualScreen:0]; |
|
|
|
_glfwWin.samples = value; |
|
|
|
window->samples = value; |
|
|
|
|
|
|
|
|
|
|
|
// These are forced to false as long as Mac OS X lacks support for OpenGL 3.0+ |
|
|
|
// These are forced to false as long as Mac OS X lacks support for OpenGL 3.0+ |
|
|
|
_glfwWin.glForward = GL_FALSE; |
|
|
|
window->glForward = GL_FALSE; |
|
|
|
_glfwWin.glDebug = GL_FALSE; |
|
|
|
window->glDebug = GL_FALSE; |
|
|
|
_glfwWin.glProfile = 0; |
|
|
|
window->glProfile = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
// Poll for new window and input events |
|
|
|
// Poll for new window and input events |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformPollEvents( void ) |
|
|
|
void _glfwPlatformPollEvents(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
NSEvent *event; |
|
|
|
NSEvent* event; |
|
|
|
|
|
|
|
|
|
|
|
do |
|
|
|
do |
|
|
|
{ |
|
|
|
{ |
|
|
@ -805,14 +802,12 @@ void _glfwPlatformPollEvents( void ) |
|
|
|
dequeue:YES]; |
|
|
|
dequeue:YES]; |
|
|
|
|
|
|
|
|
|
|
|
if (event) |
|
|
|
if (event) |
|
|
|
{ |
|
|
|
|
|
|
|
[NSApp sendEvent:event]; |
|
|
|
[NSApp sendEvent:event]; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
while (event); |
|
|
|
while (event); |
|
|
|
|
|
|
|
|
|
|
|
[_glfwLibrary.AutoreleasePool drain]; |
|
|
|
[_glfwLibrary.NS.autoreleasePool drain]; |
|
|
|
_glfwLibrary.AutoreleasePool = [[NSAutoreleasePool alloc] init]; |
|
|
|
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
@ -837,27 +832,27 @@ void _glfwPlatformWaitEvents( void ) |
|
|
|
// Hide mouse cursor (lock it) |
|
|
|
// Hide mouse cursor (lock it) |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformHideMouseCursor( void ) |
|
|
|
void _glfwPlatformHideMouseCursor(_GLFWwindow* window) |
|
|
|
{ |
|
|
|
{ |
|
|
|
[NSCursor hide]; |
|
|
|
[NSCursor hide]; |
|
|
|
CGAssociateMouseAndMouseCursorPosition( false ); |
|
|
|
CGAssociateMouseAndMouseCursorPosition(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
// Show mouse cursor (unlock it) |
|
|
|
// Show mouse cursor (unlock it) |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformShowMouseCursor( void ) |
|
|
|
void _glfwPlatformShowMouseCursor(_GLFWwindow* window) |
|
|
|
{ |
|
|
|
{ |
|
|
|
[NSCursor unhide]; |
|
|
|
[NSCursor unhide]; |
|
|
|
CGAssociateMouseAndMouseCursorPosition( true ); |
|
|
|
CGAssociateMouseAndMouseCursorPosition(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
// Set physical mouse cursor position |
|
|
|
// Set physical mouse cursor position |
|
|
|
//======================================================================== |
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformSetMouseCursorPos( int x, int y ) |
|
|
|
void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// The library seems to assume that after calling this the mouse won't move, |
|
|
|
// The library seems to assume that after calling this the mouse won't move, |
|
|
|
// but obviously it will, and escape the app's window, and activate other apps, |
|
|
|
// but obviously it will, and escape the app's window, and activate other apps, |
|
|
@ -876,7 +871,7 @@ void _glfwPlatformSetMouseCursorPos( int x, int y ) |
|
|
|
CGSetLocalEventsSuppressionInterval( 0.0 ); |
|
|
|
CGSetLocalEventsSuppressionInterval( 0.0 ); |
|
|
|
|
|
|
|
|
|
|
|
NSPoint localPoint = NSMakePoint( x, y ); |
|
|
|
NSPoint localPoint = NSMakePoint( x, y ); |
|
|
|
NSPoint globalPoint = [_glfwWin.window convertBaseToScreen:localPoint]; |
|
|
|
NSPoint globalPoint = [window->NS.window convertBaseToScreen:localPoint]; |
|
|
|
CGPoint mainScreenOrigin = CGDisplayBounds( CGMainDisplayID() ).origin; |
|
|
|
CGPoint mainScreenOrigin = CGDisplayBounds( CGMainDisplayID() ).origin; |
|
|
|
double mainScreenHeight = CGDisplayBounds( CGMainDisplayID() ).size.height; |
|
|
|
double mainScreenHeight = CGDisplayBounds( CGMainDisplayID() ).size.height; |
|
|
|
CGPoint targetPoint = CGPointMake( globalPoint.x - mainScreenOrigin.x, |
|
|
|
CGPoint targetPoint = CGPointMake( globalPoint.x - mainScreenOrigin.x, |
|
|
|