2021-08-11 00:20:51 +02:00
|
|
|
package com.jozufozu.flywheel.backend;
|
|
|
|
|
|
|
|
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
|
|
|
import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer;
|
2022-05-17 21:56:09 +02:00
|
|
|
import com.jozufozu.flywheel.core.source.FileResolution;
|
|
|
|
import com.jozufozu.flywheel.core.source.ShaderLoadingException;
|
2022-01-13 06:25:03 +01:00
|
|
|
import com.jozufozu.flywheel.core.source.ShaderSources;
|
2022-05-17 21:56:09 +02:00
|
|
|
import com.jozufozu.flywheel.core.source.error.ErrorReporter;
|
2021-08-11 00:20:51 +02:00
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
2021-09-15 08:45:29 +02:00
|
|
|
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;
|
|
|
|
|
2021-08-11 00:20:51 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
2021-08-11 00:20:51 +02:00
|
|
|
* </p>
|
|
|
|
*/
|
2021-09-15 09:26:51 +02:00
|
|
|
public class Loader implements ResourceManagerReloadListener {
|
2021-08-13 20:23:09 +02:00
|
|
|
|
2022-01-13 06:25:03 +01:00
|
|
|
Loader() {
|
2021-08-11 02:39:11 +02:00
|
|
|
// Can be null when running datagenerators due to the unfortunate time we call this
|
|
|
|
Minecraft minecraft = Minecraft.getInstance();
|
|
|
|
if (minecraft != null) {
|
2021-09-15 08:45:29 +02:00
|
|
|
ResourceManager manager = minecraft.getResourceManager();
|
|
|
|
if (manager instanceof ReloadableResourceManager) {
|
|
|
|
((ReloadableResourceManager) manager).registerReloadListener(this);
|
2021-08-11 02:39:11 +02:00
|
|
|
}
|
2021-08-11 00:20:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-09-15 09:26:51 +02:00
|
|
|
public void onResourceManagerReload(ResourceManager manager) {
|
2022-01-13 06:25:03 +01:00
|
|
|
Backend.refresh();
|
2021-08-11 00:20:51 +02:00
|
|
|
|
2022-05-17 21:56:09 +02:00
|
|
|
var errorReporter = new ErrorReporter();
|
|
|
|
ShaderSources sources = new ShaderSources(errorReporter, manager);
|
2021-08-11 00:20:51 +02:00
|
|
|
|
2022-05-17 21:56:09 +02:00
|
|
|
FileResolution.run(errorReporter, sources);
|
2021-08-11 00:20:51 +02:00
|
|
|
|
2022-05-17 21:56:09 +02:00
|
|
|
if (errorReporter.hasErrored()) {
|
|
|
|
errorReporter.dump();
|
|
|
|
throw new ShaderLoadingException("Failed to resolve all source files, see log for details");
|
|
|
|
}
|
2021-08-11 00:20:51 +02:00
|
|
|
|
2022-07-23 02:24:41 +02:00
|
|
|
sources.postResolve();
|
|
|
|
|
|
|
|
FileResolution.checkAll(errorReporter);
|
|
|
|
|
2022-01-08 07:46:29 +01:00
|
|
|
Backend.LOGGER.info("Loaded all shader sources.");
|
2021-08-11 00:20:51 +02:00
|
|
|
|
2021-12-23 06:35:48 +01:00
|
|
|
ClientLevel world = Minecraft.getInstance().level;
|
2021-12-31 00:15:25 +01:00
|
|
|
if (Backend.canUseInstancing(world)) {
|
2021-12-23 06:35:48 +01:00
|
|
|
// TODO: looks like it might be good to have another event here
|
|
|
|
InstancedRenderDispatcher.resetInstanceWorld(world);
|
|
|
|
CrumblingRenderer.reset();
|
2021-08-11 00:20:51 +02:00
|
|
|
}
|
2021-09-15 09:26:51 +02:00
|
|
|
|
2021-08-11 00:20:51 +02:00
|
|
|
}
|
|
|
|
}
|