From 5ebfbb5e97ab30d2aacd68087f16dddf8335a467 Mon Sep 17 00:00:00 2001 From: brianp Date: Tue, 17 Jun 2003 16:55:22 +0000 Subject: [PATCH] added GLUT_FPS env var option git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@66 7f0cb862-5218-0410-a997-914c9d46530a --- .../freeglut/freeglut-1.3/freeglut_display.c | 16 +++++++ .../freeglut/freeglut-1.3/freeglut_init.c | 46 +++++++++++++++++-- .../freeglut/freeglut-1.3/freeglut_internal.h | 4 ++ 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/freeglut/freeglut/freeglut-1.3/freeglut_display.c b/freeglut/freeglut/freeglut-1.3/freeglut_display.c index 900b9d0..d6ce1cb 100644 --- a/freeglut/freeglut/freeglut-1.3/freeglut_display.c +++ b/freeglut/freeglut/freeglut-1.3/freeglut_display.c @@ -92,6 +92,22 @@ void FGAPIENTRY glutSwapBuffers( void ) SwapBuffers( fgStructure.Window->Window.Device ); #endif + + /* GLUT_FPS env var support */ + if (fgState.FPSInterval) { + GLint t = glutGet(GLUT_ELAPSED_TIME); + fgState.SwapCount++; + if (fgState.SwapTime == 0) + fgState.SwapTime = t; + else if (t - fgState.SwapTime > fgState.FPSInterval) { + float time = 0.001 * (t - fgState.SwapTime); + float fps = (float) fgState.SwapCount / time; + fprintf(stderr, "FreeGLUT: %d frames in %.2f seconds = %.2f FPS\n", + fgState.SwapCount, time, fps); + fgState.SwapTime = t; + fgState.SwapCount = 0; + } + } } /* diff --git a/freeglut/freeglut/freeglut-1.3/freeglut_init.c b/freeglut/freeglut/freeglut-1.3/freeglut_init.c index 40cc2a2..a03a114 100644 --- a/freeglut/freeglut/freeglut-1.3/freeglut_init.c +++ b/freeglut/freeglut/freeglut-1.3/freeglut_init.c @@ -55,14 +55,33 @@ SFG_Display fgDisplay; /* * The settings for the current freeglut session */ -SFG_State fgState = { { -1, -1, FALSE }, { 300, 300, TRUE }, GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH, - FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, +SFG_State fgState = { { -1, -1, FALSE }, /* Position */ + { 300, 300, TRUE }, /* Size */ + GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH, /* DisplayMode */ + FALSE, /* ForceDirectContext */ + TRUE, /* TryDirectContext */ + FALSE, /* ForceIconic */ + FALSE, /* GLDebugSwitch */ + FALSE, /* XSyncSwitch */ + TRUE, /* IgnoreKeyRepeat */ + 0, /* FPSInterval */ + 0, /* SwapCount */ + 0, /* SwapTime */ #ifdef TARGET_HOST_WIN32 - { 0, FALSE }, + { 0, FALSE }, /* Time */ #else { { 0, 0 }, FALSE }, #endif - { NULL, NULL }, NULL, NULL, NULL, { 640, 480, TRUE }, 16, 72, GLUT_ACTION_EXIT, GLUT_EXEC_STATE_INIT } ; + { NULL, NULL }, /* Timers */ + NULL, /* IdleCallback */ + NULL, /* MenuStateCallback */ + NULL, /* MenuStatusCallback */ + { 640, 480, TRUE }, /* GameModeSize */ + 16, /* GameModeDepth */ + 72, /* GameModeRefresh */ + GLUT_ACTION_EXIT, /* ActionOnWindowClose */ + GLUT_EXEC_STATE_INIT /* ExecState */ +}; /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */ @@ -312,6 +331,14 @@ void fgDeinitialize( void ) fgState.MenuStateCallback = (FGCBmenuState)NULL ; fgState.MenuStatusCallback = (FGCBmenuStatus)NULL ; + /* + * FPS display + */ + fgState.SwapCount = 0; + fgState.SwapTime = 0; + fgState.FPSInterval = 0; + + #if TARGET_HOST_UNIX_X11 /* @@ -365,6 +392,17 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) #endif fgState.Time.Set = TRUE; + + /* check if GLUT_FPS env var is set */ + { + const char *fps = getenv("GLUT_FPS"); + if (fps) { + sscanf(fps, "%d", &fgState.FPSInterval); + if (fgState.FPSInterval <= 0) + fgState.FPSInterval = 5000; /* 5000 milliseconds */ + } + } + /* * Grab the environment variable indicating the X display to use. * This is harmless under Win32, so let's let it stay here... diff --git a/freeglut/freeglut/freeglut-1.3/freeglut_internal.h b/freeglut/freeglut/freeglut-1.3/freeglut_internal.h index bb93080..d8d50d8 100644 --- a/freeglut/freeglut/freeglut-1.3/freeglut_internal.h +++ b/freeglut/freeglut/freeglut-1.3/freeglut_internal.h @@ -220,6 +220,10 @@ struct tagSFG_State GLboolean IgnoreKeyRepeat; /* Whether to ignore key repeat... */ + GLuint FPSInterval; /* Interval between FPS printfs */ + GLuint SwapCount; /* Count of glutSwapBuffer calls */ + GLuint SwapTime; /* Time of last SwapBuffers */ + SFG_Time Time; /* The time that glutInit was called */ SFG_List Timers; /* The freeglut timer hooks */