diff --git a/gradle.properties b/gradle.properties index 28ca8d50f..14777e0ec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,8 +5,8 @@ org.gradle.daemon = false mod_version = 0.3.0 mc_update_version = 1.17 minecraft_version = 1.17.1 -loader_version = 0.12.5 -fabric_version = 0.43.0+1.17 +loader_version = 0.12.8 +fabric_version = 0.44.0+1.17 # build dependency versions loom_version = 0.10-SNAPSHOT diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index fe4dc0322..85f332c16 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -178,7 +178,7 @@ public class Backend { * INTERNAL USE ONLY */ public void _clearContexts() { - SpecMetaRegistry.clear(); + GameStateRegistry.clear(); programSpecRegistry.clear(); contexts.forEach(IShaderContext::delete); contexts.clear(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/SpecMetaRegistry.java b/src/main/java/com/jozufozu/flywheel/backend/GameStateRegistry.java similarity index 54% rename from src/main/java/com/jozufozu/flywheel/backend/SpecMetaRegistry.java rename to src/main/java/com/jozufozu/flywheel/backend/GameStateRegistry.java index 14717f9f7..d7e6af08c 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/SpecMetaRegistry.java +++ b/src/main/java/com/jozufozu/flywheel/backend/GameStateRegistry.java @@ -3,18 +3,15 @@ package com.jozufozu.flywheel.backend; import java.util.HashMap; import java.util.Map; -import com.jozufozu.flywheel.core.shader.extension.IProgramExtension; import com.jozufozu.flywheel.core.shader.gamestate.IGameStateProvider; import net.minecraft.resources.ResourceLocation; -public class SpecMetaRegistry { +public class GameStateRegistry { - private static final Map registeredExtensions = new HashMap<>(); private static final Map registeredStateProviders = new HashMap<>(); static void clear() { - registeredExtensions.clear(); registeredStateProviders.clear(); } @@ -28,16 +25,6 @@ public class SpecMetaRegistry { return out; } - public static IProgramExtension getExtension(ResourceLocation location) { - IProgramExtension out = registeredExtensions.get(location); - - if (out == null) { - throw new IllegalArgumentException("Extension '" + location + "' does not exist."); - } - - return out; - } - public static void register(IGameStateProvider context) { if (registeredStateProviders.containsKey(context.getID())) { throw new IllegalStateException("Duplicate game state provider: " + context.getID()); @@ -45,12 +32,4 @@ public class SpecMetaRegistry { registeredStateProviders.put(context.getID(), context); } - - public static void register(IProgramExtension extender) { - if (registeredStateProviders.containsKey(extender.getID())) { - throw new IllegalStateException("Duplicate shader extension: " + extender.getID()); - } - - registeredExtensions.put(extender.getID(), extender); - } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceData.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceData.java index 125ddbdeb..5379822de 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceData.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceData.java @@ -1,7 +1,5 @@ package com.jozufozu.flywheel.backend.instancing; -import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; - public abstract class InstanceData { Instancer owner; @@ -9,8 +7,6 @@ public abstract class InstanceData { boolean dirty; boolean removed; - public abstract void write(VecBuffer buf); - public void markDirty() { owner.markDirty(this); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/WorldShaderPipeline.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/WorldShaderPipeline.java index f26126c23..d961f0646 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/WorldShaderPipeline.java +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/WorldShaderPipeline.java @@ -43,7 +43,7 @@ public class WorldShaderPipeline

implements IShaderPipel GameStateProgram.Builder

builder = GameStateProgram.builder(compile(shader, null)); for (ProgramState variant : variants) { - builder.withVariant(variant.getContext(), compile(shader, variant)); + builder.withVariant(variant.context(), compile(shader, variant)); } return builder.build(); @@ -52,7 +52,7 @@ public class WorldShaderPipeline

