This commit is contained in:
mcrcortex
2024-08-02 14:09:32 +10:00
parent 5225bca007
commit 7dc8bbcd9a
7 changed files with 72 additions and 16 deletions

View File

@@ -3,6 +3,7 @@ package me.cortex.voxy.client.core.model;
import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet;
import me.cortex.voxy.client.core.gl.GlFramebuffer;
import me.cortex.voxy.client.core.rendering.building.BuiltSection;
import me.cortex.voxy.client.core.rendering.util.RawDownloadStream;
import me.cortex.voxy.common.world.other.Mapper;
import org.lwjgl.opengl.GL11;

View File

@@ -4,46 +4,56 @@ import me.cortex.voxy.client.config.VoxyConfig;
import me.cortex.voxy.client.core.model.ModelBakerySubsystem;
import me.cortex.voxy.client.core.rendering.building.BuiltSection;
import me.cortex.voxy.client.core.rendering.building.RenderGenerationService;
import me.cortex.voxy.client.core.rendering.hierarchical.HierarchicalOcclusionTraverser;
import me.cortex.voxy.client.core.rendering.section.AbstractSectionRenderer;
import me.cortex.voxy.client.core.rendering.section.MDICSectionRenderer;
import me.cortex.voxy.client.core.rendering.util.DownloadStream;
import me.cortex.voxy.client.core.rendering.util.UploadStream;
import me.cortex.voxy.common.world.WorldEngine;
import net.minecraft.client.render.Camera;
import java.util.List;
public class RenderService {
public class RenderService<T extends AbstractSectionRenderer<J>, J extends Viewport<J>> {
private final ViewportSelector<?> viewportSelector;
private final AbstractSectionRenderer sectionRenderer;
private final T sectionRenderer;
private final HierarchicalOcclusionTraverser traversal;
private final ModelBakerySubsystem modelService;
private final RenderGenerationService renderGen;
public RenderService(WorldEngine world) {
this.modelService = new ModelBakerySubsystem(world.getMapper());
this.sectionRenderer = new MDICSectionRenderer();
this.renderGen = new RenderGenerationService(world, this.modelService, VoxyConfig.CONFIG.renderThreads, this::consumeRenderBuildResult, false);
this.sectionRenderer = (T) createSectionRenderer();
this.renderGen = new RenderGenerationService(world, this.modelService, VoxyConfig.CONFIG.renderThreads, this::consumeBuiltSection, false);
this.traversal = new HierarchicalOcclusionTraverser(this.renderGen, null);
world.setDirtyCallback(section -> System.out.println("Section updated!!: " + WorldEngine.pprintPos(section.key)));
this.viewportSelector = new ViewportSelector<>(this.sectionRenderer::createViewport);
for(int x = -200; x<=200;x++) {
for (int z = -200; z <= 200; z++) {
for (int y = -3; y <= 3; y++) {
for(int x = -400; x<=400;x++) {
for (int z = -400; z <= 400; z++) {
for (int y = -6; y <= 6; y++) {
this.renderGen.enqueueTask(0, x, y, z);
}
}
}
}
private void consumeRenderBuildResult(BuiltSection section) {
//System.err.println("Section " + WorldEngine.pprintPos(section.position));
section.free();
private void consumeBuiltSection(BuiltSection section) {
this.traversal.consumeBuiltSection(section);
}
private static AbstractSectionRenderer<?> createSectionRenderer() {
return new MDICSectionRenderer();
}
public void setup(Camera camera) {
this.modelService.tick();
}
public void renderFarAwayOpaque(Viewport viewport) {
public void renderFarAwayOpaque(J viewport) {
//Render previous geometry with the abstract renderer
//Execute the hieracial selector
// render delta sections
@@ -51,10 +61,19 @@ public class RenderService {
//Hieracial is not an abstract thing but
// the section renderer is as it might have different backends, but they all accept a buffer containing the section list
this.sectionRenderer.renderOpaque(viewport);
//NOTE: need to do the upload and download tick here, after the section renderer renders the world, to ensure "stable"
// sections
UploadStream.INSTANCE.tick();
DownloadStream.INSTANCE.tick();
this.traversal.doTraversal(viewport);
this.sectionRenderer.buildDrawCallsAndRenderTemporal(viewport, null);
}
public void renderFarAwayTranslucent(Viewport viewport) {
public void renderFarAwayTranslucent(J viewport) {
this.sectionRenderer.renderTranslucent(viewport);
}
public void addDebugData(List<String> debug) {
@@ -66,6 +85,8 @@ public class RenderService {
this.modelService.shutdown();
this.renderGen.shutdown();
this.viewportSelector.free();
this.sectionRenderer.free();
this.traversal.free();
}
public Viewport<?> getViewport() {

View File

@@ -0,0 +1,25 @@
package me.cortex.voxy.client.core.rendering.hierarchical;
import me.cortex.voxy.client.core.rendering.Viewport;
import me.cortex.voxy.client.core.rendering.building.BuiltSection;
import me.cortex.voxy.client.core.rendering.building.RenderGenerationService;
import me.cortex.voxy.client.core.rendering.section.AbstractSectionGeometryManager;
public class HierarchicalOcclusionTraverser {
public HierarchicalOcclusionTraverser(RenderGenerationService renderGenerationService, AbstractSectionGeometryManager sectionGeometryManager) {
}
public void doTraversal(Viewport<?> viewport) {
}
public void free() {
}
public void consumeBuiltSection(BuiltSection section) {
section.free();
}
}

View File

@@ -0,0 +1,4 @@
package me.cortex.voxy.client.core.rendering.section;
public abstract class AbstractSectionGeometryManager {
}

View File

@@ -9,6 +9,6 @@ public abstract class AbstractSectionRenderer <T extends Viewport<T>> {
public abstract void renderOpaque(T viewport);
public abstract void buildDrawCallsAndRenderTemporal(T viewport, GlBuffer sectionRenderList);
public abstract void renderTranslucent(T viewport);
public abstract T createViewport();
public abstract void free();
}

View File

@@ -6,8 +6,6 @@ import me.cortex.voxy.client.core.rendering.geometry.OLD.Gl46HierarchicalViewpor
//Uses MDIC to render the sections
public class MDICSectionRenderer extends AbstractSectionRenderer<BasicViewport> {
@Override
public void renderOpaque(BasicViewport viewport) {
@@ -27,4 +25,9 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<BasicViewport>
public BasicViewport createViewport() {
return new BasicViewport();
}
@Override
public void free() {
}
}

View File

@@ -62,6 +62,8 @@ public class ActiveSectionTracker {
System.err.println("Unable to load section " + section.key + " setting to air");
status = 1;
}
//TODO: REWRITE THE section tracker _again_ to not be so shit and jank, and so that Arrays.fill is not 10% of the execution time
if (status == 1) {
//We need to set the data to air as it is undefined state
Arrays.fill(section.data, Mapper.withLight(Mapper.AIR, 15));//Since lighting is inverted