@luma.gl/webgl 9.1.0-alpha.9 → 9.1.0-beta.3

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 (200) 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 +1 -0
  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 -2
  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 +96 -25
  39. package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
  40. package/dist/adapter/helpers/webgl-texture-utils.js +225 -236
  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 +70 -75
  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 +33 -18
  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 +44 -22
  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 +32 -20
  78. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  79. package/dist/adapter/resources/webgl-texture.js +163 -218
  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.map +1 -1
  86. package/dist/adapter/webgl-adapter.js +5 -10
  87. package/dist/adapter/webgl-adapter.js.map +1 -0
  88. package/dist/adapter/webgl-canvas-context.d.ts +4 -6
  89. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  90. package/dist/adapter/webgl-canvas-context.js +13 -17
  91. package/dist/adapter/webgl-canvas-context.js.map +1 -0
  92. package/dist/adapter/webgl-device.d.ts +20 -19
  93. package/dist/adapter/webgl-device.d.ts.map +1 -1
  94. package/dist/adapter/webgl-device.js +75 -51
  95. package/dist/adapter/webgl-device.js.map +1 -0
  96. package/dist/context/debug/spector-types.js +2 -1
  97. package/dist/context/debug/spector-types.js.map +1 -0
  98. package/dist/context/debug/spector.d.ts +5 -5
  99. package/dist/context/debug/spector.d.ts.map +1 -1
  100. package/dist/context/debug/spector.js +7 -6
  101. package/dist/context/debug/spector.js.map +1 -0
  102. package/dist/context/debug/webgl-developer-tools.d.ts +2 -3
  103. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  104. package/dist/context/debug/webgl-developer-tools.js +7 -19
  105. package/dist/context/debug/webgl-developer-tools.js.map +1 -0
  106. package/dist/context/helpers/create-browser-context.d.ts +6 -22
  107. package/dist/context/helpers/create-browser-context.d.ts.map +1 -1
  108. package/dist/context/helpers/create-browser-context.js +41 -32
  109. package/dist/context/helpers/create-browser-context.js.map +1 -0
  110. package/dist/context/helpers/webgl-context-data.js +1 -0
  111. package/dist/context/helpers/webgl-context-data.js.map +1 -0
  112. package/dist/context/helpers/webgl-extensions.js +1 -0
  113. package/dist/context/helpers/webgl-extensions.js.map +1 -0
  114. package/dist/context/parameters/unified-parameter-api.js +1 -0
  115. package/dist/context/parameters/unified-parameter-api.js.map +1 -0
  116. package/dist/context/parameters/webgl-parameter-tables.d.ts +1 -1
  117. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  118. package/dist/context/parameters/webgl-parameter-tables.js +3 -2
  119. package/dist/context/parameters/webgl-parameter-tables.js.map +1 -0
  120. package/dist/context/polyfills/polyfill-webgl1-extensions.js +1 -0
  121. package/dist/context/polyfills/polyfill-webgl1-extensions.js.map +1 -0
  122. package/dist/context/state-tracker/deep-array-equal.js +1 -0
  123. package/dist/context/state-tracker/deep-array-equal.js.map +1 -0
  124. package/dist/context/state-tracker/webgl-state-tracker.js +1 -0
  125. package/dist/context/state-tracker/webgl-state-tracker.js.map +1 -0
  126. package/dist/context/state-tracker/with-parameters.js +1 -0
  127. package/dist/context/state-tracker/with-parameters.js.map +1 -0
  128. package/dist/deprecated/accessor.d.ts.map +1 -0
  129. package/dist/{classic → deprecated}/accessor.js +37 -1
  130. package/dist/deprecated/accessor.js.map +1 -0
  131. package/dist/dist.dev.js +2234 -2373
  132. package/dist/dist.min.js +2 -2
  133. package/dist/index.cjs +2124 -2256
  134. package/dist/index.cjs.map +4 -4
  135. package/dist/index.d.ts +2 -3
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/index.js +3 -4
  138. package/dist/index.js.map +1 -0
  139. package/dist/types.js +1 -0
  140. package/dist/types.js.map +1 -0
  141. package/dist/utils/fill-array.d.ts +4 -4
  142. package/dist/utils/fill-array.d.ts.map +1 -1
  143. package/dist/utils/fill-array.js +1 -0
  144. package/dist/utils/fill-array.js.map +1 -0
  145. package/dist/utils/load-script.js +1 -0
  146. package/dist/utils/load-script.js.map +1 -0
  147. package/dist/utils/split-uniforms-and-bindings.d.ts +1 -1
  148. package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -1
  149. package/dist/utils/split-uniforms-and-bindings.js +1 -0
  150. package/dist/utils/split-uniforms-and-bindings.js.map +1 -0
  151. package/dist/utils/uid.js +1 -0
  152. package/dist/utils/uid.js.map +1 -0
  153. package/package.json +5 -5
  154. package/src/adapter/converters/device-parameters.ts +3 -3
  155. package/src/adapter/converters/sampler-parameters.ts +6 -4
  156. package/src/adapter/converters/webgl-texture-table.ts +404 -0
  157. package/src/adapter/device-helpers/webgl-device-features.ts +5 -2
  158. package/src/{classic → adapter/helpers}/format-utils.ts +6 -0
  159. package/src/adapter/helpers/get-shader-layout.ts +7 -4
  160. package/src/adapter/helpers/webgl-texture-utils.ts +400 -57
  161. package/src/adapter/resources/webgl-buffer.ts +3 -1
  162. package/src/adapter/resources/webgl-command-buffer.ts +125 -41
  163. package/src/adapter/resources/webgl-command-encoder.ts +6 -0
  164. package/src/adapter/resources/webgl-external-texture.ts +14 -0
  165. package/src/adapter/resources/webgl-framebuffer.ts +79 -85
  166. package/src/adapter/resources/webgl-render-pass.ts +56 -42
  167. package/src/adapter/resources/webgl-render-pipeline.ts +56 -26
  168. package/src/adapter/resources/webgl-shader.ts +15 -7
  169. package/src/adapter/resources/webgl-texture.ts +188 -250
  170. package/src/adapter/webgl-adapter.ts +4 -12
  171. package/src/adapter/webgl-canvas-context.ts +16 -19
  172. package/src/adapter/webgl-device.ts +125 -88
  173. package/src/context/debug/spector-types.ts +1 -1
  174. package/src/context/debug/spector.ts +11 -11
  175. package/src/context/debug/webgl-developer-tools.ts +8 -31
  176. package/src/context/helpers/create-browser-context.ts +53 -63
  177. package/src/context/parameters/webgl-parameter-tables.ts +2 -2
  178. package/src/{classic → deprecated}/accessor.ts +44 -3
  179. package/src/index.ts +2 -5
  180. package/src/utils/fill-array.ts +4 -4
  181. package/src/utils/split-uniforms-and-bindings.ts +3 -3
  182. package/dist/adapter/converters/texture-formats.d.ts +0 -83
  183. package/dist/adapter/converters/texture-formats.d.ts.map +0 -1
  184. package/dist/adapter/converters/texture-formats.js +0 -511
  185. package/dist/classic/accessor.d.ts.map +0 -1
  186. package/dist/classic/clear.d.ts +0 -22
  187. package/dist/classic/clear.d.ts.map +0 -1
  188. package/dist/classic/clear.js +0 -86
  189. package/dist/classic/copy-and-blit.d.ts +0 -64
  190. package/dist/classic/copy-and-blit.d.ts.map +0 -1
  191. package/dist/classic/copy-and-blit.js +0 -194
  192. package/dist/classic/format-utils.d.ts.map +0 -1
  193. package/dist/classic/typed-array-utils.d.ts.map +0 -1
  194. package/src/adapter/converters/texture-formats.ts +0 -657
  195. package/src/classic/clear.ts +0 -115
  196. package/src/classic/copy-and-blit.ts +0 -323
  197. /package/dist/{classic → adapter/helpers}/format-utils.d.ts +0 -0
  198. /package/dist/{classic → adapter/helpers}/typed-array-utils.d.ts +0 -0
  199. /package/dist/{classic → deprecated}/accessor.d.ts +0 -0
  200. /package/src/{classic → adapter/helpers}/typed-array-utils.ts +0 -0
