remove the FogService SPI #43

Merged
embeddedt merged 3 commits from rdh/celeritas:spi-begone into stonecutter 2026-09-25 14:51:41 -04:00
7 changed files with 27 additions and 23 deletions
Showing only changes of commit 80a1daaa65 - Show all commits

No files matched your search

@@ -35,11 +35,11 @@ public abstract class ShaderChunkRenderer implements ChunkRenderer {
protected final boolean enableLegacyGLPatches; protected final boolean enableLegacyGLPatches;
protected final FogService fogService; protected final ChunkShaderEnvironment environment;
public ShaderChunkRenderer(RenderDevice device, RenderPassConfiguration<?> renderPassConfiguration, FogService fogService) { public ShaderChunkRenderer(RenderDevice device, RenderPassConfiguration<?> renderPassConfiguration, FogService fogService) {
this.device = device; this.device = device;
this.fogService = fogService; this.environment = new ChunkShaderEnvironment(fogService);
this.renderPassConfiguration = renderPassConfiguration; this.renderPassConfiguration = renderPassConfiguration;
this.enableLegacyGLPatches = !LWJGL.isOpenGLVersionSupported(3, 2); this.enableLegacyGLPatches = !LWJGL.isOpenGLVersionSupported(3, 2);
if (this.enableLegacyGLPatches) { if (this.enableLegacyGLPatches) {
@@ -112,7 +112,7 @@ public abstract class ShaderChunkRenderer implements ChunkRenderer {
if (!this.enableLegacyGLPatches) { if (!this.enableLegacyGLPatches) {
builder.bindFragmentData("fragColor", ChunkShaderBindingPoints.FRAG_COLOR); builder.bindFragmentData("fragColor", ChunkShaderBindingPoints.FRAG_COLOR);
} }
return builder.link((shader) -> new DefaultChunkShaderInterface(shader, options, this.fogService)); return builder.link((shader) -> new DefaultChunkShaderInterface(shader, options, this.environment));
} finally { } finally {
loadedShaders.forEach(GlShader::delete); loadedShaders.forEach(GlShader::delete);
} }
@@ -120,7 +120,7 @@ public abstract class ShaderChunkRenderer implements ChunkRenderer {
protected List<ChunkShaderComponent.Factory<?>> getShaderComponents() { protected List<ChunkShaderComponent.Factory<?>> getShaderComponents() {
var componentFactories = new ArrayList<ChunkShaderComponent.Factory<?>>(4); var componentFactories = new ArrayList<ChunkShaderComponent.Factory<?>>(4);
componentFactories.add(this.fogService.getFogMode()); componentFactories.add(this.environment.fogService().getFogMode());
return componentFactories; return componentFactories;
} }
@@ -4,7 +4,6 @@ import org.taumc.celeritas.lwjgl.GL20;
import static org.taumc.celeritas.lwjgl.LWJGLServiceProvider.LWJGL; import static org.taumc.celeritas.lwjgl.LWJGLServiceProvider.LWJGL;
import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext; import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext;
import org.embeddedt.embeddium.impl.render.chunk.fog.FogService;
import java.util.List; import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@@ -15,17 +14,17 @@ public enum ChunkFogMode implements ChunkShaderComponent.Factory<ChunkShaderFogC
EXP2(ChunkShaderFogComponent.Exp2::new, List.of("USE_FOG", "USE_FOG_EXP2")), EXP2(ChunkShaderFogComponent.Exp2::new, List.of("USE_FOG", "USE_FOG_EXP2")),
SMOOTH(ChunkShaderFogComponent.Smooth::new, List.of("USE_FOG", "USE_FOG_SMOOTH")); SMOOTH(ChunkShaderFogComponent.Smooth::new, List.of("USE_FOG", "USE_FOG_SMOOTH"));
private final BiFunction<ShaderBindingContext, FogService, ChunkShaderFogComponent> factory; private final BiFunction<ShaderBindingContext, ChunkShaderEnvironment, ChunkShaderFogComponent> factory;
private final List<String> defines; private final List<String> defines;
ChunkFogMode(BiFunction<ShaderBindingContext, FogService, ChunkShaderFogComponent> factory, List<String> defines) { ChunkFogMode(BiFunction<ShaderBindingContext, ChunkShaderEnvironment, ChunkShaderFogComponent> factory, List<String> defines) {
this.factory = factory; this.factory = factory;
this.defines = defines; this.defines = defines;
} }
@Override @Override
public ChunkShaderFogComponent create(ShaderBindingContext context, FogService fogService) { public ChunkShaderFogComponent create(ShaderBindingContext context, ChunkShaderEnvironment environment) {
return factory.apply(context, fogService); return factory.apply(context, environment);
} }
public List<String> getDefines() { public List<String> getDefines() {
@@ -1,7 +1,6 @@
package org.embeddedt.embeddium.impl.render.chunk.shader; package org.embeddedt.embeddium.impl.render.chunk.shader;
import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext; import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext;
import org.embeddedt.embeddium.impl.render.chunk.fog.FogService;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -10,7 +9,7 @@ public interface ChunkShaderComponent {
void setup(); void setup();
interface Factory<T extends ChunkShaderComponent> { interface Factory<T extends ChunkShaderComponent> {
T create(ShaderBindingContext context, FogService fogService); T create(ShaderBindingContext context, ChunkShaderEnvironment environment);
default Collection<String> getDefines() { default Collection<String> getDefines() {
return List.of(); return List.of();
@@ -0,0 +1,6 @@
package org.embeddedt.embeddium.impl.render.chunk.shader;
import org.embeddedt.embeddium.impl.render.chunk.fog.FogService;
public record ChunkShaderEnvironment(FogService fogService) {
}
@@ -24,8 +24,8 @@ public abstract class ChunkShaderFogComponent implements ChunkShaderComponent {
} }
public static class None extends ChunkShaderFogComponent { public static class None extends ChunkShaderFogComponent {
public None(ShaderBindingContext context, FogService fogService) { public None(ShaderBindingContext context, ChunkShaderEnvironment environment) {
super(fogService); super(environment.fogService());
} }
@Override @Override
@@ -38,8 +38,8 @@ public abstract class ChunkShaderFogComponent implements ChunkShaderComponent {
private final GlUniformFloat4v uFogColor; private final GlUniformFloat4v uFogColor;
private final GlUniformFloat uFogDensity; private final GlUniformFloat uFogDensity;
public Exp(ShaderBindingContext context, FogService fogService) { public Exp(ShaderBindingContext context, ChunkShaderEnvironment environment) {
super(fogService); super(environment.fogService());
this.uFogColor = context.bindUniform("u_FogColor", GlUniformFloat4v::new); this.uFogColor = context.bindUniform("u_FogColor", GlUniformFloat4v::new);
this.uFogDensity = context.bindUniform("u_FogDensity", GlUniformFloat::new); this.uFogDensity = context.bindUniform("u_FogDensity", GlUniformFloat::new);
@@ -56,8 +56,8 @@ public abstract class ChunkShaderFogComponent implements ChunkShaderComponent {
private final GlUniformFloat4v uFogColor; private final GlUniformFloat4v uFogColor;
private final GlUniformFloat uFogDensity; private final GlUniformFloat uFogDensity;
public Exp2(ShaderBindingContext context, FogService fogService) { public Exp2(ShaderBindingContext context, ChunkShaderEnvironment environment) {
super(fogService); super(environment.fogService());
this.uFogColor = context.bindUniform("u_FogColor", GlUniformFloat4v::new); this.uFogColor = context.bindUniform("u_FogColor", GlUniformFloat4v::new);
this.uFogDensity = context.bindUniform("u_FogDensity", GlUniformFloat::new); this.uFogDensity = context.bindUniform("u_FogDensity", GlUniformFloat::new);
@@ -77,8 +77,8 @@ public abstract class ChunkShaderFogComponent implements ChunkShaderComponent {
private final GlUniformFloat uFogStart; private final GlUniformFloat uFogStart;
private final GlUniformFloat uFogEnd; private final GlUniformFloat uFogEnd;
public Smooth(ShaderBindingContext context, FogService fogService) { public Smooth(ShaderBindingContext context, ChunkShaderEnvironment environment) {
super(fogService); super(environment.fogService());
this.uFogColor = context.bindUniform("u_FogColor", GlUniformFloat4v::new); this.uFogColor = context.bindUniform("u_FogColor", GlUniformFloat4v::new);
this.uFogShape = context.bindUniform("u_FogShape", GlUniformInt::new); this.uFogShape = context.bindUniform("u_FogShape", GlUniformInt::new);
@@ -7,7 +7,6 @@ import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformInt;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix4f; import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix4f;
import org.embeddedt.embeddium.impl.gl.tessellation.GlPrimitiveType; import org.embeddedt.embeddium.impl.gl.tessellation.GlPrimitiveType;
import org.embeddedt.embeddium.impl.render.chunk.compile.sorting.QuadPrimitiveType; import org.embeddedt.embeddium.impl.render.chunk.compile.sorting.QuadPrimitiveType;
import org.embeddedt.embeddium.impl.render.chunk.fog.FogService;
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass; import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
import org.joml.Matrix4fc; import org.joml.Matrix4fc;
import org.taumc.celeritas.lwjgl.MemoryStack; import org.taumc.celeritas.lwjgl.MemoryStack;
@@ -37,7 +36,7 @@ public class DefaultChunkShaderInterface implements ChunkShaderInterface {
private GlPrimitiveType primitiveType; private GlPrimitiveType primitiveType;
public DefaultChunkShaderInterface(ShaderBindingContext context, ChunkShaderOptions options, FogService fogService) { public DefaultChunkShaderInterface(ShaderBindingContext context, ChunkShaderOptions options, ChunkShaderEnvironment environment) {
this.uniformModelViewMatrix = context.bindUniform("u_ModelViewMatrix", GlUniformMatrix4f::new); this.uniformModelViewMatrix = context.bindUniform("u_ModelViewMatrix", GlUniformMatrix4f::new);
this.uniformProjectionMatrix = context.bindUniform("u_ProjectionMatrix", GlUniformMatrix4f::new); this.uniformProjectionMatrix = context.bindUniform("u_ProjectionMatrix", GlUniformMatrix4f::new);
this.uniformRegionOffset = context.bindUniform("u_RegionOffset", GlUniformFloat3v::new); this.uniformRegionOffset = context.bindUniform("u_RegionOffset", GlUniformFloat3v::new);
@@ -49,7 +48,7 @@ public class DefaultChunkShaderInterface implements ChunkShaderInterface {
this.uniformTextures.put(ChunkShaderTextureSlot.LIGHT, context.bindUniform("u_LightTex", GlUniformInt::new)); this.uniformTextures.put(ChunkShaderTextureSlot.LIGHT, context.bindUniform("u_LightTex", GlUniformInt::new));
} }
this.components = options.components().stream().map(c -> c.create(context, fogService)).toList(); this.components = options.components().stream().map(c -> c.create(context, environment)).toList();
} }
@Deprecated // the shader interface should not modify pipeline state @Deprecated // the shader interface should not modify pipeline state
@@ -7,6 +7,7 @@ import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat4v; import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat4v;
import org.embeddedt.embeddium.impl.render.chunk.fog.FogService; import org.embeddedt.embeddium.impl.render.chunk.fog.FogService;
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderComponent; import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderComponent;
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderEnvironment;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -57,7 +58,7 @@ public class FogHelper implements FogService {
private static class PostmodernFogComponent implements ChunkShaderComponent { private static class PostmodernFogComponent implements ChunkShaderComponent {
private static final ChunkShaderComponent.Factory<PostmodernFogComponent> FACTORY = new ChunkShaderComponent.Factory<>() { private static final ChunkShaderComponent.Factory<PostmodernFogComponent> FACTORY = new ChunkShaderComponent.Factory<>() {
@Override @Override
public PostmodernFogComponent create(ShaderBindingContext context, FogService fogService) { public PostmodernFogComponent create(ShaderBindingContext context, ChunkShaderEnvironment environment) {
return new PostmodernFogComponent(context); return new PostmodernFogComponent(context);
} }