diff --git a/src/main/java/com/jozufozu/flywheel/api/model/Mesh.java b/src/main/java/com/jozufozu/flywheel/api/model/Mesh.java index 48cded4a5..4c7d3bd58 100644 --- a/src/main/java/com/jozufozu/flywheel/api/model/Mesh.java +++ b/src/main/java/com/jozufozu/flywheel/api/model/Mesh.java @@ -28,8 +28,7 @@ public interface Mesh { * The size in bytes that this mesh's data takes up. */ default int size() { - return vertexType().getLayout() - .getStride() * vertexCount(); + return vertexType().getStride() * vertexCount(); } /** diff --git a/src/main/java/com/jozufozu/flywheel/api/vertex/VertexType.java b/src/main/java/com/jozufozu/flywheel/api/vertex/VertexType.java index 8ade48a11..38371e769 100644 --- a/src/main/java/com/jozufozu/flywheel/api/vertex/VertexType.java +++ b/src/main/java/com/jozufozu/flywheel/api/vertex/VertexType.java @@ -1,24 +1,16 @@ package com.jozufozu.flywheel.api.vertex; import com.jozufozu.flywheel.api.layout.BufferLayout; -import com.jozufozu.flywheel.api.registry.Registry; -import com.jozufozu.flywheel.impl.RegistryImpl; - -import net.minecraft.resources.ResourceLocation; /** * A vertex type containing metadata about a specific vertex layout. */ public interface VertexType extends VertexListProvider { - static Registry REGISTRY = RegistryImpl.create(); - /** * The layout of this type of vertex when buffered. */ BufferLayout getLayout(); - ResourceLocation layoutShader(); - default int getStride() { return getLayout().getStride(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/FlwPrograms.java b/src/main/java/com/jozufozu/flywheel/backend/compile/FlwPrograms.java index cfa623c10..2519c67d5 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/FlwPrograms.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/FlwPrograms.java @@ -7,7 +7,6 @@ import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.context.Context; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.uniform.ShaderUniforms; -import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.backend.ShaderIndices; import com.jozufozu.flywheel.backend.compile.component.UberShaderComponent; import com.jozufozu.flywheel.backend.compile.component.UniformComponent; @@ -99,12 +98,9 @@ public class FlwPrograms { private static ImmutableList createPipelineKeys() { ImmutableList.Builder builder = ImmutableList.builder(); - // TODO: ubershader'd contexts? for (Context context : Context.REGISTRY) { for (InstanceType instanceType : InstanceType.REGISTRY) { - for (VertexType vertexType : VertexType.REGISTRY) { - builder.add(new PipelineProgramKey(vertexType, instanceType, context)); - } + builder.add(new PipelineProgramKey(instanceType, context)); } } return builder.build(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java b/src/main/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java index 437e91372..b0507561b 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java @@ -9,7 +9,6 @@ import com.google.common.collect.ImmutableList; import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.context.Context; import com.jozufozu.flywheel.api.instance.InstanceType; -import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.backend.compile.component.IndirectComponent; import com.jozufozu.flywheel.backend.compile.component.UniformComponent; import com.jozufozu.flywheel.gl.GlCompat; @@ -89,8 +88,8 @@ public class IndirectPrograms { .build(); } - public GlProgram getIndirectProgram(VertexType vertexType, InstanceType instanceType, Context contextShader) { - return pipeline.get(new PipelineProgramKey(vertexType, instanceType, contextShader)); + public GlProgram getIndirectProgram(InstanceType instanceType, Context contextShader) { + return pipeline.get(new PipelineProgramKey(instanceType, contextShader)); } public GlProgram getCullingProgram(InstanceType instanceType) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java b/src/main/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java index 332679893..42885213e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java @@ -9,7 +9,6 @@ import com.google.common.collect.ImmutableList; import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.context.Context; import com.jozufozu.flywheel.api.instance.InstanceType; -import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.backend.compile.component.UniformComponent; import com.jozufozu.flywheel.gl.shader.GlProgram; import com.jozufozu.flywheel.glsl.ShaderSources; @@ -55,8 +54,8 @@ public class InstancingPrograms { } } - public GlProgram get(VertexType vertexType, InstanceType instanceType, Context contextShader) { - return pipeline.get(new PipelineProgramKey(vertexType, instanceType, contextShader)); + public GlProgram get(InstanceType instanceType, Context contextShader) { + return pipeline.get(new PipelineProgramKey(instanceType, contextShader)); } public void delete() { diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/Pipeline.java b/src/main/java/com/jozufozu/flywheel/backend/compile/Pipeline.java index b8839ad00..9f9ba6b93 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/Pipeline.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/Pipeline.java @@ -3,7 +3,6 @@ package com.jozufozu.flywheel.backend.compile; import java.util.Objects; import com.jozufozu.flywheel.api.instance.InstanceType; -import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.glsl.GLSLVersion; import com.jozufozu.flywheel.glsl.SourceComponent; @@ -21,7 +20,7 @@ public record Pipeline(GLSLVersion glslVersion, ResourceLocation vertexShader, R SourceComponent assemble(InstanceAssemblerContext context); } - public record InstanceAssemblerContext(VertexType vertexType, InstanceType instanceType) { + public record InstanceAssemblerContext(int baseAttribute, InstanceType instanceType) { } public static Builder builder() { diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java b/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java index d64d1a180..0f710ea7d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java @@ -7,6 +7,7 @@ import com.jozufozu.flywheel.backend.compile.component.UniformComponent; import com.jozufozu.flywheel.gl.shader.ShaderType; import com.jozufozu.flywheel.glsl.ShaderSources; import com.jozufozu.flywheel.glsl.SourceComponent; +import com.jozufozu.flywheel.lib.vertex.BlockVertex; public class PipelineCompiler { private static final Compile PIPELINE = new Compile<>(); @@ -18,11 +19,9 @@ public class PipelineCompiler { .link(PIPELINE.shader(pipeline.glslVersion(), ShaderType.VERTEX) .withComponent(uniformComponent) .withComponent(key -> pipeline.assembler() - .assemble(new Pipeline.InstanceAssemblerContext(key.vertexType(), key.instanceType()))) + .assemble(new Pipeline.InstanceAssemblerContext(BlockVertex.FORMAT.getAttributeCount(), key.instanceType()))) .withResource(pipeline.vertexAPI()) .withComponents(vertexComponents) - .withResource(key -> key.vertexType() - .layoutShader()) .withResource(key -> key.instanceType() .instanceShader()) .withResource(key -> key.contextShader() diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineProgramKey.java b/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineProgramKey.java index 9cceab7da..57050a0b3 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineProgramKey.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineProgramKey.java @@ -2,14 +2,12 @@ package com.jozufozu.flywheel.backend.compile; import com.jozufozu.flywheel.api.context.Context; import com.jozufozu.flywheel.api.instance.InstanceType; -import com.jozufozu.flywheel.api.vertex.VertexType; /** * Represents the entire context of a program's usage. * - * @param vertexType The vertex type the program should be adapted for. * @param instanceType The instance shader to use. * @param contextShader The context shader to use. */ -public record PipelineProgramKey(VertexType vertexType, InstanceType instanceType, Context contextShader) { +public record PipelineProgramKey(InstanceType instanceType, Context contextShader) { } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/component/InstancedArraysComponent.java b/src/main/java/com/jozufozu/flywheel/backend/compile/component/InstancedArraysComponent.java index ccb7f6a9d..cd9e29f59 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/component/InstancedArraysComponent.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/component/InstancedArraysComponent.java @@ -26,9 +26,7 @@ public class InstancedArraysComponent implements SourceComponent { public InstancedArraysComponent(Pipeline.InstanceAssemblerContext ctx) { this.layoutItems = ctx.instanceType() .getLayout().layoutItems; - this.baseIndex = ctx.vertexType() - .getLayout() - .getAttributeCount(); + this.baseIndex = ctx.baseAttribute(); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectCullingGroup.java b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectCullingGroup.java index 05109caf5..d5992d9b3 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectCullingGroup.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectCullingGroup.java @@ -10,7 +10,6 @@ import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.material.Material; import com.jozufozu.flywheel.api.model.Mesh; -import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.backend.compile.IndirectPrograms; import com.jozufozu.flywheel.backend.engine.UniformBuffer; import com.jozufozu.flywheel.gl.shader.GlProgram; @@ -29,7 +28,7 @@ public class IndirectCullingGroup { private boolean needsMemoryBarrier; private int instanceCountThisFrame; - IndirectCullingGroup(InstanceType instanceType, VertexType vertexType) { + IndirectCullingGroup(InstanceType instanceType) { objectStride = instanceType.getLayout() .getStride() + IndirectBuffers.INT_SIZE; @@ -38,11 +37,11 @@ public class IndirectCullingGroup { buffers.createObjectStorage(128); buffers.createDrawStorage(2); - meshPool = new IndirectMeshPool(vertexType); + meshPool = new IndirectMeshPool(); var indirectPrograms = IndirectPrograms.get(); compute = indirectPrograms.getCullingProgram(instanceType); - draw = indirectPrograms.getIndirectProgram(vertexType, instanceType, Contexts.WORLD); + draw = indirectPrograms.getIndirectProgram(instanceType, Contexts.WORLD); } public void add(IndirectInstancer instancer, RenderStage stage, Material material, Mesh mesh) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawManager.java b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawManager.java index 81cc538b7..097021e3c 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawManager.java @@ -7,13 +7,11 @@ import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.model.Model; -import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.backend.engine.InstancerKey; import com.jozufozu.flywheel.backend.engine.InstancerStorage; -import com.jozufozu.flywheel.lib.util.Pair; public class IndirectDrawManager extends InstancerStorage> { - public final Map, VertexType>, IndirectCullingGroup> renderLists = new HashMap<>(); + public final Map, IndirectCullingGroup> renderLists = new HashMap<>(); @Override protected IndirectInstancer create(InstanceType type) { @@ -27,7 +25,7 @@ public class IndirectDrawManager extends InstancerStorage> var material = entry.getKey(); var mesh = entry.getValue(); - var indirectList = (IndirectCullingGroup) renderLists.computeIfAbsent(Pair.of(key.type(), mesh.vertexType()), p -> new IndirectCullingGroup<>(p.first(), p.second())); + var indirectList = (IndirectCullingGroup) renderLists.computeIfAbsent(key.type(), IndirectCullingGroup::new); indirectList.add((IndirectInstancer) instancer, stage, material, mesh); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectMeshPool.java b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectMeshPool.java index 2472d0c96..ef665e870 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectMeshPool.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectMeshPool.java @@ -16,9 +16,11 @@ import com.jozufozu.flywheel.gl.array.GlVertexArray; import com.jozufozu.flywheel.gl.buffer.GlBuffer; import com.jozufozu.flywheel.lib.memory.MemoryBlock; import com.jozufozu.flywheel.lib.model.QuadIndexSequence; +import com.jozufozu.flywheel.lib.vertex.BlockVertexList; +import com.jozufozu.flywheel.lib.vertex.VertexTypes; public class IndirectMeshPool { - private final VertexType vertexType; + private static final VertexType VERTEX_TYPE = VertexTypes.BLOCK; private final Map meshes = new HashMap<>(); private final List meshList = new ArrayList<>(); @@ -32,20 +34,19 @@ public class IndirectMeshPool { /** * Create a new mesh pool. */ - public IndirectMeshPool(VertexType type) { - vertexType = type; + public IndirectMeshPool() { vbo = new GlBuffer(); ebo = new GlBuffer(); vertexArray = GlVertexArray.create(); vertexArray.setElementBuffer(ebo.handle()); - BufferLayout layout = vertexType.getLayout(); + BufferLayout layout = VERTEX_TYPE.getLayout(); vertexArray.bindVertexBuffer(0, vbo.handle(), 0, layout.getStride()); vertexArray.bindAttributes(0, 0, layout.attributes()); } public VertexType getVertexType() { - return vertexType; + return VERTEX_TYPE; } /** @@ -98,6 +99,8 @@ public class IndirectMeshPool { final long vertexPtr = vertexBlock.ptr(); final long indexPtr = indexBlock.ptr(); + var target = new BlockVertexList(); + int byteIndex = 0; int baseVertex = 0; int firstIndex = maxQuadIndexCount; @@ -105,7 +108,8 @@ public class IndirectMeshPool { mesh.byteIndex = byteIndex; mesh.baseVertex = baseVertex; - mesh.buffer(vertexPtr); + target.ptr(vertexPtr + mesh.byteIndex); + mesh.mesh.write(target); byteIndex += mesh.size(); baseVertex += mesh.mesh.vertexCount(); @@ -156,17 +160,13 @@ public class IndirectMeshPool { } public int size() { - return mesh.size(); + return mesh.vertexCount() * VERTEX_TYPE.getStride(); } public int indexCount() { return mesh.indexCount(); } - private void buffer(long ptr) { - mesh.write(ptr + byteIndex); - } - public Vector4fc boundingSphere() { return mesh.boundingSphere(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedCrumbling.java b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedCrumbling.java index 919769a21..73f540cb6 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedCrumbling.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedCrumbling.java @@ -57,7 +57,7 @@ public class InstancedCrumbling { .cutout(CutoutShaders.OFF); var program = InstancingPrograms.get() - .get(shader.vertexType(), shader.instanceType(), Contexts.CRUMBLING); + .get(shader.instanceType(), Contexts.CRUMBLING); UniformBuffer.syncAndBind(program); InstancingEngine.uploadMaterialIDUniform(program, crumblingMaterial); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java index 3d8a4a407..c50946dfd 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java @@ -2,7 +2,6 @@ package com.jozufozu.flywheel.backend.engine.instancing; import java.util.Collection; import java.util.EnumMap; -import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -16,7 +15,6 @@ import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.model.Mesh; import com.jozufozu.flywheel.api.model.Model; -import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.backend.engine.InstancerKey; import com.jozufozu.flywheel.backend.engine.InstancerStorage; @@ -28,7 +26,7 @@ public class InstancedDrawManager extends InstancerStorage /** * A map of vertex types to their mesh pools. */ - private final Map meshPools = new HashMap<>(); + private final InstancedMeshPool meshPool = new InstancedMeshPool(); private final EBOCache eboCache = new EBOCache(); public DrawSet get(RenderStage stage) { @@ -38,17 +36,13 @@ public class InstancedDrawManager extends InstancerStorage public void flush() { super.flush(); - for (var pool : meshPools.values()) { - pool.flush(); - } + meshPool.flush(); } public void invalidate() { super.invalidate(); - meshPools.values() - .forEach(InstancedMeshPool::delete); - meshPools.clear(); + meshPool.delete(); drawSets.values() .forEach(DrawSet::delete); @@ -58,8 +52,7 @@ public class InstancedDrawManager extends InstancerStorage } private InstancedMeshPool.BufferedMesh alloc(Mesh mesh) { - return meshPools.computeIfAbsent(mesh.vertexType(), InstancedMeshPool::new) - .alloc(mesh, eboCache); + return meshPool.alloc(mesh, eboCache); } @Override @@ -77,7 +70,7 @@ public class InstancedDrawManager extends InstancerStorage for (var entry : meshes.entrySet()) { var mesh = alloc(entry.getValue()); - ShaderState shaderState = new ShaderState(entry.getKey(), mesh.getVertexType(), instancer.type); + ShaderState shaderState = new ShaderState(entry.getKey(), instancer.type); DrawCall drawCall = new DrawCall(instancer, mesh, shaderState); drawSet.put(shaderState, drawCall); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedMeshPool.java b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedMeshPool.java index 42aa24103..4ceb6655b 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedMeshPool.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedMeshPool.java @@ -18,9 +18,10 @@ import com.jozufozu.flywheel.gl.GlPrimitive; import com.jozufozu.flywheel.gl.array.GlVertexArray; import com.jozufozu.flywheel.gl.buffer.GlBuffer; import com.jozufozu.flywheel.gl.buffer.MappedBuffer; +import com.jozufozu.flywheel.lib.vertex.VertexTypes; public class InstancedMeshPool { - private final VertexType vertexType; + private static final VertexType VERTEX_TYPE = VertexTypes.BLOCK; private final Map meshes = new HashMap<>(); private final List allBuffered = new ArrayList<>(); @@ -35,15 +36,15 @@ public class InstancedMeshPool { /** * Create a new mesh pool. */ - public InstancedMeshPool(VertexType vertexType) { - this.vertexType = vertexType; - int stride = vertexType.getLayout().getStride(); + public InstancedMeshPool() { + int stride = VERTEX_TYPE.getLayout() + .getStride(); vbo = new GlBuffer(); vbo.growthFunction(l -> Math.max(l + stride * 128L, (long) (l * 1.6))); } public VertexType getVertexType() { - return vertexType; + return VERTEX_TYPE; } /** @@ -55,10 +56,6 @@ public class InstancedMeshPool { */ public BufferedMesh alloc(Mesh mesh, EBOCache eboCache) { return meshes.computeIfAbsent(mesh, m -> { - if (m.vertexType() != vertexType) { - throw new IllegalArgumentException("Mesh has wrong vertex type"); - } - BufferedMesh bufferedMesh = new BufferedMesh(m, byteSize, eboCache); byteSize += bufferedMesh.size(); allBuffered.add(bufferedMesh); @@ -121,8 +118,12 @@ public class InstancedMeshPool { try (MappedBuffer mapped = vbo.map()) { long ptr = mapped.ptr(); + var vertexList = VERTEX_TYPE.createVertexList(); + for (BufferedMesh mesh : pendingUpload) { - mesh.buffer(ptr); + vertexList.ptr(ptr + mesh.byteIndex); + mesh.mesh.write(vertexList); + mesh.boundTo.clear(); } pendingUpload.clear(); @@ -140,7 +141,7 @@ public class InstancedMeshPool { @Override public String toString() { - return "InstancedMeshPool{" + "vertexType=" + vertexType + ", byteSize=" + byteSize + ", meshCount=" + meshes.size() + '}'; + return "InstancedMeshPool{" + "vertexType=" + VERTEX_TYPE + ", byteSize=" + byteSize + ", meshCount=" + meshes.size() + '}'; } public class BufferedMesh { @@ -158,15 +159,16 @@ public class InstancedMeshPool { } public int size() { - return mesh.size(); + return mesh.vertexCount() * VERTEX_TYPE.getStride(); } public VertexType getVertexType() { - return vertexType; + return VERTEX_TYPE; } public int getAttributeCount() { - return vertexType.getLayout().getAttributeCount(); + return VERTEX_TYPE.getLayout() + .getAttributeCount(); } public boolean isDeleted() { @@ -177,15 +179,9 @@ public class InstancedMeshPool { return mesh.isEmpty() || isDeleted(); } - private void buffer(long ptr) { - mesh.write(ptr + byteIndex); - - boundTo.clear(); - } - public void setup(GlVertexArray vao) { if (boundTo.add(vao)) { - BufferLayout type = vertexType.getLayout(); + BufferLayout type = VERTEX_TYPE.getLayout(); vao.bindVertexBuffer(0, InstancedMeshPool.this.vbo.handle(), byteIndex, type.getStride()); vao.bindAttributes(0, 0, type.attributes()); vao.setElementBuffer(ebo); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancingEngine.java b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancingEngine.java index 540c87858..da3627e40 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancingEngine.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancingEngine.java @@ -109,7 +109,7 @@ public class InstancingEngine extends AbstractEngine { } var program = InstancingPrograms.get() - .get(shader.vertexType(), shader.instanceType(), Contexts.WORLD); + .get(shader.instanceType(), Contexts.WORLD); UniformBuffer.syncAndBind(program); uploadMaterialIDUniform(program, shader.material()); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/ShaderState.java b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/ShaderState.java index 9a2645fc6..28b4955eb 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/ShaderState.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/ShaderState.java @@ -2,7 +2,6 @@ package com.jozufozu.flywheel.backend.engine.instancing; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.material.Material; -import com.jozufozu.flywheel.api.vertex.VertexType; -public record ShaderState(Material material, VertexType vertexType, InstanceType instanceType) { +public record ShaderState(Material material, InstanceType instanceType) { } diff --git a/src/main/java/com/jozufozu/flywheel/lib/vertex/BlockVertex.java b/src/main/java/com/jozufozu/flywheel/lib/vertex/BlockVertex.java index 8728b8b40..2c2aa7a6d 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/vertex/BlockVertex.java +++ b/src/main/java/com/jozufozu/flywheel/lib/vertex/BlockVertex.java @@ -4,8 +4,6 @@ import com.jozufozu.flywheel.api.layout.BufferLayout; import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.lib.layout.CommonItems; -import net.minecraft.resources.ResourceLocation; - public class BlockVertex implements VertexType { public static final BufferLayout FORMAT = BufferLayout.builder() .addItem(CommonItems.VEC3, "position") @@ -21,11 +19,6 @@ public class BlockVertex implements VertexType { return FORMAT; } - @Override - public ResourceLocation layoutShader() { - return VertexTypes.Files.BLOCK_LAYOUT; - } - @Override public BlockVertexList createVertexList() { return new BlockVertexList(); diff --git a/src/main/java/com/jozufozu/flywheel/lib/vertex/PosTexNormalVertex.java b/src/main/java/com/jozufozu/flywheel/lib/vertex/PosTexNormalVertex.java index 97dc56745..be92aca18 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/vertex/PosTexNormalVertex.java +++ b/src/main/java/com/jozufozu/flywheel/lib/vertex/PosTexNormalVertex.java @@ -4,8 +4,6 @@ import com.jozufozu.flywheel.api.layout.BufferLayout; import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.lib.layout.CommonItems; -import net.minecraft.resources.ResourceLocation; - public class PosTexNormalVertex implements VertexType { public static final BufferLayout FORMAT = BufferLayout.builder() .addItem(CommonItems.VEC3, "position") @@ -18,11 +16,6 @@ public class PosTexNormalVertex implements VertexType { return FORMAT; } - @Override - public ResourceLocation layoutShader() { - return VertexTypes.Files.POS_TEX_NORMAL_LAYOUT; - } - @Override public PosTexNormalVertexList createVertexList() { return new PosTexNormalVertexList(); diff --git a/src/main/java/com/jozufozu/flywheel/lib/vertex/VertexTypes.java b/src/main/java/com/jozufozu/flywheel/lib/vertex/VertexTypes.java index 32eed8307..3dbe71301 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/vertex/VertexTypes.java +++ b/src/main/java/com/jozufozu/flywheel/lib/vertex/VertexTypes.java @@ -2,14 +2,9 @@ package com.jozufozu.flywheel.lib.vertex; import org.jetbrains.annotations.ApiStatus; -import com.jozufozu.flywheel.Flywheel; -import com.jozufozu.flywheel.api.vertex.VertexType; - -import net.minecraft.resources.ResourceLocation; - public final class VertexTypes { - public static final BlockVertex BLOCK = VertexType.REGISTRY.registerAndGet(new BlockVertex()); - public static final PosTexNormalVertex POS_TEX_NORMAL = VertexType.REGISTRY.registerAndGet(new PosTexNormalVertex()); + public static final BlockVertex BLOCK = new BlockVertex(); + public static final PosTexNormalVertex POS_TEX_NORMAL = new PosTexNormalVertex(); private VertexTypes() { } @@ -17,14 +12,4 @@ public final class VertexTypes { @ApiStatus.Internal public static void init() { } - - public static final class Files { - public static final ResourceLocation BLOCK_LAYOUT = Names.BLOCK.withSuffix(".vert"); - public static final ResourceLocation POS_TEX_NORMAL_LAYOUT = Names.POS_TEX_NORMAL.withSuffix(".vert"); - } - - public static final class Names { - public static final ResourceLocation BLOCK = Flywheel.rl("layout/block"); - public static final ResourceLocation POS_TEX_NORMAL = Flywheel.rl("layout/pos_tex_normal"); - } } diff --git a/src/main/resources/assets/flywheel/flywheel/api/vertex.glsl b/src/main/resources/assets/flywheel/flywheel/api/vertex.glsl index 8e944eec3..5282cbfe2 100644 --- a/src/main/resources/assets/flywheel/flywheel/api/vertex.glsl +++ b/src/main/resources/assets/flywheel/flywheel/api/vertex.glsl @@ -16,9 +16,6 @@ vec4 flw_var3; /*const*/ FlwMaterial flw_material; -// To be implemented by the layout shader. -void flw_layoutVertex(); - // To be implemented by the instance shader. void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout float radius); void flw_instanceVertex(FlwInstance i); diff --git a/src/main/resources/assets/flywheel/flywheel/layout/block.vert b/src/main/resources/assets/flywheel/flywheel/internal/block.vert similarity index 94% rename from src/main/resources/assets/flywheel/flywheel/layout/block.vert rename to src/main/resources/assets/flywheel/flywheel/internal/block.vert index cbf38fe42..0de7f32f1 100644 --- a/src/main/resources/assets/flywheel/flywheel/layout/block.vert +++ b/src/main/resources/assets/flywheel/flywheel/internal/block.vert @@ -6,7 +6,7 @@ layout(location = 2) in vec2 _flw_v_texCoord; layout(location = 3) in ivec2 _flw_v_light; layout(location = 4) in vec3 _flw_v_normal; -void flw_layoutVertex() { +void _flw_layoutVertex() { flw_vertexPos = vec4(_flw_v_pos, 1.0); flw_vertexColor = _flw_v_color; flw_vertexTexCoord = _flw_v_texCoord; diff --git a/src/main/resources/assets/flywheel/flywheel/internal/indirect/draw.vert b/src/main/resources/assets/flywheel/flywheel/internal/indirect/draw.vert index 6fdd63539..b51bdfd9c 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/indirect/draw.vert +++ b/src/main/resources/assets/flywheel/flywheel/internal/indirect/draw.vert @@ -1,6 +1,7 @@ #include "flywheel:internal/indirect/api/vertex.glsl" #include "flywheel:internal/indirect/mesh.glsl" #include "flywheel:internal/material.glsl" +#include "flywheel:internal/block.vert" #include "flywheel:util/diffuse.glsl" flat out uvec3 _flw_material; @@ -33,7 +34,7 @@ void main() { _flw_unpackMaterial(p, flw_material); _flw_material = uvec3(drawCommands[batchID].fragmentMaterialID, drawCommands[batchID].packedFogAndCutout, p); - flw_layoutVertex(); + _flw_layoutVertex(); flw_beginVertex(); flw_instanceVertex(i); flw_materialVertex(); diff --git a/src/main/resources/assets/flywheel/flywheel/internal/instancing/draw.vert b/src/main/resources/assets/flywheel/flywheel/internal/instancing/draw.vert index 78dd570b3..d87477b00 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/instancing/draw.vert +++ b/src/main/resources/assets/flywheel/flywheel/internal/instancing/draw.vert @@ -1,5 +1,6 @@ #include "flywheel:internal/instancing/api/vertex.glsl" #include "flywheel:internal/material.glsl" +#include "flywheel:internal/block.vert" #include "flywheel:util/diffuse.glsl" uniform uvec4 _flw_material_instancing; @@ -11,7 +12,7 @@ void main() { FlwInstance i = _flw_unpackInstance(); - flw_layoutVertex(); + _flw_layoutVertex(); flw_beginVertex(); flw_instanceVertex(i); flw_materialVertex(); diff --git a/src/main/resources/assets/flywheel/flywheel/layout/pos_tex_normal.vert b/src/main/resources/assets/flywheel/flywheel/layout/pos_tex_normal.vert deleted file mode 100644 index 271cd2608..000000000 --- a/src/main/resources/assets/flywheel/flywheel/layout/pos_tex_normal.vert +++ /dev/null @@ -1,14 +0,0 @@ -#include "flywheel:api/vertex.glsl" - -layout(location = 0) in vec3 _flw_v_pos; -layout(location = 1) in vec2 _flw_v_texCoord; -layout(location = 2) in vec3 _flw_v_normal; - -void flw_layoutVertex() { - flw_vertexPos = vec4(_flw_v_pos, 1.0); - flw_vertexColor = vec4(1.0); - flw_vertexTexCoord = _flw_v_texCoord; - flw_vertexOverlay = ivec2(0, 10); - flw_vertexLight = vec2(1.0); - flw_vertexNormal = _flw_v_normal; -}