mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-29 08:26:37 +01:00
Fix crash on resource reload with flywheel disabled
- Closes #83 - Move engine selection to function - Rename Backend.log to Backend.LOGGER
This commit is contained in:
parent
1d8a5dc84e
commit
d38e2421c9
9 changed files with 37 additions and 33 deletions
|
@ -27,7 +27,7 @@ import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
|
|
||||||
public class Backend {
|
public class Backend {
|
||||||
public static final Logger log = LogManager.getLogger(Backend.class);
|
public static final Logger LOGGER = LogManager.getLogger(Backend.class);
|
||||||
|
|
||||||
protected static final Backend INSTANCE = new Backend();
|
protected static final Backend INSTANCE = new Backend();
|
||||||
public static Backend getInstance() {
|
public static Backend getInstance() {
|
||||||
|
@ -39,8 +39,6 @@ public class Backend {
|
||||||
public GLCapabilities capabilities;
|
public GLCapabilities capabilities;
|
||||||
public GlCompat compat;
|
public GlCompat compat;
|
||||||
|
|
||||||
private boolean enabled;
|
|
||||||
|
|
||||||
public final Loader loader;
|
public final Loader loader;
|
||||||
private final List<ShaderContext<?>> contexts = new ArrayList<>();
|
private final List<ShaderContext<?>> contexts = new ArrayList<>();
|
||||||
private final Map<ResourceLocation, StructType<?>> materialRegistry = new HashMap<>();
|
private final Map<ResourceLocation, StructType<?>> materialRegistry = new HashMap<>();
|
||||||
|
@ -93,7 +91,7 @@ public class Backend {
|
||||||
}
|
}
|
||||||
materialRegistry.put(name, spec);
|
materialRegistry.put(name, spec);
|
||||||
|
|
||||||
log.debug("registered material '" + name + "' with instance size " + spec.getLayout().getStride());
|
LOGGER.debug("registered material '" + name + "' with instance size " + spec.getLayout().getStride());
|
||||||
|
|
||||||
return spec;
|
return spec;
|
||||||
}
|
}
|
||||||
|
@ -104,20 +102,12 @@ public class Backend {
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
OptifineHandler.refresh();
|
OptifineHandler.refresh();
|
||||||
boolean usingShaders = OptifineHandler.usingShaders();
|
|
||||||
|
|
||||||
capabilities = GL.createCapabilities();
|
capabilities = GL.createCapabilities();
|
||||||
|
|
||||||
compat = new GlCompat(capabilities);
|
compat = new GlCompat(capabilities);
|
||||||
|
|
||||||
engine = FlwConfig.get()
|
engine = chooseEngine(compat);
|
||||||
.getEngine();
|
|
||||||
|
|
||||||
enabled = switch (engine) {
|
|
||||||
case OFF -> false;
|
|
||||||
case BATCHING -> !usingShaders;
|
|
||||||
case INSTANCING -> !usingShaders && compat.instancedArraysSupported();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<StructType<?>> allMaterials() {
|
public Collection<StructType<?>> allMaterials() {
|
||||||
|
@ -133,7 +123,7 @@ public class Backend {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isOn() {
|
public static boolean isOn() {
|
||||||
return getInstance().enabled;
|
return getInstance().engine != FlwEngine.OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canUseInstancing(@Nullable Level world) {
|
public static boolean canUseInstancing(@Nullable Level world) {
|
||||||
|
@ -174,4 +164,18 @@ public class Backend {
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static FlwEngine chooseEngine(GlCompat compat) {
|
||||||
|
FlwEngine preferredChoice = FlwConfig.get()
|
||||||
|
.getEngine();
|
||||||
|
|
||||||
|
boolean usingShaders = OptifineHandler.usingShaders();
|
||||||
|
boolean canUseEngine = switch (preferredChoice) {
|
||||||
|
case OFF -> true;
|
||||||
|
case BATCHING -> !usingShaders;
|
||||||
|
case INSTANCING -> !usingShaders && compat.instancedArraysSupported();
|
||||||
|
};
|
||||||
|
|
||||||
|
return canUseEngine ? preferredChoice : FlwEngine.OFF;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,10 +85,10 @@ public class Loader implements ResourceManagerReloadListener {
|
||||||
throw new ShaderLoadingException("Could not load all shaders, see log for details");
|
throw new ShaderLoadingException("Could not load all shaders, see log for details");
|
||||||
}
|
}
|
||||||
|
|
||||||
Backend.log.info("Loaded all shader programs.");
|
Backend.LOGGER.info("Loaded all shader programs.");
|
||||||
|
|
||||||
ClientLevel world = Minecraft.getInstance().level;
|
ClientLevel world = Minecraft.getInstance().level;
|
||||||
if (Backend.isFlywheelWorld(world)) {
|
if (Backend.canUseInstancing(world)) {
|
||||||
// TODO: looks like it might be good to have another event here
|
// TODO: looks like it might be good to have another event here
|
||||||
InstancedRenderDispatcher.resetInstanceWorld(world);
|
InstancedRenderDispatcher.resetInstanceWorld(world);
|
||||||
CrumblingRenderer.reset();
|
CrumblingRenderer.reset();
|
||||||
|
@ -118,7 +118,7 @@ public class Loader implements ResourceManagerReloadListener {
|
||||||
|
|
||||||
backend.register(spec);
|
backend.register(spec);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Backend.log.error(e);
|
Backend.LOGGER.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,9 +44,9 @@ public class OptifineHandler {
|
||||||
optifine = Package.getPackage(OPTIFINE_ROOT_PACKAGE);
|
optifine = Package.getPackage(OPTIFINE_ROOT_PACKAGE);
|
||||||
|
|
||||||
if (optifine == null) {
|
if (optifine == null) {
|
||||||
Backend.log.info("Optifine not detected.");
|
Backend.LOGGER.info("Optifine not detected.");
|
||||||
} else {
|
} else {
|
||||||
Backend.log.info("Optifine detected.");
|
Backend.LOGGER.info("Optifine detected.");
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ public class OptifineHandler {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Backend.log.info("No shader config found.");
|
Backend.LOGGER.info("No shader config found.");
|
||||||
}
|
}
|
||||||
return shadersOff;
|
return shadersOff;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public abstract class GlProgram extends GlObject {
|
||||||
int index = glGetUniformLocation(this.handle(), uniform);
|
int index = glGetUniformLocation(this.handle(), uniform);
|
||||||
|
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
Backend.log.debug("No active uniform '{}' exists in program '{}'. Could be unused.", uniform, this.name);
|
Backend.LOGGER.debug("No active uniform '{}' exists in program '{}'. Could be unused.", uniform, this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
|
|
|
@ -24,8 +24,8 @@ public class GlShader extends GlObject {
|
||||||
String log = GL20.glGetShaderInfoLog(handle);
|
String log = GL20.glGetShaderInfoLog(handle);
|
||||||
|
|
||||||
if (!log.isEmpty()) {
|
if (!log.isEmpty()) {
|
||||||
Backend.log.error("Shader compilation log for " + name + ": " + log);
|
Backend.LOGGER.error("Shader compilation log for " + name + ": " + log);
|
||||||
Backend.log.error(source);
|
Backend.LOGGER.error(source);
|
||||||
}
|
}
|
||||||
//Backend.log.debug(shader.printSource());
|
//Backend.log.debug(shader.printSource());
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class ProtoProgram {
|
||||||
String log = glGetProgramInfoLog(this.program);
|
String log = glGetProgramInfoLog(this.program);
|
||||||
|
|
||||||
if (!log.isEmpty()) {
|
if (!log.isEmpty()) {
|
||||||
Backend.log.debug("Program link log for " + parent.name + ": " + log);
|
Backend.LOGGER.debug("Program link log for " + parent.name + ": " + log);
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = glGetProgrami(this.program, GL_LINK_STATUS);
|
int result = glGetProgrami(this.program, GL_LINK_STATUS);
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class FileResolution {
|
||||||
builder.pointAtFile(span.getSourceFile())
|
builder.pointAtFile(span.getSourceFile())
|
||||||
.pointAt(span, 2);
|
.pointAt(span, 2);
|
||||||
}
|
}
|
||||||
Backend.log.error(builder.build());
|
Backend.LOGGER.error(builder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class ErrorReporter {
|
||||||
.pointAt(span, 2)
|
.pointAt(span, 2)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Backend.log.error(error);
|
Backend.LOGGER.error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateFileError(SourceFile file, String message) {
|
public static void generateFileError(SourceFile file, String message) {
|
||||||
|
@ -27,7 +27,7 @@ public class ErrorReporter {
|
||||||
.pointAtFile(file)
|
.pointAtFile(file)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Backend.log.error(error);
|
Backend.LOGGER.error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateMissingStruct(SourceFile file, Span vertexName, CharSequence msg) {
|
public static void generateMissingStruct(SourceFile file, Span vertexName, CharSequence msg) {
|
||||||
|
@ -45,7 +45,7 @@ public class ErrorReporter {
|
||||||
.pointAt(vertexName, 2)
|
.pointAt(vertexName, 2)
|
||||||
.hintIncludeFor(span.orElse(null), hint);
|
.hintIncludeFor(span.orElse(null), hint);
|
||||||
|
|
||||||
Backend.log.error(error.build());
|
Backend.LOGGER.error(error.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateMissingFunction(SourceFile file, CharSequence functionName, CharSequence msg) {
|
public static void generateMissingFunction(SourceFile file, CharSequence functionName, CharSequence msg) {
|
||||||
|
@ -62,6 +62,6 @@ public class ErrorReporter {
|
||||||
.pointAtFile(file)
|
.pointAtFile(file)
|
||||||
.hintIncludeFor(span.orElse(null), hint);
|
.hintIncludeFor(span.orElse(null), hint);
|
||||||
|
|
||||||
Backend.log.error(error.build());
|
Backend.LOGGER.error(error.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class WorldContext<P extends WorldProgram> implements ShaderContext<P> {
|
||||||
@Override
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
|
|
||||||
Backend.log.info("Loading context '{}'", name);
|
Backend.LOGGER.info("Loading context '{}'", name);
|
||||||
|
|
||||||
specStream.get()
|
specStream.get()
|
||||||
.map(backend::getSpec)
|
.map(backend::getSpec)
|
||||||
|
@ -46,10 +46,10 @@ public class WorldContext<P extends WorldProgram> implements ShaderContext<P> {
|
||||||
try {
|
try {
|
||||||
programs.put(spec.name, pipeline.compile(spec));
|
programs.put(spec.name, pipeline.compile(spec));
|
||||||
|
|
||||||
Backend.log.debug("Loaded program {}", spec.name);
|
Backend.LOGGER.debug("Loaded program {}", spec.name);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Backend.log.error("Error loading program {}", spec.name);
|
Backend.LOGGER.error("Error loading program {}", spec.name);
|
||||||
Backend.log.error("", e);
|
Backend.LOGGER.error("", e);
|
||||||
backend.loader.notifyError();
|
backend.loader.notifyError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue