Skip to content

Commit 2232a0d

Browse files
authored
Merge pull request #1302 from tychedelia/1271-surface-creation
WebGPU surface creation / basic app lifecycle
2 parents 33b8b52 + fa83874 commit 2232a0d

File tree

13 files changed

+1961
-506
lines changed

13 files changed

+1961
-506
lines changed

core/build.gradle.kts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ dependencies {
3939
implementation(libs.jogl)
4040
implementation(libs.gluegen)
4141

42+
val lwjglVersion = "3.3.6"
43+
val lwjglNatives = when {
44+
System.getProperty("os.name").lowercase().contains("mac") -> {
45+
if (System.getProperty("os.arch").contains("aarch64")) {
46+
"natives-macos-arm64"
47+
} else {
48+
"natives-macos"
49+
}
50+
}
51+
System.getProperty("os.name").lowercase().contains("win") -> "natives-windows"
52+
System.getProperty("os.name").lowercase().contains("linux") -> "natives-linux"
53+
else -> "natives-linux"
54+
}
55+
56+
implementation(platform("org.lwjgl:lwjgl-bom:$lwjglVersion"))
57+
implementation("org.lwjgl", "lwjgl")
58+
implementation("org.lwjgl", "lwjgl-glfw")
59+
runtimeOnly("org.lwjgl", "lwjgl", classifier = lwjglNatives)
60+
runtimeOnly("org.lwjgl", "lwjgl-glfw", classifier = lwjglNatives)
61+
4262
testImplementation(libs.junit)
4363
}
4464

core/src/processing/core/PApplet.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9981,10 +9981,6 @@ static public void runSketch(final String[] args,
99819981
}
99829982
break;
99839983

9984-
case ARGS_DISABLE_AWT:
9985-
disableAWT = true;
9986-
break;
9987-
99889984
case ARGS_WINDOW_COLOR:
99899985
if (value.charAt(0) == '#' && value.length() == 7) {
99909986
value = value.substring(1);
@@ -10036,6 +10032,10 @@ static public void runSketch(final String[] args,
1003610032
fullScreen = true;
1003710033
break;
1003810034

10035+
case ARGS_DISABLE_AWT:
10036+
disableAWT = true;
10037+
break;
10038+
1003910039
default:
1004010040
name = args[argIndex];
1004110041
break label; // because of break, argIndex won't increment again

core/src/processing/core/PConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public interface PConstants {
7272
// Experimental JavaFX renderer; even better 2D performance
7373
String FX2D = "processing.javafx.PGraphicsFX2D";
7474

75+
String WEBGPU = "processing.webgpu.PGraphicsWebGPU";
76+
7577
String PDF = "processing.pdf.PGraphicsPDF";
7678
String SVG = "processing.svg.PGraphicsSVG";
7779
String DXF = "processing.dxf.RawDXF";
Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
11
package processing.webgpu;
22

3-
public class PGraphicsWebGPU {
3+
import processing.core.PGraphics;
4+
import processing.core.PSurface;
5+
6+
public class PGraphicsWebGPU extends PGraphics {
7+
private long windowId = 0;
8+
9+
@Override
10+
public PSurface createSurface() {
11+
return surface = new PSurfaceGLFW(this);
12+
}
13+
14+
protected void initWebGPUSurface(long windowHandle, int width, int height, float scaleFactor) {
15+
windowId = PWebGPU.createSurface(windowHandle, width, height, scaleFactor);
16+
if (windowId == 0) {
17+
System.err.println("Failed to create WebGPU surface");
18+
}
19+
}
20+
21+
@Override
22+
public void setSize(int w, int h) {
23+
super.setSize(w, h);
24+
if (windowId != 0) {
25+
PWebGPU.windowResized(windowId, pixelWidth, pixelHeight);
26+
}
27+
}
28+
29+
@Override
30+
public void endDraw() {
31+
super.endDraw();
32+
PWebGPU.update();
33+
}
34+
35+
@Override
36+
public void dispose() {
37+
super.dispose();
38+
39+
PWebGPU.exit();
40+
}
441
}

0 commit comments

Comments
 (0)