From 7b0339f4649dc5111831c775debcdd65af01400e Mon Sep 17 00:00:00 2001 From: crykn Date: Sun, 21 Jan 2024 15:42:47 +0100 Subject: [PATCH] feat: Add FboScreenUtils#retrieveFboStatus and #restoreFboStatus. --- .../eskalon/commons/utils/ScreenFboUtils.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/de/eskalon/commons/utils/ScreenFboUtils.java b/src/main/java/de/eskalon/commons/utils/ScreenFboUtils.java index 1945fd0..052d5c4 100644 --- a/src/main/java/de/eskalon/commons/utils/ScreenFboUtils.java +++ b/src/main/java/de/eskalon/commons/utils/ScreenFboUtils.java @@ -15,11 +15,16 @@ package de.eskalon.commons.utils; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.glutils.FrameBuffer; import com.badlogic.gdx.utils.ScreenUtils; +import de.damios.guacamole.Preconditions; +import de.damios.guacamole.annotations.Beta; +import de.damios.guacamole.gdx.graphics.GLUtils; import de.eskalon.commons.screen.ManagedScreen; public class ScreenFboUtils { @@ -57,4 +62,20 @@ public static TextureRegion screenToTexture(ManagedScreen screen, return textureRegion; } + @Beta + public static int[] retrieveFboStatus() { + int previousFBOHandle = GLUtils.getBoundFboHandle(); + int[] previousViewport = GLUtils.getViewport(); + + return new int[] { previousFBOHandle, previousViewport[0], + previousViewport[1], previousViewport[2], previousViewport[3] }; + } + + @Beta + public static void restoreFboStatus(int[] status) { + Preconditions.checkArgument(status.length == 5); + Gdx.gl20.glBindFramebuffer(GL20.GL_FRAMEBUFFER, status[0]); + Gdx.gl20.glViewport(status[1], status[2], status[3], status[4]); + } + }