Moved to using NSOpenGLView.

This commit is contained in:
Camilla Berglund 2014-12-29 18:15:12 +01:00
parent 4783b17fa3
commit 81bcefe86c
2 changed files with 20 additions and 13 deletions

View File

@ -96,6 +96,7 @@ GLFW bundles a number of dependencies in the `deps/` directory.
- Bugfix: The cursor was not positioned over newly created full screen windows - Bugfix: The cursor was not positioned over newly created full screen windows
- [Cocoa] Added `_GLFW_USE_RETINA` to control whether windows will use the full - [Cocoa] Added `_GLFW_USE_RETINA` to control whether windows will use the full
resolution on Retina displays resolution on Retina displays
- [Cocoa] Made content view subclass of `NSOpenGLView`
- [Cocoa] Bugfix: Using a 1x1 cursor for hidden mode caused some screen - [Cocoa] Bugfix: Using a 1x1 cursor for hidden mode caused some screen
recorders to fail recorders to fail
- [Cocoa] Bugfix: Some Core Foundation objects were leaked during joystick - [Cocoa] Bugfix: Some Core Foundation objects were leaked during joystick

View File

@ -167,8 +167,6 @@ static NSRect convertRectToBacking(_GLFWwindow* window, NSRect contentRect)
- (void)windowDidResize:(NSNotification *)notification - (void)windowDidResize:(NSNotification *)notification
{ {
[window->nsgl.context update];
const NSRect contentRect = [window->ns.view frame]; const NSRect contentRect = [window->ns.view frame];
const NSRect fbRect = convertRectToBacking(window, contentRect); const NSRect fbRect = convertRectToBacking(window, contentRect);
@ -182,8 +180,6 @@ static NSRect convertRectToBacking(_GLFWwindow* window, NSRect contentRect)
- (void)windowDidMove:(NSNotification *)notification - (void)windowDidMove:(NSNotification *)notification
{ {
[window->nsgl.context update];
int x, y; int x, y;
_glfwPlatformGetWindowPos(window, &x, &y); _glfwPlatformGetWindowPos(window, &x, &y);
_glfwInputWindowPos(window, x, y); _glfwInputWindowPos(window, x, y);
@ -304,7 +300,7 @@ static int translateKey(unsigned int key)
// Content view class for the GLFW window // Content view class for the GLFW window
//------------------------------------------------------------------------ //------------------------------------------------------------------------
@interface GLFWContentView : NSView @interface GLFWContentView : NSOpenGLView
{ {
_GLFWwindow* window; _GLFWwindow* window;
NSTrackingArea* trackingArea; NSTrackingArea* trackingArea;
@ -332,7 +328,8 @@ static int translateKey(unsigned int key)
- (id)initWithGlfwWindow:(_GLFWwindow *)initWindow - (id)initWithGlfwWindow:(_GLFWwindow *)initWindow
{ {
self = [super init]; self = [super initWithFrame:NSMakeRect(0, 0, 1, 1)
pixelFormat:nil];
if (self != nil) if (self != nil)
{ {
window = initWindow; window = initWindow;
@ -870,15 +867,9 @@ static GLboolean createWindow(_GLFWwindow* window,
return GL_FALSE; return GL_FALSE;
} }
window->ns.view = [[GLFWContentView alloc] initWithGlfwWindow:window];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6)
{ {
#if defined(_GLFW_USE_RETINA)
[window->ns.view setWantsBestResolutionOpenGLSurface:YES];
#endif
if (wndconfig->resizable) if (wndconfig->resizable)
[window->ns.object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; [window->ns.object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
} }
@ -898,7 +889,6 @@ static GLboolean createWindow(_GLFWwindow* window,
} }
[window->ns.object setTitle:[NSString stringWithUTF8String:wndconfig->title]]; [window->ns.object setTitle:[NSString stringWithUTF8String:wndconfig->title]];
[window->ns.object setContentView:window->ns.view];
[window->ns.object setDelegate:window->ns.delegate]; [window->ns.object setDelegate:window->ns.delegate];
[window->ns.object setAcceptsMouseMovedEvents:YES]; [window->ns.object setAcceptsMouseMovedEvents:YES];
@ -929,6 +919,22 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (!_glfwCreateContext(window, ctxconfig, fbconfig)) if (!_glfwCreateContext(window, ctxconfig, fbconfig))
return GL_FALSE; return GL_FALSE;
window->ns.view = [[GLFWContentView alloc] initWithGlfwWindow:window];
#if defined(_GLFW_USE_RETINA)
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6)
[window->ns.view setWantsBestResolutionOpenGLSurface:YES];
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
#endif /*_GLFW_USE_RETINA*/
[window->ns.object setContentView:window->ns.view];
// NOTE: If you set the pixel format before the context it creates another
// context, only to have it destroyed by the next line
// We cannot use the view to create the context because that interface
// does not support context resource sharing
[window->ns.view setOpenGLContext:window->nsgl.context];
[window->ns.view setPixelFormat:window->nsgl.pixelFormat];
[window->nsgl.context setView:window->ns.view]; [window->nsgl.context setView:window->ns.view];
if (wndconfig->monitor) if (wndconfig->monitor)