@luma.gl/engine 8.6.0-alpha.4 → 9.0.0-alpha.4

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 (129) hide show
  1. package/dist/animation/key-frames.d.ts +1 -0
  2. package/dist/animation/key-frames.d.ts.map +1 -1
  3. package/dist/animation/key-frames.js.map +1 -1
  4. package/dist/animation/timeline.d.ts +1 -1
  5. package/dist/animation/timeline.d.ts.map +1 -1
  6. package/dist/animation/timeline.js.map +1 -1
  7. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  8. package/dist/geometries/cone-geometry.js +1 -1
  9. package/dist/geometries/cone-geometry.js.map +1 -1
  10. package/dist/geometries/cube-geometry.d.ts +4 -0
  11. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  12. package/dist/geometries/cube-geometry.js +30 -7
  13. package/dist/geometries/cube-geometry.js.map +1 -1
  14. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  15. package/dist/geometries/cylinder-geometry.js +1 -1
  16. package/dist/geometries/cylinder-geometry.js.map +1 -1
  17. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  18. package/dist/geometries/ico-sphere-geometry.js +1 -1
  19. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  20. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  21. package/dist/geometries/plane-geometry.js +1 -1
  22. package/dist/geometries/plane-geometry.js.map +1 -1
  23. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  24. package/dist/geometries/sphere-geometry.js +1 -1
  25. package/dist/geometries/sphere-geometry.js.map +1 -1
  26. package/dist/geometries/truncated-cone-geometry.d.ts +15 -3
  27. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  28. package/dist/geometries/truncated-cone-geometry.js +29 -15
  29. package/dist/geometries/truncated-cone-geometry.js.map +1 -1
  30. package/dist/geometry/geometry-table.d.ts +15 -0
  31. package/dist/geometry/geometry-table.d.ts.map +1 -0
  32. package/dist/geometry/geometry-table.js +2 -0
  33. package/dist/{transform/transform-types.js.map → geometry/geometry-table.js.map} +1 -1
  34. package/dist/geometry/geometry-utils.js.map +1 -1
  35. package/dist/geometry/geometry.d.ts +34 -7
  36. package/dist/geometry/geometry.d.ts.map +1 -1
  37. package/dist/geometry/geometry.js +33 -11
  38. package/dist/geometry/geometry.js.map +1 -1
  39. package/dist/geometry/primitive-utils.d.ts +1 -0
  40. package/dist/geometry/primitive-utils.d.ts.map +1 -0
  41. package/dist/geometry/primitive-utils.js +2 -0
  42. package/dist/geometry/primitive-utils.js.map +1 -0
  43. package/dist/index.d.ts +3 -5
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +1 -4
  46. package/dist/index.js.map +1 -1
  47. package/dist/lib/animation-loop.d.ts +14 -73
  48. package/dist/lib/animation-loop.d.ts.map +1 -1
  49. package/dist/lib/animation-loop.js +39 -160
  50. package/dist/lib/animation-loop.js.map +1 -1
  51. package/dist/lib/animation-props.d.ts +24 -0
  52. package/dist/lib/animation-props.d.ts.map +1 -0
  53. package/dist/lib/animation-props.js +2 -0
  54. package/dist/lib/animation-props.js.map +1 -0
  55. package/dist/lib/clip-space.d.ts +1 -0
  56. package/dist/lib/clip-space.d.ts.map +1 -0
  57. package/dist/lib/clip-space.js +2 -0
  58. package/dist/lib/clip-space.js.map +1 -0
  59. package/dist/lib/model-utils.d.ts +4 -3
  60. package/dist/lib/model-utils.d.ts.map +1 -1
  61. package/dist/lib/model-utils.js +24 -70
  62. package/dist/lib/model-utils.js.map +1 -1
  63. package/dist/lib/model.d.ts +34 -104
  64. package/dist/lib/model.d.ts.map +1 -1
  65. package/dist/lib/model.js +108 -505
  66. package/dist/lib/model.js.map +1 -1
  67. package/dist/lib/pipeline-factory.d.ts +55 -0
  68. package/dist/lib/pipeline-factory.d.ts.map +1 -0
  69. package/dist/lib/pipeline-factory.js +191 -0
  70. package/dist/lib/pipeline-factory.js.map +1 -0
  71. package/dist/lib/render-loop.d.ts +4 -17
  72. package/dist/lib/render-loop.d.ts.map +1 -1
  73. package/dist/lib/render-loop.js +14 -21
  74. package/dist/lib/render-loop.js.map +1 -1
  75. package/package.json +5 -5
  76. package/src/animation/key-frames.ts +1 -0
  77. package/src/animation/timeline.ts +1 -1
  78. package/src/geometries/cone-geometry.ts +1 -1
  79. package/src/geometries/cube-geometry.ts +159 -8
  80. package/src/geometries/cylinder-geometry.ts +1 -1
  81. package/src/geometries/ico-sphere-geometry.ts +1 -1
  82. package/src/geometries/plane-geometry.ts +1 -1
  83. package/src/geometries/sphere-geometry.ts +2 -2
  84. package/src/geometries/truncated-cone-geometry.ts +30 -12
  85. package/src/geometry/geometry-table.ts +16 -0
  86. package/src/geometry/geometry-utils.ts +1 -1
  87. package/src/geometry/geometry.ts +58 -13
  88. package/src/geometry/primitive-utils.ts +30 -0
  89. package/src/index.ts +7 -8
  90. package/src/lib/animation-loop.ts +85 -274
  91. package/src/lib/animation-props.ts +31 -0
  92. package/src/{utils → lib}/clip-space.ts +5 -2
  93. package/src/lib/model-utils.ts +60 -32
  94. package/src/lib/model.ts +126 -642
  95. package/src/lib/pipeline-factory.ts +225 -0
  96. package/src/lib/render-loop.ts +21 -19
  97. package/dist/lib/program-manager.d.ts +0 -39
  98. package/dist/lib/program-manager.d.ts.map +0 -1
  99. package/dist/lib/program-manager.js +0 -175
  100. package/dist/lib/program-manager.js.map +0 -1
  101. package/dist/transform/buffer-transform.d.ts +0 -36
  102. package/dist/transform/buffer-transform.d.ts.map +0 -1
  103. package/dist/transform/buffer-transform.js +0 -255
  104. package/dist/transform/buffer-transform.js.map +0 -1
  105. package/dist/transform/texture-transform.d.ts +0 -57
  106. package/dist/transform/texture-transform.d.ts.map +0 -1
  107. package/dist/transform/texture-transform.js +0 -412
  108. package/dist/transform/texture-transform.js.map +0 -1
  109. package/dist/transform/transform-shader-utils.d.ts +0 -26
  110. package/dist/transform/transform-shader-utils.d.ts.map +0 -1
  111. package/dist/transform/transform-shader-utils.js +0 -149
  112. package/dist/transform/transform-shader-utils.js.map +0 -1
  113. package/dist/transform/transform-types.d.ts +0 -44
  114. package/dist/transform/transform-types.d.ts.map +0 -1
  115. package/dist/transform/transform-types.js +0 -2
  116. package/dist/transform/transform.d.ts +0 -47
  117. package/dist/transform/transform.d.ts.map +0 -1
  118. package/dist/transform/transform.js +0 -198
  119. package/dist/transform/transform.js.map +0 -1
  120. package/dist/utils/clip-space.d.ts +0 -5
  121. package/dist/utils/clip-space.d.ts.map +0 -1
  122. package/dist/utils/clip-space.js +0 -34
  123. package/dist/utils/clip-space.js.map +0 -1
  124. package/src/lib/program-manager.ts +0 -187
  125. package/src/transform/buffer-transform.ts +0 -214
  126. package/src/transform/texture-transform.ts +0 -344
  127. package/src/transform/transform-shader-utils.ts +0 -169
  128. package/src/transform/transform-types.ts +0 -42
  129. package/src/transform/transform.ts +0 -189
