mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-10 20:45:59 +01:00
Reading copy
- All vertex lists extend from AbstractVertexList, which handles copying the input
This commit is contained in:
parent
883ae6ef09
commit
9fc5e04c9d
@ -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;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
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.util.RenderMath;
|
||||
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;
|
||||
|
||||
public BlockVertexList(BufferBuilder builder) {
|
||||
Pair<BufferBuilder.DrawState, ByteBuffer> data = builder.popNextBuffer();
|
||||
buffer = data.getSecond();
|
||||
|
||||
stride = builder.getVertexFormat()
|
||||
super(builder);
|
||||
this.stride = builder.getVertexFormat()
|
||||
.getVertexSize();
|
||||
|
||||
vertexCount = data.getFirst()
|
||||
.vertexCount();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -38,72 +26,67 @@ public class BlockVertexList implements VertexList {
|
||||
|
||||
@Override
|
||||
public float getX(int index) {
|
||||
return buffer.getFloat(vertIdx(index));
|
||||
return contents.getFloat(vertIdx(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getY(int index) {
|
||||
return buffer.getFloat(vertIdx(index) + 4);
|
||||
return contents.getFloat(vertIdx(index) + 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZ(int index) {
|
||||
return buffer.getFloat(vertIdx(index) + 8);
|
||||
return contents.getFloat(vertIdx(index) + 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getR(int index) {
|
||||
return buffer.get(vertIdx(index) + 12);
|
||||
return contents.get(vertIdx(index) + 12);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getG(int index) {
|
||||
return buffer.get(vertIdx(index) + 13);
|
||||
return contents.get(vertIdx(index) + 13);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getB(int index) {
|
||||
return buffer.get(vertIdx(index) + 14);
|
||||
return contents.get(vertIdx(index) + 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getA(int index) {
|
||||
return buffer.get(vertIdx(index) + 15);
|
||||
return contents.get(vertIdx(index) + 15);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getU(int index) {
|
||||
return buffer.getFloat(vertIdx(index) + 16);
|
||||
return contents.getFloat(vertIdx(index) + 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getV(int index) {
|
||||
return buffer.getFloat(vertIdx(index) + 20);
|
||||
return contents.getFloat(vertIdx(index) + 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLight(int index) {
|
||||
return buffer.getInt(vertIdx(index) + 24);
|
||||
return contents.getInt(vertIdx(index) + 24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getNX(int index) {
|
||||
return RenderMath.f(buffer.get(vertIdx(index) + 28));
|
||||
return RenderMath.f(contents.get(vertIdx(index) + 28));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getNY(int index) {
|
||||
return RenderMath.f(buffer.get(vertIdx(index) + 29));
|
||||
return RenderMath.f(contents.get(vertIdx(index) + 29));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getNZ(int index) {
|
||||
return RenderMath.f(buffer.get(vertIdx(index) + 30));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVertexCount() {
|
||||
return vertexCount;
|
||||
return RenderMath.f(contents.get(vertIdx(index) + 30));
|
||||
}
|
||||
|
||||
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.mojang.blaze3d.platform.MemoryTracker;
|
||||
|
||||
public class BlockVertexListUnsafe implements VertexList {
|
||||
|
||||
private final ByteBuffer contents;
|
||||
private final int vertexCount;
|
||||
private final long base;
|
||||
public class BlockVertexListUnsafe extends AbstractVertexList {
|
||||
|
||||
public BlockVertexListUnsafe(ByteBuffer copyFrom, int vertexCount) {
|
||||
this.contents = MemoryTracker.create(copyFrom.capacity());
|
||||
this.contents.order(copyFrom.order());
|
||||
this.contents.put(copyFrom);
|
||||
((Buffer) this.contents).flip();
|
||||
|
||||
this.base = MemoryUtil.memAddress(this.contents);
|
||||
this.vertexCount = vertexCount;
|
||||
super(copyFrom, vertexCount);
|
||||
}
|
||||
|
||||
private long ptr(long index) {
|
||||
@ -100,11 +90,6 @@ public class BlockVertexListUnsafe implements VertexList {
|
||||
return RenderMath.f(MemoryUtil.memGetByte(ptr(index) + 30));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVertexCount() {
|
||||
return vertexCount;
|
||||
}
|
||||
|
||||
public static class Shaded extends BlockVertexListUnsafe implements ShadedVertexList {
|
||||
|
||||
private final int unshadedStartVertex;
|
||||
|
@ -9,20 +9,10 @@ import com.jozufozu.flywheel.api.vertex.VertexList;
|
||||
import com.jozufozu.flywheel.util.RenderMath;
|
||||
import com.mojang.blaze3d.platform.MemoryTracker;
|
||||
|
||||
public class PosTexNormalVertexListUnsafe implements VertexList {
|
||||
|
||||
private final ByteBuffer contents;
|
||||
private final int vertexCount;
|
||||
private final long base;
|
||||
public class PosTexNormalVertexListUnsafe extends AbstractVertexList {
|
||||
|
||||
public PosTexNormalVertexListUnsafe(ByteBuffer copyFrom, int vertexCount) {
|
||||
this.contents = MemoryTracker.create(copyFrom.capacity());
|
||||
this.contents.order(copyFrom.order());
|
||||
this.contents.put(copyFrom);
|
||||
((Buffer) this.contents).flip();
|
||||
|
||||
this.base = MemoryUtil.memAddress(this.contents);
|
||||
this.vertexCount = vertexCount;
|
||||
super(copyFrom, vertexCount);
|
||||
}
|
||||
|
||||
private long ptr(long idx) {
|
||||
@ -93,9 +83,4 @@ public class PosTexNormalVertexListUnsafe implements VertexList {
|
||||
public float getNZ(int index) {
|
||||
return RenderMath.f(MemoryUtil.memGetByte(ptr(index) + 22));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVertexCount() {
|
||||
return vertexCount;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user