Skip to content

Commit

Permalink
feat: Add FboScreenUtils#retrieveFboStatus and #restoreFboStatus.
Browse files Browse the repository at this point in the history
  • Loading branch information
crykn committed Jan 21, 2024
1 parent 08e8d91 commit 7b0339f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/de/eskalon/commons/utils/ScreenFboUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]);
}

}

0 comments on commit 7b0339f

Please sign in to comment.