Untyped vertices

- Remove VertexType
- Rename ReusableVertexList to VertexView and all associated classes,
methods, fields, and variables
- Add VertexView#stride
- Make vertex compiler automatically include layout shader
- Fix instancing and indirect not setting correct vertex count before
writing mesh
This commit is contained in:
PepperCode1 2023-12-07 16:49:12 -08:00
parent cba04adc91
commit 1def0876d8
50 changed files with 556 additions and 717 deletions

View file

@ -40,6 +40,14 @@ public interface VertexList {
float normalZ(int index);
default Vector4f getPos(int i, Vector4f dest) {
return dest.set(x(i), y(i), z(i));
}
default Vector3f getNormal(int i, Vector3f dest) {
return dest.set(normalX(i), normalY(i), normalZ(i));
}
default void write(MutableVertexList dst, int srcIndex, int dstIndex) {
dst.x(dstIndex, x(srcIndex));
dst.y(dstIndex, y(srcIndex));
@ -68,7 +76,7 @@ public interface VertexList {
}
default void writeAll(MutableVertexList dst) {
write(dst, 0, 0, vertexCount());
write(dst, 0, 0, Math.min(vertexCount(), dst.vertexCount()));
}
int vertexCount();
@ -76,12 +84,4 @@ public interface VertexList {
default boolean isEmpty() {
return vertexCount() == 0;
}
default Vector3f getNormal(int i, Vector3f dest) {
return dest.set(normalX(i), normalY(i), normalZ(i));
}
default Vector4f getPos(int i, Vector4f dest) {
return dest.set(x(i), y(i), z(i));
}
}

View file

@ -1,5 +0,0 @@
package com.jozufozu.flywheel.api.vertex;
public interface VertexListProvider {
ReusableVertexList createVertexList();
}

View file

@ -1,16 +0,0 @@
package com.jozufozu.flywheel.api.vertex;
/**
* A vertex type containing metadata about a specific vertex layout.
*/
// TODO: query a bitset of vertex attributes that are used?
public interface VertexType extends VertexListProvider {
/**
* The byte size of a single vertex.
*/
int getStride();
default int byteOffset(int vertexIndex) {
return getStride() * vertexIndex;
}
}

View file

@ -1,9 +1,11 @@
package com.jozufozu.flywheel.api.vertex;
public interface ReusableVertexList extends MutableVertexList {
public interface VertexView extends MutableVertexList {
long ptr();
void ptr(long ptr);
void vertexCount(int vertexCount);
long stride();
}

View file

@ -0,0 +1,5 @@
package com.jozufozu.flywheel.api.vertex;
public interface VertexViewProvider {
VertexView createVertexView();
}

View file

@ -3,15 +3,15 @@ package com.jozufozu.flywheel.api.vertex;
import com.jozufozu.flywheel.impl.vertex.VertexListProviderRegistryImpl;
import com.mojang.blaze3d.vertex.VertexFormat;
public final class VertexListProviderRegistry {
public static VertexListProvider getProvider(VertexFormat format) {
public final class VertexViewProviderRegistry {
public static VertexViewProvider getProvider(VertexFormat format) {
return VertexListProviderRegistryImpl.getProvider(format);
}
public static void setProvider(VertexFormat format, VertexListProvider provider) {
public static void setProvider(VertexFormat format, VertexViewProvider provider) {
VertexListProviderRegistryImpl.setProvider(format, provider);
}
private VertexListProviderRegistry() {
private VertexViewProviderRegistry() {
}
}

View file

@ -1,14 +0,0 @@
package com.jozufozu.flywheel.backend;
import com.jozufozu.flywheel.api.layout.BufferLayout;
import com.jozufozu.flywheel.api.vertex.ReusableVertexList;
import com.jozufozu.flywheel.lib.vertex.FullVertex;
import com.jozufozu.flywheel.lib.vertex.FullVertexList;
public class InternalLayout {
public static final BufferLayout LAYOUT = FullVertex.FORMAT;
public static ReusableVertexList createVertexList() {
return new FullVertexList();
}
}

View file

@ -0,0 +1,30 @@
package com.jozufozu.flywheel.backend;
import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.api.layout.BufferLayout;
import com.jozufozu.flywheel.api.vertex.VertexView;
import com.jozufozu.flywheel.lib.layout.CommonItems;
import com.jozufozu.flywheel.lib.vertex.FullVertexView;
import net.minecraft.resources.ResourceLocation;
public final class InternalVertex {
public static final BufferLayout LAYOUT = BufferLayout.builder()
.addItem(CommonItems.VEC3, "position")
.addItem(CommonItems.UNORM_4x8, "color")
.addItem(CommonItems.VEC2, "tex")
.addItem(CommonItems.LIGHT_COORD, "overlay")
.addItem(CommonItems.LIGHT_COORD, "light")
.addItem(CommonItems.NORM_3x8, "normal")
.withPadding(1)
.build();
public static final ResourceLocation LAYOUT_SHADER = Flywheel.rl("internal/vertex_input.vert");
private InternalVertex() {
}
public static VertexView createVertexView() {
return new FullVertexView();
}
}

View file

@ -89,8 +89,8 @@ public class IndirectPrograms {
.define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE)
.withComponent(uniformComponent)
.withComponent(IndirectComponent::create)
.withResource(Files.INDIRECT_CULL)
.withResource(InstanceType::instanceShader))
.withResource(InstanceType::instanceShader)
.withResource(Files.INDIRECT_CULL))
.then((key, program) -> program.setUniformBlockBinding("FlwUniforms", 0)))
.build();
}

View file

@ -3,7 +3,7 @@ package com.jozufozu.flywheel.backend.compile;
import java.util.List;
import com.google.common.collect.ImmutableList;
import com.jozufozu.flywheel.backend.InternalLayout;
import com.jozufozu.flywheel.backend.InternalVertex;
import com.jozufozu.flywheel.backend.compile.component.UniformComponent;
import com.jozufozu.flywheel.gl.shader.ShaderType;
import com.jozufozu.flywheel.glsl.ShaderSources;
@ -18,9 +18,10 @@ public class PipelineCompiler {
.compiler(PIPELINE.program()
.link(PIPELINE.shader(pipeline.glslVersion(), ShaderType.VERTEX)
.withComponent(uniformComponent)
.withComponent(key -> pipeline.assembler()
.assemble(new Pipeline.InstanceAssemblerContext(InternalLayout.LAYOUT.getAttributeCount(), key.instanceType())))
.withResource(pipeline.vertexApiImpl())
.withResource(InternalVertex.LAYOUT_SHADER)
.withComponent(key -> pipeline.assembler()
.assemble(new Pipeline.InstanceAssemblerContext(InternalVertex.LAYOUT.getAttributeCount(), key.instanceType())))
.withComponents(vertexComponents)
.withResource(key -> key.instanceType()
.instanceShader())

View file

@ -11,7 +11,7 @@ import com.jozufozu.flywheel.api.backend.Engine;
import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.instance.Instance;
import com.jozufozu.flywheel.api.model.Mesh;
import com.jozufozu.flywheel.api.vertex.ReusableVertexList;
import com.jozufozu.flywheel.api.vertex.VertexView;
import com.jozufozu.flywheel.backend.engine.InstanceHandleImpl;
import com.jozufozu.flywheel.extension.RenderTypeExtension;
@ -32,8 +32,8 @@ public class BatchedCrumbling {
drawBuffer.prepare(bucket.vertexCount);
ReusableVertexList vertexList = drawBuffer.slice(0, 0);
long basePtr = vertexList.ptr();
VertexView vertexView = drawBuffer.slice(0, 0);
long basePtr = vertexView.ptr();
int totalVertices = 0;
@ -41,15 +41,15 @@ public class BatchedCrumbling {
var instance = pair.first();
var instancer = pair.second();
totalVertices += bufferOne(instancer, totalVertices, vertexList, drawBuffer, instance);
totalVertices += bufferOne(instancer, totalVertices, vertexView, drawBuffer, instance);
}
vertexList.ptr(basePtr);
vertexList.vertexCount(totalVertices);
vertexView.ptr(basePtr);
vertexView.vertexCount(totalVertices);
// apply these in bulk
BatchingTransforms.applyDecalUVs(vertexList);
BatchingTransforms.applyMatrices(vertexList, batchContext.matrices());
BatchingTransforms.applyDecalUVs(vertexView);
BatchingTransforms.applyMatrices(vertexView, batchContext.matrices());
drawTracker._draw(drawBuffer);
}
@ -75,25 +75,25 @@ public class BatchedCrumbling {
for (TransformCall<?> transformCall : instancer.getTransformCalls()) {
var mesh = transformCall.mesh;
bucket.vertexCount += mesh.getVertexCount();
bucket.vertexCount += mesh.vertexCount();
}
}
}
return out;
}
private static <I extends Instance> int bufferOne(BatchedInstancer<I> batchedInstancer, int baseVertex, ReusableVertexList vertexList, DrawBuffer drawBuffer, Instance instance) {
private static <I extends Instance> int bufferOne(BatchedInstancer<I> batchedInstancer, int baseVertex, VertexView vertexView, DrawBuffer drawBuffer, Instance instance) {
int totalVertices = 0;
for (TransformCall<I> transformCall : batchedInstancer.getTransformCalls()) {
Mesh mesh = transformCall.mesh.mesh;
vertexList.ptr(drawBuffer.ptrForVertex(baseVertex + totalVertices));
vertexList.vertexCount(mesh.vertexCount());
vertexView.ptr(drawBuffer.ptrForVertex(baseVertex + totalVertices));
vertexView.vertexCount(mesh.vertexCount());
mesh.write(vertexList);
mesh.write(vertexView);
batchedInstancer.type.getVertexTransformer()
.transform(vertexList, (I) instance);
.transform(vertexView, (I) instance);
totalVertices += mesh.vertexCount();
}

View file

@ -11,14 +11,14 @@ import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.api.model.Mesh;
import com.jozufozu.flywheel.api.vertex.ReusableVertexList;
import com.jozufozu.flywheel.api.vertex.VertexListProviderRegistry;
import com.jozufozu.flywheel.api.vertex.VertexView;
import com.jozufozu.flywheel.api.vertex.VertexViewProviderRegistry;
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
import com.mojang.blaze3d.vertex.VertexFormat;
public class BatchedMeshPool {
private final VertexFormat vertexFormat;
private final ReusableVertexList vertexList;
private final VertexView vertexView;
private final int growthMargin;
private final Map<Mesh, BufferedMesh> meshes = new HashMap<>();
@ -36,7 +36,7 @@ public class BatchedMeshPool {
*/
public BatchedMeshPool(VertexFormat vertexFormat) {
this.vertexFormat = vertexFormat;
vertexList = VertexListProviderRegistry.getProvider(vertexFormat).createVertexList();
vertexView = VertexViewProviderRegistry.getProvider(vertexFormat).createVertexView();
growthMargin = vertexFormat.getVertexSize() * 128;
}
@ -126,7 +126,7 @@ public class BatchedMeshPool {
private void bufferPending() {
try {
for (BufferedMesh mesh : pendingBuffer) {
mesh.buffer(vertexList);
mesh.write(vertexView);
}
pendingBuffer.clear();
@ -151,8 +151,8 @@ public class BatchedMeshPool {
public class BufferedMesh {
public final Mesh mesh;
private final int byteSize;
private final int vertexCount;
private final int byteSize;
private final Vector4fc boundingSphere;
private long byteIndex;
@ -161,32 +161,32 @@ public class BatchedMeshPool {
private BufferedMesh(Mesh mesh, long byteIndex) {
this.mesh = mesh;
vertexCount = mesh.vertexCount();
boundingSphere = mesh.boundingSphere();
byteSize = vertexCount * vertexFormat.getVertexSize();
boundingSphere = mesh.boundingSphere();
this.byteIndex = byteIndex;
}
public VertexFormat vertexFormat() {
return vertexFormat;
}
public int vertexCount() {
return vertexCount;
}
public int size() {
return byteSize;
}
public int getVertexCount() {
return vertexCount;
}
public Vector4fc boundingSphere() {
return boundingSphere;
}
public VertexFormat getVertexFormat() {
return vertexFormat;
}
public boolean isDeleted() {
return deleted;
}
private boolean isEmpty() {
public boolean isEmpty() {
return mesh.isEmpty() || isDeleted();
}
@ -194,15 +194,14 @@ public class BatchedMeshPool {
return BatchedMeshPool.this.data.ptr() + byteIndex;
}
private void buffer(ReusableVertexList vertexList) {
private void write(VertexView vertexView) {
if (isEmpty()) {
return;
}
vertexList.ptr(ptr());
vertexList.vertexCount(vertexCount);
mesh.write(vertexList);
vertexView.ptr(ptr());
vertexView.vertexCount(vertexCount);
mesh.write(vertexView);
}
public void copyTo(long ptr) {

View file

@ -6,8 +6,8 @@ import java.util.List;
import com.jozufozu.flywheel.api.event.ReloadLevelRendererEvent;
import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.vertex.ReusableVertexList;
import com.jozufozu.flywheel.api.vertex.VertexListProvider;
import com.jozufozu.flywheel.api.vertex.VertexView;
import com.jozufozu.flywheel.api.vertex.VertexViewProvider;
import com.jozufozu.flywheel.extension.BufferBuilderExtension;
import com.jozufozu.flywheel.extension.RenderTypeExtension;
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
@ -17,7 +17,7 @@ import net.minecraft.client.renderer.RenderType;
import net.minecraft.util.Mth;
/**
* A byte buffer that can be used to draw vertices through multiple {@link ReusableVertexList}s.
* A byte buffer that can be used to draw vertices through multiple {@link VertexView}s.
* <br>
* Note: The number of vertices needs to be known ahead of time.
*/
@ -28,7 +28,7 @@ public class DrawBuffer {
private final VertexFormat format;
private final int stride;
private final boolean sortOnUpload;
private final VertexListProvider provider;
private final VertexViewProvider provider;
private MemoryBlock data;
private ByteBuffer buffer;
@ -37,7 +37,7 @@ public class DrawBuffer {
private int vertexCount;
private int verticesToDraw;
public DrawBuffer(RenderType renderType, VertexFormat format, int stride, boolean sortOnUpload, VertexListProvider provider) {
public DrawBuffer(RenderType renderType, VertexFormat format, int stride, boolean sortOnUpload, VertexViewProvider provider) {
this.renderType = renderType;
this.format = format;
this.stride = stride;
@ -85,7 +85,7 @@ public class DrawBuffer {
prepared = true;
}
public ReusableVertexList slice(int startVertex, int vertexCount) {
public VertexView slice(int startVertex, int vertexCount) {
if (!prepared) {
throw new IllegalStateException("Cannot slice DrawBuffer that is not prepared!");
}
@ -94,10 +94,10 @@ public class DrawBuffer {
throw new IndexOutOfBoundsException("Vertex count greater than allocated: " + startVertex + " + " + vertexCount + " > " + this.vertexCount);
}
ReusableVertexList vertexList = provider.createVertexList();
vertexList.ptr(ptrForVertex(startVertex));
vertexList.vertexCount(vertexCount);
return vertexList;
VertexView vertexView = provider.createVertexView();
vertexView.ptr(ptrForVertex(startVertex));
vertexView.vertexCount(vertexCount);
return vertexView;
}
public long ptrForVertex(long startVertex) {

View file

@ -4,8 +4,8 @@ import java.util.EnumMap;
import java.util.Map;
import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.vertex.VertexListProvider;
import com.jozufozu.flywheel.api.vertex.VertexListProviderRegistry;
import com.jozufozu.flywheel.api.vertex.VertexViewProvider;
import com.jozufozu.flywheel.api.vertex.VertexViewProviderRegistry;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.client.renderer.RenderType;
@ -15,7 +15,7 @@ public class DrawBufferSet {
private final VertexFormat format;
private final boolean sortOnUpload;
private final int stride;
private final VertexListProvider provider;
private final VertexViewProvider provider;
private final Map<RenderStage, DrawBuffer> buffers = new EnumMap<>(RenderStage.class);
public DrawBufferSet(RenderType renderType, boolean sortOnUpload) {
@ -23,7 +23,7 @@ public class DrawBufferSet {
this.sortOnUpload = sortOnUpload;
format = renderType.format();
stride = format.getVertexSize();
provider = VertexListProviderRegistry.getProvider(format);
provider = VertexViewProviderRegistry.getProvider(format);
}
public DrawBuffer getBuffer(RenderStage stage) {

View file

@ -12,7 +12,7 @@ import com.jozufozu.flywheel.api.instance.InstanceVertexTransformer;
import com.jozufozu.flywheel.api.material.Material;
import com.jozufozu.flywheel.api.material.MaterialVertexTransformer;
import com.jozufozu.flywheel.api.task.Plan;
import com.jozufozu.flywheel.api.vertex.ReusableVertexList;
import com.jozufozu.flywheel.api.vertex.VertexView;
import com.jozufozu.flywheel.lib.task.ForEachSlicePlan;
import com.mojang.blaze3d.vertex.PoseStack;
@ -35,11 +35,11 @@ public class TransformCall<I extends Instance> {
InstanceBoundingSphereTransformer<I> boundingSphereTransformer = instancer.type.getBoundingSphereTransformer();
MaterialVertexTransformer materialVertexTransformer = material.getVertexTransformer();
meshVertexCount = mesh.getVertexCount();
meshVertexCount = mesh.vertexCount();
Vector4fc meshBoundingSphere = mesh.boundingSphere();
drawPlan = ForEachSlicePlan.of(instancer::getAll, (subList, ctx) -> {
ReusableVertexList vertexList = ctx.buffer.slice(0, meshVertexCount);
VertexView vertexView = ctx.buffer.slice(0, meshVertexCount);
Vector4f boundingSphere = new Vector4f();
for (I instance : subList) {
@ -51,12 +51,12 @@ public class TransformCall<I extends Instance> {
}
final int baseVertex = ctx.vertexCounter.getAndAdd(meshVertexCount);
vertexList.ptr(ctx.buffer.ptrForVertex(baseVertex));
vertexView.ptr(ctx.buffer.ptrForVertex(baseVertex));
mesh.copyTo(vertexList.ptr());
instanceVertexTransformer.transform(vertexList, instance);
materialVertexTransformer.transform(vertexList, ctx.level);
BatchingTransforms.applyMatrices(vertexList, ctx.matrices);
mesh.copyTo(vertexView.ptr());
instanceVertexTransformer.transform(vertexView, instance);
materialVertexTransformer.transform(vertexView, ctx.level);
BatchingTransforms.applyMatrices(vertexView, ctx.matrices);
}
});
}

View file

@ -8,7 +8,8 @@ import java.util.Map;
import org.jetbrains.annotations.Nullable;
import com.jozufozu.flywheel.api.model.Mesh;
import com.jozufozu.flywheel.backend.InternalLayout;
import com.jozufozu.flywheel.api.vertex.VertexView;
import com.jozufozu.flywheel.backend.InternalVertex;
import com.jozufozu.flywheel.gl.GlNumericType;
import com.jozufozu.flywheel.gl.array.GlVertexArray;
import com.jozufozu.flywheel.gl.buffer.GlBuffer;
@ -16,6 +17,7 @@ import com.jozufozu.flywheel.lib.memory.MemoryBlock;
import com.jozufozu.flywheel.lib.model.QuadIndexSequence;
public class IndirectMeshPool {
private final VertexView vertexView;
private final Map<Mesh, BufferedMesh> meshes = new HashMap<>();
private final List<BufferedMesh> meshList = new ArrayList<>();
@ -29,13 +31,14 @@ public class IndirectMeshPool {
* Create a new mesh pool.
*/
public IndirectMeshPool() {
vertexView = InternalVertex.createVertexView();
vbo = new GlBuffer();
ebo = new GlBuffer();
vertexArray = GlVertexArray.create();
vertexArray.setElementBuffer(ebo.handle());
vertexArray.bindVertexBuffer(0, vbo.handle(), 0, InternalLayout.LAYOUT.getStride());
vertexArray.bindAttributes(0, 0, InternalLayout.LAYOUT.attributes());
vertexArray.bindVertexBuffer(0, vbo.handle(), 0, InternalVertex.LAYOUT.getStride());
vertexArray.bindAttributes(0, 0, InternalVertex.LAYOUT.attributes());
}
/**
@ -89,8 +92,6 @@ public class IndirectMeshPool {
final long vertexPtr = vertexBlock.ptr();
final long indexPtr = indexBlock.ptr();
var target = InternalLayout.createVertexList();
int byteIndex = 0;
int baseVertex = 0;
int firstIndex = maxQuadIndexCount;
@ -98,11 +99,10 @@ public class IndirectMeshPool {
mesh.byteIndex = byteIndex;
mesh.baseVertex = baseVertex;
target.ptr(vertexPtr + mesh.byteIndex);
mesh.mesh.write(target);
mesh.write(vertexPtr, vertexView);
byteIndex += mesh.size();
baseVertex += mesh.mesh.vertexCount();
baseVertex += mesh.vertexCount();
var indexFiller = mesh.mesh.indexSequence();
if (indexFiller == QuadIndexSequence.INSTANCE) {
@ -141,16 +141,25 @@ public class IndirectMeshPool {
public static class BufferedMesh {
private final Mesh mesh;
private final int vertexCount;
private final int byteSize;
private long byteIndex;
private int baseVertex;
private int firstIndex;
private BufferedMesh(Mesh mesh) {
this.mesh = mesh;
vertexCount = mesh.vertexCount();
byteSize = vertexCount * InternalVertex.LAYOUT.getStride();
}
public int vertexCount() {
return vertexCount;
}
public int size() {
return mesh.vertexCount() * InternalLayout.LAYOUT.getStride();
return byteSize;
}
public int indexCount() {
@ -164,5 +173,11 @@ public class IndirectMeshPool {
public int firstIndex() {
return firstIndex;
}
private void write(long ptr, VertexView vertexView) {
vertexView.ptr(ptr + byteIndex);
vertexView.vertexCount(vertexCount);
mesh.write(vertexView);
}
}
}

View file

@ -1,5 +1,6 @@
package com.jozufozu.flywheel.backend.engine.instancing;
import com.jozufozu.flywheel.backend.InternalVertex;
import com.jozufozu.flywheel.backend.engine.InstanceHandleImpl;
import com.jozufozu.flywheel.gl.array.GlVertexArray;
@ -8,7 +9,6 @@ public class DrawCall {
private final InstancedInstancer<?> instancer;
private final InstancedMeshPool.BufferedMesh mesh;
private final int meshAttributes;
private GlVertexArray vao;
private GlVertexArray vaoScratch;
@ -17,7 +17,6 @@ public class DrawCall {
this.mesh = mesh;
this.shaderState = shaderState;
meshAttributes = this.mesh.getAttributeCount();
vao = GlVertexArray.create();
}
@ -37,7 +36,7 @@ public class DrawCall {
return;
}
instancer.bindIfNeeded(vao, meshAttributes);
instancer.bindIfNeeded(vao, InternalVertex.LAYOUT.getAttributeCount());
mesh.setup(vao);
vao.bindForDraw();
@ -59,7 +58,7 @@ public class DrawCall {
var vao = lazyScratchVao();
instancer.bindRaw(vao, meshAttributes, impl.index);
instancer.bindRaw(vao, InternalVertex.LAYOUT.getAttributeCount(), impl.index);
mesh.setup(vao);
vao.bindForDraw();

View file

@ -12,13 +12,15 @@ import org.lwjgl.opengl.GL32;
import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.api.model.Mesh;
import com.jozufozu.flywheel.backend.InternalLayout;
import com.jozufozu.flywheel.api.vertex.VertexView;
import com.jozufozu.flywheel.backend.InternalVertex;
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;
public class InstancedMeshPool {
private final VertexView vertexView;
private final Map<Mesh, BufferedMesh> meshes = new HashMap<>();
private final List<BufferedMesh> allBuffered = new ArrayList<>();
private final List<BufferedMesh> pendingUpload = new ArrayList<>();
@ -33,7 +35,8 @@ public class InstancedMeshPool {
* Create a new mesh pool.
*/
public InstancedMeshPool() {
int stride = InternalLayout.LAYOUT.getStride();
vertexView = InternalVertex.createVertexView();
int stride = InternalVertex.LAYOUT.getStride();
vbo = new GlBuffer();
vbo.growthFunction(l -> Math.max(l + stride * 128L, (long) (l * 1.6)));
}
@ -109,11 +112,8 @@ public class InstancedMeshPool {
try (MappedBuffer mapped = vbo.map()) {
long ptr = mapped.ptr();
var vertexList = InternalLayout.createVertexList();
for (BufferedMesh mesh : pendingUpload) {
vertexList.ptr(ptr + mesh.byteIndex);
mesh.mesh.write(vertexList);
mesh.write(ptr, vertexView);
mesh.boundTo.clear();
}
@ -137,7 +137,10 @@ public class InstancedMeshPool {
public class BufferedMesh {
private final Mesh mesh;
private final int vertexCount;
private final int byteSize;
private final int ebo;
private long byteIndex;
private boolean deleted;
@ -145,16 +148,18 @@ public class InstancedMeshPool {
private BufferedMesh(Mesh mesh, long byteIndex, EboCache eboCache) {
this.mesh = mesh;
vertexCount = mesh.vertexCount();
byteSize = vertexCount * InternalVertex.LAYOUT.getStride();
this.byteIndex = byteIndex;
this.ebo = eboCache.get(mesh.indexSequence(), mesh.indexCount());
}
public int size() {
return mesh.vertexCount() * InternalLayout.LAYOUT.getStride();
public int vertexCount() {
return vertexCount;
}
public int getAttributeCount() {
return InternalLayout.LAYOUT.getAttributeCount();
public int size() {
return byteSize;
}
public boolean isDeleted() {
@ -165,10 +170,20 @@ public class InstancedMeshPool {
return mesh.isEmpty() || isDeleted();
}
private void write(long ptr, VertexView vertexView) {
if (isEmpty()) {
return;
}
vertexView.ptr(ptr + byteIndex);
vertexView.vertexCount(vertexCount);
mesh.write(vertexView);
}
public void setup(GlVertexArray vao) {
if (boundTo.add(vao)) {
vao.bindVertexBuffer(0, InstancedMeshPool.this.vbo.handle(), byteIndex, InternalLayout.LAYOUT.getStride());
vao.bindAttributes(0, 0, InternalLayout.LAYOUT.attributes());
vao.bindVertexBuffer(0, InstancedMeshPool.this.vbo.handle(), byteIndex, InternalVertex.LAYOUT.getStride());
vao.bindAttributes(0, 0, InternalVertex.LAYOUT.attributes());
vao.setElementBuffer(ebo);
}
}

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.extension;
import com.jozufozu.flywheel.api.vertex.VertexListProvider;
import com.jozufozu.flywheel.api.vertex.VertexViewProvider;
import com.mojang.blaze3d.vertex.VertexFormat;
/**
@ -11,9 +11,9 @@ import com.mojang.blaze3d.vertex.VertexFormat;
public interface VertexFormatExtension {
/**
* @return The VertexListProvider associated with this VertexFormat.
* @return The VertexViewProvider associated with this VertexFormat.
*/
VertexListProvider flywheel$getVertexListProvider();
VertexViewProvider flywheel$getVertexViewProvider();
void flywheel$setVertexListProvider(VertexListProvider provider);
void flywheel$setVertexViewProvider(VertexViewProvider provider);
}

View file

@ -1,18 +0,0 @@
package com.jozufozu.flywheel.impl.vertex;
import com.jozufozu.flywheel.api.vertex.ReusableVertexList;
import com.jozufozu.flywheel.api.vertex.VertexListProvider;
import com.mojang.blaze3d.vertex.VertexFormat;
public class InferredVertexListProviderImpl implements VertexListProvider {
private final InferredVertexFormatInfo formatInfo;
public InferredVertexListProviderImpl(VertexFormat format) {
formatInfo = new InferredVertexFormatInfo(format);
}
@Override
public ReusableVertexList createVertexList() {
return new InferredVertexListImpl(formatInfo);
}
}

View file

@ -2,15 +2,15 @@ package com.jozufozu.flywheel.impl.vertex;
import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.api.vertex.ReusableVertexList;
import com.jozufozu.flywheel.api.vertex.VertexView;
import com.jozufozu.flywheel.lib.math.RenderMath;
import com.jozufozu.flywheel.lib.vertex.AbstractVertexList;
import com.jozufozu.flywheel.lib.vertex.AbstractVertexView;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.texture.OverlayTexture;
public class InferredVertexListImpl extends AbstractVertexList implements ReusableVertexList {
public class InferredVertexView extends AbstractVertexView implements VertexView {
protected final VertexFormat format;
protected final int stride;
@ -21,7 +21,7 @@ public class InferredVertexListImpl extends AbstractVertexList implements Reusab
protected final int lightOffset;
protected final int normalOffset;
public InferredVertexListImpl(InferredVertexFormatInfo formatInfo) {
public InferredVertexView(InferredVertexFormatInfo formatInfo) {
format = formatInfo.format;
stride = format.getVertexSize();
positionOffset = formatInfo.positionOffset;
@ -32,6 +32,11 @@ public class InferredVertexListImpl extends AbstractVertexList implements Reusab
normalOffset = formatInfo.normalOffset;
}
@Override
public long stride() {
return stride;
}
@Override
public float x(int index) {
if (positionOffset < 0) return 0;

View file

@ -0,0 +1,18 @@
package com.jozufozu.flywheel.impl.vertex;
import com.jozufozu.flywheel.api.vertex.VertexView;
import com.jozufozu.flywheel.api.vertex.VertexViewProvider;
import com.mojang.blaze3d.vertex.VertexFormat;
public class InferredVertexViewProvider implements VertexViewProvider {
private final InferredVertexFormatInfo formatInfo;
public InferredVertexViewProvider(VertexFormat format) {
formatInfo = new InferredVertexFormatInfo(format);
}
@Override
public VertexView createVertexView() {
return new InferredVertexView(formatInfo);
}
}

View file

@ -1,23 +1,23 @@
package com.jozufozu.flywheel.impl.vertex;
import com.jozufozu.flywheel.api.vertex.VertexListProvider;
import com.jozufozu.flywheel.api.vertex.VertexViewProvider;
import com.jozufozu.flywheel.extension.VertexFormatExtension;
import com.mojang.blaze3d.vertex.VertexFormat;
// TODO: Add freezing
public final class VertexListProviderRegistryImpl {
public static VertexListProvider getProvider(VertexFormat format) {
public static VertexViewProvider getProvider(VertexFormat format) {
VertexFormatExtension extension = (VertexFormatExtension) format;
VertexListProvider provider = extension.flywheel$getVertexListProvider();
VertexViewProvider provider = extension.flywheel$getVertexViewProvider();
if (provider == null) {
provider = new InferredVertexListProviderImpl(format);
extension.flywheel$setVertexListProvider(provider);
provider = new InferredVertexViewProvider(format);
extension.flywheel$setVertexViewProvider(provider);
}
return provider;
}
public static void setProvider(VertexFormat format, VertexListProvider provider) {
((VertexFormatExtension) format).flywheel$setVertexListProvider(provider);
public static void setProvider(VertexFormat format, VertexViewProvider provider) {
((VertexFormatExtension) format).flywheel$setVertexViewProvider(provider);
}
private VertexListProviderRegistryImpl() {

View file

@ -12,13 +12,12 @@ import com.dreizak.miniball.highdim.Miniball;
import com.dreizak.miniball.model.PointSet;
import com.jozufozu.flywheel.api.material.Material;
import com.jozufozu.flywheel.api.model.Mesh;
import com.jozufozu.flywheel.api.vertex.ReusableVertexList;
import com.jozufozu.flywheel.api.vertex.VertexView;
import com.jozufozu.flywheel.api.vertex.VertexList;
import com.jozufozu.flywheel.api.vertex.VertexListProviderRegistry;
import com.jozufozu.flywheel.api.vertex.VertexType;
import com.jozufozu.flywheel.api.vertex.VertexViewProviderRegistry;
import com.jozufozu.flywheel.lib.material.Materials;
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
import com.jozufozu.flywheel.lib.vertex.PositionOnlyVertexList;
import com.jozufozu.flywheel.lib.vertex.PosVertexView;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferBuilder.DrawState;
import com.mojang.blaze3d.vertex.VertexFormat;
@ -58,24 +57,23 @@ public final class ModelUtil {
return dispatcher;
}
public static MemoryBlock convertVanillaBuffer(BufferBuilder.RenderedBuffer buffer, VertexType vertexType) {
public static MemoryBlock convertVanillaBuffer(BufferBuilder.RenderedBuffer buffer, VertexView vertexView) {
DrawState drawState = buffer.drawState();
int vertexCount = drawState.vertexCount();
VertexFormat srcFormat = drawState.format();
ByteBuffer src = buffer.vertexBuffer();
MemoryBlock dst = MemoryBlock.malloc((long) vertexCount * vertexType.getStride());
MemoryBlock dst = MemoryBlock.malloc((long) vertexCount * vertexView.stride());
long srcPtr = MemoryUtil.memAddress(src);
long dstPtr = dst.ptr();
ReusableVertexList srcList = VertexListProviderRegistry.getProvider(srcFormat).createVertexList();
ReusableVertexList dstList = vertexType.createVertexList();
srcList.ptr(srcPtr);
dstList.ptr(dstPtr);
srcList.vertexCount(vertexCount);
dstList.vertexCount(vertexCount);
VertexView srcView = VertexViewProviderRegistry.getProvider(srcFormat).createVertexView();
srcView.ptr(srcPtr);
vertexView.ptr(dstPtr);
srcView.vertexCount(vertexCount);
vertexView.vertexCount(vertexCount);
srcList.writeAll(dstList);
srcView.writeAll(vertexView);
return dst;
}
@ -110,12 +108,12 @@ public final class ModelUtil {
public static Vector4f computeBoundingSphere(Iterable<Mesh> meshes) {
int vertexCount = computeTotalVertexCount(meshes);
var block = MemoryBlock.malloc((long) vertexCount * PositionOnlyVertexList.STRIDE);
var vertexList = new PositionOnlyVertexList();
var block = MemoryBlock.malloc((long) vertexCount * PosVertexView.STRIDE);
var vertexList = new PosVertexView();
int baseVertex = 0;
for (Mesh mesh : meshes) {
vertexList.ptr(block.ptr() + (long) baseVertex * PositionOnlyVertexList.STRIDE);
vertexList.ptr(block.ptr() + (long) baseVertex * PosVertexView.STRIDE);
mesh.write(vertexList);
baseVertex += mesh.vertexCount();
}

View file

@ -5,40 +5,37 @@ import org.joml.Vector4f;
import org.joml.Vector4fc;
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
import com.jozufozu.flywheel.api.vertex.ReusableVertexList;
import com.jozufozu.flywheel.api.vertex.VertexType;
import com.jozufozu.flywheel.api.vertex.VertexView;
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
public class SimpleMesh implements QuadMesh {
private final VertexType vertexType;
private final int vertexCount;
private final MemoryBlock data;
private final ReusableVertexList vertexList;
private final VertexView vertexView;
private final Vector4f boundingSphere;
private final MemoryBlock data;
@Nullable
private final String descriptor;
public SimpleMesh(VertexType vertexType, MemoryBlock data, @Nullable String descriptor) {
this.vertexType = vertexType;
public SimpleMesh(VertexView vertexView, MemoryBlock data, @Nullable String descriptor) {
this.vertexView = vertexView;
this.data = data;
this.descriptor = descriptor;
int bytes = (int) data.size();
int stride = vertexType.getStride();
int stride = (int) this.vertexView.stride();
if (bytes % stride != 0) {
throw new IllegalArgumentException("MemoryBlock contains non-whole amount of vertices!");
}
vertexCount = bytes / stride;
vertexList = this.vertexType.createVertexList();
vertexList.ptr(data.ptr());
vertexList.vertexCount(vertexCount);
this.vertexView.ptr(data.ptr());
this.vertexView.vertexCount(vertexCount);
boundingSphere = ModelUtil.computeBoundingSphere(vertexList);
boundingSphere = ModelUtil.computeBoundingSphere(vertexView);
}
public SimpleMesh(VertexType vertexType, MemoryBlock data) {
this(vertexType, data, null);
public SimpleMesh(VertexView vertexView, MemoryBlock data) {
this(vertexView, data, null);
}
@Override
@ -48,7 +45,7 @@ public class SimpleMesh implements QuadMesh {
@Override
public void write(MutableVertexList dst) {
vertexList.writeAll(dst);
vertexView.writeAll(dst);
}
@Override
@ -63,6 +60,6 @@ public class SimpleMesh implements QuadMesh {
@Override
public String toString() {
return "SimpleMesh{" + "vertexType=" + vertexType + ",vertexCount=" + vertexCount + ",descriptor={" + descriptor + "}" + "}";
return "SimpleMesh{" + "vertexCount=" + vertexCount + ",descriptor={" + descriptor + "}" + "}";
}
}

View file

@ -5,12 +5,13 @@ import java.util.function.BiFunction;
import com.google.common.collect.ImmutableMap;
import com.jozufozu.flywheel.api.material.Material;
import com.jozufozu.flywheel.api.model.Mesh;
import com.jozufozu.flywheel.api.vertex.VertexView;
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
import com.jozufozu.flywheel.lib.model.ModelUtil;
import com.jozufozu.flywheel.lib.model.SimpleMesh;
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ResultConsumer;
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ShadeSeparatedResultConsumer;
import com.jozufozu.flywheel.lib.vertex.VertexTypes;
import com.jozufozu.flywheel.lib.vertex.NoOverlayVertexView;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.RenderType;
@ -83,8 +84,9 @@ public class BakedModelBuilder {
ShadeSeparatedResultConsumer resultConsumer = (renderType, shaded, data) -> {
Material material = materialFunc.apply(renderType, shaded);
if (material != null) {
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
meshMapBuilder.put(material, new SimpleMesh(VertexTypes.BLOCK, meshData, "source=BakedModelBuilder," + "bakedModel=" + bakedModel + ",renderType=" + renderType + ",shaded=" + shaded));
VertexView vertexView = new NoOverlayVertexView();
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, vertexView);
meshMapBuilder.put(material, new SimpleMesh(vertexView, meshData, "source=BakedModelBuilder," + "bakedModel=" + bakedModel + ",renderType=" + renderType + ",shaded=" + shaded));
}
};
BakedModelBufferer.bufferSingleShadeSeparated(ModelUtil.VANILLA_RENDERER.getModelRenderer(), renderWorld, bakedModel, blockState, poseStack, modelData, resultConsumer);
@ -92,8 +94,9 @@ public class BakedModelBuilder {
ResultConsumer resultConsumer = (renderType, data) -> {
Material material = materialFunc.apply(renderType, true);
if (material != null) {
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
meshMapBuilder.put(material, new SimpleMesh(VertexTypes.BLOCK, meshData, "source=BakedModelBuilder," + "bakedModel=" + bakedModel + ",renderType=" + renderType));
VertexView vertexView = new NoOverlayVertexView();
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, vertexView);
meshMapBuilder.put(material, new SimpleMesh(vertexView, meshData, "source=BakedModelBuilder," + "bakedModel=" + bakedModel + ",renderType=" + renderType));
}
};
BakedModelBufferer.bufferSingle(ModelUtil.VANILLA_RENDERER.getModelRenderer(), renderWorld, bakedModel, blockState, poseStack, modelData, resultConsumer);

View file

@ -5,12 +5,13 @@ import java.util.function.BiFunction;
import com.google.common.collect.ImmutableMap;
import com.jozufozu.flywheel.api.material.Material;
import com.jozufozu.flywheel.api.model.Mesh;
import com.jozufozu.flywheel.api.vertex.VertexView;
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
import com.jozufozu.flywheel.lib.model.ModelUtil;
import com.jozufozu.flywheel.lib.model.SimpleMesh;
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ResultConsumer;
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ShadeSeparatedResultConsumer;
import com.jozufozu.flywheel.lib.vertex.VertexTypes;
import com.jozufozu.flywheel.lib.vertex.NoOverlayVertexView;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.RenderType;
@ -72,8 +73,9 @@ public class BlockModelBuilder {
ShadeSeparatedResultConsumer resultConsumer = (renderType, shaded, data) -> {
Material material = materialFunc.apply(renderType, shaded);
if (material != null) {
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
meshMapBuilder.put(material, new SimpleMesh(VertexTypes.BLOCK, meshData, "source=BlockModelBuilder," + "blockState=" + state + ",renderType=" + renderType + ",shaded=" + shaded));
VertexView vertexView = new NoOverlayVertexView();
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, vertexView);
meshMapBuilder.put(material, new SimpleMesh(vertexView, meshData, "source=BlockModelBuilder," + "blockState=" + state + ",renderType=" + renderType + ",shaded=" + shaded));
}
};
BakedModelBufferer.bufferBlockShadeSeparated(ModelUtil.VANILLA_RENDERER, renderWorld, state, poseStack, modelData, resultConsumer);
@ -81,8 +83,9 @@ public class BlockModelBuilder {
ResultConsumer resultConsumer = (renderType, data) -> {
Material material = materialFunc.apply(renderType, true);
if (material != null) {
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
meshMapBuilder.put(material, new SimpleMesh(VertexTypes.BLOCK, meshData, "source=BlockModelBuilder," + "blockState=" + state + ",renderType=" + renderType));
VertexView vertexView = new NoOverlayVertexView();
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, vertexView);
meshMapBuilder.put(material, new SimpleMesh(vertexView, meshData, "source=BlockModelBuilder," + "blockState=" + state + ",renderType=" + renderType));
}
};
BakedModelBufferer.bufferBlock(ModelUtil.VANILLA_RENDERER, renderWorld, state, poseStack, modelData, resultConsumer);

View file

@ -8,12 +8,13 @@ import java.util.function.BiFunction;
import com.google.common.collect.ImmutableMap;
import com.jozufozu.flywheel.api.material.Material;
import com.jozufozu.flywheel.api.model.Mesh;
import com.jozufozu.flywheel.api.vertex.VertexView;
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
import com.jozufozu.flywheel.lib.model.ModelUtil;
import com.jozufozu.flywheel.lib.model.SimpleMesh;
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ResultConsumer;
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ShadeSeparatedResultConsumer;
import com.jozufozu.flywheel.lib.vertex.VertexTypes;
import com.jozufozu.flywheel.lib.vertex.NoOverlayVertexView;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.RenderType;
@ -76,8 +77,9 @@ public class MultiBlockModelBuilder {
ShadeSeparatedResultConsumer resultConsumer = (renderType, shaded, data) -> {
Material material = materialFunc.apply(renderType, shaded);
if (material != null) {
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
meshMapBuilder.put(material, new SimpleMesh(VertexTypes.BLOCK, meshData, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded));
VertexView vertexView = new NoOverlayVertexView();
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, vertexView);
meshMapBuilder.put(material, new SimpleMesh(vertexView, meshData, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded));
}
};
BakedModelBufferer.bufferMultiBlockShadeSeparated(blocks, ModelUtil.VANILLA_RENDERER, renderWorld, poseStack, modelDataMap, resultConsumer);
@ -85,8 +87,9 @@ public class MultiBlockModelBuilder {
ResultConsumer resultConsumer = (renderType, data) -> {
Material material = materialFunc.apply(renderType, true);
if (material != null) {
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
meshMapBuilder.put(material, new SimpleMesh(VertexTypes.BLOCK, meshData, "source=MultiBlockModelBuilder," + "renderType=" + renderType));
VertexView vertexView = new NoOverlayVertexView();
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, vertexView);
meshMapBuilder.put(material, new SimpleMesh(vertexView, meshData, "source=MultiBlockModelBuilder," + "renderType=" + renderType));
}
};
BakedModelBufferer.bufferMultiBlock(blocks, ModelUtil.VANILLA_RENDERER, renderWorld, poseStack, modelDataMap, resultConsumer);

View file

@ -6,7 +6,7 @@ import org.joml.Vector2f;
import com.jozufozu.flywheel.api.model.Mesh;
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
import com.jozufozu.flywheel.lib.model.SimpleMesh;
import com.jozufozu.flywheel.lib.vertex.VertexTypes;
import com.jozufozu.flywheel.lib.vertex.PosTexNormalVertexView;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
@ -32,7 +32,7 @@ public final class ModelPartConverter {
vertexWriter.setTextureMapper(textureMapper);
modelPart.render(poseStack, vertexWriter, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY);
MemoryBlock data = vertexWriter.copyDataAndReset();
return new SimpleMesh(VertexTypes.POS_TEX_NORMAL, data, "source=ModelPartConverter");
return new SimpleMesh(new PosTexNormalVertexView(), data, "source=ModelPartConverter");
}
public static Mesh convert(ModelLayerLocation layer, @Nullable TextureAtlasSprite sprite, String... childPath) {

View file

@ -4,16 +4,14 @@ import org.jetbrains.annotations.Nullable;
import org.joml.Vector2f;
import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.api.vertex.VertexType;
import com.jozufozu.flywheel.lib.math.RenderMath;
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
import com.jozufozu.flywheel.lib.model.part.ModelPartConverter.TextureMapper;
import com.jozufozu.flywheel.lib.vertex.VertexTypes;
import com.jozufozu.flywheel.lib.vertex.PosTexNormalVertexView;
import com.mojang.blaze3d.vertex.VertexConsumer;
class VertexWriter implements VertexConsumer {
private static final VertexType VERTEX_TYPE = VertexTypes.POS_TEX_NORMAL;
private static final int STRIDE = VERTEX_TYPE.getStride();
private static final int STRIDE = (int) PosTexNormalVertexView.STRIDE;
private static final int GROWTH_MARGIN = 128 * STRIDE;
private MemoryBlock data;

View file

@ -1,28 +0,0 @@
package com.jozufozu.flywheel.lib.vertex;
import com.jozufozu.flywheel.api.vertex.ReusableVertexList;
public abstract class AbstractVertexList implements ReusableVertexList {
protected long ptr;
protected int vertexCount;
@Override
public long ptr() {
return ptr;
}
@Override
public void ptr(long ptr) {
this.ptr = ptr;
}
@Override
public int vertexCount() {
return vertexCount;
}
@Override
public void vertexCount(int vertexCount) {
this.vertexCount = vertexCount;
}
}

View file

@ -0,0 +1,64 @@
package com.jozufozu.flywheel.lib.vertex;
import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
import com.jozufozu.flywheel.api.vertex.VertexView;
public abstract class AbstractVertexView implements VertexView {
protected long ptr;
protected int vertexCount;
@Override
public long ptr() {
return ptr;
}
@Override
public void ptr(long ptr) {
this.ptr = ptr;
}
@Override
public int vertexCount() {
return vertexCount;
}
@Override
public void vertexCount(int vertexCount) {
this.vertexCount = vertexCount;
}
@Override
public void write(MutableVertexList dst, int srcIndex, int dstIndex) {
if (dst.getClass() == getClass()) {
long stride = stride();
long dstPtr = ((AbstractVertexView) dst).ptr;
MemoryUtil.memCopy(ptr + srcIndex * stride, dstPtr + dstIndex * stride, stride);
} else {
VertexView.super.write(dst, srcIndex, dstIndex);
}
}
@Override
public void write(MutableVertexList dst, int srcStartIndex, int dstStartIndex, int vertexCount) {
if (dst.getClass() == getClass()) {
long stride = stride();
long dstPtr = ((AbstractVertexView) dst).ptr;
MemoryUtil.memCopy(ptr + srcStartIndex * stride, dstPtr + dstStartIndex * stride, vertexCount * stride);
} else {
VertexView.super.write(dst, srcStartIndex, dstStartIndex, vertexCount);
}
}
@Override
public void writeAll(MutableVertexList dst) {
if (dst.getClass() == getClass()) {
long stride = stride();
long dstPtr = ((AbstractVertexView) dst).ptr;
MemoryUtil.memCopy(ptr, dstPtr, Math.min(vertexCount, dst.vertexCount()) * stride);
} else {
VertexView.super.writeAll(dst);
}
}
}

View file

@ -1,26 +0,0 @@
package com.jozufozu.flywheel.lib.vertex;
import com.jozufozu.flywheel.api.layout.BufferLayout;
import com.jozufozu.flywheel.api.vertex.VertexType;
import com.jozufozu.flywheel.lib.layout.CommonItems;
public class BlockVertex implements VertexType {
public static final BufferLayout FORMAT = BufferLayout.builder()
.addItem(CommonItems.VEC3, "position")
.addItem(CommonItems.UNORM_4x8, "color")
.addItem(CommonItems.VEC2, "tex")
.addItem(CommonItems.LIGHT_COORD, "light")
.addItem(CommonItems.NORM_3x8, "normal")
.withPadding(1)
.build();
@Override
public int getStride() {
return FORMAT.getStride();
}
@Override
public BlockVertexList createVertexList() {
return new BlockVertexList();
}
}

View file

@ -0,0 +1,134 @@
package com.jozufozu.flywheel.lib.vertex;
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.texture.OverlayTexture;
public interface EmptyVertexList extends MutableVertexList {
@Override
default float x(int index) {
return 0.0f;
}
@Override
default float y(int index){
return 0.0f;
}
@Override
default float z(int index){
return 0.0f;
}
@Override
default float r(int index) {
return 1.0f;
}
@Override
default float g(int index) {
return 1.0f;
}
@Override
default float b(int index) {
return 1.0f;
}
@Override
default float a(int index) {
return 1.0f;
}
@Override
default float u(int index) {
return 0.0f;
}
@Override
default float v(int index) {
return 0.0f;
}
@Override
default int overlay(int index) {
return OverlayTexture.NO_OVERLAY;
}
@Override
default int light(int index) {
return LightTexture.FULL_BRIGHT;
}
@Override
default float normalX(int index) {
return 0.0f;
}
@Override
default float normalY(int index) {
return 1.0f;
}
@Override
default float normalZ(int index) {
return 0.0f;
}
@Override
default void x(int index, float x) {
}
@Override
default void y(int index, float y) {
}
@Override
default void z(int index, float z) {
}
@Override
default void r(int index, float r) {
}
@Override
default void g(int index, float g) {
}
@Override
default void b(int index, float b) {
}
@Override
default void a(int index, float a) {
}
@Override
default void u(int index, float u) {
}
@Override
default void v(int index, float v) {
}
@Override
default void overlay(int index, int overlay) {
}
@Override
default void light(int index, int light) {
}
@Override
default void normalX(int index, float normalX) {
}
@Override
default void normalY(int index, float normalY) {
}
@Override
default void normalZ(int index, float normalZ) {
}
}

View file

@ -1,27 +0,0 @@
package com.jozufozu.flywheel.lib.vertex;
import com.jozufozu.flywheel.api.layout.BufferLayout;
import com.jozufozu.flywheel.api.vertex.VertexType;
import com.jozufozu.flywheel.lib.layout.CommonItems;
public class FullVertex implements VertexType {
public static final BufferLayout FORMAT = BufferLayout.builder()
.addItem(CommonItems.VEC3, "position")
.addItem(CommonItems.UNORM_4x8, "color")
.addItem(CommonItems.VEC2, "tex")
.addItem(CommonItems.LIGHT_COORD, "overlay")
.addItem(CommonItems.LIGHT_COORD, "light")
.addItem(CommonItems.NORM_3x8, "normal")
.withPadding(1)
.build();
@Override
public int getStride() {
return FORMAT.getStride();
}
@Override
public FullVertexList createVertexList() {
return new FullVertexList();
}
}

View file

@ -2,11 +2,15 @@ package com.jozufozu.flywheel.lib.vertex;
import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
import com.jozufozu.flywheel.lib.math.RenderMath;
public class FullVertexList extends AbstractVertexList {
private static final long STRIDE = 36;
public class FullVertexView extends AbstractVertexView {
public static final long STRIDE = 36;
@Override
public long stride() {
return STRIDE;
}
@Override
public float x(int index) {
@ -60,7 +64,7 @@ public class FullVertexList extends AbstractVertexList {
@Override
public int light(int index) {
return MemoryUtil.memGetInt(ptr + index * STRIDE + 28) << 4;
return MemoryUtil.memGetInt(ptr + index * STRIDE + 28);
}
@Override
@ -130,7 +134,7 @@ public class FullVertexList extends AbstractVertexList {
@Override
public void light(int index, int light) {
MemoryUtil.memPutInt(ptr + index * STRIDE + 28, light >> 4);
MemoryUtil.memPutInt(ptr + index * STRIDE + 28, light);
}
@Override
@ -147,34 +151,4 @@ public class FullVertexList extends AbstractVertexList {
public void normalZ(int index, float normalZ) {
MemoryUtil.memPutByte(ptr + index * STRIDE + 34, RenderMath.nb(normalZ));
}
@Override
public void write(MutableVertexList dst, int srcIndex, int dstIndex) {
if (getClass() == dst.getClass()) {
long dstPtr = ((FullVertexList) dst).ptr;
MemoryUtil.memCopy(ptr + srcIndex * STRIDE, dstPtr + dstIndex * STRIDE, STRIDE);
} else {
super.write(dst, srcIndex, dstIndex);
}
}
@Override
public void write(MutableVertexList dst, int srcStartIndex, int dstStartIndex, int vertexCount) {
if (getClass() == dst.getClass()) {
long dstPtr = ((FullVertexList) dst).ptr;
MemoryUtil.memCopy(ptr + srcStartIndex * STRIDE, dstPtr + dstStartIndex * STRIDE, vertexCount * STRIDE);
} else {
super.write(dst, srcStartIndex, dstStartIndex, vertexCount);
}
}
@Override
public void writeAll(MutableVertexList dst) {
if (getClass() == dst.getClass()) {
long dstPtr = ((FullVertexList) dst).ptr;
MemoryUtil.memCopy(ptr, dstPtr, vertexCount * STRIDE);
} else {
super.writeAll(dst);
}
}
}

View file

@ -2,13 +2,15 @@ package com.jozufozu.flywheel.lib.vertex;
import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
import com.jozufozu.flywheel.lib.math.RenderMath;
import net.minecraft.client.renderer.texture.OverlayTexture;
public class NoOverlayVertexView extends AbstractVertexView implements EmptyVertexList {
public static final long STRIDE = 31;
public class BlockVertexList extends AbstractVertexList {
private static final long STRIDE = 32;
@Override
public long stride() {
return STRIDE;
}
@Override
public float x(int index) {
@ -55,14 +57,9 @@ public class BlockVertexList extends AbstractVertexList {
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 20);
}
@Override
public int overlay(int index) {
return OverlayTexture.NO_OVERLAY;
}
@Override
public int light(int index) {
return MemoryUtil.memGetInt(ptr + index * STRIDE + 24) << 4;
return MemoryUtil.memGetInt(ptr + index * STRIDE + 24);
}
@Override
@ -125,13 +122,9 @@ public class BlockVertexList extends AbstractVertexList {
MemoryUtil.memPutFloat(ptr + index * STRIDE + 20, v);
}
@Override
public void overlay(int index, int overlay) {
}
@Override
public void light(int index, int light) {
MemoryUtil.memPutInt(ptr + index * STRIDE + 24, light >> 4);
MemoryUtil.memPutInt(ptr + index * STRIDE + 24, light);
}
@Override
@ -148,34 +141,4 @@ public class BlockVertexList extends AbstractVertexList {
public void normalZ(int index, float normalZ) {
MemoryUtil.memPutByte(ptr + index * STRIDE + 30, RenderMath.nb(normalZ));
}
@Override
public void write(MutableVertexList dst, int srcIndex, int dstIndex) {
if (getClass() == dst.getClass()) {
long dstPtr = ((BlockVertexList) dst).ptr;
MemoryUtil.memCopy(ptr + srcIndex * STRIDE, dstPtr + dstIndex * STRIDE, STRIDE);
} else {
super.write(dst, srcIndex, dstIndex);
}
}
@Override
public void write(MutableVertexList dst, int srcStartIndex, int dstStartIndex, int vertexCount) {
if (getClass() == dst.getClass()) {
long dstPtr = ((BlockVertexList) dst).ptr;
MemoryUtil.memCopy(ptr + srcStartIndex * STRIDE, dstPtr + dstStartIndex * STRIDE, vertexCount * STRIDE);
} else {
super.write(dst, srcStartIndex, dstStartIndex, vertexCount);
}
}
@Override
public void writeAll(MutableVertexList dst) {
if (getClass() == dst.getClass()) {
long dstPtr = ((BlockVertexList) dst).ptr;
MemoryUtil.memCopy(ptr, dstPtr, vertexCount * STRIDE);
} else {
super.writeAll(dst);
}
}
}

View file

@ -1,22 +0,0 @@
package com.jozufozu.flywheel.lib.vertex;
import com.jozufozu.flywheel.api.layout.BufferLayout;
import com.jozufozu.flywheel.api.vertex.VertexType;
import com.jozufozu.flywheel.lib.layout.CommonItems;
public class PosTexNormalVertex implements VertexType {
public static final BufferLayout FORMAT = BufferLayout.builder()
.addItem(CommonItems.VEC3, "position")
.addItem(CommonItems.VEC2, "tex")
.addItem(CommonItems.NORM_3x8, "normal")
.build();
@Override
public int getStride() {
return FORMAT.getStride();
}
@Override
public PosTexNormalVertexList createVertexList() {
return new PosTexNormalVertexList();
}
}

View file

@ -2,14 +2,15 @@ package com.jozufozu.flywheel.lib.vertex;
import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
import com.jozufozu.flywheel.lib.math.RenderMath;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.texture.OverlayTexture;
public class PosTexNormalVertexView extends AbstractVertexView implements EmptyVertexList {
public static final long STRIDE = 23;
public class PosTexNormalVertexList extends AbstractVertexList {
private static final long STRIDE = 23;
@Override
public long stride() {
return STRIDE;
}
@Override
public float x(int index) {
@ -26,26 +27,6 @@ public class PosTexNormalVertexList extends AbstractVertexList {
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 8);
}
@Override
public float r(int index) {
return 1;
}
@Override
public float g(int index) {
return 1;
}
@Override
public float b(int index) {
return 1;
}
@Override
public float a(int index) {
return 1;
}
@Override
public float u(int index) {
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 12);
@ -56,16 +37,6 @@ public class PosTexNormalVertexList extends AbstractVertexList {
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 16);
}
@Override
public int overlay(int index) {
return OverlayTexture.NO_OVERLAY;
}
@Override
public int light(int index) {
return LightTexture.FULL_BRIGHT;
}
@Override
public float normalX(int index) {
return RenderMath.f(MemoryUtil.memGetByte(ptr + index * STRIDE + 20));
@ -96,22 +67,6 @@ public class PosTexNormalVertexList extends AbstractVertexList {
MemoryUtil.memPutFloat(ptr + index * STRIDE + 8, z);
}
@Override
public void r(int index, float r) {
}
@Override
public void g(int index, float g) {
}
@Override
public void b(int index, float b) {
}
@Override
public void a(int index, float a) {
}
@Override
public void u(int index, float u) {
MemoryUtil.memPutFloat(ptr + index * STRIDE + 12, u);
@ -122,14 +77,6 @@ public class PosTexNormalVertexList extends AbstractVertexList {
MemoryUtil.memPutFloat(ptr + index * STRIDE + 16, v);
}
@Override
public void overlay(int index, int overlay) {
}
@Override
public void light(int index, int light) {
}
@Override
public void normalX(int index, float normalX) {
MemoryUtil.memPutByte(ptr + index * STRIDE + 20, RenderMath.nb(normalX));
@ -144,34 +91,4 @@ public class PosTexNormalVertexList extends AbstractVertexList {
public void normalZ(int index, float normalZ) {
MemoryUtil.memPutByte(ptr + index * STRIDE + 22, RenderMath.nb(normalZ));
}
@Override
public void write(MutableVertexList dst, int srcIndex, int dstIndex) {
if (getClass() == dst.getClass()) {
long dstPtr = ((PosTexNormalVertexList) dst).ptr;
MemoryUtil.memCopy(ptr + srcIndex * STRIDE, dstPtr + dstIndex * STRIDE, STRIDE);
} else {
super.write(dst, srcIndex, dstIndex);
}
}
@Override
public void write(MutableVertexList dst, int srcStartIndex, int dstStartIndex, int vertexCount) {
if (getClass() == dst.getClass()) {
long dstPtr = ((PosTexNormalVertexList) dst).ptr;
MemoryUtil.memCopy(ptr + srcStartIndex * STRIDE, dstPtr + dstStartIndex * STRIDE, vertexCount * STRIDE);
} else {
super.write(dst, srcStartIndex, dstStartIndex, vertexCount);
}
}
@Override
public void writeAll(MutableVertexList dst) {
if (getClass() == dst.getClass()) {
long dstPtr = ((PosTexNormalVertexList) dst).ptr;
MemoryUtil.memCopy(ptr, dstPtr, vertexCount * STRIDE);
} else {
super.writeAll(dst);
}
}
}

View file

@ -0,0 +1,42 @@
package com.jozufozu.flywheel.lib.vertex;
import org.lwjgl.system.MemoryUtil;
public class PosVertexView extends AbstractVertexView implements EmptyVertexList {
public static final long STRIDE = 12;
@Override
public long stride() {
return STRIDE;
}
@Override
public float x(int index) {
return MemoryUtil.memGetFloat(ptr + index * STRIDE);
}
@Override
public float y(int index) {
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 4);
}
@Override
public float z(int index) {
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 8);
}
@Override
public void x(int index, float x) {
MemoryUtil.memPutFloat(ptr + index * STRIDE, x);
}
@Override
public void y(int index, float y) {
MemoryUtil.memPutFloat(ptr + index * STRIDE + 4, y);
}
@Override
public void z(int index, float z) {
MemoryUtil.memPutFloat(ptr + index * STRIDE + 8, z);
}
}

View file

@ -1,171 +0,0 @@
package com.jozufozu.flywheel.lib.vertex;
import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.texture.OverlayTexture;
public class PositionOnlyVertexList extends AbstractVertexList {
public static final int STRIDE = 12;
@Override
public float x(int index) {
return MemoryUtil.memGetFloat(ptr + (long) index * STRIDE);
}
@Override
public float y(int index) {
return MemoryUtil.memGetFloat(ptr + (long) index * STRIDE + 4);
}
@Override
public float z(int index) {
return MemoryUtil.memGetFloat(ptr + (long) index * STRIDE + 8);
}
@Override
public float r(int index) {
return 1;
}
@Override
public float g(int index) {
return 1;
}
@Override
public float b(int index) {
return 1;
}
@Override
public float a(int index) {
return 1;
}
@Override
public float u(int index) {
return 0;
}
@Override
public float v(int index) {
return 0;
}
@Override
public int overlay(int index) {
return OverlayTexture.NO_OVERLAY;
}
@Override
public int light(int index) {
return LightTexture.FULL_BRIGHT;
}
@Override
public float normalX(int index) {
return 0;
}
@Override
public float normalY(int index) {
return 1;
}
@Override
public float normalZ(int index) {
return 0;
}
@Override
public void x(int index, float x) {
MemoryUtil.memPutFloat(ptr + (long) index * STRIDE, x);
}
@Override
public void y(int index, float y) {
MemoryUtil.memPutFloat(ptr + (long) index * STRIDE + 4, y);
}
@Override
public void z(int index, float z) {
MemoryUtil.memPutFloat(ptr + (long) index * STRIDE + 8, z);
}
@Override
public void r(int index, float r) {
}
@Override
public void g(int index, float g) {
}
@Override
public void b(int index, float b) {
}
@Override
public void a(int index, float a) {
}
@Override
public void u(int index, float u) {
}
@Override
public void v(int index, float v) {
}
@Override
public void overlay(int index, int overlay) {
}
@Override
public void light(int index, int light) {
}
@Override
public void normalX(int index, float normalX) {
}
@Override
public void normalY(int index, float normalY) {
}
@Override
public void normalZ(int index, float normalZ) {
}
@Override
public void write(MutableVertexList dst, int srcIndex, int dstIndex) {
if (getClass() == dst.getClass()) {
long dstPtr = ((PositionOnlyVertexList) dst).ptr;
MemoryUtil.memCopy(ptr + srcIndex * STRIDE, dstPtr + dstIndex * STRIDE, STRIDE);
} else {
super.write(dst, srcIndex, dstIndex);
}
}
@Override
public void write(MutableVertexList dst, int srcStartIndex, int dstStartIndex, int vertexCount) {
if (getClass() == dst.getClass()) {
long dstPtr = ((PositionOnlyVertexList) dst).ptr;
MemoryUtil.memCopy(ptr + srcStartIndex * STRIDE, dstPtr + dstStartIndex * STRIDE, vertexCount * STRIDE);
} else {
super.write(dst, srcStartIndex, dstStartIndex, vertexCount);
}
}
@Override
public void writeAll(MutableVertexList dst) {
if (getClass() == dst.getClass()) {
long dstPtr = ((PositionOnlyVertexList) dst).ptr;
MemoryUtil.memCopy(ptr, dstPtr, vertexCount * STRIDE);
} else {
super.writeAll(dst);
}
}
}

View file

@ -1,10 +0,0 @@
package com.jozufozu.flywheel.lib.vertex;
public final class VertexTypes {
public static final BlockVertex BLOCK = new BlockVertex();
public static final PosTexNormalVertex POS_TEX_NORMAL = new PosTexNormalVertex();
public static final FullVertex FULL = new FullVertex();
private VertexTypes() {
}
}

View file

@ -3,22 +3,22 @@ package com.jozufozu.flywheel.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import com.jozufozu.flywheel.api.vertex.VertexListProvider;
import com.jozufozu.flywheel.api.vertex.VertexViewProvider;
import com.jozufozu.flywheel.extension.VertexFormatExtension;
import com.mojang.blaze3d.vertex.VertexFormat;
@Mixin(VertexFormat.class)
abstract class VertexFormatMixin implements VertexFormatExtension {
@Unique
private VertexListProvider flywheel$vertexListProvider;
private VertexViewProvider flywheel$vertexViewProvider;
@Override
public VertexListProvider flywheel$getVertexListProvider() {
return flywheel$vertexListProvider;
public VertexViewProvider flywheel$getVertexViewProvider() {
return flywheel$vertexViewProvider;
}
@Override
public void flywheel$setVertexListProvider(VertexListProvider provider) {
flywheel$vertexListProvider = provider;
public void flywheel$setVertexViewProvider(VertexViewProvider provider) {
flywheel$vertexViewProvider = provider;
}
}

View file

@ -1,5 +1,6 @@
#include "flywheel:util/quaternion.glsl"
#ifdef COMPUTE_SHADER
void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout float radius) {
vec4 rotation = i.rotation;
vec3 pivot = i.pivot;
@ -7,10 +8,13 @@ void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout floa
center = rotateVertexByQuat(center - pivot, rotation) + pivot + pos;
}
#endif
#ifdef VERTEX_SHADER
void flw_instanceVertex(in FlwInstance i) {
flw_vertexPos = vec4(rotateVertexByQuat(flw_vertexPos.xyz - i.pivot, i.rotation) + i.pivot + i.position, 1.0);
flw_vertexNormal = rotateVertexByQuat(flw_vertexNormal, i.rotation);
flw_vertexColor = i.color;
flw_vertexLight = i.light / 15.0;
}
#endif

View file

@ -1,3 +1,4 @@
#ifdef COMPUTE_SHADER
void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout float radius) {
mat4 pose = i.pose;
center = (pose * vec4(center, 1.0)).xyz;
@ -5,10 +6,13 @@ void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout floa
float scale = max(length(pose[0].xyz), max(length(pose[1].xyz), length(pose[2].xyz)));
radius *= scale;
}
#endif
#ifdef VERTEX_SHADER
void flw_instanceVertex(in FlwInstance i) {
flw_vertexPos = i.pose * flw_vertexPos;
flw_vertexNormal = i.normal * flw_vertexNormal;
flw_vertexColor = i.color;
flw_vertexLight = i.light / 15.0;
}
#endif

View file

@ -4,21 +4,6 @@
layout(local_size_x = _FLW_SUBGROUP_SIZE) in;
// need to add stubs so the instance shader compiles.
vec4 flw_vertexPos;
vec4 flw_vertexColor;
vec2 flw_vertexTexCoord;
ivec2 flw_vertexOverlay;
vec2 flw_vertexLight;
vec3 flw_vertexNormal;
float flw_distance;
vec4 flw_var0;
vec4 flw_var1;
vec4 flw_var2;
vec4 flw_var3;
void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout float radius);
layout(std430, binding = _FLW_OBJECT_BUFFER_BINDING) restrict readonly buffer ObjectBuffer {
Object objects[];
};
@ -37,14 +22,14 @@ layout(std430, binding = _FLW_MODEL_BUFFER_BINDING) restrict buffer ModelBuffer
// flywheel:uniform/flywheel.glsl
// com.jozufozu.flywheel.lib.math.MatrixMath.writePackedFrustumPlanes
// org.joml.FrustumIntersection.testSphere
bool testSphere(vec3 center, float radius) {
bool _flw_testSphere(vec3 center, float radius) {
bvec4 xyInside = greaterThanEqual(fma(flywheel.planes.xyX, center.xxxx, fma(flywheel.planes.xyY, center.yyyy, fma(flywheel.planes.xyZ, center.zzzz, flywheel.planes.xyW))), -radius.xxxx);
bvec2 zInside = greaterThanEqual(fma(flywheel.planes.zX, center.xx, fma(flywheel.planes.zY, center.yy, fma(flywheel.planes.zZ, center.zz, flywheel.planes.zW))), -radius.xx);
return all(xyInside) && all(zInside);
}
bool isVisible(uint objectIndex, uint modelIndex) {
bool _flw_isVisible(uint objectIndex, uint modelIndex) {
BoundingSphere sphere = models[modelIndex].boundingSphere;
vec3 center;
@ -55,7 +40,7 @@ bool isVisible(uint objectIndex, uint modelIndex) {
flw_transformBoundingSphere(instance, center, radius);
return testSphere(center, radius);
return _flw_testSphere(center, radius);
}
void main() {
@ -67,7 +52,7 @@ void main() {
uint modelIndex = objects[objectIndex].modelIndex;
if (isVisible(objectIndex, modelIndex)) {
if (_flw_isVisible(objectIndex, modelIndex)) {
uint localIndex = atomicAdd(models[modelIndex].instanceCount, 1);
uint targetIndex = models[modelIndex].baseInstance + localIndex;
objectIndices[targetIndex] = objectIndex;

View file

@ -1,6 +1,5 @@
#include "flywheel:internal/diffuse.glsl"
#include "flywheel:internal/fog_distance.glsl"
#include "flywheel:internal/vertex_input.glsl"
#include "flywheel:internal/packed_material.glsl"
#include "flywheel:internal/indirect/buffers.glsl"
#include "flywheel:internal/indirect/draw_command.glsl"

View file

@ -1,6 +1,5 @@
#include "flywheel:internal/diffuse.glsl"
#include "flywheel:internal/fog_distance.glsl"
#include "flywheel:internal/vertex_input.glsl"
#include "flywheel:internal/packed_material.glsl"
uniform uvec4 _flw_packedMaterial;

View file

@ -1,15 +0,0 @@
layout(location = 0) in vec3 _flw_pos;
layout(location = 1) in vec4 _flw_color;
layout(location = 2) in vec2 _flw_texCoord;
layout(location = 3) in ivec2 _flw_overlay;
layout(location = 4) in ivec2 _flw_light;
layout(location = 5) in vec3 _flw_normal;
void _flw_layoutVertex() {
flw_vertexPos = vec4(_flw_pos, 1.0);
flw_vertexColor = _flw_color;
flw_vertexTexCoord = _flw_texCoord;
flw_vertexOverlay = _flw_overlay;
flw_vertexLight = _flw_light / 15.0;
flw_vertexNormal = _flw_normal;
}

View file

@ -0,0 +1,15 @@
layout(location = 0) in vec3 _flw_a_pos;
layout(location = 1) in vec4 _flw_a_color;
layout(location = 2) in vec2 _flw_a_texCoord;
layout(location = 3) in ivec2 _flw_a_overlay;
layout(location = 4) in ivec2 _flw_a_light;
layout(location = 5) in vec3 _flw_a_normal;
void _flw_layoutVertex() {
flw_vertexPos = vec4(_flw_a_pos, 1.0);
flw_vertexColor = _flw_a_color;
flw_vertexTexCoord = _flw_a_texCoord;
flw_vertexOverlay = _flw_a_overlay;
flw_vertexLight = (_flw_a_light >> 4) / 15.0;
flw_vertexNormal = _flw_a_normal;
}