diff --git a/core/src/processing/webgpu/PGraphicsWebGPU.java b/core/src/processing/webgpu/PGraphicsWebGPU.java index 3e27967c4..cc6fcde98 100644 --- a/core/src/processing/webgpu/PGraphicsWebGPU.java +++ b/core/src/processing/webgpu/PGraphicsWebGPU.java @@ -11,8 +11,8 @@ public PSurface createSurface() { return surface = new PSurfaceGLFW(this); } - protected void initWebGPUSurface(long windowHandle, int width, int height, float scaleFactor) { - surfaceId = PWebGPU.createSurface(windowHandle, width, height, scaleFactor); + protected void initWebGPUSurface(long windowHandle, long displayHandle, int width, int height, float scaleFactor) { + surfaceId = PWebGPU.createSurface(windowHandle, displayHandle, width, height, scaleFactor); if (surfaceId == 0) { System.err.println("Failed to create WebGPU surface"); } diff --git a/core/src/processing/webgpu/PSurfaceGLFW.java b/core/src/processing/webgpu/PSurfaceGLFW.java index d9591d10e..f80131e19 100644 --- a/core/src/processing/webgpu/PSurfaceGLFW.java +++ b/core/src/processing/webgpu/PSurfaceGLFW.java @@ -1,11 +1,6 @@ package processing.webgpu; -import org.lwjgl.glfw.GLFW; -import org.lwjgl.glfw.GLFWErrorCallback; -import org.lwjgl.glfw.GLFWFramebufferSizeCallback; -import org.lwjgl.glfw.GLFWNativeCocoa; -import org.lwjgl.glfw.GLFWNativeWin32; -import org.lwjgl.glfw.GLFWWindowPosCallback; +import org.lwjgl.glfw.*; import org.lwjgl.system.MemoryUtil; import org.lwjgl.system.Platform; @@ -30,6 +25,7 @@ public class PSurfaceGLFW implements PSurface { protected PGraphics graphics; protected long window; + protected long display; protected boolean running = false; protected boolean paused; @@ -78,6 +74,8 @@ public void initFrame(PApplet sketch) { throw new RuntimeException("Failed to create GLFW window"); } + display = GLFW.glfwGetPrimaryMonitor(); + windowCount.incrementAndGet(); // event callbacks @@ -87,11 +85,12 @@ public void initFrame(PApplet sketch) { PWebGPU.init(); long windowHandle = getWindowHandle(); + long displayHandle = getDisplayHandle(); int width = sketch.sketchWidth(); int height = sketch.sketchHeight(); float scaleFactor = sketch.sketchPixelDensity(); - webgpu.initWebGPUSurface(windowHandle, width, height, scaleFactor); + webgpu.initWebGPUSurface(windowHandle, displayHandle, width, height, scaleFactor); } } @@ -123,6 +122,24 @@ public long getWindowHandle() { return GLFWNativeCocoa.glfwGetCocoaWindow(window); } else if (Platform.get() == Platform.WINDOWS) { return GLFWNativeWin32.glfwGetWin32Window(window); + } else if (Platform.get() == Platform.LINUX) { + // TODO: need to check if x11 or wayland + return GLFWNativeWayland.glfwGetWaylandWindow(window); + } else { + throw new UnsupportedOperationException("Window handle retrieval not implemented for this platform"); + } + } + + public long getDisplayHandle() { + if (Platform.get() == Platform.MACOSX) { + // TODO: Currently unsupported + return 0; + } else if (Platform.get() == Platform.WINDOWS) { + // TODO: Currently unsupported + return 0; + } else if (Platform.get() == Platform.LINUX) { + // TODO: need to check if x11 or wayland + return GLFWNativeWayland.glfwGetWaylandDisplay(); } else { throw new UnsupportedOperationException("Window handle retrieval not implemented for this platform"); } diff --git a/core/src/processing/webgpu/PWebGPU.java b/core/src/processing/webgpu/PWebGPU.java index e0a1a7630..d53dbd9d1 100644 --- a/core/src/processing/webgpu/PWebGPU.java +++ b/core/src/processing/webgpu/PWebGPU.java @@ -38,13 +38,14 @@ public static void init() { * Creates a WebGPU surface from a native window handle. * * @param windowHandle The native window handle + * @param displayHandle The native display handle * @param width Window width in physical pixels * @param height Window height in phsyical pixels * @param scaleFactor os provided scale factor * @return Window ID to use for subsequent operations */ - public static long createSurface(long windowHandle, int width, int height, float scaleFactor) { - long surfaceId = processing_create_surface(windowHandle, width, height, scaleFactor); + public static long createSurface(long windowHandle, long displayHandle, int width, int height, float scaleFactor) { + long surfaceId = processing_create_surface(windowHandle, displayHandle, width, height, scaleFactor); checkError(); return surfaceId; }