MCPcopy Create free account
hub / github.com/VirtualGL/virtualgl / readPixels

Method readPixels

server/VirtualDrawable.cpp:399–555  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397
398
399void VirtualDrawable::readPixels(GLint x, GLint y, GLint width, GLint pitch,
400 GLint height, GLenum glFormat, PF *pf, GLubyte *bits, GLint readBuf,
401 bool stereo)
402{
403 double t0 = 0.0, tRead, tTotal;
404 GLenum type = GL_UNSIGNED_BYTE;
405
406 // Compute OpenGL format from pixel format of frame
407 if(glFormat == GL_NONE)
408 {
409 glFormat = pf_glformat[pf->id]; type = pf_gldatatype[pf->id];
410 }
411 if(glFormat == GL_NONE) THROW("Unsupported pixel format");
412
413 // Whenever the readback format changes (perhaps due to switching
414 // compression or transports), then reset the PBO synchronicity detector
415 int currentFormat =
416 (glFormat == GL_GREEN || glFormat == GL_BLUE) ? GL_RED : glFormat;
417 if(lastFormat >= 0 && lastFormat != currentFormat)
418 {
419 usePBO = (fconfig.readback == RRREAD_PBO);
420 numSync = numFrames = 0;
421 alreadyPrinted = alreadyWarned = false;
422 }
423 lastFormat = currentFormat;
424
425 if(!checkRenderMode()) return;
426
427 initReadbackContext();
428 TempContext tc(edpy != EGL_NO_DISPLAY ? (Display *)edpy : dpy,
429 getGLXDrawable(), getGLXDrawable(), ctx, edpy != EGL_NO_DISPLAY);
430
431 backend::readBuffer(readBuf);
432
433 if(pitch % 8 == 0) _glPixelStorei(GL_PACK_ALIGNMENT, 8);
434 else if(pitch % 4 == 0) _glPixelStorei(GL_PACK_ALIGNMENT, 4);
435 else if(pitch % 2 == 0) _glPixelStorei(GL_PACK_ALIGNMENT, 2);
436 else if(pitch % 1 == 0) _glPixelStorei(GL_PACK_ALIGNMENT, 1);
437
438 if(usePBO)
439 {
440 if(!ext)
441 {
442 ext = (const char *)_glGetString(GL_EXTENSIONS);
443 if(!ext || !strstr(ext, "GL_ARB_pixel_buffer_object"))
444 THROW("GL_ARB_pixel_buffer_object extension not available");
445 }
446 if(!pbo) _glGenBuffers(1, &pbo);
447 if(!pbo) THROW("Could not generate pixel buffer object");
448 if(!alreadyPrinted && fconfig.verbose)
449 {
450 vglout.println("[VGL] Using pixel buffer objects for readback (%s --> %s)",
451 formatString(oglDraw->getFormat()), formatString(glFormat));
452 alreadyPrinted = true;
453 }
454 _glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, pbo);
455 int size = 0;
456 _glGetBufferParameteriv(GL_PIXEL_PACK_BUFFER_EXT, GL_BUFFER_SIZE, &size);

Callers

nothing calls this directly

Calls 8

readBufferFunction · 0.85
formatStringFunction · 0.85
GetTimeFunction · 0.85
readPixelsFunction · 0.85
printlnMethod · 0.80
getFormatMethod · 0.80
startFrameMethod · 0.80
endFrameMethod · 0.80

Tested by

no test coverage detected