This commit is contained in:
Akko
2025-08-04 18:57:35 +02:00
parent 8cf6e78a79
commit 9495868c2e
5030 changed files with 518594 additions and 17609 deletions

View File

@@ -0,0 +1,137 @@
import { ExtensionType } from '../../../../extensions/Extensions';
import { State } from '../../shared/state/State';
import type { BLEND_MODES } from '../../shared/state/const';
import type { System } from '../../shared/system/System';
import type { GlRenderingContext } from '../context/GlRenderingContext';
/**
* System plugin to the renderer to manage WebGL state machines
* @memberof rendering
*/
export declare class GlStateSystem implements System {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLSystem];
readonly name: "state";
};
/**
* State ID
* @readonly
*/
stateId: number;
/**
* Polygon offset
* @readonly
*/
polygonOffset: number;
/**
* Blend mode
* @default 'none'
* @readonly
*/
blendMode: BLEND_MODES;
/** Whether current blend equation is different */
protected _blendEq: boolean;
/**
* GL context
* @member {WebGLRenderingContext}
* @readonly
*/
protected gl: GlRenderingContext;
protected blendModesMap: Record<BLEND_MODES, number[]>;
/**
* Collection of calls
* @member {Function[]}
*/
protected readonly map: ((value: boolean) => void)[];
/**
* Collection of check calls
* @member {Function[]}
*/
protected readonly checks: ((system: this, state: State) => void)[];
/**
* Default WebGL State
* @readonly
*/
protected defaultState: State;
constructor();
protected contextChange(gl: GlRenderingContext): void;
/**
* Sets the current state
* @param {*} state - The state to set.
*/
set(state: State): void;
/**
* Sets the state, when previous state is unknown.
* @param {*} state - The state to set
*/
forceState(state: State): void;
/**
* Sets whether to enable or disable blending.
* @param value - Turn on or off WebGl blending.
*/
setBlend(value: boolean): void;
/**
* Sets whether to enable or disable polygon offset fill.
* @param value - Turn on or off webgl polygon offset testing.
*/
setOffset(value: boolean): void;
/**
* Sets whether to enable or disable depth test.
* @param value - Turn on or off webgl depth testing.
*/
setDepthTest(value: boolean): void;
/**
* Sets whether to enable or disable depth mask.
* @param value - Turn on or off webgl depth mask.
*/
setDepthMask(value: boolean): void;
/**
* Sets whether to enable or disable cull face.
* @param {boolean} value - Turn on or off webgl cull face.
*/
setCullFace(value: boolean): void;
/**
* Sets the gl front face.
* @param {boolean} value - true is clockwise and false is counter-clockwise
*/
setFrontFace(value: boolean): void;
/**
* Sets the blend mode.
* @param {number} value - The blend mode to set to.
*/
setBlendMode(value: BLEND_MODES): void;
/**
* Sets the polygon offset.
* @param {number} value - the polygon offset
* @param {number} scale - the polygon offset scale
*/
setPolygonOffset(value: number, scale: number): void;
/** Resets all the logic and disables the VAOs. */
reset(): void;
/**
* Checks to see which updates should be checked based on which settings have been activated.
*
* For example, if blend is enabled then we should check the blend modes each time the state is changed
* or if polygon fill is activated then we need to check if the polygon offset changes.
* The idea is that we only check what we have too.
* @param func - the checking function to add or remove
* @param value - should the check function be added or removed.
*/
private _updateCheck;
/**
* A private little wrapper function that we call to check the blend mode.
* @param system - the System to perform the state check on
* @param state - the state that the blendMode will pulled from
*/
private static _checkBlendMode;
/**
* A private little wrapper function that we call to check the polygon offset.
* @param system - the System to perform the state check on
* @param state - the state that the blendMode will pulled from
*/
private static _checkPolygonOffset;
/**
* @ignore
*/
destroy(): void;
}

View File

