render image using CUDA
| 129 | |
| 130 | // render image using CUDA |
| 131 | void render() |
| 132 | { |
| 133 | // map PBO to get CUDA device pointer |
| 134 | g_GraphicsMapFlag++; |
| 135 | checkCudaErrors(cudaGraphicsMapResources(1, &cuda_pbo_resource, 0)); |
| 136 | size_t num_bytes; |
| 137 | checkCudaErrors(cudaGraphicsResourceGetMappedPointer((void **)&d_output, &num_bytes, cuda_pbo_resource)); |
| 138 | // printf("CUDA mapped PBO: May access %ld bytes\n", num_bytes); |
| 139 | |
| 140 | // call CUDA kernel, writing results to PBO |
| 141 | render_kernel(gridSize, blockSize, d_output, width, height, w); |
| 142 | |
| 143 | getLastCudaError("render_kernel failed"); |
| 144 | |
| 145 | if (g_GraphicsMapFlag) { |
| 146 | checkCudaErrors(cudaGraphicsUnmapResources(1, &cuda_pbo_resource, 0)); |
| 147 | g_GraphicsMapFlag--; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | // display results using OpenGL (called by GLUT) |
| 152 | void display() |