Skip to content

Commit

Permalink
#154 webglパッケージをv2へ移行(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Sep 2, 2024
1 parent eafb949 commit 59fd340
Show file tree
Hide file tree
Showing 25 changed files with 642 additions and 824 deletions.
9 changes: 9 additions & 0 deletions packages/cache/src/CacheStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ export class CacheStore
cacheStoreRemoveByIdService(this, this._$store, id);
}

/**
* @description 指定IDのキャッシュデータを返却
* Returns the cache data for the specified ID
*
* @param {string} id
* @return {Map<string, any>}
* @method
* @public
*/
getById (id: string): Map<string, any>
{
return this._$store.get(id);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Player/usecase/PlayerTickerUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const execute = (player: Player, timestamp: number): void =>
// 定期処理
$stage.$ticker();

if ($stage.$remoceCacheKeys) {
if ($stage.$remoceCacheKeys.length) {
playerRemoveCachePostMessageService();
}

Expand Down
10 changes: 0 additions & 10 deletions packages/display/src/BitmapData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,6 @@ export class BitmapData
this._$canvas = null;
this._$image = null;
this._$buffer = buffer;

if (this._$texture) {
const player: Player = $currentPlayer();
const context: CanvasToWebGLContext | null = player.context;
if (context) {
context.frameBuffer.releaseTexture(this._$texture);
}

this._$texture = null;
}
}

/**
Expand Down
44 changes: 22 additions & 22 deletions packages/display/src/Graphics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class Graphics
* @default null
* @public
*/
public _$recodes: any[] | null;
public $recodes: any[] | null;

/**
* @type {Float32Array}
Expand Down Expand Up @@ -253,7 +253,7 @@ export class Graphics
this.yMax = -Number.MAX_VALUE;

// private
this._$recodes = null;
this.$recodes = null;
this._$buffer = null;
this._$positionX = 0;
this._$positionY = 0;
Expand Down Expand Up @@ -716,8 +716,8 @@ export class Graphics
this.yMax = -Number.MAX_VALUE;

// init array
if (this._$recodes) {
$poolArray(this._$recodes);
if (this.$recodes) {
$poolArray(this.$recodes);
}
if (this._$fills) {
$poolArray(this._$fills);
Expand All @@ -727,7 +727,7 @@ export class Graphics
}

this._$buffer = null;
this._$recodes = null;
this.$recodes = null;
this._$fills = null;
this._$lines = null;

Expand Down Expand Up @@ -805,8 +805,8 @@ export class Graphics
if (graphics._$lines) {
this._$lines = graphics._$lines.slice(0);
}
if (graphics._$recodes) {
this._$recodes = graphics._$recodes.slice(0);
if (graphics.$recodes) {
this.$recodes = graphics.$recodes.slice(0);
}

this._$buffer = null;
Expand Down Expand Up @@ -1045,8 +1045,8 @@ export class Graphics
return this;
}

if (!this._$recodes) {
this._$recodes = $getArray();
if (!this.$recodes) {
this.$recodes = $getArray();
}

if (this._$fills[2] !== this._$fills[this._$fills.length - 2]
Expand All @@ -1058,7 +1058,7 @@ export class Graphics
this._$fills[3]
);
}
this._$recodes.push(...this._$fills);
this.$recodes.push(...this._$fills);

$poolArray(this._$fills);
this._$fills = null;
Expand All @@ -1067,7 +1067,7 @@ export class Graphics
switch (this._$fillType) {

case Graphics.FILL_STYLE:
this._$recodes.push(
this.$recodes.push(
this._$fillType,
(this._$fillColor >>> 24) & 0xff,
(this._$fillColor >>> 16) & 0xff,
Expand All @@ -1079,7 +1079,7 @@ export class Graphics

case Graphics.GRADIENT_FILL:
if (this._$fillGradient) {
this._$recodes.push(
this.$recodes.push(
this._$fillType,
...this._$fillGradient.toArray()
);
Expand All @@ -1088,7 +1088,7 @@ export class Graphics

case Graphics.BITMAP_FILL:
if (this._$fillBitmap) {
this._$recodes.push(
this.$recodes.push(
this._$fillType,
...this._$fillBitmap.toArray()
);
Expand Down Expand Up @@ -1123,11 +1123,11 @@ export class Graphics
return this;
}

if (!this._$recodes) {
this._$recodes = $getArray();
if (!this.$recodes) {
this.$recodes = $getArray();
}

this._$recodes.push(...this._$lines);
this.$recodes.push(...this._$lines);

// clear
$poolArray(this._$lines);
Expand All @@ -1137,7 +1137,7 @@ export class Graphics
switch (this._$lineType) {

case Graphics.STROKE_STYLE:
this._$recodes.push(
this.$recodes.push(
this._$lineType,
this._$lineWidth,
this._$caps,
Expand All @@ -1153,7 +1153,7 @@ export class Graphics

case Graphics.GRADIENT_STROKE:
if (this._$lineGradient) {
this._$recodes.push(
this.$recodes.push(
this._$lineType,
this._$lineWidth,
this._$caps,
Expand All @@ -1166,7 +1166,7 @@ export class Graphics

case Graphics.BITMAP_STROKE:
if (this._$fillBitmap) {
this._$recodes.push(
this.$recodes.push(
this._$lineType,
this._$lineWidth,
this._$caps,
Expand Down Expand Up @@ -1498,7 +1498,7 @@ export class Graphics
this.endFill();
}

if (!this._$recodes) {
if (!this.$recodes) {
return false;
}

Expand All @@ -1508,7 +1508,7 @@ export class Graphics
matrix[3], matrix[4], matrix[5]
);

return graphicsHitTestService(context, this._$recodes, options);
return graphicsHitTestService(context, this.$recodes, options);
}

// /**
Expand Down Expand Up @@ -1559,7 +1559,7 @@ export class Graphics
const width = Math.ceil(Math.abs(this.xMax - this.xMin));
const height = Math.ceil(Math.abs(this.yMax - this.yMin));

const array: any[] = graphicsToNumberArrayService(width, height, this._$recodes);
const array: any[] = graphicsToNumberArrayService(width, height, this.$recodes);
this._$buffer = new Float32Array(array);
$poolArray(array);

Expand Down
79 changes: 60 additions & 19 deletions packages/display/src/Shape.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { IPlayerHitObject } from "./interface/IPlayerHitObject";
import { DisplayObject } from "./DisplayObject";
import { Graphics } from "./Graphics";
import { BitmapData } from "./BitmapData";
import { Event } from "@next2d/events";
import { execute as shapeClearBitmapBufferService } from "./Shape/service/ShapeClearBitmapBufferService";
import { execute as shapeSetBitmapBufferUseCase } from "./Shape/usecase/ShapeSetBitmapBufferUseCase";
import { execute as shapeLoadSrcUseCase } from "./Shape/usecase/ShapeLoadSrcUseCase";
import {
$graphicMap,
$getArray
Expand Down Expand Up @@ -62,6 +63,26 @@ export class Shape extends DisplayObject
*/
public cacheParams: number[];

/**
* @description ビットマップ描画の判定フラグ
* Bitmap drawing judgment flag
*
* @type {boolean}
* @default false
* @protected
*/
public isBitmap: boolean;

/**
* @description 画像RGBAのUint8Array
* Image RGBA Uint8Array
*
* @type {Uint8Array|null}
* @default null
* @protected
*/
public $bitmapBuffer: Uint8Array | null;

/**
* @constructor
* @public
Expand All @@ -77,6 +98,10 @@ export class Shape extends DisplayObject
// private
this._$graphics = null;
this._$src = "";

// bitmap
this.$bitmapBuffer = null;
this.isBitmap = false;
}

/**
Expand Down Expand Up @@ -140,26 +165,42 @@ export class Shape extends DisplayObject
return ;
}

const image: HTMLImageElement = new Image();
image.addEventListener("load", () =>
{
const width: number = image.width;
const height: number = image.height;
this._$src = src;

const bitmapData: BitmapData = new BitmapData(width, height);
bitmapData.image = image;

this
.graphics
.beginBitmapFill(bitmapData)
.drawRect(0, 0, width, height);
shapeLoadSrcUseCase(this, src);
}

if (this.hasEventListener(Event.COMPLETE)) {
this.dispatchEvent(new Event(Event.COMPLETE));
}
});
/**
* @description ビットマップデータを解放します
* Releases bitmap data.
*
* @return {void}
* @method
* @public
*/
clearBitmapBuffer (): void
{
shapeClearBitmapBufferService(this);
};

Check warning on line 184 in packages/display/src/Shape.ts

View workflow job for this annotation

GitHub Actions / macos-browser-test

Unnecessary semicolon

Check warning on line 184 in packages/display/src/Shape.ts

View workflow job for this annotation

GitHub Actions / windows-browser-test

Unnecessary semicolon

this._$src = image.src = src;
/**
* @description RGBAの画像データを設定します
* Sets the RGBA image data.
*
* @param {number} width
* @param {number} height
* @param {Uint8Array} buffer
* @method
* @public
*/
setBitmapBuffer (width: number, height: number, buffer: Uint8Array): void
{
shapeSetBitmapBufferUseCase(
this,
width,
height,
buffer
);
}

// /**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Shape } from "../../Shape";
import { $stage } from "../../Stage";
import { $cacheStore } from "@next2d/cache";

/**
* @description BitmapBufferの設定をクリア
* Clear the BitmapBuffer settings
*
* @param {Shape} shape
* @return {void}
* @method
* @protected
*/
export const execute = (shape: Shape): void =>
{
shape.isBitmap = false;
shape.$bitmapBuffer = null;

// graphics clear
shape.graphics.clear();

// cache clear
$stage.$remoceCacheKeys.push(+shape.uniqueKey);
$cacheStore.removeById(shape.uniqueKey);
};
Loading

0 comments on commit 59fd340

Please sign in to comment.