Skip to content

Commit 75ea1e8

Browse files
committed
Improve immediate presentation of meshes generated in blocking mode.
Previously even when meshes were generated in the blocking defer mode "Immediate" (zero frame) they would not become visible if they were part of a previously invisible section and thus not in a render list already. This change makes it so that sections that are added to a blocking-type task queue are also forcefully added to the render list since they are very likely to contain geometry by the end of the frame.
1 parent 19d591e commit 75ea1e8

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/lists/ChunkRenderList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void sortSections(int relativeCameraSectionX, int relativeCameraSectionY
126126
}
127127
}
128128

129-
public void add(RenderSection render) {
129+
public void add(RenderSection render, boolean forceRenderGeometry) {
130130
if (this.size >= RenderRegion.REGION_SIZE) {
131131
throw new ArrayIndexOutOfBoundsException("Render list is full");
132132
}
@@ -136,7 +136,7 @@ public void add(RenderSection render) {
136136
int index = render.getSectionIndex();
137137
int flags = render.getFlags();
138138

139-
if (((flags >>> RenderSectionFlags.HAS_BLOCK_GEOMETRY) & 1) == 1) {
139+
if (((flags >>> RenderSectionFlags.HAS_BLOCK_GEOMETRY) & 1) == 1 || forceRenderGeometry) {
140140
this.sectionsWithGeometryMap[index >> 6] |= 1L << (index & 0b111111);
141141
if (this.addedSectionsAreSorted) {
142142
this.sectionsWithGeometry[this.sectionsWithGeometryCount] = (byte) index;

common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/lists/SectionCollector.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,8 @@ public SectionCollector(int frame, TaskQueueType importantRebuildQueueType, Task
3636

3737
@Override
3838
public void visit(RenderSection section) {
39-
// only process section (and associated render list) if it has content that needs rendering
40-
if (section.getFlags() != 0) {
41-
RenderRegion region = section.getRegion();
42-
ChunkRenderList renderList = region.getRenderList();
43-
44-
if (renderList.getLastVisibleFrame() != this.frame) {
45-
renderList.reset(this.frame, this.orderIsSorted());
46-
47-
this.renderLists.add(renderList);
48-
}
49-
50-
renderList.add(section);
51-
}
39+
// when a chunk with no geometry to render is added to a zero-frame defer rebuild queue that means it will very likely receive geometry to render this frame. This flag makes sure it gets added to the render list now so that it doesn't remain invisible in frame, even though we blocked the frame to generate its mesh.
40+
boolean predictNewGeometryThisFrame = false;
5241

5342
// always add to rebuild lists though, because it might just not be built yet
5443
var pendingUpdate = section.getPendingUpdate();
@@ -61,14 +50,29 @@ public void visit(RenderSection section) {
6150
this.needsRevisitForPendingUpdates = true;
6251
return;
6352
}
64-
53+
6554
var queueType = ChunkUpdateTypes.getQueueType(pendingUpdate, this.importantRebuildQueueType, this.importantSortQueueType);
6655
Queue<RenderSection> queue = this.sortedTaskLists.get(queueType);
6756

6857
if (queue.size() < queueType.queueSizeLimit()) {
6958
queue.add(section);
59+
predictNewGeometryThisFrame = queueType == TaskQueueType.ZERO_FRAME_DEFER;
7060
}
7161
}
62+
63+
// only process section (and associated render list) if it has content that needs rendering
64+
if (section.getFlags() != 0 || predictNewGeometryThisFrame) {
65+
RenderRegion region = section.getRegion();
66+
ChunkRenderList renderList = region.getRenderList();
67+
68+
if (renderList.getLastVisibleFrame() != this.frame) {
69+
renderList.reset(this.frame, this.orderIsSorted());
70+
71+
this.renderLists.add(renderList);
72+
}
73+
74+
renderList.add(section, predictNewGeometryThisFrame);
75+
}
7276
}
7377

7478
@Override

0 commit comments

Comments
 (0)