mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-07 12:56:31 +01:00
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:
parent
cba04adc91
commit
1def0876d8
50 changed files with 556 additions and 717 deletions
|
@ -40,6 +40,14 @@ public interface VertexList {
|
||||||
|
|
||||||
float normalZ(int index);
|
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) {
|
default void write(MutableVertexList dst, int srcIndex, int dstIndex) {
|
||||||
dst.x(dstIndex, x(srcIndex));
|
dst.x(dstIndex, x(srcIndex));
|
||||||
dst.y(dstIndex, y(srcIndex));
|
dst.y(dstIndex, y(srcIndex));
|
||||||
|
@ -68,7 +76,7 @@ public interface VertexList {
|
||||||
}
|
}
|
||||||
|
|
||||||
default void writeAll(MutableVertexList dst) {
|
default void writeAll(MutableVertexList dst) {
|
||||||
write(dst, 0, 0, vertexCount());
|
write(dst, 0, 0, Math.min(vertexCount(), dst.vertexCount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
int vertexCount();
|
int vertexCount();
|
||||||
|
@ -76,12 +84,4 @@ public interface VertexList {
|
||||||
default boolean isEmpty() {
|
default boolean isEmpty() {
|
||||||
return vertexCount() == 0;
|
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
package com.jozufozu.flywheel.api.vertex;
|
|
||||||
|
|
||||||
public interface VertexListProvider {
|
|
||||||
ReusableVertexList createVertexList();
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +1,11 @@
|
||||||
package com.jozufozu.flywheel.api.vertex;
|
package com.jozufozu.flywheel.api.vertex;
|
||||||
|
|
||||||
public interface ReusableVertexList extends MutableVertexList {
|
public interface VertexView extends MutableVertexList {
|
||||||
long ptr();
|
long ptr();
|
||||||
|
|
||||||
void ptr(long ptr);
|
void ptr(long ptr);
|
||||||
|
|
||||||
void vertexCount(int vertexCount);
|
void vertexCount(int vertexCount);
|
||||||
|
|
||||||
|
long stride();
|
||||||
}
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package com.jozufozu.flywheel.api.vertex;
|
||||||
|
|
||||||
|
public interface VertexViewProvider {
|
||||||
|
VertexView createVertexView();
|
||||||
|
}
|
|
@ -3,15 +3,15 @@ package com.jozufozu.flywheel.api.vertex;
|
||||||
import com.jozufozu.flywheel.impl.vertex.VertexListProviderRegistryImpl;
|
import com.jozufozu.flywheel.impl.vertex.VertexListProviderRegistryImpl;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
|
|
||||||
public final class VertexListProviderRegistry {
|
public final class VertexViewProviderRegistry {
|
||||||
public static VertexListProvider getProvider(VertexFormat format) {
|
public static VertexViewProvider getProvider(VertexFormat format) {
|
||||||
return VertexListProviderRegistryImpl.getProvider(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);
|
VertexListProviderRegistryImpl.setProvider(format, provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
private VertexListProviderRegistry() {
|
private VertexViewProviderRegistry() {
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -89,8 +89,8 @@ public class IndirectPrograms {
|
||||||
.define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE)
|
.define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE)
|
||||||
.withComponent(uniformComponent)
|
.withComponent(uniformComponent)
|
||||||
.withComponent(IndirectComponent::create)
|
.withComponent(IndirectComponent::create)
|
||||||
.withResource(Files.INDIRECT_CULL)
|
.withResource(InstanceType::instanceShader)
|
||||||
.withResource(InstanceType::instanceShader))
|
.withResource(Files.INDIRECT_CULL))
|
||||||
.then((key, program) -> program.setUniformBlockBinding("FlwUniforms", 0)))
|
.then((key, program) -> program.setUniformBlockBinding("FlwUniforms", 0)))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.jozufozu.flywheel.backend.compile;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
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.backend.compile.component.UniformComponent;
|
||||||
import com.jozufozu.flywheel.gl.shader.ShaderType;
|
import com.jozufozu.flywheel.gl.shader.ShaderType;
|
||||||
import com.jozufozu.flywheel.glsl.ShaderSources;
|
import com.jozufozu.flywheel.glsl.ShaderSources;
|
||||||
|
@ -18,9 +18,10 @@ public class PipelineCompiler {
|
||||||
.compiler(PIPELINE.program()
|
.compiler(PIPELINE.program()
|
||||||
.link(PIPELINE.shader(pipeline.glslVersion(), ShaderType.VERTEX)
|
.link(PIPELINE.shader(pipeline.glslVersion(), ShaderType.VERTEX)
|
||||||
.withComponent(uniformComponent)
|
.withComponent(uniformComponent)
|
||||||
.withComponent(key -> pipeline.assembler()
|
|
||||||
.assemble(new Pipeline.InstanceAssemblerContext(InternalLayout.LAYOUT.getAttributeCount(), key.instanceType())))
|
|
||||||
.withResource(pipeline.vertexApiImpl())
|
.withResource(pipeline.vertexApiImpl())
|
||||||
|
.withResource(InternalVertex.LAYOUT_SHADER)
|
||||||
|
.withComponent(key -> pipeline.assembler()
|
||||||
|
.assemble(new Pipeline.InstanceAssemblerContext(InternalVertex.LAYOUT.getAttributeCount(), key.instanceType())))
|
||||||
.withComponents(vertexComponents)
|
.withComponents(vertexComponents)
|
||||||
.withResource(key -> key.instanceType()
|
.withResource(key -> key.instanceType()
|
||||||
.instanceShader())
|
.instanceShader())
|
||||||
|
|
|
@ -11,7 +11,7 @@ import com.jozufozu.flywheel.api.backend.Engine;
|
||||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||||
import com.jozufozu.flywheel.api.instance.Instance;
|
import com.jozufozu.flywheel.api.instance.Instance;
|
||||||
import com.jozufozu.flywheel.api.model.Mesh;
|
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.backend.engine.InstanceHandleImpl;
|
||||||
import com.jozufozu.flywheel.extension.RenderTypeExtension;
|
import com.jozufozu.flywheel.extension.RenderTypeExtension;
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ public class BatchedCrumbling {
|
||||||
|
|
||||||
drawBuffer.prepare(bucket.vertexCount);
|
drawBuffer.prepare(bucket.vertexCount);
|
||||||
|
|
||||||
ReusableVertexList vertexList = drawBuffer.slice(0, 0);
|
VertexView vertexView = drawBuffer.slice(0, 0);
|
||||||
long basePtr = vertexList.ptr();
|
long basePtr = vertexView.ptr();
|
||||||
|
|
||||||
int totalVertices = 0;
|
int totalVertices = 0;
|
||||||
|
|
||||||
|
@ -41,15 +41,15 @@ public class BatchedCrumbling {
|
||||||
var instance = pair.first();
|
var instance = pair.first();
|
||||||
var instancer = pair.second();
|
var instancer = pair.second();
|
||||||
|
|
||||||
totalVertices += bufferOne(instancer, totalVertices, vertexList, drawBuffer, instance);
|
totalVertices += bufferOne(instancer, totalVertices, vertexView, drawBuffer, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
vertexList.ptr(basePtr);
|
vertexView.ptr(basePtr);
|
||||||
vertexList.vertexCount(totalVertices);
|
vertexView.vertexCount(totalVertices);
|
||||||
|
|
||||||
// apply these in bulk
|
// apply these in bulk
|
||||||
BatchingTransforms.applyDecalUVs(vertexList);
|
BatchingTransforms.applyDecalUVs(vertexView);
|
||||||
BatchingTransforms.applyMatrices(vertexList, batchContext.matrices());
|
BatchingTransforms.applyMatrices(vertexView, batchContext.matrices());
|
||||||
|
|
||||||
drawTracker._draw(drawBuffer);
|
drawTracker._draw(drawBuffer);
|
||||||
}
|
}
|
||||||
|
@ -75,25 +75,25 @@ public class BatchedCrumbling {
|
||||||
|
|
||||||
for (TransformCall<?> transformCall : instancer.getTransformCalls()) {
|
for (TransformCall<?> transformCall : instancer.getTransformCalls()) {
|
||||||
var mesh = transformCall.mesh;
|
var mesh = transformCall.mesh;
|
||||||
bucket.vertexCount += mesh.getVertexCount();
|
bucket.vertexCount += mesh.vertexCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out;
|
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;
|
int totalVertices = 0;
|
||||||
|
|
||||||
for (TransformCall<I> transformCall : batchedInstancer.getTransformCalls()) {
|
for (TransformCall<I> transformCall : batchedInstancer.getTransformCalls()) {
|
||||||
Mesh mesh = transformCall.mesh.mesh;
|
Mesh mesh = transformCall.mesh.mesh;
|
||||||
|
|
||||||
vertexList.ptr(drawBuffer.ptrForVertex(baseVertex + totalVertices));
|
vertexView.ptr(drawBuffer.ptrForVertex(baseVertex + totalVertices));
|
||||||
vertexList.vertexCount(mesh.vertexCount());
|
vertexView.vertexCount(mesh.vertexCount());
|
||||||
|
|
||||||
mesh.write(vertexList);
|
mesh.write(vertexView);
|
||||||
batchedInstancer.type.getVertexTransformer()
|
batchedInstancer.type.getVertexTransformer()
|
||||||
.transform(vertexList, (I) instance);
|
.transform(vertexView, (I) instance);
|
||||||
|
|
||||||
totalVertices += mesh.vertexCount();
|
totalVertices += mesh.vertexCount();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,14 +11,14 @@ import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.Flywheel;
|
import com.jozufozu.flywheel.Flywheel;
|
||||||
import com.jozufozu.flywheel.api.model.Mesh;
|
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.VertexListProviderRegistry;
|
import com.jozufozu.flywheel.api.vertex.VertexViewProviderRegistry;
|
||||||
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
|
|
||||||
public class BatchedMeshPool {
|
public class BatchedMeshPool {
|
||||||
private final VertexFormat vertexFormat;
|
private final VertexFormat vertexFormat;
|
||||||
private final ReusableVertexList vertexList;
|
private final VertexView vertexView;
|
||||||
private final int growthMargin;
|
private final int growthMargin;
|
||||||
|
|
||||||
private final Map<Mesh, BufferedMesh> meshes = new HashMap<>();
|
private final Map<Mesh, BufferedMesh> meshes = new HashMap<>();
|
||||||
|
@ -36,7 +36,7 @@ public class BatchedMeshPool {
|
||||||
*/
|
*/
|
||||||
public BatchedMeshPool(VertexFormat vertexFormat) {
|
public BatchedMeshPool(VertexFormat vertexFormat) {
|
||||||
this.vertexFormat = vertexFormat;
|
this.vertexFormat = vertexFormat;
|
||||||
vertexList = VertexListProviderRegistry.getProvider(vertexFormat).createVertexList();
|
vertexView = VertexViewProviderRegistry.getProvider(vertexFormat).createVertexView();
|
||||||
growthMargin = vertexFormat.getVertexSize() * 128;
|
growthMargin = vertexFormat.getVertexSize() * 128;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ public class BatchedMeshPool {
|
||||||
private void bufferPending() {
|
private void bufferPending() {
|
||||||
try {
|
try {
|
||||||
for (BufferedMesh mesh : pendingBuffer) {
|
for (BufferedMesh mesh : pendingBuffer) {
|
||||||
mesh.buffer(vertexList);
|
mesh.write(vertexView);
|
||||||
}
|
}
|
||||||
|
|
||||||
pendingBuffer.clear();
|
pendingBuffer.clear();
|
||||||
|
@ -151,8 +151,8 @@ public class BatchedMeshPool {
|
||||||
|
|
||||||
public class BufferedMesh {
|
public class BufferedMesh {
|
||||||
public final Mesh mesh;
|
public final Mesh mesh;
|
||||||
private final int byteSize;
|
|
||||||
private final int vertexCount;
|
private final int vertexCount;
|
||||||
|
private final int byteSize;
|
||||||
private final Vector4fc boundingSphere;
|
private final Vector4fc boundingSphere;
|
||||||
|
|
||||||
private long byteIndex;
|
private long byteIndex;
|
||||||
|
@ -161,32 +161,32 @@ public class BatchedMeshPool {
|
||||||
private BufferedMesh(Mesh mesh, long byteIndex) {
|
private BufferedMesh(Mesh mesh, long byteIndex) {
|
||||||
this.mesh = mesh;
|
this.mesh = mesh;
|
||||||
vertexCount = mesh.vertexCount();
|
vertexCount = mesh.vertexCount();
|
||||||
boundingSphere = mesh.boundingSphere();
|
|
||||||
byteSize = vertexCount * vertexFormat.getVertexSize();
|
byteSize = vertexCount * vertexFormat.getVertexSize();
|
||||||
|
boundingSphere = mesh.boundingSphere();
|
||||||
this.byteIndex = byteIndex;
|
this.byteIndex = byteIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public VertexFormat vertexFormat() {
|
||||||
|
return vertexFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int vertexCount() {
|
||||||
|
return vertexCount;
|
||||||
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
return byteSize;
|
return byteSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getVertexCount() {
|
|
||||||
return vertexCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector4fc boundingSphere() {
|
public Vector4fc boundingSphere() {
|
||||||
return boundingSphere;
|
return boundingSphere;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VertexFormat getVertexFormat() {
|
|
||||||
return vertexFormat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDeleted() {
|
public boolean isDeleted() {
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return mesh.isEmpty() || isDeleted();
|
return mesh.isEmpty() || isDeleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,15 +194,14 @@ public class BatchedMeshPool {
|
||||||
return BatchedMeshPool.this.data.ptr() + byteIndex;
|
return BatchedMeshPool.this.data.ptr() + byteIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buffer(ReusableVertexList vertexList) {
|
private void write(VertexView vertexView) {
|
||||||
if (isEmpty()) {
|
if (isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
vertexList.ptr(ptr());
|
vertexView.ptr(ptr());
|
||||||
vertexList.vertexCount(vertexCount);
|
vertexView.vertexCount(vertexCount);
|
||||||
|
mesh.write(vertexView);
|
||||||
mesh.write(vertexList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyTo(long ptr) {
|
public void copyTo(long ptr) {
|
||||||
|
|
|
@ -6,8 +6,8 @@ import java.util.List;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.event.ReloadLevelRendererEvent;
|
import com.jozufozu.flywheel.api.event.ReloadLevelRendererEvent;
|
||||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||||
import com.jozufozu.flywheel.api.vertex.ReusableVertexList;
|
import com.jozufozu.flywheel.api.vertex.VertexView;
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexListProvider;
|
import com.jozufozu.flywheel.api.vertex.VertexViewProvider;
|
||||||
import com.jozufozu.flywheel.extension.BufferBuilderExtension;
|
import com.jozufozu.flywheel.extension.BufferBuilderExtension;
|
||||||
import com.jozufozu.flywheel.extension.RenderTypeExtension;
|
import com.jozufozu.flywheel.extension.RenderTypeExtension;
|
||||||
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
||||||
|
@ -17,7 +17,7 @@ import net.minecraft.client.renderer.RenderType;
|
||||||
import net.minecraft.util.Mth;
|
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>
|
* <br>
|
||||||
* Note: The number of vertices needs to be known ahead of time.
|
* 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 VertexFormat format;
|
||||||
private final int stride;
|
private final int stride;
|
||||||
private final boolean sortOnUpload;
|
private final boolean sortOnUpload;
|
||||||
private final VertexListProvider provider;
|
private final VertexViewProvider provider;
|
||||||
|
|
||||||
private MemoryBlock data;
|
private MemoryBlock data;
|
||||||
private ByteBuffer buffer;
|
private ByteBuffer buffer;
|
||||||
|
@ -37,7 +37,7 @@ public class DrawBuffer {
|
||||||
private int vertexCount;
|
private int vertexCount;
|
||||||
private int verticesToDraw;
|
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.renderType = renderType;
|
||||||
this.format = format;
|
this.format = format;
|
||||||
this.stride = stride;
|
this.stride = stride;
|
||||||
|
@ -85,7 +85,7 @@ public class DrawBuffer {
|
||||||
prepared = true;
|
prepared = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReusableVertexList slice(int startVertex, int vertexCount) {
|
public VertexView slice(int startVertex, int vertexCount) {
|
||||||
if (!prepared) {
|
if (!prepared) {
|
||||||
throw new IllegalStateException("Cannot slice DrawBuffer that is not 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);
|
throw new IndexOutOfBoundsException("Vertex count greater than allocated: " + startVertex + " + " + vertexCount + " > " + this.vertexCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReusableVertexList vertexList = provider.createVertexList();
|
VertexView vertexView = provider.createVertexView();
|
||||||
vertexList.ptr(ptrForVertex(startVertex));
|
vertexView.ptr(ptrForVertex(startVertex));
|
||||||
vertexList.vertexCount(vertexCount);
|
vertexView.vertexCount(vertexCount);
|
||||||
return vertexList;
|
return vertexView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long ptrForVertex(long startVertex) {
|
public long ptrForVertex(long startVertex) {
|
||||||
|
|
|
@ -4,8 +4,8 @@ import java.util.EnumMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexListProvider;
|
import com.jozufozu.flywheel.api.vertex.VertexViewProvider;
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexListProviderRegistry;
|
import com.jozufozu.flywheel.api.vertex.VertexViewProviderRegistry;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
@ -15,7 +15,7 @@ public class DrawBufferSet {
|
||||||
private final VertexFormat format;
|
private final VertexFormat format;
|
||||||
private final boolean sortOnUpload;
|
private final boolean sortOnUpload;
|
||||||
private final int stride;
|
private final int stride;
|
||||||
private final VertexListProvider provider;
|
private final VertexViewProvider provider;
|
||||||
private final Map<RenderStage, DrawBuffer> buffers = new EnumMap<>(RenderStage.class);
|
private final Map<RenderStage, DrawBuffer> buffers = new EnumMap<>(RenderStage.class);
|
||||||
|
|
||||||
public DrawBufferSet(RenderType renderType, boolean sortOnUpload) {
|
public DrawBufferSet(RenderType renderType, boolean sortOnUpload) {
|
||||||
|
@ -23,7 +23,7 @@ public class DrawBufferSet {
|
||||||
this.sortOnUpload = sortOnUpload;
|
this.sortOnUpload = sortOnUpload;
|
||||||
format = renderType.format();
|
format = renderType.format();
|
||||||
stride = format.getVertexSize();
|
stride = format.getVertexSize();
|
||||||
provider = VertexListProviderRegistry.getProvider(format);
|
provider = VertexViewProviderRegistry.getProvider(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DrawBuffer getBuffer(RenderStage stage) {
|
public DrawBuffer getBuffer(RenderStage stage) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import com.jozufozu.flywheel.api.instance.InstanceVertexTransformer;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.api.material.MaterialVertexTransformer;
|
import com.jozufozu.flywheel.api.material.MaterialVertexTransformer;
|
||||||
import com.jozufozu.flywheel.api.task.Plan;
|
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.jozufozu.flywheel.lib.task.ForEachSlicePlan;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
|
||||||
|
@ -35,11 +35,11 @@ public class TransformCall<I extends Instance> {
|
||||||
InstanceBoundingSphereTransformer<I> boundingSphereTransformer = instancer.type.getBoundingSphereTransformer();
|
InstanceBoundingSphereTransformer<I> boundingSphereTransformer = instancer.type.getBoundingSphereTransformer();
|
||||||
MaterialVertexTransformer materialVertexTransformer = material.getVertexTransformer();
|
MaterialVertexTransformer materialVertexTransformer = material.getVertexTransformer();
|
||||||
|
|
||||||
meshVertexCount = mesh.getVertexCount();
|
meshVertexCount = mesh.vertexCount();
|
||||||
Vector4fc meshBoundingSphere = mesh.boundingSphere();
|
Vector4fc meshBoundingSphere = mesh.boundingSphere();
|
||||||
|
|
||||||
drawPlan = ForEachSlicePlan.of(instancer::getAll, (subList, ctx) -> {
|
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();
|
Vector4f boundingSphere = new Vector4f();
|
||||||
|
|
||||||
for (I instance : subList) {
|
for (I instance : subList) {
|
||||||
|
@ -51,12 +51,12 @@ public class TransformCall<I extends Instance> {
|
||||||
}
|
}
|
||||||
|
|
||||||
final int baseVertex = ctx.vertexCounter.getAndAdd(meshVertexCount);
|
final int baseVertex = ctx.vertexCounter.getAndAdd(meshVertexCount);
|
||||||
vertexList.ptr(ctx.buffer.ptrForVertex(baseVertex));
|
vertexView.ptr(ctx.buffer.ptrForVertex(baseVertex));
|
||||||
|
|
||||||
mesh.copyTo(vertexList.ptr());
|
mesh.copyTo(vertexView.ptr());
|
||||||
instanceVertexTransformer.transform(vertexList, instance);
|
instanceVertexTransformer.transform(vertexView, instance);
|
||||||
materialVertexTransformer.transform(vertexList, ctx.level);
|
materialVertexTransformer.transform(vertexView, ctx.level);
|
||||||
BatchingTransforms.applyMatrices(vertexList, ctx.matrices);
|
BatchingTransforms.applyMatrices(vertexView, ctx.matrices);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,8 @@ import java.util.Map;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.model.Mesh;
|
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.GlNumericType;
|
||||||
import com.jozufozu.flywheel.gl.array.GlVertexArray;
|
import com.jozufozu.flywheel.gl.array.GlVertexArray;
|
||||||
import com.jozufozu.flywheel.gl.buffer.GlBuffer;
|
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;
|
import com.jozufozu.flywheel.lib.model.QuadIndexSequence;
|
||||||
|
|
||||||
public class IndirectMeshPool {
|
public class IndirectMeshPool {
|
||||||
|
private final VertexView vertexView;
|
||||||
private final Map<Mesh, BufferedMesh> meshes = new HashMap<>();
|
private final Map<Mesh, BufferedMesh> meshes = new HashMap<>();
|
||||||
private final List<BufferedMesh> meshList = new ArrayList<>();
|
private final List<BufferedMesh> meshList = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -29,13 +31,14 @@ public class IndirectMeshPool {
|
||||||
* Create a new mesh pool.
|
* Create a new mesh pool.
|
||||||
*/
|
*/
|
||||||
public IndirectMeshPool() {
|
public IndirectMeshPool() {
|
||||||
|
vertexView = InternalVertex.createVertexView();
|
||||||
vbo = new GlBuffer();
|
vbo = new GlBuffer();
|
||||||
ebo = new GlBuffer();
|
ebo = new GlBuffer();
|
||||||
vertexArray = GlVertexArray.create();
|
vertexArray = GlVertexArray.create();
|
||||||
|
|
||||||
vertexArray.setElementBuffer(ebo.handle());
|
vertexArray.setElementBuffer(ebo.handle());
|
||||||
vertexArray.bindVertexBuffer(0, vbo.handle(), 0, InternalLayout.LAYOUT.getStride());
|
vertexArray.bindVertexBuffer(0, vbo.handle(), 0, InternalVertex.LAYOUT.getStride());
|
||||||
vertexArray.bindAttributes(0, 0, InternalLayout.LAYOUT.attributes());
|
vertexArray.bindAttributes(0, 0, InternalVertex.LAYOUT.attributes());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,8 +92,6 @@ public class IndirectMeshPool {
|
||||||
final long vertexPtr = vertexBlock.ptr();
|
final long vertexPtr = vertexBlock.ptr();
|
||||||
final long indexPtr = indexBlock.ptr();
|
final long indexPtr = indexBlock.ptr();
|
||||||
|
|
||||||
var target = InternalLayout.createVertexList();
|
|
||||||
|
|
||||||
int byteIndex = 0;
|
int byteIndex = 0;
|
||||||
int baseVertex = 0;
|
int baseVertex = 0;
|
||||||
int firstIndex = maxQuadIndexCount;
|
int firstIndex = maxQuadIndexCount;
|
||||||
|
@ -98,11 +99,10 @@ public class IndirectMeshPool {
|
||||||
mesh.byteIndex = byteIndex;
|
mesh.byteIndex = byteIndex;
|
||||||
mesh.baseVertex = baseVertex;
|
mesh.baseVertex = baseVertex;
|
||||||
|
|
||||||
target.ptr(vertexPtr + mesh.byteIndex);
|
mesh.write(vertexPtr, vertexView);
|
||||||
mesh.mesh.write(target);
|
|
||||||
|
|
||||||
byteIndex += mesh.size();
|
byteIndex += mesh.size();
|
||||||
baseVertex += mesh.mesh.vertexCount();
|
baseVertex += mesh.vertexCount();
|
||||||
|
|
||||||
var indexFiller = mesh.mesh.indexSequence();
|
var indexFiller = mesh.mesh.indexSequence();
|
||||||
if (indexFiller == QuadIndexSequence.INSTANCE) {
|
if (indexFiller == QuadIndexSequence.INSTANCE) {
|
||||||
|
@ -141,16 +141,25 @@ public class IndirectMeshPool {
|
||||||
|
|
||||||
public static class BufferedMesh {
|
public static class BufferedMesh {
|
||||||
private final Mesh mesh;
|
private final Mesh mesh;
|
||||||
|
private final int vertexCount;
|
||||||
|
private final int byteSize;
|
||||||
|
|
||||||
private long byteIndex;
|
private long byteIndex;
|
||||||
private int baseVertex;
|
private int baseVertex;
|
||||||
private int firstIndex;
|
private int firstIndex;
|
||||||
|
|
||||||
private BufferedMesh(Mesh mesh) {
|
private BufferedMesh(Mesh mesh) {
|
||||||
this.mesh = mesh;
|
this.mesh = mesh;
|
||||||
|
vertexCount = mesh.vertexCount();
|
||||||
|
byteSize = vertexCount * InternalVertex.LAYOUT.getStride();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int vertexCount() {
|
||||||
|
return vertexCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
return mesh.vertexCount() * InternalLayout.LAYOUT.getStride();
|
return byteSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int indexCount() {
|
public int indexCount() {
|
||||||
|
@ -164,5 +173,11 @@ public class IndirectMeshPool {
|
||||||
public int firstIndex() {
|
public int firstIndex() {
|
||||||
return firstIndex;
|
return firstIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void write(long ptr, VertexView vertexView) {
|
||||||
|
vertexView.ptr(ptr + byteIndex);
|
||||||
|
vertexView.vertexCount(vertexCount);
|
||||||
|
mesh.write(vertexView);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.jozufozu.flywheel.backend.engine.instancing;
|
package com.jozufozu.flywheel.backend.engine.instancing;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.backend.InternalVertex;
|
||||||
import com.jozufozu.flywheel.backend.engine.InstanceHandleImpl;
|
import com.jozufozu.flywheel.backend.engine.InstanceHandleImpl;
|
||||||
import com.jozufozu.flywheel.gl.array.GlVertexArray;
|
import com.jozufozu.flywheel.gl.array.GlVertexArray;
|
||||||
|
|
||||||
|
@ -8,7 +9,6 @@ public class DrawCall {
|
||||||
private final InstancedInstancer<?> instancer;
|
private final InstancedInstancer<?> instancer;
|
||||||
private final InstancedMeshPool.BufferedMesh mesh;
|
private final InstancedMeshPool.BufferedMesh mesh;
|
||||||
|
|
||||||
private final int meshAttributes;
|
|
||||||
private GlVertexArray vao;
|
private GlVertexArray vao;
|
||||||
private GlVertexArray vaoScratch;
|
private GlVertexArray vaoScratch;
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ public class DrawCall {
|
||||||
this.mesh = mesh;
|
this.mesh = mesh;
|
||||||
this.shaderState = shaderState;
|
this.shaderState = shaderState;
|
||||||
|
|
||||||
meshAttributes = this.mesh.getAttributeCount();
|
|
||||||
vao = GlVertexArray.create();
|
vao = GlVertexArray.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +36,7 @@ public class DrawCall {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
instancer.bindIfNeeded(vao, meshAttributes);
|
instancer.bindIfNeeded(vao, InternalVertex.LAYOUT.getAttributeCount());
|
||||||
mesh.setup(vao);
|
mesh.setup(vao);
|
||||||
|
|
||||||
vao.bindForDraw();
|
vao.bindForDraw();
|
||||||
|
@ -59,7 +58,7 @@ public class DrawCall {
|
||||||
|
|
||||||
var vao = lazyScratchVao();
|
var vao = lazyScratchVao();
|
||||||
|
|
||||||
instancer.bindRaw(vao, meshAttributes, impl.index);
|
instancer.bindRaw(vao, InternalVertex.LAYOUT.getAttributeCount(), impl.index);
|
||||||
mesh.setup(vao);
|
mesh.setup(vao);
|
||||||
|
|
||||||
vao.bindForDraw();
|
vao.bindForDraw();
|
||||||
|
|
|
@ -12,13 +12,15 @@ import org.lwjgl.opengl.GL32;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.Flywheel;
|
import com.jozufozu.flywheel.Flywheel;
|
||||||
import com.jozufozu.flywheel.api.model.Mesh;
|
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.GlPrimitive;
|
||||||
import com.jozufozu.flywheel.gl.array.GlVertexArray;
|
import com.jozufozu.flywheel.gl.array.GlVertexArray;
|
||||||
import com.jozufozu.flywheel.gl.buffer.GlBuffer;
|
import com.jozufozu.flywheel.gl.buffer.GlBuffer;
|
||||||
import com.jozufozu.flywheel.gl.buffer.MappedBuffer;
|
import com.jozufozu.flywheel.gl.buffer.MappedBuffer;
|
||||||
|
|
||||||
public class InstancedMeshPool {
|
public class InstancedMeshPool {
|
||||||
|
private final VertexView vertexView;
|
||||||
private final Map<Mesh, BufferedMesh> meshes = new HashMap<>();
|
private final Map<Mesh, BufferedMesh> meshes = new HashMap<>();
|
||||||
private final List<BufferedMesh> allBuffered = new ArrayList<>();
|
private final List<BufferedMesh> allBuffered = new ArrayList<>();
|
||||||
private final List<BufferedMesh> pendingUpload = new ArrayList<>();
|
private final List<BufferedMesh> pendingUpload = new ArrayList<>();
|
||||||
|
@ -33,7 +35,8 @@ public class InstancedMeshPool {
|
||||||
* Create a new mesh pool.
|
* Create a new mesh pool.
|
||||||
*/
|
*/
|
||||||
public InstancedMeshPool() {
|
public InstancedMeshPool() {
|
||||||
int stride = InternalLayout.LAYOUT.getStride();
|
vertexView = InternalVertex.createVertexView();
|
||||||
|
int stride = InternalVertex.LAYOUT.getStride();
|
||||||
vbo = new GlBuffer();
|
vbo = new GlBuffer();
|
||||||
vbo.growthFunction(l -> Math.max(l + stride * 128L, (long) (l * 1.6)));
|
vbo.growthFunction(l -> Math.max(l + stride * 128L, (long) (l * 1.6)));
|
||||||
}
|
}
|
||||||
|
@ -109,11 +112,8 @@ public class InstancedMeshPool {
|
||||||
try (MappedBuffer mapped = vbo.map()) {
|
try (MappedBuffer mapped = vbo.map()) {
|
||||||
long ptr = mapped.ptr();
|
long ptr = mapped.ptr();
|
||||||
|
|
||||||
var vertexList = InternalLayout.createVertexList();
|
|
||||||
|
|
||||||
for (BufferedMesh mesh : pendingUpload) {
|
for (BufferedMesh mesh : pendingUpload) {
|
||||||
vertexList.ptr(ptr + mesh.byteIndex);
|
mesh.write(ptr, vertexView);
|
||||||
mesh.mesh.write(vertexList);
|
|
||||||
mesh.boundTo.clear();
|
mesh.boundTo.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,10 @@ public class InstancedMeshPool {
|
||||||
|
|
||||||
public class BufferedMesh {
|
public class BufferedMesh {
|
||||||
private final Mesh mesh;
|
private final Mesh mesh;
|
||||||
|
private final int vertexCount;
|
||||||
|
private final int byteSize;
|
||||||
private final int ebo;
|
private final int ebo;
|
||||||
|
|
||||||
private long byteIndex;
|
private long byteIndex;
|
||||||
private boolean deleted;
|
private boolean deleted;
|
||||||
|
|
||||||
|
@ -145,16 +148,18 @@ public class InstancedMeshPool {
|
||||||
|
|
||||||
private BufferedMesh(Mesh mesh, long byteIndex, EboCache eboCache) {
|
private BufferedMesh(Mesh mesh, long byteIndex, EboCache eboCache) {
|
||||||
this.mesh = mesh;
|
this.mesh = mesh;
|
||||||
|
vertexCount = mesh.vertexCount();
|
||||||
|
byteSize = vertexCount * InternalVertex.LAYOUT.getStride();
|
||||||
this.byteIndex = byteIndex;
|
this.byteIndex = byteIndex;
|
||||||
this.ebo = eboCache.get(mesh.indexSequence(), mesh.indexCount());
|
this.ebo = eboCache.get(mesh.indexSequence(), mesh.indexCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int vertexCount() {
|
||||||
return mesh.vertexCount() * InternalLayout.LAYOUT.getStride();
|
return vertexCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAttributeCount() {
|
public int size() {
|
||||||
return InternalLayout.LAYOUT.getAttributeCount();
|
return byteSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDeleted() {
|
public boolean isDeleted() {
|
||||||
|
@ -165,10 +170,20 @@ public class InstancedMeshPool {
|
||||||
return mesh.isEmpty() || isDeleted();
|
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) {
|
public void setup(GlVertexArray vao) {
|
||||||
if (boundTo.add(vao)) {
|
if (boundTo.add(vao)) {
|
||||||
vao.bindVertexBuffer(0, InstancedMeshPool.this.vbo.handle(), byteIndex, InternalLayout.LAYOUT.getStride());
|
vao.bindVertexBuffer(0, InstancedMeshPool.this.vbo.handle(), byteIndex, InternalVertex.LAYOUT.getStride());
|
||||||
vao.bindAttributes(0, 0, InternalLayout.LAYOUT.attributes());
|
vao.bindAttributes(0, 0, InternalVertex.LAYOUT.attributes());
|
||||||
vao.setElementBuffer(ebo);
|
vao.setElementBuffer(ebo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.jozufozu.flywheel.extension;
|
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;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,9 +11,9 @@ import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
public interface VertexFormatExtension {
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,15 +2,15 @@ package com.jozufozu.flywheel.impl.vertex;
|
||||||
|
|
||||||
import org.lwjgl.system.MemoryUtil;
|
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.math.RenderMath;
|
||||||
import com.jozufozu.flywheel.lib.vertex.AbstractVertexList;
|
import com.jozufozu.flywheel.lib.vertex.AbstractVertexView;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.LightTexture;
|
import net.minecraft.client.renderer.LightTexture;
|
||||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
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 VertexFormat format;
|
||||||
protected final int stride;
|
protected final int stride;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ public class InferredVertexListImpl extends AbstractVertexList implements Reusab
|
||||||
protected final int lightOffset;
|
protected final int lightOffset;
|
||||||
protected final int normalOffset;
|
protected final int normalOffset;
|
||||||
|
|
||||||
public InferredVertexListImpl(InferredVertexFormatInfo formatInfo) {
|
public InferredVertexView(InferredVertexFormatInfo formatInfo) {
|
||||||
format = formatInfo.format;
|
format = formatInfo.format;
|
||||||
stride = format.getVertexSize();
|
stride = format.getVertexSize();
|
||||||
positionOffset = formatInfo.positionOffset;
|
positionOffset = formatInfo.positionOffset;
|
||||||
|
@ -32,6 +32,11 @@ public class InferredVertexListImpl extends AbstractVertexList implements Reusab
|
||||||
normalOffset = formatInfo.normalOffset;
|
normalOffset = formatInfo.normalOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long stride() {
|
||||||
|
return stride;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float x(int index) {
|
public float x(int index) {
|
||||||
if (positionOffset < 0) return 0;
|
if (positionOffset < 0) return 0;
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,23 +1,23 @@
|
||||||
package com.jozufozu.flywheel.impl.vertex;
|
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.jozufozu.flywheel.extension.VertexFormatExtension;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
|
|
||||||
// TODO: Add freezing
|
// TODO: Add freezing
|
||||||
public final class VertexListProviderRegistryImpl {
|
public final class VertexListProviderRegistryImpl {
|
||||||
public static VertexListProvider getProvider(VertexFormat format) {
|
public static VertexViewProvider getProvider(VertexFormat format) {
|
||||||
VertexFormatExtension extension = (VertexFormatExtension) format;
|
VertexFormatExtension extension = (VertexFormatExtension) format;
|
||||||
VertexListProvider provider = extension.flywheel$getVertexListProvider();
|
VertexViewProvider provider = extension.flywheel$getVertexViewProvider();
|
||||||
if (provider == null) {
|
if (provider == null) {
|
||||||
provider = new InferredVertexListProviderImpl(format);
|
provider = new InferredVertexViewProvider(format);
|
||||||
extension.flywheel$setVertexListProvider(provider);
|
extension.flywheel$setVertexViewProvider(provider);
|
||||||
}
|
}
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setProvider(VertexFormat format, VertexListProvider provider) {
|
public static void setProvider(VertexFormat format, VertexViewProvider provider) {
|
||||||
((VertexFormatExtension) format).flywheel$setVertexListProvider(provider);
|
((VertexFormatExtension) format).flywheel$setVertexViewProvider(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
private VertexListProviderRegistryImpl() {
|
private VertexListProviderRegistryImpl() {
|
||||||
|
|
|
@ -12,13 +12,12 @@ import com.dreizak.miniball.highdim.Miniball;
|
||||||
import com.dreizak.miniball.model.PointSet;
|
import com.dreizak.miniball.model.PointSet;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.api.model.Mesh;
|
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.VertexList;
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexListProviderRegistry;
|
import com.jozufozu.flywheel.api.vertex.VertexViewProviderRegistry;
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexType;
|
|
||||||
import com.jozufozu.flywheel.lib.material.Materials;
|
import com.jozufozu.flywheel.lib.material.Materials;
|
||||||
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
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;
|
||||||
import com.mojang.blaze3d.vertex.BufferBuilder.DrawState;
|
import com.mojang.blaze3d.vertex.BufferBuilder.DrawState;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
|
@ -58,24 +57,23 @@ public final class ModelUtil {
|
||||||
return dispatcher;
|
return dispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MemoryBlock convertVanillaBuffer(BufferBuilder.RenderedBuffer buffer, VertexType vertexType) {
|
public static MemoryBlock convertVanillaBuffer(BufferBuilder.RenderedBuffer buffer, VertexView vertexView) {
|
||||||
DrawState drawState = buffer.drawState();
|
DrawState drawState = buffer.drawState();
|
||||||
int vertexCount = drawState.vertexCount();
|
int vertexCount = drawState.vertexCount();
|
||||||
VertexFormat srcFormat = drawState.format();
|
VertexFormat srcFormat = drawState.format();
|
||||||
|
|
||||||
ByteBuffer src = buffer.vertexBuffer();
|
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 srcPtr = MemoryUtil.memAddress(src);
|
||||||
long dstPtr = dst.ptr();
|
long dstPtr = dst.ptr();
|
||||||
|
|
||||||
ReusableVertexList srcList = VertexListProviderRegistry.getProvider(srcFormat).createVertexList();
|
VertexView srcView = VertexViewProviderRegistry.getProvider(srcFormat).createVertexView();
|
||||||
ReusableVertexList dstList = vertexType.createVertexList();
|
srcView.ptr(srcPtr);
|
||||||
srcList.ptr(srcPtr);
|
vertexView.ptr(dstPtr);
|
||||||
dstList.ptr(dstPtr);
|
srcView.vertexCount(vertexCount);
|
||||||
srcList.vertexCount(vertexCount);
|
vertexView.vertexCount(vertexCount);
|
||||||
dstList.vertexCount(vertexCount);
|
|
||||||
|
|
||||||
srcList.writeAll(dstList);
|
srcView.writeAll(vertexView);
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
@ -110,12 +108,12 @@ public final class ModelUtil {
|
||||||
|
|
||||||
public static Vector4f computeBoundingSphere(Iterable<Mesh> meshes) {
|
public static Vector4f computeBoundingSphere(Iterable<Mesh> meshes) {
|
||||||
int vertexCount = computeTotalVertexCount(meshes);
|
int vertexCount = computeTotalVertexCount(meshes);
|
||||||
var block = MemoryBlock.malloc((long) vertexCount * PositionOnlyVertexList.STRIDE);
|
var block = MemoryBlock.malloc((long) vertexCount * PosVertexView.STRIDE);
|
||||||
var vertexList = new PositionOnlyVertexList();
|
var vertexList = new PosVertexView();
|
||||||
|
|
||||||
int baseVertex = 0;
|
int baseVertex = 0;
|
||||||
for (Mesh mesh : meshes) {
|
for (Mesh mesh : meshes) {
|
||||||
vertexList.ptr(block.ptr() + (long) baseVertex * PositionOnlyVertexList.STRIDE);
|
vertexList.ptr(block.ptr() + (long) baseVertex * PosVertexView.STRIDE);
|
||||||
mesh.write(vertexList);
|
mesh.write(vertexList);
|
||||||
baseVertex += mesh.vertexCount();
|
baseVertex += mesh.vertexCount();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,40 +5,37 @@ import org.joml.Vector4f;
|
||||||
import org.joml.Vector4fc;
|
import org.joml.Vector4fc;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
|
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
|
||||||
import com.jozufozu.flywheel.api.vertex.ReusableVertexList;
|
import com.jozufozu.flywheel.api.vertex.VertexView;
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexType;
|
|
||||||
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
||||||
|
|
||||||
public class SimpleMesh implements QuadMesh {
|
public class SimpleMesh implements QuadMesh {
|
||||||
private final VertexType vertexType;
|
|
||||||
private final int vertexCount;
|
private final int vertexCount;
|
||||||
private final MemoryBlock data;
|
private final VertexView vertexView;
|
||||||
private final ReusableVertexList vertexList;
|
|
||||||
private final Vector4f boundingSphere;
|
private final Vector4f boundingSphere;
|
||||||
|
private final MemoryBlock data;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final String descriptor;
|
private final String descriptor;
|
||||||
|
|
||||||
public SimpleMesh(VertexType vertexType, MemoryBlock data, @Nullable String descriptor) {
|
public SimpleMesh(VertexView vertexView, MemoryBlock data, @Nullable String descriptor) {
|
||||||
this.vertexType = vertexType;
|
this.vertexView = vertexView;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.descriptor = descriptor;
|
this.descriptor = descriptor;
|
||||||
|
|
||||||
int bytes = (int) data.size();
|
int bytes = (int) data.size();
|
||||||
int stride = vertexType.getStride();
|
int stride = (int) this.vertexView.stride();
|
||||||
if (bytes % stride != 0) {
|
if (bytes % stride != 0) {
|
||||||
throw new IllegalArgumentException("MemoryBlock contains non-whole amount of vertices!");
|
throw new IllegalArgumentException("MemoryBlock contains non-whole amount of vertices!");
|
||||||
}
|
}
|
||||||
vertexCount = bytes / stride;
|
vertexCount = bytes / stride;
|
||||||
|
|
||||||
vertexList = this.vertexType.createVertexList();
|
this.vertexView.ptr(data.ptr());
|
||||||
vertexList.ptr(data.ptr());
|
this.vertexView.vertexCount(vertexCount);
|
||||||
vertexList.vertexCount(vertexCount);
|
|
||||||
|
|
||||||
boundingSphere = ModelUtil.computeBoundingSphere(vertexList);
|
boundingSphere = ModelUtil.computeBoundingSphere(vertexView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleMesh(VertexType vertexType, MemoryBlock data) {
|
public SimpleMesh(VertexView vertexView, MemoryBlock data) {
|
||||||
this(vertexType, data, null);
|
this(vertexView, data, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,7 +45,7 @@ public class SimpleMesh implements QuadMesh {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(MutableVertexList dst) {
|
public void write(MutableVertexList dst) {
|
||||||
vertexList.writeAll(dst);
|
vertexView.writeAll(dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,6 +60,6 @@ public class SimpleMesh implements QuadMesh {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SimpleMesh{" + "vertexType=" + vertexType + ",vertexCount=" + vertexCount + ",descriptor={" + descriptor + "}" + "}";
|
return "SimpleMesh{" + "vertexCount=" + vertexCount + ",descriptor={" + descriptor + "}" + "}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,13 @@ import java.util.function.BiFunction;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.api.model.Mesh;
|
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.memory.MemoryBlock;
|
||||||
import com.jozufozu.flywheel.lib.model.ModelUtil;
|
import com.jozufozu.flywheel.lib.model.ModelUtil;
|
||||||
import com.jozufozu.flywheel.lib.model.SimpleMesh;
|
import com.jozufozu.flywheel.lib.model.SimpleMesh;
|
||||||
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ResultConsumer;
|
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ResultConsumer;
|
||||||
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ShadeSeparatedResultConsumer;
|
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 com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
@ -83,8 +84,9 @@ public class BakedModelBuilder {
|
||||||
ShadeSeparatedResultConsumer resultConsumer = (renderType, shaded, data) -> {
|
ShadeSeparatedResultConsumer resultConsumer = (renderType, shaded, data) -> {
|
||||||
Material material = materialFunc.apply(renderType, shaded);
|
Material material = materialFunc.apply(renderType, shaded);
|
||||||
if (material != null) {
|
if (material != null) {
|
||||||
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
|
VertexView vertexView = new NoOverlayVertexView();
|
||||||
meshMapBuilder.put(material, new SimpleMesh(VertexTypes.BLOCK, meshData, "source=BakedModelBuilder," + "bakedModel=" + bakedModel + ",renderType=" + renderType + ",shaded=" + shaded));
|
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);
|
BakedModelBufferer.bufferSingleShadeSeparated(ModelUtil.VANILLA_RENDERER.getModelRenderer(), renderWorld, bakedModel, blockState, poseStack, modelData, resultConsumer);
|
||||||
|
@ -92,8 +94,9 @@ public class BakedModelBuilder {
|
||||||
ResultConsumer resultConsumer = (renderType, data) -> {
|
ResultConsumer resultConsumer = (renderType, data) -> {
|
||||||
Material material = materialFunc.apply(renderType, true);
|
Material material = materialFunc.apply(renderType, true);
|
||||||
if (material != null) {
|
if (material != null) {
|
||||||
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
|
VertexView vertexView = new NoOverlayVertexView();
|
||||||
meshMapBuilder.put(material, new SimpleMesh(VertexTypes.BLOCK, meshData, "source=BakedModelBuilder," + "bakedModel=" + bakedModel + ",renderType=" + renderType));
|
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);
|
BakedModelBufferer.bufferSingle(ModelUtil.VANILLA_RENDERER.getModelRenderer(), renderWorld, bakedModel, blockState, poseStack, modelData, resultConsumer);
|
||||||
|
|
|
@ -5,12 +5,13 @@ import java.util.function.BiFunction;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.api.model.Mesh;
|
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.memory.MemoryBlock;
|
||||||
import com.jozufozu.flywheel.lib.model.ModelUtil;
|
import com.jozufozu.flywheel.lib.model.ModelUtil;
|
||||||
import com.jozufozu.flywheel.lib.model.SimpleMesh;
|
import com.jozufozu.flywheel.lib.model.SimpleMesh;
|
||||||
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ResultConsumer;
|
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ResultConsumer;
|
||||||
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ShadeSeparatedResultConsumer;
|
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 com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
@ -72,8 +73,9 @@ public class BlockModelBuilder {
|
||||||
ShadeSeparatedResultConsumer resultConsumer = (renderType, shaded, data) -> {
|
ShadeSeparatedResultConsumer resultConsumer = (renderType, shaded, data) -> {
|
||||||
Material material = materialFunc.apply(renderType, shaded);
|
Material material = materialFunc.apply(renderType, shaded);
|
||||||
if (material != null) {
|
if (material != null) {
|
||||||
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
|
VertexView vertexView = new NoOverlayVertexView();
|
||||||
meshMapBuilder.put(material, new SimpleMesh(VertexTypes.BLOCK, meshData, "source=BlockModelBuilder," + "blockState=" + state + ",renderType=" + renderType + ",shaded=" + shaded));
|
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);
|
BakedModelBufferer.bufferBlockShadeSeparated(ModelUtil.VANILLA_RENDERER, renderWorld, state, poseStack, modelData, resultConsumer);
|
||||||
|
@ -81,8 +83,9 @@ public class BlockModelBuilder {
|
||||||
ResultConsumer resultConsumer = (renderType, data) -> {
|
ResultConsumer resultConsumer = (renderType, data) -> {
|
||||||
Material material = materialFunc.apply(renderType, true);
|
Material material = materialFunc.apply(renderType, true);
|
||||||
if (material != null) {
|
if (material != null) {
|
||||||
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
|
VertexView vertexView = new NoOverlayVertexView();
|
||||||
meshMapBuilder.put(material, new SimpleMesh(VertexTypes.BLOCK, meshData, "source=BlockModelBuilder," + "blockState=" + state + ",renderType=" + renderType));
|
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);
|
BakedModelBufferer.bufferBlock(ModelUtil.VANILLA_RENDERER, renderWorld, state, poseStack, modelData, resultConsumer);
|
||||||
|
|
|
@ -8,12 +8,13 @@ import java.util.function.BiFunction;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.api.model.Mesh;
|
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.memory.MemoryBlock;
|
||||||
import com.jozufozu.flywheel.lib.model.ModelUtil;
|
import com.jozufozu.flywheel.lib.model.ModelUtil;
|
||||||
import com.jozufozu.flywheel.lib.model.SimpleMesh;
|
import com.jozufozu.flywheel.lib.model.SimpleMesh;
|
||||||
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ResultConsumer;
|
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ResultConsumer;
|
||||||
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ShadeSeparatedResultConsumer;
|
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 com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
@ -76,8 +77,9 @@ public class MultiBlockModelBuilder {
|
||||||
ShadeSeparatedResultConsumer resultConsumer = (renderType, shaded, data) -> {
|
ShadeSeparatedResultConsumer resultConsumer = (renderType, shaded, data) -> {
|
||||||
Material material = materialFunc.apply(renderType, shaded);
|
Material material = materialFunc.apply(renderType, shaded);
|
||||||
if (material != null) {
|
if (material != null) {
|
||||||
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
|
VertexView vertexView = new NoOverlayVertexView();
|
||||||
meshMapBuilder.put(material, new SimpleMesh(VertexTypes.BLOCK, meshData, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded));
|
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);
|
BakedModelBufferer.bufferMultiBlockShadeSeparated(blocks, ModelUtil.VANILLA_RENDERER, renderWorld, poseStack, modelDataMap, resultConsumer);
|
||||||
|
@ -85,8 +87,9 @@ public class MultiBlockModelBuilder {
|
||||||
ResultConsumer resultConsumer = (renderType, data) -> {
|
ResultConsumer resultConsumer = (renderType, data) -> {
|
||||||
Material material = materialFunc.apply(renderType, true);
|
Material material = materialFunc.apply(renderType, true);
|
||||||
if (material != null) {
|
if (material != null) {
|
||||||
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
|
VertexView vertexView = new NoOverlayVertexView();
|
||||||
meshMapBuilder.put(material, new SimpleMesh(VertexTypes.BLOCK, meshData, "source=MultiBlockModelBuilder," + "renderType=" + renderType));
|
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);
|
BakedModelBufferer.bufferMultiBlock(blocks, ModelUtil.VANILLA_RENDERER, renderWorld, poseStack, modelDataMap, resultConsumer);
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.joml.Vector2f;
|
||||||
import com.jozufozu.flywheel.api.model.Mesh;
|
import com.jozufozu.flywheel.api.model.Mesh;
|
||||||
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
||||||
import com.jozufozu.flywheel.lib.model.SimpleMesh;
|
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 com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -32,7 +32,7 @@ public final class ModelPartConverter {
|
||||||
vertexWriter.setTextureMapper(textureMapper);
|
vertexWriter.setTextureMapper(textureMapper);
|
||||||
modelPart.render(poseStack, vertexWriter, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY);
|
modelPart.render(poseStack, vertexWriter, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY);
|
||||||
MemoryBlock data = vertexWriter.copyDataAndReset();
|
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) {
|
public static Mesh convert(ModelLayerLocation layer, @Nullable TextureAtlasSprite sprite, String... childPath) {
|
||||||
|
|
|
@ -4,16 +4,14 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2f;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexType;
|
|
||||||
import com.jozufozu.flywheel.lib.math.RenderMath;
|
import com.jozufozu.flywheel.lib.math.RenderMath;
|
||||||
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
||||||
import com.jozufozu.flywheel.lib.model.part.ModelPartConverter.TextureMapper;
|
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;
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
|
||||||
class VertexWriter implements VertexConsumer {
|
class VertexWriter implements VertexConsumer {
|
||||||
private static final VertexType VERTEX_TYPE = VertexTypes.POS_TEX_NORMAL;
|
private static final int STRIDE = (int) PosTexNormalVertexView.STRIDE;
|
||||||
private static final int STRIDE = VERTEX_TYPE.getStride();
|
|
||||||
private static final int GROWTH_MARGIN = 128 * STRIDE;
|
private static final int GROWTH_MARGIN = 128 * STRIDE;
|
||||||
|
|
||||||
private MemoryBlock data;
|
private MemoryBlock data;
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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) {
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,11 +2,15 @@ package com.jozufozu.flywheel.lib.vertex;
|
||||||
|
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
|
|
||||||
import com.jozufozu.flywheel.lib.math.RenderMath;
|
import com.jozufozu.flywheel.lib.math.RenderMath;
|
||||||
|
|
||||||
public class FullVertexList extends AbstractVertexList {
|
public class FullVertexView extends AbstractVertexView {
|
||||||
private static final long STRIDE = 36;
|
public static final long STRIDE = 36;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long stride() {
|
||||||
|
return STRIDE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float x(int index) {
|
public float x(int index) {
|
||||||
|
@ -60,7 +64,7 @@ public class FullVertexList extends AbstractVertexList {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int light(int index) {
|
public int light(int index) {
|
||||||
return MemoryUtil.memGetInt(ptr + index * STRIDE + 28) << 4;
|
return MemoryUtil.memGetInt(ptr + index * STRIDE + 28);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -130,7 +134,7 @@ public class FullVertexList extends AbstractVertexList {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void light(int index, int light) {
|
public void light(int index, int light) {
|
||||||
MemoryUtil.memPutInt(ptr + index * STRIDE + 28, light >> 4);
|
MemoryUtil.memPutInt(ptr + index * STRIDE + 28, light);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -147,34 +151,4 @@ public class FullVertexList extends AbstractVertexList {
|
||||||
public void normalZ(int index, float normalZ) {
|
public void normalZ(int index, float normalZ) {
|
||||||
MemoryUtil.memPutByte(ptr + index * STRIDE + 34, RenderMath.nb(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -2,13 +2,15 @@ package com.jozufozu.flywheel.lib.vertex;
|
||||||
|
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
|
|
||||||
import com.jozufozu.flywheel.lib.math.RenderMath;
|
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 {
|
@Override
|
||||||
private static final long STRIDE = 32;
|
public long stride() {
|
||||||
|
return STRIDE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float x(int index) {
|
public float x(int index) {
|
||||||
|
@ -55,14 +57,9 @@ public class BlockVertexList extends AbstractVertexList {
|
||||||
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 20);
|
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int overlay(int index) {
|
|
||||||
return OverlayTexture.NO_OVERLAY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int light(int index) {
|
public int light(int index) {
|
||||||
return MemoryUtil.memGetInt(ptr + index * STRIDE + 24) << 4;
|
return MemoryUtil.memGetInt(ptr + index * STRIDE + 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -125,13 +122,9 @@ public class BlockVertexList extends AbstractVertexList {
|
||||||
MemoryUtil.memPutFloat(ptr + index * STRIDE + 20, v);
|
MemoryUtil.memPutFloat(ptr + index * STRIDE + 20, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void overlay(int index, int overlay) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void light(int index, int light) {
|
public void light(int index, int light) {
|
||||||
MemoryUtil.memPutInt(ptr + index * STRIDE + 24, light >> 4);
|
MemoryUtil.memPutInt(ptr + index * STRIDE + 24, light);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -148,34 +141,4 @@ public class BlockVertexList extends AbstractVertexList {
|
||||||
public void normalZ(int index, float normalZ) {
|
public void normalZ(int index, float normalZ) {
|
||||||
MemoryUtil.memPutByte(ptr + index * STRIDE + 30, RenderMath.nb(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,14 +2,15 @@ package com.jozufozu.flywheel.lib.vertex;
|
||||||
|
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
|
|
||||||
import com.jozufozu.flywheel.lib.math.RenderMath;
|
import com.jozufozu.flywheel.lib.math.RenderMath;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.LightTexture;
|
public class PosTexNormalVertexView extends AbstractVertexView implements EmptyVertexList {
|
||||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
public static final long STRIDE = 23;
|
||||||
|
|
||||||
public class PosTexNormalVertexList extends AbstractVertexList {
|
@Override
|
||||||
private static final long STRIDE = 23;
|
public long stride() {
|
||||||
|
return STRIDE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float x(int index) {
|
public float x(int index) {
|
||||||
|
@ -26,26 +27,6 @@ public class PosTexNormalVertexList extends AbstractVertexList {
|
||||||
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 8);
|
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
|
@Override
|
||||||
public float u(int index) {
|
public float u(int index) {
|
||||||
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 12);
|
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 12);
|
||||||
|
@ -56,16 +37,6 @@ public class PosTexNormalVertexList extends AbstractVertexList {
|
||||||
return MemoryUtil.memGetFloat(ptr + index * STRIDE + 16);
|
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
|
@Override
|
||||||
public float normalX(int index) {
|
public float normalX(int index) {
|
||||||
return RenderMath.f(MemoryUtil.memGetByte(ptr + index * STRIDE + 20));
|
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);
|
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
|
@Override
|
||||||
public void u(int index, float u) {
|
public void u(int index, float u) {
|
||||||
MemoryUtil.memPutFloat(ptr + index * STRIDE + 12, u);
|
MemoryUtil.memPutFloat(ptr + index * STRIDE + 12, u);
|
||||||
|
@ -122,14 +77,6 @@ public class PosTexNormalVertexList extends AbstractVertexList {
|
||||||
MemoryUtil.memPutFloat(ptr + index * STRIDE + 16, v);
|
MemoryUtil.memPutFloat(ptr + index * STRIDE + 16, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void overlay(int index, int overlay) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void light(int index, int light) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void normalX(int index, float normalX) {
|
public void normalX(int index, float normalX) {
|
||||||
MemoryUtil.memPutByte(ptr + index * STRIDE + 20, RenderMath.nb(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) {
|
public void normalZ(int index, float normalZ) {
|
||||||
MemoryUtil.memPutByte(ptr + index * STRIDE + 22, RenderMath.nb(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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() {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,22 +3,22 @@ package com.jozufozu.flywheel.mixin;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
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.jozufozu.flywheel.extension.VertexFormatExtension;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
|
|
||||||
@Mixin(VertexFormat.class)
|
@Mixin(VertexFormat.class)
|
||||||
abstract class VertexFormatMixin implements VertexFormatExtension {
|
abstract class VertexFormatMixin implements VertexFormatExtension {
|
||||||
@Unique
|
@Unique
|
||||||
private VertexListProvider flywheel$vertexListProvider;
|
private VertexViewProvider flywheel$vertexViewProvider;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VertexListProvider flywheel$getVertexListProvider() {
|
public VertexViewProvider flywheel$getVertexViewProvider() {
|
||||||
return flywheel$vertexListProvider;
|
return flywheel$vertexViewProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void flywheel$setVertexListProvider(VertexListProvider provider) {
|
public void flywheel$setVertexViewProvider(VertexViewProvider provider) {
|
||||||
flywheel$vertexListProvider = provider;
|
flywheel$vertexViewProvider = provider;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "flywheel:util/quaternion.glsl"
|
#include "flywheel:util/quaternion.glsl"
|
||||||
|
|
||||||
|
#ifdef COMPUTE_SHADER
|
||||||
void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout float radius) {
|
void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout float radius) {
|
||||||
vec4 rotation = i.rotation;
|
vec4 rotation = i.rotation;
|
||||||
vec3 pivot = i.pivot;
|
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;
|
center = rotateVertexByQuat(center - pivot, rotation) + pivot + pos;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VERTEX_SHADER
|
||||||
void flw_instanceVertex(in FlwInstance i) {
|
void flw_instanceVertex(in FlwInstance i) {
|
||||||
flw_vertexPos = vec4(rotateVertexByQuat(flw_vertexPos.xyz - i.pivot, i.rotation) + i.pivot + i.position, 1.0);
|
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_vertexNormal = rotateVertexByQuat(flw_vertexNormal, i.rotation);
|
||||||
flw_vertexColor = i.color;
|
flw_vertexColor = i.color;
|
||||||
flw_vertexLight = i.light / 15.0;
|
flw_vertexLight = i.light / 15.0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifdef COMPUTE_SHADER
|
||||||
void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout float radius) {
|
void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout float radius) {
|
||||||
mat4 pose = i.pose;
|
mat4 pose = i.pose;
|
||||||
center = (pose * vec4(center, 1.0)).xyz;
|
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)));
|
float scale = max(length(pose[0].xyz), max(length(pose[1].xyz), length(pose[2].xyz)));
|
||||||
radius *= scale;
|
radius *= scale;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VERTEX_SHADER
|
||||||
void flw_instanceVertex(in FlwInstance i) {
|
void flw_instanceVertex(in FlwInstance i) {
|
||||||
flw_vertexPos = i.pose * flw_vertexPos;
|
flw_vertexPos = i.pose * flw_vertexPos;
|
||||||
flw_vertexNormal = i.normal * flw_vertexNormal;
|
flw_vertexNormal = i.normal * flw_vertexNormal;
|
||||||
flw_vertexColor = i.color;
|
flw_vertexColor = i.color;
|
||||||
flw_vertexLight = i.light / 15.0;
|
flw_vertexLight = i.light / 15.0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -4,21 +4,6 @@
|
||||||
|
|
||||||
layout(local_size_x = _FLW_SUBGROUP_SIZE) in;
|
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 {
|
layout(std430, binding = _FLW_OBJECT_BUFFER_BINDING) restrict readonly buffer ObjectBuffer {
|
||||||
Object objects[];
|
Object objects[];
|
||||||
};
|
};
|
||||||
|
@ -37,14 +22,14 @@ layout(std430, binding = _FLW_MODEL_BUFFER_BINDING) restrict buffer ModelBuffer
|
||||||
// flywheel:uniform/flywheel.glsl
|
// flywheel:uniform/flywheel.glsl
|
||||||
// com.jozufozu.flywheel.lib.math.MatrixMath.writePackedFrustumPlanes
|
// com.jozufozu.flywheel.lib.math.MatrixMath.writePackedFrustumPlanes
|
||||||
// org.joml.FrustumIntersection.testSphere
|
// 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);
|
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);
|
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);
|
return all(xyInside) && all(zInside);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isVisible(uint objectIndex, uint modelIndex) {
|
bool _flw_isVisible(uint objectIndex, uint modelIndex) {
|
||||||
BoundingSphere sphere = models[modelIndex].boundingSphere;
|
BoundingSphere sphere = models[modelIndex].boundingSphere;
|
||||||
|
|
||||||
vec3 center;
|
vec3 center;
|
||||||
|
@ -55,7 +40,7 @@ bool isVisible(uint objectIndex, uint modelIndex) {
|
||||||
|
|
||||||
flw_transformBoundingSphere(instance, center, radius);
|
flw_transformBoundingSphere(instance, center, radius);
|
||||||
|
|
||||||
return testSphere(center, radius);
|
return _flw_testSphere(center, radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -67,7 +52,7 @@ void main() {
|
||||||
|
|
||||||
uint modelIndex = objects[objectIndex].modelIndex;
|
uint modelIndex = objects[objectIndex].modelIndex;
|
||||||
|
|
||||||
if (isVisible(objectIndex, modelIndex)) {
|
if (_flw_isVisible(objectIndex, modelIndex)) {
|
||||||
uint localIndex = atomicAdd(models[modelIndex].instanceCount, 1);
|
uint localIndex = atomicAdd(models[modelIndex].instanceCount, 1);
|
||||||
uint targetIndex = models[modelIndex].baseInstance + localIndex;
|
uint targetIndex = models[modelIndex].baseInstance + localIndex;
|
||||||
objectIndices[targetIndex] = objectIndex;
|
objectIndices[targetIndex] = objectIndex;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "flywheel:internal/diffuse.glsl"
|
#include "flywheel:internal/diffuse.glsl"
|
||||||
#include "flywheel:internal/fog_distance.glsl"
|
#include "flywheel:internal/fog_distance.glsl"
|
||||||
#include "flywheel:internal/vertex_input.glsl"
|
|
||||||
#include "flywheel:internal/packed_material.glsl"
|
#include "flywheel:internal/packed_material.glsl"
|
||||||
#include "flywheel:internal/indirect/buffers.glsl"
|
#include "flywheel:internal/indirect/buffers.glsl"
|
||||||
#include "flywheel:internal/indirect/draw_command.glsl"
|
#include "flywheel:internal/indirect/draw_command.glsl"
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "flywheel:internal/diffuse.glsl"
|
#include "flywheel:internal/diffuse.glsl"
|
||||||
#include "flywheel:internal/fog_distance.glsl"
|
#include "flywheel:internal/fog_distance.glsl"
|
||||||
#include "flywheel:internal/vertex_input.glsl"
|
|
||||||
#include "flywheel:internal/packed_material.glsl"
|
#include "flywheel:internal/packed_material.glsl"
|
||||||
|
|
||||||
uniform uvec4 _flw_packedMaterial;
|
uniform uvec4 _flw_packedMaterial;
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in a new issue