mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 23:47:09 +01:00
Named models
This commit is contained in:
parent
35b542fb68
commit
1d4bb972b9
14 changed files with 79 additions and 26 deletions
|
@ -1,5 +1,7 @@
|
|||
package com.jozufozu.flywheel.backend.gl.error;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
|
@ -35,4 +37,11 @@ public enum GlError {
|
|||
public static GlError poll() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.GlBufferType;
|
||||
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.ModelAllocator;
|
||||
import com.jozufozu.flywheel.backend.struct.StructType;
|
||||
|
@ -73,14 +74,22 @@ public class GPUInstancer<D extends InstanceData> implements Instancer<D> {
|
|||
if (invalid()) return;
|
||||
|
||||
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
|
||||
instanceVBO.doneForThisFrame();
|
||||
|
||||
vao.unbind();
|
||||
|
||||
GlError.pollAndThrow(() -> modelData.name() + "_unbind");
|
||||
}
|
||||
|
||||
private boolean invalid() {
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.jozufozu.flywheel.backend.gl.error.GlError;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstanceData;
|
||||
import com.jozufozu.flywheel.backend.state.IRenderState;
|
||||
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) {
|
||||
for (MaterialRenderer<P> renderer : renderers) {
|
||||
renderer.render(viewProjection, camX, camY, camZ);
|
||||
|
||||
GlError.pollAndThrow(renderer.material.spec.name::toString);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public enum BooleanConfig {
|
|||
if (player == null || state == null) return;
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public enum BooleanConfig {
|
|||
|
||||
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);
|
||||
|
||||
player.displayClientMessage(cannotUse ? error : text, false);
|
||||
|
@ -60,14 +60,14 @@ public enum BooleanConfig {
|
|||
if (player == null || state == null) return;
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -78,14 +78,14 @@ public enum BooleanConfig {
|
|||
if (player == null || state == null) return;
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
Backend.reloadWorldRenderers();
|
||||
|
|
|
@ -56,6 +56,11 @@ public class BakedModelModel implements IModel {
|
|||
this.numQuads = numQuads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return model.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buffer(VecBuffer buffer) {
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@ package com.jozufozu.flywheel.core.model;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
|
||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||
import com.jozufozu.flywheel.core.Formats;
|
||||
|
@ -30,6 +28,8 @@ public class BlockModel implements IModel {
|
|||
|
||||
private final BufferBuilderReader reader;
|
||||
|
||||
private final String name;
|
||||
|
||||
public BlockModel(BlockState state) {
|
||||
this(Minecraft.getInstance()
|
||||
.getBlockRenderer()
|
||||
|
@ -42,6 +42,12 @@ public class BlockModel implements IModel {
|
|||
|
||||
public BlockModel(BakedModel model, BlockState referenceState, PoseStack ms) {
|
||||
reader = new BufferBuilderReader(getBufferBuilder(model, referenceState, ms));
|
||||
name = referenceState.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,6 +27,11 @@ import com.jozufozu.flywheel.core.QuadConverter;
|
|||
*/
|
||||
public interface IModel {
|
||||
|
||||
/**
|
||||
* A name uniquely identifying this model.
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Copy this model into the given buffer.
|
||||
*/
|
||||
|
|
|
@ -10,9 +10,11 @@ public class ModelPart implements IModel {
|
|||
|
||||
private final List<PartBuilder.CuboidBuilder> cuboids;
|
||||
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.name = name;
|
||||
|
||||
vertices = 0;
|
||||
|
||||
|
@ -21,8 +23,13 @@ public class ModelPart implements IModel {
|
|||
}
|
||||
}
|
||||
|
||||
public static PartBuilder builder(int sizeU, int sizeV) {
|
||||
return new PartBuilder(sizeU, sizeV);
|
||||
public static PartBuilder builder(String name, int sizeU, int sizeV) {
|
||||
return new PartBuilder(name, sizeU, sizeV);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,8 +23,10 @@ public class PartBuilder {
|
|||
private TextureAtlasSprite sprite;
|
||||
|
||||
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.sizeV = (float) sizeV;
|
||||
}
|
||||
|
@ -39,7 +41,7 @@ public class PartBuilder {
|
|||
}
|
||||
|
||||
public ModelPart build() {
|
||||
return new ModelPart(cuboids);
|
||||
return new ModelPart(cuboids, name);
|
||||
}
|
||||
|
||||
private PartBuilder addCuboid(CuboidBuilder builder) {
|
||||
|
|
|
@ -15,9 +15,16 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemp
|
|||
public class WorldModel implements IModel {
|
||||
|
||||
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));
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -64,7 +64,7 @@ public class BellInstance extends TileEntityInstance<BellBlockEntity> implements
|
|||
}
|
||||
|
||||
private static ModelPart createBellModel() {
|
||||
return ModelPart.builder(32, 32)
|
||||
return ModelPart.builder("bell", 32, 32)
|
||||
.sprite(BellRenderer.BELL_RESOURCE_LOCATION.sprite())
|
||||
.cuboid()
|
||||
.start(5.0F, 6.0F, 5.0F)
|
||||
|
|
|
@ -137,7 +137,7 @@ public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends TileE
|
|||
|
||||
switch (chestType) {
|
||||
case LEFT:
|
||||
return ModelPart.builder(64, 64)
|
||||
return ModelPart.builder("chest_base_left", 64, 64)
|
||||
.sprite(renderMaterial.sprite())
|
||||
.cuboid()
|
||||
.textureOffset(0, 19)
|
||||
|
@ -146,7 +146,7 @@ public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends TileE
|
|||
.endCuboid()
|
||||
.build();
|
||||
case RIGHT:
|
||||
return ModelPart.builder(64, 64)
|
||||
return ModelPart.builder("chest_base_right", 64, 64)
|
||||
.sprite(renderMaterial.sprite())
|
||||
.cuboid()
|
||||
.textureOffset(0, 19)
|
||||
|
@ -156,7 +156,7 @@ public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends TileE
|
|||
.build();
|
||||
}
|
||||
|
||||
return ModelPart.builder(64, 64)
|
||||
return ModelPart.builder("chest_base", 64, 64)
|
||||
.sprite(renderMaterial.sprite())
|
||||
.cuboid()
|
||||
.textureOffset(0, 19)
|
||||
|
@ -170,7 +170,7 @@ public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends TileE
|
|||
|
||||
switch (chestType) {
|
||||
case LEFT:
|
||||
return ModelPart.builder(64, 64)
|
||||
return ModelPart.builder("chest_lid_left", 64, 64)
|
||||
.sprite(renderMaterial.sprite())
|
||||
.cuboid()
|
||||
.textureOffset(0, 0)
|
||||
|
@ -183,7 +183,7 @@ public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends TileE
|
|||
.endCuboid()
|
||||
.build();
|
||||
case RIGHT:
|
||||
return ModelPart.builder(64, 64)
|
||||
return ModelPart.builder("chest_lid_right", 64, 64)
|
||||
.sprite(renderMaterial.sprite())
|
||||
.cuboid()
|
||||
.textureOffset(0, 0)
|
||||
|
@ -197,7 +197,7 @@ public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends TileE
|
|||
.build();
|
||||
}
|
||||
|
||||
return ModelPart.builder(64, 64)
|
||||
return ModelPart.builder("chest_lid", 64, 64)
|
||||
.sprite(renderMaterial.sprite())
|
||||
.cuboid()
|
||||
.textureOffset(0, 0)
|
||||
|
|
|
@ -155,7 +155,7 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
|
|||
|
||||
private IModel getBodyModel() {
|
||||
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(-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()
|
||||
|
|
|
@ -101,7 +101,7 @@ public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity
|
|||
}
|
||||
|
||||
private ModelPart makeBaseModel() {
|
||||
return ModelPart.builder(64, 64)
|
||||
return ModelPart.builder("shulker_base", 64, 64)
|
||||
.sprite(texture)
|
||||
.cuboid()
|
||||
.textureOffset(0, 28)
|
||||
|
@ -112,7 +112,7 @@ public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity
|
|||
}
|
||||
|
||||
private ModelPart makeLidModel() {
|
||||
return ModelPart.builder(64, 64)
|
||||
return ModelPart.builder("shulker_lid", 64, 64)
|
||||
.sprite(texture)
|
||||
.cuboid()
|
||||
.size(16, 12, 16)
|
||||
|
|
Loading…
Reference in a new issue