Example #1
0
void initCuda()
{
  // First initialize OpenGL context, so we can properly set the GL
  // for CUDA.  NVIDIA notes this is necessary in order to achieve
  // optimal performance with OpenGL/CUDA interop.  use command-line
  // specified CUDA device, otherwise use device with highest Gflops/s
  int devCount= 0;
  cudaGetDeviceCount(&devCount);
  if( devCount < 1 )
  {
     printf("No GPUS detected\n");
     exit(EXIT_FAILURE);
  }
  cudaGLSetGLDevice( 0 );
  //Set Up scenary
  setup_scene(); 
  
  createPBO(&pbo);
  createTexture(&textureID,image_width,image_height);
 
  // Clean up on program exit
  atexit(cleanupCuda);
  


  runCuda();
}
Example #2
0
////////////////////////////////////////////////////////////////////////////////
//! Run a simple test for CUDA
////////////////////////////////////////////////////////////////////////////////
void
runTest( int argc, char** argv) {

    // Create GL context
    glutInit( &argc, argv);
    glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE);
    glutInitWindowSize( window_width, window_height);
    glutCreateWindow( "CUDA OpenGL post-processing");

    // initialize GL
    if( CUTFalse == initGL()) {
        return;
    }

    // register callbacks
    glutDisplayFunc( display);
    glutKeyboardFunc( keyboard);
    glutReshapeFunc( reshape);
    glutIdleFunc( idle);

    // create menu
    glutCreateMenu(mainMenu);
    glutAddMenuEntry("Toggle CUDA processing [ ]", ' ');
    glutAddMenuEntry("Toggle animation [a]", 'a');
    glutAddMenuEntry("Increment blur radius [=]", '=');
    glutAddMenuEntry("Decrement blur radius [-]", '-');
    glutAddMenuEntry("Quit (esc)", '\033');
    glutAttachMenu(GLUT_RIGHT_BUTTON);

    // create pbo
    createPBO( &pbo_source);
    createPBO( &pbo_dest);

    // create fbo
    createFBO( &fbo, &tex_fbo);
    // create texture for blitting onto the screen
    createTexture( &tex_screen, image_width, image_height);

    // start rendering mainloop
    glutMainLoop();
}
// Main Program
//*****************************************************************************
int main(int argc, char** argv) 
{
    pArgc = &argc;
    pArgv = argv;

    shrQAStart(argc, argv);

    // start logs 
    cExecutableName = argv[0];
    shrSetLogFileName ("oclPostProcessGL.txt");
    shrLog("%s Starting...\n\n", argv[0]); 

    // process command line arguments
    if (argc > 1) 
    {
        bQATest   = shrCheckCmdLineFlag(argc, (const char**)argv, "qatest");
        bNoPrompt = shrCheckCmdLineFlag(argc, (const char**)argv, "noprompt");
    }
    shrLog(" Image Width = %d, Image Height = %d, Blur Radius = %d\n\n", image_width, image_height, blur_radius);

    // init GL
    if(!bQATest) 
    {
        InitGL(&argc, argv);

        // create pbo
        createPBO(&pbo_source);
        createPBO(&pbo_dest);
        
        // create texture for blitting onto the screen
        createTexture(&tex_screen, image_width, image_height);        

        bGLinterop = shrTRUE;
    }

    // init CL
    if( initCL(argc, (const char**)argv) != 0 ) 
    {
        return -1;
    }

    // init fps timer
    shrDeltaT (1);

    // Create buffers and textures, 
    // and then start main GLUT rendering loop for processing and rendering, 
	// or otherwise run No-GL Q/A test sequence
    shrLog("\n%s...\n", bQATest ? "No-GL test sequence" : "Standard GL Loop"); 

    printf("\n"
        "\tControls\n"
		"\t(right click mouse button for Menu)\n"
		"\t[   ] : Toggle Post-Processing (blur filter) ON/OFF\n"
		"\t[ p ] : Toggle Processing (between GPU or CPU)\n"
		"\t[ a ] : Toggle OpenGL Animation (rotation) ON/OFF\n"
		"\t[+/=] : Increase Blur Radius\n"
		"\t[-/_] : Decrease Blur Radius\n"
		"\t[Esc] - Quit\n\n"
        );

    if(!bQATest) 
    {
        glutMainLoop();
    } 
    else 
    {
        TestNoGL();
    }
    
    Cleanup(EXIT_SUCCESS);
}
Example #4
0
void initCuda(int argc, char** argv) {
	cudaGLSetGLDevice(0);

	createPBO(&pbo);
	createTexture(&textureID, window_width, window_height);
}