MCPcopy Create free account
hub / github.com/SpaiR/imgui-java / WindowSdl

Class WindowSdl

imgui-app/src/main/java/imgui/app/WindowSdl.java:51–188  ·  view source on GitHub ↗

SDL3 + SDL_GPU implementation of Window. Pumps SDL events through ImGuiImplSdl3#processEvent(long) each frame, acquires an SDL_GPU swapchain texture, and submits a clear-load render pass through ImGuiImplSdlGpu3#prepareDrawData(long, long) + {@link ImGuiImplSdlGpu

Source from the content-addressed store, hash-verified

49 * (skipped per task scope).
50 */
51public class WindowSdl extends Window {
52 private final ImGuiImplSdl3 imGuiSdl3 = new ImGuiImplSdl3();
53 private final ImGuiImplSdlGpu3 imGuiSdlGpu3 = new ImGuiImplSdlGpu3();
54
55 private long handle;
56 private long gpuDevice;
57 private boolean shouldClose;
58
59 @Override
60 protected void init(final Configuration config) {
61 if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
62 throw new IllegalStateException("Unable to initialize SDL3: " + SDL_GetError());
63 }
64
65 final long flags = SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_RESIZABLE;
66 handle = SDL_CreateWindow(config.getTitle(), config.getWidth(), config.getHeight(), flags);
67 if (handle == 0L) {
68 throw new RuntimeException("Failed to create the SDL window: " + SDL_GetError());
69 }
70 if (config.isFullScreen()) {
71 SDL_MaximizeWindow(handle);
72 }
73
74 // Create SDL_GPU device matching whatever shader format we ship.
75 final int shaderFormats = SDL_GPU_SHADERFORMAT_SPIRV | SDL_GPU_SHADERFORMAT_DXBC | SDL_GPU_SHADERFORMAT_METALLIB;
76 gpuDevice = SDL_CreateGPUDevice(shaderFormats, false, (java.nio.ByteBuffer) null);
77 if (gpuDevice == 0L) {
78 throw new RuntimeException("Failed to create the SDL_GPU device: " + SDL_GetError());
79 }
80 if (!SDL_ClaimWindowForGPUDevice(gpuDevice, handle)) {
81 throw new RuntimeException("Failed to claim window for SDL_GPU device: " + SDL_GetError());
82 }
83
84 owner.initImGui(config);
85
86 imGuiSdl3.initForSDLGPU(handle);
87
88 final ImGuiImplSdlGpu3.InitInfo initInfo = new ImGuiImplSdlGpu3.InitInfo()
89 .setDevice(gpuDevice)
90 .setColorTargetFormat(SDL_GetGPUSwapchainTextureFormat(gpuDevice, handle));
91 imGuiSdlGpu3.init(initInfo);
92 }
93
94 @Override
95 protected void dispose() {
96 imGuiSdlGpu3.shutdown();
97 imGuiSdl3.shutdown();
98 owner.disposeImGui();
99
100 if (gpuDevice != 0L && handle != 0L) {
101 SDL_ReleaseWindowFromGPUDevice(gpuDevice, handle);
102 }
103 if (gpuDevice != 0L) {
104 SDL_DestroyGPUDevice(gpuDevice);
105 gpuDevice = 0L;
106 }
107 if (handle != 0L) {
108 SDL_DestroyWindow(handle);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected