@luma.gl/webgl 9.0.0-alpha.21 → 9.0.0-alpha.24

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 (165) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts +1 -1
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +9 -9
  4. package/dist/adapter/converters/device-parameters.js.map +1 -1
  5. package/dist/adapter/converters/sampler-parameters.d.ts +1 -1
  6. package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
  7. package/dist/adapter/converters/sampler-parameters.js +1 -1
  8. package/dist/adapter/converters/sampler-parameters.js.map +1 -1
  9. package/dist/adapter/converters/texture-formats.d.ts +29 -40
  10. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  11. package/dist/adapter/converters/texture-formats.js +152 -114
  12. package/dist/adapter/converters/texture-formats.js.map +1 -1
  13. package/dist/adapter/device-helpers/device-limits.d.ts +1 -1
  14. package/dist/adapter/device-helpers/device-limits.d.ts.map +1 -1
  15. package/dist/adapter/helpers/attribute-utils.d.ts +1 -1
  16. package/dist/adapter/helpers/attribute-utils.d.ts.map +1 -1
  17. package/dist/adapter/helpers/attribute-utils.js +1 -1
  18. package/dist/adapter/helpers/attribute-utils.js.map +1 -1
  19. package/dist/adapter/helpers/get-shader-info.d.ts +1 -1
  20. package/dist/adapter/helpers/get-shader-info.d.ts.map +1 -1
  21. package/dist/adapter/helpers/get-shader-info.js.map +1 -1
  22. package/dist/adapter/helpers/uniforms.d.ts +7 -8
  23. package/dist/adapter/helpers/uniforms.d.ts.map +1 -1
  24. package/dist/adapter/helpers/uniforms.js +4 -4
  25. package/dist/adapter/helpers/uniforms.js.map +1 -1
  26. package/dist/adapter/objects/constants-to-keys.d.ts +0 -2
  27. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  28. package/dist/adapter/objects/constants-to-keys.js +0 -20
  29. package/dist/adapter/objects/constants-to-keys.js.map +1 -1
  30. package/dist/adapter/objects/webgl-renderbuffer.d.ts +12 -9
  31. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
  32. package/dist/adapter/objects/webgl-renderbuffer.js +29 -19
  33. package/dist/adapter/objects/webgl-renderbuffer.js.map +1 -1
  34. package/dist/adapter/objects/webgl-resource.d.ts +0 -1
  35. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  36. package/dist/adapter/objects/webgl-resource.js +4 -7
  37. package/dist/adapter/objects/webgl-resource.js.map +1 -1
  38. package/dist/adapter/objects/webgl-vertex-array-object.d.ts +1 -1
  39. package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +1 -1
  40. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  41. package/dist/adapter/resources/webgl-buffer.js +3 -2
  42. package/dist/adapter/resources/webgl-buffer.js.map +1 -1
  43. package/dist/adapter/resources/webgl-command-buffer.d.ts +13 -7
  44. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  45. package/dist/adapter/resources/webgl-command-buffer.js +168 -25
  46. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  47. package/dist/adapter/resources/webgl-command-encoder.d.ts +3 -2
  48. package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
  49. package/dist/adapter/resources/webgl-command-encoder.js +6 -2
  50. package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
  51. package/dist/adapter/resources/webgl-framebuffer.d.ts +11 -14
  52. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  53. package/dist/adapter/resources/webgl-framebuffer.js +29 -79
  54. package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
  55. package/dist/adapter/resources/webgl-render-pass.d.ts +16 -1
  56. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  57. package/dist/adapter/resources/webgl-render-pass.js +80 -0
  58. package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
  59. package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -1
  60. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  61. package/dist/adapter/resources/webgl-render-pipeline.js +5 -5
  62. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  63. package/dist/adapter/resources/webgl-sampler.d.ts +1 -1
  64. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  65. package/dist/adapter/resources/webgl-sampler.js +1 -1
  66. package/dist/adapter/resources/webgl-sampler.js.map +1 -1
  67. package/dist/adapter/resources/webgl-texture.d.ts +43 -23
  68. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  69. package/dist/adapter/resources/webgl-texture.js +32 -30
  70. package/dist/adapter/resources/webgl-texture.js.map +1 -1
  71. package/dist/adapter/webgl-canvas-context.d.ts +1 -2
  72. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  73. package/dist/adapter/webgl-canvas-context.js.map +1 -1
  74. package/dist/adapter/webgl-device.d.ts +13 -6
  75. package/dist/adapter/webgl-device.d.ts.map +1 -1
  76. package/dist/adapter/webgl-device.js +20 -2
  77. package/dist/adapter/webgl-device.js.map +1 -1
  78. package/dist/classic/buffer.d.ts +1 -2
  79. package/dist/classic/buffer.d.ts.map +1 -1
  80. package/dist/classic/buffer.js +0 -6
  81. package/dist/classic/buffer.js.map +1 -1
  82. package/dist/classic/clear.d.ts +22 -0
  83. package/dist/classic/clear.d.ts.map +1 -0
  84. package/dist/classic/clear.js +88 -0
  85. package/dist/classic/clear.js.map +1 -0
  86. package/dist/classic/copy-and-blit.d.ts +45 -0
  87. package/dist/classic/copy-and-blit.d.ts.map +1 -0
  88. package/dist/classic/copy-and-blit.js +136 -0
  89. package/dist/classic/copy-and-blit.js.map +1 -0
  90. package/dist/classic/format-utils.d.ts +3 -0
  91. package/dist/classic/format-utils.d.ts.map +1 -0
  92. package/dist/classic/format-utils.js +38 -0
  93. package/dist/classic/format-utils.js.map +1 -0
  94. package/dist/classic/typed-array-utils.d.ts +15 -17
  95. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  96. package/dist/classic/typed-array-utils.js +1 -1
  97. package/dist/classic/typed-array-utils.js.map +1 -1
  98. package/dist/context/context/create-browser-context.d.ts +17 -19
  99. package/dist/context/context/create-browser-context.d.ts.map +1 -1
  100. package/dist/context/context/create-browser-context.js +4 -4
  101. package/dist/context/context/create-browser-context.js.map +1 -1
  102. package/dist/context/context/create-headless-context.d.ts +1 -1
  103. package/dist/context/context/create-headless-context.d.ts.map +1 -1
  104. package/dist/context/debug/spector.d.ts +1 -3
  105. package/dist/context/debug/spector.d.ts.map +1 -1
  106. package/dist/context/debug/webgl-developer-tools.d.ts +1 -1
  107. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  108. package/dist/context/parameters/unified-parameter-api.d.ts +1 -1
  109. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  110. package/dist/context/parameters/unified-parameter-api.js.map +1 -1
  111. package/dist/context/parameters/webgl-parameter-tables.d.ts +2 -3
  112. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  113. package/dist/context/parameters/webgl-parameter-tables.js +1 -1
  114. package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
  115. package/dist/dist.dev.js +1306 -659
  116. package/dist/index.cjs +1269 -897
  117. package/dist/index.d.ts +5 -2
  118. package/dist/index.d.ts.map +1 -1
  119. package/dist/index.js +4 -1
  120. package/dist/index.js.map +1 -1
  121. package/dist/types.d.ts +1 -1
  122. package/dist/types.d.ts.map +1 -1
  123. package/dist.min.js +22 -21
  124. package/package.json +7 -4
  125. package/src/adapter/converters/device-parameters.ts +46 -22
  126. package/src/adapter/converters/sampler-parameters.ts +1 -2
  127. package/src/adapter/converters/texture-formats.ts +242 -161
  128. package/src/adapter/helpers/attribute-utils.ts +1 -2
  129. package/src/adapter/helpers/get-shader-info.ts +3 -0
  130. package/src/adapter/helpers/uniforms.ts +9 -10
  131. package/src/adapter/objects/constants-to-keys.ts +0 -25
  132. package/src/adapter/objects/webgl-renderbuffer.ts +32 -29
  133. package/src/adapter/objects/webgl-resource.ts +4 -8
  134. package/src/adapter/resources/webgl-buffer.ts +4 -5
  135. package/src/adapter/resources/webgl-command-buffer.ts +328 -21
  136. package/src/adapter/resources/webgl-command-encoder.ts +7 -2
  137. package/src/adapter/resources/webgl-framebuffer.ts +63 -111
  138. package/src/adapter/resources/webgl-render-pass.ts +146 -2
  139. package/src/adapter/resources/webgl-render-pipeline.ts +7 -4
  140. package/src/adapter/resources/webgl-sampler.ts +1 -2
  141. package/src/adapter/resources/webgl-texture.ts +61 -43
  142. package/src/adapter/webgl-canvas-context.ts +2 -2
  143. package/src/adapter/webgl-device.ts +37 -8
  144. package/src/classic/buffer.ts +3 -3
  145. package/src/classic/clear.ts +110 -0
  146. package/src/classic/copy-and-blit.ts +189 -0
  147. package/src/classic/format-utils.ts +43 -0
  148. package/src/classic/typed-array-utils.ts +15 -26
  149. package/src/context/context/create-browser-context.ts +37 -30
  150. package/src/context/parameters/unified-parameter-api.ts +1 -1
  151. package/src/context/parameters/webgl-parameter-tables.ts +2 -2
  152. package/src/index.ts +10 -3
  153. package/dist/adapter/converters/renderbuffer-formats.d.ts +0 -16
  154. package/dist/adapter/converters/renderbuffer-formats.d.ts.map +0 -1
  155. package/dist/adapter/converters/renderbuffer-formats.js +0 -180
  156. package/dist/adapter/converters/renderbuffer-formats.js.map +0 -1
  157. package/dist/types/webgl.d.ts +0 -145
  158. package/dist/types/webgl.d.ts.map +0 -1
  159. package/dist/types/webgl.js +0 -2
  160. package/dist/types/webgl.js.map +0 -1
  161. package/src/.DS_Store +0 -0
  162. package/src/adapter/.DS_Store +0 -0
  163. package/src/adapter/converters/renderbuffer-formats.ts +0 -90
  164. package/src/context/.DS_Store +0 -0
  165. package/src/types/webgl.ts +0 -286
