diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java new file mode 100644 index 000000000..582694840 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java @@ -0,0 +1,25 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.render; + +import com.jozufozu.flywheel.backend.material.MaterialGroup; +import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.state.IRenderState; + +public class ContraptionGroup

extends MaterialGroup

{ + + private final RenderedContraption contraption; + + public ContraptionGroup(RenderedContraption contraption, MaterialManager

owner, IRenderState state) { + super(owner, state); + + this.contraption = contraption; + } + + @Override + public void setup(P program) { + contraption.setup(program); + } + + public static

MaterialManager.GroupFactory

forContraption(RenderedContraption c) { + return (materialManager, state) -> new ContraptionGroup<>(c, materialManager, state); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java index 06420bf13..ebd61a4a4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java @@ -5,9 +5,6 @@ import static org.lwjgl.opengl.GL11.glBindTexture; import static org.lwjgl.opengl.GL11.glDisable; import static org.lwjgl.opengl.GL11.glEnable; import static org.lwjgl.opengl.GL12.GL_TEXTURE_3D; -import static org.lwjgl.opengl.GL13.GL_TEXTURE0; -import static org.lwjgl.opengl.GL13.GL_TEXTURE4; -import static org.lwjgl.opengl.GL13.glActiveTexture; import static org.lwjgl.opengl.GL20.glUseProgram; import java.util.List; @@ -16,6 +13,7 @@ import java.util.Random; import org.apache.commons.lang3.tuple.Pair; import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.backend.gl.GlTextureUnit; import com.jozufozu.flywheel.backend.state.RenderLayer; import com.jozufozu.flywheel.event.BeginFrameEvent; import com.jozufozu.flywheel.event.GatherContextEvent; @@ -116,7 +114,7 @@ public class ContraptionRenderDispatcher { layer.setupRenderState(); glEnable(GL_TEXTURE_3D); - glActiveTexture(GL_TEXTURE4); // the shaders expect light volumes to be in texture 4 + GlTextureUnit.T4.makeActive(); // the shaders expect light volumes to be in texture 4 if (Backend.getInstance().canUseVBOs()) { ContraptionProgram structureShader = CreateContexts.STRUCTURE.getProgram(AllProgramSpecs.STRUCTURE); @@ -134,7 +132,7 @@ public class ContraptionRenderDispatcher { RenderLayer renderLayer = RenderLayer.fromRenderType(layer); if (renderLayer != null) { for (RenderedContraption renderer : RENDERERS.values()) { - renderer.materialManager.render(renderLayer, event.viewProjection, event.camX, event.camY, event.camZ, renderer::setup); + renderer.materialManager.render(renderLayer, event.viewProjection, event.camX, event.camY, event.camZ); } } } @@ -142,7 +140,7 @@ public class ContraptionRenderDispatcher { glBindTexture(GL_TEXTURE_3D, 0); layer.clearRenderState(); glDisable(GL_TEXTURE_3D); - glActiveTexture(GL_TEXTURE0); + GlTextureUnit.T0.makeActive(); glUseProgram(0); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java index bb528524e..d195c3066 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java @@ -13,6 +13,7 @@ import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.gl.attrib.CommonAttributes; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.instancing.IInstanceRendered; +import com.jozufozu.flywheel.backend.material.MaterialGroup; import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.model.ArrayModelRenderer; import com.jozufozu.flywheel.backend.model.BufferedModel; @@ -60,7 +61,10 @@ public class RenderedContraption extends ContraptionWorldHolder { public RenderedContraption(Contraption contraption, PlacementSimulationWorld renderWorld) { super(contraption, renderWorld); this.lighter = contraption.makeLighter(); - this.materialManager = new MaterialManager<>(CreateContexts.CWORLD).setIgnoreOriginCoordinate(true); + this.materialManager = MaterialManager.builder(CreateContexts.CWORLD) + .setGroupFactory(ContraptionGroup.forContraption(this)) + .setIgnoreOriginCoordinate(true) + .build(); this.kinetics = new ContraptionInstanceManager(this, materialManager); buildLayers();