diff options
author | Michal Krol <[email protected]> | 2010-03-10 15:49:30 +0100 |
---|---|---|
committer | Michal Krol <[email protected]> | 2010-03-10 15:49:30 +0100 |
commit | 3ce4375912c8ea488460e593e07c5bb15b92dca9 (patch) | |
tree | 1011fa439bd829fd46a44fd99478135848800e73 /progs/demos/arbocclude.c | |
parent | f59f28093ea827bd234d8e1a36bdd56a9fce5f09 (diff) | |
parent | 9b348d0ed125a22be3f318ac60cef6f201edfdab (diff) |
Merge branch 'master' into gallium-sampler-view
Conflicts:
src/gallium/auxiliary/Makefile
src/gallium/auxiliary/SConscript
src/gallium/auxiliary/tgsi/tgsi_exec.c
src/gallium/auxiliary/util/u_blitter.c
src/gallium/drivers/i915/i915_context.h
src/gallium/drivers/i965/brw_context.h
src/gallium/drivers/llvmpipe/lp_context.h
src/gallium/drivers/nv50/nv50_context.h
src/gallium/drivers/nv50/nv50_state_validate.c
src/gallium/drivers/nv50/nv50_tex.c
src/gallium/drivers/r300/r300_blit.c
src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_emit.c
src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/softpipe/sp_context.h
src/gallium/drivers/svga/svga_context.h
src/gallium/drivers/svga/svga_pipe_sampler.c
Diffstat (limited to 'progs/demos/arbocclude.c')
-rw-r--r-- | progs/demos/arbocclude.c | 213 |
1 files changed, 108 insertions, 105 deletions
diff --git a/progs/demos/arbocclude.c b/progs/demos/arbocclude.c index f669a1f26ba..cc787eeb8a7 100644 --- a/progs/demos/arbocclude.c +++ b/progs/demos/arbocclude.c @@ -32,11 +32,12 @@ #include <GL/glew.h> #include <GL/glut.h> -#define TEST_DISPLAY_LISTS 0 +#define NUM_OCC 10 static GLboolean Anim = GL_TRUE; -static GLfloat Xpos = 0; -static GLuint OccQuery; +static GLfloat Xpos[NUM_OCC], Ypos[NUM_OCC]; +static GLfloat Sign[NUM_OCC]; +static GLuint OccQuery[NUM_OCC]; static GLint Win = 0; @@ -54,38 +55,43 @@ PrintString(const char *s) static void Idle(void) { static int lastTime = 0; - static int sign = +1; int time = glutGet(GLUT_ELAPSED_TIME); float step; + int i; if (lastTime == 0) lastTime = time; else if (time - lastTime < 20) /* 50Hz update */ return; - step = (time - lastTime) / 1000.0 * sign; - lastTime = time; + for (i = 0; i < NUM_OCC; i++) { - Xpos += step; + step = (time - lastTime) / 1000.0 * Sign[i]; + + Xpos[i] += step; + + if (Xpos[i] > 2.5) { + Xpos[i] = 2.5; + Sign[i] = -1; + } + else if (Xpos[i] < -2.5) { + Xpos[i] = -2.5; + Sign[i] = +1; + } - if (Xpos > 2.5) { - Xpos = 2.5; - sign = -1; - } - else if (Xpos < -2.5) { - Xpos = -2.5; - sign = +1; } + + lastTime = time; + glutPostRedisplay(); } static void Display( void ) { - GLuint passed; - GLint ready; - char s[100]; + int i; + glClearColor(0.25, 0.25, 0.25, 0.0); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glMatrixMode( GL_PROJECTION ); @@ -96,97 +102,84 @@ static void Display( void ) glTranslatef( 0.0, 0.0, -15.0 ); /* draw the occluding polygons */ - glColor3f(0, 0.6, 0.8); + glColor3f(0, 0.4, 0.6); glBegin(GL_QUADS); - glVertex2f(-1.6, -1.5); - glVertex2f(-0.4, -1.5); - glVertex2f(-0.4, 1.5); - glVertex2f(-1.6, 1.5); - - glVertex2f( 0.4, -1.5); - glVertex2f( 1.6, -1.5); - glVertex2f( 1.6, 1.5); - glVertex2f( 0.4, 1.5); + glVertex2f(-1.6, -2.5); + glVertex2f(-0.4, -2.5); + glVertex2f(-0.4, 2.5); + glVertex2f(-1.6, 2.5); + glVertex2f( 0.4, -2.5); + glVertex2f( 1.6, -2.5); + glVertex2f( 1.6, 2.5); + glVertex2f( 0.4, 2.5); glEnd(); - /* draw the test polygon with occlusion testing */ - glPushMatrix(); - glTranslatef(Xpos, 0, -0.5); - glScalef(0.3, 0.3, 1.0); - glRotatef(-90.0 * Xpos, 0, 0, 1); - -#if defined(GL_ARB_occlusion_query) -#if TEST_DISPLAY_LISTS - glNewList(10, GL_COMPILE); - glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery); - glEndList(); - glCallList(10); -#else - glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery); -#endif glColorMask(0, 0, 0, 0); glDepthMask(GL_FALSE); - glBegin(GL_POLYGON); - glVertex3f(-1, -1, 0); - glVertex3f( 1, -1, 0); - glVertex3f( 1, 1, 0); - glVertex3f(-1, 1, 0); - glEnd(); + /* draw the test polygons with occlusion testing */ + for (i = 0; i < NUM_OCC; i++) { + glPushMatrix(); + glTranslatef(Xpos[i], Ypos[i], -0.5); + glScalef(0.2, 0.2, 1.0); + glRotatef(-90.0 * Xpos[i], 0, 0, 1); + + glBeginQueryARB(GL_SAMPLES_PASSED_ARB, OccQuery[i]); + glBegin(GL_POLYGON); + glVertex3f(-1, -1, 0); + glVertex3f( 1, -1, 0); + glVertex3f( 1, 1, 0); + glVertex3f(-1, 1, 0); + glEnd(); + glEndQueryARB(GL_SAMPLES_PASSED_ARB); + + glPopMatrix(); + } -#if TEST_DISPLAY_LISTS - glNewList(11, GL_COMPILE); - glEndQueryARB(GL_SAMPLES_PASSED_ARB); - glEndList(); - glCallList(11); -#else - glEndQueryARB(GL_SAMPLES_PASSED_ARB); -#endif - - do { - /* do useful work here, if any */ - glGetQueryObjectivARB(OccQuery, GL_QUERY_RESULT_AVAILABLE_ARB, &ready); - } while (!ready); - glGetQueryObjectuivARB(OccQuery, GL_QUERY_RESULT_ARB, &passed); - - /* turn off occlusion testing */ glColorMask(1, 1, 1, 1); glDepthMask(GL_TRUE); -#endif /* GL_ARB_occlusion_query */ - - /* draw the orange rect, so we can see what's going on */ - glColor3f(0.8, 0.5, 0); - glBegin(GL_POLYGON); - glVertex3f(-1, -1, 0); - glVertex3f( 1, -1, 0); - glVertex3f( 1, 1, 0); - glVertex3f(-1, 1, 0); - glEnd(); - glPopMatrix(); - - - /* Print result message */ - glMatrixMode( GL_PROJECTION ); - glLoadIdentity(); - glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ); - glMatrixMode( GL_MODELVIEW ); - glLoadIdentity(); - - glColor3f(1, 1, 1); -#if defined(GL_ARB_occlusion_query) - sprintf(s, " %4d Fragments Visible", passed); - glRasterPos3f(-0.50, -0.7, 0); - PrintString(s); - if (!passed) { - glRasterPos3f(-0.25, -0.8, 0); - PrintString("Fully Occluded"); + /* Draw the rectangles now. + * Draw orange if result was ready + * Draw red if result was not ready. + */ + for (i = 0; i < NUM_OCC; i++) { + GLuint passed; + GLint ready; + + glGetQueryObjectivARB(OccQuery[i], GL_QUERY_RESULT_AVAILABLE_ARB, &ready); + + glGetQueryObjectuivARB(OccQuery[i], GL_QUERY_RESULT_ARB, &passed); + + if (!ready) + glColor3f(1, 0, 0); + else + glColor3f(0.8, 0.5, 0); + + if (!ready || passed) { + glPushMatrix(); + glTranslatef(Xpos[i], Ypos[i], -0.5); + glScalef(0.2, 0.2, 1.0); + glRotatef(-90.0 * Xpos[i], 0, 0, 1); + + glBegin(GL_POLYGON); + glVertex3f(-1, -1, 0); + glVertex3f( 1, -1, 0); + glVertex3f( 1, 1, 0); + glVertex3f(-1, 1, 0); + glEnd(); + + glPopMatrix(); + } + + { + char s[10]; + glRasterPos3f(0.45, Ypos[i], 1.0); + sprintf(s, "%4d", passed); + PrintString(s); + } } -#else - glRasterPos3f(-0.25, -0.8, 0); - PrintString("GL_ARB_occlusion_query not available at compile time"); -#endif /* GL_ARB_occlusion_query */ glutSwapBuffers(); } @@ -222,14 +215,17 @@ static void Key( unsigned char key, int x, int y ) static void SpecialKey( int key, int x, int y ) { const GLfloat step = 0.1; + int i; (void) x; (void) y; switch (key) { case GLUT_KEY_LEFT: - Xpos -= step; + for (i = 0; i < NUM_OCC; i++) + Xpos[i] -= step; break; case GLUT_KEY_RIGHT: - Xpos += step; + for (i = 0; i < NUM_OCC; i++) + Xpos[i] += step; break; } glutPostRedisplay(); @@ -240,29 +236,33 @@ static void Init( void ) { const char *ext = (const char *) glGetString(GL_EXTENSIONS); GLint bits; + int i; if (!strstr(ext, "GL_ARB_occlusion_query")) { printf("Sorry, this demo requires the GL_ARB_occlusion_query extension\n"); exit(-1); } -#if defined(GL_ARB_occlusion_query) glGetQueryivARB(GL_SAMPLES_PASSED_ARB, GL_QUERY_COUNTER_BITS_ARB, &bits); if (!bits) { printf("Hmmm, GL_QUERY_COUNTER_BITS_ARB is zero!\n"); exit(-1); } -#endif /* GL_ARB_occlusion_query */ glGetIntegerv(GL_DEPTH_BITS, &bits); printf("Depthbits: %d\n", bits); -#if defined(GL_ARB_occlusion_query) - glGenQueriesARB(1, &OccQuery); - assert(OccQuery > 0); -#endif /* GL_ARB_occlusion_query */ + glGenQueriesARB(NUM_OCC, OccQuery); glEnable(GL_DEPTH_TEST); + + for (i = 0; i < NUM_OCC; i++) { + float t = (float) i / (NUM_OCC - 1); + Xpos[i] = 2.5 * t; + Ypos[i] = 4.0 * (t - 0.5); + Sign[i] = 1.0; + } + } @@ -276,7 +276,10 @@ int main( int argc, char *argv[] ) glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); - glutIdleFunc( Idle ); + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); glutDisplayFunc( Display ); Init(); glutMainLoop(); |