@@ -1,412 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import GL from '@luma.gl/constants';
3
- import { cloneTextureFrom, readPixelsToArray, Buffer, Texture2D, Framebuffer } from '@luma.gl/webgl';
4
- import { _transform as transformModule, getShaderInfo, getPassthroughFS, typeToChannelCount, combineInjects } from '@luma.gl/shadertools';
5
- import { updateForTextures, getSizeUniforms } from './transform-shader-utils';
6
- const SRC_TEX_PARAMETER_OVERRIDES = {
7
- [GL.TEXTURE_MIN_FILTER]: GL.NEAREST,
8
- [GL.TEXTURE_MAG_FILTER]: GL.NEAREST,
9
- [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
10
- [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
11
- };
12
- const FS_OUTPUT_VARIABLE = 'transform_output';
13
- export default class TextureTransform {
14
- constructor(gl, props = {}) {
15
- _defineProperty(this, "gl", void 0);
16
-
17
- _defineProperty(this, "id", 0);
18
-
19
- _defineProperty(this, "currentIndex", 0);
20
-
21
- _defineProperty(this, "_swapTexture", null);
22
-
23
- _defineProperty(this, "targetTextureVarying", null);
24
-
25
- _defineProperty(this, "targetTextureType", null);
26
-
27
- _defineProperty(this, "samplerTextureMap", null);
28
-
29
- _defineProperty(this, "bindings", []);
30
-
31
- _defineProperty(this, "resources", {});
32
-
33
- _defineProperty(this, "hasTargetTexture", false);
34
-
35
- _defineProperty(this, "hasSourceTextures", false);
36
-
37
- _defineProperty(this, "ownTexture", null);
38
-
39
- _defineProperty(this, "elementIDBuffer", null);
40
-
41
- _defineProperty(this, "_targetRefTexName", void 0);
42
-
43
- _defineProperty(this, "elementCount", void 0);
44
-
45
- this.gl = gl;
46
- this.id = this.currentIndex = 0;
47
- this._swapTexture = null;
48
- this.targetTextureVarying = null;
49
- this.targetTextureType = null;
50
- this.samplerTextureMap = null;
51
- this.bindings = [];
52
- this.resources = {};
53
-
54
- this._initialize(props);
55
-
56
- Object.seal(this);
57
- }
58
-
59
- updateModelProps(props = {}) {
60
- const updatedModelProps = this._processVertexShader(props);
61
-
62
- return Object.assign({}, props, updatedModelProps);
63
- }
64
-
65
- getDrawOptions(opts = {}) {
66
- const {
67
- sourceBuffers,
68
- sourceTextures,
69
- framebuffer,
70
- targetTexture
71
- } = this.bindings[this.currentIndex];
72
- const attributes = Object.assign({}, sourceBuffers, opts.attributes);
73
- const uniforms = Object.assign({}, opts.uniforms);
74
- const parameters = Object.assign({}, opts.parameters);
75
- let discard = opts.discard;
76
-
77
- if (this.hasSourceTextures || this.hasTargetTexture) {
78
- attributes.transform_elementID = this.elementIDBuffer;
79
-
80
- for (const sampler in this.samplerTextureMap) {
81
- const textureName = this.samplerTextureMap[sampler];
82
- uniforms[sampler] = sourceTextures[textureName];
83
- }
84
-
85
- this._setSourceTextureParameters();
86
-
87
- const sizeUniforms = getSizeUniforms({
88
- sourceTextureMap: sourceTextures,
89
- targetTextureVarying: this.targetTextureVarying,
90
- targetTexture
91
- });
92
- Object.assign(uniforms, sizeUniforms);
93
- }
94
-
95
- if (this.hasTargetTexture) {
96
- discard = false;
97
- parameters.viewport = [0, 0, framebuffer.width, framebuffer.height];
98
- }
99
-
100
- return {
101
- attributes,
102
- framebuffer,
103
- uniforms,
104
- discard,
105
- parameters
106
- };
107
- }
108
-
109
- swap() {
110
- if (this._swapTexture) {
111
- this.currentIndex = this._getNextIndex();
112
- return true;
113
- }
114
-
115
- return false;
116
- }
117
-
118
- update(opts = {}) {
119
- this._setupTextures(opts);
120
- }
121
-
122
- getTargetTexture() {
123
- const {
124
- targetTexture
125
- } = this.bindings[this.currentIndex];
126
- return targetTexture;
127
- }
128
-
129
- getData({
130
- packed = false
131
- } = {}) {
132
- const {
133
- framebuffer
134
- } = this.bindings[this.currentIndex];
135
- const pixels = readPixelsToArray(framebuffer);
136
-
137
- if (!packed) {
138
- return pixels;
139
- }
140
-
141
- const ArrayType = pixels.constructor;
142
- const channelCount = typeToChannelCount(this.targetTextureType);
143
- const packedPixels = new ArrayType(pixels.length * channelCount / 4);
144
- let packCount = 0;
145
-
146
- for (let i = 0; i < pixels.length; i += 4) {
147
- for (let j = 0; j < channelCount; j++) {
148
- packedPixels[packCount++] = pixels[i + j];
149
- }
150
- }
151
-
152
- return packedPixels;
153
- }
154
-
155
- getFramebuffer() {
156
- const currentResources = this.bindings[this.currentIndex];
157
- return currentResources.framebuffer;
158
- }
159
-
160
- delete() {
161
- if (this.ownTexture) {
162
- this.ownTexture.delete();
163
- }
164
-
165
- if (this.elementIDBuffer) {
166
- this.elementIDBuffer.delete();
167
- }
168
- }
169
-
170
- _initialize(props = {}) {
171
- const {
172
- _targetTextureVarying,
173
- _swapTexture
174
- } = props;
175
- this._swapTexture = _swapTexture;
176
- this.targetTextureVarying = _targetTextureVarying;
177
- this.hasTargetTexture = Boolean(_targetTextureVarying);
178
-
179
- this._setupTextures(props);
180
- }
181
-
182
- _createTargetTexture(props) {
183
- const {
184
- sourceTextures,
185
- textureOrReference
186
- } = props;
187
-
188
- if (textureOrReference instanceof Texture2D) {
189
- return textureOrReference;
190
- }
191
-
192
- const refTexture = sourceTextures[textureOrReference];
193
-
194
- if (!refTexture) {
195
- return null;
196
- }
197
-
198
- this._targetRefTexName = textureOrReference;
199
- return this._createNewTexture(refTexture);
200
- }
201
-
202
- _setupTextures(props = {}) {
203
- const {
204
- sourceBuffers,
205
- _sourceTextures = {},
206
- _targetTexture
207
- } = props;
208
-
209
- const targetTexture = this._createTargetTexture({
210
- sourceTextures: _sourceTextures,
211
- textureOrReference: _targetTexture
212
- });
213
-
214
- this.hasSourceTextures = this.hasSourceTextures || _sourceTextures && Object.keys(_sourceTextures).length > 0;
215
-
216
- this._updateBindings({
217
- sourceBuffers,
218
- sourceTextures: _sourceTextures,
219
- targetTexture
220
- });
221
-
222
- if ('elementCount' in props) {
223
- this._updateElementIDBuffer(props.elementCount);
224
- }
225
- }
226
-
227
- _updateElementIDBuffer(elementCount) {
228
- if (typeof elementCount !== 'number' || this.elementCount >= elementCount) {
229
- return;
230
- }
231
-
232
- const elementIds = new Float32Array(elementCount);
233
- elementIds.forEach((_, index, array) => {
234
- array[index] = index;
235
- });
236
-
237
- if (!this.elementIDBuffer) {
238
- this.elementIDBuffer = new Buffer(this.gl, {
239
- data: elementIds,
240
- accessor: {
241
- size: 1
242
- }
243
- });
244
- } else {
245
- this.elementIDBuffer.setData({
246
- data: elementIds
247
- });
248
- }
249
-
250
- this.elementCount = elementCount;
251
- }
252
-
253
- _updateBindings(opts) {
254
- this.bindings[this.currentIndex] = this._updateBinding(this.bindings[this.currentIndex], opts);
255
-
256
- if (this._swapTexture) {
257
- const {
258
- sourceTextures,
259
- targetTexture
260
- } = this._swapTextures(this.bindings[this.currentIndex]);
261
-
262
- const nextIndex = this._getNextIndex();
263
-
264
- this.bindings[nextIndex] = this._updateBinding(this.bindings[nextIndex], {
265
- sourceTextures,
266
- targetTexture
267
- });
268
- }
269
- }
270
-
271
- _updateBinding(binding, opts) {
272
- const {
273
- sourceBuffers,
274
- sourceTextures,
275
- targetTexture
276
- } = opts;
277
-
278
- if (!binding) {
279
- binding = {
280
- sourceBuffers: {},
281
- sourceTextures: {},
282
- targetTexture: null
283
- };
284
- }
285
-
286
- Object.assign(binding.sourceTextures, sourceTextures);
287
- Object.assign(binding.sourceBuffers, sourceBuffers);
288
-
289
- if (targetTexture) {
290
- binding.targetTexture = targetTexture;
291
- const {
292
- width,
293
- height
294
- } = targetTexture;
295
- const {
296
- framebuffer
297
- } = binding;
298
-
299
- if (framebuffer) {
300
- framebuffer.update({
301
- attachments: {
302
- [GL.COLOR_ATTACHMENT0]: targetTexture
303
- },
304
- resizeAttachments: false
305
- });
306
- framebuffer.resize({
307
- width,
308
- height
309
- });
310
- } else {
311
- binding.framebuffer = new Framebuffer(this.gl, {
312
- id: "transform-framebuffer",
313
- width,
314
- height,
315
- attachments: {
316
- [GL.COLOR_ATTACHMENT0]: targetTexture
317
- }
318
- });
319
- }
320
- }
321
-
322
- return binding;
323
- }
324
-
325
- _setSourceTextureParameters() {
326
- const index = this.currentIndex;
327
- const {
328
- sourceTextures
329
- } = this.bindings[index];
330
-
331
- for (const name in sourceTextures) {
332
- sourceTextures[name].setParameters(SRC_TEX_PARAMETER_OVERRIDES);
333
- }
334
- }
335
-
336
- _swapTextures(opts) {
337
- if (!this._swapTexture) {
338
- return null;
339
- }
340
-
341
- const sourceTextures = Object.assign({}, opts.sourceTextures);
342
- sourceTextures[this._swapTexture] = opts.targetTexture;
343
- const targetTexture = opts.sourceTextures[this._swapTexture];
344
- return {
345
- sourceTextures,
346
- targetTexture
347
- };
348
- }
349
-
350
- _createNewTexture(refTexture) {
351
- const texture = cloneTextureFrom(refTexture, {
352
- parameters: {
353
- [GL.TEXTURE_MIN_FILTER]: GL.NEAREST,
354
- [GL.TEXTURE_MAG_FILTER]: GL.NEAREST,
355
- [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
356
- [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
357
- },
358
- pixelStore: {
359
- [GL.UNPACK_FLIP_Y_WEBGL]: false
360
- }
361
- });
362
-
363
- if (this.ownTexture) {
364
- this.ownTexture.delete();
365
- }
366
-
367
- this.ownTexture = texture;
368
- return texture;
369
- }
370
-
371
- _getNextIndex() {
372
- return (this.currentIndex + 1) % 2;
373
- }
374
-
375
- _processVertexShader(props = {}) {
376
- const {
377
- sourceTextures,
378
- targetTexture
379
- } = this.bindings[this.currentIndex];
380
- const {
381
- vs,
382
- uniforms,
383
- targetTextureType,
384
- inject,
385
- samplerTextureMap
386
- } = updateForTextures({
387
- vs: props.vs,
388
- sourceTextureMap: sourceTextures,
389
- targetTextureVarying: this.targetTextureVarying,
390
- targetTexture
391
- });
392
- const combinedInject = combineInjects([props.inject || {}, inject]);
393
- this.targetTextureType = targetTextureType;
394
- this.samplerTextureMap = samplerTextureMap;
395
- const fs = props._fs || getPassthroughFS({
396
- version: getShaderInfo(vs).version,
397
- input: this.targetTextureVarying,
398
- inputType: targetTextureType,
399
- output: FS_OUTPUT_VARIABLE
400
- });
401
- const modules = this.hasSourceTextures || this.targetTextureVarying ? [transformModule].concat(props.modules || []) : props.modules;
402
- return {
403
- vs,
404
- fs,
405
- modules,
406
- uniforms,
407
- inject: combinedInject
408
- };
409
- }
410
-
411
- }
412
- //# sourceMappingURL=texture-transform.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/transform/texture-transform.ts"],"names":["GL","cloneTextureFrom","readPixelsToArray","Buffer","Texture2D","Framebuffer","_transform","transformModule","getShaderInfo","getPassthroughFS","typeToChannelCount","combineInjects","updateForTextures","getSizeUniforms","SRC_TEX_PARAMETER_OVERRIDES","TEXTURE_MIN_FILTER","NEAREST","TEXTURE_MAG_FILTER","TEXTURE_WRAP_S","CLAMP_TO_EDGE","TEXTURE_WRAP_T","FS_OUTPUT_VARIABLE","TextureTransform","constructor","gl","props","id","currentIndex","_swapTexture","targetTextureVarying","targetTextureType","samplerTextureMap","bindings","resources","_initialize","Object","seal","updateModelProps","updatedModelProps","_processVertexShader","assign","getDrawOptions","opts","sourceBuffers","sourceTextures","framebuffer","targetTexture","attributes","uniforms","parameters","discard","hasSourceTextures","hasTargetTexture","transform_elementID","elementIDBuffer","sampler","textureName","_setSourceTextureParameters","sizeUniforms","sourceTextureMap","viewport","width","height","swap","_getNextIndex","update","_setupTextures","getTargetTexture","getData","packed","pixels","ArrayType","channelCount","packedPixels","length","packCount","i","j","getFramebuffer","currentResources","delete","ownTexture","_targetTextureVarying","Boolean","_createTargetTexture","textureOrReference","refTexture","_targetRefTexName","_createNewTexture","_sourceTextures","_targetTexture","keys","_updateBindings","_updateElementIDBuffer","elementCount","elementIds","Float32Array","forEach","_","index","array","data","accessor","size","setData","_updateBinding","_swapTextures","nextIndex","binding","attachments","COLOR_ATTACHMENT0","resizeAttachments","resize","name","setParameters","texture","pixelStore","UNPACK_FLIP_Y_WEBGL","vs","inject","combinedInject","fs","_fs","version","input","inputType","output","modules","concat"],"mappings":";AAAA,OAAOA,EAAP,MAAe,oBAAf;AAEA,SAAQC,gBAAR,EAA0BC,iBAA1B,EAA6CC,MAA7C,EAAqDC,SAArD,EAAgEC,WAAhE,QAAkF,gBAAlF;AAEA,SACEC,UAAU,IAAIC,eADhB,EAEEC,aAFF,EAGEC,gBAHF,EAIEC,kBAJF,EAKEC,cALF,QAMO,sBANP;AAQA,SAAQC,iBAAR,EAA2BC,eAA3B,QAAiD,0BAAjD;AAMA,MAAMC,2BAA2B,GAAG;AAClC,GAACd,EAAE,CAACe,kBAAJ,GAAyBf,EAAE,CAACgB,OADM;AAElC,GAAChB,EAAE,CAACiB,kBAAJ,GAAyBjB,EAAE,CAACgB,OAFM;AAGlC,GAAChB,EAAE,CAACkB,cAAJ,GAAqBlB,EAAE,CAACmB,aAHU;AAIlC,GAACnB,EAAE,CAACoB,cAAJ,GAAqBpB,EAAE,CAACmB;AAJU,CAApC;AAMA,MAAME,kBAAkB,GAAG,kBAA3B;AAEA,eAAe,MAAMC,gBAAN,CAAuB;AAkBpCC,EAAAA,WAAW,CAACC,EAAD,EAA6BC,KAAqB,GAAG,EAArD,EAAyD;AAAA;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ACAjH,gBAAgB,CAAC;AACfkH,MAAAA,OAAO,EAAEnH,aAAa,CAAC8G,EAAD,CAAb,CAAkBK,OADZ;AAEfC,MAAAA,KAAK,EAAE,KAAK/F,oBAFG;AAGfgG,MAAAA,SAAS,EAAE/F,iBAHI;AAIfgG,MAAAA,MAAM,EAAEzG;AAJO,KAAD,CAFlB;AAQA,UAAM0G,OAAO,GACX,KAAK5E,iBAAL,IAA0B,KAAKtB,oBAA/B,GAEI,CAACtB,eAAD,EAAkByH,MAAlB,CAAyBvG,KAAK,CAACsG,OAAN,IAAiB,EAA1C,CAFJ,GAGItG,KAAK,CAACsG,OAJZ;AAKA,WAAO;AAACT,MAAAA,EAAD;AAAKG,MAAAA,EAAL;AAASM,MAAAA,OAAT;AAAkB/E,MAAAA,QAAlB;AAA4BuE,MAAAA,MAAM,EAAEC;AAApC,KAAP;AACD;;AA5TmC","sourcesContent":["import GL from '@luma.gl/constants';\n\nimport {cloneTextureFrom, readPixelsToArray, Buffer, Texture2D, Framebuffer} from '@luma.gl/webgl';\n\nimport {\n _transform as transformModule,\n getShaderInfo,\n getPassthroughFS,\n typeToChannelCount,\n combineInjects\n} from '@luma.gl/shadertools';\n\nimport {updateForTextures, getSizeUniforms} from './transform-shader-utils';\n\nimport type {TransformProps, TransformDrawOptions} from './transform-types';\n\n// TODO: move these constants to transform-shader-utils\n// Texture parameters needed so sample can precisely pick pixel for given element id.\nconst SRC_TEX_PARAMETER_OVERRIDES = {\n [GL.TEXTURE_MIN_FILTER]: GL.NEAREST,\n [GL.TEXTURE_MAG_FILTER]: GL.NEAREST,\n [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,\n [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE\n};\nconst FS_OUTPUT_VARIABLE = 'transform_output';\n\nexport default class TextureTransform {\n gl: WebGL2RenderingContext;\n id = 0;\n currentIndex = 0;\n _swapTexture = null;\n targetTextureVarying = null;\n targetTextureType = null;\n samplerTextureMap = null;\n bindings = []; // each element is an object : {sourceTextures, targetTexture, framebuffer}\n resources = {}; // resources to be deleted\n\n hasTargetTexture: boolean = false;\n hasSourceTextures: boolean = false;\n ownTexture: Texture2D | null = null;\n elementIDBuffer: Buffer | null = null;\n _targetRefTexName: string;\n elementCount: number;\n\n constructor(gl: WebGL2RenderingContext, props: TransformProps = {}) {\n this.gl = gl;\n this.id = this.currentIndex = 0;\n this._swapTexture = null;\n this.targetTextureVarying = null;\n this.targetTextureType = null;\n this.samplerTextureMap = null;\n this.bindings = []; // each element is an object : {sourceTextures, targetTexture, framebuffer}\n\n this.resources = {}; // resources to be deleted\n\n this._initialize(props);\n Object.seal(this);\n }\n\n updateModelProps(props: TransformProps = {}) {\n const updatedModelProps = this._processVertexShader(props);\n return Object.assign({}, props, updatedModelProps);\n }\n\n getDrawOptions(opts: TransformProps = {}): TransformDrawOptions {\n const {sourceBuffers, sourceTextures, framebuffer, targetTexture} =\n this.bindings[this.currentIndex];\n\n const attributes = Object.assign({}, sourceBuffers, opts.attributes);\n const uniforms = Object.assign({}, opts.uniforms);\n const parameters = Object.assign({}, opts.parameters);\n let discard = opts.discard;\n\n if (this.hasSourceTextures || this.hasTargetTexture) {\n attributes.transform_elementID = this.elementIDBuffer;\n\n for (const sampler in this.samplerTextureMap) {\n const textureName = this.samplerTextureMap[sampler];\n uniforms[sampler] = sourceTextures[textureName];\n }\n this._setSourceTextureParameters();\n // get texture size uniforms\n const sizeUniforms = getSizeUniforms({\n sourceTextureMap: sourceTextures,\n targetTextureVarying: this.targetTextureVarying,\n targetTexture\n });\n Object.assign(uniforms, sizeUniforms);\n }\n if (this.hasTargetTexture) {\n discard = false;\n parameters.viewport = [0, 0, framebuffer.width, framebuffer.height];\n }\n\n return {attributes, framebuffer, uniforms, discard, parameters};\n }\n\n swap() {\n if (this._swapTexture) {\n this.currentIndex = this._getNextIndex();\n return true;\n }\n return false;\n }\n\n // update source and/or feedbackBuffers\n update(opts = {}) {\n this._setupTextures(opts);\n }\n\n // returns current target texture\n getTargetTexture() {\n const {targetTexture} = this.bindings[this.currentIndex];\n return targetTexture;\n }\n\n getData({packed = false} = {}) {\n const {framebuffer} = this.bindings[this.currentIndex];\n const pixels = readPixelsToArray(framebuffer);\n\n if (!packed) {\n return pixels;\n }\n\n // readPixels returns 4 elements for each pixel, pack the elements when requested\n const ArrayType = pixels.constructor;\n const channelCount = typeToChannelCount(this.targetTextureType);\n // @ts-expect-error\n const packedPixels = new ArrayType((pixels.length * channelCount) / 4);\n let packCount = 0;\n for (let i = 0; i < pixels.length; i += 4) {\n for (let j = 0; j < channelCount; j++) {\n packedPixels[packCount++] = pixels[i + j];\n }\n }\n return packedPixels;\n }\n\n // returns current framebuffer object that is being used.\n getFramebuffer() {\n const currentResources = this.bindings[this.currentIndex];\n return currentResources.framebuffer;\n }\n\n // Delete owned resources.\n delete() {\n if (this.ownTexture) {\n this.ownTexture.delete();\n }\n if (this.elementIDBuffer) {\n this.elementIDBuffer.delete();\n }\n }\n\n // Private\n\n _initialize(props: TransformProps = {}) {\n const {_targetTextureVarying, _swapTexture} = props;\n this._swapTexture = _swapTexture;\n this.targetTextureVarying = _targetTextureVarying;\n this.hasTargetTexture = Boolean(_targetTextureVarying);\n this._setupTextures(props);\n }\n\n // auto create target texture if requested\n _createTargetTexture(props) {\n const {sourceTextures, textureOrReference} = props;\n if (textureOrReference instanceof Texture2D) {\n return textureOrReference;\n }\n // 'targetTexture' is a reference souce texture.\n const refTexture = sourceTextures[textureOrReference];\n if (!refTexture) {\n return null;\n }\n\n // save reference texture name, when corresponding source texture is updated\n // we also update target texture.\n this._targetRefTexName = textureOrReference;\n\n return this._createNewTexture(refTexture);\n }\n\n _setupTextures(props: TransformProps = {}) {\n const {sourceBuffers, _sourceTextures = {}, _targetTexture} = props;\n const targetTexture = this._createTargetTexture({\n sourceTextures: _sourceTextures,\n textureOrReference: _targetTexture\n });\n this.hasSourceTextures =\n this.hasSourceTextures || (_sourceTextures && Object.keys(_sourceTextures).length > 0);\n this._updateBindings({sourceBuffers, sourceTextures: _sourceTextures, targetTexture});\n if ('elementCount' in props) {\n this._updateElementIDBuffer(props.elementCount);\n }\n }\n\n _updateElementIDBuffer(elementCount: number): void {\n if (typeof elementCount !== 'number' || this.elementCount >= elementCount) {\n return;\n }\n // NOTE: using float so this will work with GLSL 1.0 shaders.\n const elementIds = new Float32Array(elementCount);\n elementIds.forEach((_, index, array) => {\n array[index] = index;\n });\n if (!this.elementIDBuffer) {\n this.elementIDBuffer = new Buffer(this.gl, {\n data: elementIds,\n accessor: {size: 1}\n });\n } else {\n this.elementIDBuffer.setData({data: elementIds});\n }\n this.elementCount = elementCount;\n }\n\n _updateBindings(opts) {\n this.bindings[this.currentIndex] = this._updateBinding(this.bindings[this.currentIndex], opts);\n if (this._swapTexture) {\n const {sourceTextures, targetTexture} = this._swapTextures(this.bindings[this.currentIndex]);\n const nextIndex = this._getNextIndex();\n this.bindings[nextIndex] = this._updateBinding(this.bindings[nextIndex], {\n sourceTextures,\n targetTexture\n });\n }\n }\n\n _updateBinding(binding, opts) {\n const {sourceBuffers, sourceTextures, targetTexture} = opts;\n if (!binding) {\n binding = {\n sourceBuffers: {},\n sourceTextures: {},\n targetTexture: null\n };\n }\n Object.assign(binding.sourceTextures, sourceTextures);\n Object.assign(binding.sourceBuffers, sourceBuffers);\n if (targetTexture) {\n binding.targetTexture = targetTexture;\n\n const {width, height} = targetTexture;\n const {framebuffer} = binding;\n if (framebuffer) {\n // First update texture without re-sizing attachments\n framebuffer.update({\n attachments: {[GL.COLOR_ATTACHMENT0]: targetTexture},\n resizeAttachments: false\n });\n // Resize to new taget texture size\n framebuffer.resize({width, height});\n } else {\n binding.framebuffer = new Framebuffer(this.gl, {\n id: `transform-framebuffer`,\n width,\n height,\n attachments: {\n [GL.COLOR_ATTACHMENT0]: targetTexture\n }\n });\n }\n }\n return binding;\n }\n\n // set texture filtering parameters on source textures.\n _setSourceTextureParameters() {\n const index = this.currentIndex;\n const {sourceTextures} = this.bindings[index];\n for (const name in sourceTextures) {\n sourceTextures[name].setParameters(SRC_TEX_PARAMETER_OVERRIDES);\n }\n }\n\n _swapTextures(opts) {\n if (!this._swapTexture) {\n return null;\n }\n const sourceTextures = Object.assign({}, opts.sourceTextures);\n sourceTextures[this._swapTexture] = opts.targetTexture;\n\n const targetTexture = opts.sourceTextures[this._swapTexture];\n\n return {sourceTextures, targetTexture};\n }\n\n // Create a buffer and add to list of buffers to be deleted.\n _createNewTexture(refTexture) {\n const texture = cloneTextureFrom(refTexture, {\n parameters: {\n [GL.TEXTURE_MIN_FILTER]: GL.NEAREST,\n [GL.TEXTURE_MAG_FILTER]: GL.NEAREST,\n [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,\n [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE\n },\n pixelStore: {\n [GL.UNPACK_FLIP_Y_WEBGL]: false\n }\n });\n\n // thre can only be one target texture\n if (this.ownTexture) {\n this.ownTexture.delete();\n }\n this.ownTexture = texture;\n\n return texture;\n }\n\n _getNextIndex() {\n return (this.currentIndex + 1) % 2;\n }\n\n // build and return shader releated parameters\n _processVertexShader(props: TransformProps = {}) {\n const {sourceTextures, targetTexture} = this.bindings[this.currentIndex];\n // @ts-expect-error TODO - uniforms is not present\n const {vs, uniforms, targetTextureType, inject, samplerTextureMap} = updateForTextures({\n vs: props.vs,\n sourceTextureMap: sourceTextures,\n targetTextureVarying: this.targetTextureVarying,\n targetTexture\n });\n const combinedInject = combineInjects([props.inject || {}, inject]);\n this.targetTextureType = targetTextureType;\n this.samplerTextureMap = samplerTextureMap;\n const fs =\n props._fs ||\n getPassthroughFS({\n version: getShaderInfo(vs).version,\n input: this.targetTextureVarying,\n inputType: targetTextureType,\n output: FS_OUTPUT_VARIABLE\n });\n const modules =\n this.hasSourceTextures || this.targetTextureVarying\n // @ts-expect-error\n ? [transformModule].concat(props.modules || [])\n : props.modules;\n return {vs, fs, modules, uniforms, inject: combinedInject};\n }\n}\n"],"file":"texture-transform.js"}
@@ -1,26 +0,0 @@
1
- export declare function updateForTextures(options: {
2
- vs: any;
3
- sourceTextureMap: any;
4
- targetTextureVarying: any;
5
- targetTexture: any;
6
- }): {
7
- vs: any;
8
- targetTextureType: any;
9
- inject: {};
10
- samplerTextureMap: {};
11
- };
12
- export declare function getSizeUniforms(options: {
13
- sourceTextureMap: any;
14
- targetTextureVarying: any;
15
- targetTexture: any;
16
- }): {};
17
- export declare function getVaryingType(line: any, varying: any): any;
18
- export declare function processAttributeDefinition(line: any, textureMap: any): {
19
- updatedLine: string;
20
- inject: {
21
- 'vs:#decl': string;
22
- 'vs:#main-start': string;
23
- };
24
- samplerTextureMap: {};
25
- };
26
- //# sourceMappingURL=transform-shader-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transform-shader-utils.d.ts","sourceRoot":"","sources":["../../src/transform/transform-shader-utils.ts"],"names":[],"mappings":"AAUA,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IACzC,EAAE,EAAE,GAAG,CAAC;IACR,gBAAgB,EAAE,GAAG,CAAC;IACtB,oBAAoB,EAAE,GAAG,CAAC;IAC1B,aAAa,EAAE,GAAG,CAAC;CACpB,GAAG;IACF,EAAE,EAAE,GAAG,CAAC;IACR,iBAAiB,EAAE,GAAG,CAAC;IACvB,MAAM,EAAE,EAAE,CAAC;IACX,iBAAiB,EAAE,EAAE,CAAC;CACvB,CAyDA;AAGD,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACvC,gBAAgB,EAAE,GAAG,CAAC;IACtB,oBAAoB,EAAE,GAAG,CAAC;IAC1B,aAAa,EAAE,GAAG,CAAC;CACpB,GAAG,EAAE,CAaL;AAID,wBAAgB,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,GAAG,GAAG,CAM3D;AAGD,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,GAAG,EACT,UAAU,EAAE,GAAG,GACd;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE;QACN,UAAU,EAAE,MAAM,CAAC;QACnB,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,iBAAiB,EAAE,EAAE,CAAC;CACvB,CAgCA"}
@@ -1,149 +0,0 @@
1
- import { assert } from '@luma.gl/webgl';
2
- import { combineInjects, getQualifierDetails, typeToChannelSuffix } from '@luma.gl/shadertools';
3
- const SAMPLER_UNIFORM_PREFIX = 'transform_uSampler_';
4
- const SIZE_UNIFORM_PREFIX = 'transform_uSize_';
5
- const VS_POS_VARIABLE = 'transform_position';
6
- export function updateForTextures(options) {
7
- const {
8
- vs,
9
- sourceTextureMap,
10
- targetTextureVarying,
11
- targetTexture
12
- } = options;
13
- const texAttributeNames = Object.keys(sourceTextureMap);
14
- let sourceCount = texAttributeNames.length;
15
- let targetTextureType = null;
16
- const samplerTextureMap = {};
17
- let updatedVs = vs;
18
- let finalInject = {};
19
-
20
- if (sourceCount > 0 || targetTextureVarying) {
21
- const vsLines = updatedVs.split('\n');
22
- const updateVsLines = vsLines.slice();
23
- vsLines.forEach((line, index, lines) => {
24
- if (sourceCount > 0) {
25
- const updated = processAttributeDefinition(line, sourceTextureMap);
26
-
27
- if (updated) {
28
- const {
29
- updatedLine,
30
- inject
31
- } = updated;
32
- updateVsLines[index] = updatedLine;
33
- finalInject = combineInjects([finalInject, inject]);
34
- Object.assign(samplerTextureMap, updated.samplerTextureMap);
35
- sourceCount--;
36
- }
37
- }
38
-
39
- if (targetTextureVarying && !targetTextureType) {
40
- targetTextureType = getVaryingType(line, targetTextureVarying);
41
- }
42
- });
43
-
44
- if (targetTextureVarying) {
45
- assert(targetTexture);
46
- const sizeName = "".concat(SIZE_UNIFORM_PREFIX).concat(targetTextureVarying);
47
- const uniformDeclaration = "uniform vec2 ".concat(sizeName, ";\n");
48
- const posInstructions = " vec2 ".concat(VS_POS_VARIABLE, " = transform_getPos(").concat(sizeName, ");\n gl_Position = vec4(").concat(VS_POS_VARIABLE, ", 0, 1.);\n");
49
- const inject = {
50
- 'vs:#decl': uniformDeclaration,
51
- 'vs:#main-start': posInstructions
52
- };
53
- finalInject = combineInjects([finalInject, inject]);
54
- }
55
-
56
- updatedVs = updateVsLines.join('\n');
57
- }
58
-
59
- return {
60
- vs: updatedVs,
61
- targetTextureType,
62
- inject: finalInject,
63
- samplerTextureMap
64
- };
65
- }
66
- export function getSizeUniforms(options) {
67
- const uniforms = {};
68
- let width;
69
- let height;
70
-
71
- if (options.targetTextureVarying) {
72
- ({
73
- width,
74
- height
75
- } = options.targetTexture);
76
- uniforms["".concat(SIZE_UNIFORM_PREFIX).concat(options.targetTextureVarying)] = [width, height];
77
- }
78
-
79
- for (const textureName in options.sourceTextureMap) {
80
- ({
81
- width,
82
- height
83
- } = options.sourceTextureMap[textureName]);
84
- uniforms["".concat(SIZE_UNIFORM_PREFIX).concat(textureName)] = [width, height];
85
- }
86
-
87
- return uniforms;
88
- }
89
- export function getVaryingType(line, varying) {
90
- const qualiferDetails = getQualifierDetails(line, ['varying', 'out']);
91
-
92
- if (!qualiferDetails) {
93
- return null;
94
- }
95
-
96
- return qualiferDetails.name === varying ? qualiferDetails.type : null;
97
- }
98
- export function processAttributeDefinition(line, textureMap) {
99
- const samplerTextureMap = {};
100
- const attributeData = getAttributeDefinition(line);
101
-
102
- if (!attributeData) {
103
- return null;
104
- }
105
-
106
- const {
107
- type,
108
- name
109
- } = attributeData;
110
-
111
- if (name && textureMap[name]) {
112
- const updatedLine = "// ".concat(line, " => Replaced by Transform with a sampler");
113
- const {
114
- samplerName,
115
- sizeName,
116
- uniformDeclerations
117
- } = getSamplerDeclarations(name);
118
- const channels = typeToChannelSuffix(type);
119
- const sampleInstruction = " ".concat(type, " ").concat(name, " = transform_getInput(").concat(samplerName, ", ").concat(sizeName, ").").concat(channels, ";\n");
120
- samplerTextureMap[samplerName] = name;
121
- const inject = {
122
- 'vs:#decl': uniformDeclerations,
123
- 'vs:#main-start': sampleInstruction
124
- };
125
- return {
126
- updatedLine,
127
- inject,
128
- samplerTextureMap
129
- };
130
- }
131
-
132
- return null;
133
- }
134
-
135
- function getAttributeDefinition(line) {
136
- return getQualifierDetails(line, ['attribute', 'in']);
137
- }
138
-
139
- function getSamplerDeclarations(textureName) {
140
- const samplerName = "".concat(SAMPLER_UNIFORM_PREFIX).concat(textureName);
141
- const sizeName = "".concat(SIZE_UNIFORM_PREFIX).concat(textureName);
142
- const uniformDeclerations = " uniform sampler2D ".concat(samplerName, ";\n uniform vec2 ").concat(sizeName, ";");
143
- return {
144
- samplerName,
145
- sizeName,
146
- uniformDeclerations
147
- };
148
- }
149
- //# sourceMappingURL=transform-shader-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/transform/transform-shader-utils.ts"],"names":["assert","combineInjects","getQualifierDetails","typeToChannelSuffix","SAMPLER_UNIFORM_PREFIX","SIZE_UNIFORM_PREFIX","VS_POS_VARIABLE","updateForTextures","options","vs","sourceTextureMap","targetTextureVarying","targetTexture","texAttributeNames","Object","keys","sourceCount","length","targetTextureType","samplerTextureMap","updatedVs","finalInject","vsLines","split","updateVsLines","slice","forEach","line","index","lines","updated","processAttributeDefinition","updatedLine","inject","assign","getVaryingType","sizeName","uniformDeclaration","posInstructions","join","getSizeUniforms","uniforms","width","height","textureName","varying","qualiferDetails","name","type","textureMap","attributeData","getAttributeDefinition","samplerName","uniformDeclerations","getSamplerDeclarations","channels","sampleInstruction"],"mappings":"AAAA,SAAQA,MAAR,QAAqB,gBAArB;AACA,SAAQC,cAAR,EAAwBC,mBAAxB,EAA6CC,mBAA7C,QAAuE,sBAAvE;AAEA,MAAMC,sBAAsB,GAAG,qBAA/B;AACA,MAAMC,mBAAmB,GAAG,kBAA5B;AACA,MAAMC,eAAe,GAAG,oBAAxB;AAKA,OAAO,SAASC,iBAAT,CAA2BC,OAA3B,EAUL;AACA,QAAM;AAACC,IAAAA,EAAD;AAAKC,IAAAA,gBAAL;AAAuBC,IAAAA,oBAAvB;AAA6CC,IAAAA;AAA7C,MAA8DJ,OA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S2B,sBAAT,CAAgCV,WAAhC,EAA6C;AAC3C,QAAMQ,WAAW,aAAMhD,sBAAN,SAA+BwC,WAA/B,CAAjB;AACA,QAAMR,QAAQ,aAAM/B,mBAAN,SAA4BuC,WAA5B,CAAd;AACA,QAAMS,mBAAmB,iCACLD,WADK,+BAEVhB,QAFU,MAAzB;AAGA,SAAO;AAACgB,IAAAA,WAAD;AAAchB,IAAAA,QAAd;AAAwBiB,IAAAA;AAAxB,GAAP;AACD","sourcesContent":["import {assert} from '@luma.gl/webgl';\nimport {combineInjects, getQualifierDetails, typeToChannelSuffix} from '@luma.gl/shadertools';\n\nconst SAMPLER_UNIFORM_PREFIX = 'transform_uSampler_';\nconst SIZE_UNIFORM_PREFIX = 'transform_uSize_';\nconst VS_POS_VARIABLE = 'transform_position';\n\n// Scan provided vertex shader\n// for each texture attribute, inject sampler instructions and build uniforms for sampler\n// for texture target, get varying type and inject position instruction\nexport function updateForTextures(options: {\n vs: any;\n sourceTextureMap: any;\n targetTextureVarying: any;\n targetTexture: any;\n}): {\n vs: any;\n targetTextureType: any;\n inject: {};\n samplerTextureMap: {};\n} {\n const {vs, sourceTextureMap, targetTextureVarying, targetTexture} = options;\n const texAttributeNames = Object.keys(sourceTextureMap);\n let sourceCount = texAttributeNames.length;\n let targetTextureType = null;\n const samplerTextureMap = {};\n let updatedVs = vs;\n let finalInject = {};\n\n if (sourceCount > 0 || targetTextureVarying) {\n const vsLines = updatedVs.split('\\n');\n const updateVsLines = vsLines.slice();\n vsLines.forEach((line, index, lines) => {\n // TODO add early exit\n if (sourceCount > 0) {\n const updated = processAttributeDefinition(line, sourceTextureMap);\n if (updated) {\n const {updatedLine, inject} = updated;\n updateVsLines[index] = updatedLine;\n // sampleInstructions.push(sampleInstruction);\n finalInject = combineInjects([finalInject, inject]);\n Object.assign(samplerTextureMap, updated.samplerTextureMap);\n sourceCount--;\n }\n }\n if (targetTextureVarying && !targetTextureType) {\n targetTextureType = getVaryingType(line, targetTextureVarying);\n }\n });\n\n if (targetTextureVarying) {\n assert(targetTexture);\n const sizeName = `${SIZE_UNIFORM_PREFIX}${targetTextureVarying}`;\n\n const uniformDeclaration = `uniform vec2 ${sizeName};\\n`;\n const posInstructions = `\\\n vec2 ${VS_POS_VARIABLE} = transform_getPos(${sizeName});\n gl_Position = vec4(${VS_POS_VARIABLE}, 0, 1.);\\n`;\n const inject = {\n 'vs:#decl': uniformDeclaration,\n 'vs:#main-start': posInstructions\n };\n finalInject = combineInjects([finalInject, inject]);\n }\n updatedVs = updateVsLines.join('\\n');\n }\n return {\n // updated vertex shader (commented texture attribute definition)\n vs: updatedVs,\n // type (float, vec2, vec3 of vec4) target texture varying\n targetTextureType,\n // required vertex and fragment shader injects\n inject: finalInject,\n // map of sampler name to texture name, can be used to set attributes\n // usefull when swapping textures, as source and destination texture change when swap is called.\n samplerTextureMap\n };\n}\n\n// builds and returns an object contaning size uniform for each texture\nexport function getSizeUniforms(options: {\n sourceTextureMap: any;\n targetTextureVarying: any;\n targetTexture: any;\n}): {} {\n const uniforms = {};\n let width;\n let height;\n if (options.targetTextureVarying) {\n ({width, height} = options.targetTexture);\n uniforms[`${SIZE_UNIFORM_PREFIX}${options.targetTextureVarying}`] = [width, height];\n }\n for (const textureName in options.sourceTextureMap) {\n ({width, height} = options.sourceTextureMap[textureName]);\n uniforms[`${SIZE_UNIFORM_PREFIX}${textureName}`] = [width, height];\n }\n return uniforms;\n}\n\n// Return size (float, vec2 etc) of a given varying, null if doens't exist.\n\nexport function getVaryingType(line: any, varying: any): any {\n const qualiferDetails = getQualifierDetails(line, ['varying', 'out']);\n if (!qualiferDetails) {\n return null;\n }\n return qualiferDetails.name === varying ? qualiferDetails.type : null;\n}\n\n// build required definitions, sample instructions for each texture attribute\nexport function processAttributeDefinition(\n line: any,\n textureMap: any\n): {\n updatedLine: string;\n inject: {\n 'vs:#decl': string;\n 'vs:#main-start': string;\n };\n samplerTextureMap: {};\n} {\n const samplerTextureMap = {};\n const attributeData = getAttributeDefinition(line);\n if (!attributeData) {\n return null;\n }\n const {type, name} = attributeData;\n if (name && textureMap[name]) {\n // eslint-disable-next-line no-useless-escape\n const updatedLine = `\\// ${line} => Replaced by Transform with a sampler`;\n const {samplerName, sizeName, uniformDeclerations} = getSamplerDeclarations(name);\n\n const channels = typeToChannelSuffix(type);\n const sampleInstruction = ` ${type} ${name} = transform_getInput(${samplerName}, ${sizeName}).${channels};\\n`;\n\n samplerTextureMap[samplerName] = name;\n const inject = {\n 'vs:#decl': uniformDeclerations,\n 'vs:#main-start': sampleInstruction\n };\n\n // samplerNameMap\n return {\n // update vertex shader line.\n updatedLine,\n // inject object with sampler instructions.\n inject,\n // sampler name to texture name map\n samplerTextureMap\n };\n }\n return null;\n}\n\n// HELPERS\n\n// Checks if provided line is defining an attribute, if so returns details otherwise null\nfunction getAttributeDefinition(line) {\n return getQualifierDetails(line, ['attribute', 'in']);\n}\n\nfunction getSamplerDeclarations(textureName) {\n const samplerName = `${SAMPLER_UNIFORM_PREFIX}${textureName}`;\n const sizeName = `${SIZE_UNIFORM_PREFIX}${textureName}`;\n const uniformDeclerations = `\\\n uniform sampler2D ${samplerName};\n uniform vec2 ${sizeName};`;\n return {samplerName, sizeName, uniformDeclerations};\n}\n"],"file":"transform-shader-utils.js"}