Skip to content

Commit ddb9dc2

Browse files
committed
Viewport tweeks
1 parent 1265c83 commit ddb9dc2

File tree

5 files changed

+47
-50
lines changed

5 files changed

+47
-50
lines changed

src/main/java/me/cortex/voxy/client/core/rendering/AbstractFarWorldRenderer.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// could maybe tosomething else
55

66
import com.mojang.blaze3d.systems.RenderSystem;
7+
import it.unimi.dsi.fastutil.ints.IntArrayList;
78
import me.cortex.voxy.client.core.gl.GlBuffer;
89
import me.cortex.voxy.client.core.model.ModelManager;
910
import me.cortex.voxy.client.core.rendering.building.BuiltSection;
@@ -23,6 +24,7 @@
2324
import org.joml.Matrix4f;
2425
import org.lwjgl.system.MemoryUtil;
2526

27+
import java.util.ArrayList;
2628
import java.util.List;
2729
import java.util.concurrent.ConcurrentLinkedDeque;
2830

@@ -55,6 +57,8 @@ public abstract class AbstractFarWorldRenderer <T extends Viewport> {
5557

5658
protected FrustumIntersection frustum;
5759

60+
private final List<T> viewports = new ArrayList<>();
61+
5862
private final ConcurrentLinkedDeque<Mapper.StateEntry> blockStateUpdates = new ConcurrentLinkedDeque<>();
5963
private final ConcurrentLinkedDeque<Mapper.BiomeEntry> biomeUpdates = new ConcurrentLinkedDeque<>();
6064
public AbstractFarWorldRenderer(int geometrySize, int maxSections) {
@@ -153,5 +157,15 @@ public ModelManager getModelManager() {
153157
return this.models;
154158
}
155159

156-
public abstract T createViewport();
160+
public final T createViewport() {
161+
var viewport = createViewport0();
162+
this.viewports.add(viewport);
163+
return viewport;
164+
}
165+
166+
final void removeViewport(T viewport) {
167+
this.viewports.remove(viewport);
168+
}
169+
170+
protected abstract T createViewport0();
157171
}

src/main/java/me/cortex/voxy/client/core/rendering/GeometryManager.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.cortex.voxy.client.core.rendering;
22

3+
import it.unimi.dsi.fastutil.ints.IntArrayList;
34
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
45
import it.unimi.dsi.fastutil.longs.LongArrayList;
56
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@@ -21,6 +22,7 @@ public class GeometryManager {
2122
private final Long2IntOpenHashMap pos2id = new Long2IntOpenHashMap();
2223
private final LongArrayList id2pos = new LongArrayList();
2324
private final ObjectArrayList<SectionMeta> sectionMetadata = new ObjectArrayList<>();
25+
private final IntArrayList markSectionIds = new IntArrayList();//Section ids to mark as visible (either due to being new, or swapping)
2426

2527
private final GlBuffer sectionMetaBuffer;
2628
private final BufferArena geometryBuffer;
@@ -31,7 +33,8 @@ public GeometryManager(long geometryBufferSize, int maxSections) {
3133
this.pos2id.defaultReturnValue(-1);
3234
}
3335

34-
void uploadResults() {
36+
IntArrayList uploadResults() {
37+
this.markSectionIds.clear();
3538
while (!this.buildResults.isEmpty()) {
3639
var result = this.buildResults.pop();
3740
boolean isDelete = result.geometryBuffer == null;
@@ -66,6 +69,7 @@ void uploadResults() {
6669
}
6770
long ptr = UploadStream.INSTANCE.upload(this.sectionMetaBuffer, (long) SECTION_METADATA_SIZE * id, SECTION_METADATA_SIZE);
6871
swapMeta.writeMetadata(ptr);
72+
this.markSectionIds.add(id);
6973
}
7074
}
7175
} else {
@@ -102,6 +106,7 @@ void uploadResults() {
102106
this.sectionMetadata.add(meta);
103107
long ptr = UploadStream.INSTANCE.upload(this.sectionMetaBuffer, (long)SECTION_METADATA_SIZE * id, SECTION_METADATA_SIZE);
104108
meta.writeMetadata(ptr);
109+
this.markSectionIds.add(id);
105110
}
106111
}
107112

@@ -112,6 +117,7 @@ void uploadResults() {
112117

113118
result.free();
114119
}
120+
return this.markSectionIds;
115121
}
116122

117123
public void enqueueResult(BuiltSection sectionGeometry) {

src/main/java/me/cortex/voxy/client/core/rendering/Gl46FarWorldRenderer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,8 @@ public void renderFarAwayTranslucent(Gl46Viewport viewport) {
207207
RenderLayer.getTranslucent().endDrawing();
208208
}
209209

210-
@Override
211-
public Gl46Viewport createViewport() {
212-
return new Gl46Viewport(this.maxSections);
210+
protected Gl46Viewport createViewport0() {
211+
return new Gl46Viewport(this, this.maxSections);
213212
}
214213

215214
@Override
Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,22 @@
11
package me.cortex.voxy.client.core.rendering;
22

33
import me.cortex.voxy.client.core.gl.GlBuffer;
4-
import me.cortex.voxy.client.core.gl.shader.Shader;
5-
import me.cortex.voxy.client.core.gl.shader.ShaderType;
6-
import me.cortex.voxy.client.core.rendering.util.UploadStream;
7-
import me.cortex.voxy.client.mixin.joml.AccessFrustumIntersection;
8-
import net.minecraft.client.render.RenderLayer;
9-
import net.minecraft.client.util.math.MatrixStack;
10-
import org.joml.Matrix4f;
11-
import org.joml.Vector3f;
12-
import org.lwjgl.opengl.GL11C;
13-
import org.lwjgl.system.MemoryUtil;
144

15-
import java.util.List;
16-
17-
import static org.lwjgl.opengl.ARBIndirectParameters.GL_PARAMETER_BUFFER_ARB;
185
import static org.lwjgl.opengl.ARBIndirectParameters.glMultiDrawElementsIndirectCountARB;
19-
import static org.lwjgl.opengl.GL11.*;
20-
import static org.lwjgl.opengl.GL14C.glBlendFuncSeparate;
21-
import static org.lwjgl.opengl.GL30.glBindVertexArray;
226
import static org.lwjgl.opengl.GL30C.GL_R8UI;
237
import static org.lwjgl.opengl.GL30C.GL_RED_INTEGER;
24-
import static org.lwjgl.opengl.GL40C.GL_DRAW_INDIRECT_BUFFER;
25-
import static org.lwjgl.opengl.GL42.GL_BLEND;
26-
import static org.lwjgl.opengl.GL42.GL_CULL_FACE;
27-
import static org.lwjgl.opengl.GL42.GL_DEPTH_TEST;
28-
import static org.lwjgl.opengl.GL42.GL_ONE;
29-
import static org.lwjgl.opengl.GL42.GL_ONE_MINUS_SRC_ALPHA;
30-
import static org.lwjgl.opengl.GL42.GL_SRC_ALPHA;
31-
import static org.lwjgl.opengl.GL42.GL_TEXTURE_2D;
32-
import static org.lwjgl.opengl.GL42.GL_TEXTURE_BINDING_2D;
338
import static org.lwjgl.opengl.GL42.GL_UNSIGNED_BYTE;
34-
import static org.lwjgl.opengl.GL42.GL_UNSIGNED_INT;
35-
import static org.lwjgl.opengl.GL42.glBindTexture;
36-
import static org.lwjgl.opengl.GL42.glColorMask;
37-
import static org.lwjgl.opengl.GL42.glDepthMask;
38-
import static org.lwjgl.opengl.GL42.glDisable;
39-
import static org.lwjgl.opengl.GL42.glEnable;
40-
import static org.lwjgl.opengl.GL42.*;
41-
import static org.lwjgl.opengl.GL43.*;
429
import static org.lwjgl.opengl.GL45C.glClearNamedBufferData;
4310

44-
public class Gl46Viewport extends Viewport {
11+
public class Gl46Viewport extends Viewport<Gl46Viewport, Gl46FarWorldRenderer> {
4512
GlBuffer visibilityBuffer;
46-
public Gl46Viewport(int maxSections) {
13+
public Gl46Viewport(Gl46FarWorldRenderer renderer, int maxSections) {
14+
super(renderer);
4715
this.visibilityBuffer = new GlBuffer(maxSections*4L);
4816
glClearNamedBufferData(this.visibilityBuffer.id, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE, new int[1]);
4917
}
5018

51-
@Override
52-
public void delete() {
19+
protected void delete0() {
5320
this.visibilityBuffer.free();
5421
}
5522
}

src/main/java/me/cortex/voxy/client/core/rendering/Viewport.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,41 @@
22

33
import org.joml.Matrix4f;
44

5-
public abstract class Viewport {
5+
public abstract class Viewport <A extends Viewport<A,T>, T extends AbstractFarWorldRenderer<A>> {
6+
private final T renderer;
7+
68
int frameId;
79
Matrix4f projection;
810
Matrix4f modelView;
911
double cameraX;
1012
double cameraY;
1113
double cameraZ;
1214

13-
public abstract void delete();
15+
protected Viewport(T renderer) {
16+
this.renderer = renderer;
17+
}
18+
19+
public final void delete() {
20+
this.delete0();
21+
this.renderer.removeViewport((A) this);
22+
}
23+
24+
protected abstract void delete0();
1425

15-
public Viewport setProjection(Matrix4f projection) {
26+
public A setProjection(Matrix4f projection) {
1627
this.projection = projection;
17-
return this;
28+
return (A) this;
1829
}
1930

20-
public Viewport setModelView(Matrix4f modelView) {
31+
public A setModelView(Matrix4f modelView) {
2132
this.modelView = modelView;
22-
return this;
33+
return (A) this;
2334
}
2435

25-
public Viewport setCamera(double x, double y, double z) {
36+
public A setCamera(double x, double y, double z) {
2637
this.cameraX = x;
2738
this.cameraY = y;
2839
this.cameraZ = z;
29-
return this;
40+
return (A) this;
3041
}
3142
}

0 commit comments

Comments
 (0)