@kmamal/sdl 0.10.0 → 0.10.2
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 +11 -3
- package/package.json +4 -4
- package/src/javascript/bindings.js +1 -4
- package/src/native/mouse.cpp +3 -2
- package/src/native/window.cpp +10 -2
package/README.md
CHANGED
|
@@ -48,6 +48,7 @@ window.on('*', console.log)
|
|
|
48
48
|
import sdl from '@kmamal/sdl'
|
|
49
49
|
import { createCanvas } from 'canvas'
|
|
50
50
|
|
|
51
|
+
// Setup
|
|
51
52
|
const window = sdl.video.createWindow({ title: "Canvas" })
|
|
52
53
|
const { pixelWidth: width, pixelHeight: height } = window
|
|
53
54
|
const canvas = createCanvas(width, height)
|
|
@@ -56,6 +57,8 @@ const ctx = canvas.getContext('2d')
|
|
|
56
57
|
// Clear screen to red
|
|
57
58
|
ctx.fillStyle = 'red'
|
|
58
59
|
ctx.fillRect(0, 0, width, height)
|
|
60
|
+
|
|
61
|
+
// Render to window
|
|
59
62
|
const buffer = canvas.toBuffer('raw')
|
|
60
63
|
window.render(width, height, width * 4, 'bgra32', buffer)
|
|
61
64
|
```
|
|
@@ -65,6 +68,7 @@ window.render(width, height, width * 4, 'bgra32', buffer)
|
|
|
65
68
|
import sdl from '@kmamal/sdl'
|
|
66
69
|
import createContext from '@kmamal/gl'
|
|
67
70
|
|
|
71
|
+
// Setup
|
|
68
72
|
const window = sdl.video.createWindow({ title: "WebGL", opengl: true })
|
|
69
73
|
const { pixelWidth: width, pixelHeight: height, native } = window
|
|
70
74
|
const gl = createContext(width, height, { window: native })
|
|
@@ -72,6 +76,8 @@ const gl = createContext(width, height, { window: native })
|
|
|
72
76
|
// Clear screen to red
|
|
73
77
|
gl.clearColor(1, 0, 0, 1)
|
|
74
78
|
gl.clear(gl.COLOR_BUFFER_BIT)
|
|
79
|
+
|
|
80
|
+
// Render to window
|
|
75
81
|
gl.swap()
|
|
76
82
|
```
|
|
77
83
|
|
|
@@ -80,12 +86,11 @@ gl.swap()
|
|
|
80
86
|
import sdl from '@kmamal/sdl'
|
|
81
87
|
import gpu from '@kmamal/gpu'
|
|
82
88
|
|
|
89
|
+
// Setup
|
|
83
90
|
const window = sdl.video.createWindow({ title: "WebGPU", webgpu: true })
|
|
84
|
-
|
|
85
91
|
const instance = gpu.create([])
|
|
86
92
|
const adapter = await instance.requestAdapter()
|
|
87
93
|
const device = await adapter.requestDevice()
|
|
88
|
-
|
|
89
94
|
const renderer = gpu.renderGPUDeviceToWindow({ device, window })
|
|
90
95
|
|
|
91
96
|
// Clear screen to red
|
|
@@ -103,11 +108,14 @@ const renderPass = commandEncoder.beginRenderPass({
|
|
|
103
108
|
renderPass.end()
|
|
104
109
|
device.queue.submit([ commandEncoder.finish() ])
|
|
105
110
|
|
|
111
|
+
// Render to window
|
|
106
112
|
renderer.swap()
|
|
107
113
|
|
|
108
114
|
```
|
|
109
115
|
|
|
110
|
-
|
|
116
|
+
### More examples
|
|
117
|
+
|
|
118
|
+
Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples) folder.
|
|
111
119
|
|
|
112
120
|
|
|
113
121
|
# API Reference
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.10.
|
|
2
|
+
"version": "0.10.2",
|
|
3
3
|
"name": "@kmamal/sdl",
|
|
4
4
|
"description": "SDL bindings for Node.js",
|
|
5
5
|
"keywords": [
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"repository": {
|
|
36
36
|
"type": "git",
|
|
37
|
-
"url": "git://github.com/kmamal/node-sdl.git"
|
|
37
|
+
"url": "git+ssh://git@github.com/kmamal/node-sdl.git"
|
|
38
38
|
},
|
|
39
39
|
"main": "./src/javascript/index.js",
|
|
40
40
|
"types": "./src/types/index.d.ts",
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@kmamal/evdev": "^0.0.1",
|
|
68
|
-
"@kmamal/testing": "^0.0.
|
|
69
|
-
"@types/node": "^20.11.
|
|
68
|
+
"@kmamal/testing": "^0.0.30",
|
|
69
|
+
"@types/node": "^20.11.20",
|
|
70
70
|
"node-addon-api": "^7.1.0",
|
|
71
71
|
"node-gyp": "^10.0.1"
|
|
72
72
|
}
|
package/src/native/mouse.cpp
CHANGED
|
@@ -128,16 +128,17 @@ mouse::setCursorImage (const Napi::CallbackInfo &info)
|
|
|
128
128
|
|
|
129
129
|
allocated_cursor = SDL_CreateColorCursor(surface, x, y);
|
|
130
130
|
if (allocated_cursor == nullptr) {
|
|
131
|
+
SDL_FreeSurface(surface);
|
|
132
|
+
|
|
131
133
|
std::ostringstream message;
|
|
132
134
|
message << "SDL_CreateColorCursor(" << x << ", " << y << ") error: " << SDL_GetError();
|
|
133
135
|
SDL_ClearError();
|
|
134
136
|
throw Napi::Error::New(env, message.str());
|
|
135
137
|
}
|
|
136
138
|
|
|
137
|
-
SDL_FreeSurface(surface);
|
|
138
|
-
|
|
139
139
|
SDL_SetCursor(allocated_cursor);
|
|
140
140
|
|
|
141
|
+
SDL_FreeSurface(surface);
|
|
141
142
|
return env.Undefined();
|
|
142
143
|
}
|
|
143
144
|
|
package/src/native/window.cpp
CHANGED
|
@@ -563,15 +563,18 @@ window::render (const Napi::CallbackInfo &info)
|
|
|
563
563
|
|
|
564
564
|
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
|
|
565
565
|
if (texture == nullptr) {
|
|
566
|
+
SDL_FreeSurface(surface);
|
|
567
|
+
|
|
566
568
|
std::ostringstream message;
|
|
567
569
|
message << "SDL_CreateTextureFromSurface(" << window_id << ") error: " << SDL_GetError();
|
|
568
570
|
SDL_ClearError();
|
|
569
571
|
throw Napi::Error::New(env, message.str());
|
|
570
572
|
}
|
|
571
573
|
|
|
572
|
-
SDL_FreeSurface(surface);
|
|
573
|
-
|
|
574
574
|
if (SDL_RenderClear(renderer) < 0) {
|
|
575
|
+
SDL_DestroyTexture(texture);
|
|
576
|
+
SDL_FreeSurface(surface);
|
|
577
|
+
|
|
575
578
|
std::ostringstream message;
|
|
576
579
|
message << "SDL_RenderClear(" << window_id << ") error: " << SDL_GetError();
|
|
577
580
|
SDL_ClearError();
|
|
@@ -579,6 +582,9 @@ window::render (const Napi::CallbackInfo &info)
|
|
|
579
582
|
}
|
|
580
583
|
|
|
581
584
|
if (SDL_RenderCopy(renderer, texture, nullptr, nullptr) < 0) {
|
|
585
|
+
SDL_DestroyTexture(texture);
|
|
586
|
+
SDL_FreeSurface(surface);
|
|
587
|
+
|
|
582
588
|
std::ostringstream message;
|
|
583
589
|
message << "SDL_RenderCopy(" << window_id << ") error: " << SDL_GetError();
|
|
584
590
|
SDL_ClearError();
|
|
@@ -587,6 +593,8 @@ window::render (const Napi::CallbackInfo &info)
|
|
|
587
593
|
|
|
588
594
|
SDL_RenderPresent(renderer);
|
|
589
595
|
|
|
596
|
+
SDL_DestroyTexture(texture);
|
|
597
|
+
SDL_FreeSurface(surface);
|
|
590
598
|
return env.Undefined();
|
|
591
599
|
}
|
|
592
600
|
|