Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@antv/g-webgpu-engine

Package Overview
Dependencies
Maintainers
62
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antv/g-webgpu-engine - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

3

es/index.js
import { WebGLEngine } from './webgl';
import { WebGPUEngine } from './webgpu';
export { WebGLEngine, WebGPUEngine };
export { WebGLEngine };
//# sourceMappingURL=index.js.map
import _isTypedArray from "lodash/isTypedArray";
import _isPlainObject from "lodash/isPlainObject";
/**

@@ -16,23 +15,29 @@ * 考虑结构体命名, eg:

}
function extractUniformsRecursively(uniformName, uniformValue, uniforms, prefix) {
if (uniformValue === null || typeof uniformValue === 'number' || // u_A: 1
typeof uniformValue === 'boolean' || // u_A: false
Array.isArray(uniformValue) && typeof uniformValue[0] === 'number' || // u_A: [1, 2, 3]
_isTypedArray(uniformValue) || // u_A: Float32Array
if (uniformValue === null || typeof uniformValue === 'number' ||
// u_A: 1
typeof uniformValue === 'boolean' ||
// u_A: false
Array.isArray(uniformValue) && typeof uniformValue[0] === 'number' ||
// u_A: [1, 2, 3]
_isTypedArray(uniformValue) ||
// u_A: Float32Array
// @ts-ignore
uniformValue === '' || 'resize' in uniformValue) {
uniformValue === '' ||
// @ts-ignore
uniformValue.resize !== undefined) {
uniforms["".concat(prefix && prefix + '.').concat(uniformName)] = uniformValue;
return;
} // u_Struct.a.b.c
}
// u_Struct.a.b.c
if (_isPlainObject(uniformValue)) {
Object.keys(uniformValue).forEach(function (childName) {
extractUniformsRecursively(childName, // @ts-ignore
extractUniformsRecursively(childName,
// @ts-ignore
uniformValue[childName], uniforms, "".concat(prefix && prefix + '.').concat(uniformName));
});
} // u_Struct[0].a
}
// u_Struct[0].a
if (Array.isArray(uniformValue)) {

@@ -42,3 +47,4 @@ // @ts-ignore

Object.keys(child).forEach(function (childName) {
extractUniformsRecursively(childName, // @ts-ignore
extractUniformsRecursively(childName,
// @ts-ignore
child[childName], uniforms, "".concat(prefix && prefix + '.').concat(uniformName, "[").concat(idx, "]"));

@@ -45,0 +51,0 @@ });

import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _primitiveMap, _usageMap, _dataTypeMap, _formatMap, _mipmapMap, _filterMap, _wrapModeMap, _colorSpaceMap, _depthFuncMap, _blendEquationMap, _blendFuncMap, _stencilFuncMap, _stencilOpMap, _cullFaceMap;
/**

@@ -6,0 +4,0 @@ * @desc 由于 regl 使用大量字符串而非 WebGL 常量,因此需要映射

@@ -1,8 +0,5 @@

import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
var _dec, _class, _temp;
import _regeneratorRuntime from "@babel/runtime/regenerator";
/**

@@ -13,3 +10,2 @@ * render w/ regl

import { gl } from '@antv/g-webgpu-core';
import { injectable } from 'inversify';
import regl from 'regl';

@@ -23,12 +19,10 @@ import ReglAttribute from './ReglAttribute';

import ReglTexture2D from './ReglTexture2D';
/**
* regl renderer
*/
export var WebGLEngine = (_dec = injectable(), _dec(_class = (_temp = /*#__PURE__*/function () {
export var WebGLEngine = /*#__PURE__*/function () {
function WebGLEngine() {
var _this = this;
_classCallCheck(this, WebGLEngine);
this.supportWebGPU = false;

@@ -39,19 +33,52 @@ this.useWGSL = false;

this.inited = void 0;
this.createModel = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
return _regeneratorRuntime.wrap(function _callee$(_context) {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(options) {
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context.prev = _context.next) {
switch (_context2.prev = _context2.next) {
case 0:
return _context.abrupt("return", new ReglModel(_this.gl, options));
case 1:
if (!options.uniforms) {
_context2.next = 3;
break;
}
_context2.next = 3;
return Promise.all(Object.keys(options.uniforms).map( /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(name) {
var texture;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!(options.uniforms[name] &&
// @ts-ignore
options.uniforms[name].load !== undefined)) {
_context.next = 5;
break;
}
_context.next = 3;
return options.uniforms[name].load();
case 3:
texture = _context.sent;
// @ts-ignore
options.uniforms[name] = texture;
case 5:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function (_x2) {
return _ref2.apply(this, arguments);
};
}()));
case 3:
return _context2.abrupt("return", new ReglModel(_this.gl, options));
case 4:
case "end":
return _context.stop();
return _context2.stop();
}
}
}, _callee);
}, _callee2);
}));
return function (_x) {

@@ -61,23 +88,17 @@ return _ref.apply(this, arguments);

}();
this.createAttribute = function (options) {
return new ReglAttribute(_this.gl, options);
};
this.createBuffer = function (options) {
return new ReglBuffer(_this.gl, options);
};
this.createElements = function (options) {
return new ReglElements(_this.gl, options);
};
this.createTexture2D = function (options) {
return new ReglTexture2D(_this.gl, options);
};
this.createFramebuffer = function (options) {
return new ReglFramebuffer(_this.gl, options);
};
this.useFramebuffer = function (framebuffer, drawCommands) {

@@ -88,31 +109,27 @@ _this.gl({

};
this.createComputeModel = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(context) {
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(context) {
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context2.prev = _context2.next) {
switch (_context3.prev = _context3.next) {
case 0:
return _context2.abrupt("return", new ReglComputeModel(_this.gl, context));
return _context3.abrupt("return", new ReglComputeModel(_this.gl, context));
case 1:
case "end":
return _context2.stop();
return _context3.stop();
}
}
}, _callee2);
}, _callee3);
}));
return function (_x2) {
return _ref2.apply(this, arguments);
return function (_x3) {
return _ref3.apply(this, arguments);
};
}();
this.clear = function (options) {
// @see https://github.com/regl-project/regl/blob/gh-pages/API.md#clear-the-draw-buffer
var color = options.color,
depth = options.depth,
stencil = options.stencil,
_options$framebuffer = options.framebuffer,
framebuffer = _options$framebuffer === void 0 ? null : _options$framebuffer;
depth = options.depth,
stencil = options.stencil,
_options$framebuffer = options.framebuffer,
framebuffer = _options$framebuffer === void 0 ? null : _options$framebuffer;
var reglClearOptions = {

@@ -124,6 +141,4 @@ color: color,

reglClearOptions.framebuffer = framebuffer === null ? framebuffer : framebuffer.get();
_this.gl.clear(reglClearOptions);
};
this.setScissor = function (scissor) {

@@ -135,3 +150,2 @@ if (_this.gl && _this.gl._gl) {

_this.gl._gl.enable(gl.SCISSOR_TEST);
_this.gl._gl.scissor(scissor.box.x, scissor.box.y, scissor.box.width, scissor.box.height);

@@ -141,13 +155,10 @@ } else {

}
_this.gl._refresh();
}
};
this.viewport = function (_ref3) {
var x = _ref3.x,
y = _ref3.y,
width = _ref3.width,
height = _ref3.height;
this.viewport = function (_ref4) {
var x = _ref4.x,
y = _ref4.y,
width = _ref4.width,
height = _ref4.height;
if (_this.gl && _this.gl._gl) {

@@ -157,13 +168,11 @@ // use WebGL context directly

_this.gl._gl.viewport(x, y, width, height);
_this.gl._refresh();
}
};
this.readPixels = function (options) {
var framebuffer = options.framebuffer,
x = options.x,
y = options.y,
width = options.width,
height = options.height;
x = options.x,
y = options.y,
width = options.width,
height = options.height;
var readPixelsOptions = {

@@ -175,18 +184,13 @@ x: x,

};
if (framebuffer) {
readPixelsOptions.framebuffer = framebuffer.get();
}
return _this.gl.read(readPixelsOptions);
};
this.getCanvas = function () {
return _this.$canvas;
};
this.getGLContext = function () {
return _this.gl._gl;
};
this.destroy = function () {

@@ -196,3 +200,2 @@ if (_this.gl) {

_this.gl.destroy();
_this.inited = false;

@@ -202,22 +205,19 @@ }

}
_createClass(WebGLEngine, [{
key: "init",
value: function () {
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(cfg) {
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(cfg) {
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context3.prev = _context3.next) {
switch (_context4.prev = _context4.next) {
case 0:
if (!this.inited) {
_context3.next = 2;
_context4.next = 2;
break;
}
return _context3.abrupt("return");
return _context4.abrupt("return");
case 2:
this.$canvas = cfg.canvas; // tslint:disable-next-line:typedef
_context3.next = 5;
this.$canvas = cfg.canvas;
// tslint:disable-next-line:typedef
_context4.next = 5;
return new Promise(function (resolve, reject) {

@@ -231,10 +231,13 @@ regl({

antialias: cfg.antialias,
premultipliedAlpha: true // preserveDrawingBuffer: false,
premultipliedAlpha: true
// preserveDrawingBuffer: false,
},
},
pixelRatio: 1,
// TODO: use extensions
extensions: ['OES_element_index_uint', 'OES_texture_float', 'OES_standard_derivatives', // wireframe
extensions: ['OES_element_index_uint', 'OES_texture_float', 'OES_standard_derivatives',
// wireframe
'angle_instanced_arrays' // VSM shadow map
],
optionalExtensions: ['EXT_texture_filter_anisotropic', 'EXT_blend_minmax', 'WEBGL_depth_texture'],

@@ -245,5 +248,4 @@ profile: true,

reject(err);
} // @ts-ignore
}
// @ts-ignore
resolve(r);

@@ -253,19 +255,15 @@ }

});
case 5:
this.gl = _context3.sent;
this.gl = _context4.sent;
this.inited = true;
case 7:
case "end":
return _context3.stop();
return _context4.stop();
}
}
}, _callee3, this);
}, _callee4, this);
}));
function init(_x3) {
function init(_x4) {
return _init.apply(this, arguments);
}
return init;

@@ -282,12 +280,13 @@ }()

