void RenderBlock:: setSize( unsigned w, unsigned h) { if (w == _mesh_width && h ==_mesh_height) return; createMeshIndexBuffer(w, h); createMeshPositionVBO(w, h); }
//////////////////////////////////////////////////////////////////////////////// //! Run test //////////////////////////////////////////////////////////////////////////////// void runGraphicsTest(int argc, char** argv) { printf("[%s] ", sSDKsample); if (g_bOpenGLQA) printf("[OpenGL Readback Comparisons] "); printf("\n"); if ( cutCheckCmdLineFlag(argc, (const char **)argv, "device") ) { printf("[%s]\n", argv[0]); printf(" Does not explicitly support -device=n in OpenGL mode\n"); printf(" To use -device=n, the sample must be running w/o OpenGL\n\n"); printf(" > %s -device=n -qatest\n", argv[0]); printf("exiting...\n"); exit(0); } // First initialize OpenGL context, so we can properly set the GL for CUDA. // This is necessary in order to achieve optimal performance with OpenGL/CUDA interop. if(CUTFalse == initGL( &argc, argv )) { cudaThreadExit(); return; } cudaGLSetGLDevice( cutGetMaxGflopsDeviceId() ); // create FFT plan CUFFT_SAFE_CALL(cufftPlan2d(&fftPlan, meshW, meshH, CUFFT_C2R) ); // allocate memory fftInputW = (meshW / 2)+1; fftInputH = meshH; fftInputSize = (fftInputW*fftInputH)*sizeof(float2); cutilSafeCall(cudaMalloc((void **)&d_h0, fftInputSize) ); cutilSafeCall(cudaMalloc((void **)&d_ht, fftInputSize) ); h_h0 = (float2 *) malloc(fftInputSize); generate_h0(); cutilSafeCall(cudaMemcpy(d_h0, h_h0, fftInputSize, cudaMemcpyHostToDevice) ); cutilSafeCall(cudaMalloc((void **)&d_slope, meshW*meshH*sizeof(float2)) ); cutCreateTimer(&timer); cutStartTimer(timer); prevTime = cutGetTimerValue(timer); // create vertex buffers and register with CUDA createVBO(&heightVertexBuffer, meshW*meshH*sizeof(float)); // DEPRECATED: cutilSafeCall(cudaGLRegisterBufferObject(heightVertexBuffer)); cutilSafeCall(cudaGraphicsGLRegisterBuffer(&cuda_heightVB_resource, heightVertexBuffer, cudaGraphicsMapFlagsWriteDiscard)); createVBO(&slopeVertexBuffer, meshW*meshH*sizeof(float2)); // DEPRECATED: cutilSafeCall(cudaGLRegisterBufferObject(slopeVertexBuffer)); cutilSafeCall(cudaGraphicsGLRegisterBuffer(&cuda_slopeVB_resource, slopeVertexBuffer, cudaGraphicsMapFlagsWriteDiscard)); // create vertex and index buffer for mesh createMeshPositionVBO(&posVertexBuffer, meshW, meshH); createMeshIndexBuffer(&indexBuffer, meshW, meshH); // Creating the Auto-Validation Code if (g_bOpenGLQA) { g_CheckRender = new CheckBackBuffer(windowH, windowH, 4); g_CheckRender->setPixelFormat(GL_RGBA); g_CheckRender->setExecPath(argv[0]); g_CheckRender->EnableQAReadback(true); } runCuda(); // register callbacks glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutMouseFunc(mouse); glutMotionFunc(motion); glutReshapeFunc(reshape); glutIdleFunc(idle); // start rendering mainloop glutMainLoop(); cudaThreadExit(); }