blob: 96f7b454ac11ca062545cfc51a342224a614fbe9 [file] [log] [blame]
Camilla Berglund3249f812010-09-07 17:34:51 +02001//========================================================================
Camilla Berglund6e553c72011-03-06 01:46:39 +01002// GLFW - An OpenGL library
Camilla Berglunde10d9352012-08-28 15:03:57 +02003// Platform: Win32
Camilla Berglund38b0ccb2010-09-07 17:41:26 +02004// API version: 3.0
Camilla Berglund3249f812010-09-07 17:34:51 +02005// WWW: http://www.glfw.org/
6//------------------------------------------------------------------------
7// Copyright (c) 2002-2006 Marcus Geelnard
8// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
9//
10// This software is provided 'as-is', without any express or implied
11// warranty. In no event will the authors be held liable for any damages
12// arising from the use of this software.
13//
14// Permission is granted to anyone to use this software for any purpose,
15// including commercial applications, and to alter it and redistribute it
16// freely, subject to the following restrictions:
17//
18// 1. The origin of this software must not be misrepresented; you must not
19// claim that you wrote the original software. If you use this software
20// in a product, an acknowledgment in the product documentation would
21// be appreciated but is not required.
22//
23// 2. Altered source versions must be plainly marked as such, and must not
24// be misrepresented as being the original software.
25//
26// 3. This notice may not be removed or altered from any source
27// distribution.
28//
29//========================================================================
30
31#include "internal.h"
32
33
Camilla Berglund479c9252010-09-10 22:03:36 +020034//////////////////////////////////////////////////////////////////////////
35////// GLFW internal API //////
36//////////////////////////////////////////////////////////////////////////
Camilla Berglund3249f812010-09-07 17:34:51 +020037
38//========================================================================
Camilla Berglund1baf2332010-09-07 17:50:43 +020039// Initialise timer
Camilla Berglund3249f812010-09-07 17:34:51 +020040//========================================================================
41
Camilla Berglund479c9252010-09-10 22:03:36 +020042void _glfwInitTimer(void)
Camilla Berglund3249f812010-09-07 17:34:51 +020043{
44 __int64 freq;
45
Camilla Berglund479c9252010-09-10 22:03:36 +020046 if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq))
Camilla Berglund3249f812010-09-07 17:34:51 +020047 {
Camilla Berglund52c27112012-09-02 15:21:40 +020048 _glfwLibrary.Win32.timer.hasPC = GL_TRUE;
Camilla Berglund3f40c462010-09-14 04:35:36 +020049 _glfwLibrary.Win32.timer.resolution = 1.0 / (double) freq;
Camilla Berglund90df26a2010-09-12 16:26:00 +020050 QueryPerformanceCounter((LARGE_INTEGER*) &_glfwLibrary.Win32.timer.t0_64);
Camilla Berglund3249f812010-09-07 17:34:51 +020051 }
52 else
53 {
Camilla Berglund52c27112012-09-02 15:21:40 +020054 _glfwLibrary.Win32.timer.hasPC = GL_FALSE;
Camilla Berglund671b0f72011-03-30 15:07:44 +020055 _glfwLibrary.Win32.timer.resolution = 0.001; // winmm resolution is 1 ms
Camilla Berglund90df26a2010-09-12 16:26:00 +020056 _glfwLibrary.Win32.timer.t0_32 = _glfw_timeGetTime();
Camilla Berglund3249f812010-09-07 17:34:51 +020057 }
58}
59
60
Camilla Berglund479c9252010-09-10 22:03:36 +020061//////////////////////////////////////////////////////////////////////////
62////// GLFW platform API //////
63//////////////////////////////////////////////////////////////////////////
Camilla Berglund3249f812010-09-07 17:34:51 +020064
65//========================================================================
66// Return timer value in seconds
67//========================================================================
68
Camilla Berglund479c9252010-09-10 22:03:36 +020069double _glfwPlatformGetTime(void)
Camilla Berglund3249f812010-09-07 17:34:51 +020070{
Camilla Berglund479c9252010-09-10 22:03:36 +020071 double t;
Camilla Berglund3249f812010-09-07 17:34:51 +020072 __int64 t_64;
73
Camilla Berglund52c27112012-09-02 15:21:40 +020074 if (_glfwLibrary.Win32.timer.hasPC)
Camilla Berglund3249f812010-09-07 17:34:51 +020075 {
Camilla Berglund479c9252010-09-10 22:03:36 +020076 QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
Camilla Berglund90df26a2010-09-12 16:26:00 +020077 t = (double)(t_64 - _glfwLibrary.Win32.timer.t0_64);
Camilla Berglund3249f812010-09-07 17:34:51 +020078 }
79 else
Camilla Berglund90df26a2010-09-12 16:26:00 +020080 t = (double)(_glfw_timeGetTime() - _glfwLibrary.Win32.timer.t0_32);
Camilla Berglund3249f812010-09-07 17:34:51 +020081
Camilla Berglund3f40c462010-09-14 04:35:36 +020082 return t * _glfwLibrary.Win32.timer.resolution;
Camilla Berglund3249f812010-09-07 17:34:51 +020083}
84
85
86//========================================================================
87// Set timer value in seconds
88//========================================================================
89
Camilla Berglund479c9252010-09-10 22:03:36 +020090void _glfwPlatformSetTime(double t)
Camilla Berglund3249f812010-09-07 17:34:51 +020091{
92 __int64 t_64;
93
Camilla Berglund52c27112012-09-02 15:21:40 +020094 if (_glfwLibrary.Win32.timer.hasPC)
Camilla Berglund3249f812010-09-07 17:34:51 +020095 {
Camilla Berglund479c9252010-09-10 22:03:36 +020096 QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
Camilla Berglund3f40c462010-09-14 04:35:36 +020097 _glfwLibrary.Win32.timer.t0_64 = t_64 - (__int64) (t / _glfwLibrary.Win32.timer.resolution);
Camilla Berglund3249f812010-09-07 17:34:51 +020098 }
99 else
Camilla Berglund90df26a2010-09-12 16:26:00 +0200100 _glfwLibrary.Win32.timer.t0_32 = _glfw_timeGetTime() - (int)(t * 1000.0);
Camilla Berglund3249f812010-09-07 17:34:51 +0200101}
102