package net.coderbot.iris.pipeline; import lombok.Getter; import net.coderbot.iris.gl.program.ProgramImages; import net.coderbot.iris.gl.program.ProgramSamplers; import net.coderbot.iris.gl.program.ProgramUniforms; import net.coderbot.iris.pipeline.transform.PatchShaderType; import net.coderbot.iris.shaderpack.ProgramSet; import net.coderbot.iris.uniforms.CommonUniforms; import net.coderbot.iris.uniforms.ExternallyManagedUniforms; import net.coderbot.iris.uniforms.builtin.BuiltinReplacementUniforms; import net.coderbot.iris.uniforms.custom.CustomUniforms; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.function.IntFunction; import net.coderbot.iris.Iris; public class SodiumTerrainPipeline { Optional terrainVertex = Optional.empty(); Optional terrainGeometry = Optional.empty(); Optional terrainFragment = Optional.empty(); Optional translucentVertex = Optional.empty(); Optional translucentGeometry = Optional.empty(); Optional translucentFragment = Optional.empty(); Optional shadowVertex = Optional.empty(); Optional shadowGeometry = Optional.empty(); Optional shadowFragment = Optional.empty(); //GlFramebuffer framebuffer; ProgramSet programSet; @Getter private final CustomUniforms customUniforms; private final WorldRenderingPipeline parent; private final IntFunction createTerrainSamplers; private final IntFunction createShadowSamplers; private final IntFunction createTerrainImages; private final IntFunction createShadowImages; public SodiumTerrainPipeline(WorldRenderingPipeline parent, ProgramSet programSet, IntFunction createTerrainSamplers, IntFunction createShadowSamplers, IntFunction createTerrainImages, IntFunction createShadowImages, CustomUniforms customUniforms, String terrainSourceName, String translucentSourceName, String shadowSourceName, CompletableFuture> terrainFuture, CompletableFuture> translucentFuture, CompletableFuture> shadowFuture) { this.parent = Objects.requireNonNull(parent); this.programSet = programSet; this.customUniforms = customUniforms; if (terrainFuture != null) { try { Map result = terrainFuture.join(); terrainVertex = Optional.ofNullable(result.get(PatchShaderType.VERTEX)); terrainGeometry = Optional.ofNullable(result.get(PatchShaderType.GEOMETRY)); terrainFragment = Optional.ofNullable(result.get(PatchShaderType.FRAGMENT)); PatchedShaderPrinter.debugPatchedShaders(terrainSourceName + "_sodium", terrainVertex.orElse(null), terrainGeometry.orElse(null), terrainFragment.orElse(null)); } catch (Exception e) { Iris.logger.error("Failed to transform terrain shader: {}", terrainSourceName, e); throw new RuntimeException("Shader transformation failed for " + terrainSourceName, e); } } if (translucentFuture != null) { try { Map result = translucentFuture.join(); translucentVertex = Optional.ofNullable(result.get(PatchShaderType.VERTEX)); translucentGeometry = Optional.ofNullable(result.get(PatchShaderType.GEOMETRY)); translucentFragment = Optional.ofNullable(result.get(PatchShaderType.FRAGMENT)); PatchedShaderPrinter.debugPatchedShaders(translucentSourceName + "_sodium", translucentVertex.orElse(null), translucentGeometry.orElse(null), translucentFragment.orElse(null)); } catch (Exception e) { Iris.logger.error("Failed to transform translucent shader: {}", translucentSourceName, e); throw new RuntimeException("Shader transformation failed for " + translucentSourceName, e); } } if (shadowFuture != null) { try { Map result = shadowFuture.join(); shadowVertex = Optional.ofNullable(result.get(PatchShaderType.VERTEX)); shadowGeometry = Optional.ofNullable(result.get(PatchShaderType.GEOMETRY)); shadowFragment = Optional.ofNullable(result.get(PatchShaderType.FRAGMENT)); PatchedShaderPrinter.debugPatchedShaders(shadowSourceName + "_sodium", shadowVertex.orElse(null), shadowGeometry.orElse(null), shadowFragment.orElse(null)); } catch (Exception e) { Iris.logger.error("Failed to transform shadow shader: {}", shadowSourceName, e); throw new RuntimeException("Shader transformation failed for " + shadowSourceName, e); } } this.createTerrainSamplers = createTerrainSamplers; this.createShadowSamplers = createShadowSamplers; this.createTerrainImages = createTerrainImages; this.createShadowImages = createShadowImages; } public Optional getTerrainVertexShaderSource() { return terrainVertex; } public Optional getTerrainGeometryShaderSource() { return terrainGeometry; } public Optional getTerrainFragmentShaderSource() { return terrainFragment; } public Optional getTranslucentVertexShaderSource() { return translucentVertex; } public Optional getTranslucentGeometryShaderSource() { return translucentGeometry; } public Optional getTranslucentFragmentShaderSource() { return translucentFragment; } public Optional getShadowVertexShaderSource() { return shadowVertex; } public Optional getShadowGeometryShaderSource() { return shadowGeometry; } public Optional getShadowFragmentShaderSource() { return shadowFragment; } public ProgramUniforms.Builder initUniforms(int programId) { ProgramUniforms.Builder uniforms = ProgramUniforms.builder("", programId); CommonUniforms.addDynamicUniforms(uniforms); customUniforms.assignTo(uniforms); ExternallyManagedUniforms.addExternallyManagedUniforms116(uniforms); BuiltinReplacementUniforms.addBuiltinReplacementUniforms(uniforms); return uniforms; } public boolean hasShadowPass() { return createShadowSamplers != null; } public ProgramSamplers initTerrainSamplers(int programId) { return createTerrainSamplers.apply(programId); } public ProgramSamplers initShadowSamplers(int programId) { return createShadowSamplers.apply(programId); } public ProgramImages initTerrainImages(int programId) { return createTerrainImages.apply(programId); } public ProgramImages initShadowImages(int programId) { return createShadowImages.apply(programId); } /*public void bindFramebuffer() { this.framebuffer.bind(); } public void unbindFramebuffer() { GlStateManager.bindFramebuffer(GL30.GL_FRAMEBUFFER, 0); }*/ }