From 785774deb261512b69789682078c31c35f508baa Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 30 May 2003 15:30:16 +0000 Subject: [PATCH] applied Ian's misc patches --- progs/demos/multiarb.c | 55 +++++++++++++------ progs/tests/stencilwrap.c | 57 ++++++++++++++++---- progs/tests/texwrap.c | 6 +-- progs/xdemos/glxgears.c | 109 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 193 insertions(+), 34 deletions(-) diff --git a/progs/demos/multiarb.c b/progs/demos/multiarb.c index c4671b516c4..239efac6633 100644 --- a/progs/demos/multiarb.c +++ b/progs/demos/multiarb.c @@ -1,4 +1,4 @@ -/* $Id: multiarb.c,v 1.11 2002/02/13 02:23:33 brianp Exp $ */ +/* $Id: multiarb.c,v 1.12 2003/05/30 15:30:17 brianp Exp $ */ /* * GL_ARB_multitexture demo @@ -33,6 +33,7 @@ static GLint NumUnits = 1; static GLboolean TexEnabled[8]; static GLfloat Drift = 0.0; +static GLfloat drift_increment = 0.005; static GLfloat Xrot = 20.0, Yrot = 30.0, Zrot = 0.0; @@ -42,7 +43,7 @@ static void Idle( void ) if (Animate) { GLint i; - Drift += 0.05; + Drift += drift_increment; if (Drift >= 1.0) Drift = 0.0; @@ -74,6 +75,9 @@ static void Idle( void ) static void DrawObject(void) { GLint i; + GLint j; + static const GLfloat tex_coords[] = { 0.0, 0.0, 1.0, 1.0, 0.0 }; + static const GLfloat vtx_coords[] = { -1.0, -1.0, 1.0, 1.0, -1.0 }; if (!TexEnabled[0] && !TexEnabled[1]) glColor3f(0.1, 0.1, 0.1); /* add onto this */ @@ -82,21 +86,24 @@ static void DrawObject(void) glBegin(GL_QUADS); - for (i = 0; i < NumUnits; i++) - glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i, 0.0, 0.0); - glVertex2f(-1.0, -1.0); - - for (i = 0; i < NumUnits; i++) - glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i, 1.0, 0.0); - glVertex2f(1.0, -1.0); - - for (i = 0; i < NumUnits; i++) - glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i, 1.0, 1.0); - glVertex2f(1.0, 1.0); - - for (i = 0; i < NumUnits; i++) - glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i, 0.0, 1.0); - glVertex2f(-1.0, 1.0); + /* Toggle between the vector and scalar entry points. This is done purely + * to hit multiple paths in the driver. + */ + if ( Drift > 0.49 ) { + for (j = 0; j < 4; j++ ) { + for (i = 0; i < NumUnits; i++) + glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i, + tex_coords[j], tex_coords[j+1]); + glVertex2f( vtx_coords[j], vtx_coords[j+1] ); + } + } + else { + for (j = 0; j < 4; j++ ) { + for (i = 0; i < NumUnits; i++) + glMultiTexCoord2fvARB(GL_TEXTURE0_ARB + i, & tex_coords[j]); + glVertex2fv( & vtx_coords[j] ); + } + } glEnd(); } @@ -105,6 +112,10 @@ static void DrawObject(void) static void Display( void ) { + static GLint T0 = 0; + static GLint Frames = 0; + GLint t; + glClear( GL_COLOR_BUFFER_BIT ); glPushMatrix(); @@ -116,6 +127,16 @@ static void Display( void ) glPopMatrix(); glutSwapBuffers(); + + Frames++; + + t = glutGet(GLUT_ELAPSED_TIME); + if (t - T0 >= 250) { + GLfloat seconds = (t - T0) / 1000.0; + drift_increment = 2.2 * seconds / Frames; + T0 = t; + Frames = 0; + } } diff --git a/progs/tests/stencilwrap.c b/progs/tests/stencilwrap.c index e65258b583a..da875412ada 100644 --- a/progs/tests/stencilwrap.c +++ b/progs/tests/stencilwrap.c @@ -16,6 +16,7 @@ static void RunTest(void) const GLenum prim = GL_LINES; GLubyte val; int bits, max, i; + GLboolean failed; glGetIntegerv(GL_STENCIL_BITS, &bits); max = (1 << bits) - 1; @@ -27,20 +28,29 @@ static void RunTest(void) /* test GL_INCR (saturation) */ glClear(GL_STENCIL_BUFFER_BIT); glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); + failed = GL_FALSE; printf("Testing GL_INCR...\n"); for (i = 1; i < max+10; i++) { int expected = (i > max) ? max : i; glBegin(prim); glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5); glEnd(); + glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val); - assert(val == expected); + if (val != expected) { + printf( "Failed GL_INCR test on iteration #%u " + "(got %u, expected %u)\n", i, val, expected ); + failed = GL_TRUE; + } } - printf("OK!\n"); + + if ( !failed ) printf("OK!\n"); + /* test GL_INCR_WRAP_EXT (wrap around) */ glClear(GL_STENCIL_BUFFER_BIT); glStencilOp(GL_KEEP, GL_KEEP, GL_INCR_WRAP_EXT); + failed = GL_FALSE; printf("Testing GL_INCR_WRAP_EXT...\n"); for (i = 1; i < max+10; i++) { int expected = i % (max + 1); @@ -48,15 +58,20 @@ static void RunTest(void) glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5); glEnd(); glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val); - assert(val == expected); + if (val != expected) { + printf( "Failed GL_INCR_WRAP test on iteration #%u " + "(got %u, expected %u)\n", i, val, expected ); + failed = GL_TRUE; + } } - printf("OK!\n"); + if ( !failed ) printf("OK!\n"); glClearStencil(max); /* test GL_INCR (saturation) */ glClear(GL_STENCIL_BUFFER_BIT); glStencilOp(GL_KEEP, GL_KEEP, GL_DECR); + failed = GL_FALSE; printf("Testing GL_DECR...\n"); for (i = max-1; i > -10; i--) { int expected = (i < 0) ? 0 : i; @@ -64,13 +79,18 @@ static void RunTest(void) glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5); glEnd(); glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val); - assert(val == expected); + if (val != expected) { + printf( "Failed GL_DECR test on iteration #%u " + "(got %u, expected %u)\n", max - i, val, expected ); + failed = GL_TRUE; + } } - printf("OK!\n"); + if ( !failed ) printf("OK!\n"); /* test GL_INCR_WRAP_EXT (wrap-around) */ glClear(GL_STENCIL_BUFFER_BIT); glStencilOp(GL_KEEP, GL_KEEP, GL_DECR_WRAP_EXT); + failed = GL_FALSE; printf("Testing GL_DECR_WRAP_EXT...\n"); for (i = max-1; i > -10; i--) { int expected = (i < 0) ? max + i + 1: i; @@ -78,9 +98,13 @@ static void RunTest(void) glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5); glEnd(); glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &val); - assert(val == expected); + if (val != expected) { + printf( "Failed GL_DECR_WRAP test on iteration #%u " + "(got %u, expected %u)\n", max - i, val, expected ); + failed = GL_TRUE; + } } - printf("OK!\n"); + if ( !failed ) printf("OK!\n"); glDisable(GL_STENCIL_TEST); } @@ -122,9 +146,24 @@ static void Key( unsigned char key, int x, int y ) static void Init( void ) { + const char * ver_str; + float version; + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); - if (!glutExtensionSupported("GL_EXT_stencil_wrap")) { + + + /* Check for both the extension string and GL version 1.4 on the + * outside chance that some silly vendor exports version 1.4 but doesn't + * export the extension string. The stencil-wrap modes are a required + * part of GL 1.4. + */ + + ver_str = glGetString( GL_VERSION ); + version = (ver_str == NULL) ? 1.0 : strtof( ver_str, NULL ); + + if ( !glutExtensionSupported("GL_EXT_stencil_wrap") + && (version < 1.4) ) { printf("Sorry, GL_EXT_stencil_wrap not supported.\n"); exit(1); } diff --git a/progs/tests/texwrap.c b/progs/tests/texwrap.c index 7751afd46b1..2602f3210de 100644 --- a/progs/tests/texwrap.c +++ b/progs/tests/texwrap.c @@ -1,4 +1,4 @@ -/* $Id: texwrap.c,v 1.5 2003/02/04 02:35:00 brianp Exp $ */ +/* $Id: texwrap.c,v 1.6 2003/05/30 15:30:17 brianp Exp $ */ /* * Test texture wrap modes. @@ -35,7 +35,7 @@ #define SIZE 8 static GLubyte BorderImage[SIZE+2][SIZE+2][4]; static GLubyte NoBorderImage[SIZE][SIZE][4]; -static GLuint Border = 1; +static GLuint Border = 0; #define WRAP_MODE(m) { m , # m, GL_TRUE, 1.0, { NULL, NULL } } @@ -142,7 +142,7 @@ static void Display( void ) /* loop over border modes */ for (j = 0; j < modes[j].mode != 0; j++) { const GLfloat x0 = 0, y0 = 0, x1 = 140, y1 = 140; - const GLfloat b = 0.2; + const GLfloat b = 1.2; const GLfloat s0 = -b, t0 = -b, s1 = 1.0+b, t1 = 1.0+b; if ( modes[j].supported != GL_TRUE ) diff --git a/progs/xdemos/glxgears.c b/progs/xdemos/glxgears.c index 8475cab07af..f6acd99f6bf 100644 --- a/progs/xdemos/glxgears.c +++ b/progs/xdemos/glxgears.c @@ -58,8 +58,15 @@ typedef GLint ( * PFNGLXGETSWAPINTERVALMESAPROC) ( void ); typedef Bool ( * PFNGLXGETMSCRATEOMLPROC) (Display *dpy, GLXDrawable drawable, int32_t *numerator, int32_t *denominator); #endif +#ifndef GLX_MESA_swap_frame_usage +#define GLX_MESA_swap_frame_usage 1 +typedef int ( * PFNGLXGETFRAMEUSAGEMESAPROC) (Display *dpy, GLXDrawable drawable, float * usage ); +#endif + #define BENCHMARK +PFNGLXGETFRAMEUSAGEMESAPROC get_frame_usage = NULL; + #ifdef BENCHMARK /* XXX this probably isn't very portable */ @@ -108,10 +115,14 @@ static GLfloat angle = 0.0; static GLboolean has_OML_sync_control = GL_FALSE; static GLboolean has_SGI_swap_control = GL_FALSE; static GLboolean has_MESA_swap_control = GL_FALSE; +static GLboolean has_MESA_swap_frame_usage = GL_FALSE; static char ** extension_table = NULL; static unsigned num_extensions; +static GLboolean use_ztrick = GL_FALSE; +static GLfloat aspect; + /* * * Draw a gear wheel. You'll probably want to call this function when @@ -139,6 +150,7 @@ gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, da = 2.0 * M_PI / teeth / 4.0; glShadeModel(GL_FLAT); + glPolygonMode( GL_FRONT, GL_LINE ); glNormal3f(0.0, 0.0, 1.0); @@ -254,7 +266,65 @@ gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, static void draw(void) { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + if ( use_ztrick ) { + static GLboolean flip = GL_FALSE; + static const GLfloat vert[4][3] = { + { -1, -1, -0.999 }, + { 1, -1, -0.999 }, + { 1, 1, -0.999 }, + { -1, 1, -0.999 } + }; + static const GLfloat col[4][3] = { + { 1.0, 0.6, 0.0 }, + { 1.0, 0.6, 0.0 }, + { 0.0, 0.0, 0.0 }, + { 0.0, 0.0, 0.0 }, + }; + + if ( flip ) { + glDepthRange(0, 0.5); + glDepthFunc(GL_LEQUAL); + } + else { + glDepthRange(1.0, 0.4999); + glDepthFunc(GL_GEQUAL); + } + + flip = !flip; + + /* The famous Quake "Z trick" only works when the whole screen is + * re-drawn each frame. + */ + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1, 1, -1, 1, -1, 1); + glDisable(GL_LIGHTING); + glShadeModel(GL_SMOOTH); + + glEnable( GL_VERTEX_ARRAY ); + glEnable( GL_COLOR_ARRAY ); + glVertexPointer( 3, GL_FLOAT, 0, vert ); + glColorPointer( 3, GL_FLOAT, 0, col ); + glDrawArrays( GL_POLYGON, 0, 4 ); + glDisable( GL_COLOR_ARRAY ); + glDisable( GL_VERTEX_ARRAY ); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -aspect, aspect, 5.0, 60.0); + + glEnable(GL_LIGHTING); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); + } + else { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } glPushMatrix(); glRotatef(view_rotx, 1.0, 0.0, 0.0); @@ -287,12 +357,14 @@ draw(void) static void reshape(int width, int height) { - GLfloat h = (GLfloat) height / (GLfloat) width; + aspect = (GLfloat) height / (GLfloat) width; + glViewport(0, 0, (GLint) width, (GLint) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); + + glFrustum(-1.0, 1.0, -aspect, aspect, 5.0, 60.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -40.0); @@ -409,6 +481,8 @@ make_window( Display *dpy, const char *name, static void event_loop(Display *dpy, Window win) { + float frame_usage = 0.0; + while (1) { while (XPending(dpy) > 0) { XEvent event; @@ -453,6 +527,13 @@ event_loop(Display *dpy, Window win) angle += 2.0; draw(); + if ( get_frame_usage != NULL ) { + GLfloat temp; + + (*get_frame_usage)( dpy, win, & temp ); + frame_usage += temp; + } + glXSwapBuffers(dpy, win); /* calc framerate */ @@ -469,10 +550,19 @@ event_loop(Display *dpy, Window win) if (t - t0 >= 5.0) { GLfloat seconds = t - t0; GLfloat fps = frames / seconds; - printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, - fps); + if ( get_frame_usage != NULL ) { + printf("%d frames in %3.1f seconds = %6.3f FPS (%3.1f%% usage)\n", + frames, seconds, fps, + (frame_usage * 100.0) / (float) frames ); + } + else { + printf("%d frames in %3.1f seconds = %6.3f FPS\n", + frames, seconds, fps); + } + t0 = t; frames = 0; + frame_usage = 0.0; } } } @@ -642,6 +732,9 @@ main(int argc, char *argv[]) */ force_get_rate = GL_TRUE; } + else if (strcmp(argv[i], "-ztrick") == 0) { + use_ztrick = GL_TRUE; + } else if (strcmp(argv[i], "-help") == 0) { printf("Usage:\n"); printf(" gears [options]\n"); @@ -669,6 +762,7 @@ main(int argc, char *argv[]) has_OML_sync_control = is_extension_supported( "GLX_OML_sync_control" ); has_SGI_swap_control = is_extension_supported( "GLX_SGI_swap_control" ); has_MESA_swap_control = is_extension_supported( "GLX_MESA_swap_control" ); + has_MESA_swap_frame_usage = is_extension_supported( "GLX_MESA_swap_frame_usage" ); if ( has_MESA_swap_control ) { set_swap_interval = (PFNGLXSWAPINTERVALMESAPROC) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalMESA" ); @@ -679,6 +773,11 @@ main(int argc, char *argv[]) } + if ( has_MESA_swap_frame_usage ) { + get_frame_usage = (PFNGLXGETFRAMEUSAGEMESAPROC) glXGetProcAddressARB( (const GLubyte *) "glXGetFrameUsageMESA" ); + } + + if (printInfo) { printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); -- 2.30.2