MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / asyncDebugDownloadRGBA8

Method asyncDebugDownloadRGBA8

src/main/java/field/graphics/FBO.java:636–668  ·  view source on GitHub ↗

this operates asynchronously if we are not currently inside the draw loop (that is, if there is no valid context for our thread). only one debug download can be pending at a time. You can pass in null to this routine and you'll get a correctly sized ByteByffer back that you can reuse for subsequent

(ByteBuffer to)

Source from the content-addressed store, hash-verified

634 if (to == null || !to.isDirect() || to.limit() < sz) {
635 ato = ByteBuffer.allocateDirect(sz);
636 } else ato = to;
637
638 Thread t = Thread.currentThread();
639 CompletableFuture<ByteBuffer> c = new CompletableFuture<ByteBuffer>() {
640 @Override
641 public ByteBuffer get() throws InterruptedException, ExecutionException {
642 if (Thread.currentThread() == t && !isDone()) return ato;
643 return super.get();
644 }
645 };
646 Runnable r = () -> {
647 int[] a = {0};
648 a[0] = glGetInteger(GL_FRAMEBUFFER_BINDING);
649 glBindFramebuffer(GL_FRAMEBUFFER, getOpenGLFrameBufferNameInCurrentContext());
650 glReadPixels(0, 0, specification.width, specification.height, GL11.GL_RGBA, GL_UNSIGNED_BYTE, ato);
651 glBindFramebuffer(GL_FRAMEBUFFER, a[0]);
652 c.complete(ato);
653 };
654
655 if (GraphicsContext.getContext() == null) {
656 postDrawQueue.set(r);
657 } else {
658 r.run();
659 }
660
661 return c;
662 }
663
664 /**
665 * this operates asynchronously if we are not currently inside the draw loop (that is, if there is no valid context for our thread). only one debug download can be pending at a time. You can
666 * pass in null to this routine and you'll get a correctly sized ByteByffer back that you can reuse for subsequent calls. Regardless of the original format of the FBO this always returns
667 * something that's RGB / byte,.
668 */
669 public Future<ByteBuffer> asyncDebugDownloadRGB8(ByteBuffer to) {
670 ByteBuffer ato;
671

Callers

nothing calls this directly

Calls 8

getContextMethod · 0.95
glGetIntegerMethod · 0.80
glReadPixelsMethod · 0.80
setMethod · 0.65
limitMethod · 0.45
completeMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected