forked from processing/processing4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPGraphicsWebGPU.java
More file actions
58 lines (49 loc) · 1.37 KB
/
PGraphicsWebGPU.java
File metadata and controls
58 lines (49 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package processing.webgpu;
import processing.core.PGraphics;
import processing.core.PSurface;
public class PGraphicsWebGPU extends PGraphics {
private long windowId = 0;
@Override
public PSurface createSurface() {
return surface = new PSurfaceGLFW(this);
}
protected void initWebGPUSurface(long windowHandle, int width, int height, float scaleFactor) {
windowId = PWebGPU.createSurface(windowHandle, width, height, scaleFactor);
if (windowId == 0) {
System.err.println("Failed to create WebGPU surface");
}
}
@Override
public void setSize(int w, int h) {
super.setSize(w, h);
if (windowId != 0) {
PWebGPU.windowResized(windowId, pixelWidth, pixelHeight);
}
}
@Override
public void beginDraw() {
super.beginDraw();
checkSettings();
}
@Override
public void endDraw() {
super.endDraw();
PWebGPU.update();
}
@Override
public void dispose() {
super.dispose();
if (windowId != 0) {
PWebGPU.destroySurface(windowId);
windowId = 0;
}
PWebGPU.exit();
}
@Override
protected void backgroundImpl() {
if (windowId == 0) {
return;
}
PWebGPU.backgroundColor(windowId, backgroundR, backgroundG, backgroundB, backgroundA);
}
}