key: "beginFrame",
value: function beginFrame() {//
value: function beginFrame() {
//
}
}, {
key: "endFrame",
value: function endFrame() {//
value: function endFrame() {
//
}
}]);
return WebGLEngine;
}(), _temp)) || _class);
}();
//# sourceMappingURL=index.js.map
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
/**

@@ -10,11 +9,10 @@ * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#attributes

_classCallCheck(this, ReglAttribute);
this.attribute = void 0;
this.buffer = void 0;
var buffer = options.buffer,
offset = options.offset,
stride = options.stride,
normalized = options.normalized,
size = options.size,
divisor = options.divisor;
offset = options.offset,
stride = options.stride,
normalized = options.normalized,
size = options.size,
divisor = options.divisor;
this.buffer = buffer;

@@ -28,3 +26,2 @@ this.attribute = {

};
if (size) {

@@ -34,3 +31,2 @@ this.attribute.size = size;

}
_createClass(ReglAttribute, [{

@@ -52,7 +48,5 @@ key: "get",

}]);
return ReglAttribute;
}();
export { ReglAttribute as default };
//# sourceMappingURL=ReglAttribute.js.map

@@ -5,2 +5,3 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";

import { dataTypeMap, usageMap } from './constants';
/**

@@ -10,20 +11,17 @@ * adaptor for regl.Buffer

*/
var ReglBuffer = /*#__PURE__*/function () {
function ReglBuffer(reGl, options) {
_classCallCheck(this, ReglBuffer);
this.buffer = void 0;
var data = options.data,
usage = options.usage,
type = options.type; // @ts-ignore
usage = options.usage,
type = options.type;
// @ts-ignore
this.buffer = reGl.buffer({
data: data,
usage: usageMap[usage || gl.STATIC_DRAW],
type: dataTypeMap[type || gl.UNSIGNED_BYTE] // length: 0,
type: dataTypeMap[type || gl.UNSIGNED_BYTE]
// length: 0,
});
}
_createClass(ReglBuffer, [{

@@ -37,3 +35,3 @@ key: "get",

value: function destroy() {
this.buffer.destroy();
// this.buffer.destroy();
}

@@ -44,3 +42,3 @@ }, {

var data = _ref.data,
offset = _ref.offset;
offset = _ref.offset;
// @ts-ignore

@@ -50,7 +48,5 @@ this.buffer.subdata(data, offset);

}]);
return ReglBuffer;
}();
export { ReglBuffer as default };
//# sourceMappingURL=ReglBuffer.js.map
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";

@@ -8,9 +7,6 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";

import _isTypedArray from "lodash/isTypedArray";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { AST_TOKEN_TYPES, createEntity, STORAGE_CLASS } from '@antv/g-webgpu-core';
/* babel-plugin-inline-import './shaders/quad.vert.glsl' */

@@ -20,12 +16,10 @@ var quadVert = "attribute vec3 a_Position;\nattribute vec2 a_TexCoord;\n\nvarying vec2 v_TexCoord;\n\nvoid main() {\n gl_Position = vec4(a_Position, 1.0);\n v_TexCoord = a_TexCoord;\n}";

