Generic OpenGL readback test
| 399 | |
| 400 | // Generic OpenGL readback test |
| 401 | int readTest(int format) |
| 402 | { |
| 403 | PF *pf = pf_get(format); |
| 404 | unsigned char *rgbaBuffer = NULL; |
| 405 | int n, retval = 0; |
| 406 | double rbtime, readPixelsTime; Timer timer2; |
| 407 | GLuint bufferID = 0; |
| 408 | #ifdef USEIFR |
| 409 | NV_IFROGL_TRANSFEROBJECT_HANDLE ifrTransfer = NULL; |
| 410 | #endif |
| 411 | char temps[STRLEN]; |
| 412 | size_t bufSize = PAD(drawableWidth * pf->size) * drawableHeight; |
| 413 | |
| 414 | try |
| 415 | { |
| 416 | fprintf(stderr, "glReadPixels(): "); |
| 417 | |
| 418 | glPixelStorei(GL_UNPACK_ALIGNMENT, align); |
| 419 | glPixelStorei(GL_PACK_ALIGNMENT, align); |
| 420 | |
| 421 | #ifdef GL_EXT_framebuffer_object |
| 422 | if(useFBO) glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); |
| 423 | else |
| 424 | #endif |
| 425 | glReadBuffer(GL_FRONT); |
| 426 | |
| 427 | if(usePBO) |
| 428 | { |
| 429 | const char *ext = (const char *)glGetString(GL_EXTENSIONS); |
| 430 | if(!ext || !strstr(ext, "GL_ARB_pixel_buffer_object")) |
| 431 | THROW("GL_ARB_pixel_buffer_object extension not available"); |
| 432 | glGenBuffers(1, &bufferID); |
| 433 | if(!bufferID) THROW("Could not generate PBO buffer"); |
| 434 | glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, bufferID); |
| 435 | glBufferData(GL_PIXEL_PACK_BUFFER_EXT, bufSize, NULL, GL_STREAM_READ); |
| 436 | check_errors("PBO initialization"); |
| 437 | int temp = 0; |
| 438 | glGetBufferParameteriv(GL_PIXEL_PACK_BUFFER_EXT, GL_BUFFER_SIZE, |
| 439 | &temp); |
| 440 | if((size_t)temp != bufSize) |
| 441 | THROW("Could not generate PBO buffer"); |
| 442 | temp = 0; |
| 443 | glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING_EXT, &temp); |
| 444 | if(!!temp != usePBO) THROW("Could not bind PBO buffer"); |
| 445 | } |
| 446 | #ifdef USEIFR |
| 447 | if(useIFR) |
| 448 | { |
| 449 | NV_IFROGL_TO_SYS_CONFIG ifrConfig; |
| 450 | ifrConfig.format = NV_IFROGL_TARGET_FORMAT_CUSTOM; |
| 451 | ifrConfig.flags = NV_IFROGL_TRANSFER_OBJECT_FLAG_NONE; |
| 452 | ifrConfig.customFormat = glFormat[format]; |
| 453 | ifrConfig.customType = pf_gldatatype[format]; |
| 454 | if(ifr.nvIFROGLCreateTransferToSysObject(ifrSession, &ifrConfig, |
| 455 | &ifrTransfer) != NV_IFROGL_SUCCESS) |
| 456 | THROW("Could not create IFR transfer object\n"); |
| 457 | } |
| 458 | #endif |
no test coverage detected