From 13a438c91ecb24d0966f1464e30e8eb1b9634370 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 9 Feb 2012 01:53:26 +0100 Subject: [PATCH] Replaced NSDate time source with mach_absolute_time. --- readme.html | 1 + src/cocoa_init.m | 2 ++ src/cocoa_platform.h | 6 +++++- src/cocoa_time.m | 38 ++++++++++++++++++++++++++++++++++---- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/readme.html b/readme.html index eb18fced..19e4285d 100644 --- a/readme.html +++ b/readme.html @@ -310,6 +310,7 @@ version of GLFW.

  • Bugfix: The FSAA test did not check for the availability of GL_ARB_multisample
  • [Cocoa] Added support for OpenGL 3.2 core profile in 10.7 Lion and above
  • [Cocoa] Added support for joysticks
  • +
  • [Cocoa] Replaced NSDate time source with mach_absolute_time
  • [Cocoa] Bugfix: The loop condition for saving video modes used the wrong index variable
  • [Cocoa] Bugfix: The OpenGL framework was not retrieved, making glfwGetProcAddress crash
  • [X11] Added support for the GLX_EXT_swap_control extension as an alternative to GLX_SGI_swap_control
  • diff --git a/src/cocoa_init.m b/src/cocoa_init.m index bf4f7c2e..2c747515 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -230,6 +230,8 @@ int _glfwPlatformInit(void) _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); _glfwLibrary.currentRamp = _glfwLibrary.originalRamp; + _glfwInitTimer(); + _glfwInitJoysticks(); return GL_TRUE; diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index d5daf775..93492dbb 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -85,7 +85,8 @@ typedef struct _GLFWwindowNS typedef struct _GLFWlibraryNS { struct { - double t0; + double base; + double resolution; } timer; // dlopen handle for dynamically loading OpenGL extension entry points @@ -101,6 +102,9 @@ typedef struct _GLFWlibraryNS // Prototypes for platform specific internal functions //======================================================================== +// Time +void _glfwInitTimer(void); + // Joystick input void _glfwInitJoysticks(void); void _glfwTerminateJoysticks(void); diff --git a/src/cocoa_time.m b/src/cocoa_time.m index d7e7d2b8..4facbffb 100644 --- a/src/cocoa_time.m +++ b/src/cocoa_time.m @@ -29,6 +29,36 @@ #include "internal.h" +#include + + +//======================================================================== +// Return raw time +//======================================================================== + +static uint64_t getRawTime(void) +{ + return mach_absolute_time(); +} + + +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Initialise timer +//======================================================================== + +void _glfwInitTimer(void) +{ + mach_timebase_info_data_t info; + mach_timebase_info(&info); + + _glfwLibrary.NS.timer.resolution = (double) info.numer / (info.denom * 1.0e9); + _glfwLibrary.NS.timer.base = getRawTime(); +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// @@ -40,8 +70,8 @@ double _glfwPlatformGetTime(void) { - return [NSDate timeIntervalSinceReferenceDate] - - _glfwLibrary.NS.timer.t0; + return (double) (getRawTime() - _glfwLibrary.NS.timer.base) * + _glfwLibrary.NS.timer.resolution; } //======================================================================== @@ -50,7 +80,7 @@ double _glfwPlatformGetTime(void) void _glfwPlatformSetTime(double time) { - _glfwLibrary.NS.timer.t0 = - [NSDate timeIntervalSinceReferenceDate] - time; + _glfwLibrary.NS.timer.base = getRawTime() - + (uint64_t) (time / _glfwLibrary.NS.timer.resolution); }