var debug = false;
/**
* adaptor for regl.DrawCommand
*/
var ReglComputeModel = /*#__PURE__*/function () {
function ReglComputeModel(reGl, context) {
var _this = this;
_classCallCheck(this, ReglComputeModel);
this.reGl = reGl;

@@ -44,7 +38,7 @@ this.context = context;

var name = uniform.name,
type = uniform.type,
data = uniform.data,
isReferer = uniform.isReferer,
storageClass = uniform.storageClass; // store data with a 2D texture
type = uniform.type,
data = uniform.data,
isReferer = uniform.isReferer,
storageClass = uniform.storageClass;
// store data with a 2D texture
if (storageClass === STORAGE_CLASS.StorageBuffer) {

@@ -54,9 +48,7 @@ if (!isReferer) {

var _this$textureCache$na = _this.textureCache[name],
width = _this$textureCache$na.textureWidth,
isOutput = _this$textureCache$na.isOutput;
width = _this$textureCache$na.textureWidth,
isOutput = _this$textureCache$na.isOutput;
uniforms["".concat(name, "Size")] = [width, width];
if (isOutput) {
_this.outputTextureName = name;
if (_this.context.needPingpong) {

@@ -68,9 +60,11 @@ _this.outputTextureName = "".concat(name, "Output");

} else {
// @ts-ignore
_this.textureCache[name] = {
data: undefined
}; // refer to another kernel's output,
};
// refer to another kernel's output,
// the referred kernel may not have been initialized, so we use dynamic way here
uniforms["".concat(name, "Size")] = function () {
return (// @ts-ignore
return (
// @ts-ignore
data.compiledBundle.context.output.textureSize

@@ -80,3 +74,2 @@ );

}
uniforms[name] = function () {

@@ -86,3 +79,2 @@ if (debug) {

}
return _this.textureCache[name].texture;

@@ -94,5 +86,4 @@ };

throw new Error("invalid data type ".concat(type));
} // get uniform dynamically
}
// get uniform dynamically
uniforms[name] = function () {

@@ -103,11 +94,11 @@ return uniform.data;

});
var _this$getOuputDataTex = this.getOuputDataTexture(),
textureWidth = _this$getOuputDataTex.textureWidth,
texelCount = _this$getOuputDataTex.texelCount; // 传入 output 纹理尺寸和数据长度,便于多余的 texel 提前退出
textureWidth = _this$getOuputDataTex.textureWidth,
texelCount = _this$getOuputDataTex.texelCount;
// 传入 output 纹理尺寸和数据长度,便于多余的 texel 提前退出
uniforms.u_OutputTextureSize = [textureWidth, textureWidth];
uniforms.u_OutputTexelCount = texelCount; // 保存在 Kernel 的上下文中,供其他 Kernel 引用
uniforms.u_OutputTexelCount = texelCount;
// 保存在 Kernel 的上下文中,供其他 Kernel 引用
this.context.output.textureSize = [textureWidth, textureWidth];

@@ -128,3 +119,2 @@ var drawParams = {

}
_createClass(ReglComputeModel, [{

@@ -134,8 +124,9 @@ key: "run",

var _this2 = this;
if (this.context.maxIteration > 1 && this.context.needPingpong) {
this.compiledPingpong = true;
} // need pingpong when (@in@out and execute(10)) or use `setBinding('out', self)`
}
// need pingpong when (@in@out and execute(10)) or use `setBinding('out', self)`
// this.needPingpong =
// !!(this.context.maxIteration > 1 && this.context.needPingpong);
// if (this.relativeOutputTextureNames.length) {

@@ -150,7 +141,5 @@ // const { id, texture } = this.getOuputDataTexture();

if (this.compiledPingpong || this.dynamicPingpong) {
this.swap();
}
this.texFBO = this.reGl.framebuffer({

@@ -162,3 +151,2 @@ color: this.getOuputDataTexture().texture

});
if (debug) {

@@ -173,5 +161,3 @@ console.log("[".concat(this.entity, "]: output ").concat(this.getOuputDataTexture().id));

var _this3 = this;
var pixels, _this$getOuputDataTex2, originalDataLength, elementsPerTexel, _this$getOuputDataTex3, typedArrayConstructor, formattedPixels, i;
return _regeneratorRuntime.wrap(function _callee$(_context) {

@@ -185,4 +171,5 @@ while (1) {

pixels = _this3.reGl.read();
}); // @ts-ignore
});
// @ts-ignore
if (!pixels) {

@@ -192,6 +179,4 @@ _context.next = 6;

}
_this$getOuputDataTex2 = this.getOuputDataTexture(), originalDataLength = _this$getOuputDataTex2.originalDataLength, elementsPerTexel = _this$getOuputDataTex2.elementsPerTexel, _this$getOuputDataTex3 = _this$getOuputDataTex2.typedArrayConstructor, typedArrayConstructor = _this$getOuputDataTex3 === void 0 ? Float32Array : _this$getOuputDataTex3;
formattedPixels = [];
if (elementsPerTexel !== 4) {

@@ -210,11 +195,9 @@ for (i = 0; i < pixels.length; i += 4) {

formattedPixels = pixels;
} // 截取多余的部分
}
// 截取多余的部分
// @ts-ignore
return _context.abrupt("return", new typedArrayConstructor(formattedPixels.slice(0, originalDataLength)));
case 6:
return _context.abrupt("return", new Float32Array());
case 7:

@@ -227,7 +210,5 @@ case "end":

}));
function readData() {
return _readData.apply(this, arguments);
}
return readData;

@@ -238,4 +219,4 @@ }()

value: function confirmInput(model, inputName) {
var inputModel; // refer to self, same as pingpong
var inputModel;
// refer to self, same as pingpong
if (this.entity === model.entity) {

@@ -247,6 +228,4 @@ this.dynamicPingpong = true;

}
this.textureCache[inputName].id = inputModel.getOuputDataTexture().id;
this.textureCache[inputName].texture = inputModel.getOuputDataTexture().texture;
if (debug) {

@@ -258,3 +237,4 @@ console.log("[".concat(this.entity, "]: confirm input ").concat(inputName, " from model ").concat(inputModel.entity, ", ").concat(inputModel.getOuputDataTexture().id));

key: "updateUniform",
value: function updateUniform() {// already get uniform's data dynamically when created, do nothing here
value: function updateUniform() {
// already get uniform's data dynamically when created, do nothing here
}

@@ -270,9 +250,8 @@ }, {

});
if (buffer) {
var _this$calcDataTexture = this.calcDataTexture(bufferName, buffer.type, data),
texture = _this$calcDataTexture.texture,
paddingData = _this$calcDataTexture.data; // TODO: destroy outdated texture
texture = _this$calcDataTexture.texture,
paddingData = _this$calcDataTexture.data;
// TODO: destroy outdated texture
this.textureCache[bufferName].data = paddingData;

@@ -284,3 +263,4 @@ this.textureCache[bufferName].texture = texture;

key: "destroy",
value: function destroy() {// regl will destroy all resources
value: function destroy() {
// regl will destroy all resources
}

@@ -293,3 +273,2 @@ }, {

}
if (this.compiledPingpong) {

@@ -300,7 +279,5 @@ var outputTextureUniformName = this.context.output.name;

}
var tmp = this.outputTextureName;
this.outputTextureName = this.swapOutputTextureName;
this.swapOutputTextureName = tmp;
if (debug) {

@@ -326,3 +303,3 @@ console.log("[".concat(this.entity, "]: after swap, output ").concat(this.getOuputDataTexture().id));

var data = texture.data,
textureWidth = texture.textureWidth;
textureWidth = texture.textureWidth;
return _objectSpread(_objectSpread({}, texture), {}, {

@@ -343,10 +320,8 @@ id: textureId++,

var elementsPerTexel = 1;
if (type === AST_TOKEN_TYPES.Vector4FloatArray) {
elementsPerTexel = 4;
} // 用 0 补全不足 vec4 的部分
}
// 用 0 补全不足 vec4 的部分
var paddingData = [];
for (var i = 0; i < data.length; i += elementsPerTexel) {

@@ -362,5 +337,5 @@ if (elementsPerTexel === 1) {

}
} // 使用纹理存储,例如 Array(8) 使用 3 * 3 纹理,末尾空白使用 0 填充
}
// 使用纹理存储,例如 Array(8) 使用 3 * 3 纹理,末尾空白使用 0 填充
var originalDataLength = data.length;

@@ -370,7 +345,5 @@ var texelCount = Math.ceil(originalDataLength / elementsPerTexel);

var paddingTexelCount = width * width;
if (texelCount < paddingTexelCount) {
paddingData.push.apply(paddingData, _toConsumableArray(new Array((paddingTexelCount - texelCount) * 4).fill(0)));
}
var texture = this.reGl.texture({

@@ -395,7 +368,5 @@ width: width,

}]);
return ReglComputeModel;
}();
export { ReglComputeModel as default };
//# sourceMappingURL=ReglComputeModel.js.map

@@ -5,15 +5,14 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";

import { dataTypeMap, usageMap } from './constants';
/**
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#elements
*/
var ReglElements = /*#__PURE__*/function () {
function ReglElements(reGl, options) {
_classCallCheck(this, ReglElements);
this.elements = void 0;
var data = options.data,
usage = options.usage,
type = options.type,
count = options.count;
usage = options.usage,
type = options.type,
count = options.count;
this.elements = reGl.elements({

@@ -26,3 +25,2 @@ data: data,

}
_createClass(ReglElements, [{

@@ -45,7 +43,5 @@ key: "get",

}]);
return ReglElements;
}();
export { ReglElements as default };
//# sourceMappingURL=ReglElements.js.map
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
/**

@@ -11,10 +10,9 @@ * adaptor for regl.Framebuffer

_classCallCheck(this, ReglFramebuffer);
this.framebuffer = void 0;
var width = options.width,
height = options.height,
color = options.color,
colors = options.colors,
depth = options.depth,
stencil = options.stencil;
height = options.height,
color = options.color,
colors = options.colors,
depth = options.depth,
stencil = options.stencil;
var framebufferOptions = {

@@ -24,3 +22,2 @@ width: width,

};
if (Array.isArray(colors)) {

@@ -31,11 +28,10 @@ framebufferOptions.colors = colors.map(function (c) {

}
if (color && typeof color !== 'boolean') {
framebufferOptions.color = color.get();
} // TODO: depth & stencil
}
// TODO: depth & stencil
this.framebuffer = reGl.framebuffer(framebufferOptions);
}
_createClass(ReglFramebuffer, [{

@@ -55,11 +51,9 @@ key: "get",

var width = _ref.width,
height = _ref.height;
height = _ref.height;
this.framebuffer.resize(width, height);
}
}]);
return ReglFramebuffer;
}();
export { ReglFramebuffer as default };
//# sourceMappingURL=ReglFramebuffer.js.map

@@ -5,11 +5,7 @@ import _typeof from "@babel/runtime/helpers/typeof";

import _createClass from "@babel/runtime/helpers/createClass";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
import { gl } from '@antv/g-webgpu-core';
import { extractUniforms } from '../utils/uniform';
import { blendEquationMap, blendFuncMap, cullFaceMap, depthFuncMap, primitiveMap, stencilFuncMap, stencilOpMap } from './constants';
/**

@@ -21,3 +17,2 @@ * adaptor for regl.DrawCommand

_classCallCheck(this, ReglModel);
this.reGl = void 0;

@@ -28,17 +23,17 @@ this.drawCommand = void 0;

var vs = options.vs,
fs = options.fs,
attributes = options.attributes,
uniforms = options.uniforms,
primitive = options.primitive,
count = options.count,
elements = options.elements,
depth = options.depth,
blend = options.blend,
stencil = options.stencil,
cull = options.cull,
instances = options.instances,
scissor = options.scissor,
viewport = options.viewport;
fs = options.fs,
defines = options.defines,
attributes = options.attributes,
uniforms = options.uniforms,
primitive = options.primitive,
count = options.count,
elements = options.elements,
depth = options.depth,
blend = options.blend,
stencil = options.stencil,
cull = options.cull,
instances = options.instances,
scissor = options.scissor,
viewport = options.viewport;
var reglUniforms = {};
if (uniforms) {

@@ -52,3 +47,2 @@ this.uniforms = extractUniforms(uniforms);

}
var reglAttributes = {};

@@ -58,31 +52,27 @@ Object.keys(attributes).forEach(function (name) {

});
var defineStmts = defines && this.generateDefines(defines) || '';
var drawParams = {
attributes: reglAttributes,
frag: "#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n".concat(fs),
frag: "#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n".concat(defineStmts, "\n").concat(fs),
uniforms: reglUniforms,
vert: vs,
vert: "\n".concat(defineStmts, "\n").concat(vs),
primitive: primitiveMap[primitive === undefined ? gl.TRIANGLES : primitive]
};
if (instances) {
drawParams.instances = instances;
} // elements 中可能包含 count,此时不应传入
}
// elements 中可能包含 count,此时不应传入
if (count) {
drawParams.count = count;
}
if (elements) {
drawParams.elements = elements.get();
}
if (scissor) {
drawParams.scissor = scissor;
}
if (viewport) {
drawParams.viewport = viewport;
}
this.initDepthDrawParams({

@@ -102,3 +92,2 @@ depth: depth

}
_createClass(ReglModel, [{

@@ -113,10 +102,11 @@ key: "addUniforms",

var uniforms = _objectSpread(_objectSpread({}, this.uniforms), extractUniforms(options.uniforms || {}));
var reglDrawProps = {};
Object.keys(uniforms).forEach(function (uniformName) {
var type = _typeof(uniforms[uniformName]);
if (type === 'boolean' || type === 'number' || Array.isArray(uniforms[uniformName]) || // @ts-ignore
if (type === 'boolean' || type === 'number' || Array.isArray(uniforms[uniformName]) ||
// @ts-ignore
uniforms[uniformName].BYTES_PER_ELEMENT) {
reglDrawProps[uniformName] = uniforms[uniformName];
} else if (type === 'string') {
// TODO: image url
} else {

@@ -130,8 +120,9 @@ reglDrawProps[uniformName] = uniforms[uniformName].get();

key: "destroy",
value: function destroy() {// don't need do anything since we will call `rendererService.cleanup()`
value: function destroy() {
// don't need do anything since we will call `rendererService.cleanup()`
}
/**
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#depth-buffer
*/
}, {

@@ -141,3 +132,2 @@ key: "initDepthDrawParams",

var depth = _ref.depth;
if (depth) {

@@ -152,6 +142,6 @@ drawParams.depth = {

}
/**
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#blending
*/
}, {

@@ -161,10 +151,9 @@ key: "initBlendDrawParams",

var blend = _ref2.blend;
if (blend) {
var enable = blend.enable,
func = blend.func,
equation = blend.equation,
_blend$color = blend.color,
color = _blend$color === void 0 ? [0, 0, 0, 0] : _blend$color; // @ts-ignore
func = blend.func,
equation = blend.equation,
_blend$color = blend.color,
color = _blend$color === void 0 ? [0, 0, 0, 0] : _blend$color;
// @ts-ignore
drawParams.blend = {

@@ -186,6 +175,6 @@ enable: !!enable,

}
/**
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#stencil
*/
}, {

@@ -195,25 +184,24 @@ key: "initStencilDrawParams",

var stencil = _ref3.stencil;
if (stencil) {
var enable = stencil.enable,
_stencil$mask = stencil.mask,
mask = _stencil$mask === void 0 ? -1 : _stencil$mask,
_stencil$func = stencil.func,
func = _stencil$func === void 0 ? {
cmp: gl.ALWAYS,
ref: 0,
mask: -1
} : _stencil$func,
_stencil$opFront = stencil.opFront,
opFront = _stencil$opFront === void 0 ? {
fail: gl.KEEP,
zfail: gl.KEEP,
zpass: gl.KEEP
} : _stencil$opFront,
_stencil$opBack = stencil.opBack,
opBack = _stencil$opBack === void 0 ? {
fail: gl.KEEP,
zfail: gl.KEEP,
zpass: gl.KEEP
} : _stencil$opBack;
_stencil$mask = stencil.mask,
mask = _stencil$mask === void 0 ? -1 : _stencil$mask,
_stencil$func = stencil.func,
func = _stencil$func === void 0 ? {
cmp: gl.ALWAYS,
ref: 0,
mask: -1
} : _stencil$func,
_stencil$opFront = stencil.opFront,
opFront = _stencil$opFront === void 0 ? {
fail: gl.KEEP,
zfail: gl.KEEP,
zpass: gl.KEEP
} : _stencil$opFront,
_stencil$opBack = stencil.opBack,
opBack = _stencil$opBack === void 0 ? {
fail: gl.KEEP,
zfail: gl.KEEP,
zpass: gl.KEEP
} : _stencil$opBack;
drawParams.stencil = {

@@ -238,6 +226,6 @@ enable: !!enable,

}
/**
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#culling
*/
}, {

@@ -247,7 +235,6 @@ key: "initCullDrawParams",

var cull = _ref4.cull;
if (cull) {
var enable = cull.enable,
_cull$face = cull.face,
face = _cull$face === void 0 ? gl.BACK : _cull$face;
_cull$face = cull.face,
face = _cull$face === void 0 ? gl.BACK : _cull$face;
drawParams.cull = {

@@ -259,8 +246,13 @@ enable: !!enable,

}
}, {
key: "generateDefines",
value: function generateDefines(defines) {
return Object.keys(defines).map(function (name) {
return "#define ".concat(name, " ").concat(Number(defines[name]));
}).join('\n');
}
}]);
return ReglModel;
}();
export { ReglModel as default };
//# sourceMappingURL=ReglModel.js.map
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import { formatMap } from './constants';
/**

@@ -8,11 +9,9 @@ * adaptor for regl.Renderbuffer

*/
var ReglRenderbuffer = /*#__PURE__*/function () {
function ReglRenderbuffer(reGl, options) {
_classCallCheck(this, ReglRenderbuffer);
this.renderbuffer = void 0;
var width = options.width,
height = options.height,
format = options.format;
height = options.height,
format = options.format;
this.renderbuffer = reGl.renderbuffer({

@@ -24,3 +23,2 @@ width: width,

}
_createClass(ReglRenderbuffer, [{

@@ -40,11 +38,9 @@ key: "get",

var width = _ref.width,
height = _ref.height;
height = _ref.height;
this.renderbuffer.resize(width, height);
}
}]);
return ReglRenderbuffer;
}();
export { ReglRenderbuffer as default };
//# sourceMappingURL=ReglRenderbuffer.js.map

@@ -5,2 +5,3 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";

import { colorSpaceMap, dataTypeMap, filterMap, formatMap, mipmapMap, wrapModeMap } from './constants';
/**

@@ -10,7 +11,5 @@ * adaptor for regl.Buffer

*/
var ReglTexture2D = /*#__PURE__*/function () {
function ReglTexture2D(reGl, options) {
_classCallCheck(this, ReglTexture2D);
this.texture = void 0;

@@ -20,28 +19,28 @@ this.width = void 0;

var data = options.data,
_options$type = options.type,
type = _options$type === void 0 ? gl.UNSIGNED_BYTE : _options$type,
width = options.width,
height = options.height,
_options$flipY = options.flipY,
flipY = _options$flipY === void 0 ? false : _options$flipY,
_options$format = options.format,
format = _options$format === void 0 ? gl.RGBA : _options$format,
_options$mipmap = options.mipmap,
mipmap = _options$mipmap === void 0 ? false : _options$mipmap,
_options$wrapS = options.wrapS,
wrapS = _options$wrapS === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapS,
_options$wrapT = options.wrapT,
wrapT = _options$wrapT === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapT,
_options$aniso = options.aniso,
aniso = _options$aniso === void 0 ? 0 : _options$aniso,
_options$alignment = options.alignment,
alignment = _options$alignment === void 0 ? 1 : _options$alignment,
_options$premultiplyA = options.premultiplyAlpha,
premultiplyAlpha = _options$premultiplyA === void 0 ? false : _options$premultiplyA,
_options$mag = options.mag,
mag = _options$mag === void 0 ? gl.NEAREST : _options$mag,
_options$min = options.min,
min = _options$min === void 0 ? gl.NEAREST : _options$min,
_options$colorSpace = options.colorSpace,
colorSpace = _options$colorSpace === void 0 ? gl.BROWSER_DEFAULT_WEBGL : _options$colorSpace;
_options$type = options.type,
type = _options$type === void 0 ? gl.UNSIGNED_BYTE : _options$type,
width = options.width,
height = options.height,
_options$flipY = options.flipY,
flipY = _options$flipY === void 0 ? false : _options$flipY,
_options$format = options.format,
format = _options$format === void 0 ? gl.RGBA : _options$format,
_options$mipmap = options.mipmap,
mipmap = _options$mipmap === void 0 ? false : _options$mipmap,
_options$wrapS = options.wrapS,
wrapS = _options$wrapS === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapS,
_options$wrapT = options.wrapT,
wrapT = _options$wrapT === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapT,
_options$aniso = options.aniso,
aniso = _options$aniso === void 0 ? 0 : _options$aniso,
_options$alignment = options.alignment,
alignment = _options$alignment === void 0 ? 1 : _options$alignment,
_options$premultiplyA = options.premultiplyAlpha,
premultiplyAlpha = _options$premultiplyA === void 0 ? false : _options$premultiplyA,
_options$mag = options.mag,
mag = _options$mag === void 0 ? gl.NEAREST : _options$mag,
_options$min = options.min,
min = _options$min === void 0 ? gl.NEAREST : _options$min,
_options$colorSpace = options.colorSpace,
colorSpace = _options$colorSpace === void 0 ? gl.BROWSER_DEFAULT_WEBGL : _options$colorSpace;
this.width = width;

@@ -66,7 +65,5 @@ this.height = height;

};
if (data) {
textureOptions.data = data;
}
if (typeof mipmap === 'number') {

@@ -77,6 +74,4 @@ textureOptions.mipmap = mipmapMap[mipmap];

}
this.texture = reGl.texture(textureOptions);
}
_createClass(ReglTexture2D, [{

@@ -97,3 +92,3 @@ key: "get",

var width = _ref.width,
height = _ref.height;
height = _ref.height;
this.texture.resize(width, height);

@@ -109,7 +104,5 @@ this.width = width;

}]);
return ReglTexture2D;
}();
export { ReglTexture2D as default };
//# sourceMappingURL=ReglTexture2D.js.map

@@ -12,12 +12,3 @@ "use strict";

});
Object.defineProperty(exports, "WebGPUEngine", {
enumerable: true,
get: function get() {
return _webgpu.WebGPUEngine;
}
});
var _webgl = require("./webgl");
var _webgpu = require("./webgpu");
//# sourceMappingURL=index.js.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,7 +8,4 @@ value: true

exports.extractUniforms = extractUniforms;
var _isTypedArray2 = _interopRequireDefault(require("lodash/isTypedArray"));
var _isPlainObject2 = _interopRequireDefault(require("lodash/isPlainObject"));
/**

@@ -27,23 +23,29 @@ * 考虑结构体命名, eg:

}
function extractUniformsRecursively(uniformName, uniformValue, uniforms, prefix) {
if (uniformValue === null || typeof uniformValue === 'number' || // u_A: 1
typeof uniformValue === 'boolean' || // u_A: false
Array.isArray(uniformValue) && typeof uniformValue[0] === 'number' || // u_A: [1, 2, 3]
(0, _isTypedArray2.default)(uniformValue) || // u_A: Float32Array
if (uniformValue === null || typeof uniformValue === 'number' ||
// u_A: 1
typeof uniformValue === 'boolean' ||
// u_A: false
Array.isArray(uniformValue) && typeof uniformValue[0] === 'number' ||
// u_A: [1, 2, 3]
(0, _isTypedArray2.default)(uniformValue) ||
// u_A: Float32Array
// @ts-ignore
uniformValue === '' || 'resize' in uniformValue) {
uniformValue === '' ||
// @ts-ignore
uniformValue.resize !== undefined) {
uniforms["".concat(prefix && prefix + '.').concat(uniformName)] = uniformValue;
return;
} // u_Struct.a.b.c
}
// u_Struct.a.b.c
if ((0, _isPlainObject2.default)(uniformValue)) {
Object.keys(uniformValue).forEach(function (childName) {
extractUniformsRecursively(childName, // @ts-ignore
extractUniformsRecursively(childName,
// @ts-ignore
uniformValue[childName], uniforms, "".concat(prefix && prefix + '.').concat(uniformName));
});
} // u_Struct[0].a
}
// u_Struct[0].a
if (Array.isArray(uniformValue)) {

@@ -53,3 +55,4 @@ // @ts-ignore

Object.keys(child).forEach(function (childName) {
extractUniformsRecursively(childName, // @ts-ignore
extractUniformsRecursively(childName,
// @ts-ignore
child[childName], uniforms, "".concat(prefix && prefix + '.').concat(uniformName, "[").concat(idx, "]"));

@@ -56,0 +59,0 @@ });

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.cullFaceMap = exports.stencilOpMap = exports.stencilFuncMap = exports.blendFuncMap = exports.blendEquationMap = exports.depthFuncMap = exports.colorSpaceMap = exports.wrapModeMap = exports.filterMap = exports.mipmapMap = exports.formatMap = exports.dataTypeMap = exports.usageMap = exports.primitiveMap = void 0;
exports.wrapModeMap = exports.usageMap = exports.stencilOpMap = exports.stencilFuncMap = exports.primitiveMap = exports.mipmapMap = exports.formatMap = exports.filterMap = exports.depthFuncMap = exports.dataTypeMap = exports.cullFaceMap = exports.colorSpaceMap = exports.blendFuncMap = exports.blendEquationMap = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _gWebgpuCore = require("@antv/g-webgpu-core");
var _primitiveMap, _usageMap, _dataTypeMap, _formatMap, _mipmapMap, _filterMap, _wrapModeMap, _colorSpaceMap, _depthFuncMap, _blendEquationMap, _blendFuncMap, _stencilFuncMap, _stencilOpMap, _cullFaceMap;
// @see https://github.com/regl-project/regl/blob/gh-pages/lib/constants/primitives.json

@@ -17,0 +12,0 @@ var primitiveMap = (_primitiveMap = {}, (0, _defineProperty2.default)(_primitiveMap, _gWebgpuCore.gl.POINTS, 'points'), (0, _defineProperty2.default)(_primitiveMap, _gWebgpuCore.gl.LINES, 'lines'), (0, _defineProperty2.default)(_primitiveMap, _gWebgpuCore.gl.LINE_LOOP, 'line loop'), (0, _defineProperty2.default)(_primitiveMap, _gWebgpuCore.gl.LINE_STRIP, 'line strip'), (0, _defineProperty2.default)(_primitiveMap, _gWebgpuCore.gl.TRIANGLES, 'triangles'), (0, _defineProperty2.default)(_primitiveMap, _gWebgpuCore.gl.TRIANGLE_FAN, 'triangle fan'), (0, _defineProperty2.default)(_primitiveMap, _gWebgpuCore.gl.TRIANGLE_STRIP, 'triangle strip'), _primitiveMap);

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,40 +8,25 @@ value: true

exports.WebGLEngine = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _gWebgpuCore = require("@antv/g-webgpu-core");
var _inversify = require("inversify");
var _regl = _interopRequireDefault(require("regl"));
var _ReglAttribute = _interopRequireDefault(require("./ReglAttribute"));
var _ReglBuffer = _interopRequireDefault(require("./ReglBuffer"));
var _ReglComputeModel = _interopRequireDefault(require("./ReglComputeModel"));
var _ReglElements = _interopRequireDefault(require("./ReglElements"));
var _ReglFramebuffer = _interopRequireDefault(require("./ReglFramebuffer"));
var _ReglModel = _interopRequireDefault(require("./ReglModel"));
var _ReglTexture2D = _interopRequireDefault(require("./ReglTexture2D"));
var _dec, _class, _temp;
/**
* render w/ regl
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md
*/
/**
* regl renderer
*/
var WebGLEngine = (_dec = (0, _inversify.injectable)(), _dec(_class = (_temp = /*#__PURE__*/function () {
var WebGLEngine = /*#__PURE__*/function () {
function WebGLEngine() {
var _this = this;
(0, _classCallCheck2.default)(this, WebGLEngine);

@@ -54,19 +38,52 @@ this.supportWebGPU = false;

this.inited = void 0;
this.createModel = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(options) {
return _regenerator.default.wrap(function _callee$(_context) {
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(options) {
return _regenerator.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context.prev = _context.next) {
switch (_context2.prev = _context2.next) {
case 0:
return _context.abrupt("return", new _ReglModel.default(_this.gl, options));
case 1:
if (!options.uniforms) {
_context2.next = 3;
break;
}
_context2.next = 3;
return Promise.all(Object.keys(options.uniforms).map( /*#__PURE__*/function () {
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(name) {
var texture;
return _regenerator.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!(options.uniforms[name] &&
// @ts-ignore
options.uniforms[name].load !== undefined)) {
_context.next = 5;
break;
}
_context.next = 3;
return options.uniforms[name].load();
case 3:
texture = _context.sent;
// @ts-ignore
options.uniforms[name] = texture;
case 5:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function (_x2) {
return _ref2.apply(this, arguments);
};
}()));
case 3:
return _context2.abrupt("return", new _ReglModel.default(_this.gl, options));
case 4:
case "end":
return _context.stop();
return _context2.stop();
}
}
}, _callee);
}, _callee2);
}));
return function (_x) {

@@ -76,23 +93,17 @@ return _ref.apply(this, arguments);

}();
this.createAttribute = function (options) {
return new _ReglAttribute.default(_this.gl, options);
};
this.createBuffer = function (options) {
return new _ReglBuffer.default(_this.gl, options);
};
this.createElements = function (options) {
return new _ReglElements.default(_this.gl, options);
};
this.createTexture2D = function (options) {
return new _ReglTexture2D.default(_this.gl, options);
};
this.createFramebuffer = function (options) {
return new _ReglFramebuffer.default(_this.gl, options);
};
this.useFramebuffer = function (framebuffer, drawCommands) {

@@ -103,31 +114,27 @@ _this.gl({

};
this.createComputeModel = /*#__PURE__*/function () {
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(context) {
return _regenerator.default.wrap(function _callee2$(_context2) {
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(context) {
return _regenerator.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context2.prev = _context2.next) {
switch (_context3.prev = _context3.next) {
case 0:
return _context2.abrupt("return", new _ReglComputeModel.default(_this.gl, context));
return _context3.abrupt("return", new _ReglComputeModel.default(_this.gl, context));
case 1:
case "end":
return _context2.stop();
return _context3.stop();
}
}
}, _callee2);
}, _callee3);
}));
return function (_x2) {
return _ref2.apply(this, arguments);
return function (_x3) {
return _ref3.apply(this, arguments);
};
}();
this.clear = function (options) {
// @see https://github.com/regl-project/regl/blob/gh-pages/API.md#clear-the-draw-buffer
var color = options.color,
depth = options.depth,
stencil = options.stencil,
_options$framebuffer = options.framebuffer,
framebuffer = _options$framebuffer === void 0 ? null : _options$framebuffer;
depth = options.depth,
stencil = options.stencil,
_options$framebuffer = options.framebuffer,
framebuffer = _options$framebuffer === void 0 ? null : _options$framebuffer;
var reglClearOptions = {

@@ -139,6 +146,4 @@ color: color,

reglClearOptions.framebuffer = framebuffer === null ? framebuffer : framebuffer.get();
_this.gl.clear(reglClearOptions);
};
this.setScissor = function (scissor) {

@@ -150,3 +155,2 @@ if (_this.gl && _this.gl._gl) {

_this.gl._gl.enable(_gWebgpuCore.gl.SCISSOR_TEST);
_this.gl._gl.scissor(scissor.box.x, scissor.box.y, scissor.box.width, scissor.box.height);

@@ -156,13 +160,10 @@ } else {

}
_this.gl._refresh();
}
};
this.viewport = function (_ref3) {
var x = _ref3.x,
y = _ref3.y,
width = _ref3.width,
height = _ref3.height;
this.viewport = function (_ref4) {
var x = _ref4.x,
y = _ref4.y,
width = _ref4.width,
height = _ref4.height;
if (_this.gl && _this.gl._gl) {

@@ -172,13 +173,11 @@ // use WebGL context directly

_this.gl._gl.viewport(x, y, width, height);
_this.gl._refresh();
}
};
this.readPixels = function (options) {
var framebuffer = options.framebuffer,
x = options.x,
y = options.y,
width = options.width,
height = options.height;
x = options.x,
y = options.y,
width = options.width,
height = options.height;
var readPixelsOptions = {

@@ -190,18 +189,13 @@ x: x,

};
if (framebuffer) {
readPixelsOptions.framebuffer = framebuffer.get();
}
return _this.gl.read(readPixelsOptions);
};
this.getCanvas = function () {
return _this.$canvas;
};
this.getGLContext = function () {
return _this.gl._gl;
};
this.destroy = function () {

@@ -211,3 +205,2 @@ if (_this.gl) {

_this.gl.destroy();
_this.inited = false;

@@ -217,22 +210,19 @@ }

}
(0, _createClass2.default)(WebGLEngine, [{
key: "init",
value: function () {
var _init = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(cfg) {
return _regenerator.default.wrap(function _callee3$(_context3) {
var _init = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(cfg) {
return _regenerator.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context3.prev = _context3.next) {
switch (_context4.prev = _context4.next) {
case 0:
if (!this.inited) {
_context3.next = 2;
_context4.next = 2;
break;
}
return _context3.abrupt("return");
return _context4.abrupt("return");
case 2:
this.$canvas = cfg.canvas; // tslint:disable-next-line:typedef
_context3.next = 5;
this.$canvas = cfg.canvas;
// tslint:disable-next-line:typedef
_context4.next = 5;
return new Promise(function (resolve, reject) {

@@ -246,10 +236,13 @@ (0, _regl.default)({

antialias: cfg.antialias,
premultipliedAlpha: true // preserveDrawingBuffer: false,
premultipliedAlpha: true
// preserveDrawingBuffer: false,
},
},
pixelRatio: 1,
// TODO: use extensions
extensions: ['OES_element_index_uint', 'OES_texture_float', 'OES_standard_derivatives', // wireframe
extensions: ['OES_element_index_uint', 'OES_texture_float', 'OES_standard_derivatives',
// wireframe
'angle_instanced_arrays' // VSM shadow map
],
optionalExtensions: ['EXT_texture_filter_anisotropic', 'EXT_blend_minmax', 'WEBGL_depth_texture'],

@@ -260,5 +253,4 @@ profile: true,

reject(err);
} // @ts-ignore
}
// @ts-ignore
resolve(r);

@@ -268,19 +260,15 @@ }

});
case 5:
this.gl = _context3.sent;
this.gl = _context4.sent;
this.inited = true;
case 7:
case "end":
return _context3.stop();
return _context4.stop();
}
}
}, _callee3, this);
}, _callee4, this);
}));
function init(_x3) {
function init(_x4) {
return _init.apply(this, arguments);
}
return init;

@@ -297,12 +285,14 @@ }()

key: "beginFrame",
value: function beginFrame() {//
value: function beginFrame() {
//
}
}, {
key: "endFrame",
value: function endFrame() {//
value: function endFrame() {
//
}
}]);
return WebGLEngine;
}(), _temp)) || _class);
}();
exports.WebGLEngine = WebGLEngine;
//# sourceMappingURL=index.js.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,7 +8,4 @@ value: true

