-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1408 from ZhuRuoLing/releases/1.21
添加可缓存的BER渲染管线api
- Loading branch information
Showing
12 changed files
with
433 additions
and
367 deletions.
There are no files selected for viewing
18 changes: 0 additions & 18 deletions
18
src/main/java/dev/dubhe/anvilcraft/api/LaserStateAccess.java
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
src/main/java/dev/dubhe/anvilcraft/api/rendering/CacheableBERenderingPipeline.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,92 @@ | ||
package dev.dubhe.anvilcraft.api.rendering; | ||
|
||
import dev.dubhe.anvilcraft.client.init.ModRenderTypes; | ||
import lombok.Getter; | ||
import net.minecraft.client.multiplayer.ClientLevel; | ||
import net.minecraft.client.renderer.RenderType; | ||
import net.minecraft.world.level.ChunkPos; | ||
import org.joml.Matrix4f; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Queue; | ||
|
||
public class CacheableBERenderingPipeline { | ||
public static final RenderType[] SUPPORTED_RENDERTYPES = new RenderType[]{ | ||
RenderType.solid(), | ||
ModRenderTypes.LASER | ||
}; | ||
|
||
public static final RenderType[] BLOOM_RENDERTYPES = new RenderType[]{ | ||
ModRenderTypes.LASER | ||
}; | ||
|
||
@Getter | ||
private static CacheableBERenderingPipeline instance; | ||
private final ClientLevel level; | ||
private final Queue<Runnable> pendingCompiles = new ArrayDeque<>(); | ||
private final Queue<Runnable> pendingUploads = new ArrayDeque<>(); | ||
private final Map<ChunkPos, RenderRegion> renderRegions = new HashMap<>(); | ||
private boolean valid = true; | ||
|
||
public RenderRegion getRenderRegion(ChunkPos chunkPos) { | ||
if (renderRegions.containsKey(chunkPos)) { | ||
return renderRegions.get(chunkPos); | ||
} | ||
RenderRegion renderRegion = new RenderRegion(chunkPos, this); | ||
renderRegions.put(chunkPos, renderRegion); | ||
return renderRegion; | ||
} | ||
|
||
public CacheableBERenderingPipeline(ClientLevel level) { | ||
this.level = level; | ||
} | ||
|
||
public void runTasks() { | ||
while (!pendingCompiles.isEmpty() && valid) { | ||
pendingCompiles.poll().run(); | ||
} | ||
while (!pendingUploads.isEmpty() && valid) { | ||
pendingUploads.poll().run(); | ||
} | ||
} | ||
|
||
public static void updateLevel(ClientLevel level) { | ||
if (instance != null) { | ||
instance.releaseBuffers(); | ||
} | ||
instance = new CacheableBERenderingPipeline(level); | ||
} | ||
|
||
public void blockRemoved(CacheableBlockEntity be){ | ||
ChunkPos chunkPos = new ChunkPos(be.getBlockPos()); | ||
getRenderRegion(chunkPos).blockRemoved(be); | ||
} | ||
|
||
public void update(CacheableBlockEntity be){ | ||
ChunkPos chunkPos = new ChunkPos(be.getBlockPos()); | ||
getRenderRegion(chunkPos).update(be); | ||
} | ||
|
||
public void submitUploadTask(Runnable task) { | ||
pendingUploads.add(task); | ||
} | ||
|
||
public void submitCompileTask(Runnable task) { | ||
pendingCompiles.add(task); | ||
} | ||
|
||
public void releaseBuffers() { | ||
renderRegions.values().forEach(RenderRegion::releaseBuffers); | ||
valid = false; | ||
} | ||
|
||
public void renderBloomed(Matrix4f frustumMatrix, Matrix4f projectionMatrix) { | ||
renderRegions.values().forEach(it -> it.renderBloomed(frustumMatrix, projectionMatrix)); | ||
} | ||
|
||
public void render(Matrix4f frustumMatrix, Matrix4f projectionMatrix) { | ||
renderRegions.values().forEach(it -> it.render(frustumMatrix, projectionMatrix)); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/dev/dubhe/anvilcraft/api/rendering/CacheableBlockEntity.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,17 @@ | ||
package dev.dubhe.anvilcraft.api.rendering; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.neoforged.api.distmarker.Dist; | ||
import net.neoforged.api.distmarker.OnlyIn; | ||
|
||
public abstract class CacheableBlockEntity extends BlockEntity { | ||
public CacheableBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState blockState) { | ||
super(type, pos, blockState); | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public abstract CacheableBlockEntityRenderer<? extends CacheableBlockEntity> getRenderer(); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/dev/dubhe/anvilcraft/api/rendering/CacheableBlockEntityRenderer.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,14 @@ | ||
package dev.dubhe.anvilcraft.api.rendering; | ||
|
||
import com.mojang.blaze3d.vertex.BufferBuilder; | ||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import net.minecraft.client.renderer.RenderType; | ||
|
||
public interface CacheableBlockEntityRenderer<T extends CacheableBlockEntity> { | ||
void compileRenderType( | ||
T cacheableBlockEntity, | ||
RenderType renderType, | ||
BufferBuilder bufferBuilder, | ||
PoseStack poseStack | ||
); | ||
} |
Oops, something went wrong.