2021-08-11 00:20:51 +02:00
|
|
|
package com.jozufozu.flywheel.backend;
|
|
|
|
|
|
|
|
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
2022-09-30 05:41:44 +02:00
|
|
|
import com.jozufozu.flywheel.backend.instancing.compile.FlwCompiler;
|
2022-05-17 21:56:09 +02:00
|
|
|
import com.jozufozu.flywheel.core.source.FileResolution;
|
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-07-24 03:18:48 +02:00
|
|
|
Backend.LOGGER.info("Loaded all shader sources in " + sources.getLoadTime());
|
|
|
|
|
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()) {
|
2022-08-07 02:17:46 +02:00
|
|
|
throw errorReporter.dump();
|
2022-05-17 21:56:09 +02:00
|
|
|
}
|
2021-08-11 00:20:51 +02:00
|
|
|
|
2022-07-23 02:24:41 +02:00
|
|
|
sources.postResolve();
|
|
|
|
|
2022-07-24 03:18:48 +02:00
|
|
|
Backend.LOGGER.info("Successfully resolved all source files.");
|
|
|
|
|
2022-07-23 02:24:41 +02:00
|
|
|
FileResolution.checkAll(errorReporter);
|
|
|
|
|
2022-07-24 03:18:48 +02:00
|
|
|
Backend.LOGGER.info("All shaders passed checks.");
|
|
|
|
|
2022-09-30 05:41:44 +02:00
|
|
|
FlwCompiler.INSTANCE.run();
|
2021-08-11 00:20:51 +02:00
|
|
|
|
2022-09-16 22:32:13 +02:00
|
|
|
ClientLevel level = Minecraft.getInstance().level;
|
|
|
|
if (Backend.canUseInstancing(level)) {
|
|
|
|
InstancedRenderDispatcher.resetInstanceLevel(level);
|
2021-08-11 00:20:51 +02:00
|
|
|
}
|
2021-09-15 09:26:51 +02:00
|
|
|
|
2021-08-11 00:20:51 +02:00
|
|
|
}
|
|
|
|
}
|