Named models

This commit is contained in:
Jozufozu 2021-11-08 20:48:02 -08:00
parent 35b542fb68
commit 1d4bb972b9
14 changed files with 79 additions and 26 deletions

View file

@ -1,5 +1,7 @@
package com.jozufozu.flywheel.backend.gl.error; package com.jozufozu.flywheel.backend.gl.error;
import java.util.function.Supplier;
import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30; import org.lwjgl.opengl.GL30;
@ -35,4 +37,11 @@ public enum GlError {
public static GlError poll() { public static GlError poll() {
return errorLookup.get(GL20.glGetError()); return errorLookup.get(GL20.glGetError());
} }
public static void pollAndThrow(Supplier<String> context) {
GlError poll = GlError.poll();
if (poll != null) {
throw new GlException(poll, context.get());
}
}
} }

View file

@ -9,6 +9,7 @@ import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer; import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer; import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer;
import com.jozufozu.flywheel.backend.gl.error.GlError;
import com.jozufozu.flywheel.backend.model.IBufferedModel; import com.jozufozu.flywheel.backend.model.IBufferedModel;
import com.jozufozu.flywheel.backend.model.ModelAllocator; import com.jozufozu.flywheel.backend.model.ModelAllocator;
import com.jozufozu.flywheel.backend.struct.StructType; import com.jozufozu.flywheel.backend.struct.StructType;
@ -73,14 +74,22 @@ public class GPUInstancer<D extends InstanceData> implements Instancer<D> {
if (invalid()) return; if (invalid()) return;
vao.bind(); vao.bind();
renderSetup(); GlError.pollAndThrow(() -> modelData.name() + "_bind");
if (glInstanceCount > 0) model.drawInstances(glInstanceCount); renderSetup();
GlError.pollAndThrow(() -> modelData.name() + "_setup");
if (glInstanceCount > 0) {
model.drawInstances(glInstanceCount);
GlError.pollAndThrow(() -> modelData.name() + "_draw");
}
// persistent mapping sync point // persistent mapping sync point
instanceVBO.doneForThisFrame(); instanceVBO.doneForThisFrame();
vao.unbind(); vao.unbind();
GlError.pollAndThrow(() -> modelData.name() + "_unbind");
} }
private boolean invalid() { private boolean invalid() {

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.jozufozu.flywheel.backend.gl.error.GlError;
import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.instancing.InstanceData;
import com.jozufozu.flywheel.backend.state.IRenderState; import com.jozufozu.flywheel.backend.state.IRenderState;
import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.WorldProgram;
@ -45,6 +46,8 @@ public class MaterialGroupImpl<P extends WorldProgram> implements MaterialGroup
public void render(Matrix4f viewProjection, double camX, double camY, double camZ) { public void render(Matrix4f viewProjection, double camX, double camY, double camZ) {
for (MaterialRenderer<P> renderer : renderers) { for (MaterialRenderer<P> renderer : renderers) {
renderer.render(viewProjection, camX, camY, camZ); renderer.render(viewProjection, camX, camY, camZ);
GlError.pollAndThrow(renderer.material.spec.name::toString);
} }
} }

View file

@ -37,7 +37,7 @@ public enum BooleanConfig {
if (player == null || state == null) return; if (player == null || state == null) return;
if (state == BooleanDirective.DISPLAY) { if (state == BooleanDirective.DISPLAY) {
Component text = new TextComponent("Flywheel renderer is currently: ").append(boolToText(FlwConfig.get().client.enabled.get())); Component text = new TextComponent("Flywheel renderer is currently: ").append(boolToText(FlwConfig.get().enabled()));
player.displayClientMessage(text, false); player.displayClientMessage(text, false);
return; return;
} }
@ -47,7 +47,7 @@ public enum BooleanConfig {
FlwConfig.get().client.enabled.set(enabled); FlwConfig.get().client.enabled.set(enabled);
Component text = boolToText(FlwConfig.get().client.enabled.get()).append(new TextComponent(" Flywheel renderer").withStyle(ChatFormatting.WHITE)); Component text = boolToText(FlwConfig.get().enabled()).append(new TextComponent(" Flywheel renderer").withStyle(ChatFormatting.WHITE));
Component error = new TextComponent("Flywheel renderer does not support Optifine Shaders").withStyle(ChatFormatting.RED); Component error = new TextComponent("Flywheel renderer does not support Optifine Shaders").withStyle(ChatFormatting.RED);
player.displayClientMessage(cannotUse ? error : text, false); player.displayClientMessage(cannotUse ? error : text, false);
@ -60,14 +60,14 @@ public enum BooleanConfig {
if (player == null || state == null) return; if (player == null || state == null) return;
if (state == BooleanDirective.DISPLAY) { if (state == BooleanDirective.DISPLAY) {
Component text = new TextComponent("Normal debug mode is currently: ").append(boolToText(FlwConfig.get().client.debugNormals.get())); Component text = new TextComponent("Normal debug mode is currently: ").append(boolToText(FlwConfig.get().debugNormals()));
player.displayClientMessage(text, false); player.displayClientMessage(text, false);
return; return;
} }
FlwConfig.get().client.debugNormals.set(state.get()); FlwConfig.get().client.debugNormals.set(state.get());
Component text = boolToText(FlwConfig.get().client.debugNormals.get()).append(new TextComponent(" normal debug mode").withStyle(ChatFormatting.WHITE)); Component text = boolToText(FlwConfig.get().debugNormals()).append(new TextComponent(" normal debug mode").withStyle(ChatFormatting.WHITE));
player.displayClientMessage(text, false); player.displayClientMessage(text, false);
} }
@ -78,14 +78,14 @@ public enum BooleanConfig {
if (player == null || state == null) return; if (player == null || state == null) return;
if (state == BooleanDirective.DISPLAY) { if (state == BooleanDirective.DISPLAY) {
Component text = new TextComponent("Chunk caching is currently: ").append(boolToText(FlwConfig.get().client.chunkCaching.get())); Component text = new TextComponent("Chunk caching is currently: ").append(boolToText(FlwConfig.get().chunkCaching()));
player.displayClientMessage(text, false); player.displayClientMessage(text, false);
return; return;
} }
FlwConfig.get().client.chunkCaching.set(state.get()); FlwConfig.get().client.chunkCaching.set(state.get());
Component text = boolToText(FlwConfig.get().client.chunkCaching.get()).append(new TextComponent(" chunk caching").withStyle(ChatFormatting.WHITE)); Component text = boolToText(FlwConfig.get().chunkCaching()).append(new TextComponent(" chunk caching").withStyle(ChatFormatting.WHITE));
player.displayClientMessage(text, false); player.displayClientMessage(text, false);
Backend.reloadWorldRenderers(); Backend.reloadWorldRenderers();

View file

@ -56,6 +56,11 @@ public class BakedModelModel implements IModel {
this.numQuads = numQuads; this.numQuads = numQuads;
} }
@Override
public String name() {
return model.toString();
}
@Override @Override
public void buffer(VecBuffer buffer) { public void buffer(VecBuffer buffer) {

View file

@ -2,8 +2,6 @@ package com.jozufozu.flywheel.core.model;
import java.util.Arrays; import java.util.Arrays;
import org.lwjgl.opengl.GL11;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.core.Formats; import com.jozufozu.flywheel.core.Formats;
@ -30,6 +28,8 @@ public class BlockModel implements IModel {
private final BufferBuilderReader reader; private final BufferBuilderReader reader;
private final String name;
public BlockModel(BlockState state) { public BlockModel(BlockState state) {
this(Minecraft.getInstance() this(Minecraft.getInstance()
.getBlockRenderer() .getBlockRenderer()
@ -42,6 +42,12 @@ public class BlockModel implements IModel {
public BlockModel(BakedModel model, BlockState referenceState, PoseStack ms) { public BlockModel(BakedModel model, BlockState referenceState, PoseStack ms) {
reader = new BufferBuilderReader(getBufferBuilder(model, referenceState, ms)); reader = new BufferBuilderReader(getBufferBuilder(model, referenceState, ms));
name = referenceState.toString();
}
@Override
public String name() {
return name;
} }
@Override @Override

View file

@ -27,6 +27,11 @@ import com.jozufozu.flywheel.core.QuadConverter;
*/ */
public interface IModel { public interface IModel {
/**
* A name uniquely identifying this model.
*/
String name();
/** /**
* Copy this model into the given buffer. * Copy this model into the given buffer.
*/ */

View file

@ -10,9 +10,11 @@ public class ModelPart implements IModel {
private final List<PartBuilder.CuboidBuilder> cuboids; private final List<PartBuilder.CuboidBuilder> cuboids;
private int vertices; private int vertices;
private final String name;
public ModelPart(List<PartBuilder.CuboidBuilder> cuboids) { public ModelPart(List<PartBuilder.CuboidBuilder> cuboids, String name) {
this.cuboids = cuboids; this.cuboids = cuboids;
this.name = name;
vertices = 0; vertices = 0;
@ -21,8 +23,13 @@ public class ModelPart implements IModel {
} }
} }
public static PartBuilder builder(int sizeU, int sizeV) { public static PartBuilder builder(String name, int sizeU, int sizeV) {
return new PartBuilder(sizeU, sizeV); return new PartBuilder(name, sizeU, sizeV);
}
@Override
public String name() {
return name;
} }
@Override @Override

View file

@ -23,8 +23,10 @@ public class PartBuilder {
private TextureAtlasSprite sprite; private TextureAtlasSprite sprite;
private final List<CuboidBuilder> cuboids = new ArrayList<>(); private final List<CuboidBuilder> cuboids = new ArrayList<>();
private final String name;
public PartBuilder(int sizeU, int sizeV) { public PartBuilder(String name, int sizeU, int sizeV) {
this.name = name;
this.sizeU = (float) sizeU; this.sizeU = (float) sizeU;
this.sizeV = (float) sizeV; this.sizeV = (float) sizeV;
} }
@ -39,7 +41,7 @@ public class PartBuilder {
} }
public ModelPart build() { public ModelPart build() {
return new ModelPart(cuboids); return new ModelPart(cuboids, name);
} }
private PartBuilder addCuboid(CuboidBuilder builder) { private PartBuilder addCuboid(CuboidBuilder builder) {

View file

@ -15,9 +15,16 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemp
public class WorldModel implements IModel { public class WorldModel implements IModel {
private final BufferBuilderReader reader; private final BufferBuilderReader reader;
private final String name;
public WorldModel(BlockAndTintGetter renderWorld, RenderType layer, Collection<StructureTemplate.StructureBlockInfo> blocks) { public WorldModel(BlockAndTintGetter renderWorld, RenderType layer, Collection<StructureTemplate.StructureBlockInfo> blocks, String name) {
reader = new BufferBuilderReader(ModelUtil.getBufferBuilderFromTemplate(renderWorld, layer, blocks)); reader = new BufferBuilderReader(ModelUtil.getBufferBuilderFromTemplate(renderWorld, layer, blocks));
this.name = name;
}
@Override
public String name() {
return name;
} }
@Override @Override

View file

@ -64,7 +64,7 @@ public class BellInstance extends TileEntityInstance<BellBlockEntity> implements
} }
private static ModelPart createBellModel() { private static ModelPart createBellModel() {
return ModelPart.builder(32, 32) return ModelPart.builder("bell", 32, 32)
.sprite(BellRenderer.BELL_RESOURCE_LOCATION.sprite()) .sprite(BellRenderer.BELL_RESOURCE_LOCATION.sprite())
.cuboid() .cuboid()
.start(5.0F, 6.0F, 5.0F) .start(5.0F, 6.0F, 5.0F)

View file

@ -137,7 +137,7 @@ public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends TileE
switch (chestType) { switch (chestType) {
case LEFT: case LEFT:
return ModelPart.builder(64, 64) return ModelPart.builder("chest_base_left", 64, 64)
.sprite(renderMaterial.sprite()) .sprite(renderMaterial.sprite())
.cuboid() .cuboid()
.textureOffset(0, 19) .textureOffset(0, 19)
@ -146,7 +146,7 @@ public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends TileE
.endCuboid() .endCuboid()
.build(); .build();
case RIGHT: case RIGHT:
return ModelPart.builder(64, 64) return ModelPart.builder("chest_base_right", 64, 64)
.sprite(renderMaterial.sprite()) .sprite(renderMaterial.sprite())
.cuboid() .cuboid()
.textureOffset(0, 19) .textureOffset(0, 19)
@ -156,7 +156,7 @@ public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends TileE
.build(); .build();
} }
return ModelPart.builder(64, 64) return ModelPart.builder("chest_base", 64, 64)
.sprite(renderMaterial.sprite()) .sprite(renderMaterial.sprite())
.cuboid() .cuboid()
.textureOffset(0, 19) .textureOffset(0, 19)
@ -170,7 +170,7 @@ public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends TileE
switch (chestType) { switch (chestType) {
case LEFT: case LEFT:
return ModelPart.builder(64, 64) return ModelPart.builder("chest_lid_left", 64, 64)
.sprite(renderMaterial.sprite()) .sprite(renderMaterial.sprite())
.cuboid() .cuboid()
.textureOffset(0, 0) .textureOffset(0, 0)
@ -183,7 +183,7 @@ public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends TileE
.endCuboid() .endCuboid()
.build(); .build();
case RIGHT: case RIGHT:
return ModelPart.builder(64, 64) return ModelPart.builder("chest_lid_right", 64, 64)
.sprite(renderMaterial.sprite()) .sprite(renderMaterial.sprite())
.cuboid() .cuboid()
.textureOffset(0, 0) .textureOffset(0, 0)
@ -197,7 +197,7 @@ public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends TileE
.build(); .build();
} }
return ModelPart.builder(64, 64) return ModelPart.builder("chest_lid", 64, 64)
.sprite(renderMaterial.sprite()) .sprite(renderMaterial.sprite())
.cuboid() .cuboid()
.textureOffset(0, 0) .textureOffset(0, 0)

View file

@ -155,7 +155,7 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
private IModel getBodyModel() { private IModel getBodyModel() {
int y = -3; int y = -3;
return ModelPart.builder(64, 32) return ModelPart.builder("minecart", 64, 32)
.cuboid().invertYZ().start(-10, -8, -y).size(20, 16, 2).textureOffset(0, 10).rotateX(((float)Math.PI / 2F)).endCuboid() .cuboid().invertYZ().start(-10, -8, -y).size(20, 16, 2).textureOffset(0, 10).rotateX(((float)Math.PI / 2F)).endCuboid()
.cuboid().invertYZ().start(-8, y, -10).size(16, 8, 2).rotateY(((float)Math.PI * 1.5F)).endCuboid() .cuboid().invertYZ().start(-8, y, -10).size(16, 8, 2).rotateY(((float)Math.PI * 1.5F)).endCuboid()
.cuboid().invertYZ().start(-8, y, -10).size(16, 8, 2).rotateY(((float)Math.PI / 2F)).endCuboid() .cuboid().invertYZ().start(-8, y, -10).size(16, 8, 2).rotateY(((float)Math.PI / 2F)).endCuboid()

View file

@ -101,7 +101,7 @@ public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity
} }
private ModelPart makeBaseModel() { private ModelPart makeBaseModel() {
return ModelPart.builder(64, 64) return ModelPart.builder("shulker_base", 64, 64)
.sprite(texture) .sprite(texture)
.cuboid() .cuboid()
.textureOffset(0, 28) .textureOffset(0, 28)
@ -112,7 +112,7 @@ public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity
} }
private ModelPart makeLidModel() { private ModelPart makeLidModel() {
return ModelPart.builder(64, 64) return ModelPart.builder("shulker_lid", 64, 64)
.sprite(texture) .sprite(texture)
.cuboid() .cuboid()
.size(16, 12, 16) .size(16, 12, 16)