Skip to content

Commit 5d91529

Browse files
committed
Cleaned up ImGui implementation
1 parent c5aae91 commit 5d91529

File tree

8 files changed

+9
-68
lines changed

8 files changed

+9
-68
lines changed

common/src/main/java/foundry/veil/api/client/render/VeilRenderSystem.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import foundry.veil.ext.LevelRendererExtension;
3232
import foundry.veil.ext.TextureManagerExtension;
3333
import foundry.veil.ext.VertexBufferExtension;
34+
import foundry.veil.impl.client.imgui.AdvancedFboImGuiAreaImpl;
3435
import foundry.veil.impl.client.imgui.VeilImGuiImpl;
3536
import foundry.veil.impl.client.necromancer.render.NecromancerRenderDispatcher;
3637
import foundry.veil.impl.client.render.dynamicbuffer.VanillaShaderCompiler;
@@ -1176,6 +1177,7 @@ public static void beginFrame() {
11761177

11771178
@ApiStatus.Internal
11781179
public static void endFrame() {
1180+
AdvancedFboImGuiAreaImpl.end();
11791181
VeilImGuiImpl.get().endFrame();
11801182

11811183
if (Veil.platform().hasErrors()) {

common/src/main/java/foundry/veil/impl/client/editor/ShaderInspector.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,6 @@ public void addShaders(ObjIntConsumer<ResourceLocation> registry) {
771771
for (ShaderProgram shader : shaders.values()) {
772772
registry.accept(shader.getName(), shader.getProgram());
773773
}
774-
VeilImGuiImpl.get().addImguiShaders(registry);
775774
}
776775
},
777776
IRIS(Component.translatable("inspector.veil.shader.source.iris"), () -> IrisCompat.INSTANCE != null) {

common/src/main/java/foundry/veil/impl/client/imgui/InactiveVeilImGuiImpl.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,7 @@ public void beginFrame() {
2424
public void endFrame() {
2525
}
2626

27-
@Override
28-
public void toggle() {
29-
}
30-
3127
@Override
3228
public void updateFonts() {
3329
}
34-
35-
@Override
36-
public void addImguiShaders(ObjIntConsumer<ResourceLocation> registry) {
37-
}
3830
}

common/src/main/java/foundry/veil/impl/client/imgui/VeilImGui.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package foundry.veil.impl.client.imgui;
22

3-
import net.minecraft.resources.ResourceLocation;
43
import org.jetbrains.annotations.ApiStatus;
54

6-
import java.util.function.ObjIntConsumer;
7-
85
/**
96
* Manages the internal ImGui state.
107
*
@@ -21,9 +18,5 @@ public interface VeilImGui {
2118

2219
void endFrame();
2320

24-
void toggle();
25-
2621
void updateFonts();
27-
28-
void addImguiShaders(ObjIntConsumer<ResourceLocation> registry);
2922
}

common/src/main/java/foundry/veil/impl/client/imgui/VeilImGuiImpl.java

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@
99
import imgui.flag.ImGuiConfigFlags;
1010
import imgui.gl3.ImGuiImplGl3;
1111
import imgui.internal.ImGuiContext;
12-
import net.minecraft.resources.ResourceLocation;
1312
import org.jetbrains.annotations.ApiStatus;
1413
import org.lwjgl.system.NativeResource;
1514

16-
import java.lang.invoke.MethodHandle;
17-
import java.lang.invoke.MethodHandles;
1815
import java.util.concurrent.atomic.AtomicBoolean;
19-
import java.util.function.ObjIntConsumer;
2016

2117
import static org.lwjgl.glfw.GLFW.glfwGetCurrentContext;
2218
import static org.lwjgl.glfw.GLFW.glfwMakeContextCurrent;
@@ -27,30 +23,6 @@
2723
@ApiStatus.Internal
2824
public class VeilImGuiImpl implements VeilImGui, NativeResource {
2925

30-
private static final MethodHandle DATA_GETTER;
31-
private static final MethodHandle SHADER_GETTER;
32-
33-
static {
34-
MethodHandle dataGetter;
35-
MethodHandle shaderGetter;
36-
37-
try {
38-
Class<?> dataClass = Class.forName("imgui.gl3.ImGuiImplGl3$Data");
39-
MethodHandles.Lookup dataLookup = MethodHandles.privateLookupIn(ImGuiImplGl3.class, MethodHandles.lookup());
40-
dataGetter = dataLookup.findGetter(ImGuiImplGl3.class, "data", dataClass);
41-
42-
MethodHandles.Lookup shaderLookup = MethodHandles.privateLookupIn(dataClass, dataLookup);
43-
shaderGetter = shaderLookup.findGetter(dataClass, "shaderHandle", int.class);
44-
} catch (Throwable t) {
45-
Veil.LOGGER.error("Failed to get ImGui shader handle: {}", t.getMessage());
46-
dataGetter = null;
47-
shaderGetter = null;
48-
}
49-
50-
DATA_GETTER = dataGetter;
51-
SHADER_GETTER = shaderGetter;
52-
}
53-
5426
private static VeilImGui instance = new InactiveVeilImGuiImpl();
5527

5628
private final VeilImGuiImplGlfw implGlfw;
@@ -59,7 +31,7 @@ public class VeilImGuiImpl implements VeilImGui, NativeResource {
5931
private final ImPlotContext imPlotContext;
6032
private final AtomicBoolean active;
6133

62-
private VeilImGuiImpl(long window) throws Throwable {
34+
private VeilImGuiImpl(long window) {
6335
this.implGlfw = new VeilImGuiImplGlfw(this);
6436
this.implGl3 = new ImGuiImplGl3();
6537

@@ -135,8 +107,6 @@ public void beginFrame() {
135107

136108
@Override
137109
public void endFrame() {
138-
AdvancedFboImGuiAreaImpl.end();
139-
140110
try {
141111
if (!this.active.get()) {
142112
Veil.LOGGER.error("ImGui state de-synced");
@@ -161,11 +131,6 @@ public void endFrame() {
161131
}
162132
}
163133

164-
@Override
165-
public void toggle() {
166-
VeilRenderSystem.renderer().getEditorManager().toggle();
167-
}
168-
169134
@Override
170135
public void updateFonts() {
171136
this.implGl3.destroyFontsTexture();
@@ -174,18 +139,6 @@ public void updateFonts() {
174139
}
175140
}
176141

177-
@Override
178-
public void addImguiShaders(ObjIntConsumer<ResourceLocation> registry) {
179-
if (DATA_GETTER != null && SHADER_GETTER != null) {
180-
try {
181-
int handle = (int) SHADER_GETTER.invoke(DATA_GETTER.invoke(this.implGl3));
182-
registry.accept(ResourceLocation.fromNamespaceAndPath("imgui", "blit"), handle);
183-
} catch (Throwable t) {
184-
Veil.LOGGER.warn("Failed to add ImGui shader", t);
185-
}
186-
}
187-
}
188-
189142
@Override
190143
public void free() {
191144
try {

fabric/src/main/java/foundry/veil/fabric/mixin/client/KeyboardHandlerMixin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package foundry.veil.fabric.mixin.client;
22

33
import foundry.veil.VeilClient;
4+
import foundry.veil.api.client.render.VeilRenderSystem;
45
import foundry.veil.impl.client.imgui.VeilImGuiImpl;
56
import net.minecraft.client.KeyboardHandler;
67
import net.minecraft.client.Minecraft;
@@ -23,7 +24,7 @@ public class KeyboardHandlerMixin {
2324
@Inject(method = "keyPress", at = @At("TAIL"))
2425
public void keyPress(long window, int key, int scancode, int action, int mods, CallbackInfo ci) {
2526
if (window == this.minecraft.getWindow().getWindow() && action == GLFW_PRESS && VeilClient.EDITOR_KEY.matches(key, scancode)) {
26-
VeilImGuiImpl.get().toggle();
27+
VeilRenderSystem.renderer().getEditorManager().toggle();
2728
}
2829
}
2930
}

fabric/src/main/java/foundry/veil/fabric/mixin/client/MouseHandlerMixin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package foundry.veil.fabric.mixin.client;
22

33
import foundry.veil.VeilClient;
4+
import foundry.veil.api.client.render.VeilRenderSystem;
45
import foundry.veil.impl.client.imgui.VeilImGuiImpl;
56
import net.minecraft.client.Minecraft;
67
import net.minecraft.client.MouseHandler;
@@ -23,7 +24,7 @@ public class MouseHandlerMixin {
2324
@Inject(method = "onPress", at = @At("HEAD"))
2425
public void keyPress(long window, int button, int action, int mods, CallbackInfo ci) {
2526
if (window == this.minecraft.getWindow().getWindow() && action == GLFW_PRESS && VeilClient.EDITOR_KEY.matchesMouse(button)) {
26-
VeilImGuiImpl.get().toggle();
27+
VeilRenderSystem.renderer().getEditorManager().toggle();
2728
}
2829
}
2930
}

neoforge/src/main/java/foundry/veil/forge/VeilForgeClientEvents.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static void clientDisconnected(ClientPlayerNetworkEvent.LoggingOut event)
4747
@SubscribeEvent
4848
public static void keyPressed(InputEvent.Key event) {
4949
if (event.getAction() == GLFW_PRESS && VeilClient.EDITOR_KEY.matches(event.getKey(), event.getScanCode())) {
50-
VeilImGuiImpl.get().toggle();
50+
VeilRenderSystem.renderer().getEditorManager().toggle();
5151
}
5252
}
5353

@@ -114,7 +114,7 @@ public static void registerClientCommands(RegisterClientCommandsEvent event) {
114114
@SubscribeEvent
115115
public static void mousePressed(InputEvent.MouseButton.Pre event) {
116116
if (event.getAction() == GLFW_PRESS && VeilClient.EDITOR_KEY.matchesMouse(event.getButton())) {
117-
VeilImGuiImpl.get().toggle();
117+
VeilRenderSystem.renderer().getEditorManager().toggle();
118118
}
119119
}
120120

0 commit comments

Comments
 (0)