@zephyr3d/device 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base_types.js +602 -0
- package/dist/base_types.js.map +1 -0
- package/dist/builder/ast.js +2135 -0
- package/dist/builder/ast.js.map +1 -0
- package/dist/builder/base.js +477 -0
- package/dist/builder/base.js.map +1 -0
- package/dist/builder/builtinfunc.js +4101 -0
- package/dist/builder/builtinfunc.js.map +1 -0
- package/dist/builder/constructors.js +173 -0
- package/dist/builder/constructors.js.map +1 -0
- package/dist/builder/errors.js +148 -0
- package/dist/builder/errors.js.map +1 -0
- package/dist/builder/programbuilder.js +2323 -0
- package/dist/builder/programbuilder.js.map +1 -0
- package/dist/builder/reflection.js +60 -0
- package/dist/builder/reflection.js.map +1 -0
- package/dist/builder/types.js +1563 -0
- package/dist/builder/types.js.map +1 -0
- package/dist/device.js +515 -0
- package/dist/device.js.map +1 -0
- package/dist/gpuobject.js +2047 -0
- package/dist/gpuobject.js.map +1 -0
- package/dist/helpers/drawtext.js +187 -0
- package/dist/helpers/drawtext.js.map +1 -0
- package/dist/helpers/font.js +189 -0
- package/dist/helpers/font.js.map +1 -0
- package/dist/helpers/glyphmanager.js +121 -0
- package/dist/helpers/glyphmanager.js.map +1 -0
- package/dist/helpers/textureatlas.js +170 -0
- package/dist/helpers/textureatlas.js.map +1 -0
- package/dist/index.d.ts +3873 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/timer.js +38 -0
- package/dist/timer.js.map +1 -0
- package/dist/uniformdata.js +147 -0
- package/dist/uniformdata.js.map +1 -0
- package/dist/vertexdata.js +135 -0
- package/dist/vertexdata.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtinfunc.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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base.js';
|
|
2
|
+
import { PBTextureType, typeAtomicI32, typeAtomicU32, typeU32, PBPrimitiveType, typeF32, typeI32, typeBool, typeF32Vec2, typeI32Vec2, typeU32Vec2, typeBVec2, typeF32Vec3, typeI32Vec3, typeU32Vec3, typeBVec3, typeF32Vec4, typeI32Vec4, typeU32Vec4, typeBVec4, typeMat2, typeMat2x3, typeMat2x4, typeMat3x2, typeMat3, typeMat3x4, typeMat4x2, typeMat4x3, typeMat4, typeTex1D, typeTex2D, typeTex3D, typeTexCube, typeTexDepth2D, typeTexDepthCube, typeTex2DArray, typeTexDepth2DArray, typeTexExternal, typeITex1D, typeITex2D, typeITex3D, typeITexCube, typeITex2DArray, typeUTex1D, typeUTex2D, typeUTex3D, typeUTexCube, typeUTex2DArray, typeSampler, typeSamplerComparison, PBTextureTypeInfo } from './types.js';
|
|
3
|
+
import { ASTShaderExpConstructor, ASTScalar } from './ast.js';
|
|
4
|
+
import { PBParamLengthError, PBParamTypeError, PBDeviceNotSupport } from './errors.js';
|
|
5
|
+
|
|
6
|
+
const StorageTextureFormatMap = {
|
|
7
|
+
rgba8unorm: 'rgba8unorm',
|
|
8
|
+
rgba8snorm: 'rgba8snorm',
|
|
9
|
+
rgba8uint: 'rgba8ui',
|
|
10
|
+
rgba8sint: 'rgba8i',
|
|
11
|
+
rgba16uint: 'rgba16ui',
|
|
12
|
+
rgba16sint: 'rgba16i',
|
|
13
|
+
rgba16float: 'rgba16f',
|
|
14
|
+
r32float: 'r32f',
|
|
15
|
+
r32uint: 'r32ui',
|
|
16
|
+
r32sint: 'r32i',
|
|
17
|
+
rg32float: 'rg32f',
|
|
18
|
+
rg32uint: 'rg32ui',
|
|
19
|
+
rg32sint: 'rg32i',
|
|
20
|
+
rgba32float: 'rgba32f',
|
|
21
|
+
rgba32uint: 'rgba32ui',
|
|
22
|
+
rgba32sint: 'rgba32i'
|
|
23
|
+
};
|
|
24
|
+
function vec_n(vecType, ...args) {
|
|
25
|
+
if (this.getDevice().type === 'webgl') {
|
|
26
|
+
if (vecType.scalarType === PBPrimitiveType.U32) {
|
|
27
|
+
throw new PBDeviceNotSupport('unsigned integer type');
|
|
28
|
+
}
|
|
29
|
+
if (vecType.isMatrixType() && vecType.cols !== vecType.rows) {
|
|
30
|
+
throw new PBDeviceNotSupport('non-square matrix type');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (args.length === 1 && typeof args[0] === 'string') {
|
|
34
|
+
return new PBShaderExp(args[0], vecType);
|
|
35
|
+
} else {
|
|
36
|
+
const exp = new PBShaderExp('', vecType);
|
|
37
|
+
if (vecType.isScalarType() && args.length === 1 && (typeof args[0] === 'number' || typeof args[0] === 'boolean')) {
|
|
38
|
+
exp.$ast = new ASTScalar(args[0], vecType);
|
|
39
|
+
} else {
|
|
40
|
+
exp.$ast = new ASTShaderExpConstructor(exp.$typeinfo, args.map((arg)=>{
|
|
41
|
+
if (typeof arg === 'string') {
|
|
42
|
+
throw new PBParamTypeError('vec_n');
|
|
43
|
+
}
|
|
44
|
+
return arg instanceof PBShaderExp ? arg.$ast : arg;
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
return exp;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const primitiveCtors = {
|
|
51
|
+
float: typeF32,
|
|
52
|
+
int: typeI32,
|
|
53
|
+
uint: typeU32,
|
|
54
|
+
bool: typeBool,
|
|
55
|
+
vec2: typeF32Vec2,
|
|
56
|
+
ivec2: typeI32Vec2,
|
|
57
|
+
uvec2: typeU32Vec2,
|
|
58
|
+
bvec2: typeBVec2,
|
|
59
|
+
vec3: typeF32Vec3,
|
|
60
|
+
ivec3: typeI32Vec3,
|
|
61
|
+
uvec3: typeU32Vec3,
|
|
62
|
+
bvec3: typeBVec3,
|
|
63
|
+
vec4: typeF32Vec4,
|
|
64
|
+
ivec4: typeI32Vec4,
|
|
65
|
+
uvec4: typeU32Vec4,
|
|
66
|
+
bvec4: typeBVec4,
|
|
67
|
+
mat2: typeMat2,
|
|
68
|
+
mat2x3: typeMat2x3,
|
|
69
|
+
mat2x4: typeMat2x4,
|
|
70
|
+
mat3x2: typeMat3x2,
|
|
71
|
+
mat3: typeMat3,
|
|
72
|
+
mat3x4: typeMat3x4,
|
|
73
|
+
mat4x2: typeMat4x2,
|
|
74
|
+
mat4x3: typeMat4x3,
|
|
75
|
+
mat4: typeMat4
|
|
76
|
+
};
|
|
77
|
+
const simpleCtors = {
|
|
78
|
+
tex1D: typeTex1D,
|
|
79
|
+
tex2D: typeTex2D,
|
|
80
|
+
tex3D: typeTex3D,
|
|
81
|
+
texCube: typeTexCube,
|
|
82
|
+
tex2DShadow: typeTexDepth2D,
|
|
83
|
+
texCubeShadow: typeTexDepthCube,
|
|
84
|
+
tex2DArray: typeTex2DArray,
|
|
85
|
+
tex2DArrayShadow: typeTexDepth2DArray,
|
|
86
|
+
texExternal: typeTexExternal,
|
|
87
|
+
itex1D: typeITex1D,
|
|
88
|
+
itex2D: typeITex2D,
|
|
89
|
+
itex3D: typeITex3D,
|
|
90
|
+
itexCube: typeITexCube,
|
|
91
|
+
itex2DArray: typeITex2DArray,
|
|
92
|
+
utex1D: typeUTex1D,
|
|
93
|
+
utex2D: typeUTex2D,
|
|
94
|
+
utex3D: typeUTex3D,
|
|
95
|
+
utexCube: typeUTexCube,
|
|
96
|
+
utex2DArray: typeUTex2DArray,
|
|
97
|
+
sampler: typeSampler,
|
|
98
|
+
samplerComparison: typeSamplerComparison
|
|
99
|
+
};
|
|
100
|
+
function makeStorageTextureCtor(type) {
|
|
101
|
+
const ctor = {};
|
|
102
|
+
for (const k of Object.keys(StorageTextureFormatMap)){
|
|
103
|
+
ctor[k] = function(rhs) {
|
|
104
|
+
return new PBShaderExp(rhs, new PBTextureTypeInfo(type, StorageTextureFormatMap[k]));
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return ctor;
|
|
108
|
+
}
|
|
109
|
+
const texStorageCtors = {
|
|
110
|
+
texStorage1D: PBTextureType.TEX_STORAGE_1D,
|
|
111
|
+
texStorage2D: PBTextureType.TEX_STORAGE_2D,
|
|
112
|
+
texStorage2DArray: PBTextureType.TEX_STORAGE_2D_ARRAY,
|
|
113
|
+
texStorage3D: PBTextureType.TEX_STORAGE_3D
|
|
114
|
+
};
|
|
115
|
+
/** @internal */ function setConstructors(cls) {
|
|
116
|
+
Object.keys(primitiveCtors).forEach((k)=>{
|
|
117
|
+
cls.prototype[k] = makeConstructor(function(...args) {
|
|
118
|
+
return vec_n.call(this, primitiveCtors[k], ...args);
|
|
119
|
+
}, primitiveCtors[k]);
|
|
120
|
+
});
|
|
121
|
+
Object.keys(simpleCtors).forEach((k)=>{
|
|
122
|
+
cls.prototype[k] = function(rhs) {
|
|
123
|
+
return new PBShaderExp(rhs, simpleCtors[k]);
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
Object.keys(texStorageCtors).forEach((k)=>{
|
|
127
|
+
cls.prototype[k] = makeStorageTextureCtor(texStorageCtors[k]);
|
|
128
|
+
});
|
|
129
|
+
cls.prototype['atomic_int'] = function(...args) {
|
|
130
|
+
if (args.length > 1) {
|
|
131
|
+
throw new PBParamLengthError('atomic_int');
|
|
132
|
+
}
|
|
133
|
+
if (args.length === 1) {
|
|
134
|
+
if (typeof args[0] !== 'string') {
|
|
135
|
+
throw new PBParamTypeError('atomic_int', 'name');
|
|
136
|
+
}
|
|
137
|
+
return new PBShaderExp(args[0], typeAtomicI32);
|
|
138
|
+
} else {
|
|
139
|
+
const exp = new PBShaderExp('', typeAtomicI32);
|
|
140
|
+
exp.$ast = new ASTShaderExpConstructor(exp.$typeinfo, []);
|
|
141
|
+
return exp;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
cls.prototype['atomic_uint'] = function(...args) {
|
|
145
|
+
if (args.length > 1) {
|
|
146
|
+
throw new PBParamLengthError('atomic_uint');
|
|
147
|
+
}
|
|
148
|
+
if (args.length === 1 && typeof args[0] === 'string') {
|
|
149
|
+
return new PBShaderExp(args[0], typeAtomicU32);
|
|
150
|
+
} else if (args.length === 0) {
|
|
151
|
+
const exp = new PBShaderExp('', typeAtomicU32);
|
|
152
|
+
exp.$ast = new ASTShaderExpConstructor(exp.$typeinfo, []);
|
|
153
|
+
return exp;
|
|
154
|
+
}
|
|
155
|
+
const arg = args[0];
|
|
156
|
+
if (typeof arg === 'number' && Number.isInteger(arg) || arg instanceof PBShaderExp && arg.$ast.getType().typeId === typeU32.typeId) {
|
|
157
|
+
const exp = new PBShaderExp('', typeAtomicU32);
|
|
158
|
+
exp.$ast = new ASTShaderExpConstructor(exp.$typeinfo, [
|
|
159
|
+
arg instanceof PBShaderExp ? arg.$ast : arg
|
|
160
|
+
]);
|
|
161
|
+
return exp;
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
};
|
|
165
|
+
} /*
|
|
166
|
+
ProgramBuilder.prototype.texStorage1D = makeStorageTextureCtor(typeinfo.PBTextureType.TEX_STORAGE_1D);
|
|
167
|
+
ProgramBuilder.prototype.texStorage2D = makeStorageTextureCtor(typeinfo.PBTextureType.TEX_STORAGE_2D);
|
|
168
|
+
ProgramBuilder.prototype.texStorage2DArray = makeStorageTextureCtor(typeinfo.PBTextureType.TEX_STORAGE_2D_ARRAY);
|
|
169
|
+
ProgramBuilder.prototype.texStorage3D = makeStorageTextureCtor(typeinfo.PBTextureType.TEX_STORAGE_3D);
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
export { setConstructors };
|
|
173
|
+
//# sourceMappingURL=constructors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constructors.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/** @internal */ function expValueToString(deviceType, value) {
|
|
2
|
+
if (typeof value === 'number' || typeof value === 'boolean' || Array.isArray(value)) {
|
|
3
|
+
return `${value}`;
|
|
4
|
+
} else {
|
|
5
|
+
return value.$ast?.toString(deviceType);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** @internal */ function expValueTypeToString(deviceType, type) {
|
|
9
|
+
return type?.toTypeName(deviceType);
|
|
10
|
+
}
|
|
11
|
+
/** @internal */ class PBError extends Error {
|
|
12
|
+
}
|
|
13
|
+
/** @internal */ class PBValueOutOfRange extends PBError {
|
|
14
|
+
value;
|
|
15
|
+
constructor(value){
|
|
16
|
+
super();
|
|
17
|
+
this.value = value;
|
|
18
|
+
}
|
|
19
|
+
getMessage(deviceType) {
|
|
20
|
+
return `value out of range: ${this.value}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** @internal */ class PBTypeCastError extends PBError {
|
|
24
|
+
value;
|
|
25
|
+
valueType;
|
|
26
|
+
expectedType;
|
|
27
|
+
constructor(value, valueType, expectedType){
|
|
28
|
+
super();
|
|
29
|
+
this.value = value;
|
|
30
|
+
this.valueType = valueType;
|
|
31
|
+
this.expectedType = expectedType;
|
|
32
|
+
}
|
|
33
|
+
getMessage(deviceType) {
|
|
34
|
+
const valueStr = typeof this.value === 'string' ? this.value : expValueToString(deviceType, this.value);
|
|
35
|
+
const valueTypeStr = typeof this.valueType === 'string' ? this.valueType : expValueTypeToString(deviceType, this.valueType);
|
|
36
|
+
const expectedTypeStr = typeof this.expectedType === 'string' ? this.expectedType : expValueTypeToString(deviceType, this.expectedType);
|
|
37
|
+
return `cannot convert '${valueStr}' of type '${valueTypeStr}' to type ${expectedTypeStr}`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** @internal */ class PBParamLengthError extends PBError {
|
|
41
|
+
func;
|
|
42
|
+
constructor(func){
|
|
43
|
+
super();
|
|
44
|
+
this.func = func;
|
|
45
|
+
}
|
|
46
|
+
getMessage(deviceType) {
|
|
47
|
+
return `wrong argument count for function '${this.func}'`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** @internal */ class PBParamTypeError extends PBError {
|
|
51
|
+
func;
|
|
52
|
+
param;
|
|
53
|
+
constructor(func, param){
|
|
54
|
+
super();
|
|
55
|
+
this.func = func;
|
|
56
|
+
this.param = param || null;
|
|
57
|
+
}
|
|
58
|
+
getMessage(deviceType) {
|
|
59
|
+
return `parameter type error for function '${this.func}': ${this.param}`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** @internal */ class PBParamValueError extends PBError {
|
|
63
|
+
func;
|
|
64
|
+
param;
|
|
65
|
+
reason;
|
|
66
|
+
constructor(func, param, reason){
|
|
67
|
+
super();
|
|
68
|
+
this.func = func;
|
|
69
|
+
this.param = param || null;
|
|
70
|
+
this.reason = reason || null;
|
|
71
|
+
}
|
|
72
|
+
getMessage(deviceType) {
|
|
73
|
+
return `invalid parameter value for function '${this.func}'${this.param ? ': ' + this.param : ''}${this.reason ? ': ' + this.reason : ''}}`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** @internal */ class PBOverloadingMatchError extends PBError {
|
|
77
|
+
func;
|
|
78
|
+
constructor(func){
|
|
79
|
+
super();
|
|
80
|
+
this.func = func;
|
|
81
|
+
}
|
|
82
|
+
getMessage(deviceType) {
|
|
83
|
+
return `No matched overloading found for function '${this.func}'`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** @internal */ class PBReferenceValueRequired extends PBError {
|
|
87
|
+
value;
|
|
88
|
+
constructor(value){
|
|
89
|
+
super();
|
|
90
|
+
this.value = value;
|
|
91
|
+
}
|
|
92
|
+
getMessage(deviceType) {
|
|
93
|
+
return `'${expValueToString(deviceType, this.value)}' is not a reference type`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** @internal */ class PBPointerValueRequired extends PBError {
|
|
97
|
+
value;
|
|
98
|
+
constructor(value){
|
|
99
|
+
super();
|
|
100
|
+
this.value = value;
|
|
101
|
+
}
|
|
102
|
+
getMessage(deviceType) {
|
|
103
|
+
return `'${expValueToString(deviceType, this.value)}' is not a pointer type`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** @internal */ class PBDeviceNotSupport extends PBError {
|
|
107
|
+
feature;
|
|
108
|
+
constructor(feature){
|
|
109
|
+
super();
|
|
110
|
+
this.feature = feature;
|
|
111
|
+
}
|
|
112
|
+
getMessage(deviceType) {
|
|
113
|
+
return `feature not support for ${deviceType} device: ${this.feature}`;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** @internal */ class PBNonScopedFunctionCall extends PBError {
|
|
117
|
+
funcName;
|
|
118
|
+
constructor(funcName){
|
|
119
|
+
super();
|
|
120
|
+
this.funcName = funcName;
|
|
121
|
+
}
|
|
122
|
+
getMessage(deviceType) {
|
|
123
|
+
return `function call must be made inside a function scope: ${this.funcName}()`;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** @internal */ class PBASTError extends PBError {
|
|
127
|
+
ast;
|
|
128
|
+
text;
|
|
129
|
+
constructor(ast, text){
|
|
130
|
+
super();
|
|
131
|
+
this.ast = ast;
|
|
132
|
+
this.text = text;
|
|
133
|
+
}
|
|
134
|
+
getMessage(deviceType) {
|
|
135
|
+
return `${this.text}: ${this.ast.toString(deviceType)}`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/** @internal */ class PBInternalError extends PBError {
|
|
139
|
+
constructor(desc){
|
|
140
|
+
super(desc);
|
|
141
|
+
}
|
|
142
|
+
getMessage(deviceType) {
|
|
143
|
+
return `Internal error: ${this.message}`;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { PBASTError, PBDeviceNotSupport, PBError, PBInternalError, PBNonScopedFunctionCall, PBOverloadingMatchError, PBParamLengthError, PBParamTypeError, PBParamValueError, PBPointerValueRequired, PBReferenceValueRequired, PBTypeCastError, PBValueOutOfRange, expValueToString, expValueTypeToString };
|
|
148
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|