mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 23:47:09 +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;
|
||||
|
||||
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();
|
||||
public static Backend getInstance() {
|
||||
|
@ -39,8 +39,6 @@ public class Backend {
|
|||
public GLCapabilities capabilities;
|
||||
public GlCompat compat;
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
public final Loader loader;
|
||||
private final List<ShaderContext<?>> contexts = new ArrayList<>();
|
||||
private final Map<ResourceLocation, StructType<?>> materialRegistry = new HashMap<>();
|
||||
|
@ -93,7 +91,7 @@ public class Backend {
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
@ -104,20 +102,12 @@ public class Backend {
|
|||
|
||||
public void refresh() {
|
||||
OptifineHandler.refresh();
|
||||
boolean usingShaders = OptifineHandler.usingShaders();
|
||||
|
||||
capabilities = GL.createCapabilities();
|
||||
|
||||
compat = new GlCompat(capabilities);
|
||||
|
||||
engine = FlwConfig.get()
|
||||
.getEngine();
|
||||
|
||||
enabled = switch (engine) {
|
||||
case OFF -> false;
|
||||
case BATCHING -> !usingShaders;
|
||||
case INSTANCING -> !usingShaders && compat.instancedArraysSupported();
|
||||
};
|
||||
engine = chooseEngine(compat);
|
||||
}
|
||||
|
||||
public Collection<StructType<?>> allMaterials() {
|
||||
|
@ -133,7 +123,7 @@ public class Backend {
|
|||
}
|
||||
|
||||
public static boolean isOn() {
|
||||
return getInstance().enabled;
|
||||
return getInstance().engine != FlwEngine.OFF;
|
||||
}
|
||||
|
||||
public static boolean canUseInstancing(@Nullable Level world) {
|
||||
|
@ -174,4 +164,18 @@ public class Backend {
|
|||
|
||||
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");
|
||||
}
|
||||
|
||||
Backend.log.info("Loaded all shader programs.");
|
||||
Backend.LOGGER.info("Loaded all shader programs.");
|
||||
|
||||
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
|
||||
InstancedRenderDispatcher.resetInstanceWorld(world);
|
||||
CrumblingRenderer.reset();
|
||||
|
@ -118,7 +118,7 @@ public class Loader implements ResourceManagerReloadListener {
|
|||
|
||||
backend.register(spec);
|
||||
} catch (Exception e) {
|
||||
Backend.log.error(e);
|
||||
Backend.LOGGER.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,9 +44,9 @@ public class OptifineHandler {
|
|||
optifine = Package.getPackage(OPTIFINE_ROOT_PACKAGE);
|
||||
|
||||
if (optifine == null) {
|
||||
Backend.log.info("Optifine not detected.");
|
||||
Backend.LOGGER.info("Optifine not detected.");
|
||||
} else {
|
||||
Backend.log.info("Optifine detected.");
|
||||
Backend.LOGGER.info("Optifine detected.");
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public class OptifineHandler {
|
|||
return false;
|
||||
});
|
||||
} catch (IOException e) {
|
||||
Backend.log.info("No shader config found.");
|
||||
Backend.LOGGER.info("No shader config found.");
|
||||
}
|
||||
return shadersOff;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public abstract class GlProgram extends GlObject {
|
|||
int index = glGetUniformLocation(this.handle(), uniform);
|
||||
|
||||
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;
|
||||
|
|
|
@ -24,8 +24,8 @@ public class GlShader extends GlObject {
|
|||
String log = GL20.glGetShaderInfoLog(handle);
|
||||
|
||||
if (!log.isEmpty()) {
|
||||
Backend.log.error("Shader compilation log for " + name + ": " + log);
|
||||
Backend.log.error(source);
|
||||
Backend.LOGGER.error("Shader compilation log for " + name + ": " + log);
|
||||
Backend.LOGGER.error(source);
|
||||
}
|
||||
//Backend.log.debug(shader.printSource());
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public class ProtoProgram {
|
|||
String log = glGetProgramInfoLog(this.program);
|
||||
|
||||
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);
|
||||
|
|
|
@ -73,7 +73,7 @@ public class FileResolution {
|
|||
builder.pointAtFile(span.getSourceFile())
|
||||
.pointAt(span, 2);
|
||||
}
|
||||
Backend.log.error(builder.build());
|
||||
Backend.LOGGER.error(builder.build());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ public class ErrorReporter {
|
|||
.pointAt(span, 2)
|
||||
.build();
|
||||
|
||||
Backend.log.error(error);
|
||||
Backend.LOGGER.error(error);
|
||||
}
|
||||
|
||||
public static void generateFileError(SourceFile file, String message) {
|
||||
|
@ -27,7 +27,7 @@ public class ErrorReporter {
|
|||
.pointAtFile(file)
|
||||
.build();
|
||||
|
||||
Backend.log.error(error);
|
||||
Backend.LOGGER.error(error);
|
||||
}
|
||||
|
||||
public static void generateMissingStruct(SourceFile file, Span vertexName, CharSequence msg) {
|
||||
|
@ -45,7 +45,7 @@ public class ErrorReporter {
|
|||
.pointAt(vertexName, 2)
|
||||
.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) {
|
||||
|
@ -62,6 +62,6 @@ public class ErrorReporter {
|
|||
.pointAtFile(file)
|
||||
.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
|
||||
public void load() {
|
||||
|
||||
Backend.log.info("Loading context '{}'", name);
|
||||
Backend.LOGGER.info("Loading context '{}'", name);
|
||||
|
||||
specStream.get()
|
||||
.map(backend::getSpec)
|
||||
|
@ -46,10 +46,10 @@ public class WorldContext<P extends WorldProgram> implements ShaderContext<P> {
|
|||
try {
|
||||
programs.put(spec.name, pipeline.compile(spec));
|
||||
|
||||
Backend.log.debug("Loaded program {}", spec.name);
|
||||
Backend.LOGGER.debug("Loaded program {}", spec.name);
|
||||
} catch (Exception e) {
|
||||
Backend.log.error("Error loading program {}", spec.name);
|
||||
Backend.log.error("", e);
|
||||
Backend.LOGGER.error("Error loading program {}", spec.name);
|
||||
Backend.LOGGER.error("", e);
|
||||
backend.loader.notifyError();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue