aboutsummaryrefslogtreecommitdiffstats
path: root/pugl
diff options
context:
space:
mode:
Diffstat (limited to 'pugl')
-rw-r--r--pugl/pugl.h10
-rw-r--r--pugl/pugl_osx.m9
-rw-r--r--pugl/pugl_win.cpp13
-rw-r--r--pugl/pugl_x11.c10
4 files changed, 42 insertions, 0 deletions
diff --git a/pugl/pugl.h b/pugl/pugl.h
index 01b7f01..c8e62d4 100644
--- a/pugl/pugl.h
+++ b/pugl/pugl.h
@@ -635,6 +635,16 @@ PUGL_API PuglGlFunc
puglGetProcAddress(const char* name);
/**
+ Return the time in seconds.
+
+ This is a monotonically increasing clock with high resolution. The returned
+ time is only useful to compare against other times returned by this
+ function, its absolute value has no meaning.
+*/
+PUGL_API double
+puglGetTime(PuglView* view);
+
+/**
Request a redisplay on the next call to puglProcessEvents().
*/
PUGL_API void
diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m
index 02bf46a..1503034 100644
--- a/pugl/pugl_osx.m
+++ b/pugl/pugl_osx.m
@@ -27,6 +27,7 @@
#import <Cocoa/Cocoa.h>
#include <stdlib.h>
+#include <time.h>
#undef PUGL_HAVE_CAIRO
@@ -726,6 +727,14 @@ puglGetProcAddress(const char *name)
return func;
}
+double
+puglGetTime(PuglView* view)
+{
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return (double)ts.tv_sec + ts.tv_nsec / 1000000000.0;
+}
+
void
puglPostRedisplay(PuglView* view)
{
diff --git a/pugl/pugl_win.cpp b/pugl/pugl_win.cpp
index 6185c91..2ae832b 100644
--- a/pugl/pugl_win.cpp
+++ b/pugl/pugl_win.cpp
@@ -55,6 +55,7 @@ struct PuglInternalsImpl {
HDC hdc;
HGLRC hglrc;
WNDCLASS wc;
+ double timerFrequency;
};
LRESULT CALLBACK
@@ -99,6 +100,10 @@ puglCreateWindow(PuglView* view, const char* title)
PuglInternals* impl = view->impl;
+ LARGE_INTEGER frequency;
+ QueryPerformanceFrequency(&frequency);
+ impl->timerFrequency = frequency.QuadPart;
+
if (!title) {
title = "Window";
}
@@ -619,6 +624,14 @@ puglGetProcAddress(const char* name)
return (PuglGlFunc)wglGetProcAddress(name);
}
+double
+puglGetTime(PuglView* view)
+{
+ LARGE_INTEGER count;
+ QueryPerformanceCounter(&count);
+ return double(count.QuadPart) / view->impl->timerFrequency;
+}
+
void
puglPostRedisplay(PuglView* view)
{
diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c
index 6563805..2fd6e92 100644
--- a/pugl/pugl_x11.c
+++ b/pugl/pugl_x11.c
@@ -20,6 +20,7 @@
@file pugl_x11.c X11 Pugl Implementation.
*/
+#define _POSIX_C_SOURCE 199309L
#include "pugl/pugl_internal.h"
#include "pugl/pugl_x11.h"
@@ -38,6 +39,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#ifndef MIN
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
@@ -516,6 +518,14 @@ puglProcessEvents(PuglView* view)
return PUGL_SUCCESS;
}
+double
+puglGetTime(PuglView* view)
+{
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return (double)ts.tv_sec + ts.tv_nsec / 1000000000.0;
+}
+
void
puglPostRedisplay(PuglView* view)
{