LevelRenderer .java

net.minecraft.client.renderer.LevelRenderer (class): members: isChunkRenderingUsingMultiDrawIndirect, collectPerFrameRenderThreadGizmos, terrainFog.

net.minecraft.client.rendererclass1,342 linesclient58.2 KB

Implements

API Surface (28)

void render(final GraphicsResourceAllocator resourceAllocator, final boolean renderOutline, final CameraRenderState cameraState, final GpuBufferSlice terrainFog, final Vector4f fogColor, final boolean shouldRenderSky, final boolean consistentDepthRequired)
void beforeExecutePass(final String name)
void afterExecutePass(final String name)
ChunkSectionsToRender prepareChunkRenders(final Matrix4fc modelViewMatrix, final boolean respectTranslucentOrder)
void addTransientBlock(final long blockNode, final TransientBlockRenderState state)
void removeTransientBlocksInSection(final long sectionNode, final long compileTaskStartTimeNs)
ChunkSectionsToRender prepareChunkRendersIndirect(final Matrix4fc modelViewMatrix, final boolean respectTranslucentOrder)
void resize(final int width, final int height)
void endFrame()
void close()
void blitEntityOutline()
void invalidateCompiledGeometry(final ClientLevel level, final Options options, final Camera camera, final BlockColors blockColors)
void clearVisibleSections()
void resetLevelRenderData()
boolean hasRenderedAllSections()
boolean isSectionCompiledAndVisible(final BlockPos blockPos, final long chunkFadeDuration)
EntityRenderDispatcher entityRenderDispatcher()
BlockEntityRenderDispatcher blockEntityRenderDispatcher()
CloudRenderer cloudRenderer()
WeatherEffectRenderer weatherEffectRenderer()
WorldBorderRenderer worldBorderRenderer()
ObjectArrayList<SectionRenderDispatcher.RenderSection> visibleSections()
ObjectArrayList<SectionRenderDispatcher.RenderSection> nearbyVisibleSections()
LongCollection expectedChunks()
SectionOcclusionGraph sectionOcclusionGraph()
TemporaryCollection collectPerFrameRenderThreadGizmos()
boolean isChunkRenderingUsingMultiDrawIndirect()
void addMainThreadGizmos(final List<GizmoInstance> mainThreadGizmos)

Fields & Constants (63)

OIT_WAVELET_RANK
OIT_COEFFICIENT_COUNT
OIT_TRANSMITTANCE_TARGET_COUNT
ENTITY_OUTLINE_POST_CHAIN_ID
MINIMUM_TRANSPARENT_SORT_COUNT
CHUNK_VISIBILITY_THRESHOLD
DEPTH_BOUNDS_CLEAR_COLOR
ZERO_CLEAR_COLOR
gameRenderer
entityRenderDispatcher
blockEntityRenderDispatcher
renderBuffers
featureRenderDispatcher
submitNodeStorage
modelManager
textureManager
atlasManager
shaderManager
levelRenderState
optionsRenderState
skyRenderer
cloudRenderer
worldBorderRenderer
weatherEffectRenderer
sectionOcclusionGraph
visibleSections
nearbyVisibleSections
transientBlocks
transientBlockRemovalQueue
viewArea
entityOutlineTarget
targets

…and 31 more (see full source).

String literals (42)

"entity_outline"
"Entity Outline"
"repositionCamera"
"submitFeatures"
"prepareFeatures"
"setupFrameGraph"
"main"
"depth_bounds"
"depth_bounds_culled"
"transmittance"
"accumulate"
"cloud_depth"
"terrain_depth"
"always_on_top_depth"
"clear"
"executeFrameGraph"
"compileSections"
"uploadTerrainBuffers"
"updateSectionOcclusion"
"Solid"
"Main"
"See through features"
"Always on top features"
"Integrate always on top depth"

Code Graph: Dependencies (80)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

