mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-28 16:06:28 +01:00
Groups store their types again
- Fix crash rendering breaking overlay
This commit is contained in:
parent
a70adc8bba
commit
ef5de609a2
4 changed files with 49 additions and 28 deletions
|
@ -22,13 +22,15 @@ import net.minecraft.client.renderer.RenderType;
|
||||||
public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialGroup {
|
public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialGroup {
|
||||||
|
|
||||||
protected final InstancingEngine<P> owner;
|
protected final InstancingEngine<P> owner;
|
||||||
|
protected final RenderType type;
|
||||||
|
|
||||||
protected final ArrayList<InstancedMaterialRenderer<P>> renderers = new ArrayList<>();
|
protected final ArrayList<InstancedMaterialRenderer<P>> renderers = new ArrayList<>();
|
||||||
|
|
||||||
private final Map<MaterialSpec<?>, InstancedMaterial<?>> materials = new HashMap<>();
|
private final Map<MaterialSpec<?>, InstancedMaterial<?>> materials = new HashMap<>();
|
||||||
|
|
||||||
public InstancedMaterialGroup(InstancingEngine<P> owner) {
|
public InstancedMaterialGroup(InstancingEngine<P> owner, RenderType type) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,7 +45,7 @@ public class InstancedMaterialGroup<P extends WorldProgram> implements MaterialG
|
||||||
return (InstancedMaterial<D>) materials.computeIfAbsent(spec, this::createInstanceMaterial);
|
return (InstancedMaterial<D>) materials.computeIfAbsent(spec, this::createInstanceMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(RenderType type, Matrix4f viewProjection, double camX, double camY, double camZ) {
|
public void render(Matrix4f viewProjection, double camX, double camY, double camZ) {
|
||||||
type.setupRenderState();
|
type.setupRenderState();
|
||||||
TextureBinder.bindActiveTextures();
|
TextureBinder.bindActiveTextures();
|
||||||
for (InstancedMaterialRenderer<P> renderer : renderers) {
|
for (InstancedMaterialRenderer<P> renderer : renderers) {
|
||||||
|
|
|
@ -4,6 +4,9 @@ import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.gl.GlVertexArray;
|
import com.jozufozu.flywheel.backend.gl.GlVertexArray;
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
|
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
|
||||||
|
@ -60,15 +63,15 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a material group that will render in the given layer with the given state.
|
* Get a material group that will render in the given layer with the given type.
|
||||||
*
|
*
|
||||||
* @param layer The {@link RenderLayer} you want to draw in.
|
* @param layer The {@link RenderLayer} you want to draw in.
|
||||||
* @param state The {@link RenderType} you need to draw with.
|
* @param type The {@link RenderType} you need to draw with.
|
||||||
* @return A material group whose children will
|
* @return A material group whose children will
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public MaterialGroup state(RenderLayer layer, RenderType state) {
|
public MaterialGroup state(RenderLayer layer, RenderType type) {
|
||||||
return layers.get(layer).computeIfAbsent(state, $ -> groupFactory.create(this));
|
return layers.get(layer).computeIfAbsent(type, t -> groupFactory.create(this, t));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,34 +79,44 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void render(RenderLayerEvent event, MultiBufferSource buffers) {
|
public void render(RenderLayerEvent event, MultiBufferSource buffers) {
|
||||||
double camX = event.camX;
|
double camX;
|
||||||
double camY = event.camY;
|
double camY;
|
||||||
double camZ = event.camZ;
|
double camZ;
|
||||||
Matrix4f viewProjection = event.viewProjection;
|
Matrix4f viewProjection;
|
||||||
if (!ignoreOriginCoordinate) {
|
if (!ignoreOriginCoordinate) {
|
||||||
camX -= originCoordinate.getX();
|
camX = event.camX - originCoordinate.getX();
|
||||||
camY -= originCoordinate.getY();
|
camY = event.camY - originCoordinate.getY();
|
||||||
camZ -= originCoordinate.getZ();
|
camZ = event.camZ - originCoordinate.getZ();
|
||||||
|
|
||||||
Matrix4f translate = Matrix4f.createTranslateMatrix((float) -camX, (float) -camY, (float) -camZ);
|
viewProjection = Matrix4f.createTranslateMatrix((float) -camX, (float) -camY, (float) -camZ);
|
||||||
|
viewProjection.multiplyBackward(event.viewProjection);
|
||||||
translate.multiplyBackward(viewProjection);
|
} else {
|
||||||
|
camX = event.camX;
|
||||||
viewProjection = translate;
|
camY = event.camY;
|
||||||
|
camZ = event.camZ;
|
||||||
|
viewProjection = event.viewProjection;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<RenderType, InstancedMaterialGroup<P>> entry : layers.get(event.getLayer()).entrySet()) {
|
getGroupsToRender(event.getLayer()).forEach(group -> group.render(viewProjection, camX, camY, camZ));
|
||||||
RenderType state = entry.getKey();
|
|
||||||
InstancedMaterialGroup<P> group = entry.getValue();
|
|
||||||
|
|
||||||
group.render(state, viewProjection, camX, camY, camZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
GlBufferType.ELEMENT_ARRAY_BUFFER.unbind();
|
GlBufferType.ELEMENT_ARRAY_BUFFER.unbind();
|
||||||
GlBufferType.ARRAY_BUFFER.unbind();
|
GlBufferType.ARRAY_BUFFER.unbind();
|
||||||
GlVertexArray.unbind();
|
GlVertexArray.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Stream<InstancedMaterialGroup<P>> getGroupsToRender(@Nullable RenderLayer layer) {
|
||||||
|
if (layer != null) {
|
||||||
|
return layers.get(layer)
|
||||||
|
.values()
|
||||||
|
.stream();
|
||||||
|
} else {
|
||||||
|
return layers.values()
|
||||||
|
.stream()
|
||||||
|
.flatMap(it -> it.values()
|
||||||
|
.stream());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete() {
|
public void delete() {
|
||||||
for (Map<RenderType, InstancedMaterialGroup<P>> groups : layers.values()) {
|
for (Map<RenderType, InstancedMaterialGroup<P>> groups : layers.values()) {
|
||||||
|
@ -159,7 +172,7 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface GroupFactory<P extends WorldProgram> {
|
public interface GroupFactory<P extends WorldProgram> {
|
||||||
InstancedMaterialGroup<P> create(InstancingEngine<P> materialManager);
|
InstancedMaterialGroup<P> create(InstancingEngine<P> engine, RenderType type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder<P extends WorldProgram> {
|
public static class Builder<P extends WorldProgram> {
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
|
||||||
|
package com.jozufozu.flywheel.backend.material.instancing;
|
||||||
|
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
|
import net.minecraft.MethodsReturnNonnullByDefault;
|
|
@ -18,12 +18,12 @@ public class CrumblingGroup<P extends CrumblingProgram> extends InstancedMateria
|
||||||
private int width;
|
private int width;
|
||||||
private int height;
|
private int height;
|
||||||
|
|
||||||
public CrumblingGroup(InstancingEngine<P> owner) {
|
public CrumblingGroup(InstancingEngine<P> owner, RenderType type) {
|
||||||
super(owner);
|
super(owner, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(RenderType type, Matrix4f viewProjection, double camX, double camY, double camZ) {
|
public void render(Matrix4f viewProjection, double camX, double camY, double camZ) {
|
||||||
type.setupRenderState();
|
type.setupRenderState();
|
||||||
|
|
||||||
int renderTex = RenderSystem.getShaderTexture(0);
|
int renderTex = RenderSystem.getShaderTexture(0);
|
||||||
|
|
Loading…
Reference in a new issue