Skip to content

Commit

Permalink
Fix GL errors due to disposed textures still being bound after render…
Browse files Browse the repository at this point in the history
…ing multiple projectors at once.
  • Loading branch information
fnuecke committed Feb 7, 2022
1 parent 9a8b278 commit 3056d55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main/java/li/cil/oc2/client/renderer/ModShaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static ShaderInstance getProjectorsShader() {
return projectorsShader;
}

@SuppressWarnings("ConstantConditions") // Setting samples to null to clear them is fine.
public static void configureProjectorsShader(
final RenderTarget target,
final Matrix4f inverseCameraMatrix,
Expand All @@ -51,10 +52,15 @@ public static void configureProjectorsShader(
projectorsShader.setSampler("MainCameraDepth", target.getDepthTextureId());
projectorsShader.safeGetUniform("InverseMainCamera").set(inverseCameraMatrix);

for (int i = 0; i < projectorCount; i++) {
projectorsShader.setSampler(PROJECTOR_COLOR_NAMES[i], colors[i].getId());
projectorsShader.setSampler(PROJECTOR_DEPTH_NAMES[i], depths[i].getDepthTextureId());
projectorsShader.safeGetUniform(PROJECTOR_CAMERA_NAMES[i]).set(projectorCameraMatrices[i]);
for (int i = 0; i < MAX_PROJECTORS; i++) {
if (i < projectorCount) {
projectorsShader.setSampler(PROJECTOR_COLOR_NAMES[i], colors[i].getId());
projectorsShader.setSampler(PROJECTOR_DEPTH_NAMES[i], depths[i].getDepthTextureId());
projectorsShader.safeGetUniform(PROJECTOR_CAMERA_NAMES[i]).set(projectorCameraMatrices[i]);
} else {
projectorsShader.setSampler(PROJECTOR_COLOR_NAMES[i], null);
projectorsShader.setSampler(PROJECTOR_DEPTH_NAMES[i], null);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;

Expand Down Expand Up @@ -181,6 +182,7 @@ public static void handleRenderLevelLast(final RenderLevelLastEvent event) {
renderProjectorColors(minecraft, event.getPoseStack().last().pose(), event.getProjectionMatrix(), projectorCount);
} finally {
VISIBLE_PROJECTORS.clear();
Arrays.fill(PROJECTOR_COLOR_TARGETS, null);
}
}

Expand Down

0 comments on commit 3056d55

Please sign in to comment.