UNPKG

3.58 kBJavaScriptView Raw
1import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2import _createClass from "@babel/runtime/helpers/createClass";
3import { gl } from '@antv/g-webgpu-core';
4import { colorSpaceMap, dataTypeMap, filterMap, formatMap, mipmapMap, wrapModeMap } from './constants';
5/**
6 * adaptor for regl.Buffer
7 * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#buffers
8 */
9
10var ReglTexture2D = /*#__PURE__*/function () {
11 function ReglTexture2D(reGl, options) {
12 _classCallCheck(this, ReglTexture2D);
13
14 this.texture = void 0;
15 this.width = void 0;
16 this.height = void 0;
17 var data = options.data,
18 _options$type = options.type,
19 type = _options$type === void 0 ? gl.UNSIGNED_BYTE : _options$type,
20 width = options.width,
21 height = options.height,
22 _options$flipY = options.flipY,
23 flipY = _options$flipY === void 0 ? false : _options$flipY,
24 _options$format = options.format,
25 format = _options$format === void 0 ? gl.RGBA : _options$format,
26 _options$mipmap = options.mipmap,
27 mipmap = _options$mipmap === void 0 ? false : _options$mipmap,
28 _options$wrapS = options.wrapS,
29 wrapS = _options$wrapS === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapS,
30 _options$wrapT = options.wrapT,
31 wrapT = _options$wrapT === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapT,
32 _options$aniso = options.aniso,
33 aniso = _options$aniso === void 0 ? 0 : _options$aniso,
34 _options$alignment = options.alignment,
35 alignment = _options$alignment === void 0 ? 1 : _options$alignment,
36 _options$premultiplyA = options.premultiplyAlpha,
37 premultiplyAlpha = _options$premultiplyA === void 0 ? false : _options$premultiplyA,
38 _options$mag = options.mag,
39 mag = _options$mag === void 0 ? gl.NEAREST : _options$mag,
40 _options$min = options.min,
41 min = _options$min === void 0 ? gl.NEAREST : _options$min,
42 _options$colorSpace = options.colorSpace,
43 colorSpace = _options$colorSpace === void 0 ? gl.BROWSER_DEFAULT_WEBGL : _options$colorSpace;
44 this.width = width;
45 this.height = height;
46 var textureOptions = {
47 width: width,
48 height: height,
49 // @ts-ignore
50 type: dataTypeMap[type],
51 format: formatMap[format],
52 wrapS: wrapModeMap[wrapS],
53 wrapT: wrapModeMap[wrapT],
54 // @ts-ignore
55 mag: filterMap[mag],
56 min: filterMap[min],
57 alignment: alignment,
58 flipY: flipY,
59 colorSpace: colorSpaceMap[colorSpace],
60 premultiplyAlpha: premultiplyAlpha,
61 aniso: aniso
62 };
63
64 if (data) {
65 textureOptions.data = data;
66 }
67
68 if (typeof mipmap === 'number') {
69 textureOptions.mipmap = mipmapMap[mipmap];
70 } else if (typeof mipmap === 'boolean') {
71 textureOptions.mipmap = mipmap;
72 }
73
74 this.texture = reGl.texture(textureOptions);
75 }
76
77 _createClass(ReglTexture2D, [{
78 key: "get",
79 value: function get() {
80 return this.texture;
81 }
82 }, {
83 key: "update",
84 value: function update() {
85 // @ts-ignore
86 this.texture._texture.bind();
87 }
88 }, {
89 key: "resize",
90 value: function resize(_ref) {
91 var width = _ref.width,
92 height = _ref.height;
93 this.texture.resize(width, height);
94 this.width = width;
95 this.height = height;
96 }
97 }, {
98 key: "destroy",
99 value: function destroy() {
100 this.texture.destroy();
101 }
102 }]);
103
104 return ReglTexture2D;
105}();
106
107export { ReglTexture2D as default };
108//# sourceMappingURL=ReglTexture2D.js.map
\No newline at end of file