Skip to content

Commit 0b96b77

Browse files
committed
beryl compatibility
1 parent 7fa1fa7 commit 0b96b77

4 files changed

Lines changed: 26 additions & 23 deletions

File tree

src/main/java/net/vulkanmod/mixin/render/clouds/LevelRendererM.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public abstract class LevelRendererM {
2222
@Shadow private @Nullable ClientLevel level;
2323
@Shadow @Final private LevelTargetBundle targets;
2424

25-
@Unique private CloudRenderer cloudRenderer;
25+
@Unique private CloudRenderer vmCloudRenderer;
2626

2727
@Inject(method = "addCloudsPass", at = @At("HEAD"), cancellable = true)
2828
public void addCloudsPass(FrameGraphBuilder frameGraphBuilder, CloudStatus cloudStatus, Vec3 camPos, float partialTicks, int i, float g, CallbackInfo ci) {
29-
if (this.cloudRenderer == null) {
30-
this.cloudRenderer = new CloudRenderer();
29+
if (this.vmCloudRenderer == null) {
30+
this.vmCloudRenderer = new CloudRenderer();
3131
}
3232

3333
FramePass framePass = frameGraphBuilder.addPass("clouds");
@@ -41,8 +41,8 @@ public void addCloudsPass(FrameGraphBuilder frameGraphBuilder, CloudStatus cloud
4141
Profiler profiler = Profiler.getMainProfiler();
4242
profiler.push("Clouds");
4343

44-
this.cloudRenderer.renderClouds(this.level, this.ticks, partialTicks,
45-
camPos.x(), camPos.y(), camPos.z());
44+
this.vmCloudRenderer.renderClouds(this.level, this.ticks, partialTicks,
45+
camPos.x(), camPos.y(), camPos.z());
4646

4747
profiler.pop();
4848
});
@@ -52,15 +52,15 @@ public void addCloudsPass(FrameGraphBuilder frameGraphBuilder, CloudStatus cloud
5252

5353
@Inject(method = "allChanged", at = @At("RETURN"))
5454
private void onAllChanged(CallbackInfo ci) {
55-
if (this.cloudRenderer != null) {
56-
this.cloudRenderer.resetBuffer();
55+
if (this.vmCloudRenderer != null) {
56+
this.vmCloudRenderer.resetBuffer();
5757
}
5858
}
5959

6060
@Inject(method = "onResourceManagerReload", at = @At("RETURN"))
6161
private void onReload(ResourceManager resourceManager, CallbackInfo ci) {
62-
if (this.cloudRenderer != null) {
63-
this.cloudRenderer.loadTexture();
62+
if (this.vmCloudRenderer != null) {
63+
this.vmCloudRenderer.loadTexture();
6464
}
6565
}
6666

src/main/java/net/vulkanmod/render/PipelineManager.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
public abstract class PipelineManager {
1717
public static VertexFormat terrainVertexFormat;
1818

19-
public static void setTerrainVertexFormat(VertexFormat format) {
20-
terrainVertexFormat = format;
21-
}
22-
2319
static GraphicsPipeline
2420
terrainShader, terrainShaderEarlyZ,
2521
fastBlitPipeline, cloudsPipeline;
@@ -29,18 +25,18 @@ public static void setTerrainVertexFormat(VertexFormat format) {
2925
public static void init() {
3026
setTerrainVertexFormat(CustomVertexFormat.COMPRESSED_TERRAIN);
3127
createBasicPipelines();
32-
setDefaultShader();
28+
setDefaultTerrainShaderGetter();
3329
ThreadBuilderPack.defaultTerrainBuilderConstructor();
3430
}
3531

36-
public static void setDefaultShader() {
32+
public static void setDefaultTerrainShaderGetter() {
3733
setShaderGetter(
3834
renderType -> renderType == TerrainRenderType.TRANSLUCENT ? terrainShaderEarlyZ : terrainShader);
3935
}
4036

4137
private static void createBasicPipelines() {
42-
terrainShaderEarlyZ = createPipeline("terrain_earlyZ", terrainVertexFormat);
43-
terrainShader = createPipeline("terrain", terrainVertexFormat);
38+
terrainShaderEarlyZ = createPipeline("terrain_earlyZ", CustomVertexFormat.COMPRESSED_TERRAIN);
39+
terrainShader = createPipeline("terrain", CustomVertexFormat.COMPRESSED_TERRAIN);
4440
fastBlitPipeline = createPipeline("blit", CustomVertexFormat.NONE);
4541
cloudsPipeline = createPipeline("clouds", DefaultVertexFormat.POSITION_COLOR);
4642
}
@@ -71,6 +67,14 @@ public static void setShaderGetter(Function<TerrainRenderType, GraphicsPipeline>
7167
shaderGetter = consumer;
7268
}
7369

70+
public static void setTerrainVertexFormat(VertexFormat format) {
71+
terrainVertexFormat = format;
72+
}
73+
74+
public static VertexFormat getTerrainVertexFormat() {
75+
return terrainVertexFormat;
76+
}
77+
7478
public static GraphicsPipeline getTerrainDirectShader(RenderType renderType) {
7579
return terrainShader;
7680
}

src/main/java/net/vulkanmod/render/chunk/RenderSection.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.google.common.collect.Sets;
44
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
5-
import net.minecraft.client.Minecraft;
65
import net.minecraft.world.level.Level;
76
import net.minecraft.world.level.block.entity.BlockEntity;
87
import net.vulkanmod.render.chunk.buffer.AreaBuffer;
@@ -298,7 +297,7 @@ public void resetDrawParameters(TerrainRenderType renderType) {
298297
AreaBuffer areaBuffer = drawBuffers.getAreaBuffer(renderType);
299298
int vertexOffset = DrawParametersBuffer.getVertexOffset(ptr);
300299
if (areaBuffer != null && vertexOffset != -1) {
301-
int segmentOffset = vertexOffset * DrawBuffers.VERTEX_SIZE;
300+
int segmentOffset = vertexOffset * drawBuffers.vertexSize;
302301
areaBuffer.setSegmentFree(segmentOffset);
303302
}
304303

src/main/java/net/vulkanmod/render/chunk/buffer/DrawBuffers.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import static org.lwjgl.vulkan.VK10.*;
2525

2626
public class DrawBuffers {
27-
public static final int VERTEX_SIZE = PipelineManager.terrainVertexFormat.getVertexSize();
2827
public static final int INDEX_SIZE = Short.BYTES;
2928
public static final int UNDEFINED_FACING_IDX = QuadFacing.UNDEFINED.ordinal();
3029
public static final float POS_OFFSET = CustomVertexFormat.getPositionOffset();
@@ -34,6 +33,7 @@ public class DrawBuffers {
3433
private static final long cmdBufferPtr = MemoryUtil.nmemAlignedAlloc(CMD_STRIDE, (long) ChunkAreaManager.AREA_SIZE * QuadFacing.COUNT * CMD_STRIDE);
3534

3635
private final int index;
36+
public final int vertexSize = PipelineManager.getTerrainVertexFormat().getVertexSize();
3737
private final Vector3i origin;
3838
private final int minHeight;
3939

@@ -116,10 +116,10 @@ public void upload(RenderSection section, UploadBuffer buffer, TerrainRenderType
116116

117117
if (vertexBuffer != null && doUpload) {
118118
areaBuffer.upload(segment, vertexBuffer, offset);
119-
vertexOffset = (segment.offset + offset) / VERTEX_SIZE;
119+
vertexOffset = (segment.offset + offset) / vertexSize;
120120

121121
offset += vertexBuffer.remaining();
122-
vertexCount = vertexBuffer.limit() / VERTEX_SIZE;
122+
vertexCount = vertexBuffer.limit() / vertexSize;
123123
indexCount = vertexCount * 6 / 4;
124124
}
125125

@@ -154,7 +154,7 @@ private AreaBuffer getAreaBufferOrAlloc(TerrainRenderType renderType) {
154154
};
155155

156156
return this.vertexBuffers.computeIfAbsent(
157-
renderType, renderType1 -> new AreaBuffer(AreaBuffer.Usage.VERTEX, initialSize, VERTEX_SIZE));
157+
renderType, renderType1 -> new AreaBuffer(AreaBuffer.Usage.VERTEX, initialSize, vertexSize));
158158
}
159159

160160
public AreaBuffer getAreaBuffer(TerrainRenderType r) {

0 commit comments

Comments
 (0)