@luma.gl/webgl 9.0.0-alpha.30 → 9.0.0-alpha.31

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 (59) hide show
  1. package/dist/adapter/converters/shader-formats.d.ts +9 -0
  2. package/dist/adapter/converters/shader-formats.d.ts.map +1 -0
  3. package/dist/adapter/converters/shader-formats.js +53 -0
  4. package/dist/adapter/converters/shader-formats.js.map +1 -0
  5. package/dist/adapter/converters/texture-formats.d.ts +1 -2
  6. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  7. package/dist/adapter/converters/texture-formats.js +2 -23
  8. package/dist/adapter/converters/texture-formats.js.map +1 -1
  9. package/dist/adapter/converters/vertex-formats.d.ts +8 -2
  10. package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
  11. package/dist/adapter/converters/vertex-formats.js +47 -9
  12. package/dist/adapter/converters/vertex-formats.js.map +1 -1
  13. package/dist/adapter/helpers/{uniforms.d.ts → decode-webgl-types.d.ts} +9 -8
  14. package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -0
  15. package/dist/adapter/helpers/{uniforms.js → decode-webgl-types.js} +14 -13
  16. package/dist/adapter/helpers/decode-webgl-types.js.map +1 -0
  17. package/dist/adapter/helpers/get-shader-layout.d.ts +1 -51
  18. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  19. package/dist/adapter/helpers/get-shader-layout.js +14 -86
  20. package/dist/adapter/helpers/get-shader-layout.js.map +1 -1
  21. package/dist/adapter/helpers/{attribute-utils.d.ts → webgl-topology-utils.d.ts} +1 -1
  22. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -0
  23. package/dist/adapter/helpers/{attribute-utils.js → webgl-topology-utils.js} +1 -1
  24. package/dist/adapter/helpers/webgl-topology-utils.js.map +1 -0
  25. package/dist/adapter/objects/webgl-vertex-array-object.d.ts +2 -1
  26. package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +1 -1
  27. package/dist/adapter/objects/webgl-vertex-array-object.js.map +1 -1
  28. package/dist/adapter/resources/webgl-command-encoder.js +1 -1
  29. package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
  30. package/dist/adapter/resources/webgl-render-pipeline.d.ts +14 -9
  31. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  32. package/dist/adapter/resources/webgl-render-pipeline.js +58 -59
  33. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  34. package/dist/dist.dev.js +478 -391
  35. package/dist/index.cjs +641 -695
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +1 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/types.d.ts +2 -0
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/types.js.map +1 -1
  43. package/dist.min.js +22 -22
  44. package/package.json +5 -5
  45. package/src/adapter/converters/shader-formats.ts +41 -0
  46. package/src/adapter/converters/texture-formats.ts +3 -16
  47. package/src/adapter/converters/vertex-formats.ts +67 -10
  48. package/src/adapter/helpers/{uniforms.ts → decode-webgl-types.ts} +22 -17
  49. package/src/adapter/helpers/get-shader-layout.ts +51 -159
  50. package/src/adapter/objects/webgl-vertex-array-object.ts +2 -1
  51. package/src/adapter/resources/webgl-command-encoder.ts +1 -1
  52. package/src/adapter/resources/webgl-render-pipeline.ts +121 -77
  53. package/src/index.ts +1 -1
  54. package/src/types.ts +2 -0
  55. package/dist/adapter/helpers/attribute-utils.d.ts.map +0 -1
  56. package/dist/adapter/helpers/attribute-utils.js.map +0 -1
  57. package/dist/adapter/helpers/uniforms.d.ts.map +0 -1
  58. package/dist/adapter/helpers/uniforms.js.map +0 -1
  59. /package/src/adapter/helpers/{attribute-utils.ts → webgl-topology-utils.ts} +0 -0
@@ -1,17 +1,18 @@
1
- import { UniformFormat, VertexFormat } from '@luma.gl/core';
1
+ import { ShaderUniformType, ShaderAttributeType, VertexFormat } from '@luma.gl/core';
2
2
  import { GL, GLUniformType, GLCompositeType, GLDataType } from '@luma.gl/constants';
3
3
  /** Check is uniform is of sampler type */
4
4
  export declare function isSamplerUniform(type: GLUniformType): boolean;
