@luma.gl/webgl 9.0.0-alpha.44 → 9.0.0-alpha.46

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 (56) hide show
  1. package/dist/adapter/device-helpers/device-features.js +1 -0
  2. package/dist/adapter/device-helpers/device-features.js.map +1 -1
  3. package/dist/adapter/helpers/webgl-topology-utils.d.ts +6 -1
  4. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
  5. package/dist/adapter/helpers/webgl-topology-utils.js +40 -0
  6. package/dist/adapter/helpers/webgl-topology-utils.js.map +1 -1
  7. package/dist/adapter/resources/webgl-buffer.d.ts +1 -1
  8. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  9. package/dist/adapter/resources/webgl-buffer.js +2 -0
  10. package/dist/adapter/resources/webgl-buffer.js.map +1 -1
  11. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  12. package/dist/adapter/resources/webgl-command-buffer.js +6 -4
  13. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  14. package/dist/adapter/resources/webgl-render-pipeline.d.ts +2 -0
  15. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  16. package/dist/adapter/resources/webgl-render-pipeline.js +4 -44
  17. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  18. package/dist/adapter/resources/webgl-transform-feedback.d.ts +53 -0
  19. package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -0
  20. package/dist/adapter/resources/webgl-transform-feedback.js +161 -0
  21. package/dist/adapter/resources/webgl-transform-feedback.js.map +1 -0
  22. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  23. package/dist/adapter/resources/webgl-vertex-array.js +5 -3
  24. package/dist/adapter/resources/webgl-vertex-array.js.map +1 -1
  25. package/dist/adapter/webgl-device.d.ts +4 -2
  26. package/dist/adapter/webgl-device.d.ts.map +1 -1
  27. package/dist/adapter/webgl-device.js +7 -3
  28. package/dist/adapter/webgl-device.js.map +1 -1
  29. package/dist/classic/copy-and-blit.d.ts +3 -3
  30. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  31. package/dist/classic/copy-and-blit.js +12 -20
  32. package/dist/classic/copy-and-blit.js.map +1 -1
  33. package/dist/dist.dev.js +2140 -2302
  34. package/dist/index.cjs +645 -806
  35. package/dist/index.d.ts +1 -2
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +1 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist.min.js +23 -22
  40. package/package.json +5 -5
  41. package/src/adapter/device-helpers/device-features.ts +1 -0
  42. package/src/adapter/helpers/webgl-topology-utils.ts +40 -0
  43. package/src/adapter/resources/webgl-buffer.ts +12 -8
  44. package/src/adapter/resources/webgl-command-buffer.ts +7 -13
  45. package/src/adapter/resources/webgl-render-pipeline.ts +11 -47
  46. package/src/adapter/resources/webgl-transform-feedback.ts +205 -0
  47. package/src/adapter/resources/webgl-vertex-array.ts +11 -8
  48. package/src/adapter/webgl-device.ts +10 -5
  49. package/src/classic/copy-and-blit.ts +16 -19
  50. package/src/index.ts +5 -4
  51. package/LICENSE +0 -34
  52. package/dist/classic/buffer-with-accessor.d.ts +0 -82
  53. package/dist/classic/buffer-with-accessor.d.ts.map +0 -1
  54. package/dist/classic/buffer-with-accessor.js +0 -314
  55. package/dist/classic/buffer-with-accessor.js.map +0 -1
  56. package/src/classic/buffer-with-accessor.ts +0 -466
