@antv/l7-renderer 2.25.7 → 2.25.9

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 (93) hide show
  1. package/es/device/DeviceAttribute.d.ts +13 -0
  2. package/es/device/DeviceAttribute.js +30 -0
  3. package/es/device/DeviceBuffer.d.ts +18 -0
  4. package/es/device/DeviceBuffer.js +51 -0
  5. package/es/device/DeviceCache.d.ts +14 -0
  6. package/es/device/DeviceCache.js +198 -0
  7. package/es/device/DeviceElements.d.ts +13 -0
  8. package/es/device/DeviceElements.js +42 -0
  9. package/es/device/DeviceFramebuffer.d.ts +24 -0
  10. package/es/device/DeviceFramebuffer.js +81 -0
  11. package/es/device/DeviceModel.d.ts +61 -0
  12. package/es/device/DeviceModel.js +488 -0
  13. package/es/device/DeviceTexture2D.d.ts +23 -0
  14. package/es/device/DeviceTexture2D.js +132 -0
  15. package/es/device/constants.d.ts +35 -0
  16. package/es/device/constants.js +117 -0
  17. package/es/device/index.d.ts +68 -0
  18. package/es/device/index.js +311 -0
  19. package/es/device/utils/HashMap.d.ts +24 -0
  20. package/es/device/utils/HashMap.js +86 -0
  21. package/es/device/utils/pipeline.d.ts +1 -0
  22. package/es/device/utils/pipeline.js +6 -0
  23. package/es/device/utils/typedarray.d.ts +7 -0
  24. package/es/device/utils/typedarray.js +33 -0
  25. package/es/device/utils/webgl.d.ts +1 -0
  26. package/es/device/utils/webgl.js +10 -0
  27. package/es/index.d.ts +3 -0
  28. package/es/index.js +7 -0
  29. package/es/regl/ReglAttribute.d.ts +16 -0
  30. package/es/regl/ReglAttribute.js +29 -0
  31. package/es/regl/ReglBuffer.d.ts +17 -0
  32. package/es/regl/ReglBuffer.js +33 -0
  33. package/es/regl/ReglElements.d.ts +14 -0
  34. package/es/regl/ReglElements.js +27 -0
  35. package/es/regl/ReglFramebuffer.d.ts +16 -0
  36. package/es/regl/ReglFramebuffer.js +31 -0
  37. package/es/regl/ReglModel.d.ts +46 -0
  38. package/es/regl/ReglModel.js +302 -0
  39. package/es/regl/ReglRenderbuffer.d.ts +16 -0
  40. package/es/regl/ReglRenderbuffer.js +24 -0
  41. package/es/regl/ReglTexture2D.d.ts +22 -0
  42. package/es/regl/ReglTexture2D.js +94 -0
  43. package/es/regl/constants.d.ts +43 -0
  44. package/es/regl/constants.js +133 -0
  45. package/es/regl/index.d.ts +56 -0
  46. package/es/regl/index.js +227 -0
  47. package/lib/device/DeviceAttribute.d.ts +13 -0
  48. package/lib/device/DeviceAttribute.js +50 -0
  49. package/lib/device/DeviceBuffer.d.ts +18 -0
  50. package/lib/device/DeviceBuffer.js +71 -0
  51. package/lib/device/DeviceCache.d.ts +14 -0
  52. package/lib/device/DeviceCache.js +214 -0
  53. package/lib/device/DeviceElements.d.ts +13 -0
  54. package/lib/device/DeviceElements.js +62 -0
  55. package/lib/device/DeviceFramebuffer.d.ts +24 -0
  56. package/lib/device/DeviceFramebuffer.js +101 -0
  57. package/lib/device/DeviceModel.d.ts +61 -0
  58. package/lib/device/DeviceModel.js +495 -0
  59. package/lib/device/DeviceTexture2D.d.ts +23 -0
  60. package/lib/device/DeviceTexture2D.js +151 -0
  61. package/lib/device/constants.d.ts +35 -0
  62. package/lib/device/constants.js +141 -0
  63. package/lib/device/index.d.ts +68 -0
  64. package/lib/device/index.js +332 -0
  65. package/lib/device/utils/HashMap.d.ts +24 -0
  66. package/lib/device/utils/HashMap.js +113 -0
  67. package/lib/device/utils/pipeline.d.ts +1 -0
  68. package/lib/device/utils/pipeline.js +30 -0
  69. package/lib/device/utils/typedarray.d.ts +7 -0
  70. package/lib/device/utils/typedarray.js +58 -0
  71. package/lib/device/utils/webgl.d.ts +1 -0
  72. package/lib/device/utils/webgl.js +34 -0
  73. package/lib/index.d.ts +3 -0
  74. package/lib/index.js +42 -0
  75. package/lib/regl/ReglAttribute.d.ts +16 -0
  76. package/lib/regl/ReglAttribute.js +49 -0
  77. package/lib/regl/ReglBuffer.d.ts +17 -0
  78. package/lib/regl/ReglBuffer.js +53 -0
  79. package/lib/regl/ReglElements.d.ts +14 -0
  80. package/lib/regl/ReglElements.js +47 -0
  81. package/lib/regl/ReglFramebuffer.d.ts +16 -0
  82. package/lib/regl/ReglFramebuffer.js +51 -0
  83. package/lib/regl/ReglModel.d.ts +46 -0
  84. package/lib/regl/ReglModel.js +311 -0
  85. package/lib/regl/ReglRenderbuffer.d.ts +16 -0
  86. package/lib/regl/ReglRenderbuffer.js +44 -0
  87. package/lib/regl/ReglTexture2D.d.ts +22 -0
  88. package/lib/regl/ReglTexture2D.js +107 -0
  89. package/lib/regl/constants.d.ts +43 -0
  90. package/lib/regl/constants.js +170 -0
  91. package/lib/regl/index.d.ts +56 -0
  92. package/lib/regl/index.js +256 -0
  93. package/package.json +4 -4
