@luma.gl/webgl 9.1.0-alpha.2 → 9.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts +3 -3
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +19 -11
  4. package/dist/adapter/converters/device-parameters.js.map +1 -0
  5. package/dist/adapter/converters/sampler-parameters.js +7 -4
  6. package/dist/adapter/converters/sampler-parameters.js.map +1 -0
  7. package/dist/adapter/converters/shader-formats.js +1 -0
  8. package/dist/adapter/converters/shader-formats.js.map +1 -0
  9. package/dist/adapter/converters/vertex-formats.js +1 -0
  10. package/dist/adapter/converters/vertex-formats.js.map +1 -0
  11. package/dist/adapter/converters/webgl-texture-table.d.ts +40 -0
  12. package/dist/adapter/converters/webgl-texture-table.d.ts.map +1 -0
  13. package/dist/adapter/converters/webgl-texture-table.js +304 -0
  14. package/dist/adapter/converters/webgl-texture-table.js.map +1 -0
  15. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
  16. package/dist/adapter/device-helpers/webgl-device-features.js +2 -3
  17. package/dist/adapter/device-helpers/webgl-device-features.js.map +1 -0
  18. package/dist/adapter/device-helpers/webgl-device-info.js +1 -0
  19. package/dist/adapter/device-helpers/webgl-device-info.js.map +1 -0
  20. package/dist/adapter/device-helpers/webgl-device-limits.js +1 -0
  21. package/dist/adapter/device-helpers/webgl-device-limits.js.map +1 -0
  22. package/dist/adapter/helpers/decode-webgl-types.js +1 -0
  23. package/dist/adapter/helpers/decode-webgl-types.js.map +1 -0
  24. package/dist/adapter/helpers/format-utils.d.ts.map +1 -0
  25. package/dist/{classic → adapter/helpers}/format-utils.js +7 -0
  26. package/dist/adapter/helpers/format-utils.js.map +1 -0
  27. package/dist/adapter/helpers/get-shader-layout.d.ts +1 -1
  28. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  29. package/dist/adapter/helpers/get-shader-layout.js +5 -4
  30. package/dist/adapter/helpers/get-shader-layout.js.map +1 -0
  31. package/dist/adapter/helpers/parse-shader-compiler-log.js +1 -0
  32. package/dist/adapter/helpers/parse-shader-compiler-log.js.map +1 -0
  33. package/dist/adapter/helpers/set-uniform.js +1 -0
  34. package/dist/adapter/helpers/set-uniform.js.map +1 -0
  35. package/dist/adapter/helpers/typed-array-utils.d.ts.map +1 -0
  36. package/dist/{classic → adapter/helpers}/typed-array-utils.js +1 -0
  37. package/dist/adapter/helpers/typed-array-utils.js.map +1 -0
  38. package/dist/adapter/helpers/webgl-texture-utils.d.ts +100 -29
  39. package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
  40. package/dist/adapter/helpers/webgl-texture-utils.js +231 -240
  41. package/dist/adapter/helpers/webgl-texture-utils.js.map +1 -0
  42. package/dist/adapter/helpers/webgl-topology-utils.js +1 -0
  43. package/dist/adapter/helpers/webgl-topology-utils.js.map +1 -0
  44. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  45. package/dist/adapter/resources/webgl-buffer.js +4 -1
  46. package/dist/adapter/resources/webgl-buffer.js.map +1 -0
  47. package/dist/adapter/resources/webgl-command-buffer.d.ts +59 -2
  48. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  49. package/dist/adapter/resources/webgl-command-buffer.js +89 -32
  50. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -0
  51. package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
  52. package/dist/adapter/resources/webgl-command-encoder.js +4 -0
  53. package/dist/adapter/resources/webgl-command-encoder.js.map +1 -0
  54. package/dist/adapter/resources/webgl-external-texture.js +15 -0
  55. package/dist/adapter/resources/webgl-external-texture.js.map +1 -0
  56. package/dist/adapter/resources/webgl-framebuffer.d.ts +33 -35
  57. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  58. package/dist/adapter/resources/webgl-framebuffer.js +71 -76
  59. package/dist/adapter/resources/webgl-framebuffer.js.map +1 -0
  60. package/dist/adapter/resources/webgl-query-set.js +1 -0
  61. package/dist/adapter/resources/webgl-query-set.js.map +1 -0
  62. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  63. package/dist/adapter/resources/webgl-render-pass.js +49 -21
  64. package/dist/adapter/resources/webgl-render-pass.js.map +1 -0
  65. package/dist/adapter/resources/webgl-render-pipeline.d.ts +3 -4
  66. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  67. package/dist/adapter/resources/webgl-render-pipeline.js +45 -23
  68. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -0
  69. package/dist/adapter/resources/webgl-sampler.js +1 -0
  70. package/dist/adapter/resources/webgl-sampler.js.map +1 -0
  71. package/dist/adapter/resources/webgl-shader.d.ts +1 -0
  72. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  73. package/dist/adapter/resources/webgl-shader.js +13 -6
  74. package/dist/adapter/resources/webgl-shader.js.map +1 -0
  75. package/dist/adapter/resources/webgl-texture-view.js +1 -0
  76. package/dist/adapter/resources/webgl-texture-view.js.map +1 -0
  77. package/dist/adapter/resources/webgl-texture.d.ts +33 -21
  78. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  79. package/dist/adapter/resources/webgl-texture.js +172 -242
  80. package/dist/adapter/resources/webgl-texture.js.map +1 -0
  81. package/dist/adapter/resources/webgl-transform-feedback.js +1 -0
  82. package/dist/adapter/resources/webgl-transform-feedback.js.map +1 -0
  83. package/dist/adapter/resources/webgl-vertex-array.js +1 -0
  84. package/dist/adapter/resources/webgl-vertex-array.js.map +1 -0
  85. package/dist/adapter/webgl-adapter.d.ts +21 -0
  86. package/dist/adapter/webgl-adapter.d.ts.map +1 -0
  87. package/dist/adapter/webgl-adapter.js +86 -0
  88. package/dist/adapter/webgl-adapter.js.map +1 -0
  89. package/dist/adapter/webgl-canvas-context.d.ts +4 -6
  90. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  91. package/dist/adapter/webgl-canvas-context.js +13 -17
  92. package/dist/adapter/webgl-canvas-context.js.map +1 -0
  93. package/dist/adapter/webgl-device.d.ts +35 -46
  94. package/dist/adapter/webgl-device.d.ts.map +1 -1
  95. package/dist/adapter/webgl-device.js +100 -156
  96. package/dist/adapter/webgl-device.js.map +1 -0
  97. package/dist/context/debug/spector-types.d.ts +1108 -0
  98. package/dist/context/debug/spector-types.d.ts.map +1 -0
  99. package/dist/context/debug/spector-types.js +698 -0
  100. package/dist/context/debug/spector-types.js.map +1 -0
  101. package/dist/context/debug/spector.d.ts +12 -8
  102. package/dist/context/debug/spector.d.ts.map +1 -1
  103. package/dist/context/debug/spector.js +24 -17
  104. package/dist/context/debug/spector.js.map +1 -0
  105. package/dist/context/debug/webgl-developer-tools.d.ts +2 -3
  106. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  107. package/dist/context/debug/webgl-developer-tools.js +7 -19
  108. package/dist/context/debug/webgl-developer-tools.js.map +1 -0
  109. package/dist/context/helpers/create-browser-context.d.ts +6 -22
  110. package/dist/context/helpers/create-browser-context.d.ts.map +1 -1
  111. package/dist/context/helpers/create-browser-context.js +41 -32
  112. package/dist/context/helpers/create-browser-context.js.map +1 -0
  113. package/dist/context/helpers/webgl-context-data.js +1 -0
  114. package/dist/context/helpers/webgl-context-data.js.map +1 -0
  115. package/dist/context/helpers/webgl-extensions.js +1 -0
  116. package/dist/context/helpers/webgl-extensions.js.map +1 -0
  117. package/dist/context/parameters/unified-parameter-api.js +1 -0
  118. package/dist/context/parameters/unified-parameter-api.js.map +1 -0
  119. package/dist/context/parameters/webgl-parameter-tables.d.ts +1 -1
  120. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  121. package/dist/context/parameters/webgl-parameter-tables.js +3 -2
  122. package/dist/context/parameters/webgl-parameter-tables.js.map +1 -0
  123. package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts +9 -0
  124. package/dist/context/polyfills/polyfill-webgl1-extensions.d.ts.map +1 -0
  125. package/dist/context/polyfills/polyfill-webgl1-extensions.js +182 -0
  126. package/dist/context/polyfills/polyfill-webgl1-extensions.js.map +1 -0
  127. package/dist/context/state-tracker/deep-array-equal.js +1 -0
  128. package/dist/context/state-tracker/deep-array-equal.js.map +1 -0
  129. package/dist/context/state-tracker/webgl-state-tracker.d.ts +43 -0
  130. package/dist/context/state-tracker/webgl-state-tracker.d.ts.map +1 -0
  131. package/dist/context/state-tracker/{track-context-state.js → webgl-state-tracker.js} +45 -74
  132. package/dist/context/state-tracker/webgl-state-tracker.js.map +1 -0
  133. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  134. package/dist/context/state-tracker/with-parameters.js +6 -4
  135. package/dist/context/state-tracker/with-parameters.js.map +1 -0
  136. package/dist/deprecated/accessor.d.ts.map +1 -0
  137. package/dist/{classic → deprecated}/accessor.js +37 -1
  138. package/dist/deprecated/accessor.js.map +1 -0
  139. package/dist/dist.dev.js +2397 -2430
  140. package/dist/dist.min.js +2 -2
  141. package/dist/index.cjs +2273 -2298
  142. package/dist/index.cjs.map +4 -4
  143. package/dist/index.d.ts +5 -4
  144. package/dist/index.d.ts.map +1 -1
  145. package/dist/index.js +6 -6
  146. package/dist/index.js.map +1 -0
  147. package/dist/types.js +1 -0
  148. package/dist/types.js.map +1 -0
  149. package/dist/utils/fill-array.d.ts +4 -4
  150. package/dist/utils/fill-array.d.ts.map +1 -1
  151. package/dist/utils/fill-array.js +1 -0
  152. package/dist/utils/fill-array.js.map +1 -0
  153. package/dist/utils/load-script.js +1 -0
  154. package/dist/utils/load-script.js.map +1 -0
  155. package/dist/utils/split-uniforms-and-bindings.d.ts +1 -1
  156. package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -1
  157. package/dist/utils/split-uniforms-and-bindings.js +1 -0
  158. package/dist/utils/split-uniforms-and-bindings.js.map +1 -0
  159. package/dist/utils/uid.d.ts +7 -0
  160. package/dist/utils/uid.d.ts.map +1 -0
  161. package/dist/utils/uid.js +15 -0
  162. package/dist/utils/uid.js.map +1 -0
  163. package/package.json +5 -5
  164. package/src/adapter/converters/device-parameters.ts +21 -15
  165. package/src/adapter/converters/sampler-parameters.ts +6 -4
  166. package/src/adapter/converters/webgl-texture-table.ts +404 -0
  167. package/src/adapter/device-helpers/webgl-device-features.ts +5 -3
  168. package/src/{classic → adapter/helpers}/format-utils.ts +6 -0
  169. package/src/adapter/helpers/get-shader-layout.ts +7 -4
  170. package/src/adapter/helpers/webgl-texture-utils.ts +410 -64
  171. package/src/adapter/resources/webgl-buffer.ts +3 -1
  172. package/src/adapter/resources/webgl-command-buffer.ts +125 -41
  173. package/src/adapter/resources/webgl-command-encoder.ts +6 -0
  174. package/src/adapter/resources/webgl-external-texture.ts +14 -0
  175. package/src/adapter/resources/webgl-framebuffer.ts +80 -86
  176. package/src/adapter/resources/webgl-render-pass.ts +72 -45
  177. package/src/adapter/resources/webgl-render-pipeline.ts +58 -27
  178. package/src/adapter/resources/webgl-shader.ts +15 -7
  179. package/src/adapter/resources/webgl-texture.ts +202 -274
  180. package/src/adapter/webgl-adapter.ts +105 -0
  181. package/src/adapter/webgl-canvas-context.ts +16 -19
  182. package/src/adapter/webgl-device.ts +144 -210
  183. package/src/context/debug/spector-types.ts +1154 -0
  184. package/src/context/debug/spector.ts +38 -29
  185. package/src/context/debug/webgl-developer-tools.ts +8 -31
  186. package/src/context/helpers/create-browser-context.ts +53 -63
  187. package/src/context/parameters/webgl-parameter-tables.ts +2 -2
  188. package/src/context/polyfills/polyfill-webgl1-extensions.ts +202 -0
  189. package/src/context/state-tracker/{track-context-state.ts → webgl-state-tracker.ts} +55 -94
  190. package/src/context/state-tracker/with-parameters.ts +5 -4
  191. package/src/{classic → deprecated}/accessor.ts +44 -3
  192. package/src/index.ts +7 -12
  193. package/src/utils/fill-array.ts +4 -4
  194. package/src/utils/split-uniforms-and-bindings.ts +3 -3
  195. package/src/utils/uid.ts +16 -0
  196. package/dist/adapter/converters/texture-formats.d.ts +0 -83
  197. package/dist/adapter/converters/texture-formats.d.ts.map +0 -1
  198. package/dist/adapter/converters/texture-formats.js +0 -518
  199. package/dist/classic/accessor.d.ts.map +0 -1
  200. package/dist/classic/clear.d.ts +0 -22
  201. package/dist/classic/clear.d.ts.map +0 -1
  202. package/dist/classic/clear.js +0 -86
  203. package/dist/classic/copy-and-blit.d.ts +0 -63
  204. package/dist/classic/copy-and-blit.d.ts.map +0 -1
  205. package/dist/classic/copy-and-blit.js +0 -193
  206. package/dist/classic/format-utils.d.ts.map +0 -1
  207. package/dist/classic/typed-array-utils.d.ts.map +0 -1
  208. package/dist/context/state-tracker/track-context-state.d.ts +0 -22
  209. package/dist/context/state-tracker/track-context-state.d.ts.map +0 -1
  210. package/src/adapter/converters/texture-formats.ts +0 -665
  211. package/src/classic/clear.ts +0 -115
  212. package/src/classic/copy-and-blit.ts +0 -318
  213. /package/dist/{classic → adapter/helpers}/format-utils.d.ts +0 -0
  214. /package/dist/{classic → adapter/helpers}/typed-array-utils.d.ts +0 -0
  215. /package/dist/{classic → deprecated}/accessor.d.ts +0 -0
  216. /package/src/{classic → adapter/helpers}/typed-array-utils.ts +0 -0