@@ -1,657 +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
- // 8-bit formats
145
- 'r8unorm': {gl: GL.R8, b: 1, c: 1, rb: true},
146
- 'r8snorm': {gl: GL.R8_SNORM, b: 1, c: 1, render: snorm8_renderable},
147
- 'r8uint': {gl: GL.R8UI, b: 1, c: 1, rb: true},
148
- 'r8sint': {gl: GL.R8I, b: 1, c: 1, rb: true},
149
-
150
- // 16-bit formats
151
- 'rg8unorm': {gl: GL.RG8, b: 2, c: 2, rb: true},
152
- 'rg8snorm': {gl: GL.RG8_SNORM, b: 2, c: 2, render: snorm8_renderable},
153
- 'rg8uint': {gl: GL.RG8UI, b: 2, c: 2, rb: true},
154
- 'rg8sint': {gl: GL.RG8I, b: 2, c: 2, rb: true},
155
-
156
- 'r16uint': {gl: GL.R16UI, b: 2, c: 1, rb: true},
157
- 'r16sint': {gl: GL.R16I, b: 2, c: 1, rb: true},
158
- 'r16float': {gl: GL.R16F, b: 2, c: 1, render: float16_renderable, filter: 'float16-filterable-webgl', rb: true},
159
- 'r16unorm-webgl': {gl: GL.R16_EXT, b:2, c:1, f: norm16_renderable, rb: true},
160
- 'r16snorm-webgl': {gl: GL.R16_SNORM_EXT, b:2, c:1, f: snorm16_renderable},
161
-
162
- // Packed 16-bit formats
163
- 'rgba4unorm-webgl': {gl: GL.RGBA4, b: 2, c: 4, wgpu: false, rb: true},
164
- 'rgb565unorm-webgl': {gl: GL.RGB565, b: 2, c: 4, wgpu: false, rb: true},
165
- 'rgb5a1unorm-webgl': {gl: GL.RGB5_A1, b: 2, c: 4, wgpu: false, rb: true},
166
-
167
- // 24-bit formats
168
- 'rgb8unorm-webgl': {gl: GL.RGB8, b: 3, c: 3, wgpu: false},
169
- 'rgb8snorm-webgl': {gl: GL.RGB8_SNORM, b: 3, c: 3, wgpu: false},
170
-
171
- // 32-bit formats
172
- 'rgba8unorm': {gl: GL.RGBA8, b: 4, c: 2, bpp: 4},
173
- 'rgba8unorm-srgb': {gl: GL.SRGB8_ALPHA8, b: 4, c: 4, bpp: 4},
174
- 'rgba8snorm': {gl: GL.RGBA8_SNORM, b: 4, c: 4, render: snorm8_renderable},
175
- 'rgba8uint': {gl: GL.RGBA8UI, b: 4, c: 4, bpp: 4},
176
- 'rgba8sint': {gl: GL.RGBA8I, b: 4, c: 4, bpp: 4},
177
- // reverse colors, webgpu only
178
- 'bgra8unorm': {b: 4, c: 4},
179
- 'bgra8unorm-srgb': {b: 4, c: 4},
180
-
181
- 'rg16uint': {gl: GL.RG16UI, b: 4, c: 1, bpp: 4},
182
- 'rg16sint': {gl: GL.RG16I, b: 4, c: 2, bpp: 4},
183
- 'rg16float': {gl: GL.RG16F, bpp: 4, b: 4, c: 2, render: float16_renderable, filter: float16_filterable, rb: true},
184
- 'rg16unorm-webgl': {gl: GL.RG16_EXT, b:2, c:2, render: norm16_renderable},
185
- 'rg16snorm-webgl': {gl: GL.RG16_SNORM_EXT, b:2, c:2, render: snorm16_renderable},
186
-
187
- 'r32uint': {gl: GL.R32UI, b: 4, c: 1, bpp: 4, rb: true},
188
- 'r32sint': {gl: GL.R32I, b: 4, c: 1, bpp: 4, rb: true},
189
- 'r32float': {gl: GL.R32F, bpp: 4, b: 4, c: 1, render: float32_renderable, filter: float32_filterable},
190
-
191
- // Packed 32-bit formats
192
- 'rgb9e5ufloat': {gl: GL.RGB9_E5, b: 4, c: 3, p: 1, render: rgb9e5ufloat_renderable}, // , filter: true},
193
- 'rg11b10ufloat': {gl: GL.R11F_G11F_B10F, b: 4, c: 3, p: 1,render: float32_renderable, rb: true},
194
- 'rgb10a2unorm': {gl: GL.RGB10_A2, b: 4, c: 4, p: 1, rb: true},
195
- 'rgb10a2uint-webgl': {b: 4, c: 4, gl: GL.RGB10_A2UI, p: 1, wgpu: false, bpp: 4, rb: true},
196
-
197
- // 48-bit formats
198
- 'rgb16unorm-webgl': {gl: GL.RGB16_EXT, b:2, c:3, f: norm16_renderable}, // rgb not renderable
199
- 'rgb16snorm-webgl': {gl: GL.RGB16_SNORM_EXT, b:2, c:3, f: norm16_renderable}, // rgb not renderable
200
-
201
- // 64-bit formats
202
- 'rg32uint': {gl: GL.RG32UI, b: 8, c: 2, rb: true},
203
- 'rg32sint': {gl: GL.RG32I, b: 8, c: 2, rb: true},
204
- 'rg32float': {gl: GL.RG32F, b: 8, c: 2, render: float32_renderable, filter: float32_filterable, rb: true},
205
- 'rgba16uint': {gl: GL.RGBA16UI, b: 8, c: 4, rb: true},
206
- 'rgba16sint': {gl: GL.RGBA16I, b: 8, c: 4, rb: true},
207
- 'rgba16float': {gl: GL.RGBA16F, b: 8, c: 4, render: float16_renderable, filter: float16_filterable},
208
- 'rgba16unorm-webgl': {gl: GL.RGBA16_EXT, b:2, c:4, render: norm16_renderable, rb: true},
209
- 'rgba16snorm-webgl': {gl: GL.RGBA16_SNORM_EXT, b:2, c:4, render: snorm16_renderable},
210
-
211
- // 96-bit formats (deprecated!)
212
- 'rgb32float-webgl': {gl: GL.RGB32F, render: float32_renderable, filter: float32_filterable,
213
- gl2ext: EXT_color_buffer_float, dataFormat: GL.RGB, types: [GL.FLOAT]},
214
-
215
- // 128-bit formats
216
- 'rgba32uint': {gl: GL.RGBA32UI, b: 16, c: 4, rb: true},
217
- 'rgba32sint': {gl: GL.RGBA32I, b: 16, c: 4, rb: true},
218
- 'rgba32float': {gl: GL.RGBA32F, b: 16, c: 4, render: float32_renderable, filter: float32_filterable, rb: true},
219
-
220
- // Depth and stencil formats
221
- 'stencil8': {gl: GL.STENCIL_INDEX8, b: 1, c: 1, attachment: GL.STENCIL_ATTACHMENT, rb: true}, // 8 stencil bits
222
-
223
- 'depth16unorm': {gl: GL.DEPTH_COMPONENT16, b: 2, c: 1, attachment: GL.DEPTH_ATTACHMENT,
224
- dataFormat: GL.DEPTH_COMPONENT, types: [GL.UNSIGNED_SHORT], rb: true}, // 16 depth bits
225
- 'depth24plus': {gl: GL.DEPTH_COMPONENT24, b: 3, c: 1, attachment: GL.DEPTH_ATTACHMENT,
226
- dataFormat: GL.DEPTH_COMPONENT, types: [GL.UNSIGNED_INT]},
227
- 'depth32float': {gl: GL.DEPTH_COMPONENT32F, b: 4, c: 1, attachment: GL.DEPTH_ATTACHMENT,
228
- dataFormat: GL.DEPTH_COMPONENT, types: [GL.FLOAT], rb: true},
229
-
230
- // The depth component of the "depth24plus" and "depth24plus-stencil8" formats may be implemented as either a 24-bit depth value or a "depth32float" value.
231
- 'depth24plus-stencil8': {gl: GL.DEPTH24_STENCIL8, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, rb: true, depthTexture: true,
232
- dataFormat: GL.DEPTH_STENCIL, types: [GL.UNSIGNED_INT_24_8]},
233
- // "depth32float-stencil8" feature - TODO below is render buffer only?
234
- 'depth32float-stencil8': {gl: GL.DEPTH32F_STENCIL8, b: 5, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT,
235
- dataFormat: GL.DEPTH_STENCIL, types: [GL.FLOAT_32_UNSIGNED_INT_24_8_REV], rb: true},
236
-
237
- // BC compressed formats: check device.features.has("texture-compression-bc");
238
-
239
- 'bc1-rgb-unorm-webgl': {gl: GL.COMPRESSED_RGB_S3TC_DXT1_EXT, x: X_S3TC, f: texture_compression_bc},
240
- 'bc1-rgb-unorm-srgb-webgl': {gl: GL.COMPRESSED_SRGB_S3TC_DXT1_EXT, x: X_S3TC_SRGB, f: texture_compression_bc},
241
-
242
- 'bc1-rgba-unorm': {gl: GL.COMPRESSED_RGBA_S3TC_DXT1_EXT, x: X_S3TC, f: texture_compression_bc},
243
- 'bc1-rgba-unorm-srgb': {gl: GL.COMPRESSED_SRGB_S3TC_DXT1_EXT, x: X_S3TC_SRGB, f: texture_compression_bc},
244
- 'bc2-rgba-unorm': {gl: GL.COMPRESSED_RGBA_S3TC_DXT3_EXT, x: X_S3TC, f: texture_compression_bc},
245
- 'bc2-rgba-unorm-srgb': {gl: GL.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, x: X_S3TC_SRGB, f: texture_compression_bc},
246
- 'bc3-rgba-unorm': {gl: GL.COMPRESSED_RGBA_S3TC_DXT5_EXT, x: X_S3TC, f: texture_compression_bc},
247
- 'bc3-rgba-unorm-srgb': {gl: GL.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, x: X_S3TC_SRGB, f: texture_compression_bc},
248
- 'bc4-r-unorm': {gl: GL.COMPRESSED_RED_RGTC1_EXT, x: X_RGTC, f: texture_compression_bc},
249
- 'bc4-r-snorm': {gl: GL.COMPRESSED_SIGNED_RED_RGTC1_EXT, x: X_RGTC, f: texture_compression_bc},
250
- 'bc5-rg-unorm': {gl: GL.COMPRESSED_RED_GREEN_RGTC2_EXT, x: X_RGTC, f: texture_compression_bc},
251
- 'bc5-rg-snorm': {gl: GL.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, x: X_RGTC, f: texture_compression_bc},
252
- 'bc6h-rgb-ufloat': {gl: GL.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, x: X_BPTC, f: texture_compression_bc},
253
- 'bc6h-rgb-float': {gl: GL.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, x: X_BPTC, f: texture_compression_bc},
254
- 'bc7-rgba-unorm': {gl: GL.COMPRESSED_RGBA_BPTC_UNORM_EXT, x: X_BPTC, f: texture_compression_bc},
255
- 'bc7-rgba-unorm-srgb': {gl: GL.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, x: X_BPTC, f: texture_compression_bc},
256
-
257
- // WEBGL_compressed_texture_etc: device.features.has("texture-compression-etc2")
258
- // Note: Supposedly guaranteed availability compressed formats in WebGL2, but through CPU decompression
259
-
260
- 'etc2-rgb8unorm': {gl: GL.COMPRESSED_RGB8_ETC2, f: texture_compression_etc2},
261
- 'etc2-rgb8unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ETC2, f: texture_compression_etc2},
262
- 'etc2-rgb8a1unorm': {gl: GL.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, f: texture_compression_etc2},
263
- 'etc2-rgb8a1unorm-srgb': {gl: GL.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, f: texture_compression_etc2},
264
- 'etc2-rgba8unorm': {gl: GL.COMPRESSED_RGBA8_ETC2_EAC, f: texture_compression_etc2},
265
- 'etc2-rgba8unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, f: texture_compression_etc2},
266
-
267
- 'eac-r11unorm': {gl: GL.COMPRESSED_R11_EAC, f: texture_compression_etc2},
268
- 'eac-r11snorm': {gl: GL.COMPRESSED_SIGNED_R11_EAC, f: texture_compression_etc2},
269
- 'eac-rg11unorm': {gl: GL.COMPRESSED_RG11_EAC, f: texture_compression_etc2},
270
- 'eac-rg11snorm': {gl: GL.COMPRESSED_SIGNED_RG11_EAC, f: texture_compression_etc2},
271
-
272
- // X_ASTC compressed formats: device.features.has("texture-compression-astc")
273
-
274
- 'astc-4x4-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_4x4_KHR, f: texture_compression_astc},
275
- 'astc-4x4-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, f: texture_compression_astc},
276
- 'astc-5x4-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_5x4_KHR, f: texture_compression_astc},
277
- 'astc-5x4-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, f: texture_compression_astc},
278
- 'astc-5x5-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_5x5_KHR, f: texture_compression_astc},
279
- 'astc-5x5-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, f: texture_compression_astc},
280
- 'astc-6x5-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_6x5_KHR, f: texture_compression_astc},
281
- 'astc-6x5-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, f: texture_compression_astc},
282
- 'astc-6x6-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_6x6_KHR, f: texture_compression_astc},
283
- 'astc-6x6-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, f: texture_compression_astc},
284
- 'astc-8x5-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_8x5_KHR, f: texture_compression_astc},
285
- 'astc-8x5-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, f: texture_compression_astc},
286
- 'astc-8x6-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_8x6_KHR, f: texture_compression_astc},
287
- 'astc-8x6-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, f: texture_compression_astc},
288
- 'astc-8x8-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_8x8_KHR, f: texture_compression_astc},
289
- 'astc-8x8-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, f: texture_compression_astc},
290
- 'astc-10x5-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_10x10_KHR, f: texture_compression_astc},
291
- 'astc-10x5-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, f: texture_compression_astc},
292
- 'astc-10x6-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_10x6_KHR, f: texture_compression_astc},
293
- 'astc-10x6-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, f: texture_compression_astc},
294
- 'astc-10x8-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_10x8_KHR, f: texture_compression_astc},
295
- 'astc-10x8-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, f: texture_compression_astc},
296
- 'astc-10x10-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_10x10_KHR, f: texture_compression_astc},
297
- 'astc-10x10-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, f: texture_compression_astc},
298
- 'astc-12x10-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_12x10_KHR, f: texture_compression_astc},
299
- 'astc-12x10-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, f: texture_compression_astc},
300
- 'astc-12x12-unorm': {gl: GL.COMPRESSED_RGBA_ASTC_12x12_KHR, f: texture_compression_astc},
301
- 'astc-12x12-unorm-srgb': {gl: GL.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, f: texture_compression_astc},
302
-
303
- // WEBGL_compressed_texture_pvrtc
304
-
305
- 'pvrtc-rgb4unorm-webgl': {gl: GL.COMPRESSED_RGB_PVRTC_4BPPV1_IMG, f: texture_compression_pvrtc_webgl},
306
- 'pvrtc-rgba4unorm-webgl': {gl: GL.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, f: texture_compression_pvrtc_webgl},
307
- 'pvrtc-rbg2unorm-webgl': {gl: GL.COMPRESSED_RGB_PVRTC_2BPPV1_IMG, f: texture_compression_pvrtc_webgl},
308
- 'pvrtc-rgba2unorm-webgl': {gl: GL.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, f: texture_compression_pvrtc_webgl},
309
-
310
- // WEBGL_compressed_texture_etc1
311
-
312
- 'etc1-rbg-unorm-webgl': {gl: GL.COMPRESSED_RGB_ETC1_WEBGL, f: texture_compression_etc1_webgl},
313
-
314
- // WEBGL_compressed_texture_atc
315
-
316
- 'atc-rgb-unorm-webgl': {gl: GL.COMPRESSED_RGB_ATC_WEBGL, f: texture_compression_atc_webgl},
317
- 'atc-rgba-unorm-webgl': {gl: GL.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL, f: texture_compression_atc_webgl},
318
- 'atc-rgbai-unorm-webgl': {gl: GL.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL, f: texture_compression_atc_webgl}
319
- };
320
-
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
- /** @deprecated should be removed */
416
- const DATA_FORMAT_CHANNELS = {
417
- [GL.RED]: 1,
418
- [GL.RED_INTEGER]: 1,
419
- [GL.RG]: 2,
420
- [GL.RG_INTEGER]: 2,
421
- [GL.RGB]: 3,
422
- [GL.RGB_INTEGER]: 3,
423
- [GL.RGBA]: 4,
424
- [GL.RGBA_INTEGER]: 4,
425
- [GL.DEPTH_COMPONENT]: 1,
426
- [GL.DEPTH_STENCIL]: 1,
427
- [GL.ALPHA]: 1,
428
- [GL.LUMINANCE]: 1,
429
- [GL.LUMINANCE_ALPHA]: 2
430
- };
431
-
432
- /** @deprecated should be removed */
433
- const TYPE_SIZES = {
434
- [GL.FLOAT]: 4,
435
- [GL.UNSIGNED_INT]: 4,
436
- [GL.INT]: 4,
437
- [GL.UNSIGNED_SHORT]: 2,
438
- [GL.SHORT]: 2,
439
- [GL.HALF_FLOAT]: 2,
440
- [GL.BYTE]: 1,
441
- [GL.UNSIGNED_BYTE]: 1
442
- };
443
-
444
- // FUNCTIONS
445
-
446
- /** Checks if a texture format is supported */
447
- export function isTextureFormatSupported(
448
- gl: WebGL2RenderingContext,
449
- format: TextureFormat,
450
- extensions: GLExtensions
451
- ): boolean {
452
- const info = TEXTURE_FORMATS[format];
453
- if (!info) {
454
- return false;
455
- }
456
- // Check that we have a GL constant
457
- if (info.gl === undefined) {
458
- return false;
459
- }
460
- const feature = info.f;
461
- if (feature) {
462
- return checkTextureFeature(gl, feature, extensions);
463
- }
464
- // Check extensions
465
- const extension = info.x || info.gl2ext;
466
- if (extension) {
467
- return Boolean(getWebGLExtension(gl, extension, extensions));
468
- }
469
- return true;
470
- }
471
-
472
- export function isRenderbufferFormatSupported(
473
- gl: WebGL2RenderingContext,
474
- format: TextureFormat,
475
- extensions: GLExtensions
476
- ): boolean {
477
- // Note: Order is important since the function call initializes extensions.
478
- return isTextureFormatSupported(gl, format, extensions) && Boolean(TEXTURE_FORMATS[format]?.rb);
479
- }
480
-
481
- /** Checks if a texture format is supported */
482
- export function getTextureFormatSupport(
483
- gl: WebGL2RenderingContext,
484
- format: TextureFormat,
485
- extensions: GLExtensions
486
- ): {
487
- supported: boolean;
488
- filterable?: boolean;
489
- renderable?: boolean;
490
- blendable?: boolean;
491
- storable?: boolean;
492
- } {
493
- const info = TEXTURE_FORMATS[format];
494
- if (!info) {
495
- return {supported: false};
496
- }
497
- // let decoded;
498
- // try {
499
- // decoded = decodeTextureFormat(format);
500
- // } catch {}
501
-
502
- // Support Check that we have a GL constant
503
- let supported = info.gl === undefined;
504
- supported = supported && checkTextureFeature(gl, info.f, extensions);
505
-
506
- // Filtering
507
- // const filterable = info.filter
508
- // ? checkTextureFeature(gl, infofilter])
509
- // : decoded && !decoded.signed;
510
- // const renderable = info.filter
511
- // ? checkTextureFeature(gl, inforender])
512
- // : decoded && !decoded.signed;
513
-
514
- return {
515
- supported,
516
- renderable: supported && checkTextureFeature(gl, info.render, extensions),
517
- filterable: supported && checkTextureFeature(gl, info.filter, extensions),
518
- blendable: false, // tod,
519
- storable: false
520
- };
521
- }
522
-
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
- /** Get parameters necessary to work with format in WebGL: internalFormat, dataFormat, type, compressed, */
568
- export function getTextureFormatWebGL(format: TextureFormat): {
569
- internalFormat: GL;
570
- format: GLTexelDataFormat;
571
- type: GLPixelType;
572
- compressed: boolean;
573
- } {
574
- const formatData = TEXTURE_FORMATS[format];
575
- const webglFormat = convertTextureFormatToGL(format);
576
- const decoded = decodeTextureFormat(format);
577
- return {
578
- internalFormat: webglFormat,
579
- format:
580
- formatData?.dataFormat ||
581
- getWebGLPixelDataFormat(decoded.channels, decoded.integer, decoded.normalized, webglFormat),
582
- // depth formats don't have a type
583
- type: decoded.dataType
584
- ? getGLFromVertexType(decoded.dataType)
585
- : formatData?.types?.[0] || GL.UNSIGNED_BYTE,
586
- compressed: decoded.compressed || false
587
- };
588
- }
589
-
590
- export function getDepthStencilAttachmentWebGL(
591
- format: TextureFormat
592
- ): GL.DEPTH_ATTACHMENT | GL.STENCIL_ATTACHMENT | GL.DEPTH_STENCIL_ATTACHMENT {
593
- const info = TEXTURE_FORMATS[format];
594
- if (!info?.attachment) {
595
- throw new Error(`${format} is not a depth stencil format`);
596
- }
597
- return info.attachment;
598
- }
599
-
600
- /** TODO - VERY roundabout legacy way of calculating bytes per pixel */
601
- export function getTextureFormatBytesPerPixel(format: TextureFormat): number {
602
- // TODO remove webgl1 support
603
- const params = getTextureFormatWebGL(format);
604
- // NOTE(Tarek): Default to RGBA bytes
605
- const channels = DATA_FORMAT_CHANNELS[params.format] || 4;
606
- const channelSize = TYPE_SIZES[params.type] || 1;
607
- return channels * channelSize;
608
- }
609
-
610
- // DATA TYPE HELPERS
611
-
612
- export function getWebGLPixelDataFormat(
613
- channels: 'r' | 'rg' | 'rgb' | 'rgba' | 'bgra',
614
- integer: boolean,
615
- normalized: boolean,
616
- format: GL
617
- ): GLTexelDataFormat {
618
- // WebGL1 formats use same internalFormat
619
- if (format === GL.RGBA || format === GL.RGB) {
620
- return format;
621
- }
622
- // prettier-ignore
623
- switch (channels) {
624
- case 'r': return integer && !normalized ? GL.RED_INTEGER : GL.RED;
625
- case 'rg': return integer && !normalized ? GL.RG_INTEGER : GL.RG;
626
- case 'rgb': return integer && !normalized ? GL.RGB_INTEGER : GL.RGB;
627
- case 'rgba': return integer && !normalized ? GL.RGBA_INTEGER : GL.RGBA;
628
- case 'bgra': throw new Error('bgra pixels not supported by WebGL');
629
- default: return GL.RGBA;
630
- }
631
- }
632
-
633
- /**
634
- * Map WebGPU style texture format strings to GL constants
635
- */
636
- function convertTextureFormatToGL(format: TextureFormat): GL | undefined {
637
- const formatInfo = TEXTURE_FORMATS[format];
638
- const webglFormat = formatInfo?.gl;
639
- if (webglFormat === undefined) {
640
- throw new Error(`Unsupported texture format ${format}`);
641
- }
642
- return webglFormat;
643
- }
644
-
645
- /**
646
- * Map WebGL texture formats (GL constants) to WebGPU-style TextureFormat strings
647
- export function convertGLToTextureFormat(format: GL | TextureFormat): TextureFormat {
648
- if (typeof format === 'string') {
649
- return format;
650
- }
651
- const entry = Object.entries(TEXTURE_FORMATS).find(([, entry]) => entry.gl === format);
652
- if (!entry) {
653
- throw new Error(`Unknown texture format ${format}`);
654
- }
655
- return entry[0] as TextureFormat;
656
- }
657
- */