@kmamal/sdl 0.8.4 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -8
- package/package.json +1 -1
- package/src/javascript/video/window.js +13 -0
- package/src/native/binding.cpp +11 -10
- package/src/native/cocoa-window.h +3 -1
- package/src/native/cocoa-window.mm +11 -1
- package/src/native/sdl-helpers.cpp +72 -58
- package/src/native/sdl-helpers.h +2 -1
- package/src/types/index.d.ts +3 -0
package/README.md
CHANGED
|
@@ -12,11 +12,11 @@ Prebuilt binaries are available for x64 architectures, arm-based Macs, and Raspb
|
|
|
12
12
|
|
|
13
13
|
#### Canvas, WebGL, and WebGPU
|
|
14
14
|
|
|
15
|
-
One goal of this project is to allow using Canvas
|
|
16
|
-
You can
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
One goal of this project is to allow using Canvas, WebGL, and WebGPU without a browser.
|
|
16
|
+
You can use the [canvas](https://www.npmjs.com/package/canvas) package to render using the canvas API.
|
|
17
|
+
For WebGL you can use [@kmamal/gl](https://github.com/kmamal/headless-gl#readme) and for WebGPU you can use [@kmamal/gpu](https://github.com/kmamal/gpu#readme).
|
|
18
|
+
Both WebGL and WebGPU support rendering directly to the window (without any intermediate buffer copying).
|
|
19
|
+
Canvas still uses an intermediate buffer, but that might change in the future.
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
## Installation
|
|
@@ -65,7 +65,7 @@ window.render(width, height, width * 4, 'bgra32', buffer)
|
|
|
65
65
|
import sdl from '@kmamal/sdl'
|
|
66
66
|
import createContext from '@kmamal/gl'
|
|
67
67
|
|
|
68
|
-
const window = sdl.video.createWindow({title: "WebGL", opengl: true })
|
|
68
|
+
const window = sdl.video.createWindow({ title: "WebGL", opengl: true })
|
|
69
69
|
const { pixelWidth: width, pixelHeight: height, native } = window
|
|
70
70
|
const gl = createContext(width, height, { window: native })
|
|
71
71
|
|
|
@@ -75,6 +75,38 @@ gl.clear(gl.COLOR_BUFFER_BIT)
|
|
|
75
75
|
gl.swap()
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
+
### WebGPU
|
|
79
|
+
```js
|
|
80
|
+
import sdl from '@kmamal/sdl'
|
|
81
|
+
import gpu from '@kmamal/gpu'
|
|
82
|
+
|
|
83
|
+
const window = sdl.video.createWindow({ title: "WebGPU", webgpu: true })
|
|
84
|
+
|
|
85
|
+
const instance = gpu.create([])
|
|
86
|
+
const adapter = await instance.requestAdapter()
|
|
87
|
+
const device = await adapter.requestDevice()
|
|
88
|
+
|
|
89
|
+
const renderer = gpu.renderGPUDeviceToWindow({ device, window })
|
|
90
|
+
|
|
91
|
+
// Clear screen to red
|
|
92
|
+
const commandEncoder = device.createCommandEncoder()
|
|
93
|
+
const renderPass = commandEncoder.beginRenderPass({
|
|
94
|
+
colorAttachments: [
|
|
95
|
+
{
|
|
96
|
+
view: renderer.getCurrentTextureView(),
|
|
97
|
+
clearValue: { r: 1.0, g: 0.0, b: 0.0, a: 1.0 },
|
|
98
|
+
loadOp: 'clear',
|
|
99
|
+
storeOp: 'store',
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
})
|
|
103
|
+
renderPass.end()
|
|
104
|
+
device.queue.submit([ commandEncoder.finish() ])
|
|
105
|
+
|
|
106
|
+
renderer.swap()
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
|
|
78
110
|
There are more examples [in the `examples/` folder](https://github.com/kmamal/node-sdl/tree/master/examples).
|
|
79
111
|
|
|
80
112
|
|
|
@@ -148,6 +180,7 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
148
180
|
* [window.vsync](#windowvsync)
|
|
149
181
|
* [window.setVsync(vsync)](#windowsetvsyncvsync)
|
|
150
182
|
* [window.opengl](#windowopengl)
|
|
183
|
+
* [window.webgpu](#windowwebgpu)
|
|
151
184
|
* [window.native](#windownative)
|
|
152
185
|
* [window.maximized](#windowmaximized)
|
|
153
186
|
* [window.maximize()](#windowmaximize)
|
|
@@ -542,6 +575,7 @@ The window that the mouse is hovered over, or `null` if the mouse is not over a
|
|
|
542
575
|
* `accelerated: <boolean>` Set to `false` to disable hardware accelerated rendering. Default: `true`
|
|
543
576
|
* `vsync: <boolean>` Set to `false` to disable frame rate synchronization. Default: `true`
|
|
544
577
|
* `opengl: <boolean>` Set to `true` to create an OpenGL-compatible window (for use with [@kmamal/gl](https://github.com/kmamal/headless-gl#readme)). Default: `false`
|
|
578
|
+
* `webgpu: <boolean>` Set to `true` to create an WebGPU-compatible window (for use with [@kmamal/gpu](https://github.com/kmamal/gpu#readme)). Default: `false`
|
|
545
579
|
* `skipTaskbar: <boolean>` X11 only. Set to `true` to not add this window to the taskbar. Default: `false`
|
|
546
580
|
* `popupMenu: <boolean>` X11 only. Set to `true` to treat this window like a popup menu. Default: `false`
|
|
547
581
|
* `tooltip: <boolean>` X11 only. Set to `true` to treat this window like a tooltip. Default: `false`
|
|
@@ -553,9 +587,11 @@ Creates a new window.
|
|
|
553
587
|
The following restrictions apply:
|
|
554
588
|
* If you specify the `display` option, you can't also specify the `x` or `y` options, and vice-versa.
|
|
555
589
|
* The `resizable` and `borderless` options are mutually exclusive.
|
|
590
|
+
* The `opengl` and `webgpu` options are mutually exclusive.
|
|
556
591
|
* The `vsync` option only applies to windows that are also `accelerated`.
|
|
592
|
+
* The `accelerated` and `vsync` options have no effect if either `opengl` or `webgpu` is also specified.
|
|
557
593
|
|
|
558
|
-
If you set the `opengl`
|
|
594
|
+
If you set the `opengl` or `webgpu` options, then you can only render to the window with OpenGL/WebGPU calls.
|
|
559
595
|
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer) will fail.
|
|
560
596
|
|
|
561
597
|
## class Window
|
|
@@ -867,6 +903,8 @@ Will be `true` if the window is using hardware accelerated rendering.
|
|
|
867
903
|
|
|
868
904
|
Changes the window's accelerated property.
|
|
869
905
|
|
|
906
|
+
If you have set the `opengl` or `webgpu` options, then calls to this function will fail.
|
|
907
|
+
|
|
870
908
|
### window.vsync
|
|
871
909
|
|
|
872
910
|
* `<boolean>`
|
|
@@ -881,6 +919,8 @@ Note that vsync can only be used if that window is also [`accelerated`](#windowa
|
|
|
881
919
|
|
|
882
920
|
Changes the window's vsync property.
|
|
883
921
|
|
|
922
|
+
If you have set the `opengl` or `webgpu` options, then calls to this function will fail.
|
|
923
|
+
|
|
884
924
|
### window.opengl
|
|
885
925
|
|
|
886
926
|
* `<boolean>`
|
|
@@ -889,12 +929,20 @@ Will be `true` if the window was created in OpenGl mode.
|
|
|
889
929
|
In OpenGL mode, you can only render to the window with OpenGL calls.
|
|
890
930
|
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer) will fail.
|
|
891
931
|
|
|
932
|
+
### window.webgpu
|
|
933
|
+
|
|
934
|
+
* `<boolean>`
|
|
935
|
+
|
|
936
|
+
Will be `true` if the window was created in WebGPU mode.
|
|
937
|
+
In WebGPU mode, you can only render to the window with WebGPU calls.
|
|
938
|
+
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer) will fail.
|
|
939
|
+
|
|
892
940
|
### window.native
|
|
893
941
|
|
|
894
942
|
* `<any>`
|
|
895
943
|
|
|
896
944
|
Holds a copy of the native (platform-specific) representation of the window.
|
|
897
|
-
Only used for passing to [@kmamal/gl](https://github.com/kmamal/headless-gl#readme).
|
|
945
|
+
Only used for passing to [@kmamal/gl](https://github.com/kmamal/headless-gl#readme) or [@kmamal/gpu](https://github.com/kmamal/gpu#readme).
|
|
898
946
|
|
|
899
947
|
### window.maximized
|
|
900
948
|
|
|
@@ -975,6 +1023,9 @@ Such a window will always be treated as a utility window.
|
|
|
975
1023
|
Displays an image in the window.
|
|
976
1024
|
The provided image will be stretched over the entire window.
|
|
977
1025
|
|
|
1026
|
+
If you set the `opengl` or `webgpu` options, then you can only render to the window with OpenGL/WebGPU calls.
|
|
1027
|
+
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer) will fail.
|
|
1028
|
+
|
|
978
1029
|
### window.setIcon(width, height, stride, format, buffer)
|
|
979
1030
|
|
|
980
1031
|
* `width, height, stride, format, buffer: `[`<Image>`](#image-data) The image to display as the icon of the window.
|
package/package.json
CHANGED
|
@@ -48,6 +48,7 @@ class Window extends EventsViaPoll {
|
|
|
48
48
|
accelerated = true,
|
|
49
49
|
vsync = true,
|
|
50
50
|
opengl = false,
|
|
51
|
+
webgpu = false,
|
|
51
52
|
skipTaskbar = false,
|
|
52
53
|
popupMenu = false,
|
|
53
54
|
tooltip = false,
|
|
@@ -74,12 +75,14 @@ class Window extends EventsViaPoll {
|
|
|
74
75
|
if (typeof accelerated !== 'boolean') { throw Object.assign(new Error("accelerated must be a boolean"), { accelerated }) }
|
|
75
76
|
if (typeof vsync !== 'boolean') { throw Object.assign(new Error("vsync must be a boolean"), { vsync }) }
|
|
76
77
|
if (typeof opengl !== 'boolean') { throw Object.assign(new Error("opengl must be a boolean"), { opengl }) }
|
|
78
|
+
if (typeof webgpu !== 'boolean') { throw Object.assign(new Error("webgpu must be a boolean"), { webgpu }) }
|
|
77
79
|
if (typeof skipTaskbar !== 'boolean') { throw Object.assign(new Error("skipTaskbar must be a boolean"), { skipTaskbar }) }
|
|
78
80
|
if (typeof popupMenu !== 'boolean') { throw Object.assign(new Error("popupMenu must be a boolean"), { popupMenu }) }
|
|
79
81
|
if (typeof tooltip !== 'boolean') { throw Object.assign(new Error("tooltip must be a boolean"), { tooltip }) }
|
|
80
82
|
if (typeof utility !== 'boolean') { throw Object.assign(new Error("utility must be a boolean"), { utility }) }
|
|
81
83
|
if (display && (Number.isFinite(x) || Number.isFinite(y))) { throw Object.assign(new Error("display and x/y are mutually exclusive"), { display, x, y }) }
|
|
82
84
|
if (resizable && borderless) { throw Object.assign(new Error("resizable and borderless are mutually exclusive"), { resizable, borderless }) }
|
|
85
|
+
if (opengl && webgpu) { throw Object.assign(new Error("opengl and webgpu are mutually exclusive"), { opengl, webgpu }) }
|
|
83
86
|
|
|
84
87
|
let displayIndex = 0
|
|
85
88
|
if (display) {
|
|
@@ -104,6 +107,7 @@ class Window extends EventsViaPoll {
|
|
|
104
107
|
accelerated,
|
|
105
108
|
vsync,
|
|
106
109
|
opengl,
|
|
110
|
+
webgpu,
|
|
107
111
|
skipTaskbar,
|
|
108
112
|
popupMenu,
|
|
109
113
|
tooltip,
|
|
@@ -132,6 +136,7 @@ class Window extends EventsViaPoll {
|
|
|
132
136
|
this._title = title
|
|
133
137
|
this._visible = visible
|
|
134
138
|
this._opengl = opengl
|
|
139
|
+
this._webgpu = webgpu
|
|
135
140
|
|
|
136
141
|
this._focused = false
|
|
137
142
|
this._hovered = false
|
|
@@ -256,6 +261,9 @@ class Window extends EventsViaPoll {
|
|
|
256
261
|
setAccelerated (accelerated) {
|
|
257
262
|
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
258
263
|
|
|
264
|
+
if (this._opengl) { throw new Error("can't call setAccelerated in opengl mode") }
|
|
265
|
+
if (this._webgpu) { throw new Error("can't call setAccelerated in webgpu mode") }
|
|
266
|
+
|
|
259
267
|
if (typeof accelerated !== 'boolean') { throw Object.assign(new Error("accelerated must be a boolean"), { accelerated }) }
|
|
260
268
|
|
|
261
269
|
[ this._accelerated, this._vsync ] = Bindings.window_setAcceleratedAndVsync(this._id, accelerated, this._vsync)
|
|
@@ -265,12 +273,16 @@ class Window extends EventsViaPoll {
|
|
|
265
273
|
setVsync (vsync) {
|
|
266
274
|
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
267
275
|
|
|
276
|
+
if (this._opengl) { throw new Error("can't call setVsync in opengl mode") }
|
|
277
|
+
if (this._webgpu) { throw new Error("can't call setVsync in webgpu mode") }
|
|
278
|
+
|
|
268
279
|
if (typeof vsync !== 'boolean') { throw Object.assign(new Error("vsync must be a boolean"), { vsync }) }
|
|
269
280
|
|
|
270
281
|
[ this._accelerated, this._vsync ] = Bindings.window_setAcceleratedAndVsync(this._id, this._accelerated, vsync)
|
|
271
282
|
}
|
|
272
283
|
|
|
273
284
|
get opengl () { return this._opengl }
|
|
285
|
+
get webgpu () { return this._webgpu }
|
|
274
286
|
get native () { return this._native }
|
|
275
287
|
|
|
276
288
|
get minimized () { return this._minimized }
|
|
@@ -325,6 +337,7 @@ class Window extends EventsViaPoll {
|
|
|
325
337
|
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
326
338
|
|
|
327
339
|
if (this._opengl) { throw new Error("can't call render in opengl mode") }
|
|
340
|
+
if (this._webgpu) { throw new Error("can't call render in webgpu mode") }
|
|
328
341
|
|
|
329
342
|
const _format = Enums.pixelFormat[format] ?? null
|
|
330
343
|
|
package/src/native/binding.cpp
CHANGED
|
@@ -321,7 +321,7 @@ window_create(napi_env env, napi_callback_info info)
|
|
|
321
321
|
int * height = nullptr;
|
|
322
322
|
void * native_pointer = nullptr;
|
|
323
323
|
|
|
324
|
-
napi_value argv[
|
|
324
|
+
napi_value argv[19];
|
|
325
325
|
size_t argc = sizeof(argv) / sizeof(napi_value);
|
|
326
326
|
CALL_NAPI(napi_get_cb_info, info, &argc, argv, nullptr, nullptr);
|
|
327
327
|
|
|
@@ -360,7 +360,7 @@ window_create(napi_env env, napi_callback_info info)
|
|
|
360
360
|
}
|
|
361
361
|
|
|
362
362
|
bool visible, fullscreen, resizable, borderless, always_on_top,
|
|
363
|
-
accelerated, vsync, opengl,
|
|
363
|
+
accelerated, vsync, opengl, webgpu,
|
|
364
364
|
skip_taskbar, popup_menu, tooltip, utility;
|
|
365
365
|
CALL_NAPI(napi_get_value_bool, argv[6], &visible);
|
|
366
366
|
CALL_NAPI(napi_get_value_bool, argv[7], &fullscreen);
|
|
@@ -370,21 +370,22 @@ window_create(napi_env env, napi_callback_info info)
|
|
|
370
370
|
CALL_NAPI(napi_get_value_bool, argv[11], &accelerated);
|
|
371
371
|
CALL_NAPI(napi_get_value_bool, argv[12], &vsync);
|
|
372
372
|
CALL_NAPI(napi_get_value_bool, argv[13], &opengl);
|
|
373
|
-
CALL_NAPI(napi_get_value_bool, argv[14], &
|
|
374
|
-
CALL_NAPI(napi_get_value_bool, argv[15], &
|
|
375
|
-
CALL_NAPI(napi_get_value_bool, argv[16], &
|
|
376
|
-
CALL_NAPI(napi_get_value_bool, argv[17], &
|
|
373
|
+
CALL_NAPI(napi_get_value_bool, argv[14], &webgpu);
|
|
374
|
+
CALL_NAPI(napi_get_value_bool, argv[15], &skip_taskbar);
|
|
375
|
+
CALL_NAPI(napi_get_value_bool, argv[16], &popup_menu);
|
|
376
|
+
CALL_NAPI(napi_get_value_bool, argv[17], &tooltip);
|
|
377
|
+
CALL_NAPI(napi_get_value_bool, argv[18], &utility);
|
|
377
378
|
|
|
378
|
-
int pixel_width, pixel_height, window_id,
|
|
379
|
+
int pixel_width, pixel_height, window_id, native_size;
|
|
379
380
|
|
|
380
381
|
CALL_SDL_HELPER(window_create,
|
|
381
382
|
title, display,
|
|
382
383
|
&x, &y, &width, &height,
|
|
383
384
|
&pixel_width, &pixel_height,
|
|
384
385
|
visible, &fullscreen, &resizable, &borderless, &always_on_top,
|
|
385
|
-
&accelerated, &vsync, opengl,
|
|
386
|
+
&accelerated, &vsync, opengl, webgpu,
|
|
386
387
|
&skip_taskbar, &popup_menu, &tooltip, &utility,
|
|
387
|
-
&window_id, &native_pointer, &
|
|
388
|
+
&window_id, &native_pointer, &native_size
|
|
388
389
|
);
|
|
389
390
|
|
|
390
391
|
napi_value key, value;
|
|
@@ -470,7 +471,7 @@ window_create(napi_env env, napi_callback_info info)
|
|
|
470
471
|
|
|
471
472
|
if (native_pointer) {
|
|
472
473
|
CALL_NAPI(napi_create_external_buffer,
|
|
473
|
-
|
|
474
|
+
native_size, native_pointer, freePointer, native_pointer,
|
|
474
475
|
&value);
|
|
475
476
|
CALL_NAPI(napi_create_string_latin1, "native", 6, &key);
|
|
476
477
|
CALL_NAPI(napi_set_property, result, key, value);
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
#include <Cocoa/Cocoa.h>
|
|
2
|
+
#import <QuartzCore/CAMetalLayer.h>
|
|
2
3
|
|
|
3
4
|
#include "cocoa-window.h"
|
|
4
5
|
|
|
5
|
-
extern "C" CALayer *
|
|
6
|
+
extern "C" CALayer * getCocoaGlView(NSWindow * window) {
|
|
6
7
|
NSView * view = window.contentView;
|
|
7
8
|
[view setWantsLayer:YES];
|
|
9
|
+
[[view layer] setContentsScale:[window backingScaleFactor]];
|
|
10
|
+
return view.layer;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
extern "C" CALayer * getCocoaGpuView(NSWindow * window) {
|
|
14
|
+
NSView * view = window.contentView;
|
|
15
|
+
[view setWantsLayer:YES];
|
|
16
|
+
[view setLayer:[CAMetalLayer layer]];
|
|
17
|
+
[[view layer] setContentsScale:[window backingScaleFactor]];
|
|
8
18
|
return view.layer;
|
|
9
19
|
}
|
|
10
20
|
|
|
@@ -11,19 +11,28 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
#if defined(__LINUX__)
|
|
14
|
-
#define
|
|
15
|
-
|
|
14
|
+
#define GL_NativeWindow Window
|
|
15
|
+
struct GPU_NativeData {
|
|
16
|
+
Display *display;
|
|
17
|
+
Window window;
|
|
18
|
+
};
|
|
19
|
+
#define GPU_WINDOW_FLAG SDL_WINDOW_VULKAN
|
|
16
20
|
#elif defined(__WIN32__)
|
|
17
|
-
#define
|
|
18
|
-
|
|
21
|
+
#define GL_NativeWindow HWND
|
|
22
|
+
struct GPU_NativeData {
|
|
23
|
+
HWND hwnd;
|
|
24
|
+
HINSTANCE hinstance;
|
|
25
|
+
};
|
|
26
|
+
#define GPU_WINDOW_FLAG 0
|
|
19
27
|
#elif defined(__MACOSX__)
|
|
20
28
|
#include "cocoa-window.h"
|
|
21
|
-
#define
|
|
22
|
-
|
|
29
|
+
#define GL_NativeWindow CALayer *
|
|
30
|
+
struct GPU_NativeData {
|
|
31
|
+
CALayer *layer;
|
|
32
|
+
};
|
|
33
|
+
#define GPU_WINDOW_FLAG SDL_WINDOW_METAL
|
|
23
34
|
#endif
|
|
24
35
|
|
|
25
|
-
typedef __WINDOW_TYPE__ NativeWindow;
|
|
26
|
-
|
|
27
36
|
|
|
28
37
|
#define RETURN_ERROR(...) do { \
|
|
29
38
|
char * error; \
|
|
@@ -880,21 +889,6 @@ initialize (Variant & object)
|
|
|
880
889
|
}
|
|
881
890
|
|
|
882
891
|
|
|
883
|
-
ErrorMessage *
|
|
884
|
-
_windowGetPixelSize(SDL_Window * window, int * pixel_width, int * pixel_height)
|
|
885
|
-
{
|
|
886
|
-
SDL_Renderer * renderer = SDL_GetRenderer(window);
|
|
887
|
-
if (renderer == nullptr) {
|
|
888
|
-
RETURN_ERROR("SDL_GetRenderer() error: %s\n", SDL_GetError());
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
if (SDL_GetRendererOutputSize(renderer, pixel_width, pixel_height) != 0) {
|
|
892
|
-
RETURN_ERROR("SDL_GetRendererOutputSize() error: %s\n", SDL_GetError());
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
return nullptr;
|
|
896
|
-
}
|
|
897
|
-
|
|
898
892
|
ErrorMessage *
|
|
899
893
|
_windowUpdateTexture(
|
|
900
894
|
SDL_Window * window,
|
|
@@ -951,8 +945,7 @@ _windowUpdateRenderer(
|
|
|
951
945
|
ErrorMessage * error;
|
|
952
946
|
|
|
953
947
|
int pixel_width, pixel_height;
|
|
954
|
-
|
|
955
|
-
if (error != nullptr) { return error; }
|
|
948
|
+
SDL_GetWindowSizeInPixels(window, &pixel_width, &pixel_height);
|
|
956
949
|
|
|
957
950
|
error = _windowUpdateTexture(window, renderer, pixel_width, pixel_height, nullptr);
|
|
958
951
|
if (error != nullptr) { return error; }
|
|
@@ -1064,8 +1057,7 @@ packageEvent (const SDL_Event & event, Variant & object)
|
|
|
1064
1057
|
}
|
|
1065
1058
|
|
|
1066
1059
|
int pixel_width, pixel_height;
|
|
1067
|
-
|
|
1068
|
-
if (error != nullptr) { return error; }
|
|
1060
|
+
SDL_GetWindowSizeInPixels(window, &pixel_width, &pixel_height);
|
|
1069
1061
|
|
|
1070
1062
|
SET_NUM(object, "type", (int) EventType::RESIZE);
|
|
1071
1063
|
SET_NUM(object, "width", event.window.data1);
|
|
@@ -1475,11 +1467,12 @@ window_create (
|
|
|
1475
1467
|
bool * accelerated,
|
|
1476
1468
|
bool * vsync,
|
|
1477
1469
|
bool opengl,
|
|
1470
|
+
bool webgpu,
|
|
1478
1471
|
bool * skip_taskbar,
|
|
1479
1472
|
bool * popup_menu,
|
|
1480
1473
|
bool * tooltip,
|
|
1481
1474
|
bool * utility,
|
|
1482
|
-
int * window_id, void ** native_pointer, int *
|
|
1475
|
+
int * window_id, void ** native_pointer, int * native_size
|
|
1483
1476
|
) {
|
|
1484
1477
|
if (*x == nullptr) {
|
|
1485
1478
|
*x = (int *) malloc(sizeof(int));
|
|
@@ -1504,17 +1497,22 @@ window_create (
|
|
|
1504
1497
|
| (*borderless ? SDL_WINDOW_BORDERLESS : 0)
|
|
1505
1498
|
| (*always_on_top ? SDL_WINDOW_ALWAYS_ON_TOP : 0)
|
|
1506
1499
|
| (opengl ? SDL_WINDOW_OPENGL : 0)
|
|
1500
|
+
| (webgpu ? GPU_WINDOW_FLAG : 0)
|
|
1507
1501
|
| (*skip_taskbar ? SDL_WINDOW_SKIP_TASKBAR : 0)
|
|
1508
1502
|
| (*popup_menu ? SDL_WINDOW_POPUP_MENU : 0)
|
|
1509
1503
|
| (*tooltip ? SDL_WINDOW_TOOLTIP : 0)
|
|
1510
|
-
| (*utility ? SDL_WINDOW_UTILITY : 0)
|
|
1504
|
+
| (*utility ? SDL_WINDOW_UTILITY : 0)
|
|
1505
|
+
;
|
|
1511
1506
|
|
|
1512
1507
|
SDL_Window * window = SDL_CreateWindow(title, **x, **y, **width, **height, desired_flags);
|
|
1513
1508
|
if (window == nullptr) {
|
|
1514
1509
|
RETURN_ERROR("SDL_CreateWindow() error: %s\n", SDL_GetError());
|
|
1515
1510
|
}
|
|
1516
1511
|
|
|
1517
|
-
|
|
1512
|
+
*window_id = SDL_GetWindowID(window);
|
|
1513
|
+
if (*window_id == 0) {
|
|
1514
|
+
RETURN_ERROR("SDL_GetWindowID() error: %s\n", SDL_GetError());
|
|
1515
|
+
}
|
|
1518
1516
|
|
|
1519
1517
|
int actual_flags = SDL_GetWindowFlags(window);
|
|
1520
1518
|
*fullscreen = actual_flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP);
|
|
@@ -1526,12 +1524,10 @@ window_create (
|
|
|
1526
1524
|
*tooltip = actual_flags & SDL_WINDOW_TOOLTIP;
|
|
1527
1525
|
*utility = actual_flags & SDL_WINDOW_UTILITY;
|
|
1528
1526
|
|
|
1529
|
-
*
|
|
1530
|
-
|
|
1531
|
-
RETURN_ERROR("SDL_GetWindowID() error: %s\n", SDL_GetError());
|
|
1532
|
-
}
|
|
1527
|
+
SDL_GetWindowPosition(window, *x, *y);
|
|
1528
|
+
SDL_GetWindowSizeInPixels(window, pixel_width, pixel_height);
|
|
1533
1529
|
|
|
1534
|
-
if (opengl) {
|
|
1530
|
+
if (opengl || webgpu) {
|
|
1535
1531
|
SDL_SysWMinfo info;
|
|
1536
1532
|
SDL_VERSION(&(info.version));
|
|
1537
1533
|
bool got_info = SDL_GetWindowWMInfo(window, &info);
|
|
@@ -1539,20 +1535,41 @@ window_create (
|
|
|
1539
1535
|
RETURN_ERROR("SDL_GetWindowWMInfo(%d) error: %s\n", *window_id, SDL_GetError());
|
|
1540
1536
|
}
|
|
1541
1537
|
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1538
|
+
if (opengl) {
|
|
1539
|
+
int size = sizeof(GL_NativeWindow);
|
|
1540
|
+
GL_NativeWindow *pointer = (GL_NativeWindow *) malloc(size);
|
|
1541
|
+
#if defined(__LINUX__)
|
|
1542
|
+
*pointer = info.info.x11.window;
|
|
1543
|
+
#elif defined(__WIN32__)
|
|
1544
|
+
*pointer = info.info.win.window;
|
|
1545
|
+
#elif defined(__MACOSX__)
|
|
1546
|
+
*pointer = getCocoaGlView(info.info.cocoa.window);
|
|
1547
|
+
#endif
|
|
1548
|
+
|
|
1549
|
+
*native_pointer = pointer;
|
|
1550
|
+
*native_size = size;
|
|
1551
|
+
} else if (webgpu) {
|
|
1552
|
+
int size = sizeof(GPU_NativeData);
|
|
1553
|
+
GPU_NativeData *pointer = (GPU_NativeData *) malloc(size);
|
|
1554
|
+
|
|
1555
|
+
#if defined(__LINUX__)
|
|
1556
|
+
pointer->display = info.info.x11.display;
|
|
1557
|
+
pointer->window = info.info.x11.window;
|
|
1558
|
+
#elif defined(__WIN32__)
|
|
1559
|
+
pointer->hwnd = info.info.win.window;
|
|
1560
|
+
pointer->hinstance = info.info.win.hinstance;
|
|
1561
|
+
#elif defined(__MACOSX__)
|
|
1562
|
+
pointer->layer = getCocoaGpuView(info.info.cocoa.window);
|
|
1563
|
+
#endif
|
|
1564
|
+
|
|
1565
|
+
*native_pointer = pointer;
|
|
1566
|
+
*native_size = size;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
else {
|
|
1570
|
+
ErrorMessage * error = _windowUpdateRenderer(window, accelerated, vsync);
|
|
1571
|
+
if (error != nullptr) { return error; }
|
|
1547
1572
|
}
|
|
1548
|
-
|
|
1549
|
-
ErrorMessage * error;
|
|
1550
|
-
|
|
1551
|
-
error = _windowUpdateRenderer(window, accelerated, vsync);
|
|
1552
|
-
if (error != nullptr) { return error; }
|
|
1553
|
-
|
|
1554
|
-
error = _windowGetPixelSize(window, pixel_width, pixel_height);
|
|
1555
|
-
if (error != nullptr) { return error; }
|
|
1556
1573
|
|
|
1557
1574
|
if (visible) { SDL_ShowWindow(window); }
|
|
1558
1575
|
|
|
@@ -1595,8 +1612,7 @@ window_setSize (int window_id, int width, int height, int * pixel_width, int * p
|
|
|
1595
1612
|
|
|
1596
1613
|
SDL_SetWindowSize(window, width, height);
|
|
1597
1614
|
|
|
1598
|
-
|
|
1599
|
-
if (error != nullptr) { return error; }
|
|
1615
|
+
SDL_GetWindowSizeInPixels(window, pixel_width, pixel_height);
|
|
1600
1616
|
|
|
1601
1617
|
return nullptr;
|
|
1602
1618
|
}
|
|
@@ -1796,8 +1812,7 @@ window_render (
|
|
|
1796
1812
|
}
|
|
1797
1813
|
|
|
1798
1814
|
int pixel_width, pixel_height;
|
|
1799
|
-
|
|
1800
|
-
if (error != nullptr) { return error; }
|
|
1815
|
+
SDL_GetWindowSizeInPixels(window, &pixel_width, &pixel_height);
|
|
1801
1816
|
|
|
1802
1817
|
if (pixel_width != texture_width || pixel_height != texture_height) {
|
|
1803
1818
|
ErrorMessage * error = _windowUpdateTexture(window, renderer, pixel_width, pixel_height, &texture);
|
|
@@ -1851,14 +1866,13 @@ window_destroy (int window_id)
|
|
|
1851
1866
|
}
|
|
1852
1867
|
|
|
1853
1868
|
SDL_Renderer * renderer = SDL_GetRenderer(window);
|
|
1854
|
-
if (renderer
|
|
1855
|
-
|
|
1856
|
-
}
|
|
1869
|
+
if (renderer != nullptr) {
|
|
1870
|
+
SDL_Texture * texture = (SDL_Texture *) SDL_GetWindowData(window, "texture");
|
|
1857
1871
|
|
|
1858
|
-
|
|
1872
|
+
SDL_DestroyTexture(texture);
|
|
1873
|
+
SDL_DestroyRenderer(renderer);
|
|
1874
|
+
}
|
|
1859
1875
|
|
|
1860
|
-
SDL_DestroyTexture(texture);
|
|
1861
|
-
SDL_DestroyRenderer(renderer);
|
|
1862
1876
|
SDL_DestroyWindow(window);
|
|
1863
1877
|
|
|
1864
1878
|
return nullptr;
|
package/src/native/sdl-helpers.h
CHANGED
|
@@ -67,11 +67,12 @@ ErrorMessage * window_create (
|
|
|
67
67
|
bool * accelerated,
|
|
68
68
|
bool * vsync,
|
|
69
69
|
bool opengl,
|
|
70
|
+
bool webgpu,
|
|
70
71
|
bool * skipTaskbar,
|
|
71
72
|
bool * popupMenu,
|
|
72
73
|
bool * tooltip,
|
|
73
74
|
bool * utility,
|
|
74
|
-
int * window_id, void ** native_pointer, int *
|
|
75
|
+
int * window_id, void ** native_pointer, int * native_size
|
|
75
76
|
);
|
|
76
77
|
ErrorMessage * window_setTitle (int window_id, const char * title);
|
|
77
78
|
ErrorMessage * window_setPosition (int window_id, int x, int y);
|
package/src/types/index.d.ts
CHANGED
|
@@ -437,6 +437,8 @@ export namespace Sdl {
|
|
|
437
437
|
readonly vsync: boolean
|
|
438
438
|
setVsync (vsync: boolean): void
|
|
439
439
|
|
|
440
|
+
readonly opengl: boolean
|
|
441
|
+
readonly webgpu: boolean
|
|
440
442
|
readonly native: unknown
|
|
441
443
|
|
|
442
444
|
readonly maximized: boolean
|
|
@@ -492,6 +494,7 @@ export namespace Sdl {
|
|
|
492
494
|
accelerated?: boolean
|
|
493
495
|
vsync?: boolean
|
|
494
496
|
opengl?: boolean
|
|
497
|
+
webgpu?: boolean
|
|
495
498
|
skipTaskbar?: boolean
|
|
496
499
|
popupMenu?: boolean
|
|
497
500
|
tooltip?: boolean
|