From a3476fd54cc3fb58892f3ce35f77dcffc0595522 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Tue, 7 Dec 2021 23:15:09 -0800 Subject: [PATCH] Keeping up - Contraptions always use ArrayModelRenderer - De-duplicate UI framebuffer swapping code - Unbind VAO between contraption structure drawing and engine drawing - Bump flywheel build --- gradle.properties | 2 +- .../render/FlwContraptionManager.java | 5 +++- .../render/RenderedContraption.java | 18 +++++-------- .../foundation/config/ui/ConfigScreen.java | 25 ++---------------- .../foundation/gui/ConfirmationScreen.java | 26 +++---------------- .../create/foundation/gui/UIRenderHelper.java | 16 ++++++++++++ 6 files changed, 32 insertions(+), 60 deletions(-) diff --git a/gradle.properties b/gradle.properties index f322fbf90..a9db4420b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,7 +19,7 @@ parchment_version = 2021.10.31 # dependency versions registrate_version = MC1.18-1.0.21 -flywheel_version = 1.18-0.3.0.1 +flywheel_version = 1.18-0.3.0.3 jei_version = 9.0.0.40 # curseforge information diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java index e0cf9516c..172e9e897 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java @@ -5,6 +5,7 @@ import static org.lwjgl.opengl.GL12.GL_TEXTURE_3D; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.gl.GlTextureUnit; +import com.jozufozu.flywheel.backend.gl.GlVertexArray; import com.jozufozu.flywheel.backend.state.RenderLayer; import com.jozufozu.flywheel.event.RenderLayerEvent; import com.jozufozu.flywheel.util.TextureBinder; @@ -55,11 +56,13 @@ public class FlwContraptionManager extends ContraptionRenderManager lighter; - public final InstancingEngine materialManager; + public final InstancingEngine engine; public final ContraptionInstanceManager kinetics; private final Map renderLayers = new HashMap<>(); @@ -47,12 +47,12 @@ public class RenderedContraption extends ContraptionRenderInfo { public RenderedContraption(Contraption contraption, PlacementSimulationWorld renderWorld) { super(contraption, renderWorld); this.lighter = contraption.makeLighter(); - this.materialManager = InstancingEngine.builder(CreateContexts.CWORLD) + this.engine = InstancingEngine.builder(CreateContexts.CWORLD) .setGroupFactory(ContraptionGroup.forContraption(this)) .setIgnoreOriginCoordinate(true) .build(); - this.kinetics = new ContraptionInstanceManager(this, materialManager); - this.materialManager.addListener(this.kinetics); + this.kinetics = new ContraptionInstanceManager(this, engine); + this.engine.addListener(this.kinetics); buildLayers(); if (Backend.getInstance().canUseInstancing()) { @@ -113,7 +113,7 @@ public class RenderedContraption extends ContraptionRenderInfo { lighter.delete(); - materialManager.delete(); + engine.delete(); kinetics.invalidate(); } @@ -129,13 +129,7 @@ public class RenderedContraption extends ContraptionRenderInfo { for (RenderType layer : blockLayers) { Supplier layerModel = () -> new WorldModel(renderWorld, layer, contraption.getBlocks().values(), layer + "_" + contraption.entity.getId()); - ModelRenderer renderer; - if (Backend.getInstance().compat.vertexArrayObjectsSupported()) - renderer = new ArrayModelRenderer(layerModel); - else - renderer = new ModelRenderer(layerModel); - - renderLayers.put(layer, renderer); + renderLayers.put(layer, new ArrayModelRenderer(layerModel)); } } diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreen.java index 75a7619ba..57f871372 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreen.java @@ -9,13 +9,8 @@ import javax.annotation.Nonnull; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.util.TriConsumer; -import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL30; -import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; -import com.mojang.blaze3d.pipeline.RenderTarget; -import com.mojang.blaze3d.platform.GlConst; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; @@ -98,29 +93,13 @@ public abstract class ConfigScreen extends AbstractSimiScreen { @Override protected void prepareFrame() { - RenderTarget thisBuffer = UIRenderHelper.framebuffer; - RenderTarget mainBuffer = minecraft.getMainRenderTarget(); - - GlCompat functions = Backend.getInstance().compat; - functions.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, mainBuffer.frameBufferId); - functions.fbo.bindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, thisBuffer.frameBufferId); - functions.blit.blitFramebuffer(0, 0, mainBuffer.viewWidth, mainBuffer.viewHeight, 0, 0, mainBuffer.viewWidth, mainBuffer.viewHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR); - - functions.fbo.bindFramebuffer(GlConst.GL_FRAMEBUFFER, thisBuffer.frameBufferId); + UIRenderHelper.swapAndBlitColor(minecraft.getMainRenderTarget(), UIRenderHelper.framebuffer); RenderSystem.clear(GL30.GL_STENCIL_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT, Minecraft.ON_OSX); } @Override protected void endFrame() { - RenderTarget thisBuffer = UIRenderHelper.framebuffer; - RenderTarget mainBuffer = minecraft.getMainRenderTarget(); - - GlCompat functions = Backend.getInstance().compat; - functions.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, thisBuffer.frameBufferId); - functions.fbo.bindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, mainBuffer.frameBufferId); - functions.blit.blitFramebuffer(0, 0, mainBuffer.viewWidth, mainBuffer.viewHeight, 0, 0, mainBuffer.viewWidth, mainBuffer.viewHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR); - - functions.fbo.bindFramebuffer(GlConst.GL_FRAMEBUFFER, mainBuffer.frameBufferId); + UIRenderHelper.swapAndBlitColor(UIRenderHelper.framebuffer, minecraft.getMainRenderTarget()); } @Override diff --git a/src/main/java/com/simibubi/create/foundation/gui/ConfirmationScreen.java b/src/main/java/com/simibubi/create/foundation/gui/ConfirmationScreen.java index 51912d733..2a4ecc98e 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/ConfirmationScreen.java +++ b/src/main/java/com/simibubi/create/foundation/gui/ConfirmationScreen.java @@ -6,13 +6,8 @@ import java.util.function.Consumer; import javax.annotation.Nonnull; -import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL30; -import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; -import com.mojang.blaze3d.pipeline.RenderTarget; -import com.mojang.blaze3d.platform.GlConst; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.gui.element.BoxElement; @@ -214,31 +209,16 @@ public class ConfirmationScreen extends AbstractSimiScreen { this.fillGradient(ms, 0, 0, this.width, this.height, 0x70101010, 0x80101010); } + @Override protected void prepareFrame() { - RenderTarget thisBuffer = UIRenderHelper.framebuffer; - RenderTarget mainBuffer = minecraft.getMainRenderTarget(); - - GlCompat functions = Backend.getInstance().compat; - functions.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, mainBuffer.frameBufferId); - functions.fbo.bindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, thisBuffer.frameBufferId); - functions.blit.blitFramebuffer(0, 0, mainBuffer.viewWidth, mainBuffer.viewHeight, 0, 0, mainBuffer.viewWidth, mainBuffer.viewHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR); - - functions.fbo.bindFramebuffer(GlConst.GL_FRAMEBUFFER, thisBuffer.frameBufferId); + UIRenderHelper.swapAndBlitColor(minecraft.getMainRenderTarget(), UIRenderHelper.framebuffer); RenderSystem.clear(GL30.GL_STENCIL_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT, Minecraft.ON_OSX); } @Override protected void endFrame() { - RenderTarget thisBuffer = UIRenderHelper.framebuffer; - RenderTarget mainBuffer = minecraft.getMainRenderTarget(); - - GlCompat functions = Backend.getInstance().compat; - functions.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, thisBuffer.frameBufferId); - functions.fbo.bindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, mainBuffer.frameBufferId); - functions.blit.blitFramebuffer(0, 0, mainBuffer.viewWidth, mainBuffer.viewHeight, 0, 0, mainBuffer.viewWidth, mainBuffer.viewHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR); - - functions.fbo.bindFramebuffer(GlConst.GL_FRAMEBUFFER, mainBuffer.frameBufferId); + UIRenderHelper.swapAndBlitColor(UIRenderHelper.framebuffer, minecraft.getMainRenderTarget()); } @Override diff --git a/src/main/java/com/simibubi/create/foundation/gui/UIRenderHelper.java b/src/main/java/com/simibubi/create/foundation/gui/UIRenderHelper.java index 7aa771f3b..58cf31de7 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/UIRenderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/gui/UIRenderHelper.java @@ -2,7 +2,12 @@ package com.simibubi.create.foundation.gui; import javax.annotation.Nonnull; +import org.lwjgl.opengl.GL20; +import org.lwjgl.opengl.GL30; + import com.mojang.blaze3d.pipeline.RenderTarget; +import com.mojang.blaze3d.platform.GlConst; +import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.BufferBuilder; @@ -252,6 +257,17 @@ public class UIRenderHelper { poseStack.mulPoseMatrix(Matrix4f.createScaleMatrix(1, -1, 1)); } + /** + * Switch from src to dst, after copying the contents of src to dst. + */ + public static void swapAndBlitColor(RenderTarget src, RenderTarget dst) { + GlStateManager._glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, src.frameBufferId); + GlStateManager._glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, dst.frameBufferId); + GlStateManager._glBlitFrameBuffer(0, 0, src.viewWidth, src.viewHeight, 0, 0, dst.viewWidth, dst.viewHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR); + + GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, dst.frameBufferId); + } + public static class CustomRenderTarget extends RenderTarget { public CustomRenderTarget(boolean pUseDepth) {