@antv/l7-renderer 2.19.10 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/es/device/DeviceAttribute.d.ts +13 -0
  2. package/es/device/DeviceAttribute.js +44 -0
  3. package/es/device/DeviceBuffer.d.ts +18 -0
  4. package/es/device/DeviceBuffer.js +65 -0
  5. package/es/device/DeviceElements.d.ts +13 -0
  6. package/es/device/DeviceElements.js +52 -0
  7. package/es/device/DeviceFramebuffer.d.ts +15 -0
  8. package/es/device/DeviceFramebuffer.js +58 -0
  9. package/es/device/DeviceModel.d.ts +36 -0
  10. package/es/device/DeviceModel.js +414 -0
  11. package/es/device/DeviceTexture2D.d.ts +20 -0
  12. package/es/device/DeviceTexture2D.js +116 -0
  13. package/es/device/constants.d.ts +29 -0
  14. package/es/device/constants.js +32 -0
  15. package/es/device/index.d.ts +53 -0
  16. package/es/device/index.js +319 -0
  17. package/es/device/utils/pipeline.d.ts +1 -0
  18. package/es/device/utils/pipeline.js +1 -0
  19. package/es/device/utils/typedarray.d.ts +2 -0
  20. package/es/device/utils/typedarray.js +16 -0
  21. package/es/device/utils/webgl.d.ts +1 -0
  22. package/es/device/utils/webgl.js +9 -0
  23. package/es/index.d.ts +2 -1
  24. package/es/index.js +2 -1
  25. package/es/regl/ReglModel.js +20 -6
  26. package/es/regl/ReglTexture2D.js +1 -1
  27. package/es/regl/index.d.ts +3 -0
  28. package/es/regl/index.js +10 -3
  29. package/lib/device/DeviceAttribute.js +58 -0
  30. package/lib/device/DeviceBuffer.js +68 -0
  31. package/lib/device/DeviceElements.js +66 -0
  32. package/lib/device/DeviceFramebuffer.js +67 -0
  33. package/lib/device/DeviceModel.js +370 -0
  34. package/lib/device/DeviceTexture2D.js +119 -0
  35. package/lib/device/constants.js +117 -0
  36. package/lib/device/index.js +189 -0
  37. package/lib/device/utils/pipeline.js +30 -0
  38. package/lib/device/utils/typedarray.js +43 -0
  39. package/lib/device/utils/webgl.js +34 -0
  40. package/lib/index.js +3 -0
  41. package/lib/regl/ReglModel.js +16 -2
  42. package/lib/regl/index.js +5 -0
  43. package/package.json +15 -15