implements IShaderPipel private P compile(WorldShader shader, @Nullable ProgramState variant) { if (variant != null) { - shader.setDefines(variant.getDefines()); + shader.setDefines(variant.defines()); } ProtoProgram program = shader.createProgram() @@ -61,10 +61,6 @@ public class WorldShaderPipeline

implements IShaderPipel .link() .deleteLinkedShaders(); - if (variant != null) { - return factory.create(shader.name, program.program, variant.getExtensions()); - } else { - return factory.create(shader.name, program.program, null); - } + return factory.create(shader.name, program.program); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/struct/BasicStructType.java b/src/main/java/com/jozufozu/flywheel/backend/struct/BasicStructType.java deleted file mode 100644 index eaa9eaa3d..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/struct/BasicStructType.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.jozufozu.flywheel.backend.struct; - -import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; -import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.util.NonNullSupplier; - -public class BasicStructType implements StructType { - - private final NonNullSupplier factory; - private final VertexFormat format; - - public BasicStructType(NonNullSupplier factory, VertexFormat format) { - this.factory = factory; - this.format = format; - } - - @Override - public S create() { - return factory.get(); - } - - @Override - public VertexFormat format() { - return format; - } - - @Override - public StructWriter getWriter(VecBuffer backing) { - return new BasicWriter(backing); - } - - public class BasicWriter implements StructWriter { - private final VecBuffer buffer; - - public BasicWriter(VecBuffer buffer) { - this.buffer = buffer; - } - - @Override - public void write(S struct) { - struct.write(buffer); - } - - @Override - public void seek(int pos) { - buffer.position(pos * format.getStride()); - } - } -} diff --git a/src/main/java/com/jozufozu/flywheel/core/Contexts.java b/src/main/java/com/jozufozu/flywheel/core/Contexts.java index a4115136a..1838e7777 100644 --- a/src/main/java/com/jozufozu/flywheel/core/Contexts.java +++ b/src/main/java/com/jozufozu/flywheel/core/Contexts.java @@ -2,7 +2,7 @@ package com.jozufozu.flywheel.core; import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.SpecMetaRegistry; +import com.jozufozu.flywheel.backend.GameStateRegistry; import com.jozufozu.flywheel.backend.pipeline.IShaderPipeline; import com.jozufozu.flywheel.backend.pipeline.InstancingTemplate; import com.jozufozu.flywheel.backend.pipeline.WorldShaderPipeline; @@ -24,7 +24,7 @@ public class Contexts { public static void flwInit(GatherContextEvent event) { Backend backend = event.getBackend(); - SpecMetaRegistry.register(NormalDebugStateProvider.INSTANCE); + GameStateRegistry.register(NormalDebugStateProvider.INSTANCE); FileResolution crumblingBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.CRUMBLING, ".glsl")); FileResolution worldBuiltins = Resolver.INSTANCE.findShader(ResourceUtil.subPath(Names.WORLD, ".glsl")); diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingProgram.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingProgram.java index 1da5ae75a..8669ccef1 100644 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingProgram.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingProgram.java @@ -2,11 +2,8 @@ package com.jozufozu.flywheel.core.crumbling; import static org.lwjgl.opengl.GL20.glUniform2f; -import java.util.List; - import com.jozufozu.flywheel.core.atlas.AtlasInfo; import com.jozufozu.flywheel.core.shader.WorldProgram; -import com.jozufozu.flywheel.core.shader.extension.IProgramExtension; import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -18,8 +15,8 @@ public class CrumblingProgram extends WorldProgram { protected final int uTextureScale; protected int uCrumbling; - public CrumblingProgram(ResourceLocation name, int handle, List extensions) { - super(name, handle, extensions); + public CrumblingProgram(ResourceLocation name, int handle) { + super(name, handle); uTextureScale = getUniformLocation("uTextureScale"); } diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/BasicData.java b/src/main/java/com/jozufozu/flywheel/core/materials/BasicData.java index 3434b5284..eed1208bd 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/BasicData.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/BasicData.java @@ -1,6 +1,5 @@ package com.jozufozu.flywheel.core.materials; -import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; import com.jozufozu.flywheel.backend.instancing.InstanceData; public abstract class BasicData extends InstanceData implements IFlatLight { @@ -65,8 +64,4 @@ public abstract class BasicData extends InstanceData implements IFlatLight, Rotate return this; } - @Override - public void write(VecBuffer buf) { - super.write(buf); - ((WriteSafe) (Object) model).write(buf); - ((WriteSafe) (Object) normal).write(buf); - } - @Override public ModelData multiply(Quaternion quaternion) { markDirty(); diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/oriented/OrientedData.java b/src/main/java/com/jozufozu/flywheel/core/materials/oriented/OrientedData.java index 850b426a3..d819870f2 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/oriented/OrientedData.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/oriented/OrientedData.java @@ -1,6 +1,5 @@ package com.jozufozu.flywheel.core.materials.oriented; -import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; import com.jozufozu.flywheel.core.materials.BasicData; import com.jozufozu.flywheel.util.vec.Vec3; import com.mojang.math.Quaternion; @@ -92,20 +91,5 @@ public class OrientedData extends BasicData { return this; } - @Override - public void write(VecBuffer buf) { - super.write(buf); - - buf.putFloat(posX); - buf.putFloat(posY); - buf.putFloat(posZ); - buf.putFloat(pivotX); - buf.putFloat(pivotY); - buf.putFloat(pivotZ); - buf.putFloat(qX); - buf.putFloat(qY); - buf.putFloat(qZ); - buf.putFloat(qW); - } } diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/ExtensibleGlProgram.java b/src/main/java/com/jozufozu/flywheel/core/shader/ExtensibleGlProgram.java index c3e9fda79..ac64b9aab 100644 --- a/src/main/java/com/jozufozu/flywheel/core/shader/ExtensibleGlProgram.java +++ b/src/main/java/com/jozufozu/flywheel/core/shader/ExtensibleGlProgram.java @@ -1,15 +1,12 @@ package com.jozufozu.flywheel.core.shader; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.core.shader.extension.IExtensionInstance; -import com.jozufozu.flywheel.core.shader.extension.IProgramExtension; import net.minecraft.resources.ResourceLocation; @@ -24,22 +21,10 @@ import net.minecraft.resources.ResourceLocation; */ public class ExtensibleGlProgram extends GlProgram { - protected final List extensions; + protected final List extensions = new ArrayList<>(); - public ExtensibleGlProgram(ResourceLocation name, int handle, @Nullable List extensions) { + public ExtensibleGlProgram(ResourceLocation name, int handle) { super(name, handle); - - if (extensions != null) { - List list = new ArrayList<>(); - list.add(new FogMode(this)); // TODO: temporary fog fix - for (IProgramExtension e : extensions) { - IExtensionInstance extension = e.create(this); - list.add(extension); - } - this.extensions = list; - } else { - this.extensions = Collections.emptyList(); - } } @Override @@ -73,6 +58,6 @@ public class ExtensibleGlProgram extends GlProgram { public interface Factory

{ @Nonnull - P create(ResourceLocation name, int handle, @Nullable List extensions); + P create(ResourceLocation name, int handle); } } diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/WorldProgram.java b/src/main/java/com/jozufozu/flywheel/core/shader/WorldProgram.java index ad8c0a9fb..67f7f6703 100644 --- a/src/main/java/com/jozufozu/flywheel/core/shader/WorldProgram.java +++ b/src/main/java/com/jozufozu/flywheel/core/shader/WorldProgram.java @@ -4,9 +4,7 @@ import static org.lwjgl.opengl.GL20.glUniform1f; import static org.lwjgl.opengl.GL20.glUniform2f; import static org.lwjgl.opengl.GL20.glUniform3f; -import java.util.List; - -import com.jozufozu.flywheel.core.shader.extension.IProgramExtension; +import com.jozufozu.flywheel.core.shader.extension.WorldFog; import com.jozufozu.flywheel.util.AnimationTickHolder; import com.mojang.blaze3d.platform.Window; import com.mojang.math.Matrix4f; @@ -23,8 +21,10 @@ public class WorldProgram extends ExtensibleGlProgram { protected int uBlockAtlas; protected int uLightMap; - public WorldProgram(ResourceLocation name, int handle, List extensions) { - super(name, handle, extensions); + public WorldProgram(ResourceLocation name, int handle) { + super(name, handle); + + this.extensions.add(new WorldFog(this)); super.bind(); registerSamplers(); diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/extension/IExtensionInstance.java b/src/main/java/com/jozufozu/flywheel/core/shader/extension/IExtensionInstance.java index 7bc070158..d6c2e0f04 100644 --- a/src/main/java/com/jozufozu/flywheel/core/shader/extension/IExtensionInstance.java +++ b/src/main/java/com/jozufozu/flywheel/core/shader/extension/IExtensionInstance.java @@ -5,8 +5,7 @@ import net.minecraft.resources.ResourceLocation; public interface IExtensionInstance { /** - * Bind the extra program state. It is recommended to grab the state information from global variables, - * or local variables passed through a {@link IProgramExtension}. + * Bind the extra program state. It is recommended to grab the state information from global variables. */ void bind(); diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/extension/IProgramExtension.java b/src/main/java/com/jozufozu/flywheel/core/shader/extension/IProgramExtension.java deleted file mode 100644 index 0767c46bf..000000000 --- a/src/main/java/com/jozufozu/flywheel/core/shader/extension/IProgramExtension.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.jozufozu.flywheel.core.shader.extension; - -import com.jozufozu.flywheel.backend.SpecMetaRegistry; -import com.jozufozu.flywheel.backend.gl.shader.GlProgram; -import com.mojang.serialization.Codec; - -import net.minecraft.resources.ResourceLocation; - -/** - * A factory interface for creating {@link IExtensionInstance}s. These are what end up being passed in - * during shader program construction. - */ -public interface IProgramExtension { - - Codec CODEC = ResourceLocation.CODEC.xmap(SpecMetaRegistry::getExtension, IProgramExtension::getID); - - /** - * Construct the extension, binding any necessary information using the provided {@link GlProgram}. - * - * @param program The program being extended. - * @return An extension object, possibly initialized using the program. - */ - IExtensionInstance create(GlProgram program); - - ResourceLocation getID(); -} diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/FogMode.java b/src/main/java/com/jozufozu/flywheel/core/shader/extension/WorldFog.java similarity index 76% rename from src/main/java/com/jozufozu/flywheel/core/shader/FogMode.java rename to src/main/java/com/jozufozu/flywheel/core/shader/extension/WorldFog.java index f605869f3..0aba10b1e 100644 --- a/src/main/java/com/jozufozu/flywheel/core/shader/FogMode.java +++ b/src/main/java/com/jozufozu/flywheel/core/shader/extension/WorldFog.java @@ -1,22 +1,21 @@ -package com.jozufozu.flywheel.core.shader; +package com.jozufozu.flywheel.core.shader.extension; import org.lwjgl.opengl.GL20; import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.backend.gl.shader.GlProgram; -import com.jozufozu.flywheel.core.shader.extension.IExtensionInstance; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.resources.ResourceLocation; -public class FogMode implements IExtensionInstance { +public class WorldFog implements IExtensionInstance { - public static final ResourceLocation NAME = new ResourceLocation(Flywheel.ID, "fog_linear"); + public static final ResourceLocation NAME = new ResourceLocation(Flywheel.ID, "fog"); private final int uFogColor; private final int uFogRange; - public FogMode(GlProgram program) { + public WorldFog(GlProgram program) { this.uFogColor = program.getUniformLocation("uFogColor"); this.uFogRange = program.getUniformLocation("uFogRange"); } diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/IGameStateProvider.java b/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/IGameStateProvider.java index 587dd2c9f..8e472de72 100644 --- a/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/IGameStateProvider.java +++ b/src/main/java/com/jozufozu/flywheel/core/shader/gamestate/IGameStateProvider.java @@ -1,13 +1,13 @@ package com.jozufozu.flywheel.core.shader.gamestate; -import com.jozufozu.flywheel.backend.SpecMetaRegistry; +import com.jozufozu.flywheel.backend.GameStateRegistry; import com.mojang.serialization.Codec; import net.minecraft.resources.ResourceLocation; public interface IGameStateProvider { - Codec CODEC = ResourceLocation.CODEC.xmap(SpecMetaRegistry::getStateProvider, IGameStateProvider::getID); + Codec CODEC = ResourceLocation.CODEC.xmap(GameStateRegistry::getStateProvider, IGameStateProvider::getID); ResourceLocation getID(); diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramState.java b/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramState.java index 1279bdd17..e680c4e85 100644 --- a/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramState.java +++ b/src/main/java/com/jozufozu/flywheel/core/shader/spec/ProgramState.java @@ -2,16 +2,14 @@ package com.jozufozu.flywheel.core.shader.spec; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; -import com.jozufozu.flywheel.core.shader.extension.IProgramExtension; import com.jozufozu.flywheel.util.CodecUtil; import com.mojang.datafixers.util.Either; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import com.mojang.serialization.codecs.RecordCodecBuilder; -public class ProgramState { +public record ProgramState(IGameStateCondition context, List defines) { // TODO: Use Codec.dispatch private static final Codec WHEN = Codec.either(BooleanGameStateCondition.BOOLEAN_SUGAR, SpecificValueCondition.CODEC) @@ -28,37 +26,8 @@ public class ProgramState { }); public static final Codec CODEC = RecordCodecBuilder.create(state -> state.group(WHEN.fieldOf("when") - .forGetter(ProgramState::getContext), CodecUtil.oneOrMore(Codec.STRING) - .optionalFieldOf("define", Collections.emptyList()) - .forGetter(ProgramState::getDefines), CodecUtil.oneOrMore(IProgramExtension.CODEC) - .optionalFieldOf("extend", Collections.emptyList()) - .forGetter(ProgramState::getExtensions)) + .forGetter(ProgramState::context), CodecUtil.oneOrMore(Codec.STRING) + .optionalFieldOf("define", Collections.emptyList()) + .forGetter(ProgramState::defines)) .apply(state, ProgramState::new)); - - private final IGameStateCondition context; - private final List defines; - private final List extensions; - - public ProgramState(IGameStateCondition context, List defines, List extensions) { - this.context = context; - this.defines = defines; - this.extensions = extensions; - } - - public IGameStateCondition getContext() { - return context; - } - - public List getDefines() { - return defines; - } - - public List getExtensions() { - return extensions; - } - - @Override - public String toString() { - return "ProgramState{" + "gameState=" + context.getID() + ", defines=" + defines + ", extensions=" + extensions.stream().map(IProgramExtension::getID).collect(Collectors.toList()) + '}'; - } } diff --git a/src/main/resources/assets/flywheel/flywheel/shaders/context/fog.glsl b/src/main/resources/assets/flywheel/flywheel/shaders/context/fog.glsl index b6d086422..49380b14f 100644 --- a/src/main/resources/assets/flywheel/flywheel/shaders/context/fog.glsl +++ b/src/main/resources/assets/flywheel/flywheel/shaders/context/fog.glsl @@ -1,3 +1,5 @@ +#define USE_FOG + #if defined(VERTEX_SHADER) out float FragDistance; #elif defined(FRAGMENT_SHADER)