sfml.js 1.0.0 → 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 +10 -9
- package/README.ko.md +10 -9
- package/README.md +10 -9
- package/README.zh-CN.md +10 -9
- 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 +40 -48
- 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 -144
- package/docs/development.ko.md +0 -144
- package/docs/development.md +0 -146
- package/docs/development.zh-CN.md +0 -146
- 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 -107
- 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
|
@@ -1,24 +1,40 @@
|
|
|
1
1
|
import {
|
|
2
|
-
dispatchDrawable,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
dispatchDrawable,
|
|
3
|
+
graphicsFlush,
|
|
4
|
+
recordSprite,
|
|
5
|
+
registerTarget,
|
|
6
|
+
spriteState,
|
|
7
|
+
recordVertices,
|
|
8
|
+
textureId,
|
|
9
|
+
graphicsReads,
|
|
10
|
+
validateTextureRead,
|
|
11
|
+
type SpriteData,
|
|
12
|
+
recordVertexBuffer,
|
|
13
|
+
vertexBufferId,
|
|
14
|
+
shaderId,
|
|
15
|
+
shaderTextures,
|
|
16
|
+
recordShape,
|
|
17
|
+
shapeState,
|
|
18
|
+
graphicsShapeReads,
|
|
19
|
+
type ShapeData,
|
|
6
20
|
} from '../internal/graphics-state';
|
|
7
21
|
import {
|
|
8
|
-
transformableState,
|
|
22
|
+
transformableState,
|
|
23
|
+
type TransformableState,
|
|
9
24
|
} from '../internal/transformable';
|
|
10
25
|
import {
|
|
11
|
-
defaultRenderStates,
|
|
26
|
+
defaultRenderStates,
|
|
27
|
+
validateRenderStates,
|
|
12
28
|
} from '../internal/render-states';
|
|
13
29
|
import {
|
|
14
|
-
transformStorage,
|
|
30
|
+
transformStorage,
|
|
31
|
+
vertexStorage,
|
|
32
|
+
type ReadonlyValue,
|
|
15
33
|
} from '../internal/value-storage';
|
|
16
34
|
import { Vector2, Vector2u, Vector2i, Vector2f } from '../system/vector2';
|
|
17
35
|
import { Color } from './color';
|
|
18
36
|
import { Drawable } from './drawable';
|
|
19
|
-
import {
|
|
20
|
-
RenderStates, type RenderStatesInput,
|
|
21
|
-
} from './render-states';
|
|
37
|
+
import { RenderStates, type RenderStatesInput } from './render-states';
|
|
22
38
|
import { StencilValue } from './stencil-mode';
|
|
23
39
|
import { PrimitiveType, validatePrimitiveType } from './primitive-type';
|
|
24
40
|
import { Vertex } from './vertex';
|
|
@@ -96,7 +112,9 @@ export abstract class RenderTarget {
|
|
|
96
112
|
* @ko 대기 중인 그리기를 제출하고 OpenGL 컨텍스트를 활성화하거나 비활성화합니다. 성공 여부를 반환합니다.
|
|
97
113
|
*/
|
|
98
114
|
setActive(active = true): boolean {
|
|
99
|
-
if (typeof active !== 'boolean')
|
|
115
|
+
if (typeof active !== 'boolean') {
|
|
116
|
+
throw new TypeError('Expected a boolean');
|
|
117
|
+
}
|
|
100
118
|
this.flush();
|
|
101
119
|
return this.activate(active);
|
|
102
120
|
}
|
|
@@ -109,7 +127,9 @@ export abstract class RenderTarget {
|
|
|
109
127
|
* @ko 이후 그리기에 사용할 뷰를 복사하여 설정합니다. 이미 기록된 그리기는 원래 뷰를 유지합니다.
|
|
110
128
|
*/
|
|
111
129
|
setView(view: ReadonlyValue<View>): void {
|
|
112
|
-
if (!(view instanceof View))
|
|
130
|
+
if (!(view instanceof View)) {
|
|
131
|
+
throw new TypeError('Expected a View');
|
|
132
|
+
}
|
|
113
133
|
const offset = this.nextCommand();
|
|
114
134
|
this.words[offset] = 5;
|
|
115
135
|
writeView(view, this.floats, offset + 9);
|
|
@@ -144,7 +164,9 @@ export abstract class RenderTarget {
|
|
|
144
164
|
* @ko view의 정규화된 뷰포트를 대상의 픽셀 사각형으로 변환합니다.
|
|
145
165
|
*/
|
|
146
166
|
getViewport(view: ReadonlyValue<View>): IntRect {
|
|
147
|
-
if (!(view instanceof View))
|
|
167
|
+
if (!(view instanceof View)) {
|
|
168
|
+
throw new TypeError('Expected a View');
|
|
169
|
+
}
|
|
148
170
|
return this.pixelRectangle(view.getViewport());
|
|
149
171
|
}
|
|
150
172
|
|
|
@@ -155,7 +177,9 @@ export abstract class RenderTarget {
|
|
|
155
177
|
* @ko view의 정규화된 시저 영역을 픽셀 사각형으로 변환합니다.
|
|
156
178
|
*/
|
|
157
179
|
getScissor(view: ReadonlyValue<View>): IntRect {
|
|
158
|
-
if (!(view instanceof View))
|
|
180
|
+
if (!(view instanceof View)) {
|
|
181
|
+
throw new TypeError('Expected a View');
|
|
182
|
+
}
|
|
159
183
|
return this.pixelRectangle(view.getScissor());
|
|
160
184
|
}
|
|
161
185
|
|
|
@@ -167,7 +191,8 @@ export abstract class RenderTarget {
|
|
|
167
191
|
* @ko 대상의 픽셀 좌표를 월드 좌표로 변환합니다. view를 생략하면 현재 뷰를 사용합니다.
|
|
168
192
|
*/
|
|
169
193
|
mapPixelToCoords(
|
|
170
|
-
point: ReadonlyValue<Vector2i>,
|
|
194
|
+
point: ReadonlyValue<Vector2i>,
|
|
195
|
+
view: ReadonlyValue<View> = this.currentView,
|
|
171
196
|
): Vector2f {
|
|
172
197
|
if (!(point instanceof Vector2) || point.scalarType !== 'i32') {
|
|
173
198
|
throw new TypeError('Expected a Vector2i');
|
|
@@ -175,10 +200,14 @@ export abstract class RenderTarget {
|
|
|
175
200
|
const viewport = this.getViewport(view);
|
|
176
201
|
const x = f(f(point.x) - f(viewport.position.x));
|
|
177
202
|
const y = f(f(point.y) - f(viewport.position.y));
|
|
178
|
-
return view
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
203
|
+
return view
|
|
204
|
+
.getInverseTransform()
|
|
205
|
+
.transformPoint(
|
|
206
|
+
new Vector2f(
|
|
207
|
+
f(-1 + f(f(2 * x) / f(viewport.size.x))),
|
|
208
|
+
f(1 + f(f(-2 * y) / f(viewport.size.y))),
|
|
209
|
+
),
|
|
210
|
+
);
|
|
182
211
|
}
|
|
183
212
|
|
|
184
213
|
/**
|
|
@@ -189,7 +218,8 @@ export abstract class RenderTarget {
|
|
|
189
218
|
* @ko 월드 좌표를 대상의 정수 픽셀 좌표로 변환합니다. view를 생략하면 현재 뷰를 사용합니다.
|
|
190
219
|
*/
|
|
191
220
|
mapCoordsToPixel(
|
|
192
|
-
point: ReadonlyValue<Vector2f>,
|
|
221
|
+
point: ReadonlyValue<Vector2f>,
|
|
222
|
+
view: ReadonlyValue<View> = this.currentView,
|
|
193
223
|
): Vector2i {
|
|
194
224
|
if (!(point instanceof Vector2) || point.scalarType !== 'f32') {
|
|
195
225
|
throw new TypeError('Expected a Vector2f');
|
|
@@ -197,10 +227,14 @@ export abstract class RenderTarget {
|
|
|
197
227
|
const viewport = this.getViewport(view);
|
|
198
228
|
const normalized = view.getTransform().transformPoint(point);
|
|
199
229
|
return new Vector2i(
|
|
200
|
-
f(
|
|
201
|
-
f(viewport.
|
|
202
|
-
|
|
203
|
-
|
|
230
|
+
f(
|
|
231
|
+
f(f(f(normalized.x + 1) / 2) * f(viewport.size.x)) +
|
|
232
|
+
f(viewport.position.x),
|
|
233
|
+
),
|
|
234
|
+
f(
|
|
235
|
+
f(f(f(-normalized.y + 1) / 2) * f(viewport.size.y)) +
|
|
236
|
+
f(viewport.position.y),
|
|
237
|
+
),
|
|
204
238
|
);
|
|
205
239
|
}
|
|
206
240
|
|
|
@@ -245,21 +279,25 @@ export abstract class RenderTarget {
|
|
|
245
279
|
* @ko 네이티브 생성 또는 크기 변경이 성공한 후에만 호출됩니다.
|
|
246
280
|
*/
|
|
247
281
|
protected initializeViews(size: Readonly<Vector2u>): void {
|
|
248
|
-
const view = new View(
|
|
249
|
-
new Vector2f(), new Vector2f(size.x, size.y))
|
|
282
|
+
const view = new View(
|
|
283
|
+
new FloatRect(new Vector2f(), new Vector2f(size.x, size.y)),
|
|
284
|
+
);
|
|
250
285
|
copyView(this.defaultView, view);
|
|
251
286
|
copyView(this.currentView, view);
|
|
252
287
|
}
|
|
253
288
|
|
|
254
289
|
private pixelRectangle(rectangle: ReadonlyValue<FloatRect>): IntRect {
|
|
255
290
|
const size = this.getSize();
|
|
256
|
-
return new IntRect(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
291
|
+
return new IntRect(
|
|
292
|
+
new Vector2i(
|
|
293
|
+
roundAway(f(f(size.x) * rectangle.position.x)),
|
|
294
|
+
roundAway(f(f(size.y) * rectangle.position.y)),
|
|
295
|
+
),
|
|
296
|
+
new Vector2i(
|
|
297
|
+
roundAway(f(f(size.x) * rectangle.size.x)),
|
|
298
|
+
roundAway(f(f(size.y) * rectangle.size.y)),
|
|
299
|
+
),
|
|
300
|
+
);
|
|
263
301
|
}
|
|
264
302
|
|
|
265
303
|
/**
|
|
@@ -273,9 +311,12 @@ export abstract class RenderTarget {
|
|
|
273
311
|
color: ReadonlyValue<Color> = Color.Black,
|
|
274
312
|
stencil?: number | Readonly<StencilValue>,
|
|
275
313
|
): void {
|
|
276
|
-
if (!(color instanceof Color))
|
|
314
|
+
if (!(color instanceof Color)) {
|
|
315
|
+
throw new TypeError('Expected a Color');
|
|
316
|
+
}
|
|
277
317
|
const rgba = color.toInteger();
|
|
278
|
-
const value =
|
|
318
|
+
const value =
|
|
319
|
+
stencil === undefined ? 0 : new StencilValue(stencil).value;
|
|
279
320
|
const offset = this.nextCommand();
|
|
280
321
|
this.words[offset] = stencil === undefined ? 0 : 2;
|
|
281
322
|
this.words[offset + 1] = rgba;
|
|
@@ -319,8 +360,12 @@ export abstract class RenderTarget {
|
|
|
319
360
|
* @ja firstVertex から vertexCount 個の頂点を描画し、末尾を超える数は自動的に切り詰めます。
|
|
320
361
|
* @ko firstVertex부터 vertexCount개의 꼭짓점을 그리며 끝을 초과하는 수는 자동으로 잘립니다.
|
|
321
362
|
*/
|
|
322
|
-
draw(
|
|
323
|
-
|
|
363
|
+
draw(
|
|
364
|
+
buffer: VertexBuffer,
|
|
365
|
+
firstVertex: number,
|
|
366
|
+
vertexCount: number,
|
|
367
|
+
states?: RenderStatesInput,
|
|
368
|
+
): void;
|
|
324
369
|
/**
|
|
325
370
|
* Copies a vertex snapshot and records a draw using type; states defaults to
|
|
326
371
|
* RenderStates.Default.
|
|
@@ -329,33 +374,55 @@ export abstract class RenderTarget {
|
|
|
329
374
|
* @ko 꼭짓점 스냅샷을 복사하고 type에 따라 그리기를 기록합니다. states의 기본값은
|
|
330
375
|
* RenderStates.Default입니다.
|
|
331
376
|
*/
|
|
332
|
-
draw(
|
|
333
|
-
|
|
334
|
-
|
|
377
|
+
draw(
|
|
378
|
+
vertices: readonly ReadonlyValue<Vertex>[],
|
|
379
|
+
type: PrimitiveType,
|
|
380
|
+
states?: RenderStatesInput,
|
|
381
|
+
): void;
|
|
382
|
+
draw(
|
|
383
|
+
drawable: Drawable | readonly ReadonlyValue<Vertex>[],
|
|
335
384
|
statesOrType: RenderStatesInput | number = defaultRenderStates,
|
|
336
385
|
statesOrCount: RenderStatesInput | number = defaultRenderStates,
|
|
337
|
-
rangeStates: RenderStatesInput = defaultRenderStates
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
386
|
+
rangeStates: RenderStatesInput = defaultRenderStates,
|
|
387
|
+
): void {
|
|
388
|
+
if (
|
|
389
|
+
drawable instanceof VertexBuffer &&
|
|
390
|
+
typeof statesOrType === 'number'
|
|
391
|
+
) {
|
|
392
|
+
const value =
|
|
393
|
+
rangeStates instanceof RenderStates
|
|
394
|
+
? rangeStates
|
|
395
|
+
: new RenderStates(rangeStates);
|
|
396
|
+
this[recordVertexBuffer](
|
|
397
|
+
drawable,
|
|
398
|
+
statesOrType,
|
|
399
|
+
statesOrCount as number,
|
|
400
|
+
value,
|
|
401
|
+
);
|
|
343
402
|
return;
|
|
344
403
|
}
|
|
345
404
|
if (drawable instanceof Drawable) {
|
|
346
|
-
const value =
|
|
347
|
-
|
|
405
|
+
const value =
|
|
406
|
+
statesOrType instanceof RenderStates
|
|
407
|
+
? statesOrType
|
|
408
|
+
: new RenderStates(statesOrType as RenderStatesInput);
|
|
348
409
|
drawable[dispatchDrawable](this, value);
|
|
349
410
|
return;
|
|
350
411
|
}
|
|
351
|
-
if (!Array.isArray(drawable))
|
|
412
|
+
if (!Array.isArray(drawable)) {
|
|
413
|
+
throw new TypeError('Expected a Drawable');
|
|
414
|
+
}
|
|
352
415
|
validatePrimitiveType(statesOrType as PrimitiveType);
|
|
353
|
-
const value =
|
|
354
|
-
|
|
416
|
+
const value =
|
|
417
|
+
statesOrCount instanceof RenderStates
|
|
418
|
+
? statesOrCount
|
|
419
|
+
: new RenderStates(statesOrCount as RenderStatesInput);
|
|
355
420
|
validateRenderStates(value);
|
|
356
421
|
// Validate and capture every view before touching the command queue.
|
|
357
422
|
const vertices = drawable.map(vertex => {
|
|
358
|
-
if (!(vertex instanceof Vertex))
|
|
423
|
+
if (!(vertex instanceof Vertex)) {
|
|
424
|
+
throw new TypeError('Expected a Vertex');
|
|
425
|
+
}
|
|
359
426
|
return vertex[vertexStorage];
|
|
360
427
|
});
|
|
361
428
|
// Array holes must not turn into partially initialized draw commands.
|
|
@@ -364,13 +431,17 @@ export abstract class RenderTarget {
|
|
|
364
431
|
throw new TypeError('Expected attached Vertex values');
|
|
365
432
|
}
|
|
366
433
|
}
|
|
367
|
-
this.writeVertices(
|
|
434
|
+
this.writeVertices(
|
|
435
|
+
vertices.length,
|
|
436
|
+
statesOrType as PrimitiveType,
|
|
437
|
+
value,
|
|
368
438
|
offset => {
|
|
369
439
|
for (const vertex of vertices) {
|
|
370
440
|
this.vertexBytes.set(vertex, offset);
|
|
371
441
|
offset += 20;
|
|
372
442
|
}
|
|
373
|
-
}
|
|
443
|
+
},
|
|
444
|
+
);
|
|
374
445
|
}
|
|
375
446
|
|
|
376
447
|
/**
|
|
@@ -380,7 +451,9 @@ export abstract class RenderTarget {
|
|
|
380
451
|
* @ko 외부 그래픽 작업 전에 대기 중인 그리기를 제출합니다.
|
|
381
452
|
*/
|
|
382
453
|
flush(): void {
|
|
383
|
-
if (this.count !== 0)
|
|
454
|
+
if (this.count !== 0) {
|
|
455
|
+
this.submit(false);
|
|
456
|
+
}
|
|
384
457
|
}
|
|
385
458
|
|
|
386
459
|
[graphicsFlush](): void {
|
|
@@ -400,7 +473,9 @@ export abstract class RenderTarget {
|
|
|
400
473
|
const appearance = shape[shapeState];
|
|
401
474
|
validateTextureRead(this, appearance.texture);
|
|
402
475
|
this.validateShaderReads(states);
|
|
403
|
-
const matrix = new Transform(states.transform).combine(
|
|
476
|
+
const matrix = new Transform(states.transform).combine(
|
|
477
|
+
shape.getTransform(),
|
|
478
|
+
);
|
|
404
479
|
const offset = this.nextCommand();
|
|
405
480
|
this.words[offset] = 7;
|
|
406
481
|
this.words[offset + 1] = appearance.id;
|
|
@@ -408,7 +483,9 @@ export abstract class RenderTarget {
|
|
|
408
483
|
this.floats.set(matrix[transformStorage], offset + 9);
|
|
409
484
|
this.writeModes(offset, states);
|
|
410
485
|
this.pendingShapes.add(shape);
|
|
411
|
-
if (appearance.texture)
|
|
486
|
+
if (appearance.texture) {
|
|
487
|
+
this.pendingTextures.add(appearance.texture);
|
|
488
|
+
}
|
|
412
489
|
}
|
|
413
490
|
|
|
414
491
|
[recordSprite](sprite: SpriteCommandSource, states: RenderStates): void {
|
|
@@ -432,23 +509,39 @@ export abstract class RenderTarget {
|
|
|
432
509
|
this.pendingTextures.add(appearance.texture);
|
|
433
510
|
}
|
|
434
511
|
|
|
435
|
-
[recordVertices](
|
|
436
|
-
|
|
512
|
+
[recordVertices](
|
|
513
|
+
bytes: Uint8Array,
|
|
514
|
+
type: PrimitiveType,
|
|
515
|
+
states: RenderStates,
|
|
516
|
+
): void {
|
|
437
517
|
validateRenderStates(states);
|
|
438
518
|
validatePrimitiveType(type);
|
|
439
|
-
this.writeVertices(bytes.byteLength / 20, type, states,
|
|
440
|
-
|
|
519
|
+
this.writeVertices(bytes.byteLength / 20, type, states, offset =>
|
|
520
|
+
this.vertexBytes.set(bytes, offset),
|
|
521
|
+
);
|
|
441
522
|
}
|
|
442
523
|
|
|
443
|
-
[recordVertexBuffer](
|
|
444
|
-
|
|
524
|
+
[recordVertexBuffer](
|
|
525
|
+
buffer: VertexBuffer,
|
|
526
|
+
first: number,
|
|
527
|
+
count: number,
|
|
528
|
+
states: RenderStates,
|
|
529
|
+
): void {
|
|
445
530
|
validateRenderStates(states);
|
|
446
|
-
if (
|
|
447
|
-
|
|
531
|
+
if (
|
|
532
|
+
!Number.isInteger(first) ||
|
|
533
|
+
first < 0 ||
|
|
534
|
+
first > 0xffffffff ||
|
|
535
|
+
!Number.isInteger(count) ||
|
|
536
|
+
count < 0 ||
|
|
537
|
+
count > 0xffffffff
|
|
538
|
+
) {
|
|
448
539
|
throw new RangeError('Vertex range is out of bounds');
|
|
449
540
|
}
|
|
450
541
|
const available = buffer.getVertexCount();
|
|
451
|
-
if (first >= available || count === 0)
|
|
542
|
+
if (first >= available || count === 0) {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
452
545
|
count = Math.min(count, available - first);
|
|
453
546
|
validateTextureRead(this, states.texture);
|
|
454
547
|
this.validateShaderReads(states);
|
|
@@ -463,7 +556,9 @@ export abstract class RenderTarget {
|
|
|
463
556
|
this.floats.set(states.transform[transformStorage], offset + 9);
|
|
464
557
|
this.writeModes(offset, states);
|
|
465
558
|
this.pendingBuffers.add(buffer);
|
|
466
|
-
if (states.texture)
|
|
559
|
+
if (states.texture) {
|
|
560
|
+
this.pendingTextures.add(states.texture);
|
|
561
|
+
}
|
|
467
562
|
}
|
|
468
563
|
|
|
469
564
|
private writeModes(offset: number, states: RenderStates): void {
|
|
@@ -490,31 +585,48 @@ export abstract class RenderTarget {
|
|
|
490
585
|
}
|
|
491
586
|
|
|
492
587
|
private validateShaderReads(states: RenderStates): void {
|
|
493
|
-
if (!states.shader)
|
|
588
|
+
if (!states.shader) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
494
591
|
for (const texture of states.shader[shaderTextures].values()) {
|
|
495
592
|
validateTextureRead(this, texture);
|
|
496
593
|
}
|
|
497
594
|
}
|
|
498
595
|
|
|
499
|
-
private writeVertices(
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
596
|
+
private writeVertices(
|
|
597
|
+
count: number,
|
|
598
|
+
type: PrimitiveType,
|
|
599
|
+
states: RenderStates,
|
|
600
|
+
copy: (offset: number) => void,
|
|
601
|
+
): void {
|
|
602
|
+
if (
|
|
603
|
+
!Number.isInteger(count) ||
|
|
604
|
+
count < 0 ||
|
|
605
|
+
count > Math.floor(0x7fffffff / 20)
|
|
606
|
+
) {
|
|
503
607
|
throw new RangeError('Vertex count exceeds the buffer limit');
|
|
504
608
|
}
|
|
505
|
-
if (count === 0)
|
|
609
|
+
if (count === 0) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
506
612
|
validateTextureRead(this, states.texture);
|
|
507
613
|
this.validateShaderReads(states);
|
|
508
614
|
const matrix = states.transform[transformStorage];
|
|
509
|
-
if (
|
|
510
|
-
|
|
511
|
-
|
|
615
|
+
if (
|
|
616
|
+
this.count === this.words.length / commandWords ||
|
|
617
|
+
(this.vertexCount !== 0 &&
|
|
618
|
+
(this.vertexCount + count) * 20 > this.vertexBytes.byteLength)
|
|
619
|
+
) {
|
|
512
620
|
this.flush();
|
|
513
621
|
}
|
|
514
622
|
if (count * 20 > this.vertexBytes.byteLength) {
|
|
515
|
-
const capacity = Math.min(
|
|
516
|
-
Math.
|
|
517
|
-
|
|
623
|
+
const capacity = Math.min(
|
|
624
|
+
Math.floor(0x7fffffff / 20),
|
|
625
|
+
Math.max(4096, count, this.vertexBytes.byteLength / 10),
|
|
626
|
+
);
|
|
627
|
+
this.vertexBytes = new Uint8Array(
|
|
628
|
+
this.allocateVertexBuffer(capacity),
|
|
629
|
+
);
|
|
518
630
|
}
|
|
519
631
|
// Copy before reserving: a failed copy cannot leave a partial command.
|
|
520
632
|
copy(this.vertexCount * 20);
|
|
@@ -528,7 +640,9 @@ export abstract class RenderTarget {
|
|
|
528
640
|
this.floats.set(matrix, offset + 9);
|
|
529
641
|
this.writeModes(offset, states);
|
|
530
642
|
this.vertexCount += count;
|
|
531
|
-
if (states.texture)
|
|
643
|
+
if (states.texture) {
|
|
644
|
+
this.pendingTextures.add(states.texture);
|
|
645
|
+
}
|
|
532
646
|
}
|
|
533
647
|
|
|
534
648
|
protected abstract submitCommands(count: number, display: boolean): void;
|
|
@@ -548,7 +662,9 @@ export abstract class RenderTarget {
|
|
|
548
662
|
}
|
|
549
663
|
|
|
550
664
|
private nextCommand(): number {
|
|
551
|
-
if (this.count === this.words.length / commandWords)
|
|
665
|
+
if (this.count === this.words.length / commandWords) {
|
|
666
|
+
this.submit(false);
|
|
667
|
+
}
|
|
552
668
|
return this.count++ * commandWords;
|
|
553
669
|
}
|
|
554
670
|
}
|
|
@@ -28,7 +28,9 @@ function coordinates(size: Readonly<Vector2u>): void {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function flag(value: boolean): void {
|
|
31
|
-
if (typeof value !== 'boolean')
|
|
31
|
+
if (typeof value !== 'boolean') {
|
|
32
|
+
throw new TypeError('Expected a boolean');
|
|
33
|
+
}
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
/**
|
|
@@ -61,7 +63,9 @@ export class RenderTexture extends RenderTarget {
|
|
|
61
63
|
constructor(
|
|
62
64
|
size?: Readonly<Vector2u>, settings: Readonly<ContextSettings> = {},
|
|
63
65
|
) {
|
|
64
|
-
if (size !== undefined)
|
|
66
|
+
if (size !== undefined) {
|
|
67
|
+
coordinates(size);
|
|
68
|
+
}
|
|
65
69
|
const requested = contextSettings(settings);
|
|
66
70
|
const { handle, buffer, info, targetInfo } = native.createRenderTexture(
|
|
67
71
|
graphicsContext(), size?.x, size?.y, requested,
|
|
@@ -70,7 +74,9 @@ export class RenderTexture extends RenderTarget {
|
|
|
70
74
|
this[graphicsNative] = handle;
|
|
71
75
|
this.state = nativeStruct<NativeTextureInfo>(info);
|
|
72
76
|
this.targetInfo = nativeStruct<{ sRgb: boolean }>(targetInfo);
|
|
73
|
-
if (size)
|
|
77
|
+
if (size) {
|
|
78
|
+
this.initializeViews(size);
|
|
79
|
+
}
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
/**
|
|
@@ -94,7 +100,9 @@ export class RenderTexture extends RenderTarget {
|
|
|
94
100
|
): boolean {
|
|
95
101
|
coordinates(size);
|
|
96
102
|
const requested = contextSettings(settings);
|
|
97
|
-
if (this.texture)
|
|
103
|
+
if (this.texture) {
|
|
104
|
+
flushTextureReaders(this);
|
|
105
|
+
}
|
|
98
106
|
this.flush();
|
|
99
107
|
const info = native.resizeRenderTexture(
|
|
100
108
|
this[graphicsNative], size.x, size.y, requested,
|
|
@@ -124,8 +132,12 @@ export class RenderTexture extends RenderTarget {
|
|
|
124
132
|
*/
|
|
125
133
|
setSmooth(smooth: boolean): void {
|
|
126
134
|
flag(smooth);
|
|
127
|
-
if (smooth === this.state.smooth)
|
|
128
|
-
|
|
135
|
+
if (smooth === this.state.smooth) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (this.texture) {
|
|
139
|
+
flushTextureReaders(this);
|
|
140
|
+
}
|
|
129
141
|
native.setRenderTextureSmooth(this[graphicsNative], smooth);
|
|
130
142
|
}
|
|
131
143
|
|
|
@@ -147,8 +159,12 @@ export class RenderTexture extends RenderTarget {
|
|
|
147
159
|
*/
|
|
148
160
|
setRepeated(repeated: boolean): void {
|
|
149
161
|
flag(repeated);
|
|
150
|
-
if (repeated === this.state.repeated)
|
|
151
|
-
|
|
162
|
+
if (repeated === this.state.repeated) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (this.texture) {
|
|
166
|
+
flushTextureReaders(this);
|
|
167
|
+
}
|
|
152
168
|
native.setRenderTextureRepeated(this[graphicsNative], repeated);
|
|
153
169
|
}
|
|
154
170
|
|
|
@@ -179,7 +195,9 @@ export class RenderTexture extends RenderTarget {
|
|
|
179
195
|
* @ko 그린 후 display()를 호출한 다음 해당 이미지의 mipmap을 생성합니다.
|
|
180
196
|
*/
|
|
181
197
|
generateMipmap(): boolean {
|
|
182
|
-
if (this.texture)
|
|
198
|
+
if (this.texture) {
|
|
199
|
+
flushTextureReaders(this);
|
|
200
|
+
}
|
|
183
201
|
return native.generateRenderTextureMipmap(this[graphicsNative]);
|
|
184
202
|
}
|
|
185
203
|
|
|
@@ -190,12 +208,16 @@ export class RenderTexture extends RenderTarget {
|
|
|
190
208
|
* @ko OpenGL에 직접 접근하거나 비활성화하기 전에 기록된 작업을 완료합니다.
|
|
191
209
|
*/
|
|
192
210
|
protected activate(active: boolean): boolean {
|
|
193
|
-
if (active && this.texture)
|
|
211
|
+
if (active && this.texture) {
|
|
212
|
+
flushTextureReaders(this);
|
|
213
|
+
}
|
|
194
214
|
return native.setRenderTextureActive(this[graphicsNative], active);
|
|
195
215
|
}
|
|
196
216
|
|
|
197
217
|
protected changeGLStates(operation: 0 | 1 | 2): void {
|
|
198
|
-
if (this.texture)
|
|
218
|
+
if (this.texture) {
|
|
219
|
+
flushTextureReaders(this);
|
|
220
|
+
}
|
|
199
221
|
native.changeRenderTextureGLStates(this[graphicsNative], operation);
|
|
200
222
|
}
|
|
201
223
|
|
|
@@ -224,7 +246,9 @@ export class RenderTexture extends RenderTarget {
|
|
|
224
246
|
}
|
|
225
247
|
|
|
226
248
|
protected submitCommands(count: number, display: boolean): void {
|
|
227
|
-
if (this.texture)
|
|
249
|
+
if (this.texture) {
|
|
250
|
+
flushTextureReaders(this);
|
|
251
|
+
}
|
|
228
252
|
native.submitRenderTexture(this[graphicsNative], count, display);
|
|
229
253
|
}
|
|
230
254
|
|
|
@@ -89,7 +89,9 @@ export class RenderWindow extends RenderTarget {
|
|
|
89
89
|
const initializeViews = () => {
|
|
90
90
|
super.initializeViews(Window.prototype.getSize.call(this));
|
|
91
91
|
};
|
|
92
|
-
if (native.isWindowOpen(this[graphicsNative]))
|
|
92
|
+
if (native.isWindowOpen(this[graphicsNative])) {
|
|
93
|
+
initializeViews();
|
|
94
|
+
}
|
|
93
95
|
registerWindowHooks(this, () => {
|
|
94
96
|
initializeViews();
|
|
95
97
|
this.onCreate();
|
|
@@ -169,7 +171,9 @@ export class RenderWindow extends RenderTarget {
|
|
|
169
171
|
* @ko 클라이언트 영역의 최소 픽셀 크기를 설정합니다. undefined는 제한을 해제합니다.
|
|
170
172
|
*/
|
|
171
173
|
setMinimumSize(size: Readonly<Vector2u> | undefined): void {
|
|
172
|
-
if (size !== undefined)
|
|
174
|
+
if (size !== undefined) {
|
|
175
|
+
windowSize(size);
|
|
176
|
+
}
|
|
173
177
|
this.flush();
|
|
174
178
|
Window.prototype.setMinimumSize.call(this, size);
|
|
175
179
|
}
|
|
@@ -181,7 +185,9 @@ export class RenderWindow extends RenderTarget {
|
|
|
181
185
|
* @ko 클라이언트 영역의 최대 픽셀 크기를 설정합니다. undefined는 제한을 해제합니다.
|
|
182
186
|
*/
|
|
183
187
|
setMaximumSize(size: Readonly<Vector2u> | undefined): void {
|
|
184
|
-
if (size !== undefined)
|
|
188
|
+
if (size !== undefined) {
|
|
189
|
+
windowSize(size);
|
|
190
|
+
}
|
|
185
191
|
this.flush();
|
|
186
192
|
Window.prototype.setMaximumSize.call(this, size);
|
|
187
193
|
}
|