Move away from a static backend class, add a registration event

This commit is contained in:
JozsefA 2021-06-06 15:46:16 -07:00
parent 457fff78f3
commit d47f898c76
89 changed files with 487 additions and 340 deletions

View file

@ -11,18 +11,13 @@ import org.apache.logging.log4j.Logger;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLCapabilities;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
import com.jozufozu.flywheel.backend.instancing.InstanceData;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
import com.jozufozu.flywheel.backend.instancing.MaterialSpec;
import com.jozufozu.flywheel.core.WorldContext;
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
import com.simibubi.create.foundation.config.AllConfigs;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.IReloadableResourceManager;
import net.minecraft.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.world.IWorld;
@ -31,33 +26,47 @@ import net.minecraft.world.World;
public class Backend {
public static final Logger log = LogManager.getLogger(Backend.class);
public static final ShaderSources SHADER_SOURCES = new ShaderSources();
private static final Backend INSTANCE = new Backend();
public static GLCapabilities capabilities;
public static GlCompat compat;
private static Matrix4f projectionMatrix = new Matrix4f();
private static boolean instancedArrays;
private static boolean enabled;
static final Map<ResourceLocation, MaterialSpec<?>> materialRegistry = new HashMap<>();
static final List<ShaderContext<?>> contexts = new ArrayList<>();
static final Map<ResourceLocation, ProgramSpec> programSpecRegistry = new HashMap<>();
static {
register(WorldContext.INSTANCE);
register(InstancedRenderDispatcher.CRUMBLING);
public static Backend getInstance() {
return INSTANCE;
}
public final Minecraft minecraft;
public ShaderSources sources;
public GLCapabilities capabilities;
public GlCompat compat;
private Matrix4f projectionMatrix = new Matrix4f();
private boolean instancedArrays;
private boolean enabled;
private final List<IShaderContext<?>> contexts = new ArrayList<>();
private final Map<ResourceLocation, MaterialSpec<?>> materialRegistry = new HashMap<>();
private final Map<ResourceLocation, ProgramSpec> programSpecRegistry = new HashMap<>();
public Backend() {
throw new IllegalStateException();
// Can be null when running datagenerators due to the unfortunate time we call this
minecraft = Minecraft.getInstance();
if (minecraft == null) return;
sources = new ShaderSources(this);
OptifineHandler.init();
}
void clearContexts() {
SpecMetaRegistry.clear();
contexts.forEach(IShaderContext::delete);
materialRegistry.clear();
}
/**
* Get a string describing the Flywheel backend. When there are eventually multiple backends
* (Meshlet, MDI, GL31 Draw Instanced are planned), this will name which one is in use.
*/
public static String getBackendDescriptor() {
public String getBackendDescriptor() {
if (canUseInstancing()) {
return "GL33 Instanced Arrays";
}
@ -72,7 +81,7 @@ public class Backend {
/**
* Register a shader program.
*/
public static ProgramSpec register(ProgramSpec spec) {
public ProgramSpec register(ProgramSpec spec) {
ResourceLocation name = spec.name;
if (programSpecRegistry.containsKey(name)) {
throw new IllegalStateException("Program spec '" + name + "' already registered.");
@ -84,7 +93,7 @@ public class Backend {
/**
* Register a shader context.
*/
public static <P extends GlProgram> ShaderContext<P> register(ShaderContext<P> spec) {
public <C extends ShaderContext<?>> C register(C spec) {
contexts.add(spec);
return spec;
}
@ -92,7 +101,7 @@ public class Backend {
/**
* Register an instancing material.
*/
public static <D extends InstanceData> MaterialSpec<D> register(MaterialSpec<D> spec) {
public <D extends InstanceData> MaterialSpec<D> register(MaterialSpec<D> spec) {
ResourceLocation name = spec.name;
if (materialRegistry.containsKey(name)) {
throw new IllegalStateException("Material spec '" + name + "' already registered.");
@ -101,52 +110,32 @@ public class Backend {
return spec;
}
public static ProgramSpec getSpec(ResourceLocation name) {
public ProgramSpec getSpec(ResourceLocation name) {
return programSpecRegistry.get(name);
}
/**
* Used to avoid calling Flywheel functions on (fake) worlds that don't specifically support it.
*/
public static boolean isFlywheelWorld(IWorld world) {
return (world instanceof IFlywheelWorld && ((IFlywheelWorld) world).supportsFlywheel()) || world == Minecraft.getInstance().world;
}
public static boolean available() {
public boolean available() {
return canUseVBOs();
}
public static boolean canUseInstancing() {
public boolean canUseInstancing() {
return enabled && instancedArrays;
}
public static boolean canUseVBOs() {
public boolean canUseVBOs() {
return enabled && gl20();
}
public static boolean gl33() {
public boolean gl33() {
return capabilities.OpenGL33;
}
public static boolean gl20() {
public boolean gl20() {
return capabilities.OpenGL20;
}
public static void init() {
// Can be null when running datagenerators due to the unfortunate time we call this
Minecraft mc = Minecraft.getInstance();
if (mc == null) return;
IResourceManager manager = mc.getResourceManager();
if (manager instanceof IReloadableResourceManager) {
((IReloadableResourceManager) manager).addReloadListener(SHADER_SOURCES);
}
OptifineHandler.init();
}
public static void refresh() {
public void refresh() {
OptifineHandler.refresh();
capabilities = GL.createCapabilities();
compat = new GlCompat(capabilities);
@ -158,27 +147,38 @@ public class Backend {
enabled = AllConfigs.CLIENT.experimentalRendering.get() && !OptifineHandler.usingShaders();
}
public static void reloadWorldRenderers() {
RenderWork.enqueue(Minecraft.getInstance().worldRenderer::loadRenderers);
}
public static boolean canUseInstancing(World world) {
public boolean canUseInstancing(World world) {
return canUseInstancing() && isFlywheelWorld(world);
}
public static Collection<MaterialSpec<?>> allMaterials() {
public Collection<MaterialSpec<?>> allMaterials() {
return materialRegistry.values();
}
public static Collection<ProgramSpec> allPrograms() {
public Collection<ProgramSpec> allPrograms() {
return programSpecRegistry.values();
}
public static Matrix4f getProjectionMatrix() {
public Collection<IShaderContext<?>> allContexts() {
return contexts;
}
public Matrix4f getProjectionMatrix() {
return projectionMatrix;
}
public static void setProjectionMatrix(Matrix4f projectionMatrix) {
Backend.projectionMatrix = projectionMatrix;
public void setProjectionMatrix(Matrix4f projectionMatrix) {
this.projectionMatrix = projectionMatrix;
}
/**
* Used to avoid calling Flywheel functions on (fake) worlds that don't specifically support it.
*/
public static boolean isFlywheelWorld(IWorld world) {
return (world instanceof IFlywheelWorld && ((IFlywheelWorld) world).supportsFlywheel()) || world == Minecraft.getInstance().world;
}
public static void reloadWorldRenderers() {
RenderWork.enqueue(Minecraft.getInstance().worldRenderer::loadRenderers);
}
}

View file

@ -0,0 +1,17 @@
package com.jozufozu.flywheel.backend;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import net.minecraft.util.ResourceLocation;
public interface IShaderContext<P extends GlProgram> {
P getProgram(ResourceLocation loc);
/**
* Load all programs associated with this context. This might be just one, if the context is very specialized.
*/
void load();
void delete();
}

View file

@ -1,14 +1,12 @@
package com.jozufozu.flywheel.backend;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import com.google.common.collect.Lists;
import com.jozufozu.flywheel.backend.gl.GlObject;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import com.jozufozu.flywheel.backend.gl.shader.GlShader;
@ -21,21 +19,20 @@ import com.jozufozu.flywheel.core.shader.spec.ProgramState;
import net.minecraft.util.ResourceLocation;
public abstract class ShaderContext<P extends GlProgram> {
public abstract class ShaderContext<P extends GlProgram> implements IShaderContext<P> {
protected final Map<ResourceLocation, IMultiProgram<P>> programs = new HashMap<>();
protected ShaderSources sourceRepo;
public final Backend backend;
/**
* Load all programs associated with this context. This might be just one, if the context is very specialized.
*/
public final void load(ShaderSources loader) {
this.sourceRepo = loader;
load();
public ShaderContext(Backend backend) {
this.backend = backend;
}
protected abstract void load();
@Override
public P getProgram(ResourceLocation spec) {
return programs.get(spec).get();
}
public Program loadAndLink(ProgramSpec spec, @Nullable ProgramState state) {
Shader vertexFile = getSource(ShaderType.VERTEX, spec.vert);
@ -46,23 +43,20 @@ public abstract class ShaderContext<P extends GlProgram> {
fragmentFile.defineAll(state.getDefines());
}
return link(loadProgram(spec.name, vertexFile, fragmentFile));
return link(buildProgram(spec.name, vertexFile, fragmentFile));
}
protected Shader getSource(ShaderType type, ResourceLocation name) {
return sourceRepo.source(name, type);
return backend.sources.source(name, type);
}
protected Program link(Program program) {
return program.link();
}
public P getProgram(ResourceLocation spec) {
return programs.get(spec).get();
}
protected Program loadProgram(ResourceLocation name, Shader... shaders) {
return loadProgram(name, Lists.newArrayList(shaders));
@Override
public void delete() {
programs.values().forEach(IMultiProgram::delete);
}
/**
@ -72,8 +66,8 @@ public abstract class ShaderContext<P extends GlProgram> {
* @param shaders What are the different shader stages that should be linked together?
* @return A program with all provided shaders attached
*/
protected Program loadProgram(ResourceLocation name, Collection<Shader> shaders) {
List<GlShader> compiled = new ArrayList<>(shaders.size());
protected static Program buildProgram(ResourceLocation name, Shader... shaders) {
List<GlShader> compiled = new ArrayList<>(shaders.length);
try {
Program builder = new Program(name);

View file

@ -29,15 +29,17 @@ import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
import com.jozufozu.flywheel.backend.loading.Shader;
import com.jozufozu.flywheel.backend.loading.ShaderLoadingException;
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
import com.jozufozu.flywheel.core.shader.spec.SpecMetaRegistry;
import com.jozufozu.flywheel.event.GatherContextEvent;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.JsonOps;
import net.minecraft.resources.IReloadableResourceManager;
import net.minecraft.resources.IResource;
import net.minecraft.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.ModLoader;
import net.minecraftforge.resource.IResourceType;
import net.minecraftforge.resource.ISelectiveResourceReloadListener;
import net.minecraftforge.resource.VanillaResourceType;
@ -47,31 +49,39 @@ public class ShaderSources implements ISelectiveResourceReloadListener {
public static final String SHADER_DIR = "flywheel/shaders/";
public static final String PROGRAM_DIR = "flywheel/programs/";
public static final ArrayList<String> EXTENSIONS = Lists.newArrayList(".vert", ".vsh", ".frag", ".fsh", ".glsl");
private static final Gson GSON = new GsonBuilder().create();
private final Map<ResourceLocation, String> shaderSource = new HashMap<>();
private boolean shouldCrash;
private final Gson gson = new GsonBuilder().create();
private final Backend backend;
public ShaderSources(Backend backend) {
this.backend = backend;
IResourceManager manager = backend.minecraft.getResourceManager();
if (manager instanceof IReloadableResourceManager) {
((IReloadableResourceManager) manager).addReloadListener(this);
}
}
@Override
public void onResourceManagerReload(IResourceManager manager, Predicate<IResourceType> predicate) {
if (predicate.test(VanillaResourceType.SHADERS)) {
OptifineHandler.refresh();
Backend.refresh();
backend.refresh();
if (Backend.gl20()) {
if (backend.gl20()) {
shaderSource.clear();
shouldCrash = false;
SpecMetaRegistry.init();
backend.clearContexts();
ModLoader.get().postEvent(new GatherContextEvent(backend));
loadProgramSpecs(manager);
loadShaderSources(manager);
for (ShaderContext<?> context : Backend.contexts) {
context.load(this);
for (IShaderContext<?> context : backend.allContexts()) {
context.load();
}
if (shouldCrash) {
@ -97,13 +107,13 @@ public class ShaderSources implements ISelectiveResourceReloadListener {
ResourceLocation specName = ResourceUtil.trim(location, PROGRAM_DIR, ".json");
DataResult<Pair<ProgramSpec, JsonElement>> result = ProgramSpec.CODEC.decode(JsonOps.INSTANCE, gson.fromJson(s, JsonElement.class));
DataResult<Pair<ProgramSpec, JsonElement>> result = ProgramSpec.CODEC.decode(JsonOps.INSTANCE, GSON.fromJson(s, JsonElement.class));
ProgramSpec spec = result.get().orThrow().getFirst();
spec.setName(specName);
Backend.register(spec);
backend.register(spec);
} catch (Exception e) {
Backend.log.error(e);
}

View file

@ -1,14 +1,10 @@
package com.jozufozu.flywheel.core.shader.spec;
package com.jozufozu.flywheel.backend;
import java.util.HashMap;
import java.util.Map;
import com.jozufozu.flywheel.core.shader.WorldFog;
import com.jozufozu.flywheel.core.shader.extension.IProgramExtension;
import com.jozufozu.flywheel.core.shader.gamestate.FogStateProvider;
import com.jozufozu.flywheel.core.shader.gamestate.IGameStateProvider;
import com.jozufozu.flywheel.core.shader.gamestate.NormalDebugStateProvider;
import com.jozufozu.flywheel.core.shader.gamestate.RainbowDebugStateProvider;
import net.minecraft.util.ResourceLocation;
@ -17,18 +13,9 @@ public class SpecMetaRegistry {
private static final Map<ResourceLocation, IProgramExtension> registeredExtensions = new HashMap<>();
private static final Map<ResourceLocation, IGameStateProvider> registeredStateProviders = new HashMap<>();
// TODO: proper registration, don't call this from ShaderLoader
private static boolean initialized = false;
public static void init() {
if (initialized) return;
initialized = true;
register(FogStateProvider.INSTANCE);
register(RainbowDebugStateProvider.INSTANCE);
register(NormalDebugStateProvider.INSTANCE);
register(WorldFog.LINEAR);
register(WorldFog.EXP2);
static void clear() {
registeredExtensions.clear();
registeredStateProviders.clear();
}
public static IGameStateProvider getStateProvider(ResourceLocation location) {

View file

@ -4,18 +4,18 @@ import com.jozufozu.flywheel.backend.Backend;
public class GlVertexArray extends GlObject {
public GlVertexArray() {
setHandle(Backend.compat.vao.genVertexArrays());
setHandle(Backend.getInstance().compat.vao.genVertexArrays());
}
public void bind() {
Backend.compat.vao.bindVertexArray(handle());
Backend.getInstance().compat.vao.bindVertexArray(handle());
}
public void unbind() {
Backend.compat.vao.bindVertexArray(0);
Backend.getInstance().compat.vao.bindVertexArray(0);
}
protected void deleteInternal(int handle) {
Backend.compat.vao.deleteVertexArrays(handle);
Backend.getInstance().compat.vao.deleteVertexArrays(handle);
}
}

View file

@ -54,7 +54,7 @@ public class GlBuffer extends GlObject {
}
public MappedBuffer getBuffer(int offset, int length) {
if (Backend.compat.mapBufferRange != MapBufferRange.UNSUPPORTED) {
if (Backend.getInstance().compat.mapBufferRange != MapBufferRange.UNSUPPORTED) {
return new MappedBufferRange(this, offset, length, GL30.GL_MAP_WRITE_BIT);
} else {
MappedFullBuffer fullBuffer = new MappedFullBuffer(this, MappedBufferUsage.WRITE_ONLY);

View file

@ -26,7 +26,7 @@ public class MappedBufferRange extends MappedBuffer {
@Override
protected void checkAndMap() {
if (!mapped) {
setInternal(Backend.compat.mapBufferRange.mapBuffer(owner.type, offset, length, access));
setInternal(Backend.getInstance().compat.mapBufferRange.mapBuffer(owner.type, offset, length, access));
mapped = true;
}
}

View file

@ -16,11 +16,10 @@ import com.jozufozu.flywheel.backend.gl.versioned.instancing.InstancedArrays;
import com.jozufozu.flywheel.backend.gl.versioned.instancing.VertexArrayObject;
/**
* An instance of this class stores information
* about what OpenGL features are available.
* <p>
* Each field stores an enum variant that provides access to the
* most appropriate version of a feature for the current system.
* An instance of this class stores information about what OpenGL features are available.
* <br>
* Each field stores an enum variant that provides access to the most appropriate version of a feature for the current
* system.
*/
public class GlCompat {
public final MapBufferRange mapBufferRange;

View file

@ -1,5 +1,7 @@
package com.jozufozu.flywheel.backend.instancing;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
/**
* An interface giving {@link TileEntityInstance}s a hook to have a function called at
* the start of a frame. By implementing {@link IDynamicInstance}, a {@link TileEntityInstance}

View file

@ -1,5 +1,7 @@
package com.jozufozu.flywheel.backend.instancing;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
/**
* An interface giving {@link TileEntityInstance}s a hook to have a function called at
* the end of every tick. By implementing {@link ITickableInstance}, a {@link TileEntityInstance}

View file

@ -12,12 +12,9 @@ import java.util.Vector;
import javax.annotation.Nonnull;
import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
import com.jozufozu.flywheel.core.Contexts;
import com.jozufozu.flywheel.core.CrumblingInstanceManager;
import com.jozufozu.flywheel.core.CrumblingProgram;
import com.jozufozu.flywheel.core.WorldContext;
import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.jozufozu.flywheel.event.BeginFrameEvent;
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
@ -38,7 +35,6 @@ import net.minecraft.entity.Entity;
import net.minecraft.inventory.container.PlayerContainer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.LazyValue;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.world.IWorld;
@ -48,15 +44,9 @@ import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber
public class InstancedRenderDispatcher {
public static final ResourceLocation CRUMBLING_CONTEXT = new ResourceLocation(Flywheel.ID, "context/crumbling");
public static final WorldContext<CrumblingProgram> CRUMBLING = new WorldContext<>(CrumblingProgram::new)
.withName(CRUMBLING_CONTEXT)
.withBuiltin(ShaderType.FRAGMENT, CRUMBLING_CONTEXT, "/builtin.frag")
.withBuiltin(ShaderType.VERTEX, CRUMBLING_CONTEXT, "/builtin.vert");
private static final RenderType crumblingLayer = ModelBakery.BLOCK_DESTRUCTION_RENDER_LAYERS.get(0);
private static final WorldAttached<TileInstanceManager> tileInstanceManager = new WorldAttached<>(world -> new TileInstanceManager(WorldContext.INSTANCE.getMaterialManager(world)));
private static final WorldAttached<TileInstanceManager> tileInstanceManager = new WorldAttached<>(world -> new TileInstanceManager(Contexts.WORLD.getMaterialManager(world)));
private static final LazyValue<Vector<CrumblingInstanceManager>> blockBreaking = new LazyValue<>(() -> {
Vector<CrumblingInstanceManager> renderers = new Vector<>(10);
for (int i = 0; i < 10; i++) {
@ -86,7 +76,7 @@ public class InstancedRenderDispatcher {
@SubscribeEvent
public static void onBeginFrame(BeginFrameEvent event) {
WorldContext.INSTANCE.getMaterialManager(event.getWorld())
Contexts.WORLD.getMaterialManager(event.getWorld())
.checkAndShiftOrigin(event.getInfo());
get(event.getWorld())
.beginFrame(event.getInfo());
@ -95,8 +85,8 @@ public class InstancedRenderDispatcher {
@SubscribeEvent
public static void renderLayer(RenderLayerEvent event) {
ClientWorld world = event.getWorld();
if (!Backend.canUseInstancing(world)) return;
MaterialManager<WorldProgram> materialManager = WorldContext.INSTANCE.getMaterialManager(world);
if (!Backend.getInstance().canUseInstancing(world)) return;
MaterialManager<WorldProgram> materialManager = Contexts.WORLD.getMaterialManager(world);
event.type.startDrawing();
@ -108,8 +98,8 @@ public class InstancedRenderDispatcher {
@SubscribeEvent
public static void onReloadRenderers(ReloadRenderersEvent event) {
ClientWorld world = event.getWorld();
if (Backend.canUseInstancing() && world != null) {
WorldContext.INSTANCE.getMaterialManager(world).delete();
if (Backend.getInstance().canUseInstancing() && world != null) {
Contexts.WORLD.getMaterialManager(world).delete();
TileInstanceManager tileRenderer = get(world);
tileRenderer.invalidate();
@ -118,7 +108,7 @@ public class InstancedRenderDispatcher {
}
public static void renderBreaking(ClientWorld world, Matrix4f viewProjection, double cameraX, double cameraY, double cameraZ) {
if (!Backend.canUseInstancing(world)) return;
if (!Backend.getInstance().canUseInstancing(world)) return;
WorldRenderer worldRenderer = Minecraft.getInstance().worldRenderer;
Long2ObjectMap<SortedSet<DestroyBlockProgress>> breakingProgressions = worldRenderer.blockBreakingProgressions;

View file

@ -5,6 +5,8 @@ import java.util.Map;
import javax.annotation.Nullable;
import com.google.common.collect.Maps;
import com.jozufozu.flywheel.backend.instancing.tile.ITileInstanceFactory;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;

View file

@ -241,7 +241,7 @@ public class Instancer<D extends InstanceData> {
instanceFormat.vertexAttribPointers(staticAttributes);
for (int i = 0; i < instanceFormat.getAttributeCount(); i++) {
Backend.compat.instancedArrays.vertexAttribDivisor(i + staticAttributes, 1);
Backend.getInstance().compat.instancedArrays.vertexAttribDivisor(i + staticAttributes, 1);
}
}

View file

@ -5,13 +5,13 @@ import java.util.HashMap;
import java.util.Map;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.WorldContext;
import com.jozufozu.flywheel.core.materials.ModelData;
import com.jozufozu.flywheel.core.materials.OrientedData;
import com.jozufozu.flywheel.core.shader.IProgramCallback;
import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.jozufozu.flywheel.util.WeakHashSet;
import com.simibubi.create.foundation.render.AllMaterialSpecs;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.RenderType;
@ -34,10 +34,10 @@ public class MaterialManager<P extends WorldProgram> {
public MaterialManager(WorldContext<P> context) {
this.materials = new HashMap<>();
this.renderers = new ArrayList<>(Backend.allMaterials().size());
this.renderers = new ArrayList<>(Backend.getInstance().allMaterials().size());
this.listeners = new WeakHashSet<>();
for (MaterialSpec<?> spec : Backend.allMaterials()) {
for (MaterialSpec<?> spec : Backend.getInstance().allMaterials()) {
InstanceMaterial<?> material = new InstanceMaterial<>(this::getOriginCoordinate, spec);
materials.put(spec.name, material);
MaterialRenderer<P> renderer = new MaterialRenderer<>(context.getProgram(spec.getProgramName()), material);
@ -89,11 +89,11 @@ public class MaterialManager<P extends WorldProgram> {
}
public InstanceMaterial<ModelData> getTransformMaterial() {
return getMaterial(AllMaterialSpecs.TRANSFORMED);
return getMaterial(Materials.TRANSFORMED);
}
public InstanceMaterial<OrientedData> getOrientedMaterial() {
return getMaterial(AllMaterialSpecs.ORIENTED);
return getMaterial(Materials.ORIENTED);
}
public Vector3i getOriginCoordinate() {

View file

@ -8,6 +8,7 @@ import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.client.renderer.ActiveRenderInfo;
@ -109,7 +110,7 @@ public class TileInstanceManager implements MaterialManager.OriginShiftListener
@SuppressWarnings("unchecked")
@Nullable
public <T extends TileEntity> TileEntityInstance<? super T> getInstance(T tile, boolean create) {
if (!Backend.canUseInstancing()) return null;
if (!Backend.getInstance().canUseInstancing()) return null;
TileEntityInstance<?> instance = instances.get(tile);
@ -123,7 +124,7 @@ public class TileInstanceManager implements MaterialManager.OriginShiftListener
}
public <T extends TileEntity> void onLightUpdate(T tile) {
if (!Backend.canUseInstancing()) return;
if (!Backend.getInstance().canUseInstancing()) return;
if (tile instanceof IInstanceRendered) {
TileEntityInstance<? super T> instance = getInstance(tile, false);
@ -134,7 +135,7 @@ public class TileInstanceManager implements MaterialManager.OriginShiftListener
}
public <T extends TileEntity> void add(T tile) {
if (!Backend.canUseInstancing()) return;
if (!Backend.getInstance().canUseInstancing()) return;
if (tile instanceof IInstanceRendered) {
addInternal(tile);
@ -142,7 +143,7 @@ public class TileInstanceManager implements MaterialManager.OriginShiftListener
}
public <T extends TileEntity> void update(T tile) {
if (!Backend.canUseInstancing()) return;
if (!Backend.getInstance().canUseInstancing()) return;
if (tile instanceof IInstanceRendered) {
TileEntityInstance<? super T> instance = getInstance(tile, false);
@ -161,7 +162,7 @@ public class TileInstanceManager implements MaterialManager.OriginShiftListener
}
public <T extends TileEntity> void remove(T tile) {
if (!Backend.canUseInstancing()) return;
if (!Backend.getInstance().canUseInstancing()) return;
if (tile instanceof IInstanceRendered) {
removeInternal(tile);
@ -169,13 +170,13 @@ public class TileInstanceManager implements MaterialManager.OriginShiftListener
}
public synchronized <T extends TileEntity> void queueAdd(T tile) {
if (!Backend.canUseInstancing()) return;
if (!Backend.getInstance().canUseInstancing()) return;
queuedAdditions.add(tile);
}
public synchronized <T extends TileEntity> void queueUpdate(T tile) {
if (!Backend.canUseInstancing()) return;
if (!Backend.getInstance().canUseInstancing()) return;
queuedUpdates.add(tile);
}

View file

@ -1,4 +1,6 @@
package com.jozufozu.flywheel.backend.instancing;
package com.jozufozu.flywheel.backend.instancing.tile;
import com.jozufozu.flywheel.backend.instancing.MaterialManager;
import net.minecraft.tileentity.TileEntity;

View file

@ -1,8 +1,14 @@
package com.jozufozu.flywheel.backend.instancing;
package com.jozufozu.flywheel.backend.instancing.tile;
import java.util.Arrays;
import java.util.stream.Stream;
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.IInstance;
import com.jozufozu.flywheel.backend.instancing.ITickableInstance;
import com.jozufozu.flywheel.backend.instancing.InstanceMaterial;
import com.jozufozu.flywheel.backend.instancing.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.TileInstanceManager;
import com.jozufozu.flywheel.core.materials.IFlatLight;
import com.jozufozu.flywheel.core.materials.ModelData;
import com.jozufozu.flywheel.core.materials.OrientedData;

View file

@ -75,7 +75,7 @@ public class BufferedModel {
public void drawInstances(int instanceCount) {
if (!valid()) return;
Backend.compat.drawInstanced.drawArraysInstanced(primitiveMode, 0, vertexCount, instanceCount);
Backend.getInstance().compat.drawInstanced.drawArraysInstanced(primitiveMode, 0, vertexCount, instanceCount);
}
public void delete() {

View file

@ -49,7 +49,7 @@ public class IndexedModel extends BufferedModel {
public void drawInstances(int instanceCount) {
if (vertexCount <= 0 || deleted) return;
Backend.compat.drawInstanced.drawElementsInstanced(primitiveMode, ebo.elementCount, ebo.eboIndexType, 0, instanceCount);
Backend.getInstance().compat.drawInstanced.drawElementsInstanced(primitiveMode, ebo.elementCount, ebo.eboIndexType, 0, instanceCount);
}
@Override

View file

@ -0,0 +1,48 @@
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.gl.shader.ShaderType;
import com.jozufozu.flywheel.core.shader.WorldFog;
import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.jozufozu.flywheel.core.shader.gamestate.FogStateProvider;
import com.jozufozu.flywheel.core.shader.gamestate.NormalDebugStateProvider;
import com.jozufozu.flywheel.event.GatherContextEvent;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class Contexts {
public static WorldContext<WorldProgram> WORLD;
public static WorldContext<CrumblingProgram> CRUMBLING;
@SubscribeEvent
public static void flwInit(GatherContextEvent event) {
Backend backend = event.getBackend();
SpecMetaRegistry.register(FogStateProvider.INSTANCE);
SpecMetaRegistry.register(NormalDebugStateProvider.INSTANCE);
SpecMetaRegistry.register(WorldFog.LINEAR);
SpecMetaRegistry.register(WorldFog.EXP2);
CRUMBLING = backend.register(new WorldContext<>(backend, CrumblingProgram::new)
.withName(Names.CRUMBLING)
.withBuiltin(ShaderType.FRAGMENT, Names.CRUMBLING, "/builtin.frag")
.withBuiltin(ShaderType.VERTEX, Names.CRUMBLING, "/builtin.vert"));
WORLD = backend.register(new WorldContext<>(backend, WorldProgram::new)
.withName(Names.WORLD)
.withBuiltin(ShaderType.FRAGMENT, Names.WORLD, "/builtin.frag")
.withBuiltin(ShaderType.VERTEX, Names.WORLD, "/builtin.vert"));
}
public static class Names {
public static final ResourceLocation CRUMBLING = new ResourceLocation(Flywheel.ID, "context/crumbling");
public static final ResourceLocation WORLD = new ResourceLocation(Flywheel.ID, "context/world");
}
}

View file

@ -1,6 +1,5 @@
package com.jozufozu.flywheel.core;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
import com.jozufozu.flywheel.backend.instancing.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.TileInstanceManager;
@ -8,7 +7,7 @@ import net.minecraft.util.math.BlockPos;
public class CrumblingInstanceManager extends TileInstanceManager {
public CrumblingInstanceManager() {
super(new MaterialManager<>(InstancedRenderDispatcher.CRUMBLING));
super(new MaterialManager<>(Contexts.CRUMBLING));
}
@Override

View file

@ -0,0 +1,24 @@
package com.jozufozu.flywheel.core;
import com.jozufozu.flywheel.backend.gl.attrib.CommonAttributes;
import com.jozufozu.flywheel.backend.gl.attrib.MatrixAttributes;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
public class Formats {
public static final VertexFormat UNLIT_MODEL = VertexFormat.builder()
.addAttributes(CommonAttributes.VEC3, CommonAttributes.NORMAL, CommonAttributes.UV)
.build();
public static final VertexFormat TRANSFORMED = litInstance()
.addAttributes(MatrixAttributes.MAT4,
MatrixAttributes.MAT3)
.build();
public static final VertexFormat ORIENTED = litInstance()
.addAttributes(CommonAttributes.VEC3, CommonAttributes.VEC3, CommonAttributes.QUATERNION)
.build();
public static VertexFormat.Builder litInstance() {
return VertexFormat.builder()
.addAttributes(CommonAttributes.LIGHT, CommonAttributes.RGBA);
}
}

View file

@ -0,0 +1,34 @@
package com.jozufozu.flywheel.core;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.InstanceData;
import com.jozufozu.flywheel.backend.instancing.MaterialSpec;
import com.jozufozu.flywheel.core.materials.ModelData;
import com.jozufozu.flywheel.core.materials.OrientedData;
import com.jozufozu.flywheel.event.GatherContextEvent;
import com.simibubi.create.foundation.render.AllMaterialSpecs;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class Materials {
public static final MaterialSpec<OrientedData> ORIENTED = AllMaterialSpecs.register(new MaterialSpec<>(Locations.ORIENTED, Programs.ORIENTED, Formats.UNLIT_MODEL, Formats.ORIENTED, OrientedData::new));
public static final MaterialSpec<ModelData> TRANSFORMED = AllMaterialSpecs.register(new MaterialSpec<>(Locations.MODEL, Programs.TRANSFORMED, Formats.UNLIT_MODEL, Formats.TRANSFORMED, ModelData::new));
public static <D extends InstanceData> MaterialSpec<D> register(MaterialSpec<D> spec) {
return Backend.getInstance().register(spec);
}
@SubscribeEvent
public static void flwInit(GatherContextEvent event) {
register(ORIENTED);
register(TRANSFORMED);
}
public static class Locations {
public static final ResourceLocation MODEL = new ResourceLocation("create", "model");
public static final ResourceLocation ORIENTED = new ResourceLocation("create", "oriented");
}
}

View file

@ -0,0 +1,10 @@
package com.jozufozu.flywheel.core;
import com.jozufozu.flywheel.Flywheel;
import net.minecraft.util.ResourceLocation;
public class Programs {
public static final ResourceLocation TRANSFORMED = new ResourceLocation(Flywheel.ID, "model");
public static final ResourceLocation ORIENTED = new ResourceLocation(Flywheel.ID, "oriented");
}

View file

@ -7,7 +7,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.ResourceUtil;
import com.jozufozu.flywheel.backend.ShaderContext;
@ -35,13 +34,6 @@ public class WorldContext<P extends WorldProgram> extends ShaderContext<P> {
private static final String declaration = "#flwbuiltins";
private static final Pattern builtinPattern = Pattern.compile(declaration);
public static final ResourceLocation WORLD_CONTEXT = new ResourceLocation(Flywheel.ID, "context/world");
public static final WorldContext<WorldProgram> INSTANCE = new WorldContext<>(WorldProgram::new)
.withName(WORLD_CONTEXT)
.withBuiltin(ShaderType.FRAGMENT, WORLD_CONTEXT, "/builtin.frag")
.withBuiltin(ShaderType.VERTEX, WORLD_CONTEXT, "/builtin.vert");
protected ResourceLocation name;
protected Supplier<Stream<ResourceLocation>> specStream;
protected TemplateFactory templateFactory;
@ -53,10 +45,11 @@ public class WorldContext<P extends WorldProgram> extends ShaderContext<P> {
private final ExtensibleGlProgram.Factory<P> factory;
public WorldContext(ExtensibleGlProgram.Factory<P> factory) {
public WorldContext(Backend backend, ExtensibleGlProgram.Factory<P> factory) {
super(backend);
this.factory = factory;
specStream = () -> Backend.allMaterials()
specStream = () -> backend.allMaterials()
.stream()
.map(MaterialSpec::getProgramName);
@ -102,16 +95,16 @@ public class WorldContext<P extends WorldProgram> extends ShaderContext<P> {
Backend.log.info("Loading context '{}'", name);
try {
builtins.forEach((type, resourceLocation) -> builtinSources.put(type, sourceRepo.getShaderSource(resourceLocation)));
builtins.forEach((type, resourceLocation) -> builtinSources.put(type, backend.sources.getShaderSource(resourceLocation)));
} catch (ShaderLoadingException e) {
sourceRepo.notifyError();
backend.sources.notifyError();
Backend.log.error(String.format("Could not find builtin: %s", e.getMessage()));
return;
}
template = templateFactory.create(sourceRepo);
template = templateFactory.create(backend.sources);
transformer = new ShaderTransformer()
.pushStage(this::injectBuiltins)
.pushStage(Shader::processIncludes)
@ -119,7 +112,7 @@ public class WorldContext<P extends WorldProgram> extends ShaderContext<P> {
.pushStage(Shader::processIncludes);
specStream.get()
.map(Backend::getSpec)
.map(backend::getSpec)
.forEach(spec -> {
try {
@ -128,11 +121,18 @@ public class WorldContext<P extends WorldProgram> extends ShaderContext<P> {
Backend.log.debug("Loaded program {}", spec.name);
} catch (Exception e) {
Backend.log.error("Program '{}': {}", spec.name, e);
sourceRepo.notifyError();
backend.sources.notifyError();
}
});
}
@Override
public void delete() {
super.delete();
materialManager.forEach(MaterialManager::delete);
}
@Override
protected Shader getSource(ShaderType type, ResourceLocation name) {
Shader source = super.getSource(type, name);

View file

@ -1,7 +1,7 @@
package com.jozufozu.flywheel.core.shader.extension;
import com.jozufozu.flywheel.backend.SpecMetaRegistry;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import com.jozufozu.flywheel.core.shader.spec.SpecMetaRegistry;
import com.mojang.serialization.Codec;
import net.minecraft.util.ResourceLocation;

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.core.shader.gamestate;
import com.jozufozu.flywheel.core.shader.spec.SpecMetaRegistry;
import com.jozufozu.flywheel.backend.SpecMetaRegistry;
import com.mojang.serialization.Codec;
import net.minecraft.util.ResourceLocation;

View file

@ -24,7 +24,7 @@ public class ForgeEvents {
ArrayList<String> right = event.getRight();
String text = "Flywheel: " + Backend.getBackendDescriptor();
String text = "Flywheel: " + Backend.getInstance().getBackendDescriptor();
if (right.size() < 10) {
right.add("");
right.add(text);

View file

@ -0,0 +1,19 @@
package com.jozufozu.flywheel.event;
import com.jozufozu.flywheel.backend.Backend;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.event.lifecycle.IModBusEvent;
public class GatherContextEvent extends Event implements IModBusEvent {
private final Backend backend;
public GatherContextEvent(Backend backend) {
this.backend = backend;
}
public Backend getBackend() {
return backend;
}
}

View file

@ -51,7 +51,7 @@ public class LightVolume {
public LightVolume(GridAlignedBB sampleVolume) {
setSampleVolume(sampleVolume);
pixelFormat = Backend.compat.pixelFormat;
pixelFormat = Backend.getInstance().compat.pixelFormat;
this.glTexture = new GlTexture(GL_TEXTURE_3D);
this.lightData = MemoryUtil.memAlloc(this.textureVolume.volume() * pixelFormat.byteCount());

View file

@ -24,8 +24,6 @@ import com.simibubi.create.foundation.item.CustomItemModels;
import com.simibubi.create.foundation.item.CustomRenderedItems;
import com.simibubi.create.foundation.ponder.content.PonderIndex;
import com.simibubi.create.foundation.ponder.elements.WorldSectionElement;
import com.simibubi.create.foundation.render.AllMaterialSpecs;
import com.simibubi.create.foundation.render.CreateFlywheelHandler;
import com.simibubi.create.foundation.render.SuperByteBufferCache;
import com.simibubi.create.foundation.utility.ghost.GhostBlocks;
import com.simibubi.create.foundation.utility.outliner.Outliner;
@ -79,13 +77,10 @@ public class CreateClient {
modEventBus.addListener(AllParticleTypes::registerFactories);
modEventBus.addListener(ClientEvents::loadCompleted);
Backend.init();
CreateFlywheelHandler.init();
Backend.getInstance();
}
public static void clientInit(FMLClientSetupEvent event) {
AllMaterialSpecs.init();
BUFFER_CACHE.registerCompartment(KineticTileEntityRenderer.KINETIC_TILE);
BUFFER_CACHE.registerCompartment(ContraptionRenderDispatcher.CONTRAPTION, 20);
BUFFER_CACHE.registerCompartment(WorldSectionElement.DOC_WORLD_SECTION, 20);

View file

@ -39,7 +39,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer<KineticTil
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
for (RenderType type : RenderType.getBlockLayers())
if (RenderTypeLookup.canRenderInLayer(te.getBlockState(), type))

View file

@ -2,7 +2,7 @@ package com.simibubi.create.content.contraptions.base;
import com.jozufozu.flywheel.backend.instancing.InstanceMaterial;
import com.jozufozu.flywheel.backend.instancing.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.TileEntityInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
import com.simibubi.create.content.contraptions.relays.elementary.ShaftBlock;

View file

@ -37,7 +37,7 @@ public class DrillMovementBehaviour extends BlockBreakingMovementBehaviour {
@OnlyIn(value = Dist.CLIENT)
public void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld,
ContraptionMatrices matrices, IRenderTypeBuffer buffer) {
if (!Backend.canUseInstancing())
if (!Backend.getInstance().canUseInstancing())
DrillRenderer.renderInContraption(context, renderWorld, matrices, buffer);
}

View file

@ -55,7 +55,7 @@ public class HarvesterMovementBehaviour extends MovementBehaviour {
@Override
public void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld,
ContraptionMatrices matrices, IRenderTypeBuffer buffers) {
if (!Backend.canUseInstancing())
if (!Backend.getInstance().canUseInstancing())
HarvesterRenderer.renderInContraption(context, renderWorld, matrices, buffers);
}

View file

@ -156,7 +156,7 @@ public class MechanicalCrafterRenderer extends SafeTileEntityRenderer<Mechanical
BlockState blockState = te.getBlockState();
IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid());
if (!Backend.canUseInstancing(te.getWorld())) {
if (!Backend.getInstance().canUseInstancing(te.getWorld())) {
SuperByteBuffer superBuffer = PartialBufferer.get(AllBlockPartials.SHAFTLESS_COGWHEEL, blockState);
standardKineticRotationTransform(superBuffer, te, light);
superBuffer.rotateCentered(Direction.UP, (float) (blockState.get(HORIZONTAL_FACING).getAxis() != Direction.Axis.X ? 0 : Math.PI / 2));

View file

@ -28,7 +28,7 @@ public class HandCrankRenderer extends KineticTileEntityRenderer {
int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
BlockState state = te.getBlockState();
Block block = state.getBlock();

View file

@ -257,7 +257,7 @@ public class DeployerMovementBehaviour extends MovementBehaviour {
@Override
public void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld,
ContraptionMatrices matrices, IRenderTypeBuffer buffers) {
if (!Backend.canUseInstancing())
if (!Backend.getInstance().canUseInstancing())
DeployerRenderer.renderInContraption(context, renderWorld, matrices, buffers);
}

View file

@ -53,7 +53,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer<DeployerTileEntity>
renderItem(te, partialTicks, ms, buffer, light, overlay);
FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay);
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
renderComponents(te, partialTicks, ms, buffer, light, overlay);
}
@ -112,7 +112,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer<DeployerTileEntity>
protected void renderComponents(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid());
if (!Backend.canUseInstancing(te.getWorld())) {
if (!Backend.getInstance().canUseInstancing(te.getWorld())) {
KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te), ms, vb, light);
}

View file

@ -28,7 +28,7 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer {
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
Direction direction = te.getBlockState()
.get(FACING);

View file

@ -36,7 +36,7 @@ public class FlywheelRenderer extends KineticTileEntityRenderer {
int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
BlockState blockState = te.getBlockState();
FlywheelTileEntity wte = (FlywheelTileEntity) te;

View file

@ -1,7 +1,7 @@
package com.simibubi.create.content.contraptions.components.flywheel.engine;
import com.jozufozu.flywheel.backend.instancing.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.TileEntityInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import com.jozufozu.flywheel.core.PartialModel;
import com.jozufozu.flywheel.core.materials.ModelData;
import com.mojang.blaze3d.matrix.MatrixStack;

View file

@ -24,7 +24,7 @@ public class EngineRenderer<T extends EngineTileEntity> extends SafeTileEntityRe
protected void renderSafe(T te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light,
int overlay) {
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
Block block = te.getBlockState()
.getBlock();

View file

@ -33,7 +33,7 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer {
protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
BlockState blockState = te.getBlockState();
MechanicalMixerTileEntity mixer = (MechanicalMixerTileEntity) te;

View file

@ -33,7 +33,7 @@ public class MechanicalPressRenderer extends KineticTileEntityRenderer {
int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
BlockPos pos = te.getPos();
BlockState blockState = te.getBlockState();

View file

@ -49,7 +49,7 @@ public class SawRenderer extends SafeTileEntityRenderer<SawTileEntity> {
renderItems(te, partialTicks, ms, buffer, light, overlay);
FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay);
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
renderShaft(te, ms, buffer, light, overlay);
}

View file

@ -26,7 +26,7 @@ public class BearingRenderer extends KineticTileEntityRenderer {
protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);

View file

@ -34,7 +34,7 @@ public class StabilizedBearingMovementBehaviour extends MovementBehaviour {
@OnlyIn(Dist.CLIENT)
public void renderInContraption(MovementContext context, PlacementSimulationWorld renderWorld,
ContraptionMatrices matrices, IRenderTypeBuffer buffer) {
if (Backend.canUseInstancing()) return;
if (Backend.getInstance().canUseInstancing()) return;
Direction facing = context.state.get(BlockStateProperties.FACING);
PartialModel top = AllBlockPartials.BEARING_TOP;

View file

@ -2,7 +2,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.ch
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.TileEntityInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import com.jozufozu.flywheel.core.materials.ModelData;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;

View file

@ -26,7 +26,7 @@ public class StickerRenderer extends SafeTileEntityRenderer<StickerTileEntity> {
protected void renderSafe(StickerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
BlockState state = te.getBlockState();
SuperByteBuffer head = PartialBufferer.get(AllBlockPartials.STICKER_HEAD, state);

View file

@ -32,7 +32,7 @@ public class GantryCarriageRenderer extends KineticTileEntityRenderer {
int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
BlockState state = te.getBlockState();
Direction facing = state.get(GantryCarriageBlock.FACING);

View file

@ -8,10 +8,11 @@ import com.jozufozu.flywheel.backend.instancing.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance;
import com.jozufozu.flywheel.backend.model.BufferedModel;
import com.jozufozu.flywheel.backend.model.IndexedModel;
import com.jozufozu.flywheel.core.Formats;
import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.instancing.ConditionalInstance;
import com.jozufozu.flywheel.core.materials.OrientedData;
import com.simibubi.create.AllItems;
import com.simibubi.create.foundation.render.AllMaterialSpecs;
import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.VecHelper;
@ -29,7 +30,7 @@ public class GlueInstance extends EntityInstance<SuperGlueEntity> implements ITi
public GlueInstance(MaterialManager<?> renderer, SuperGlueEntity entity) {
super(renderer, entity);
Instancer<OrientedData> instancer = renderer.getMaterial(AllMaterialSpecs.ORIENTED)
Instancer<OrientedData> instancer = renderer.getMaterial(Materials.ORIENTED)
.get(entity.getType(), GlueInstance::supplyModel);
model = new ConditionalInstance<>(instancer)
.withCondition(this::shouldShow)
@ -109,6 +110,6 @@ public class GlueInstance extends EntityInstance<SuperGlueEntity> implements ITi
ByteBuffer buffer = ByteBuffer.allocate(quads.length * 4);
buffer.asFloatBuffer().put(quads);
return IndexedModel.fromSequentialQuads(AllMaterialSpecs.UNLIT_MODEL, buffer, 8);
return IndexedModel.fromSequentialQuads(Formats.UNLIT_MODEL, buffer, 8);
}
}

View file

@ -44,7 +44,7 @@ public abstract class AbstractPulleyRenderer extends KineticTileEntityRenderer {
protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
float offset = getOffset(te, partialTicks);

View file

@ -11,14 +11,10 @@ import static org.lwjgl.opengl.GL13.glEnable;
import java.util.List;
import java.util.Random;
import java.util.stream.Stream;
import org.apache.commons.lang3.tuple.Pair;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
import com.jozufozu.flywheel.backend.loading.ModelTemplate;
import com.jozufozu.flywheel.core.WorldContext;
import com.jozufozu.flywheel.event.BeginFrameEvent;
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
import com.jozufozu.flywheel.event.RenderLayerEvent;
@ -31,6 +27,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
import com.simibubi.create.foundation.render.AllProgramSpecs;
import com.simibubi.create.foundation.render.Compartment;
import com.simibubi.create.foundation.render.CreateContexts;
import com.simibubi.create.foundation.render.SuperByteBuffer;
import com.simibubi.create.foundation.render.SuperByteBufferCache;
import com.simibubi.create.foundation.render.TileEntityRenderHelper;
@ -53,7 +50,6 @@ import net.minecraft.client.renderer.RenderTypeLookup;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.LightType;
import net.minecraft.world.World;
@ -74,12 +70,6 @@ public class ContraptionRenderDispatcher {
public static final Int2ObjectMap<ContraptionWorldHolder> WORLD_HOLDERS = new Int2ObjectOpenHashMap<>();
public static final Compartment<Pair<Contraption, Integer>> CONTRAPTION = new Compartment<>();
private static final ResourceLocation ctxRoot = new ResourceLocation("create", "context/contraption");
public static final WorldContext<ContraptionProgram> TILES = contraptionContext();
public static final WorldContext<ContraptionProgram> STRUCTURE = contraptionContext()
.withSpecStream(() -> Stream.of(AllProgramSpecs.STRUCTURE))
.withTemplateFactory(ModelTemplate::new);
public static void tick() {
if (Minecraft.getInstance().isGamePaused()) return;
@ -118,8 +108,8 @@ public class ContraptionRenderDispatcher {
glEnable(GL_TEXTURE_3D);
glActiveTexture(GL_TEXTURE4); // the shaders expect light volumes to be in texture 4
if (Backend.canUseVBOs()) {
ContraptionProgram structureShader = STRUCTURE.getProgram(AllProgramSpecs.STRUCTURE);
if (Backend.getInstance().canUseVBOs()) {
ContraptionProgram structureShader = CreateContexts.STRUCTURE.getProgram(AllProgramSpecs.STRUCTURE);
structureShader.bind();
structureShader.uploadViewProjection(event.viewProjection);
@ -130,7 +120,7 @@ public class ContraptionRenderDispatcher {
}
}
if (Backend.canUseInstancing()) {
if (Backend.getInstance().canUseInstancing()) {
for (RenderedContraption renderer : RENDERERS.values()) {
renderer.materialManager.render(layer, event.viewProjection, event.camX, event.camY, event.camZ, renderer::setup);
}
@ -150,7 +140,7 @@ public class ContraptionRenderDispatcher {
public static void render(AbstractContraptionEntity entity, Contraption contraption,
ContraptionMatrices matrices, IRenderTypeBuffer buffers) {
World world = entity.world;
if (Backend.canUseVBOs() && Backend.isFlywheelWorld(world)) {
if (Backend.getInstance().canUseVBOs() && Backend.isFlywheelWorld(world)) {
RenderedContraption renderer = getRenderer(world, contraption);
PlacementSimulationWorld renderWorld = renderer.renderWorld;
@ -343,10 +333,4 @@ public class ContraptionRenderDispatcher {
WORLD_HOLDERS.values().removeIf(ContraptionWorldHolder::isDead);
}
private static WorldContext<ContraptionProgram> contraptionContext() {
return new WorldContext<>(ContraptionProgram::new)
.withName(ctxRoot)
.withBuiltin(ShaderType.FRAGMENT, ctxRoot, "/builtin.frag")
.withBuiltin(ShaderType.VERTEX, ctxRoot, "/builtin.vert");
}
}

View file

@ -24,6 +24,7 @@ import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity;
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter;
import com.simibubi.create.foundation.render.CreateContexts;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld;
@ -59,11 +60,11 @@ public class RenderedContraption extends ContraptionWorldHolder {
public RenderedContraption(PlacementSimulationWorld renderWorld, Contraption contraption) {
super(contraption, renderWorld);
this.lighter = contraption.makeLighter();
this.materialManager = new ContraptionMaterialManager(ContraptionRenderDispatcher.TILES);
this.materialManager = new ContraptionMaterialManager(CreateContexts.CWORLD);
this.kinetics = new ContraptionInstanceManager(this, materialManager);
buildLayers();
if (Backend.canUseInstancing()) {
if (Backend.getInstance().canUseInstancing()) {
buildInstancedTiles();
buildActors();
}
@ -134,7 +135,7 @@ public class RenderedContraption extends ContraptionWorldHolder {
BufferedModel layerModel = buildStructureModel(renderWorld, contraption, layer);
if (layerModel != null) {
if (Backend.compat.vertexArrayObjectsSupported())
if (Backend.getInstance().compat.vertexArrayObjectsSupported())
renderLayers.put(layer, new ArrayModelRenderer(layerModel));
else
renderLayers.put(layer, new ModelRenderer(layerModel));

View file

@ -28,7 +28,7 @@ public class FluidValveRenderer extends KineticTileEntityRenderer {
protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
BlockState blockState = te.getBlockState();

View file

@ -32,7 +32,7 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer<SpeedContro
super.renderSafe(tileEntityIn, partialTicks, ms, buffer, light, overlay);
IVertexBuilder builder = buffer.getBuffer(RenderType.getSolid());
if (!Backend.canUseInstancing(tileEntityIn.getWorld())) {
if (!Backend.getInstance().canUseInstancing(tileEntityIn.getWorld())) {
KineticTileEntityRenderer.renderRotatingBuffer(tileEntityIn, getRotatedModel(tileEntityIn), ms, builder, light);
}

View file

@ -57,7 +57,7 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
protected void renderSafe(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
if (!Backend.canUseInstancing(te.getWorld())) {
if (!Backend.getInstance().canUseInstancing(te.getWorld())) {
BlockState blockState = te.getBlockState();
if (!AllBlocks.BELT.has(blockState)) return;

View file

@ -28,7 +28,7 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer {
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
Block block = te.getBlockState().getBlock();
final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState());

View file

@ -40,7 +40,7 @@ public class GaugeRenderer extends KineticTileEntityRenderer {
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
BlockState gaugeState = te.getBlockState();

View file

@ -27,7 +27,7 @@ public class GearboxRenderer extends KineticTileEntityRenderer {
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS);
final BlockPos pos = te.getPos();

View file

@ -2,7 +2,7 @@ package com.simibubi.create.content.curiosities.projector;
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.TileEntityInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import com.simibubi.create.foundation.render.effects.EffectsHandler;
public class ChromaticProjectorInstance extends TileEntityInstance<ChromaticProjectorTileEntity> implements IDynamicInstance {

View file

@ -9,7 +9,7 @@ import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.InstanceData;
import com.jozufozu.flywheel.backend.instancing.Instancer;
import com.jozufozu.flywheel.backend.instancing.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.TileEntityInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.logistics.block.FlapData;
import com.simibubi.create.foundation.gui.widgets.InterpolatedValue;

View file

@ -31,7 +31,7 @@ public class BeltTunnelRenderer extends SmartTileEntityRenderer<BeltTunnelTileEn
int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
SuperByteBuffer flapBuffer = PartialBufferer.get(AllBlockPartials.BELT_TUNNEL_FLAP, te.getBlockState());
IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid());

View file

@ -45,7 +45,7 @@ public class EjectorRenderer extends KineticTileEntityRenderer {
float lidProgress = ((EjectorTileEntity) te).getLidProgress(partialTicks);
float angle = lidProgress * 70;
if (!Backend.canUseInstancing(te.getWorld())) {
if (!Backend.getInstance().canUseInstancing(te.getWorld())) {
SuperByteBuffer model = PartialBufferer.get(AllBlockPartials.EJECTOR_TOP, te.getBlockState());
applyLidAngle(te, angle, model.matrixStacker());
model.light(light)

View file

@ -2,7 +2,7 @@ package com.simibubi.create.content.logistics.block.diodes;
import com.jozufozu.flywheel.backend.instancing.ITickableInstance;
import com.jozufozu.flywheel.backend.instancing.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.TileEntityInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import com.jozufozu.flywheel.core.materials.ModelData;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;

View file

@ -6,7 +6,7 @@ import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.InstanceData;
import com.jozufozu.flywheel.backend.instancing.Instancer;
import com.jozufozu.flywheel.backend.instancing.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.TileEntityInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import com.jozufozu.flywheel.core.PartialModel;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.logistics.block.FlapData;

View file

@ -30,7 +30,7 @@ public class FunnelRenderer extends SmartTileEntityRenderer<FunnelTileEntity> {
int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (!te.hasFlap() || Backend.canUseInstancing(te.getWorld()))
if (!te.hasFlap() || Backend.getInstance().canUseInstancing(te.getWorld()))
return;
BlockState blockState = te.getBlockState();

View file

@ -42,7 +42,7 @@ public class ArmRenderer extends KineticTileEntityRenderer {
super.renderSafe(te, pt, ms, buffer, light, overlay);
ArmTileEntity arm = (ArmTileEntity) te;
boolean usingFlywheel = Backend.canUseInstancing(te.getWorld());
boolean usingFlywheel = Backend.getInstance().canUseInstancing(te.getWorld());
ItemStack item = arm.heldItem;
boolean hasItem = !item.isEmpty();

View file

@ -3,7 +3,7 @@ package com.simibubi.create.content.logistics.block.redstone;
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.InstanceMaterial;
import com.jozufozu.flywheel.backend.instancing.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.TileEntityInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import com.jozufozu.flywheel.core.materials.ModelData;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;

View file

@ -28,7 +28,7 @@ public class AnalogLeverRenderer extends SafeTileEntityRenderer<AnalogLeverTileE
protected void renderSafe(AnalogLeverTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
BlockState leverState = te.getBlockState();
int lightCoords = WorldRenderer.getLightmapCoordinates(te.getWorld(), leverState, te.getPos());

View file

@ -3,7 +3,7 @@ package com.simibubi.create.content.schematics.block;
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.InstanceMaterial;
import com.jozufozu.flywheel.backend.instancing.MaterialManager;
import com.jozufozu.flywheel.backend.instancing.TileEntityInstance;
import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance;
import com.jozufozu.flywheel.core.materials.ModelData;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;

View file

@ -46,7 +46,7 @@ public class SchematicannonRenderer extends SafeTileEntityRenderer<Schematicanno
if (blocksLaunching)
renderLaunchedBlocks(tileEntityIn, partialTicks, ms, buffer, light, overlay);
if (Backend.canUseInstancing(tileEntityIn.getWorld())) return;
if (Backend.getInstance().canUseInstancing(tileEntityIn.getWorld())) return;
BlockPos pos = tileEntityIn.getPos();

View file

@ -13,6 +13,7 @@ import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock;
@ -96,11 +97,12 @@ public abstract class ConfigScreen extends AbstractSimiScreen {
Framebuffer thisBuffer = UIRenderHelper.framebuffer;
Framebuffer mainBuffer = Minecraft.getInstance().getFramebuffer();
Backend.compat.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, mainBuffer.framebufferObject);
Backend.compat.fbo.bindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, thisBuffer.framebufferObject);
Backend.compat.blit.blitFramebuffer(0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, 0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR);
GlCompat functions = Backend.getInstance().compat;
functions.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, mainBuffer.framebufferObject);
functions.fbo.bindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, thisBuffer.framebufferObject);
functions.blit.blitFramebuffer(0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, 0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR);
Backend.compat.fbo.bindFramebuffer(FramebufferConstants.FRAME_BUFFER, thisBuffer.framebufferObject);
functions.fbo.bindFramebuffer(FramebufferConstants.FRAME_BUFFER, thisBuffer.framebufferObject);
GL11.glClear(GL30.GL_STENCIL_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT);
}
@ -111,11 +113,12 @@ public abstract class ConfigScreen extends AbstractSimiScreen {
Framebuffer thisBuffer = UIRenderHelper.framebuffer;
Framebuffer mainBuffer = Minecraft.getInstance().getFramebuffer();
Backend.compat.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, thisBuffer.framebufferObject);
Backend.compat.fbo.bindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, mainBuffer.framebufferObject);
Backend.compat.blit.blitFramebuffer(0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, 0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR);
GlCompat functions = Backend.getInstance().compat;
functions.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, thisBuffer.framebufferObject);
functions.fbo.bindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, mainBuffer.framebufferObject);
functions.blit.blitFramebuffer(0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, 0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR);
Backend.compat.fbo.bindFramebuffer(FramebufferConstants.FRAME_BUFFER, mainBuffer.framebufferObject);
functions.fbo.bindFramebuffer(FramebufferConstants.FRAME_BUFFER, mainBuffer.framebufferObject);
}
@Override

View file

@ -2,8 +2,8 @@ package com.simibubi.create.foundation.data;
import javax.annotation.Nullable;
import com.jozufozu.flywheel.backend.instancing.ITileInstanceFactory;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
import com.jozufozu.flywheel.backend.instancing.tile.ITileInstanceFactory;
import com.tterrag.registrate.AbstractRegistrate;
import com.tterrag.registrate.builders.BuilderCallback;
import com.tterrag.registrate.builders.TileEntityBuilder;

View file

@ -19,7 +19,7 @@ public class CancelEntityRenderMixin {
@Inject(at = @At("RETURN"), method = "getAllEntities", cancellable = true)
private void filterEntities(CallbackInfoReturnable<Iterable<Entity>> cir) {
if (Backend.canUseInstancing()) {
if (Backend.getInstance().canUseInstancing()) {
Iterable<Entity> entities = cir.getReturnValue();
ArrayList<Entity> list = Lists.newArrayList(entities);

View file

@ -27,7 +27,7 @@ public class CancelTileEntityRenderMixin {
*/
@Inject(at = @At("RETURN"), method = "getTileEntities", cancellable = true)
private void noRenderInstancedTiles(CallbackInfoReturnable<List<TileEntity>> cir) {
if (Backend.canUseInstancing()) {
if (Backend.getInstance().canUseInstancing()) {
List<TileEntity> tiles = cir.getReturnValue();
tiles.removeIf(tile -> tile instanceof IInstanceRendered && !((IInstanceRendered) tile).shouldRenderNormally());

View file

@ -8,7 +8,6 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.OptifineHandler;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
import com.jozufozu.flywheel.event.BeginFrameEvent;
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
@ -51,13 +50,13 @@ public class RenderHooksMixin {
@Inject(at = @At("TAIL"), method = "renderLayer")
private void renderLayer(RenderType type, MatrixStack stack, double camX, double camY, double camZ,
CallbackInfo ci) {
if (!Backend.available())
if (!Backend.getInstance().available())
return;
Matrix4f view = stack.peek()
.getModel();
Matrix4f viewProjection = view.copy();
viewProjection.multiplyBackward(Backend.getProjectionMatrix());
viewProjection.multiplyBackward(Backend.getInstance().getProjectionMatrix());
MinecraftForge.EVENT_BUS.post(new RenderLayerEvent(world, type, viewProjection, camX, camY, camZ));
GL20.glUseProgram(0);
@ -65,8 +64,7 @@ public class RenderHooksMixin {
@Inject(at = @At("TAIL"), method = "loadRenderers")
private void refresh(CallbackInfo ci) {
OptifineHandler.refresh();
Backend.refresh();
Backend.getInstance().refresh();
MinecraftForge.EVENT_BUS.post(new ReloadRenderersEvent(world));
}
@ -82,13 +80,13 @@ public class RenderHooksMixin {
private void renderBlockBreaking(MatrixStack stack, float p_228426_2_, long p_228426_3_, boolean p_228426_5_,
ActiveRenderInfo info, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f p_228426_9_,
CallbackInfo ci) {
if (!Backend.available())
if (!Backend.getInstance().available())
return;
Matrix4f view = stack.peek()
.getModel();
Matrix4f viewProjection = view.copy();
viewProjection.multiplyBackward(Backend.getProjectionMatrix());
viewProjection.multiplyBackward(Backend.getInstance().getProjectionMatrix());
Vector3d cameraPos = info.getProjectedView();
InstancedRenderDispatcher.renderBreaking(world, viewProjection, cameraPos.x, cameraPos.y, cameraPos.z);

View file

@ -30,7 +30,7 @@ public abstract class StoreProjectionMatrixMixin {
@Inject(method = "loadProjectionMatrix", at = @At("TAIL"))
private void onProjectionMatrixLoad(Matrix4f projection, CallbackInfo ci) {
if (shouldCopy) {
Backend.setProjectionMatrix(projection.copy());
Backend.getInstance().setProjectionMatrix(projection.copy());
shouldCopy = false;
}
}

View file

@ -1,20 +1,11 @@
package com.simibubi.create.foundation.render;
import com.jozufozu.flywheel.backend.gl.attrib.CommonAttributes;
import com.jozufozu.flywheel.backend.gl.attrib.MatrixAttributes;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.core.Formats;
public class AllInstanceFormats {
public static final VertexFormat MODEL = litInstance()
.addAttributes(MatrixAttributes.MAT4,
MatrixAttributes.MAT3)
.build();
public static final VertexFormat ORIENTED = litInstance()
.addAttributes(CommonAttributes.VEC3, CommonAttributes.VEC3, CommonAttributes.QUATERNION)
.build();
public static VertexFormat ROTATING = kineticInstance()
.addAttributes(CommonAttributes.NORMAL)
.build();
@ -35,13 +26,8 @@ public class AllInstanceFormats {
CommonAttributes.FLOAT, CommonAttributes.FLOAT, CommonAttributes.FLOAT, CommonAttributes.FLOAT)
.build();
private static VertexFormat.Builder litInstance() {
return VertexFormat.builder()
.addAttributes(CommonAttributes.LIGHT, CommonAttributes.RGBA);
}
private static VertexFormat.Builder kineticInstance() {
return litInstance()
return Formats.litInstance()
.addAttributes(CommonAttributes.VEC3, CommonAttributes.FLOAT, CommonAttributes.FLOAT);
}
}

View file

@ -1,12 +1,10 @@
package com.simibubi.create.foundation.render;
import static com.jozufozu.flywheel.backend.Backend.register;
import com.jozufozu.flywheel.backend.gl.attrib.CommonAttributes;
import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.InstanceData;
import com.jozufozu.flywheel.backend.instancing.MaterialSpec;
import com.jozufozu.flywheel.core.materials.ModelData;
import com.jozufozu.flywheel.core.materials.OrientedData;
import com.jozufozu.flywheel.core.Formats;
import com.jozufozu.flywheel.event.GatherContextEvent;
import com.simibubi.create.Create;
import com.simibubi.create.content.contraptions.base.RotatingData;
import com.simibubi.create.content.contraptions.components.actors.ActorData;
@ -14,27 +12,33 @@ import com.simibubi.create.content.contraptions.relays.belt.BeltData;
import com.simibubi.create.content.logistics.block.FlapData;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class AllMaterialSpecs {
public static void init() {
// noop, make sure the static field are loaded.
}
public static final VertexFormat UNLIT_MODEL = VertexFormat.builder()
.addAttributes(CommonAttributes.VEC3, CommonAttributes.NORMAL, CommonAttributes.UV)
.build();
public static final MaterialSpec<RotatingData> ROTATING = new MaterialSpec<>(Locations.ROTATING, AllProgramSpecs.ROTATING, Formats.UNLIT_MODEL, AllInstanceFormats.ROTATING, RotatingData::new);
public static final MaterialSpec<BeltData> BELTS = new MaterialSpec<>(Locations.BELTS, AllProgramSpecs.BELT, Formats.UNLIT_MODEL, AllInstanceFormats.BELT, BeltData::new);
public static final MaterialSpec<ActorData> ACTORS = new MaterialSpec<>(Locations.ACTORS, AllProgramSpecs.ACTOR, Formats.UNLIT_MODEL, AllInstanceFormats.ACTOR, ActorData::new);
public static final MaterialSpec<FlapData> FLAPS = new MaterialSpec<>(Locations.FLAPS, AllProgramSpecs.FLAPS, Formats.UNLIT_MODEL, AllInstanceFormats.FLAP, FlapData::new);
public static final MaterialSpec<RotatingData> ROTATING = register(new MaterialSpec<>(Locations.ROTATING, AllProgramSpecs.ROTATING, UNLIT_MODEL, AllInstanceFormats.ROTATING, RotatingData::new));
public static final MaterialSpec<ModelData> TRANSFORMED = register(new MaterialSpec<>(Locations.MODEL, AllProgramSpecs.MODEL, UNLIT_MODEL, AllInstanceFormats.MODEL, ModelData::new));
public static final MaterialSpec<OrientedData> ORIENTED = register(new MaterialSpec<>(Locations.ORIENTED, AllProgramSpecs.ORIENTED, UNLIT_MODEL, AllInstanceFormats.ORIENTED, OrientedData::new));
public static <D extends InstanceData> MaterialSpec<D> register(MaterialSpec<D> spec) {
return Backend.getInstance().register(spec);
}
public static final MaterialSpec<BeltData> BELTS = register(new MaterialSpec<>(Locations.BELTS, AllProgramSpecs.BELT, UNLIT_MODEL, AllInstanceFormats.BELT, BeltData::new));
public static final MaterialSpec<ActorData> ACTORS = register(new MaterialSpec<>(Locations.ACTORS, AllProgramSpecs.ACTOR, UNLIT_MODEL, AllInstanceFormats.ACTOR, ActorData::new));
public static final MaterialSpec<FlapData> FLAPS = register(new MaterialSpec<>(Locations.FLAPS, AllProgramSpecs.FLAPS, UNLIT_MODEL, AllInstanceFormats.FLAP, FlapData::new));
@SubscribeEvent
public static void flwInit(GatherContextEvent event) {
register(ROTATING);
register(BELTS);
register(ACTORS);
register(FLAPS);
}
public static class Locations {
public static final ResourceLocation MODEL = new ResourceLocation("create", "model");
public static final ResourceLocation ORIENTED = new ResourceLocation("create", "oriented");
public static final ResourceLocation ROTATING = new ResourceLocation(Create.ID, "rotating");
public static final ResourceLocation BELTS = new ResourceLocation(Create.ID, "belts");
public static final ResourceLocation ACTORS = new ResourceLocation(Create.ID, "actors");

View file

@ -1,15 +1,11 @@
package com.simibubi.create.foundation.render;
import com.jozufozu.flywheel.Flywheel;
import com.simibubi.create.Create;
import net.minecraft.util.ResourceLocation;
public class AllProgramSpecs {
public static final ResourceLocation MODEL = new ResourceLocation(Flywheel.ID, "model");//, Locations.MODEL_VERT, Locations.BLOCK);
public static final ResourceLocation ORIENTED = new ResourceLocation(Flywheel.ID, "oriented");//, Locations.ORIENTED, Locations.BLOCK);
public static final ResourceLocation ROTATING = loc("rotating");
public static final ResourceLocation CHROMATIC = loc("chromatic");
public static final ResourceLocation BELT = loc("belt");

View file

@ -0,0 +1,46 @@
package com.simibubi.create.foundation.render;
import java.util.stream.Stream;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.SpecMetaRegistry;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
import com.jozufozu.flywheel.backend.loading.ModelTemplate;
import com.jozufozu.flywheel.core.WorldContext;
import com.jozufozu.flywheel.core.shader.gamestate.RainbowDebugStateProvider;
import com.jozufozu.flywheel.event.GatherContextEvent;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionProgram;
import com.simibubi.create.foundation.render.effects.EffectsContext;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class CreateContexts {
private static final ResourceLocation CONTRAPTION = new ResourceLocation("create", "context/contraption");
public static EffectsContext EFFECTS;
public static WorldContext<ContraptionProgram> CWORLD;
public static WorldContext<ContraptionProgram> STRUCTURE;
@SubscribeEvent
public static void flwInit(GatherContextEvent event) {
Backend backend = event.getBackend();
SpecMetaRegistry.register(RainbowDebugStateProvider.INSTANCE);
EFFECTS = backend.register(new EffectsContext(backend));
CWORLD = backend.register(contraptionContext(backend));
STRUCTURE = backend.register(contraptionContext(backend)
.withSpecStream(() -> Stream.of(AllProgramSpecs.STRUCTURE))
.withTemplateFactory(ModelTemplate::new));
}
private static WorldContext<ContraptionProgram> contraptionContext(Backend backend) {
return new WorldContext<>(backend, ContraptionProgram::new)
.withName(CONTRAPTION)
.withBuiltin(ShaderType.FRAGMENT, CONTRAPTION, "/builtin.frag")
.withBuiltin(ShaderType.VERTEX, CONTRAPTION, "/builtin.vert");
}
}

View file

@ -1,13 +0,0 @@
package com.simibubi.create.foundation.render;
import com.jozufozu.flywheel.backend.Backend;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher;
import com.simibubi.create.foundation.render.effects.EffectsContext;
public class CreateFlywheelHandler {
public static void init() {
Backend.register(ContraptionRenderDispatcher.TILES);
Backend.register(ContraptionRenderDispatcher.STRUCTURE);
Backend.register(EffectsContext.INSTANCE);
}
}

View file

@ -11,15 +11,13 @@ import net.minecraft.util.ResourceLocation;
public class EffectsContext extends ShaderContext<SphereFilterProgram> {
public static final EffectsContext INSTANCE = new EffectsContext();
public EffectsContext() {
super();
public EffectsContext(Backend backend) {
super(backend);
}
@Override
public void load() {
ProgramSpec programSpec = Backend.getSpec(AllProgramSpecs.CHROMATIC);
ProgramSpec programSpec = Backend.getInstance().getSpec(AllProgramSpecs.CHROMATIC);
try {
programs.put(programSpec.name, new SphereFilterProgram(loadAndLink(programSpec, null)));
@ -27,7 +25,7 @@ public class EffectsContext extends ShaderContext<SphereFilterProgram> {
Backend.log.debug("Loaded program {}", programSpec.name);
} catch (Exception e) {
Backend.log.error("Program '{}': {}", programSpec.name, e);
sourceRepo.notifyError();
backend.sources.notifyError();
}
}

View file

@ -12,6 +12,7 @@ import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.core.FullscreenQuad;
import com.jozufozu.flywheel.util.RenderUtil;
import com.simibubi.create.foundation.render.AllProgramSpecs;
import com.simibubi.create.foundation.render.CreateContexts;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import net.minecraft.client.MainWindow;
@ -29,11 +30,11 @@ public class EffectsHandler {
@Nullable
public static EffectsHandler getInstance() {
if (Backend.available() && instance == null) {
instance = new EffectsHandler();
if (Backend.getInstance().available() && instance == null) {
instance = new EffectsHandler(Backend.getInstance());
}
if (!Backend.available() && instance != null) {
if (!Backend.getInstance().available() && instance != null) {
instance.delete();
instance = null;
}
@ -49,12 +50,12 @@ public class EffectsHandler {
return Minecraft.getInstance().gameRenderer.getFarPlaneDistance() * 4;
}
private final Backend backend;
private final Framebuffer framebuffer;
private final ArrayList<FilterSphere> spheres;
public EffectsHandler() {
public EffectsHandler(Backend backend) {
this.backend = backend;
spheres = new ArrayList<>();
Framebuffer render = Minecraft.getInstance().getFramebuffer();
@ -79,10 +80,10 @@ public class EffectsHandler {
Framebuffer mainBuffer = Minecraft.getInstance().getFramebuffer();
Backend.compat.fbo.bindFramebuffer(FramebufferConstants.FRAME_BUFFER, framebuffer.framebufferObject);
backend.compat.fbo.bindFramebuffer(FramebufferConstants.FRAME_BUFFER, framebuffer.framebufferObject);
GL11.glClear(GL30.GL_COLOR_BUFFER_BIT);
SphereFilterProgram program = EffectsContext.INSTANCE.getProgram(AllProgramSpecs.CHROMATIC);
SphereFilterProgram program = CreateContexts.EFFECTS.getProgram(AllProgramSpecs.CHROMATIC);
program.bind();
program.bindColorTexture(mainBuffer.getColorAttachment());
@ -129,10 +130,10 @@ public class EffectsHandler {
program.unbind();
spheres.clear();
Backend.compat.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, framebuffer.framebufferObject);
Backend.compat.fbo.bindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, mainBuffer.framebufferObject);
Backend.compat.blit.blitFramebuffer(0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, 0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR);
Backend.compat.fbo.bindFramebuffer(FramebufferConstants.FRAME_BUFFER, mainBuffer.framebufferObject);
backend.compat.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, framebuffer.framebufferObject);
backend.compat.fbo.bindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, mainBuffer.framebufferObject);
backend.compat.blit.blitFramebuffer(0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, 0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR);
backend.compat.fbo.bindFramebuffer(FramebufferConstants.FRAME_BUFFER, mainBuffer.framebufferObject);
}
public void delete() {

View file

@ -19,7 +19,7 @@ public abstract class ColoredOverlayTileEntityRenderer<T extends TileEntity> ext
protected void renderSafe(T te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
if (Backend.canUseInstancing(te.getWorld())) return;
if (Backend.getInstance().canUseInstancing(te.getWorld())) return;
SuperByteBuffer render = render(getOverlayBuffer(te), getColor(te, partialTicks), light);
render.renderInto(ms, buffer.getBuffer(RenderType.getSolid()));

View file

@ -2,6 +2,7 @@
#flwinclude <"flywheel:core/lightutil.glsl">
varying vec3 BoxCoord;
varying vec2 BoxLight;
uniform sampler3D uLightVolume;
uniform sampler2D uBlockAtlas;