Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Hacker <dd0t@users.sourceforge.net>2010-04-28 22:22:28 +0400
committerStefan Hacker <dd0t@users.sourceforge.net>2010-04-28 22:22:28 +0400
commitd8f1ac1115ad341b9bc20cb79e3406dd5e099028 (patch)
treeb556c8a3afd1dd876053e7e0f7e78a3803d7c1e7 /overlay_gl
parentfbb54cb9632041b9e1e64472c719f8d29fc336ec (diff)
Add an optional FPS counter to the overlay
Diffstat (limited to 'overlay_gl')
-rw-r--r--overlay_gl/overlay.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/overlay_gl/overlay.c b/overlay_gl/overlay.c
index 82bec052b..32ea35adc 100644
--- a/overlay_gl/overlay.c
+++ b/overlay_gl/overlay.c
@@ -53,6 +53,7 @@
#include <pwd.h>
#include <math.h>
#include <errno.h>
+#include <time.h>
typedef unsigned char bool;
#define true 1
@@ -85,6 +86,9 @@ typedef struct _Context {
bool bGlx;
GLuint uiProgram;
+
+ clock_t timeT;
+ unsigned int frameCount;
} Context;
static const char vshader[] = ""
@@ -149,6 +153,8 @@ static void newContext(Context * ctx) {
ctx->iSocket = -1;
ctx->omMsg.omh.iLength = -1;
ctx->texture = ~0;
+ ctx->timeT = clock();
+ ctx->frameCount = 0;
char *home = getenv("HOME");
if (home == NULL) {
@@ -566,6 +572,22 @@ void glXSwapBuffers(Display * dpy, GLXDrawable draw) {
if (!c) {
ods("Current context is: %p", ctx);
+ clock_t t = clock();
+ float elapsed = static_cast<float>(t - ctx->timeT) / CLOCKS_PER_SEC;
+ ++(ctx->frameCount);
+ if (elapsed > 1.0) { // Send FPS update every second
+ OverlayMsg om;
+ om.omh.uiMagic = OVERLAY_MAGIC_NUMBER;
+ om.omh.uiType = OVERLAY_MSGTYPE_FPS;
+ om.omh.iLength = sizeof(OverlayMsgFps);
+ om.omf.fps = static_cast<unsigned int>(ctx->frameCount * elapsed);
+
+ sendMessage(om);
+
+ ctx->frameCount = 0;
+ ctx->timeT = t;
+ }
+
c = (Context *) malloc(sizeof(Context));
if (!c) {
ods("malloc failure");