Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/processing/webgpu/PGraphicsWebGPU.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
31 changes: 24 additions & 7 deletions core/src/processing/webgpu/PSurfaceGLFW.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -78,6 +74,8 @@ public void initFrame(PApplet sketch) {
throw new RuntimeException("Failed to create GLFW window");
}

display = GLFW.glfwGetPrimaryMonitor();

windowCount.incrementAndGet();

// event callbacks
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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");
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/processing/webgpu/PWebGPU.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading