Skip to content

Commit

Permalink
refactor: Add the WorldRenderingPipeline interface, which ShaderPipel…
Browse files Browse the repository at this point in the history
…ine now implements
  • Loading branch information
coderbot16 committed Mar 7, 2021
1 parent 4f0c73f commit c138727
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
10 changes: 6 additions & 4 deletions src/main/java/net/coderbot/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.mojang.blaze3d.platform.GlStateManager;
import net.coderbot.iris.config.IrisConfig;
import net.coderbot.iris.pipeline.ShaderPipeline;
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
import net.coderbot.iris.shaderpack.DimensionId;
import net.coderbot.iris.shaderpack.ShaderPack;
import net.minecraft.client.world.ClientWorld;
Expand Down Expand Up @@ -44,7 +45,7 @@ public class Iris implements ClientModInitializer {
private static ShaderPack currentPack;
private static String currentPackName;

private static ShaderPipeline pipeline;
private static WorldRenderingPipeline pipeline;
private static IrisConfig irisConfig;
private static FileSystem zipFileSystem;
private static KeyBinding reloadKeybind;
Expand Down Expand Up @@ -280,8 +281,9 @@ private static void destroyPipeline() {
// Destroy the old world rendering pipeline
//
// This destroys all loaded shader programs and all of the render targets.
if (pipeline != null) {
pipeline.destroy();
if (pipeline instanceof ShaderPipeline) {
// TODO: Don't cast this to ShaderPipeline?
((ShaderPipeline) pipeline).destroy();
pipeline = null;
}
}
Expand Down Expand Up @@ -321,7 +323,7 @@ public static void checkDimension() {
}
}

public static ShaderPipeline getPipeline() {
public static WorldRenderingPipeline getPipeline() {
if (pipeline == null) {
pipeline = new ShaderPipeline(Objects.requireNonNull(currentPack).getProgramSet(lastDimension));
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/coderbot/iris/mixin/MixinWorldRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class MixinWorldRenderer {
CapturedRenderingState.INSTANCE.setGbufferModelView(matrices.peek().getModel());
CapturedRenderingState.INSTANCE.setTickDelta(tickDelta);
Iris.checkDimension();
Iris.getPipeline().beginWorldRender();
Iris.getPipeline().beginWorldRendering();
}

// Inject a bit early so that we can end our rendering in time.
Expand Down Expand Up @@ -160,7 +160,7 @@ public class MixinWorldRenderer {
}*/

@Inject(method = RENDER, at = @At(value = "CONSTANT", args = "stringValue=translucent"))
private void iris$copyCurrentDepthTexture(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo callback) {
Iris.getPipeline().copyCurrentDepthTexture();
private void iris$beginTranslucents(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo callback) {
Iris.getPipeline().beginTranslucents();
}
}
15 changes: 11 additions & 4 deletions src/main/java/net/coderbot/iris/pipeline/ShaderPipeline.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.coderbot.iris.pipeline;

import java.io.IOException;
import java.util.*;

import com.mojang.blaze3d.platform.GlStateManager;
Expand Down Expand Up @@ -33,7 +32,7 @@
/**
* Encapsulates the compiled shader program objects for the currently loaded shaderpack.
*/
public class ShaderPipeline {
public class ShaderPipeline implements WorldRenderingPipeline {
private final RenderTargets renderTargets;
@Nullable
private final Pass basic;
Expand Down Expand Up @@ -122,6 +121,7 @@ private void checkWorld() {
}
}

@Override
public void pushProgram(GbufferProgram program) {
checkWorld();

Expand All @@ -135,6 +135,7 @@ public void pushProgram(GbufferProgram program) {
programStackLog.add("push:" + program);
}

@Override
public void popProgram(GbufferProgram expected) {
checkWorld();

Expand Down Expand Up @@ -267,6 +268,7 @@ private void teardownProgram() {
this.baseline.bind();
}

@Override
public boolean shouldDisableVanillaEntityShadows() {
// TODO: Don't hardcode this for Sildur's
// OptiFine seems to disable vanilla shadows when the shaderpack uses shadow mapping?
Expand Down Expand Up @@ -435,7 +437,10 @@ private void prepareRenderTargets() {
RenderSystem.clear(GL11C.GL_COLOR_BUFFER_BIT, MinecraftClient.IS_SYSTEM_MAC);
}

public void copyCurrentDepthTexture() {
@Override
public void beginTranslucents() {
// We need to copy the current depth texture so that depthtex1 and depthtex2 can contain the depth values for
// all non-translucent content, as required.
baseline.bind();
GlStateManager.bindTexture(renderTargets.getDepthTextureNoTranslucents().getTextureId());
GL20C.glCopyTexImage2D(GL20C.GL_TEXTURE_2D, 0, GL20C.GL_DEPTH_COMPONENT, 0, 0, renderTargets.getCurrentWidth(), renderTargets.getCurrentHeight(), 0);
Expand All @@ -459,7 +464,8 @@ public static GbufferProgram getProgramForSheet(ParticleTextureSheet sheet) {
// TODO: better way to avoid this global state?
private boolean isRenderingWorld = false;

public void beginWorldRender() {
@Override
public void beginWorldRendering() {
isRenderingWorld = true;

checkWorld();
Expand All @@ -481,6 +487,7 @@ public void beginWorldRender() {
pushProgram(GbufferProgram.BASIC);
}

@Override
public void finalizeWorldRendering() {
checkWorld();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.coderbot.iris.pipeline;

import net.coderbot.iris.layer.GbufferProgram;

public interface WorldRenderingPipeline {
void beginWorldRendering();
void beginTranslucents();
void pushProgram(GbufferProgram program);
void popProgram(GbufferProgram program);
void finalizeWorldRendering();

boolean shouldDisableVanillaEntityShadows();
}

0 comments on commit c138727

Please sign in to comment.