From 5759f53934d3f70dd3968fd747cf5bcb92563f21 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 11 May 2001 12:08:15 +0000 Subject: made render path selection more flexible --- progs/demos/isosurf.c | 414 ++++++++++++++++++++++++++++---------------------- 1 file changed, 233 insertions(+), 181 deletions(-) (limited to 'progs/demos') diff --git a/progs/demos/isosurf.c b/progs/demos/isosurf.c index a9d5128c54a..47e654f59a3 100644 --- a/progs/demos/isosurf.c +++ b/progs/demos/isosurf.c @@ -1,4 +1,4 @@ -/* $Id: isosurf.c,v 1.9 2001/04/19 13:12:40 keithw Exp $ */ +/* $Id: isosurf.c,v 1.10 2001/05/11 12:08:15 keithw Exp $ */ /* * Display an isosurface of 3-D wind speed volume. @@ -38,17 +38,17 @@ #define LIT 0x1 #define UNLIT 0x2 -#define TEXTURE 0x4 -#define NO_TEXTURE 0x8 #define REFLECT 0x10 -#define NO_REFLECT 0x20 #define POINT_FILTER 0x40 #define LINEAR_FILTER 0x80 #define GLVERTEX 0x100 -#define DRAW_ARRAYS 0x200 /* or draw_elts, if compiled */ +#define DRAW_ELTS 0x4 +#define DRAW_ARRAYS 0x200 #define ARRAY_ELT 0x400 -#define COMPILED 0x800 +#define LOCKED 0x800 +#define UNLOCKED 0x8 #define IMMEDIATE 0x1000 +#define DISPLAYLIST 0x2000000 #define SHADE_SMOOTH 0x2000 #define SHADE_FLAT 0x4000 #define TRIANGLES 0x8000 @@ -61,17 +61,15 @@ #define FOG 0x400000 #define NO_FOG 0x800000 #define QUIT 0x1000000 -#define DISPLAYLIST 0x2000000 #define GLINFO 0x4000000 #define STIPPLE 0x8000000 -#define NO_STIPPLE 0x10000000 +#define NO_STIPPLE 0x20 -#define LIGHT_MASK (LIT|UNLIT) -#define TEXTURE_MASK (TEXTURE|NO_TEXTURE) -#define REFLECT_MASK (REFLECT|NO_REFLECT) +#define LIGHT_MASK (LIT|UNLIT|REFLECT) #define FILTER_MASK (POINT_FILTER|LINEAR_FILTER) -#define RENDER_STYLE_MASK (GLVERTEX|DRAW_ARRAYS|ARRAY_ELT) -#define COMPILED_MASK (COMPILED|IMMEDIATE|DISPLAYLIST) +#define RENDER_STYLE_MASK (GLVERTEX|DRAW_ARRAYS|DRAW_ELTS|ARRAY_ELT) +#define DLIST_MASK (IMMEDIATE|DISPLAYLIST) +#define LOCK_MASK (LOCKED|UNLOCKED) #define MATERIAL_MASK (MATERIALS|NO_MATERIALS) #define PRIMITIVE_MASK (TRIANGLES|STRIPS|POINTS) #define CLIP_MASK (USER_CLIP|NO_USER_CLIP) @@ -83,6 +81,7 @@ static GLuint maxverts = MAXVERTS; static float data[MAXVERTS][6]; static float compressed_data[MAXVERTS][6]; +static float expanded_data[MAXVERTS*3][6]; static GLuint indices[MAXVERTS]; static GLuint tri_indices[MAXVERTS*3]; static GLfloat col[100][4]; @@ -90,11 +89,11 @@ static GLint numverts, num_tri_verts, numuniq; static GLfloat xrot; static GLfloat yrot; -static GLfloat dist = -6; +static GLfloat dist; static GLint state, allowed = ~0; static GLboolean doubleBuffer = GL_TRUE; -static GLdouble plane[4] = {1.0, 0.0, -1.0, 0.0}; -static GLuint surf1, surf2, surf3; +static GLdouble plane[4]; +static GLuint surf1, dlist_state; static GLboolean PrintInfo = GL_FALSE; @@ -112,11 +111,6 @@ static GLubyte halftone[] = { 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55}; -/* forward decl */ -int BuildVertexList( int mode ); -int BuildArrayEltList( int mode ); -int BuildDrawArraysList( int mode ); - static void read_surface( char *filename ) { @@ -143,6 +137,31 @@ static void read_surface( char *filename ) +static void print_flags( const char *msg, GLuint flags ) +{ + fprintf(stderr, + "%s (0x%x): %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", + msg, flags, + (flags & GLVERTEX) ? "glVertex, " : "", + (flags & DRAW_ARRAYS) ? "glDrawArrays, " : "", + (flags & DRAW_ELTS) ? "glDrawElements, " : "", + (flags & ARRAY_ELT) ? "glArrayElement, " : "", + (flags & LOCKED) ? "locked arrays, " : "", + (flags & TRIANGLES) ? "GL_TRIANGLES, " : "", + (flags & STRIPS) ? "GL_TRIANGLE_STRIP, " : "", + (flags & POINTS) ? "GL_POINTS, " : "", + (flags & DISPLAYLIST) ? "as a displaylist, " : "", + (flags & LIT) ? "lit, " : "", + (flags & UNLIT) ? "unlit, " : "", + (flags & REFLECT) ? "reflect, " : "", + (flags & SHADE_FLAT) ? "flat-shaded, " : "", + (flags & USER_CLIP) ? "user_clip, " : "", + (flags & MATERIALS) ? "materials, " : "", + (flags & FOG) ? "fog, " : "", + (flags & STIPPLE) ? "stipple, " : ""); +} + + struct data_idx { float *data; @@ -286,6 +305,20 @@ static void compactify_arrays(void) free( ind ); } +static void expand_arrays(void) +{ + int i; + int parity = 0; + for (i = 2 ; i < numverts ; i++, parity ^= 1) { + int v0 = i-2+parity; + int v1 = i-1-parity; + int v2 = i; + memcpy( expanded_data[(i-2)*3+0], data[v0], sizeof(data[0]) ); + memcpy( expanded_data[(i-2)*3+1], data[v1], sizeof(data[0]) ); + memcpy( expanded_data[(i-2)*3+2], data[v2], sizeof(data[0]) ); + } +} + static float myrand( float max ) { return max*rand()/(RAND_MAX+1.0); @@ -326,12 +359,33 @@ static void make_tri_indices( void ) static void draw_surface( int with_state ) { GLuint i, j; + + if (with_state & DISPLAYLIST) { + if ((with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK|MATERIAL_MASK)) != + dlist_state) { + /* + */ + fprintf(stderr, "rebuilding displaylist\n"); + + if (dlist_state) + glDeleteLists( surf1, 1 ); + + dlist_state = with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK| + MATERIAL_MASK); + surf1 = glGenLists(1); + glNewList(surf1, GL_COMPILE); + draw_surface( dlist_state ); + glEndList(); + } - switch (with_state & (COMPILED_MASK|RENDER_STYLE_MASK|PRIMITIVE_MASK)) { + glCallList( surf1 ); + return; + } + + switch (with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK)) { #ifdef GL_EXT_vertex_array - case (IMMEDIATE|DRAW_ARRAYS|TRIANGLES): - case (COMPILED|DRAW_ARRAYS|TRIANGLES): + case (DRAW_ELTS|TRIANGLES): if (with_state & MATERIALS) { for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) { GLuint nr = MIN(num_tri_verts-i, 600); @@ -345,8 +399,11 @@ static void draw_surface( int with_state ) } break; - case (IMMEDIATE|ARRAY_ELT|TRIANGLES): - case (COMPILED|ARRAY_ELT|TRIANGLES): + case (DRAW_ARRAYS|TRIANGLES): + glDrawArraysEXT( GL_TRIANGLES, 0, (numverts-2)*3 ); + break; + + case (ARRAY_ELT|TRIANGLES): if (with_state & MATERIALS) { for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) { GLuint nr = MIN(num_tri_verts-i, 600); @@ -370,48 +427,29 @@ static void draw_surface( int with_state ) /* Uses the original arrays (including duplicate elements): */ - case (IMMEDIATE|DRAW_ARRAYS|STRIPS): + case (DRAW_ARRAYS|STRIPS): glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts ); break; - case (COMPILED|DRAW_ARRAYS|STRIPS): + case (DRAW_ELTS|STRIPS): glDrawElements( GL_TRIANGLE_STRIP, numverts, GL_UNSIGNED_INT, indices ); break; /* Uses the original arrays (including duplicate elements): */ - case (IMMEDIATE|ARRAY_ELT|STRIPS): + case (ARRAY_ELT|STRIPS): glBegin( GL_TRIANGLE_STRIP ); for (i = 0 ; i < numverts ; i++) glArrayElement( i ); glEnd(); break; - case (COMPILED|ARRAY_ELT|STRIPS): - glBegin( GL_TRIANGLE_STRIP ); - for (i = 0 ; i < numverts ; i++) - glArrayElement( indices[i] ); - glEnd(); - break; - - case (DISPLAYLIST|GLVERTEX|STRIPS): - glCallList(surf1); - break; - case (DISPLAYLIST|ARRAY_ELT|STRIPS): - glCallList(surf2); - break; - case (DISPLAYLIST|DRAW_ARRAYS|STRIPS): - glCallList(surf3); - break; - - - case (IMMEDIATE|DRAW_ARRAYS|POINTS): + case (DRAW_ARRAYS|POINTS): glDrawArraysEXT( GL_POINTS, 0, numverts ); break; - case (COMPILED|DRAW_ARRAYS|POINTS): + case (DRAW_ELTS|POINTS): glDrawElements( GL_POINTS, numverts, GL_UNSIGNED_INT, indices ); break; - case (IMMEDIATE|ARRAY_ELT|POINTS): - case (COMPILED|ARRAY_ELT|POINTS): + case (ARRAY_ELT|POINTS): glBegin( GL_POINTS ); for (i = 0 ; i < numverts ; i++) glArrayElement( indices[i] ); @@ -419,7 +457,7 @@ static void draw_surface( int with_state ) break; #endif - case (IMMEDIATE|GLVERTEX|TRIANGLES): + case (GLVERTEX|TRIANGLES): if (with_state & MATERIALS) { for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) { GLuint nr = MIN(num_tri_verts-i, 600); @@ -443,7 +481,7 @@ static void draw_surface( int with_state ) } break; - case (IMMEDIATE|GLVERTEX|POINTS): + case (GLVERTEX|POINTS): glBegin( GL_POINTS ); for ( i = 0 ; i < numverts ; i++ ) { glNormal3fv( &data[i][3] ); @@ -452,15 +490,19 @@ static void draw_surface( int with_state ) glEnd(); break; - /* Uses the original arrays (including duplicate elements): - */ - default: + case (GLVERTEX|STRIPS): glBegin( GL_TRIANGLE_STRIP ); for (i=0;i