Conditional state restore and BufferUploader sanity check

- Only restore state that has changed
 - Sanity check to fix error condition on reset
This commit is contained in:
Jozufozu 2022-01-08 16:48:42 -08:00
parent 3391e3e168
commit b2c03a4069
3 changed files with 73 additions and 36 deletions

View file

@ -45,11 +45,18 @@ public class GlStateTracker {
GlBufferType[] values = GlBufferType.values();
for (int i = 0; i < values.length; i++) {
if (buffers[i] != GlStateTracker.buffers[i]) {
GlStateManager._glBindBuffer(values[i].glEnum, buffers[i]);
}
}
if (vao != GlStateTracker.vao) {
GlStateManager._glBindVertexArray(vao);
}
if (program != GlStateTracker.program) {
GlStateManager._glUseProgram(program);
}
}
}
}

View file

@ -0,0 +1,29 @@
package com.jozufozu.flywheel.mixin;
import javax.annotation.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.jozufozu.flywheel.backend.gl.GlStateTracker;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.blaze3d.vertex.VertexFormat;
@Mixin(BufferUploader.class)
public class BufferUploaderMixin {
@Shadow
@Nullable
private static VertexFormat lastFormat;
@Inject(method = "reset", at = @At("HEAD"))
private static void stopBufferUploaderFromClearingBufferStateIfNothingIsBound(CallbackInfo ci) {
// Trust our tracker over BufferUploader's.
if (GlStateTracker.getVertexArray() == 0) {
lastFormat = null;
}
}
}

View file

@ -7,6 +7,7 @@
"client": [
"BlockEntityTypeMixin",
"BufferBuilderMixin",
"BufferUploaderMixin",
"CameraMixin",
"CancelEntityRenderMixin",
"ChunkRebuildHooksMixin",