|
| 1 | +/* |
| 2 | + * Copyright (c) NeoForged and contributors |
| 3 | + * SPDX-License-Identifier: LGPL-2.1-only |
| 4 | + */ |
| 5 | + |
| 6 | +package net.neoforged.neoforge.client.event; |
| 7 | + |
| 8 | +import com.mojang.blaze3d.framegraph.FrameGraphBuilder; |
| 9 | +import com.mojang.blaze3d.resource.RenderTargetDescriptor; |
| 10 | +import net.minecraft.client.Camera; |
| 11 | +import net.minecraft.client.DeltaTracker; |
| 12 | +import net.minecraft.client.renderer.LevelTargetBundle; |
| 13 | +import net.minecraft.client.renderer.culling.Frustum; |
| 14 | +import net.minecraft.util.profiling.ProfilerFiller; |
| 15 | +import net.neoforged.bus.api.Event; |
| 16 | +import net.neoforged.bus.api.ICancellableEvent; |
| 17 | +import net.neoforged.fml.LogicalSide; |
| 18 | +import net.neoforged.neoforge.common.NeoForge; |
| 19 | +import org.jetbrains.annotations.ApiStatus; |
| 20 | +import org.joml.Matrix4f; |
| 21 | + |
| 22 | +/** |
| 23 | + * Fired when the {@linkplain FrameGraphBuilder frame graph} is set up at the start of level rendering, right before |
| 24 | + * the vanilla frame passes are set up. |
| 25 | + * <p> |
| 26 | + * This event is not {@linkplain ICancellableEvent cancellable}. |
| 27 | + * <p> |
| 28 | + * This event is fired on the {@linkplain NeoForge#EVENT_BUS main Forge event bus}, |
| 29 | + * only on the {@linkplain LogicalSide#CLIENT logical client}. |
| 30 | + */ |
| 31 | +public final class FrameGraphSetupEvent extends Event { |
| 32 | + private final FrameGraphBuilder builder; |
| 33 | + private final LevelTargetBundle targets; |
| 34 | + private final RenderTargetDescriptor renderTargetDescriptor; |
| 35 | + private final Frustum frustum; |
| 36 | + private final Camera camera; |
| 37 | + private final Matrix4f modelViewMatrix; |
| 38 | + private final Matrix4f projectionMatrix; |
| 39 | + private final DeltaTracker deltaTracker; |
| 40 | + private final ProfilerFiller profiler; |
| 41 | + private boolean enableOutline; |
| 42 | + |
| 43 | + @ApiStatus.Internal |
| 44 | + public FrameGraphSetupEvent( |
| 45 | + FrameGraphBuilder builder, |
| 46 | + LevelTargetBundle targets, |
| 47 | + RenderTargetDescriptor renderTargetDescriptor, |
| 48 | + Frustum frustum, |
| 49 | + Camera camera, |
| 50 | + Matrix4f modelViewMatrix, |
| 51 | + Matrix4f projectionMatrix, |
| 52 | + DeltaTracker deltaTracker, |
| 53 | + ProfilerFiller profiler) { |
| 54 | + this.builder = builder; |
| 55 | + this.targets = targets; |
| 56 | + this.renderTargetDescriptor = renderTargetDescriptor; |
| 57 | + this.frustum = frustum; |
| 58 | + this.camera = camera; |
| 59 | + this.modelViewMatrix = modelViewMatrix; |
| 60 | + this.projectionMatrix = projectionMatrix; |
| 61 | + this.deltaTracker = deltaTracker; |
| 62 | + this.profiler = profiler; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * {@return the {@link FrameGraphBuilder} used to set up the frame graph} |
| 67 | + */ |
| 68 | + public FrameGraphBuilder getFrameGrapBuilder() { |
| 69 | + return builder; |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * {@return the render targets used during level rendering} |
| 74 | + */ |
| 75 | + public LevelTargetBundle getTargetBundle() { |
| 76 | + return targets; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * {@return the render target descriptor to use for creating full-screen render targets} |
| 81 | + */ |
| 82 | + public RenderTargetDescriptor getRenderTargetDescriptor() { |
| 83 | + return renderTargetDescriptor; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * {@return the culling frustum} |
| 88 | + */ |
| 89 | + public Frustum getFrustum() { |
| 90 | + return frustum; |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * {@return the active {@link Camera}} |
| 95 | + */ |
| 96 | + public Camera getCamera() { |
| 97 | + return camera; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * {@return the model view matrix} |
| 102 | + */ |
| 103 | + public Matrix4f getModelViewMatrix() { |
| 104 | + return modelViewMatrix; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * {@return the projection matrix} |
| 109 | + */ |
| 110 | + public Matrix4f getProjectionMatrix() { |
| 111 | + return projectionMatrix; |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * {@return the {@link DeltaTracker}} |
| 116 | + */ |
| 117 | + public DeltaTracker getDeltaTracker() { |
| 118 | + return deltaTracker; |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * {@return the active {@linkplain ProfilerFiller profiler}} |
| 123 | + */ |
| 124 | + public ProfilerFiller getProfiler() { |
| 125 | + return profiler; |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * Enables the entity outline post-processing shader regardless of any entities having active outlines |
| 130 | + */ |
| 131 | + public void enableOutlineProcessing() { |
| 132 | + this.enableOutline = true; |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * {@return whether the entity outline post-processing shader will be enabled regardless of entities using it} |
| 137 | + */ |
| 138 | + public boolean isOutlineProcessingEnabled() { |
| 139 | + return enableOutline; |
| 140 | + } |
| 141 | +} |
0 commit comments