mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-28 16:06:28 +01:00
Reading copy
- All vertex lists extend from AbstractVertexList, which handles copying the input
This commit is contained in:
parent
faa5652c4c
commit
f01e169954
4 changed files with 69 additions and 67 deletions
|
@ -0,0 +1,49 @@
|
||||||
|
package com.jozufozu.flywheel.core.vertex;
|
||||||
|
|
||||||
|
import java.nio.Buffer;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.vertex.VertexList;
|
||||||
|
import com.mojang.blaze3d.platform.MemoryTracker;
|
||||||
|
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||||
|
|
||||||
|
public abstract class AbstractVertexList implements VertexList, AutoCloseable {
|
||||||
|
|
||||||
|
protected final ByteBuffer contents;
|
||||||
|
protected final long base;
|
||||||
|
protected final int vertexCount;
|
||||||
|
|
||||||
|
protected AbstractVertexList(ByteBuffer copyFrom, int vertexCount) {
|
||||||
|
this.contents = MemoryTracker.create(copyFrom.capacity());
|
||||||
|
this.vertexCount = vertexCount;
|
||||||
|
this.base = MemoryUtil.memAddress(this.contents);
|
||||||
|
init(copyFrom);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractVertexList(BufferBuilder builder) {
|
||||||
|
var pair = builder.popNextBuffer();
|
||||||
|
ByteBuffer copyFrom = pair.getSecond();
|
||||||
|
this.contents = MemoryTracker.create(copyFrom.capacity());
|
||||||
|
this.vertexCount = pair.getFirst().vertexCount();
|
||||||
|
this.base = MemoryUtil.memAddress(this.contents);
|
||||||
|
init(copyFrom);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(ByteBuffer copyFrom) {
|
||||||
|
this.contents.order(copyFrom.order());
|
||||||
|
this.contents.put(copyFrom);
|
||||||
|
((Buffer) this.contents).flip();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
MemoryUtil.memFree(contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getVertexCount() {
|
||||||
|
return vertexCount;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,30 +1,18 @@
|
||||||
package com.jozufozu.flywheel.core.vertex;
|
package com.jozufozu.flywheel.core.vertex;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.vertex.ShadedVertexList;
|
import com.jozufozu.flywheel.api.vertex.ShadedVertexList;
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexList;
|
|
||||||
import com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder;
|
import com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder;
|
||||||
import com.jozufozu.flywheel.util.RenderMath;
|
import com.jozufozu.flywheel.util.RenderMath;
|
||||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||||
import com.mojang.datafixers.util.Pair;
|
|
||||||
|
|
||||||
public class BlockVertexList implements VertexList {
|
public class BlockVertexList extends AbstractVertexList {
|
||||||
|
|
||||||
private final ByteBuffer buffer;
|
|
||||||
private final int vertexCount;
|
|
||||||
private final int stride;
|
private final int stride;
|
||||||
|
|
||||||
public BlockVertexList(BufferBuilder builder) {
|
public BlockVertexList(BufferBuilder builder) {
|
||||||
Pair<BufferBuilder.DrawState, ByteBuffer> data = builder.popNextBuffer();
|
super(builder);
|
||||||
buffer = data.getSecond();
|
this.stride = builder.getVertexFormat()
|
||||||
|
|
||||||
stride = builder.getVertexFormat()
|
|
||||||
.getVertexSize();
|
.getVertexSize();
|
||||||
|
|
||||||
vertexCount = data.getFirst()
|
|
||||||
.vertexCount();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,72 +26,67 @@ public class BlockVertexList implements VertexList {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getX(int index) {
|
public float getX(int index) {
|
||||||
return buffer.getFloat(vertIdx(index));
|
return contents.getFloat(vertIdx(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getY(int index) {
|
public float getY(int index) {
|
||||||
return buffer.getFloat(vertIdx(index) + 4);
|
return contents.getFloat(vertIdx(index) + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getZ(int index) {
|
public float getZ(int index) {
|
||||||
return buffer.getFloat(vertIdx(index) + 8);
|
return contents.getFloat(vertIdx(index) + 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte getR(int index) {
|
public byte getR(int index) {
|
||||||
return buffer.get(vertIdx(index) + 12);
|
return contents.get(vertIdx(index) + 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte getG(int index) {
|
public byte getG(int index) {
|
||||||
return buffer.get(vertIdx(index) + 13);
|
return contents.get(vertIdx(index) + 13);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte getB(int index) {
|
public byte getB(int index) {
|
||||||
return buffer.get(vertIdx(index) + 14);
|
return contents.get(vertIdx(index) + 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte getA(int index) {
|
public byte getA(int index) {
|
||||||
return buffer.get(vertIdx(index) + 15);
|
return contents.get(vertIdx(index) + 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getU(int index) {
|
public float getU(int index) {
|
||||||
return buffer.getFloat(vertIdx(index) + 16);
|
return contents.getFloat(vertIdx(index) + 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getV(int index) {
|
public float getV(int index) {
|
||||||
return buffer.getFloat(vertIdx(index) + 20);
|
return contents.getFloat(vertIdx(index) + 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLight(int index) {
|
public int getLight(int index) {
|
||||||
return buffer.getInt(vertIdx(index) + 24);
|
return contents.getInt(vertIdx(index) + 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getNX(int index) {
|
public float getNX(int index) {
|
||||||
return RenderMath.f(buffer.get(vertIdx(index) + 28));
|
return RenderMath.f(contents.get(vertIdx(index) + 28));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getNY(int index) {
|
public float getNY(int index) {
|
||||||
return RenderMath.f(buffer.get(vertIdx(index) + 29));
|
return RenderMath.f(contents.get(vertIdx(index) + 29));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getNZ(int index) {
|
public float getNZ(int index) {
|
||||||
return RenderMath.f(buffer.get(vertIdx(index) + 30));
|
return RenderMath.f(contents.get(vertIdx(index) + 30));
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getVertexCount() {
|
|
||||||
return vertexCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Shaded extends BlockVertexList implements ShadedVertexList {
|
public static class Shaded extends BlockVertexList implements ShadedVertexList {
|
||||||
|
|
|
@ -10,20 +10,10 @@ import com.jozufozu.flywheel.api.vertex.VertexList;
|
||||||
import com.jozufozu.flywheel.util.RenderMath;
|
import com.jozufozu.flywheel.util.RenderMath;
|
||||||
import com.mojang.blaze3d.platform.MemoryTracker;
|
import com.mojang.blaze3d.platform.MemoryTracker;
|
||||||
|
|
||||||
public class BlockVertexListUnsafe implements VertexList {
|
public class BlockVertexListUnsafe extends AbstractVertexList {
|
||||||
|
|
||||||
private final ByteBuffer contents;
|
|
||||||
private final int vertexCount;
|
|
||||||
private final long base;
|
|
||||||
|
|
||||||
public BlockVertexListUnsafe(ByteBuffer copyFrom, int vertexCount) {
|
public BlockVertexListUnsafe(ByteBuffer copyFrom, int vertexCount) {
|
||||||
this.contents = MemoryTracker.create(copyFrom.capacity());
|
super(copyFrom, vertexCount);
|
||||||
this.contents.order(copyFrom.order());
|
|
||||||
this.contents.put(copyFrom);
|
|
||||||
((Buffer) this.contents).flip();
|
|
||||||
|
|
||||||
this.base = MemoryUtil.memAddress(this.contents);
|
|
||||||
this.vertexCount = vertexCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private long ptr(long index) {
|
private long ptr(long index) {
|
||||||
|
@ -100,11 +90,6 @@ public class BlockVertexListUnsafe implements VertexList {
|
||||||
return RenderMath.f(MemoryUtil.memGetByte(ptr(index) + 30));
|
return RenderMath.f(MemoryUtil.memGetByte(ptr(index) + 30));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getVertexCount() {
|
|
||||||
return vertexCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Shaded extends BlockVertexListUnsafe implements ShadedVertexList {
|
public static class Shaded extends BlockVertexListUnsafe implements ShadedVertexList {
|
||||||
|
|
||||||
private final int unshadedStartVertex;
|
private final int unshadedStartVertex;
|
||||||
|
|
|
@ -9,20 +9,10 @@ import com.jozufozu.flywheel.api.vertex.VertexList;
|
||||||
import com.jozufozu.flywheel.util.RenderMath;
|
import com.jozufozu.flywheel.util.RenderMath;
|
||||||
import com.mojang.blaze3d.platform.MemoryTracker;
|
import com.mojang.blaze3d.platform.MemoryTracker;
|
||||||
|
|
||||||
public class PosTexNormalVertexListUnsafe implements VertexList {
|
public class PosTexNormalVertexListUnsafe extends AbstractVertexList {
|
||||||
|
|
||||||
private final ByteBuffer contents;
|
|
||||||
private final int vertexCount;
|
|
||||||
private final long base;
|
|
||||||
|
|
||||||
public PosTexNormalVertexListUnsafe(ByteBuffer copyFrom, int vertexCount) {
|
public PosTexNormalVertexListUnsafe(ByteBuffer copyFrom, int vertexCount) {
|
||||||
this.contents = MemoryTracker.create(copyFrom.capacity());
|
super(copyFrom, vertexCount);
|
||||||
this.contents.order(copyFrom.order());
|
|
||||||
this.contents.put(copyFrom);
|
|
||||||
((Buffer) this.contents).flip();
|
|
||||||
|
|
||||||
this.base = MemoryUtil.memAddress(this.contents);
|
|
||||||
this.vertexCount = vertexCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private long ptr(long idx) {
|
private long ptr(long idx) {
|
||||||
|
@ -93,9 +83,4 @@ public class PosTexNormalVertexListUnsafe implements VertexList {
|
||||||
public float getNZ(int index) {
|
public float getNZ(int index) {
|
||||||
return RenderMath.f(MemoryUtil.memGetByte(ptr(index) + 22));
|
return RenderMath.f(MemoryUtil.memGetByte(ptr(index) + 22));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getVertexCount() {
|
|
||||||
return vertexCount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue