@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,602 @@
|
|
|
1
|
+
import { floatToHalf } from '@zephyr3d/base';
|
|
2
|
+
|
|
3
|
+
const RED_SHIFT = 0;
|
|
4
|
+
const GREEN_SHIFT = 1;
|
|
5
|
+
const BLUE_SHIFT = 2;
|
|
6
|
+
const ALPHA_SHIFT = 3;
|
|
7
|
+
const DEPTH_SHIFT = 4;
|
|
8
|
+
const STENCIL_SHIFT = 5;
|
|
9
|
+
const FLOAT_SHIFT = 6;
|
|
10
|
+
const INTEGER_SHIFT = 7;
|
|
11
|
+
const SIGNED_SHIFT = 8;
|
|
12
|
+
const SRGB_SHIFT = 9;
|
|
13
|
+
const BGR_SHIFT = 10;
|
|
14
|
+
const BLOCK_SIZE_SHIFT = 11;
|
|
15
|
+
const BLOCK_SIZE_MASK = 0x1f << BLOCK_SIZE_SHIFT;
|
|
16
|
+
const BLOCK_WIDTH_SHIFT = 16;
|
|
17
|
+
const BLOCK_WIDTH_MASK = 0xf << BLOCK_WIDTH_SHIFT;
|
|
18
|
+
const BLOCK_HEIGHT_SHIFT = 20;
|
|
19
|
+
const BLOCK_HEIGHT_MASK = 0xf << BLOCK_HEIGHT_SHIFT;
|
|
20
|
+
const COMPRESSED_FORMAT_SHIFT = 24;
|
|
21
|
+
const COMPRESSION_FORMAT_BC1 = 1 << COMPRESSED_FORMAT_SHIFT;
|
|
22
|
+
const COMPRESSION_FORMAT_BC2 = 2 << COMPRESSED_FORMAT_SHIFT;
|
|
23
|
+
const COMPRESSION_FORMAT_BC3 = 3 << COMPRESSED_FORMAT_SHIFT;
|
|
24
|
+
/*
|
|
25
|
+
const COMPRESSION_FORMAT_BC4 = 4 << COMPRESSED_FORMAT_SHIFT;
|
|
26
|
+
const COMPRESSION_FORMAT_BC5 = 5 << COMPRESSED_FORMAT_SHIFT;
|
|
27
|
+
const COMPRESSION_FORMAT_BC6 = 6 << COMPRESSED_FORMAT_SHIFT;
|
|
28
|
+
const COMPRESSION_FORMAT_BC7 = 7 << COMPRESSED_FORMAT_SHIFT;
|
|
29
|
+
const COMPRESSION_FORMAT_ETC2_RGB8 = 8 << COMPRESSED_FORMAT_SHIFT;
|
|
30
|
+
const COMPRESSION_FORMAT_ETC2_RGB8_A1 = 9 << COMPRESSED_FORMAT_SHIFT;
|
|
31
|
+
const COMPRESSION_FORMAT_ETC2_RGBA8 = 10 << COMPRESSED_FORMAT_SHIFT;
|
|
32
|
+
const COMPRESSION_FORMAT_ASTC_4x4 = 11 << COMPRESSED_FORMAT_SHIFT;
|
|
33
|
+
const COMPRESSION_FORMAT_ASTC_5x4 = 12 << COMPRESSED_FORMAT_SHIFT;
|
|
34
|
+
const COMPRESSION_FORMAT_ASTC_5x5 = 13 << COMPRESSED_FORMAT_SHIFT;
|
|
35
|
+
const COMPRESSION_FORMAT_ASTC_6x5 = 14 << COMPRESSED_FORMAT_SHIFT;
|
|
36
|
+
const COMPRESSION_FORMAT_ASTC_6x6 = 15 << COMPRESSED_FORMAT_SHIFT;
|
|
37
|
+
const COMPRESSION_FORMAT_ASTC_8x5 = 16 << COMPRESSED_FORMAT_SHIFT;
|
|
38
|
+
const COMPRESSION_FORMAT_ASTC_8x6 = 17 << COMPRESSED_FORMAT_SHIFT;
|
|
39
|
+
const COMPRESSION_FORMAT_ASTC_8x8 = 18 << COMPRESSED_FORMAT_SHIFT;
|
|
40
|
+
const COMPRESSION_FORMAT_ASTC_10x5 = 19 << COMPRESSED_FORMAT_SHIFT;
|
|
41
|
+
const COMPRESSION_FORMAT_ASTC_10x6 = 20 << COMPRESSED_FORMAT_SHIFT;
|
|
42
|
+
const COMPRESSION_FORMAT_ASTC_10x8 = 21 << COMPRESSED_FORMAT_SHIFT;
|
|
43
|
+
const COMPRESSION_FORMAT_ASTC_10x10 = 22 << COMPRESSED_FORMAT_SHIFT;
|
|
44
|
+
const COMPRESSION_FORMAT_ASTC_12x10 = 23 << COMPRESSED_FORMAT_SHIFT;
|
|
45
|
+
const COMPRESSION_FORMAT_ASTC_12x12 = 24 << COMPRESSED_FORMAT_SHIFT;
|
|
46
|
+
*/ const COMPRESSION_FORMAT_BITMASK = 0x1f << COMPRESSED_FORMAT_SHIFT;
|
|
47
|
+
const RED_BITMASK = 1 << RED_SHIFT;
|
|
48
|
+
const GREEN_BITMASK = 1 << GREEN_SHIFT;
|
|
49
|
+
const BLUE_BITMASK = 1 << BLUE_SHIFT;
|
|
50
|
+
const ALPHA_BITMASK = 1 << ALPHA_SHIFT;
|
|
51
|
+
const DEPTH_BITMASK = 1 << DEPTH_SHIFT;
|
|
52
|
+
const STENCIL_BITMASK = 1 << STENCIL_SHIFT;
|
|
53
|
+
const FLOAT_BITMASK = 1 << FLOAT_SHIFT;
|
|
54
|
+
const INTEGER_BITMASK = 1 << INTEGER_SHIFT;
|
|
55
|
+
const SIGNED_BITMASK = 1 << SIGNED_SHIFT;
|
|
56
|
+
const SRGB_BITMASK = 1 << SRGB_SHIFT;
|
|
57
|
+
const BGR_BITMASK = 1 << BGR_SHIFT;
|
|
58
|
+
function makeTextureFormat(compression, r, g, b, a, depth, stencil, float, integer, signed, srgb, bgr, blockWidth, blockHeight, blockSize) {
|
|
59
|
+
const compressionBits = compression;
|
|
60
|
+
const colorBits = (r ? RED_BITMASK : 0) | (g ? GREEN_BITMASK : 0) | (b ? BLUE_BITMASK : 0) | (a ? ALPHA_BITMASK : 0);
|
|
61
|
+
const depthStencilBits = (depth ? DEPTH_BITMASK : 0) | (stencil ? STENCIL_BITMASK : 0);
|
|
62
|
+
const floatBits = float ? FLOAT_BITMASK : 0;
|
|
63
|
+
const integerBits = integer ? INTEGER_BITMASK : 0;
|
|
64
|
+
const signedBits = signed ? SIGNED_BITMASK : 0;
|
|
65
|
+
const srgbBits = srgb ? SRGB_BITMASK : 0;
|
|
66
|
+
const bgrBits = bgr ? BGR_BITMASK : 0;
|
|
67
|
+
const blockBits = blockWidth << BLOCK_WIDTH_SHIFT | blockHeight << BLOCK_HEIGHT_SHIFT | blockSize << BLOCK_SIZE_SHIFT;
|
|
68
|
+
return compressionBits | colorBits | depthStencilBits | floatBits | integerBits | signedBits | srgbBits | bgrBits | blockBits;
|
|
69
|
+
}
|
|
70
|
+
const textureFormatMap = {
|
|
71
|
+
'unknown': 0,
|
|
72
|
+
'r8unorm': makeTextureFormat(0, true, false, false, false, false, false, false, false, false, false, false, 1, 1, 1),
|
|
73
|
+
'r8snorm': makeTextureFormat(0, true, false, false, false, false, false, false, false, true, false, false, 1, 1, 1),
|
|
74
|
+
'r16f': makeTextureFormat(0, true, false, false, false, false, false, true, false, true, false, false, 1, 1, 2),
|
|
75
|
+
'r32f': makeTextureFormat(0, true, false, false, false, false, false, true, false, true, false, false, 1, 1, 4),
|
|
76
|
+
'r8ui': makeTextureFormat(0, true, false, false, false, false, false, false, true, false, false, false, 1, 1, 1),
|
|
77
|
+
'r8i': makeTextureFormat(0, true, false, false, false, false, false, false, true, true, false, false, 1, 1, 1),
|
|
78
|
+
'r16ui': makeTextureFormat(0, true, false, false, false, false, false, false, true, false, false, false, 1, 1, 2),
|
|
79
|
+
'r16i': makeTextureFormat(0, true, false, false, false, false, false, false, true, true, false, false, 1, 1, 2),
|
|
80
|
+
'r32ui': makeTextureFormat(0, true, false, false, false, false, false, false, true, false, false, false, 1, 1, 4),
|
|
81
|
+
'r32i': makeTextureFormat(0, true, false, false, false, false, false, false, true, true, false, false, 1, 1, 4),
|
|
82
|
+
'rg8unorm': makeTextureFormat(0, true, true, false, false, false, false, false, false, false, false, false, 1, 1, 2),
|
|
83
|
+
'rg8snorm': makeTextureFormat(0, true, true, false, false, false, false, false, false, true, false, false, 1, 1, 2),
|
|
84
|
+
'rg16f': makeTextureFormat(0, true, true, false, false, false, false, true, false, true, false, false, 1, 1, 4),
|
|
85
|
+
'rg32f': makeTextureFormat(0, true, true, false, false, false, false, true, false, true, false, false, 1, 1, 8),
|
|
86
|
+
'rg8ui': makeTextureFormat(0, true, true, false, false, false, false, false, true, false, false, false, 1, 1, 2),
|
|
87
|
+
'rg8i': makeTextureFormat(0, true, true, false, false, false, false, false, true, true, false, false, 1, 1, 2),
|
|
88
|
+
'rg16ui': makeTextureFormat(0, true, true, false, false, false, false, false, true, false, false, false, 1, 1, 4),
|
|
89
|
+
'rg16i': makeTextureFormat(0, true, true, false, false, false, false, false, true, true, false, false, 1, 1, 4),
|
|
90
|
+
'rg32ui': makeTextureFormat(0, true, true, false, false, false, false, false, true, false, false, false, 1, 1, 8),
|
|
91
|
+
'rg32i': makeTextureFormat(0, true, true, false, false, false, false, false, true, true, false, false, 1, 1, 8),
|
|
92
|
+
'rgba8unorm': makeTextureFormat(0, true, true, true, true, false, false, false, false, false, false, false, 1, 1, 4),
|
|
93
|
+
'rgba8unorm-srgb': makeTextureFormat(0, true, true, true, true, false, false, false, false, false, true, false, 1, 1, 4),
|
|
94
|
+
'rgba8snorm': makeTextureFormat(0, true, true, true, true, false, false, false, false, true, false, false, 1, 1, 4),
|
|
95
|
+
'bgra8unorm': makeTextureFormat(0, true, true, true, true, false, false, false, false, false, false, true, 1, 1, 4),
|
|
96
|
+
'bgra8unorm-srgb': makeTextureFormat(0, true, true, true, true, false, false, false, false, false, true, true, 1, 1, 4),
|
|
97
|
+
'rgba16f': makeTextureFormat(0, true, true, true, true, false, false, true, false, true, false, false, 1, 1, 8),
|
|
98
|
+
'rgba32f': makeTextureFormat(0, true, true, true, true, false, false, true, false, true, false, false, 1, 1, 16),
|
|
99
|
+
'rgba8ui': makeTextureFormat(0, true, true, true, true, false, false, false, true, false, false, false, 1, 1, 4),
|
|
100
|
+
'rgba8i': makeTextureFormat(0, true, true, true, true, false, false, false, true, true, false, false, 1, 1, 4),
|
|
101
|
+
'rgba16ui': makeTextureFormat(0, true, true, true, true, false, false, false, true, false, false, false, 1, 1, 8),
|
|
102
|
+
'rgba16i': makeTextureFormat(0, true, true, true, true, false, false, false, true, true, false, false, 1, 1, 8),
|
|
103
|
+
'rgba32ui': makeTextureFormat(0, true, true, true, true, false, false, false, true, false, false, false, 1, 1, 16),
|
|
104
|
+
'rgba32i': makeTextureFormat(0, true, true, true, true, false, false, false, true, true, false, false, 1, 1, 16),
|
|
105
|
+
'rg11b10uf': makeTextureFormat(0, true, true, true, false, false, false, true, false, false, false, false, 1, 1, 4),
|
|
106
|
+
'd16': makeTextureFormat(0, false, false, false, false, true, false, false, false, false, false, false, 1, 1, 2),
|
|
107
|
+
'd24': makeTextureFormat(0, false, false, false, false, true, false, false, false, false, false, false, 0, 0, 0),
|
|
108
|
+
'd32f': makeTextureFormat(0, false, false, false, false, true, false, true, false, true, false, false, 1, 1, 4),
|
|
109
|
+
'd24s8': makeTextureFormat(0, false, false, false, false, true, true, false, false, false, false, false, 1, 1, 4),
|
|
110
|
+
'd32fs8': makeTextureFormat(0, false, false, false, false, true, true, true, false, true, false, false, 1, 1, 5),
|
|
111
|
+
// compressed texture formats
|
|
112
|
+
'dxt1': makeTextureFormat(COMPRESSION_FORMAT_BC1, true, true, true, true, false, false, false, false, false, false, false, 4, 4, 8),
|
|
113
|
+
'dxt1-srgb': makeTextureFormat(COMPRESSION_FORMAT_BC1, true, true, true, true, false, false, false, false, false, true, false, 4, 4, 8),
|
|
114
|
+
'dxt3': makeTextureFormat(COMPRESSION_FORMAT_BC2, true, true, true, true, false, false, false, false, false, false, false, 4, 4, 16),
|
|
115
|
+
'dxt3-srgb': makeTextureFormat(COMPRESSION_FORMAT_BC2, true, true, true, true, false, false, false, false, false, true, false, 4, 4, 16),
|
|
116
|
+
'dxt5': makeTextureFormat(COMPRESSION_FORMAT_BC3, true, true, true, true, false, false, false, false, false, false, false, 4, 4, 16),
|
|
117
|
+
'dxt5-srgb': makeTextureFormat(COMPRESSION_FORMAT_BC3, true, true, true, true, false, false, false, false, false, true, false, 4, 4, 16)
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Converts a non-sRGB texture format to the corresponding sRGB texture format
|
|
121
|
+
* @param format - The texture format to be converted
|
|
122
|
+
* @returns The sRGB texture format
|
|
123
|
+
* @public
|
|
124
|
+
*/ function linearTextureFormatToSRGB(format) {
|
|
125
|
+
switch(format){
|
|
126
|
+
case 'rgba8unorm':
|
|
127
|
+
return 'rgba8unorm-srgb';
|
|
128
|
+
case 'bgra8unorm':
|
|
129
|
+
return 'bgra8unorm-srgb';
|
|
130
|
+
case 'dxt1':
|
|
131
|
+
return 'dxt1-srgb';
|
|
132
|
+
case 'dxt3':
|
|
133
|
+
return 'dxt3-srgb';
|
|
134
|
+
case 'dxt5':
|
|
135
|
+
return 'dxt5-srgb';
|
|
136
|
+
default:
|
|
137
|
+
return format;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Check if a given texture format contains an alpha channel.
|
|
142
|
+
* @param format - The texture format to be checked.
|
|
143
|
+
* @returns true if the texture format contains an alpha channel, otherwise false
|
|
144
|
+
* @public
|
|
145
|
+
*/ function hasAlphaChannel(format) {
|
|
146
|
+
return !!(textureFormatMap[format] & ALPHA_BITMASK);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Check if a given texture format contains a red channel.
|
|
150
|
+
* @param format - The texture format to be checked.
|
|
151
|
+
* @returns true if the texture format contains a red channel, otherwise false
|
|
152
|
+
* @public
|
|
153
|
+
*/ function hasRedChannel(format) {
|
|
154
|
+
return !!(textureFormatMap[format] & RED_BITMASK);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Check if a given texture format contains a green channel.
|
|
158
|
+
* @param format - The texture format to be checked.
|
|
159
|
+
* @returns true if the texture format contains a green channel, otherwise false
|
|
160
|
+
* @public
|
|
161
|
+
*/ function hasGreenChannel(format) {
|
|
162
|
+
return !!(textureFormatMap[format] & GREEN_BITMASK);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Check if a given texture format contains a blue channel.
|
|
166
|
+
* @param format - The texture format to be checked.
|
|
167
|
+
* @returns true if the texture format contains a blue channel, otherwise false
|
|
168
|
+
* @public
|
|
169
|
+
*/ function hasBlueChannel(format) {
|
|
170
|
+
return !!(textureFormatMap[format] & BLUE_BITMASK);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Check if a given texture format contains a depth channel.
|
|
174
|
+
* @param format - The texture format to be checked.
|
|
175
|
+
* @returns true if the texture format contains a depth channel, otherwise false
|
|
176
|
+
* @public
|
|
177
|
+
*/ function hasDepthChannel(format) {
|
|
178
|
+
return !!(textureFormatMap[format] & DEPTH_BITMASK);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Check if a given texture format contains a stencil channel.
|
|
182
|
+
* @param format - The texture format to be checked.
|
|
183
|
+
* @returns true if the texture format contains a stencil channel, otherwise false
|
|
184
|
+
* @public
|
|
185
|
+
*/ function hasStencilChannel(format) {
|
|
186
|
+
return !!(textureFormatMap[format] & STENCIL_BITMASK);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Check whether a given texture format is floating-point.
|
|
190
|
+
* @param format - The texture format to be checked.
|
|
191
|
+
* @returns true if the texture format is floating-point, otherwise false
|
|
192
|
+
* @public
|
|
193
|
+
*/ function isFloatTextureFormat(format) {
|
|
194
|
+
return !!(textureFormatMap[format] & FLOAT_BITMASK);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Check whether a given texture format is integer.
|
|
198
|
+
* @param format - The texture format to be checked.
|
|
199
|
+
* @returns true if the texture format is integer, otherwise false
|
|
200
|
+
* @public
|
|
201
|
+
*/ function isIntegerTextureFormat(format) {
|
|
202
|
+
return !!(textureFormatMap[format] & INTEGER_BITMASK);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Check whether a given texture format is signed.
|
|
206
|
+
* @param format - The texture format to be checked.
|
|
207
|
+
* @returns true if the texture format is signed, otherwise false
|
|
208
|
+
* @public
|
|
209
|
+
*/ function isSignedTextureFormat(format) {
|
|
210
|
+
return !!(textureFormatMap[format] & SIGNED_BITMASK);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Check whether a given texture format is a compressed format.
|
|
214
|
+
* @param format - The texture format to be checked.
|
|
215
|
+
* @returns true if the texture format is a compressed format, otherwise false
|
|
216
|
+
* @public
|
|
217
|
+
*/ function isCompressedTextureFormat(format) {
|
|
218
|
+
return !!(textureFormatMap[format] & COMPRESSION_FORMAT_BITMASK);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Check whether a given texture format is sRGB format.
|
|
222
|
+
* @param format - The texture format to be checked.
|
|
223
|
+
* @returns true if the texture format is sRGB format, otherwise false
|
|
224
|
+
* @public
|
|
225
|
+
*/ function isSRGBTextureFormat(format) {
|
|
226
|
+
return !!(textureFormatMap[format] & SRGB_BITMASK);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Get block size of given texture format
|
|
230
|
+
* @param format - The texture format
|
|
231
|
+
* @returns The block size
|
|
232
|
+
* @public
|
|
233
|
+
*/ function getTextureFormatBlockSize(format) {
|
|
234
|
+
return (textureFormatMap[format] & BLOCK_SIZE_MASK) >> BLOCK_SIZE_SHIFT;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get block width of given texture format
|
|
238
|
+
* @param format - The texture format
|
|
239
|
+
* @returns The block width
|
|
240
|
+
* @public
|
|
241
|
+
*/ function getTextureFormatBlockWidth(format) {
|
|
242
|
+
return (textureFormatMap[format] & BLOCK_WIDTH_MASK) >> BLOCK_WIDTH_SHIFT;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Get block height of given texture format
|
|
246
|
+
* @param format - The texture format
|
|
247
|
+
* @returns The block height
|
|
248
|
+
* @public
|
|
249
|
+
*/ function getTextureFormatBlockHeight(format) {
|
|
250
|
+
return (textureFormatMap[format] & BLOCK_HEIGHT_MASK) >> BLOCK_HEIGHT_SHIFT;
|
|
251
|
+
}
|
|
252
|
+
function normalizeColorComponent(val, maxval) {
|
|
253
|
+
return Math.min(maxval, Math.max(Math.floor(val * maxval), 0));
|
|
254
|
+
}
|
|
255
|
+
function normalizeColorComponentSigned(val, maxval) {
|
|
256
|
+
return normalizeColorComponent(val * 0.5 + 0.5, maxval) - (maxval + 1) / 2;
|
|
257
|
+
}
|
|
258
|
+
/** @internal */ function encodePixel(format, r, g, b, a) {
|
|
259
|
+
switch(format){
|
|
260
|
+
case 'r8unorm':
|
|
261
|
+
return new Uint8Array([
|
|
262
|
+
normalizeColorComponent(r, 255)
|
|
263
|
+
]);
|
|
264
|
+
case 'r8snorm':
|
|
265
|
+
return new Int8Array([
|
|
266
|
+
normalizeColorComponentSigned(r, 255)
|
|
267
|
+
]);
|
|
268
|
+
case 'r16f':
|
|
269
|
+
return new Uint16Array([
|
|
270
|
+
floatToHalf(r)
|
|
271
|
+
]);
|
|
272
|
+
case 'r32f':
|
|
273
|
+
return new Float32Array([
|
|
274
|
+
r
|
|
275
|
+
]);
|
|
276
|
+
case 'r8ui':
|
|
277
|
+
return new Uint8Array([
|
|
278
|
+
r | 0
|
|
279
|
+
]);
|
|
280
|
+
case 'r8i':
|
|
281
|
+
return new Int8Array([
|
|
282
|
+
r | 0
|
|
283
|
+
]);
|
|
284
|
+
case 'r16ui':
|
|
285
|
+
return new Uint16Array([
|
|
286
|
+
r | 0
|
|
287
|
+
]);
|
|
288
|
+
case 'r16i':
|
|
289
|
+
return new Int16Array([
|
|
290
|
+
r | 0
|
|
291
|
+
]);
|
|
292
|
+
case 'r32ui':
|
|
293
|
+
return new Uint32Array([
|
|
294
|
+
r | 0
|
|
295
|
+
]);
|
|
296
|
+
case 'r32i':
|
|
297
|
+
return new Int32Array([
|
|
298
|
+
r | 0
|
|
299
|
+
]);
|
|
300
|
+
case 'rg8unorm':
|
|
301
|
+
return new Uint8Array([
|
|
302
|
+
normalizeColorComponent(r, 255),
|
|
303
|
+
normalizeColorComponent(g, 255)
|
|
304
|
+
]);
|
|
305
|
+
case 'rg8snorm':
|
|
306
|
+
return new Int8Array([
|
|
307
|
+
normalizeColorComponentSigned(r, 255),
|
|
308
|
+
normalizeColorComponentSigned(g, 255)
|
|
309
|
+
]);
|
|
310
|
+
case 'rg16f':
|
|
311
|
+
return new Uint16Array([
|
|
312
|
+
floatToHalf(r),
|
|
313
|
+
floatToHalf(g)
|
|
314
|
+
]);
|
|
315
|
+
case 'rg32f':
|
|
316
|
+
return new Float32Array([
|
|
317
|
+
r,
|
|
318
|
+
g
|
|
319
|
+
]);
|
|
320
|
+
case 'rg8ui':
|
|
321
|
+
return new Uint8Array([
|
|
322
|
+
r | 0,
|
|
323
|
+
g | 0
|
|
324
|
+
]);
|
|
325
|
+
case 'rg8i':
|
|
326
|
+
return new Int8Array([
|
|
327
|
+
r | 0,
|
|
328
|
+
g | 0
|
|
329
|
+
]);
|
|
330
|
+
case 'rg16ui':
|
|
331
|
+
return new Uint16Array([
|
|
332
|
+
r | 0,
|
|
333
|
+
g | 0
|
|
334
|
+
]);
|
|
335
|
+
case 'rg16i':
|
|
336
|
+
return new Int16Array([
|
|
337
|
+
r | 0,
|
|
338
|
+
g | 0
|
|
339
|
+
]);
|
|
340
|
+
case 'rg32ui':
|
|
341
|
+
return new Uint32Array([
|
|
342
|
+
r | 0,
|
|
343
|
+
g | 0
|
|
344
|
+
]);
|
|
345
|
+
case 'rg32i':
|
|
346
|
+
return new Int32Array([
|
|
347
|
+
r | 0,
|
|
348
|
+
g | 0
|
|
349
|
+
]);
|
|
350
|
+
case 'rgba8unorm':
|
|
351
|
+
case 'rgba8unorm-srgb':
|
|
352
|
+
return new Uint8Array([
|
|
353
|
+
normalizeColorComponent(r, 255),
|
|
354
|
+
normalizeColorComponent(g, 255),
|
|
355
|
+
normalizeColorComponent(b, 255),
|
|
356
|
+
normalizeColorComponent(a, 255)
|
|
357
|
+
]);
|
|
358
|
+
case 'bgra8unorm':
|
|
359
|
+
case 'bgra8unorm-srgb':
|
|
360
|
+
return new Uint8Array([
|
|
361
|
+
normalizeColorComponent(b, 255),
|
|
362
|
+
normalizeColorComponent(g, 255),
|
|
363
|
+
normalizeColorComponent(r, 255),
|
|
364
|
+
normalizeColorComponent(a, 255)
|
|
365
|
+
]);
|
|
366
|
+
case 'rgba8snorm':
|
|
367
|
+
return new Int8Array([
|
|
368
|
+
normalizeColorComponentSigned(r, 255),
|
|
369
|
+
normalizeColorComponentSigned(g, 255),
|
|
370
|
+
normalizeColorComponentSigned(b, 255),
|
|
371
|
+
normalizeColorComponentSigned(a, 255)
|
|
372
|
+
]);
|
|
373
|
+
case 'rgba16f':
|
|
374
|
+
return new Uint16Array([
|
|
375
|
+
floatToHalf(r),
|
|
376
|
+
floatToHalf(g),
|
|
377
|
+
floatToHalf(b),
|
|
378
|
+
floatToHalf(a)
|
|
379
|
+
]);
|
|
380
|
+
case 'rgba32f':
|
|
381
|
+
return new Float32Array([
|
|
382
|
+
r,
|
|
383
|
+
g,
|
|
384
|
+
b,
|
|
385
|
+
a
|
|
386
|
+
]);
|
|
387
|
+
case 'rgba8ui':
|
|
388
|
+
return new Uint8Array([
|
|
389
|
+
r | 0,
|
|
390
|
+
g | 0,
|
|
391
|
+
b | 0,
|
|
392
|
+
a | 0
|
|
393
|
+
]);
|
|
394
|
+
case 'rgba8i':
|
|
395
|
+
return new Int8Array([
|
|
396
|
+
r | 0,
|
|
397
|
+
g | 0,
|
|
398
|
+
b | 0,
|
|
399
|
+
a | 0
|
|
400
|
+
]);
|
|
401
|
+
case 'rgba16ui':
|
|
402
|
+
return new Uint16Array([
|
|
403
|
+
r | 0,
|
|
404
|
+
g | 0,
|
|
405
|
+
b | 0,
|
|
406
|
+
a | 0
|
|
407
|
+
]);
|
|
408
|
+
case 'rgba16i':
|
|
409
|
+
return new Int16Array([
|
|
410
|
+
r | 0,
|
|
411
|
+
g | 0,
|
|
412
|
+
b | 0,
|
|
413
|
+
a | 0
|
|
414
|
+
]);
|
|
415
|
+
case 'rgba32ui':
|
|
416
|
+
return new Uint32Array([
|
|
417
|
+
r | 0,
|
|
418
|
+
g | 0,
|
|
419
|
+
b | 0,
|
|
420
|
+
a | 0
|
|
421
|
+
]);
|
|
422
|
+
case 'rgba32i':
|
|
423
|
+
return new Int32Array([
|
|
424
|
+
r | 0,
|
|
425
|
+
g | 0,
|
|
426
|
+
b | 0,
|
|
427
|
+
a | 0
|
|
428
|
+
]);
|
|
429
|
+
default:
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/** @internal */ function encodePixelToArray(format, r, g, b, a, arr) {
|
|
434
|
+
switch(format){
|
|
435
|
+
case 'r8unorm':
|
|
436
|
+
arr.push(normalizeColorComponent(r, 255));
|
|
437
|
+
break;
|
|
438
|
+
case 'r8snorm':
|
|
439
|
+
arr.push(normalizeColorComponentSigned(r, 255));
|
|
440
|
+
break;
|
|
441
|
+
case 'r16f':
|
|
442
|
+
arr.push(floatToHalf(r));
|
|
443
|
+
break;
|
|
444
|
+
case 'r32f':
|
|
445
|
+
arr.push(r);
|
|
446
|
+
break;
|
|
447
|
+
case 'r8ui':
|
|
448
|
+
arr.push(r | 0);
|
|
449
|
+
break;
|
|
450
|
+
case 'r8i':
|
|
451
|
+
arr.push(r | 0);
|
|
452
|
+
break;
|
|
453
|
+
case 'r16ui':
|
|
454
|
+
arr.push(r | 0);
|
|
455
|
+
break;
|
|
456
|
+
case 'r16i':
|
|
457
|
+
arr.push(r | 0);
|
|
458
|
+
break;
|
|
459
|
+
case 'r32ui':
|
|
460
|
+
arr.push(r | 0);
|
|
461
|
+
break;
|
|
462
|
+
case 'r32i':
|
|
463
|
+
arr.push(r | 0);
|
|
464
|
+
break;
|
|
465
|
+
case 'rg8unorm':
|
|
466
|
+
arr.push(normalizeColorComponent(r, 255), normalizeColorComponent(g, 255));
|
|
467
|
+
break;
|
|
468
|
+
case 'rg8snorm':
|
|
469
|
+
arr.push(normalizeColorComponentSigned(r, 255), normalizeColorComponentSigned(g, 255));
|
|
470
|
+
break;
|
|
471
|
+
case 'rg16f':
|
|
472
|
+
arr.push(floatToHalf(r), floatToHalf(g));
|
|
473
|
+
break;
|
|
474
|
+
case 'rg32f':
|
|
475
|
+
arr.push(r, g);
|
|
476
|
+
break;
|
|
477
|
+
case 'rg8ui':
|
|
478
|
+
arr.push(r | 0, g | 0);
|
|
479
|
+
break;
|
|
480
|
+
case 'rg8i':
|
|
481
|
+
arr.push(r | 0, g | 0);
|
|
482
|
+
break;
|
|
483
|
+
case 'rg16ui':
|
|
484
|
+
arr.push(r | 0, g | 0);
|
|
485
|
+
break;
|
|
486
|
+
case 'rg16i':
|
|
487
|
+
arr.push(r | 0, g | 0);
|
|
488
|
+
break;
|
|
489
|
+
case 'rg32ui':
|
|
490
|
+
arr.push(r | 0, g | 0);
|
|
491
|
+
break;
|
|
492
|
+
case 'rg32i':
|
|
493
|
+
arr.push(r | 0, g | 0);
|
|
494
|
+
break;
|
|
495
|
+
case 'rgba8unorm':
|
|
496
|
+
case 'rgba8unorm-srgb':
|
|
497
|
+
arr.push(normalizeColorComponent(r, 255), normalizeColorComponent(g, 255), normalizeColorComponent(b, 255), normalizeColorComponent(a, 255));
|
|
498
|
+
break;
|
|
499
|
+
case 'bgra8unorm':
|
|
500
|
+
case 'bgra8unorm-srgb':
|
|
501
|
+
arr.push(normalizeColorComponent(b, 255), normalizeColorComponent(g, 255), normalizeColorComponent(r, 255), normalizeColorComponent(a, 255));
|
|
502
|
+
break;
|
|
503
|
+
case 'rgba8snorm':
|
|
504
|
+
arr.push(normalizeColorComponentSigned(r, 255), normalizeColorComponentSigned(g, 255), normalizeColorComponentSigned(b, 255), normalizeColorComponentSigned(a, 255));
|
|
505
|
+
break;
|
|
506
|
+
case 'rgba16f':
|
|
507
|
+
arr.push(floatToHalf(r), floatToHalf(g), floatToHalf(b), floatToHalf(a));
|
|
508
|
+
break;
|
|
509
|
+
case 'rgba32f':
|
|
510
|
+
arr.push(r, g, b, a);
|
|
511
|
+
break;
|
|
512
|
+
case 'rgba8ui':
|
|
513
|
+
arr.push(r | 0, g | 0, b | 0, a | 0);
|
|
514
|
+
break;
|
|
515
|
+
case 'rgba8i':
|
|
516
|
+
arr.push(r | 0, g | 0, b | 0, a | 0);
|
|
517
|
+
break;
|
|
518
|
+
case 'rgba16ui':
|
|
519
|
+
arr.push(r | 0, g | 0, b | 0, a | 0);
|
|
520
|
+
break;
|
|
521
|
+
case 'rgba16i':
|
|
522
|
+
arr.push(r | 0, g | 0, b | 0, a | 0);
|
|
523
|
+
break;
|
|
524
|
+
case 'rgba32ui':
|
|
525
|
+
arr.push(r | 0, g | 0, b | 0, a | 0);
|
|
526
|
+
break;
|
|
527
|
+
case 'rgba32i':
|
|
528
|
+
arr.push(r | 0, g | 0, b | 0, a | 0);
|
|
529
|
+
break;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
var ShaderType;
|
|
533
|
+
(function(ShaderType) {
|
|
534
|
+
ShaderType[ShaderType["Vertex"] = 1] = "Vertex";
|
|
535
|
+
ShaderType[ShaderType["Fragment"] = 2] = "Fragment";
|
|
536
|
+
ShaderType[ShaderType["Compute"] = 4] = "Compute";
|
|
537
|
+
})(ShaderType || (ShaderType = {}));
|
|
538
|
+
/**
|
|
539
|
+
* Event that will be fired when device is lost
|
|
540
|
+
* @public
|
|
541
|
+
*/ class DeviceLostEvent {
|
|
542
|
+
/** The event name */ static NAME = 'devicelost';
|
|
543
|
+
type = DeviceLostEvent.NAME;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Event that will be fired when device has just been restored
|
|
547
|
+
* @public
|
|
548
|
+
*/ class DeviceRestoreEvent {
|
|
549
|
+
/** The event name */ static NAME = 'devicerestored';
|
|
550
|
+
type = DeviceRestoreEvent.NAME;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Event that will be fired when size of back buffer has changed
|
|
554
|
+
* @public
|
|
555
|
+
*/ class DeviceResizeEvent {
|
|
556
|
+
/** The event name */ static NAME = 'resize';
|
|
557
|
+
width;
|
|
558
|
+
height;
|
|
559
|
+
type = DeviceResizeEvent.NAME;
|
|
560
|
+
constructor(width, height){
|
|
561
|
+
this.width = width;
|
|
562
|
+
this.height = height;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Event that will be fired when any gpu object is created
|
|
567
|
+
* @public
|
|
568
|
+
*/ class DeviceGPUObjectAddedEvent {
|
|
569
|
+
/** the event name */ static NAME = 'gpuobject_added';
|
|
570
|
+
object;
|
|
571
|
+
type = DeviceGPUObjectAddedEvent.NAME;
|
|
572
|
+
constructor(obj){
|
|
573
|
+
this.object = obj;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Event that will be fired when any gpu object is disposed
|
|
578
|
+
* @public
|
|
579
|
+
*/ class DeviceGPUObjectRemovedEvent {
|
|
580
|
+
/** The event name */ static NAME = 'gpuobject_removed';
|
|
581
|
+
object;
|
|
582
|
+
type = DeviceGPUObjectRemovedEvent.NAME;
|
|
583
|
+
constructor(obj){
|
|
584
|
+
this.object = obj;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Event that will be fired when any gpu object name is changed
|
|
589
|
+
* @public
|
|
590
|
+
*/ class DeviceGPUObjectRenameEvent {
|
|
591
|
+
/** The event name */ static NAME = 'gpuobject_rename';
|
|
592
|
+
object;
|
|
593
|
+
lastName;
|
|
594
|
+
type = DeviceGPUObjectRenameEvent.NAME;
|
|
595
|
+
constructor(obj, lastName){
|
|
596
|
+
this.object = obj;
|
|
597
|
+
this.lastName = lastName;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
export { DeviceGPUObjectAddedEvent, DeviceGPUObjectRemovedEvent, DeviceGPUObjectRenameEvent, DeviceLostEvent, DeviceResizeEvent, DeviceRestoreEvent, ShaderType, encodePixel, encodePixelToArray, getTextureFormatBlockHeight, getTextureFormatBlockSize, getTextureFormatBlockWidth, hasAlphaChannel, hasBlueChannel, hasDepthChannel, hasGreenChannel, hasRedChannel, hasStencilChannel, isCompressedTextureFormat, isFloatTextureFormat, isIntegerTextureFormat, isSRGBTextureFormat, isSignedTextureFormat, linearTextureFormatToSRGB };
|
|
602
|
+
//# sourceMappingURL=base_types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base_types.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|