Remove duplicate code between Simple and MultiFrame PBO capturer

This commit is contained in:
Jonas Herzig
2020-10-03 19:48:09 +02:00
parent 2b6d1b2359
commit a7d424679b
4 changed files with 11 additions and 72 deletions

View File

@@ -4,7 +4,7 @@ import com.replaymod.render.frame.CubicOpenGlFrame;
import com.replaymod.render.frame.OpenGlFrame;
public class CubicPboOpenGlFrameCapturer extends
MultiFramePboOpenGlFrameCapturer<CubicOpenGlFrame, CubicOpenGlFrameCapturer.Data> {
PboOpenGlFrameCapturer<CubicOpenGlFrame, CubicOpenGlFrameCapturer.Data> {
private final int frameSize;
public CubicPboOpenGlFrameCapturer(WorldRenderer worldRenderer, RenderInfo renderInfo, int frameSize) {

View File

@@ -10,12 +10,12 @@ import org.lwjgl.opengl.GL12;
import java.io.IOException;
import java.nio.ByteBuffer;
public abstract class MultiFramePboOpenGlFrameCapturer<F extends Frame, D extends Enum<D> & CaptureData>
public abstract class PboOpenGlFrameCapturer<F extends Frame, D extends Enum<D> & CaptureData>
extends OpenGlFrameCapturer<F, D> {
private final D[] data;
private PixelBufferObject pbo, otherPBO;
public MultiFramePboOpenGlFrameCapturer(WorldRenderer worldRenderer, RenderInfo renderInfo, Class<D> type, int framePixels) {
public PboOpenGlFrameCapturer(WorldRenderer worldRenderer, RenderInfo renderInfo, Class<D> type, int framePixels) {
super(worldRenderer, renderInfo);
data = type.getEnumConstants();

View File

@@ -1,81 +1,20 @@
package com.replaymod.render.capturer;
import com.replaymod.render.frame.OpenGlFrame;
import com.replaymod.render.utils.ByteBufferPool;
import com.replaymod.render.utils.PixelBufferObject;
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import java.io.IOException;
import java.nio.ByteBuffer;
public class SimplePboOpenGlFrameCapturer extends OpenGlFrameCapturer<OpenGlFrame, CaptureData> {
private final int bufferSize;
private PixelBufferObject pbo, otherPBO;
public class SimplePboOpenGlFrameCapturer extends PboOpenGlFrameCapturer<OpenGlFrame, SimplePboOpenGlFrameCapturer.SinglePass> {
public SimplePboOpenGlFrameCapturer(WorldRenderer worldRenderer, RenderInfo renderInfo) {
super(worldRenderer, renderInfo);
ReadableDimension size = renderInfo.getFrameSize();
bufferSize = size.getHeight() * size.getWidth() * 4;
pbo = new PixelBufferObject(bufferSize, PixelBufferObject.Usage.READ);
otherPBO = new PixelBufferObject(bufferSize, PixelBufferObject.Usage.READ);
}
private void swapPBOs() {
PixelBufferObject old = pbo;
pbo = otherPBO;
otherPBO = old;
super(worldRenderer, renderInfo, SinglePass.class,
renderInfo.getFrameSize().getWidth() * renderInfo.getFrameSize().getHeight());
}
@Override
public boolean isDone() {
return framesDone >= renderInfo.getTotalFrames() + 2;
protected OpenGlFrame create(OpenGlFrame[] from) {
return from[0];
}
@Override
public OpenGlFrame process() {
OpenGlFrame frame = null;
if (framesDone > 1) {
// Read pbo to memory
pbo.bind();
ByteBuffer pboBuffer = pbo.mapReadOnly();
ByteBuffer buffer = ByteBufferPool.allocate(bufferSize);
buffer.put(pboBuffer);
buffer.rewind();
pbo.unmap();
pbo.unbind();
frame = new OpenGlFrame(framesDone - 2, frameSize, 4, buffer);
}
if (framesDone < renderInfo.getTotalFrames()) {
// Then fill it again
renderFrame(framesDone, renderInfo.updateForNextFrame());
}
framesDone++;
swapPBOs();
return frame;
}
@Override
protected OpenGlFrame captureFrame(int frameId, CaptureData data) {
pbo.bind();
frameBuffer().beginWrite(true);
GL11.glReadPixels(0, 0, getFrameWidth(), getFrameHeight(), GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, 0);
frameBuffer().endWrite();
pbo.unbind();
return null;
}
@Override
public void close() throws IOException {
super.close();
pbo.delete();
otherPBO.delete();
public enum SinglePass implements CaptureData {
SINGLE_PASS
}
}

View File

@@ -4,7 +4,7 @@ import com.replaymod.render.frame.OpenGlFrame;
import com.replaymod.render.frame.StereoscopicOpenGlFrame;
public class StereoscopicPboOpenGlFrameCapturer
extends MultiFramePboOpenGlFrameCapturer<StereoscopicOpenGlFrame, StereoscopicOpenGlFrameCapturer.Data> {
extends PboOpenGlFrameCapturer<StereoscopicOpenGlFrame, StereoscopicOpenGlFrameCapturer.Data> {
public StereoscopicPboOpenGlFrameCapturer(WorldRenderer worldRenderer, RenderInfo renderInfo) {
super(worldRenderer, renderInfo, StereoscopicOpenGlFrameCapturer.Data.class,