@@ -0,0 +1,211 @@
'use strict';
var Extensions = require('../../../../extensions/Extensions.js');
var State = require('../../shared/state/State.js');
var mapWebGLBlendModesToPixi = require('./mapWebGLBlendModesToPixi.js');
"use strict";
const BLEND = 0;
const OFFSET = 1;
const CULLING = 2;
const DEPTH_TEST = 3;
const WINDING = 4;
const DEPTH_MASK = 5;
const _GlStateSystem = class _GlStateSystem {
constructor() {
this.gl = null;
this.stateId = 0;
this.polygonOffset = 0;
this.blendMode = "none";
this._blendEq = false;
this.map = [];
this.map[BLEND] = this.setBlend;
this.map[OFFSET] = this.setOffset;
this.map[CULLING] = this.setCullFace;
this.map[DEPTH_TEST] = this.setDepthTest;
this.map[WINDING] = this.setFrontFace;
this.map[DEPTH_MASK] = this.setDepthMask;
this.checks = [];
this.defaultState = State.State.for2d();
}
contextChange(gl) {
this.gl = gl;
this.blendModesMap = mapWebGLBlendModesToPixi.mapWebGLBlendModesToPixi(gl);
this.reset();
}
/**
* Sets the current state
* @param {*} state - The state to set.
*/
set(state) {
state = state || this.defaultState;
if (this.stateId !== state.data) {
let diff = this.stateId ^ state.data;
let i = 0;
while (diff) {
if (diff & 1) {
this.map[i].call(this, !!(state.data & 1 << i));
}
diff = diff >> 1;
i++;
}
this.stateId = state.data;
}
for (let i = 0; i < this.checks.length; i++) {
this.checks[i](this, state);
}
}
/**
* Sets the state, when previous state is unknown.
* @param {*} state - The state to set
*/
forceState(state) {
state = state || this.defaultState;
for (let i = 0; i < this.map.length; i++) {
this.map[i].call(this, !!(state.data & 1 << i));
}
for (let i = 0; i < this.checks.length; i++) {
this.checks[i](this, state);
}
this.stateId = state.data;
}
/**
* Sets whether to enable or disable blending.
* @param value - Turn on or off WebGl blending.
*/
setBlend(value) {
this._updateCheck(_GlStateSystem._checkBlendMode, value);
this.gl[value ? "enable" : "disable"](this.gl.BLEND);
}
/**
* Sets whether to enable or disable polygon offset fill.
* @param value - Turn on or off webgl polygon offset testing.
*/
setOffset(value) {
this._updateCheck(_GlStateSystem._checkPolygonOffset, value);
this.gl[value ? "enable" : "disable"](this.gl.POLYGON_OFFSET_FILL);
}
/**
* Sets whether to enable or disable depth test.
* @param value - Turn on or off webgl depth testing.
*/
setDepthTest(value) {
this.gl[value ? "enable" : "disable"](this.gl.DEPTH_TEST);
}
/**
* Sets whether to enable or disable depth mask.
* @param value - Turn on or off webgl depth mask.
*/
setDepthMask(value) {
this.gl.depthMask(value);
}
/**
* Sets whether to enable or disable cull face.
* @param {boolean} value - Turn on or off webgl cull face.
*/
setCullFace(value) {
this.gl[value ? "enable" : "disable"](this.gl.CULL_FACE);
}
/**
* Sets the gl front face.
* @param {boolean} value - true is clockwise and false is counter-clockwise
*/
setFrontFace(value) {
this.gl.frontFace(this.gl[value ? "CW" : "CCW"]);
}
/**
* Sets the blend mode.
* @param {number} value - The blend mode to set to.
*/
setBlendMode(value) {
if (!this.blendModesMap[value]) {
value = "normal";
}
if (value === this.blendMode) {
return;
}
this.blendMode = value;
const mode = this.blendModesMap[value];
const gl = this.gl;
if (mode.length === 2) {
gl.blendFunc(mode[0], mode[1]);
} else {
gl.blendFuncSeparate(mode[0], mode[1], mode[2], mode[3]);
}
if (mode.length === 6) {
this._blendEq = true;
gl.blendEquationSeparate(mode[4], mode[5]);
} else if (this._blendEq) {
this._blendEq = false;
gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
}
}
/**
* Sets the polygon offset.
* @param {number} value - the polygon offset
* @param {number} scale - the polygon offset scale
*/
setPolygonOffset(value, scale) {
this.gl.polygonOffset(value, scale);
}
// used
/** Resets all the logic and disables the VAOs. */
reset() {
this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, false);
this.forceState(this.defaultState);
this._blendEq = true;
this.blendMode = "";
this.setBlendMode("normal");
}
/**
* Checks to see which updates should be checked based on which settings have been activated.
*
* For example, if blend is enabled then we should check the blend modes each time the state is changed
* or if polygon fill is activated then we need to check if the polygon offset changes.
* The idea is that we only check what we have too.
* @param func - the checking function to add or remove
* @param value - should the check function be added or removed.
*/
_updateCheck(func, value) {
const index = this.checks.indexOf(func);
if (value && index === -1) {
this.checks.push(func);
} else if (!value && index !== -1) {
this.checks.splice(index, 1);
}
}
/**
* A private little wrapper function that we call to check the blend mode.
* @param system - the System to perform the state check on
* @param state - the state that the blendMode will pulled from
*/
static _checkBlendMode(system, state) {
system.setBlendMode(state.blendMode);
}
/**
* A private little wrapper function that we call to check the polygon offset.
* @param system - the System to perform the state check on
* @param state - the state that the blendMode will pulled from
*/
static _checkPolygonOffset(system, state) {
system.setPolygonOffset(1, state.polygonOffset);
}
/**
* @ignore
*/
destroy() {
this.gl = null;
this.checks.length = 0;
}
};
/** @ignore */
_GlStateSystem.extension = {
type: [
Extensions.ExtensionType.WebGLSystem
],
name: "state"
};
let GlStateSystem = _GlStateSystem;
exports.GlStateSystem = GlStateSystem;
//# sourceMappingURL=GlStateSystem.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,209 @@
import { ExtensionType } from '../../../../extensions/Extensions.mjs';
import { State } from '../../shared/state/State.mjs';
import { mapWebGLBlendModesToPixi } from './mapWebGLBlendModesToPixi.mjs';
"use strict";
const BLEND = 0;
const OFFSET = 1;
const CULLING = 2;
const DEPTH_TEST = 3;
const WINDING = 4;
const DEPTH_MASK = 5;
const _GlStateSystem = class _GlStateSystem {
constructor() {
this.gl = null;
this.stateId = 0;
this.polygonOffset = 0;
this.blendMode = "none";
this._blendEq = false;
this.map = [];
this.map[BLEND] = this.setBlend;
this.map[OFFSET] = this.setOffset;
this.map[CULLING] = this.setCullFace;
this.map[DEPTH_TEST] = this.setDepthTest;
this.map[WINDING] = this.setFrontFace;
this.map[DEPTH_MASK] = this.setDepthMask;
this.checks = [];
this.defaultState = State.for2d();
}
contextChange(gl) {
this.gl = gl;
this.blendModesMap = mapWebGLBlendModesToPixi(gl);
this.reset();
}
/**
* Sets the current state
* @param {*} state - The state to set.
*/
set(state) {
state = state || this.defaultState;
if (this.stateId !== state.data) {
let diff = this.stateId ^ state.data;
let i = 0;
while (diff) {
if (diff & 1) {
this.map[i].call(this, !!(state.data & 1 << i));
}
diff = diff >> 1;
i++;
}
this.stateId = state.data;
}
for (let i = 0; i < this.checks.length; i++) {
this.checks[i](this, state);
}
}
/**
* Sets the state, when previous state is unknown.
* @param {*} state - The state to set
*/
forceState(state) {
state = state || this.defaultState;
for (let i = 0; i < this.map.length; i++) {
this.map[i].call(this, !!(state.data & 1 << i));
}
for (let i = 0; i < this.checks.length; i++) {
this.checks[i](this, state);
}
this.stateId = state.data;
}
/**
* Sets whether to enable or disable blending.
* @param value - Turn on or off WebGl blending.
*/
setBlend(value) {
this._updateCheck(_GlStateSystem._checkBlendMode, value);
this.gl[value ? "enable" : "disable"](this.gl.BLEND);
}
/**
* Sets whether to enable or disable polygon offset fill.
* @param value - Turn on or off webgl polygon offset testing.
*/
setOffset(value) {
this._updateCheck(_GlStateSystem._checkPolygonOffset, value);
this.gl[value ? "enable" : "disable"](this.gl.POLYGON_OFFSET_FILL);
}
/**
* Sets whether to enable or disable depth test.
* @param value - Turn on or off webgl depth testing.
*/
setDepthTest(value) {
this.gl[value ? "enable" : "disable"](this.gl.DEPTH_TEST);
}
/**
* Sets whether to enable or disable depth mask.
* @param value - Turn on or off webgl depth mask.
*/
setDepthMask(value) {
this.gl.depthMask(value);
}
/**
* Sets whether to enable or disable cull face.
* @param {boolean} value - Turn on or off webgl cull face.
*/
setCullFace(value) {
this.gl[value ? "enable" : "disable"](this.gl.CULL_FACE);
}
/**
* Sets the gl front face.
* @param {boolean} value - true is clockwise and false is counter-clockwise
*/
setFrontFace(value) {
this.gl.frontFace(this.gl[value ? "CW" : "CCW"]);
}
/**
* Sets the blend mode.
* @param {number} value - The blend mode to set to.
*/
setBlendMode(value) {
if (!this.blendModesMap[value]) {
value = "normal";
}
if (value === this.blendMode) {
return;
}
this.blendMode = value;
const mode = this.blendModesMap[value];
const gl = this.gl;
if (mode.length === 2) {
gl.blendFunc(mode[0], mode[1]);
} else {
gl.blendFuncSeparate(mode[0], mode[1], mode[2], mode[3]);
}
if (mode.length === 6) {
this._blendEq = true;
gl.blendEquationSeparate(mode[4], mode[5]);
} else if (this._blendEq) {
this._blendEq = false;
gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
}
}
/**
* Sets the polygon offset.
* @param {number} value - the polygon offset
* @param {number} scale - the polygon offset scale
*/
setPolygonOffset(value, scale) {
this.gl.polygonOffset(value, scale);
}
// used
/** Resets all the logic and disables the VAOs. */
reset() {
this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, false);
this.forceState(this.defaultState);
this._blendEq = true;
this.blendMode = "";
this.setBlendMode("normal");
}
/**
* Checks to see which updates should be checked based on which settings have been activated.
*
* For example, if blend is enabled then we should check the blend modes each time the state is changed
* or if polygon fill is activated then we need to check if the polygon offset changes.
* The idea is that we only check what we have too.
* @param func - the checking function to add or remove
* @param value - should the check function be added or removed.
*/
_updateCheck(func, value) {
const index = this.checks.indexOf(func);
if (value && index === -1) {
this.checks.push(func);
} else if (!value && index !== -1) {
this.checks.splice(index, 1);
}
}
/**
* A private little wrapper function that we call to check the blend mode.
* @param system - the System to perform the state check on
* @param state - the state that the blendMode will pulled from
*/
static _checkBlendMode(system, state) {
system.setBlendMode(state.blendMode);
}
/**
* A private little wrapper function that we call to check the polygon offset.
* @param system - the System to perform the state check on
* @param state - the state that the blendMode will pulled from
*/
static _checkPolygonOffset(system, state) {
system.setPolygonOffset(1, state.polygonOffset);
}
/**
* @ignore
*/
destroy() {
this.gl = null;
this.checks.length = 0;
}
};
/** @ignore */
_GlStateSystem.extension = {
type: [
ExtensionType.WebGLSystem
],
name: "state"
};
let GlStateSystem = _GlStateSystem;
export { GlStateSystem };
//# sourceMappingURL=GlStateSystem.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
import type { BLEND_MODES } from '../../shared/state/const';
import type { GlRenderingContext } from '../context/GlRenderingContext';
/**
* Maps gl blend combinations to WebGL.
* @param gl
* @returns {object} Map of gl blend combinations to WebGL.
*/
export declare function mapWebGLBlendModesToPixi(gl: GlRenderingContext): Record<BLEND_MODES, number[]>;

