Removed NativeImage Y flip (moved to gpu)

Removed un-needed framebuffers
Removed multi-framebuffer async path and made everything "async"
This commit is contained in:
mcrcortex committed 2024-08-29 10:37:28 +10:00
1 parent a6493b623c
commit e208d9babc
5 files changed
+85 -70

No files matched your search

@@ -1,6 +1,7 @@
package com.moulberry.flashback.exporting;
import com.mojang.blaze3d.pipeline.MainTarget;
import com.mojang.blaze3d.pipeline.RenderTarget;
import com.mojang.blaze3d.platform.NativeImage;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.opengl.GL30C;
@@ -10,35 +11,17 @@ import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
public class SaveableFramebuffer implements AutoCloseable {
private MainTarget framebuffer;
private int pboId;
public @Nullable FloatBuffer audioBuffer;
private boolean isDownloading = false;
public SaveableFramebuffer() {
this.framebuffer = null;
this.pboId = -1;
}
public boolean isDownloading() {
return isDownloading;
}
public MainTarget getFramebuffer(int width, int height) {
if (this.isDownloading) {
throw new IllegalStateException("Can't get the framebuffer for rendering while still downloading");
}
if (this.framebuffer == null) {
this.framebuffer = new MainTarget(width, height);
}
return this.framebuffer;
}
public void startDownload(int width, int height) {
public void startDownload(RenderTarget framebuffer, int width, int height) {
if (this.isDownloading) {
throw new IllegalStateException("Can't start downloading while already downloading");
}
@@ -52,13 +35,13 @@ public class SaveableFramebuffer implements AutoCloseable {
GL30C.glBindBuffer(GL30C.GL_PIXEL_PACK_BUFFER, 0);
}
this.framebuffer.bindWrite(true);
framebuffer.bindWrite(true);
GL30C.glBindBuffer(GL30C.GL_PIXEL_PACK_BUFFER, this.pboId);
GL30C.glReadPixels(0, 0, width, height, GL30C.GL_RGBA, GL30C.GL_UNSIGNED_BYTE, 0);
GL30C.glBindBuffer(GL30C.GL_PIXEL_PACK_BUFFER, 0);
this.framebuffer.unbindWrite();
framebuffer.unbindWrite();
}
public NativeImage finishDownload(int width, int height) {
@@ -79,15 +62,6 @@ public class SaveableFramebuffer implements AutoCloseable {
// Copy bytes
MemoryUtil.memCopy(MemoryUtil.memAddress(buffer), nativeImage.pixels, nativeImage.size);
// for (int y = 0; y < nativeImage.getHeight(); ++y) {
// for (int x = 0; x < nativeImage.getWidth(); ++x) {
// int rgba = nativeImage.getPixelRGBA(x, y);
// nativeImage.setPixelRGBA(x, y, (rgba & 0xFFFFFF) | (80 << NativeImage.Format.RGBA.alphaOffset()));
// }
// }
nativeImage.flipY();
GL30C.glUnmapBuffer(GL30C.GL_PIXEL_PACK_BUFFER);
GL30C.glBindBuffer(GL30C.GL_PIXEL_PACK_BUFFER, 0);
@@ -95,10 +69,6 @@ public class SaveableFramebuffer implements AutoCloseable {
}
public void close() {
if (this.framebuffer != null) {
this.framebuffer.destroyBuffers();
this.framebuffer = null;
}
if (this.pboId != -1) {
GL30C.glDeleteBuffers(this.pboId);
this.pboId = -1;