mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 06:53:42 +01:00
MaterialManager and MaterialGroup refactor
- Material manager builder - No more overload render method/IProgramCallback - MaterialRenderers accept a Program consumer instead
This commit is contained in:
parent
976017d084
commit
5308671882
3 changed files with 34 additions and 7 deletions
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,9 +5,6 @@ import static org.lwjgl.opengl.GL11.glBindTexture;
|
||||||
import static org.lwjgl.opengl.GL11.glDisable;
|
import static org.lwjgl.opengl.GL11.glDisable;
|
||||||
import static org.lwjgl.opengl.GL11.glEnable;
|
import static org.lwjgl.opengl.GL11.glEnable;
|
||||||
import static org.lwjgl.opengl.GL12.GL_TEXTURE_3D;
|
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 static org.lwjgl.opengl.GL20.glUseProgram;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -16,6 +13,7 @@ import java.util.Random;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
|
import com.jozufozu.flywheel.backend.gl.GlTextureUnit;
|
||||||
import com.jozufozu.flywheel.backend.state.RenderLayer;
|
import com.jozufozu.flywheel.backend.state.RenderLayer;
|
||||||
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
||||||
import com.jozufozu.flywheel.event.GatherContextEvent;
|
import com.jozufozu.flywheel.event.GatherContextEvent;
|
||||||
|
@ -116,7 +114,7 @@ public class ContraptionRenderDispatcher {
|
||||||
|
|
||||||
layer.setupRenderState();
|
layer.setupRenderState();
|
||||||
glEnable(GL_TEXTURE_3D);
|
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()) {
|
if (Backend.getInstance().canUseVBOs()) {
|
||||||
ContraptionProgram structureShader = CreateContexts.STRUCTURE.getProgram(AllProgramSpecs.STRUCTURE);
|
ContraptionProgram structureShader = CreateContexts.STRUCTURE.getProgram(AllProgramSpecs.STRUCTURE);
|
||||||
|
@ -134,7 +132,7 @@ public class ContraptionRenderDispatcher {
|
||||||
RenderLayer renderLayer = RenderLayer.fromRenderType(layer);
|
RenderLayer renderLayer = RenderLayer.fromRenderType(layer);
|
||||||
if (renderLayer != null) {
|
if (renderLayer != null) {
|
||||||
for (RenderedContraption renderer : RENDERERS.values()) {
|
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);
|
glBindTexture(GL_TEXTURE_3D, 0);
|
||||||
layer.clearRenderState();
|
layer.clearRenderState();
|
||||||
glDisable(GL_TEXTURE_3D);
|
glDisable(GL_TEXTURE_3D);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
GlTextureUnit.T0.makeActive();
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.CommonAttributes;
|
||||||
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
||||||
import com.jozufozu.flywheel.backend.instancing.IInstanceRendered;
|
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.material.MaterialManager;
|
||||||
import com.jozufozu.flywheel.backend.model.ArrayModelRenderer;
|
import com.jozufozu.flywheel.backend.model.ArrayModelRenderer;
|
||||||
import com.jozufozu.flywheel.backend.model.BufferedModel;
|
import com.jozufozu.flywheel.backend.model.BufferedModel;
|
||||||
|
@ -60,7 +61,10 @@ public class RenderedContraption extends ContraptionWorldHolder {
|
||||||
public RenderedContraption(Contraption contraption, PlacementSimulationWorld renderWorld) {
|
public RenderedContraption(Contraption contraption, PlacementSimulationWorld renderWorld) {
|
||||||
super(contraption, renderWorld);
|
super(contraption, renderWorld);
|
||||||
this.lighter = contraption.makeLighter();
|
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);
|
this.kinetics = new ContraptionInstanceManager(this, materialManager);
|
||||||
|
|
||||||
buildLayers();
|
buildLayers();
|
||||||
|
|
Loading…
Reference in a new issue