Flywheel/src/main/java/com/jozufozu/flywheel/backend/Loader.java

51 lines
1.5 KiB
Java
Raw Normal View History

package com.jozufozu.flywheel.backend;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
import com.jozufozu.flywheel.backend.instancing.compile.FlwCompiler;
import com.jozufozu.flywheel.core.source.ShaderSources;
import com.jozufozu.flywheel.core.source.error.ErrorReporter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.server.packs.resources.ReloadableResourceManager;
import net.minecraft.server.packs.resources.ResourceManager;
2021-09-15 09:26:51 +02:00
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
/**
* The main entity for loading shaders.
*
* <p>
2021-09-15 09:26:51 +02:00
* This class is responsible for invoking the loading, parsing, and compilation stages.
* </p>
*/
2021-09-15 09:26:51 +02:00
public class Loader implements ResourceManagerReloadListener {
Loader() {
// Can be null when running datagenerators due to the unfortunate time we call this
Minecraft minecraft = Minecraft.getInstance();
if (minecraft == null) {
return;
}
if (minecraft.getResourceManager() instanceof ReloadableResourceManager reloadable) {
reloadable.registerReloadListener(this);
}
}
@Override
2021-09-15 09:26:51 +02:00
public void onResourceManagerReload(ResourceManager manager) {
Backend.refresh();
var errorReporter = new ErrorReporter();
ShaderSources sources = new ShaderSources(errorReporter, manager);
FlwCompiler.INSTANCE = new FlwCompiler(sources);
ClientLevel level = Minecraft.getInstance().level;
if (Backend.canUseInstancing(level)) {
InstancedRenderDispatcher.resetInstanceLevel(level);
}
2021-09-15 09:26:51 +02:00
}
}