display results using OpenGL (called by GLUT)
| 209 | |
| 210 | // display results using OpenGL (called by GLUT) |
| 211 | void display() |
| 212 | { |
| 213 | sdkStartTimer(&timer); |
| 214 | |
| 215 | // map PBO to get CUDA device pointer |
| 216 | uchar4 *d_output; |
| 217 | checkCudaErrors(cudaGraphicsMapResources(1, &cuda_pbo_resource, 0)); |
| 218 | size_t num_bytes; |
| 219 | checkCudaErrors(cudaGraphicsResourceGetMappedPointer((void **)&d_output, &num_bytes, cuda_pbo_resource)); |
| 220 | render(imageWidth, imageHeight, tx, ty, scale, cx, cy, blockSize, gridSize, g_FilterMode, d_output); |
| 221 | |
| 222 | checkCudaErrors(cudaGraphicsUnmapResources(1, &cuda_pbo_resource, 0)); |
| 223 | |
| 224 | // Common display path |
| 225 | { |
| 226 | // display results |
| 227 | glClear(GL_COLOR_BUFFER_BIT); |
| 228 | |
| 229 | #if USE_BUFFER_TEX |
| 230 | // display using buffer texture |
| 231 | glBindTexture(GL_TEXTURE_BUFFER_EXT, bufferTex); |
| 232 | glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fprog); |
| 233 | glEnable(GL_FRAGMENT_PROGRAM_ARB); |
| 234 | glProgramLocalParameterI4iNV(GL_FRAGMENT_PROGRAM_ARB, 0, width, 0, 0, 0); |
| 235 | #else |
| 236 | // download image from PBO to OpenGL texture |
| 237 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo); |
| 238 | glBindTexture(GL_TEXTURE_TYPE, displayTex); |
| 239 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 240 | glTexSubImage2D(GL_TEXTURE_TYPE, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, 0); |
| 241 | glEnable(GL_TEXTURE_TYPE); |
| 242 | #endif |
| 243 | |
| 244 | // draw textured quad |
| 245 | glDisable(GL_DEPTH_TEST); |
| 246 | glBegin(GL_QUADS); |
| 247 | glTexCoord2f(0.0f, (GLfloat)height); |
| 248 | glVertex2f(0.0f, 0.0f); |
| 249 | glTexCoord2f((GLfloat)width, (GLfloat)height); |
| 250 | glVertex2f(1.0f, 0.0f); |
| 251 | glTexCoord2f((GLfloat)width, 0.0f); |
| 252 | glVertex2f(1.0f, 1.0f); |
| 253 | glTexCoord2f(0.0f, 0.0f); |
| 254 | glVertex2f(0.0f, 1.0f); |
| 255 | glEnd(); |
| 256 | glDisable(GL_TEXTURE_TYPE); |
| 257 | glDisable(GL_FRAGMENT_PROGRAM_ARB); |
| 258 | |
| 259 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0); |
| 260 | |
| 261 | if (drawCurves) { |
| 262 | // draw spline curves |
| 263 | glPushMatrix(); |
| 264 | glScalef(0.25, 0.25, 1.0); |
| 265 | |
| 266 | glTranslatef(0.0, 2.0, 0.0); |
| 267 | glColor3f(1.0, 0.0, 0.0); |
| 268 | plotCurve(bspline_w3); |
nothing calls this directly
no test coverage detected