@luma.gl/webgl 9.0.0-alpha.30 → 9.0.0-alpha.32
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.
- package/dist/adapter/converters/shader-formats.d.ts +9 -0
- package/dist/adapter/converters/shader-formats.d.ts.map +1 -0
- package/dist/adapter/converters/shader-formats.js +53 -0
- package/dist/adapter/converters/shader-formats.js.map +1 -0
- package/dist/adapter/converters/texture-formats.d.ts +1 -2
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +2 -23
- package/dist/adapter/converters/texture-formats.js.map +1 -1
- package/dist/adapter/converters/vertex-formats.d.ts +8 -2
- package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
- package/dist/adapter/converters/vertex-formats.js +47 -9
- package/dist/adapter/converters/vertex-formats.js.map +1 -1
- package/dist/adapter/helpers/{uniforms.d.ts → decode-webgl-types.d.ts} +9 -8
- package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -0
- package/dist/adapter/helpers/{uniforms.js → decode-webgl-types.js} +14 -13
- package/dist/adapter/helpers/decode-webgl-types.js.map +1 -0
- package/dist/adapter/helpers/get-shader-layout.d.ts +1 -51
- package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-shader-layout.js +14 -86
- package/dist/adapter/helpers/get-shader-layout.js.map +1 -1
- package/dist/adapter/helpers/set-uniform.d.ts +3 -2
- package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
- package/dist/adapter/helpers/set-uniform.js +25 -25
- package/dist/adapter/helpers/set-uniform.js.map +1 -1
- package/dist/adapter/helpers/{attribute-utils.d.ts → webgl-topology-utils.d.ts} +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -0
- package/dist/adapter/helpers/{attribute-utils.js → webgl-topology-utils.js} +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.js.map +1 -0
- package/dist/adapter/objects/webgl-vertex-array-object.d.ts +2 -1
- package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-vertex-array-object.js.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +16 -10
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +58 -59
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/classic/buffer-with-accessor.d.ts +0 -1
- package/dist/classic/buffer-with-accessor.d.ts.map +1 -1
- package/dist/classic/buffer-with-accessor.js +0 -1
- package/dist/classic/buffer-with-accessor.js.map +1 -1
- package/dist/dist.dev.js +513 -418
- package/dist/index.cjs +670 -722
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist.min.js +22 -22
- package/package.json +5 -5
- package/src/adapter/converters/shader-formats.ts +41 -0
- package/src/adapter/converters/texture-formats.ts +3 -16
- package/src/adapter/converters/vertex-formats.ts +67 -10
- package/src/adapter/helpers/{uniforms.ts → decode-webgl-types.ts} +22 -17
- package/src/adapter/helpers/get-shader-layout.ts +51 -159
- package/src/adapter/helpers/set-uniform.ts +33 -33
- package/src/adapter/objects/webgl-vertex-array-object.ts +2 -1
- package/src/adapter/resources/webgl-command-encoder.ts +1 -1
- package/src/adapter/resources/webgl-render-pipeline.ts +125 -82
- package/src/classic/buffer-with-accessor.ts +0 -1
- package/src/index.ts +1 -1
- package/src/types.ts +2 -0
- package/dist/adapter/helpers/attribute-utils.d.ts.map +0 -1
- package/dist/adapter/helpers/attribute-utils.js.map +0 -1
- package/dist/adapter/helpers/uniforms.d.ts.map +0 -1
- package/dist/adapter/helpers/uniforms.js.map +0 -1
- /package/src/adapter/helpers/{attribute-utils.ts → webgl-topology-utils.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/webgl",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.32",
|
|
4
4
|
"description": "WebGL2 adapter for the luma.gl API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/runtime": "^7.0.0",
|
|
47
|
-
"@luma.gl/constants": "9.0.0-alpha.
|
|
48
|
-
"@luma.gl/core": "9.0.0-alpha.
|
|
47
|
+
"@luma.gl/constants": "9.0.0-alpha.32",
|
|
48
|
+
"@luma.gl/core": "9.0.0-alpha.32",
|
|
49
49
|
"@probe.gl/env": "^4.0.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@luma.gl/test-utils": "9.0.0-alpha.
|
|
52
|
+
"@luma.gl/test-utils": "9.0.0-alpha.32"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "08b30dcae4aee321738cf05b509cef6b3b24c880"
|
|
55
55
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {GL} from '@luma.gl/constants';
|
|
2
|
+
import {ShaderAttributeType, ShaderDataType} from '@luma.gl/core';
|
|
3
|
+
|
|
4
|
+
/** Get shader attribute type from GL constants */
|
|
5
|
+
export function getShaderAttributeTypeFromGL(type: GL, components: 1 | 2 | 3 | 4): ShaderAttributeType {
|
|
6
|
+
const dataType = getShaderDataTypeFromGL(type);
|
|
7
|
+
switch (components) {
|
|
8
|
+
case 1: return dataType;
|
|
9
|
+
case 2: return `vec2<${dataType}>`;
|
|
10
|
+
case 3: return `vec2<${dataType}>`;
|
|
11
|
+
case 4: return `vec2<${dataType}>`;
|
|
12
|
+
default: throw new Error(String(components));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Get shader data type from GL constants */
|
|
17
|
+
export function getShaderDataTypeFromGL(type: GL): ShaderDataType {
|
|
18
|
+
switch (type) {
|
|
19
|
+
case GL.INT: return 'i32';
|
|
20
|
+
case GL.UNSIGNED_INT: return 'u32';
|
|
21
|
+
case GL.SHORT: return 'i32';
|
|
22
|
+
case GL.UNSIGNED_SHORT: return 'u32';
|
|
23
|
+
case GL.BYTE: return 'i32';
|
|
24
|
+
case GL.UNSIGNED_BYTE: return 'u32';
|
|
25
|
+
case GL.FLOAT: return 'f32';
|
|
26
|
+
case GL.HALF_FLOAT: return 'f16';
|
|
27
|
+
default: throw new Error(String(type));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** GetGL constant from shader data type */
|
|
32
|
+
export function getGLFromShaderDataType(type: ShaderDataType): GL.INT | GL.UNSIGNED_INT | GL.FLOAT | GL.HALF_FLOAT {
|
|
33
|
+
switch (type) {
|
|
34
|
+
// TODO
|
|
35
|
+
case 'i32': return GL.INT;
|
|
36
|
+
case 'u32': return GL.UNSIGNED_INT;
|
|
37
|
+
case 'f32': return GL.FLOAT;
|
|
38
|
+
case 'f16': return GL.HALF_FLOAT;
|
|
39
|
+
default: throw new Error(String(type));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -2,6 +2,7 @@ import type {TextureFormat, DeviceFeature} from '@luma.gl/core';
|
|
|
2
2
|
import {decodeTextureFormat} from '@luma.gl/core';
|
|
3
3
|
import {GL} from '@luma.gl/constants';
|
|
4
4
|
import {isWebGL2} from '../../context/context/webgl-checks';
|
|
5
|
+
import { getGLFromVertexType } from './vertex-formats';
|
|
5
6
|
|
|
6
7
|
/* eslint-disable camelcase */
|
|
7
8
|
|
|
@@ -603,7 +604,8 @@ export function getWebGLTextureParameters(formatOrGL: TextureFormat | GL, isWebG
|
|
|
603
604
|
decoded.normalized,
|
|
604
605
|
webglFormat
|
|
605
606
|
),
|
|
606
|
-
type
|
|
607
|
+
// depth formats don't have a type
|
|
608
|
+
type: decoded.dataType ? getGLFromVertexType(decoded.dataType) : GL.UNSIGNED_BYTE,
|
|
607
609
|
// @ts-expect-error
|
|
608
610
|
compressed: decoded.compressed
|
|
609
611
|
};
|
|
@@ -699,18 +701,3 @@ function getWebGLPixelDataFormat(
|
|
|
699
701
|
default: return GL.RGBA;
|
|
700
702
|
}
|
|
701
703
|
}
|
|
702
|
-
|
|
703
|
-
export function getWebGLDataType(dataType: string): GL {
|
|
704
|
-
// prettier-ignore
|
|
705
|
-
switch (dataType) {
|
|
706
|
-
case 'uint8': return GL.UNSIGNED_BYTE;
|
|
707
|
-
case 'sint8': return GL.BYTE;
|
|
708
|
-
case 'uint16': return GL.UNSIGNED_SHORT;
|
|
709
|
-
case 'sint16': return GL.SHORT;
|
|
710
|
-
case 'uint32': return GL.UNSIGNED_INT;
|
|
711
|
-
case 'sint32': return GL.INT;
|
|
712
|
-
case 'float16': return GL.HALF_FLOAT;
|
|
713
|
-
case 'float32': return GL.FLOAT;
|
|
714
|
-
default: return GL.UNSIGNED_BYTE;
|
|
715
|
-
}
|
|
716
|
-
}
|
|
@@ -1,23 +1,80 @@
|
|
|
1
1
|
import {GL} from '@luma.gl/constants';
|
|
2
|
-
import {VertexFormat} from '@luma.gl/core';
|
|
2
|
+
import {VertexFormat, VertexType} from '@luma.gl/core';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type GLDataType =
|
|
5
|
+
| GL.UNSIGNED_BYTE
|
|
6
|
+
| GL.BYTE
|
|
7
|
+
| GL.UNSIGNED_SHORT
|
|
8
|
+
| GL.SHORT
|
|
9
|
+
| GL.UNSIGNED_INT
|
|
10
|
+
| GL.INT
|
|
11
|
+
| GL.HALF_FLOAT
|
|
12
|
+
| GL.FLOAT;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/** Get vertex format from GL constants */
|
|
16
|
+
export function getVertexFormatFromGL(type: GLDataType, components: 1 | 2 | 3 | 4): VertexFormat {
|
|
17
|
+
const base = getVertexTypeFromGL(type);
|
|
18
|
+
// prettier-ignore
|
|
6
19
|
switch (components) {
|
|
20
|
+
// @ts-expect-error TODO deal with lack of formats
|
|
7
21
|
case 1: return base;
|
|
8
22
|
case 2: return `${base}x2`;
|
|
23
|
+
// @ts-expect-error TODO deal with lack of formats
|
|
9
24
|
case 3: return `${base}x3`;
|
|
10
25
|
case 4: return `${base}x4`;
|
|
11
|
-
default: throw new Error(String(components));
|
|
12
26
|
}
|
|
27
|
+
// @ts-ignore unreachable
|
|
28
|
+
throw new Error(String(components));
|
|
13
29
|
}
|
|
14
30
|
|
|
15
|
-
|
|
31
|
+
/** Get data type from GL constants */
|
|
32
|
+
export function getVertexTypeFromGL(type: GLDataType, normalized = false): VertexType {
|
|
33
|
+
// prettier-ignore
|
|
16
34
|
switch (type) {
|
|
17
|
-
//
|
|
18
|
-
case GL.INT: return 'sint32';
|
|
19
|
-
case GL.UNSIGNED_INT: return 'uint32';
|
|
35
|
+
// WebGPU does not support normalized 32 bit integer attributes
|
|
36
|
+
case GL.INT: return normalized ? 'sint32' : 'sint32';
|
|
37
|
+
case GL.UNSIGNED_INT: return normalized ? 'uint32' : 'uint32';
|
|
38
|
+
case GL.SHORT: return normalized ? 'sint16' : 'unorm16';
|
|
39
|
+
case GL.UNSIGNED_SHORT: return normalized ? 'uint16' : 'unorm16';
|
|
40
|
+
case GL.BYTE: return normalized ? 'sint8' : 'snorm16';
|
|
41
|
+
case GL.UNSIGNED_BYTE: return normalized ? 'uint8' : 'unorm8';
|
|
20
42
|
case GL.FLOAT: return 'float32';
|
|
21
|
-
|
|
43
|
+
case GL.HALF_FLOAT: return 'float16';
|
|
44
|
+
}
|
|
45
|
+
// @ts-ignore unreachable
|
|
46
|
+
throw new Error(String(type));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function getGLFromVertexType(
|
|
50
|
+
dataType: VertexType
|
|
51
|
+
):
|
|
52
|
+
| GL.UNSIGNED_BYTE
|
|
53
|
+
| GL.BYTE
|
|
54
|
+
| GL.UNSIGNED_SHORT
|
|
55
|
+
| GL.SHORT
|
|
56
|
+
| GL.UNSIGNED_INT
|
|
57
|
+
| GL.INT
|
|
58
|
+
| GL.HALF_FLOAT
|
|
59
|
+
| GL.FLOAT {
|
|
60
|
+
// prettier-ignore
|
|
61
|
+
switch (dataType) {
|
|
62
|
+
case 'uint8': return GL.UNSIGNED_BYTE;
|
|
63
|
+
case 'sint8': return GL.BYTE;
|
|
64
|
+
case 'unorm8': return GL.UNSIGNED_BYTE;
|
|
65
|
+
case 'snorm8': return GL.BYTE;
|
|
66
|
+
case 'uint16': return GL.UNSIGNED_SHORT;
|
|
67
|
+
case 'sint16': return GL.SHORT;
|
|
68
|
+
case 'unorm16': return GL.UNSIGNED_SHORT;
|
|
69
|
+
case 'snorm16': return GL.SHORT;
|
|
70
|
+
case 'uint32': return GL.UNSIGNED_INT;
|
|
71
|
+
case 'sint32': return GL.INT;
|
|
72
|
+
// WebGPU does not support normalized 32 bit integer attributes
|
|
73
|
+
// case 'unorm32': return GL.UNSIGNED_INT;
|
|
74
|
+
// case 'snorm32': return GL.INT;
|
|
75
|
+
case 'float16': return GL.HALF_FLOAT;
|
|
76
|
+
case 'float32': return GL.FLOAT;
|
|
22
77
|
}
|
|
23
|
-
|
|
78
|
+
// @ts-ignore unreachable
|
|
79
|
+
throw new Error(String(dataType));
|
|
80
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {ShaderUniformType, ShaderAttributeType, VertexFormat} from '@luma.gl/core';
|
|
2
2
|
import {GL, GLUniformType, GLSamplerType, GLCompositeType, GLDataType} from '@luma.gl/constants';
|
|
3
3
|
|
|
4
4
|
/** Check is uniform is of sampler type */
|
|
@@ -27,7 +27,7 @@ const SAMPLER_TYPES: GLSamplerType[] = [
|
|
|
27
27
|
// Composite types table
|
|
28
28
|
const COMPOSITE_GL_TYPES: Record<
|
|
29
29
|
GLCompositeType,
|
|
30
|
-
[GLDataType, number, string,
|
|
30
|
+
[GLDataType, number, string, ShaderUniformType, VertexFormat?]
|
|
31
31
|
> = {
|
|
32
32
|
[GL.FLOAT]: [GL.FLOAT, 1, 'float', 'f32', 'float32'],
|
|
33
33
|
[GL.FLOAT_VEC2]: [GL.FLOAT, 2, 'vec2', 'vec2<f32>', 'float32x2'],
|
|
@@ -44,11 +44,12 @@ const COMPOSITE_GL_TYPES: Record<
|
|
|
44
44
|
[GL.UNSIGNED_INT_VEC3]: [GL.UNSIGNED_INT, 3, 'uvec3', 'vec3<u32>', 'uint32x3'],
|
|
45
45
|
[GL.UNSIGNED_INT_VEC4]: [GL.UNSIGNED_INT, 4, 'uvec4', 'vec4<u32>', 'uint32x4'],
|
|
46
46
|
|
|
47
|
-
[GL.BOOL]: [GL.FLOAT, 1, 'bool', 'f32', '
|
|
48
|
-
[GL.BOOL_VEC2]: [GL.FLOAT, 2, 'bvec2', 'vec2<f32>'],
|
|
49
|
-
[GL.BOOL_VEC3]: [GL.FLOAT, 3, 'bvec3', 'vec3<f32>'],
|
|
50
|
-
[GL.BOOL_VEC4]: [GL.FLOAT, 4, 'bvec4', 'vec4<f32>'],
|
|
47
|
+
[GL.BOOL]: [GL.FLOAT, 1, 'bool', 'f32', 'float32'],
|
|
48
|
+
[GL.BOOL_VEC2]: [GL.FLOAT, 2, 'bvec2', 'vec2<f32>', 'float32x2'],
|
|
49
|
+
[GL.BOOL_VEC3]: [GL.FLOAT, 3, 'bvec3', 'vec3<f32>', 'float32x3'],
|
|
50
|
+
[GL.BOOL_VEC4]: [GL.FLOAT, 4, 'bvec4', 'vec4<f32>', 'float32x4'],
|
|
51
51
|
|
|
52
|
+
// TODO - are sizes/components below correct?
|
|
52
53
|
[GL.FLOAT_MAT2]: [GL.FLOAT, 8, 'mat2', 'mat2x2<f32>'], // 4
|
|
53
54
|
[GL.FLOAT_MAT2x3]: [GL.FLOAT, 8, 'mat2x3', 'mat2x3<f32>'], // 6
|
|
54
55
|
[GL.FLOAT_MAT2x4]: [GL.FLOAT, 8, 'mat2x4', 'mat2x4<f32>'], // 8
|
|
@@ -62,11 +63,11 @@ const COMPOSITE_GL_TYPES: Record<
|
|
|
62
63
|
[GL.FLOAT_MAT4]: [GL.FLOAT, 16, 'mat4', 'mat4x4<f32>'] // 16
|
|
63
64
|
};
|
|
64
65
|
|
|
65
|
-
/** Decomposes a composite type GL.VEC3 into a basic type (GL.FLOAT) and components (3) */
|
|
66
|
-
export function
|
|
67
|
-
|
|
68
|
-
): {format:
|
|
69
|
-
const typeAndSize = COMPOSITE_GL_TYPES[
|
|
66
|
+
/** Decomposes a composite type (GL.VEC3) into a basic type (GL.FLOAT) and components (3) */
|
|
67
|
+
export function decodeGLUniformType(
|
|
68
|
+
glUniformType: GL
|
|
69
|
+
): {format: ShaderUniformType; components: number; glType: GLDataType} {
|
|
70
|
+
const typeAndSize = COMPOSITE_GL_TYPES[glUniformType];
|
|
70
71
|
if (!typeAndSize) {
|
|
71
72
|
throw new Error('uniform');
|
|
72
73
|
}
|
|
@@ -74,17 +75,21 @@ export function decodeUniformType(
|
|
|
74
75
|
return {format, components, glType};
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
/** Decomposes a composite type (GL.VEC3) into a basic type (GL.FLOAT) and components (3) */
|
|
79
|
+
export function decodeGLAttributeType(glAttributeType: GL): {
|
|
80
|
+
attributeType: ShaderAttributeType;
|
|
81
|
+
vertexFormat: VertexFormat;
|
|
79
82
|
components: number;
|
|
80
|
-
glType: GLDataType;
|
|
83
|
+
// glType: GLDataType;
|
|
81
84
|
} {
|
|
82
|
-
const typeAndSize = COMPOSITE_GL_TYPES[
|
|
85
|
+
const typeAndSize = COMPOSITE_GL_TYPES[glAttributeType];
|
|
83
86
|
if (!typeAndSize) {
|
|
84
87
|
throw new Error('attribute')
|
|
85
88
|
}
|
|
86
|
-
const [
|
|
87
|
-
|
|
89
|
+
const [, components, , shaderType, vertexFormat] = typeAndSize;
|
|
90
|
+
// TODO sanity - if (shaderType.startsWith('mat' ...))
|
|
91
|
+
const attributeType = shaderType as unknown as ShaderAttributeType
|
|
92
|
+
return {attributeType, vertexFormat, components}; // , glType};
|
|
88
93
|
}
|
|
89
94
|
|
|
90
95
|
/** Decomposes a composite type GL.VEC3 into a basic type (GL.FLOAT) and components (3) */
|
|
@@ -2,22 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
4
|
ShaderLayout,
|
|
5
|
-
AttributeLayout,
|
|
6
5
|
UniformBinding,
|
|
7
6
|
UniformBlockBinding,
|
|
8
|
-
|
|
9
|
-
VaryingBinding
|
|
10
|
-
AccessorObject,
|
|
11
|
-
BufferMapping,
|
|
12
|
-
VertexFormat
|
|
7
|
+
AttributeDeclaration,
|
|
8
|
+
VaryingBinding
|
|
13
9
|
} from '@luma.gl/core';
|
|
14
|
-
|
|
10
|
+
|
|
15
11
|
import {GL} from '@luma.gl/constants';
|
|
16
12
|
import {isWebGL2} from '../../context/context/webgl-checks';
|
|
17
13
|
import {Accessor} from '../../classic/accessor'; // TODO - should NOT depend on classic API
|
|
18
|
-
import {
|
|
19
|
-
import {getVertexFormat} from '../converters/vertex-formats';
|
|
20
|
-
import {isSamplerUniform} from './uniforms';
|
|
14
|
+
import {decodeGLUniformType, decodeGLAttributeType, isSamplerUniform} from './decode-webgl-types';
|
|
21
15
|
|
|
22
16
|
/**
|
|
23
17
|
* Extract metadata describing binding information for a program's shaders
|
|
@@ -30,20 +24,7 @@ export function getShaderLayout(gl: WebGLRenderingContext, program: WebGLProgram
|
|
|
30
24
|
bindings: []
|
|
31
25
|
};
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
for (const attribute of attributes) {
|
|
35
|
-
// TODO - multicolumn attributes like a matrix4 can be up to 16 elts...
|
|
36
|
-
const size = Math.min(attribute.accessor.size, 4);
|
|
37
|
-
const format =
|
|
38
|
-
// attribute.accessor.format ||
|
|
39
|
-
getVertexFormat(attribute.accessor.type || GL.FLOAT, size);
|
|
40
|
-
shaderLayout.attributes.push({
|
|
41
|
-
name: attribute.name,
|
|
42
|
-
location: attribute.location,
|
|
43
|
-
format,
|
|
44
|
-
stepMode: attribute.accessor.divisor === 1 ? 'instance' : 'vertex'
|
|
45
|
-
});
|
|
46
|
-
}
|
|
27
|
+
shaderLayout.attributes = readAttributeDeclarations(gl, program);
|
|
47
28
|
|
|
48
29
|
// Uniform blocks
|
|
49
30
|
const uniformBlocks: UniformBlockBinding[] = readUniformBlocks(gl, program);
|
|
@@ -98,79 +79,6 @@ export function getShaderLayout(gl: WebGLRenderingContext, program: WebGLProgram
|
|
|
98
79
|
return shaderLayout;
|
|
99
80
|
}
|
|
100
81
|
|
|
101
|
-
/**
|
|
102
|
-
* Merges an provided shader layout into a base shader layout
|
|
103
|
-
* In WebGL, this allows the auto generated shader layout to be overridden by the application
|
|
104
|
-
* Typically to change the format of the vertex attributes (from float32x4 to uint8x4 etc).
|
|
105
|
-
* @todo Drop this? This could also be done more clearly with bufferMapping
|
|
106
|
-
*/
|
|
107
|
-
export function mergeShaderLayout(
|
|
108
|
-
baseLayout: ShaderLayout,
|
|
109
|
-
overrideLayout: ShaderLayout
|
|
110
|
-
): ShaderLayout {
|
|
111
|
-
// Deep clone the base layout
|
|
112
|
-
const mergedLayout: ShaderLayout = {
|
|
113
|
-
...baseLayout,
|
|
114
|
-
attributes: baseLayout.attributes.map(attribute => ({...attribute}))
|
|
115
|
-
};
|
|
116
|
-
// Merge the attributes
|
|
117
|
-
for (const attribute of overrideLayout?.attributes || []) {
|
|
118
|
-
const baseAttribute = mergedLayout.attributes.find(attr => attr.name === attribute.name);
|
|
119
|
-
if (!baseAttribute) {
|
|
120
|
-
log.warn(`shader layout attribute ${attribute.name} not present in shader`);
|
|
121
|
-
} else {
|
|
122
|
-
baseAttribute.format = attribute.format || baseAttribute.format;
|
|
123
|
-
baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return mergedLayout;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function mergeBufferMap(baseLayout: ShaderLayout, bufferMap: BufferMapping[]): ShaderLayout {
|
|
130
|
-
// Deep clone the base layout
|
|
131
|
-
const mergedLayout: ShaderLayout = {
|
|
132
|
-
...baseLayout,
|
|
133
|
-
attributes: baseLayout.attributes.map(attribute => ({...attribute}))
|
|
134
|
-
};
|
|
135
|
-
for (const bufferMapping of bufferMap) {
|
|
136
|
-
// Handle interleave
|
|
137
|
-
switch (bufferMapping.type) {
|
|
138
|
-
case 'interleave':
|
|
139
|
-
// Handle interleaved buffer mapping
|
|
140
|
-
for (const attributeOverride of bufferMapping.attributes) {
|
|
141
|
-
overrideShaderLayoutAttribute(mergedLayout, attributeOverride);
|
|
142
|
-
}
|
|
143
|
-
break;
|
|
144
|
-
|
|
145
|
-
default:
|
|
146
|
-
// Handle simple attribute overrides
|
|
147
|
-
overrideShaderLayoutAttribute(mergedLayout, bufferMapping);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return mergedLayout;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function overrideShaderLayoutAttribute(
|
|
154
|
-
layout: ShaderLayout,
|
|
155
|
-
attributeOverride: {name: string; format?: VertexFormat}
|
|
156
|
-
): void {
|
|
157
|
-
const attribute = getAttributeFromLayout(layout, attributeOverride.name);
|
|
158
|
-
if (attribute && attributeOverride.format) {
|
|
159
|
-
attribute.format = attributeOverride.format;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export function getAttributeFromLayout(
|
|
164
|
-
shaderLayout: ShaderLayout,
|
|
165
|
-
name: string
|
|
166
|
-
): AttributeLayout | null {
|
|
167
|
-
const attribute = shaderLayout.attributes.find(attr => attr.name === name);
|
|
168
|
-
if (!attribute) {
|
|
169
|
-
log.warn(`shader layout attribute "${name}" not present in shader`);
|
|
170
|
-
}
|
|
171
|
-
return attribute || null;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
82
|
// HELPERS
|
|
175
83
|
|
|
176
84
|
/**
|
|
@@ -178,11 +86,11 @@ export function getAttributeFromLayout(
|
|
|
178
86
|
*
|
|
179
87
|
* linkProgram needs to have been called, although linking does not need to have been successful
|
|
180
88
|
*/
|
|
181
|
-
function
|
|
89
|
+
function readAttributeDeclarations(
|
|
182
90
|
gl: WebGLRenderingContext,
|
|
183
91
|
program: WebGLProgram
|
|
184
|
-
):
|
|
185
|
-
const attributes:
|
|
92
|
+
): AttributeDeclaration[] {
|
|
93
|
+
const attributes: AttributeDeclaration[] = [];
|
|
186
94
|
|
|
187
95
|
const count = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
|
|
188
96
|
|
|
@@ -191,23 +99,30 @@ function readAttributeBindings(
|
|
|
191
99
|
if (!activeInfo) {
|
|
192
100
|
throw new Error('activeInfo');
|
|
193
101
|
}
|
|
194
|
-
const {name, type: compositeType, size} = activeInfo;
|
|
102
|
+
const {name, type: compositeType /* , size*/} = activeInfo;
|
|
195
103
|
const location = gl.getAttribLocation(program, name);
|
|
196
|
-
// Add only user provided attributes, for built-in attributes like
|
|
197
|
-
// `gl_InstanceID` locaiton will be < 0
|
|
104
|
+
// Add only user provided attributes, for built-in attributes like `gl_InstanceID` location will be < 0
|
|
198
105
|
if (location >= 0) {
|
|
199
|
-
const {
|
|
200
|
-
|
|
201
|
-
//
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
|
|
106
|
+
const {attributeType} = decodeGLAttributeType(compositeType);
|
|
107
|
+
|
|
108
|
+
// Whether an attribute is instanced is essentially fixed by the structure of the shader code,
|
|
109
|
+
// so it is arguably a static property of the shader.
|
|
110
|
+
// There is no hint in the shader declarations
|
|
111
|
+
// Heuristic: Any attribute name containing the word "instance" will be assumed to be instanced
|
|
112
|
+
const stepMode = /instance/i.test(name) ? 'instance' : 'vertex';
|
|
113
|
+
|
|
114
|
+
attributes.push({
|
|
115
|
+
name,
|
|
116
|
+
location,
|
|
117
|
+
stepMode,
|
|
118
|
+
type: attributeType,
|
|
119
|
+
// size - for arrays, size is the number of elements in the array
|
|
120
|
+
});
|
|
207
121
|
}
|
|
208
122
|
}
|
|
209
123
|
|
|
210
|
-
|
|
124
|
+
// Sort by declaration order
|
|
125
|
+
attributes.sort((a: AttributeDeclaration, b: AttributeDeclaration) => a.location - b.location);
|
|
211
126
|
return attributes;
|
|
212
127
|
}
|
|
213
128
|
|
|
@@ -231,7 +146,7 @@ function readVaryings(gl: WebGLRenderingContext, program: WebGLProgram): Varying
|
|
|
231
146
|
throw new Error('activeInfo');
|
|
232
147
|
}
|
|
233
148
|
const {name, type: compositeType, size} = activeInfo;
|
|
234
|
-
const {glType, components} =
|
|
149
|
+
const {glType, components} = decodeGLUniformType(compositeType);
|
|
235
150
|
const accessor = new Accessor({type: glType, size: size * components});
|
|
236
151
|
const varying = {location, name, accessor}; // Base values
|
|
237
152
|
varyings.push(varying);
|
|
@@ -290,9 +205,7 @@ function readUniformBindings(gl: WebGLRenderingContext, program: WebGLProgram):
|
|
|
290
205
|
|
|
291
206
|
/**
|
|
292
207
|
* Extract info about all "active" uniform blocks
|
|
293
|
-
*
|
|
294
|
-
* ("Active" just means that unused (aka inactive) blocks may have been
|
|
295
|
-
* optimized away during linking)
|
|
208
|
+
* @note In WebGL, "active" just means that unused (inactive) blocks may have been optimized away during linking)
|
|
296
209
|
*/
|
|
297
210
|
function readUniformBlocks(
|
|
298
211
|
gl: WebGLRenderingContext,
|
|
@@ -346,7 +259,7 @@ function readUniformBlocks(
|
|
|
346
259
|
|
|
347
260
|
blockInfo.uniforms.push({
|
|
348
261
|
name: activeInfo.name,
|
|
349
|
-
format:
|
|
262
|
+
format: decodeGLUniformType(uniformType[i]).format,
|
|
350
263
|
type: uniformType[i],
|
|
351
264
|
arrayLength: uniformArrayLength[i],
|
|
352
265
|
byteOffset: uniformOffset[i],
|
|
@@ -363,6 +276,27 @@ function readUniformBlocks(
|
|
|
363
276
|
return uniformBlocks;
|
|
364
277
|
}
|
|
365
278
|
|
|
279
|
+
/**
|
|
280
|
+
* TOOD - compare with a above, confirm copy, then delete
|
|
281
|
+
const bindings: Binding[] = [];
|
|
282
|
+
const count = gl.getProgramParameter(program, gl.ACTIVE_UNIFORM_BLOCKS);
|
|
283
|
+
for (let blockIndex = 0; blockIndex < count; blockIndex++) {
|
|
284
|
+
const vertex = gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
|
|
285
|
+
const fragment = gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER),
|
|
286
|
+
const visibility = (vertex) + (fragment);
|
|
287
|
+
const binding: BufferBinding = {
|
|
288
|
+
location: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_BINDING),
|
|
289
|
+
// name: gl.getActiveUniformBlockName(program, blockIndex),
|
|
290
|
+
type: 'uniform',
|
|
291
|
+
visibility,
|
|
292
|
+
minBindingSize: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_DATA_SIZE),
|
|
293
|
+
// uniformCount: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_ACTIVE_UNIFORMS),
|
|
294
|
+
// uniformIndices: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES),
|
|
295
|
+
}
|
|
296
|
+
bindings.push(binding);
|
|
297
|
+
}
|
|
298
|
+
*/
|
|
299
|
+
|
|
366
300
|
const SAMPLER_UNIFORMS_GL_TO_GPU: Record<
|
|
367
301
|
number,
|
|
368
302
|
[
|
|
@@ -426,45 +360,3 @@ function parseUniformName(name: string): {name: string; length: number; isArray:
|
|
|
426
360
|
isArray: Boolean(matches[2])
|
|
427
361
|
};
|
|
428
362
|
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* TODO - verify this is a copy of above and delete
|
|
432
|
-
* import type {TextureFormat} from '@luma.gl/core';
|
|
433
|
-
* Extract info about all "active" uniform blocks
|
|
434
|
-
* ("Active" just means that unused (inactive) blocks may have been optimized away during linking)
|
|
435
|
-
*
|
|
436
|
-
function getUniformBlockBindings(gl: WebGLRenderingContext, program): Binding[] {
|
|
437
|
-
if (!isWebGL2(gl)) {
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
const bindings: Binding[] = [];
|
|
441
|
-
const count = gl.getProgramParameter(program, gl.ACTIVE_UNIFORM_BLOCKS);
|
|
442
|
-
for (let blockIndex = 0; blockIndex < count; blockIndex++) {
|
|
443
|
-
const vertex = gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER),
|
|
444
|
-
const fragment = gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER),
|
|
445
|
-
const visibility = (vertex) + (fragment);
|
|
446
|
-
const binding: BufferBinding = {
|
|
447
|
-
location: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_BINDING),
|
|
448
|
-
// name: gl.getActiveUniformBlockName(program, blockIndex),
|
|
449
|
-
type: 'uniform',
|
|
450
|
-
visibility,
|
|
451
|
-
minBindingSize: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_DATA_SIZE),
|
|
452
|
-
// uniformCount: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_ACTIVE_UNIFORMS),
|
|
453
|
-
// uniformIndices: gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES),
|
|
454
|
-
}
|
|
455
|
-
bindings.push(binding);
|
|
456
|
-
}
|
|
457
|
-
return bindings;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
function setBindings(gl2: WebGL2RenderingContext, program: WebGLProgram, bindings: Binding[][]): void {
|
|
461
|
-
for (const bindGroup of bindings) {
|
|
462
|
-
for (const binding of bindGroup) {
|
|
463
|
-
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
// Set up indirection table
|
|
468
|
-
// this.gl2.uniformBlockBinding(this.handle, blockIndex, blockBinding);
|
|
469
|
-
}
|
|
470
|
-
*/
|
|
@@ -1,53 +1,53 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
|
|
3
3
|
// Uniforms
|
|
4
|
-
import {
|
|
4
|
+
import type {UniformValue} from '@luma.gl/core';
|
|
5
|
+
import {GL, GLCompositeType, GLSamplerType} from '@luma.gl/constants';
|
|
5
6
|
|
|
6
7
|
/** Set a raw uniform (without type conversion and caching) */
|
|
7
8
|
/* eslint-disable max-len */
|
|
8
9
|
export function setUniform(
|
|
9
10
|
gl: WebGLRenderingContext,
|
|
10
11
|
location: WebGLUniformLocation,
|
|
11
|
-
type:
|
|
12
|
-
value:
|
|
12
|
+
type: GLCompositeType | GLSamplerType,
|
|
13
|
+
value: UniformValue
|
|
13
14
|
): void {
|
|
14
15
|
const gl2 = gl as WebGL2RenderingContext;
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
case GL.SAMPLER_2D:
|
|
21
|
-
case GL.SAMPLER_CUBE:
|
|
22
|
-
// WebGL2 samplers
|
|
23
|
-
case GL.SAMPLER_3D:
|
|
24
|
-
case GL.SAMPLER_2D_SHADOW:
|
|
25
|
-
case GL.SAMPLER_2D_ARRAY:
|
|
26
|
-
case GL.SAMPLER_2D_ARRAY_SHADOW:
|
|
27
|
-
case GL.SAMPLER_CUBE_SHADOW:
|
|
28
|
-
case GL.INT_SAMPLER_2D:
|
|
29
|
-
case GL.INT_SAMPLER_3D:
|
|
30
|
-
case GL.INT_SAMPLER_CUBE:
|
|
31
|
-
case GL.INT_SAMPLER_2D_ARRAY:
|
|
32
|
-
case GL.UNSIGNED_INT_SAMPLER_2D:
|
|
33
|
-
case GL.UNSIGNED_INT_SAMPLER_3D:
|
|
34
|
-
case GL.UNSIGNED_INT_SAMPLER_CUBE:
|
|
35
|
-
case GL.UNSIGNED_INT_SAMPLER_2D_ARRAY:
|
|
36
|
-
return gl.uniform1i(location, value);
|
|
37
|
-
}
|
|
17
|
+
// Prepare the value for WebGL setters
|
|
18
|
+
let uniformValue = value;
|
|
19
|
+
if (uniformValue === true) {
|
|
20
|
+
uniformValue = 1;
|
|
38
21
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
value = 1;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (value === false) {
|
|
45
|
-
value = 0;
|
|
22
|
+
if (uniformValue === false) {
|
|
23
|
+
uniformValue = 0;
|
|
46
24
|
}
|
|
47
|
-
const arrayValue =
|
|
25
|
+
const arrayValue = typeof uniformValue === 'number' ? [uniformValue] : uniformValue;
|
|
48
26
|
|
|
49
27
|
// prettier-ignore
|
|
50
28
|
switch (type) {
|
|
29
|
+
// WebGL1 samplers
|
|
30
|
+
case GL.SAMPLER_2D:
|
|
31
|
+
case GL.SAMPLER_CUBE:
|
|
32
|
+
// WebGL2 samplers
|
|
33
|
+
case GL.SAMPLER_3D:
|
|
34
|
+
case GL.SAMPLER_2D_SHADOW:
|
|
35
|
+
case GL.SAMPLER_2D_ARRAY:
|
|
36
|
+
case GL.SAMPLER_2D_ARRAY_SHADOW:
|
|
37
|
+
case GL.SAMPLER_CUBE_SHADOW:
|
|
38
|
+
case GL.INT_SAMPLER_2D:
|
|
39
|
+
case GL.INT_SAMPLER_3D:
|
|
40
|
+
case GL.INT_SAMPLER_CUBE:
|
|
41
|
+
case GL.INT_SAMPLER_2D_ARRAY:
|
|
42
|
+
case GL.UNSIGNED_INT_SAMPLER_2D:
|
|
43
|
+
case GL.UNSIGNED_INT_SAMPLER_3D:
|
|
44
|
+
case GL.UNSIGNED_INT_SAMPLER_CUBE:
|
|
45
|
+
case GL.UNSIGNED_INT_SAMPLER_2D_ARRAY:
|
|
46
|
+
if (typeof value !== 'number') {
|
|
47
|
+
throw new Error('samplers must be set to integers');
|
|
48
|
+
}
|
|
49
|
+
return gl.uniform1i(location, value);
|
|
50
|
+
|
|
51
51
|
case GL.FLOAT: return gl.uniform1fv(location, arrayValue);
|
|
52
52
|
case GL.FLOAT_VEC2: return gl.uniform2fv(location, arrayValue);
|
|
53
53
|
case GL.FLOAT_VEC3: return gl.uniform3fv(location, arrayValue);
|
|
@@ -8,6 +8,7 @@ import {WebGLResource} from './webgl-resource';
|
|
|
8
8
|
import {WEBGLBuffer} from '../resources/webgl-buffer';
|
|
9
9
|
|
|
10
10
|
import {BufferWithAccessor} from '../../classic/buffer-with-accessor';
|
|
11
|
+
import {AccessorObject} from '../..';
|
|
11
12
|
|
|
12
13
|
const ERR_ELEMENTS = 'elements must be GL.ELEMENT_ARRAY_BUFFER';
|
|
13
14
|
|
|
@@ -93,7 +94,7 @@ export class WEBGLVertexArrayObject extends WebGLResource<VertexArrayObjectProps
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
/** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
|
|
96
|
-
setBuffer(location: number, buffer: WEBGLBuffer, accessor:
|
|
97
|
+
setBuffer(location: number, buffer: WEBGLBuffer, accessor: AccessorObject): void {
|
|
97
98
|
// Check target
|
|
98
99
|
if (buffer.glTarget === GL.ELEMENT_ARRAY_BUFFER) {
|
|
99
100
|
this.setElementBuffer(buffer, accessor);
|
|
@@ -15,7 +15,7 @@ export class WEBGLCommandEncoder extends CommandEncoder {
|
|
|
15
15
|
readonly commandBuffer: WEBGLCommandBuffer;
|
|
16
16
|
|
|
17
17
|
constructor(device: WebGLDevice, props: CommandEncoderProps) {
|
|
18
|
-
super(props);
|
|
18
|
+
super(device, props);
|
|
19
19
|
this.device = device;
|
|
20
20
|
this.commandBuffer = new WEBGLCommandBuffer(device);
|
|
21
21
|
}
|