5
- /** Decomposes a composite type GL.VEC3 into a basic type (GL.FLOAT) and components (3) */
6
- export declare function decodeUniformType(uniformType: GL): {
7
- format: UniformFormat;
5
+ /** Decomposes a composite type (GL.VEC3) into a basic type (GL.FLOAT) and components (3) */
6
+ export declare function decodeGLUniformType(glUniformType: GL): {
7
+ format: ShaderUniformType;
8
8
  components: number;
9
9
  glType: GLDataType;
10
10
  };
11
- export declare function decodeAttributeType(attributeType: GL): {
12
- format: VertexFormat;
11
+ /** Decomposes a composite type (GL.VEC3) into a basic type (GL.FLOAT) and components (3) */
12
+ export declare function decodeGLAttributeType(glAttributeType: GL): {
13
+ attributeType: ShaderAttributeType;
14
+ vertexFormat: VertexFormat;
13
15
  components: number;
14
- glType: GLDataType;
15
16
  };
16
17
  /** Decomposes a composite type GL.VEC3 into a basic type (GL.FLOAT) and components (3) */
17
18
  export declare function decomposeCompositeGLDataType(compositeGLDataType: GLCompositeType): {
@@ -22,4 +23,4 @@ export declare function getCompositeGLDataType(type: GL, components: any): {
22
23
  glType: GLDataType;
23
24
  name: string;
24
25
  } | null;
25
- //# sourceMappingURL=uniforms.d.ts.map
26
+ //# sourceMappingURL=decode-webgl-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode-webgl-types.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/decode-webgl-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,mBAAmB,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AACnF,OAAO,EAAC,EAAE,EAAE,aAAa,EAAiB,eAAe,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAEjG,0CAA0C;AAC1C,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAE7D;AA2DD,4FAA4F;AAC5F,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,EAAE,GAChB;IAAC,MAAM,EAAE,iBAAiB,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAC,CAOrE;AAED,4FAA4F;AAC5F,wBAAgB,qBAAqB,CAAC,eAAe,EAAE,EAAE,GAAG;IAC1D,aAAa,EAAE,mBAAmB,CAAC;IACnC,YAAY,EAAE,YAAY,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;CAEpB,CASA;AAED,0FAA0F;AAC1F,wBAAgB,4BAA4B,CAC1C,mBAAmB,EAAE,eAAe,GACnC;IAAC,IAAI,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAC,GAAG,IAAI,CAO/C;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,EAAE,EAAE,UAAU,KAAA,GAAG;IAAC,MAAM,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,GAAG,IAAI,CAkBtG"}
@@ -16,10 +16,10 @@ const COMPOSITE_GL_TYPES = {
16
16
  [GL.UNSIGNED_INT_VEC2]: [GL.UNSIGNED_INT, 2, 'uvec2', 'vec2<u32>', 'uint32x2'],
17
17
  [GL.UNSIGNED_INT_VEC3]: [GL.UNSIGNED_INT, 3, 'uvec3', 'vec3<u32>', 'uint32x3'],
18
18
  [GL.UNSIGNED_INT_VEC4]: [GL.UNSIGNED_INT, 4, 'uvec4', 'vec4<u32>', 'uint32x4'],
19
- [GL.BOOL]: [GL.FLOAT, 1, 'bool', 'f32', 'float32x2'],
20
- [GL.BOOL_VEC2]: [GL.FLOAT, 2, 'bvec2', 'vec2<f32>'],
21
- [GL.BOOL_VEC3]: [GL.FLOAT, 3, 'bvec3', 'vec3<f32>'],
22
- [GL.BOOL_VEC4]: [GL.FLOAT, 4, 'bvec4', 'vec4<f32>'],
19
+ [GL.BOOL]: [GL.FLOAT, 1, 'bool', 'f32', 'float32'],
20
+ [GL.BOOL_VEC2]: [GL.FLOAT, 2, 'bvec2', 'vec2<f32>', 'float32x2'],
21
+ [GL.BOOL_VEC3]: [GL.FLOAT, 3, 'bvec3', 'vec3<f32>', 'float32x3'],
22
+ [GL.BOOL_VEC4]: [GL.FLOAT, 4, 'bvec4', 'vec4<f32>', 'float32x4'],
23
23
  [GL.FLOAT_MAT2]: [GL.FLOAT, 8, 'mat2', 'mat2x2<f32>'],
24
24
  [GL.FLOAT_MAT2x3]: [GL.FLOAT, 8, 'mat2x3', 'mat2x3<f32>'],
25
25
  [GL.FLOAT_MAT2x4]: [GL.FLOAT, 8, 'mat2x4', 'mat2x4<f32>'],
@@ -30,8 +30,8 @@ const COMPOSITE_GL_TYPES = {
30
30
  [GL.FLOAT_MAT4x3]: [GL.FLOAT, 16, 'mat4x3', 'mat4x3<f32>'],
31
31
  [GL.FLOAT_MAT4]: [GL.FLOAT, 16, 'mat4', 'mat4x4<f32>']
32
32
  };
33
- export function decodeUniformType(uniformType) {
34
- const typeAndSize = COMPOSITE_GL_TYPES[uniformType];
33
+ export function decodeGLUniformType(glUniformType) {
34
+ const typeAndSize = COMPOSITE_GL_TYPES[glUniformType];
35
35
  if (!typeAndSize) {
36
36
  throw new Error('uniform');
37
37
  }
@@ -42,16 +42,17 @@ export function decodeUniformType(uniformType) {
42
42
  glType
43
43
  };
44
44
  }
45
- export function decodeAttributeType(attributeType) {
46
- const typeAndSize = COMPOSITE_GL_TYPES[attributeType];
45
+ export function decodeGLAttributeType(glAttributeType) {
46
+ const typeAndSize = COMPOSITE_GL_TYPES[glAttributeType];
47
47
  if (!typeAndSize) {
48
48
  throw new Error('attribute');
49
49
  }
50
- const [glType, components,,, format] = typeAndSize;
50
+ const [, components,, shaderType, vertexFormat] = typeAndSize;
51
+ const attributeType = shaderType;
51
52
  return {
52
- format,
53
- components,
54
- glType
53
+ attributeType,
54
+ vertexFormat,
55
+ components
55
56
  };
56
57
  }
57
58
  export function decomposeCompositeGLDataType(compositeGLDataType) {
@@ -86,4 +87,4 @@ export function getCompositeGLDataType(type, components) {
86
87
  }
87
88
  return null;
88
89
  }
89
- //# sourceMappingURL=uniforms.js.map
90
+ //# sourceMappingURL=decode-webgl-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode-webgl-types.js","names":["GL","isSamplerUniform","type","SAMPLER_TYPES","includes","SAMPLER_2D","SAMPLER_CUBE","SAMPLER_3D","SAMPLER_2D_SHADOW","SAMPLER_2D_ARRAY","SAMPLER_2D_ARRAY_SHADOW","SAMPLER_CUBE_SHADOW","INT_SAMPLER_2D","INT_SAMPLER_3D","INT_SAMPLER_CUBE","INT_SAMPLER_2D_ARRAY","UNSIGNED_INT_SAMPLER_2D","UNSIGNED_INT_SAMPLER_3D","UNSIGNED_INT_SAMPLER_CUBE","UNSIGNED_INT_SAMPLER_2D_ARRAY","COMPOSITE_GL_TYPES","FLOAT","FLOAT_VEC2","FLOAT_VEC3","FLOAT_VEC4","INT","INT_VEC2","INT_VEC3","INT_VEC4","UNSIGNED_INT","UNSIGNED_INT_VEC2","UNSIGNED_INT_VEC3","UNSIGNED_INT_VEC4","BOOL","BOOL_VEC2","BOOL_VEC3","BOOL_VEC4","FLOAT_MAT2","FLOAT_MAT2x3","FLOAT_MAT2x4","FLOAT_MAT3x2","FLOAT_MAT3","FLOAT_MAT3x4","FLOAT_MAT4x2","FLOAT_MAT4x3","FLOAT_MAT4","decodeGLUniformType","glUniformType","typeAndSize","Error","glType","components","format","decodeGLAttributeType","glAttributeType","shaderType","vertexFormat","attributeType","decomposeCompositeGLDataType","compositeGLDataType","getCompositeGLDataType","BYTE","UNSIGNED_BYTE","SHORT","UNSIGNED_SHORT","compType","compComponents","name","Number"],"sources":["../../../src/adapter/helpers/decode-webgl-types.ts"],"sourcesContent":["import {ShaderUniformType, ShaderAttributeType, VertexFormat} from '@luma.gl/core';\nimport {GL, GLUniformType, GLSamplerType, GLCompositeType, GLDataType} from '@luma.gl/constants';\n\n/** Check is uniform is of sampler type */\nexport function isSamplerUniform(type: GLUniformType): boolean {\n return SAMPLER_TYPES.includes(type as GLSamplerType);\n}\n\nconst SAMPLER_TYPES: GLSamplerType[] = [\n GL.SAMPLER_2D,\n GL.SAMPLER_CUBE,\n GL.SAMPLER_3D,\n GL.SAMPLER_2D_SHADOW,\n GL.SAMPLER_2D_ARRAY,\n GL.SAMPLER_2D_ARRAY_SHADOW,\n GL.SAMPLER_CUBE_SHADOW,\n GL.INT_SAMPLER_2D,\n GL.INT_SAMPLER_3D,\n GL.INT_SAMPLER_CUBE,\n GL.INT_SAMPLER_2D_ARRAY,\n GL.UNSIGNED_INT_SAMPLER_2D,\n GL.UNSIGNED_INT_SAMPLER_3D,\n GL.UNSIGNED_INT_SAMPLER_CUBE,\n GL.UNSIGNED_INT_SAMPLER_2D_ARRAY\n];\n\n// Composite types table\nconst COMPOSITE_GL_TYPES: Record<\n GLCompositeType,\n [GLDataType, number, string, ShaderUniformType, VertexFormat?]\n> = {\n [GL.FLOAT]: [GL.FLOAT, 1, 'float', 'f32', 'float32'],\n [GL.FLOAT_VEC2]: [GL.FLOAT, 2, 'vec2', 'vec2<f32>', 'float32x2'],\n [GL.FLOAT_VEC3]: [GL.FLOAT, 3, 'vec3', 'vec3<f32>', 'float32x3'],\n [GL.FLOAT_VEC4]: [GL.FLOAT, 4, 'vec4', 'vec4<f32>', 'float32x4'],\n\n [GL.INT]: [GL.INT, 1, 'int', 'i32', 'sint32'],\n [GL.INT_VEC2]: [GL.INT, 2, 'ivec2', 'vec2<i32>', 'sint32x2'],\n [GL.INT_VEC3]: [GL.INT, 3, 'ivec3', 'vec3<i32>', 'sint32x3'],\n [GL.INT_VEC4]: [GL.INT, 4, 'ivec4', 'vec4<i32>', 'sint32x4'],\n\n [GL.UNSIGNED_INT]: [GL.UNSIGNED_INT, 1, 'uint', 'u32', 'uint32'],\n [GL.UNSIGNED_INT_VEC2]: [GL.UNSIGNED_INT, 2, 'uvec2', 'vec2<u32>', 'uint32x2'],\n [GL.UNSIGNED_INT_VEC3]: [GL.UNSIGNED_INT, 3, 'uvec3', 'vec3<u32>', 'uint32x3'],\n [GL.UNSIGNED_INT_VEC4]: [GL.UNSIGNED_INT, 4, 'uvec4', 'vec4<u32>', 'uint32x4'],\n\n [GL.BOOL]: [GL.FLOAT, 1, 'bool', 'f32', 'float32'],\n [GL.BOOL_VEC2]: [GL.FLOAT, 2, 'bvec2', 'vec2<f32>', 'float32x2'],\n [GL.BOOL_VEC3]: [GL.FLOAT, 3, 'bvec3', 'vec3<f32>', 'float32x3'],\n [GL.BOOL_VEC4]: [GL.FLOAT, 4, 'bvec4', 'vec4<f32>', 'float32x4'],\n\n // TODO - are sizes/components below correct?\n [GL.FLOAT_MAT2]: [GL.FLOAT, 8, 'mat2', 'mat2x2<f32>'], // 4\n [GL.FLOAT_MAT2x3]: [GL.FLOAT, 8, 'mat2x3', 'mat2x3<f32>'], // 6\n [GL.FLOAT_MAT2x4]: [GL.FLOAT, 8, 'mat2x4', 'mat2x4<f32>'], // 8\n\n [GL.FLOAT_MAT3x2]: [GL.FLOAT, 12, 'mat3x2', 'mat3x2<f32>'], // 6\n [GL.FLOAT_MAT3]: [GL.FLOAT, 12, 'mat3', 'mat3x3<f32>'], // 9\n [GL.FLOAT_MAT3x4]: [GL.FLOAT, 12, 'mat3x4', 'mat3x4<f32>'], // 12\n\n [GL.FLOAT_MAT4x2]: [GL.FLOAT, 16, 'mat4x2', 'mat4x2<f32>'], // 8\n [GL.FLOAT_MAT4x3]: [GL.FLOAT, 16, 'mat4x3', 'mat4x3<f32>'], // 12\n [GL.FLOAT_MAT4]: [GL.FLOAT, 16, 'mat4', 'mat4x4<f32>'] // 16\n};\n\n/** Decomposes a composite type (GL.VEC3) into a basic type (GL.FLOAT) and components (3) */\nexport function decodeGLUniformType(\n glUniformType: GL\n): {format: ShaderUniformType; components: number; glType: GLDataType} {\n const typeAndSize = COMPOSITE_GL_TYPES[glUniformType];\n if (!typeAndSize) {\n throw new Error('uniform');\n }\n const [glType, components, , format] = typeAndSize;\n return {format, components, glType};\n}\n\n/** Decomposes a composite type (GL.VEC3) into a basic type (GL.FLOAT) and components (3) */\nexport function decodeGLAttributeType(glAttributeType: GL): {\n attributeType: ShaderAttributeType;\n vertexFormat: VertexFormat;\n components: number;\n // glType: GLDataType;\n} {\n const typeAndSize = COMPOSITE_GL_TYPES[glAttributeType];\n if (!typeAndSize) {\n throw new Error('attribute')\n }\n const [, components, , shaderType, vertexFormat] = typeAndSize;\n // TODO sanity - if (shaderType.startsWith('mat' ...))\n const attributeType = shaderType as unknown as ShaderAttributeType\n return {attributeType, vertexFormat, components}; // , glType};\n}\n\n/** Decomposes a composite type GL.VEC3 into a basic type (GL.FLOAT) and components (3) */\nexport function decomposeCompositeGLDataType(\n compositeGLDataType: GLCompositeType\n): {type: GLDataType; components: number} | null {\n const typeAndSize = COMPOSITE_GL_TYPES[compositeGLDataType];\n if (!typeAndSize) {\n return null;\n }\n const [type, components] = typeAndSize;\n return {type, components};\n}\n\nexport function getCompositeGLDataType(type: GL, components): {glType: GLDataType; name: string} | null {\n switch (type) {\n case GL.BYTE:\n case GL.UNSIGNED_BYTE:\n case GL.SHORT:\n case GL.UNSIGNED_SHORT:\n type = GL.FLOAT;\n break;\n default:\n }\n\n for (const glType in COMPOSITE_GL_TYPES) {\n const [compType, compComponents, name] = COMPOSITE_GL_TYPES[glType];\n if (compType === type && compComponents === components) {\n return {glType: Number(glType), name};\n }\n }\n return null;\n}\n"],"mappings":"AACA,SAAQA,EAAE,QAAkE,oBAAoB;AAGhG,OAAO,SAASC,gBAAgBA,CAACC,IAAmB,EAAW;EAC7D,OAAOC,aAAa,CAACC,QAAQ,CAACF,IAAqB,CAAC;AACtD;AAEA,MAAMC,aAA8B,GAAG,CACrCH,EAAE,CAACK,UAAU,EACbL,EAAE,CAACM,YAAY,EACfN,EAAE,CAACO,UAAU,EACbP,EAAE,CAACQ,iBAAiB,EACpBR,EAAE,CAACS,gBAAgB,EACnBT,EAAE,CAACU,uBAAuB,EAC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AIC,KAAK,CAAC,WAAW,CAAC;EAC9B;EACA,MAAM,GAAGE,UAAU,GAAII,UAAU,EAAEC,YAAY,CAAC,GAAGR,WAAW;EAE9D,MAAMS,aAAa,GAAGF,UAA4C;EAClE,OAAO;IAACE,aAAa;IAAED,YAAY;IAAEL;EAAU,CAAC;AAClD;AAGA,OAAO,SAASO,4BAA4BA,CAC1CC,mBAAoC,EACW;EAC/C,MAAMX,WAAW,GAAG5B,kBAAkB,CAACuC,mBAAmB,CAAC;EAC3D,IAAI,CAACX,WAAW,EAAE;IAChB,OAAO,IAAI;EACb;EACA,MAAM,CAAC9C,IAAI,EAAEiD,UAAU,CAAC,GAAGH,WAAW;EACtC,OAAO;IAAC9C,IAAI;IAAEiD;EAAU,CAAC;AAC3B;AAEA,OAAO,SAASS,sBAAsBA,CAAC1D,IAAQ,EAAEiD,UAAU,EAA6C;EACtG,QAAQjD,IAAI;IACV,KAAKF,EAAE,CAAC6D,IAAI;IACZ,KAAK7D,EAAE,CAAC8D,aAAa;IACrB,KAAK9D,EAAE,CAAC+D,KAAK;IACb,KAAK/D,EAAE,CAACgE,cAAc;MACpB9D,IAAI,GAAGF,EAAE,CAACqB,KAAK;MACf;IACF;EACF;EAEA,KAAK,MAAM6B,MAAM,IAAI9B,kBAAkB,EAAE;IACvC,MAAM,CAAC6C,QAAQ,EAAEC,cAAc,EAAEC,IAAI,CAAC,GAAG/C,kBAAkB,CAAC8B,MAAM,CAAC;IACnE,IAAIe,QAAQ,KAAK/D,IAAI,IAAIgE,cAAc,KAAKf,UAAU,EAAE;MACtD,OAAO;QAACD,MAAM,EAAEkB,MAAM,CAAClB,MAAM,CAAC;QAAEiB;MAAI,CAAC;IACvC;EACF;EACA,OAAO,IAAI;AACb"}
@@ -1,58 +1,8 @@
1
- import type { ShaderLayout, AttributeLayout, BufferMapping } from '@luma.gl/core';
1
+ import type { ShaderLayout } from '@luma.gl/core';
2
2
  /**
3
3
  * Extract metadata describing binding information for a program's shaders
4
4
  * Note: `linkProgram()` needs to have been called
5
5
  * (although linking does not need to have been successful).
6
6
  */
7
7
  export declare function getShaderLayout(gl: WebGLRenderingContext, program: WebGLProgram): ShaderLayout;
8
- /**
9
- * Merges an provided shader layout into a base shader layout
10
- * In WebGL, this allows the auto generated shader layout to be overridden by the application
11
- * Typically to change the format of the vertex attributes (from float32x4 to uint8x4 etc).
12
- * @todo Drop this? This could also be done more clearly with bufferMapping
13
- */
14
- export declare function mergeShaderLayout(baseLayout: ShaderLayout, overrideLayout: ShaderLayout): ShaderLayout;
15
- export declare function mergeBufferMap(baseLayout: ShaderLayout, bufferMap: BufferMapping[]): ShaderLayout;
16
- export declare function getAttributeFromLayout(shaderLayout: ShaderLayout, name: string): AttributeLayout | null;
17
- /**
18
- * TODO - verify this is a copy of above and delete
19
- * import type {TextureFormat} from '@luma.gl/core';
20
- * Extract info about all "active" uniform blocks
21
- * ("Active" just means that unused (inactive) blocks may have been optimized away during linking)
22
- *
23
- function getUniformBlockBindings(gl: WebGLRenderingContext, program): Binding[] {
24
- if (!isWebGL2(gl)) {
25
- return;
26
- }
27
- const bindings: Binding[] = [];
28
- const count = gl.getProgramParameter(program, gl.ACTIVE_UNIFORM_BLOCKS);
29
- for (let blockIndex = 0; blockIndex < count; blockIndex++) {
30
- const vertex = gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
31
- const fragment = gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER),
32
- const visibility = (vertex) + (fragment);
33
- const binding: BufferBinding = {
34
- location: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_BINDING),
35
- // name: gl.getActiveUniformBlockName(program, blockIndex),
36
- type: 'uniform',
37
- visibility,
38
- minBindingSize: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_DATA_SIZE),
39
- // uniformCount: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_ACTIVE_UNIFORMS),
40
- // uniformIndices: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES),
41
- }
42
- bindings.push(binding);
43
- }
44
- return bindings;
45
- }
46
-
47
- function setBindings(gl2: WebGL2RenderingContext, program: WebGLProgram, bindings: Binding[][]): void {
48
- for (const bindGroup of bindings) {
49
- for (const binding of bindGroup) {
50
-
51
- }
52
- }
53
-
54
- // Set up indirection table
55
- // this.gl2.uniformBlockBinding(this.handle, blockIndex, blockBinding);
56
- }
57
- */
58
8
  //# sourceMappingURL=get-shader-layout.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-shader-layout.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/get-shader-layout.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EAMf,aAAa,EAEd,MAAM,eAAe,CAAC;AASvB;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,qBAAqB,EAAE,OAAO,EAAE,YAAY,GAAG,YAAY,CAwE9F;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,YAAY,EACxB,cAAc,EAAE,YAAY,GAC3B,YAAY,CAiBd;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,YAAY,CAsBjG;AAYD,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,YAAY,EAC1B,IAAI,EAAE,MAAM,GACX,eAAe,GAAG,IAAI,CAMxB;AAkQD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG"}
1
+ {"version":3,"file":"get-shader-layout.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/get-shader-layout.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EAKb,MAAM,eAAe,CAAC;AAOvB;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,qBAAqB,EAAE,OAAO,EAAE,YAAY,GAAG,YAAY,CA2D9F"}
@@ -1,26 +1,13 @@
1
- import { log } from '@luma.gl/core';
2
1
  import { GL } from '@luma.gl/constants';
3
2
  import { isWebGL2 } from "../../context/context/webgl-checks.js";
4
3
  import { Accessor } from "../../classic/accessor.js";
5
- import { decodeUniformType, decodeAttributeType } from "./uniforms.js";
6
- import { getVertexFormat } from "../converters/vertex-formats.js";
7
- import { isSamplerUniform } from "./uniforms.js";
4
+ import { decodeGLUniformType, decodeGLAttributeType, isSamplerUniform } from "./decode-webgl-types.js";
8
5
  export function getShaderLayout(gl, program) {
9
6
  const shaderLayout = {
10
7
  attributes: [],
11
8
  bindings: []
12
9
  };
13
- const attributes = readAttributeBindings(gl, program);
14
- for (const attribute of attributes) {
15
- const size = Math.min(attribute.accessor.size, 4);
16
- const format = getVertexFormat(attribute.accessor.type || GL.FLOAT, size);
17
- shaderLayout.attributes.push({
18
- name: attribute.name,
19
- location: attribute.location,
20
- format,
21
- stepMode: attribute.accessor.divisor === 1 ? 'instance' : 'vertex'
22
- });
23
- }
10
+ shaderLayout.attributes = readAttributeDeclarations(gl, program);
24
11
  const uniformBlocks = readUniformBlocks(gl, program);
25
12
  for (const uniformBlock of uniformBlocks) {
26
13
  const uniforms = uniformBlock.uniforms.map(uniform => ({
@@ -67,58 +54,7 @@ export function getShaderLayout(gl, program) {
67
54
  }
68
55
  return shaderLayout;
69
56
  }
70
- export function mergeShaderLayout(baseLayout, overrideLayout) {
71
- const mergedLayout = {
72
- ...baseLayout,
73
- attributes: baseLayout.attributes.map(attribute => ({
74
- ...attribute
75
- }))
76
- };
77
- for (const attribute of (overrideLayout === null || overrideLayout === void 0 ? void 0 : overrideLayout.attributes) || []) {
78
- const baseAttribute = mergedLayout.attributes.find(attr => attr.name === attribute.name);
79
- if (!baseAttribute) {
80
- log.warn("shader layout attribute ".concat(attribute.name, " not present in shader"));
81
- } else {
82
- baseAttribute.format = attribute.format || baseAttribute.format;
83
- baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
84
- }
85
- }
86
- return mergedLayout;
87
- }
88
- export function mergeBufferMap(baseLayout, bufferMap) {
89
- const mergedLayout = {
90
- ...baseLayout,
91
- attributes: baseLayout.attributes.map(attribute => ({
92
- ...attribute
93
- }))
94
- };
95
- for (const bufferMapping of bufferMap) {
96
- switch (bufferMapping.type) {
97
- case 'interleave':
98
- for (const attributeOverride of bufferMapping.attributes) {
99
- overrideShaderLayoutAttribute(mergedLayout, attributeOverride);
100
- }
101
- break;
102
- default:
103
- overrideShaderLayoutAttribute(mergedLayout, bufferMapping);
104
- }
105
- }
106
- return mergedLayout;
107
- }
108
- function overrideShaderLayoutAttribute(layout, attributeOverride) {
109
- const attribute = getAttributeFromLayout(layout, attributeOverride.name);
110
- if (attribute && attributeOverride.format) {
111
- attribute.format = attributeOverride.format;
112
- }
113
- }
114
- export function getAttributeFromLayout(shaderLayout, name) {
115
- const attribute = shaderLayout.attributes.find(attr => attr.name === name);
116
- if (!attribute) {
117
- log.warn("shader layout attribute \"".concat(name, "\" not present in shader"));
118
- }
119
- return attribute || null;
120
- }
121
- function readAttributeBindings(gl, program) {
57
+ function readAttributeDeclarations(gl, program) {
122
58
  const attributes = [];
123
59
  const count = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
124
60
  for (let index = 0; index < count; index++) {
@@ -128,28 +64,20 @@ function readAttributeBindings(gl, program) {
128
64
  }
129
65
  const {
130
66
  name,
131
- type: compositeType,
132
- size
67
+ type: compositeType
133
68
  } = activeInfo;
134
69
  const location = gl.getAttribLocation(program, name);
135
70
  if (location >= 0) {
136
71
  const {
137
- glType,
138
- components
139
- } = decodeAttributeType(compositeType);
140
- const accessor = {
141
- type: glType,
142
- size: size * components
143
- };
144
- if (/instance/i.test(name)) {
145
- accessor.divisor = 1;
146
- }
147
- const attributeInfo = {
148
- location,
72
+ attributeType
73
+ } = decodeGLAttributeType(compositeType);
74
+ const stepMode = /instance/i.test(name) ? 'instance' : 'vertex';
75
+ attributes.push({
149
76
  name,
150
- accessor: new Accessor(accessor)
151
- };
152
- attributes.push(attributeInfo);
77
+ location,
78
+ stepMode,
79
+ type: attributeType
80
+ });
153
81
  }
154
82
  }
155
83
  attributes.sort((a, b) => a.location - b.location);
@@ -175,7 +103,7 @@ function readVaryings(gl, program) {
175
103
  const {
176
104
  glType,
177
105
  components
178
- } = decodeUniformType(compositeType);
106
+ } = decodeGLUniformType(compositeType);
179
107
  const accessor = new Accessor({
180
108
  type: glType,
181
109
  size: size * components
@@ -261,7 +189,7 @@ function readUniformBlocks(gl, program) {
261
189
  }
262
190
  blockInfo.uniforms.push({
263
191
  name: activeInfo.name,
264
- format: decodeUniformType(uniformType[i]).format,
192
+ format: decodeGLUniformType(uniformType[i]).format,
265
193
  type: uniformType[i],
266
194
  arrayLength: uniformArrayLength[i],
267
195
  byteOffset: uniformOffset[i],
@@ -1 +1 @@
1
- {"version":3,"file":"get-shader-layout.js","names":["log","GL","isWebGL2","Accessor","decodeUniformType","decodeAttributeType","getVertexFormat","isSamplerUniform","getShaderLayout","gl","program","shaderLayout","attributes","bindings","readAttributeBindings","attribute","size","Math","min","accessor","format","type","FLOAT","push","name","location","stepMode","divisor","uniformBlocks","readUniformBlocks","uniformBlock","uniforms","map","uniform","byteOffset","byteStride","arrayLength","visibility","vertex","fragment","minBindingSize","byteLength","readUniformBindings","textureUnit","viewDimension","sampleType","getSamplerInfo","length","varyings","readVaryings","mergeShaderLayout","baseLayout","overrideLayout","mergedLayout","baseAttribute","find","attr","warn","concat","mergeBufferMap","bufferMap","bufferMapping","attributeOverride","overrideShaderLayoutAttribute","layout","getAttributeFromLayout","count","getProgramParameter","ACTIVE_ATTRIBUTES","index","activeInfo","getActiveAttrib","Error","compositeType","getAttribLocation","glType","components","test","attributeInfo","sort","a","b","gl2","TRANSFORM_FEEDBACK_VARYINGS","getTransformFeedbackVarying","varying","uniformCount","ACTIVE_UNIFORMS","i","getActiveUniform","rawName","isArray","parseUniformName","webglLocation","getUniformLocation","uniformInfo","j","elementName","arrayElementUniformInfo","getBlockParameter","blockIndex","pname","getActiveUniformBlockParameter","blockCount","ACTIVE_UNIFORM_BLOCKS","blockInfo","getActiveUniformBlockName","UNIFORM_BLOCK_BINDING","UNIFORM_BLOCK_DATA_SIZE","UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER","UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER","UNIFORM_BLOCK_ACTIVE_UNIFORMS","uniformIndices","UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES","uniformType","getActiveUniforms","UNIFORM_TYPE","uniformArrayLength","UNIFORM_SIZE","uniformOffset","UNIFORM_OFFSET","uniformStride","UNIFORM_ARRAY_STRIDE","SAMPLER_UNIFORMS_GL_TO_GPU","SAMPLER_2D","SAMPLER_CUBE","SAMPLER_3D","SAMPLER_2D_SHADOW","SAMPLER_2D_ARRAY","SAMPLER_2D_ARRAY_SHADOW","SAMPLER_CUBE_SHADOW","INT_SAMPLER_2D","INT_SAMPLER_3D","INT_SAMPLER_CUBE","INT_SAMPLER_2D_ARRAY","UNSIGNED_INT_SAMPLER_2D","UNSIGNED_INT_SAMPLER_3D","UNSIGNED_INT_SAMPLER_CUBE","UNSIGNED_INT_SAMPLER_2D_ARRAY","sampler","UNIFORM_NAME_REGEXP","matches","exec","Boolean"],"sources":["../../../src/adapter/helpers/get-shader-layout.ts"],"sourcesContent":["// luma.gl, MIT license\n\nimport type {\n ShaderLayout,\n AttributeLayout,\n UniformBinding,\n UniformBlockBinding,\n AttributeBinding,\n VaryingBinding,\n AccessorObject,\n BufferMapping,\n VertexFormat\n} from '@luma.gl/core';\nimport {log} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\nimport {isWebGL2} from '../../context/context/webgl-checks';\nimport {Accessor} from '../../classic/accessor'; // TODO - should NOT depend on classic API\nimport {decodeUniformType, decodeAttributeType} from './uniforms';\nimport {getVertexFormat} from '../converters/vertex-formats';\nimport {isSamplerUniform} from './uniforms';\n\n/**\n * Extract metadata describing binding information for a program's shaders\n * Note: `linkProgram()` needs to have been called\n * (although linking does not need to have been successful).\n */\nexport function getShaderLayout(gl: WebGLRenderingContext, program: WebGLProgram): ShaderLayout {\n const shaderLayout: ShaderLayout = {\n attributes: [],\n bindings: []\n };\n\n const attributes: AttributeBinding[] = readAttributeBindings(gl, program);\n for (const attribute of attributes) {\n // TODO - multicolumn attributes like a matrix4 can be up to 16 elts...\n const size = Math.min(attribute.accessor.size, 4);\n const format =\n // attribute.accessor.format ||\n getVertexFormat(attribute.accessor.type || GL.FLOAT, size);\n shaderLayout.attributes.push({\n name: attribute.name,\n location: attribute.location,\n format,\n stepMode: attribute.accessor.divisor === 1 ? 'instance' : 'vertex'\n });\n }\n\n // Uniform blocks\n const uniformBlocks: UniformBlockBinding[] = readUniformBlocks(gl, program);\n for (const uniformBlock of uniformBlocks) {\n const uniforms = uniformBlock.uniforms.map(uniform => ({\n name: uniform.name,\n format: uniform.format,\n byteOffset: uniform.byteOffset,\n byteStride: uniform.byteStride,\n arrayLength: uniform.arrayLength\n }));\n shaderLayout.bindings.push({\n type: 'uniform',\n name: uniformBlock.name,\n location: uniformBlock.location,\n visibility: (uniformBlock.vertex ? 0x1 : 0) & (uniformBlock.fragment ? 0x2 : 0),\n minBindingSize: uniformBlock.byteLength,\n uniforms\n });\n }\n\n const uniforms: UniformBinding[] = readUniformBindings(gl, program);\n let textureUnit = 0;\n for (const uniform of uniforms) {\n if (isSamplerUniform(uniform.type)) {\n const {viewDimension, sampleType} = getSamplerInfo(uniform.type);\n shaderLayout.bindings.push({\n type: 'texture',\n name: uniform.name,\n location: textureUnit,\n viewDimension,\n sampleType\n });\n\n // @ts-expect-error\n uniform.textureUnit = textureUnit;\n textureUnit += 1;\n }\n }\n\n if (uniforms.length) {\n shaderLayout.uniforms = uniforms;\n }\n\n // Varyings\n const varyings: VaryingBinding[] = readVaryings(gl, program);\n // Note - samplers are always in unform bindings, even if uniform blocks are used\n if (varyings?.length) {\n shaderLayout.varyings = varyings;\n }\n\n return shaderLayout;\n}\n\n/**\n * Merges an provided shader layout into a base shader layout\n * In WebGL, this allows the auto generated shader layout to be overridden by the application\n * Typically to change the format of the vertex attributes (from float32x4 to uint8x4 etc).\n * @todo Drop this? This could also be done more clearly with bufferMapping\n */\nexport function mergeShaderLayout(\n baseLayout: ShaderLayout,\n overrideLayout: ShaderLayout\n): ShaderLayout {\n // Deep clone the base layout\n const mergedLayout: ShaderLayout = {\n ...baseLayout,\n attributes: baseLayout.attributes.map(attribute => ({...attribute}))\n };\n // Merge the attributes\n for (const attribute of overrideLayout?.attributes || []) {\n const baseAttribute = mergedLayout.attributes.find(attr => attr.name === attribute.name);\n if (!baseAttribute) {\n log.warn(`shader layout attribute ${attribute.name} not present in shader`);\n } else {\n baseAttribute.format = attribute.format || baseAttribute.format;\n baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;\n }\n }\n return mergedLayout;\n}\n\nexport function mergeBufferMap(baseLayout: ShaderLayout, bufferMap: BufferMapping[]): ShaderLayout {\n // Deep clone the base layout\n const mergedLayout: ShaderLayout = {\n ...baseLayout,\n attributes: baseLayout.attributes.map(attribute => ({...attribute}))\n };\n for (const bufferMapping of bufferMap) {\n // Handle interleave\n switch (bufferMapping.type) {\n case 'interleave':\n // Handle interleaved buffer mapping\n for (const attributeOverride of bufferMapping.attributes) {\n overrideShaderLayoutAttribute(mergedLayout, attributeOverride);\n }\n break;\n\n default:\n // Handle simple attribute overrides\n overrideShaderLayoutAttribute(mergedLayout, bufferMapping);\n }\n }\n return mergedLayout;\n}\n\nfunction overrideShaderLayoutAttribute(\n layout: ShaderLayout,\n attributeOverride: {name: string; format?: VertexFormat}\n): void {\n const attribute = getAttributeFromLayout(layout, attributeOverride.name);\n if (attribute && attributeOverride.format) {\n attribute.format = attributeOverride.format;\n }\n}\n\nexport function getAttributeFromLayout(\n shaderLayout: ShaderLayout,\n name: string\n): AttributeLayout | null {\n const attribute = shaderLayout.attributes.find(attr => attr.name === name);\n if (!attribute) {\n log.warn(`shader layout attribute \"${name}\" not present in shader`);\n }\n return attribute || null;\n}\n\n// HELPERS\n\n/**\n * Extract info about all transform feedback varyings\n *\n * linkProgram needs to have been called, although linking does not need to have been successful\n */\nfunction readAttributeBindings(\n gl: WebGLRenderingContext,\n program: WebGLProgram\n): AttributeBinding[] {\n const attributes: AttributeBinding[] = [];\n\n const count = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);\n\n for (let index = 0; index < count; index++) {\n const activeInfo = gl.getActiveAttrib(program, index);\n if (!activeInfo) {\n throw new Error('activeInfo');\n }\n const {name, type: compositeType, size} = activeInfo;\n const location = gl.getAttribLocation(program, name);\n // Add only user provided attributes, for built-in attributes like\n // `gl_InstanceID` locaiton will be < 0\n if (location >= 0) {\n const {glType, components} = decodeAttributeType(compositeType);\n const accessor: AccessorObject = {type: glType, size: size * components};\n // Any attribute name containing the word \"instance\" will be assumed to be instanced\n if (/instance/i.test(name)) {\n accessor.divisor = 1;\n }\n const attributeInfo = {location, name, accessor: new Accessor(accessor)}; // Base values\n attributes.push(attributeInfo);\n }\n }\n\n attributes.sort((a: AttributeBinding, b: AttributeBinding) => a.location - b.location);\n return attributes;\n}\n\n/**\n * Extract info about all transform feedback varyings\n *\n * linkProgram needs to have been called, although linking does not need to have been successful\n */\nfunction readVaryings(gl: WebGLRenderingContext, program: WebGLProgram): VaryingBinding[] {\n if (!isWebGL2(gl)) {\n return [];\n }\n const gl2 = gl as WebGL2RenderingContext;\n\n const varyings: VaryingBinding[] = [];\n\n const count = gl.getProgramParameter(program, GL.TRANSFORM_FEEDBACK_VARYINGS);\n for (let location = 0; location < count; location++) {\n const activeInfo = gl2.getTransformFeedbackVarying(program, location);\n if (!activeInfo) {\n throw new Error('activeInfo');\n }\n const {name, type: compositeType, size} = activeInfo;\n const {glType, components} = decodeUniformType(compositeType);\n const accessor = new Accessor({type: glType, size: size * components});\n const varying = {location, name, accessor}; // Base values\n varyings.push(varying);\n }\n\n varyings.sort((a, b) => a.location - b.location);\n return varyings;\n}\n\n/**\n * Extract info about all uniforms\n *\n * Query uniform locations and build name to setter map.\n */\nfunction readUniformBindings(gl: WebGLRenderingContext, program: WebGLProgram): UniformBinding[] {\n const uniforms: UniformBinding[] = [];\n\n const uniformCount = gl.getProgramParameter(program, GL.ACTIVE_UNIFORMS);\n for (let i = 0; i < uniformCount; i++) {\n const activeInfo = gl.getActiveUniform(program, i);\n if (!activeInfo) {\n throw new Error('activeInfo');\n }\n const {name: rawName, size, type} = activeInfo;\n const {name, isArray} = parseUniformName(rawName);\n let webglLocation = gl.getUniformLocation(program, name);\n const uniformInfo = {\n // WebGL locations are uniquely typed but just numbers\n location: webglLocation as number,\n name,\n size,\n type,\n isArray\n };\n uniforms.push(uniformInfo);\n\n // Array (e.g. matrix) uniforms can occupy several 4x4 byte banks\n if (uniformInfo.size > 1) {\n for (let j = 0; j < uniformInfo.size; j++) {\n const elementName = `${name}[${j}]`;\n\n webglLocation = gl.getUniformLocation(program, elementName);\n\n const arrayElementUniformInfo = {\n ...uniformInfo,\n name: elementName,\n location: webglLocation as number\n };\n\n uniforms.push(arrayElementUniformInfo);\n }\n }\n }\n return uniforms;\n}\n\n/**\n * Extract info about all \"active\" uniform blocks\n *\n * (\"Active\" just means that unused (aka inactive) blocks may have been\n * optimized away during linking)\n */\nfunction readUniformBlocks(\n gl: WebGLRenderingContext,\n program: WebGLProgram\n): UniformBlockBinding[] {\n if (!isWebGL2(gl)) {\n return [];\n }\n const gl2 = gl as WebGL2RenderingContext;\n\n const getBlockParameter = (blockIndex: number, pname: GL): any =>\n gl2.getActiveUniformBlockParameter(program, blockIndex, pname);\n\n const uniformBlocks: UniformBlockBinding[] = [];\n\n const blockCount = gl2.getProgramParameter(program, GL.ACTIVE_UNIFORM_BLOCKS);\n for (let blockIndex = 0; blockIndex < blockCount; blockIndex++) {\n const blockInfo: UniformBlockBinding = {\n name: gl2.getActiveUniformBlockName(program, blockIndex) || '',\n location: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_BINDING),\n byteLength: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_DATA_SIZE),\n vertex: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),\n fragment: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER),\n uniformCount: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_ACTIVE_UNIFORMS),\n uniforms: [] as any[]\n };\n\n const uniformIndices =\n (getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) as number[]) || [];\n\n const uniformType = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_TYPE); // Array of GLenum indicating the types of the uniforms.\n const uniformArrayLength = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_SIZE); // Array of GLuint indicating the sizes of the uniforms.\n // const uniformBlockIndex = gl2.getActiveUniforms(\n // program,\n // uniformIndices,\n // GL.UNIFORM_BLOCK_INDEX\n // ); // Array of GLint indicating the block indices of the uniforms.\n const uniformOffset = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_OFFSET); // Array of GLint indicating the uniform buffer offsets.\n const uniformStride = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_ARRAY_STRIDE); // Array of GLint indicating the strides between the elements.\n // const uniformMatrixStride = gl2.getActiveUniforms(\n // program,\n // uniformIndices,\n // GL.UNIFORM_MATRIX_STRIDE\n // ); // Array of GLint indicating the strides between columns of a column-major matrix or a row-major matrix.\n // const uniformRowMajor = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_IS_ROW_MAJOR);\n for (let i = 0; i < blockInfo.uniformCount; ++i) {\n const activeInfo = gl2.getActiveUniform(program, uniformIndices[i]);\n if (!activeInfo) {\n throw new Error('activeInfo');\n }\n\n blockInfo.uniforms.push({\n name: activeInfo.name,\n format: decodeUniformType(uniformType[i]).format,\n type: uniformType[i],\n arrayLength: uniformArrayLength[i],\n byteOffset: uniformOffset[i],\n byteStride: uniformStride[i]\n // matrixStride: uniformStride[i],\n // rowMajor: uniformRowMajor[i]\n });\n }\n\n uniformBlocks.push(blockInfo);\n }\n\n uniformBlocks.sort((a, b) => a.location - b.location);\n return uniformBlocks;\n}\n\nconst SAMPLER_UNIFORMS_GL_TO_GPU: Record<\n number,\n [\n '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d',\n 'float' | 'unfilterable-float' | 'depth' | 'sint' | 'uint'\n ]\n> = {\n [GL.SAMPLER_2D]: ['2d', 'float'],\n [GL.SAMPLER_CUBE]: ['cube', 'float'],\n [GL.SAMPLER_3D]: ['3d', 'float'],\n [GL.SAMPLER_2D_SHADOW]: ['3d', 'depth'],\n [GL.SAMPLER_2D_ARRAY]: ['2d-array', 'float'],\n [GL.SAMPLER_2D_ARRAY_SHADOW]: ['2d-array', 'depth'],\n [GL.SAMPLER_CUBE_SHADOW]: ['cube', 'float'],\n [GL.INT_SAMPLER_2D]: ['2d', 'sint'],\n [GL.INT_SAMPLER_3D]: ['3d', 'sint'],\n [GL.INT_SAMPLER_CUBE]: ['cube', 'sint'],\n [GL.INT_SAMPLER_2D_ARRAY]: ['2d-array', 'uint'],\n [GL.UNSIGNED_INT_SAMPLER_2D]: ['2d', 'uint'],\n [GL.UNSIGNED_INT_SAMPLER_3D]: ['3d', 'uint'],\n [GL.UNSIGNED_INT_SAMPLER_CUBE]: ['cube', 'uint'],\n [GL.UNSIGNED_INT_SAMPLER_2D_ARRAY]: ['2d-array', 'uint']\n};\n\ntype SamplerInfo = {\n viewDimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';\n sampleType: 'float' | 'unfilterable-float' | 'depth' | 'sint' | 'uint';\n};\n\nfunction getSamplerInfo(type: GL): SamplerInfo {\n const sampler = SAMPLER_UNIFORMS_GL_TO_GPU[type];\n if (!sampler) {\n throw new Error('sampler');\n }\n const [viewDimension, sampleType] = sampler;\n return {viewDimension, sampleType};\n}\n\n// HELPERS\n\nfunction parseUniformName(name: string): {name: string; length: number; isArray: boolean} {\n // Shortcut to avoid redundant or bad matches\n if (name[name.length - 1] !== ']') {\n return {\n name,\n length: 1,\n isArray: false\n };\n }\n\n // if array name then clean the array brackets\n const UNIFORM_NAME_REGEXP = /([^[]*)(\\[[0-9]+\\])?/;\n const matches = UNIFORM_NAME_REGEXP.exec(name);\n if (!matches || matches.length < 2) {\n throw new Error(`Failed to parse GLSL uniform name ${name}`);\n }\n\n return {\n name: matches[1],\n length: matches[2] ? 1 : 0,\n isArray: Boolean(matches[2])\n };\n}\n\n/**\n * TODO - verify this is a copy of above and delete\n * import type {TextureFormat} from '@luma.gl/core';\n* Extract info about all \"active\" uniform blocks\n * (\"Active\" just means that unused (inactive) blocks may have been optimized away during linking)\n *\n function getUniformBlockBindings(gl: WebGLRenderingContext, program): Binding[] {\n if (!isWebGL2(gl)) {\n return;\n }\n const bindings: Binding[] = [];\n const count = gl.getProgramParameter(program, gl.ACTIVE_UNIFORM_BLOCKS);\n for (let blockIndex = 0; blockIndex < count; blockIndex++) {\n const vertex = gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),\n const fragment = gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER),\n const visibility = (vertex) + (fragment);\n const binding: BufferBinding = {\n location: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_BINDING),\n // name: gl.getActiveUniformBlockName(program, blockIndex),\n type: 'uniform',\n visibility,\n minBindingSize: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_DATA_SIZE),\n // uniformCount: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_ACTIVE_UNIFORMS),\n // uniformIndices: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES),\n }\n bindings.push(binding);\n }\n return bindings;\n}\n\nfunction setBindings(gl2: WebGL2RenderingContext, program: WebGLProgram, bindings: Binding[][]): void {\n for (const bindGroup of bindings) {\n for (const binding of bindGroup) {\n\n }\n }\n\n // Set up indirection table\n // this.gl2.uniformBlockBinding(this.handle, blockIndex, blockBinding);\n}\n */\n"],"mappings":"AAaA,SAAQA,GAAG,QAAO,eAAe;AACjC,SAAQC,EAAE,QAAO,oBAAoB;AAAC,SAC9BC,QAAQ;AAAA,SACRC,QAAQ;AAAA,SACRC,iBAAiB,EAAEC,mBAAmB;AAAA,SACtCC,eAAe;AAAA,SACfC,gBAAgB;AAOxB,OAAO,SAASC,eAAeA,CAACC,EAAyB,EAAEC,OAAqB,EAAgB;EAC9F,MAAMC,YAA0B,GAAG;IACjCC,UAAU,EAAE,EAAE;IACdC,QAAQ,EAAE;EACZ,CAAC;EAED,MAAMD,UAA8B,GAAGE,qBAAqB,CAACL,EAAE,EAAEC,OAAO,CAAC;EACzE,KAAK,MAAMK,SAAS,IAAIH,UAAU,EAAE;IAElC,MAAMI,IAAI,GAAGC,IAAI,CAACC,GAAG,CAACH,SAAS,CAACI,QAAQ,CAACH,IAAI,EAAE,CAAC,CAAC;IACjD,MAAMI,MAAM,GAEVd,eAAe,CAACS,SAAS,CAACI,QAAQ,CAACE,IAAI,IAAIpB,EAAE,CAACqB,KAAK,EAAEN,IAAI,CAAC;IAC5DL,YAAY,CAACC,UAAU,CAACW,IAAI,CAAC;MAC3BC,IAAI,EAAET,SAAS,CAACS,IAAI;MACpBC,QAAQ,EAAEV,SAAS,CAACU,QAAQ;MAC5BL,MAAM;MACNM,QAAQ,EAAEX,SAAS,CAACI,QAAQ,CAACQ,OAAO,KAAK,CAAC,GAAG,UAAU,GAAG;IAC5D,CAAC,CAAC;EACJ;EAGA,MAAMC,aAAoC,GAAGC,iBAAiB,CAACpB,EAAE,EAAEC,OAAO,C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AO;IAAC/F,aAAa;IAAEC;EAAU,CAAC;AACpC;AAIA,SAAS+C,gBAAgBA,CAACpE,IAAY,EAAoD;EAExF,IAAIA,IAAI,CAACA,IAAI,CAACuB,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE;IACjC,OAAO;MACLvB,IAAI;MACJuB,MAAM,EAAE,CAAC;MACT4C,OAAO,EAAE;IACX,CAAC;EACH;EAGA,MAAMiD,mBAAmB,GAAG,sBAAsB;EAClD,MAAMC,OAAO,GAAGD,mBAAmB,CAACE,IAAI,CAACtH,IAAI,CAAC;EAC9C,IAAI,CAACqH,OAAO,IAAIA,OAAO,CAAC9F,MAAM,GAAG,CAAC,EAAE;IAClC,MAAM,IAAIyB,KAAK,sCAAAd,MAAA,CAAsClC,IAAI,CAAE,CAAC;EAC9D;EAEA,OAAO;IACLA,IAAI,EAAEqH,OAAO,CAAC,CAAC,CAAC;IAChB9F,MAAM,EAAE8F,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAC1BlD,OAAO,EAAEoD,OAAO,CAACF,OAAO,CAAC,CAAC,CAAC;EAC7B,CAAC;AACH"}
1
+ {"version":3,"file":"get-shader-layout.js","names":["GL","isWebGL2","Accessor","decodeGLUniformType","decodeGLAttributeType","isSamplerUniform","getShaderLayout","gl","program","shaderLayout","attributes","bindings","readAttributeDeclarations","uniformBlocks","readUniformBlocks","uniformBlock","uniforms","map","uniform","name","format","byteOffset","byteStride","arrayLength","push","type","location","visibility","vertex","fragment","minBindingSize","byteLength","readUniformBindings","textureUnit","viewDimension","sampleType","getSamplerInfo","length","varyings","readVaryings","count","getProgramParameter","ACTIVE_ATTRIBUTES","index","activeInfo","getActiveAttrib","Error","compositeType","getAttribLocation","attributeType","stepMode","test","sort","a","b","gl2","TRANSFORM_FEEDBACK_VARYINGS","getTransformFeedbackVarying","size","glType","components","accessor","varying","uniformCount","ACTIVE_UNIFORMS","i","getActiveUniform","rawName","isArray","parseUniformName","webglLocation","getUniformLocation","uniformInfo","j","elementName","concat","arrayElementUniformInfo","getBlockParameter","blockIndex","pname","getActiveUniformBlockParameter","blockCount","ACTIVE_UNIFORM_BLOCKS","blockInfo","getActiveUniformBlockName","UNIFORM_BLOCK_BINDING","UNIFORM_BLOCK_DATA_SIZE","UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER","UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER","UNIFORM_BLOCK_ACTIVE_UNIFORMS","uniformIndices","UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES","uniformType","getActiveUniforms","UNIFORM_TYPE","uniformArrayLength","UNIFORM_SIZE","uniformOffset","UNIFORM_OFFSET","uniformStride","UNIFORM_ARRAY_STRIDE","SAMPLER_UNIFORMS_GL_TO_GPU","SAMPLER_2D","SAMPLER_CUBE","SAMPLER_3D","SAMPLER_2D_SHADOW","SAMPLER_2D_ARRAY","SAMPLER_2D_ARRAY_SHADOW","SAMPLER_CUBE_SHADOW","INT_SAMPLER_2D","INT_SAMPLER_3D","INT_SAMPLER_CUBE","INT_SAMPLER_2D_ARRAY","UNSIGNED_INT_SAMPLER_2D","UNSIGNED_INT_SAMPLER_3D","UNSIGNED_INT_SAMPLER_CUBE","UNSIGNED_INT_SAMPLER_2D_ARRAY","sampler","UNIFORM_NAME_REGEXP","matches","exec","Boolean"],"sources":["../../../src/adapter/helpers/get-shader-layout.ts"],"sourcesContent":["// luma.gl, MIT license\n\nimport type {\n ShaderLayout,\n UniformBinding,\n UniformBlockBinding,\n AttributeDeclaration,\n VaryingBinding\n} from '@luma.gl/core';\n\nimport {GL} from '@luma.gl/constants';\nimport {isWebGL2} from '../../context/context/webgl-checks';\nimport {Accessor} from '../../classic/accessor'; // TODO - should NOT depend on classic API\nimport {decodeGLUniformType, decodeGLAttributeType, isSamplerUniform} from './decode-webgl-types';\n\n/**\n * Extract metadata describing binding information for a program's shaders\n * Note: `linkProgram()` needs to have been called\n * (although linking does not need to have been successful).\n */\nexport function getShaderLayout(gl: WebGLRenderingContext, program: WebGLProgram): ShaderLayout {\n const shaderLayout: ShaderLayout = {\n attributes: [],\n bindings: []\n };\n\n shaderLayout.attributes = readAttributeDeclarations(gl, program);\n\n // Uniform blocks\n const uniformBlocks: UniformBlockBinding[] = readUniformBlocks(gl, program);\n for (const uniformBlock of uniformBlocks) {\n const uniforms = uniformBlock.uniforms.map(uniform => ({\n name: uniform.name,\n format: uniform.format,\n byteOffset: uniform.byteOffset,\n byteStride: uniform.byteStride,\n arrayLength: uniform.arrayLength\n }));\n shaderLayout.bindings.push({\n type: 'uniform',\n name: uniformBlock.name,\n location: uniformBlock.location,\n visibility: (uniformBlock.vertex ? 0x1 : 0) & (uniformBlock.fragment ? 0x2 : 0),\n minBindingSize: uniformBlock.byteLength,\n uniforms\n });\n }\n\n const uniforms: UniformBinding[] = readUniformBindings(gl, program);\n let textureUnit = 0;\n for (const uniform of uniforms) {\n if (isSamplerUniform(uniform.type)) {\n const {viewDimension, sampleType} = getSamplerInfo(uniform.type);\n shaderLayout.bindings.push({\n type: 'texture',\n name: uniform.name,\n location: textureUnit,\n viewDimension,\n sampleType\n });\n\n // @ts-expect-error\n uniform.textureUnit = textureUnit;\n textureUnit += 1;\n }\n }\n\n if (uniforms.length) {\n shaderLayout.uniforms = uniforms;\n }\n\n // Varyings\n const varyings: VaryingBinding[] = readVaryings(gl, program);\n // Note - samplers are always in unform bindings, even if uniform blocks are used\n if (varyings?.length) {\n shaderLayout.varyings = varyings;\n }\n\n return shaderLayout;\n}\n\n// HELPERS\n\n/**\n * Extract info about all transform feedback varyings\n *\n * linkProgram needs to have been called, although linking does not need to have been successful\n */\nfunction readAttributeDeclarations(\n gl: WebGLRenderingContext,\n program: WebGLProgram\n): AttributeDeclaration[] {\n const attributes: AttributeDeclaration[] = [];\n\n const count = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);\n\n for (let index = 0; index < count; index++) {\n const activeInfo = gl.getActiveAttrib(program, index);\n if (!activeInfo) {\n throw new Error('activeInfo');\n }\n const {name, type: compositeType /* , size*/} = activeInfo;\n const location = gl.getAttribLocation(program, name);\n // Add only user provided attributes, for built-in attributes like `gl_InstanceID` location will be < 0\n if (location >= 0) {\n const {attributeType} = decodeGLAttributeType(compositeType);\n\n // Whether an attribute is instanced is essentially fixed by the structure of the shader code, \n // so it is arguably a static property of the shader.\n // There is no hint in the shader declarations\n // Heuristic: Any attribute name containing the word \"instance\" will be assumed to be instanced\n const stepMode = /instance/i.test(name) ? 'instance' : 'vertex';\n\n attributes.push({\n name,\n location,\n stepMode,\n type: attributeType,\n // size - for arrays, size is the number of elements in the array\n });\n }\n }\n\n // Sort by declaration order\n attributes.sort((a: AttributeDeclaration, b: AttributeDeclaration) => a.location - b.location);\n return attributes;\n}\n\n/**\n * Extract info about all transform feedback varyings\n *\n * linkProgram needs to have been called, although linking does not need to have been successful\n */\nfunction readVaryings(gl: WebGLRenderingContext, program: WebGLProgram): VaryingBinding[] {\n if (!isWebGL2(gl)) {\n return [];\n }\n const gl2 = gl as WebGL2RenderingContext;\n\n const varyings: VaryingBinding[] = [];\n\n const count = gl.getProgramParameter(program, GL.TRANSFORM_FEEDBACK_VARYINGS);\n for (let location = 0; location < count; location++) {\n const activeInfo = gl2.getTransformFeedbackVarying(program, location);\n if (!activeInfo) {\n throw new Error('activeInfo');\n }\n const {name, type: compositeType, size} = activeInfo;\n const {glType, components} = decodeGLUniformType(compositeType);\n const accessor = new Accessor({type: glType, size: size * components});\n const varying = {location, name, accessor}; // Base values\n varyings.push(varying);\n }\n\n varyings.sort((a, b) => a.location - b.location);\n return varyings;\n}\n\n/**\n * Extract info about all uniforms\n *\n * Query uniform locations and build name to setter map.\n */\nfunction readUniformBindings(gl: WebGLRenderingContext, program: WebGLProgram): UniformBinding[] {\n const uniforms: UniformBinding[] = [];\n\n const uniformCount = gl.getProgramParameter(program, GL.ACTIVE_UNIFORMS);\n for (let i = 0; i < uniformCount; i++) {\n const activeInfo = gl.getActiveUniform(program, i);\n if (!activeInfo) {\n throw new Error('activeInfo');\n }\n const {name: rawName, size, type} = activeInfo;\n const {name, isArray} = parseUniformName(rawName);\n let webglLocation = gl.getUniformLocation(program, name);\n const uniformInfo = {\n // WebGL locations are uniquely typed but just numbers\n location: webglLocation as number,\n name,\n size,\n type,\n isArray\n };\n uniforms.push(uniformInfo);\n\n // Array (e.g. matrix) uniforms can occupy several 4x4 byte banks\n if (uniformInfo.size > 1) {\n for (let j = 0; j < uniformInfo.size; j++) {\n const elementName = `${name}[${j}]`;\n\n webglLocation = gl.getUniformLocation(program, elementName);\n\n const arrayElementUniformInfo = {\n ...uniformInfo,\n name: elementName,\n location: webglLocation as number\n };\n\n uniforms.push(arrayElementUniformInfo);\n }\n }\n }\n return uniforms;\n}\n\n/**\n * Extract info about all \"active\" uniform blocks\n * @note In WebGL, \"active\" just means that unused (inactive) blocks may have been optimized away during linking)\n */\nfunction readUniformBlocks(\n gl: WebGLRenderingContext,\n program: WebGLProgram\n): UniformBlockBinding[] {\n if (!isWebGL2(gl)) {\n return [];\n }\n const gl2 = gl as WebGL2RenderingContext;\n\n const getBlockParameter = (blockIndex: number, pname: GL): any =>\n gl2.getActiveUniformBlockParameter(program, blockIndex, pname);\n\n const uniformBlocks: UniformBlockBinding[] = [];\n\n const blockCount = gl2.getProgramParameter(program, GL.ACTIVE_UNIFORM_BLOCKS);\n for (let blockIndex = 0; blockIndex < blockCount; blockIndex++) {\n const blockInfo: UniformBlockBinding = {\n name: gl2.getActiveUniformBlockName(program, blockIndex) || '',\n location: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_BINDING),\n byteLength: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_DATA_SIZE),\n vertex: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),\n fragment: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER),\n uniformCount: getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_ACTIVE_UNIFORMS),\n uniforms: [] as any[]\n };\n\n const uniformIndices =\n (getBlockParameter(blockIndex, GL.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) as number[]) || [];\n\n const uniformType = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_TYPE); // Array of GLenum indicating the types of the uniforms.\n const uniformArrayLength = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_SIZE); // Array of GLuint indicating the sizes of the uniforms.\n // const uniformBlockIndex = gl2.getActiveUniforms(\n // program,\n // uniformIndices,\n // GL.UNIFORM_BLOCK_INDEX\n // ); // Array of GLint indicating the block indices of the uniforms.\n const uniformOffset = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_OFFSET); // Array of GLint indicating the uniform buffer offsets.\n const uniformStride = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_ARRAY_STRIDE); // Array of GLint indicating the strides between the elements.\n // const uniformMatrixStride = gl2.getActiveUniforms(\n // program,\n // uniformIndices,\n // GL.UNIFORM_MATRIX_STRIDE\n // ); // Array of GLint indicating the strides between columns of a column-major matrix or a row-major matrix.\n // const uniformRowMajor = gl2.getActiveUniforms(program, uniformIndices, GL.UNIFORM_IS_ROW_MAJOR);\n for (let i = 0; i < blockInfo.uniformCount; ++i) {\n const activeInfo = gl2.getActiveUniform(program, uniformIndices[i]);\n if (!activeInfo) {\n throw new Error('activeInfo');\n }\n\n blockInfo.uniforms.push({\n name: activeInfo.name,\n format: decodeGLUniformType(uniformType[i]).format,\n type: uniformType[i],\n arrayLength: uniformArrayLength[i],\n byteOffset: uniformOffset[i],\n byteStride: uniformStride[i]\n // matrixStride: uniformStride[i],\n // rowMajor: uniformRowMajor[i]\n });\n }\n\n uniformBlocks.push(blockInfo);\n }\n\n uniformBlocks.sort((a, b) => a.location - b.location);\n return uniformBlocks;\n}\n\n/**\n * TOOD - compare with a above, confirm copy, then delete\n const bindings: Binding[] = [];\n const count = gl.getProgramParameter(program, gl.ACTIVE_UNIFORM_BLOCKS);\n for (let blockIndex = 0; blockIndex < count; blockIndex++) {\n const vertex = gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),\n const fragment = gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER),\n const visibility = (vertex) + (fragment);\n const binding: BufferBinding = {\n location: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_BINDING),\n // name: gl.getActiveUniformBlockName(program, blockIndex),\n type: 'uniform',\n visibility,\n minBindingSize: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_DATA_SIZE),\n // uniformCount: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_ACTIVE_UNIFORMS),\n // uniformIndices: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES),\n }\n bindings.push(binding);\n }\n*/\n\nconst SAMPLER_UNIFORMS_GL_TO_GPU: Record<\n number,\n [\n '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d',\n 'float' | 'unfilterable-float' | 'depth' | 'sint' | 'uint'\n ]\n> = {\n [GL.SAMPLER_2D]: ['2d', 'float'],\n [GL.SAMPLER_CUBE]: ['cube', 'float'],\n [GL.SAMPLER_3D]: ['3d', 'float'],\n [GL.SAMPLER_2D_SHADOW]: ['3d', 'depth'],\n [GL.SAMPLER_2D_ARRAY]: ['2d-array', 'float'],\n [GL.SAMPLER_2D_ARRAY_SHADOW]: ['2d-array', 'depth'],\n [GL.SAMPLER_CUBE_SHADOW]: ['cube', 'float'],\n [GL.INT_SAMPLER_2D]: ['2d', 'sint'],\n [GL.INT_SAMPLER_3D]: ['3d', 'sint'],\n [GL.INT_SAMPLER_CUBE]: ['cube', 'sint'],\n [GL.INT_SAMPLER_2D_ARRAY]: ['2d-array', 'uint'],\n [GL.UNSIGNED_INT_SAMPLER_2D]: ['2d', 'uint'],\n [GL.UNSIGNED_INT_SAMPLER_3D]: ['3d', 'uint'],\n [GL.UNSIGNED_INT_SAMPLER_CUBE]: ['cube', 'uint'],\n [GL.UNSIGNED_INT_SAMPLER_2D_ARRAY]: ['2d-array', 'uint']\n};\n\ntype SamplerInfo = {\n viewDimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';\n sampleType: 'float' | 'unfilterable-float' | 'depth' | 'sint' | 'uint';\n};\n\nfunction getSamplerInfo(type: GL): SamplerInfo {\n const sampler = SAMPLER_UNIFORMS_GL_TO_GPU[type];\n if (!sampler) {\n throw new Error('sampler');\n }\n const [viewDimension, sampleType] = sampler;\n return {viewDimension, sampleType};\n}\n\n// HELPERS\n\nfunction parseUniformName(name: string): {name: string; length: number; isArray: boolean} {\n // Shortcut to avoid redundant or bad matches\n if (name[name.length - 1] !== ']') {\n return {\n name,\n length: 1,\n isArray: false\n };\n }\n\n // if array name then clean the array brackets\n const UNIFORM_NAME_REGEXP = /([^[]*)(\\[[0-9]+\\])?/;\n const matches = UNIFORM_NAME_REGEXP.exec(name);\n if (!matches || matches.length < 2) {\n throw new Error(`Failed to parse GLSL uniform name ${name}`);\n }\n\n return {\n name: matches[1],\n length: matches[2] ? 1 : 0,\n isArray: Boolean(matches[2])\n };\n}\n"],"mappings":"AAUA,SAAQA,EAAE,QAAO,oBAAoB;AAAC,SAC9BC,QAAQ;AAAA,SACRC,QAAQ;AAAA,SACRC,mBAAmB,EAAEC,qBAAqB,EAAEC,gBAAgB;AAOpE,OAAO,SAASC,eAAeA,CAACC,EAAyB,EAAEC,OAAqB,EAAgB;EAC9F,MAAMC,YAA0B,GAAG;IACjCC,UAAU,EAAE,EAAE;IACdC,QAAQ,EAAE;EACZ,CAAC;EAEDF,YAAY,CAACC,UAAU,GAAGE,yBAAyB,CAACL,EAAE,EAAEC,OAAO,CAAC;EAGhE,MAAMK,aAAoC,GAAGC,iBAAiB,CAACP,EAAE,EAAEC,OAAO,C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AAC;EAChD,CAACnH,EAAE,CAACoH,6BAA6B,GAAG,CAAC,UAAU,EAAE,MAAM;AACzD,CAAC;AAOD,SAAShF,cAAcA,CAACX,IAAQ,EAAe;EAC7C,MAAM4F,OAAO,GAAGhB,0BAA0B,CAAC5E,IAAI,CAAC;EAChD,IAAI,CAAC4F,OAAO,EAAE;IACZ,MAAM,IAAIvE,KAAK,CAAC,SAAS,CAAC;EAC5B;EACA,MAAM,CAACZ,aAAa,EAAEC,UAAU,CAAC,GAAGkF,OAAO;EAC3C,OAAO;IAACnF,aAAa;IAAEC;EAAU,CAAC;AACpC;AAIA,SAASkC,gBAAgBA,CAAClD,IAAY,EAAoD;EAExF,IAAIA,IAAI,CAACA,IAAI,CAACkB,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE;IACjC,OAAO;MACLlB,IAAI;MACJkB,MAAM,EAAE,CAAC;MACT+B,OAAO,EAAE;IACX,CAAC;EACH;EAGA,MAAMkD,mBAAmB,GAAG,sBAAsB;EAClD,MAAMC,OAAO,GAAGD,mBAAmB,CAACE,IAAI,CAACrG,IAAI,CAAC;EAC9C,IAAI,CAACoG,OAAO,IAAIA,OAAO,CAAClF,MAAM,GAAG,CAAC,EAAE;IAClC,MAAM,IAAIS,KAAK,sCAAA6B,MAAA,CAAsCxD,IAAI,CAAE,CAAC;EAC9D;EAEA,OAAO;IACLA,IAAI,EAAEoG,OAAO,CAAC,CAAC,CAAC;IAChBlF,MAAM,EAAEkF,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAC1BnD,OAAO,EAAEqD,OAAO,CAACF,OAAO,CAAC,CAAC,CAAC;EAC7B,CAAC;AACH"}
@@ -8,4 +8,4 @@ export declare function getVertexCount(options: {
8
8
  drawMode: GLPrimitiveTopology;
9
9
  vertexCount: number;
10
10
  }): number;
11
- //# sourceMappingURL=attribute-utils.d.ts.map
11
+ //# sourceMappingURL=webgl-topology-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webgl-topology-utils.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/webgl-topology-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,mBAAmB,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAGxE,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,WAAW,CAmB/E;AAGD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IAAC,QAAQ,EAAE,mBAAmB,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAC,GAAG,MAAM,CAkBvG;AAGD,wBAAgB,cAAc,CAAC,OAAO,EAAE;IAAC,QAAQ,EAAE,mBAAmB,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAC,GAAG,MAAM,CAapG"}
@@ -61,4 +61,4 @@ export function getVertexCount(options) {
61
61
  throw new Error('drawMode');
62
62
  }
63
63
  }
64
- //# sourceMappingURL=attribute-utils.js.map
64
+ //# sourceMappingURL=webgl-topology-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webgl-topology-utils.js","names":["GL","getPrimitiveDrawMode","drawMode","POINTS","LINES","LINE_STRIP","LINE_LOOP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN","Error","getPrimitiveCount","options","vertexCount","getVertexCount","primitiveCount"],"sources":["../../../src/adapter/helpers/webgl-topology-utils.ts"],"sourcesContent":["import {GL, GLPrimitiveTopology, GLPrimitive} from '@luma.gl/constants';\n\n// Counts the number of complete primitives given a number of vertices and a drawMode\nexport function getPrimitiveDrawMode(drawMode: GLPrimitiveTopology): GLPrimitive {\n switch (drawMode) {\n case GL.POINTS:\n return GL.POINTS;\n case GL.LINES:\n return GL.LINES;\n case GL.LINE_STRIP:\n return GL.LINES;\n case GL.LINE_LOOP:\n return GL.LINES;\n case GL.TRIANGLES:\n return GL.TRIANGLES;\n case GL.TRIANGLE_STRIP:\n return GL.TRIANGLES;\n case GL.TRIANGLE_FAN:\n return GL.TRIANGLES;\n default:\n throw new Error('drawMode');\n }\n}\n\n// Counts the number of complete \"primitives\" given a number of vertices and a drawMode\nexport function getPrimitiveCount(options: {drawMode: GLPrimitiveTopology, vertexCount: number}): number {\n const {drawMode, vertexCount} = options;\n switch (drawMode) {\n case GL.POINTS:\n case GL.LINE_LOOP:\n return vertexCount;\n case GL.LINES:\n return vertexCount / 2;\n case GL.LINE_STRIP:\n return vertexCount - 1;\n case GL.TRIANGLES:\n return vertexCount / 3;\n case GL.TRIANGLE_STRIP:\n case GL.TRIANGLE_FAN:\n return vertexCount - 2;\n default:\n throw new Error('drawMode');\n }\n}\n\n// Counts the number of vertices after splitting the vertex stream into separate \"primitives\"\nexport function getVertexCount(options: {drawMode: GLPrimitiveTopology, vertexCount: number}): number {\n const {drawMode, vertexCount} = options;\n const primitiveCount = getPrimitiveCount({drawMode, vertexCount});\n switch (getPrimitiveDrawMode(drawMode)) {\n case GL.POINTS:\n return primitiveCount;\n case GL.LINES:\n return primitiveCount * 2;\n case GL.TRIANGLES:\n return primitiveCount * 3;\n default:\n throw new Error('drawMode');\n }\n}\n"],"mappings":"AAAA,SAAQA,EAAE,QAAyC,oBAAoB;AAGvE,OAAO,SAASC,oBAAoBA,CAACC,QAA6B,EAAe;EAC/E,QAAQA,QAAQ;IACd,KAAKF,EAAE,CAACG,MAAM;MACZ,OAAOH,EAAE,CAACG,MAAM;IAClB,KAAKH,EAAE,CAACI,KAAK;MACX,OAAOJ,EAAE,CAACI,KAAK;IACjB,KAAKJ,EAAE,CAACK,UAAU;MAChB,OAAOL,EAAE,CAACI,KAAK;IACjB,KAAKJ,EAAE,CAACM,SAAS;MACf,OAAON,EAAE,CAACI,KAAK;IACjB,KAAKJ,EAAE,CAACO,SAAS;MACf,OAAOP,EAAE,CAACO,SAAS;IACrB,KAAKP,EAAE,CAACQ,cAAc;MACpB,OAAOR,EAAE,CAACO,SAAS;IACrB,KAAKP,EAAE,CAACS,YAAY;MAClB,OAAOT,EAAE,CAACO,SAAS;IACrB;MACE,MAAM,IAAIG,KAAK,CAAC,UAAU,CAAC;EAC/B;AACF;AAGA,OAAO,SAASC,iBAAiBA,CAACC,OAA6D,EAAU;EACvG,MAAM;IAACV,QAAQ;IAAEW;EAAW,CAAC,GAAGD,OAAO;EACvC,QAAQV,QAAQ;IACd,KAAKF,EAAE,CAACG,MAAM;IACd,KAAKH,EAAE,CAACM,SAAS;MACf,OAAOO,WAAW;IACpB,KAAKb,EAAE,CAACI,KAAK;MACX,OAAOS,WAAW,GAAG,CAAC;IACxB,KAAKb,EAAE,CAACK,UAAU;MAChB,OAAOQ,WAAW,GAAG,CAAC;IACxB,KAAKb,EAAE,CAACO,SAAS;MACf,OAAOM,WAAW,GAAG,CAAC;IACxB,KAAKb,EAAE,CAACQ,cAAc;IACtB,KAAKR,EAAE,CAACS,YAAY;MAClB,OAAOI,WAAW,GAAG,CAAC;IACxB;MACE,MAAM,IAAIH,KAAK,CAAC,UAAU,CAAC;EAC/B;AACF;AAGA,OAAO,SAASI,cAAcA,CAACF,OAA6D,EAAU;EACpG,MAAM;IAACV,QAAQ;IAAEW;EAAW,CAAC,GAAGD,OAAO;EACvC,MAAMG,cAAc,GAAGJ,iBAAiB,CAAC;IAACT,QAAQ;IAAEW;EAAW,CAAC,CAAC;EACjE,QAAQZ,oBAAoB,CAACC,QAAQ,CAAC;IACpC,KAAKF,EAAE,CAACG,MAAM;MACZ,OAAOY,cAAc;IACvB,KAAKf,EAAE,CAACI,KAAK;MACX,OAAOW,cAAc,GAAG,CAAC;IAC3B,KAAKf,EAAE,CAACO,SAAS;MACf,OAAOQ,cAAc,GAAG,CAAC;IAC3B;MACE,MAAM,IAAIL,KAAK,CAAC,UAAU,CAAC;EAC/B;AACF"}
@@ -1,6 +1,7 @@
1
1
  import type { Device, Buffer, ResourceProps, TypedArray } from '@luma.gl/core';
2
2
  import { WebGLResource } from './webgl-resource';
3
3
  import { WEBGLBuffer } from '../resources/webgl-buffer';
4
+ import { AccessorObject } from '../..';
4
5
  /**
5
6
  * VertexArrayObject properties
6
7
  * @param constantAttributeZero Attribute 0 can not be disable on most desktop OpenGL based browsers
@@ -30,7 +31,7 @@ export declare class WEBGLVertexArrayObject extends WebGLResource<VertexArrayObj
30
31
  enable(location: number, enable?: boolean): void;
31
32
  setElementBuffer(elementBuffer?: WEBGLBuffer | null, opts?: {}): void;
32
33
  /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
33
- setBuffer(location: number, buffer: WEBGLBuffer, accessor: any): void;
34
+ setBuffer(location: number, buffer: WEBGLBuffer, accessor: AccessorObject): void;
34
35
  /**
35
36
  * Set an attribute to a constant value
36
37
  * @param device
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-vertex-array-object.d.ts","sourceRoot":"","sources":["../../../src/adapter/objects/webgl-vertex-array-object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAe,MAAM,eAAe,CAAC;AAM3F,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AAMtD;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,aAAa,GAAG;IACnD,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,gCAAgC;AAChC,qBAAa,sBAAuB,SAAQ,aAAa,CAAC,sBAAsB,CAAC;IAC/E,IAAa,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAE1C;IAED,sBAAsB;IACtB,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,WAAW,CAAQ;IAE3B,MAAM,CAAC,gCAAgC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;gBAKpD,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,sBAAsB;IAKjD,OAAO,IAAI,IAAI;IAMf,aAAa;IAIb,aAAa,IAAI,IAAI;IAOrB,WAAW,CAAC,MAAM,EA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,MAAM,EAAE,KAAK,CAAC,EAAE,sBAAsB;IAKjD,OAAO,IAAI,IAAI;IAMf,aAAa;IAIb,aAAa,IAAI,IAAI;IAOrB,WAAW,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI;IAI1D;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,UAAO,GAAG,IAAI;IAgB7C,gBAAgB,CAAC,aAAa,GAAE,WAAW,GAAG,IAAW,EAAE,IAAI,KAAK;IASpE,gGAAgG;IAChG,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI;IA+BhF;;;;;;;;;;OAUG;IACH,WAAW,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI;IAgBnD;;;;;OAKG;IACH,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,KAAA,GAAG,MAAM;CA2BvD"}
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-vertex-array-object.js","names":["Resource","assert","getScratchArray","fillArray","GL","getBrowser","WebGLResource","ERR_ELEMENTS","_Symbol$toStringTag","Symbol","toStringTag","WEBGLVertexArrayObject","isConstantAttributeZeroSupported","device","info","type","constructor","props","defaultProps","constantAttributeZero","_defineProperty","Object","seal","destroy","buffer","_this$buffer","_createHandle","gl2","createVertexArray","_deleteHandle","deleteVertexArray","handle","elements","_bindHandle","bindVertexArray","enable","location","arguments","length","undefined","canDisableAttributeZero","isWebGL2","canDisableAttribute","Number","bind","gl","enableVertexAttribArray","disableVertexAttribArray","setElementBuffer","elementBuffer","opts","glTarget","ELEMENT_ARRAY_BUFFER","bindBuffer","setBuffer","accessor","size","stride","offset","normalized","integer","divisor","ARRAY_BUFFER","assertWebGL2","vertexAttribIPointer","vertexAttribPointer","vertexAttribDivisor","setConstant","array","Float32Array","setConstantFloatArray","Int32Array","setConstantIntArray","Uint32Array","setConstantUintArray","getConstantBuffer","elementCount","value","constantValue","normalizeConstantArrayValue","byteLength","updateNeeded","createBuffer","reallocate","compareConstantArrayValues","bufferValue","typedArray","target","source","start","count","subData","vertexAttrib1fv","vertexAttrib2fv","vertexAttrib3fv","vertexAttrib4fv","_device$gl","vertexAttribI4iv","_device$gl2","vertexAttribI4uiv","arrayValue","Array","isArray","v1","v2","i"],"sources":["../../../src/adapter/objects/webgl-vertex-array-object.ts"],"sourcesContent":["import type {Device, Buffer, ResourceProps, TypedArray, NumericArray} from '@luma.gl/core';\nimport {Resource, assert, getScratchArray, fillArray} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\nimport {getBrowser} from '@probe.gl/env';\n\nimport {WebGLDevice} from '../webgl-device';\nimport {WebGLResource} from './webgl-resource';\nimport {WEBGLBuffer} from '../resources/webgl-buffer';\n\nimport {BufferWithAccessor} from '../../classic/buffer-with-accessor';\n\nconst ERR_ELEMENTS = 'elements must be GL.ELEMENT_ARRAY_BUFFER';\n\n/**\n * VertexArrayObject properties\n * @param constantAttributeZero Attribute 0 can not be disable on most desktop OpenGL based browsers\n * and on iOS Safari browser.\n */\nexport type VertexArrayObjectProps = ResourceProps & {\n constantAttributeZero?: boolean;\n};\n\n/** VertexArrayObject wrapper */\nexport class WEBGLVertexArrayObject extends WebGLResource<VertexArrayObjectProps> {\n override get [Symbol.toStringTag](): string {\n return 'BaseVertexArrayObject';\n }\n\n /** Buffer constant */\n private buffer: BufferWithAccessor | null = null;\n private bufferValue = null;\n\n static isConstantAttributeZeroSupported(device: Device): boolean {\n return device.info.type === 'webgl2' || getBrowser() === 'Chrome';\n }\n\n // Create a VertexArray\n constructor(device: Device, props?: VertexArrayObjectProps) {\n super(device, props, {...Resource.defaultProps, constantAttributeZero: false});\n Object.seal(this);\n }\n\n override destroy(): void {\n super.destroy();\n if (this.buffer) {\n this.buffer?.destroy();\n } }\n\n override _createHandle() {\n return this.gl2.createVertexArray();\n }\n\n override _deleteHandle(): void {\n this.gl2.deleteVertexArray(this.handle);\n // @ts-expect-error\n return [this.elements];\n // return [this.elements, ...this.buffers];\n }\n\n override _bindHandle(handle: WEBGLVertexArrayObject): void {\n this.gl2.bindVertexArray(handle);\n }\n\n /**\n * Enabling an attribute location makes it reference the currently bound buffer\n * Disabling an attribute location makes it reference the global constant value\n * TODO - handle single values for size 1 attributes?\n * TODO - convert classic arrays based on known type?\n */\n enable(location: number, enable = true): void {\n // Attribute 0 cannot be disabled in most desktop OpenGL based browsers...\n const canDisableAttributeZero = this.device.isWebGL2 || getBrowser() === 'Chrome';\n const canDisableAttribute = canDisableAttributeZero || location !== 0;\n\n if (enable || canDisableAttribute) {\n location = Number(location);\n this.bind(() =>\n enable\n ? this.gl.enableVertexAttribArray(location)\n : this.gl.disableVertexAttribArray(location)\n );\n } }\n\n // Set (bind) an elements buffer, for indexed rendering.\n // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER. Constants not supported\n setElementBuffer(elementBuffer: WEBGLBuffer | null = null, opts = {}) {\n assert(!elementBuffer || elementBuffer.glTarget === GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS);\n\n // The GL.ELEMENT_ARRAY_BUFFER_BINDING is stored on the VertexArrayObject...\n this.bind(() => {\n this.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, elementBuffer ? elementBuffer.handle : null);\n });\n }\n\n /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */\n setBuffer(location: number, buffer: WEBGLBuffer, accessor: any): void {\n // Check target\n if (buffer.glTarget === GL.ELEMENT_ARRAY_BUFFER) {\n this.setElementBuffer(buffer, accessor);\n return;\n }\n\n const {size, type, stride, offset, normalized, integer, divisor} = accessor;\n\n const {gl, gl2} = this;\n location = Number(location);\n\n this.bind(() => {\n // A non-zero buffer object must be bound to the GL_ARRAY_BUFFER target\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer.handle);\n\n // WebGL2 supports *integer* data formats, i.e. GPU will see integer values\n if (integer) {\n this.device.assertWebGL2();\n gl2.vertexAttribIPointer(location, size, type, stride, offset);\n } else {\n // Attaches ARRAY_BUFFER with specified buffer format to location\n gl.vertexAttribPointer(location, size, type, normalized, stride, offset);\n }\n gl.enableVertexAttribArray(location);\n gl2.vertexAttribDivisor(location, divisor || 0);\n\n // NOTE We don't unbind buffer here, typically another buffer will be bound just after\n });\n }\n\n /**\n * Set an attribute to a constant value\n * @param device\n * @param location\n * @param array\n * \n * @note Constants are stored globally on the WebGL context, not the VAO\n * so they need to be updated before every render\n * @todo - use known type (in configuration or passed in) to allow non-typed arrays?\n * @todo - remember/cache values to avoid setting them unnecessarily?\n */\n setConstant(location: any, array: TypedArray): void {\n switch (array.constructor) {\n case Float32Array:\n setConstantFloatArray(this.device, location, array as Float32Array);\n break;\n case Int32Array:\n setConstantIntArray(this.device, location, array as Int32Array);\n break;\n case Uint32Array:\n setConstantUintArray(this.device, location, array as Uint32Array);\n break;\n default:\n assert(false);\n }\n }\n\n /**\n * Provide a means to create a buffer that is equivalent to a constant.\n * NOTE: Desktop OpenGL cannot disable attribute 0.\n * https://stackoverflow.com/questions/20305231/webgl-warning-attribute-0-is-disabled-\n * this-has-significant-performance-penalty\n */\n getConstantBuffer(elementCount: number, value): Buffer {\n // Create buffer only when needed, and reuse it (avoids inflating buffer creation statistics)\n\n const constantValue = normalizeConstantArrayValue(value);\n\n const byteLength = constantValue.byteLength * elementCount;\n const length = constantValue.length * elementCount;\n\n let updateNeeded = !this.buffer;\n\n this.buffer = this.buffer || this.device.createBuffer({byteLength}) as BufferWithAccessor;\n updateNeeded = updateNeeded || this.buffer.reallocate(byteLength);\n\n // Reallocate and update contents if needed\n updateNeeded =\n updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);\n\n if (updateNeeded) {\n // Create a typed array that is big enough, and fill it with the required data\n const typedArray = getScratchArray(value.constructor, length);\n fillArray({target: typedArray, source: constantValue, start: 0, count: length});\n this.buffer.subData(typedArray);\n this.bufferValue = value;\n }\n\n return this.buffer;\n }\n}\n\nfunction setConstantFloatArray(device: WebGLDevice, location: number, array: Float32Array): void {\n switch (array.length) {\n case 1:\n device.gl.vertexAttrib1fv(location, array);\n break;\n case 2:\n device.gl.vertexAttrib2fv(location, array);\n break;\n case 3:\n device.gl.vertexAttrib3fv(location, array);\n break;\n case 4:\n device.gl.vertexAttrib4fv(location, array);\n break;\n default:\n assert(false);\n }\n}\n\nfunction setConstantIntArray(device: WebGLDevice, location: number, array: Int32Array): void {\n device.assertWebGL2();\n device.gl2?.vertexAttribI4iv(location, array);\n // switch (array.length) {\n // case 1:\n // gl.vertexAttribI1iv(location, array);\n // break;\n // case 2:\n // gl.vertexAttribI2iv(location, array);\n // break;\n // case 3:\n // gl.vertexAttribI3iv(location, array);\n // break;\n // case 4:\n // break;\n // default:\n // assert(false);\n // }\n}\n\nfunction setConstantUintArray(device: WebGLDevice, location: number, array: Uint32Array) {\n device.assertWebGL2();\n device.gl2?.vertexAttribI4uiv(location, array);\n // switch (array.length) {\n // case 1:\n // gl.vertexAttribI1uiv(location, array);\n // break;\n // case 2:\n // gl.vertexAttribI2uiv(location, array);\n // break;\n // case 3:\n // gl.vertexAttribI3uiv(location, array);\n // break;\n // case 4:\n // gl.vertexAttribI4uiv(location, array);\n // break;\n // default:\n // assert(false);\n // }\n}\n\n// HELPERS\n\n/**\n * TODO - convert Arrays based on known type? (read type from accessor, don't assume Float32Array)\n * TODO - handle single values for size 1 attributes?\n */\nfunction normalizeConstantArrayValue(arrayValue: NumericArray) {\n if (Array.isArray(arrayValue)) {\n return new Float32Array(arrayValue);\n }\n return arrayValue;\n}\n\n/**\n * \n */\nfunction compareConstantArrayValues(v1: NumericArray, v2: NumericArray): boolean {\n if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {\n return false;\n }\n for (let i = 0; i < v1.length; ++i) {\n if (v1[i] !== v2[i]) {\n return false;\n }\n }\n return true;\n}\n"],"mappings":";;AACA,SAAQA,QAAQ,EAAEC,MAAM,EAAEC,eAAe,EAAEC,SAAS,QAAO,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EAAE,CAACjE,MAAM,KAAKkE,EAAE,CAAClE,MAAM,IAAIiE,EAAE,CAACvF,WAAW,KAAKwF,EAAE,CAACxF,WAAW,EAAE;IAC9E,OAAO,KAAK;EACd;EACA,KAAK,IAAIyF,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,EAAE,CAACjE,MAAM,EAAE,EAAEmE,CAAC,EAAE;IAClC,IAAIF,EAAE,CAACE,CAAC,CAAC,KAAKD,EAAE,CAACC,CAAC,CAAC,EAAE;MACnB,OAAO,KAAK;IACd;EACF;EACA,OAAO,IAAI;AACb"}
1
+ {"version":3,"file":"webgl-vertex-array-object.js","names":["Resource","assert","getScratchArray","fillArray","GL","getBrowser","WebGLResource","ERR_ELEMENTS","_Symbol$toStringTag","Symbol","toStringTag","WEBGLVertexArrayObject","isConstantAttributeZeroSupported","device","info","type","constructor","props","defaultProps","constantAttributeZero","_defineProperty","Object","seal","destroy","buffer","_this$buffer","_createHandle","gl2","createVertexArray","_deleteHandle","deleteVertexArray","handle","elements","_bindHandle","bindVertexArray","enable","location","arguments","length","undefined","canDisableAttributeZero","isWebGL2","canDisableAttribute","Number","bind","gl","enableVertexAttribArray","disableVertexAttribArray","setElementBuffer","elementBuffer","opts","glTarget","ELEMENT_ARRAY_BUFFER","bindBuffer","setBuffer","accessor","size","stride","offset","normalized","integer","divisor","ARRAY_BUFFER","assertWebGL2","vertexAttribIPointer","vertexAttribPointer","vertexAttribDivisor","setConstant","array","Float32Array","setConstantFloatArray","Int32Array","setConstantIntArray","Uint32Array","setConstantUintArray","getConstantBuffer","elementCount","value","constantValue","normalizeConstantArrayValue","byteLength","updateNeeded","createBuffer","reallocate","compareConstantArrayValues","bufferValue","typedArray","target","source","start","count","subData","vertexAttrib1fv","vertexAttrib2fv","vertexAttrib3fv","vertexAttrib4fv","_device$gl","vertexAttribI4iv","_device$gl2","vertexAttribI4uiv","arrayValue","Array","isArray","v1","v2","i"],"sources":["../../../src/adapter/objects/webgl-vertex-array-object.ts"],"sourcesContent":["import type {Device, Buffer, ResourceProps, TypedArray, NumericArray} from '@luma.gl/core';\nimport {Resource, assert, getScratchArray, fillArray} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\nimport {getBrowser} from '@probe.gl/env';\n\nimport {WebGLDevice} from '../webgl-device';\nimport {WebGLResource} from './webgl-resource';\nimport {WEBGLBuffer} from '../resources/webgl-buffer';\n\nimport {BufferWithAccessor} from '../../classic/buffer-with-accessor';\nimport {AccessorObject} from '../..';\n\nconst ERR_ELEMENTS = 'elements must be GL.ELEMENT_ARRAY_BUFFER';\n\n/**\n * VertexArrayObject properties\n * @param constantAttributeZero Attribute 0 can not be disable on most desktop OpenGL based browsers\n * and on iOS Safari browser.\n */\nexport type VertexArrayObjectProps = ResourceProps & {\n constantAttributeZero?: boolean;\n};\n\n/** VertexArrayObject wrapper */\nexport class WEBGLVertexArrayObject extends WebGLResource<VertexArrayObjectProps> {\n override get [Symbol.toStringTag](): string {\n return 'BaseVertexArrayObject';\n }\n\n /** Buffer constant */\n private buffer: BufferWithAccessor | null = null;\n private bufferValue = null;\n\n static isConstantAttributeZeroSupported(device: Device): boolean {\n return device.info.type === 'webgl2' || getBrowser() === 'Chrome';\n }\n\n // Create a VertexArray\n constructor(device: Device, props?: VertexArrayObjectProps) {\n super(device, props, {...Resource.defaultProps, constantAttributeZero: false});\n Object.seal(this);\n }\n\n override destroy(): void {\n super.destroy();\n if (this.buffer) {\n this.buffer?.destroy();\n } }\n\n override _createHandle() {\n return this.gl2.createVertexArray();\n }\n\n override _deleteHandle(): void {\n this.gl2.deleteVertexArray(this.handle);\n // @ts-expect-error\n return [this.elements];\n // return [this.elements, ...this.buffers];\n }\n\n override _bindHandle(handle: WEBGLVertexArrayObject): void {\n this.gl2.bindVertexArray(handle);\n }\n\n /**\n * Enabling an attribute location makes it reference the currently bound buffer\n * Disabling an attribute location makes it reference the global constant value\n * TODO - handle single values for size 1 attributes?\n * TODO - convert classic arrays based on known type?\n */\n enable(location: number, enable = true): void {\n // Attribute 0 cannot be disabled in most desktop OpenGL based browsers...\n const canDisableAttributeZero = this.device.isWebGL2 || getBrowser() === 'Chrome';\n const canDisableAttribute = canDisableAttributeZero || location !== 0;\n\n if (enable || canDisableAttribute) {\n location = Number(location);\n this.bind(() =>\n enable\n ? this.gl.enableVertexAttribArray(location)\n : this.gl.disableVertexAttribArray(location)\n );\n } }\n\n // Set (bind) an elements buffer, for indexed rendering.\n // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER. Constants not supported\n setElementBuffer(elementBuffer: WEBGLBuffer | null = null, opts = {}) {\n assert(!elementBuffer || elementBuffer.glTarget === GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS);\n\n // The GL.ELEMENT_ARRAY_BUFFER_BINDING is stored on the VertexArrayObject...\n this.bind(() => {\n this.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, elementBuffer ? elementBuffer.handle : null);\n });\n }\n\n /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */\n setBuffer(location: number, buffer: WEBGLBuffer, accessor: AccessorObject): void {\n // Check target\n if (buffer.glTarget === GL.ELEMENT_ARRAY_BUFFER) {\n this.setElementBuffer(buffer, accessor);\n return;\n }\n\n const {size, type, stride, offset, normalized, integer, divisor} = accessor;\n\n const {gl, gl2} = this;\n location = Number(location);\n\n this.bind(() => {\n // A non-zero buffer object must be bound to the GL_ARRAY_BUFFER target\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer.handle);\n\n // WebGL2 supports *integer* data formats, i.e. GPU will see integer values\n if (integer) {\n this.device.assertWebGL2();\n gl2.vertexAttribIPointer(location, size, type, stride, offset);\n } else {\n // Attaches ARRAY_BUFFER with specified buffer format to location\n gl.vertexAttribPointer(location, size, type, normalized, stride, offset);\n }\n gl.enableVertexAttribArray(location);\n gl2.vertexAttribDivisor(location, divisor || 0);\n\n // NOTE We don't unbind buffer here, typically another buffer will be bound just after\n });\n }\n\n /**\n * Set an attribute to a constant value\n * @param device\n * @param location\n * @param array\n * \n * @note Constants are stored globally on the WebGL context, not the VAO\n * so they need to be updated before every render\n * @todo - use known type (in configuration or passed in) to allow non-typed arrays?\n * @todo - remember/cache values to avoid setting them unnecessarily?\n */\n setConstant(location: any, array: TypedArray): void {\n switch (array.constructor) {\n case Float32Array:\n setConstantFloatArray(this.device, location, array as Float32Array);\n break;\n case Int32Array:\n setConstantIntArray(this.device, location, array as Int32Array);\n break;\n case Uint32Array:\n setConstantUintArray(this.device, location, array as Uint32Array);\n break;\n default:\n assert(false);\n }\n }\n\n /**\n * Provide a means to create a buffer that is equivalent to a constant.\n * NOTE: Desktop OpenGL cannot disable attribute 0.\n * https://stackoverflow.com/questions/20305231/webgl-warning-attribute-0-is-disabled-\n * this-has-significant-performance-penalty\n */\n getConstantBuffer(elementCount: number, value): Buffer {\n // Create buffer only when needed, and reuse it (avoids inflating buffer creation statistics)\n\n const constantValue = normalizeConstantArrayValue(value);\n\n const byteLength = constantValue.byteLength * elementCount;\n const length = constantValue.length * elementCount;\n\n let updateNeeded = !this.buffer;\n\n this.buffer = this.buffer || this.device.createBuffer({byteLength}) as BufferWithAccessor;\n updateNeeded = updateNeeded || this.buffer.reallocate(byteLength);\n\n // Reallocate and update contents if needed\n updateNeeded =\n updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);\n\n if (updateNeeded) {\n // Create a typed array that is big enough, and fill it with the required data\n const typedArray = getScratchArray(value.constructor, length);\n fillArray({target: typedArray, source: constantValue, start: 0, count: length});\n this.buffer.subData(typedArray);\n this.bufferValue = value;\n }\n\n return this.buffer;\n }\n}\n\nfunction setConstantFloatArray(device: WebGLDevice, location: number, array: Float32Array): void {\n switch (array.length) {\n case 1:\n device.gl.vertexAttrib1fv(location, array);\n break;\n case 2:\n device.gl.vertexAttrib2fv(location, array);\n break;\n case 3:\n device.gl.vertexAttrib3fv(location, array);\n break;\n case 4:\n device.gl.vertexAttrib4fv(location, array);\n break;\n default:\n assert(false);\n }\n}\n\nfunction setConstantIntArray(device: WebGLDevice, location: number, array: Int32Array): void {\n device.assertWebGL2();\n device.gl2?.vertexAttribI4iv(location, array);\n // switch (array.length) {\n // case 1:\n // gl.vertexAttribI1iv(location, array);\n // break;\n // case 2:\n // gl.vertexAttribI2iv(location, array);\n // break;\n // case 3:\n // gl.vertexAttribI3iv(location, array);\n // break;\n // case 4:\n // break;\n // default:\n // assert(false);\n // }\n}\n\nfunction setConstantUintArray(device: WebGLDevice, location: number, array: Uint32Array) {\n device.assertWebGL2();\n device.gl2?.vertexAttribI4uiv(location, array);\n // switch (array.length) {\n // case 1:\n // gl.vertexAttribI1uiv(location, array);\n // break;\n // case 2:\n // gl.vertexAttribI2uiv(location, array);\n // break;\n // case 3:\n // gl.vertexAttribI3uiv(location, array);\n // break;\n // case 4:\n // gl.vertexAttribI4uiv(location, array);\n // break;\n // default:\n // assert(false);\n // }\n}\n\n// HELPERS\n\n/**\n * TODO - convert Arrays based on known type? (read type from accessor, don't assume Float32Array)\n * TODO - handle single values for size 1 attributes?\n */\nfunction normalizeConstantArrayValue(arrayValue: NumericArray) {\n if (Array.isArray(arrayValue)) {\n return new Float32Array(arrayValue);\n }\n return arrayValue;\n}\n\n/**\n * \n */\nfunction compareConstantArrayValues(v1: NumericArray, v2: NumericArray): boolean {\n if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {\n return false;\n }\n for (let i = 0; i < v1.length; ++i) {\n if (v1[i] !== v2[i]) {\n return false;\n }\n }\n return true;\n}\n"],"mappings":";;AACA,SAAQA,QAAQ,EAAEC,MAAM,EAAEC,eAAe,EAAEC,SAAS,QAAO,eAAe;AAC1E,SAAQC,EAAE,QAAO,oBAAoB;AACrC,SAAQC,UAAU,QAAO,eAAe;AAAC,SAGjCC,aAAa;AAMrB,MAAMC,YAAY,GAAG,0CAA0C;AAACC,mBAAA,GAahDC,MAAM,CAACC,WAAW;AADlC,OAAO,MAAMC,sBAAsB,SAASL,aAAa,CAAyB;EAChF,KAAAE,mBAAA,IAA4C;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