LevelRenderer.java1342 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer;
2
3
import com.mojang.blaze3d.framegraph.FrameGraphBuilder;
4
import com.mojang.blaze3d.framegraph.FramePass;
5
import com.mojang.blaze3d.pipeline.RenderTarget;
6
import com.mojang.blaze3d.pipeline.TextureTarget;
7
import com.mojang.blaze3d.platform.Lighting;
8
import com.mojang.blaze3d.resource.GraphicsResourceAllocator;
9
import com.mojang.blaze3d.resource.RenderTargetDescriptor;
10
import com.mojang.blaze3d.systems.RenderSystem;
11
import com.mojang.blaze3d.vertex.PoseStack;
12
import com.mojang.renderpearl.api.GpuFormat;
13
import com.mojang.renderpearl.api.buffers.GpuBuffer;
14
import com.mojang.renderpearl.api.buffers.GpuBufferSlice;
15
import com.mojang.renderpearl.api.commands.RenderPass;
16
import com.mojang.renderpearl.api.commands.RenderPassDescriptor;
17
import com.mojang.renderpearl.api.device.DeviceFeatures;
18
import com.mojang.renderpearl.api.device.DeviceInfo;
19
import com.mojang.renderpearl.api.device.DeviceLimits;
20
import com.mojang.renderpearl.api.device.HintsAndWorkarounds;
21
import com.mojang.renderpearl.api.pipeline.IndexType;
22
import com.mojang.renderpearl.api.pipeline.PrimitiveTopology;
23
import com.mojang.renderpearl.api.textures.AddressMode;
24
import com.mojang.renderpearl.api.textures.FilterMode;
25
import com.mojang.renderpearl.api.textures.GpuSampler;
26
import com.mojang.renderpearl.api.textures.GpuTextureView;
27
import com.mojang.renderpearl.api.vertex.VertexFormat;
28
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
29
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
30
import it.unimi.dsi.fastutil.longs.LongCollection;
31
import it.unimi.dsi.fastutil.longs.Long2ObjectMap.Entry;
32
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
33
import it.unimi.dsi.fastutil.objects.ObjectBidirectionalIterator;
34
import it.unimi.dsi.fastutil.objects.ObjectIterator;
35
import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
36
import java.util.ArrayList;
37
import java.util.EnumMap;
38
import java.util.List;
39
import java.util.Map;
40
import java.util.Optional;
41
import java.util.OptionalDouble;
42
import java.util.concurrent.BlockingQueue;
43
import java.util.concurrent.LinkedBlockingQueue;
44
import net.fabricmc.api.EnvType;
45
import net.fabricmc.api.Environment;
46
import net.minecraft.SharedConstants;
47
import net.minecraft.client.Camera;
48
import net.minecraft.client.CloudStatus;
49
import net.minecraft.client.Minecraft;
50
import net.minecraft.client.Options;
51
import net.minecraft.client.PrioritizeChunkUpdates;
52
import net.minecraft.client.TextureFilteringMethod;
53
import net.minecraft.client.color.block.BlockColors;
54
import net.minecraft.client.multiplayer.ClientLevel;
55
import net.minecraft.client.renderer.block.dispatch.BlockStateModel;
56
import net.minecraft.client.renderer.block.dispatch.BlockStateModelPart;
57
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
58
import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState;
59
import net.minecraft.client.renderer.chunk.ChunkSectionLayer;
60
import net.minecraft.client.renderer.chunk.ChunkSectionLayerGroup;
61
import net.minecraft.client.renderer.chunk.ChunkSectionsToRender;
62
import net.minecraft.client.renderer.chunk.CompiledSectionMesh;
63
import net.minecraft.client.renderer.chunk.SectionCompiler;
64
import net.minecraft.client.renderer.chunk.SectionMesh;
65
import net.minecraft.client.renderer.chunk.SectionRenderDispatcher;
66
import net.minecraft.client.renderer.chunk.TranslucencyPointOfView;
67
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
68
import net.minecraft.client.renderer.entity.state.EntityRenderState;
69
import net.minecraft.client.renderer.feature.FeatureRenderDispatcher;
70
import net.minecraft.client.renderer.gizmos.DrawableGizmoPrimitives;
71
import net.minecraft.client.renderer.oit.OitRenderPassProvider;
72
import net.minecraft.client.renderer.oit.OitStage;
73
import net.minecraft.client.renderer.rendertype.RenderType;
74
import net.minecraft.client.renderer.rendertype.RenderTypes;
75
import net.minecraft.client.renderer.state.OptionsRenderState;
76
import net.minecraft.client.renderer.state.level.BlockBreakingRenderState;
77
import net.minecraft.client.renderer.state.level.BlockOutlineRenderState;
78
import net.minecraft.client.renderer.state.level.CameraRenderState;
79
import net.minecraft.client.renderer.state.level.LevelRenderState;
80
import net.minecraft.client.renderer.state.level.SectionUpdateRenderState;
81
import net.minecraft.client.renderer.state.level.SkyRenderState;
82
import net.minecraft.client.renderer.state.level.TransientBlockRenderState;
83
import net.minecraft.client.renderer.texture.TextureAtlas;
84
import net.minecraft.client.renderer.texture.TextureManager;
85
import net.minecraft.client.resources.model.ModelManager;
86
import net.minecraft.client.resources.model.sprite.AtlasManager;
87
import net.minecraft.core.BlockPos;
88
import net.minecraft.core.SectionPos;
89
import net.minecraft.gizmos.Gizmos;
90
import net.minecraft.gizmos.SimpleGizmoCollector;
91
import net.minecraft.gizmos.Gizmos.TemporaryCollection;
92
import net.minecraft.gizmos.SimpleGizmoCollector.GizmoInstance;
93
import net.minecraft.resources.Identifier;
94
import net.minecraft.util.ARGB;
95
import net.minecraft.util.RandomSource;
96
import net.minecraft.util.Util;
97
import net.minecraft.util.profiling.Profiler;
98
import net.minecraft.util.profiling.ProfilerFiller;
99
import net.minecraft.world.level.block.LeavesBlock;
100
import net.minecraft.world.level.block.RenderShape;
101
import net.minecraft.world.level.dimension.DimensionType.Skybox;
102
import net.minecraft.world.level.material.FogType;
103
import net.minecraft.world.phys.Vec3;
104
import org.joml.Matrix4f;
105
import org.joml.Matrix4fStack;
106
import org.joml.Matrix4fc;
107
import org.joml.Vector4f;
108
import org.joml.Vector4fc;
109
import org.jspecify.annotations.Nullable;
110
111
@Environment(EnvType.CLIENT)
112
public class LevelRenderer implements AutoCloseable {
113
	public static final int OIT_WAVELET_RANK = 2;
114
	public static final int OIT_COEFFICIENT_COUNT = Math.powExact(2, 3);
115
	public static final int OIT_TRANSMITTANCE_TARGET_COUNT = OIT_COEFFICIENT_COUNT / 4;
116
	private static final Identifier ENTITY_OUTLINE_POST_CHAIN_ID = Identifier.withDefaultNamespace("entity_outline");
117
	private static final int MINIMUM_TRANSPARENT_SORT_COUNT = 15;
118
	private static final float CHUNK_VISIBILITY_THRESHOLD = 0.3F;
119
	private static final Vector4fc DEPTH_BOUNDS_CLEAR_COLOR = new Vector4f(-Float.MAX_VALUE, 0.0F, 0.0F, 0.0F);
120
	private static final Vector4fc ZERO_CLEAR_COLOR = new Vector4f(0.0F);
121
	private final GameRenderer gameRenderer;
122
	private final EntityRenderDispatcher entityRenderDispatcher;
123
	private final BlockEntityRenderDispatcher blockEntityRenderDispatcher;
124
	private final RenderBuffers renderBuffers;
125
	private final FeatureRenderDispatcher featureRenderDispatcher;
126
	private final SubmitNodeStorage submitNodeStorage = new SubmitNodeStorage();
127
	private final ModelManager modelManager;
128
	private final TextureManager textureManager;
129
	private final AtlasManager atlasManager;
130
	private final ShaderManager shaderManager;
131
	private final LevelRenderState levelRenderState;
132
	private final OptionsRenderState optionsRenderState;
133
	private @Nullable SkyRenderer skyRenderer;
134
	private final CloudRenderer cloudRenderer = new CloudRenderer();
135
	private final WorldBorderRenderer worldBorderRenderer = new WorldBorderRenderer();
136
	private final WeatherEffectRenderer weatherEffectRenderer = new WeatherEffectRenderer();
137
	private final SectionOcclusionGraph sectionOcclusionGraph = new SectionOcclusionGraph();
138
	private final ObjectArrayList<SectionRenderDispatcher.RenderSection> visibleSections = new ObjectArrayList<>(10000);
139
	private final ObjectArrayList<SectionRenderDispatcher.RenderSection> nearbyVisibleSections = new ObjectArrayList<>(50);
140
	private final Long2ObjectLinkedOpenHashMap<TransientBlockRenderState> transientBlocks = new Long2ObjectLinkedOpenHashMap<>();
141
	private final BlockingQueue<TransientBlockRenderState.Removal> transientBlockRemovalQueue = new LinkedBlockingQueue<>();
142
	private @Nullable ViewArea viewArea;
143
	private final RenderTarget entityOutlineTarget;
144
	private final LevelTargetBundle targets = new LevelTargetBundle();
145
	private @Nullable SectionRenderDispatcher sectionRenderDispatcher;
146
	private @Nullable BlockPos lastTranslucentSortBlockPos;
147
	private int translucencyResortIterationIndex;
148
	private @Nullable GpuSampler chunkLayerSampler;
149
	private boolean currentFrameRendersEntityOutline;
150
	private final boolean multiDrawIndirectAvailable;
151
	private boolean usingMultiDrawIndirectForTerrain;
152
	private final SimpleGizmoCollector renderThreadGizmos = new SimpleGizmoCollector();
153
	private LevelRenderer.FinalizedGizmos finalizedGizmos = new LevelRenderer.FinalizedGizmos(new DrawableGizmoPrimitives(), new DrawableGizmoPrimitives());
154
155
	public LevelRenderer(
156
		final EntityRenderDispatcher entityRenderDispatcher,
157
		final BlockEntityRenderDispatcher blockEntityRenderDispatcher,
158
		final ModelManager modelManager,
159
		final TextureManager textureManager,
160
		final AtlasManager atlasManager,
161
		final ShaderManager shaderManager,
162
		final GameRenderer gameRenderer,
163
		final int width,
164
		final int height
165
	) {
166
		this.gameRenderer = gameRenderer;
167
		this.entityRenderDispatcher = entityRenderDispatcher;
168
		this.blockEntityRenderDispatcher = blockEntityRenderDispatcher;
169
		this.renderBuffers = gameRenderer.renderBuffers();
170
		this.featureRenderDispatcher = gameRenderer.featureRenderDispatcher();
171
		this.modelManager = modelManager;
172
		this.textureManager = textureManager;
173
		this.atlasManager = atlasManager;
174
		this.shaderManager = shaderManager;
175
		this.levelRenderState = gameRenderer.gameRenderState().levelRenderState;
176
		this.optionsRenderState = gameRenderer.gameRenderState().optionsRenderState;
177
		this.entityOutlineTarget = new TextureTarget("Entity Outline", width, height, GpuFormat.RGBA8_UNORM, null);
178
		DeviceInfo deviceInfo = RenderSystem.getDevice().getDeviceInfo();
179
		DeviceFeatures deviceFeatures = deviceInfo.features();
180
		DeviceLimits deviceLimits = deviceInfo.limits();
181
		HintsAndWorkarounds hintsAndWorkarounds = deviceInfo.hintsAndWorkarounds();
182
		this.multiDrawIndirectAvailable = deviceLimits.maxDrawIndirectDrawCount() > 0
183
			&& deviceFeatures.nonZeroFirstInstance()
184
			&& !hintsAndWorkarounds.multiDrawIndirectHasKnownIssues();
185
		this.usingMultiDrawIndirectForTerrain = this.multiDrawIndirectAvailable;
186
	}
187
188
	public void render(
189
		final GraphicsResourceAllocator resourceAllocator,
190
		final boolean renderOutline,
191
		final CameraRenderState cameraState,
192
		final GpuBufferSlice terrainFog,
193
		final Vector4f fogColor,
194
		final boolean shouldRenderSky,
195
		final boolean consistentDepthRequired
196
	) {
197
		RenderSystem.isRenderingLevel = true;
198
		final ProfilerFiller profiler = Profiler.get();
199
		this.submitNodeStorage.setUseImprovedTransparency(this.gameRenderer.useImprovedTransparency());
200
		profiler.push("repositionCamera");
201
		this.repositionCamera(cameraState);
202
		Matrix4fStack modelViewStack = RenderSystem.getModelViewStack();
203
		modelViewStack.pushMatrix();
204
		modelViewStack.mul(cameraState.viewRotationMatrix);
205
		profiler.popPush("submitFeatures");
206
		this.submitFeatures(this.levelRenderState, this.submitNodeStorage, renderOutline);
207
		profiler.popPush("prepareFeatures");
208
		FeatureRenderDispatcher.PreparedFrame featureFrame = this.featureRenderDispatcher.prepareFrame(this.submitNodeStorage);
209
		this.currentFrameRendersEntityOutline = featureFrame.hasAnyOutline() && this.levelRenderState.shouldShowEntityOutlines;
210
		profiler.popPush("setupFrameGraph");
211
		FrameGraphBuilder frame = new FrameGraphBuilder();
212
		this.targets.main = frame.importExternal("main", this.gameRenderer.mainRenderTarget());
213
		int screenWidth = this.gameRenderer.mainRenderTarget().width;
214
		int screenHeight = this.gameRenderer.mainRenderTarget().height;
215
		RenderTargetDescriptor extraDepthTargetDescriptor = new RenderTargetDescriptor(
216
			screenWidth, screenHeight, null, new RenderTargetDescriptor.TextureProperties(null, GpuFormat.D32_FLOAT)
217
		);
218
		RenderTargetDescriptor extraDepthTargetDescriptorCleared = new RenderTargetDescriptor(
219
			screenWidth, screenHeight, null, RenderTargetDescriptor.TextureProperties.DEFAULT_DEPTH
220
		);
221
		if (this.gameRenderer.useImprovedTransparency()) {
222
			RenderTargetDescriptor depthBoundsTargetDescriptor = new RenderTargetDescriptor(
223
				screenWidth, screenHeight, new RenderTargetDescriptor.TextureProperties(DEPTH_BOUNDS_CLEAR_COLOR, GpuFormat.RGBA32_FLOAT), null
224
			);
225
			this.targets.depthBounds = frame.createInternal("depth_bounds", depthBoundsTargetDescriptor);
226
			RenderTargetDescriptor depthBoundsCulledTargetDescriptor = new RenderTargetDescriptor(
227
				screenWidth, screenHeight, new RenderTargetDescriptor.TextureProperties(null, GpuFormat.RGBA32_FLOAT), null
228
			);
229
			this.targets.depthBoundsCulled = frame.createInternal("depth_bounds_culled", depthBoundsCulledTargetDescriptor);
230
			RenderTargetDescriptor transmittanceTargetDescriptor = new RenderTargetDescriptor(
231
				screenWidth, screenHeight, new RenderTargetDescriptor.TextureProperties(ZERO_CLEAR_COLOR, GpuFormat.RGBA16_FLOAT), null
232
			);
233
234
			for (int i = 0; i < OIT_TRANSMITTANCE_TARGET_COUNT; i++) {
235
				this.targets.transmittance.set(i, frame.createInternal("transmittance", transmittanceTargetDescriptor));
236
			}
237
238
			RenderTargetDescriptor accumulateTargetDescriptor = new RenderTargetDescriptor(
239
				screenWidth, screenHeight, new RenderTargetDescriptor.TextureProperties(ZERO_CLEAR_COLOR, GpuFormat.RGBA16_FLOAT), null
240
			);
241
			this.targets.accumulate = frame.createInternal("accumulate", accumulateTargetDescriptor);
242
			this.targets.oitCloudDepth = frame.createInternal("cloud_depth", extraDepthTargetDescriptor);
243
			this.targets.oitTerrainWithWaterPatchDepth = frame.createInternal("terrain_depth", extraDepthTargetDescriptor);
244
		}
245
246
		if (this.frameHasAlwaysOnTopGizmos() && consistentDepthRequired) {
247
			this.targets.alwaysOnTopDepth = frame.createInternal("always_on_top_depth", extraDepthTargetDescriptorCleared);
248
		}
249
250
		this.targets.entityOutline = frame.importExternal("entity_outline", this.entityOutlineTarget);
251
		FramePass clearPass = frame.addPass("clear");
252
		this.targets.main = clearPass.readsAndWrites(this.targets.main);
253
		clearPass.executes(
254
			() -> {
255
				RenderTarget mainRenderTarget = this.gameRenderer.mainRenderTarget();
256
				RenderSystem.getDevice()
257
					.createCommandEncoder()
258
					.clearColorAndDepthTextures(
259
						mainRenderTarget.getColorTexture(), new Vector4f(fogColor.x, fogColor.y, fogColor.z, 0.0F), mainRenderTarget.getDepthTexture(), 0.0
260
					);
261
			}
262
		);
263
		if (shouldRenderSky) {
264
			this.addSkyPass(frame, cameraState, terrainFog);
265
		}
266
267
		Matrix4fc terrainMatrix = new Matrix4f(this.levelRenderState.cameraRenderState.viewRotationMatrix);
268
		this.usingMultiDrawIndirectForTerrain = this.multiDrawIndirectAvailable && this.levelRenderState.shouldUseMultiDrawIndirectForTerrain;
269
		ChunkSectionsToRender chunkSectionsToRender;
270
		if (this.usingMultiDrawIndirectForTerrain) {
271
			chunkSectionsToRender = this.prepareChunkRendersIndirect(terrainMatrix, !this.gameRenderer.useImprovedTransparency());
272
		} else {
273
			chunkSectionsToRender = this.prepareChunkRenders(terrainMatrix, !this.gameRenderer.useImprovedTransparency());
274
		}
275
276
		this.addMainPass(frame, featureFrame, terrainFog, chunkSectionsToRender, consistentDepthRequired);
277
		if (this.currentFrameRendersEntityOutline) {
278
			PostChain entityOutlineChain = this.shaderManager.getPostChain(ENTITY_OUTLINE_POST_CHAIN_ID, LevelTargetBundle.OUTLINE_TARGETS);
279
			if (entityOutlineChain != null) {
280
				entityOutlineChain.addToFrame(frame, screenWidth, screenHeight, this.targets);
281
			}
282
		}
283
284
		profiler.popPush("executeFrameGraph");
285
		frame.execute(resourceAllocator, new FrameGraphBuilder.Inspector() {
286
			@Override
287
			public void beforeExecutePass(final String name) {
288
				profiler.push(name);
289
			}
290
291
			@Override
292
			public void afterExecutePass(final String name) {
293
				profiler.pop();
294
			}
295
		});
296
		profiler.pop();
297
		this.targets.clear();
298
		modelViewStack.popMatrix();
299
		featureFrame.close();
300
		profiler.push("compileSections");
301
		this.compileSections(cameraState);
302
		profiler.pop();
303
		if (this.sectionRenderDispatcher != null) {
304
			this.sectionRenderDispatcher.lock();
305
			profiler.push("uploadTerrainBuffers");
306
307
			try {
308
				this.sectionRenderDispatcher.uploadTerrainBuffersToGpu();
309
			} finally {
310
				this.sectionRenderDispatcher.unlock();
311
			}
312
313
			profiler.pop();
314
		}
315
316
		profiler.push("updateSectionOcclusion");
317
		this.sectionOcclusionGraph.update(cameraState, this.optionsRenderState.fov, this.levelRenderState.chunkLoadingRenderState);
318
		profiler.pop();
319
		Runnable playerCompiledSectionCallback = this.levelRenderState.playerCompiledSectionCallback;
320
		if (playerCompiledSectionCallback != null) {
321
			long chunkFadeDuration = Util.toMillis(this.optionsRenderState.chunkSectionFadeInTime);
322
			if (this.isSectionCompiledAndVisible(this.levelRenderState.cameraRenderState.blockPos, chunkFadeDuration)) {
323
				playerCompiledSectionCallback.run();
324
			}
325
		}
326
327
		RenderSystem.isRenderingLevel = false;
328
	}
329
330
	private void submitFeatures(final LevelRenderState levelRenderState, final SubmitNodeCollector submitNodeCollector, final boolean renderOutline) {
331
		PoseStack poseStack = new PoseStack();
332
		this.submitEntities(poseStack, levelRenderState, submitNodeCollector);
333
		levelRenderState.entityRenderStates.clear();
334
		this.submitBlockEntities(poseStack, levelRenderState, submitNodeCollector);
335
		levelRenderState.blockEntityRenderStates.clear();
336
		this.submitBlockDestroyAnimation(poseStack, submitNodeCollector, levelRenderState);
337
		levelRenderState.blockBreakingRenderStates.clear();
338
		this.submitTransientBlocks(poseStack, submitNodeCollector, levelRenderState);
339
		levelRenderState.particlesRenderState.submit(submitNodeCollector, levelRenderState.cameraRenderState);
340
		if (renderOutline) {
341
			this.submitBlockOutline(poseStack, this.submitNodeStorage, levelRenderState);
342
		}
343
344
		this.finalizeGizmoCollection();
345
		this.finalizedGizmos.standardPrimitives().submit(submitNodeCollector, levelRenderState.cameraRenderState, false);
346
		this.finalizedGizmos.alwaysOnTopPrimitives().submit(submitNodeCollector, levelRenderState.cameraRenderState, true);
347
		if (!levelRenderState.shouldShowEntityOutlines) {
348
			for (SubmitNodeCollection collection : this.submitNodeStorage.getSubmitsPerOrder().values()) {
349
				collection.outline.clear();
350
			}
351
		}
352
353
		this.checkPoseStack(poseStack);
354
	}
355
356
	private void repositionCamera(final CameraRenderState camera) {
357
		Vec3 cameraPos = camera.pos;
358
		SectionPos cameraSectionPos = SectionPos.of(cameraPos);
359
		if (this.viewArea.repositionCamera(cameraSectionPos)) {
360
			this.worldBorderRenderer.invalidate();
361
		}
362
363
		this.sectionRenderDispatcher.setCameraPosition(cameraPos);
364
	}
365
366
	private void addSkyPass(final FrameGraphBuilder frame, final CameraRenderState cameraState, final GpuBufferSlice skyFog) {
367
		FogType fogType = cameraState.fogType;
368
		if (fogType != FogType.POWDER_SNOW && fogType != FogType.LAVA && !cameraState.entityRenderState.doesMobEffectBlockSky) {
369
			if (this.levelRenderState.shouldResetSkyRenderer || this.skyRenderer == null) {
370
				if (this.skyRenderer != null) {
371
					this.skyRenderer.close();
372
				}
373
374
				this.skyRenderer = new SkyRenderer(this.textureManager, this.atlasManager, this.gameRenderer.mainRenderTarget());
375
			}
376
377
			SkyRenderState state = this.levelRenderState.skyRenderState;
378
			if (state.skybox != Skybox.NONE) {
379
				FramePass pass = frame.addPass("sky");
380
				this.targets.main = pass.readsAndWrites(this.targets.main);
381
				pass.executes(() -> this.skyRenderer.render(skyFog, state));
382
			}
383
		}
384
	}
385
386
	private void addMainPass(
387
		final FrameGraphBuilder frame,
388
		final FeatureRenderDispatcher.PreparedFrame featureFrame,
389
		final GpuBufferSlice terrainFog,
390
		final ChunkSectionsToRender chunkSectionsToRender,
391
		final boolean consistentDepthRequired
392
	) {
393
		FramePass pass = frame.addPass("main");
394
		this.targets.main = pass.readsAndWrites(this.targets.main);
395
		boolean useImprovedTransparency = this.gameRenderer.useImprovedTransparency();
396
		if (useImprovedTransparency) {
397
			this.targets.depthBounds = pass.readsAndWrites(this.targets.depthBounds);
398
			this.targets.depthBoundsCulled = pass.readsAndWrites(this.targets.depthBoundsCulled);
399
400
			for (int i = 0; i < OIT_TRANSMITTANCE_TARGET_COUNT; i++) {
401
				this.targets.transmittance.set(i, pass.readsAndWrites(this.targets.transmittance.get(i)));
402
			}
403
404
			this.targets.accumulate = pass.readsAndWrites(this.targets.accumulate);
405
			if (this.optionsRenderState.cloudStatus != CloudStatus.OFF && ARGB.alpha(this.levelRenderState.cloudColor) > 0) {
406
				this.targets.oitCloudDepth = pass.readsAndWrites(this.targets.oitCloudDepth);
407
			}
408
409
			if (featureFrame.hasAnyWaterMask()) {
410
				this.targets.oitTerrainWithWaterPatchDepth = pass.readsAndWrites(this.targets.oitTerrainWithWaterPatchDepth);
411
			}
412
		}
413
414
		boolean hasAlwaysOnTopGizmos = this.frameHasAlwaysOnTopGizmos();
415
		if (hasAlwaysOnTopGizmos && consistentDepthRequired) {
416
			this.targets.alwaysOnTopDepth = pass.readsAndWrites(this.targets.alwaysOnTopDepth);
417
		}
418
419
		if (this.currentFrameRendersEntityOutline && this.targets.entityOutline != null) {
420
			this.targets.entityOutline = pass.readsAndWrites(this.targets.entityOutline);
421
		}
422
423
		pass.executes(
424
			() -> {
425
				RenderSystem.setShaderFog(terrainFog);
426
				if (this.levelRenderState.shouldResetChunkLayerSampler || this.chunkLayerSampler == null) {
427
					if (this.chunkLayerSampler != null) {
428
						this.chunkLayerSampler.close();
429
					}
430
431
					int maxAnisotropy = this.optionsRenderState.textureFiltering == TextureFilteringMethod.ANISOTROPIC ? this.optionsRenderState.maxAnisotropyValue : 1;
432
					this.chunkLayerSampler = RenderSystem.getDevice()
433
						.createSampler(AddressMode.CLAMP_TO_EDGE, AddressMode.CLAMP_TO_EDGE, FilterMode.LINEAR, FilterMode.LINEAR, maxAnisotropy, OptionalDouble.empty());
434
				}
435
436
				this.prepareTranslucents();
437
				this.gameRenderer.lighting().setupFor(Lighting.Entry.LEVEL);
438
				RenderTarget mainTarget = this.targets.main.get();
439
440
				try (RenderPass renderPass = RenderSystem.getDevice()
441
						.createCommandEncoder()
442
						.createRenderPass(
443
							() -> useImprovedTransparency ? "Solid" : "Main",
444
							mainTarget.getColorTextureView(),
445
							Optional.empty(),
446
							mainTarget.getDepthTextureView(),
447
							OptionalDouble.empty()
448
						)) {
449
					RenderSystem.bindDefaultUniforms(renderPass);
450
					this.executeSolid(chunkSectionsToRender, featureFrame, renderPass);
451
					if (!useImprovedTransparency) {
452
						this.executeClassicTransparency(chunkSectionsToRender, featureFrame, renderPass);
453
					}
454
				}
455
456
				if (useImprovedTransparency) {
457
					this.executeOit(chunkSectionsToRender, featureFrame);
458
				}
459
460
				this.executeOutline(featureFrame);
461
				if (featureFrame.hasAnySeeThrough()) {
462
					this.executeSeeThrough(featureFrame, mainTarget);
463
				}
464
465
				if (hasAlwaysOnTopGizmos) {
466
					this.executeAlwaysOnTop(featureFrame, mainTarget, consistentDepthRequired);
467
				}
468
			}
469
		);
470
	}
471
472
	private void executeSeeThrough(final FeatureRenderDispatcher.PreparedFrame featureFrame, final RenderTarget mainTarget) {
473
		RenderPassDescriptor descriptor = RenderPassDescriptor.builder(() -> "See through features").withColorAttachment(mainTarget.getColorTextureView()).build();
474
475
		try (RenderPass renderPass = RenderSystem.getDevice().createCommandEncoder().createRenderPass(descriptor)) {
476
			RenderSystem.bindDefaultUniforms(renderPass);
477
			featureFrame.executeSeeThrough(renderPass);
478
		}
479
	}
480
481
	private void executeAlwaysOnTop(final FeatureRenderDispatcher.PreparedFrame featureFrame, final RenderTarget mainTarget, final boolean consistentDepthRequired) {
482
		GpuTextureView depthTextureView = consistentDepthRequired ? this.targets.alwaysOnTopDepth.get().getDepthTextureView() : mainTarget.getDepthTextureView();
483
484
		try (RenderPass renderPass = RenderSystem.getDevice()
485
				.createCommandEncoder()
486
				.createRenderPass(() -> "Always on top features", mainTarget.getColorTextureView(), Optional.empty(), depthTextureView, OptionalDouble.of(0.0))) {
487
			RenderSystem.bindDefaultUniforms(renderPass);
488
			featureFrame.executeAlwaysOnTop(renderPass);
489
		}
490
491
		if (consistentDepthRequired) {
492
			RenderPassDescriptor integrateDepthDescriptor = RenderPassDescriptor.builder(() -> "Integrate always on top depth")
493
				.withDepthAttachment(mainTarget.getDepthTextureView())
494
				.build();
495
			GpuSampler nearestSampler = RenderSystem.getSamplerCache().getClampToEdge(FilterMode.NEAREST);
496
497
			try (RenderPass renderPass = RenderSystem.getDevice().createCommandEncoder().createRenderPass(integrateDepthDescriptor)) {
498
				renderPass.setUniform("InSampler", depthTextureView, nearestSampler);
499
				renderPass.setPipeline(RenderSystem.getCompiledPipeline(RenderPipelines.INTEGRATE_DEPTH));
500
				renderPass.draw(3, 1, 0, 0);
501
			}
502
		}
503
	}
504
505
	private boolean frameHasAlwaysOnTopGizmos() {
506
		return !this.finalizedGizmos.alwaysOnTopPrimitives().isEmpty();
507
	}
508
509
	private void executeSolid(
510
		final ChunkSectionsToRender chunkSectionsToRender, final FeatureRenderDispatcher.PreparedFrame featureFrame, final RenderPass renderPass
511
	) {
512
		ProfilerFiller profiler = Profiler.get();
513
		profiler.push("solidTerrain");
514
		GpuTextureView blockAtlas = this.textureManager.getTexture(TextureAtlas.LOCATION_BLOCKS).getTextureView();
515
		chunkSectionsToRender.renderGroup(ChunkSectionLayerGroup.OPAQUE, renderPass, this.chunkLayerSampler, blockAtlas, this.levelRenderState.renderWireframeTerrain);
516
		profiler.popPush("renderSolidFeatures");
517
		featureFrame.executeSolid(renderPass);
518
		profiler.pop();
519
	}
520
521
	private void prepareTranslucents() {
522
		CloudStatus cloudStatus = this.optionsRenderState.cloudStatus;
523
		boolean shouldRenderClouds = cloudStatus != CloudStatus.OFF && ARGB.alpha(this.levelRenderState.cloudColor) > 0;
524
		if (shouldRenderClouds) {
525
			this.cloudRenderer
526
				.prepare(
527
					this.levelRenderState.cloudColor,
528
					cloudStatus,
529
					this.levelRenderState.cloudHeight,
530
					this.optionsRenderState.cloudRange,
531
					this.levelRenderState.cameraRenderState.pos,
532
					this.levelRenderState.gameTime,
533
					this.levelRenderState.worldPartialTicks
534
				);
535
		}
536
537
		int renderDistance = this.optionsRenderState.renderDistance * 16;
538
		CameraRenderState cameraState = this.levelRenderState.cameraRenderState;
539
		this.worldBorderRenderer
540
			.prepare(this.levelRenderState.worldBorderRenderState, cameraState.pos, renderDistance, this.levelRenderState.cameraRenderState.depthFar);
541
		this.weatherEffectRenderer.prepare(cameraState.pos, this.levelRenderState.weatherRenderState);
542
		RenderSystem.resizeAllAutoStorageIndexBuffers();
543
	}
544
545
	private void executeOit(final ChunkSectionsToRender chunkSectionsToRender, final FeatureRenderDispatcher.PreparedFrame featureFrame) {
546
		boolean frameHasWaterMask = featureFrame.hasAnyWaterMask();
547
		CloudStatus cloudStatus = this.optionsRenderState.cloudStatus;
548
		boolean shouldRenderClouds = cloudStatus != CloudStatus.OFF && ARGB.alpha(this.levelRenderState.cloudColor) > 0;
549
		int renderDistance = this.optionsRenderState.renderDistance * 16;
550
		CameraRenderState cameraState = this.levelRenderState.cameraRenderState;
551
		GpuTextureView mainDepthTextureView = this.gameRenderer.mainRenderTarget().getDepthTextureView();
552
		RenderTarget mainTarget = this.targets.main.get();
553
		if (frameHasWaterMask) {
554
			this.executeOitWaterMask(featureFrame, mainTarget);
555
		}
556
557
		GpuTextureView depthBoundsTargetView = this.targets.depthBounds.get().getColorTextureView();
558
		GpuTextureView depthBoundsCulledTargetView = this.targets.depthBoundsCulled.get().getColorTextureView();
559
		GpuTextureView accumulateTargetView = this.targets.accumulate.get().getColorTextureView();
560
		GpuTextureView[] transmittanceTargetViews = new GpuTextureView[OIT_TRANSMITTANCE_TARGET_COUNT];
561
562
		for (int i = 0; i < OIT_TRANSMITTANCE_TARGET_COUNT; i++) {
563
			transmittanceTargetViews[i] = this.targets.transmittance.get(i).get().getColorTextureView();
564
		}
565
566
		OitRenderPassProvider.Parameters params = new OitRenderPassProvider.Parameters(
567
			depthBoundsTargetView, transmittanceTargetViews, accumulateTargetView, mainDepthTextureView
568
		);
569
		OitRenderPassProvider.Parameters cloudParams;
570
		if (shouldRenderClouds) {
571
			GpuTextureView cloudDepthTextureView = this.targets.oitCloudDepth.get().getDepthTextureView();
572
			cloudParams = new OitRenderPassProvider.Parameters(depthBoundsCulledTargetView, transmittanceTargetViews, accumulateTargetView, cloudDepthTextureView);
573
		} else {
574
			cloudParams = null;
575
		}
576
577
		OitRenderPassProvider.Parameters terrainParams;
578
		if (frameHasWaterMask) {
579
			GpuTextureView terrainDepthTextureView = this.targets.oitTerrainWithWaterPatchDepth.get().getDepthTextureView();
580
			terrainParams = new OitRenderPassProvider.Parameters(depthBoundsTargetView, transmittanceTargetViews, accumulateTargetView, terrainDepthTextureView);
581
		} else {
582
			terrainParams = params;
583
		}
584
585
		GpuTextureView blockAtlas = this.textureManager.getTexture(TextureAtlas.LOCATION_BLOCKS).getTextureView();
586
587
		for (OitStage stage : OitStage.values()) {
588
			chunkSectionsToRender.renderOit(this.chunkLayerSampler, stage, terrainParams, blockAtlas, this.gameRenderer.lightmap());
589
590
			try (RenderPass renderPass = OitRenderPassProvider.createRenderPass(stage, () -> "Features, World Border, Weather", params)) {
591
				featureFrame.executeOit(stage, renderPass);
592
				this.worldBorderRenderer.renderOit(this.levelRenderState.worldBorderRenderState, cameraState.pos, renderDistance, stage, renderPass);
593
				this.weatherEffectRenderer.renderOit(stage, this.levelRenderState.weatherRenderState, renderPass);
594
			}
595
596
			if (stage == OitStage.DEPTH_BOUNDS) {
597
				this.executeDepthBoundsCull();
598
				params.setDepthBoundsTargetView(depthBoundsCulledTargetView);
599
				terrainParams.setDepthBoundsTargetView(depthBoundsCulledTargetView);
600
			}
601
602
			if (shouldRenderClouds) {
603
				this.cloudRenderer.renderOit(cloudStatus, stage, mainDepthTextureView, cloudParams);
604
			}
605
606
			if (stage == OitStage.DEPTH_BOUNDS && frameHasWaterMask) {
607
				this.executeOitWaterMask(featureFrame, mainTarget);
608
			}
609
		}
610
611
		GpuSampler nearestSampler = RenderSystem.getSamplerCache().getClampToEdge(FilterMode.NEAREST);
612
		RenderTarget renderTarget = this.gameRenderer.mainRenderTarget();
613
614
		try (RenderPass renderPass = RenderSystem.getDevice()
615
				.createCommandEncoder()
616
				.createRenderPass(() -> "OIT Composite", renderTarget.getColorTextureView(), Optional.empty(), renderTarget.getDepthTextureView(), OptionalDouble.empty())) {
617
			RenderSystem.bindDefaultUniforms(renderPass);
618
			renderPass.setUniform("Sampler0", accumulateTargetView, nearestSampler);
619
620
			for (int i = 0; i < OIT_TRANSMITTANCE_TARGET_COUNT; i++) {
621
				renderPass.setUniform("Coeff" + i, this.targets.transmittance.get(i).get().getColorTextureView(), nearestSampler);
622
			}
623
624
			renderPass.setUniform("DepthBoundsSampler", depthBoundsTargetView, nearestSampler);
625
			renderPass.setPipeline(RenderSystem.getCompiledPipeline(RenderPipelines.OIT_COMPOSITE));
626
			renderPass.draw(3, 1, 0, 0);
627
		}
628
	}
629
630
	private void executeDepthBoundsCull() {
631
		GpuSampler nearestSampler = RenderSystem.getSamplerCache().getClampToEdge(FilterMode.NEAREST);
632
		RenderTarget depthBoundsTarget = this.targets.depthBounds.get();
633
		RenderTarget depthBoundsCulledTarget = this.targets.depthBoundsCulled.get();
634
635
		try (RenderPass renderPass = RenderSystem.getDevice()
636
				.createCommandEncoder()
637
				.createRenderPass(
638
					() -> "OIT cull Depth Bounds",
639
					depthBoundsCulledTarget.getColorTextureView(),
640
					Optional.empty(),
641
					this.gameRenderer.mainRenderTarget().getDepthTextureView(),
642
					OptionalDouble.empty()
643
				)) {
644
			RenderSystem.bindDefaultUniforms(renderPass);
645
			renderPass.setPipeline(RenderSystem.getCompiledPipeline(RenderPipelines.BLIT_DEPTH_BOUNDS));
646
			renderPass.setUniform("InSampler", depthBoundsTarget.getColorTextureView(), nearestSampler);
647
			renderPass.draw(3, 1, 0, 0);
648
			renderPass.setUniform("DepthBoundsSampler", depthBoundsTarget.getColorTextureView(), nearestSampler);
649
			renderPass.setPipeline(RenderSystem.getCompiledPipeline(RenderPipelines.OIT_DEPTH_BOUNDS_CULL));
650
			renderPass.draw(3, 1, 0, 0);
651
		}
652
	}
653
654
	private void executeOitWaterMask(final FeatureRenderDispatcher.PreparedFrame featureFrame, final RenderTarget mainTarget) {
655
		GpuSampler nearestSampler = RenderSystem.getSamplerCache().getClampToEdge(FilterMode.NEAREST);
656
		RenderTarget terrainTarget = this.targets.oitTerrainWithWaterPatchDepth.get();
657
		RenderPassDescriptor descriptor = RenderPassDescriptor.builder(() -> "Water mask").withDepthAttachment(terrainTarget.getDepthTextureView()).build();
658
659
		try (RenderPass renderPass = RenderSystem.getDevice().createCommandEncoder().createRenderPass(descriptor)) {
660
			RenderSystem.bindDefaultUniforms(renderPass);
661
			renderPass.setPipeline(RenderSystem.getCompiledPipeline(RenderPipelines.BLIT_DEPTH));
662
			renderPass.setUniform("InSampler", mainTarget.getDepthTextureView(), nearestSampler);
663
			renderPass.draw(3, 1, 0, 0);
664
			featureFrame.executeWaterMask(renderPass);
665
		}
666
	}
667
668
	private void executeClassicTransparency(
669
		final ChunkSectionsToRender chunkSectionsToRender, final FeatureRenderDispatcher.PreparedFrame featureFrame, final RenderPass renderPass
670
	) {
671
		ProfilerFiller profiler = Profiler.get();
672
		CloudStatus cloudStatus = this.optionsRenderState.cloudStatus;
673
		boolean shouldRenderClouds = cloudStatus != CloudStatus.OFF && ARGB.alpha(this.levelRenderState.cloudColor) > 0;
674
		int renderDistance = this.optionsRenderState.renderDistance * 16;
675
		profiler.push("renderTranslucentFeatures");
676
		featureFrame.executeTranslucent(renderPass);
677
		profiler.pop();
678
		GpuTextureView blockAtlas = this.textureManager.getTexture(TextureAtlas.LOCATION_BLOCKS).getTextureView();
679
		profiler.push("translucentTerrain");
680
		chunkSectionsToRender.renderGroup(
681
			ChunkSectionLayerGroup.TRANSLUCENT, renderPass, this.chunkLayerSampler, blockAtlas, this.levelRenderState.renderWireframeTerrain
682
		);
683
		profiler.pop();
684
		featureFrame.executeTranslucentAfterTerrain(renderPass);
685
		if (shouldRenderClouds) {
686
			this.cloudRenderer.render(cloudStatus, renderPass);
687
		}
688
689
		Vec3 cameraPos = this.levelRenderState.cameraRenderState.pos;
690
		this.weatherEffectRenderer.render(this.levelRenderState.weatherRenderState, renderPass);
691
		this.worldBorderRenderer.render(this.levelRenderState.worldBorderRenderState, renderPass, cameraPos, renderDistance);
692
	}
693
694
	private void executeOutline(final FeatureRenderDispatcher.PreparedFrame featureFrame) {
695
		if (this.currentFrameRendersEntityOutline) {
696
			try (RenderPass renderPass = RenderSystem.getDevice()
697
					.createCommandEncoder()
698
					.createRenderPass(() -> "Outline", this.entityOutlineTarget.getColorTextureView(), Optional.of(ZERO_CLEAR_COLOR), null, OptionalDouble.empty())) {
699
				RenderSystem.bindDefaultUniforms(renderPass);
700
				featureFrame.executeOutline(renderPass);
701
			}
702
		}
703
	}
704
705
	private int extractSectionDrawGroups(
706
		final boolean respectTranslucentOrder,
707
		final List<DynamicGpuData.ChunkSectionInfo> sectionInfos,
708
		final Map<ChunkSectionLayer, List<LevelRenderer.ChunkDrawGroup>> drawGroups
709
	) {
710
		int largestIndexCount = 0;
711
		Int2ObjectOpenHashMap<LevelRenderer.ChunkDrawGroup> drawGroupCache = new Int2ObjectOpenHashMap<>();
712
		if (this.sectionRenderDispatcher != null) {
713
			this.sectionRenderDispatcher.lock();
714
			long fadeDuration = Util.toMillis(this.optionsRenderState.chunkSectionFadeInTime);
715
			long now = Util.getMillis();
716
			int lastTransparentGroupHash = 0;
717
718
			try {
719
				for (SectionRenderDispatcher.RenderSection section : this.visibleSections) {
720
					SectionMesh sectionMesh = section.getSectionMesh();
721
					BlockPos renderOffset = section.getRenderOrigin();
722
					int sectionInfoDataIndex = -1;
723
724
					for (ChunkSectionLayer layer : ChunkSectionLayer.values()) {
725
						SectionMesh.SectionDraw draw = sectionMesh.getSectionDraw(layer);
726
						SectionRenderDispatcher.RenderSectionBufferSlice slice = this.sectionRenderDispatcher.getRenderSectionSlice(sectionMesh, layer);
727
						if (slice != null && draw != null && (!draw.hasCustomIndexBuffer() || slice.indexBuffer() != null)) {
728
							if (sectionInfoDataIndex == -1) {
729
								sectionInfoDataIndex = sectionInfos.size();
730
								sectionInfos.add(
731
									new DynamicGpuData.ChunkSectionInfo(renderOffset.getX(), renderOffset.getY(), renderOffset.getZ(), section.getVisibility(now, fadeDuration))
732
								);
733
							}
734
735
							int combinedHash = 173;
736
							VertexFormat vertexFormat = layer.pipeline(false).getVertexFormatBinding(0);
737
							GpuBuffer vertexBuffer = slice.vertexBuffer();
738
							combinedHash = 31 * combinedHash + vertexBuffer.hashCode();
739
							int firstIndex = 0;
740
							GpuBuffer indexBuffer;
741
							IndexType indexType;
742
							if (!draw.hasCustomIndexBuffer()) {
743
								if (draw.indexCount() > largestIndexCount) {
744
									largestIndexCount = draw.indexCount();
745
								}
746
747
								indexBuffer = null;
748
								indexType = null;
749
							} else {
750
								indexBuffer = slice.indexBuffer();
751
								indexType = draw.indexType();
752
								combinedHash = 31 * combinedHash + indexBuffer.hashCode();
753
								combinedHash = 31 * combinedHash + indexType.hashCode();
754
								firstIndex = (int)(slice.indexBufferOffset() / indexType.bytes);
755
							}
756
757
							int baseVertex = (int)(slice.vertexBufferOffset() / vertexFormat.getVertexSize());
758
							LevelRenderer.ChunkDrawGroup drawGroup = null;
759
							if (layer.translucent() && respectTranslucentOrder) {
760
								if (combinedHash == lastTransparentGroupHash) {
761
									drawGroup = drawGroups.get(layer).getLast();
762
								}
763
764
								lastTransparentGroupHash = combinedHash;
765
							} else {
766
								drawGroup = drawGroupCache.getOrDefault(combinedHash, null);
767
							}
768
769
							if (drawGroup == null) {
770
								drawGroup = new LevelRenderer.ChunkDrawGroup(vertexBuffer.slice(), indexBuffer != null ? indexBuffer.slice() : null, indexType, new ArrayList<>());
771
								drawGroupCache.put(combinedHash, drawGroup);
772
								drawGroups.get(layer).add(drawGroup);
773
							}
774
775
							drawGroup.draws.add(new DynamicGpuData.IndexedDraw(draw.indexCount(), 1, firstIndex, baseVertex, sectionInfoDataIndex));
776
						}
777
					}
778
				}
779
			} finally {
780
				this.sectionRenderDispatcher.unlock();
781
			}
782
		}
783
784
		return largestIndexCount;
785
	}
786
787
	public ChunkSectionsToRender prepareChunkRenders(final Matrix4fc modelViewMatrix, final boolean respectTranslucentOrder) {
788
		Map<ChunkSectionLayer, List<LevelRenderer.ChunkDrawGroup>> drawGroups = Util.makeEnumMap(ChunkSectionLayer.class, var0 -> new ReferenceArrayList<>());
789
		List<DynamicGpuData.ChunkSectionInfo> sectionInfos = new ArrayList<>();
790
		GpuTextureView blockAtlas = this.textureManager.getTexture(TextureAtlas.LOCATION_BLOCKS).getTextureView();
791
		int textureAtlasWidth = blockAtlas.getWidth(0);
792
		int textureAtlasHeight = blockAtlas.getHeight(0);
793
		int largestIndexCount = this.extractSectionDrawGroups(respectTranslucentOrder, sectionInfos, drawGroups);
794
		Map<ChunkSectionLayer, List<RenderPass.Draw<GpuBufferSlice[]>>> flattenDraws = Util.makeEnumMap(ChunkSectionLayer.class, layerx -> new ReferenceArrayList<>());
795
796
		for (ChunkSectionLayer layer : ChunkSectionLayer.values()) {
797
			List<LevelRenderer.ChunkDrawGroup> sortedDrawGroups = drawGroups.get(layer);
798
			if (layer.translucent() && respectTranslucentOrder) {
799
				sortedDrawGroups = sortedDrawGroups.reversed();
800
			}
801
802
			for (LevelRenderer.ChunkDrawGroup drawGroup : sortedDrawGroups) {
803
				List<RenderPass.Draw<GpuBufferSlice[]>> dest = flattenDraws.get(layer);
804
				List<DynamicGpuData.IndexedDraw> sortedDraws = drawGroup.draws;
805
				if (layer.translucent() && respectTranslucentOrder) {
806
					sortedDraws = sortedDraws.reversed();
807
				}
808
809
				for (DynamicGpuData.IndexedDraw draw : sortedDraws) {
810
					int sectionInfoDataIndex = draw.baseInstance();
811
					GpuBuffer indexBuffer = drawGroup.indexBuffer == null ? null : drawGroup.indexBuffer().buffer();
812
					dest.add(
813
						new RenderPass.Draw<>(
814
							0,
815
							drawGroup.vertexBuffer.buffer(),
816
							indexBuffer,
817
							drawGroup.indexType,
818
							draw.firstIndex(),
819
							draw.indexCount(),
820
							draw.baseVertex(),
821
							(sectionUbos, uploader) -> uploader.setUniform("ChunkSection", sectionUbos[sectionInfoDataIndex])
822
						)
823
					);
824
				}
825
			}
826
		}
827
828
		GpuBufferSlice terrainTransformUbo = RenderSystem.getDynamicUniforms().writeTerrainTransform(modelViewMatrix, textureAtlasWidth, textureAtlasHeight);
829
		GpuBufferSlice[] chunkSectionInfos = RenderSystem.getDynamicUniforms().writeChunkSections(sectionInfos.toArray(new DynamicGpuData.ChunkSectionInfo[0]));
830
		RenderSystem.AutoStorageIndexBuffer autoIndices = RenderSystem.getSequentialBuffer(PrimitiveTopology.QUADS);
831
		if (largestIndexCount != 0) {
832
			autoIndices.requestIndexCount(largestIndexCount);
833
		}
834
835
		return new ChunkSectionsToRender.DrawSeparate(terrainTransformUbo, flattenDraws, largestIndexCount, chunkSectionInfos);
836
	}
837
838
	public void addTransientBlock(final long blockNode, final TransientBlockRenderState state) {
839
		this.transientBlocks.put(blockNode, state);
840
	}
841
842
	public void removeTransientBlocksInSection(final long sectionNode, final long compileTaskStartTimeNs) {
843
		this.transientBlockRemovalQueue.add(new TransientBlockRenderState.Removal(sectionNode, compileTaskStartTimeNs));
844
	}
845
846
	private void performTransientBlockRemovals() {
847
		while (true) {
848
			TransientBlockRenderState.Removal removal = this.transientBlockRemovalQueue.poll();
849
			if (removal == null) {
850
				return;
851
			}
852
853
			ObjectBidirectionalIterator<Entry<TransientBlockRenderState>> iterator = Minecraft.getInstance()
854
				.levelRenderer
855
				.transientBlocks
856
				.long2ObjectEntrySet()
857
				.fastIterator();
858
859
			while (iterator.hasNext()) {
860
				Entry<TransientBlockRenderState> entry = iterator.next();
861
				TransientBlockRenderState state = entry.getValue();
862
				if (state.createTimeNs > removal.compileTaskStartTimeNs()) {
863
					break;
864
				}
865
866
				if (SectionPos.blockToSection(entry.getLongKey()) == removal.sectionNode()) {
867
					iterator.remove();
868
				}
869
			}
870
		}
871
	}
872
873
	public ChunkSectionsToRender prepareChunkRendersIndirect(final Matrix4fc modelViewMatrix, final boolean respectTranslucentOrder) {
874
		EnumMap<ChunkSectionLayer, List<LevelRenderer.ChunkDrawGroup>> drawGroups = new EnumMap<>(ChunkSectionLayer.class);
875
876
		for (ChunkSectionLayer layer : ChunkSectionLayer.values()) {
877
			drawGroups.put(layer, new ReferenceArrayList<>());
878
		}
879
880
		List<DynamicGpuData.ChunkSectionInfo> sectionInfos = new ArrayList<>();
881
		GpuTextureView blockAtlas = this.textureManager.getTexture(TextureAtlas.LOCATION_BLOCKS).getTextureView();
882
		int textureAtlasWidth = blockAtlas.getWidth(0);
883
		int textureAtlasHeight = blockAtlas.getHeight(0);
884
		int largestIndexCount = this.extractSectionDrawGroups(respectTranslucentOrder, sectionInfos, drawGroups);
885
		EnumMap<ChunkSectionLayer, List<ChunkSectionsToRender.GpuMultiDrawIndexedIndirect>> indirectDraws = new EnumMap<>(ChunkSectionLayer.class);
886
887
		for (ChunkSectionLayer layer : ChunkSectionLayer.values()) {
888
			indirectDraws.put(layer, new ArrayList<>());
889
		}
890
891
		List<List<DynamicGpuData.IndexedDraw>> batchedDraws = new ArrayList<>();
892
893
		for (ChunkSectionLayer layer : ChunkSectionLayer.values()) {
894
			List<LevelRenderer.ChunkDrawGroup> sortedDrawGroups = drawGroups.get(layer);
895
			if (layer.translucent() && respectTranslucentOrder) {
896
				sortedDrawGroups = sortedDrawGroups.reversed();
897
			}
898
899
			for (LevelRenderer.ChunkDrawGroup chunkDrawGroup : sortedDrawGroups) {
900
				List<DynamicGpuData.IndexedDraw> sortedDraws = chunkDrawGroup.draws;
901
				if (layer.translucent() && respectTranslucentOrder) {
902
					sortedDraws = sortedDraws.reversed();
903
				}
904
905
				batchedDraws.add(sortedDraws);
906
			}
907
		}
908
909
		GpuBufferSlice[] indirectBufferSlices = RenderSystem.getDynamicUniforms().writeChunkSectionCommands(batchedDraws);
910
		int index = 0;
911
912
		for (ChunkSectionLayer layer : ChunkSectionLayer.values()) {
913
			List<LevelRenderer.ChunkDrawGroup> sortedDrawGroups = drawGroups.get(layer);
914
			if (layer.translucent() && respectTranslucentOrder) {
915
				sortedDrawGroups = sortedDrawGroups.reversed();
916
			}
917
918
			for (LevelRenderer.ChunkDrawGroup chunkDrawGroup : sortedDrawGroups) {
919
				List<DynamicGpuData.IndexedDraw> draws = chunkDrawGroup.draws;
920
				GpuBufferSlice indirectBuffer = indirectBufferSlices[index++];
921
				indirectDraws.get(layer)
922
					.add(
923
						new ChunkSectionsToRender.GpuMultiDrawIndexedIndirect(
924
							chunkDrawGroup.vertexBuffer, chunkDrawGroup.indexBuffer, chunkDrawGroup.indexType, indirectBuffer, draws.size()
925
						)
926
					);
927
			}
928
		}
929
930
		GpuBufferSlice terrainTransformUbo = RenderSystem.getDynamicUniforms().writeTerrainTransform(modelViewMatrix, textureAtlasWidth, textureAtlasHeight);
931
		GpuBufferSlice chunkSectionInfos = RenderSystem.getDynamicUniforms().writeChunkSectionsInstanced(sectionInfos);
932
		RenderSystem.AutoStorageIndexBuffer autoIndices = RenderSystem.getSequentialBuffer(PrimitiveTopology.QUADS);
933
		if (largestIndexCount != 0) {
934
			autoIndices.requestIndexCount(largestIndexCount);
935
		}
936
937
		return new ChunkSectionsToRender.DrawIndirect(terrainTransformUbo, indirectDraws, largestIndexCount, chunkSectionInfos);
938
	}
939
940
	private void compileSections(final CameraRenderState camera) {
941
		ProfilerFiller profiler = Profiler.get();
942
		profiler.push("populateSectionsToCompile");
943
		BlockPos cameraPosition = camera.blockPos;
944
945
		for (SectionUpdateRenderState state : this.levelRenderState.sectionUpdateRenderStates) {
946
			BlockPos center = SectionPos.of(state.sectionNode()).center();
947
			double distSqr = center.distSqr(cameraPosition);
948
			boolean isNearby = distSqr < 768.0;
949
			boolean rebuildSync = false;
950
			if (this.optionsRenderState.prioritizeChunkUpdates == PrioritizeChunkUpdates.NEARBY) {
951
				rebuildSync = isNearby || state.playerChanged();
952
			} else if (this.optionsRenderState.prioritizeChunkUpdates == PrioritizeChunkUpdates.PLAYER_AFFECTED) {
953
				rebuildSync = state.playerChanged();
954
			}
955
956
			SectionRenderDispatcher.RenderSection section = this.viewArea.getRenderSection(state.sectionNode());
957
			if (rebuildSync) {
958
				profiler.push("compileSectionSynchronously");
959
				section.compileSync(state.region());
960
				profiler.pop();
961
			} else {
962
				section.compileAsync(state.region());
963
			}
964
		}
965
966
		profiler.popPush("scheduleTranslucentResort");
967
		this.scheduleTranslucentSectionResort(camera.pos);
968
		profiler.pop();
969
	}
970
971
	private void checkPoseStack(final PoseStack poseStack) {
972
		if (!poseStack.isEmpty()) {
973
			throw new IllegalStateException("Pose stack not empty");
974
		}
975
	}
976
977
	private void submitEntities(final PoseStack poseStack, final LevelRenderState levelRenderState, final SubmitNodeCollector output) {
978
		Vec3 cameraPos = levelRenderState.cameraRenderState.pos;
979
		double camX = cameraPos.x();
980
		double camY = cameraPos.y();
981
		double camZ = cameraPos.z();
982
983
		for (EntityRenderState state : levelRenderState.entityRenderStates) {
984
			this.entityRenderDispatcher.submit(state, levelRenderState.cameraRenderState, state.x - camX, state.y - camY, state.z - camZ, poseStack, output);
985
		}
986
	}
987
988
	private void submitBlockEntities(final PoseStack poseStack, final LevelRenderState levelRenderState, final SubmitNodeCollector submitNodeCollector) {
989
		Vec3 cameraPos = levelRenderState.cameraRenderState.pos;
990
		double camX = cameraPos.x();
991
		double camY = cameraPos.y();
992
		double camZ = cameraPos.z();
993
994
		for (BlockEntityRenderState renderState : levelRenderState.blockEntityRenderStates) {
995
			BlockPos blockPos = renderState.blockPos;
996
			poseStack.pushPose();
997
			poseStack.translate(blockPos.getX() - camX, blockPos.getY() - camY, blockPos.getZ() - camZ);
998
			this.blockEntityRenderDispatcher.submit(renderState, poseStack, submitNodeCollector, levelRenderState.cameraRenderState);
999
			poseStack.popPose();
1000
		}
1001
	}
1002
1003
	private void submitBlockDestroyAnimation(final PoseStack poseStack, final SubmitNodeCollector submitNodeCollector, final LevelRenderState levelRenderState) {
1004
		if (!levelRenderState.blockBreakingRenderStates.isEmpty()) {
1005
			Vec3 cameraPos = levelRenderState.cameraRenderState.pos;
1006
			double camX = cameraPos.x();
1007
			double camY = cameraPos.y();
1008
			double camZ = cameraPos.z();
1009
			List<BlockStateModelPart> parts = new ArrayList<>();
1010
			RandomSource random = RandomSource.createThreadLocalInstance();
1011
1012
			for (BlockBreakingRenderState state : levelRenderState.blockBreakingRenderStates) {
1013
				if (state.blockState().getRenderShape() == RenderShape.MODEL) {
1014
					BlockPos pos = state.blockPos();
1015
					poseStack.pushPose();
1016
					poseStack.translate(pos.getX() - camX, pos.getY() - camY, pos.getZ() - camZ);
1017
					poseStack.translate(state.blockState().getOffset(pos));
1018
					BlockStateModel model = this.modelManager.getBlockStateModelSet().get(state.blockState());
1019
					random.setSeed(state.blockState().getSeed(pos));
1020
					model.collectParts(random, parts);
1021
					submitNodeCollector.submitBreakingBlockModel(poseStack, List.copyOf(parts), state.progress(), model.hasMaterialFlag(1));
1022
					parts.clear();
1023
					poseStack.popPose();
1024
				}
1025
			}
1026
		}
1027
	}
1028
1029
	private void submitTransientBlocks(final PoseStack poseStack, final SubmitNodeCollector submitNodeCollector, final LevelRenderState levelRenderState) {
1030
		this.performTransientBlockRemovals();
1031
		ObjectIterator<Entry<TransientBlockRenderState>> iterator = this.transientBlocks.long2ObjectEntrySet().fastIterator();
1032
		long currentTimeMs = Util.getMillis();
1033
		Vec3 cameraPos = levelRenderState.cameraRenderState.pos;
1034
		double camX = cameraPos.x();
1035
		double camY = cameraPos.y();
1036
		double camZ = cameraPos.z();
1037
1038
		while (iterator.hasNext()) {
1039
			Entry<TransientBlockRenderState> entry = iterator.next();
1040
			TransientBlockRenderState state = entry.getValue();
1041
			if (currentTimeMs >= state.liveUntilMs) {
1042
				iterator.remove();
1043
			} else {
1044
				poseStack.pushPose();
1045
				BlockPos blockPos = state.movingBlockRenderState.blockPos;
1046
				poseStack.translate(blockPos.getX() - camX, blockPos.getY() - camY, blockPos.getZ() - camZ);
1047
				submitNodeCollector.submitMovingBlock(poseStack, state.movingBlockRenderState, 0);
1048
				poseStack.popPose();
1049
			}
1050
		}
1051
	}
1052
1053
	private void submitBlockOutline(final PoseStack poseStack, final SubmitNodeCollector submitNodeCollector, final LevelRenderState levelRenderState) {
1054
		BlockOutlineRenderState state = levelRenderState.blockOutlineRenderState;
1055
		if (state != null) {
1056
			Vec3 cameraPos = levelRenderState.cameraRenderState.pos;
1057
			BlockPos pos = state.pos();
1058
			poseStack.pushPose();
1059
			poseStack.translate(pos.getX() - cameraPos.x, pos.getY() - cameraPos.y, pos.getZ() - cameraPos.z);
1060
			if (state.highContrast()) {
1061
				this.submitHitOutline(poseStack, submitNodeCollector, RenderTypes.secondaryBlockOutline(), state, -16777216, 7.0F, state.isTranslucent());
1062
			}
1063
1064
			int outlineColor = state.highContrast() ? -11010079 : ARGB.black(102);
1065
			RenderType blockOutlineRenderType;
1066
			if (state.highContrast()) {
1067
				blockOutlineRenderType = RenderTypes.linesDepthBias();
1068
			} else if (this.gameRenderer.useImprovedTransparency()) {
1069
				blockOutlineRenderType = RenderTypes.linesTranslucentNoDepthWrite();
1070
			} else {
1071
				blockOutlineRenderType = RenderTypes.linesTranslucent();
1072
			}
1073
1074
			this.submitHitOutline(
1075
				poseStack,
1076
				submitNodeCollector,
1077
				blockOutlineRenderType,
1078
				state,
1079
				outlineColor,
1080
				this.gameRenderer.gameRenderState().windowRenderState.appropriateLineWidth,
1081
				state.isTranslucent()
1082
			);
1083
			poseStack.popPose();
1084
		}
1085
	}
1086
1087
	private void submitHitOutline(
1088
		final PoseStack poseStack,
1089
		final SubmitNodeCollector submitNodeCollector,
1090
		final RenderType renderType,
1091
		final BlockOutlineRenderState state,
1092
		final int color,
1093
		final float width,
1094
		final boolean afterTerrain
1095
	) {
1096
		if (SharedConstants.DEBUG_SHAPES) {
1097
			submitNodeCollector.submitShapeOutline(poseStack, state.shape(), renderType, -1, width, afterTerrain);
1098
			if (state.collisionShape() != null) {
1099
				submitNodeCollector.submitShapeOutline(poseStack, state.collisionShape(), renderType, ARGB.colorFromFloat(0.4F, 0.0F, 0.0F, 0.0F), width, afterTerrain);
1100
			}
1101
1102
			if (state.occlusionShape() != null) {
1103
				submitNodeCollector.submitShapeOutline(poseStack, state.occlusionShape(), renderType, ARGB.colorFromFloat(0.4F, 0.0F, 1.0F, 0.0F), width, afterTerrain);
1104
			}
1105
1106
			if (state.interactionShape() != null) {
1107
				submitNodeCollector.submitShapeOutline(poseStack, state.interactionShape(), renderType, ARGB.colorFromFloat(0.4F, 0.0F, 0.0F, 1.0F), width, afterTerrain);
1108
			}
1109
		} else {
1110
			submitNodeCollector.submitShapeOutline(poseStack, state.shape(), renderType, color, width, afterTerrain);
1111
		}
1112
	}
1113
1114
	public void resize(final int width, final int height) {
1115
		this.sectionOcclusionGraph.invalidate();
1116
		this.entityOutlineTarget.resize(width, height);
1117
	}
1118
1119
	public void endFrame() {
1120
		this.cloudRenderer.endFrame();
1121
	}
1122
1123
	@Override
1124
	public void close() {
1125
		this.resetLevelRenderData();
1126
		this.entityOutlineTarget.destroyBuffers();
1127
		if (this.skyRenderer != null) {
1128
			this.skyRenderer.close();
1129
		}
1130
1131
		if (this.chunkLayerSampler != null) {
1132
			this.chunkLayerSampler.close();
1133
		}
1134
1135
		this.worldBorderRenderer.close();
1136
		this.cloudRenderer.close();
1137
		this.weatherEffectRenderer.close();
1138
	}
1139
1140
	public void blitEntityOutline() {
1141
		if (this.currentFrameRendersEntityOutline) {
1142
			this.entityOutlineTarget
1143
				.blitAndBlendToTexture(this.gameRenderer.mainRenderTarget().getColorTextureView(), this.gameRenderer.mainRenderTarget().getDepthTextureView());
1144
		}
1145
	}
1146
1147
	public void invalidateCompiledGeometry(final ClientLevel level, final Options options, final Camera camera, final BlockColors blockColors) {
1148
		SectionCompiler sectionCompiler = new SectionCompiler(
1149
			options.ambientOcclusion().get(),
1150
			options.cutoutLeaves().get(),
1151
			this.modelManager.getBlockStateModelSet(),
1152
			this.modelManager.getFluidStateModelSet(),
1153
			blockColors
1154
		);
1155
		if (this.sectionRenderDispatcher == null) {
1156
			this.sectionRenderDispatcher = new SectionRenderDispatcher(
1157
				Util.backgroundExecutor(), this.renderBuffers, sectionCompiler, this.sectionOcclusionGraph::schedulePropagationFrom
1158
			);
1159
		} else {
1160
			this.sectionRenderDispatcher.setCompiler(sectionCompiler);
1161
		}
1162
1163
		this.cloudRenderer().markForRebuild();
1164
		LeavesBlock.setCutoutLeaves(options.cutoutLeaves().get());
1165
		if (this.viewArea != null) {
1166
			this.viewArea.releaseAllBuffers();
1167
		}
1168
1169
		this.sectionRenderDispatcher.clearCompileQueue();
1170
		this.viewArea = new ViewArea(
1171
			this.sectionRenderDispatcher,
1172
			level.getMinY(),
1173
			level.getMaxY(),
1174
			level.getMinSectionY(),
1175
			level.getMaxSectionY(),
1176
			options.getEffectiveRenderDistance(),
1177
			this.sectionOcclusionGraph
1178
		);
1179
		this.sectionOcclusionGraph().waitAndReset(this.viewArea);
1180
		this.clearVisibleSections();
1181
		SectionPos cameraSectionPos = SectionPos.of(camera.position());
1182
		this.viewArea.repositionCamera(cameraSectionPos);
1183
	}
1184
1185
	private void scheduleTranslucentSectionResort(final Vec3 cameraPos) {
1186
		if (!this.visibleSections.isEmpty()) {
1187
			BlockPos cameraBlockPos = BlockPos.containing(cameraPos);
1188
			boolean blockPosChanged = !cameraBlockPos.equals(this.lastTranslucentSortBlockPos);
1189
			TranslucencyPointOfView pointOfView = new TranslucencyPointOfView();
1190
1191
			for (SectionRenderDispatcher.RenderSection section : this.nearbyVisibleSections) {
1192
				this.scheduleResort(section, pointOfView, cameraPos, blockPosChanged, true);
1193
			}
1194
1195
			this.translucencyResortIterationIndex = this.translucencyResortIterationIndex % this.visibleSections.size();
1196
			int resortsLeft = Math.max(this.visibleSections.size() / 8, 15);
1197
1198
			while (resortsLeft-- > 0) {
1199
				int index = this.translucencyResortIterationIndex++ % this.visibleSections.size();
1200
				this.scheduleResort(this.visibleSections.get(index), pointOfView, cameraPos, blockPosChanged, false);
1201
			}
1202
1203
			this.lastTranslucentSortBlockPos = cameraBlockPos;
1204
		}
1205
	}
1206
1207
	private void scheduleResort(
1208
		final SectionRenderDispatcher.RenderSection section,
1209
		final TranslucencyPointOfView pointOfView,
1210
		final Vec3 cameraPos,
1211
		final boolean blockPosChanged,
1212
		final boolean isNearby
1213
	) {
1214
		pointOfView.set(cameraPos, section.getSectionNode());
1215
		boolean pointOfViewChanged = section.getSectionMesh().isDifferentPointOfView(pointOfView);
1216
		boolean resortBecauseBlockPosChanged = blockPosChanged && (pointOfView.isAxisAligned() || isNearby);
1217
		if ((resortBecauseBlockPosChanged || pointOfViewChanged)
1218
			&& !section.transparencyResortingScheduled()
1219
			&& section.hasTranslucentGeometry()
1220
			&& !this.gameRenderer.useImprovedTransparency()) {
1221
			section.resortTransparency();
1222
		}
1223
	}
1224
1225
	public void clearVisibleSections() {
1226
		this.visibleSections.clear();
1227
		this.nearbyVisibleSections.clear();
1228
	}
1229
1230
	public void resetLevelRenderData() {
1231
		if (this.viewArea != null) {
1232
			this.viewArea.releaseAllBuffers();
1233
			this.viewArea = null;
1234
		}
1235
1236
		if (this.sectionRenderDispatcher != null) {
1237
			this.sectionRenderDispatcher.dispose();
1238
		}
1239
1240
		this.sectionRenderDispatcher = null;
1241
		this.sectionOcclusionGraph.waitAndReset(null);
1242
		this.clearVisibleSections();
1243
	}
1244
1245
	public boolean hasRenderedAllSections() {
1246
		return this.sectionRenderDispatcher == null || this.sectionRenderDispatcher.isQueueEmpty();
1247
	}
1248
1249
	public boolean isSectionCompiledAndVisible(final BlockPos blockPos, final long chunkFadeDuration) {
1250
		if (this.viewArea == null) {
1251
			return false;
1252
		}
1253
1254
		SectionRenderDispatcher.RenderSection renderSection = this.viewArea.getRenderSectionAt(blockPos);
1255
		return renderSection != null && renderSection.sectionMesh.get() != CompiledSectionMesh.UNCOMPILED
1256
			? renderSection.getVisibility(Util.getMillis(), chunkFadeDuration) >= 0.3F
1257
			: false;
1258
	}
1259
1260
	public @Nullable SectionRenderDispatcher sectionRenderDispatcher() {
1261
		return this.sectionRenderDispatcher;
1262
	}
1263
1264
	public EntityRenderDispatcher entityRenderDispatcher() {
1265
		return this.entityRenderDispatcher;
1266
	}
1267
1268
	public BlockEntityRenderDispatcher blockEntityRenderDispatcher() {
1269
		return this.blockEntityRenderDispatcher;
1270
	}
1271
1272
	public CloudRenderer cloudRenderer() {
1273
		return this.cloudRenderer;
1274
	}
1275
1276
	public @Nullable SkyRenderer skyRenderer() {
1277
		return this.skyRenderer;
1278
	}
1279
1280
	public WeatherEffectRenderer weatherEffectRenderer() {
1281
		return this.weatherEffectRenderer;
1282
	}
1283
1284
	public WorldBorderRenderer worldBorderRenderer() {
1285
		return this.worldBorderRenderer;
1286
	}
1287
1288
	public @Nullable ViewArea viewArea() {
1289
		return this.viewArea;
1290
	}
1291
1292
	public ObjectArrayList<SectionRenderDispatcher.RenderSection> visibleSections() {
1293
		return this.visibleSections;
1294
	}
1295
1296
	public ObjectArrayList<SectionRenderDispatcher.RenderSection> nearbyVisibleSections() {
1297
		return this.nearbyVisibleSections;
1298
	}
1299
1300
	public LongCollection expectedChunks() {
1301
		return this.sectionOcclusionGraph.expectedChunks();
1302
	}
1303
1304
	public SectionOcclusionGraph sectionOcclusionGraph() {
1305
		return this.sectionOcclusionGraph;
1306
	}
1307
1308
	public TemporaryCollection collectPerFrameRenderThreadGizmos() {
1309
		return Gizmos.withCollector(this.renderThreadGizmos);
1310
	}
1311
1312
	public boolean isChunkRenderingUsingMultiDrawIndirect() {
1313
		return this.usingMultiDrawIndirectForTerrain;
1314
	}
1315
1316
	private void finalizeGizmoCollection() {
1317
		DrawableGizmoPrimitives standardPrimitives = new DrawableGizmoPrimitives();
1318
		DrawableGizmoPrimitives alwaysOnTopPrimitives = new DrawableGizmoPrimitives();
1319
		long currentMillis = Util.getMillis();
1320
1321
		for (GizmoInstance instance : this.renderThreadGizmos.drainGizmos()) {
1322
			instance.gizmo().emit(instance.isAlwaysOnTop() ? alwaysOnTopPrimitives : standardPrimitives, instance.getAlphaMultiplier(currentMillis));
1323
		}
1324
1325
		this.finalizedGizmos = new LevelRenderer.FinalizedGizmos(standardPrimitives, alwaysOnTopPrimitives);
1326
	}
1327
1328
	public void addMainThreadGizmos(final List<GizmoInstance> mainThreadGizmos) {
1329
		this.renderThreadGizmos.addTemporaryGizmos(mainThreadGizmos);
1330
	}
1331
1332
	@Environment(EnvType.CLIENT)
1333
	private record ChunkDrawGroup(
1334
		GpuBufferSlice vertexBuffer, @Nullable GpuBufferSlice indexBuffer, @Nullable IndexType indexType, List<DynamicGpuData.IndexedDraw> draws
1335
	) {
1336
	}
1337
1338
	@Environment(EnvType.CLIENT)
1339
	private record FinalizedGizmos(DrawableGizmoPrimitives standardPrimitives, DrawableGizmoPrimitives alwaysOnTopPrimitives) {
1340
	}
1341
}
1342

Decompiled Minecraft 26.3 source of LevelRenderer (net/minecraft/client/renderer/LevelRenderer.java) with Mojang official mappings, stored verbatim on the site.