exports.default = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
/**

@@ -24,7 +20,7 @@ * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#attributes

var buffer = options.buffer,
offset = options.offset,
stride = options.stride,
normalized = options.normalized,
size = options.size,
divisor = options.divisor;
offset = options.offset,
stride = options.stride,
normalized = options.normalized,
size = options.size,
divisor = options.divisor;
this.buffer = buffer;

@@ -38,3 +34,2 @@ this.attribute = {

};
if (size) {

@@ -44,3 +39,2 @@ this.attribute.size = size;

}
(0, _createClass2.default)(ReglAttribute, [{

@@ -64,4 +58,3 @@ key: "get",

}();
exports.default = ReglAttribute;
//# sourceMappingURL=ReglAttribute.js.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,11 +8,6 @@ value: true

exports.default = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _gWebgpuCore = require("@antv/g-webgpu-core");
var _constants = require("./constants");
/**

@@ -28,13 +22,12 @@ * adaptor for regl.Buffer

var data = options.data,
usage = options.usage,
type = options.type; // @ts-ignore
usage = options.usage,
type = options.type;
// @ts-ignore
this.buffer = reGl.buffer({
data: data,
usage: _constants.usageMap[usage || _gWebgpuCore.gl.STATIC_DRAW],
type: _constants.dataTypeMap[type || _gWebgpuCore.gl.UNSIGNED_BYTE] // length: 0,
type: _constants.dataTypeMap[type || _gWebgpuCore.gl.UNSIGNED_BYTE]
// length: 0,
});
}
(0, _createClass2.default)(ReglBuffer, [{

@@ -48,3 +41,3 @@ key: "get",

value: function destroy() {
this.buffer.destroy();
// this.buffer.destroy();
}

@@ -55,3 +48,3 @@ }, {

var data = _ref.data,
offset = _ref.offset;
offset = _ref.offset;
// @ts-ignore

@@ -63,4 +56,3 @@ this.buffer.subdata(data, offset);

}();
exports.default = ReglBuffer;
//# sourceMappingURL=ReglBuffer.js.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,23 +8,12 @@ value: true

exports.default = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _isTypedArray2 = _interopRequireDefault(require("lodash/isTypedArray"));
var _gWebgpuCore = require("@antv/g-webgpu-core");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
/* babel-plugin-inline-import './shaders/quad.vert.glsl' */

