sfml.js 1.0.0-rc.2 → 1.1.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.ja.md +16 -11
- package/README.ko.md +16 -11
- package/README.md +16 -11
- package/README.zh-CN.md +16 -11
- package/assets/breakout.png +0 -0
- package/binding.gyp +23 -16
- package/dist/audio/effect-processor.js +9 -3
- package/dist/audio/input-sound-file.js +41 -15
- package/dist/audio/listener.js +33 -11
- package/dist/audio/music.js +41 -18
- package/dist/audio/output-sound-file.js +4 -2
- package/dist/audio/playback-device.js +11 -3
- package/dist/audio/sound-buffer-recorder.js +8 -5
- package/dist/audio/sound-buffer.js +40 -17
- package/dist/audio/sound-file-factory.js +21 -9
- package/dist/audio/sound-file-reader.js +21 -7
- package/dist/audio/sound-recorder.js +36 -15
- package/dist/audio/sound-source.js +117 -40
- package/dist/audio/sound-stream.js +14 -5
- package/dist/audio/sound.js +9 -4
- package/dist/audio/value.js +42 -16
- package/dist/graphics/blend-mode.js +2 -1
- package/dist/graphics/boolean-vector.d.ts +1 -2
- package/dist/graphics/boolean-vector.js +19 -9
- package/dist/graphics/color.js +2 -1
- package/dist/graphics/convex-shape.js +7 -3
- package/dist/graphics/font.js +52 -23
- package/dist/graphics/glsl-matrix.js +8 -3
- package/dist/graphics/glsl.js +47 -16
- package/dist/graphics/glyph.js +27 -10
- package/dist/graphics/image.js +30 -14
- package/dist/graphics/rect.js +15 -8
- package/dist/graphics/render-states.js +18 -9
- package/dist/graphics/render-target.js +49 -23
- package/dist/graphics/render-texture.js +24 -12
- package/dist/graphics/render-window.js +6 -3
- package/dist/graphics/shader.js +67 -32
- package/dist/graphics/shape.js +25 -13
- package/dist/graphics/sprite.js +19 -9
- package/dist/graphics/stencil-mode.js +10 -6
- package/dist/graphics/swap.js +2 -1
- package/dist/graphics/text.js +123 -48
- package/dist/graphics/texture.js +48 -24
- package/dist/graphics/transform.js +29 -13
- package/dist/graphics/transformable.js +2 -1
- package/dist/graphics/vertex-array.js +40 -18
- package/dist/graphics/vertex-buffer.js +39 -19
- package/dist/graphics/vertex.js +6 -3
- package/dist/graphics/view.js +30 -14
- package/dist/index.d.ts +4 -4
- package/dist/internal/audio-codec-registry.js +12 -6
- package/dist/internal/audio-input-stream.js +2 -1
- package/dist/internal/audio-music-pump.js +58 -24
- package/dist/internal/audio-recorder-session.js +17 -7
- package/dist/internal/audio-worker-session.js +28 -10
- package/dist/internal/audio-worker.js +40 -21
- package/dist/internal/glsl-value.d.ts +3 -1
- package/dist/internal/glsl-value.js +18 -8
- package/dist/internal/graphics-state.js +29 -15
- package/dist/internal/input-stream.d.ts +3 -1
- package/dist/internal/input-stream.js +16 -7
- package/dist/internal/numeric-properties.js +2 -1
- package/dist/internal/render-states.js +2 -1
- package/dist/internal/scalar.js +22 -13
- package/dist/internal/shaped-glyph.d.ts +3 -1
- package/dist/internal/shaped-glyph.js +12 -4
- package/dist/internal/struct-view.d.ts +3 -1
- package/dist/internal/struct-view.js +3 -1
- package/dist/internal/transformable.js +2 -1
- package/dist/network/common.js +23 -11
- package/dist/network/dns.js +25 -17
- package/dist/network/ftp.js +43 -18
- package/dist/network/http.js +126 -56
- package/dist/network/ip-address.js +50 -25
- package/dist/network/packet.js +63 -25
- package/dist/network/sftp.js +175 -74
- package/dist/network/socket-selector.js +28 -14
- package/dist/network/socket.js +71 -30
- package/dist/network/tcp-listener.js +42 -19
- package/dist/network/tcp-socket.js +111 -53
- package/dist/network/tls-material.js +2 -1
- package/dist/network/udp-socket.js +68 -33
- package/dist/system/angle.js +2 -1
- package/dist/system/clock.js +4 -2
- package/dist/system/err.js +5 -2
- package/dist/system/file-input-stream.js +8 -4
- package/dist/system/input-stream.js +6 -3
- package/dist/system/operators.d.ts +1 -1
- package/dist/system/operators.js +90 -50
- package/dist/system/sleep.js +4 -2
- package/dist/system/time.js +12 -6
- package/dist/system/vector2.js +6 -7
- package/dist/system/vector3.js +11 -6
- package/dist/window/clipboard.js +2 -1
- package/dist/window/context.js +10 -5
- package/dist/window/cursor.js +2 -1
- package/dist/window/event.js +9 -5
- package/dist/window/mouse.js +4 -2
- package/dist/window/video-mode.js +2 -1
- package/dist/window/window.js +19 -12
- package/native/addon.cc +25 -12
- package/native/audio-binding.cc +266 -126
- package/native/audio-codec-binding.cc +147 -77
- package/native/audio-device-binding.cc +76 -49
- package/native/audio-file-binding.cc +116 -67
- package/native/audio-recorder-binding.cc +147 -98
- package/native/audio-recorder.h +1 -1
- package/native/audio-state.h +53 -30
- package/native/audio-stream-binding.cc +148 -94
- package/native/audio-stream.h +5 -4
- package/native/audio-worker-binding.cc +163 -81
- package/native/audio-worker.h +35 -19
- package/native/batch-drawable.cc +29 -16
- package/native/batch-drawable.h +11 -8
- package/native/context-binding.cc +40 -27
- package/native/context-settings.h +15 -8
- package/native/deferred-delete.cc +9 -6
- package/native/deferred-delete.h +7 -8
- package/native/error-stream-binding.cc +42 -28
- package/native/font-binding.cc +89 -48
- package/native/graphics-binding.cc +122 -72
- package/native/graphics-state.h +50 -36
- package/native/image-binding.cc +38 -24
- package/native/image-state.h +26 -18
- package/native/input-binding.cc +42 -27
- package/native/render-window-binding.cc +38 -23
- package/native/shader-binding.cc +115 -50
- package/native/shape-binding.cc +94 -49
- package/native/shape-state.h +18 -9
- package/native/shaped-glyph-storage.h +9 -5
- package/native/stream-binding.cc +143 -117
- package/native/system-binding.cc +17 -12
- package/native/text-binding.cc +68 -35
- package/native/text-state.h +25 -18
- package/native/texture-binding.cc +42 -33
- package/native/texture-resource.h +20 -12
- package/native/time-value.h +3 -1
- package/native/transformable-binding.cc +12 -6
- package/native/transformable-state.h +6 -6
- package/native/value-binding.h +46 -28
- package/native/value-layout.h +10 -10
- package/native/values-binding.cc +29 -23
- package/native/vertex-binding.cc +18 -12
- package/native/vertex-buffer-binding.cc +38 -24
- package/native/vertex-storage.h +2 -2
- package/native/view-data.h +4 -3
- package/native/window-binding.cc +75 -45
- package/native/window-event.h +20 -11
- package/native/window-owner.h +15 -12
- package/package.json +43 -50
- package/src/audio/effect-processor.ts +9 -3
- package/src/audio/input-sound-file.ts +108 -36
- package/src/audio/listener.ts +39 -13
- package/src/audio/music.ts +112 -47
- package/src/audio/output-sound-file.ts +40 -11
- package/src/audio/playback-device.ts +23 -8
- package/src/audio/sound-buffer-recorder.ts +35 -13
- package/src/audio/sound-buffer.ts +166 -58
- package/src/audio/sound-file-factory.ts +127 -49
- package/src/audio/sound-file-reader.ts +49 -15
- package/src/audio/sound-recorder.ts +100 -34
- package/src/audio/sound-source.ts +142 -45
- package/src/audio/sound-stream.ts +15 -5
- package/src/audio/sound.ts +12 -4
- package/src/audio/value.ts +89 -26
- package/src/graphics/blend-mode.ts +3 -1
- package/src/graphics/boolean-vector.ts +56 -26
- package/src/graphics/color.ts +3 -1
- package/src/graphics/convex-shape.ts +10 -3
- package/src/graphics/font.ts +171 -50
- package/src/graphics/glsl-matrix.ts +9 -3
- package/src/graphics/glsl.ts +81 -35
- package/src/graphics/glyph.ts +67 -26
- package/src/graphics/image.ts +119 -45
- package/src/graphics/rect.ts +56 -24
- package/src/graphics/render-states.ts +31 -14
- package/src/graphics/render-target.ts +197 -81
- package/src/graphics/render-texture.ts +36 -12
- package/src/graphics/render-window.ts +9 -3
- package/src/graphics/shader.ts +186 -61
- package/src/graphics/shape.ts +93 -35
- package/src/graphics/sprite.ts +64 -25
- package/src/graphics/stencil-mode.ts +12 -6
- package/src/graphics/swap.ts +3 -2
- package/src/graphics/text.ts +229 -74
- package/src/graphics/texture.ts +180 -61
- package/src/graphics/transform.ts +132 -47
- package/src/graphics/transformable.ts +3 -1
- package/src/graphics/vertex-array.ts +87 -35
- package/src/graphics/vertex-buffer.ts +97 -33
- package/src/graphics/vertex.ts +9 -3
- package/src/graphics/view.ts +59 -21
- package/src/index.ts +101 -23
- package/src/internal/audio-codec-registry.ts +18 -6
- package/src/internal/audio-input-stream.ts +6 -2
- package/src/internal/audio-music-pump.ts +116 -41
- package/src/internal/audio-native.ts +249 -96
- package/src/internal/audio-recorder-session.ts +68 -24
- package/src/internal/audio-worker-session.ts +65 -21
- package/src/internal/audio-worker.ts +85 -41
- package/src/internal/glsl-value.ts +26 -11
- package/src/internal/graphics-state.ts +57 -20
- package/src/internal/input-stream.ts +23 -10
- package/src/internal/native.ts +252 -99
- package/src/internal/numeric-properties.ts +2 -1
- package/src/internal/render-states.ts +3 -1
- package/src/internal/scalar.ts +33 -14
- package/src/internal/shaped-glyph.ts +25 -12
- package/src/internal/struct-view.ts +40 -13
- package/src/internal/transformable.ts +3 -1
- package/src/network/common.ts +35 -11
- package/src/network/dns.ts +95 -38
- package/src/network/ftp.ts +129 -47
- package/src/network/http.ts +232 -77
- package/src/network/ip-address.ts +118 -48
- package/src/network/packet.ts +161 -54
- package/src/network/sftp.ts +498 -168
- package/src/network/socket-selector.ts +66 -26
- package/src/network/socket.ts +133 -46
- package/src/network/tcp-listener.ts +78 -29
- package/src/network/tcp-socket.ts +240 -95
- package/src/network/tls-material.ts +6 -2
- package/src/network/udp-socket.ts +147 -53
- package/src/system/angle.ts +3 -1
- package/src/system/clock.ts +12 -4
- package/src/system/err.ts +5 -2
- package/src/system/file-input-stream.ts +12 -4
- package/src/system/input-stream.ts +9 -3
- package/src/system/operators.ts +290 -115
- package/src/system/sleep.ts +6 -2
- package/src/system/time.ts +18 -6
- package/src/system/timeout-with-predicate.ts +19 -8
- package/src/system/vector2.ts +101 -49
- package/src/system/vector3.ts +85 -36
- package/src/window/clipboard.ts +3 -1
- package/src/window/context.ts +15 -5
- package/src/window/cursor.ts +3 -1
- package/src/window/event.ts +26 -12
- package/src/window/mouse.ts +6 -2
- package/src/window/video-mode.ts +3 -1
- package/src/window/window.ts +119 -37
- package/test/native/audio-probes.cc +74 -36
- package/test/native/deferred-delete-probes.cc +17 -11
- package/test/native/drawable-probes.cc +70 -36
- package/test/native/exception-probes.cc +14 -9
- package/test/native/image-probes.cc +20 -10
- package/test/native/matrix-probes.cc +8 -4
- package/test/native/network-oracle.cc +17 -11
- package/test/native/render-texture-probes.cc +33 -24
- package/test/native/shader-probes.cc +9 -9
- package/test/native/shape-probes.cc +37 -23
- package/test/native/sprite-probes.cc +41 -25
- package/test/native/system-probes.cc +58 -35
- package/test/native/text-probes.cc +77 -44
- package/test/native/texture-probes.cc +43 -26
- package/test/native/time-probes.cc +18 -12
- package/test/native/transform-probes.cc +15 -10
- package/test/native/transformable-probes.cc +23 -17
- package/test/native/value-oracle.h +9 -4
- package/test/native/value-probes.cc +31 -23
- package/test/native/vertex-array-probes.cc +22 -14
- package/test/native/vertex-buffer-probes.cc +28 -17
- package/test/native/view-probes.cc +29 -17
- package/test/native/window-probes.cc +66 -33
- package/tools/ensure-sfml.cjs +9 -0
- package/tools/generate-network-constants.cjs +11 -6
- package/tools/generate-window-constants.cjs +31 -12
- package/docs/README.ja.md +0 -30
- package/docs/README.ko.md +0 -30
- package/docs/README.md +0 -30
- package/docs/README.zh-CN.md +0 -30
- package/docs/api.ja.md +0 -84
- package/docs/api.ko.md +0 -84
- package/docs/api.md +0 -81
- package/docs/api.zh-CN.md +0 -81
- package/docs/audio.ja.md +0 -249
- package/docs/audio.ko.md +0 -251
- package/docs/audio.md +0 -252
- package/docs/audio.zh-CN.md +0 -252
- package/docs/concepts.ja.md +0 -130
- package/docs/concepts.ko.md +0 -130
- package/docs/concepts.md +0 -131
- package/docs/concepts.zh-CN.md +0 -131
- package/docs/development.ja.md +0 -148
- package/docs/development.ko.md +0 -148
- package/docs/development.md +0 -150
- package/docs/development.zh-CN.md +0 -150
- package/docs/getting-started.ja.md +0 -154
- package/docs/getting-started.ko.md +0 -154
- package/docs/getting-started.md +0 -156
- package/docs/getting-started.zh-CN.md +0 -156
- package/docs/graphics.ja.md +0 -256
- package/docs/graphics.ko.md +0 -254
- package/docs/graphics.md +0 -255
- package/docs/graphics.zh-CN.md +0 -257
- package/docs/network.ja.md +0 -214
- package/docs/network.ko.md +0 -216
- package/docs/network.md +0 -218
- package/docs/network.zh-CN.md +0 -218
- package/docs/system.ja.md +0 -169
- package/docs/system.ko.md +0 -171
- package/docs/system.md +0 -173
- package/docs/system.zh-CN.md +0 -173
- package/docs/window.ja.md +0 -138
- package/docs/window.ko.md +0 -140
- package/docs/window.md +0 -141
- package/docs/window.zh-CN.md +0 -141
- package/native/exception-boundary.h +0 -97
- package/native/numeric-fields.h +0 -96
- package/native/shared-handle.h +0 -69
- package/test/tsconfig.json +0 -8
- package/tools/configure-lsp.cjs +0 -23
- package/tools/lib_downloader.cjs +0 -92
- package/tools/lib_downloader_urls.cjs +0 -23
package/src/graphics/shader.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { resolve } from 'node:path';
|
|
2
2
|
import { native, type NativeGraphicsHandle } from '../internal/native';
|
|
3
3
|
import {
|
|
4
|
-
flushGraphics,
|
|
4
|
+
flushGraphics,
|
|
5
|
+
graphicsContext,
|
|
6
|
+
graphicsNative,
|
|
7
|
+
shaderId,
|
|
8
|
+
shaderTextures,
|
|
5
9
|
} from '../internal/graphics-state';
|
|
6
10
|
import {
|
|
7
|
-
vector2Storage,
|
|
11
|
+
vector2Storage,
|
|
12
|
+
vector3Storage,
|
|
13
|
+
type ReadonlyValue as R,
|
|
8
14
|
} from '../internal/value-storage';
|
|
9
15
|
import { glslStorage } from '../internal/glsl-value';
|
|
10
16
|
import { InputStream } from '../system/input-stream';
|
|
@@ -41,13 +47,30 @@ export enum ShaderType {
|
|
|
41
47
|
Fragment,
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
type Uniform =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
type Uniform =
|
|
51
|
+
| number
|
|
52
|
+
| boolean
|
|
53
|
+
| R<Glsl.Vec2>
|
|
54
|
+
| R<Glsl.Vec3>
|
|
55
|
+
| R<Glsl.Vec4>
|
|
56
|
+
| R<Glsl.Ivec2>
|
|
57
|
+
| R<Glsl.Ivec3>
|
|
58
|
+
| R<Glsl.Ivec4>
|
|
59
|
+
| R<Glsl.Bvec2>
|
|
60
|
+
| R<Glsl.Bvec3>
|
|
61
|
+
| R<Glsl.Bvec4>
|
|
62
|
+
| R<Glsl.Mat3>
|
|
63
|
+
| R<Glsl.Mat4>
|
|
64
|
+
| ReadonlyTexture
|
|
65
|
+
| typeof Shader.CurrentTexture;
|
|
66
|
+
type ArrayElement =
|
|
67
|
+
| number
|
|
68
|
+
| R<Glsl.Vec2>
|
|
69
|
+
| R<Glsl.Vec3>
|
|
70
|
+
| R<Glsl.Vec4>
|
|
71
|
+
| R<Glsl.Mat3>
|
|
72
|
+
| R<Glsl.Mat4>;
|
|
73
|
+
type Sources<T> = [T, ShaderType] | [T, T] | [T, T, T];
|
|
51
74
|
|
|
52
75
|
/**
|
|
53
76
|
* Read-only interface to the same shader program.
|
|
@@ -55,9 +78,15 @@ type Sources<T> = [ T, ShaderType ] | [ T, T ] | [ T, T, T ];
|
|
|
55
78
|
* @ja 同じシェーダープログラムへの読み取り専用インターフェース。
|
|
56
79
|
* @ko 동일한 셰이더 프로그램의 읽기 전용 인터페이스입니다.
|
|
57
80
|
*/
|
|
58
|
-
export type ReadonlyShader = Readonly<
|
|
59
|
-
|
|
60
|
-
|
|
81
|
+
export type ReadonlyShader = Readonly<
|
|
82
|
+
Pick<
|
|
83
|
+
Shader,
|
|
84
|
+
| typeof graphicsNative
|
|
85
|
+
| typeof shaderId
|
|
86
|
+
| typeof shaderTextures
|
|
87
|
+
| 'getNativeHandle'
|
|
88
|
+
>
|
|
89
|
+
>;
|
|
61
90
|
|
|
62
91
|
function nameString(name: string): void {
|
|
63
92
|
if (typeof name !== 'string' || name.includes('\0')) {
|
|
@@ -65,20 +94,49 @@ function nameString(name: string): void {
|
|
|
65
94
|
}
|
|
66
95
|
}
|
|
67
96
|
|
|
68
|
-
function numeric(value: Uniform): {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (value
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (value
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (value instanceof Glsl.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (value instanceof Glsl.
|
|
97
|
+
function numeric(value: Uniform): {
|
|
98
|
+
type: number;
|
|
99
|
+
data: Float32Array | Int32Array;
|
|
100
|
+
} {
|
|
101
|
+
if (typeof value === 'number') {
|
|
102
|
+
return { type: 0, data: new Float32Array([ value ]) };
|
|
103
|
+
}
|
|
104
|
+
if (typeof value === 'boolean') {
|
|
105
|
+
return { type: 2, data: new Int32Array([ +value ]) };
|
|
106
|
+
}
|
|
107
|
+
if (value instanceof Glsl.Vec2) {
|
|
108
|
+
return { type: 3, data: value[vector2Storage] as Float32Array };
|
|
109
|
+
}
|
|
110
|
+
if (value instanceof Glsl.Vec3) {
|
|
111
|
+
return { type: 4, data: value[vector3Storage] as Float32Array };
|
|
112
|
+
}
|
|
113
|
+
if (value instanceof Glsl.Vec4) {
|
|
114
|
+
return { type: 5, data: value[glslStorage] as Float32Array };
|
|
115
|
+
}
|
|
116
|
+
if (value instanceof Glsl.Ivec2) {
|
|
117
|
+
return { type: 6, data: value[vector2Storage] as Int32Array };
|
|
118
|
+
}
|
|
119
|
+
if (value instanceof Glsl.Ivec3) {
|
|
120
|
+
return { type: 7, data: value[vector3Storage] as Int32Array };
|
|
121
|
+
}
|
|
122
|
+
if (value instanceof Glsl.Ivec4) {
|
|
123
|
+
return { type: 8, data: value[glslStorage] as Int32Array };
|
|
124
|
+
}
|
|
125
|
+
if (value instanceof Glsl.Bvec2) {
|
|
126
|
+
return { type: 9, data: new Int32Array(value[glslStorage]) };
|
|
127
|
+
}
|
|
128
|
+
if (value instanceof Glsl.Bvec3) {
|
|
129
|
+
return { type: 10, data: new Int32Array(value[glslStorage]) };
|
|
130
|
+
}
|
|
131
|
+
if (value instanceof Glsl.Bvec4) {
|
|
132
|
+
return { type: 11, data: new Int32Array(value[glslStorage]) };
|
|
133
|
+
}
|
|
134
|
+
if (value instanceof Glsl.Mat3) {
|
|
135
|
+
return { type: 12, data: value[glslStorage] };
|
|
136
|
+
}
|
|
137
|
+
if (value instanceof Glsl.Mat4) {
|
|
138
|
+
return { type: 13, data: value[glslStorage] };
|
|
139
|
+
}
|
|
82
140
|
throw new TypeError('Expected a Shader uniform value');
|
|
83
141
|
}
|
|
84
142
|
|
|
@@ -103,7 +161,9 @@ export class Shader {
|
|
|
103
161
|
* @ja 描画時に現在のオブジェクトにバインドされたテクスチャを使う uniform テクスチャのプレースホルダー。
|
|
104
162
|
* @ko 그릴 때 현재 객체에 바인딩된 텍스처를 사용하는 텍스처 uniform 자리표시자입니다.
|
|
105
163
|
*/
|
|
106
|
-
static readonly CurrentTexture: unique symbol = Symbol(
|
|
164
|
+
static readonly CurrentTexture: unique symbol = Symbol(
|
|
165
|
+
'Shader.CurrentTexture',
|
|
166
|
+
);
|
|
107
167
|
readonly [graphicsNative]: NativeGraphicsHandle<'shader'>;
|
|
108
168
|
readonly [shaderId]: number;
|
|
109
169
|
/**
|
|
@@ -172,16 +232,26 @@ export class Shader {
|
|
|
172
232
|
const code: (string | null)[] = [ null, null, null ];
|
|
173
233
|
for (let i = 0; i < 3; i++) {
|
|
174
234
|
const stream = stages[i];
|
|
175
|
-
if (stream === null)
|
|
176
|
-
|
|
235
|
+
if (stream === null) {
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
if (!(stream instanceof InputStream)) {
|
|
239
|
+
throw new TypeError('Expected an InputStream');
|
|
240
|
+
}
|
|
177
241
|
const size = await stream.getSize();
|
|
178
|
-
if (size === undefined || size === 0n)
|
|
242
|
+
if (size === undefined || size === 0n) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
179
245
|
if (typeof size !== 'bigint' || size < 0n || size > 0x7fffffffn) {
|
|
180
246
|
throw new RangeError('Shader stream size exceeds the buffer limit');
|
|
181
247
|
}
|
|
182
|
-
if (await stream.seek(0n) === undefined)
|
|
248
|
+
if ((await stream.seek(0n)) === undefined) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
183
251
|
const bytes = new Uint8Array(Number(size));
|
|
184
|
-
if (await stream.read(bytes) !== size)
|
|
252
|
+
if ((await stream.read(bytes)) !== size) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
185
255
|
code[i] = Buffer.from(bytes.buffer).toString('utf8');
|
|
186
256
|
}
|
|
187
257
|
return this.compile(true, code);
|
|
@@ -204,23 +274,36 @@ export class Shader {
|
|
|
204
274
|
* @ko 기록된 그리기를 먼저 제출한 후 GLSL float 또는 int를 명시하여 숫자 uniform을 설정합니다.
|
|
205
275
|
*/
|
|
206
276
|
setUniform(name: string, value: number, type: 'float' | 'int'): void;
|
|
207
|
-
setUniform(
|
|
277
|
+
setUniform(
|
|
278
|
+
name: string,
|
|
279
|
+
value: Uniform,
|
|
280
|
+
scalarType?: 'float' | 'int',
|
|
281
|
+
): void {
|
|
208
282
|
nameString(name);
|
|
209
|
-
if (
|
|
210
|
-
|
|
211
|
-
|
|
283
|
+
if (
|
|
284
|
+
scalarType !== undefined &&
|
|
285
|
+
(typeof value !== 'number' || ![ 'float', 'int' ].includes(scalarType))
|
|
286
|
+
) {
|
|
287
|
+
throw new TypeError(
|
|
288
|
+
'Expected a numeric uniform and float or int type',
|
|
289
|
+
);
|
|
212
290
|
}
|
|
213
291
|
if (value instanceof Texture || value === Shader.CurrentTexture) {
|
|
214
292
|
flushGraphics();
|
|
215
|
-
const location = native.setShaderTexture(
|
|
216
|
-
|
|
293
|
+
const location = native.setShaderTexture(
|
|
294
|
+
this[graphicsNative],
|
|
295
|
+
name,
|
|
296
|
+
value instanceof Texture ? value[graphicsNative] : null,
|
|
297
|
+
);
|
|
217
298
|
if (value instanceof Texture && location !== undefined) {
|
|
218
299
|
this.textures.set(location, value);
|
|
219
300
|
}
|
|
220
301
|
return;
|
|
221
302
|
}
|
|
222
|
-
const { type, data } =
|
|
223
|
-
|
|
303
|
+
const { type, data } =
|
|
304
|
+
scalarType === 'int'
|
|
305
|
+
? { type: 1, data: new Int32Array([ value as number ]) }
|
|
306
|
+
: numeric(value);
|
|
224
307
|
flushGraphics();
|
|
225
308
|
native.setShaderUniform(this[graphicsNative], name, type, data, false);
|
|
226
309
|
}
|
|
@@ -232,18 +315,30 @@ export class Shader {
|
|
|
232
315
|
* @ja 記録済み描画を先に送信し、同じ型の float、浮動小数点ベクトル、または行列の配列を同期的にアップロードします。
|
|
233
316
|
* @ko 기록된 그리기를 먼저 제출한 후 동일 형식의 float, 부동소수점 벡터 또는 행렬 배열을 동기적으로 업로드합니다.
|
|
234
317
|
*/
|
|
235
|
-
setUniformArray(
|
|
318
|
+
setUniformArray(
|
|
319
|
+
name: string,
|
|
320
|
+
values: Float32Array | readonly ArrayElement[],
|
|
321
|
+
): void {
|
|
236
322
|
nameString(name);
|
|
237
323
|
let type = 0;
|
|
238
324
|
let data: Float32Array;
|
|
239
|
-
if (values instanceof Float32Array)
|
|
240
|
-
|
|
241
|
-
|
|
325
|
+
if (values instanceof Float32Array) {
|
|
326
|
+
data = values;
|
|
327
|
+
} else {
|
|
328
|
+
if (!Array.isArray(values)) {
|
|
329
|
+
throw new TypeError('Expected a uniform array');
|
|
330
|
+
}
|
|
242
331
|
const parts = Array.from(values, value => numeric(value));
|
|
243
|
-
if (parts.length)
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
332
|
+
if (parts.length) {
|
|
333
|
+
type = parts[0].type;
|
|
334
|
+
}
|
|
335
|
+
if (
|
|
336
|
+
![ 0, 3, 4, 5, 12, 13 ].includes(type) ||
|
|
337
|
+
parts.some(part => part.type !== type)
|
|
338
|
+
) {
|
|
339
|
+
throw new TypeError(
|
|
340
|
+
'Expected a homogeneous float, vector or matrix array',
|
|
341
|
+
);
|
|
247
342
|
}
|
|
248
343
|
const size = parts[0]?.data.length ?? 1;
|
|
249
344
|
data = new Float32Array(parts.length * size);
|
|
@@ -283,14 +378,18 @@ export class Shader {
|
|
|
283
378
|
* @ja 現在の環境がシェーダーに対応しているかを返します。
|
|
284
379
|
* @ko 현재 환경의 셰이더 지원 여부를 반환합니다.
|
|
285
380
|
*/
|
|
286
|
-
static isAvailable(): boolean {
|
|
381
|
+
static isAvailable(): boolean {
|
|
382
|
+
return native.isShaderAvailable(false);
|
|
383
|
+
}
|
|
287
384
|
/**
|
|
288
385
|
* Returns whether the current environment supports geometry shaders.
|
|
289
386
|
* @zh 返回当前环境是否支持几何着色器。
|
|
290
387
|
* @ja 現在の環境がジオメトリシェーダーに対応しているかを返します。
|
|
291
388
|
* @ko 현재 환경의 기하 셰이더 지원 여부를 반환합니다.
|
|
292
389
|
*/
|
|
293
|
-
static isGeometryAvailable(): boolean {
|
|
390
|
+
static isGeometryAvailable(): boolean {
|
|
391
|
+
return native.isShaderAvailable(true);
|
|
392
|
+
}
|
|
294
393
|
|
|
295
394
|
/**
|
|
296
395
|
* Normalizes stage arguments into a [vertex, geometry, fragment] tuple.
|
|
@@ -300,16 +399,26 @@ export class Shader {
|
|
|
300
399
|
*/
|
|
301
400
|
private stages<T>(sources: Sources<T>): (T | null)[] {
|
|
302
401
|
if (sources.length === 2 && typeof sources[1] === 'number') {
|
|
303
|
-
if (
|
|
402
|
+
if (
|
|
403
|
+
!Number.isInteger(sources[1]) ||
|
|
404
|
+
sources[1] < 0 ||
|
|
405
|
+
sources[1] > 2
|
|
406
|
+
) {
|
|
304
407
|
throw new RangeError('Invalid shader type');
|
|
305
408
|
}
|
|
306
409
|
const result: (T | null)[] = [ null, null, null ];
|
|
307
410
|
result[sources[1]] = sources[0];
|
|
308
411
|
return result;
|
|
309
412
|
}
|
|
310
|
-
if (sources.length === 2)
|
|
311
|
-
|
|
312
|
-
|
|
413
|
+
if (sources.length === 2) {
|
|
414
|
+
return [ sources[0], null, sources[1] as T ];
|
|
415
|
+
}
|
|
416
|
+
if (sources.length === 3) {
|
|
417
|
+
return sources as T[];
|
|
418
|
+
}
|
|
419
|
+
throw new TypeError(
|
|
420
|
+
'Expected a shader source and type, or two/three sources',
|
|
421
|
+
);
|
|
313
422
|
}
|
|
314
423
|
|
|
315
424
|
/**
|
|
@@ -318,11 +427,20 @@ export class Shader {
|
|
|
318
427
|
* @ja ファイルまたはメモリからソースを読み込み、コンパイルします。
|
|
319
428
|
* @ko 파일 또는 메모리에서 소스를 로드하고 컴파일합니다.
|
|
320
429
|
*/
|
|
321
|
-
private async load(
|
|
430
|
+
private async load(
|
|
431
|
+
memory: boolean,
|
|
432
|
+
sources: Sources<string>,
|
|
433
|
+
): Promise<boolean> {
|
|
322
434
|
const stages = this.stages(sources).map(source => {
|
|
323
|
-
if (source === null)
|
|
324
|
-
|
|
325
|
-
|
|
435
|
+
if (source === null) {
|
|
436
|
+
return null;
|
|
437
|
+
}
|
|
438
|
+
if (typeof source !== 'string') {
|
|
439
|
+
throw new TypeError('Expected shader source strings');
|
|
440
|
+
}
|
|
441
|
+
if (!memory && source.includes('\0')) {
|
|
442
|
+
throw new TypeError('Invalid shader path');
|
|
443
|
+
}
|
|
326
444
|
return memory || !source ? source : resolve(source);
|
|
327
445
|
});
|
|
328
446
|
return this.compile(memory, stages);
|
|
@@ -334,11 +452,18 @@ export class Shader {
|
|
|
334
452
|
* @ja シェーダープログラムを非同期にコンパイルしてリンクします。
|
|
335
453
|
* @ko 셰이더 프로그램을 비동기로 컴파일하고 링크합니다.
|
|
336
454
|
*/
|
|
337
|
-
private compile(
|
|
455
|
+
private compile(
|
|
456
|
+
memory: boolean,
|
|
457
|
+
sources: (string | null)[],
|
|
458
|
+
): Promise<boolean> {
|
|
338
459
|
return new Promise((resolve, reject) => {
|
|
339
460
|
native.compileShader(memory, sources, (error, program) => {
|
|
340
|
-
if (error)
|
|
341
|
-
|
|
461
|
+
if (error) {
|
|
462
|
+
return reject(error);
|
|
463
|
+
}
|
|
464
|
+
if (!program) {
|
|
465
|
+
return resolve(false);
|
|
466
|
+
}
|
|
342
467
|
try {
|
|
343
468
|
flushGraphics();
|
|
344
469
|
native.commitShader(this[graphicsNative], program);
|
package/src/graphics/shape.ts
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
|
-
native,
|
|
2
|
+
native,
|
|
3
|
+
type NativeGraphicsHandle,
|
|
4
|
+
type NativeShapeInfo,
|
|
3
5
|
} from '../internal/native';
|
|
4
6
|
import {
|
|
5
|
-
dispatchDrawable,
|
|
6
|
-
|
|
7
|
+
dispatchDrawable,
|
|
8
|
+
flushShapeReaders,
|
|
9
|
+
graphicsContext,
|
|
10
|
+
graphicsNative,
|
|
11
|
+
recordShape,
|
|
12
|
+
shapeState,
|
|
13
|
+
textureId,
|
|
14
|
+
type ShapeData,
|
|
7
15
|
} from '../internal/graphics-state';
|
|
8
16
|
import {
|
|
9
|
-
withTransformable,
|
|
17
|
+
withTransformable,
|
|
18
|
+
transformableState,
|
|
19
|
+
type TransformableState,
|
|
10
20
|
} from '../internal/transformable';
|
|
11
21
|
import {
|
|
12
|
-
mutableValue,
|
|
22
|
+
mutableValue,
|
|
23
|
+
rectStorage,
|
|
24
|
+
type ReadonlyValue as R,
|
|
13
25
|
} from '../internal/value-storage';
|
|
14
26
|
import { LazyValue } from '../internal/lazy-value';
|
|
15
27
|
import { nativeStruct } from '../internal/struct-view';
|
|
@@ -29,7 +41,9 @@ interface ShapeInit {
|
|
|
29
41
|
}
|
|
30
42
|
|
|
31
43
|
export function shapeNumber(value: number): number {
|
|
32
|
-
if (typeof value !== 'number')
|
|
44
|
+
if (typeof value !== 'number') {
|
|
45
|
+
throw new TypeError('Expected a number');
|
|
46
|
+
}
|
|
33
47
|
const result = Math.fround(value);
|
|
34
48
|
if (!Number.isFinite(result)) {
|
|
35
49
|
throw new RangeError('Expected a finite float32 value');
|
|
@@ -38,8 +52,11 @@ export function shapeNumber(value: number): number {
|
|
|
38
52
|
}
|
|
39
53
|
|
|
40
54
|
export function shapeCount(value: number): number {
|
|
41
|
-
if (
|
|
42
|
-
|
|
55
|
+
if (
|
|
56
|
+
!Number.isInteger(value) ||
|
|
57
|
+
value < 0 ||
|
|
58
|
+
value > Math.floor(0x7fffffff / (6 * 20)) - 2
|
|
59
|
+
) {
|
|
43
60
|
throw new RangeError('Shape point count exceeds the buffer limit');
|
|
44
61
|
}
|
|
45
62
|
return value;
|
|
@@ -68,16 +85,23 @@ class ShapeResource extends Drawable {
|
|
|
68
85
|
|
|
69
86
|
constructor(init: ShapeInit) {
|
|
70
87
|
super();
|
|
71
|
-
const mapping = native.createShape(
|
|
72
|
-
|
|
88
|
+
const mapping = native.createShape(
|
|
89
|
+
graphicsContext(),
|
|
90
|
+
init.kind,
|
|
91
|
+
init.x ?? 0,
|
|
92
|
+
init.y ?? 0,
|
|
93
|
+
init.source?.[graphicsNative],
|
|
94
|
+
);
|
|
73
95
|
this[graphicsNative] = mapping.handle;
|
|
74
96
|
this[shapeState] = {
|
|
75
|
-
id: mapping.id,
|
|
97
|
+
id: mapping.id,
|
|
98
|
+
words: new Uint32Array(mapping.appearance),
|
|
76
99
|
rectangle: new Int32Array(mapping.appearance, 12, 4),
|
|
77
100
|
texture: init.source?.[shapeState].texture ?? null,
|
|
78
101
|
};
|
|
79
102
|
this[transformableState] = {
|
|
80
|
-
handle: mapping.transformable,
|
|
103
|
+
handle: mapping.transformable,
|
|
104
|
+
values: new Float32Array(mapping.buffer),
|
|
81
105
|
};
|
|
82
106
|
this.shapeInfo = nativeStruct<NativeShapeInfo>(mapping.info);
|
|
83
107
|
}
|
|
@@ -90,18 +114,27 @@ class ShapeResource extends Drawable {
|
|
|
90
114
|
* @ko 텍스처 참조를 설정하고 유지합니다. null은 텍스처를 비활성화하며 resetRect가 true이면 전체 텍스처를 사용합니다.
|
|
91
115
|
*/
|
|
92
116
|
setTexture(
|
|
93
|
-
this: ShapeResource,
|
|
117
|
+
this: ShapeResource,
|
|
118
|
+
texture: ReadonlyTexture | null,
|
|
119
|
+
resetRect = false,
|
|
94
120
|
): void {
|
|
95
121
|
if (texture !== null && !(texture instanceof Texture)) {
|
|
96
122
|
throw new TypeError('Expected a Texture or null');
|
|
97
123
|
}
|
|
98
|
-
if (typeof resetRect !== 'boolean')
|
|
124
|
+
if (typeof resetRect !== 'boolean') {
|
|
125
|
+
throw new TypeError('Expected a boolean');
|
|
126
|
+
}
|
|
99
127
|
const state = this[shapeState];
|
|
100
|
-
const reset =
|
|
101
|
-
|
|
128
|
+
const reset =
|
|
129
|
+
texture &&
|
|
130
|
+
(resetRect ||
|
|
131
|
+
(!state.texture && state.rectangle.every(value => value === 0)));
|
|
102
132
|
if (texture !== state.texture) {
|
|
103
|
-
native.setShapeTexture(
|
|
104
|
-
|
|
133
|
+
native.setShapeTexture(
|
|
134
|
+
this[graphicsNative],
|
|
135
|
+
texture?.[graphicsNative] ?? null,
|
|
136
|
+
texture?.[textureId] ?? 0,
|
|
137
|
+
);
|
|
105
138
|
state.texture = texture;
|
|
106
139
|
}
|
|
107
140
|
if (reset) {
|
|
@@ -128,7 +161,9 @@ class ShapeResource extends Drawable {
|
|
|
128
161
|
* @ko 사용할 텍스처 픽셀 영역을 복사합니다. 음수 크기로 텍스처를 반전할 수 있습니다.
|
|
129
162
|
*/
|
|
130
163
|
setTextureRect(this: ShapeResource, rectangle: R<IntRect>): void {
|
|
131
|
-
if (!(rectangle instanceof IntRect))
|
|
164
|
+
if (!(rectangle instanceof IntRect)) {
|
|
165
|
+
throw new TypeError('Expected an IntRect');
|
|
166
|
+
}
|
|
132
167
|
this[shapeState].rectangle.set(rectangle[rectStorage]);
|
|
133
168
|
}
|
|
134
169
|
|
|
@@ -141,9 +176,11 @@ class ShapeResource extends Drawable {
|
|
|
141
176
|
getTextureRect(): R<IntRect> {
|
|
142
177
|
if (!this.rectangleView) {
|
|
143
178
|
const handle = this[graphicsNative];
|
|
144
|
-
this.rectangleView = intRectFromState(
|
|
145
|
-
this[shapeState].rectangle, () =>
|
|
146
|
-
|
|
179
|
+
this.rectangleView = intRectFromState(
|
|
180
|
+
new LazyValue(this[shapeState].rectangle, () =>
|
|
181
|
+
native.shapeTextureRect(handle),
|
|
182
|
+
),
|
|
183
|
+
);
|
|
147
184
|
}
|
|
148
185
|
return this.rectangleView;
|
|
149
186
|
}
|
|
@@ -155,7 +192,9 @@ class ShapeResource extends Drawable {
|
|
|
155
192
|
* @ko 채우기 색상을 설정합니다. 그릴 때 텍스처 색상과 곱해집니다.
|
|
156
193
|
*/
|
|
157
194
|
setFillColor(this: ShapeResource, color: R<Color>): void {
|
|
158
|
-
if (!(color instanceof Color))
|
|
195
|
+
if (!(color instanceof Color)) {
|
|
196
|
+
throw new TypeError('Expected a Color');
|
|
197
|
+
}
|
|
159
198
|
this[shapeState].words[1] = color.toInteger();
|
|
160
199
|
}
|
|
161
200
|
|
|
@@ -176,7 +215,9 @@ class ShapeResource extends Drawable {
|
|
|
176
215
|
* @ko 윤곽선 색상을 복사합니다.
|
|
177
216
|
*/
|
|
178
217
|
setOutlineColor(this: ShapeResource, color: R<Color>): void {
|
|
179
|
-
if (!(color instanceof Color))
|
|
218
|
+
if (!(color instanceof Color)) {
|
|
219
|
+
throw new TypeError('Expected a Color');
|
|
220
|
+
}
|
|
180
221
|
this[shapeState].words[2] = color.toInteger();
|
|
181
222
|
}
|
|
182
223
|
|
|
@@ -220,7 +261,9 @@ class ShapeResource extends Drawable {
|
|
|
220
261
|
*/
|
|
221
262
|
setMiterLimit(this: ShapeResource, limit: number): void {
|
|
222
263
|
limit = shapeNumber(limit);
|
|
223
|
-
if (limit < 1)
|
|
264
|
+
if (limit < 1) {
|
|
265
|
+
throw new RangeError('Miter limit must be at least 1');
|
|
266
|
+
}
|
|
224
267
|
this.changeGeometry(1, limit);
|
|
225
268
|
}
|
|
226
269
|
|
|
@@ -252,31 +295,46 @@ class ShapeResource extends Drawable {
|
|
|
252
295
|
*/
|
|
253
296
|
getLocalBounds(): FloatRect {
|
|
254
297
|
const { left, top, boundsWidth, boundsHeight } = this.shapeInfo;
|
|
255
|
-
return new FloatRect(
|
|
256
|
-
new Vector2f(
|
|
298
|
+
return new FloatRect(
|
|
299
|
+
new Vector2f(left, top),
|
|
300
|
+
new Vector2f(boundsWidth, boundsHeight),
|
|
301
|
+
);
|
|
257
302
|
}
|
|
258
303
|
|
|
259
304
|
protected changeGeometry(
|
|
260
|
-
operation: number,
|
|
305
|
+
operation: number,
|
|
306
|
+
x: number,
|
|
307
|
+
y?: number,
|
|
308
|
+
z?: number,
|
|
261
309
|
): void {
|
|
262
310
|
flushShapeReaders(this);
|
|
263
|
-
native.changeShapeGeometry(
|
|
264
|
-
this[graphicsNative], operation, x, y, z);
|
|
311
|
+
native.changeShapeGeometry(this[graphicsNative], operation, x, y, z);
|
|
265
312
|
}
|
|
266
313
|
|
|
267
314
|
protected readPoint(index: number): Vector2f {
|
|
268
|
-
return new Vector2f(
|
|
315
|
+
return new Vector2f(
|
|
316
|
+
...native.getShapePoint(this[graphicsNative], index),
|
|
317
|
+
);
|
|
269
318
|
}
|
|
270
319
|
|
|
271
|
-
protected draw(
|
|
320
|
+
protected draw(
|
|
321
|
+
this: Shape,
|
|
322
|
+
target: RenderTarget,
|
|
323
|
+
states: RenderStates,
|
|
324
|
+
): void {
|
|
272
325
|
target[recordShape](this, states);
|
|
273
326
|
}
|
|
274
327
|
|
|
275
328
|
[dispatchDrawable](
|
|
276
|
-
this: Shape,
|
|
329
|
+
this: Shape,
|
|
330
|
+
target: RenderTarget,
|
|
331
|
+
states: RenderStates,
|
|
277
332
|
): void {
|
|
278
|
-
if (this.draw === ShapeResource.prototype.draw)
|
|
279
|
-
|
|
333
|
+
if (this.draw === ShapeResource.prototype.draw) {
|
|
334
|
+
this.draw(target, states);
|
|
335
|
+
} else {
|
|
336
|
+
super[dispatchDrawable](target, states);
|
|
337
|
+
}
|
|
280
338
|
}
|
|
281
339
|
}
|
|
282
340
|
|