MaterialManager and MaterialGroup refactor

- Material manager builder
 - No more overload render method/IProgramCallback
 - MaterialRenderers accept a Program consumer instead
This commit is contained in:
Jozufozu 2021-07-23 23:45:31 -07:00
parent 976017d084
commit 5308671882
3 changed files with 34 additions and 7 deletions

View file

@ -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<P extends ContraptionProgram> extends MaterialGroup<P> {
private final RenderedContraption contraption;
public ContraptionGroup(RenderedContraption contraption, MaterialManager<P> owner, IRenderState state) {
super(owner, state);
this.contraption = contraption;
}
@Override
public void setup(P program) {
contraption.setup(program);
}
public static <P extends ContraptionProgram> MaterialManager.GroupFactory<P> forContraption(RenderedContraption c) {
return (materialManager, state) -> new ContraptionGroup<>(c, materialManager, state);
}
}

View file

@ -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);
}

View file

@ -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();