Update to 1.21.5
This commit is contained in:
@@ -23,6 +23,13 @@ import static com.replaymod.core.versions.MCVer.resizeMainWindow;
|
||||
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
||||
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
|
||||
|
||||
//#if MC>=12105
|
||||
//$$ import com.mojang.blaze3d.buffers.BufferType;
|
||||
//$$ import com.mojang.blaze3d.buffers.BufferUsage;
|
||||
//$$ import com.mojang.blaze3d.buffers.GpuBuffer;
|
||||
//$$ import com.mojang.blaze3d.systems.GpuDevice;
|
||||
//#endif
|
||||
|
||||
public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData> implements FrameCapturer<F> {
|
||||
protected final WorldRenderer worldRenderer;
|
||||
protected final RenderInfo renderInfo;
|
||||
@@ -81,20 +88,30 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
|
||||
resizeMainWindow(mc, getFrameWidth(), getFrameHeight());
|
||||
|
||||
pushMatrix();
|
||||
//#if MC<12105
|
||||
frameBuffer().beginWrite(true);
|
||||
//#endif
|
||||
|
||||
//#if MC>=12105
|
||||
//$$ RenderSystem.getDevice()
|
||||
//$$ .createCommandEncoder()
|
||||
//$$ .clearColorAndDepthTextures(mc.getFramebuffer().getColorAttachment(), 0, mc.getFramebuffer().getDepthAttachment(), 1);
|
||||
//#else
|
||||
GlStateManager.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
|
||||
//#if MC>=11400 && MC<12102
|
||||
, false
|
||||
//#endif
|
||||
);
|
||||
//#endif
|
||||
//#if MC<11904
|
||||
GlStateManager.enableTexture();
|
||||
//#endif
|
||||
|
||||
worldRenderer.renderWorld(partialTicks, captureData);
|
||||
|
||||
//#if MC<12105
|
||||
frameBuffer().endWrite();
|
||||
//#endif
|
||||
popMatrix();
|
||||
|
||||
return captureFrame(frameId, captureData);
|
||||
@@ -102,9 +119,19 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
|
||||
|
||||
protected OpenGlFrame captureFrame(int frameId, D captureData) {
|
||||
ByteBuffer buffer = ByteBufferPool.allocate(getFrameWidth() * getFrameHeight() * 4);
|
||||
//#if MC>=12105
|
||||
//$$ GpuDevice device = RenderSystem.getDevice();
|
||||
//$$ try (GpuBuffer gpuBuffer = device.createBuffer(null, BufferType.PIXEL_PACK, BufferUsage.STATIC_READ, getFrameWidth() * getFrameHeight() * 4)) {
|
||||
//$$ device.createCommandEncoder().copyTextureToBuffer(frameBuffer().getColorAttachment(), gpuBuffer, 0, () -> {}, 0);
|
||||
//$$ try (GpuBuffer.ReadView view = device.createCommandEncoder().readBuffer(gpuBuffer)) {
|
||||
//$$ buffer.put(view.data());
|
||||
//$$ }
|
||||
//$$ }
|
||||
//#else
|
||||
frameBuffer().beginWrite(true);
|
||||
GL11.glReadPixels(0, 0, getFrameWidth(), getFrameHeight(), GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, buffer);
|
||||
frameBuffer().endWrite();
|
||||
//#endif
|
||||
buffer.rewind();
|
||||
|
||||
return new OpenGlFrame(frameId, new Dimension(getFrameWidth(), getFrameHeight()), 4, buffer);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.replaymod.render.capturer;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.replaymod.render.frame.OpenGlFrame;
|
||||
import com.replaymod.render.rendering.Channel;
|
||||
import com.replaymod.render.rendering.Frame;
|
||||
@@ -14,11 +13,24 @@ import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
//#if MC>=12105
|
||||
//$$ import com.mojang.blaze3d.buffers.BufferType;
|
||||
//$$ import com.mojang.blaze3d.buffers.BufferUsage;
|
||||
//$$ import com.mojang.blaze3d.buffers.GpuBuffer;
|
||||
//$$ import com.mojang.blaze3d.systems.CommandEncoder;
|
||||
//$$ import com.mojang.blaze3d.systems.GpuDevice;
|
||||
//$$ import com.mojang.blaze3d.systems.RenderSystem;
|
||||
//#endif
|
||||
|
||||
public abstract class PboOpenGlFrameCapturer<F extends Frame, D extends Enum<D> & CaptureData>
|
||||
extends OpenGlFrameCapturer<F, D> {
|
||||
private final boolean withDepth;
|
||||
private final D[] data;
|
||||
//#if MC>=12105
|
||||
//$$ private GpuBuffer pbo, otherPBO;
|
||||
//#else
|
||||
private PixelBufferObject pbo, otherPBO;
|
||||
//#endif
|
||||
|
||||
public PboOpenGlFrameCapturer(WorldRenderer worldRenderer, RenderInfo renderInfo, Class<D> type, int framePixels) {
|
||||
super(worldRenderer, renderInfo);
|
||||
@@ -26,14 +38,23 @@ public abstract class PboOpenGlFrameCapturer<F extends Frame, D extends Enum<D>
|
||||
withDepth = renderInfo.getRenderSettings().isDepthMap();
|
||||
data = type.getEnumConstants();
|
||||
int bufferSize = framePixels * (4 /* bgra */ + (withDepth ? 4 /* float */ : 0)) * data.length;
|
||||
//#if MC>=12105
|
||||
//$$ pbo = RenderSystem.getDevice().createBuffer(null, BufferType.PIXEL_PACK, BufferUsage.STREAM_READ, bufferSize);
|
||||
//$$ otherPBO = RenderSystem.getDevice().createBuffer(null, BufferType.PIXEL_PACK, BufferUsage.STREAM_READ, bufferSize);
|
||||
//#else
|
||||
pbo = new PixelBufferObject(bufferSize, PixelBufferObject.Usage.READ);
|
||||
otherPBO = new PixelBufferObject(bufferSize, PixelBufferObject.Usage.READ);
|
||||
//#endif
|
||||
}
|
||||
|
||||
protected abstract F create(OpenGlFrame[] from);
|
||||
|
||||
private void swapPBOs() {
|
||||
//#if MC>=12105
|
||||
//$$ GpuBuffer old = pbo;
|
||||
//#else
|
||||
PixelBufferObject old = pbo;
|
||||
//#endif
|
||||
pbo = otherPBO;
|
||||
otherPBO = old;
|
||||
}
|
||||
@@ -43,13 +64,26 @@ public abstract class PboOpenGlFrameCapturer<F extends Frame, D extends Enum<D>
|
||||
return framesDone >= renderInfo.getTotalFrames() + 2;
|
||||
}
|
||||
|
||||
private F readFromPbo(ByteBuffer pboBuffer, int bytesPerPixel) {
|
||||
private F readFromPbo(ByteBuffer pboBuffer, int bytesPerPixel, boolean swapRB) {
|
||||
OpenGlFrame[] frames = new OpenGlFrame[data.length];
|
||||
int frameBufferSize = getFrameWidth() * getFrameHeight() * bytesPerPixel;
|
||||
for (int i = 0; i < frames.length; i++) {
|
||||
ByteBuffer frameBuffer = ByteBufferPool.allocate(frameBufferSize);
|
||||
pboBuffer.limit(pboBuffer.position() + frameBufferSize);
|
||||
frameBuffer.put(pboBuffer);
|
||||
if (swapRB) {
|
||||
for (int j = 0; j < frameBufferSize; j += 4) {
|
||||
byte r = pboBuffer.get();
|
||||
byte g = pboBuffer.get();
|
||||
byte b = pboBuffer.get();
|
||||
byte a = pboBuffer.get();
|
||||
frameBuffer.put(b);
|
||||
frameBuffer.put(g);
|
||||
frameBuffer.put(r);
|
||||
frameBuffer.put(a);
|
||||
}
|
||||
} else {
|
||||
frameBuffer.put(pboBuffer);
|
||||
}
|
||||
frameBuffer.rewind();
|
||||
frames[i] = new OpenGlFrame(framesDone - 2, frameSize, bytesPerPixel, frameBuffer);
|
||||
}
|
||||
@@ -62,17 +96,27 @@ public abstract class PboOpenGlFrameCapturer<F extends Frame, D extends Enum<D>
|
||||
|
||||
if (framesDone > 1) {
|
||||
// Read pbo to memory
|
||||
//#if MC>=12105
|
||||
//$$ try (GpuBuffer.ReadView view = RenderSystem.getDevice().createCommandEncoder().readBuffer(pbo)) {
|
||||
//$$ channels = new HashMap<>();
|
||||
//$$ channels.put(Channel.BRGA, readFromPbo(view.data(), 4, true));
|
||||
//$$ if (withDepth) {
|
||||
//$$ channels.put(Channel.DEPTH, readFromPbo(view.data(), 4, false));
|
||||
//$$ }
|
||||
//$$ }
|
||||
//#else
|
||||
pbo.bind();
|
||||
ByteBuffer pboBuffer = pbo.mapReadOnly();
|
||||
|
||||
channels = new HashMap<>();
|
||||
channels.put(Channel.BRGA, readFromPbo(pboBuffer, 4));
|
||||
channels.put(Channel.BRGA, readFromPbo(pboBuffer, 4, false));
|
||||
if (withDepth) {
|
||||
channels.put(Channel.DEPTH, readFromPbo(pboBuffer, 4));
|
||||
channels.put(Channel.DEPTH, readFromPbo(pboBuffer, 4, false));
|
||||
}
|
||||
|
||||
pbo.unmap();
|
||||
pbo.unbind();
|
||||
//#endif
|
||||
}
|
||||
|
||||
if (framesDone < renderInfo.getTotalFrames()) {
|
||||
@@ -90,6 +134,15 @@ public abstract class PboOpenGlFrameCapturer<F extends Frame, D extends Enum<D>
|
||||
|
||||
@Override
|
||||
protected OpenGlFrame captureFrame(int frameId, D captureData) {
|
||||
//#if MC>=12105
|
||||
//$$ int offset = captureData.ordinal() * getFrameWidth() * getFrameHeight() * 4;
|
||||
//$$ CommandEncoder cmd = RenderSystem.getDevice().createCommandEncoder();
|
||||
//$$ cmd.copyTextureToBuffer(frameBuffer().getColorAttachment(), pbo, offset, () -> {}, 0);
|
||||
//$$ if (withDepth) {
|
||||
//$$ offset += data.length * getFrameWidth() * getFrameHeight() * 4;
|
||||
//$$ cmd.copyTextureToBuffer(frameBuffer().getDepthAttachment(), pbo, offset, () -> {}, 0);
|
||||
//$$ }
|
||||
//#else
|
||||
pbo.bind();
|
||||
|
||||
int offset = captureData.ordinal() * getFrameWidth() * getFrameHeight() * 4;
|
||||
@@ -102,13 +155,14 @@ public abstract class PboOpenGlFrameCapturer<F extends Frame, D extends Enum<D>
|
||||
frameBuffer().endWrite();
|
||||
|
||||
pbo.unbind();
|
||||
//#endif
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
pbo.delete();
|
||||
otherPBO.delete();
|
||||
pbo.close();
|
||||
otherPBO.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user