@next2d/webgl 3.0.5 → 3.2.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/package.json +3 -3
- package/src/AtlasManager.js +11 -7
- package/src/Context/usecase/ContextContainerEndAtlasNodeUseCase.d.ts +13 -0
- package/src/Context/usecase/ContextContainerEndAtlasNodeUseCase.js +61 -0
- package/src/Context/usecase/ContextContainerEndLayerUseCase.d.ts +1 -1
- package/src/Context/usecase/ContextContainerEndLayerUseCase.js +9 -1
- package/src/Context.d.ts +4 -1
- package/src/Context.js +22 -2
- package/src/Mesh.js +3 -1
- package/src/TextureManager/service/TextureManagerBindService.js +12 -7
- package/src/TextureManager/usecase/TextureManagerReleaseTextureObjectUseCase.js +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next2d/webgl",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Next2D Webgl Package",
|
|
5
5
|
"author": "Toshiyuki Ienaga<ienaga@next2d.app> (https://github.com/ienaga/)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"url": "git+https://github.com/Next2D/Player.git"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@next2d/texture-packer": "3.0
|
|
28
|
-
"@next2d/render-queue": "3.0
|
|
27
|
+
"@next2d/texture-packer": "3.2.0",
|
|
28
|
+
"@next2d/render-queue": "3.2.0"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/AtlasManager.js
CHANGED
|
@@ -15,13 +15,15 @@ export const $setAtlasAttachmentObject = (attachment_object) => {
|
|
|
15
15
|
$atlasAttachmentObjects[$activeAtlasIndex] = attachment_object;
|
|
16
16
|
};
|
|
17
17
|
export const $getAtlasAttachmentObject = () => {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
let attachmentObject = $atlasAttachmentObjects[$activeAtlasIndex];
|
|
19
|
+
if (!attachmentObject) {
|
|
20
|
+
attachmentObject = frameBufferManagerGetAttachmentObjectUseCase($RENDER_MAX_SIZE, $RENDER_MAX_SIZE, true);
|
|
21
|
+
$atlasAttachmentObjects[$activeAtlasIndex] = attachmentObject;
|
|
20
22
|
}
|
|
21
|
-
return
|
|
23
|
+
return attachmentObject;
|
|
22
24
|
};
|
|
23
25
|
export const $hasAtlasAttachmentObject = () => {
|
|
24
|
-
return $activeAtlasIndex
|
|
26
|
+
return !!$atlasAttachmentObjects[$activeAtlasIndex];
|
|
25
27
|
};
|
|
26
28
|
export const $rootNodes = [];
|
|
27
29
|
export let $atlasTexture = null;
|
|
@@ -33,15 +35,17 @@ export const $getAtlasTextureObject = () => {
|
|
|
33
35
|
};
|
|
34
36
|
const $transferBounds = [];
|
|
35
37
|
export const $getActiveTransferBounds = (index) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
let bounds = $transferBounds[index];
|
|
39
|
+
if (!bounds) {
|
|
40
|
+
bounds = new Float32Array([
|
|
38
41
|
$MAX_VALUE,
|
|
39
42
|
$MAX_VALUE,
|
|
40
43
|
$MIN_VALUE,
|
|
41
44
|
$MIN_VALUE
|
|
42
45
|
]);
|
|
46
|
+
$transferBounds[index] = bounds;
|
|
43
47
|
}
|
|
44
|
-
return
|
|
48
|
+
return bounds;
|
|
45
49
|
};
|
|
46
50
|
export const $clearTransferBounds = () => {
|
|
47
51
|
for (let idx = 0; idx < $transferBounds.length; ++idx) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Node } from "@next2d/texture-packer";
|
|
2
|
+
/**
|
|
3
|
+
* @description コンテナのアトラスノードへの描画を終了し、
|
|
4
|
+
* temp FBOの内容をアトラスのノード領域にコピーします。
|
|
5
|
+
* End container atlas node rendering,
|
|
6
|
+
* copy temp FBO contents to atlas node region.
|
|
7
|
+
*
|
|
8
|
+
* @param {Node} node
|
|
9
|
+
* @return {void}
|
|
10
|
+
* @method
|
|
11
|
+
* @protected
|
|
12
|
+
*/
|
|
13
|
+
export declare const execute: (node: Node) => void;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { $containerLayerStack } from "./ContextContainerBeginLayerUseCase";
|
|
2
|
+
import { execute as frameBufferManagerReleaseAttachmentObjectUseCase } from "../../FrameBufferManager/usecase/FrameBufferManagerReleaseAttachmentObjectUseCase";
|
|
3
|
+
import { execute as variantsBlendMatrixTextureShaderService } from "../../Shader/Variants/Blend/service/VariantsBlendMatrixTextureShaderService";
|
|
4
|
+
import { execute as shaderManagerSetMatrixTextureWithColorTransformUniformService } from "../../Shader/ShaderManager/service/ShaderManagerSetMatrixTextureWithColorTransformUniformService";
|
|
5
|
+
import { execute as textureManagerBind0UseCase } from "../../TextureManager/usecase/TextureManagerBind0UseCase";
|
|
6
|
+
import { execute as shaderManagerDrawTextureUseCase } from "../../Shader/ShaderManager/usecase/ShaderManagerDrawTextureUseCase";
|
|
7
|
+
import { execute as textureManagerReleaseTextureObjectUseCase } from "../../TextureManager/usecase/TextureManagerReleaseTextureObjectUseCase";
|
|
8
|
+
import { execute as blendOperationUseCase } from "../../Blend/usecase/BlendOperationUseCase";
|
|
9
|
+
import { $context } from "../../WebGLUtil";
|
|
10
|
+
import { $getAtlasAttachmentObject } from "../../AtlasManager";
|
|
11
|
+
/**
|
|
12
|
+
* @description コンテナ用のカラー変換(恒等変換)
|
|
13
|
+
* Identity color transform for container copy
|
|
14
|
+
*
|
|
15
|
+
* @type {Float32Array}
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
const $identityColorTransform = new Float32Array([1, 1, 1, 1, 0, 0, 0, 0]);
|
|
19
|
+
/**
|
|
20
|
+
* @description コンテナのアトラスノードへの描画を終了し、
|
|
21
|
+
* temp FBOの内容をアトラスのノード領域にコピーします。
|
|
22
|
+
* End container atlas node rendering,
|
|
23
|
+
* copy temp FBO contents to atlas node region.
|
|
24
|
+
*
|
|
25
|
+
* @param {Node} node
|
|
26
|
+
* @return {void}
|
|
27
|
+
* @method
|
|
28
|
+
* @protected
|
|
29
|
+
*/
|
|
30
|
+
export const execute = (node) => {
|
|
31
|
+
// temp FBOへの描画をフラッシュ
|
|
32
|
+
$context.drawArraysInstanced();
|
|
33
|
+
const tempAttachment = $context.$mainAttachmentObject;
|
|
34
|
+
const textureObject = tempAttachment.texture;
|
|
35
|
+
// mainを復元($containerLayerStackから)
|
|
36
|
+
$context.$mainAttachmentObject = $containerLayerStack.pop();
|
|
37
|
+
// temp FBOを解放(テクスチャは保持してアトラスコピーに使用)
|
|
38
|
+
frameBufferManagerReleaseAttachmentObjectUseCase(tempAttachment, false);
|
|
39
|
+
if (textureObject) {
|
|
40
|
+
// アトラスにバインド
|
|
41
|
+
const atlas = $getAtlasAttachmentObject();
|
|
42
|
+
$context.bind(atlas);
|
|
43
|
+
// ノード領域を設定(scissor + clear + transfer bounds登録)
|
|
44
|
+
$context.beginNodeRendering(node);
|
|
45
|
+
// ブレンドモード設定(premultiplied alpha用: ONE, ONE_MINUS_SRC_ALPHA)
|
|
46
|
+
blendOperationUseCase("normal");
|
|
47
|
+
// テクスチャをノード位置に描画(Y軸反転: WebGLはbottom-left原点)
|
|
48
|
+
const offsetY = atlas.height - node.y - node.h;
|
|
49
|
+
$context.setTransform(1, 0, 0, 1, node.x, offsetY);
|
|
50
|
+
const shaderManager = variantsBlendMatrixTextureShaderService(false);
|
|
51
|
+
shaderManagerSetMatrixTextureWithColorTransformUniformService(shaderManager, $identityColorTransform, node.w, node.h);
|
|
52
|
+
textureManagerBind0UseCase(textureObject);
|
|
53
|
+
shaderManagerDrawTextureUseCase(shaderManager);
|
|
54
|
+
// ノード描画終了
|
|
55
|
+
$context.endNodeRendering();
|
|
56
|
+
// テクスチャを解放
|
|
57
|
+
textureManagerReleaseTextureObjectUseCase(textureObject);
|
|
58
|
+
}
|
|
59
|
+
// mainをバインド
|
|
60
|
+
$context.bind($context.$mainAttachmentObject);
|
|
61
|
+
};
|
|
@@ -15,4 +15,4 @@ import type { IBlendMode } from "../../interface/IBlendMode";
|
|
|
15
15
|
* @method
|
|
16
16
|
* @public
|
|
17
17
|
*/
|
|
18
|
-
export declare const execute: (blend_mode: IBlendMode, matrix: Float32Array, color_transform: Float32Array | null, use_filter: boolean, filter_bounds: Float32Array | null, filter_params: Float32Array | null, unique_key: string, filter_key: string) => void;
|
|
18
|
+
export declare const execute: (blend_mode: IBlendMode, matrix: Float32Array, color_transform: Float32Array | null, use_filter: boolean, filter_bounds: Float32Array | null, filter_params: Float32Array | null, unique_key: string, filter_key: string, _layer_scale_x?: number, _layer_scale_y?: number) => void;
|
|
@@ -39,7 +39,10 @@ const $colorMatrixBuffer = new Float32Array(20);
|
|
|
39
39
|
* @method
|
|
40
40
|
* @public
|
|
41
41
|
*/
|
|
42
|
-
export const execute = (blend_mode, matrix, color_transform, use_filter, filter_bounds, filter_params, unique_key, filter_key
|
|
42
|
+
export const execute = (blend_mode, matrix, color_transform, use_filter, filter_bounds, filter_params, unique_key, filter_key,
|
|
43
|
+
// layer_scale は display 側で layer サイズに反映済み。
|
|
44
|
+
// compose時は layer 全体を等倍でmainに貼るので直接は参照しない。
|
|
45
|
+
_layer_scale_x = 1, _layer_scale_y = 1) => {
|
|
43
46
|
// 一時アタッチメントへの描画をフラッシュ
|
|
44
47
|
$context.drawArraysInstanced();
|
|
45
48
|
const layerAttachment = $context.$mainAttachmentObject;
|
|
@@ -133,6 +136,10 @@ export const execute = (blend_mode, matrix, color_transform, use_filter, filter_
|
|
|
133
136
|
break;
|
|
134
137
|
}
|
|
135
138
|
}
|
|
139
|
+
// issue #274: layer は layerScale 倍解像度で確保されており、
|
|
140
|
+
// 子孫のcacheAsBitmap子は既にその倍解像度でlayer内に収まっている。
|
|
141
|
+
// cacheAsBitmap の仕様としてスクリーン上も cacheScale 倍のサイズで
|
|
142
|
+
// 表示されるため、ここでの縮小は行わずそのまま main に合成する。
|
|
136
143
|
// キャッシュに保存
|
|
137
144
|
if (unique_key) {
|
|
138
145
|
$cacheStore.set(unique_key, "fKey", filter_key);
|
|
@@ -160,6 +167,7 @@ export const execute = (blend_mode, matrix, color_transform, use_filter, filter_
|
|
|
160
167
|
// メインのアタッチメントをバインド(currentAttachmentObjectを更新)
|
|
161
168
|
$context.bind($context.$mainAttachmentObject);
|
|
162
169
|
if (textureObject) {
|
|
170
|
+
// cacheAsBitmap と同様、layer は layerScale 倍解像度のままmainに合成する
|
|
163
171
|
$context.reset();
|
|
164
172
|
$context.globalCompositeOperation = blend_mode;
|
|
165
173
|
blendDrawFilterToMainUseCase(textureObject, color_transform, matrix[4], matrix[5]);
|
package/src/Context.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare class Context {
|
|
|
22
22
|
joints: number;
|
|
23
23
|
miterLimit: number;
|
|
24
24
|
newDrawState: boolean;
|
|
25
|
+
private readonly _pendingAtlasNodes;
|
|
25
26
|
constructor(gl: WebGL2RenderingContext, samples: number, device_pixel_ratio?: number);
|
|
26
27
|
clearTransferBounds(): void;
|
|
27
28
|
updateBackgroundColor(red: number, green: number, blue: number, alpha: number): void;
|
|
@@ -70,7 +71,9 @@ export declare class Context {
|
|
|
70
71
|
useGrid(grid_data: Float32Array | null): void;
|
|
71
72
|
applyFilter(node: Node, unique_key: string, updated: boolean, width: number, height: number, is_bitmap: boolean, matrix: Float32Array, color_transform: Float32Array, blend_mode: IBlendMode, bounds: Float32Array, params: Float32Array): void;
|
|
72
73
|
containerBeginLayer(width: number, height: number): void;
|
|
73
|
-
containerEndLayer(blend_mode: IBlendMode, matrix: Float32Array, color_transform: Float32Array | null, use_filter: boolean, filter_bounds: Float32Array | null, filter_params: Float32Array | null, unique_key: string, filter_key: string): void;
|
|
74
|
+
containerEndLayer(blend_mode: IBlendMode, matrix: Float32Array, color_transform: Float32Array | null, use_filter: boolean, filter_bounds: Float32Array | null, filter_params: Float32Array | null, unique_key: string, filter_key: string, layer_scale_x?: number, layer_scale_y?: number): void;
|
|
75
|
+
containerBeginAtlasNode(width: number, height: number): Node;
|
|
76
|
+
containerEndAtlasNode(): void;
|
|
74
77
|
containerDrawCachedFilter(blend_mode: IBlendMode, matrix: Float32Array, color_transform: Float32Array, filter_bounds: Float32Array, unique_key: string, filter_key: string): void;
|
|
75
78
|
createImageBitmap(width: number, height: number): Promise<ImageBitmap>;
|
|
76
79
|
}
|
package/src/Context.js
CHANGED
|
@@ -43,6 +43,7 @@ import { execute as contextStrokeUseCase } from "./Context/usecase/ContextStroke
|
|
|
43
43
|
import { execute as contextApplyFilterUseCase } from "./Context/usecase/ContextApplyFilterUseCase";
|
|
44
44
|
import { execute as contextContainerBeginLayerUseCase } from "./Context/usecase/ContextContainerBeginLayerUseCase";
|
|
45
45
|
import { execute as contextContainerEndLayerUseCase } from "./Context/usecase/ContextContainerEndLayerUseCase";
|
|
46
|
+
import { execute as contextContainerEndAtlasNodeUseCase } from "./Context/usecase/ContextContainerEndAtlasNodeUseCase";
|
|
46
47
|
import { execute as contextContainerDrawCachedFilterUseCase } from "./Context/usecase/ContextContainerDrawCachedFilterUseCase";
|
|
47
48
|
import { execute as contextUpdateTransferBoundsService } from "./Context/service/ContextUpdateTransferBoundsService";
|
|
48
49
|
import { execute as contextDrawFillUseCase } from "./Context/usecase/ContextDrawFillUseCase";
|
|
@@ -167,6 +168,12 @@ export class Context {
|
|
|
167
168
|
writable: true,
|
|
168
169
|
value: false
|
|
169
170
|
});
|
|
171
|
+
Object.defineProperty(this, "_pendingAtlasNodes", {
|
|
172
|
+
enumerable: true,
|
|
173
|
+
configurable: true,
|
|
174
|
+
writable: true,
|
|
175
|
+
value: []
|
|
176
|
+
});
|
|
170
177
|
$setWebGL2RenderingContext(gl);
|
|
171
178
|
$setRenderMaxSize(gl.getParameter(gl.MAX_TEXTURE_SIZE));
|
|
172
179
|
$setSamples(samples);
|
|
@@ -376,8 +383,21 @@ export class Context {
|
|
|
376
383
|
this.drawArraysInstanced();
|
|
377
384
|
contextContainerBeginLayerUseCase(width, height);
|
|
378
385
|
}
|
|
379
|
-
containerEndLayer(blend_mode, matrix, color_transform, use_filter, filter_bounds, filter_params, unique_key, filter_key) {
|
|
380
|
-
contextContainerEndLayerUseCase(blend_mode, matrix, color_transform, use_filter, filter_bounds, filter_params, unique_key, filter_key);
|
|
386
|
+
containerEndLayer(blend_mode, matrix, color_transform, use_filter, filter_bounds, filter_params, unique_key, filter_key, layer_scale_x = 1, layer_scale_y = 1) {
|
|
387
|
+
contextContainerEndLayerUseCase(blend_mode, matrix, color_transform, use_filter, filter_bounds, filter_params, unique_key, filter_key, layer_scale_x, layer_scale_y);
|
|
388
|
+
}
|
|
389
|
+
containerBeginAtlasNode(width, height) {
|
|
390
|
+
this.drawArraysInstanced();
|
|
391
|
+
// アトラスノードを確保(後でコピー先として使用)
|
|
392
|
+
const node = atlasManagerCreateNodeService(width, height);
|
|
393
|
+
this._pendingAtlasNodes.push(node);
|
|
394
|
+
// temp FBOを作成して子要素の描画先として設定
|
|
395
|
+
contextContainerBeginLayerUseCase(width, height);
|
|
396
|
+
return node;
|
|
397
|
+
}
|
|
398
|
+
containerEndAtlasNode() {
|
|
399
|
+
const node = this._pendingAtlasNodes.pop();
|
|
400
|
+
contextContainerEndAtlasNodeUseCase(node);
|
|
381
401
|
}
|
|
382
402
|
containerDrawCachedFilter(blend_mode, matrix, color_transform, filter_bounds, unique_key, filter_key) {
|
|
383
403
|
contextContainerDrawCachedFilterUseCase(blend_mode, matrix, color_transform, filter_bounds, unique_key, filter_key);
|
package/src/Mesh.js
CHANGED
|
@@ -62,7 +62,9 @@ export const $addFillBuffer = (buffer) => {
|
|
|
62
62
|
const length = buffer.length + $fillBufferOffset;
|
|
63
63
|
if (length > $fillBuffer.length) {
|
|
64
64
|
const newBuffer = new Float32Array($upperPowerOfTwo(length));
|
|
65
|
-
|
|
65
|
+
if ($fillBufferOffset > 0) {
|
|
66
|
+
newBuffer.set($fillBuffer.subarray(0, $fillBufferOffset));
|
|
67
|
+
}
|
|
66
68
|
newBuffer.set(buffer, $fillBufferOffset);
|
|
67
69
|
$fillBuffer = newBuffer;
|
|
68
70
|
}
|
|
@@ -13,21 +13,26 @@ import { $activeTextureUnit, $boundTextures, $setActiveTextureUnit } from "../..
|
|
|
13
13
|
* @protected
|
|
14
14
|
*/
|
|
15
15
|
export const execute = (index, unit, texture_object = null, smooth = false) => {
|
|
16
|
-
if ($activeTextureUnit
|
|
16
|
+
if ($activeTextureUnit !== unit) {
|
|
17
17
|
$setActiveTextureUnit(unit);
|
|
18
18
|
$gl.activeTexture(unit);
|
|
19
19
|
}
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const boundTexture = $boundTextures[index];
|
|
21
|
+
if (boundTexture === texture_object) {
|
|
22
|
+
// Same reference, already bound to this unit.
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (boundTexture !== null
|
|
26
|
+
&& texture_object !== null
|
|
27
|
+
&& boundTexture.id === texture_object.id) {
|
|
24
28
|
return;
|
|
25
29
|
}
|
|
26
30
|
$boundTextures[index] = texture_object;
|
|
27
31
|
$gl.bindTexture($gl.TEXTURE_2D, texture_object ? texture_object.resource : null);
|
|
28
32
|
if (texture_object && texture_object.smooth !== smooth) {
|
|
29
33
|
texture_object.smooth = smooth;
|
|
30
|
-
|
|
31
|
-
$gl.texParameteri($gl.TEXTURE_2D, $gl.
|
|
34
|
+
const filter = smooth ? $gl.LINEAR : $gl.NEAREST;
|
|
35
|
+
$gl.texParameteri($gl.TEXTURE_2D, $gl.TEXTURE_MIN_FILTER, filter);
|
|
36
|
+
$gl.texParameteri($gl.TEXTURE_2D, $gl.TEXTURE_MAG_FILTER, filter);
|
|
32
37
|
}
|
|
33
38
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { $gl } from "../../WebGLUtil";
|
|
2
|
+
import { $boundTextures } from "../../TextureManager";
|
|
2
3
|
/**
|
|
3
4
|
* @description TextureObjectをオブジェクトプールに保管、サイズオーバー時は削除します。
|
|
4
5
|
* Stores the TextureObject in the object pool and deletes it if it exceeds the size.
|
|
@@ -9,5 +10,10 @@ import { $gl } from "../../WebGLUtil";
|
|
|
9
10
|
* @protected
|
|
10
11
|
*/
|
|
11
12
|
export const execute = (texture_object) => {
|
|
13
|
+
for (let idx = 0; idx < $boundTextures.length; ++idx) {
|
|
14
|
+
if ($boundTextures[idx] === texture_object) {
|
|
15
|
+
$boundTextures[idx] = null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
12
18
|
$gl.deleteTexture(texture_object.resource);
|
|
13
19
|
};
|