// Main display loop void AppWindow::display () { float t[10]; // frame timings // Animation PERF_PUSH ( "animate" ); scene.DoAnimation ( frame ); PERF_POP (); switch ( draw_mode ) { case MODE_OPENGL: t[0] = -1; // no shadow timing // Basic OpenGL render. PERF_PUSH ( "render" ); renderCamSetupGL ( scene, GLS_PROGRAM ); renderLightSetupGL ( scene, GLS_PROGRAM ); glShadeModel ( GL_FLAT ); glClearColor ( 1, 1, 1, 1 ); glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Use default shading program glUseProgram ( GLS_PROGRAM ); // Render polygons scene.SetMaterial ( -1, Vector4DF(1,1,1,1), Vector4DF(0.1,0.1,0.1,1), Vector4DF(1,1,1,1) ); renderSceneGL ( scene, GLS_PROGRAM ); // Render outlines scene.SetOverrideMaterial ( Vector4DF(0.4,0.4,0.4,1), Vector4DF(0.1,0.1,0.1,1), Vector4DF(0,0,0,1) ); // black glPolygonMode ( GL_FRONT_AND_BACK, GL_LINE ); glEnable ( GL_POLYGON_OFFSET_LINE ); glPolygonOffset ( 0, -0.2 ); renderSceneGL ( scene, GLS_PROGRAM ); glPolygonMode ( GL_FRONT_AND_BACK, GL_FILL ); glDisable ( GL_POLYGON_OFFSET_LINE ); glUseProgram ( 0); t[0] = PERF_POP (); break; case MODE_OPTIX: case MODE_OPTIXPRIME: #if defined(BUILD_OPTIX) || defined(BUILD_OPTIX_PRIME) // Render shadows with either Optix or Optix Prime PERF_PUSH ( "shadow" ); int finalshader; #ifdef BUILD_OPTIX if (draw_mode == MODE_OPTIX) { finalshader = OPTIX_PROGRAM; t[0] = renderOptix ( scene, frame, num_samples ); renderSetupOptixGL ( scene, finalshader ); } #endif #ifdef BUILD_OPTIX_PRIME if (draw_mode == MODE_OPTIXPRIME) { finalshader = OPTIXPRIME_PROGRAM; Vector4DF timing = renderOptixPrime ( scene, getWidth(), getHeight(), num_samples ); t[0] = timing.w; t[2] = timing.y; renderSetupOptixPrimeGL ( scene, finalshader, getWidth(), getHeight() ); } #endif glFinish (); PERF_POP (); // Final render with OpenGL glClearColor ( 1, 1, 1, 1 ); glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); renderCamSetupGL ( scene, finalshader ); // Send camera params to final shader renderLightSetupGL ( scene, finalshader ); // Send light params to final shader PERF_PUSH ( "render" ); glUseProgram ( finalshader ); scene.SetMaterial ( -1, Vector4DF(.2,.2,.2,1), Vector4DF(0.8,0.8,0.8,1), Vector4DF(1,1,1,1) ); renderSceneGL ( scene, finalshader ); // Render outlines scene.SetOverrideMaterial ( Vector4DF(0.1,0.1,0.1,1), Vector4DF(0.4,0.4,0.4,1), Vector4DF(0,0,0,1) ); // black glPolygonMode ( GL_FRONT_AND_BACK, GL_LINE ); // Render outlines using override colors glEnable ( GL_POLYGON_OFFSET_LINE ); glPolygonOffset ( 0, -0.2 ); renderSceneGL ( scene, finalshader ); glPolygonMode ( GL_FRONT_AND_BACK, GL_FILL ); glDisable ( GL_POLYGON_OFFSET_LINE ); t[1] = PERF_POP (); glUseProgram ( 0 ); #endif break; break; }; //drawScene (); // Draw scene //drawGui (); // Draw GUI (nvGUI in app_util) //draw2D (); // Draw 2D (nv2D in app_util) // OpenGL - Swap buffers PERF_PUSH ( "present" ); swapBuffers(); t[3] = PERF_POP (); // Writing timing if ( gTimingFP != 0x0 ) { // frame #, animate, shadow, render, present fprintf ( gTimingFP, "%d, %f, %f, %f, %f\n", frame, t[0], t[1], t[2], t[3] ); } frame++; }