@@ -35,10 +23,9 @@ var quadVert = "attribute vec3 a_Position;\nattribute vec2 a_TexCoord;\n\nvarying vec2 v_TexCoord;\n\nvoid main() {\n gl_Position = vec4(a_Position, 1.0);\n v_TexCoord = a_TexCoord;\n}";

var debug = false;
/**
* adaptor for regl.DrawCommand
*/
var ReglComputeModel = /*#__PURE__*/function () {
function ReglComputeModel(reGl, context) {
var _this = this;
(0, _classCallCheck2.default)(this, ReglComputeModel);

@@ -58,7 +45,7 @@ this.reGl = reGl;

var name = uniform.name,
type = uniform.type,
data = uniform.data,
isReferer = uniform.isReferer,
storageClass = uniform.storageClass; // store data with a 2D texture
type = uniform.type,
data = uniform.data,
isReferer = uniform.isReferer,
storageClass = uniform.storageClass;
// store data with a 2D texture
if (storageClass === _gWebgpuCore.STORAGE_CLASS.StorageBuffer) {

@@ -68,9 +55,7 @@ if (!isReferer) {

var _this$textureCache$na = _this.textureCache[name],
width = _this$textureCache$na.textureWidth,
isOutput = _this$textureCache$na.isOutput;
width = _this$textureCache$na.textureWidth,
isOutput = _this$textureCache$na.isOutput;
uniforms["".concat(name, "Size")] = [width, width];
if (isOutput) {
_this.outputTextureName = name;
if (_this.context.needPingpong) {

@@ -82,9 +67,11 @@ _this.outputTextureName = "".concat(name, "Output");

} else {
// @ts-ignore
_this.textureCache[name] = {
data: undefined
}; // refer to another kernel's output,
};
// refer to another kernel's output,
// the referred kernel may not have been initialized, so we use dynamic way here
uniforms["".concat(name, "Size")] = function () {
return (// @ts-ignore
return (
// @ts-ignore
data.compiledBundle.context.output.textureSize

@@ -94,3 +81,2 @@ );

}
uniforms[name] = function () {

@@ -100,3 +86,2 @@ if (debug) {

}
return _this.textureCache[name].texture;

@@ -108,5 +93,4 @@ };

throw new Error("invalid data type ".concat(type));
} // get uniform dynamically
}
// get uniform dynamically
uniforms[name] = function () {

@@ -117,11 +101,11 @@ return uniform.data;

});
var _this$getOuputDataTex = this.getOuputDataTexture(),
textureWidth = _this$getOuputDataTex.textureWidth,
texelCount = _this$getOuputDataTex.texelCount; // 传入 output 纹理尺寸和数据长度,便于多余的 texel 提前退出
textureWidth = _this$getOuputDataTex.textureWidth,
texelCount = _this$getOuputDataTex.texelCount;
// 传入 output 纹理尺寸和数据长度,便于多余的 texel 提前退出
uniforms.u_OutputTextureSize = [textureWidth, textureWidth];
uniforms.u_OutputTexelCount = texelCount; // 保存在 Kernel 的上下文中,供其他 Kernel 引用
uniforms.u_OutputTexelCount = texelCount;
// 保存在 Kernel 的上下文中,供其他 Kernel 引用
this.context.output.textureSize = [textureWidth, textureWidth];

@@ -142,3 +126,2 @@ var drawParams = {

}
(0, _createClass2.default)(ReglComputeModel, [{

@@ -148,8 +131,9 @@ key: "run",

var _this2 = this;
if (this.context.maxIteration > 1 && this.context.needPingpong) {
this.compiledPingpong = true;
} // need pingpong when (@in@out and execute(10)) or use `setBinding('out', self)`
}
// need pingpong when (@in@out and execute(10)) or use `setBinding('out', self)`
// this.needPingpong =
// !!(this.context.maxIteration > 1 && this.context.needPingpong);
// if (this.relativeOutputTextureNames.length) {

@@ -164,7 +148,5 @@ // const { id, texture } = this.getOuputDataTexture();

if (this.compiledPingpong || this.dynamicPingpong) {
this.swap();
}
this.texFBO = this.reGl.framebuffer({

@@ -176,3 +158,2 @@ color: this.getOuputDataTexture().texture

});
if (debug) {

@@ -187,5 +168,3 @@ console.log("[".concat(this.entity, "]: output ").concat(this.getOuputDataTexture().id));

var _this3 = this;
var pixels, _this$getOuputDataTex2, originalDataLength, elementsPerTexel, _this$getOuputDataTex3, typedArrayConstructor, formattedPixels, i;
return _regenerator.default.wrap(function _callee$(_context) {

@@ -199,4 +178,5 @@ while (1) {

pixels = _this3.reGl.read();
}); // @ts-ignore
});
// @ts-ignore
if (!pixels) {

@@ -206,6 +186,4 @@ _context.next = 6;

}
_this$getOuputDataTex2 = this.getOuputDataTexture(), originalDataLength = _this$getOuputDataTex2.originalDataLength, elementsPerTexel = _this$getOuputDataTex2.elementsPerTexel, _this$getOuputDataTex3 = _this$getOuputDataTex2.typedArrayConstructor, typedArrayConstructor = _this$getOuputDataTex3 === void 0 ? Float32Array : _this$getOuputDataTex3;
formattedPixels = [];
if (elementsPerTexel !== 4) {

@@ -224,11 +202,9 @@ for (i = 0; i < pixels.length; i += 4) {

formattedPixels = pixels;
} // 截取多余的部分
}
// 截取多余的部分
// @ts-ignore
return _context.abrupt("return", new typedArrayConstructor(formattedPixels.slice(0, originalDataLength)));
case 6:
return _context.abrupt("return", new Float32Array());
case 7:

@@ -241,7 +217,5 @@ case "end":

}));
function readData() {
return _readData.apply(this, arguments);
}
return readData;

@@ -252,4 +226,4 @@ }()

value: function confirmInput(model, inputName) {
var inputModel; // refer to self, same as pingpong
var inputModel;
// refer to self, same as pingpong
if (this.entity === model.entity) {

@@ -261,6 +235,4 @@ this.dynamicPingpong = true;

}
this.textureCache[inputName].id = inputModel.getOuputDataTexture().id;
this.textureCache[inputName].texture = inputModel.getOuputDataTexture().texture;
if (debug) {

@@ -272,3 +244,4 @@ console.log("[".concat(this.entity, "]: confirm input ").concat(inputName, " from model ").concat(inputModel.entity, ", ").concat(inputModel.getOuputDataTexture().id));

key: "updateUniform",
value: function updateUniform() {// already get uniform's data dynamically when created, do nothing here
value: function updateUniform() {
// already get uniform's data dynamically when created, do nothing here
}

@@ -284,9 +257,8 @@ }, {

});
if (buffer) {
var _this$calcDataTexture = this.calcDataTexture(bufferName, buffer.type, data),
texture = _this$calcDataTexture.texture,
paddingData = _this$calcDataTexture.data; // TODO: destroy outdated texture
texture = _this$calcDataTexture.texture,
paddingData = _this$calcDataTexture.data;
// TODO: destroy outdated texture
this.textureCache[bufferName].data = paddingData;

@@ -298,3 +270,4 @@ this.textureCache[bufferName].texture = texture;

key: "destroy",
value: function destroy() {// regl will destroy all resources
value: function destroy() {
// regl will destroy all resources
}

@@ -307,3 +280,2 @@ }, {

}
if (this.compiledPingpong) {

@@ -314,7 +286,5 @@ var outputTextureUniformName = this.context.output.name;

}
var tmp = this.outputTextureName;
this.outputTextureName = this.swapOutputTextureName;
this.swapOutputTextureName = tmp;
if (debug) {

@@ -340,3 +310,3 @@ console.log("[".concat(this.entity, "]: after swap, output ").concat(this.getOuputDataTexture().id));

var data = texture.data,
textureWidth = texture.textureWidth;
textureWidth = texture.textureWidth;
return _objectSpread(_objectSpread({}, texture), {}, {

@@ -357,10 +327,8 @@ id: textureId++,

var elementsPerTexel = 1;
if (type === _gWebgpuCore.AST_TOKEN_TYPES.Vector4FloatArray) {
elementsPerTexel = 4;
} // 用 0 补全不足 vec4 的部分
}
// 用 0 补全不足 vec4 的部分
var paddingData = [];
for (var i = 0; i < data.length; i += elementsPerTexel) {

@@ -376,5 +344,5 @@ if (elementsPerTexel === 1) {

}
} // 使用纹理存储,例如 Array(8) 使用 3 * 3 纹理,末尾空白使用 0 填充
}
// 使用纹理存储,例如 Array(8) 使用 3 * 3 纹理,末尾空白使用 0 填充
var originalDataLength = data.length;

@@ -384,7 +352,5 @@ var texelCount = Math.ceil(originalDataLength / elementsPerTexel);

var paddingTexelCount = width * width;
if (texelCount < paddingTexelCount) {
paddingData.push.apply(paddingData, (0, _toConsumableArray2.default)(new Array((paddingTexelCount - texelCount) * 4).fill(0)));
}
var texture = this.reGl.texture({

@@ -411,4 +377,3 @@ width: width,

}();
exports.default = ReglComputeModel;
//# sourceMappingURL=ReglComputeModel.js.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,11 +8,6 @@ value: true

exports.default = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _gWebgpuCore = require("@antv/g-webgpu-core");
var _constants = require("./constants");
/**

@@ -27,5 +21,5 @@ * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#elements

var data = options.data,
usage = options.usage,
type = options.type,
count = options.count;
usage = options.usage,
type = options.type,
count = options.count;
this.elements = reGl.elements({

@@ -38,3 +32,2 @@ data: data,

}
(0, _createClass2.default)(ReglElements, [{

@@ -59,4 +52,3 @@ key: "get",

}();
exports.default = ReglElements;
//# sourceMappingURL=ReglElements.js.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,7 +8,4 @@ value: true

exports.default = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
/**

@@ -24,7 +20,7 @@ * adaptor for regl.Framebuffer

var width = options.width,
height = options.height,
color = options.color,
colors = options.colors,
depth = options.depth,
stencil = options.stencil;
height = options.height,
color = options.color,
colors = options.colors,
depth = options.depth,
stencil = options.stencil;
var framebufferOptions = {

@@ -34,3 +30,2 @@ width: width,

};
if (Array.isArray(colors)) {

@@ -41,11 +36,10 @@ framebufferOptions.colors = colors.map(function (c) {

}
if (color && typeof color !== 'boolean') {
framebufferOptions.color = color.get();
} // TODO: depth & stencil
}
// TODO: depth & stencil
this.framebuffer = reGl.framebuffer(framebufferOptions);
}
(0, _createClass2.default)(ReglFramebuffer, [{

@@ -65,3 +59,3 @@ key: "get",

var width = _ref.width,
height = _ref.height;
height = _ref.height;
this.framebuffer.resize(width, height);

@@ -72,4 +66,3 @@ }

}();
exports.default = ReglFramebuffer;
//# sourceMappingURL=ReglFramebuffer.js.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,21 +8,11 @@ value: true

exports.default = void 0;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _gWebgpuCore = require("@antv/g-webgpu-core");
var _uniform = require("../utils/uniform");
var _constants = require("./constants");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
/**

@@ -40,17 +29,17 @@ * adaptor for regl.DrawCommand

var vs = options.vs,
fs = options.fs,
attributes = options.attributes,
uniforms = options.uniforms,
primitive = options.primitive,
count = options.count,
elements = options.elements,
depth = options.depth,
blend = options.blend,
stencil = options.stencil,
cull = options.cull,
instances = options.instances,
scissor = options.scissor,
viewport = options.viewport;
fs = options.fs,
defines = options.defines,
attributes = options.attributes,
uniforms = options.uniforms,
primitive = options.primitive,
count = options.count,
elements = options.elements,
depth = options.depth,
blend = options.blend,
stencil = options.stencil,
cull = options.cull,
instances = options.instances,
scissor = options.scissor,
viewport = options.viewport;
var reglUniforms = {};
if (uniforms) {

@@ -64,3 +53,2 @@ this.uniforms = (0, _uniform.extractUniforms)(uniforms);

}
var reglAttributes = {};

@@ -70,31 +58,27 @@ Object.keys(attributes).forEach(function (name) {

});
var defineStmts = defines && this.generateDefines(defines) || '';
var drawParams = {
attributes: reglAttributes,
frag: "#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n".concat(fs),
frag: "#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n#else\n precision mediump float;\n#endif\n".concat(defineStmts, "\n").concat(fs),
uniforms: reglUniforms,
vert: vs,
vert: "\n".concat(defineStmts, "\n").concat(vs),
primitive: _constants.primitiveMap[primitive === undefined ? _gWebgpuCore.gl.TRIANGLES : primitive]
};
if (instances) {
drawParams.instances = instances;
} // elements 中可能包含 count,此时不应传入
}
// elements 中可能包含 count,此时不应传入
if (count) {
drawParams.count = count;
}
if (elements) {
drawParams.elements = elements.get();
}
if (scissor) {
drawParams.scissor = scissor;
}
if (viewport) {
drawParams.viewport = viewport;
}
this.initDepthDrawParams({

@@ -114,3 +98,2 @@ depth: depth

}
(0, _createClass2.default)(ReglModel, [{

@@ -125,10 +108,11 @@ key: "addUniforms",

var uniforms = _objectSpread(_objectSpread({}, this.uniforms), (0, _uniform.extractUniforms)(options.uniforms || {}));
var reglDrawProps = {};
Object.keys(uniforms).forEach(function (uniformName) {
var type = (0, _typeof2.default)(uniforms[uniformName]);
if (type === 'boolean' || type === 'number' || Array.isArray(uniforms[uniformName]) || // @ts-ignore
if (type === 'boolean' || type === 'number' || Array.isArray(uniforms[uniformName]) ||
// @ts-ignore
uniforms[uniformName].BYTES_PER_ELEMENT) {
reglDrawProps[uniformName] = uniforms[uniformName];
} else if (type === 'string') {
// TODO: image url
} else {

@@ -142,8 +126,9 @@ reglDrawProps[uniformName] = uniforms[uniformName].get();

key: "destroy",
value: function destroy() {// don't need do anything since we will call `rendererService.cleanup()`
value: function destroy() {
// don't need do anything since we will call `rendererService.cleanup()`
}
/**
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#depth-buffer
*/
}, {

@@ -153,3 +138,2 @@ key: "initDepthDrawParams",

var depth = _ref.depth;
if (depth) {

@@ -164,6 +148,6 @@ drawParams.depth = {

}
/**
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#blending
*/
}, {

@@ -173,10 +157,9 @@ key: "initBlendDrawParams",

var blend = _ref2.blend;
if (blend) {
var enable = blend.enable,
func = blend.func,
equation = blend.equation,
_blend$color = blend.color,
color = _blend$color === void 0 ? [0, 0, 0, 0] : _blend$color; // @ts-ignore
func = blend.func,
equation = blend.equation,
_blend$color = blend.color,
color = _blend$color === void 0 ? [0, 0, 0, 0] : _blend$color;
// @ts-ignore
drawParams.blend = {

@@ -198,6 +181,6 @@ enable: !!enable,

}
/**
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#stencil
*/
}, {

@@ -207,25 +190,24 @@ key: "initStencilDrawParams",

var stencil = _ref3.stencil;
if (stencil) {
var enable = stencil.enable,
_stencil$mask = stencil.mask,
mask = _stencil$mask === void 0 ? -1 : _stencil$mask,
_stencil$func = stencil.func,
func = _stencil$func === void 0 ? {
cmp: _gWebgpuCore.gl.ALWAYS,
ref: 0,
mask: -1
} : _stencil$func,
_stencil$opFront = stencil.opFront,
opFront = _stencil$opFront === void 0 ? {
fail: _gWebgpuCore.gl.KEEP,
zfail: _gWebgpuCore.gl.KEEP,
zpass: _gWebgpuCore.gl.KEEP
} : _stencil$opFront,
_stencil$opBack = stencil.opBack,
opBack = _stencil$opBack === void 0 ? {
fail: _gWebgpuCore.gl.KEEP,
zfail: _gWebgpuCore.gl.KEEP,
zpass: _gWebgpuCore.gl.KEEP
} : _stencil$opBack;
_stencil$mask = stencil.mask,
mask = _stencil$mask === void 0 ? -1 : _stencil$mask,
_stencil$func = stencil.func,
func = _stencil$func === void 0 ? {
cmp: _gWebgpuCore.gl.ALWAYS,
ref: 0,
mask: -1
} : _stencil$func,
_stencil$opFront = stencil.opFront,
opFront = _stencil$opFront === void 0 ? {
fail: _gWebgpuCore.gl.KEEP,
zfail: _gWebgpuCore.gl.KEEP,
zpass: _gWebgpuCore.gl.KEEP
} : _stencil$opFront,
_stencil$opBack = stencil.opBack,
opBack = _stencil$opBack === void 0 ? {
fail: _gWebgpuCore.gl.KEEP,
zfail: _gWebgpuCore.gl.KEEP,
zpass: _gWebgpuCore.gl.KEEP
} : _stencil$opBack;
drawParams.stencil = {

@@ -250,6 +232,6 @@ enable: !!enable,

}
/**
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#culling
*/
}, {

@@ -259,7 +241,6 @@ key: "initCullDrawParams",

var cull = _ref4.cull;
if (cull) {
var enable = cull.enable,
_cull$face = cull.face,
face = _cull$face === void 0 ? _gWebgpuCore.gl.BACK : _cull$face;
_cull$face = cull.face,
face = _cull$face === void 0 ? _gWebgpuCore.gl.BACK : _cull$face;
drawParams.cull = {

@@ -271,7 +252,13 @@ enable: !!enable,

}
}, {
key: "generateDefines",
value: function generateDefines(defines) {
return Object.keys(defines).map(function (name) {
return "#define ".concat(name, " ").concat(Number(defines[name]));
}).join('\n');
}
}]);
return ReglModel;
}();
exports.default = ReglModel;
//# sourceMappingURL=ReglModel.js.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,9 +8,5 @@ value: true

exports.default = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _constants = require("./constants");
/**

@@ -26,4 +21,4 @@ * adaptor for regl.Renderbuffer

var width = options.width,
height = options.height,
format = options.format;
height = options.height,
format = options.format;
this.renderbuffer = reGl.renderbuffer({

@@ -35,3 +30,2 @@ width: width,

}
(0, _createClass2.default)(ReglRenderbuffer, [{

@@ -51,3 +45,3 @@ key: "get",

var width = _ref.width,
height = _ref.height;
height = _ref.height;
this.renderbuffer.resize(width, height);

@@ -58,4 +52,3 @@ }

}();
exports.default = ReglRenderbuffer;
//# sourceMappingURL=ReglRenderbuffer.js.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,11 +8,6 @@ value: true

exports.default = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _gWebgpuCore = require("@antv/g-webgpu-core");
var _constants = require("./constants");
/**

@@ -30,28 +24,28 @@ * adaptor for regl.Buffer

var data = options.data,
_options$type = options.type,
type = _options$type === void 0 ? _gWebgpuCore.gl.UNSIGNED_BYTE : _options$type,
width = options.width,
height = options.height,
_options$flipY = options.flipY,
flipY = _options$flipY === void 0 ? false : _options$flipY,
_options$format = options.format,
format = _options$format === void 0 ? _gWebgpuCore.gl.RGBA : _options$format,
_options$mipmap = options.mipmap,
mipmap = _options$mipmap === void 0 ? false : _options$mipmap,
_options$wrapS = options.wrapS,
wrapS = _options$wrapS === void 0 ? _gWebgpuCore.gl.CLAMP_TO_EDGE : _options$wrapS,
_options$wrapT = options.wrapT,
wrapT = _options$wrapT === void 0 ? _gWebgpuCore.gl.CLAMP_TO_EDGE : _options$wrapT,
_options$aniso = options.aniso,
aniso = _options$aniso === void 0 ? 0 : _options$aniso,
_options$alignment = options.alignment,
alignment = _options$alignment === void 0 ? 1 : _options$alignment,
_options$premultiplyA = options.premultiplyAlpha,
premultiplyAlpha = _options$premultiplyA === void 0 ? false : _options$premultiplyA,
_options$mag = options.mag,
mag = _options$mag === void 0 ? _gWebgpuCore.gl.NEAREST : _options$mag,
_options$min = options.min,
min = _options$min === void 0 ? _gWebgpuCore.gl.NEAREST : _options$min,
_options$colorSpace = options.colorSpace,
colorSpace = _options$colorSpace === void 0 ? _gWebgpuCore.gl.BROWSER_DEFAULT_WEBGL : _options$colorSpace;
_options$type = options.type,
type = _options$type === void 0 ? _gWebgpuCore.gl.UNSIGNED_BYTE : _options$type,
width = options.width,
height = options.height,
_options$flipY = options.flipY,
flipY = _options$flipY === void 0 ? false : _options$flipY,
_options$format = options.format,
format = _options$format === void 0 ? _gWebgpuCore.gl.RGBA : _options$format,
_options$mipmap = options.mipmap,
mipmap = _options$mipmap === void 0 ? false : _options$mipmap,
_options$wrapS = options.wrapS,
wrapS = _options$wrapS === void 0 ? _gWebgpuCore.gl.CLAMP_TO_EDGE : _options$wrapS,
_options$wrapT = options.wrapT,
wrapT = _options$wrapT === void 0 ? _gWebgpuCore.gl.CLAMP_TO_EDGE : _options$wrapT,
_options$aniso = options.aniso,
aniso = _options$aniso === void 0 ? 0 : _options$aniso,
_options$alignment = options.alignment,
alignment = _options$alignment === void 0 ? 1 : _options$alignment,
_options$premultiplyA = options.premultiplyAlpha,
premultiplyAlpha = _options$premultiplyA === void 0 ? false : _options$premultiplyA,
_options$mag = options.mag,
mag = _options$mag === void 0 ? _gWebgpuCore.gl.NEAREST : _options$mag,
_options$min = options.min,
min = _options$min === void 0 ? _gWebgpuCore.gl.NEAREST : _options$min,
_options$colorSpace = options.colorSpace,
colorSpace = _options$colorSpace === void 0 ? _gWebgpuCore.gl.BROWSER_DEFAULT_WEBGL : _options$colorSpace;
this.width = width;

@@ -76,7 +70,5 @@ this.height = height;

};
if (data) {
textureOptions.data = data;
}
if (typeof mipmap === 'number') {

@@ -87,6 +79,4 @@ textureOptions.mipmap = _constants.mipmapMap[mipmap];

}
this.texture = reGl.texture(textureOptions);
}
(0, _createClass2.default)(ReglTexture2D, [{

@@ -107,3 +97,3 @@ key: "get",

var width = _ref.width,
height = _ref.height;
height = _ref.height;
this.texture.resize(width, height);

@@ -121,4 +111,3 @@ this.width = width;

}();
exports.default = ReglTexture2D;
//# sourceMappingURL=ReglTexture2D.js.map
{
"name": "@antv/g-webgpu-engine",
"version": "0.6.0",
"version": "0.7.0",
"description": "",

@@ -25,12 +25,5 @@ "main": "lib/index.js",

"dependencies": {
"@antv/g-webgpu-core": "^0.6.0",
"@webgpu/glslang": "^0.0.15",
"@webgpu/types": "^0.0.31",
"@antv/g-webgpu-core": "^0.5.1",
"gl-matrix": "^3.1.0",
"hammerjs": "^2.0.8",
"inversify": "^5.0.1",
"inversify-inject-decorators": "^3.1.0",
"lodash": "^4.17.15",
"probe.gl": "^3.1.1",
"reflect-metadata": "^0.1.13",
"regl": "^1.3.11"

@@ -40,3 +33,2 @@ },

"@types/gl-matrix": "^2.4.5",
"@types/hammerjs": "^2.0.36",
"@types/lodash": "^4.14.138"

@@ -46,4 +38,3 @@ },

"access": "public"
},
"gitHead": "25cfea6a4e7fb2d471392949531f99413186cfd6"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc