Merge remote-tracking branch 'origin/1.17/dev' into 1.17/fabric/dev

Conflicts:
	build.gradle
	gradle.properties
This commit is contained in:
PepperBell 2021-12-05 18:42:30 -08:00
commit e7ef9291c7
19 changed files with 32 additions and 216 deletions

View file

@ -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

View file

@ -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();

View file

@ -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<ResourceLocation, IProgramExtension> registeredExtensions = new HashMap<>();
private static final Map<ResourceLocation, IGameStateProvider> 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);
}
}

View file

@ -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);
}

View file

@ -43,7 +43,7 @@ public class WorldShaderPipeline<P extends WorldProgram> implements IShaderPipel
GameStateProgram.Builder<P> 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<P extends WorldProgram> 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<P extends WorldProgram> 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);
}
}

View file

@ -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<S extends InstanceData> implements StructType<S> {
private final NonNullSupplier<S> factory;
private final VertexFormat format;
public BasicStructType(NonNullSupplier<S> 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<S> getWriter(VecBuffer backing) {
return new BasicWriter(backing);
}
public class BasicWriter implements StructWriter<S> {
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());
}
}
}

View file

@ -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"));

View file

@ -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<IProgramExtension> extensions) {
super(name, handle, extensions);
public CrumblingProgram(ResourceLocation name, int handle) {
super(name, handle);
uTextureScale = getUniformLocation("uTextureScale");
}

View file

@ -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<BasicData> {
@ -65,8 +64,4 @@ public abstract class BasicData extends InstanceData implements IFlatLight<Basic
return this;
}
@Override
public void write(VecBuffer buf) {
buf.putByteArray(new byte[]{blockLight, skyLight, r, g, b, a});
}
}

View file

@ -1,8 +1,6 @@
package com.jozufozu.flywheel.core.materials.model;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
import com.jozufozu.flywheel.core.materials.BasicData;
import com.jozufozu.flywheel.util.WriteSafe;
import com.jozufozu.flywheel.util.transform.Rotate;
import com.jozufozu.flywheel.util.transform.Scale;
import com.jozufozu.flywheel.util.transform.Translate;
@ -48,13 +46,6 @@ public class ModelData extends BasicData implements Translate<ModelData>, 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();

View file

@ -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);
}
}

View file

@ -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<IExtensionInstance> extensions;
protected final List<IExtensionInstance> extensions = new ArrayList<>();
public ExtensibleGlProgram(ResourceLocation name, int handle, @Nullable List<IProgramExtension> extensions) {
public ExtensibleGlProgram(ResourceLocation name, int handle) {
super(name, handle);
if (extensions != null) {
List<IExtensionInstance> 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<P extends GlProgram> {
@Nonnull
P create(ResourceLocation name, int handle, @Nullable List<IProgramExtension> extensions);
P create(ResourceLocation name, int handle);
}
}

View file

@ -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<IProgramExtension> extensions) {
super(name, handle, extensions);
public WorldProgram(ResourceLocation name, int handle) {
super(name, handle);
this.extensions.add(new WorldFog(this));
super.bind();
registerSamplers();

View file

@ -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();

View file

@ -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<IProgramExtension> 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();
}

View file

@ -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");
}

View file

@ -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<IGameStateProvider> CODEC = ResourceLocation.CODEC.xmap(SpecMetaRegistry::getStateProvider, IGameStateProvider::getID);
Codec<IGameStateProvider> CODEC = ResourceLocation.CODEC.xmap(GameStateRegistry::getStateProvider, IGameStateProvider::getID);
ResourceLocation getID();

View file

@ -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<String> defines) {
// TODO: Use Codec.dispatch
private static final Codec<IGameStateCondition> WHEN = Codec.either(BooleanGameStateCondition.BOOLEAN_SUGAR, SpecificValueCondition.CODEC)
@ -28,37 +26,8 @@ public class ProgramState {
});
public static final Codec<ProgramState> 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<String> defines;
private final List<IProgramExtension> extensions;
public ProgramState(IGameStateCondition context, List<String> defines, List<IProgramExtension> extensions) {
this.context = context;
this.defines = defines;
this.extensions = extensions;
}
public IGameStateCondition getContext() {
return context;
}
public List<String> getDefines() {
return defines;
}
public List<IProgramExtension> getExtensions() {
return extensions;
}
@Override
public String toString() {
return "ProgramState{" + "gameState=" + context.getID() + ", defines=" + defines + ", extensions=" + extensions.stream().map(IProgramExtension::getID).collect(Collectors.toList()) + '}';
}
}

View file

@ -1,3 +1,5 @@
#define USE_FOG
#if defined(VERTEX_SHADER)
out float FragDistance;
#elif defined(FRAGMENT_SHADER)