Skip to content

Commit

Permalink
#154 feat: WebGLのパッケージを移行(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Jul 26, 2024
1 parent 5f3ec92 commit 52ca1c5
Show file tree
Hide file tree
Showing 30 changed files with 431 additions and 181 deletions.
3 changes: 0 additions & 3 deletions packages/webgl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,5 @@
"repository": {
"type": "git",
"url": "git+https://github.com/Next2D/Player.git"
},
"peerDependencies": {
"@next2d/share": "file:../share"
}
}
4 changes: 1 addition & 3 deletions packages/webgl/src/BezierConverter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { $Float32Array } from "@next2d/share";

/**
* @class
*/
Expand All @@ -13,7 +11,7 @@ export class BezierConverter
*/
constructor ()
{
this._$bezierConverterBuffer = new $Float32Array(32);
this._$bezierConverterBuffer = new Float32Array(32);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/webgl/src/CanvasGradientToWebGL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
$clamp,
$poolInt32Array4,
$poolFloat32Array6
} from "@next2d/share";
} from "./WebGLUtil";

/**
* @class
Expand Down
67 changes: 35 additions & 32 deletions packages/webgl/src/CanvasToWebGLContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { CanvasToWebGLContextBlend } from "./CanvasToWebGLContextBlend";
import { CanvasPatternToWebGL } from "./CanvasPatternToWebGL";
import { CanvasGradientToWebGL } from "./CanvasGradientToWebGL";
import { WebGLFillMeshGenerator } from "./WebGLFillMeshGenerator";
import { $setRenderSize } from "./Const";
import type { CanvasToWebGLShader } from "./shader/CanvasToWebGLShader";
import type { GradientShapeShaderVariantCollection } from "./shader/variants/GradientShapeShaderVariantCollection";
import type { ShapeShaderVariantCollection } from "./shader/variants/ShapeShaderVariantCollection";
Expand All @@ -29,16 +28,14 @@ import type { CapsStyleImpl } from "./interface/CapsStyleImpl";
import type { JointStyleImpl } from "./interface/JointStyleImpl";
import type { CachePositionImpl } from "./interface/CachePositionImpl";
import {
$Math,
$setRenderSize,
$getFloat32Array9,
$getArray,
$clamp,
$poolArray,
$inverseMatrix,
$poolFloat32Array9,
$poolBoundsObject,
$getBoundsObject
} from "@next2d/share";
$poolFloat32Array9
} from "./WebGLUtil";

/**
* @class
Expand Down Expand Up @@ -98,7 +95,7 @@ export class CanvasToWebGLContext
* @type {number}
* @private
*/
const samples: number = $Math.min(
const samples: number = Math.min(
sample,
gl.getParameter(gl.MAX_SAMPLES)
);
Expand All @@ -107,7 +104,7 @@ export class CanvasToWebGLContext
* @type {number}
* @private
*/
this._$maxTextureSize = $Math.min(8192,
this._$maxTextureSize = Math.min(8192,
gl.getParameter(gl.MAX_TEXTURE_SIZE)
) - 2;

Expand All @@ -121,7 +118,12 @@ export class CanvasToWebGLContext
* @type {BoundsImpl}
* @private
*/
this._$cacheBounds = $getBoundsObject();
this._$cacheBounds = {
"xMin": 0,
"yMin": 0,
"xMax": 0,
"yMax": 0
};

/**
* @type {Float32Array}
Expand Down Expand Up @@ -296,7 +298,12 @@ export class CanvasToWebGLContext
* @type {object}
* @private
*/
this._$maskBounds = $getBoundsObject(0, 0, 0, 0);
this._$maskBounds = {
"xMin": 0,
"yMin": 0,
"xMax": 0,
"yMax": 0
};

/**
* @type {object}
Expand Down Expand Up @@ -575,7 +582,7 @@ export class CanvasToWebGLContext
*/
_$getTextureScale (width: number, height: number): number
{
const maxSize = $Math.max(width, height);
const maxSize = Math.max(width, height);
if (maxSize > this._$maxTextureSize) {
return this._$maxTextureSize / maxSize;
}
Expand Down Expand Up @@ -1462,10 +1469,10 @@ export class CanvasToWebGLContext
return false;
}

this._$maskBounds.xMin = $Math.max(0, $Math.min(this._$maskBounds.xMin, x));
this._$maskBounds.yMin = $Math.max(0, $Math.min(this._$maskBounds.yMin, y));
this._$maskBounds.xMax = $Math.min(currentAttachment.width, $Math.min(this._$maskBounds.xMax, width));
this._$maskBounds.yMax = $Math.min(currentAttachment.height, $Math.min(this._$maskBounds.yMax, height));
this._$maskBounds.xMin = Math.max(0, Math.min(this._$maskBounds.xMin, x));
this._$maskBounds.yMin = Math.max(0, Math.min(this._$maskBounds.yMin, y));
this._$maskBounds.xMax = Math.min(currentAttachment.width, Math.min(this._$maskBounds.xMax, width));
this._$maskBounds.yMax = Math.min(currentAttachment.height, Math.min(this._$maskBounds.yMax, height));

return true;
}
Expand Down Expand Up @@ -1550,27 +1557,27 @@ export class CanvasToWebGLContext

const strokeStyle: Float32Array|CanvasGradientToWebGL|CanvasPatternToWebGL = this.strokeStyle;

let face: number = $Math.sign(matrix[0] * matrix[4]);
let face: number = Math.sign(matrix[0] * matrix[4]);
if (face > 0 && matrix[1] !== 0 && matrix[3] !== 0) {
face = -$Math.sign(matrix[1] * matrix[3]);
face = -Math.sign(matrix[1] * matrix[3]);
}

let lineWidth: number = this.lineWidth * 0.5;
let scaleX: number;
let scaleY: number;
if (this._$grid.enabled) {
// lineWidth *= $getSameScaleBase();
scaleX = $Math.abs(this._$grid.ancestorMatrixA + this._$grid.ancestorMatrixD);
scaleY = $Math.abs(this._$grid.ancestorMatrixB + this._$grid.ancestorMatrixE);
scaleX = Math.abs(this._$grid.ancestorMatrixA + this._$grid.ancestorMatrixD);
scaleY = Math.abs(this._$grid.ancestorMatrixB + this._$grid.ancestorMatrixE);
} else {
scaleX = $Math.abs(matrix[0] + matrix[3]);
scaleY = $Math.abs(matrix[1] + matrix[4]);
scaleX = Math.abs(matrix[0] + matrix[3]);
scaleY = Math.abs(matrix[1] + matrix[4]);
}

const scaleMin: number = $Math.min(scaleX, scaleY);
const scaleMax: number = $Math.max(scaleX, scaleY);
lineWidth *= scaleMax * (1 - 0.3 * $Math.cos($Math.PI * 0.5 * (scaleMin / scaleMax)));
lineWidth = $Math.max(1, lineWidth);
const scaleMin: number = Math.min(scaleX, scaleY);
const scaleMax: number = Math.max(scaleX, scaleY);
lineWidth *= scaleMax * (1 - 0.3 * Math.cos(Math.PI * 0.5 * (scaleMin / scaleMax)));
lineWidth = Math.max(1, lineWidth);

const hasGrid: boolean = this._$grid.enabled;

Expand Down Expand Up @@ -1903,7 +1910,7 @@ export class CanvasToWebGLContext
.textureManager
.bind0(texture, true);

const halfBlur: number = $Math.ceil(blur * 0.5);
const halfBlur: number = Math.ceil(blur * 0.5);
const fraction: number = 1 - (halfBlur - blur * 0.5);
const samples: number = 1 + blur;

Expand Down Expand Up @@ -2267,11 +2274,7 @@ export class CanvasToWebGLContext
*/
_$endLayer (): void
{
const bounds: BoundsImpl | void = this._$positions.pop();
if (bounds) {
$poolBoundsObject(bounds);
}

this._$positions.pop();
this._$isLayer = !!this._$blends.pop();
}

Expand Down Expand Up @@ -2340,7 +2343,7 @@ export class CanvasToWebGLContext
*/
textureScale (width: number, height: number): number
{
const maxSize = $Math.max(width, height);
const maxSize = Math.max(width, height);
if (maxSize > this._$maxTextureSize) {
return this._$maxTextureSize / maxSize;
}
Expand Down
50 changes: 23 additions & 27 deletions packages/webgl/src/CanvasToWebGLContextBlend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import type { BlendShaderVariantCollection } from "./shader/variants/BlendShader
import type { BlendModeImpl } from "./interface/BlendModeImpl";
import type { AttachmentImpl } from "./interface/AttachmentImpl";
import type { CachePositionImpl } from "./interface/CachePositionImpl";
import {
$Math,
$Number,
$inverseMatrix
} from "@next2d/share";
import { $inverseMatrix } from "./WebGLUtil";

/**
* @class
Expand Down Expand Up @@ -481,8 +477,8 @@ export class CanvasToWebGLContextBlend
withCT, ct0, ct1, ct2, ct3, ct4, ct5, ct6, ct7
);

const width: number = $Math.abs(x_max - x_min);
const height: number = $Math.abs(y_max - y_min);
const width: number = Math.abs(x_max - x_min);
const height: number = Math.abs(y_max - y_min);

this._$gl.enable(this._$gl.SCISSOR_TEST);
this._$gl.scissor(x_min, render_height - (y_min + height), width, height);
Expand Down Expand Up @@ -578,37 +574,37 @@ export class CanvasToWebGLContextBlend
const y2: number = +(left * b + bottom * d + ty);
const y3: number = +(left * b + top * d + ty);

const no: number = $Number.MAX_VALUE;
const xMin: number = +$Math.min($Math.min($Math.min($Math.min( no, x0), x1), x2), x3);
const xMax: number = +$Math.max($Math.max($Math.max($Math.max(-no, x0), x1), x2), x3);
const yMin: number = +$Math.min($Math.min($Math.min($Math.min( no, y0), y1), y2), y3);
const yMax: number = +$Math.max($Math.max($Math.max($Math.max(-no, y0), y1), y2), y3);
const no: number = Number.MAX_VALUE;
const xMin: number = +Math.min(Math.min(Math.min(Math.min( no, x0), x1), x2), x3);
const xMax: number = +Math.max(Math.max(Math.max(Math.max(-no, x0), x1), x2), x3);
const yMin: number = +Math.min(Math.min(Math.min(Math.min( no, y0), y1), y2), y3);
const yMax: number = +Math.max(Math.max(Math.max(Math.max(-no, y0), y1), y2), y3);

const sx: number = $Math.max(0, xMin);
const sy: number = $Math.max(0, yMin);
const sw: number = $Math.min($Math.max(0, renderWidth - sx), $Math.ceil($Math.abs(xMax - xMin)));
const sh: number = $Math.min($Math.max(0, renderHeight - sy), $Math.ceil($Math.abs(yMax - yMin)));
const sx: number = Math.max(0, xMin);
const sy: number = Math.max(0, yMin);
const sw: number = Math.min(Math.max(0, renderWidth - sx), Math.ceil(Math.abs(xMax - xMin)));
const sh: number = Math.min(Math.max(0, renderHeight - sy), Math.ceil(Math.abs(yMax - yMin)));

if (!sw || !sh) {
return ;
}

this._$gl.enable(this._$gl.SCISSOR_TEST);
this._$gl.scissor(sx, $Math.max(0, renderHeight - (sy + sh)), sw + 1, sh + 1);
this._$gl.scissor(sx, Math.max(0, renderHeight - (sy + sh)), sw + 1, sh + 1);

} else {

const sx: number = $Math.max(0, x + tx);
const sy: number = $Math.max(0, y + ty);
const sw: number = $Math.min($Math.max(0, renderWidth - sx), w);
const sh: number = $Math.min($Math.max(0, renderHeight - sy), h);
const sx: number = Math.max(0, x + tx);
const sy: number = Math.max(0, y + ty);
const sw: number = Math.min(Math.max(0, renderWidth - sx), w);
const sh: number = Math.min(Math.max(0, renderHeight - sy), h);

if (!sw || !sh) {
return ;
}

this._$gl.enable(this._$gl.SCISSOR_TEST);
this._$gl.scissor(sx, $Math.max(0, renderHeight - (sy + sh)), sw + 1, sh + 1);
this._$gl.scissor(sx, Math.max(0, renderHeight - (sy + sh)), sw + 1, sh + 1);
}

this.toOperation(operation);
Expand All @@ -620,10 +616,10 @@ export class CanvasToWebGLContextBlend

default:
{
const sx: number = $Math.max(0, x + matrix[6]);
const sy: number = $Math.max(0, y + matrix[7]);
const sw: number = $Math.min($Math.max(0, renderWidth - sx), w);
const sh: number = $Math.min($Math.max(0, renderHeight - sy), h);
const sx: number = Math.max(0, x + matrix[6]);
const sy: number = Math.max(0, y + matrix[7]);
const sw: number = Math.min(Math.max(0, renderWidth - sx), w);
const sh: number = Math.min(Math.max(0, renderHeight - sy), h);

if (!sw || !sh) {
return ;
Expand Down Expand Up @@ -667,7 +663,7 @@ export class CanvasToWebGLContextBlend
);

this._$gl.enable(this._$gl.SCISSOR_TEST);
this._$gl.scissor(sx, $Math.max(0, renderHeight - (sy + sh)), sw, sh);
this._$gl.scissor(sx, Math.max(0, renderHeight - (sy + sh)), sw, sh);

this.toOneZero();
shader._$drawImage();
Expand Down
13 changes: 6 additions & 7 deletions packages/webgl/src/CanvasToWebGLContextGrid.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { BoundsImpl } from "./interface/BoundsImpl";
import type { GridImpl } from "./interface/GridImpl";
import { $Math } from "@next2d/share";

/**
* @class
Expand Down Expand Up @@ -301,8 +300,8 @@ export class CanvasToWebGLContextGrid
const gridWidth: number = grid.w;
const gridHeight: number = grid.h;

const sameWidth: number = $Math.abs($Math.ceil(boundsWidth * same_scale));
const sameHeight: number = $Math.abs($Math.ceil(boundsHeight * same_scale));
const sameWidth: number = Math.abs(Math.ceil(boundsWidth * same_scale));
const sameHeight: number = Math.abs(Math.ceil(boundsHeight * same_scale));

// 等倍サイズでの正規化grid
const minXST: number = gridWidth > 0 ? (grid.x - bounds.xMin) / boundsWidth : 0.00001;
Expand All @@ -318,14 +317,14 @@ export class CanvasToWebGLContextGrid

if (minXPQ >= maxXPQ) {
const m: number = minXST / (minXST + (1 - maxXST));
minXPQ = $Math.max(m - 0.00001, 0);
maxXPQ = $Math.min(m + 0.00001, 1);
minXPQ = Math.max(m - 0.00001, 0);
maxXPQ = Math.min(m + 0.00001, 1);
}

if (minYPQ >= maxYPQ) {
const m: number = minYST / (minYST + (1 - maxYST));
minYPQ = $Math.max(m - 0.00001, 0);
maxYPQ = $Math.min(m + 0.00001, 1);
minYPQ = Math.max(m - 0.00001, 0);
maxYPQ = Math.min(m + 0.00001, 1);
}

this.enabled = true;
Expand Down
4 changes: 2 additions & 2 deletions packages/webgl/src/CanvasToWebGLContextMask.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { WebGLFillMeshGenerator } from "./WebGLFillMeshGenerator";
import type { CanvasToWebGLContext } from "./CanvasToWebGLContext";
import type { ShapeShaderVariantCollection } from "./shader/variants/ShapeShaderVariantCollection";
import type { CanvasToWebGLShader } from "./shader/CanvasToWebGLShader";
import type { WebGLShaderUniform } from "./shader/WebGLShaderUniform";
import type { AttachmentImpl } from "./interface/AttachmentImpl";
import type { ClipObjectImpl } from "./interface/ClipObjectImpl";
import type { IndexRangeImpl } from "./interface/IndexRangeImpl";
import { $poolArray } from "@next2d/share";
import { WebGLFillMeshGenerator } from "./WebGLFillMeshGenerator";
import { $poolArray } from "./WebGLUtil";

/**
* @class
Expand Down
2 changes: 1 addition & 1 deletion packages/webgl/src/CanvasToWebGLContextPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { VerticesImpl } from "./interface/VerticesImpl";
import {
$getArray,
$poolArray
} from "@next2d/share";
} from "./WebGLUtil";

/**
* @class
Expand Down
9 changes: 4 additions & 5 deletions packages/webgl/src/CanvasToWebGLContextStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import type { CapsStyleImpl } from "./interface/CapsStyleImpl";
import type { JointStyleImpl } from "./interface/JointStyleImpl";
import {
$getFloat32Array4,
$poolFloat32Array4,
$Float32Array
} from "@next2d/share";
$poolFloat32Array4
} from "./WebGLUtil";

/**
* @class
Expand Down Expand Up @@ -100,7 +99,7 @@ export class CanvasToWebGLContextStyle
}
set fillStyle (style: Float32Array|CanvasGradientToWebGL|CanvasPatternToWebGL)
{
if (this._$fillStyle instanceof $Float32Array) {
if (this._$fillStyle instanceof Float32Array) {
$poolFloat32Array4(this._$fillStyle);
}
this._$fillStyle = style;
Expand All @@ -116,7 +115,7 @@ export class CanvasToWebGLContextStyle
}
set strokeStyle (style: Float32Array|CanvasGradientToWebGL|CanvasPatternToWebGL)
{
if (this._$strokeStyle instanceof $Float32Array) {
if (this._$strokeStyle instanceof Float32Array) {
$poolFloat32Array4(this._$strokeStyle);
}
this._$strokeStyle = style;
Expand Down
Loading

0 comments on commit 52ca1c5

Please sign in to comment.