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-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-03-30 21:59:09 +02:00
|
|
|
import com.jozufozu.flywheel.gl.versioned.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-06 03:03:25 +02:00
|
|
|
.engineFactory(level -> new BatchingEngine())
|
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-06 03:03:25 +02:00
|
|
|
.engineFactory(level -> new InstancingEngine(Contexts.WORLD, 100))
|
2023-04-03 08:58:28 +02:00
|
|
|
.fallback(() -> Backends.BATCHING)
|
2022-08-23 07:17:36 +02:00
|
|
|
.supported(() -> !ShadersModHandler.isShaderPackInUse() && GlCompat.getInstance()
|
|
|
|
.instancedArraysSupported())
|
2022-10-08 23:02:54 +02:00
|
|
|
.pipelineShader(Pipelines.INSTANCED_ARRAYS)
|
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-06 03:03:25 +02:00
|
|
|
.engineFactory(level -> new IndirectEngine(100))
|
2023-04-03 08:58:28 +02:00
|
|
|
.fallback(() -> Backends.INSTANCING)
|
2022-08-23 07:17:36 +02:00
|
|
|
.supported(() -> !ShadersModHandler.isShaderPackInUse() && GlCompat.getInstance()
|
|
|
|
.supportsIndirect())
|
2022-10-08 23:02:54 +02:00
|
|
|
.pipelineShader(Pipelines.INDIRECT)
|
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
|
|
|
}
|