@@ -37,7 +37,7 @@ const EXT_FLOAT_RENDER_WEBGL2 = 'EXT_color_buffer_float';
37
37
  const checkExtension = (gl: WebGLRenderingContext, extension: string): boolean =>
38
38
  gl.getExtension(extension);
39
39
  const checkExtensions = (gl: WebGLRenderingContext, extensions: string[]): boolean =>
40
- extensions.every((extension) => gl.getExtension(extension));
40
+ extensions.every(extension => gl.getExtension(extension));
41
41
 
42
42
  // prettier-ignore
43
43
  const TEXTURE_FEATURE_CHECKS: Partial<Record<DeviceFeature, (gl: WebGLRenderingContext) => boolean> > = {
@@ -70,12 +70,12 @@ export function checkTextureFeature(gl: WebGLRenderingContext, feature: DeviceFe
70
70
  }
71
71
 
72
72
  const checkTextureFeatures = (gl: WebGLRenderingContext, features: DeviceFeature[]): boolean =>
73
- features.every((feature) => checkTextureFeature(gl, feature));
73
+ features.every(feature => checkTextureFeature(gl, feature));
74
74
 
75
75
  /** Return a list of texture feature strings (for Device.features). Mainly compressed texture support */
76
76
  export function getTextureFeatures(gl: WebGLRenderingContext): DeviceFeature[] {
77
77
  const textureFeatures = Object.keys(TEXTURE_FEATURE_CHECKS) as DeviceFeature[];
78
- return textureFeatures.filter((feature) => checkTextureFeature(gl, feature));
78
+ return textureFeatures.filter(feature => checkTextureFeature(gl, feature));
79
79
  }
80
80
 
81
81
  // TEXTURE FORMATS
@@ -86,60 +86,45 @@ type Format = {
86
86
  /** If a different unsized format is needed in WebGL1 */
87
87
  gl1?: GL;
88
88
  gl1ext?: string;
89
- gl2ext?: string; // format requires WebGL2, when using a WebGL 1 context, color renderbuffer formats are limited
89
+ /** format requires WebGL2, when using a WebGL 1 context, color renderbuffer formats are limited */
90
+ gl2ext?: string;
90
91
 
91
- b?: number; // (bytes per pixel), for memory usage calculations.
92
+ /** (bytes per pixel), for memory usage calculations. */
93
+ b?: number;
92
94
  /** channels */
93
95
  c?: number;
94
96
  bpp?: number;
95
97
  /** packed */
96
98
  p?: number;
97
- x?: string; // compressed
98
- f?: DeviceFeature; // for compressed texture formats
99
- render?: DeviceFeature; // renderable if extension is present
99
+ /** compressed */
100
+ x?: string;
101
+ /** for compressed texture formats */
102
+ f?: DeviceFeature;
103
+ /** renderable if feature is present */
104
+ render?: DeviceFeature;
105
+ /** filterable if feature is present */
100
106
  filter?: DeviceFeature;
101
107
 
102
- wgpu?: false; // If not supported on WebGPU
108
+ /** If not supported on WebGPU */
109
+ wgpu?: false;
103
110
 
104
111
  types?: number[];
105
112
 
106
113
  dataFormat?: GL;
114
+ /** Depth and stencil format attachment points. If set, needs to be a Renderbuffer unless depthTexture is set */
107
115
  attachment?: GL.DEPTH_ATTACHMENT | GL.STENCIL_ATTACHMENT | GL.DEPTH_STENCIL_ATTACHMENT;
116
+ /** if depthTexture is set this is a depth/stencil format that can be set to a texture */
117
+ depthTexture?: boolean;
118
+
119
+ renderbuffer?: boolean
108
120
  };
109
121
 
110
122
  // TABLES
111
123
 
112
- /** Legal combinations for internalFormat, format and type *
113
- // [GL.DEPTH_COMPONENT]: {types: [GL.UNSIGNED_SHORT, GL.UNSIGNED_INT, GL.UNSIGNED_INT_24_8], gl1ext: DEPTH},
114
- // [GL.DEPTH_STENCIL]: {gl1ext: DEPTH},
115
- // Sized texture format
116
- // R
117
- [GL.R8]: {dataFormat: GL.RED, types: [GL.UNSIGNED_BYTE], gl2: true},
118
- [GL.R16F]: {dataFormat: GL.RED, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
119
- [GL.R8UI]: {dataFormat: GL.RED_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
120
- // // RG
121
- [GL.RG8]: {dataFormat: GL.RG, types: [GL.UNSIGNED_BYTE], gl2: true},
122
- [GL.RG16F]: {dataFormat: GL.RG, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
123
- [GL.RG8UI]: {dataFormat: GL.RG_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
124
- // // RGB
125
- [GL.RGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
126
- [GL.SRGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true, gl1ext: EXT_SRGB},
127
- [GL.RGB16F]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true, gl1ext: EXT_HALF_FLOAT_WEBGL1},
128
- [GL.RGB8UI]: {dataFormat: GL.RGB_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
129
- // // RGBA
130
-
131
- [GL.RGB565]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5], gl2: true},
132
- [GL.R11F_G11F_B10F]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_INT_10F_11F_11F_REV, GL.HALF_FLOAT, GL.FLOAT], gl2: true},
133
- [GL.RGB9_E5]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true, gl1ext: EXT_HALF_FLOAT_WEBGL1},
134
- [GL.RGBA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true},
135
- [GL.SRGB8_ALPHA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true, gl1ext: EXT_SRGB},
136
- [GL.RGB5_A1]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_5_5_1], gl2: true},
137
- [GL.RGBA4]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4], gl2: true},
138
- [GL.RGBA16F]: {dataFormat: GL.RGBA, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true, gl1ext: EXT_HALF_FLOAT_WEBGL1},
139
- [GL.RGBA8UI]: {dataFormat: GL.RGBA_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true}
140
- */
141
-
142
- /** Texture format data */
124
+ /**
125
+ * Texture format data -
126
+ * Exported but can change without notice
127
+ */
143
128
  // prettier-ignore
144
129
  export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
145
130
  // Unsized formats that leave the precision up to the driver.
@@ -153,31 +138,31 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
153
138
  // 'rgba8unorm-srgb-unsized': {gl: GL.SRGB_ALPHA_EXT, b: 4, c: 2, bpp: 4, gl1Ext: SRGB},
154
139
 
155
140
  // 8-bit formats
156
- 'r8unorm': {gl: GL.R8, b: 1, c: 1},
141
+ 'r8unorm': {gl: GL.R8, b: 1, c: 1, renderbuffer: true},
157
142
  'r8snorm': {gl: GL.R8_SNORM, b: 1, c: 1},
158
- 'r8uint': {gl: GL.R8UI, b: 1, c: 1},
159
- 'r8sint': {gl: GL.R8I, b: 1, c: 1},
143
+ 'r8uint': {gl: GL.R8UI, b: 1, c: 1, renderbuffer: true},
144
+ 'r8sint': {gl: GL.R8I, b: 1, c: 1, renderbuffer: true},
160
145
 
161
146
  // 16-bit formats
162
- 'rg8unorm': {gl: GL.RG8, b: 2, c: 2},
147
+ 'rg8unorm': {gl: GL.RG8, b: 2, c: 2, renderbuffer: true},
163
148
  'rg8snorm': {gl: GL.RG8_SNORM, b: 2, c: 2},
164
- 'rg8uint': {gl: GL.RG8UI, b: 2, c: 2},
165
- 'rg8sint': {gl: GL.RG8I, b: 2, c: 2},
149
+ 'rg8uint': {gl: GL.RG8UI, b: 2, c: 2, renderbuffer: true},
150
+ 'rg8sint': {gl: GL.RG8I, b: 2, c: 2, renderbuffer: true},
166
151
 
167
- 'r16uint': {gl: GL.R16UI, b: 2, c: 1},
168
- 'r16sint': {gl: GL.R16I, b: 2, c: 1},
169
- 'r16float': {gl: GL.R16F, b: 2, c: 1, render: 'texture-renderable-float16-webgl', filter: 'texture-filter-linear-float16-webgl'},
170
- 'r16unorm-webgl': {gl: GL.R16_EXT, b:2, c:1, f: 'texture-formats-norm16-webgl'},
171
- 'r16snorm-webgl': {gl: GL.R16_SNORM_EXT, b:2, c:1, f: 'texture-formats-norm16-webgl'},
152
+ 'r16uint': {gl: GL.R16UI, b: 2, c: 1, renderbuffer: true},
153
+ 'r16sint': {gl: GL.R16I, b: 2, c: 1, renderbuffer: true},
154
+ 'r16float': {gl: GL.R16F, b: 2, c: 1, render: 'texture-renderable-float16-webgl', filter: 'texture-filter-linear-float16-webgl', renderbuffer: true},
155
+ 'r16unorm-webgl': {gl: GL.R16_EXT, b:2, c:1, f: 'texture-formats-norm16-webgl', renderbuffer: true, x: EXT_TEXTURE_NORM16},
156
+ 'r16snorm-webgl': {gl: GL.R16_SNORM_EXT, b:2, c:1, f: 'texture-formats-norm16-webgl', x: EXT_TEXTURE_NORM16},
172
157
 
173
158
  // Packed 16-bit formats
174
- 'rgba4unorm-webgl': {gl: GL.RGBA4, b: 2, c: 4, wgpu: false},
175
- 'rgb565unorm-webgl': {gl: GL.RGB565, b: 2, c: 4, wgpu: false},
176
- 'rgb5a1unorm-webgl': {gl: GL.RGB5_A1, b: 2, c: 4, wgpu: false},
159
+ 'rgba4unorm-webgl': {gl: GL.RGBA4, b: 2, c: 4, wgpu: false, renderbuffer: true},
160
+ 'rgb565unorm-webgl': {gl: GL.RGB565, b: 2, c: 4, wgpu: false, renderbuffer: true},
161
+ 'rgb5a1unorm-webgl': {gl: GL.RGB5_A1, b: 2, c: 4, wgpu: false, renderbuffer: true},
177
162
 
178
163
  // 24-bit formats
179
- 'rbg8unorm-webgl': {gl: GL.RGB8, b: 3, c: 3, wgpu: false},
180
- 'rbg8snorm-webgl': {gl: GL.RGB8_SNORM, b: 3, c: 3, wgpu: false},
164
+ 'rgb8unorm-webgl': {gl: GL.RGB8, b: 3, c: 3, wgpu: false},
165
+ 'rgb8snorm-webgl': {gl: GL.RGB8_SNORM, b: 3, c: 3, wgpu: false},
181
166
 
182
167
  // 32-bit formats
183
168
  'rgba8unorm': {gl: GL.RGBA8, gl1: GL.RGBA, b: 4, c: 2, bpp: 4},
@@ -192,34 +177,34 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
192
177
  'rg16uint': {gl: GL.RG16UI, b: 4, c: 1, bpp: 4},
193
178
  'rg16sint': {gl: GL.RG16I, b: 4, c: 2, bpp: 4},
194
179
  // When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
195
- 'rg16float': {gl: GL.RG16F, bpp: 4, b: 4, c: 2, render: 'texture-renderable-float16-webgl', filter: 'texture-filter-linear-float16-webgl'},
196
- 'rg16unorm-webgl': {gl: GL.RG16_EXT, b:2, c:2, f: 'texture-formats-norm16-webgl'},
197
- 'rg16snorm-webgl': {gl: GL.RG16_SNORM_EXT, b:2, c:2, f: 'texture-formats-norm16-webgl'},
180
+ 'rg16float': {gl: GL.RG16F, bpp: 4, b: 4, c: 2, render: 'texture-renderable-float16-webgl', filter: 'texture-filter-linear-float16-webgl', renderbuffer: true},
181
+ 'rg16unorm-webgl': {gl: GL.RG16_EXT, b:2, c:2, f: 'texture-formats-norm16-webgl', x: EXT_TEXTURE_NORM16},
182
+ 'rg16snorm-webgl': {gl: GL.RG16_SNORM_EXT, b:2, c:2, f: 'texture-formats-norm16-webgl', x: EXT_TEXTURE_NORM16},
198
183
 
199
- 'r32uint': {gl: GL.R32UI, b: 4, c: 1, bpp: 4},
200
- 'r32sint': {gl: GL.R32I, b: 4, c: 1, bpp: 4},
184
+ 'r32uint': {gl: GL.R32UI, b: 4, c: 1, bpp: 4, renderbuffer: true},
185
+ 'r32sint': {gl: GL.R32I, b: 4, c: 1, bpp: 4, renderbuffer: true},
201
186
  'r32float': {gl: GL.R32F, bpp: 4, b: 4, c: 1, render: 'texture-renderable-float32-webgl', filter: 'texture-filter-linear-float32-webgl'},
202
187
 
203
188
  // Packed 32-bit formats
204
189
  'rgb9e5ufloat': {gl: GL.RGB9_E5, b: 4, c: 3, p: 1, render: 'texture-renderable-float16-webgl', filter: 'texture-filter-linear-float16-webgl'},
205
- 'rg11b10ufloat': {gl: GL.R11F_G11F_B10F, b: 4, c: 3, p: 1,render: 'texture-renderable-float32-webgl'},
206
- 'rgb10a2unorm': {gl: GL.RGB10_A2, b: 4, c: 4, p: 1},
190
+ 'rg11b10ufloat': {gl: GL.R11F_G11F_B10F, b: 4, c: 3, p: 1,render: 'texture-renderable-float32-webgl', renderbuffer: true},
191
+ 'rgb10a2unorm': {gl: GL.RGB10_A2, b: 4, c: 4, p: 1, renderbuffer: true},
207
192
  // webgl2 only
208
- 'rgb10a2unorm-webgl': {b: 4, c: 4, gl: GL.RGB10_A2UI, p: 1, wgpu: false, bpp: 4},
193
+ 'rgb10a2unorm-webgl': {b: 4, c: 4, gl: GL.RGB10_A2UI, p: 1, wgpu: false, bpp: 4, renderbuffer: true},
209
194
 
210
195
  // 48-bit formats
211
- 'rgb16unorm-webgl': {gl: GL.RGB16_EXT, b:2, c:3, f: 'texture-formats-norm16-webgl'},
212
- 'rgb16snorm-webgl': {gl: GL.RGB16_SNORM_EXT, b:2, c:3, f: 'texture-formats-norm16-webgl'},
196
+ 'rgb16unorm-webgl': {gl: GL.RGB16_EXT, b:2, c:3, f: 'texture-formats-norm16-webgl', x: EXT_TEXTURE_NORM16},
197
+ 'rgb16snorm-webgl': {gl: GL.RGB16_SNORM_EXT, b:2, c:3, f: 'texture-formats-norm16-webgl', x: EXT_TEXTURE_NORM16},
213
198
 
214
199
  // 64-bit formats
215
- 'rg32uint': {gl: GL.RG32UI, b: 8, c: 2},
216
- 'rg32sint': {gl: GL.RG32I, b: 8, c: 2},
217
- 'rg32float': {gl: GL.RG32F, b: 8, c: 2, render: 'texture-renderable-float32-webgl', filter: 'texture-filter-linear-float32-webgl'},
218
- 'rgba16uint': {gl: GL.RGBA16UI, b: 8, c: 4},
219
- 'rgba16sint': {gl: GL.RGBA16I, b: 8, c: 4},
200
+ 'rg32uint': {gl: GL.RG32UI, b: 8, c: 2, renderbuffer: true},
201
+ 'rg32sint': {gl: GL.RG32I, b: 8, c: 2, renderbuffer: true},
202
+ 'rg32float': {gl: GL.RG32F, b: 8, c: 2, render: 'texture-renderable-float32-webgl', filter: 'texture-filter-linear-float32-webgl', renderbuffer: true},
203
+ 'rgba16uint': {gl: GL.RGBA16UI, b: 8, c: 4, renderbuffer: true},
204
+ 'rgba16sint': {gl: GL.RGBA16I, b: 8, c: 4, renderbuffer: true},
220
205
  'rgba16float': {gl: GL.RGBA16F, gl1: GL.RGBA, b: 8, c: 4, render: 'texture-renderable-float16-webgl', filter: 'texture-filter-linear-float16-webgl'},
221
- 'rgba16unorm-webgl': {gl: GL.RGBA16_EXT, b:2, c:4, f: 'texture-formats-norm16-webgl'},
222
- 'rgba16snorm-webgl': {gl: GL.RGBA16_SNORM_EXT, b:2, c:4, f: 'texture-formats-norm16-webgl'},
206
+ 'rgba16unorm-webgl': {gl: GL.RGBA16_EXT, b:2, c:4, f: 'texture-formats-norm16-webgl', renderbuffer: true, x: EXT_TEXTURE_NORM16},
207
+ 'rgba16snorm-webgl': {gl: GL.RGBA16_SNORM_EXT, b:2, c:4, f: 'texture-formats-norm16-webgl', x: EXT_TEXTURE_NORM16},
223
208
 
224
209
  // 96-bit formats (deprecated!)
225
210
  'rgb32float-webgl': {gl: GL.RGB32F, gl1: GL.RGB, render: 'texture-renderable-float32-webgl', filter: 'texture-filter-linear-float32-webgl',
@@ -227,22 +212,23 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
227
212
  dataFormat: GL.RGB, types: [GL.FLOAT]},
228
213
 
229
214
  // 128-bit formats
230
- 'rgba32uint': {gl: GL.RGBA32UI, b: 16, c: 4},
231
- 'rgba32sint': {gl: GL.RGBA32I, b: 16, c: 4},
232
- 'rgba32float': {gl: GL.RGBA32F, gl1: GL.RGBA, b: 16, c: 4, render: 'texture-renderable-float32-webgl', filter: 'texture-filter-linear-float32-webgl'},
215
+ 'rgba32uint': {gl: GL.RGBA32UI, b: 16, c: 4, renderbuffer: true},
216
+ 'rgba32sint': {gl: GL.RGBA32I, b: 16, c: 4, renderbuffer: true},
217
+ 'rgba32float': {gl: GL.RGBA32F, b: 16, c: 4, render: 'texture-renderable-float32-webgl', filter: 'texture-filter-linear-float32-webgl', renderbuffer: true},
233
218
 
234
219
  // Depth and stencil formats
235
- 'stencil8': {gl: GL.STENCIL_INDEX8, b: 1, c: 1, attachment: GL.STENCIL_ATTACHMENT}, // 8 stencil bits
220
+ 'stencil8': {gl: GL.STENCIL_INDEX8, gl1: GL.STENCIL_INDEX8, b: 1, c: 1, attachment: GL.STENCIL_ATTACHMENT, renderbuffer: true}, // 8 stencil bits
236
221
 
237
- 'depth16unorm': {gl: GL.DEPTH_COMPONENT16, gl1: GL.DEPTH_COMPONENT16, b: 2, c: 1, attachment: GL.DEPTH_ATTACHMENT}, // 16 depth bits
222
+ 'depth16unorm': {gl: GL.DEPTH_COMPONENT16, gl1: GL.DEPTH_COMPONENT16, b: 2, c: 1, attachment: GL.DEPTH_ATTACHMENT, renderbuffer: true}, // 16 depth bits
238
223
  'depth24plus': {gl: GL.DEPTH_COMPONENT24, b: 3, c: 1, attachment: GL.DEPTH_ATTACHMENT},
239
- 'depth32float': {gl: GL.DEPTH_COMPONENT32F, b: 4, c: 1, attachment: GL.DEPTH_ATTACHMENT},
224
+ 'depth32float': {gl: GL.DEPTH_COMPONENT32F, b: 4, c: 1, attachment: GL.DEPTH_ATTACHMENT, renderbuffer: true},
240
225
 
241
- 'depth24plus-stencil8': {b: 4, gl: GL.UNSIGNED_INT_24_8, gl1: GL.DEPTH_STENCIL, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT},
226
+ // The depth component of the "depth24plus" and "depth24plus-stencil8" formats may be implemented as either a 24-bit depth value or a "depth32float" value.
227
+ 'depth24plus-stencil8': {gl: GL.DEPTH_STENCIL, gl1: GL.DEPTH_STENCIL, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, renderbuffer: true, depthTexture: true},
242
228
  // "depth24unorm-stencil8" feature
243
- 'depth24unorm-stencil8': {gl: GL.DEPTH24_STENCIL8, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT},
229
+ 'depth24unorm-stencil8': {gl: GL.DEPTH24_STENCIL8, b: 4, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, renderbuffer: true},
244
230
  // "depth32float-stencil8" feature
245
- 'depth32float-stencil8': {gl: GL.DEPTH32F_STENCIL8, b: 5, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT},
231
+ 'depth32float-stencil8': {gl: GL.DEPTH32F_STENCIL8, b: 5, c: 2, p: 1, attachment: GL.DEPTH_STENCIL_ATTACHMENT, renderbuffer: true},
246
232
 
247
233
  // BC compressed formats: check device.features.has("texture-compression-bc");
248
234
 
@@ -328,25 +314,137 @@ export const TEXTURE_FORMATS: Record<TextureFormat, Format> = {
328
314
  'atc-rgbai-unorm-webgl': {gl: GL.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL, f: texture_compression_atc_webgl}
329
315
  };
330
316
 
331
- // FUNCTIONS
317
+ /** Legal combinations for internalFormat, format and type *
318
+ // [GL.DEPTH_COMPONENT]: {types: [GL.UNSIGNED_SHORT, GL.UNSIGNED_INT, GL.UNSIGNED_INT_24_8], gl1ext: DEPTH},
319
+ // [GL.DEPTH_STENCIL]: {gl1ext: DEPTH},
320
+ // Sized texture format
321
+ // R
322
+ [GL.R8]: {dataFormat: GL.RED, types: [GL.UNSIGNED_BYTE], gl2: true},
323
+ [GL.R16F]: {dataFormat: GL.RED, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
324
+ [GL.R8UI]: {dataFormat: GL.RED_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
325
+ // // RG
326
+ [GL.RG8]: {dataFormat: GL.RG, types: [GL.UNSIGNED_BYTE], gl2: true},
327
+ [GL.RG16F]: {dataFormat: GL.RG, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true},
328
+ [GL.RG8UI]: {dataFormat: GL.RG_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
329
+ // // RGB
330
+ [GL.RGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true},
331
+ [GL.SRGB8]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE], gl2: true, gl1ext: EXT_SRGB},
332
+ [GL.RGB16F]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true, gl1ext: EXT_HALF_FLOAT_WEBGL1},
333
+ [GL.RGB8UI]: {dataFormat: GL.RGB_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true},
334
+ // // RGBA
332
335
 
333
- function getTextureFormat(format: TextureFormat | GL): TextureFormat {
334
- if (typeof format === 'string') {
335
- return format;
336
- }
337
- const entry = Object.entries(TEXTURE_FORMATS).find(([, entry]) => (entry.gl === format || entry.gl1 === format));
338
- if (!entry) {
339
- throw new Error(`Unknown texture format ${format}`);
340
- }
341
- return entry[0] as TextureFormat;
342
- }
336
+ [GL.RGB565]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_6_5], gl2: true},
337
+ [GL.R11F_G11F_B10F]: {dataFormat: GL.RGB, types: [GL.UNSIGNED_INT_10F_11F_11F_REV, GL.HALF_FLOAT, GL.FLOAT], gl2: true},
338
+ [GL.RGB9_E5]: {dataFormat: GL.RGB, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true, gl1ext: EXT_HALF_FLOAT_WEBGL1},
339
+ [GL.RGBA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true},
340
+ [GL.SRGB8_ALPHA8]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE], gl2: true, gl1ext: EXT_SRGB},
341
+ [GL.RGB5_A1]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_5_5_5_1], gl2: true},
342
+ [GL.RGBA4]: {dataFormat: GL.RGBA, types: [GL.UNSIGNED_BYTE, GL.UNSIGNED_SHORT_4_4_4_4], gl2: true},
343
+ [GL.RGBA16F]: {dataFormat: GL.RGBA, types: [GL.HALF_FLOAT, GL.FLOAT], gl2: true, gl1ext: EXT_HALF_FLOAT_WEBGL1},
344
+ [GL.RGBA8UI]: {dataFormat: GL.RGBA_INTEGER, types: [GL.UNSIGNED_BYTE], gl2: true}
345
+ */
346
+
347
+ /* This table is now baked into the above table
348
+ type RenderbufferFormat = {
349
+ bpp: number;
350
+ gl2?: boolean;
351
+ ext?: string;
352
+ };
353
+
354
+ export const RENDERBUFFER_FORMATS: Record<string, RenderbufferFormat> = {
355
+ [GL.DEPTH_COMPONENT16]: {bpp: 2}, // 16 depth bits.
356
+ // TODO - Not clear which webgpu value to map this to.
357
+ // [GL.DEPTH_COMPONENT24]: {gl2: true, bpp: 3},
358
+ [GL.DEPTH_COMPONENT32F]: {gl2: true, bpp: 4},
359
+
360
+ [GL.STENCIL_INDEX8]: {bpp: 1}, // 8 stencil bits.
361
+
362
+ [GL.DEPTH_STENCIL]: {bpp: 4},
363
+ [GL.DEPTH24_STENCIL8]: {gl2: true, bpp: 4},
364
+ [GL.DEPTH32F_STENCIL8]: {gl2: true, bpp: 5},
365
+
366
+ // When using a WebGL 1 context, color renderbuffer formats are limited
367
+ [GL.RGBA4]: {gl2: true, bpp: 2},
368
+ [GL.RGB565]: {gl2: true, bpp: 2},
369
+ [GL.RGB5_A1]: {gl2: true, bpp: 2},
370
+
371
+ // When using a WebGL 2 context, the following values are available additionally:
372
+ [GL.R8]: {gl2: true, bpp: 1},
373
+ [GL.R8UI]: {gl2: true, bpp: 1},
374
+ [GL.R8I]: {gl2: true, bpp: 1},
375
+ [GL.R16UI]: {gl2: true, bpp: 2},
376
+ [GL.R16I]: {gl2: true, bpp: 2},
377
+ [GL.R32UI]: {gl2: true, bpp: 4},
378
+ [GL.R32I]: {gl2: true, bpp: 4},
379
+ [GL.RG8]: {gl2: true, bpp: 2},
380
+ [GL.RG8UI]: {gl2: true, bpp: 2},
381
+ [GL.RG8I]: {gl2: true, bpp: 2},
382
+ [GL.RG16UI]: {gl2: true, bpp: 4},
383
+ [GL.RG16I]: {gl2: true, bpp: 4},
384
+ [GL.RG32UI]: {gl2: true, bpp: 8},
385
+ [GL.RG32I]: {gl2: true, bpp: 8},
386
+ [GL.RGB8]: {gl2: true, bpp: 3},
387
+ [GL.RGBA8]: {gl2: true, bpp: 4},
388
+ // [GL.SRGB8_ALPHA8]: {gl2: true, gl1: SRGB}, // When using the EXT_sRGB WebGL1 extension
389
+ [GL.RGB10_A2]: {gl2: true, bpp: 4},
390
+ [GL.RGBA8UI]: {gl2: true, bpp: 4},
391
+ [GL.RGBA8I]: {gl2: true, bpp: 4},
392
+ [GL.RGB10_A2UI]: {gl2: true, bpp: 4},
393
+ [GL.RGBA16UI]: {gl2: true, bpp: 8},
394
+ [GL.RGBA16I]: {gl2: true, bpp: 8},
395
+ [GL.RGBA32I]: {gl2: true, bpp: 16},
396
+ [GL.RGBA32UI]: {gl2: true, bpp: 16},
397
+
398
+ // When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension
399
+ [GL.R16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 2},
400
+ [GL.RG16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4},
401
+ [GL.RGBA16F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
402
+ [GL.R32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4},
403
+ [GL.RG32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 8},
404
+ // TODO - can't get WEBGL_color_buffer_float to work on renderbuffers
405
+ [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2, bpp: 16},
406
+ // [GL.RGBA32F]: {ext: EXT_FLOAT_WEBGL2, gl1: EXT_FLOAT_WEBGL1},
407
+ [GL.R11F_G11F_B10F]: {ext: EXT_FLOAT_WEBGL2, bpp: 4}
408
+ };
409
+ */
410
+
411
+ /** @deprecated should be removed */
412
+ const DATA_FORMAT_CHANNELS = {
413
+ [GL.RED]: 1,
414
+ [GL.RED_INTEGER]: 1,
415
+ [GL.RG]: 2,
416
+ [GL.RG_INTEGER]: 2,
417
+ [GL.RGB]: 3,
418
+ [GL.RGB_INTEGER]: 3,
419
+ [GL.RGBA]: 4,
420
+ [GL.RGBA_INTEGER]: 4,
421
+ [GL.DEPTH_COMPONENT]: 1,
422
+ [GL.DEPTH_STENCIL]: 1,
423
+ [GL.ALPHA]: 1,
424
+ [GL.LUMINANCE]: 1,
425
+ [GL.LUMINANCE_ALPHA]: 2
426
+ };
427
+
428
+ /** @deprecated should be removed */
429
+ const TYPE_SIZES = {
430
+ [GL.FLOAT]: 4,
431
+ [GL.UNSIGNED_INT]: 4,
432
+ [GL.INT]: 4,
433
+ [GL.UNSIGNED_SHORT]: 2,
434
+ [GL.SHORT]: 2,
435
+ [GL.HALF_FLOAT]: 2,
436
+ [GL.BYTE]: 1,
437
+ [GL.UNSIGNED_BYTE]: 1
438
+ };
439
+
440
+ // FUNCTIONS
343
441
 
344
442
  /** Checks if a texture format is supported */
345
443
  export function isTextureFormatSupported(
346
444
  gl: WebGLRenderingContext,
347
445
  formatOrGL: TextureFormat | GL
348
446
  ): boolean {
349
- const format = getTextureFormat(formatOrGL);
447
+ const format = convertGLToTextureFormat(formatOrGL);
350
448
  const info = TEXTURE_FORMATS[format];
351
449
  if (!info) {
352
450
  return false;
@@ -366,6 +464,39 @@ export function isTextureFormatSupported(
366
464
  return true;
367
465
  }
368
466
 
467
+ export function isRenderbufferFormatSupported(gl: WebGLRenderingContext, format: TextureFormat): boolean {
468
+ // Note: Order is important since the function call initializes extensions.
469
+ return isTextureFormatSupported(gl, format) && TEXTURE_FORMATS[format]?.renderbuffer;
470
+ }
471
+
472
+ /**
473
+ * Map WebGL texture formats (GL constants) to WebGPU-style TextureFormat strings
474
+ */
475
+ export function convertGLToTextureFormat(format: GL | TextureFormat): TextureFormat {
476
+ if (typeof format === 'string') {
477
+ return format;
478
+ }
479
+ const entry = Object.entries(TEXTURE_FORMATS).find(
480
+ ([, entry]) => entry.gl === format || entry.gl1 === format
481
+ );
482
+ if (!entry) {
483
+ throw new Error(`Unknown texture format ${format}`);
484
+ }
485
+ return entry[0] as TextureFormat;
486
+ }
487
+
488
+ /**
489
+ * Map WebGPU style texture format strings to GL constants
490
+ */
491
+ export function convertTextureFormatToGL(format: TextureFormat, isWebGL2: boolean): GL | undefined {
492
+ const formatInfo = TEXTURE_FORMATS[format];
493
+ const webglFormat = isWebGL2 ? formatInfo?.gl : formatInfo?.gl1;
494
+ if (webglFormat === undefined) {
495
+ throw new Error(`Unsupported texture format ${format}`);
496
+ }
497
+ return webglFormat;
498
+ }
499
+
369
500
  /** Checks if a texture format is supported */
370
501
  export function getTextureFormatSupport(
371
502
  gl: WebGLRenderingContext,
@@ -377,7 +508,7 @@ export function getTextureFormatSupport(
377
508
  blendable?: boolean;
378
509
  storable?: boolean;
379
510
  } {
380
- const format = getTextureFormat(formatOrGL);
511
+ const format = convertGLToTextureFormat(formatOrGL);
381
512
  const info = TEXTURE_FORMATS[format];
382
513
  if (!info) {
383
514
  return {supported: false};
@@ -413,7 +544,7 @@ export function isTextureFormatFilterable(
413
544
  gl: WebGLRenderingContext,
414
545
  formatOrGL: TextureFormat | GL
415
546
  ): boolean {
416
- const format = getTextureFormat(formatOrGL);
547
+ const format = convertGLToTextureFormat(formatOrGL);
417
548
  if (!isTextureFormatSupported(gl, format)) {
418
549
  return false;
419
550
  }
@@ -449,7 +580,7 @@ export function isTextureFormatRenderable(
449
580
  gl: WebGLRenderingContext,
450
581
  formatOrGL: TextureFormat | GL
451
582
  ): boolean {
452
- const format = getTextureFormat(formatOrGL);
583
+ const format = convertGLToTextureFormat(formatOrGL);
453
584
  if (!isTextureFormatSupported(gl, format)) {
454
585
  return false;
455
586
  }
@@ -460,27 +591,9 @@ export function isTextureFormatRenderable(
460
591
  return true;
461
592
  }
462
593
 
463
- /**
464
- * Converts WebGPU string style texture formats to GL constants
465
- * Pass through GL constants
466
- */
467
- export function getWebGLTextureFormat(gl: WebGLRenderingContext, formatOrGL: TextureFormat | GL): GL | undefined {
468
- const format = getTextureFormat(formatOrGL);
469
- const formatInfo = TEXTURE_FORMATS[format];
470
- const webglFormat = isWebGL2(gl) ? formatInfo?.gl : formatInfo?.gl1;
471
- // Remap or pass through
472
- if (typeof format === 'number') {
473
- return webglFormat || format;
474
- }
475
- if (webglFormat === undefined) {
476
- throw new Error(`Unsupported texture format ${format}`);
477
- }
478
- return webglFormat;
479
- }
480
-
481
- export function getWebGLTextureParameters(gl: WebGLRenderingContext, formatOrGL: TextureFormat | GL) {
482
- const format = getTextureFormat(formatOrGL);
483
- const webglFormat = getWebGLTextureFormat(gl, format);
594
+ export function getWebGLTextureParameters(formatOrGL: TextureFormat | GL, isWebGL2: boolean) {
595
+ const format = convertGLToTextureFormat(formatOrGL);
596
+ const webglFormat = convertTextureFormatToGL(format, isWebGL2);
484
597
  const decoded = decodeTextureFormat(format);
485
598
  return {
486
599
  format: webglFormat,
@@ -496,20 +609,14 @@ export function getWebGLTextureParameters(gl: WebGLRenderingContext, formatOrGL:
496
609
  };
497
610
  }
498
611
 
499
- export function getWebGLDepthStencilAttachment(
500
- formatOrGL: TextureFormat | GL
612
+ export function getDepthStencilAttachmentWebGL(
613
+ format: TextureFormat
501
614
  ): GL.DEPTH_ATTACHMENT | GL.STENCIL_ATTACHMENT | GL.DEPTH_STENCIL_ATTACHMENT {
502
- const format = getTextureFormat(formatOrGL);
503
- if (typeof format === 'number') {
504
- // TODO
505
- throw new Error('unsupported depth stencil format')
506
- }
507
615
  const info = TEXTURE_FORMATS[format];
508
- const attachment = info.attachment;
509
- if (!attachment) {
510
- throw new Error('not a depth stencil format');
616
+ if (!info?.attachment) {
617
+ throw new Error(`${format} is not a depth stencil format`);
511
618
  }
512
- return attachment;
619
+ return info.attachment;
513
620
  }
514
621
 
515
622
  /**
@@ -558,39 +665,13 @@ export function _checkFloat32ColorAttachment(
558
665
  }
559
666
  }
560
667
 
561
- /** @deprecated should be removed */
562
- const DATA_FORMAT_CHANNELS = {
563
- [GL.RED]: 1,
564
- [GL.RED_INTEGER]: 1,
565
- [GL.RG]: 2,
566
- [GL.RG_INTEGER]: 2,
567
- [GL.RGB]: 3,
568
- [GL.RGB_INTEGER]: 3,
569
- [GL.RGBA]: 4,
570
- [GL.RGBA_INTEGER]: 4,
571
- [GL.DEPTH_COMPONENT]: 1,
572
- [GL.DEPTH_STENCIL]: 1,
573
- [GL.ALPHA]: 1,
574
- [GL.LUMINANCE]: 1,
575
- [GL.LUMINANCE_ALPHA]: 2
576
- };
577
-
578
- /** @deprecated should be removed */
579
- const TYPE_SIZES = {
580
- [GL.FLOAT]: 4,
581
- [GL.UNSIGNED_INT]: 4,
582
- [GL.INT]: 4,
583
- [GL.UNSIGNED_SHORT]: 2,
584
- [GL.SHORT]: 2,
585
- [GL.HALF_FLOAT]: 2,
586
- [GL.BYTE]: 1,
587
- [GL.UNSIGNED_BYTE]: 1
588
- };
589
-
590
668
  /** TODO - VERY roundabout legacy way of calculating bytes per pixel */
591
- export function getTextureFormatBytesPerPixel(gl: WebGLRenderingContext, formatOrGL: TextureFormat | GL): number {
592
- const format = getTextureFormat(formatOrGL);
593
- const params = getWebGLTextureParameters(gl, format);
669
+ export function getTextureFormatBytesPerPixel(
670
+ formatOrGL: TextureFormat | GL,
671
+ isWebGL2: boolean
672
+ ): number {
673
+ const format = convertGLToTextureFormat(formatOrGL);
674
+ const params = getWebGLTextureParameters(format, isWebGL2);
594
675
  // NOTE(Tarek): Default to RGBA bytes
595
676
  const channels = DATA_FORMAT_CHANNELS[params.dataFormat] || 4;
596
677
  const channelSize = TYPE_SIZES[params.type] || 1;
@@ -1,5 +1,4 @@
1
- import GL from '@luma.gl/constants';
2
- import {GLDrawMode, GLPrimitive} from '../../types/webgl';
1
+ import {GL, GLDrawMode, GLPrimitive} from '@luma.gl/constants';
3
2
 
4
3
  // Counts the number of complete primitives given a number of vertices and a drawMode
5
4
  export function getPrimitiveDrawMode(drawMode: GLDrawMode): GLPrimitive {
@@ -1,5 +1,8 @@
1
1
  // luma.gl, MIT license
2
2
 
3
+ // Note: This was the only dependency that made @luma.gl/webgl depend on @luma.gl/shadertools
4
+ // This file was coped from shadertools to avoid the dependency
5
+
3
6
  /** Information extracted from shader source code */
4
7
  export type ShaderInfo = {
5
8
  name: string;
@@ -1,6 +1,5 @@
1
1
  import {UniformFormat, VertexFormat} from '@luma.gl/api';
2
- import GL from '@luma.gl/constants';
3
- import {GLUniformType, GLSamplerType, GLCompositeType, GLType} from '../../types/webgl';
2
+ import {GL, GLUniformType, GLSamplerType, GLCompositeType, GLDataType} from '@luma.gl/constants';
4
3
 
5
4
  /** Check is uniform is of sampler type */
6
5
  export function isSamplerUniform(type: GLUniformType): boolean {
@@ -28,7 +27,7 @@ const SAMPLER_TYPES: GLSamplerType[] = [
28
27
  // Composite types table
29
28
  const COMPOSITE_GL_TYPES: Record<
30
29
  GLCompositeType,
31
- [GLType, number, string, UniformFormat, VertexFormat?]
30
+ [GLDataType, number, string, UniformFormat, VertexFormat?]
32
31
  > = {
33
32
  [GL.FLOAT]: [GL.FLOAT, 1, 'float', 'f32', 'float32'],
34
33
  [GL.FLOAT_VEC2]: [GL.FLOAT, 2, 'vec2', 'vec2<f32>', 'float32x2'],
@@ -66,7 +65,7 @@ const COMPOSITE_GL_TYPES: Record<
66
65
  /** Decomposes a composite type GL.VEC3 into a basic type (GL.FLOAT) and components (3) */
67
66
  export function decodeUniformType(
68
67
  uniformType: GL
69
- ): {format: UniformFormat; components: number; glType: GLType} {
68
+ ): {format: UniformFormat; components: number; glType: GLDataType} {
70
69
  const typeAndSize = COMPOSITE_GL_TYPES[uniformType];
71
70
  if (!typeAndSize) {
72
71
  throw new Error('uniform');
@@ -78,7 +77,7 @@ export function decodeUniformType(
78
77
  export function decodeAttributeType(attributeType: GL): {
79
78
  format: VertexFormat;
80
79
  components: number;
81
- glType: GLType;
80
+ glType: GLDataType;
82
81
  } {
83
82
  const typeAndSize = COMPOSITE_GL_TYPES[attributeType];
84
83
  if (!typeAndSize) {
@@ -89,10 +88,10 @@ export function decodeAttributeType(attributeType: GL): {
89
88
  }
90
89
 
91
90
  /** Decomposes a composite type GL.VEC3 into a basic type (GL.FLOAT) and components (3) */
92
- export function decomposeCompositeGLType(
93
- compositeGLType: GLCompositeType
94
- ): {type: GLType; components: number} | null {
95
- const typeAndSize = COMPOSITE_GL_TYPES[compositeGLType];
91
+ export function decomposeCompositeGLDataType(
92
+ compositeGLDataType: GLCompositeType
93
+ ): {type: GLDataType; components: number} | null {
94
+ const typeAndSize = COMPOSITE_GL_TYPES[compositeGLDataType];
96
95
  if (!typeAndSize) {
97
96
  return null;
98
97
  }
@@ -100,7 +99,7 @@ export function decomposeCompositeGLType(
100
99
  return {type, components};
101
100
  }
102
101
 
103
- export function getCompositeGLType(type: GL, components): {glType: GLType; name: string} | null {
102
+ export function getCompositeGLDataType(type: GL, components): {glType: GLDataType; name: string} | null {
104
103
  switch (type) {
105
104
  case GL.BYTE:
106
105
  case GL.UNSIGNED_BYTE:
@@ -21,28 +21,3 @@ export function getKeyValue(gl: WebGLRenderingContext, name: string | GL): GL {
21
21
  assert(value !== undefined, `Accessing undefined constant GL.${name}`);
22
22
  return value;
23
23
  }
24
-
25
- export function getKey(gl: WebGLRenderingContext, value: any): string {
26
- // @ts-ignore expect-error depends on settings
27
- gl = gl.gl || gl;
28
- value = Number(value);
29
- for (const key in gl) {
30
- // @ts-ignore expect-error depends on settings
31
- if (gl[key] === value) {
32
- return `GL.${key}`;
33
- }
34
- }
35
- return String(value);
36
- }
37
-
38
- export function getKeyType(gl: WebGLRenderingContext, value: any): string {
39
- assert(value !== undefined, 'undefined key');
40
- value = Number(value);
41
- for (const key in gl) {
42
- // @ts-ignore expect-error depends on settings
43
- if (gl[key] === value) {
44
- return `GL.${key}`;
45
- }
46
- }
47
- return String(value);
48
- }