@@ -0,0 +1,13 @@
1
+ import type { Device } from '@antv/g-device-api';
2
+ import type { IAttribute, IAttributeInitializationOptions, IBuffer } from '@antv/l7-core';
3
+ export default class DeviceAttribute implements IAttribute {
4
+ private attribute;
5
+ private buffer;
6
+ constructor(device: Device, options: IAttributeInitializationOptions);
7
+ get(): IBuffer;
8
+ updateBuffer(options: {
9
+ data: number[] | number[][] | Uint8Array | Uint16Array | Uint32Array;
10
+ offset: number;
11
+ }): void;
12
+ destroy(): void;
13
+ }
@@ -0,0 +1,30 @@
1
+ // src/device/DeviceAttribute.ts
2
+ var DeviceAttribute = class {
3
+ constructor(device, options) {
4
+ const { buffer, offset, stride, normalized, size, divisor, shaderLocation } = options;
5
+ this.buffer = buffer;
6
+ this.attribute = {
7
+ shaderLocation,
8
+ buffer: buffer.get(),
9
+ offset: offset || 0,
10
+ stride: stride || 0,
11
+ normalized: normalized || false,
12
+ divisor: divisor || 0
13
+ };
14
+ if (size) {
15
+ this.attribute.size = size;
16
+ }
17
+ }
18
+ get() {
19
+ return this.buffer;
20
+ }
21
+ updateBuffer(options) {
22
+ this.buffer.subData(options);
23
+ }
24
+ destroy() {
25
+ this.buffer.destroy();
26
+ }
27
+ };
28
+ export {
29
+ DeviceAttribute as default
30
+ };
@@ -0,0 +1,18 @@
1
+ import type { Buffer, Device } from '@antv/g-device-api';
2
+ import type { IBuffer, IBufferInitializationOptions } from '@antv/l7-core';
3
+ /**
4
+ * Use Buffer from @antv/g-device-api
5
+ */
6
+ export default class DeviceBuffer implements IBuffer {
7
+ private buffer;
8
+ private isDestroyed;
9
+ private type;
10
+ private size;
11
+ constructor(device: Device, options: IBufferInitializationOptions);
12
+ get(): Buffer;
13
+ destroy(): void;
14
+ subData({ data, offset, }: {
15
+ data: number[] | number[][] | Uint8Array | Uint16Array | Uint32Array;
16
+ offset: number;
17
+ }): void;
18
+ }
@@ -0,0 +1,51 @@
1
+ // src/device/DeviceBuffer.ts
2
+ import { BufferUsage } from "@antv/g-device-api";
3
+ import { gl } from "@antv/l7-core";
4
+ import { hintMap, typedArrayCtorMap } from "./constants";
5
+ import { isTypedArray } from "./utils/typedarray";
6
+ var DeviceBuffer = class {
7
+ constructor(device, options) {
8
+ this.isDestroyed = false;
9
+ const { data, usage, type, isUBO, label } = options;
10
+ let typed;
11
+ if (isTypedArray(data)) {
12
+ typed = data;
13
+ } else {
14
+ typed = new typedArrayCtorMap[this.type || gl.FLOAT](data);
15
+ }
16
+ this.type = type;
17
+ this.size = typed.byteLength;
18
+ this.buffer = device.createBuffer({
19
+ viewOrSize: typed,
20
+ usage: isUBO ? BufferUsage.UNIFORM : BufferUsage.VERTEX,
21
+ hint: hintMap[usage || gl.STATIC_DRAW]
22
+ });
23
+ if (label) {
24
+ device.setResourceName(this.buffer, label);
25
+ }
26
+ }
27
+ get() {
28
+ return this.buffer;
29
+ }
30
+ destroy() {
31
+ if (!this.isDestroyed) {
32
+ this.buffer.destroy();
33
+ }
34
+ this.isDestroyed = true;
35
+ }
36
+ subData({
37
+ data,
38
+ offset
39
+ }) {
40
+ let typed;
41
+ if (isTypedArray(data)) {
42
+ typed = data;
43
+ } else {
44
+ typed = new typedArrayCtorMap[this.type || gl.FLOAT](data);
45
+ }
46
+ this.buffer.setSubData(offset, new Uint8Array(typed.buffer));
47
+ }
48
+ };
49
+ export {
50
+ DeviceBuffer as default
51
+ };
@@ -0,0 +1,14 @@
1
+ import type { Bindings, BindingsDescriptor, Device, InputLayout, InputLayoutDescriptor, Program, ProgramDescriptor, RenderPipeline, RenderPipelineDescriptor } from '@antv/g-device-api';
2
+ export declare class RenderCache {
3
+ private device;
4
+ constructor(device: Device);
5
+ private bindingsCache;
6
+ private renderPipelinesCache;
7
+ private inputLayoutsCache;
8
+ private programCache;
9
+ createBindings(descriptor: BindingsDescriptor): Bindings;
10
+ createRenderPipeline(descriptor: RenderPipelineDescriptor): RenderPipeline;
11
+ createInputLayout(descriptor: InputLayoutDescriptor): InputLayout;
12
+ createProgram(descriptor: ProgramDescriptor): Program;
13
+ destroy(): void;
14
+ }
@@ -0,0 +1,198 @@
1
+ // src/device/DeviceCache.ts
2
+ import {
3
+ TransparentBlack,
4
+ bindingsDescriptorCopy,
5
+ bindingsDescriptorEquals,
6
+ inputLayoutDescriptorCopy,
7
+ inputLayoutDescriptorEquals,
8
+ renderPipelineDescriptorCopy,
9
+ renderPipelineDescriptorEquals
10
+ } from "@antv/g-device-api";
11
+ import { HashMap, hashCodeNumberFinish, hashCodeNumberUpdate, nullHashFunc } from "./utils/HashMap";
12
+ function blendStateHash(hash, a) {
13
+ hash = hashCodeNumberUpdate(hash, a.blendMode);
14
+ hash = hashCodeNumberUpdate(hash, a.blendSrcFactor);
15
+ hash = hashCodeNumberUpdate(hash, a.blendDstFactor);
16
+ return hash;
17
+ }
18
+ function attachmentStateHash(hash, a) {
19
+ hash = blendStateHash(hash, a.rgbBlendState);
20
+ hash = blendStateHash(hash, a.alphaBlendState);
21
+ hash = hashCodeNumberUpdate(hash, a.channelWriteMask);
22
+ return hash;
23
+ }
24
+ function colorHash(hash, a) {
25
+ hash = hashCodeNumberUpdate(hash, a.r << 24 | a.g << 16 | a.b << 8 | a.a);
26
+ return hash;
27
+ }
28
+ function megaStateDescriptorHash(hash, a) {
29
+ var _a, _b, _c, _d, _e, _f, _g, _h;
30
+ for (let i = 0; i < a.attachmentsState.length; i++)
31
+ hash = attachmentStateHash(hash, a.attachmentsState[i]);
32
+ hash = colorHash(hash, a.blendConstant || TransparentBlack);
33
+ hash = hashCodeNumberUpdate(hash, a.depthCompare);
34
+ hash = hashCodeNumberUpdate(hash, a.depthWrite ? 1 : 0);
35
+ hash = hashCodeNumberUpdate(hash, (_a = a.stencilFront) == null ? void 0 : _a.compare);
36
+ hash = hashCodeNumberUpdate(hash, (_b = a.stencilFront) == null ? void 0 : _b.passOp);
37
+ hash = hashCodeNumberUpdate(hash, (_c = a.stencilFront) == null ? void 0 : _c.failOp);
38
+ hash = hashCodeNumberUpdate(hash, (_d = a.stencilFront) == null ? void 0 : _d.depthFailOp);
39
+ hash = hashCodeNumberUpdate(hash, (_e = a.stencilBack) == null ? void 0 : _e.compare);
40
+ hash = hashCodeNumberUpdate(hash, (_f = a.stencilBack) == null ? void 0 : _f.passOp);
41
+ hash = hashCodeNumberUpdate(hash, (_g = a.stencilBack) == null ? void 0 : _g.failOp);
42
+ hash = hashCodeNumberUpdate(hash, (_h = a.stencilBack) == null ? void 0 : _h.depthFailOp);
43
+ hash = hashCodeNumberUpdate(hash, a.stencilWrite ? 1 : 0);
44
+ hash = hashCodeNumberUpdate(hash, a.cullMode);
45
+ hash = hashCodeNumberUpdate(hash, a.frontFace ? 1 : 0);
46
+ hash = hashCodeNumberUpdate(hash, a.polygonOffset ? 1 : 0);
47
+ return hash;
48
+ }
49
+ function renderPipelineDescriptorHash(a) {
50
+ let hash = 0;
51
+ hash = hashCodeNumberUpdate(hash, a.program.id);
52
+ if (a.inputLayout !== null)
53
+ hash = hashCodeNumberUpdate(hash, a.inputLayout.id);
54
+ hash = megaStateDescriptorHash(hash, a.megaStateDescriptor);
55
+ for (let i = 0; i < a.colorAttachmentFormats.length; i++)
56
+ hash = hashCodeNumberUpdate(hash, a.colorAttachmentFormats[i] || 0);
57
+ hash = hashCodeNumberUpdate(hash, a.depthStencilAttachmentFormat || 0);
58
+ return hashCodeNumberFinish(hash);
59
+ }
60
+ function bindingsDescriptorHash(a) {
61
+ let hash = 0;
62
+ if (a.samplerBindings) {
63
+ for (let i = 0; i < a.samplerBindings.length; i++) {
64
+ const binding = a.samplerBindings[i];
65
+ if (binding !== null && binding.texture !== null)
66
+ hash = hashCodeNumberUpdate(hash, binding.texture.id);
67
+ }
68
+ }
69
+ if (a.uniformBufferBindings) {
70
+ for (let i = 0; i < a.uniformBufferBindings.length; i++) {
71
+ const binding = a.uniformBufferBindings[i];
72
+ if (binding !== null && binding.buffer !== null) {
73
+ hash = hashCodeNumberUpdate(hash, binding.buffer.id);
74
+ hash = hashCodeNumberUpdate(hash, binding.binding);
75
+ hash = hashCodeNumberUpdate(hash, binding.offset);
76
+ hash = hashCodeNumberUpdate(hash, binding.size);
77
+ }
78
+ }
79
+ }
80
+ if (a.storageBufferBindings) {
81
+ for (let i = 0; i < a.storageBufferBindings.length; i++) {
82
+ const binding = a.storageBufferBindings[i];
83
+ if (binding !== null && binding.buffer !== null) {
84
+ hash = hashCodeNumberUpdate(hash, binding.buffer.id);
85
+ hash = hashCodeNumberUpdate(hash, binding.binding);
86
+ hash = hashCodeNumberUpdate(hash, binding.offset);
87
+ hash = hashCodeNumberUpdate(hash, binding.size);
88
+ }
89
+ }
90
+ }
91
+ if (a.storageTextureBindings) {
92
+ for (let i = 0; i < a.storageTextureBindings.length; i++) {
93
+ const binding = a.storageTextureBindings[i];
94
+ if (binding !== null && binding.texture !== null) {
95
+ hash = hashCodeNumberUpdate(hash, binding.texture.id);
96
+ hash = hashCodeNumberUpdate(hash, binding.binding);
97
+ }
98
+ }
99
+ }
100
+ return hashCodeNumberFinish(hash);
101
+ }
102
+ function programDescriptorEquals(a, b) {
103
+ var _a, _b, _c, _d;
104
+ return ((_a = a.vertex) == null ? void 0 : _a.glsl) === ((_b = b.vertex) == null ? void 0 : _b.glsl) && ((_c = a.fragment) == null ? void 0 : _c.glsl) === ((_d = b.fragment) == null ? void 0 : _d.glsl);
105
+ }
106
+ function programDescriptorCopy(a) {
107
+ var _a, _b;
108
+ return {
109
+ vertex: {
110
+ glsl: (_a = a.vertex) == null ? void 0 : _a.glsl
111
+ },
112
+ fragment: {
113
+ glsl: (_b = a.fragment) == null ? void 0 : _b.glsl
114
+ }
115
+ };
116
+ }
117
+ var RenderCache = class {
118
+ constructor(device) {
119
+ this.device = device;
120
+ this.bindingsCache = new HashMap(
121
+ bindingsDescriptorEquals,
122
+ bindingsDescriptorHash
123
+ );
124
+ this.renderPipelinesCache = new HashMap(
125
+ renderPipelineDescriptorEquals,
126
+ renderPipelineDescriptorHash
127
+ );
128
+ this.inputLayoutsCache = new HashMap(
129
+ inputLayoutDescriptorEquals,
130
+ nullHashFunc
131
+ );
132
+ this.programCache = new HashMap(
133
+ programDescriptorEquals,
134
+ nullHashFunc
135
+ );
136
+ }
137
+ createBindings(descriptor) {
138
+ var _a;
139
+ let bindings = this.bindingsCache.get(descriptor);
140
+ if (bindings === null) {
141
+ const descriptorCopy = bindingsDescriptorCopy(descriptor);
142
+ descriptorCopy.uniformBufferBindings = (_a = descriptorCopy.uniformBufferBindings) == null ? void 0 : _a.filter(
143
+ ({ size }) => size && size > 0
144
+ );
145
+ bindings = this.device.createBindings(descriptorCopy);
146
+ this.bindingsCache.add(descriptorCopy, bindings);
147
+ }
148
+ return bindings;
149
+ }
150
+ createRenderPipeline(descriptor) {
151
+ let renderPipeline = this.renderPipelinesCache.get(descriptor);
152
+ if (renderPipeline === null) {
153
+ const descriptorCopy = renderPipelineDescriptorCopy(descriptor);
154
+ descriptorCopy.colorAttachmentFormats = descriptorCopy.colorAttachmentFormats.filter(
155
+ (f) => f
156
+ );
157
+ renderPipeline = this.device.createRenderPipeline(descriptorCopy);
158
+ this.renderPipelinesCache.add(descriptorCopy, renderPipeline);
159
+ }
160
+ return renderPipeline;
161
+ }
162
+ createInputLayout(descriptor) {
163
+ descriptor.vertexBufferDescriptors = descriptor.vertexBufferDescriptors.filter((d) => !!d);
164
+ let inputLayout = this.inputLayoutsCache.get(descriptor);
165
+ if (inputLayout === null) {
166
+ const descriptorCopy = inputLayoutDescriptorCopy(descriptor);
167
+ inputLayout = this.device.createInputLayout(descriptorCopy);
168
+ this.inputLayoutsCache.add(descriptorCopy, inputLayout);
169
+ }
170
+ return inputLayout;
171
+ }
172
+ createProgram(descriptor) {
173
+ let program = this.programCache.get(descriptor);
174
+ if (program === null) {
175
+ const descriptorCopy = programDescriptorCopy(descriptor);
176
+ program = this.device.createProgram(descriptor);
177
+ this.programCache.add(descriptorCopy, program);
178
+ }
179
+ return program;
180
+ }
181
+ destroy() {
182
+ for (const bindings of this.bindingsCache.values())
183
+ bindings.destroy();
184
+ for (const renderPipeline of this.renderPipelinesCache.values())
185
+ renderPipeline.destroy();
186
+ for (const inputLayout of this.inputLayoutsCache.values())
187
+ inputLayout.destroy();
188
+ for (const program of this.programCache.values())
189
+ program.destroy();
190
+ this.bindingsCache.clear();
191
+ this.renderPipelinesCache.clear();
192
+ this.inputLayoutsCache.clear();
193
+ this.programCache.clear();
194
+ }
195
+ };
196
+ export {
197
+ RenderCache
198
+ };
@@ -0,0 +1,13 @@
1
+ import type { Buffer, Device } from '@antv/g-device-api';
2
+ import type { IElements, IElementsInitializationOptions } from '@antv/l7-core';
3
+ export default class DeviceElements implements IElements {
4
+ private indexBuffer;
5
+ private type;
6
+ private count;
7
+ constructor(device: Device, options: IElementsInitializationOptions);
8
+ get(): Buffer;
9
+ subData({ data, }: {
10
+ data: number[] | number[][] | Uint8Array | Uint16Array | Uint32Array;
11
+ }): void;
12
+ destroy(): void;
13
+ }
@@ -0,0 +1,42 @@
1
+ // src/device/DeviceElements.ts
2
+ import { BufferUsage } from "@antv/g-device-api";
3
+ import { gl } from "@antv/l7-core";
4
+ import { typedArrayCtorMap } from "./constants";
5
+ import { isTypedArray } from "./utils/typedarray";
6
+ var DeviceElements = class {
7
+ constructor(device, options) {
8
+ const { data, type, count = 0 } = options;
9
+ let typed;
10
+ if (isTypedArray(data)) {
11
+ typed = data;
12
+ } else {
13
+ typed = new typedArrayCtorMap[this.type || gl.UNSIGNED_INT](data);
14
+ }
15
+ this.type = type;
16
+ this.count = count;
17
+ this.indexBuffer = device.createBuffer({
18
+ viewOrSize: typed,
19
+ usage: BufferUsage.INDEX
20
+ });
21
+ }
22
+ get() {
23
+ return this.indexBuffer;
24
+ }
25
+ subData({
26
+ data
27
+ }) {
28
+ let typed;
29
+ if (isTypedArray(data)) {
30
+ typed = data;
31
+ } else {
32
+ typed = new typedArrayCtorMap[this.type || gl.UNSIGNED_INT](data);
33
+ }
34
+ this.indexBuffer.setSubData(0, new Uint8Array(typed.buffer));
35
+ }
36
+ destroy() {
37
+ this.indexBuffer.destroy();
38
+ }
39
+ };
40
+ export {
41
+ DeviceElements as default
42
+ };
@@ -0,0 +1,24 @@
1
+ import type { Device, RenderTarget, Texture } from '@antv/g-device-api';
2
+ import type { IFramebuffer, IFramebufferInitializationOptions } from '@antv/l7-core';
3
+ /**
4
+ * Contains 2 render targets: color and depth.
5
+ */
6
+ export default class DeviceFramebuffer implements IFramebuffer {
7
+ private device;
8
+ private options;
9
+ private colorRenderTarget;
10
+ colorTexture: Texture;
11
+ private depthRenderTarget;
12
+ private depthTexture;
13
+ private width;
14
+ private height;
15
+ constructor(device: Device, options: IFramebufferInitializationOptions);
16
+ private createColorRenderTarget;
17
+ private createDepthRenderTarget;
18
+ get(): RenderTarget;
19
+ destroy(): void;
20
+ resize({ width, height }: {
21
+ width: number;
22
+ height: number;
23
+ }): void;
24
+ }
@@ -0,0 +1,81 @@
1
+ // src/device/DeviceFramebuffer.ts
2
+ import { Format, TextureUsage } from "@antv/g-device-api";
3
+ import { isTexture2D } from "./DeviceTexture2D";
4
+ var DeviceFramebuffer = class {
5
+ constructor(device, options) {
6
+ this.device = device;
7
+ this.options = options;
8
+ this.createColorRenderTarget();
9
+ this.createDepthRenderTarget();
10
+ }
11
+ createColorRenderTarget(resize = false) {
12
+ const { width, height, color } = this.options;
13
+ if (color) {
14
+ if (isTexture2D(color)) {
15
+ if (resize) {
16
+ color.resize({ width, height });
17
+ }
18
+ this.colorTexture = color.get();
19
+ this.colorRenderTarget = this.device.createRenderTargetFromTexture(this.colorTexture);
20
+ this.width = color["width"];
21
+ this.height = color["height"];
22
+ } else if (width && height) {
23
+ this.colorTexture = this.device.createTexture({
24
+ format: Format.U8_RGBA_RT,
25
+ usage: TextureUsage.RENDER_TARGET,
26
+ width,
27
+ height
28
+ });
29
+ this.colorRenderTarget = this.device.createRenderTargetFromTexture(this.colorTexture);
30
+ this.width = width;
31
+ this.height = height;
32
+ }
33
+ }
34
+ }
35
+ createDepthRenderTarget(resize = false) {
36
+ const { width, height, depth } = this.options;
37
+ if (depth) {
38
+ if (isTexture2D(depth)) {
39
+ if (resize) {
40
+ depth.resize({ width, height });
41
+ }
42
+ this.depthTexture = depth.get();
43
+ this.depthRenderTarget = this.device.createRenderTargetFromTexture(this.depthTexture);
44
+ this.width = depth["width"];
45
+ this.height = depth["height"];
46
+ } else if (width && height) {
47
+ this.depthTexture = this.device.createTexture({
48
+ format: Format.D24_S8,
49
+ usage: TextureUsage.RENDER_TARGET,
50
+ width,
51
+ height
52
+ });
53
+ this.depthRenderTarget = this.device.createRenderTargetFromTexture(this.depthTexture);
54
+ this.width = width;
55
+ this.height = height;
56
+ }
57
+ }
58
+ }
59
+ get() {
60
+ return this.colorRenderTarget;
61
+ }
62
+ destroy() {
63
+ var _a, _b;
64
+ (_a = this.colorRenderTarget) == null ? void 0 : _a.destroy();
65
+ (_b = this.depthRenderTarget) == null ? void 0 : _b.destroy();
66
+ }
67
+ resize({ width, height }) {
68
+ if (this.width !== width || this.height !== height) {
69
+ this.destroy();
70
+ this.colorTexture.destroyed = true;
71
+ this.depthTexture.destroyed = true;
72
+ this.options.width = width;
73
+ this.options.height = height;
74
+ this.createColorRenderTarget(true);
75
+ this.createDepthRenderTarget(true);
76
+ }
77
+ }
78
+ };
79
+ export {
80
+ DeviceFramebuffer as default
81
+ };
@@ -0,0 +1,61 @@
1
+ import type { Device } from '@antv/g-device-api';
2
+ import type { IModel, IModelDrawOptions, IModelInitializationOptions, IUniform } from '@antv/l7-core';
3
+ import type DeviceRendererService from '.';
4
+ export default class DeviceModel implements IModel {
5
+ private device;
6
+ private options;
7
+ private service;
8
+ private destroyed;
9
+ private uniforms;
10
+ private program;
11
+ private inputLayout;
12
+ private pipeline;
13
+ private indexBuffer;
14
+ private vertexBuffers;
15
+ private bindings;
16
+ private pipelineCache;
17
+ private currentPipelineKey;
18
+ constructor(device: Device, options: IModelInitializationOptions, service: DeviceRendererService);
19
+ /**
20
+ * 生成 Pipeline 缓存键,用于判断是否需要重新创建 Pipeline
21
+ * 包含所有影响 Pipeline 创建的参数
22
+ * 注意:当 blend/stencil 禁用时,使用简化的 key 以避免创建重复 Pipeline
23
+ */
24
+ private getPipelineKey;
25
+ private createPipeline;
26
+ updateAttributesAndElements(): void;
27
+ /**
28
+ * No need to implement this method, you should update data on `Attribute` like this:
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * attribute.updateBuffer({
33
+ * data: [],
34
+ * offset: 0,
35
+ * });
36
+ * ```
37
+ */
38
+ updateAttributes(): void;
39
+ addUniforms(uniforms: {
40
+ [key: string]: IUniform;
41
+ }): void;
42
+ draw(options: IModelDrawOptions, pick?: boolean): void;
43
+ destroy(): void;
44
+ private initDepthDrawParams;
45
+ private getBlendDrawParams;
46
+ /**
47
+ * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#stencil
48
+ */
49
+ private getStencilDrawParams;
50
+ /**
51
+ * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#culling
52
+ */
53
+ private initCullDrawParams;
54
+ /**
55
+ * 考虑结构体命名, eg:
56
+ * a: { b: 1 } -> 'a.b'
57
+ * a: [ { b: 1 } ] -> 'a[0].b'
58
+ */
59
+ private extractUniforms;
60
+ private extractUniformsRecursively;
61
+ }