@@ -71,6 +71,7 @@ const WEBGL_FEATURES = {
71
71
  'webgl': [true, true],
72
72
  'webgl2': [false, true],
73
73
  'timer-query-webgl': ['EXT_disjoint_timer_query', 'EXT_disjoint_timer_query_webgl2'],
74
+ 'transform-feedback-webgl2': [false, true],
74
75
  'vertex-array-object-webgl1': ['OES_vertex_array_object', true],
75
76
  'instanced-rendering-webgl1': ['ANGLE_instanced_arrays', true],
76
77
  'multiple-render-targets-webgl1': ['WEBGL_draw_buffers', true],
@@ -1 +1 @@
1
- {"version":3,"file":"device-features.js","names":["isWebGL2","isOldIE","getTextureFeatures","_checkFloat32ColorAttachment","getDeviceFeatures","gl","features","getWebGLFeatures","textureFeature","add","getExtension","Set","feature","Object","keys","WEBGL_FEATURES","isFeatureSupported","featureInfo","webgl1Feature","webgl2Feature","featureDefinition","Boolean","canCompileGLSLExtension","behavior","compiledGLSLExtensions","extensionName","opts","arguments","length","undefined","source","shader","createShader","VERTEX_SHADER","Error","shaderSource","compileShader","canCompile","getShaderParameter","COMPILE_STATUS","deleteShader"],"sources":["../../../src/adapter/device-helpers/device-features.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\n// Feature detection for WebGL\n// Provides a function that enables simple checking of which WebGL features are\n// available in an WebGL1 or WebGL2 environment.\n\nimport {DeviceFeature} from '@luma.gl/core';\nimport {isWebGL2} from '../../context/context/webgl-checks';\nimport {isOldIE} from './is-old-ie';\nimport {getTextureFeatures, _checkFloat32ColorAttachment} from '../converters/texture-formats';\n\n/** Get WebGPU style feature strings */\nexport function getDeviceFeatures(gl: WebGLRenderingContext): Set<DeviceFeature> {\n const features = getWebGLFeatures(gl);\n\n // texture features\n // features.add('texture-compression-bc'); \n for (const textureFeature of getTextureFeatures(gl)) {\n features.add(textureFeature);\n }\n\n // TODO\n // features.add('depth-clip-control'); // GPUPrimitiveState.clampDepth\n // features.add('depth24unorm-stencil8'); // GPUTextureFormat 'depth24unorm-stencil8'.\n // features.add('depth32float-stencil8'); // GPUTextureFormat 'depth32float-stencil8'.\n // features.add('timestamp-query'); // GPUQueryType \"timestamp-query\"\n // \"indirect-first-instance\"\n\n return features;\n}\n\n/** Extract all WebGL features */\nexport function getWebGLFeatures(gl: WebGLRenderingContext): Set<DeviceFeature> {\n // Enables EXT_float_blend first: https://developer.mozilla.org/en-US/docs/Web/API/EXT_float_blend\n gl.getExtension('EXT_color_buffer_float');\n gl.getExtension('WEBGL_color_buffer_float');\n gl.getExtension('EXT_float_blend');\n\n const features = new Set<DeviceFeature>();\n for (const feature of Object.keys(WEBGL_FEATURES)) {\n // @ts-expect-error\n if (isFeatureSupported(gl, feature)) {\n // @ts-expect-error\n features.add(feature);\n }\n }\n return features;\n}\n\nfunction isFeatureSupported(gl: WebGLRenderingContext, feature: DeviceFeature): boolean {\n const featureInfo = WEBGL_FEATURES[feature];\n if (!featureInfo) {\n return false;\n }\n\n const [webgl1Feature, webgl2Feature] = featureInfo || [];\n\n // Get extension name from table\n const featureDefinition = isWebGL2(gl) ? webgl2Feature : webgl1Feature;\n\n // Check if the value is dependent on checking one or more extensions\n if (typeof featureDefinition === 'boolean') {\n return featureDefinition;\n }\n\n switch (feature) {\n case 'texture-renderable-rgba32float-webgl':\n return isWebGL2(gl) ? Boolean(gl.getExtension(featureDefinition)) :\n _checkFloat32ColorAttachment(gl);\n case 'glsl-derivatives':\n return canCompileGLSLExtension(gl, featureDefinition); // TODO options\n case 'glsl-frag-data':\n return canCompileGLSLExtension(gl, featureDefinition, {behavior: 'require'}); // TODO options\n case 'glsl-frag-depth':\n return canCompileGLSLExtension(gl, featureDefinition); // TODO options\n default:\n return Boolean(gl.getExtension(featureDefinition));\n }\n}\n\nconst compiledGLSLExtensions: Record<string, boolean> = {};\n\n/*\n * Enables feature detection in IE11 due to a bug where gl.getExtension may return true\n * but fail to compile when the extension is enabled in the shader. Specifically,\n * the OES_standard_derivatives and WEBGL_draw_buffers extensions fails to compile in IE11 even though its included\n * in the list of supported extensions.\n * opts allows user agent to be overridden for testing\n * Inputs :\n * gl : WebGL context\n * cap : Key of WEBGL_FEATURES object identifying the extension\n * opts :\n * behavior : behavior of extension to be tested, by defualt `enable` is used\n * Returns : true, if shader is compiled successfully, false otherwise\n */\nexport function canCompileGLSLExtension(gl: WebGLRenderingContext, extensionName, opts: {behavior?} = {}) {\n if (!isOldIE(opts)) {\n return true;\n }\n\n if (extensionName in compiledGLSLExtensions) {\n return compiledGLSLExtensions[extensionName];\n }\n\n const behavior = opts.behavior || 'enable';\n const source = `#extension GL_${extensionName} : ${behavior}\\nvoid main(void) {}`;\n\n const shader = gl.createShader(gl.VERTEX_SHADER);\n if (!shader) {\n throw new Error('shader');\n }\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n const canCompile = gl.getShaderParameter(shader, gl.COMPILE_STATUS);\n gl.deleteShader(shader);\n compiledGLSLExtensions[extensionName] = canCompile;\n return canCompile;\n}\n\n/** Defines luma.gl \"feature\" names and semantics\n * Format: 'feature-name: [WebGL1 support, WebGL2 support] / [WebGL1 and WebGL2 support]', when support is 'string' it is the name of the extension\n */\nconst WEBGL_FEATURES: Partial<Record<DeviceFeature, [boolean | string, boolean | string]>> = {\n 'webgl': [true, true],\n 'webgl2': [false, true],\n\n 'timer-query-webgl': ['EXT_disjoint_timer_query', 'EXT_disjoint_timer_query_webgl2'],\n\n // WEBGL1 SUPPORT\n 'vertex-array-object-webgl1': ['OES_vertex_array_object', true],\n 'instanced-rendering-webgl1': ['ANGLE_instanced_arrays', true],\n 'multiple-render-targets-webgl1': ['WEBGL_draw_buffers', true],\n 'index-uint32-webgl1': ['OES_element_index_uint', true],\n 'blend-minmax-webgl1': ['EXT_blend_minmax', true],\n 'texture-blend-float-webgl1': ['EXT_float_blend', 'EXT_float_blend'],\n\n // TEXTURES, RENDERBUFFERS\n 'texture-formats-srgb-webgl1': ['EXT_sRGB', true],\n\n // TEXTURES\n 'texture-formats-depth-webgl1': ['WEBGL_depth_texture', true],\n 'texture-formats-float32-webgl1': ['OES_texture_float', true],\n 'texture-formats-float16-webgl1': ['OES_texture_half_float', true],\n\n 'texture-filter-linear-float32-webgl': ['OES_texture_float_linear', 'OES_texture_float_linear'],\n 'texture-filter-linear-float16-webgl': ['OES_texture_half_float_linear', 'OES_texture_half_float_linear'],\n 'texture-filter-anisotropic-webgl': ['EXT_texture_filter_anisotropic', 'EXT_texture_filter_anisotropic'],\n\n // FRAMEBUFFERS, TEXTURES AND RENDERBUFFERS\n 'texture-renderable-rgba32float-webgl': ['WEBGL_color_buffer_float', 'EXT_color_buffer_float'], // Note override check\n 'texture-renderable-float32-webgl': [false, 'EXT_color_buffer_float'],\n 'texture-renderable-float16-webgl': ['EXT_color_buffer_half_float', 'EXT_color_buffer_half_float'],\n\n // GLSL extensions\n 'glsl-frag-data': ['WEBGL_draw_buffers', true],\n 'glsl-frag-depth': ['EXT_frag_depth', true],\n 'glsl-derivatives': ['OES_standard_derivatives', true],\n 'glsl-texture-lod': ['EXT_shader_texture_lod', true]\n};\n"],"mappings":"SAQQA,QAAQ;AAAA,SACRC,OAAO;AAAA,SACPC,kBAAkB,EAAEC,4BAA4B;AAGxD,OAAO,SAASC,iBAAiBA,CAACC,EAAyB,EAAsB;EAC/E,MAAMC,QAAQ,GAAGC,gBAAgB,CAACF,EAAE,CAAC;EAIrC,KAAK,MAAMG,cAAc,IAAIN,kBAAkB,CAACG,EAAE,CAAC,EAAE;IACnDC,QAAQ,CAACG,GAAG,CAACD,cAAc,CAAC;EAC9B;EASA,OAAOF,QAAQ;AACjB;AAGA,OAAO,SAASC,gBAAgBA,CAACF,EAAyB,EAAsB;EAE9EA,EAAE,CAACK,YAAY,CAAC,wBAAwB,CAAC;EACzCL,EAAE,CAACK,YAAY,CAAC,0BAA0B,CAAC;EAC3CL,EAAE,CAACK,YAAY,CAAC,iBAAiB,CAAC;EAElC,MAAMJ,QAAQ,GAAG,IAAIK,GAAG,CAAgB,CAAC;EACzC,KAAK,MAAMC,OAAO,IAAIC,MAAM,CAACC,IAAI,CAACC,cAAc,CAAC,EAAE;IAEjD,IAAIC,kBAAkB,CAACX,EAAE,EAAEO,OAAO,CAAC,EAAE;MAEnCN,QAAQ,CAACG,GAAG,CAACG,OAAO,CAAC;IACvB;EACF;EACA,OAAON,QAAQ;AACjB;AAEA,SAASU,kBAAkBA,CAACX,EAAyB,EAAEO,OAAsB,EAAW;EACtF,MAAMK,WAAW,GAAGF,cAAc,CAACH,OAAO,CAAC;EAC3C,IAAI,CAACK,WAAW,EAAE;IAChB,OAAO,KAAK;EACd;EAEA,MAAM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qCAAqC,EAAE,CAAC,0BAA0B,EAAE,0BAA0B,CAAC;EAC/F,qCAAqC,EAAE,CAAC,+BAA+B,EAAE,+BAA+B,CAAC;EACzG,kCAAkC,EAAE,CAAC,gCAAgC,EAAE,gCAAgC,CAAC;EAGxG,sCAAsC,EAAE,CAAC,0BAA0B,EAAE,wBAAwB,CAAC;EAC9F,kCAAkC,EAAE,CAAC,KAAK,EAAE,wBAAwB,CAAC;EACrE,kCAAkC,EAAE,CAAC,6BAA6B,EAAE,6BAA6B,CAAC;EAGlG,gBAAgB,EAAE,CAAC,oBAAoB,EAAE,IAAI,CAAC;EAC9C,iBAAiB,EAAE,CAAC,gBAAgB,EAAE,IAAI,CAAC;EAC3C,kBAAkB,EAAE,CAAC,0BAA0B,EAAE,IAAI,CAAC;EACtD,kBAAkB,EAAE,CAAC,wBAAwB,EAAE,IAAI;AACrD,CAAC"}
1
+ {"version":3,"file":"device-features.js","names":["isWebGL2","isOldIE","getTextureFeatures","_checkFloat32ColorAttachment","getDeviceFeatures","gl","features","getWebGLFeatures","textureFeature","add","getExtension","Set","feature","Object","keys","WEBGL_FEATURES","isFeatureSupported","featureInfo","webgl1Feature","webgl2Feature","featureDefinition","Boolean","canCompileGLSLExtension","behavior","compiledGLSLExtensions","extensionName","opts","arguments","length","undefined","source","shader","createShader","VERTEX_SHADER","Error","shaderSource","compileShader","canCompile","getShaderParameter","COMPILE_STATUS","deleteShader"],"sources":["../../../src/adapter/device-helpers/device-features.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\n// Feature detection for WebGL\n// Provides a function that enables simple checking of which WebGL features are\n// available in an WebGL1 or WebGL2 environment.\n\nimport {DeviceFeature} from '@luma.gl/core';\nimport {isWebGL2} from '../../context/context/webgl-checks';\nimport {isOldIE} from './is-old-ie';\nimport {getTextureFeatures, _checkFloat32ColorAttachment} from '../converters/texture-formats';\n\n/** Get WebGPU style feature strings */\nexport function getDeviceFeatures(gl: WebGLRenderingContext): Set<DeviceFeature> {\n const features = getWebGLFeatures(gl);\n\n // texture features\n // features.add('texture-compression-bc'); \n for (const textureFeature of getTextureFeatures(gl)) {\n features.add(textureFeature);\n }\n\n // TODO\n // features.add('depth-clip-control'); // GPUPrimitiveState.clampDepth\n // features.add('depth24unorm-stencil8'); // GPUTextureFormat 'depth24unorm-stencil8'.\n // features.add('depth32float-stencil8'); // GPUTextureFormat 'depth32float-stencil8'.\n // features.add('timestamp-query'); // GPUQueryType \"timestamp-query\"\n // \"indirect-first-instance\"\n\n return features;\n}\n\n/** Extract all WebGL features */\nexport function getWebGLFeatures(gl: WebGLRenderingContext): Set<DeviceFeature> {\n // Enables EXT_float_blend first: https://developer.mozilla.org/en-US/docs/Web/API/EXT_float_blend\n gl.getExtension('EXT_color_buffer_float');\n gl.getExtension('WEBGL_color_buffer_float');\n gl.getExtension('EXT_float_blend');\n\n const features = new Set<DeviceFeature>();\n for (const feature of Object.keys(WEBGL_FEATURES)) {\n // @ts-expect-error\n if (isFeatureSupported(gl, feature)) {\n // @ts-expect-error\n features.add(feature);\n }\n }\n return features;\n}\n\nfunction isFeatureSupported(gl: WebGLRenderingContext, feature: DeviceFeature): boolean {\n const featureInfo = WEBGL_FEATURES[feature];\n if (!featureInfo) {\n return false;\n }\n\n const [webgl1Feature, webgl2Feature] = featureInfo || [];\n\n // Get extension name from table\n const featureDefinition = isWebGL2(gl) ? webgl2Feature : webgl1Feature;\n\n // Check if the value is dependent on checking one or more extensions\n if (typeof featureDefinition === 'boolean') {\n return featureDefinition;\n }\n\n switch (feature) {\n case 'texture-renderable-rgba32float-webgl':\n return isWebGL2(gl) ? Boolean(gl.getExtension(featureDefinition)) :\n _checkFloat32ColorAttachment(gl);\n case 'glsl-derivatives':\n return canCompileGLSLExtension(gl, featureDefinition); // TODO options\n case 'glsl-frag-data':\n return canCompileGLSLExtension(gl, featureDefinition, {behavior: 'require'}); // TODO options\n case 'glsl-frag-depth':\n return canCompileGLSLExtension(gl, featureDefinition); // TODO options\n default:\n return Boolean(gl.getExtension(featureDefinition));\n }\n}\n\nconst compiledGLSLExtensions: Record<string, boolean> = {};\n\n/*\n * Enables feature detection in IE11 due to a bug where gl.getExtension may return true\n * but fail to compile when the extension is enabled in the shader. Specifically,\n * the OES_standard_derivatives and WEBGL_draw_buffers extensions fails to compile in IE11 even though its included\n * in the list of supported extensions.\n * opts allows user agent to be overridden for testing\n * Inputs :\n * gl : WebGL context\n * cap : Key of WEBGL_FEATURES object identifying the extension\n * opts :\n * behavior : behavior of extension to be tested, by defualt `enable` is used\n * Returns : true, if shader is compiled successfully, false otherwise\n */\nexport function canCompileGLSLExtension(gl: WebGLRenderingContext, extensionName, opts: {behavior?} = {}) {\n if (!isOldIE(opts)) {\n return true;\n }\n\n if (extensionName in compiledGLSLExtensions) {\n return compiledGLSLExtensions[extensionName];\n }\n\n const behavior = opts.behavior || 'enable';\n const source = `#extension GL_${extensionName} : ${behavior}\\nvoid main(void) {}`;\n\n const shader = gl.createShader(gl.VERTEX_SHADER);\n if (!shader) {\n throw new Error('shader');\n }\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n const canCompile = gl.getShaderParameter(shader, gl.COMPILE_STATUS);\n gl.deleteShader(shader);\n compiledGLSLExtensions[extensionName] = canCompile;\n return canCompile;\n}\n\n/** Defines luma.gl \"feature\" names and semantics\n * Format: 'feature-name: [WebGL1 support, WebGL2 support] / [WebGL1 and WebGL2 support]', when support is 'string' it is the name of the extension\n */\nconst WEBGL_FEATURES: Partial<Record<DeviceFeature, [boolean | string, boolean | string]>> = {\n 'webgl': [true, true],\n 'webgl2': [false, true],\n\n 'timer-query-webgl': ['EXT_disjoint_timer_query', 'EXT_disjoint_timer_query_webgl2'],\n 'transform-feedback-webgl2': [false, true],\n\n // WEBGL1 SUPPORT\n 'vertex-array-object-webgl1': ['OES_vertex_array_object', true],\n 'instanced-rendering-webgl1': ['ANGLE_instanced_arrays', true],\n 'multiple-render-targets-webgl1': ['WEBGL_draw_buffers', true],\n 'index-uint32-webgl1': ['OES_element_index_uint', true],\n 'blend-minmax-webgl1': ['EXT_blend_minmax', true],\n 'texture-blend-float-webgl1': ['EXT_float_blend', 'EXT_float_blend'],\n\n // TEXTURES, RENDERBUFFERS\n 'texture-formats-srgb-webgl1': ['EXT_sRGB', true],\n\n // TEXTURES\n 'texture-formats-depth-webgl1': ['WEBGL_depth_texture', true],\n 'texture-formats-float32-webgl1': ['OES_texture_float', true],\n 'texture-formats-float16-webgl1': ['OES_texture_half_float', true],\n\n 'texture-filter-linear-float32-webgl': ['OES_texture_float_linear', 'OES_texture_float_linear'],\n 'texture-filter-linear-float16-webgl': ['OES_texture_half_float_linear', 'OES_texture_half_float_linear'],\n 'texture-filter-anisotropic-webgl': ['EXT_texture_filter_anisotropic', 'EXT_texture_filter_anisotropic'],\n\n // FRAMEBUFFERS, TEXTURES AND RENDERBUFFERS\n 'texture-renderable-rgba32float-webgl': ['WEBGL_color_buffer_float', 'EXT_color_buffer_float'], // Note override check\n 'texture-renderable-float32-webgl': [false, 'EXT_color_buffer_float'],\n 'texture-renderable-float16-webgl': ['EXT_color_buffer_half_float', 'EXT_color_buffer_half_float'],\n\n // GLSL extensions\n 'glsl-frag-data': ['WEBGL_draw_buffers', true],\n 'glsl-frag-depth': ['EXT_frag_depth', true],\n 'glsl-derivatives': ['OES_standard_derivatives', true],\n 'glsl-texture-lod': ['EXT_shader_texture_lod', true]\n};\n"],"mappings":"SAQQA,QAAQ;AAAA,SACRC,OAAO;AAAA,SACPC,kBAAkB,EAAEC,4BAA4B;AAGxD,OAAO,SAASC,iBAAiBA,CAACC,EAAyB,EAAsB;EAC/E,MAAMC,QAAQ,GAAGC,gBAAgB,CAACF,EAAE,CAAC;EAIrC,KAAK,MAAMG,cAAc,IAAIN,kBAAkB,CAACG,EAAE,CAAC,EAAE;IACnDC,QAAQ,CAACG,GAAG,CAACD,cAAc,CAAC;EAC9B;EASA,OAAOF,QAAQ;AACjB;AAGA,OAAO,SAASC,gBAAgBA,CAACF,E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ology, GLPrimitive } from '@luma.gl/constants';
1
+ import { GL, GLPrimitiveTopology, GLPrimitive } from '@luma.gl/constants';
2
+ import { PrimitiveTopology } from '@luma.gl/core';
2
3
  export declare function getPrimitiveDrawMode(drawMode: GLPrimitiveTopology): GLPrimitive;
3
4
  export declare function getPrimitiveCount(options: {
4
5
  drawMode: GLPrimitiveTopology;
@@ -8,4 +9,8 @@ export declare function getVertexCount(options: {
8
9
  drawMode: GLPrimitiveTopology;
9
10
  vertexCount: number;
10
11
  }): number;
12
+ /** Get the primitive type for draw */
13
+ export declare function getGLDrawMode(topology: PrimitiveTopology): GL.POINTS | GL.LINES | GL.LINE_STRIP | GL.LINE_LOOP | GL.TRIANGLES | GL.TRIANGLE_STRIP | GL.TRIANGLE_FAN;
14
+ /** Get the primitive type for transform feedback */
15
+ export declare function getGLPrimitive(topology: PrimitiveTopology): GL.POINTS | GL.LINES | GL.TRIANGLES;
11
16
  //# sourceMappingURL=webgl-topology-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-topology-utils.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/webgl-topology-utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAK,mBAAmB,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAGxE,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,WAAW,CAmB/E;AAGD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IAAC,QAAQ,EAAE,mBAAmB,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAC,GAAG,MAAM,CAkBvG;AAGD,wBAAgB,cAAc,CAAC,OAAO,EAAE;IAAC,QAAQ,EAAE,mBAAmB,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAC,GAAG,MAAM,CAapG"}
1
+ {"version":3,"file":"webgl-topology-utils.d.ts","sourceRoot":"","sources":["../../../src/adapter/helpers/webgl-topology-utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,EAAE,EAAE,mBAAmB,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAGhD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,WAAW,CAmB/E;AAGD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IAAC,QAAQ,EAAE,mBAAmB,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAC,GAAG,MAAM,CAkBvG;AAGD,wBAAgB,cAAc,CAAC,OAAO,EAAE;IAAC,QAAQ,EAAE,mBAAmB,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAC,GAAG,MAAM,CAapG;AAED,sCAAsC;AACtC,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,iBAAiB,GAEzB,EAAE,CAAC,MAAM,GACT,EAAE,CAAC,KAAK,GACR,EAAE,CAAC,UAAU,GACb,EAAE,CAAC,SAAS,GACZ,EAAE,CAAC,SAAS,GACZ,EAAE,CAAC,cAAc,GACjB,EAAE,CAAC,YAAY,CAYlB;AAED,oDAAoD;AACpD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,iBAAiB,GAAG,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC,KAAK,GAAG,EAAE,CAAC,SAAS,CAY/F"}
@@ -61,4 +61,44 @@ export function getVertexCount(options) {
61
61
  throw new Error('drawMode');
62
62
  }
63
63
  }
64
+ export function getGLDrawMode(topology) {
65
+ switch (topology) {
66
+ case 'point-list':
67
+ return GL.POINTS;
68
+ case 'line-list':
69
+ return GL.LINES;
70
+ case 'line-strip':
71
+ return GL.LINE_STRIP;
72
+ case 'line-loop-webgl':
73
+ return GL.LINE_LOOP;
74
+ case 'triangle-list':
75
+ return GL.TRIANGLES;
76
+ case 'triangle-strip':
77
+ return GL.TRIANGLE_STRIP;
78
+ case 'triangle-fan-webgl':
79
+ return GL.TRIANGLE_FAN;
80
+ default:
81
+ throw new Error(topology);
82
+ }
83
+ }
84
+ export function getGLPrimitive(topology) {
85
+ switch (topology) {
86
+ case 'point-list':
87
+ return GL.POINTS;
88
+ case 'line-list':
89
+ return GL.LINES;
90
+ case 'line-strip':
91
+ return GL.LINES;
92
+ case 'line-loop-webgl':
93
+ return GL.LINES;
94
+ case 'triangle-list':
95
+ return GL.TRIANGLES;
96
+ case 'triangle-strip':
97
+ return GL.TRIANGLES;
98
+ case 'triangle-fan-webgl':
99
+ return GL.TRIANGLES;
100
+ default:
101
+ throw new Error(topology);
102
+ }
103
+ }
64
104
  //# sourceMappingURL=webgl-topology-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-topology-utils.js","names":["GL","getPrimitiveDrawMode","drawMode","POINTS","LINES","LINE_STRIP","LINE_LOOP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN","Error","getPrimitiveCount","options","vertexCount","getVertexCount","primitiveCount"],"sources":["../../../src/adapter/helpers/webgl-topology-utils.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {GL, GLPrimitiveTopology, GLPrimitive} from '@luma.gl/constants';\n\n// Counts the number of complete primitives given a number of vertices and a drawMode\nexport function getPrimitiveDrawMode(drawMode: GLPrimitiveTopology): GLPrimitive {\n switch (drawMode) {\n case GL.POINTS:\n return GL.POINTS;\n case GL.LINES:\n return GL.LINES;\n case GL.LINE_STRIP:\n return GL.LINES;\n case GL.LINE_LOOP:\n return GL.LINES;\n case GL.TRIANGLES:\n return GL.TRIANGLES;\n case GL.TRIANGLE_STRIP:\n return GL.TRIANGLES;\n case GL.TRIANGLE_FAN:\n return GL.TRIANGLES;\n default:\n throw new Error('drawMode');\n }\n}\n\n// Counts the number of complete \"primitives\" given a number of vertices and a drawMode\nexport function getPrimitiveCount(options: {drawMode: GLPrimitiveTopology, vertexCount: number}): number {\n const {drawMode, vertexCount} = options;\n switch (drawMode) {\n case GL.POINTS:\n case GL.LINE_LOOP:\n return vertexCount;\n case GL.LINES:\n return vertexCount / 2;\n case GL.LINE_STRIP:\n return vertexCount - 1;\n case GL.TRIANGLES:\n return vertexCount / 3;\n case GL.TRIANGLE_STRIP:\n case GL.TRIANGLE_FAN:\n return vertexCount - 2;\n default:\n throw new Error('drawMode');\n }\n}\n\n// Counts the number of vertices after splitting the vertex stream into separate \"primitives\"\nexport function getVertexCount(options: {drawMode: GLPrimitiveTopology, vertexCount: number}): number {\n const {drawMode, vertexCount} = options;\n const primitiveCount = getPrimitiveCount({drawMode, vertexCount});\n switch (getPrimitiveDrawMode(drawMode)) {\n case GL.POINTS:\n return primitiveCount;\n case GL.LINES:\n return primitiveCount * 2;\n case GL.TRIANGLES:\n return primitiveCount * 3;\n default:\n throw new Error('drawMode');\n }\n}\n"],"mappings":"AAGA,SAAQA,EAAE,QAAyC,oBAAoB;AAGvE,OAAO,SAASC,oBAAoBA,CAACC,QAA6B,EAAe;EAC/E,QAAQA,QAAQ;IACd,KAAKF,EAAE,CAACG,MAAM;MACZ,OAAOH,EAAE,CAACG,MAAM;IAClB,KAAKH,EAAE,CAACI,KAAK;MACX,OAAOJ,EAAE,CAACI,KAAK;IACjB,KAAKJ,EAAE,CAACK,UAAU;MAChB,OAAOL,EAAE,CAACI,KAAK;IACjB,KAAKJ,EAAE,CAACM,SAAS;MACf,OAAON,EAAE,CAACI,KAAK;IACjB,KAAKJ,EAAE,CAACO,SAAS;MACf,OAAOP,EAAE,CAACO,SAAS;IACrB,KAAKP,EAAE,CAACQ,cAAc;MACpB,OAAOR,EAAE,CAACO,SAAS;IACrB,KAAKP,EAAE,CAACS,YAAY;MAClB,OAAOT,EAAE,CAACO,SAAS;IACrB;MACE,MAAM,IAAIG,KAAK,CAAC,UAAU,CAAC;EAC/B;AACF;AAGA,OAAO,SAASC,iBAAiBA,CAACC,OAA6D,EAAU;EACvG,MAAM;IAACV,QAAQ;IAAEW;EAAW,CAAC,GAAGD,OAAO;EACvC,QAAQV,QAAQ;IACd,KAAKF,EAAE,CAACG,MAAM;IACd,KAAKH,EAAE,CAACM,SAAS;MACf,OAAOO,WAAW;IACpB,KAAKb,EAAE,CAACI,KAAK;MACX,OAAOS,WAAW,GAAG,CAAC;IACxB,KAAKb,EAAE,CAACK,UAAU;MAChB,OAAOQ,WAAW,GAAG,CAAC;IACxB,KAAKb,EAAE,CAACO,SAAS;MACf,OAAOM,WAAW,GAAG,CAAC;IACxB,KAAKb,EAAE,CAACQ,cAAc;IACtB,KAAKR,EAAE,CAACS,YAAY;MAClB,OAAOI,WAAW,GAAG,CAAC;IACxB;MACE,MAAM,IAAIH,KAAK,CAAC,UAAU,CAAC;EAC/B;AACF;AAGA,OAAO,SAASI,cAAcA,CAACF,OAA6D,EAAU;EACpG,MAAM;IAACV,QAAQ;IAAEW;EAAW,CAAC,GAAGD,OAAO;EACvC,MAAMG,cAAc,GAAGJ,iBAAiB,CAAC;IAACT,QAAQ;IAAEW;EAAW,CAAC,CAAC;EACjE,QAAQZ,oBAAoB,CAACC,QAAQ,CAAC;IACpC,KAAKF,EAAE,CAACG,MAAM;MACZ,OAAOY,cAAc;IACvB,KAAKf,EAAE,CAACI,KAAK;MACX,OAAOW,cAAc,GAAG,CAAC;IAC3B,KAAKf,EAAE,CAACO,SAAS;MACf,OAAOQ,cAAc,GAAG,CAAC;IAC3B;MACE,MAAM,IAAIL,KAAK,CAAC,UAAU,CAAC;EAC/B;AACF"}
1
+ {"version":3,"file":"webgl-topology-utils.js","names":["GL","getPrimitiveDrawMode","drawMode","POINTS","LINES","LINE_STRIP","LINE_LOOP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN","Error","getPrimitiveCount","options","vertexCount","getVertexCount","primitiveCount","getGLDrawMode","topology","getGLPrimitive"],"sources":["../../../src/adapter/helpers/webgl-topology-utils.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {GL, GLPrimitiveTopology, GLPrimitive} from '@luma.gl/constants';\nimport {PrimitiveTopology} from '@luma.gl/core';\n\n// Counts the number of complete primitives given a number of vertices and a drawMode\nexport function getPrimitiveDrawMode(drawMode: GLPrimitiveTopology): GLPrimitive {\n switch (drawMode) {\n case GL.POINTS:\n return GL.POINTS;\n case GL.LINES:\n return GL.LINES;\n case GL.LINE_STRIP:\n return GL.LINES;\n case GL.LINE_LOOP:\n return GL.LINES;\n case GL.TRIANGLES:\n return GL.TRIANGLES;\n case GL.TRIANGLE_STRIP:\n return GL.TRIANGLES;\n case GL.TRIANGLE_FAN:\n return GL.TRIANGLES;\n default:\n throw new Error('drawMode');\n }\n}\n\n// Counts the number of complete \"primitives\" given a number of vertices and a drawMode\nexport function getPrimitiveCount(options: {drawMode: GLPrimitiveTopology, vertexCount: number}): number {\n const {drawMode, vertexCount} = options;\n switch (drawMode) {\n case GL.POINTS:\n case GL.LINE_LOOP:\n return vertexCount;\n case GL.LINES:\n return vertexCount / 2;\n case GL.LINE_STRIP:\n return vertexCount - 1;\n case GL.TRIANGLES:\n return vertexCount / 3;\n case GL.TRIANGLE_STRIP:\n case GL.TRIANGLE_FAN:\n return vertexCount - 2;\n default:\n throw new Error('drawMode');\n }\n}\n\n// Counts the number of vertices after splitting the vertex stream into separate \"primitives\"\nexport function getVertexCount(options: {drawMode: GLPrimitiveTopology, vertexCount: number}): number {\n const {drawMode, vertexCount} = options;\n const primitiveCount = getPrimitiveCount({drawMode, vertexCount});\n switch (getPrimitiveDrawMode(drawMode)) {\n case GL.POINTS:\n return primitiveCount;\n case GL.LINES:\n return primitiveCount * 2;\n case GL.TRIANGLES:\n return primitiveCount * 3;\n default:\n throw new Error('drawMode');\n }\n}\n\n/** Get the primitive type for draw */\nexport function getGLDrawMode(\n topology: PrimitiveTopology\n):\n | GL.POINTS\n | GL.LINES\n | GL.LINE_STRIP\n | GL.LINE_LOOP\n | GL.TRIANGLES\n | GL.TRIANGLE_STRIP\n | GL.TRIANGLE_FAN {\n // prettier-ignore\n switch (topology) {\n case 'point-list': return GL.POINTS;\n case 'line-list': return GL.LINES;\n case 'line-strip': return GL.LINE_STRIP;\n case 'line-loop-webgl': return GL.LINE_LOOP;\n case 'triangle-list': return GL.TRIANGLES;\n case 'triangle-strip': return GL.TRIANGLE_STRIP;\n case 'triangle-fan-webgl': return GL.TRIANGLE_FAN;\n default: throw new Error(topology);\n }\n}\n\n/** Get the primitive type for transform feedback */\nexport function getGLPrimitive(topology: PrimitiveTopology): GL.POINTS | GL.LINES | GL.TRIANGLES {\n // prettier-ignore\n switch (topology) {\n case 'point-list': return GL.POINTS;\n case 'line-list': return GL.LINES;\n case 'line-strip': return GL.LINES;\n case 'line-loop-webgl': return GL.LINES;\n case 'triangle-list': return GL.TRIANGLES;\n case 'triangle-strip': return GL.TRIANGLES;\n case 'triangle-fan-webgl': return GL.TRIANGLES;\n default: throw new Error(topology);\n }\n}\n"],"mappings":"AAGA,SAAQA,EAAE,QAAyC,oBAAoB;AAIvE,OAAO,SAASC,oBAAoBA,CAACC,QAA6B,EAAe;EAC/E,QAAQA,QAAQ;IACd,KAAKF,EAAE,CAACG,MAAM;MACZ,OAAOH,EAAE,CAACG,MAAM;IAClB,KAAKH,EAAE,CAACI,KAAK;MACX,OAAOJ,EAAE,CAACI,KAAK;IACjB,KAAKJ,EAAE,CAACK,UAAU;MAChB,OAAOL,EAAE,CAACI,KAAK;IACjB,KAAKJ,EAAE,CAACM,SAAS;MACf,OAAON,EAAE,CAACI,KAAK;IACjB,KAAKJ,EAAE,CAACO,SAAS;MACf,OAAOP,EAAE,CAACO,SAAS;IACrB,KAAKP,EAAE,CAACQ,cAAc;MACpB,OAAOR,EAAE,CAACO,SAAS;IACrB,KAAKP,EAAE,CAACS,YAAY;MAClB,OAAOT,EAAE,CAACO,SAAS;IACrB;MACE,MAAM,IAAIG,KAAK,CAAC,UAAU,CAAC;EAC/B;AACF;AAGA,OAAO,SAASC,iBAAiBA,CAACC,OAA6D,EAAU;EACvG,MAAM;IAACV,QAAQ;IAAEW;EAAW,CAAC,GAAGD,OAAO;EACvC,QAAQV,QAAQ;IACd,KAAKF,EA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cAAc;IAC/C,KAAK,oBAAoB;MAAE,OAAOR,EAAE,CAACS,YAAY;IACjD;MAAS,MAAM,IAAIC,KAAK,CAACO,QAAQ,CAAC;EACpC;AACF;AAGA,OAAO,SAASC,cAAcA,CAACD,QAA2B,EAAuC;EAE/F,QAAQA,QAAQ;IACd,KAAK,YAAY;MAAE,OAAOjB,EAAE,CAACG,MAAM;IACnC,KAAK,WAAW;MAAE,OAAOH,EAAE,CAACI,KAAK;IACjC,KAAK,YAAY;MAAE,OAAOJ,EAAE,CAACI,KAAK;IAClC,KAAK,iBAAiB;MAAE,OAAOJ,EAAE,CAACI,KAAK;IACvC,KAAK,eAAe;MAAE,OAAOJ,EAAE,CAACO,SAAS;IACzC,KAAK,gBAAgB;MAAE,OAAOP,EAAE,CAACO,SAAS;IAC1C,KAAK,oBAAoB;MAAE,OAAOP,EAAE,CAACO,SAAS;IAC9C;MAAS,MAAM,IAAIG,KAAK,CAACO,QAAQ,CAAC;EACpC;AACF"}
@@ -27,7 +27,7 @@ export declare class WEBGLBuffer extends Buffer {
27
27
  destroy(): void;
28
28
  write(data: ArrayBufferView, byteOffset?: number): void;
29
29
  /** Read data from the buffer */
30
- readAsync(byteOffset?: number, byteLength?: number): Promise<ArrayBuffer>;
30
+ readAsync(byteOffset?: number, byteLength?: number): Promise<Uint8Array>;
31
31
  _invalidateDebugData(): void;
32
32
  _getWriteTarget(): GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER;
33
33
  _getReadTarget(): GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER;
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-buffer.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgl-buffer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAC,MAAM,EAAS,MAAM,eAAe,CAAC;AAC7C,OAAO,EA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GAAG,IAAI;IAwBpC,OAAO,IAAI,IAAI;IAWf,KAAK,CAAC,IAAI,EAAE,eAAe,EAAE,UAAU,GAAE,MAAU,GAAG,IAAI;IAqBnE,gCAAgC;IACjB,SAAS,CAAC,UAAU,SAAI,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAoBlF,oBAAoB;IAIpB,eAAe;IAKf,cAAc;CAIf"}
@@ -88,9 +88,11 @@ export class WEBGLBuffer extends Buffer {
88
88
  this.gl.bindBuffer(glTarget, null);
89
89
  }
90
90
  async readAsync() {
91
+ var _byteLength;
91
92
  let byteOffset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
92
93
  let byteLength = arguments.length > 1 ? arguments[1] : undefined;
93
94
  this.device.assertWebGL2();
95
+ byteLength = (_byteLength = byteLength) !== null && _byteLength !== void 0 ? _byteLength : this.byteLength;
94
96
  const data = new Uint8Array(byteLength);
95
97
  const dstOffset = 0;
96
98
  this.gl.bindBuffer(GL.COPY_READ_BUFFER, this.handle);
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-buffer.js","names":["Buffer","assert","GL","DEBUG_DATA_LENGTH","WEBGLBuffer","constructor","device","props","arguments","length","undefined","gl","gl2","handle","glTarget","glUsage","glIndexType","UNSIGNED_SHORT","byteLength","bytesUsed","debugData","createBuffer","setSpectorMetadata","data","getWebGLTarget","usage","getWebGLUsage","indexType","UNSIGNED_INT","_initWithData","byteOffset","_initWithByteLength","ArrayBuffer","isView","_getWriteTarget","bindBuffer","bufferData","bufferSubData","slice","trackAllocatedMemory","Float32Array","destroy","destroyed","removeStats","trackDeallocatedMemory","deleteBuffer","write","srcOffset","isWebGL2","COPY_WRITE_BUFFER","assertWebGL2","readAsync","Uint8Array","dstOffset","COPY_READ_BUFFER","getBufferSubData","_invalidateDebugData","_getReadTarget","INDEX","ELEMENT_ARRAY_BUFFER","VERTEX","ARRAY_BUFFER","UNIFORM","UNIFORM_BUFFER","STATIC_DRAW","DYNAMIC_DRAW"],"sources":["../../../src/adapter/resources/webgl-buffer.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {BufferProps} from '@luma.gl/core';\nimport {Buffer, assert} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\nimport {WebGLDevice} from '../webgl-device';\n\nconst DEBUG_DATA_LENGTH = 10;\n\n/** WebGL Buffer interface */\nexport class WEBGLBuffer extends Buffer {\n readonly device: WebGLDevice;\n readonly gl: WebGLRenderingContext;\n readonly gl2: WebGL2RenderingContext | null;\n readonly handle: WebGLBuffer;\n\n /** Target in OpenGL defines the type of buffer */\n readonly glTarget: GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER;\n /** Usage is a hint on how frequently the buffer will be updates */\n readonly glUsage: GL.STATIC_DRAW | GL.DYNAMIC_DRAW;\n /** Index type is needed when issuing draw calls, so we pre-compute it */\n readonly glIndexType: GL.UNSIGNED_SHORT | GL.UNSIGNED_INT = GL.UNSIGNED_SHORT;\n\n /** Number of bytes allocated on the GPU for this buffer */\n byteLength: number;\n /** Number of bytes used */\n bytesUsed: number;\n /** A partial CPU-side copy of the data in this buffer, for debugging purposes */\n debugData: ArrayBuffer | null = null;\n\n constructor(device: WebGLDevice, props: BufferProps = {}) {\n super(device, props);\n\n this.device = device;\n this.gl = this.device.gl;\n this.gl2 = this.device.gl2;\n\n const handle = typeof props === 'object' ? (props ).handle : undefined;\n this.handle = handle || this.gl.createBuffer();\n device.setSpectorMetadata(this.handle, {...this.props, data: typeof this.props.data});\n\n // - In WebGL1, need to make sure we use GL.ELEMENT_ARRAY_BUFFER when initializing element buffers\n // otherwise buffer type will lock to generic (non-element) buffer\n // - In WebGL2, we can use GL.COPY_READ_BUFFER which avoids locking the type here\n this.glTarget = getWebGLTarget(this.props.usage);\n this.glUsage = getWebGLUsage(this.props.usage);\n this.glIndexType = this.props.indexType === 'uint32' ? GL.UNSIGNED_INT : GL.UNSIGNED_SHORT;\n\n this.debugData = null;\n\n // Set data: (re)initializes the buffer\n if (props.data) {\n this._initWithData(props.data, props.byteOffset, props.byteLength);\n } else {\n this._initWithByteLength(props.byteLength || 0);\n }\n }\n\n // PRIVATE METHODS\n\n /** Allocate a new buffer and initialize to contents of typed array */\n _initWithData(data, byteOffset: number = 0, byteLength: number = data.byteLength + byteOffset): this {\n assert(ArrayBuffer.isView(data));\n\n const glTarget = this._getWriteTarget();\n this.gl.bindBuffer(glTarget, this.handle);\n this.gl.bufferData(glTarget, byteLength, this.glUsage);\n this.gl.bufferSubData(glTarget, byteOffset, data);\n this.gl.bindBuffer(glTarget, null);\n\n this.debugData = data.slice(0, DEBUG_DATA_LENGTH);\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n this.trackAllocatedMemory(byteLength);\n\n return this;\n }\n\n // Allocate a GPU buffer of specified size.\n _initWithByteLength(byteLength: number): this {\n assert(byteLength >= 0);\n\n // Workaround needed for Safari (#291):\n // gl.bufferData with size equal to 0 crashes. Instead create zero sized array.\n let data = byteLength;\n if (byteLength === 0) {\n // @ts-expect-error\n data = new Float32Array(0);\n }\n\n const glTarget = this._getWriteTarget();\n\n this.gl.bindBuffer(glTarget, this.handle);\n this.gl.bufferData(glTarget, data, this.glUsage);\n this.gl.bindBuffer(glTarget, null);\n\n this.debugData = null;\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n\n return this;\n }\n\n override destroy(): void {\n if (!this.destroyed && this.handle) {\n this.removeStats();\n this.trackDeallocatedMemory();\n this.gl.deleteBuffer(this.handle);\n this.destroyed = true;\n // @ts-expect-error\n this.handle = null;\n }\n }\n\n override write(data: ArrayBufferView, byteOffset: number = 0): void {\n const srcOffset = 0;\n const byteLength = undefined; // data.byteLength;\n\n // Create the buffer - binding it here for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n const glTarget = this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;\n this.gl.bindBuffer(glTarget, this.handle);\n // WebGL2: subData supports additional srcOffset and length parameters\n if (srcOffset !== 0 || byteLength !== undefined) {\n this.device.assertWebGL2();\n this.gl2.bufferSubData(glTarget, byteOffset, data, srcOffset, byteLength);\n } else {\n this.gl.bufferSubData(glTarget, byteOffset, data);\n }\n this.gl.bindBuffer(glTarget, null);\n\n // TODO - update local `data` if offsets are right\n // this.debugData = data.slice(byteOffset, 40);\n }\n\n /** Read data from the buffer */\n override async readAsync(\n byteOffset: number = 0,\n byteLength?: number\n ): Promise<ArrayBuffer> {\n this.device.assertWebGL2();\n\n const data = new Uint8Array(byteLength);\n const dstOffset = 0;\n\n // Use GL.COPY_READ_BUFFER to avoid disturbing other targets and locking type\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, this.handle);\n this.gl2.getBufferSubData(GL.COPY_READ_BUFFER, byteOffset, data, dstOffset, byteLength);\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, null);\n\n // TODO - update local `data` if offsets are 0\n // this.debugData = null;\n\n return data;\n }\n\n // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)\n\n _invalidateDebugData() {\n this.debugData = null;\n }\n\n _getWriteTarget() {\n return this.glTarget;\n // return this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;\n }\n\n _getReadTarget() {\n return this.glTarget;\n // return this.device.isWebGL2 ? GL.COPY_READ_BUFFER : this.glTarget;\n }\n}\n\n// static MAP_READ = 0x01;\n// static MAP_WRITE = 0x02;\n// static COPY_SRC = 0x0004;\n// static COPY_DST = 0x0008;\n// static INDEX = 0x0010;\n// static VERTEX = 0x0020;\n// static UNIFORM = 0x0040;\n// static STORAGE = 0x0080;\n// static INDIRECT = 0x0100;\n// static QUERY_RESOLVE = 0x0200;\n\nfunction getWebGLTarget(usage: number): GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER {\n if (usage & Buffer.INDEX) {\n return GL.ELEMENT_ARRAY_BUFFER;\n }\n if (usage & Buffer.VERTEX) {\n return GL.ARRAY_BUFFER;\n }\n if (usage & Buffer.UNIFORM) {\n return GL.UNIFORM_BUFFER;\n }\n\n // gl.COPY_READ_BUFFER: Buffer for copying from one buffer object to another.\n // gl.COPY_WRITE_BUFFER: Buffer for copying from one buffer object to another.\n // gl.TRANSFORM_FEEDBACK_BUFFER: Buffer for transform feedback operations.\n // gl.PIXEL_PACK_BUFFER: Buffer used for pixel transfer operations.\n // gl.PIXEL_UNPACK_BUFFER: Buffer used for pixel transfer operations.\n\n // Binding a buffer for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n return GL.ARRAY_BUFFER;\n}\n\n/** @todo usage is not passed correctly */\nfunction getWebGLUsage(usage: number): GL.STATIC_DRAW | GL.DYNAMIC_DRAW {\n if (usage & Buffer.INDEX) {\n return GL.STATIC_DRAW;\n }\n if (usage & Buffer.VERTEX) {\n return GL.STATIC_DRAW;\n }\n if (usage & Buffer.UNIFORM) {\n return GL.DYNAMIC_DRAW;\n }\n return GL.STATIC_DRAW;\n}\n"],"mappings":"AAIA,SAAQA,MAAM,EAAEC,MAAM,QAAO,eAAe;AAC5C,SAAQC,EAAE,QAAO,oBAAoB;AAGrC,MAAMC,iBAAiB,GAAG,EAAE;AAG5B,OAAO,MAAMC,WAAW,SAASJ,MAAM,CAAC;EAoBtCK,WAAWA,CAACC,MAAmB,EAA2B;IAAA,IAAzBC,KAAkB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IACtD,KAAK,CAACF,MAAM,EAAEC,KAAK,CAAC;IAAC,KApBdD,MAAM;IAAA,KACNK,EAAE;IAAA,KACFC,GAAG;IAAA,KACHC,MAAM;IAAA,KAGNC,QAAQ;IAAA,KAERC,OAAO;IAAA,KAEPC,WAAW,GAAwCd,EAAE,CAACe,cAAc;IAAA,KAG7EC,UAAU;IAAA,KAEVC,SA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EAChC;EACA,IAAIlC,KAAK,GAAGzB,MAAM,CAAC4D,MAAM,EAAE;IACzB,OAAO1D,EAAE,CAAC2D,YAAY;EACxB;EACA,IAAIpC,KAAK,GAAGzB,MAAM,CAAC8D,OAAO,EAAE;IAC1B,OAAO5D,EAAE,CAAC6D,cAAc;EAC1B;EAUA,OAAO7D,EAAE,CAAC2D,YAAY;AACxB;AAGA,SAASnC,aAAaA,CAACD,KAAa,EAAoC;EACtE,IAAIA,KAAK,GAAGzB,MAAM,CAAC0D,KAAK,EAAE;IACxB,OAAOxD,EAAE,CAAC8D,WAAW;EACvB;EACA,IAAIvC,KAAK,GAAGzB,MAAM,CAAC4D,MAAM,EAAE;IACzB,OAAO1D,EAAE,CAAC8D,WAAW;EACvB;EACA,IAAIvC,KAAK,GAAGzB,MAAM,CAAC8D,OAAO,EAAE;IAC1B,OAAO5D,EAAE,CAAC+D,YAAY;EACxB;EACA,OAAO/D,EAAE,CAAC8D,WAAW;AACvB"}
1
+ {"version":3,"file":"webgl-buffer.js","names":["Buffer","assert","GL","DEBUG_DATA_LENGTH","WEBGLBuffer","constructor","device","props","arguments","length","undefined","gl","gl2","handle","glTarget","glUsage","glIndexType","UNSIGNED_SHORT","byteLength","bytesUsed","debugData","createBuffer","setSpectorMetadata","data","getWebGLTarget","usage","getWebGLUsage","indexType","UNSIGNED_INT","_initWithData","byteOffset","_initWithByteLength","ArrayBuffer","isView","_getWriteTarget","bindBuffer","bufferData","bufferSubData","slice","trackAllocatedMemory","Float32Array","destroy","destroyed","removeStats","trackDeallocatedMemory","deleteBuffer","write","srcOffset","isWebGL2","COPY_WRITE_BUFFER","assertWebGL2","readAsync","_byteLength","Uint8Array","dstOffset","COPY_READ_BUFFER","getBufferSubData","_invalidateDebugData","_getReadTarget","INDEX","ELEMENT_ARRAY_BUFFER","VERTEX","ARRAY_BUFFER","UNIFORM","UNIFORM_BUFFER","STATIC_DRAW","DYNAMIC_DRAW"],"sources":["../../../src/adapter/resources/webgl-buffer.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {BufferProps} from '@luma.gl/core';\nimport {Buffer, assert} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\nimport {WebGLDevice} from '../webgl-device';\n\nconst DEBUG_DATA_LENGTH = 10;\n\n/** WebGL Buffer interface */\nexport class WEBGLBuffer extends Buffer {\n readonly device: WebGLDevice;\n readonly gl: WebGLRenderingContext;\n readonly gl2: WebGL2RenderingContext | null;\n readonly handle: WebGLBuffer;\n\n /** Target in OpenGL defines the type of buffer */\n readonly glTarget: GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER;\n /** Usage is a hint on how frequently the buffer will be updates */\n readonly glUsage: GL.STATIC_DRAW | GL.DYNAMIC_DRAW;\n /** Index type is needed when issuing draw calls, so we pre-compute it */\n readonly glIndexType: GL.UNSIGNED_SHORT | GL.UNSIGNED_INT = GL.UNSIGNED_SHORT;\n\n /** Number of bytes allocated on the GPU for this buffer */\n byteLength: number;\n /** Number of bytes used */\n bytesUsed: number;\n /** A partial CPU-side copy of the data in this buffer, for debugging purposes */\n debugData: ArrayBuffer | null = null;\n\n constructor(device: WebGLDevice, props: BufferProps = {}) {\n super(device, props);\n\n this.device = device;\n this.gl = this.device.gl;\n this.gl2 = this.device.gl2;\n\n const handle = typeof props === 'object' ? props.handle : undefined;\n this.handle = handle || this.gl.createBuffer();\n device.setSpectorMetadata(this.handle, {...this.props, data: typeof this.props.data});\n\n // - In WebGL1, need to make sure we use GL.ELEMENT_ARRAY_BUFFER when initializing element buffers\n // otherwise buffer type will lock to generic (non-element) buffer\n // - In WebGL2, we can use GL.COPY_READ_BUFFER which avoids locking the type here\n this.glTarget = getWebGLTarget(this.props.usage);\n this.glUsage = getWebGLUsage(this.props.usage);\n this.glIndexType = this.props.indexType === 'uint32' ? GL.UNSIGNED_INT : GL.UNSIGNED_SHORT;\n\n this.debugData = null;\n\n // Set data: (re)initializes the buffer\n if (props.data) {\n this._initWithData(props.data, props.byteOffset, props.byteLength);\n } else {\n this._initWithByteLength(props.byteLength || 0);\n }\n }\n\n // PRIVATE METHODS\n\n /** Allocate a new buffer and initialize to contents of typed array */\n _initWithData(\n data,\n byteOffset: number = 0,\n byteLength: number = data.byteLength + byteOffset\n ): this {\n assert(ArrayBuffer.isView(data));\n\n const glTarget = this._getWriteTarget();\n this.gl.bindBuffer(glTarget, this.handle);\n this.gl.bufferData(glTarget, byteLength, this.glUsage);\n this.gl.bufferSubData(glTarget, byteOffset, data);\n this.gl.bindBuffer(glTarget, null);\n\n this.debugData = data.slice(0, DEBUG_DATA_LENGTH);\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n this.trackAllocatedMemory(byteLength);\n\n return this;\n }\n\n // Allocate a GPU buffer of specified size.\n _initWithByteLength(byteLength: number): this {\n assert(byteLength >= 0);\n\n // Workaround needed for Safari (#291):\n // gl.bufferData with size equal to 0 crashes. Instead create zero sized array.\n let data = byteLength;\n if (byteLength === 0) {\n // @ts-expect-error\n data = new Float32Array(0);\n }\n\n const glTarget = this._getWriteTarget();\n\n this.gl.bindBuffer(glTarget, this.handle);\n this.gl.bufferData(glTarget, data, this.glUsage);\n this.gl.bindBuffer(glTarget, null);\n\n this.debugData = null;\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n\n return this;\n }\n\n override destroy(): void {\n if (!this.destroyed && this.handle) {\n this.removeStats();\n this.trackDeallocatedMemory();\n this.gl.deleteBuffer(this.handle);\n this.destroyed = true;\n // @ts-expect-error\n this.handle = null;\n }\n }\n\n override write(data: ArrayBufferView, byteOffset: number = 0): void {\n const srcOffset = 0;\n const byteLength = undefined; // data.byteLength;\n\n // Create the buffer - binding it here for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n const glTarget = this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;\n this.gl.bindBuffer(glTarget, this.handle);\n // WebGL2: subData supports additional srcOffset and length parameters\n if (srcOffset !== 0 || byteLength !== undefined) {\n this.device.assertWebGL2();\n this.gl2.bufferSubData(glTarget, byteOffset, data, srcOffset, byteLength);\n } else {\n this.gl.bufferSubData(glTarget, byteOffset, data);\n }\n this.gl.bindBuffer(glTarget, null);\n\n // TODO - update local `data` if offsets are right\n // this.debugData = data.slice(byteOffset, 40);\n }\n\n /** Read data from the buffer */\n override async readAsync(byteOffset = 0, byteLength?: number): Promise<Uint8Array> {\n this.device.assertWebGL2();\n\n byteLength = byteLength ?? this.byteLength;\n const data = new Uint8Array(byteLength);\n const dstOffset = 0;\n\n // Use GL.COPY_READ_BUFFER to avoid disturbing other targets and locking type\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, this.handle);\n this.gl2.getBufferSubData(GL.COPY_READ_BUFFER, byteOffset, data, dstOffset, byteLength);\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, null);\n\n // TODO - update local `data` if offsets are 0\n // this.debugData = null;\n\n return data;\n }\n\n // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)\n\n _invalidateDebugData() {\n this.debugData = null;\n }\n\n _getWriteTarget() {\n return this.glTarget;\n // return this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;\n }\n\n _getReadTarget() {\n return this.glTarget;\n // return this.device.isWebGL2 ? GL.COPY_READ_BUFFER : this.glTarget;\n }\n}\n\n// static MAP_READ = 0x01;\n// static MAP_WRITE = 0x02;\n// static COPY_SRC = 0x0004;\n// static COPY_DST = 0x0008;\n// static INDEX = 0x0010;\n// static VERTEX = 0x0020;\n// static UNIFORM = 0x0040;\n// static STORAGE = 0x0080;\n// static INDIRECT = 0x0100;\n// static QUERY_RESOLVE = 0x0200;\n\nfunction getWebGLTarget(\n usage: number\n): GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER {\n if (usage & Buffer.INDEX) {\n return GL.ELEMENT_ARRAY_BUFFER;\n }\n if (usage & Buffer.VERTEX) {\n return GL.ARRAY_BUFFER;\n }\n if (usage & Buffer.UNIFORM) {\n return GL.UNIFORM_BUFFER;\n }\n\n // gl.COPY_READ_BUFFER: Buffer for copying from one buffer object to another.\n // gl.COPY_WRITE_BUFFER: Buffer for copying from one buffer object to another.\n // gl.TRANSFORM_FEEDBACK_BUFFER: Buffer for transform feedback operations.\n // gl.PIXEL_PACK_BUFFER: Buffer used for pixel transfer operations.\n // gl.PIXEL_UNPACK_BUFFER: Buffer used for pixel transfer operations.\n\n // Binding a buffer for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n return GL.ARRAY_BUFFER;\n}\n\n/** @todo usage is not passed correctly */\nfunction getWebGLUsage(usage: number): GL.STATIC_DRAW | GL.DYNAMIC_DRAW {\n if (usage & Buffer.INDEX) {\n return GL.STATIC_DRAW;\n }\n if (usage & Buffer.VERTEX) {\n return GL.STATIC_DRAW;\n }\n if (usage & Buffer.UNIFORM) {\n return GL.DYNAMIC_DRAW;\n }\n return GL.STATIC_DRAW;\n}\n"],"mappings":"AAIA,SAAQA,MAAM,EAAEC,MAAM,QAAO,eAAe;AAC5C,SAAQC,EAAE,QAAO,oBAAoB;AAGrC,MAAMC,iBAAiB,GAAG,EAAE;AAG5B,OAAO,MAAMC,WAAW,SAASJ,MAAM,CAAC;EAoBtCK,WAAWA,CAACC,MAAmB,EAA2B;IAAA,IAAzBC,KAAkB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IACtD,KAAK,CAACF,MAAM,EAAEC,KAAK,CAAC;IAAC,KApBdD,MAAM;IAAA,KACNK,EAAE;IAAA,KACFC,GAAG;IAAA,KACHC,MAAM;IAAA,KAGNC,QAAQ;IAAA,KAERC,OAAO;IAAA,KAEPC,WAAW,GAAwCd,EAAE,CAACe,cAAc;IAAA,KAG7EC,UAAU;IAAA,KAEVC,SAAS;IAAA,KAETC,SAAS,GAA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AC/D,IAAIA,KAAK,GAAGzB,MAAM,CAAC2D,KAAK,EAAE;IACxB,OAAOzD,EAAE,CAAC0D,oBAAoB;EAChC;EACA,IAAInC,KAAK,GAAGzB,MAAM,CAAC6D,MAAM,EAAE;IACzB,OAAO3D,EAAE,CAAC4D,YAAY;EACxB;EACA,IAAIrC,KAAK,GAAGzB,MAAM,CAAC+D,OAAO,EAAE;IAC1B,OAAO7D,EAAE,CAAC8D,cAAc;EAC1B;EAUA,OAAO9D,EAAE,CAAC4D,YAAY;AACxB;AAGA,SAASpC,aAAaA,CAACD,KAAa,EAAoC;EACtE,IAAIA,KAAK,GAAGzB,MAAM,CAAC2D,KAAK,EAAE;IACxB,OAAOzD,EAAE,CAAC+D,WAAW;EACvB;EACA,IAAIxC,KAAK,GAAGzB,MAAM,CAAC6D,MAAM,EAAE;IACzB,OAAO3D,EAAE,CAAC+D,WAAW;EACvB;EACA,IAAIxC,KAAK,GAAGzB,MAAM,CAAC+D,OAAO,EAAE;IAC1B,OAAO7D,EAAE,CAACgE,YAAY;EACxB;EACA,OAAOhE,EAAE,CAAC+D,WAAW;AACvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-command-buffer.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgl-command-buffer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,2BAA2B,EAC5B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,aAAa,EAId,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAC;AAGtC,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAS5C,KAAK,yBAAyB,GAAG;IAC/B,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,yBAAyB,CAAC;CACpC,CAAC;AAEF,KAAK,0BAA0B,GAAG;IAChC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAA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0BAA0B,CAAC;CACrC,CAAC;AAEF,KAAK,0BAA0B,GAAG;IAChC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO,EAAE,0BAA0B,CAAC;CACrC,CAAC;AAEF,KAAK,2BAA2B,GAAG;IACjC,IAAI,EAAE,yBAAyB,CAAC;IAChC,OAAO,EAAE,2BAA2B,CAAC;CACtC,CAAC;AAEF,KAAK,OAAO,GACR,yBAAyB,GACzB,0BAA0B,GAC1B,0BAA0B,GAC1B,2BAA2B,CAAC;AAEhC,qBAAa,kBAAmB,SAAQ,aAAa;IACnD,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,OAAO,EAAE,CAAM;gBAEb,MAAM,EAAE,WAAW;IAK/B,cAAc,CAAC,QAAQ,GAAE,OAAO,EAAkB;CAkBnD;AAwQD,wBAAgB,oBAAoB,CAAC,MAAM,KAAA,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAmB1D;AAGD,wBAAgB,aAAa,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAcjD"}
@@ -1,12 +1,13 @@
1
1
  import { CommandBuffer, Texture } from '@luma.gl/core';
2
2
  import { GL } from '@luma.gl/constants';
3
3
  import { WEBGLTexture } from "./webgl-texture.js";
4
+ import { getWebGLTextureParameters } from "../converters/texture-formats.js";
4
5
  function cast(value) {
5
6
  return value;
6
7
  }
7
8
  export class WEBGLCommandBuffer extends CommandBuffer {
8
9
  constructor(device) {
9
- super({});
10
+ super(device, {});
10
11
  this.device = void 0;
11
12
  this.commands = [];
12
13
  this.device = device;
@@ -66,7 +67,7 @@ function _copyTextureToBuffer(device, options) {
66
67
  if (aspect !== 'all') {
67
68
  throw new Error('not supported');
68
69
  }
69
- if (mipLevel !== 0 || depthOrArrayLayers !== undefined || bytesPerRow || rowsPerImage) {
70
+ if (mipLevel !== 0 || depthOrArrayLayers !== 0 || bytesPerRow || rowsPerImage) {
70
71
  throw new Error('not implemented');
71
72
  }
72
73
  const gl2 = device.assertWebGL2();
@@ -78,8 +79,9 @@ function _copyTextureToBuffer(device, options) {
78
79
  const webglBuffer = destination;
79
80
  const sourceWidth = width || framebuffer.width;
80
81
  const sourceHeight = height || framebuffer.height;
81
- const sourceFormat = GL.RGBA;
82
- const sourceType = GL.UNSIGNED_BYTE;
82
+ const sourceParams = getWebGLTextureParameters(framebuffer.texture.format, true);
83
+ const sourceFormat = sourceParams.dataFormat;
84
+ const sourceType = sourceParams.type;
83
85
  gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, webglBuffer.handle);
84
86
  gl2.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);
85
87
  gl2.readPixels(origin[0], origin[1], sourceWidth, sourceHeight, sourceFormat, sourceType, byteOffset);
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-command-buffer.js","names":["CommandBuffer","Texture","GL","WEBGLTexture","cast","value","WEBGLCommandBuffer","constructor","device","commands","submitCommands","arguments","length","undefined","command","name","_copyBufferToBuffer","options","_copyBufferToTexture","_copyTextureToBuffer","_copyTextureToTexture","source","destination","gl2","assertWebGL2","_options$sourceOffset","_options$destinationO","bindBuffer","COPY_READ_BUFFER","handle","COPY_WRITE_BUFFER","copyBufferSubData","sourceOffset","destinationOffset","size","Error","mipLevel","aspect","width","height","depthOrArrayLayers","origin","byteOffset","bytesPerRow","rowsPerImage","framebuffer","destroyFramebuffer","getFramebuffer","webglBuffer","sourceWidth","sourceHeight","sourceFormat","RGBA","sourceType","UNSIGNED_BYTE","PIXEL_PACK_BUFFER","bindFramebuffer","FRAMEBUFFER","readPixels","destroy","destinationMipmaplevel","destinationInternalFormat","sourceX","sourceY","isSubCopy","gl","texture","textureTarget","Number","isFinite","bind","copyTexImage2D","unbind","glFormatToComponents","format","ALPHA","R32F","RED","RG32F","RG","RGB","RGB32F","RGBA32F","glTypeToBytes","type","UNSIGNED_SHORT_5_6_5","UNSIGNED_SHORT_4_4_4_4","UNSIGNED_SHORT_5_5_5_1","FLOAT","id","createFramebuffer","colorAttachments"],"sources":["../../../src/adapter/resources/webgl-command-buffer.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {\n CopyBufferToBufferOptions,\n CopyBufferToTextureOptions,\n CopyTextureToBufferOptions,\n CopyTextureToTextureOptions\n} from '@luma.gl/core';\nimport {\n CommandBuffer,\n Texture,\n // Buffer,\n Framebuffer\n} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\n\n// import {getTypedArrayFromGLType, getGLTypeFromTypedArray} from '../../classic/typed-array-utils';\nimport {WebGLDevice} from '../webgl-device';\nimport {WEBGLBuffer} from './webgl-buffer';\nimport {WEBGLTexture} from './webgl-texture';\nimport {WEBGLFramebuffer} from './webgl-framebuffer';\n\nfunction cast<T>(value: unknown): T {\n return value as T;\n}\n\ntype CopyBufferToBufferCommand = {\n name: 'copy-buffer-to-buffer';\n options: CopyBufferToBufferOptions;\n};\n\ntype CopyBufferToTextureCommand = {\n name: 'copy-buffer-to-texture';\n options: CopyBufferToTextureOptions;\n};\n\ntype CopyTextureToBufferCommand = {\n name: 'copy-texture-to-buffer';\n options: CopyTextureToBufferOptions;\n};\n\ntype CopyTextureToTextureCommand = {\n name: 'copy-texture-to-texture';\n options: CopyTextureToTextureOptions;\n};\n\ntype Command =\n | CopyBufferToBufferCommand\n | CopyBufferToTextureCommand\n | CopyTextureToBufferCommand\n | CopyTextureToTextureCommand;\n\nexport class WEBGLCommandBuffer extends CommandBuffer {\n device: WebGLDevice;\n commands: Command[] = [];\n\n constructor(device: WebGLDevice) {\n super({});\n this.device = device;\n }\n\n submitCommands(commands: Command[] = this.commands) {\n for (const command of commands) {\n switch (command.name) {\n case 'copy-buffer-to-buffer':\n _copyBufferToBuffer(this.device, command.options);\n break;\n case 'copy-buffer-to-texture':\n _copyBufferToTexture(this.device, command.options);\n break;\n case 'copy-texture-to-buffer':\n _copyTextureToBuffer(this.device, command.options);\n break;\n case 'copy-texture-to-texture':\n _copyTextureToTexture(this.device, command.options);\n break;\n }\n }\n }\n}\n\nfunction _copyBufferToBuffer(device: WebGLDevice, options: CopyBufferToBufferOptions): void {\n const source = cast<WEBGLBuffer>(options.source);\n const destination = cast<WEBGLBuffer>(options.destination);\n\n const gl2 = device.assertWebGL2();\n if (gl2) {\n // In WebGL2 we can perform the copy on the GPU\n // Use GL.COPY_READ_BUFFER+GL.COPY_WRITE_BUFFER avoid disturbing other targets and locking type\n gl2.bindBuffer(GL.COPY_READ_BUFFER, source.handle);\n gl2.bindBuffer(GL.COPY_WRITE_BUFFER, destination.handle);\n gl2.copyBufferSubData(\n GL.COPY_READ_BUFFER,\n GL.COPY_WRITE_BUFFER,\n options.sourceOffset ?? 0,\n options.destinationOffset ?? 0,\n options.size\n );\n gl2.bindBuffer(GL.COPY_READ_BUFFER, null);\n gl2.bindBuffer(GL.COPY_WRITE_BUFFER, null);\n } else {\n // TODO - in WebGL1 we would have to read back to CPU\n // read / write buffer from / to CPU\n throw new Error('copyBufferToBuffer not implemented in WebGL1');\n }\n}\n\n/**\n * Copies data from a Buffer object into a Texture object\n * NOTE: doesn't wait for copy to be complete\n */\nfunction _copyBufferToTexture(device: WebGLDevice, options: CopyBufferToTextureOptions): void {\n throw new Error('Not implemented');\n}\n\n/**\n * Copies data from a Texture object into a Buffer object.\n * NOTE: doesn't wait for copy to be complete\n */\nfunction _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferOptions): void {\n const {\n /** Texture to copy to/from. */\n source,\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n mipLevel = 0,\n /** Defines which aspects of the texture to copy to/from. */\n aspect = 'all',\n\n /** Width to copy */\n width = options.source.width,\n /** Height to copy */\n height = options.source.height,\n depthOrArrayLayers = 0,\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */\n origin = [0, 0],\n\n /** Destination buffer */\n destination,\n /** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */\n byteOffset = 0,\n /**\n * The stride, in bytes, between the beginning of each block row and the subsequent block row.\n * Required if there are multiple block rows (i.e. the copy height or depth is more than one block).\n */\n bytesPerRow,\n /**\n * Number of block rows per single image of the texture.\n * rowsPerImage &times; bytesPerRow is the stride, in bytes, between the beginning of each image of data and the subsequent image.\n * Required if there are multiple images (i.e. the copy depth is more than one).\n */\n rowsPerImage\n } = options;\n\n // TODO - Not possible to read just stencil or depth part in WebGL?\n if (aspect !== 'all') {\n throw new Error('not supported');\n }\n\n // TODO - mipLevels are set when attaching texture to framebuffer\n if (mipLevel !== 0 || depthOrArrayLayers !== undefined || bytesPerRow || rowsPerImage) {\n throw new Error('not implemented');\n }\n\n // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature\n const gl2 = device.assertWebGL2();\n\n const {framebuffer, destroyFramebuffer} = getFramebuffer(source);\n try {\n const webglBuffer = destination as WEBGLBuffer;\n const sourceWidth = width || framebuffer.width;\n const sourceHeight = height || framebuffer.height;\n\n // TODO - hack - should be deduced\n const sourceFormat = GL.RGBA;\n const sourceType = GL.UNSIGNED_BYTE;\n\n // if (!target) {\n // // Create new buffer with enough size\n // const components = glFormatToComponents(sourceFormat);\n // const byteCount = glTypeToBytes(sourceType);\n // const byteLength = byteOffset + sourceWidth * sourceHeight * components * byteCount;\n // target = device.createBuffer({byteLength});\n // }\n\n gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, webglBuffer.handle);\n gl2.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);\n\n gl2.readPixels(\n origin[0],\n origin[1],\n sourceWidth,\n sourceHeight,\n sourceFormat,\n sourceType,\n byteOffset\n );\n } finally {\n gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, null);\n gl2.bindFramebuffer(GL.FRAMEBUFFER, null);\n\n if (destroyFramebuffer) {\n framebuffer.destroy();\n }\n }\n}\n\n/**\n * Copies data from a Framebuffer or a Texture object into a Buffer object.\n * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transfer.\nexport function readPixelsToBuffer(\n source: Framebuffer | Texture,\n options?: {\n sourceX?: number;\n sourceY?: number;\n sourceFormat?: number;\n target?: Buffer; // A new Buffer object is created when not provided.\n targetByteOffset?: number; // byte offset in buffer object\n // following parameters are auto deduced if not provided\n sourceWidth?: number;\n sourceHeight?: number;\n sourceType?: number;\n }\n): Buffer\n */\n\n/**\n * Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)\n */\n// eslint-disable-next-line complexity, max-statements\nfunction _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextureOptions): void {\n const {\n /** Texture to copy to/from. */\n source,\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n // mipLevel = 0,\n /** Defines which aspects of the texture to copy to/from. */\n // aspect = 'all',\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */\n origin = [0, 0],\n\n /** Texture to copy to/from. */\n destination,\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n // destinationMipLevel = options.mipLevel,\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */\n // destinationOrigin = [0, 0],\n /** Defines which aspects of the texture to copy to/from. */\n // destinationAspect = options.aspect,\n\n } = options;\n\n let {\n width = options.destination.width,\n height = options.destination.width,\n // depthOrArrayLayers = 0\n } = options;\n\n const destinationMipmaplevel = 0;\n const destinationInternalFormat = GL.RGBA;\n\n const {framebuffer, destroyFramebuffer} = getFramebuffer(source);\n const [sourceX, sourceY] = origin;\n\n const isSubCopy = false;\n // typeof destinationX !== 'undefined' ||\n // typeof destinationY !== 'undefined' ||\n // typeof destinationZ !== 'undefined';\n\n // destinationX = destinationX || 0;\n // destinationY = destinationY || 0;\n // destinationZ = destinationZ || 0;\n device.gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);\n // TODO - support gl.readBuffer (WebGL2 only)\n // const prevBuffer = gl.readBuffer(attachment);\n\n let texture = null;\n let textureTarget: GL;\n if (destination instanceof WEBGLTexture) {\n texture = destination;\n width = Number.isFinite(width) ? width : texture.width;\n height = Number.isFinite(height) ? height : texture.height;\n texture.bind(0);\n textureTarget = texture.destination;\n } else {\n throw new Error('whoops');\n // textureTarget = destination;\n }\n\n if (!isSubCopy) {\n device.gl.copyTexImage2D(\n textureTarget,\n destinationMipmaplevel,\n destinationInternalFormat,\n sourceX,\n sourceY,\n width,\n height,\n 0 /* border must be 0 */\n );\n } else {\n // switch (textureTarget) {\n // case GL.TEXTURE_2D:\n // case GL.TEXTURE_CUBE_MAP:\n // device.gl.copyTexSubImage2D(\n // textureTarget,\n // destinationMipmaplevel,\n // destinationX,\n // destinationY,\n // sourceX,\n // sourceY,\n // width,\n // height\n // );\n // break;\n // case GL.TEXTURE_2D_ARRAY:\n // case GL.TEXTURE_3D:\n // const gl2 = device.assertWebGL2();\n // gl2.copyTexSubImage3D(\n // textureTarget,\n // destinationMipmaplevel,\n // destinationX,\n // destinationY,\n // destinationZ,\n // sourceX,\n // sourceY,\n // width,\n // height\n // );\n // break;\n // default:\n // }\n }\n if (texture) {\n texture.unbind();\n }\n // ts-expect-error\n // device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);\n if (destroyFramebuffer) {\n framebuffer.destroy();\n }\n return texture;\n}\n\n// Returns number of components in a specific readPixels WebGL format\nexport function glFormatToComponents(format): 1 | 2 | 3 | 4 {\n switch (format) {\n case GL.ALPHA:\n case GL.R32F:\n case GL.RED:\n return 1;\n case GL.RG32F:\n case GL.RG:\n return 2;\n case GL.RGB:\n case GL.RGB32F:\n return 3;\n case GL.RGBA:\n case GL.RGBA32F:\n return 4;\n // TODO: Add support for additional WebGL2 formats\n default:\n throw new Error('GLFormat');\n }\n}\n\n// Return byte count for given readPixels WebGL type\nexport function glTypeToBytes(type: GL): 1 | 2 | 4 {\n switch (type) {\n case GL.UNSIGNED_BYTE:\n return 1;\n case GL.UNSIGNED_SHORT_5_6_5:\n case GL.UNSIGNED_SHORT_4_4_4_4:\n case GL.UNSIGNED_SHORT_5_5_5_1:\n return 2;\n case GL.FLOAT:\n return 4;\n // TODO: Add support for additional WebGL2 types\n default:\n throw new Error('GLType');\n }\n}\n\n// Helper methods\n\nfunction getFramebuffer(source: Texture | Framebuffer): {\n framebuffer: WEBGLFramebuffer;\n destroyFramebuffer: boolean;\n} {\n if (source instanceof Texture) {\n const {width, height, id} = source;\n const framebuffer = source.device.createFramebuffer({\n id: `framebuffer-for-${id}`,\n width,\n height,\n colorAttachments: [source]\n }) as unknown as WEBGLFramebuffer;\n\n return {framebuffer, destroyFramebuffer: true};\n }\n return {framebuffer: source as unknown as WEBGLFramebuffer, destroyFramebuffer: false};\n}\n"],"mappings":"AASA,SACEA,aAAa,EACbC,OAAO,QAGF,eAAe;AACtB,SAAQC,EAAE,QAAO,oBAAoB;AAAC,SAK9BC,YAAY;AAGpB,SAASC,IAAIA,CAAIC,KAAc,EAAK;EAClC,OAAOA,KAAK;AACd;AA4BA,OAAO,MAAMC,kBAAkB,SAASN,aAAa,CAAC;EAIpDO,WAAWA,CAACC,MAAmB,EAAE;IAC/B,KAAK,CAAC,CAAC,CAAC,CAAC;IAAC,KAJZA,MAAM;IAAA,KACNC,QAAQ,GAAc,EAAE;IAItB,IAAI,CAACD,MAAM,GAAGA,MAAM;EACtB;EAEAE,cAAcA,CAAA,EAAsC;IAAA,IAArCD,QAAmB,GAAAE,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI,CAACF,QAAQ;IAChD,KAAK,MAAMK,OAAO,IAAIL,QAAQ,EAAE;MAC9B,QAAQK,OAAO,CAACC,IAAI;QAClB,KAAK,uBAAuB;UAC1BC,mBAAmB,CAAC,IAAI,CAACR,MAAM,EAAEM,OAAO,CAACG,OAAO,CAAC;UACjD;QACF,KAAK,wBAAwB;UAC3BC,oBAAoB,CAAC,IAAI,CAACV,MAAM,EAAEM,OAAO,CAACG,OAAO,CAAC;UAClD;QACF,KAAK,wBAAwB;UAC3BE,oBAAoB,CAAC,IAAI,CAACX,MAAM,EAAEM,OA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;EACjD,QAAQA,IAAI;IACV,KAAKlF,EAAE,CAACoD,aAAa;MACnB,OAAO,CAAC;IACV,KAAKpD,EAAE,CAACmF,oBAAoB;IAC5B,KAAKnF,EAAE,CAACoF,sBAAsB;IAC9B,KAAKpF,EAAE,CAACqF,sBAAsB;MAC5B,OAAO,CAAC;IACV,KAAKrF,EAAE,CAACsF,KAAK;MACX,OAAO,CAAC;IAEV;MACE,MAAM,IAAIrD,KAAK,CAAC,QAAQ,CAAC;EAC7B;AACF;AAIA,SAASY,cAAcA,CAAC1B,MAA6B,EAGnD;EACA,IAAIA,MAAM,YAAYpB,OAAO,EAAE;IAC7B,MAAM;MAACqC,KAAK;MAAEC,MAAM;MAAEkD;IAAE,CAAC,GAAGpE,MAAM;IAClC,MAAMwB,WAAW,GAAGxB,MAAM,CAACb,MAAM,CAACkF,iBAAiB,CAAC;MAClDD,EAAE,EAAG,mBAAkBA,EAAG,EAAC;MAC3BnD,KAAK;MACLC,MAAM;MACNoD,gBAAgB,EAAE,CAACtE,MAAM;IAC3B,CAAC,CAAgC;IAEjC,OAAO;MAACwB,WAAW;MAAEC,kBAAkB,EAAE;IAAI,CAAC;EAChD;EACA,OAAO;IAACD,WAAW,EAAExB,MAAqC;IAAEyB,kBAAkB,EAAE;EAAK,CAAC;AACxF"}
1
+ {"version":3,"file":"webgl-command-buffer.js","names":["CommandBuffer","Texture","GL","WEBGLTexture","getWebGLTextureParameters","cast","value","WEBGLCommandBuffer","constructor","device","commands","submitCommands","arguments","length","undefined","command","name","_copyBufferToBuffer","options","_copyBufferToTexture","_copyTextureToBuffer","_copyTextureToTexture","source","destination","gl2","assertWebGL2","_options$sourceOffset","_options$destinationO","bindBuffer","COPY_READ_BUFFER","handle","COPY_WRITE_BUFFER","copyBufferSubData","sourceOffset","destinationOffset","size","Error","mipLevel","aspect","width","height","depthOrArrayLayers","origin","byteOffset","bytesPerRow","rowsPerImage","framebuffer","destroyFramebuffer","getFramebuffer","webglBuffer","sourceWidth","sourceHeight","sourceParams","texture","format","sourceFormat","dataFormat","sourceType","type","PIXEL_PACK_BUFFER","bindFramebuffer","FRAMEBUFFER","readPixels","destroy","destinationMipmaplevel","destinationInternalFormat","RGBA","sourceX","sourceY","isSubCopy","gl","textureTarget","Number","isFinite","bind","copyTexImage2D","unbind","glFormatToComponents","ALPHA","R32F","RED","RG32F","RG","RGB","RGB32F","RGBA32F","glTypeToBytes","UNSIGNED_BYTE","UNSIGNED_SHORT_5_6_5","UNSIGNED_SHORT_4_4_4_4","UNSIGNED_SHORT_5_5_5_1","FLOAT","id","createFramebuffer","colorAttachments"],"sources":["../../../src/adapter/resources/webgl-command-buffer.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {\n CopyBufferToBufferOptions,\n CopyBufferToTextureOptions,\n CopyTextureToBufferOptions,\n CopyTextureToTextureOptions\n} from '@luma.gl/core';\nimport {CommandBuffer, Texture, Framebuffer} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\n\nimport {WebGLDevice} from '../webgl-device';\nimport {WEBGLBuffer} from './webgl-buffer';\nimport {WEBGLTexture} from './webgl-texture';\nimport {WEBGLFramebuffer} from './webgl-framebuffer';\nimport {getWebGLTextureParameters} from '../converters/texture-formats';\n\nfunction cast<T>(value: unknown): T {\n return value as T;\n}\n\ntype CopyBufferToBufferCommand = {\n name: 'copy-buffer-to-buffer';\n options: CopyBufferToBufferOptions;\n};\n\ntype CopyBufferToTextureCommand = {\n name: 'copy-buffer-to-texture';\n options: CopyBufferToTextureOptions;\n};\n\ntype CopyTextureToBufferCommand = {\n name: 'copy-texture-to-buffer';\n options: CopyTextureToBufferOptions;\n};\n\ntype CopyTextureToTextureCommand = {\n name: 'copy-texture-to-texture';\n options: CopyTextureToTextureOptions;\n};\n\ntype Command =\n | CopyBufferToBufferCommand\n | CopyBufferToTextureCommand\n | CopyTextureToBufferCommand\n | CopyTextureToTextureCommand;\n\nexport class WEBGLCommandBuffer extends CommandBuffer {\n device: WebGLDevice;\n commands: Command[] = [];\n\n constructor(device: WebGLDevice) {\n super(device, {});\n this.device = device;\n }\n\n submitCommands(commands: Command[] = this.commands) {\n for (const command of commands) {\n switch (command.name) {\n case 'copy-buffer-to-buffer':\n _copyBufferToBuffer(this.device, command.options);\n break;\n case 'copy-buffer-to-texture':\n _copyBufferToTexture(this.device, command.options);\n break;\n case 'copy-texture-to-buffer':\n _copyTextureToBuffer(this.device, command.options);\n break;\n case 'copy-texture-to-texture':\n _copyTextureToTexture(this.device, command.options);\n break;\n }\n }\n }\n}\n\nfunction _copyBufferToBuffer(device: WebGLDevice, options: CopyBufferToBufferOptions): void {\n const source = cast<WEBGLBuffer>(options.source);\n const destination = cast<WEBGLBuffer>(options.destination);\n\n const gl2 = device.assertWebGL2();\n if (gl2) {\n // In WebGL2 we can perform the copy on the GPU\n // Use GL.COPY_READ_BUFFER+GL.COPY_WRITE_BUFFER avoid disturbing other targets and locking type\n gl2.bindBuffer(GL.COPY_READ_BUFFER, source.handle);\n gl2.bindBuffer(GL.COPY_WRITE_BUFFER, destination.handle);\n gl2.copyBufferSubData(\n GL.COPY_READ_BUFFER,\n GL.COPY_WRITE_BUFFER,\n options.sourceOffset ?? 0,\n options.destinationOffset ?? 0,\n options.size\n );\n gl2.bindBuffer(GL.COPY_READ_BUFFER, null);\n gl2.bindBuffer(GL.COPY_WRITE_BUFFER, null);\n } else {\n // TODO - in WebGL1 we would have to read back to CPU\n // read / write buffer from / to CPU\n throw new Error('copyBufferToBuffer not implemented in WebGL1');\n }\n}\n\n/**\n * Copies data from a Buffer object into a Texture object\n * NOTE: doesn't wait for copy to be complete\n */\nfunction _copyBufferToTexture(device: WebGLDevice, options: CopyBufferToTextureOptions): void {\n throw new Error('Not implemented');\n}\n\n/**\n * Copies data from a Texture object into a Buffer object.\n * NOTE: doesn't wait for copy to be complete\n */\nfunction _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferOptions): void {\n const {\n /** Texture to copy to/from. */\n source,\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n mipLevel = 0,\n /** Defines which aspects of the texture to copy to/from. */\n aspect = 'all',\n\n /** Width to copy */\n width = options.source.width,\n /** Height to copy */\n height = options.source.height,\n depthOrArrayLayers = 0,\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */\n origin = [0, 0],\n\n /** Destination buffer */\n destination,\n /** Offset, in bytes, from the beginning of the buffer to the start of the image data (default 0) */\n byteOffset = 0,\n /**\n * The stride, in bytes, between the beginning of each block row and the subsequent block row.\n * Required if there are multiple block rows (i.e. the copy height or depth is more than one block).\n */\n bytesPerRow,\n /**\n * Number of block rows per single image of the texture.\n * rowsPerImage &times; bytesPerRow is the stride, in bytes, between the beginning of each image of data and the subsequent image.\n * Required if there are multiple images (i.e. the copy depth is more than one).\n */\n rowsPerImage\n } = options;\n\n // TODO - Not possible to read just stencil or depth part in WebGL?\n if (aspect !== 'all') {\n throw new Error('not supported');\n }\n\n // TODO - mipLevels are set when attaching texture to framebuffer\n if (mipLevel !== 0 || depthOrArrayLayers !== 0 || bytesPerRow || rowsPerImage) {\n throw new Error('not implemented');\n }\n\n // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature\n const gl2 = device.assertWebGL2();\n\n const {framebuffer, destroyFramebuffer} = getFramebuffer(source);\n try {\n const webglBuffer = destination as WEBGLBuffer;\n const sourceWidth = width || framebuffer.width;\n const sourceHeight = height || framebuffer.height;\n const sourceParams = getWebGLTextureParameters(framebuffer.texture.format, true);\n const sourceFormat = sourceParams.dataFormat;\n const sourceType = sourceParams.type;\n\n // if (!target) {\n // // Create new buffer with enough size\n // const components = glFormatToComponents(sourceFormat);\n // const byteCount = glTypeToBytes(sourceType);\n // const byteLength = byteOffset + sourceWidth * sourceHeight * components * byteCount;\n // target = device.createBuffer({byteLength});\n // }\n\n gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, webglBuffer.handle);\n gl2.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);\n\n gl2.readPixels(\n origin[0],\n origin[1],\n sourceWidth,\n sourceHeight,\n sourceFormat,\n sourceType,\n byteOffset\n );\n } finally {\n gl2.bindBuffer(GL.PIXEL_PACK_BUFFER, null);\n gl2.bindFramebuffer(GL.FRAMEBUFFER, null);\n\n if (destroyFramebuffer) {\n framebuffer.destroy();\n }\n }\n}\n\n/**\n * Copies data from a Framebuffer or a Texture object into a Buffer object.\n * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transfer.\nexport function readPixelsToBuffer(\n source: Framebuffer | Texture,\n options?: {\n sourceX?: number;\n sourceY?: number;\n sourceFormat?: number;\n target?: Buffer; // A new Buffer object is created when not provided.\n targetByteOffset?: number; // byte offset in buffer object\n // following parameters are auto deduced if not provided\n sourceWidth?: number;\n sourceHeight?: number;\n sourceType?: number;\n }\n): Buffer\n */\n\n/**\n * Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)\n */\n// eslint-disable-next-line complexity, max-statements\nfunction _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextureOptions): void {\n const {\n /** Texture to copy to/from. */\n source,\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n // mipLevel = 0,\n /** Defines which aspects of the texture to copy to/from. */\n // aspect = 'all',\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */\n origin = [0, 0],\n\n /** Texture to copy to/from. */\n destination,\n /** Mip-map level of the texture to copy to/from. (Default 0) */\n // destinationMipLevel = options.mipLevel,\n /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */\n // destinationOrigin = [0, 0],\n /** Defines which aspects of the texture to copy to/from. */\n // destinationAspect = options.aspect,\n\n } = options;\n\n let {\n width = options.destination.width,\n height = options.destination.width,\n // depthOrArrayLayers = 0\n } = options;\n\n const destinationMipmaplevel = 0;\n const destinationInternalFormat = GL.RGBA;\n\n const {framebuffer, destroyFramebuffer} = getFramebuffer(source);\n const [sourceX, sourceY] = origin;\n\n const isSubCopy = false;\n // typeof destinationX !== 'undefined' ||\n // typeof destinationY !== 'undefined' ||\n // typeof destinationZ !== 'undefined';\n\n // destinationX = destinationX || 0;\n // destinationY = destinationY || 0;\n // destinationZ = destinationZ || 0;\n device.gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);\n // TODO - support gl.readBuffer (WebGL2 only)\n // const prevBuffer = gl.readBuffer(attachment);\n\n let texture = null;\n let textureTarget: GL;\n if (destination instanceof WEBGLTexture) {\n texture = destination;\n width = Number.isFinite(width) ? width : texture.width;\n height = Number.isFinite(height) ? height : texture.height;\n texture.bind(0);\n textureTarget = texture.destination;\n } else {\n throw new Error('whoops');\n // textureTarget = destination;\n }\n\n if (!isSubCopy) {\n device.gl.copyTexImage2D(\n textureTarget,\n destinationMipmaplevel,\n destinationInternalFormat,\n sourceX,\n sourceY,\n width,\n height,\n 0 /* border must be 0 */\n );\n } else {\n // switch (textureTarget) {\n // case GL.TEXTURE_2D:\n // case GL.TEXTURE_CUBE_MAP:\n // device.gl.copyTexSubImage2D(\n // textureTarget,\n // destinationMipmaplevel,\n // destinationX,\n // destinationY,\n // sourceX,\n // sourceY,\n // width,\n // height\n // );\n // break;\n // case GL.TEXTURE_2D_ARRAY:\n // case GL.TEXTURE_3D:\n // const gl2 = device.assertWebGL2();\n // gl2.copyTexSubImage3D(\n // textureTarget,\n // destinationMipmaplevel,\n // destinationX,\n // destinationY,\n // destinationZ,\n // sourceX,\n // sourceY,\n // width,\n // height\n // );\n // break;\n // default:\n // }\n }\n if (texture) {\n texture.unbind();\n }\n // ts-expect-error\n // device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);\n if (destroyFramebuffer) {\n framebuffer.destroy();\n }\n return texture;\n}\n\n// Returns number of components in a specific readPixels WebGL format\nexport function glFormatToComponents(format): 1 | 2 | 3 | 4 {\n switch (format) {\n case GL.ALPHA:\n case GL.R32F:\n case GL.RED:\n return 1;\n case GL.RG32F:\n case GL.RG:\n return 2;\n case GL.RGB:\n case GL.RGB32F:\n return 3;\n case GL.RGBA:\n case GL.RGBA32F:\n return 4;\n // TODO: Add support for additional WebGL2 formats\n default:\n throw new Error('GLFormat');\n }\n}\n\n// Return byte count for given readPixels WebGL type\nexport function glTypeToBytes(type: GL): 1 | 2 | 4 {\n switch (type) {\n case GL.UNSIGNED_BYTE:\n return 1;\n case GL.UNSIGNED_SHORT_5_6_5:\n case GL.UNSIGNED_SHORT_4_4_4_4:\n case GL.UNSIGNED_SHORT_5_5_5_1:\n return 2;\n case GL.FLOAT:\n return 4;\n // TODO: Add support for additional WebGL2 types\n default:\n throw new Error('GLType');\n }\n}\n\n// Helper methods\n\nfunction getFramebuffer(source: Texture | Framebuffer): {\n framebuffer: WEBGLFramebuffer;\n destroyFramebuffer: boolean;\n} {\n if (source instanceof Texture) {\n const {width, height, id} = source;\n const framebuffer = source.device.createFramebuffer({\n id: `framebuffer-for-${id}`,\n width,\n height,\n colorAttachments: [source]\n }) as unknown as WEBGLFramebuffer;\n\n return {framebuffer, destroyFramebuffer: true};\n }\n return {framebuffer: source as unknown as WEBGLFramebuffer, destroyFramebuffer: false};\n}\n"],"mappings":"AASA,SAAQA,aAAa,EAAEC,OAAO,QAAoB,eAAe;AACjE,SAAQC,EAAE,QAAO,oBAAoB;AAAC,SAI9BC,YAAY;AAAA,SAEZC,yBAAyB;AAEjC,SAASC,IAAIA,CAAIC,KAAc,EAAK;EAClC,OAAOA,KAAK;AACd;AA4BA,OAAO,MAAMC,kBAAkB,SAASP,aAAa,CAAC;EAIpDQ,WAAWA,CAACC,MAAmB,EAAE;IAC/B,KAAK,CAACA,MAAM,EAAE,CAAC,CAAC,CAAC;IAAC,KAJpBA,MAAM;IAAA,KACNC,QAAQ,GAAc,EAAE;IAItB,IAAI,CAACD,MAAM,GAAGA,MAAM;EACtB;EAEAE,cAAcA,CAAA,EAAsC;IAAA,IAArCD,QAAmB,GAAAE,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI,CAACF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E;EAAK,CAAC;AACxF"}
@@ -4,6 +4,7 @@ import type { RenderPass, VertexArray } from '@luma.gl/core';
4
4
  import { RenderPipeline } from '@luma.gl/core';
5
5
  import { WebGLDevice } from '../webgl-device';
6
6
  import { WEBGLShader } from './webgl-shader';
7
+ import { WEBGLTransformFeedback } from './webgl-transform-feedback';
7
8
  /** Creates a new render pipeline */
8
9
  export declare class WEBGLRenderPipeline extends RenderPipeline {
9
10
  /** The WebGL device that created this render pipeline */
@@ -47,6 +48,7 @@ export declare class WEBGLRenderPipeline extends RenderPipeline {
47
48
  firstIndex?: number;
48
49
  firstInstance?: number;
49
50
  baseVertex?: number;
51
+ transformFeedback?: WEBGLTransformFeedback;
50
52
  }): boolean;
51
53
  protected _compileAndLink(): void;
52
54
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-render-pipeline.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgl-render-pipeline.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,YAAY,EAAE,mBAAmB,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAC9E,OAAO,KAAK,EAAC,YAAY,EAAoB,MAAM,eAAe,CAAC;AACnE,OAAO,KAAK,EAAC,UAAU,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAC,cAAc,EAAsC,MAAM,eAAe,CAAC;AAUlF,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAQ3C,oCAAoC;AACpC,qBAAa,mBAAoB,SAAQ,cAAc;IACrD,yDAAyD;IACzD,MAAM,EAAE,WAAW,CAAC;IACpB,yCAAyC;IACzC,MAAM,EAAE,YAAY,CAAC;IACrB,oBAAoB;IACpB,EAAE,EAAE,WAAW,CAAC;IAChB,sBAAsB;IACtB,EAAE,EAAE,WAAW,CAAC;IAChB,mEAAmE;IACnE,kBAAkB,EAAE,YAAY,CAAC;IAEjC,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C,OAAO,EAAE;QACZ,UAAU,EAAE,UAAU,CAAC;QACvB,wBAAwB;QACxB,WAAW,EAAE,WAAW,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,iBAAiB,CAAC,EAAE,sBAAsB,CAAC;KAC5C,GAAG,OAAO;IA+GX,SAAS,CAAC,eAAe;IA4BzB;;;;OAIG;IACH,sBAAsB;IAatB;;;;;;;;;;;;;;;;;;;;MAoBE;IAEF,iDAAiD;IACjD,cAAc;IAgFd;;;OAGG;IACH,cAAc;CASf"}
@@ -7,6 +7,7 @@ import { setUniform } from "../helpers/set-uniform.js";
7
7
  import { WEBGLBuffer } from "./webgl-buffer.js";
8
8
  import { WEBGLFramebuffer } from "./webgl-framebuffer.js";
9
9
  import { WEBGLTexture } from "./webgl-texture.js";
10
+ import { getGLDrawMode } from "../helpers/webgl-topology-utils.js";
10
11
  const LOG_PROGRAM_PERF_PRIORITY = 4;
11
12
  export class WEBGLRenderPipeline extends RenderPipeline {
12
13
  constructor(device, props) {
@@ -95,7 +96,8 @@ export class WEBGLRenderPipeline extends RenderPipeline {
95
96
  vertexArray,
96
97
  vertexCount,
97
98
  instanceCount,
98
- firstVertex = 0
99
+ firstVertex = 0,
100
+ transformFeedback
99
101
  } = options;
100
102
  const glDrawMode = getGLDrawMode(this.props.topology);
101
103
  const isIndexed = Boolean(vertexArray.indexBuffer);
@@ -106,10 +108,8 @@ export class WEBGLRenderPipeline extends RenderPipeline {
106
108
  }
107
109
  this.device.gl.useProgram(this.handle);
108
110
  vertexArray.bindBeforeRender(renderPass);
109
- const primitiveMode = getGLPrimitive(this.props.topology);
110
- const transformFeedback = null;
111
111
  if (transformFeedback) {
112
- transformFeedback.begin(primitiveMode);
112
+ transformFeedback.begin(this.props.topology);
113
113
  }
114
114
  this._applyBindings();
115
115
  this._applyUniforms();
@@ -236,44 +236,4 @@ export class WEBGLRenderPipeline extends RenderPipeline {
236
236
  }
237
237
  }
238
238
  }
239
- function getGLDrawMode(topology) {
240
- switch (topology) {
241
- case 'point-list':
242
- return GL.POINTS;
243
- case 'line-list':
244
- return GL.LINES;
245
- case 'line-strip':
246
- return GL.LINE_STRIP;
247
- case 'line-loop-webgl':
248
- return GL.LINE_LOOP;
249
- case 'triangle-list':
250
- return GL.TRIANGLES;
251
- case 'triangle-strip':
252
- return GL.TRIANGLE_STRIP;
253
- case 'triangle-fan-webgl':
254
- return GL.TRIANGLE_FAN;
255
- default:
256
- throw new Error(topology);
257
- }
258
- }
259
- function getGLPrimitive(topology) {
260
- switch (topology) {
261
- case 'point-list':
262
- return GL.POINTS;
263
- case 'line-list':
264
- return GL.LINES;
265
- case 'line-strip':
266
- return GL.LINES;
267
- case 'line-loop-webgl':
268
- return GL.LINES;
269
- case 'triangle-list':
270
- return GL.TRIANGLES;
271
- case 'triangle-strip':
272
- return GL.TRIANGLES;
273
- case 'triangle-fan-webgl':
274
- return GL.TRIANGLES;
275
- default:
276
- throw new Error(topology);
277
- }
278
- }
279
239
  //# sourceMappingURL=webgl-render-pipeline.js.map