diff options
author | Brian Paul <[email protected]> | 2002-08-17 00:12:12 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2002-08-17 00:12:12 +0000 |
commit | 46a035f76d3b7a2355f7655c9dd7e519d4238cdc (patch) | |
tree | 79178916830b7f890b66fa5f78305c8305a28a41 /src | |
parent | 10730663a128c35c0241a79d885665e6272014d7 (diff) |
added glutGetProcAddress() and GLUT_FPS env var option
Diffstat (limited to 'src')
-rw-r--r-- | src/glut/glx/glut_ext.c | 15 | ||||
-rw-r--r-- | src/glut/glx/glut_init.c | 10 | ||||
-rw-r--r-- | src/glut/glx/glut_swap.c | 20 | ||||
-rw-r--r-- | src/glut/glx/glutint.h | 5 |
4 files changed, 50 insertions, 0 deletions
diff --git a/src/glut/glx/glut_ext.c b/src/glut/glx/glut_ext.c index abcb17a911b..ceea4ca15ab 100644 --- a/src/glut/glx/glut_ext.c +++ b/src/glut/glx/glut_ext.c @@ -50,4 +50,19 @@ glutExtensionSupported(const char *extension) return 0; } + +/* XXX This isn't an official GLUT function, yet */ +void * APIENTRY +glutGetProcAddress(const char *procName) +{ +#if defined(_WIN32) + return (void *) wglGetProcAddress((LPCSTR) procName); +#elif defined(GLX_ARB_get_proc_address) + return (void *) glXGetProcAddressARB((const GLubyte *) procName); +#else + return NULL; +#endif +} + + /* ENDCENTRY */ diff --git a/src/glut/glx/glut_init.c b/src/glut/glx/glut_init.c index dcd423a9417..d814479db0d 100644 --- a/src/glut/glx/glut_init.c +++ b/src/glut/glx/glut_init.c @@ -331,6 +331,16 @@ glutInit(int *argcp, char **argv) glutInitWindowPosition(__glutInitX, __glutInitY); } __glutInitTime(&unused); + + /* check if GLUT_FPS env var is set */ + { + const char *fps = getenv("GLUT_FPS"); + if (fps) { + sscanf(fps, "%d", &__glutFPS); + if (__glutFPS <= 0) + __glutFPS = 5000; /* 5000 milliseconds */ + } + } } #ifdef _WIN32 diff --git a/src/glut/glx/glut_swap.c b/src/glut/glx/glut_swap.c index 0864e58d429..cb3f653c72c 100644 --- a/src/glut/glx/glut_swap.c +++ b/src/glut/glx/glut_swap.c @@ -5,8 +5,13 @@ and is provided without guarantee or warrantee expressed or implied. This program is -not- in the public domain. */ +#include <stdio.h> #include "glutint.h" +GLint __glutFPS = 0; +GLint __glutSwapCount = 0; +GLint __glutSwapTime = 0; + /* CENTRY */ void APIENTRY glutSwapBuffers(void) @@ -43,5 +48,20 @@ glutSwapBuffers(void) glutPostRedisplay to trigger redraws. If glutPostRedisplay were used, __glutSetWindow would be called and a glFinish to throttle buffering would occur. */ + + if (__glutFPS) { + GLint t = glutGet(GLUT_ELAPSED_TIME); + __glutSwapCount++; + if (__glutSwapTime == 0) + __glutSwapTime = t; + else if (t - __glutSwapTime > __glutFPS) { + float time = 0.001 * (t - __glutSwapTime); + float fps = (float) __glutSwapCount / time; + fprintf(stderr, "GLUT: %d frames in %.2f seconds = %.2f FPS\n", + __glutSwapCount, time, fps); + __glutSwapTime = t; + __glutSwapCount = 0; + } + } } /* ENDCENTRY */ diff --git a/src/glut/glx/glutint.h b/src/glut/glx/glutint.h index b0d6c86b7c4..5e06bfc435e 100644 --- a/src/glut/glx/glutint.h +++ b/src/glut/glx/glutint.h @@ -798,6 +798,11 @@ extern void __glutDetermineMesaSwapHackSupport(void); /* private routines from glut_gameglut.c */ extern void GLUTAPIENTRYV __glutCloseDownGameMode(void); +/* private variables from glut_swap.c (BrianP) */ +extern GLint __glutFPS; +extern GLint __glutSwapCount; +extern GLint __glutSwapTime; + #if defined(_WIN32) /* private routines from win32_*.c */ extern LONG WINAPI __glutWindowProc(HWND win, UINT msg, WPARAM w, LPARAM l); |