| 418 | } |
| 419 | |
| 420 | void initPixelBuffer() |
| 421 | { |
| 422 | if (pbo) { |
| 423 | // unregister this buffer object from CUDA C |
| 424 | checkCudaErrors(cudaGraphicsUnregisterResource(cuda_pbo_resource)); |
| 425 | |
| 426 | // delete old buffer |
| 427 | glDeleteBuffers(1, &pbo); |
| 428 | glDeleteTextures(1, &tex); |
| 429 | } |
| 430 | |
| 431 | // create pixel buffer object for display |
| 432 | glGenBuffers(1, &pbo); |
| 433 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo); |
| 434 | glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, width * height * sizeof(GLubyte) * 4, 0, GL_STREAM_DRAW_ARB); |
| 435 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0); |
| 436 | |
| 437 | // register this buffer object with CUDA |
| 438 | checkCudaErrors(cudaGraphicsGLRegisterBuffer(&cuda_pbo_resource, pbo, cudaGraphicsMapFlagsWriteDiscard)); |
| 439 | |
| 440 | // create texture for display |
| 441 | glGenTextures(1, &tex); |
| 442 | glBindTexture(GL_TEXTURE_2D, tex); |
| 443 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 444 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 445 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 446 | glBindTexture(GL_TEXTURE_2D, 0); |
| 447 | } |
| 448 | |
| 449 | // Load raw data from disk |
| 450 | void *loadRawFile(char *filename, size_t size) |