Boop
This commit is contained in:
@@ -101,10 +101,14 @@ public class VoxelCore {
|
|||||||
boolean firstTime = true;
|
boolean firstTime = true;
|
||||||
public void renderSetup(Frustum frustum, Camera camera) {
|
public void renderSetup(Frustum frustum, Camera camera) {
|
||||||
if (this.firstTime) {
|
if (this.firstTime) {
|
||||||
this.distanceTracker.init(camera.getBlockPos().getX(), camera.getBlockPos().getZ());
|
//this.distanceTracker.init(camera.getBlockPos().getX(), camera.getBlockPos().getZ());
|
||||||
this.firstTime = false;
|
this.firstTime = false;
|
||||||
|
|
||||||
|
this.renderTracker.addLvl0(0,0,0);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
this.distanceTracker.setCenter(camera.getBlockPos().getX(), camera.getBlockPos().getY(), camera.getBlockPos().getZ());
|
//this.distanceTracker.setCenter(camera.getBlockPos().getX(), camera.getBlockPos().getY(), camera.getBlockPos().getZ());
|
||||||
this.renderer.setupRender(frustum, camera);
|
this.renderer.setupRender(frustum, camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,25 +15,7 @@ import java.util.concurrent.ConcurrentLinkedDeque;
|
|||||||
public class GeometryManager {
|
public class GeometryManager {
|
||||||
private static final int SECTION_METADATA_SIZE = 32;
|
private static final int SECTION_METADATA_SIZE = 32;
|
||||||
|
|
||||||
|
|
||||||
//Note! the opaquePreDataCount and translucentPreDataCount are never writen to the meta buffer, as they are indexed in reverse relative to the base opaque and translucent geometry
|
|
||||||
private record SectionMeta(long position, long opaqueGeometryPtr, int opaqueQuadCount, int opaquePreDataCount, long translucentGeometryPtr, int translucentQuadCount, int translucentPreDataCount) {
|
|
||||||
public void writeMetadata(long ptr) {
|
|
||||||
//THIS IS DUE TO ENDIANNESS and that we are splitting a long into 2 ints
|
|
||||||
MemoryUtil.memPutInt(ptr, (int) (this.position>>32)); ptr += 4;
|
|
||||||
MemoryUtil.memPutInt(ptr, (int) this.position); ptr += 4;
|
|
||||||
ptr += 8;
|
|
||||||
|
|
||||||
MemoryUtil.memPutInt(ptr, (int) this.opaqueGeometryPtr + this.opaquePreDataCount); ptr += 4;
|
|
||||||
MemoryUtil.memPutInt(ptr, this.opaqueQuadCount); ptr += 4;
|
|
||||||
|
|
||||||
MemoryUtil.memPutInt(ptr, (int) this.translucentGeometryPtr + this.translucentPreDataCount); ptr += 4;
|
|
||||||
MemoryUtil.memPutInt(ptr, this.translucentQuadCount); ptr += 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final ConcurrentLinkedDeque<BuiltSection> buildResults = new ConcurrentLinkedDeque<>();
|
private final ConcurrentLinkedDeque<BuiltSection> buildResults = new ConcurrentLinkedDeque<>();
|
||||||
|
|
||||||
private int sectionCount = 0;
|
private int sectionCount = 0;
|
||||||
private final Long2IntOpenHashMap pos2id = new Long2IntOpenHashMap();
|
private final Long2IntOpenHashMap pos2id = new Long2IntOpenHashMap();
|
||||||
private final LongArrayList id2pos = new LongArrayList();
|
private final LongArrayList id2pos = new LongArrayList();
|
||||||
@@ -42,37 +24,16 @@ public class GeometryManager {
|
|||||||
private final GlBuffer sectionMetaBuffer;
|
private final GlBuffer sectionMetaBuffer;
|
||||||
private final BufferArena geometryBuffer;
|
private final BufferArena geometryBuffer;
|
||||||
|
|
||||||
|
|
||||||
public GeometryManager(long geometryBufferSize, int maxSections) {
|
public GeometryManager(long geometryBufferSize, int maxSections) {
|
||||||
this.sectionMetaBuffer = new GlBuffer(((long) maxSections) * SECTION_METADATA_SIZE);
|
this.sectionMetaBuffer = new GlBuffer(((long) maxSections) * SECTION_METADATA_SIZE);
|
||||||
this.geometryBuffer = new BufferArena(geometryBufferSize, 8);
|
this.geometryBuffer = new BufferArena(geometryBufferSize, 8);
|
||||||
this.pos2id.defaultReturnValue(-1);
|
this.pos2id.defaultReturnValue(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enqueueResult(BuiltSection sectionGeometry) {
|
|
||||||
this.buildResults.add(sectionGeometry);
|
|
||||||
}
|
|
||||||
|
|
||||||
private SectionMeta createMeta(BuiltSection geometry) {
|
|
||||||
long geometryPtr = this.geometryBuffer.upload(geometry.buffer);
|
|
||||||
|
|
||||||
//TODO: support translucent geometry
|
|
||||||
return new SectionMeta(geometry.position, geometryPtr, (int) (geometry.buffer.size/8), 0, -1,0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void freeMeta(SectionMeta meta) {
|
|
||||||
if (meta.opaqueGeometryPtr != -1) {
|
|
||||||
this.geometryBuffer.free(meta.opaqueGeometryPtr);
|
|
||||||
}
|
|
||||||
if (meta.translucentGeometryPtr != -1) {
|
|
||||||
this.geometryBuffer.free(meta.translucentGeometryPtr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void uploadResults() {
|
void uploadResults() {
|
||||||
while (!this.buildResults.isEmpty()) {
|
while (!this.buildResults.isEmpty()) {
|
||||||
var result = this.buildResults.pop();
|
var result = this.buildResults.pop();
|
||||||
boolean isDelete = result.buffer == null && result.translucentGeometryBuffer == null;
|
boolean isDelete = result.opaque == null && result.translucent == null;
|
||||||
if (isDelete) {
|
if (isDelete) {
|
||||||
int id = -1;
|
int id = -1;
|
||||||
if ((id = this.pos2id.remove(result.position)) != -1) {
|
if ((id = this.pos2id.remove(result.position)) != -1) {
|
||||||
@@ -165,9 +126,47 @@ public class GeometryManager {
|
|||||||
return this.sectionMetaBuffer.id;
|
return this.sectionMetaBuffer.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public float getGeometryBufferUsage() {
|
public float getGeometryBufferUsage() {
|
||||||
return this.geometryBuffer.usage();
|
return this.geometryBuffer.usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: pack the offsets of each axis so that implicit face culling can work
|
||||||
|
//Note! the opaquePreDataCount and translucentPreDataCount are never writen to the meta buffer, as they are indexed in reverse relative to the base opaque and translucent geometry
|
||||||
|
private record SectionMeta(long position, int aabb, long opaqueGeometryPtr, int opaqueQuadCount, int opaquePreDataCount, long translucentGeometryPtr, int translucentQuadCount, int translucentPreDataCount) {
|
||||||
|
public void writeMetadata(long ptr) {
|
||||||
|
//THIS IS DUE TO ENDIANNESS and that we are splitting a long into 2 ints
|
||||||
|
MemoryUtil.memPutInt(ptr, (int) (this.position>>32)); ptr += 4;
|
||||||
|
MemoryUtil.memPutInt(ptr, (int) this.position); ptr += 4;
|
||||||
|
ptr += 8;
|
||||||
|
|
||||||
|
MemoryUtil.memPutInt(ptr, (int) this.opaqueGeometryPtr + this.opaquePreDataCount); ptr += 4;
|
||||||
|
MemoryUtil.memPutInt(ptr, this.opaqueQuadCount); ptr += 4;
|
||||||
|
|
||||||
|
MemoryUtil.memPutInt(ptr, (int) this.translucentGeometryPtr + this.translucentPreDataCount); ptr += 4;
|
||||||
|
MemoryUtil.memPutInt(ptr, this.translucentQuadCount); ptr += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SectionMeta createMeta(BuiltSection geometry) {
|
||||||
|
long geometryPtr = this.geometryBuffer.upload(geometry.opaque.buffer());
|
||||||
|
|
||||||
|
//TODO: support translucent geometry
|
||||||
|
return new SectionMeta(geometry.position, 0, geometryPtr, (int) (geometry.opaque.buffer().size/8), 0, -1,0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void freeMeta(SectionMeta meta) {
|
||||||
|
if (meta.opaqueGeometryPtr != -1) {
|
||||||
|
this.geometryBuffer.free(meta.opaqueGeometryPtr);
|
||||||
|
}
|
||||||
|
if (meta.translucentGeometryPtr != -1) {
|
||||||
|
this.geometryBuffer.free(meta.translucentGeometryPtr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enqueueResult(BuiltSection sectionGeometry) {
|
||||||
|
this.buildResults.add(sectionGeometry);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package me.cortex.zenith.client.core.rendering.building;
|
package me.cortex.zenith.client.core.rendering.building;
|
||||||
|
|
||||||
|
import me.cortex.zenith.common.util.MemoryBuffer;
|
||||||
import me.cortex.zenith.common.world.WorldEngine;
|
import me.cortex.zenith.common.world.WorldEngine;
|
||||||
import me.cortex.zenith.common.world.WorldSection;
|
import me.cortex.zenith.common.world.WorldSection;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
|
|
||||||
public class RenderDataFactory {
|
public class RenderDataFactory {
|
||||||
@@ -27,7 +29,9 @@ public class RenderDataFactory {
|
|||||||
public BuiltSection generateMesh(WorldSection section, int buildMask) {
|
public BuiltSection generateMesh(WorldSection section, int buildMask) {
|
||||||
section.copyDataTo(this.sectionCache);
|
section.copyDataTo(this.sectionCache);
|
||||||
|
|
||||||
return new BuiltSection(section.getKey(), null, null);
|
var output = new MemoryBuffer(8*1);
|
||||||
|
|
||||||
|
return new BuiltSection(section.getKey(), new BuiltSectionGeometry(output, new short[0]), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user