@@ -1,665 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import type {TextureFormat, DeviceFeature} from '@luma.gl/core';
6
- import {decodeTextureFormat} from '@luma.gl/core';
7
- import {GL, GLPixelType, GLExtensions, GLTexelDataFormat} from '@luma.gl/constants';
8
- import {getWebGLExtension} from '../../context/helpers/webgl-extensions';
9
- import {getGLFromVertexType} from './vertex-formats';
10
-
11
- /* eslint-disable camelcase */
12
-
13
- // TEXTURE FEATURES
14
-
15
- // Define local device feature strings to optimize minification
16
- const texture_compression_bc: DeviceFeature = 'texture-compression-bc';
17
- const texture_compression_astc: DeviceFeature = 'texture-compression-astc';
18
- const texture_compression_etc2: DeviceFeature = 'texture-compression-etc2';
19
- const texture_compression_etc1_webgl: DeviceFeature = 'texture-compression-etc1-webgl';
20
- const texture_compression_pvrtc_webgl: DeviceFeature = 'texture-compression-pvrtc-webgl';
21
- const texture_compression_atc_webgl: DeviceFeature = 'texture-compression-atc-webgl';
22
-
23
- const float32_renderable: DeviceFeature = 'float32-renderable-webgl';
24
- const float16_renderable: DeviceFeature = 'float16-renderable-webgl';
25
- const rgb9e5ufloat_renderable: DeviceFeature = 'rgb9e5ufloat_renderable-webgl';
26
- const snorm8_renderable: DeviceFeature = 'snorm8-renderable-webgl';
27
- const norm16_renderable: DeviceFeature = 'norm16-renderable-webgl';
28
- const snorm16_renderable: DeviceFeature = 'snorm16-renderable-webgl';
29
-
30
- const float32_filterable: DeviceFeature = 'float32-filterable';
31
- const float16_filterable: DeviceFeature = 'float16-filterable-webgl';
32
-
33
- // Define local webgl extension strings to optimize minification
34
- const X_S3TC = 'WEBGL_compressed_texture_s3tc'; // BC1, BC2, BC3
35
- const X_S3TC_SRGB = 'WEBGL_compressed_texture_s3tc_srgb'; // BC1, BC2, BC3
36
- const X_RGTC = 'EXT_texture_compression_rgtc'; // BC4, BC5
37
- const X_BPTC = 'EXT_texture_compression_bptc'; // BC6, BC7
38
- const X_ETC2 = 'WEBGL_compressed_texture_etc'; // Renamed from 'WEBGL_compressed_texture_es3'
39
- const X_ASTC = 'WEBGL_compressed_texture_astc';
40
- const X_ETC1 = 'WEBGL_compressed_texture_etc1';
41
- const X_PVRTC = 'WEBGL_compressed_texture_pvrtc';
42
- const X_ATC = 'WEBGL_compressed_texture_atc';
43
-
44
- // Define local webgl extension strings to optimize minification
45
- const EXT_texture_norm16 = 'EXT_texture_norm16';
46
- const EXT_render_snorm = 'EXT_render_snorm';
47
- const EXT_color_buffer_float = 'EXT_color_buffer_float';
48
-
49
- // prettier-ignore
50
- export const TEXTURE_FEATURES: Partial<Record<DeviceFeature, string[]>> = {
51
- 'float32-renderable-webgl': ['EXT_color_buffer_float'],
52
- 'float16-renderable-webgl': ['EXT_color_buffer_half_float'],
53
- 'rgb9e5ufloat_renderable-webgl': ['WEBGL_render_shared_exponent'],
54
- 'snorm8-renderable-webgl': [EXT_render_snorm],
55
- 'norm16-renderable-webgl': [EXT_texture_norm16],
56
- 'snorm16-renderable-webgl': [EXT_texture_norm16, EXT_render_snorm],
57
-
58
- 'float32-filterable': ['OES_texture_float_linear'],
59
- 'float16-filterable-webgl': ['OES_texture_half_float_linear'],
60
- 'texture-filterable-anisotropic-webgl': ['EXT_texture_filter_anisotropic'],
61
-
62
- 'texture-blend-float-webgl': ['EXT_float_blend'],
63
-
64
- 'texture-compression-bc': [X_S3TC, X_S3TC_SRGB, X_RGTC, X_BPTC],
65
- // 'texture-compression-bc3-srgb-webgl': [X_S3TC_SRGB],
66
- // 'texture-compression-bc3-webgl': [X_S3TC],
67
- 'texture-compression-bc5-webgl': [X_RGTC],
68
- 'texture-compression-bc7-webgl': [X_BPTC],
69
- 'texture-compression-etc2': [X_ETC2],
70
- 'texture-compression-astc': [X_ASTC],
71
- 'texture-compression-etc1-webgl': [X_ETC1],
72
- 'texture-compression-pvrtc-webgl': [X_PVRTC],
73
- 'texture-compression-atc-webgl': [X_ATC]
74
- };
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
- export function isTextureFeature(feature: DeviceFeature): boolean {
86
- return feature in TEXTURE_FEATURES;
87
- }
88
-
89
- /** Checks a texture feature (for Device.features). Mainly compressed texture support */
90
- export function checkTextureFeature(
91
- gl: WebGL2RenderingContext,
92
- feature: DeviceFeature,
93
- extensions: GLExtensions
94
- ): boolean {
95
- const textureExtensions = TEXTURE_FEATURES[feature] || [];
96
- return textureExtensions.every(extension => getWebGLExtension(gl, extension, extensions));
97
- }
98
-
99
- // TEXTURE FORMATS
100
-
101
- /** Map a format to webgl and constants */
102
- type Format = {
103
- gl?: GL;
104
- /** format requires WebGL2, when using a WebGL 1 context, color renderbuffer formats are limited */
105
- gl2ext?: string;
106
-
107
- /** (bytes per pixel), for memory usage calculations. */
108
- b?: number;
109
- /** channels */
110
- c?: number;
111
- bpp?: number;
112
- /** packed */
113
- p?: number;
114
- /** compressed */
115
- x?: string;
116
- /** for compressed texture formats */
117
- f?: DeviceFeature;
118
- /** renderable if feature is present */
119
- render?: DeviceFeature;
120
- /** filterable if feature is present */
121
- filter?: DeviceFeature;
122
-
123
- /** If not supported on WebGPU */
124
- wgpu?: false;
125
-
126
- types?: GLPixelType[];
127
- dataFormat?: GLTexelDataFormat;
128
- /** Depth and stencil format attachment points. If set, needs to be a Renderbuffer unless depthTexture is set */
129
- attachment?: GL.DEPTH_ATTACHMENT | GL.STENCIL_ATTACHMENT | GL.DEPTH_STENCIL_ATTACHMENT;
130
- /** if depthTexture is set this is a depth/stencil format that can be set to a texture */
131
- depthTexture?: boolean;
132
- /** @deprecated can this format be used with renderbuffers */
133
- rb?: boolean;
134
- };
135
-
136
- // TABLES
137
-
138
- /**
139
- * Texture format data -
140
- * Exported but can change without notice
141
- */
142
- // prettier-ignore
143
- export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
144
- // Unsized formats that leave the precision up to the driver. TODO - Fix bpp constants
145
- 'rgb8unorm-unsized': {gl: GL.RGB, b: 4, c: 2, bpp: 4,
146
- dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5]},
147
- 'rgba8unorm-unsized': {gl: GL.RGBA, b: 4, c: 2, bpp: 4,
148
- dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4, GL.UNSIGNED_SHORT_5_5_5_1]},
149
- // 'r8unorm-unsized': {gl: GL.LUMINANCE, b: 4, c: 2, bpp: 4},
150
- // 'rgb8unorm-srgb-unsized': {gl: GL.SRGB_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
151
- // 'rgba8unorm-srgb-unsized': {gl: GL.SRGB_ALPHA_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
152
-
153
- // 8-bit formats
154
- 'r8unorm': {gl: GL.R8, b: 1, c: 1, rb: true},
155
- 'r8snorm': {gl: GL.R8_SNORM, b: 1, c: 1, render: snorm8_renderable},
156
- 'r8uint': {gl: GL.R8UI, b: 1, c: 1, rb: true},
157
- 'r8sint': {gl: GL.R8I, b: 1, c: 1, rb: true},
158
-
159
- // 16-bit formats
160
- 'rg8unorm': {gl: GL.RG8, b: 2, c: 2, rb: true},
161
- 'rg8snorm': {gl: GL.RG8_SNORM, b: 2, c: 2, render: snorm8_renderable},
162
- 'rg8uint': {gl: GL.RG8UI, b: 2, c: 2, rb: true},
163
- 'rg8sint': {gl: GL.RG8I, b: 2, c: 2, rb: true},
164
-
165
- 'r16uint': {gl: GL.R16UI, b: 2, c: 1, rb: true},
166
- 'r16sint': {gl: GL.R16I, b: 2, c: 1, rb: true},
167
- 'r16float': {gl: GL.R16F, b: 2, c: 1, render: float16_renderable, filter: 'float16-filterable-webgl', rb: true},
168
- 'r16unorm-webgl': {gl: GL.R16_EXT, b:2, c:1, f: norm16_renderable, rb: true},
169
- 'r16snorm-webgl': {gl: GL.R16_SNORM_EXT, b:2, c:1, f: snorm16_renderable},
170
-
171
- // Packed 16-bit formats
172
- 'rgba4unorm-webgl': {gl: GL.RGBA4, b: 2, c: 4, wgpu: false, rb: true},
173
- 'rgb565unorm-webgl': {gl: GL.RGB565, b: 2, c: 4, wgpu: false, rb: true},
174
- 'rgb5a1unorm-webgl': {gl: GL.RGB5_A1, b: 2, c: 4, wgpu: false, rb: true},
175
-
176
- // 24-bit formats
177
- 'rgb8unorm-webgl': {gl: GL.RGB8, b: 3, c: 3, wgpu: false},
178
- 'rgb8snorm-webgl': {gl: GL.RGB8_SNORM, b: 3, c: 3, wgpu: false},
179
-
180
- // 32-bit formats
181
- 'rgba8unorm': {gl: GL.RGBA8, b: 4, c: 2, bpp: 4},
182
- 'rgba8unorm-srgb': {gl: GL.SRGB8_ALPHA8, b: 4, c: 4, bpp: 4},
183
- 'rgba8snorm': {gl: GL.RGBA8_SNORM, b: 4, c: 4, render: snorm8_renderable},
184
- 'rgba8uint': {gl: GL.RGBA8UI, b: 4, c: 4, bpp: 4},
185
- 'rgba8sint': {gl: GL.RGBA8I, b: 4, c: 4, bpp: 4},
186
- // reverse colors, webgpu only
187
- 'bgra8unorm': {b: 4, c: 4},
188
- 'bgra8unorm-srgb': {b: 4, c: 4},
189
-
190
- 'rg16uint': {gl: GL.RG16UI, b: 4, c: 1, bpp: 4},
191
- 'rg16sint': {gl: GL.RG16I, b: 4, c: 2, bpp: 4},
192
- 'rg16float': {gl: GL.RG16F, bpp: 4, b: 4, c: 2, render: float16_renderable, filter: float16_filterable, rb: true},
193
- 'rg16unorm-webgl': {gl: GL.RG16_EXT, b:2, c:2, render: norm16_renderable},
194
- 'rg16snorm-webgl': {gl: GL.RG16_SNORM_EXT, b:2, c:2, render: snorm16_renderable},
195
-
196
- 'r32uint': {gl: GL.R32UI, b: 4, c: 1, bpp: 4, rb: true},
197
- 'r32sint': {gl: GL.R32I, b: 4, c: 1, bpp: 4, rb: true},
198
- 'r32float': {gl: GL.R32F, bpp: 4, b: 4, c: 1, render: float32_renderable, filter: float32_filterable},
199
-
200
- // Packed 32-bit formats
201
- 'rgb9e5ufloat': {gl: GL.RGB9_E5, b: 4, c: 3, p: 1, render: rgb9e5ufloat_renderable}, // , filter: true},
202
- 'rg11b10ufloat': {gl: GL.R11F_G11F_B10F, b: 4, c: 3, p: 1,render: float32_renderable, rb: true},
203
- 'rgb10a2unorm': {gl: GL.RGB10_A2, b: 4, c: 4, p: 1, rb: true},
204
- 'rgb10a2uint-webgl': {b: 4, c: 4, gl: GL.RGB10_A2UI, p: 1, wgpu: false, bpp: 4, rb: true},
205
-
206
- // 48-bit formats
207
- 'rgb16unorm-webgl': {gl: GL.RGB16_EXT, b:2, c:3, f: norm16_renderable}, // rgb not renderable
208
- 'rgb16snorm-webgl': {gl: GL.RGB16_SNORM_EXT, b:2, c:3, f: norm16_renderable}, // rgb not renderable
209
-
210
- // 64-bit formats
211
- 'rg32uint': {gl: GL.RG32UI, b: 8, c: 2, rb: true},
212
- 'rg32sint': {gl: GL.RG32I, b: 8, c: 2, rb: true},
213
- 'rg32float': {gl: GL.RG32F, b: 8, c: 2, render: float32_renderable, filter: float32_filterable, rb: true},
214
- 'rgba16uint': {gl: GL.RGBA16UI, b: 8, c: 4, rb: true},
215
- 'rgba16sint': {gl: GL.RGBA16I, b: 8, c: 4, rb: true},
216
- 'rgba16float': {gl: GL.RGBA16F, b: 8, c: 4, render: float16_renderable, filter: float16_filterable},
217
- 'rgba16unorm-webgl': {gl: GL.RGBA16_EXT, b:2, c:4, render: norm16_renderable, rb: true},
218
- 'rgba16snorm-webgl': {gl: GL.RGBA16_SNORM_EXT, b:2, c:4, render: snorm16_renderable},
219
-
220
- // 96-bit formats (deprecated!)
221
- 'rgb32float-webgl': {gl: GL.RGB32F, render: float32_renderable, filter: float32_filterable,
222
- gl2ext: EXT_color_buffer_float, dataFormat: GL.RGB, types: [GL.FLOAT]},
223
-
224
- // 128-bit formats
225
- 'rgba32uint': {gl: GL.RGBA32UI, b: 16, c: 4, rb: true},
226
- 'rgba32sint': {gl: GL.RGBA32I, b: 16, c: 4, rb: true},
227
- 'rgba32float': {gl: GL.RGBA32F, b: 16, c: 4, render: float32_renderable, filter: float32_filterable, rb: true},
228
-
229
- // Depth and stencil formats
230
- 'stencil8': {gl: GL.STENCIL_INDEX8, b: 1, c: 1, attachment: GL.STENCIL_ATTACHMENT, rb: true}, // 8 stencil bits
231
-
232
- 'depth16unorm': {gl: GL.DEPTH_COMPONENT16, b: 2, c: 1, attachment: GL.DEPTH_ATTACHMENT,
233
- dataFormat: GL.DEPTH_COMPONENT, types: [GL.UNSIGNED_SHORT], rb: true}, // 16 depth bits
234
- 'depth24plus': {gl: GL.DEPTH_COMPONENT24, b: 3, c: 1, attachment: GL.DEPTH_ATTACHMENT,
235
- dataFormat: GL.DEPTH_COMPONENT, types: [GL.UNSIGNED_INT]},
236
- 'depth32float': {gl: GL.DEPTH_COMPONENT32F, b: 4, c: 1, attachment: GL.DEPTH_ATTACHMENT,
237
- dataFormat: GL.DEPTH_COMPONENT, types: [GL.FLOAT], rb: true},
238
-
239
- // The depth component of the "depth24plus" and "depth24plus-stencil8" formats may be implemented as either a 24-bit depth value or a "depth32float" value.
240
- 'depth24plus-stencil8': {gl: GL.DEPTH24_STENCIL8, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, rb: true, depthTexture: true,
241
- dataFormat: GL.DEPTH_STENCIL, types: [GL.UNSIGNED_INT_24_8]},
242
- // "depth24unorm-stencil8" feature
243
- 'depth24unorm-stencil8': {gl: GL.DEPTH24_STENCIL8, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT,
244
- dataFormat: GL.DEPTH_STENCIL, types: [GL.UNSIGNED_INT_24_8], rb: true},
245
- // "depth32float-stencil8" feature - TODO below is render buffer only?
246
- 'depth32float-stencil8': {gl: GL.DEPTH32F_STENCIL8, b: 5, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT,
247
- dataFormat: GL.DEPTH_STENCIL, types: [GL.FLOAT_32_UNSIGNED_INT_24_8_REV], rb: true},
248
-
249
- // BC compressed formats: check device.features.has("texture-compression-bc");
250
-
251
- 'bc1-rgb-unorm-webgl': {gl: GL.COMPRESSED_RGB_S3TC_DXT1_EXT, x: X_S3TC, f: texture_compression_bc},
252
- 'bc1-rgb-unorm-srgb-webgl': {gl: GL.COMPRESSED_SRGB_S3TC_DXT1_EXT, x: X_S3TC_SRGB, f: texture_compression_bc},
253
-
254
- 'bc1-rgba-unorm': {gl: GL.COMPRESSED_RGBA_S3TC_DXT1_EXT, x: X_S3TC, f: texture_compression_bc},
255
- 'bc1-rgba-unorm-srgb': {gl: GL.COMPRESSED_SRGB_S3TC_DXT1_EXT, x: X_S3TC_SRGB, f: texture_compression_bc},
256
- 'bc2-rgba-unorm': {gl: GL.COMPRESSED_RGBA_S3TC_DXT3_EXT, x: X_S3TC, f: texture_compression_bc},
257
- 'bc2-rgba-unorm-srgb': {gl: GL.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, x: X_S3TC_SRGB, f: texture_compression_bc},
258
- 'bc3-rgba-unorm': {gl: GL.COMPRESSED_RGBA_S3TC_DXT5_EXT, x: X_S3TC, f: texture_compression_bc},
259
- 'bc3-rgba-unorm-srgb': {gl: GL.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, x: X_S3TC_SRGB, f: texture_compression_bc},
260
- 'bc4-r-unorm': {gl: GL.COMPRESSED_RED_RGTC1_EXT, x: X_RGTC, f: texture_compression_bc},
261
- 'bc4-r-snorm': {gl: GL.COMPRESSED_SIGNED_RED_RGTC1_EXT, x: X_RGTC, f: texture_compression_bc},
262
- 'bc5-rg-unorm': {gl: GL.COMPRESSED_RED_GREEN_RGTC2_EXT, x: X_RGTC, f: texture_compression_bc},
263
- 'bc5-rg-snorm': {gl: GL.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, x: X_RGTC, f: texture_compression_bc},
264
- 'bc6h-rgb-ufloat': {gl: GL.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, x: X_BPTC, f: texture_compression_bc},
265
- 'bc6h-rgb-float': {gl: GL.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, x: X_BPTC, f: texture_compression_bc},
266
- 'bc7-rgba-unorm': {gl: GL.COMPRESSED_RGBA_BPTC_UNORM_EXT, x: X_BPTC, f: texture_compression_bc},
267
- 'bc7-rgba-unorm-srgb': {gl: GL.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, x: X_BPTC, f: texture_compression_bc},
268
-
269
- // WEBGL_compressed_texture_etc: device.features.has("texture-compression-etc2")
270
- // Note: Supposedly guaranteed availability compressed formats in WebGL2, but through CPU decompression
271
-
272
- 'etc2-rgb8unorm': {gl: GL.COMPRESSED_RGB8_ETC2, f: texture_compression_etc2},
273
- 'etc2-rgb8unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ETC2, f: texture_compression_etc2},
274
- 'etc2-rgb8a1unorm': {gl: GL.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, f: texture_compression_etc2},
275
- 'etc2-rgb8a1unorm-srgb': {gl: GL.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, f: texture_compression_etc2},
276
- 'etc2-rgba8unorm': {gl: GL.COMPRESSED_RGBA8_ETC2_EAC, f: texture_compression_etc2},
277
- 'etc2-rgba8unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, f: texture_compression_etc2},
278
-
279
- 'eac-r11unorm': {gl: GL.COMPRESSED_R11_EAC, f: texture_compression_etc2},
280
- 'eac-r11snorm': {gl: GL.COMPRESSED_SIGNED_R11_EAC, f: texture_compression_etc2},
281
- 'eac-rg11unorm': {gl: GL.COMPRESSED_RG11_EAC, f: texture_compression_etc2},
282
- 'eac-rg11snorm': {gl: GL.COMPRESSED_SIGNED_RG11_EAC, f: texture_compression_etc2},
283
-
284
- // X_ASTC compressed formats: device.features.has("texture-compression-astc")
285
-
286
- 'astc-4x4-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_4x4_KHR, f: texture_compression_astc},
287
- 'astc-4x4-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, f: texture_compression_astc},
288
- 'astc-5x4-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_5x4_KHR, f: texture_compression_astc},
289
- 'astc-5x4-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, f: texture_compression_astc},
290
- 'astc-5x5-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_5x5_KHR, f: texture_compression_astc},
291
- 'astc-5x5-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, f: texture_compression_astc},
292
- 'astc-6x5-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_6x5_KHR, f: texture_compression_astc},
293
- 'astc-6x5-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, f: texture_compression_astc},
294
- 'astc-6x6-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_6x6_KHR, f: texture_compression_astc},
295
- 'astc-6x6-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, f: texture_compression_astc},
296
- 'astc-8x5-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_8x5_KHR, f: texture_compression_astc},
297
- 'astc-8x5-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, f: texture_compression_astc},
298
- 'astc-8x6-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_8x6_KHR, f: texture_compression_astc},
299
- 'astc-8x6-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, f: texture_compression_astc},
300
- 'astc-8x8-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_8x8_KHR, f: texture_compression_astc},
301
- 'astc-8x8-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, f: texture_compression_astc},
302
- 'astc-10x5-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_10x10_KHR, f: texture_compression_astc},
303
- 'astc-10x5-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, f: texture_compression_astc},
304
- 'astc-10x6-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_10x6_KHR, f: texture_compression_astc},
305
- 'astc-10x6-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, f: texture_compression_astc},
306
- 'astc-10x8-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_10x8_KHR, f: texture_compression_astc},
307
- 'astc-10x8-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, f: texture_compression_astc},
308
- 'astc-10x10-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_10x10_KHR, f: texture_compression_astc},
309
- 'astc-10x10-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, f: texture_compression_astc},
310
- 'astc-12x10-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_12x10_KHR, f: texture_compression_astc},
311
- 'astc-12x10-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, f: texture_compression_astc},
312
- 'astc-12x12-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_12x12_KHR, f: texture_compression_astc},
313
- 'astc-12x12-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, f: texture_compression_astc},
314
-
315
- // WEBGL_compressed_texture_pvrtc
316
-
317
- 'pvrtc-rgb4unorm-webgl': {gl: GL.COMPRESSED_RGB_PVRTC_4BPPV1_IMG, f: texture_compression_pvrtc_webgl},
318
- 'pvrtc-rgba4unorm-webgl': {gl: GL.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, f: texture_compression_pvrtc_webgl},
319
- 'pvrtc-rbg2unorm-webgl': {gl: GL.COMPRESSED_RGB_PVRTC_2BPPV1_IMG, f: texture_compression_pvrtc_webgl},
320
- 'pvrtc-rgba2unorm-webgl': {gl: GL.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, f: texture_compression_pvrtc_webgl},
321
-
322
- // WEBGL_compressed_texture_etc1
323
-
324
- 'etc1-rbg-unorm-webgl': {gl: GL.COMPRESSED_RGB_ETC1_WEBGL, f: texture_compression_etc1_webgl},
325
-
326
- // WEBGL_compressed_texture_atc
327
-
328
- 'atc-rgb-unorm-webgl': {gl: GL.COMPRESSED_RGB_ATC_WEBGL, f: texture_compression_atc_webgl},
329
- 'atc-rgba-unorm-webgl': {gl: GL.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL, f: texture_compression_atc_webgl},
330
- 'atc-rgbai-unorm-webgl': {gl: GL.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL, f: texture_compression_atc_webgl}
331
- };
332
-
333
- /** Legal combinations for internalFormat, format and type *
334
- // [GL.DEPTH_COMPONENT]: {types: [GL.UNSIGNED_SHORT, GL.UNSIGNED_INT, GL.UNSIGNED_INT_24_8]},
335
- // [GL.DEPTH_STENCIL]: ,
336
- // Sized texture format
337
- // R
338
- [GL.R8]: {dataFormat: GL.RED, types: [GL.UNSIGNED_BYTE], gl2: true},
339
- [GL.R16F]: {dataFormat: GL.RED, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
340
- [GL.R8UI]: {dataFormat: GL.RED_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
341
- // // RG
342
- [GL.RG8]: {dataFormat: GL.RG, types: [GL.UNSIGNED_BYTE], gl2: true},
343
- [GL.RG16F]: {dataFormat: GL.RG, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
344
- [GL.RG8UI]: {dataFormat: GL.RG_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
345
- // // RGB
346
- [GL.RGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
347
- [GL.SRGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
348
- [GL.RGB16F]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
349
- [GL.RGB8UI]: {dataFormat: GL.RGB_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
350
- // // RGBA
351
-
352
- [GL.RGB565]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5], gl2: true},
353
- [GL.R11F_G11F_B10F]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_INT_10F_11F_11F_REV, GL.HALF_FLOAT, GL.FLOAT], gl2: true},
354
- [GL.RGB9_E5]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
355
- [GL.RGBA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true},
356
- [GL.SRGB8_ALPHA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true, gl1ext: EXT_SRGB},
357
- [GL.RGB5_A1]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_5_5_1], gl2: true},
358
- [GL.RGBA4]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4], gl2: true},
359
- [GL.RGBA16F]: {dataFormat: GL.RGBA, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
360
- [GL.RGBA8UI]: {dataFormat: GL.RGBA_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true}
361
- */
362
-
363
- /* This table is now baked into the above table
364
- type RenderbufferFormat = {
365
- bpp: number;
366
- gl2?: boolean;
367
- ext?: string;
368
- };
369
-
370
- export const RENDERBUFFER_FORMATS: Record<string, RenderbufferFormat> = {
371
- [GL.DEPTH_COMPONENT16]: {bpp: 2}, // 16 depth bits.
372
- // TODO - Not clear which webgpu value to map this to.
373
- // [GL.DEPTH_COMPONENT24]: {gl2: true, bpp: 3},
374
- [GL.DEPTH_COMPONENT32F]: {gl2: true, bpp: 4},
375
-
376
- [GL.STENCIL_INDEX8]: {bpp: 1}, // 8 stencil bits.
377
-
378
- [GL.DEPTH_STENCIL]: {bpp: 4},
379
- [GL.DEPTH24_STENCIL8]: {gl2: true, bpp: 4},
380
- [GL.DEPTH32F_STENCIL8]: {gl2: true, bpp: 5},
381
-
382
- // When using a WebGL 1 context, color renderbuffer formats are limited
383
- [GL.RGBA4]: {gl2: true, bpp: 2},
384
- [GL.RGB565]: {gl2: true, bpp: 2},
385
- [GL.RGB5_A1]: {gl2: true, bpp: 2},
386
-
387
- // When using a WebGL 2 context, the following values are available additionally:
388
- [GL.R8]: {gl2: true, bpp: 1},
389
- [GL.R8UI]: {gl2: true, bpp: 1},
390
- [GL.R8I]: {gl2: true, bpp: 1},
391
- [GL.R16UI]: {gl2: true, bpp: 2},
392
- [GL.R16I]: {gl2: true, bpp: 2},
393
- [GL.R32UI]: {gl2: true, bpp: 4},
394
- [GL.R32I]: {gl2: true, bpp: 4},
395
- [GL.RG8]: {gl2: true, bpp: 2},
396
- [GL.RG8UI]: {gl2: true, bpp: 2},
397
- [GL.RG8I]: {gl2: true, bpp: 2},
398
- [GL.RG16UI]: {gl2: true, bpp: 4},
399
- [GL.RG16I]: {gl2: true, bpp: 4},
400
- [GL.RG32UI]: {gl2: true, bpp: 8},
401
- [GL.RG32I]: {gl2: true, bpp: 8},
402
- [GL.RGB8]: {gl2: true, bpp: 3},
403
- [GL.RGBA8]: {gl2: true, bpp: 4},
404
- // [GL.SRGB8_ALPHA8]: {gl2: true, gl1: SRGB}, // When using the EXT_sRGB WebGL1 extension
405
- [GL.RGB10_A2]: {gl2: true, bpp: 4},
406
- [GL.RGBA8UI]: {gl2: true, bpp: 4},
407
- [GL.RGBA8I]: {gl2: true, bpp: 4},
408
- [GL.RGB10_A2UI]: {gl2: true, bpp: 4},
409
- [GL.RGBA16UI]: {gl2: true, bpp: 8},
410
- [GL.RGBA16I]: {gl2: true, bpp: 8},
411
- [GL.RGBA32I]: {gl2: true, bpp: 16},
412
- [GL.RGBA32UI]: {gl2: true, bpp: 16},
413
-
414
- // When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
415
- [GL.R16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 2},
416
- [GL.RG16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4},
417
- [GL.RGBA16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
418
- [GL.R32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4},
419
- [GL.RG32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
420
- // TODO - can't get WEBGL_color_buffer_float to work on renderbuffers
421
- [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 16},
422
- // [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2},
423
- [GL.R11F_G11F_B10F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4}
424
- };
425
- */
426
-
427
- /** @deprecated should be removed */
428
- const DATA_FORMAT_CHANNELS = {
429
- [GL.RED]: 1,
430
- [GL.RED_INTEGER]: 1,
431
- [GL.RG]: 2,
432
- [GL.RG_INTEGER]: 2,
433
- [GL.RGB]: 3,
434
- [GL.RGB_INTEGER]: 3,
435
- [GL.RGBA]: 4,
436
- [GL.RGBA_INTEGER]: 4,
437
- [GL.DEPTH_COMPONENT]: 1,
438
- [GL.DEPTH_STENCIL]: 1,
439
- [GL.ALPHA]: 1,
440
- [GL.LUMINANCE]: 1,
441
- [GL.LUMINANCE_ALPHA]: 2
442
- };
443
-
444
- /** @deprecated should be removed */
445
- const TYPE_SIZES = {
446
- [GL.FLOAT]: 4,
447
- [GL.UNSIGNED_INT]: 4,
448
- [GL.INT]: 4,
449
- [GL.UNSIGNED_SHORT]: 2,
450
- [GL.SHORT]: 2,
451
- [GL.HALF_FLOAT]: 2,
452
- [GL.BYTE]: 1,
453
- [GL.UNSIGNED_BYTE]: 1
454
- };
455
-
456
- // FUNCTIONS
457
-
458
- /** Checks if a texture format is supported */
459
- export function isTextureFormatSupported(
460
- gl: WebGL2RenderingContext,
461
- format: TextureFormat,
462
- extensions: GLExtensions
463
- ): boolean {
464
- const info = TEXTURE_FORMATS[format];
465
- if (!info) {
466
- return false;
467
- }
468
- // Check that we have a GL constant
469
- if (info.gl === undefined) {
470
- return false;
471
- }
472
- // Check extensions
473
- const extension = info.x || info.gl2ext;
474
- if (extension) {
475
- return Boolean(getWebGLExtension(gl, extension, extensions));
476
- }
477
- return true;
478
- }
479
-
480
- export function isRenderbufferFormatSupported(
481
- gl: WebGL2RenderingContext,
482
- format: TextureFormat,
483
- extensions: GLExtensions
484
- ): boolean {
485
- // Note: Order is important since the function call initializes extensions.
486
- return isTextureFormatSupported(gl, format, extensions) && Boolean(TEXTURE_FORMATS[format]?.rb);
487
- }
488
-
489
- /** Checks if a texture format is supported */
490
- export function getTextureFormatSupport(
491
- gl: WebGL2RenderingContext,
492
- format: TextureFormat,
493
- extensions: GLExtensions
494
- ): {
495
- supported: boolean;
496
- filterable?: boolean;
497
- renderable?: boolean;
498
- blendable?: boolean;
499
- storable?: boolean;
500
- } {
501
- const info = TEXTURE_FORMATS[format];
502
- if (!info) {
503
- return {supported: false};
504
- }
505
- // let decoded;
506
- // try {
507
- // decoded = decodeTextureFormat(format);
508
- // } catch {}
509
-
510
- // Support Check that we have a GL constant
511
- let supported = info.gl === undefined;
512
- supported = supported && checkTextureFeature(gl, info.f as DeviceFeature, extensions);
513
-
514
- // Filtering
515
- // const filterable = info.filter
516
- // ? checkTextureFeature(gl, infofilter])
517
- // : decoded && !decoded.signed;
518
- // const renderable = info.filter
519
- // ? checkTextureFeature(gl, inforender])
520
- // : decoded && !decoded.signed;
521
-
522
- return {
523
- supported,
524
- renderable: supported && checkTextureFeature(gl, info.render as DeviceFeature, extensions),
525
- filterable: supported && checkTextureFeature(gl, info.filter as DeviceFeature, extensions),
526
- blendable: false, // tod,
527
- storable: false
528
- };
529
- }
530
-
531
- /** Checks whether linear filtering (interpolated sampling) is available for floating point textures */
532
- export function isTextureFormatFilterable(
533
- gl: WebGL2RenderingContext,
534
- format: TextureFormat,
535
- extensions: GLExtensions
536
- ): boolean {
537
- if (!isTextureFormatSupported(gl, format, extensions)) {
538
- return false;
539
- }
540
- if (format.startsWith('depth') || format.startsWith('stencil')) {
541
- return false;
542
- }
543
- try {
544
- const decoded = decodeTextureFormat(format);
545
- if (decoded.signed) {
546
- return false;
547
- }
548
- } catch {
549
- return false;
550
- }
551
- if (format.endsWith('32float')) {
552
- return Boolean(getWebGLExtension(gl, 'OES_texture_float_linear, extensions', extensions));
553
- }
554
- if (format.endsWith('16float')) {
555
- return Boolean(getWebGLExtension(gl, 'OES_texture_half_float_linear, extensions', extensions));
556
- }
557
- return true;
558
- }
559
-
560
- export function isTextureFormatRenderable(
561
- gl: WebGL2RenderingContext,
562
- format: TextureFormat,
563
- extensions: GLExtensions
564
- ): boolean {
565
- if (!isTextureFormatSupported(gl, format, extensions)) {
566
- return false;
567
- }
568
- if (typeof format === 'number') {
569
- return false; // isTextureFormatFilterableWebGL(gl, format);
570
- }
571
- // TODO depends on device...
572
- return true;
573
- }
574
-
575
- /** Get parameters necessary to work with format in WebGL: internalFormat, dataFormat, type, compressed, */
576
- export function getTextureFormatWebGL(format: TextureFormat): {
577
- internalFormat: GL;
578
- format: GLTexelDataFormat;
579
- type: GLPixelType;
580
- compressed: boolean;
581
- } {
582
- const formatData = TEXTURE_FORMATS[format];
583
- const webglFormat = convertTextureFormatToGL(format);
584
- const decoded = decodeTextureFormat(format);
585
- return {
586
- internalFormat: webglFormat,
587
- format:
588
- formatData?.dataFormat ||
589
- getWebGLPixelDataFormat(decoded.format, decoded.integer, decoded.normalized, webglFormat),
590
- // depth formats don't have a type
591
- type: decoded.dataType
592
- ? getGLFromVertexType(decoded.dataType)
593
- : formatData?.types?.[0] || GL.UNSIGNED_BYTE,
594
- // @ts-expect-error
595
- compressed: decoded.compressed
596
- };
597
- }
598
-
599
- export function getDepthStencilAttachmentWebGL(
600
- format: TextureFormat
601
- ): GL.DEPTH_ATTACHMENT | GL.STENCIL_ATTACHMENT | GL.DEPTH_STENCIL_ATTACHMENT {
602
- const info = TEXTURE_FORMATS[format];
603
- if (!info?.attachment) {
604
- throw new Error(`${format} is not a depth stencil format`);
605
- }
606
- return info.attachment;
607
- }
608
-
609
- /** TODO - VERY roundabout legacy way of calculating bytes per pixel */
610
- export function getTextureFormatBytesPerPixel(format: TextureFormat): number {
611
- // TODO remove webgl1 support
612
- const params = getTextureFormatWebGL(format);
613
- // NOTE(Tarek): Default to RGBA bytes
614
- const channels = DATA_FORMAT_CHANNELS[params.format] || 4;
615
- const channelSize = TYPE_SIZES[params.type] || 1;
616
- return channels * channelSize;
617
- }
618
-
619
- // DATA TYPE HELPERS
620
-
621
- export function getWebGLPixelDataFormat(
622
- dataFormat: string,
623
- integer: boolean,
624
- normalized: boolean,
625
- format: GL
626
- ): GLTexelDataFormat {
627
- // WebGL1 formats use same internalFormat
628
- if (format === GL.RGBA || format === GL.RGB) {
629
- return format;
630
- }
631
- // prettier-ignore
632
- switch (dataFormat) {
633
- case 'r': return integer && !normalized ? GL.RED_INTEGER : GL.RED;
634
- case 'rg': return integer && !normalized ? GL.RG_INTEGER : GL.RG;
635
- case 'rgb': return integer && !normalized ? GL.RGB_INTEGER : GL.RGB;
636
- case 'rgba': return integer && !normalized ? GL.RGBA_INTEGER : GL.RGBA;
637
- default: return GL.RGBA;
638
- }
639
- }
640
-
641
- /**
642
- * Map WebGPU style texture format strings to GL constants
643
- */
644
- function convertTextureFormatToGL(format: TextureFormat): GL | undefined {
645
- const formatInfo = TEXTURE_FORMATS[format];
646
- const webglFormat = formatInfo?.gl;
647
- if (webglFormat === undefined) {
648
- throw new Error(`Unsupported texture format ${format}`);
649
- }
650
- return webglFormat;
651
- }
652
-
653
- /**
654
- * Map WebGL texture formats (GL constants) to WebGPU-style TextureFormat strings
655
- export function convertGLToTextureFormat(format: GL | TextureFormat): TextureFormat {
656
- if (typeof format === 'string') {
657
- return format;
658
- }
659
- const entry = Object.entries(TEXTURE_FORMATS).find(([, entry]) => entry.gl === format);
660
- if (!entry) {
661
- throw new Error(`Unknown texture format ${format}`);
662
- }
663
- return entry[0] as TextureFormat;
664
- }
665
- */