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/texture.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
native,
|
|
2
|
+
native,
|
|
3
|
+
type NativeGraphicsHandle,
|
|
4
|
+
type NativeTextureInfo,
|
|
3
5
|
type NativeTextureMapping,
|
|
4
6
|
} from '../internal/native';
|
|
5
7
|
import {
|
|
6
|
-
graphicsContext,
|
|
8
|
+
graphicsContext,
|
|
9
|
+
graphicsNative,
|
|
10
|
+
flushGraphics,
|
|
11
|
+
textureId,
|
|
12
|
+
textureOwner,
|
|
7
13
|
type PendingTarget,
|
|
8
14
|
} from '../internal/graphics-state';
|
|
9
15
|
import { type ReadonlyValue } from '../internal/value-storage';
|
|
@@ -22,10 +28,20 @@ import { CoordinateType } from './render-states';
|
|
|
22
28
|
* @ja 同一テクスチャリソースへのコンパイル時 const 参照。
|
|
23
29
|
* @ko 동일한 텍스처 리소스에 대한 컴파일 시점의 const 참조입니다.
|
|
24
30
|
*/
|
|
25
|
-
export type ReadonlyTexture = Readonly<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
export type ReadonlyTexture = Readonly<
|
|
32
|
+
Pick<
|
|
33
|
+
Texture,
|
|
34
|
+
| typeof graphicsNative
|
|
35
|
+
| typeof textureId
|
|
36
|
+
| typeof textureOwner
|
|
37
|
+
| 'getSize'
|
|
38
|
+
| 'copyToImage'
|
|
39
|
+
| 'isSmooth'
|
|
40
|
+
| 'isRepeated'
|
|
41
|
+
| 'isSrgb'
|
|
42
|
+
| 'getNativeHandle'
|
|
43
|
+
>
|
|
44
|
+
>;
|
|
29
45
|
|
|
30
46
|
/**
|
|
31
47
|
* Internal factory for a render target's borrowed GPU texture.
|
|
@@ -34,11 +50,13 @@ typeof graphicsNative | typeof textureId | typeof textureOwner |
|
|
|
34
50
|
* @ko 렌더 대상에서 빌린 GPU 텍스처를 위한 내부 팩토리입니다.
|
|
35
51
|
*/
|
|
36
52
|
export let textureFromMapping: (
|
|
37
|
-
mapping: NativeTextureMapping,
|
|
53
|
+
mapping: NativeTextureMapping,
|
|
54
|
+
owner: PendingTarget,
|
|
38
55
|
) => ReadonlyTexture;
|
|
39
56
|
|
|
40
57
|
export let fontTextureFromMapping: (
|
|
41
|
-
mapping: NativeTextureMapping,
|
|
58
|
+
mapping: NativeTextureMapping,
|
|
59
|
+
owner: object,
|
|
42
60
|
) => ReadonlyTexture;
|
|
43
61
|
|
|
44
62
|
function coordinates(value: Readonly<Vector2u>): void {
|
|
@@ -48,12 +66,18 @@ function coordinates(value: Readonly<Vector2u>): void {
|
|
|
48
66
|
}
|
|
49
67
|
|
|
50
68
|
function flag(value: boolean): void {
|
|
51
|
-
if (typeof value !== 'boolean')
|
|
69
|
+
if (typeof value !== 'boolean') {
|
|
70
|
+
throw new TypeError('Expected a boolean');
|
|
71
|
+
}
|
|
52
72
|
}
|
|
53
73
|
|
|
54
74
|
function areaSnapshot(area?: ReadonlyValue<IntRect>): IntRect | undefined {
|
|
55
|
-
if (area === undefined)
|
|
56
|
-
|
|
75
|
+
if (area === undefined) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
if (!(area instanceof IntRect)) {
|
|
79
|
+
throw new TypeError('Expected an IntRect');
|
|
80
|
+
}
|
|
57
81
|
return new IntRect(area);
|
|
58
82
|
}
|
|
59
83
|
|
|
@@ -137,12 +161,18 @@ export class Texture {
|
|
|
137
161
|
*/
|
|
138
162
|
constructor(image: Image, sRgb?: boolean, area?: ReadonlyValue<IntRect>);
|
|
139
163
|
constructor(
|
|
140
|
-
source?: Readonly<Vector2u> | ReadonlyTexture | Image,
|
|
164
|
+
source?: Readonly<Vector2u> | ReadonlyTexture | Image,
|
|
165
|
+
sRgb = false,
|
|
141
166
|
area?: ReadonlyValue<IntRect>,
|
|
142
167
|
) {
|
|
143
168
|
flag(sRgb);
|
|
144
|
-
if (
|
|
145
|
-
|
|
169
|
+
if (
|
|
170
|
+
source !== undefined &&
|
|
171
|
+
!(source instanceof Texture) &&
|
|
172
|
+
!(source instanceof Image)
|
|
173
|
+
) {
|
|
174
|
+
coordinates(source as Readonly<Vector2u>);
|
|
175
|
+
}
|
|
146
176
|
if (area !== undefined && !(area instanceof IntRect)) {
|
|
147
177
|
throw new TypeError('Expected an IntRect');
|
|
148
178
|
}
|
|
@@ -159,8 +189,13 @@ export class Texture {
|
|
|
159
189
|
this[graphicsNative] = mapping.handle;
|
|
160
190
|
this[textureId] = mapping.id;
|
|
161
191
|
this.state = nativeStruct<NativeTextureInfo>(mapping.info);
|
|
162
|
-
if (
|
|
163
|
-
|
|
192
|
+
if (
|
|
193
|
+
source instanceof Image &&
|
|
194
|
+
!this.loadFromImage(source, sRgb, area)
|
|
195
|
+
) {
|
|
196
|
+
throw new SFMLError(
|
|
197
|
+
'SFML could not create the texture from the image',
|
|
198
|
+
);
|
|
164
199
|
}
|
|
165
200
|
}
|
|
166
201
|
|
|
@@ -224,7 +259,10 @@ export class Texture {
|
|
|
224
259
|
flag(sRgb);
|
|
225
260
|
flushGraphics();
|
|
226
261
|
const state = native.resizeTexture(
|
|
227
|
-
this[graphicsNative],
|
|
262
|
+
this[graphicsNative],
|
|
263
|
+
size.x,
|
|
264
|
+
size.y,
|
|
265
|
+
sRgb,
|
|
228
266
|
);
|
|
229
267
|
return state !== undefined;
|
|
230
268
|
}
|
|
@@ -236,7 +274,9 @@ export class Texture {
|
|
|
236
274
|
* @ko GPU에서 독립적인 네이티브 소유 Image로 동기적으로 읽어옵니다.
|
|
237
275
|
*/
|
|
238
276
|
copyToImage(): Image {
|
|
239
|
-
return imageFromMapping(
|
|
277
|
+
return imageFromMapping(
|
|
278
|
+
native.copyTextureToImage(this[graphicsNative]),
|
|
279
|
+
);
|
|
240
280
|
}
|
|
241
281
|
|
|
242
282
|
/**
|
|
@@ -261,13 +301,15 @@ export class Texture {
|
|
|
261
301
|
*/
|
|
262
302
|
swap(other: Texture): void {
|
|
263
303
|
this.checkWritable();
|
|
264
|
-
if (!(other instanceof Texture))
|
|
304
|
+
if (!(other instanceof Texture)) {
|
|
305
|
+
throw new TypeError('Expected a Texture');
|
|
306
|
+
}
|
|
265
307
|
other.checkWritable();
|
|
266
|
-
if (other === this)
|
|
308
|
+
if (other === this) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
267
311
|
flushGraphics();
|
|
268
|
-
native.swapTextures(
|
|
269
|
-
this[graphicsNative], other[graphicsNative],
|
|
270
|
-
);
|
|
312
|
+
native.swapTextures(this[graphicsNative], other[graphicsNative]);
|
|
271
313
|
}
|
|
272
314
|
|
|
273
315
|
/**
|
|
@@ -279,8 +321,12 @@ export class Texture {
|
|
|
279
321
|
*/
|
|
280
322
|
assign(source: ReadonlyTexture): this {
|
|
281
323
|
this.checkWritable();
|
|
282
|
-
if (!(source instanceof Texture))
|
|
283
|
-
|
|
324
|
+
if (!(source instanceof Texture)) {
|
|
325
|
+
throw new TypeError('Expected a Texture');
|
|
326
|
+
}
|
|
327
|
+
if (source === this) {
|
|
328
|
+
return this;
|
|
329
|
+
}
|
|
284
330
|
flushGraphics();
|
|
285
331
|
native.assignTexture(this[graphicsNative], source[graphicsNative]);
|
|
286
332
|
return this;
|
|
@@ -294,13 +340,17 @@ export class Texture {
|
|
|
294
340
|
* @ko 파일을 비동기로 디코딩한 후 픽셀을 업로드하고 성공 여부를 반환합니다. area는 픽셀 좌표이며 기본값은 전체 이미지입니다.
|
|
295
341
|
*/
|
|
296
342
|
async loadFromFile(
|
|
297
|
-
filename: string,
|
|
343
|
+
filename: string,
|
|
344
|
+
sRgb = false,
|
|
345
|
+
area?: ReadonlyValue<IntRect>,
|
|
298
346
|
): Promise<boolean> {
|
|
299
347
|
this.checkWritable();
|
|
300
348
|
flag(sRgb);
|
|
301
349
|
const snapshot = areaSnapshot(area);
|
|
302
350
|
const image = new Image();
|
|
303
|
-
if (!await image.loadFromFile(filename))
|
|
351
|
+
if (!(await image.loadFromFile(filename))) {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
304
354
|
return this.loadFromImage(image, sRgb, snapshot);
|
|
305
355
|
}
|
|
306
356
|
|
|
@@ -312,13 +362,17 @@ export class Texture {
|
|
|
312
362
|
* @ko 인코딩된 이미지 바이트를 비동기로 디코딩한 후 픽셀을 업로드하고 성공 여부를 반환합니다. sRgb의 기본값은 false입니다.
|
|
313
363
|
*/
|
|
314
364
|
async loadFromMemory(
|
|
315
|
-
data: Uint8Array,
|
|
365
|
+
data: Uint8Array,
|
|
366
|
+
sRgb = false,
|
|
367
|
+
area?: ReadonlyValue<IntRect>,
|
|
316
368
|
): Promise<boolean> {
|
|
317
369
|
this.checkWritable();
|
|
318
370
|
flag(sRgb);
|
|
319
371
|
const snapshot = areaSnapshot(area);
|
|
320
372
|
const image = new Image();
|
|
321
|
-
if (!await image.loadFromMemory(data))
|
|
373
|
+
if (!(await image.loadFromMemory(data))) {
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
322
376
|
return this.loadFromImage(image, sRgb, snapshot);
|
|
323
377
|
}
|
|
324
378
|
|
|
@@ -331,13 +385,17 @@ export class Texture {
|
|
|
331
385
|
* 거부합니다.
|
|
332
386
|
*/
|
|
333
387
|
async loadFromStream(
|
|
334
|
-
stream: InputStream,
|
|
388
|
+
stream: InputStream,
|
|
389
|
+
sRgb = false,
|
|
390
|
+
area?: ReadonlyValue<IntRect>,
|
|
335
391
|
): Promise<boolean> {
|
|
336
392
|
this.checkWritable();
|
|
337
393
|
flag(sRgb);
|
|
338
394
|
const snapshot = areaSnapshot(area);
|
|
339
395
|
const image = new Image();
|
|
340
|
-
if (!await image.loadFromStream(stream))
|
|
396
|
+
if (!(await image.loadFromStream(stream))) {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
341
399
|
return this.loadFromImage(image, sRgb, snapshot);
|
|
342
400
|
}
|
|
343
401
|
|
|
@@ -349,19 +407,27 @@ export class Texture {
|
|
|
349
407
|
* @ko Image의 지정한 픽셀 영역을 동기적으로 업로드하고 성공 여부를 반환합니다. 기본값은 전체 이미지입니다.
|
|
350
408
|
*/
|
|
351
409
|
loadFromImage(
|
|
352
|
-
image: Image,
|
|
410
|
+
image: Image,
|
|
411
|
+
sRgb = false,
|
|
412
|
+
area?: ReadonlyValue<IntRect>,
|
|
353
413
|
): boolean {
|
|
354
414
|
this.checkWritable();
|
|
355
|
-
if (!(image instanceof Image))
|
|
415
|
+
if (!(image instanceof Image)) {
|
|
416
|
+
throw new TypeError('Expected an Image');
|
|
417
|
+
}
|
|
356
418
|
flag(sRgb);
|
|
357
419
|
if (area !== undefined && !(area instanceof IntRect)) {
|
|
358
420
|
throw new TypeError('Expected an IntRect');
|
|
359
421
|
}
|
|
360
422
|
flushGraphics();
|
|
361
423
|
const state = native.loadTextureImage(
|
|
362
|
-
this[graphicsNative],
|
|
363
|
-
|
|
364
|
-
|
|
424
|
+
this[graphicsNative],
|
|
425
|
+
image[graphicsNative],
|
|
426
|
+
sRgb,
|
|
427
|
+
area?.position.x ?? 0,
|
|
428
|
+
area?.position.y ?? 0,
|
|
429
|
+
area?.size.x ?? 0,
|
|
430
|
+
area?.size.y ?? 0,
|
|
365
431
|
);
|
|
366
432
|
return state !== undefined;
|
|
367
433
|
}
|
|
@@ -382,7 +448,9 @@ export class Texture {
|
|
|
382
448
|
* @ko size 크기의 RGBA8 픽셀 블록을 dest에 업로드합니다. 모든 좌표와 크기는 픽셀 단위입니다.
|
|
383
449
|
*/
|
|
384
450
|
update(
|
|
385
|
-
pixels: Uint8Array,
|
|
451
|
+
pixels: Uint8Array,
|
|
452
|
+
size: Readonly<Vector2u>,
|
|
453
|
+
dest: Readonly<Vector2u>,
|
|
386
454
|
): void;
|
|
387
455
|
/**
|
|
388
456
|
* Copies image, texture or window contents to dest (default origin); the
|
|
@@ -392,18 +460,26 @@ export class Texture {
|
|
|
392
460
|
* @ko 이미지, 텍스처 또는 창 내용을 dest(기본값은 원점)에 복사합니다. 대상 영역은 전체 소스를 담을 수 있어야 합니다.
|
|
393
461
|
*/
|
|
394
462
|
update(
|
|
395
|
-
source: Image | ReadonlyTexture | Window,
|
|
463
|
+
source: Image | ReadonlyTexture | Window,
|
|
464
|
+
dest?: Readonly<Vector2u>,
|
|
396
465
|
): void;
|
|
397
466
|
update(
|
|
398
467
|
source: Uint8Array | Image | ReadonlyTexture | Window,
|
|
399
|
-
sizeOrDest?: Readonly<Vector2u>,
|
|
468
|
+
sizeOrDest?: Readonly<Vector2u>,
|
|
469
|
+
dest?: Readonly<Vector2u>,
|
|
400
470
|
): void {
|
|
401
471
|
this.checkWritable();
|
|
402
|
-
if (sizeOrDest !== undefined)
|
|
403
|
-
|
|
472
|
+
if (sizeOrDest !== undefined) {
|
|
473
|
+
coordinates(sizeOrDest);
|
|
474
|
+
}
|
|
475
|
+
if (dest !== undefined) {
|
|
476
|
+
coordinates(dest);
|
|
477
|
+
}
|
|
404
478
|
if (source instanceof Uint8Array) {
|
|
405
479
|
if ((sizeOrDest === undefined) !== (dest === undefined)) {
|
|
406
|
-
throw new TypeError(
|
|
480
|
+
throw new TypeError(
|
|
481
|
+
'Pixel region requires both size and destination',
|
|
482
|
+
);
|
|
407
483
|
}
|
|
408
484
|
const width = sizeOrDest?.x ?? this.state.width;
|
|
409
485
|
const height = sizeOrDest?.y ?? this.state.height;
|
|
@@ -414,31 +490,59 @@ export class Texture {
|
|
|
414
490
|
throw new RangeError('Pixel length must equal width * height * 4');
|
|
415
491
|
}
|
|
416
492
|
flushGraphics();
|
|
417
|
-
native.updateTexture(
|
|
493
|
+
native.updateTexture(
|
|
494
|
+
this[graphicsNative],
|
|
495
|
+
source,
|
|
496
|
+
width,
|
|
497
|
+
height,
|
|
498
|
+
x,
|
|
499
|
+
y,
|
|
500
|
+
);
|
|
418
501
|
return;
|
|
419
502
|
}
|
|
420
|
-
if (
|
|
421
|
-
|
|
422
|
-
|
|
503
|
+
if (
|
|
504
|
+
!(source instanceof Image) &&
|
|
505
|
+
!(source instanceof Texture) &&
|
|
506
|
+
!(source instanceof Window)
|
|
507
|
+
) {
|
|
508
|
+
throw new TypeError(
|
|
509
|
+
'Expected RGBA Uint8Array, Image, Texture or Window',
|
|
510
|
+
);
|
|
423
511
|
}
|
|
424
512
|
if (dest !== undefined) {
|
|
425
|
-
throw new TypeError(
|
|
513
|
+
throw new TypeError(
|
|
514
|
+
'Image, Texture or Window update only accepts a destination',
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
if (source instanceof Window && !source.isOpen()) {
|
|
518
|
+
return;
|
|
426
519
|
}
|
|
427
|
-
if (source instanceof Window && !source.isOpen()) return;
|
|
428
520
|
const size = source.getSize();
|
|
429
521
|
const x = sizeOrDest?.x ?? 0;
|
|
430
522
|
const y = sizeOrDest?.y ?? 0;
|
|
431
523
|
this.checkRegion(size.x, size.y, x, y);
|
|
432
524
|
flushGraphics();
|
|
433
525
|
if (source instanceof Image) {
|
|
434
|
-
native.updateTextureImage(
|
|
435
|
-
|
|
526
|
+
native.updateTextureImage(
|
|
527
|
+
this[graphicsNative],
|
|
528
|
+
source[graphicsNative],
|
|
529
|
+
x,
|
|
530
|
+
y,
|
|
531
|
+
);
|
|
436
532
|
} else if (source instanceof Window) {
|
|
437
|
-
native.updateTextureWindow(
|
|
438
|
-
|
|
533
|
+
native.updateTextureWindow(
|
|
534
|
+
this[graphicsNative],
|
|
535
|
+
source[graphicsNative],
|
|
536
|
+
x,
|
|
537
|
+
y,
|
|
538
|
+
);
|
|
439
539
|
} else {
|
|
440
|
-
native.updateTextureTexture(
|
|
441
|
-
|
|
540
|
+
native.updateTextureTexture(
|
|
541
|
+
this[graphicsNative],
|
|
542
|
+
source[graphicsNative],
|
|
543
|
+
x,
|
|
544
|
+
y,
|
|
545
|
+
);
|
|
442
546
|
}
|
|
443
547
|
}
|
|
444
548
|
|
|
@@ -451,7 +555,9 @@ export class Texture {
|
|
|
451
555
|
setSmooth(smooth: boolean): void {
|
|
452
556
|
this.checkWritable();
|
|
453
557
|
flag(smooth);
|
|
454
|
-
if (smooth === this.state.smooth)
|
|
558
|
+
if (smooth === this.state.smooth) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
455
561
|
flushGraphics();
|
|
456
562
|
native.setTextureSmooth(this[graphicsNative], smooth);
|
|
457
563
|
}
|
|
@@ -476,7 +582,9 @@ export class Texture {
|
|
|
476
582
|
setRepeated(repeated: boolean): void {
|
|
477
583
|
this.checkWritable();
|
|
478
584
|
flag(repeated);
|
|
479
|
-
if (repeated === this.state.repeated)
|
|
585
|
+
if (repeated === this.state.repeated) {
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
480
588
|
flushGraphics();
|
|
481
589
|
native.setTextureRepeated(this[graphicsNative], repeated);
|
|
482
590
|
}
|
|
@@ -508,8 +616,12 @@ export class Texture {
|
|
|
508
616
|
* @ko 텍스처가 읽기 전용으로 빌린 뷰이면 쓰기를 거부합니다.
|
|
509
617
|
*/
|
|
510
618
|
private checkWritable(): void {
|
|
511
|
-
if (this[textureOwner])
|
|
512
|
-
|
|
619
|
+
if (this[textureOwner]) {
|
|
620
|
+
throw new TypeError('Cannot modify a RenderTexture texture view');
|
|
621
|
+
}
|
|
622
|
+
if (this.resourceOwner) {
|
|
623
|
+
throw new TypeError('Cannot modify a Font texture view');
|
|
624
|
+
}
|
|
513
625
|
}
|
|
514
626
|
|
|
515
627
|
/**
|
|
@@ -519,10 +631,17 @@ export class Texture {
|
|
|
519
631
|
* @ko 갱신 영역이 텍스처 범위 안에 있는지 검증합니다.
|
|
520
632
|
*/
|
|
521
633
|
private checkRegion(
|
|
522
|
-
width: number,
|
|
634
|
+
width: number,
|
|
635
|
+
height: number,
|
|
636
|
+
x: number,
|
|
637
|
+
y: number,
|
|
523
638
|
): void {
|
|
524
|
-
if (
|
|
525
|
-
|
|
639
|
+
if (
|
|
640
|
+
x > this.state.width ||
|
|
641
|
+
y > this.state.height ||
|
|
642
|
+
width > this.state.width - x ||
|
|
643
|
+
height > this.state.height - y
|
|
644
|
+
) {
|
|
526
645
|
throw new RangeError('Update region is outside the texture');
|
|
527
646
|
}
|
|
528
647
|
}
|