View File

@@ -0,0 +1,32 @@
'use strict';
var adapter = require('../../../../environment/adapter.js');
"use strict";
function mapWebGLBlendModesToPixi(gl) {
const blendMap = {};
blendMap.normal = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
blendMap.add = [gl.ONE, gl.ONE];
blendMap.multiply = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
blendMap.screen = [gl.ONE, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
blendMap.none = [0, 0];
blendMap["normal-npm"] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
blendMap["add-npm"] = [gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE];
blendMap["screen-npm"] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
blendMap.erase = [gl.ZERO, gl.ONE_MINUS_SRC_ALPHA];
const isWebGl2 = !(gl instanceof adapter.DOMAdapter.get().getWebGLRenderingContext());
if (isWebGl2) {
blendMap.min = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, gl.MIN, gl.MIN];
blendMap.max = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, gl.MAX, gl.MAX];
} else {
const ext = gl.getExtension("EXT_blend_minmax");
if (ext) {
blendMap.min = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, ext.MIN_EXT, ext.MIN_EXT];
blendMap.max = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, ext.MAX_EXT, ext.MAX_EXT];
}
}
return blendMap;
}
exports.mapWebGLBlendModesToPixi = mapWebGLBlendModesToPixi;
//# sourceMappingURL=mapWebGLBlendModesToPixi.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mapWebGLBlendModesToPixi.js","sources":["../../../../../src/rendering/renderers/gl/state/mapWebGLBlendModesToPixi.ts"],"sourcesContent":["import { DOMAdapter } from '../../../../environment/adapter';\n\nimport type { BLEND_MODES } from '../../shared/state/const';\nimport type { GlRenderingContext } from '../context/GlRenderingContext';\n\n/**\n * Maps gl blend combinations to WebGL.\n * @param gl\n * @returns {object} Map of gl blend combinations to WebGL.\n */\nexport function mapWebGLBlendModesToPixi(gl: GlRenderingContext): Record<BLEND_MODES, number[]>\n{\n const blendMap: Partial<Record<BLEND_MODES, number[]>> = {};\n\n // TODO - premultiply alpha would be different.\n // add a boolean for that!\n blendMap.normal = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];\n blendMap.add = [gl.ONE, gl.ONE];\n blendMap.multiply = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];\n blendMap.screen = [gl.ONE, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];\n blendMap.none = [0, 0];\n\n // not-premultiplied blend modes\n blendMap['normal-npm'] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];\n blendMap['add-npm'] = [gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE];\n blendMap['screen-npm'] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];\n\n blendMap.erase = [gl.ZERO, gl.ONE_MINUS_SRC_ALPHA];\n\n const isWebGl2 = !(gl instanceof DOMAdapter.get().getWebGLRenderingContext());\n\n if (isWebGl2)\n {\n blendMap.min = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, gl.MIN, gl.MIN];\n blendMap.max = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, gl.MAX, gl.MAX];\n }\n else\n {\n const ext = gl.getExtension('EXT_blend_minmax');\n\n if (ext)\n {\n blendMap.min = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, ext.MIN_EXT, ext.MIN_EXT];\n blendMap.max = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, ext.MAX_EXT, ext.MAX_EXT];\n }\n }\n\n // TODO - implement if requested!\n // composite operations\n // array[BLEND_MODES.SRC_IN] = [gl.DST_ALPHA, gl.ZERO];\n // array[BLEND_MODES.SRC_OUT] = [gl.ONE_MINUS_DST_ALPHA, gl.ZERO];\n // array[BLEND_MODES.SRC_ATOP] = [gl.DST_ALPHA, gl.ONE_MINUS_SRC_ALPHA];\n // array[BLEND_MODES.DST_OVER] = [gl.ONE_MINUS_DST_ALPHA, gl.ONE];\n // array[BLEND_MODES.DST_IN] = [gl.ZERO, gl.SRC_ALPHA];\n // array[BLEND_MODES.DST_OUT] = [gl.ZERO, gl.ONE_MINUS_SRC_ALPHA];\n // array[BLEND_MODES.DST_ATOP] = [gl.ONE_MINUS_DST_ALPHA, gl.SRC_ALPHA];\n // array[BLEND_MODES.XOR] = [gl.ONE_MINUS_DST_ALPHA, gl.ONE_MINUS_SRC_ALPHA];\n // SUBTRACT from flash\n // array[BLEND_MODES.SUBTRACT] = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, gl.FUNC_REVERSE_SUBTRACT, gl.FUNC_ADD];\n\n return blendMap as Record<BLEND_MODES, number[]>;\n}\n"],"names":["DOMAdapter"],"mappings":";;;;;AAUO,SAAS,yBAAyB,EACzC,EAAA;AACI,EAAA,MAAM,WAAmD,EAAC,CAAA;AAI1D,EAAA,QAAA,CAAS,MAAS,GAAA,CAAC,EAAG,CAAA,GAAA,EAAK,GAAG,mBAAmB,CAAA,CAAA;AACjD,EAAA,QAAA,CAAS,GAAM,GAAA,CAAC,EAAG,CAAA,GAAA,EAAK,GAAG,GAAG,CAAA,CAAA;AAC9B,EAAS,QAAA,CAAA,QAAA,GAAW,CAAC,EAAG,CAAA,SAAA,EAAW,GAAG,mBAAqB,EAAA,EAAA,CAAG,GAAK,EAAA,EAAA,CAAG,mBAAmB,CAAA,CAAA;AACzF,EAAS,QAAA,CAAA,MAAA,GAAS,CAAC,EAAG,CAAA,GAAA,EAAK,GAAG,mBAAqB,EAAA,EAAA,CAAG,GAAK,EAAA,EAAA,CAAG,mBAAmB,CAAA,CAAA;AACjF,EAAS,QAAA,CAAA,IAAA,GAAO,CAAC,CAAA,EAAG,CAAC,CAAA,CAAA;AAGrB,EAAS,QAAA,CAAA,YAAY,CAAI,GAAA,CAAC,EAAG,CAAA,SAAA,EAAW,GAAG,mBAAqB,EAAA,EAAA,CAAG,GAAK,EAAA,EAAA,CAAG,mBAAmB,CAAA,CAAA;AAC9F,EAAS,QAAA,CAAA,SAAS,CAAI,GAAA,CAAC,EAAG,CAAA,SAAA,EAAW,GAAG,GAAK,EAAA,EAAA,CAAG,GAAK,EAAA,EAAA,CAAG,GAAG,CAAA,CAAA;AAC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CAAA;AAAA,KAC5E;AAAA,GACJ;AAeA,EAAO,OAAA,QAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1,30 @@
import { DOMAdapter } from '../../../../environment/adapter.mjs';
"use strict";
function mapWebGLBlendModesToPixi(gl) {
const blendMap = {};
blendMap.normal = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
blendMap.add = [gl.ONE, gl.ONE];
blendMap.multiply = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
blendMap.screen = [gl.ONE, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
blendMap.none = [0, 0];
blendMap["normal-npm"] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
blendMap["add-npm"] = [gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE];
blendMap["screen-npm"] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];
blendMap.erase = [gl.ZERO, gl.ONE_MINUS_SRC_ALPHA];
const isWebGl2 = !(gl instanceof DOMAdapter.get().getWebGLRenderingContext());
if (isWebGl2) {
blendMap.min = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, gl.MIN, gl.MIN];
blendMap.max = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, gl.MAX, gl.MAX];
} else {
const ext = gl.getExtension("EXT_blend_minmax");
if (ext) {
blendMap.min = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, ext.MIN_EXT, ext.MIN_EXT];
blendMap.max = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, ext.MAX_EXT, ext.MAX_EXT];
}
}
return blendMap;
}
export { mapWebGLBlendModesToPixi };
//# sourceMappingURL=mapWebGLBlendModesToPixi.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mapWebGLBlendModesToPixi.mjs","sources":["../../../../../src/rendering/renderers/gl/state/mapWebGLBlendModesToPixi.ts"],"sourcesContent":["import { DOMAdapter } from '../../../../environment/adapter';\n\nimport type { BLEND_MODES } from '../../shared/state/const';\nimport type { GlRenderingContext } from '../context/GlRenderingContext';\n\n/**\n * Maps gl blend combinations to WebGL.\n * @param gl\n * @returns {object} Map of gl blend combinations to WebGL.\n */\nexport function mapWebGLBlendModesToPixi(gl: GlRenderingContext): Record<BLEND_MODES, number[]>\n{\n const blendMap: Partial<Record<BLEND_MODES, number[]>> = {};\n\n // TODO - premultiply alpha would be different.\n // add a boolean for that!\n blendMap.normal = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA];\n blendMap.add = [gl.ONE, gl.ONE];\n blendMap.multiply = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];\n blendMap.screen = [gl.ONE, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];\n blendMap.none = [0, 0];\n\n // not-premultiplied blend modes\n blendMap['normal-npm'] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];\n blendMap['add-npm'] = [gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE];\n blendMap['screen-npm'] = [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_COLOR, gl.ONE, gl.ONE_MINUS_SRC_ALPHA];\n\n blendMap.erase = [gl.ZERO, gl.ONE_MINUS_SRC_ALPHA];\n\n const isWebGl2 = !(gl instanceof DOMAdapter.get().getWebGLRenderingContext());\n\n if (isWebGl2)\n {\n blendMap.min = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, gl.MIN, gl.MIN];\n blendMap.max = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, gl.MAX, gl.MAX];\n }\n else\n {\n const ext = gl.getExtension('EXT_blend_minmax');\n\n if (ext)\n {\n blendMap.min = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, ext.MIN_EXT, ext.MIN_EXT];\n blendMap.max = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, ext.MAX_EXT, ext.MAX_EXT];\n }\n }\n\n // TODO - implement if requested!\n // composite operations\n // array[BLEND_MODES.SRC_IN] = [gl.DST_ALPHA, gl.ZERO];\n // array[BLEND_MODES.SRC_OUT] = [gl.ONE_MINUS_DST_ALPHA, gl.ZERO];\n // array[BLEND_MODES.SRC_ATOP] = [gl.DST_ALPHA, gl.ONE_MINUS_SRC_ALPHA];\n // array[BLEND_MODES.DST_OVER] = [gl.ONE_MINUS_DST_ALPHA, gl.ONE];\n // array[BLEND_MODES.DST_IN] = [gl.ZERO, gl.SRC_ALPHA];\n // array[BLEND_MODES.DST_OUT] = [gl.ZERO, gl.ONE_MINUS_SRC_ALPHA];\n // array[BLEND_MODES.DST_ATOP] = [gl.ONE_MINUS_DST_ALPHA, gl.SRC_ALPHA];\n // array[BLEND_MODES.XOR] = [gl.ONE_MINUS_DST_ALPHA, gl.ONE_MINUS_SRC_ALPHA];\n // SUBTRACT from flash\n // array[BLEND_MODES.SUBTRACT] = [gl.ONE, gl.ONE, gl.ONE, gl.ONE, gl.FUNC_REVERSE_SUBTRACT, gl.FUNC_ADD];\n\n return blendMap as Record<BLEND_MODES, number[]>;\n}\n"],"names":[],"mappings":";;;AAUO,SAAS,yBAAyB,EACzC,EAAA;AACI,EAAA,MAAM,WAAmD,EAAC,CAAA;AAI1D,EAAA,QAAA,CAAS,MAAS,GAAA,CAAC,EAAG,CAAA,GAAA,EAAK,GAAG,mBAAmB,CAAA,CAAA;AACjD,EAAA,QAAA,CAAS,GAAM,GAAA,CAAC,EAAG,CAAA,GAAA,EAAK,GAAG,GAAG,CAAA,CAAA;AAC9B,EAAS,QAAA,CAAA,QAAA,GAAW,CAAC,EAAG,CAAA,SAAA,EAAW,GAAG,mBAAqB,EAAA,EAAA,CAAG,GAAK,EAAA,EAAA,CAAG,mBAAmB,CAAA,C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