@luma.gl/webgl 9.1.0-alpha.15 → 9.1.0-alpha.17
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/device-parameters.d.ts +3 -3
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/sampler-parameters.js +6 -4
- package/dist/adapter/converters/texture-formats.d.ts +49 -11
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +150 -160
- package/dist/adapter/helpers/format-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/format-utils.js +6 -0
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +34 -30
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.js +52 -256
- package/dist/adapter/resources/webgl-command-buffer.d.ts +59 -2
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +87 -31
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js +3 -0
- package/dist/adapter/resources/webgl-external-texture.js +14 -0
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +1 -2
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +38 -20
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +30 -16
- package/dist/adapter/resources/webgl-shader.d.ts +1 -0
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +7 -5
- package/dist/adapter/resources/webgl-texture.d.ts +8 -14
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +119 -208
- package/dist/adapter/webgl-adapter.d.ts.map +1 -1
- package/dist/adapter/webgl-adapter.js +4 -10
- package/dist/adapter/webgl-device.d.ts +8 -3
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +53 -22
- package/dist/context/debug/spector-types.js +1 -1
- package/dist/context/debug/spector.d.ts +5 -5
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +6 -6
- package/dist/context/debug/webgl-developer-tools.d.ts +2 -3
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +6 -19
- package/dist/context/helpers/create-browser-context.d.ts +6 -22
- package/dist/context/helpers/create-browser-context.d.ts.map +1 -1
- package/dist/context/helpers/create-browser-context.js +40 -32
- package/dist/dist.dev.js +366 -400
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +341 -384
- package/dist/index.cjs.map +3 -3
- package/package.json +4 -4
- package/src/adapter/converters/device-parameters.ts +3 -3
- package/src/adapter/converters/sampler-parameters.ts +6 -4
- package/src/adapter/converters/texture-formats.ts +171 -177
- package/src/adapter/helpers/format-utils.ts +6 -0
- package/src/adapter/helpers/webgl-texture-utils.ts +99 -75
- package/src/adapter/resources/webgl-command-buffer.ts +124 -40
- package/src/adapter/resources/webgl-command-encoder.ts +6 -0
- package/src/adapter/resources/webgl-external-texture.ts +14 -0
- package/src/adapter/resources/webgl-framebuffer.ts +1 -2
- package/src/adapter/resources/webgl-render-pass.ts +44 -23
- package/src/adapter/resources/webgl-render-pipeline.ts +32 -16
- package/src/adapter/resources/webgl-shader.ts +8 -6
- package/src/adapter/resources/webgl-texture.ts +126 -235
- package/src/adapter/webgl-adapter.ts +4 -12
- package/src/adapter/webgl-device.ts +88 -48
- package/src/context/debug/spector-types.ts +1 -1
- package/src/context/debug/spector.ts +11 -11
- package/src/context/debug/webgl-developer-tools.ts +8 -31
- package/src/context/helpers/create-browser-context.ts +53 -63
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/webgl",
|
|
3
|
-
"version": "9.1.0-alpha.
|
|
3
|
+
"version": "9.1.0-alpha.17",
|
|
4
4
|
"description": "WebGL2 adapter for the luma.gl core API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@luma.gl/core": "9.1.0-alpha.
|
|
43
|
+
"@luma.gl/core": "9.1.0-alpha.16"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@luma.gl/constants": "9.1.0-alpha.
|
|
46
|
+
"@luma.gl/constants": "9.1.0-alpha.17",
|
|
47
47
|
"@math.gl/types": "4.1.0-alpha.3",
|
|
48
48
|
"@probe.gl/env": "^4.0.8"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "a0d4d3ddc549bbfae6e43eebc8e1afdc4da1693c"
|
|
51
51
|
}
|
|
@@ -31,7 +31,7 @@ export function withDeviceAndGLParameters<T = unknown>(
|
|
|
31
31
|
device: Device,
|
|
32
32
|
parameters: Parameters,
|
|
33
33
|
glParameters: GLParameters,
|
|
34
|
-
func: (
|
|
34
|
+
func: (_?: Device) => T
|
|
35
35
|
): T {
|
|
36
36
|
if (isObjectEmpty(parameters)) {
|
|
37
37
|
// Avoid setting state if no parameters provided. Just call and return
|
|
@@ -62,7 +62,7 @@ export function withDeviceAndGLParameters<T = unknown>(
|
|
|
62
62
|
export function withGLParameters<T = unknown>(
|
|
63
63
|
device: Device,
|
|
64
64
|
parameters: GLParameters,
|
|
65
|
-
func: (
|
|
65
|
+
func: (_?: Device) => T
|
|
66
66
|
): T {
|
|
67
67
|
if (isObjectEmpty(parameters)) {
|
|
68
68
|
// Avoid setting state if no parameters provided. Just call and return
|
|
@@ -91,7 +91,7 @@ export function withGLParameters<T = unknown>(
|
|
|
91
91
|
export function withDeviceParameters<T = unknown>(
|
|
92
92
|
device: Device,
|
|
93
93
|
parameters: Parameters,
|
|
94
|
-
func: (
|
|
94
|
+
func: (_?: Device) => T
|
|
95
95
|
): T {
|
|
96
96
|
if (isObjectEmpty(parameters)) {
|
|
97
97
|
// Avoid setting state if no parameters provided. Just call and return
|
|
@@ -84,7 +84,7 @@ function convertMaxFilterMode(maxFilter: 'nearest' | 'linear'): GL.NEAREST | GL.
|
|
|
84
84
|
*/
|
|
85
85
|
function convertMinFilterMode(
|
|
86
86
|
minFilter: 'nearest' | 'linear',
|
|
87
|
-
mipmapFilter
|
|
87
|
+
mipmapFilter: 'none' | 'nearest' | 'linear' = 'none'
|
|
88
88
|
):
|
|
89
89
|
| GL.NEAREST
|
|
90
90
|
| GL.LINEAR
|
|
@@ -95,10 +95,12 @@ function convertMinFilterMode(
|
|
|
95
95
|
if (!mipmapFilter) {
|
|
96
96
|
return convertMaxFilterMode(minFilter);
|
|
97
97
|
}
|
|
98
|
-
switch (
|
|
98
|
+
switch (mipmapFilter) {
|
|
99
|
+
case 'none':
|
|
100
|
+
return convertMaxFilterMode(minFilter);
|
|
99
101
|
case 'nearest':
|
|
100
|
-
return
|
|
102
|
+
return minFilter === 'nearest' ? GL.NEAREST_MIPMAP_NEAREST : GL.NEAREST_MIPMAP_LINEAR;
|
|
101
103
|
case 'linear':
|
|
102
|
-
return
|
|
104
|
+
return minFilter === 'nearest' ? GL.LINEAR_MIPMAP_NEAREST : GL.LINEAR_MIPMAP_LINEAR;
|
|
103
105
|
}
|
|
104
106
|
}
|
|
@@ -73,15 +73,6 @@ export const TEXTURE_FEATURES: Partial<Record<DeviceFeature, string[]>> = {
|
|
|
73
73
|
'texture-compression-atc-webgl': [X_ATC]
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
/** Return a list of texture feature strings (for Device.features). Mainly compressed texture support */
|
|
77
|
-
// export function getTextureFeatures(
|
|
78
|
-
// gl: WebGL2RenderingContext,
|
|
79
|
-
// extensions: GLExtensions
|
|
80
|
-
// ): DeviceFeature[] {
|
|
81
|
-
// const textureFeatures = Object.keys(TEXTURE_FEATURES) as DeviceFeature[];
|
|
82
|
-
// return textureFeatures.filter(feature => checkTextureFeature(gl, feature, extensions));
|
|
83
|
-
// }
|
|
84
|
-
|
|
85
76
|
export function isTextureFeature(feature: DeviceFeature): boolean {
|
|
86
77
|
return feature in TEXTURE_FEATURES;
|
|
87
78
|
}
|
|
@@ -115,10 +106,10 @@ type Format = {
|
|
|
115
106
|
x?: string;
|
|
116
107
|
/** for compressed texture formats */
|
|
117
108
|
f?: DeviceFeature;
|
|
118
|
-
/** renderable if feature is present */
|
|
119
|
-
render?: DeviceFeature;
|
|
120
|
-
/** filterable if feature is present */
|
|
121
|
-
filter?: DeviceFeature;
|
|
109
|
+
/** renderable if feature is present. false means the spec does not support this format */
|
|
110
|
+
render?: DeviceFeature | false;
|
|
111
|
+
/** filterable if feature is present. false means the spec does not support this format */
|
|
112
|
+
filter?: DeviceFeature | false;
|
|
122
113
|
|
|
123
114
|
/** If not supported on WebGPU */
|
|
124
115
|
wgpu?: false;
|
|
@@ -201,7 +192,7 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
|
|
|
201
192
|
// 64-bit formats
|
|
202
193
|
'rg32uint': {gl: GL.RG32UI, b: 8, c: 2, rb: true},
|
|
203
194
|
'rg32sint': {gl: GL.RG32I, b: 8, c: 2, rb: true},
|
|
204
|
-
'rg32float': {gl: GL.RG32F, b: 8, c: 2, render:
|
|
195
|
+
'rg32float': {gl: GL.RG32F, b: 8, c: 2, render: false, filter: float32_filterable, rb: true},
|
|
205
196
|
'rgba16uint': {gl: GL.RGBA16UI, b: 8, c: 4, rb: true},
|
|
206
197
|
'rgba16sint': {gl: GL.RGBA16I, b: 8, c: 4, rb: true},
|
|
207
198
|
'rgba16float': {gl: GL.RGBA16F, b: 8, c: 4, render: float16_renderable, filter: float16_filterable},
|
|
@@ -318,100 +309,6 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
|
|
|
318
309
|
'atc-rgbai-unorm-webgl': {gl: GL.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL, f: texture_compression_atc_webgl}
|
|
319
310
|
};
|
|
320
311
|
|
|
321
|
-
/** Legal combinations for internalFormat, format and type *
|
|
322
|
-
// [GL.DEPTH_COMPONENT]: {types: [GL.UNSIGNED_SHORT, GL.UNSIGNED_INT, GL.UNSIGNED_INT_24_8]},
|
|
323
|
-
// [GL.DEPTH_STENCIL]: ,
|
|
324
|
-
// Sized texture format
|
|
325
|
-
// R
|
|
326
|
-
[GL.R8]: {dataFormat: GL.RED, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
327
|
-
[GL.R16F]: {dataFormat: GL.RED, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
328
|
-
[GL.R8UI]: {dataFormat: GL.RED_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
329
|
-
// // RG
|
|
330
|
-
[GL.RG8]: {dataFormat: GL.RG, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
331
|
-
[GL.RG16F]: {dataFormat: GL.RG, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
332
|
-
[GL.RG8UI]: {dataFormat: GL.RG_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
333
|
-
// // RGB
|
|
334
|
-
[GL.RGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
335
|
-
[GL.SRGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
336
|
-
[GL.RGB16F]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
337
|
-
[GL.RGB8UI]: {dataFormat: GL.RGB_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
338
|
-
// // RGBA
|
|
339
|
-
|
|
340
|
-
[GL.RGB565]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5], gl2: true},
|
|
341
|
-
[GL.R11F_G11F_B10F]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_INT_10F_11F_11F_REV, GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
342
|
-
[GL.RGB9_E5]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
343
|
-
[GL.RGBA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
344
|
-
[GL.SRGB8_ALPHA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true, gl1ext: EXT_SRGB},
|
|
345
|
-
[GL.RGB5_A1]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_5_5_1], gl2: true},
|
|
346
|
-
[GL.RGBA4]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4], gl2: true},
|
|
347
|
-
[GL.RGBA16F]: {dataFormat: GL.RGBA, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
348
|
-
[GL.RGBA8UI]: {dataFormat: GL.RGBA_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true}
|
|
349
|
-
*/
|
|
350
|
-
|
|
351
|
-
/* This table is now baked into the above table
|
|
352
|
-
type RenderbufferFormat = {
|
|
353
|
-
bpp: number;
|
|
354
|
-
gl2?: boolean;
|
|
355
|
-
ext?: string;
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
export const RENDERBUFFER_FORMATS: Record<string, RenderbufferFormat> = {
|
|
359
|
-
[GL.DEPTH_COMPONENT16]: {bpp: 2}, // 16 depth bits.
|
|
360
|
-
// TODO - Not clear which webgpu value to map this to.
|
|
361
|
-
// [GL.DEPTH_COMPONENT24]: {gl2: true, bpp: 3},
|
|
362
|
-
[GL.DEPTH_COMPONENT32F]: {gl2: true, bpp: 4},
|
|
363
|
-
|
|
364
|
-
[GL.STENCIL_INDEX8]: {bpp: 1}, // 8 stencil bits.
|
|
365
|
-
|
|
366
|
-
[GL.DEPTH_STENCIL]: {bpp: 4},
|
|
367
|
-
[GL.DEPTH24_STENCIL8]: {gl2: true, bpp: 4},
|
|
368
|
-
[GL.DEPTH32F_STENCIL8]: {gl2: true, bpp: 5},
|
|
369
|
-
|
|
370
|
-
// When using a WebGL 1 context, color renderbuffer formats are limited
|
|
371
|
-
[GL.RGBA4]: {gl2: true, bpp: 2},
|
|
372
|
-
[GL.RGB565]: {gl2: true, bpp: 2},
|
|
373
|
-
[GL.RGB5_A1]: {gl2: true, bpp: 2},
|
|
374
|
-
|
|
375
|
-
// When using a WebGL 2 context, the following values are available additionally:
|
|
376
|
-
[GL.R8]: {gl2: true, bpp: 1},
|
|
377
|
-
[GL.R8UI]: {gl2: true, bpp: 1},
|
|
378
|
-
[GL.R8I]: {gl2: true, bpp: 1},
|
|
379
|
-
[GL.R16UI]: {gl2: true, bpp: 2},
|
|
380
|
-
[GL.R16I]: {gl2: true, bpp: 2},
|
|
381
|
-
[GL.R32UI]: {gl2: true, bpp: 4},
|
|
382
|
-
[GL.R32I]: {gl2: true, bpp: 4},
|
|
383
|
-
[GL.RG8]: {gl2: true, bpp: 2},
|
|
384
|
-
[GL.RG8UI]: {gl2: true, bpp: 2},
|
|
385
|
-
[GL.RG8I]: {gl2: true, bpp: 2},
|
|
386
|
-
[GL.RG16UI]: {gl2: true, bpp: 4},
|
|
387
|
-
[GL.RG16I]: {gl2: true, bpp: 4},
|
|
388
|
-
[GL.RG32UI]: {gl2: true, bpp: 8},
|
|
389
|
-
[GL.RG32I]: {gl2: true, bpp: 8},
|
|
390
|
-
[GL.RGB8]: {gl2: true, bpp: 3},
|
|
391
|
-
[GL.RGBA8]: {gl2: true, bpp: 4},
|
|
392
|
-
// [GL.SRGB8_ALPHA8]: {gl2: true, gl1: SRGB}, // When using the EXT_sRGB WebGL1 extension
|
|
393
|
-
[GL.RGB10_A2]: {gl2: true, bpp: 4},
|
|
394
|
-
[GL.RGBA8UI]: {gl2: true, bpp: 4},
|
|
395
|
-
[GL.RGBA8I]: {gl2: true, bpp: 4},
|
|
396
|
-
[GL.RGB10_A2UI]: {gl2: true, bpp: 4},
|
|
397
|
-
[GL.RGBA16UI]: {gl2: true, bpp: 8},
|
|
398
|
-
[GL.RGBA16I]: {gl2: true, bpp: 8},
|
|
399
|
-
[GL.RGBA32I]: {gl2: true, bpp: 16},
|
|
400
|
-
[GL.RGBA32UI]: {gl2: true, bpp: 16},
|
|
401
|
-
|
|
402
|
-
// When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
|
|
403
|
-
[GL.R16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 2},
|
|
404
|
-
[GL.RG16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4},
|
|
405
|
-
[GL.RGBA16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
|
|
406
|
-
[GL.R32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4},
|
|
407
|
-
[GL.RG32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
|
|
408
|
-
// TODO - can't get WEBGL_color_buffer_float to work on renderbuffers
|
|
409
|
-
[GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 16},
|
|
410
|
-
// [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2},
|
|
411
|
-
[GL.R11F_G11F_B10F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4}
|
|
412
|
-
};
|
|
413
|
-
*/
|
|
414
|
-
|
|
415
312
|
/** @deprecated should be removed */
|
|
416
313
|
const DATA_FORMAT_CHANNELS = {
|
|
417
314
|
[GL.RED]: 1,
|
|
@@ -469,17 +366,25 @@ export function isTextureFormatSupported(
|
|
|
469
366
|
return true;
|
|
470
367
|
}
|
|
471
368
|
|
|
472
|
-
|
|
369
|
+
/** Checks whether linear filtering (interpolated sampling) is available for floating point textures */
|
|
370
|
+
export function isTextureFormatFilterable(
|
|
473
371
|
gl: WebGL2RenderingContext,
|
|
474
372
|
format: TextureFormat,
|
|
475
373
|
extensions: GLExtensions
|
|
476
374
|
): boolean {
|
|
477
|
-
|
|
478
|
-
return isTextureFormatSupported(gl, format, extensions) && Boolean(TEXTURE_FORMATS[format]?.rb);
|
|
375
|
+
return getTextureFormatSupportWebGL(gl, format, extensions).filterable || false;
|
|
479
376
|
}
|
|
480
377
|
|
|
481
|
-
|
|
482
|
-
|
|
378
|
+
export function isTextureFormatRenderable(
|
|
379
|
+
gl: WebGL2RenderingContext,
|
|
380
|
+
format: TextureFormat,
|
|
381
|
+
extensions: GLExtensions
|
|
382
|
+
): boolean {
|
|
383
|
+
return getTextureFormatSupportWebGL(gl, format, extensions).renderable || false;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** Checks if a texture format is supported, renderable, filterable etc */
|
|
387
|
+
export function getTextureFormatSupportWebGL(
|
|
483
388
|
gl: WebGL2RenderingContext,
|
|
484
389
|
format: TextureFormat,
|
|
485
390
|
extensions: GLExtensions
|
|
@@ -490,80 +395,52 @@ export function getTextureFormatSupport(
|
|
|
490
395
|
blendable?: boolean;
|
|
491
396
|
storable?: boolean;
|
|
492
397
|
} {
|
|
493
|
-
const
|
|
494
|
-
if (!
|
|
398
|
+
const formatInto = decodeTextureFormat(format);
|
|
399
|
+
if (!formatInto) {
|
|
495
400
|
return {supported: false};
|
|
496
401
|
}
|
|
497
|
-
// let decoded;
|
|
498
|
-
// try {
|
|
499
|
-
// decoded = decodeTextureFormat(format);
|
|
500
|
-
// } catch {}
|
|
501
402
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
403
|
+
const webglFormatInfo = TEXTURE_FORMATS[format];
|
|
404
|
+
if (!webglFormatInfo) {
|
|
405
|
+
return {supported: false};
|
|
406
|
+
}
|
|
505
407
|
|
|
506
|
-
//
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
408
|
+
// Support Check that we have a GL constant
|
|
409
|
+
let supported = webglFormatInfo.gl !== undefined;
|
|
410
|
+
supported = supported && checkTextureFeature(gl, webglFormatInfo.f, extensions);
|
|
411
|
+
|
|
412
|
+
const isDepthStencil = format.startsWith('depth') || format.startsWith('stencil');
|
|
413
|
+
const isSigned = formatInto?.signed;
|
|
414
|
+
|
|
415
|
+
const renderable =
|
|
416
|
+
supported &&
|
|
417
|
+
!isSigned &&
|
|
418
|
+
webglFormatInfo.render &&
|
|
419
|
+
checkTextureFeature(gl, webglFormatInfo.render, extensions);
|
|
420
|
+
|
|
421
|
+
const filterable =
|
|
422
|
+
supported &&
|
|
423
|
+
!isDepthStencil &&
|
|
424
|
+
!isSigned &&
|
|
425
|
+
webglFormatInfo.filter &&
|
|
426
|
+
checkTextureFeature(gl, webglFormatInfo.filter, extensions);
|
|
427
|
+
|
|
428
|
+
// if (format.endsWith('32float')) {
|
|
429
|
+
// return Boolean(getWebGLExtension(gl, 'OES_texture_float_linear, extensions', extensions));
|
|
430
|
+
// }
|
|
431
|
+
// if (format.endsWith('16float')) {
|
|
432
|
+
// return Boolean(getWebGLExtension(gl, 'OES_texture_half_float_linear, extensions', extensions));
|
|
433
|
+
// }
|
|
513
434
|
|
|
514
435
|
return {
|
|
515
436
|
supported,
|
|
516
|
-
renderable
|
|
517
|
-
filterable
|
|
518
|
-
blendable: false, //
|
|
519
|
-
storable: false
|
|
437
|
+
renderable,
|
|
438
|
+
filterable,
|
|
439
|
+
blendable: false, // TODO,
|
|
440
|
+
storable: false // TODO
|
|
520
441
|
};
|
|
521
442
|
}
|
|
522
443
|
|
|
523
|
-
/** Checks whether linear filtering (interpolated sampling) is available for floating point textures */
|
|
524
|
-
export function isTextureFormatFilterable(
|
|
525
|
-
gl: WebGL2RenderingContext,
|
|
526
|
-
format: TextureFormat,
|
|
527
|
-
extensions: GLExtensions
|
|
528
|
-
): boolean {
|
|
529
|
-
if (!isTextureFormatSupported(gl, format, extensions)) {
|
|
530
|
-
return false;
|
|
531
|
-
}
|
|
532
|
-
if (format.startsWith('depth') || format.startsWith('stencil')) {
|
|
533
|
-
return false;
|
|
534
|
-
}
|
|
535
|
-
try {
|
|
536
|
-
const decoded = decodeTextureFormat(format);
|
|
537
|
-
if (decoded.signed) {
|
|
538
|
-
return false;
|
|
539
|
-
}
|
|
540
|
-
} catch {
|
|
541
|
-
return false;
|
|
542
|
-
}
|
|
543
|
-
if (format.endsWith('32float')) {
|
|
544
|
-
return Boolean(getWebGLExtension(gl, 'OES_texture_float_linear, extensions', extensions));
|
|
545
|
-
}
|
|
546
|
-
if (format.endsWith('16float')) {
|
|
547
|
-
return Boolean(getWebGLExtension(gl, 'OES_texture_half_float_linear, extensions', extensions));
|
|
548
|
-
}
|
|
549
|
-
return true;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
export function isTextureFormatRenderable(
|
|
553
|
-
gl: WebGL2RenderingContext,
|
|
554
|
-
format: TextureFormat,
|
|
555
|
-
extensions: GLExtensions
|
|
556
|
-
): boolean {
|
|
557
|
-
if (!isTextureFormatSupported(gl, format, extensions)) {
|
|
558
|
-
return false;
|
|
559
|
-
}
|
|
560
|
-
if (typeof format === 'number') {
|
|
561
|
-
return false; // isTextureFormatFilterableWebGL(gl, format);
|
|
562
|
-
}
|
|
563
|
-
// TODO depends on device...
|
|
564
|
-
return true;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
444
|
/** Get parameters necessary to work with format in WebGL: internalFormat, dataFormat, type, compressed, */
|
|
568
445
|
export function getTextureFormatWebGL(format: TextureFormat): {
|
|
569
446
|
internalFormat: GL;
|
|
@@ -642,6 +519,29 @@ function convertTextureFormatToGL(format: TextureFormat): GL | undefined {
|
|
|
642
519
|
return webglFormat;
|
|
643
520
|
}
|
|
644
521
|
|
|
522
|
+
// LEGACY CODE
|
|
523
|
+
// TODO - remove when confident in above implementation
|
|
524
|
+
|
|
525
|
+
/** luma.gl v9 does not user renderbufers
|
|
526
|
+
export function isRenderbufferFormatSupported(
|
|
527
|
+
gl: WebGL2RenderingContext,
|
|
528
|
+
format: TextureFormat,
|
|
529
|
+
extensions: GLExtensions
|
|
530
|
+
): boolean {
|
|
531
|
+
// Note: Order is important since the function call initializes extensions.
|
|
532
|
+
return isTextureFormatSupported(gl, format, extensions) && Boolean(TEXTURE_FORMATS[format]?.rb);
|
|
533
|
+
}
|
|
534
|
+
*/
|
|
535
|
+
|
|
536
|
+
/** Return a list of texture feature strings (for Device.features). Mainly compressed texture support */
|
|
537
|
+
// export function getTextureFeatures(
|
|
538
|
+
// gl: WebGL2RenderingContext,
|
|
539
|
+
// extensions: GLExtensions
|
|
540
|
+
// ): DeviceFeature[] {
|
|
541
|
+
// const textureFeatures = Object.keys(TEXTURE_FEATURES) as DeviceFeature[];
|
|
542
|
+
// return textureFeatures.filter(feature => checkTextureFeature(gl, feature, extensions));
|
|
543
|
+
// }
|
|
544
|
+
|
|
645
545
|
/**
|
|
646
546
|
* Map WebGL texture formats (GL constants) to WebGPU-style TextureFormat strings
|
|
647
547
|
export function convertGLToTextureFormat(format: GL | TextureFormat): TextureFormat {
|
|
@@ -655,3 +555,97 @@ export function convertGLToTextureFormat(format: GL | TextureFormat): TextureFor
|
|
|
655
555
|
return entry[0] as TextureFormat;
|
|
656
556
|
}
|
|
657
557
|
*/
|
|
558
|
+
|
|
559
|
+
/** Legal combinations for internalFormat, format and type *
|
|
560
|
+
// [GL.DEPTH_COMPONENT]: {types: [GL.UNSIGNED_SHORT, GL.UNSIGNED_INT, GL.UNSIGNED_INT_24_8]},
|
|
561
|
+
// [GL.DEPTH_STENCIL]: ,
|
|
562
|
+
// Sized texture format
|
|
563
|
+
// R
|
|
564
|
+
[GL.R8]: {dataFormat: GL.RED, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
565
|
+
[GL.R16F]: {dataFormat: GL.RED, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
566
|
+
[GL.R8UI]: {dataFormat: GL.RED_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
567
|
+
// // RG
|
|
568
|
+
[GL.RG8]: {dataFormat: GL.RG, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
569
|
+
[GL.RG16F]: {dataFormat: GL.RG, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
570
|
+
[GL.RG8UI]: {dataFormat: GL.RG_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
571
|
+
// // RGB
|
|
572
|
+
[GL.RGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
573
|
+
[GL.SRGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
574
|
+
[GL.RGB16F]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
575
|
+
[GL.RGB8UI]: {dataFormat: GL.RGB_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
576
|
+
// // RGBA
|
|
577
|
+
|
|
578
|
+
[GL.RGB565]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5], gl2: true},
|
|
579
|
+
[GL.R11F_G11F_B10F]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_INT_10F_11F_11F_REV, GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
580
|
+
[GL.RGB9_E5]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
581
|
+
[GL.RGBA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true},
|
|
582
|
+
[GL.SRGB8_ALPHA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true, gl1ext: EXT_SRGB},
|
|
583
|
+
[GL.RGB5_A1]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_5_5_1], gl2: true},
|
|
584
|
+
[GL.RGBA4]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4], gl2: true},
|
|
585
|
+
[GL.RGBA16F]: {dataFormat: GL.RGBA, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
|
|
586
|
+
[GL.RGBA8UI]: {dataFormat: GL.RGBA_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true}
|
|
587
|
+
*/
|
|
588
|
+
|
|
589
|
+
/* This table is now baked into the above table
|
|
590
|
+
type RenderbufferFormat = {
|
|
591
|
+
bpp: number;
|
|
592
|
+
gl2?: boolean;
|
|
593
|
+
ext?: string;
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
export const RENDERBUFFER_FORMATS: Record<string, RenderbufferFormat> = {
|
|
597
|
+
[GL.DEPTH_COMPONENT16]: {bpp: 2}, // 16 depth bits.
|
|
598
|
+
// TODO - Not clear which webgpu value to map this to.
|
|
599
|
+
// [GL.DEPTH_COMPONENT24]: {gl2: true, bpp: 3},
|
|
600
|
+
[GL.DEPTH_COMPONENT32F]: {gl2: true, bpp: 4},
|
|
601
|
+
|
|
602
|
+
[GL.STENCIL_INDEX8]: {bpp: 1}, // 8 stencil bits.
|
|
603
|
+
|
|
604
|
+
[GL.DEPTH_STENCIL]: {bpp: 4},
|
|
605
|
+
[GL.DEPTH24_STENCIL8]: {gl2: true, bpp: 4},
|
|
606
|
+
[GL.DEPTH32F_STENCIL8]: {gl2: true, bpp: 5},
|
|
607
|
+
|
|
608
|
+
// When using a WebGL 1 context, color renderbuffer formats are limited
|
|
609
|
+
[GL.RGBA4]: {gl2: true, bpp: 2},
|
|
610
|
+
[GL.RGB565]: {gl2: true, bpp: 2},
|
|
611
|
+
[GL.RGB5_A1]: {gl2: true, bpp: 2},
|
|
612
|
+
|
|
613
|
+
// When using a WebGL 2 context, the following values are available additionally:
|
|
614
|
+
[GL.R8]: {gl2: true, bpp: 1},
|
|
615
|
+
[GL.R8UI]: {gl2: true, bpp: 1},
|
|
616
|
+
[GL.R8I]: {gl2: true, bpp: 1},
|
|
617
|
+
[GL.R16UI]: {gl2: true, bpp: 2},
|
|
618
|
+
[GL.R16I]: {gl2: true, bpp: 2},
|
|
619
|
+
[GL.R32UI]: {gl2: true, bpp: 4},
|
|
620
|
+
[GL.R32I]: {gl2: true, bpp: 4},
|
|
621
|
+
[GL.RG8]: {gl2: true, bpp: 2},
|
|
622
|
+
[GL.RG8UI]: {gl2: true, bpp: 2},
|
|
623
|
+
[GL.RG8I]: {gl2: true, bpp: 2},
|
|
624
|
+
[GL.RG16UI]: {gl2: true, bpp: 4},
|
|
625
|
+
[GL.RG16I]: {gl2: true, bpp: 4},
|
|
626
|
+
[GL.RG32UI]: {gl2: true, bpp: 8},
|
|
627
|
+
[GL.RG32I]: {gl2: true, bpp: 8},
|
|
628
|
+
[GL.RGB8]: {gl2: true, bpp: 3},
|
|
629
|
+
[GL.RGBA8]: {gl2: true, bpp: 4},
|
|
630
|
+
// [GL.SRGB8_ALPHA8]: {gl2: true, gl1: SRGB}, // When using the EXT_sRGB WebGL1 extension
|
|
631
|
+
[GL.RGB10_A2]: {gl2: true, bpp: 4},
|
|
632
|
+
[GL.RGBA8UI]: {gl2: true, bpp: 4},
|
|
633
|
+
[GL.RGBA8I]: {gl2: true, bpp: 4},
|
|
634
|
+
[GL.RGB10_A2UI]: {gl2: true, bpp: 4},
|
|
635
|
+
[GL.RGBA16UI]: {gl2: true, bpp: 8},
|
|
636
|
+
[GL.RGBA16I]: {gl2: true, bpp: 8},
|
|
637
|
+
[GL.RGBA32I]: {gl2: true, bpp: 16},
|
|
638
|
+
[GL.RGBA32UI]: {gl2: true, bpp: 16},
|
|
639
|
+
|
|
640
|
+
// When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
|
|
641
|
+
[GL.R16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 2},
|
|
642
|
+
[GL.RG16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4},
|
|
643
|
+
[GL.RGBA16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
|
|
644
|
+
[GL.R32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4},
|
|
645
|
+
[GL.RG32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
|
|
646
|
+
// TODO - can't get WEBGL_color_buffer_float to work on renderbuffers
|
|
647
|
+
[GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 16},
|
|
648
|
+
// [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2},
|
|
649
|
+
[GL.R11F_G11F_B10F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4}
|
|
650
|
+
};
|
|
651
|
+
*/
|
|
@@ -10,14 +10,20 @@ export function glFormatToComponents(format) {
|
|
|
10
10
|
case GL.ALPHA:
|
|
11
11
|
case GL.R32F:
|
|
12
12
|
case GL.RED:
|
|
13
|
+
case GL.RED_INTEGER:
|
|
13
14
|
return 1;
|
|
15
|
+
case GL.RG32I:
|
|
16
|
+
case GL.RG32UI:
|
|
14
17
|
case GL.RG32F:
|
|
18
|
+
case GL.RG_INTEGER:
|
|
15
19
|
case GL.RG:
|
|
16
20
|
return 2;
|
|
17
21
|
case GL.RGB:
|
|
22
|
+
case GL.RGB_INTEGER:
|
|
18
23
|
case GL.RGB32F:
|
|
19
24
|
return 3;
|
|
20
25
|
case GL.RGBA:
|
|
26
|
+
case GL.RGBA_INTEGER:
|
|
21
27
|
case GL.RGBA32F:
|
|
22
28
|
return 4;
|
|
23
29
|
// TODO: Add support for additional WebGL2 formats
|