-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RegisterRenderBuffersEvent to register fixed BufferBuilders for R…
…enderTypes (#546)
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
patches/net/minecraft/client/renderer/RenderBuffers.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- a/net/minecraft/client/renderer/RenderBuffers.java | ||
+++ b/net/minecraft/client/renderer/RenderBuffers.java | ||
@@ -39,6 +_,7 @@ | ||
put(p_307112_, RenderType.waterMask()); | ||
ModelBakery.DESTROY_TYPES.forEach(p_173062_ -> put(p_307112_, p_173062_)); | ||
}); | ||
+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.RegisterRenderBuffersEvent(sortedmap)); | ||
this.crumblingBufferSource = MultiBufferSource.immediate(new BufferBuilder(1536)); | ||
this.bufferSource = MultiBufferSource.immediateWithBuffers(sortedmap, new BufferBuilder(786432)); | ||
this.outlineBufferSource = new OutlineBufferSource(this.bufferSource); |
57 changes: 57 additions & 0 deletions
57
src/main/java/net/neoforged/neoforge/client/event/RegisterRenderBuffersEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.client.event; | ||
|
||
import com.mojang.blaze3d.vertex.BufferBuilder; | ||
import java.util.SortedMap; | ||
import net.minecraft.client.renderer.RenderType; | ||
import net.neoforged.bus.api.Event; | ||
import net.neoforged.bus.api.ICancellableEvent; | ||
import net.neoforged.fml.LogicalSide; | ||
import net.neoforged.fml.event.IModBusEvent; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
/** | ||
* Fired to allow mods to register custom {@linkplain BufferBuilder render buffers}. | ||
* This allows to have dedicated {@linkplain BufferBuilder render buffer} for each {@linkplain RenderType render type} | ||
* that can filled and rendered in batch | ||
* This event is fired after the default Minecraft render buffers have been registered. | ||
* | ||
* <p>This event is not {@linkplain ICancellableEvent cancellable}, and does not {@linkplain HasResult have a result}.</p> | ||
* | ||
* <p>This event is fired on the mod-specific event bus, only on the {@linkplain LogicalSide#CLIENT logical client}.</p> | ||
*/ | ||
public class RegisterRenderBuffersEvent extends Event implements IModBusEvent { | ||
private final SortedMap<RenderType, BufferBuilder> renderBuffers; | ||
|
||
@ApiStatus.Internal | ||
public RegisterRenderBuffersEvent(SortedMap<RenderType, BufferBuilder> renderBuffers) { | ||
this.renderBuffers = renderBuffers; | ||
} | ||
|
||
/** | ||
* Registers a default render buffer with buffer size specified in the render type. | ||
* | ||
* @param renderType a render type of the render buffer | ||
*/ | ||
public void registerRenderBuffer(RenderType renderType) { | ||
registerRenderBuffer(renderType, new BufferBuilder(renderType.bufferSize())); | ||
} | ||
|
||
/** | ||
* Registers a render buffer for specified render type. | ||
* | ||
* @param renderType a render type of the render buffer | ||
* @param renderBuffer a render buffer to register | ||
*/ | ||
public void registerRenderBuffer(RenderType renderType, BufferBuilder renderBuffer) { | ||
if (renderBuffers.containsKey(renderType)) { | ||
throw new IllegalStateException("Duplicate attempt to register render buffer: " + renderType); | ||
} | ||
|
||
renderBuffers.put(renderType, renderBuffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters