2023-04-08 01:01:03 +02:00
|
|
|
package com.jozufozu.flywheel.backend;
|
2022-08-23 07:17:36 +02:00
|
|
|
|
2023-04-03 08:58:28 +02:00
|
|
|
import com.jozufozu.flywheel.Flywheel;
|
|
|
|
import com.jozufozu.flywheel.api.backend.Backend;
|
2023-04-19 06:28:28 +02:00
|
|
|
import com.jozufozu.flywheel.backend.compile.IndirectPrograms;
|
|
|
|
import com.jozufozu.flywheel.backend.compile.InstancingPrograms;
|
2023-03-31 01:52:51 +02:00
|
|
|
import com.jozufozu.flywheel.backend.engine.batching.BatchingEngine;
|
|
|
|
import com.jozufozu.flywheel.backend.engine.indirect.IndirectEngine;
|
|
|
|
import com.jozufozu.flywheel.backend.engine.instancing.InstancingEngine;
|
2023-05-02 08:43:01 +02:00
|
|
|
import com.jozufozu.flywheel.gl.GlCompat;
|
2023-04-08 01:01:03 +02:00
|
|
|
import com.jozufozu.flywheel.lib.backend.SimpleBackend;
|
2023-03-31 01:52:51 +02:00
|
|
|
import com.jozufozu.flywheel.lib.context.Contexts;
|
|
|
|
import com.jozufozu.flywheel.lib.util.ShadersModHandler;
|
2022-08-23 07:17:36 +02:00
|
|
|
|
|
|
|
import net.minecraft.ChatFormatting;
|
|
|
|
import net.minecraft.network.chat.TextComponent;
|
|
|
|
|
2023-04-03 08:58:28 +02:00
|
|
|
public class Backends {
|
2022-08-23 07:17:36 +02:00
|
|
|
/**
|
|
|
|
* Use a thread pool to buffer instances in parallel on the CPU.
|
|
|
|
*/
|
2023-04-03 08:58:28 +02:00
|
|
|
public static final Backend BATCHING = SimpleBackend.builder()
|
2022-09-15 21:37:18 +02:00
|
|
|
.engineMessage(new TextComponent("Using Batching Engine").withStyle(ChatFormatting.GREEN))
|
2023-04-10 23:30:08 +02:00
|
|
|
.engineFactory(level -> new BatchingEngine(256))
|
2022-08-23 07:17:36 +02:00
|
|
|
.supported(() -> !ShadersModHandler.isShaderPackInUse())
|
2023-04-03 08:58:28 +02:00
|
|
|
.register(Flywheel.rl("batching"));
|
2022-08-23 07:17:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use GPU instancing to render everything.
|
|
|
|
*/
|
2023-04-03 08:58:28 +02:00
|
|
|
public static final Backend INSTANCING = SimpleBackend.builder()
|
2022-09-15 21:37:18 +02:00
|
|
|
.engineMessage(new TextComponent("Using Instancing Engine").withStyle(ChatFormatting.GREEN))
|
2023-04-10 23:30:08 +02:00
|
|
|
.engineFactory(level -> new InstancingEngine(256, Contexts.WORLD))
|
2023-04-03 08:58:28 +02:00
|
|
|
.fallback(() -> Backends.BATCHING)
|
2023-04-25 06:54:59 +02:00
|
|
|
.supported(() -> !ShadersModHandler.isShaderPackInUse() && GlCompat.supportsInstancing() && InstancingPrograms.allLoaded())
|
2023-04-03 08:58:28 +02:00
|
|
|
.register(Flywheel.rl("instancing"));
|
2022-08-23 07:17:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use Compute shaders to cull instances.
|
|
|
|
*/
|
2023-04-03 08:58:28 +02:00
|
|
|
public static final Backend INDIRECT = SimpleBackend.builder()
|
2022-09-15 21:37:18 +02:00
|
|
|
.engineMessage(new TextComponent("Using Indirect Engine").withStyle(ChatFormatting.GREEN))
|
2023-04-10 23:30:08 +02:00
|
|
|
.engineFactory(level -> new IndirectEngine(256))
|
2023-04-03 08:58:28 +02:00
|
|
|
.fallback(() -> Backends.INSTANCING)
|
2023-04-25 06:54:59 +02:00
|
|
|
.supported(() -> !ShadersModHandler.isShaderPackInUse() && GlCompat.supportsIndirect() && IndirectPrograms.allLoaded())
|
2023-04-03 08:58:28 +02:00
|
|
|
.register(Flywheel.rl("indirect"));
|
2022-09-15 21:37:18 +02:00
|
|
|
|
2022-08-23 07:17:36 +02:00
|
|
|
public static void init() {
|
2022-09-30 05:41:44 +02:00
|
|
|
}
|
2022-08-23 07:17:36 +02:00
|
|
|
}
|