@@ -0,0 +1,66 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/device/DeviceElements.ts
20
+ var DeviceElements_exports = {};
21
+ __export(DeviceElements_exports, {
22
+ default: () => DeviceElements
23
+ });
24
+ module.exports = __toCommonJS(DeviceElements_exports);
25
+ var import_g_device_api = require("@antv/g-device-api");
26
+ var import_l7_core = require("@antv/l7-core");
27
+ var import_constants = require("./constants");
28
+ var import_typedarray = require("./utils/typedarray");
29
+ var DeviceElements = class {
30
+ constructor(device, options) {
31
+ const { data, type, count = 0 } = options;
32
+ let typed;
33
+ if ((0, import_typedarray.isTypedArray)(data)) {
34
+ typed = data;
35
+ } else {
36
+ typed = new import_constants.typedArrayCtorMap[this.type || import_l7_core.gl.UNSIGNED_INT](
37
+ data
38
+ );
39
+ }
40
+ this.type = type;
41
+ this.count = count;
42
+ this.indexBuffer = device.createBuffer({
43
+ viewOrSize: typed,
44
+ usage: import_g_device_api.BufferUsage.INDEX
45
+ });
46
+ }
47
+ get() {
48
+ return this.indexBuffer;
49
+ }
50
+ subData({
51
+ data
52
+ }) {
53
+ let typed;
54
+ if ((0, import_typedarray.isTypedArray)(data)) {
55
+ typed = data;
56
+ } else {
57
+ typed = new import_constants.typedArrayCtorMap[this.type || import_l7_core.gl.UNSIGNED_INT](
58
+ data
59
+ );
60
+ }
61
+ this.indexBuffer.setSubData(0, new Uint8Array(typed.buffer));
62
+ }
63
+ destroy() {
64
+ this.indexBuffer.destroy();
65
+ }
66
+ };
@@ -0,0 +1,67 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/device/DeviceFramebuffer.ts
20
+ var DeviceFramebuffer_exports = {};
21
+ __export(DeviceFramebuffer_exports, {
22
+ default: () => DeviceFramebuffer
23
+ });
24
+ module.exports = __toCommonJS(DeviceFramebuffer_exports);
25
+ var import_g_device_api = require("@antv/g-device-api");
26
+ var import_DeviceTexture2D = require("./DeviceTexture2D");
27
+ var DeviceFramebuffer = class {
28
+ constructor(device, options) {
29
+ this.device = device;
30
+ const { width, height, color } = options;
31
+ if ((0, import_DeviceTexture2D.isTexture2D)(color)) {
32
+ this.renderTarget = device.createRenderTargetFromTexture(
33
+ color.get()
34
+ );
35
+ this.width = color["width"];
36
+ this.height = color["height"];
37
+ } else if (width && height) {
38
+ this.renderTarget = device.createRenderTarget({
39
+ format: import_g_device_api.Format.U8_RGBA_RT,
40
+ width,
41
+ height
42
+ });
43
+ this.width = width;
44
+ this.height = height;
45
+ }
46
+ }
47
+ get() {
48
+ return this.renderTarget;
49
+ }
50
+ destroy() {
51
+ this.renderTarget.destroy();
52
+ }
53
+ resize({ width, height }) {
54
+ if (this.width !== width || this.height !== height) {
55
+ if (this.renderTarget) {
56
+ this.renderTarget.destroy();
57
+ }
58
+ this.renderTarget = this.device.createRenderTarget({
59
+ format: import_g_device_api.Format.U8_RGBA_RT,
60
+ width,
61
+ height
62
+ });
63
+ this.width = width;
64
+ this.height = height;
65
+ }
66
+ }
67
+ };
@@ -0,0 +1,370 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/device/DeviceModel.ts
20
+ var DeviceModel_exports = {};
21
+ __export(DeviceModel_exports, {
22
+ default: () => DeviceModel
23
+ });
24
+ module.exports = __toCommonJS(DeviceModel_exports);
25
+ var import_g_device_api = require("@antv/g-device-api");
26
+ var import_l7_core = require("@antv/l7-core");
27
+ var import_l7_utils = require("@antv/l7-utils");
28
+ var import_constants = require("./constants");
29
+ var { isPlainObject, isTypedArray } = import_l7_utils.lodashUtil;
30
+ var DeviceModel = class {
31
+ constructor(device, options) {
32
+ this.device = device;
33
+ this.options = options;
34
+ this.destroyed = false;
35
+ this.uniforms = {};
36
+ this.vertexBuffers = [];
37
+ const { vs, fs, attributes, uniforms, count, elements } = options;
38
+ this.options = options;
39
+ const program = device.createProgram({
40
+ vertex: {
41
+ glsl: vs
42
+ },
43
+ fragment: {
44
+ glsl: fs
45
+ }
46
+ });
47
+ this.program = program;
48
+ if (uniforms) {
49
+ this.uniforms = this.extractUniforms(uniforms);
50
+ }
51
+ const vertexBufferDescriptors = [];
52
+ let inferredCount = 0;
53
+ Object.keys(attributes).forEach((name) => {
54
+ const attribute = attributes[name];
55
+ const buffer = attribute.get();
56
+ this.vertexBuffers.push(buffer.get());
57
+ const {
58
+ offset = 0,
59
+ stride = 0,
60
+ // TODO: normalized
61
+ size = 1,
62
+ divisor = 0,
63
+ shaderLocation = 0
64
+ } = attribute["attribute"];
65
+ vertexBufferDescriptors.push({
66
+ arrayStride: stride || size * 4,
67
+ // TODO: L7 hasn't use instanced array for now.
68
+ stepMode: import_g_device_api.VertexStepMode.VERTEX,
69
+ attributes: [
70
+ {
71
+ format: import_constants.sizeFormatMap[size],
72
+ shaderLocation,
73
+ offset,
74
+ divisor
75
+ }
76
+ ]
77
+ });
78
+ inferredCount = buffer["size"] / size;
79
+ });
80
+ if (!count) {
81
+ this.options.count = inferredCount;
82
+ }
83
+ if (elements) {
84
+ this.indexBuffer = elements.get();
85
+ }
86
+ const inputLayout = device.createInputLayout({
87
+ vertexBufferDescriptors,
88
+ indexBufferFormat: elements ? import_g_device_api.Format.U32_R : null,
89
+ program
90
+ });
91
+ this.inputLayout = inputLayout;
92
+ this.pipeline = this.createPipeline(options);
93
+ }
94
+ createPipeline(options) {
95
+ const { primitive = import_l7_core.gl.TRIANGLES, depth, cull, blend } = options;
96
+ const depthParams = this.initDepthDrawParams({ depth });
97
+ const depthEnabled = !!(depthParams && depthParams.enable);
98
+ const cullParams = this.initCullDrawParams({ cull });
99
+ const cullEnabled = !!(cullParams && cullParams.enable);
100
+ const blendParams = this.getBlendDrawParams({ blend });
101
+ const blendEnabled = !!(blendParams && blendParams.enable);
102
+ return this.device.createRenderPipeline({
103
+ inputLayout: this.inputLayout,
104
+ program: this.program,
105
+ topology: import_constants.primitiveMap[primitive],
106
+ colorAttachmentFormats: [import_g_device_api.Format.U8_RGBA_RT],
107
+ depthStencilAttachmentFormat: import_g_device_api.Format.D24_S8,
108
+ megaStateDescriptor: {
109
+ attachmentsState: [
110
+ {
111
+ channelWriteMask: import_g_device_api.ChannelWriteMask.ALL,
112
+ rgbBlendState: {
113
+ blendMode: blendEnabled && blendParams.equation.rgb || import_g_device_api.BlendMode.ADD,
114
+ blendSrcFactor: blendEnabled && blendParams.func.srcRGB || import_g_device_api.BlendFactor.SRC_ALPHA,
115
+ blendDstFactor: blendEnabled && blendParams.func.dstRGB || import_g_device_api.BlendFactor.ONE_MINUS_SRC_ALPHA
116
+ },
117
+ alphaBlendState: {
118
+ blendMode: blendEnabled && blendParams.equation.alpha || import_g_device_api.BlendMode.ADD,
119
+ blendSrcFactor: blendEnabled && blendParams.func.srcAlpha || import_g_device_api.BlendFactor.ONE,
120
+ blendDstFactor: blendEnabled && blendParams.func.dstAlpha || import_g_device_api.BlendFactor.ONE_MINUS_SRC_ALPHA
121
+ }
122
+ }
123
+ ],
124
+ blendConstant: import_g_device_api.TransparentBlack,
125
+ depthWrite: depthEnabled,
126
+ depthCompare: depthEnabled && depthParams.func || import_g_device_api.CompareFunction.LESS,
127
+ cullMode: cullEnabled && cullParams.face || import_g_device_api.CullMode.NONE,
128
+ stencilWrite: false
129
+ }
130
+ });
131
+ }
132
+ updateAttributesAndElements() {
133
+ }
134
+ updateAttributes() {
135
+ }
136
+ addUniforms(uniforms) {
137
+ this.uniforms = {
138
+ ...this.uniforms,
139
+ ...this.extractUniforms(uniforms)
140
+ };
141
+ }
142
+ draw(options) {
143
+ const mergedOptions = {
144
+ ...this.options,
145
+ ...options
146
+ };
147
+ const {
148
+ count = 0,
149
+ instances,
150
+ elements,
151
+ uniforms = {},
152
+ uniformBuffers,
153
+ textures
154
+ } = mergedOptions;
155
+ this.uniforms = {
156
+ ...this.uniforms,
157
+ ...this.extractUniforms(uniforms)
158
+ };
159
+ const { width, height } = this.device;
160
+ const renderPass = this.device.renderPass;
161
+ this.pipeline = this.createPipeline(mergedOptions);
162
+ renderPass.setPipeline(this.pipeline);
163
+ renderPass.setVertexInput(
164
+ this.inputLayout,
165
+ this.vertexBuffers.map((buffer) => ({
166
+ buffer
167
+ })),
168
+ elements ? {
169
+ buffer: this.indexBuffer,
170
+ offset: 0
171
+ // TODO: use defaule value
172
+ } : null
173
+ );
174
+ renderPass.setViewport(0, 0, width, height);
175
+ if (uniformBuffers) {
176
+ this.bindings = this.device.createBindings({
177
+ pipeline: this.pipeline,
178
+ uniformBufferBindings: uniformBuffers.map((uniformBuffer, i) => {
179
+ const buffer = uniformBuffer;
180
+ return {
181
+ binding: i,
182
+ buffer: buffer.get(),
183
+ size: buffer["size"]
184
+ };
185
+ }),
186
+ samplerBindings: textures == null ? void 0 : textures.map((t) => ({
187
+ texture: t["texture"],
188
+ sampler: t["sampler"]
189
+ }))
190
+ });
191
+ }
192
+ if (this.bindings) {
193
+ renderPass.setBindings(this.bindings);
194
+ this.program.setUniformsLegacy(this.uniforms);
195
+ }
196
+ if (elements) {
197
+ const indexCount = elements["count"];
198
+ if (indexCount === 0) {
199
+ renderPass.draw(count, instances);
200
+ } else {
201
+ renderPass.drawIndexed(indexCount, instances);
202
+ }
203
+ } else {
204
+ renderPass.draw(count, instances);
205
+ }
206
+ }
207
+ destroy() {
208
+ var _a, _b, _c;
209
+ this.program.destroy();
210
+ (_a = this.vertexBuffers) == null ? void 0 : _a.forEach((buffer) => buffer.destroy());
211
+ (_b = this.indexBuffer) == null ? void 0 : _b.destroy();
212
+ (_c = this.bindings) == null ? void 0 : _c.destroy();
213
+ this.inputLayout.destroy();
214
+ this.pipeline.destroy();
215
+ this.destroyed = true;
216
+ }
217
+ initDepthDrawParams({
218
+ depth
219
+ }) {
220
+ if (depth) {
221
+ return {
222
+ enable: depth.enable === void 0 ? true : !!depth.enable,
223
+ mask: depth.mask === void 0 ? true : !!depth.mask,
224
+ func: import_constants.depthFuncMap[depth.func || import_l7_core.gl.LESS],
225
+ range: depth.range || [0, 1]
226
+ };
227
+ }
228
+ }
229
+ getBlendDrawParams({
230
+ blend
231
+ }) {
232
+ const { enable, func, equation, color = [0, 0, 0, 0] } = blend || {};
233
+ return {
234
+ enable: !!enable,
235
+ func: {
236
+ srcRGB: import_constants.blendFuncMap[func && func.srcRGB || import_l7_core.gl.SRC_ALPHA],
237
+ srcAlpha: import_constants.blendFuncMap[func && func.srcAlpha || import_l7_core.gl.SRC_ALPHA],
238
+ dstRGB: import_constants.blendFuncMap[func && func.dstRGB || import_l7_core.gl.ONE_MINUS_SRC_ALPHA],
239
+ dstAlpha: import_constants.blendFuncMap[func && func.dstAlpha || import_l7_core.gl.ONE_MINUS_SRC_ALPHA]
240
+ },
241
+ equation: {
242
+ rgb: import_constants.blendEquationMap[equation && equation.rgb || import_l7_core.gl.FUNC_ADD],
243
+ alpha: import_constants.blendEquationMap[equation && equation.alpha || import_l7_core.gl.FUNC_ADD]
244
+ },
245
+ color
246
+ };
247
+ }
248
+ // /**
249
+ // * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#stencil
250
+ // */
251
+ // private getStencilDrawParams({
252
+ // stencil,
253
+ // }: Pick<IModelInitializationOptions, 'stencil'>) {
254
+ // const {
255
+ // enable,
256
+ // mask = -1,
257
+ // func = {
258
+ // cmp: gl.ALWAYS,
259
+ // ref: 0,
260
+ // mask: -1,
261
+ // },
262
+ // opFront = {
263
+ // fail: gl.KEEP,
264
+ // zfail: gl.KEEP,
265
+ // zpass: gl.KEEP,
266
+ // },
267
+ // opBack = {
268
+ // fail: gl.KEEP,
269
+ // zfail: gl.KEEP,
270
+ // zpass: gl.KEEP,
271
+ // },
272
+ // } = stencil || {};
273
+ // return {
274
+ // enable: !!enable,
275
+ // mask,
276
+ // func: {
277
+ // ...func,
278
+ // cmp: stencilFuncMap[func.cmp],
279
+ // },
280
+ // opFront: {
281
+ // fail: stencilOpMap[opFront.fail],
282
+ // zfail: stencilOpMap[opFront.zfail],
283
+ // zpass: stencilOpMap[opFront.zpass],
284
+ // },
285
+ // opBack: {
286
+ // fail: stencilOpMap[opBack.fail],
287
+ // zfail: stencilOpMap[opBack.zfail],
288
+ // zpass: stencilOpMap[opBack.zpass],
289
+ // },
290
+ // };
291
+ // }
292
+ // private getColorMaskDrawParams(
293
+ // { stencil }: Pick<IModelInitializationOptions, 'stencil'>,
294
+ // pick: boolean,
295
+ // ) {
296
+ // // TODO: 重构相关参数
297
+ // // 掩膜模式下,颜色通道全部关闭
298
+ // const colorMask =
299
+ // stencil?.enable && stencil.opFront && !pick
300
+ // ? [false, false, false, false]
301
+ // : [true, true, true, true]; // 非掩码模式下,颜色通道全部开启
302
+ // return colorMask;
303
+ // }
304
+ /**
305
+ * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#culling
306
+ */
307
+ initCullDrawParams({
308
+ cull
309
+ }) {
310
+ if (cull) {
311
+ const { enable, face = import_l7_core.gl.BACK } = cull;
312
+ return {
313
+ enable: !!enable,
314
+ face: import_constants.cullFaceMap[face]
315
+ };
316
+ }
317
+ }
318
+ /**
319
+ * 考虑结构体命名, eg:
320
+ * a: { b: 1 } -> 'a.b'
321
+ * a: [ { b: 1 } ] -> 'a[0].b'
322
+ */
323
+ extractUniforms(uniforms) {
324
+ const extractedUniforms = {};
325
+ Object.keys(uniforms).forEach((uniformName) => {
326
+ this.extractUniformsRecursively(
327
+ uniformName,
328
+ uniforms[uniformName],
329
+ extractedUniforms,
330
+ ""
331
+ );
332
+ });
333
+ return extractedUniforms;
334
+ }
335
+ extractUniformsRecursively(uniformName, uniformValue, uniforms, prefix) {
336
+ if (uniformValue === null || typeof uniformValue === "number" || // u_A: 1
337
+ typeof uniformValue === "boolean" || // u_A: false
338
+ Array.isArray(uniformValue) && typeof uniformValue[0] === "number" || // u_A: [1, 2, 3]
339
+ isTypedArray(uniformValue) || // u_A: Float32Array
340
+ // @ts-ignore
341
+ uniformValue === "" || "resize" in uniformValue) {
342
+ uniforms[`${prefix && prefix + "."}${uniformName}`] = uniformValue;
343
+ return;
344
+ }
345
+ if (isPlainObject(uniformValue)) {
346
+ Object.keys(uniformValue).forEach((childName) => {
347
+ this.extractUniformsRecursively(
348
+ childName,
349
+ // @ts-ignore
350
+ uniformValue[childName],
351
+ uniforms,
352
+ `${prefix && prefix + "."}${uniformName}`
353
+ );
354
+ });
355
+ }
356
+ if (Array.isArray(uniformValue)) {
357
+ uniformValue.forEach((child, idx) => {
358
+ Object.keys(child).forEach((childName) => {
359
+ this.extractUniformsRecursively(
360
+ childName,
361
+ // @ts-ignore
362
+ child[childName],
363
+ uniforms,
364
+ `${prefix && prefix + "."}${uniformName}[${idx}]`
365
+ );
366
+ });
367
+ });
368
+ }
369
+ }
370
+ };
@@ -0,0 +1,119 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/device/DeviceTexture2D.ts
20
+ var DeviceTexture2D_exports = {};
21
+ __export(DeviceTexture2D_exports, {
22
+ default: () => DeviceTexture2D,
23
+ isTexture2D: () => isTexture2D
24
+ });
25
+ module.exports = __toCommonJS(DeviceTexture2D_exports);
26
+ var import_g_device_api = require("@antv/g-device-api");
27
+ var import_l7_core = require("@antv/l7-core");
28
+ var import_constants = require("./constants");
29
+ function isTexture2D(t) {
30
+ return false;
31
+ }
32
+ var DeviceTexture2D = class {
33
+ constructor(device, options) {
34
+ this.isDestroy = false;
35
+ const {
36
+ data,
37
+ type = import_l7_core.gl.UNSIGNED_BYTE,
38
+ width,
39
+ height,
40
+ flipY = false,
41
+ format = import_l7_core.gl.RGBA,
42
+ wrapS = import_l7_core.gl.CLAMP_TO_EDGE,
43
+ wrapT = import_l7_core.gl.CLAMP_TO_EDGE,
44
+ // aniso = 0,
45
+ alignment = 1
46
+ // mipmap = false,
47
+ // premultiplyAlpha = false,
48
+ // mag = gl.NEAREST,
49
+ // min = gl.NEAREST,
50
+ // colorSpace = gl.BROWSER_DEFAULT_WEBGL,
51
+ // x = 0,
52
+ // y = 0,
53
+ // copy = false,
54
+ } = options;
55
+ this.width = width;
56
+ this.height = height;
57
+ let pixelFormat = import_g_device_api.Format.U8_RGBA_RT;
58
+ if (type === import_l7_core.gl.UNSIGNED_BYTE && format === import_l7_core.gl.RGBA) {
59
+ pixelFormat = import_g_device_api.Format.U8_RGBA_RT;
60
+ } else if (format === import_l7_core.gl.LUMINANCE && type === import_l7_core.gl.FLOAT) {
61
+ pixelFormat = import_g_device_api.Format.F32_LUMINANCE;
62
+ } else if (format === import_l7_core.gl.LUMINANCE && type === import_l7_core.gl.UNSIGNED_BYTE) {
63
+ pixelFormat = import_g_device_api.Format.U8_LUMINANCE;
64
+ } else {
65
+ throw new Error(`create texture error, type: ${type}, format: ${format}`);
66
+ }
67
+ this.texture = device.createTexture({
68
+ format: pixelFormat,
69
+ width,
70
+ height,
71
+ usage: import_g_device_api.TextureUsage.SAMPLED,
72
+ pixelStore: {
73
+ unpackFlipY: flipY,
74
+ packAlignment: alignment
75
+ }
76
+ });
77
+ if (data) {
78
+ this.texture.setImageData([data]);
79
+ }
80
+ this.sampler = device.createSampler({
81
+ addressModeU: import_constants.wrapModeMap[wrapS],
82
+ addressModeV: import_constants.wrapModeMap[wrapT],
83
+ minFilter: import_g_device_api.FilterMode.POINT,
84
+ // TODO: use mag & min
85
+ magFilter: import_g_device_api.FilterMode.BILINEAR,
86
+ mipmapFilter: import_g_device_api.MipmapFilterMode.NO_MIP,
87
+ lodMinClamp: 0,
88
+ lodMaxClamp: 0
89
+ // maxAnisotropy: aniso,
90
+ });
91
+ }
92
+ get() {
93
+ return this.texture;
94
+ }
95
+ update(props) {
96
+ const { data } = props;
97
+ this.texture.setImageData([data]);
98
+ }
99
+ bind() {
100
+ }
101
+ resize({ width, height }) {
102
+ this.width = width;
103
+ this.height = height;
104
+ }
105
+ getSize() {
106
+ return [this.width, this.height];
107
+ }
108
+ destroy() {
109
+ var _a;
110
+ if (!this.isDestroy) {
111
+ (_a = this.texture) == null ? void 0 : _a.destroy();
112
+ }
113
+ this.isDestroy = true;
114
+ }
115
+ };
116
+ // Annotate the CommonJS export names for ESM import in node:
117
+ 0 && (module.exports = {
118
+ isTexture2D
119
+ });