@luma.gl/webgl 9.0.0-alpha.23 → 9.0.0-alpha.25

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 (151) 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 +1 -1
  4. package/dist/adapter/converters/device-parameters.js.map +1 -1
  5. package/dist/adapter/converters/sampler-parameters.js.map +1 -1
  6. package/dist/adapter/converters/texture-formats.d.ts +3 -3
  7. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  8. package/dist/adapter/converters/texture-formats.js +1 -1
  9. package/dist/adapter/converters/texture-formats.js.map +1 -1
  10. package/dist/adapter/converters/vertex-formats.d.ts +1 -1
  11. package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
  12. package/dist/adapter/converters/vertex-formats.js +1 -1
  13. package/dist/adapter/converters/vertex-formats.js.map +1 -1
  14. package/dist/adapter/device-helpers/device-features.js.map +1 -1
  15. package/dist/adapter/device-helpers/device-limits.d.ts +2 -2
  16. package/dist/adapter/device-helpers/device-limits.d.ts.map +1 -1
  17. package/dist/adapter/device-helpers/device-limits.js +1 -1
  18. package/dist/adapter/device-helpers/device-limits.js.map +1 -1
  19. package/dist/adapter/device-helpers/get-device-info.js +1 -1
  20. package/dist/adapter/device-helpers/get-device-info.js.map +1 -1
  21. package/dist/adapter/helpers/attribute-utils.js.map +1 -1
  22. package/dist/adapter/helpers/get-shader-info.d.ts +1 -1
  23. package/dist/adapter/helpers/get-shader-info.d.ts.map +1 -1
  24. package/dist/adapter/helpers/get-shader-layout.js +1 -1
  25. package/dist/adapter/helpers/get-shader-layout.js.map +1 -1
  26. package/dist/adapter/helpers/parse-shader-compiler-log.js.map +1 -1
  27. package/dist/adapter/helpers/set-uniform.d.ts +1 -1
  28. package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
  29. package/dist/adapter/helpers/set-uniform.js +1 -1
  30. package/dist/adapter/helpers/set-uniform.js.map +1 -1
  31. package/dist/adapter/helpers/uniforms.js.map +1 -1
  32. package/dist/adapter/objects/constants-to-keys.d.ts +1 -1
  33. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  34. package/dist/adapter/objects/constants-to-keys.js.map +1 -1
  35. package/dist/adapter/objects/webgl-renderbuffer.d.ts +2 -2
  36. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
  37. package/dist/adapter/objects/webgl-renderbuffer.js +1 -1
  38. package/dist/adapter/objects/webgl-renderbuffer.js.map +1 -1
  39. package/dist/adapter/objects/webgl-resource.d.ts +1 -1
  40. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  41. package/dist/adapter/objects/webgl-resource.js.map +1 -1
  42. package/dist/adapter/objects/webgl-vertex-array-object.d.ts +1 -1
  43. package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +1 -1
  44. package/dist/adapter/objects/webgl-vertex-array-object.js +1 -1
  45. package/dist/adapter/objects/webgl-vertex-array-object.js.map +1 -1
  46. package/dist/adapter/resources/webgl-buffer.js +1 -1
  47. package/dist/adapter/resources/webgl-buffer.js.map +1 -1
  48. package/dist/adapter/resources/webgl-command-buffer.d.ts +6 -6
  49. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  50. package/dist/adapter/resources/webgl-command-buffer.js +1 -1
  51. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  52. package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
  53. package/dist/adapter/resources/webgl-framebuffer.d.ts +3 -3
  54. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  55. package/dist/adapter/resources/webgl-framebuffer.js +1 -1
  56. package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
  57. package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
  58. package/dist/adapter/resources/webgl-render-pipeline.js +3 -2
  59. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  60. package/dist/adapter/resources/webgl-sampler.js.map +1 -1
  61. package/dist/adapter/resources/webgl-shader.js +1 -1
  62. package/dist/adapter/resources/webgl-shader.js.map +1 -1
  63. package/dist/adapter/resources/webgl-texture.d.ts +5 -5
  64. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  65. package/dist/adapter/resources/webgl-texture.js.map +1 -1
  66. package/dist/adapter/webgl-canvas-context.js.map +1 -1
  67. package/dist/adapter/webgl-device.js +2 -2
  68. package/dist/adapter/webgl-device.js.map +1 -1
  69. package/dist/classic/accessor.d.ts +1 -1
  70. package/dist/classic/accessor.d.ts.map +1 -1
  71. package/dist/classic/accessor.js +1 -1
  72. package/dist/classic/accessor.js.map +1 -1
  73. package/dist/classic/{buffer.d.ts → buffer-with-accessor.d.ts} +8 -8
  74. package/dist/classic/buffer-with-accessor.d.ts.map +1 -0
  75. package/dist/classic/{buffer.js → buffer-with-accessor.js} +3 -3
  76. package/dist/classic/buffer-with-accessor.js.map +1 -0
  77. package/dist/classic/clear.d.ts +22 -0
  78. package/dist/classic/clear.d.ts.map +1 -0
  79. package/dist/classic/clear.js +88 -0
  80. package/dist/classic/clear.js.map +1 -0
  81. package/dist/classic/copy-and-blit.d.ts +45 -0
  82. package/dist/classic/copy-and-blit.d.ts.map +1 -0
  83. package/dist/classic/copy-and-blit.js +136 -0
  84. package/dist/classic/copy-and-blit.js.map +1 -0
  85. package/dist/classic/format-utils.d.ts +3 -0
  86. package/dist/classic/format-utils.d.ts.map +1 -0
  87. package/dist/classic/format-utils.js +38 -0
  88. package/dist/classic/format-utils.js.map +1 -0
  89. package/dist/classic/typed-array-utils.js.map +1 -1
  90. package/dist/context/context/create-browser-context.d.ts +17 -19
  91. package/dist/context/context/create-browser-context.d.ts.map +1 -1
  92. package/dist/context/context/create-browser-context.js +4 -4
  93. package/dist/context/context/create-browser-context.js.map +1 -1
  94. package/dist/context/context/create-headless-context.d.ts +1 -1
  95. package/dist/context/context/create-headless-context.d.ts.map +1 -1
  96. package/dist/context/debug/spector.d.ts +1 -3
  97. package/dist/context/debug/spector.d.ts.map +1 -1
  98. package/dist/context/debug/spector.js.map +1 -1
  99. package/dist/context/debug/webgl-developer-tools.d.ts +1 -1
  100. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  101. package/dist/context/debug/webgl-developer-tools.js +1 -1
  102. package/dist/context/debug/webgl-developer-tools.js.map +1 -1
  103. package/dist/context/parameters/webgl-parameter-tables.d.ts +1 -1
  104. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  105. package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
  106. package/dist/context/polyfill/get-parameter-polyfill.js +3 -3
  107. package/dist/context/polyfill/get-parameter-polyfill.js.map +1 -1
  108. package/dist/context/polyfill/polyfill-context.js.map +1 -1
  109. package/dist/context/polyfill/polyfill-table.js +1 -1
  110. package/dist/context/polyfill/polyfill-table.js.map +1 -1
  111. package/dist/context/polyfill/polyfill-vertex-array-object.js.map +1 -1
  112. package/dist/context/state-tracker/track-context-state.js.map +1 -1
  113. package/dist/dist.dev.js +251 -83
  114. package/dist/index.cjs +694 -520
  115. package/dist/index.d.ts +4 -2
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js +3 -1
  118. package/dist/index.js.map +1 -1
  119. package/dist/types.d.ts +1 -1
  120. package/dist/types.d.ts.map +1 -1
  121. package/dist.min.js +22 -22
  122. package/package.json +5 -5
  123. package/src/adapter/converters/device-parameters.ts +1 -1
  124. package/src/adapter/converters/texture-formats.ts +1 -1
  125. package/src/adapter/converters/vertex-formats.ts +1 -1
  126. package/src/adapter/device-helpers/device-limits.ts +1 -1
  127. package/src/adapter/device-helpers/get-device-info.ts +1 -1
  128. package/src/adapter/helpers/get-shader-layout.ts +1 -1
  129. package/src/adapter/helpers/set-uniform.ts +1 -1
  130. package/src/adapter/objects/constants-to-keys.ts +1 -1
  131. package/src/adapter/objects/webgl-renderbuffer.ts +1 -1
  132. package/src/adapter/objects/webgl-resource.ts +1 -1
  133. package/src/adapter/objects/webgl-vertex-array-object.ts +1 -1
  134. package/src/adapter/resources/webgl-buffer.ts +1 -1
  135. package/src/adapter/resources/webgl-command-buffer.ts +1 -1
  136. package/src/adapter/resources/webgl-framebuffer.ts +1 -1
  137. package/src/adapter/resources/webgl-render-pipeline.ts +2 -2
  138. package/src/adapter/resources/webgl-shader.ts +1 -1
  139. package/src/adapter/webgl-device.ts +2 -2
  140. package/src/classic/accessor.ts +1 -1
  141. package/src/classic/{buffer.ts → buffer-with-accessor.ts} +9 -9
  142. package/src/classic/clear.ts +110 -0
  143. package/src/classic/copy-and-blit.ts +189 -0
  144. package/src/classic/format-utils.ts +43 -0
  145. package/src/context/context/create-browser-context.ts +37 -30
  146. package/src/context/debug/webgl-developer-tools.ts +1 -1
  147. package/src/context/polyfill/get-parameter-polyfill.ts +1 -1
  148. package/src/context/polyfill/polyfill-table.ts +1 -1
  149. package/src/index.ts +8 -3
  150. package/dist/classic/buffer.d.ts.map +0 -1
  151. package/dist/classic/buffer.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/webgl",
3
- "version": "9.0.0-alpha.23",
3
+ "version": "9.0.0-alpha.25",
4
4
  "description": "WebGL2 adapter for the luma.gl API",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -44,12 +44,12 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@babel/runtime": "^7.0.0",
47
- "@luma.gl/api": "9.0.0-alpha.23",
48
- "@luma.gl/constants": "9.0.0-alpha.23",
47
+ "@luma.gl/api": "9.0.0-alpha.25",
48
+ "@luma.gl/constants": "9.0.0-alpha.25",
49
49
  "@probe.gl/env": "^4.0.2"
50
50
  },
51
51
  "devDependencies": {
52
- "@luma.gl/test-utils": "9.0.0-alpha.23"
52
+ "@luma.gl/test-utils": "9.0.0-alpha.25"
53
53
  },
54
- "gitHead": "5e4a30497333bea4be8f2b3f3db33c0b67931b9c"
54
+ "gitHead": "a91e00399e59c1b5310bdfd842648238c5abf908"
55
55
  }
@@ -6,7 +6,7 @@ import {
6
6
  log,
7
7
  isObjectEmpty
8
8
  } from '@luma.gl/api';
9
- import GL from '@luma.gl/constants';
9
+ import {GL} from '@luma.gl/constants';
10
10
  import type {GLParameters} from '@luma.gl/constants';
11
11
  import {pushContextState, popContextState} from '../../context/state-tracker/track-context-state';
12
12
  import {setParameters} from '../../context/parameters/unified-parameter-api';
@@ -1,6 +1,6 @@
1
1
  import type {TextureFormat, DeviceFeature} from '@luma.gl/api';
2
2
  import {decodeTextureFormat} from '@luma.gl/api';
3
- import GL from '@luma.gl/constants';
3
+ import {GL} from '@luma.gl/constants';
4
4
  import {isWebGL2} from '../../context/context/webgl-checks';
5
5
 
6
6
  /* eslint-disable camelcase */
@@ -1,4 +1,4 @@
1
- import GL from '@luma.gl/constants';
1
+ import {GL} from '@luma.gl/constants';
2
2
  import {VertexFormat} from '@luma.gl/api';
3
3
 
4
4
  export function getVertexFormat(type: GL, components: number): VertexFormat {
@@ -1,6 +1,6 @@
1
1
  // luma.gl, MIT license
2
2
  import type {DeviceLimits} from '@luma.gl/api';
3
- import GL from '@luma.gl/constants';
3
+ import {GL} from '@luma.gl/constants';
4
4
  import {getWebGL2Context} from '../../context/context/webgl-checks';
5
5
 
6
6
  /** Populate a WebGPU style device limits */
@@ -1,5 +1,5 @@
1
1
  import {DeviceInfo} from '@luma.gl/api';
2
- import GL from '@luma.gl/constants';
2
+ import {GL} from '@luma.gl/constants';
3
3
  import {isWebGL2} from '../../context/context/webgl-checks';
4
4
 
5
5
  /** @returns strings identifying the GPU vendor and driver. */
@@ -11,7 +11,7 @@ import {
11
11
  // AttributeLayout,
12
12
  AccessorObject
13
13
  } from '@luma.gl/api';
14
- import GL from '@luma.gl/constants';
14
+ import {GL} from '@luma.gl/constants';
15
15
  import {isWebGL2} from '../../context/context/webgl-checks';
16
16
  import {Accessor} from '../../classic/accessor'; // TODO - should NOT depend on classic API
17
17
  import {decodeUniformType, decodeAttributeType} from './uniforms';
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable */
2
2
 
3
3
  // Uniforms
4
- import GL from '@luma.gl/constants';
4
+ import {GL} from '@luma.gl/constants';
5
5
 
6
6
  /** Set a raw uniform (without type conversion and caching) */
7
7
  /* eslint-disable max-len */
@@ -1,5 +1,5 @@
1
1
  import {assert} from '@luma.gl/api';
2
- import GL from '@luma.gl/constants';
2
+ import {GL} from '@luma.gl/constants';
3
3
 
4
4
  // Resolve a WebGL enumeration name (returns itself if already a number)
5
5
  export function getKeyValue(gl: WebGLRenderingContext, name: string | GL): GL {
@@ -1,5 +1,5 @@
1
1
  import {assert, ResourceProps, TextureFormat} from '@luma.gl/api';
2
- import GL from '@luma.gl/constants';
2
+ import {GL} from '@luma.gl/constants';
3
3
  import {WebGLDevice} from '../webgl-device';
4
4
  import {WebGLResource} from './webgl-resource';
5
5
  import {isRenderbufferFormatSupported} from '../converters/texture-formats';
@@ -1,7 +1,7 @@
1
1
  // luma.gl, MIT license
2
2
  import {Resource, assert, uid, stubRemovedMethods} from '@luma.gl/api';
3
3
  import type {Device, ResourceProps} from '@luma.gl/api';
4
- import GL from '@luma.gl/constants';
4
+ import {GL} from '@luma.gl/constants';
5
5
  import {isWebGL2, assertWebGLContext} from '../../context/context/webgl-checks';
6
6
  import {WebGLDevice} from '../webgl-device';
7
7
 
@@ -1,5 +1,5 @@
1
1
  import {assert, ResourceProps} from '@luma.gl/api';
2
- import GL from '@luma.gl/constants';
2
+ import {GL} from '@luma.gl/constants';
3
3
  import {getBrowser} from '@probe.gl/env';
4
4
 
5
5
  import {WebGLDevice} from '../webgl-device';
@@ -1,6 +1,6 @@
1
1
  import type {BufferProps} from '@luma.gl/api';
2
2
  import {Buffer, assert} from '@luma.gl/api';
3
- import GL from '@luma.gl/constants';
3
+ import {GL} from '@luma.gl/constants';
4
4
  import {WebGLDevice} from '../webgl-device';
5
5
 
6
6
  const DEBUG_DATA_LENGTH = 10;
@@ -12,7 +12,7 @@ import {
12
12
  // Buffer,
13
13
  Framebuffer
14
14
  } from '@luma.gl/api';
15
- import GL from '@luma.gl/constants';
15
+ import {GL} from '@luma.gl/constants';
16
16
 
17
17
  // import {getTypedArrayFromGLType, getGLTypeFromTypedArray} from '../../classic/typed-array-utils';
18
18
  import {WebGLDevice} from '../webgl-device';
@@ -2,7 +2,7 @@
2
2
 
3
3
  import type {FramebufferProps, TextureFormat} from '@luma.gl/api';
4
4
  import {Framebuffer, Texture, assert} from '@luma.gl/api';
5
- import GL from '@luma.gl/constants';
5
+ import {GL} from '@luma.gl/constants';
6
6
  import {WebGLDevice} from '../webgl-device';
7
7
  import {WEBGLTexture} from './webgl-texture';
8
8
  import {WEBGLRenderbuffer} from '../objects/webgl-renderbuffer';
@@ -9,7 +9,7 @@ import type {
9
9
  AttributeLayout
10
10
  } from '@luma.gl/api';
11
11
  import {RenderPipeline, cast, log, decodeVertexFormat} from '@luma.gl/api';
12
- import GL from '@luma.gl/constants';
12
+ import {GL} from '@luma.gl/constants';
13
13
 
14
14
  import {getWebGLDataType} from '../converters/texture-formats';
15
15
  import {getShaderLayout} from '../helpers/get-shader-layout';
@@ -359,7 +359,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
359
359
  _applyUniforms() {
360
360
  for (const uniformLayout of this.layout.uniforms || []) {
361
361
  const {name, location, type, textureUnit} = uniformLayout;
362
- const value = this.uniforms[name] || textureUnit;
362
+ const value = this.uniforms[name] ?? textureUnit;
363
363
  if (value !== undefined) {
364
364
  setUniform(this.device.gl, location, type, value);
365
365
  }
@@ -1,6 +1,6 @@
1
1
  // luma.gl, MIT license
2
2
  import {log, uid, Shader, ShaderProps, CompilerMessage, formatCompilerLog} from '@luma.gl/api';
3
- import GL from '@luma.gl/constants';
3
+ import {GL} from '@luma.gl/constants';
4
4
  import {getShaderInfo} from '../helpers/get-shader-info';
5
5
  import {parseShaderCompilerLog} from '../helpers/parse-shader-compiler-log';
6
6
  import {WebGLDevice} from '../webgl-device';
@@ -50,7 +50,7 @@ import type {
50
50
  CommandEncoderProps
51
51
  } from '@luma.gl/api';
52
52
 
53
- import {ClassicBuffer} from '../classic/buffer';
53
+ import {BufferWithAccessor} from '../classic/buffer-with-accessor';
54
54
  import {WEBGLBuffer} from './resources/webgl-buffer';
55
55
  import {WEBGLShader} from './resources/webgl-shader';
56
56
  import {WEBGLSampler} from './resources/webgl-sampler';
@@ -284,7 +284,7 @@ ${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`
284
284
 
285
285
  createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): WEBGLBuffer {
286
286
  const newProps = this._getBufferProps(props);
287
- return new ClassicBuffer(this, newProps);
287
+ return new BufferWithAccessor(this, newProps);
288
288
  }
289
289
 
290
290
  _createTexture(props: TextureProps): WEBGLTexture {
@@ -1,5 +1,5 @@
1
1
  import {assert, checkProps, Buffer, AccessorObject} from '@luma.gl/api';
2
- import GL from '@luma.gl/constants';
2
+ import {GL} from '@luma.gl/constants';
3
3
  import {getTypedArrayFromGLType} from './typed-array-utils';
4
4
 
5
5
  const DEFAULT_ACCESSOR_VALUES = {
@@ -2,7 +2,7 @@
2
2
 
3
3
  import type {Device, BufferProps, TypedArray} from '@luma.gl/api';
4
4
  import {assert, checkProps} from '@luma.gl/api';
5
- import GL from '@luma.gl/constants';
5
+ import {GL} from '@luma.gl/constants';
6
6
  import {assertWebGL2Context} from '../context/context/webgl-checks';
7
7
  import {AccessorObject} from '../types';
8
8
  import {Accessor} from './accessor';
@@ -42,7 +42,7 @@ const PROP_CHECKS_SET_PROPS = {
42
42
  removedProps: DEPRECATED_PROPS
43
43
  };
44
44
 
45
- function getWEBGLBufferProps(props: ClassicBufferProps | ArrayBufferView | number): BufferProps {
45
+ function getWEBGLBufferProps(props: BufferWithAccessorProps | ArrayBufferView | number): BufferProps {
46
46
  // Signature `new Buffer(gl, new Float32Array(...)`
47
47
  if (ArrayBuffer.isView(props)) {
48
48
  return {data: props};
@@ -62,7 +62,7 @@ function getWEBGLBufferProps(props: ClassicBufferProps | ArrayBufferView | numbe
62
62
  }
63
63
 
64
64
  /** WebGL Buffer interface */
65
- export type ClassicBufferProps = BufferProps & {
65
+ export type BufferWithAccessorProps = BufferProps & {
66
66
  handle?: WebGLBuffer;
67
67
 
68
68
  target?: number;
@@ -81,11 +81,11 @@ export type ClassicBufferProps = BufferProps & {
81
81
  }
82
82
 
83
83
  /** WebGL Buffer interface */
84
- export class ClassicBuffer extends WEBGLBuffer {
84
+ export class BufferWithAccessor extends WEBGLBuffer {
85
85
  usage: number;
86
86
  accessor: Accessor;
87
87
 
88
- constructor(device: Device | WebGLRenderingContext, props?: ClassicBufferProps);
88
+ constructor(device: Device | WebGLRenderingContext, props?: BufferWithAccessorProps);
89
89
  constructor(device: Device | WebGLRenderingContext, data: ArrayBufferView | number[]);
90
90
  constructor(device: Device | WebGLRenderingContext, byteLength: number);
91
91
 
@@ -96,7 +96,7 @@ export class ClassicBuffer extends WEBGLBuffer {
96
96
  // this.initialize(props);
97
97
 
98
98
  // Deprecated: Merge main props and accessor
99
- this.setAccessor(Object.assign({}, props, (props as ClassicBufferProps).accessor));
99
+ this.setAccessor(Object.assign({}, props, (props as BufferWithAccessorProps).accessor));
100
100
 
101
101
  // infer GL type from supplied typed array
102
102
  if (this.props.data) {
@@ -126,7 +126,7 @@ export class ClassicBuffer extends WEBGLBuffer {
126
126
  // Signature: `new Buffer(gl, {data: new Float32Array(...)})`
127
127
  // Signature: `new Buffer(gl, new Float32Array(...))`
128
128
  // Signature: `new Buffer(gl, 100)`
129
- initialize(props: ClassicBufferProps = {}): this {
129
+ initialize(props: BufferWithAccessorProps = {}): this {
130
130
  // Signature `new Buffer(gl, new Float32Array(...)`
131
131
  if (ArrayBuffer.isView(props)) {
132
132
  props = {data: props};
@@ -157,7 +157,7 @@ export class ClassicBuffer extends WEBGLBuffer {
157
157
  return this;
158
158
  }
159
159
 
160
- setProps(props: ClassicBufferProps): this {
160
+ setProps(props: BufferWithAccessorProps): this {
161
161
  props = checkProps('Buffer', props, PROP_CHECKS_SET_PROPS);
162
162
 
163
163
  if ('accessor' in props) {
@@ -197,7 +197,7 @@ export class ClassicBuffer extends WEBGLBuffer {
197
197
  }
198
198
 
199
199
  // Update with new data. Reinitializes the buffer
200
- setData(props: ClassicBufferProps) {
200
+ setData(props: BufferWithAccessorProps) {
201
201
  return this.initialize(props);
202
202
  }
203
203
 
@@ -0,0 +1,110 @@
1
+ import {Device, Framebuffer, assert} from '@luma.gl/api';
2
+ import {WebGLDevice} from '../adapter/webgl-device';
3
+ import {withParameters} from '../context/state-tracker/with-parameters';
4
+
5
+ // Should collapse during minification
6
+ const GL_DEPTH_BUFFER_BIT = 0x00000100;
7
+ const GL_STENCIL_BUFFER_BIT = 0x00000400;
8
+ const GL_COLOR_BUFFER_BIT = 0x00004000;
9
+
10
+ const GL_COLOR = 0x1800;
11
+ const GL_DEPTH = 0x1801;
12
+ const GL_STENCIL = 0x1802;
13
+ const GL_DEPTH_STENCIL = 0x84f9;
14
+
15
+ // Should disappear if asserts are removed
16
+ const ERR_ARGUMENTS = 'clear: bad arguments';
17
+
18
+ /**
19
+ * Optionally clears depth, color and stencil buffers
20
+ * @deprecated Set clear color when creating a RenderPass.
21
+ */
22
+ export function clear(
23
+ gl: Device | WebGLRenderingContext,
24
+ options?: {framebuffer?: Framebuffer; color?: any; depth?: any; stencil?: any}
25
+ ): void {
26
+ const device = WebGLDevice.attach(gl);
27
+ const {framebuffer = null, color = null, depth = null, stencil = null} = options || {};
28
+ const parameters: any = {};
29
+
30
+ if (framebuffer) {
31
+ parameters.framebuffer = framebuffer;
32
+ }
33
+
34
+ let clearFlags = 0;
35
+
36
+ if (color) {
37
+ clearFlags |= GL_COLOR_BUFFER_BIT;
38
+ if (color !== true) {
39
+ parameters.clearColor = color;
40
+ }
41
+ }
42
+
43
+ if (depth) {
44
+ clearFlags |= GL_DEPTH_BUFFER_BIT;
45
+ if (depth !== true) {
46
+ parameters.clearDepth = depth;
47
+ }
48
+ }
49
+
50
+ if (stencil) {
51
+ clearFlags |= GL_STENCIL_BUFFER_BIT;
52
+ if (depth !== true) {
53
+ parameters.clearStencil = depth;
54
+ }
55
+ }
56
+
57
+ assert(clearFlags !== 0, ERR_ARGUMENTS);
58
+
59
+ // Temporarily set any clear "colors" and call clear
60
+ withParameters(device.gl, parameters, () => {
61
+ device.gl.clear(clearFlags);
62
+ });
63
+ }
64
+
65
+ /**
66
+ * WebGL2 - clear a specific drawing buffer
67
+ * @deprecated Set clear color when creating a RenderPass
68
+ */
69
+ export function clearBuffer(
70
+ gl: Device | WebGLRenderingContext,
71
+ options?: {framebuffer?: Framebuffer; buffer?: any; drawBuffer?: any; value?: any}
72
+ ) {
73
+ const device = WebGLDevice.attach(gl);
74
+
75
+ const {framebuffer = null, buffer = GL_COLOR, drawBuffer = 0, value = [0, 0, 0, 0]} = options || {};
76
+ withParameters(device.gl2, {framebuffer}, () => {
77
+ // Method selection per OpenGL ES 3 docs
78
+ switch (buffer) {
79
+ case GL_COLOR:
80
+ switch (value.constructor) {
81
+ case Int32Array:
82
+ device.gl2.clearBufferiv(buffer, drawBuffer, value);
83
+ break;
84
+ case Uint32Array:
85
+ device.gl2.clearBufferuiv(buffer, drawBuffer, value);
86
+ break;
87
+ case Float32Array:
88
+ default:
89
+ device.gl2.clearBufferfv(buffer, drawBuffer, value);
90
+ }
91
+ break;
92
+
93
+ case GL_DEPTH:
94
+ device.gl2.clearBufferfv(GL_DEPTH, 0, [value]);
95
+ break;
96
+
97
+ case GL_STENCIL:
98
+ device.gl2.clearBufferiv(GL_STENCIL, 0, [value]);
99
+ break;
100
+
101
+ case GL_DEPTH_STENCIL:
102
+ const [depth, stencil] = value;
103
+ device.gl2.clearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);
104
+ break;
105
+
106
+ default:
107
+ assert(false, ERR_ARGUMENTS);
108
+ }
109
+ });
110
+ }
@@ -0,0 +1,189 @@
1
+ // luma.gl, MIT license
2
+ import {assert, Texture, Framebuffer, FramebufferProps} from '@luma.gl/api';
3
+ import {GL} from '@luma.gl/constants';
4
+
5
+ import {BufferWithAccessor as Buffer} from './buffer-with-accessor';
6
+ import {WEBGLTexture} from '../adapter/resources/webgl-texture';
7
+ import {WEBGLFramebuffer} from '../adapter/resources/webgl-framebuffer';
8
+ import {withParameters} from '../context/state-tracker/with-parameters';
9
+ import {getGLTypeFromTypedArray, getTypedArrayFromGLType} from './typed-array-utils';
10
+ import {glFormatToComponents, glTypeToBytes} from './format-utils';
11
+
12
+ /**
13
+ * Copies data from a type or a Texture object into ArrayBuffer object.
14
+ * App can provide targetPixelArray or have it auto allocated by this method
15
+ * newly allocated by this method unless provided by app.
16
+ * @deprecated Use CommandEncoder.copyTextureToBuffer and Buffer.read
17
+ * @note Slow requires roundtrip to GPU
18
+ *
19
+ * @param source
20
+ * @param options
21
+ * @returns pixel array,
22
+ */
23
+ export function readPixelsToArray(
24
+ source: Framebuffer | Texture,
25
+ options?: {
26
+ sourceX?: number;
27
+ sourceY?: number;
28
+ sourceFormat?: number;
29
+ sourceAttachment?: number;
30
+ target?: Uint8Array | Uint16Array | Float32Array;
31
+ // following parameters are auto deduced if not provided
32
+ sourceWidth?: number;
33
+ sourceHeight?: number;
34
+ sourceType?: number;
35
+ }
36
+ ): Uint8Array | Uint16Array | Float32Array {
37
+ const {sourceX = 0, sourceY = 0, sourceFormat = GL.RGBA} = options || {};
38
+ let {
39
+ sourceAttachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
40
+ target = null,
41
+ // following parameters are auto deduced if not provided
42
+ sourceWidth,
43
+ sourceHeight,
44
+ sourceType
45
+ } = options || {};
46
+
47
+ const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
48
+ assert(framebuffer);
49
+ const {gl, handle} = framebuffer as WEBGLFramebuffer;
50
+ sourceWidth = sourceWidth || framebuffer.width;
51
+ sourceHeight = sourceHeight || framebuffer.height;
52
+
53
+ // TODO - Set and unset gl.readBuffer
54
+ if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {
55
+ sourceAttachment = GL.FRONT;
56
+ }
57
+
58
+ const attachment = sourceAttachment - GL.COLOR_ATTACHMENT0;
59
+ // assert(attachments[sourceAttachment]);
60
+
61
+ // Deduce the type from color attachment if not provided.
62
+ sourceType = sourceType || (framebuffer.colorAttachments[attachment] as WEBGLTexture).type;
63
+
64
+ // Deduce type and allocated pixelArray if needed
65
+ target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
66
+
67
+ // Pixel array available, if necessary, deduce type from it.
68
+ sourceType = sourceType || getGLTypeFromTypedArray(target);
69
+
70
+ const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
71
+ gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
72
+ // @ts-expect-error
73
+ gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
74
+ if (deleteFramebuffer) {
75
+ framebuffer.destroy();
76
+ }
77
+ return target;
78
+ }
79
+
80
+ /**
81
+ * Copies data from a Framebuffer or a Texture object into a Buffer object.
82
+ * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transffer.
83
+ * @param source
84
+ * @param options
85
+ */
86
+ export function readPixelsToBuffer(
87
+ source: Framebuffer | Texture,
88
+ options?: {
89
+ sourceX?: number;
90
+ sourceY?: number;
91
+ sourceFormat?: number;
92
+ target?: Buffer; // A new Buffer object is created when not provided.
93
+ targetByteOffset?: number; // byte offset in buffer object
94
+ // following parameters are auto deduced if not provided
95
+ sourceWidth?: number;
96
+ sourceHeight?: number;
97
+ sourceType?: number;
98
+ }
99
+ ): Buffer {
100
+ const {sourceX = 0, sourceY = 0, sourceFormat = GL.RGBA, targetByteOffset = 0} = options || {};
101
+ // following parameters are auto deduced if not provided
102
+ let {target, sourceWidth, sourceHeight, sourceType} = options || {};
103
+ const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
104
+ assert(framebuffer);
105
+ sourceWidth = sourceWidth || framebuffer.width;
106
+ sourceHeight = sourceHeight || framebuffer.height;
107
+
108
+ // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
109
+ const webglFramebuffer = framebuffer as WEBGLFramebuffer;
110
+ const gl2 = webglFramebuffer.device.assertWebGL2();
111
+
112
+ // deduce type if not available.
113
+ sourceType = sourceType || (target ? target.type : GL.UNSIGNED_BYTE);
114
+
115
+ if (!target) {
116
+ // Create new buffer with enough size
117
+ const components = glFormatToComponents(sourceFormat);
118
+ const byteCount = glTypeToBytes(sourceType);
119
+ const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
120
+ target = new Buffer(gl2, {byteLength, accessor: {type: sourceType, size: components}});
121
+ }
122
+
123
+ // @ts-expect-error
124
+ target.bind({target: GL.PIXEL_PACK_BUFFER});
125
+ withParameters(gl2, {framebuffer}, () => {
126
+ gl2.readPixels(
127
+ sourceX,
128
+ sourceY,
129
+ sourceWidth,
130
+ sourceHeight,
131
+ sourceFormat,
132
+ sourceType,
133
+ targetByteOffset
134
+ );
135
+ });
136
+ target.unbind({target: GL.PIXEL_PACK_BUFFER});
137
+ if (deleteFramebuffer) {
138
+ framebuffer.destroy();
139
+ }
140
+
141
+ return target;
142
+ }
143
+
144
+ function getFramebuffer(source: Texture | Framebuffer): {
145
+ framebuffer: Framebuffer;
146
+ deleteFramebuffer: boolean;
147
+ } {
148
+ if (!(source instanceof Framebuffer)) {
149
+ return {framebuffer: toFramebuffer(source), deleteFramebuffer: true};
150
+ }
151
+ return {framebuffer: source, deleteFramebuffer: false};
152
+ }
153
+
154
+ /**
155
+ * Wraps a given texture into a framebuffer object, that can be further used
156
+ * to read data from the texture object.
157
+ */
158
+ export function toFramebuffer(texture: Texture, props?: FramebufferProps): Framebuffer {
159
+ const {device, width, height, id} = texture;
160
+ const framebuffer = device.createFramebuffer({
161
+ ...props,
162
+ id: `framebuffer-for-${id}`,
163
+ width,
164
+ height,
165
+ colorAttachments: [
166
+ texture
167
+ ]
168
+ }
169
+ );
170
+ return framebuffer;
171
+ }
172
+
173
+ function getPixelArray(
174
+ pixelArray,
175
+ type,
176
+ format,
177
+ width: number,
178
+ height: number
179
+ ): Uint8Array | Uint16Array | Float32Array {
180
+ if (pixelArray) {
181
+ return pixelArray;
182
+ }
183
+ // Allocate pixel array if not already available, using supplied type
184
+ type = type || GL.UNSIGNED_BYTE;
185
+ const ArrayType = getTypedArrayFromGLType(type, {clamped: false});
186
+ const components = glFormatToComponents(format);
187
+ // TODO - check for composite type (components = 1).
188
+ return new ArrayType(width * height * components) as Uint8Array | Uint16Array | Float32Array;
189
+ }
@@ -0,0 +1,43 @@
1
+ import {assert} from '@luma.gl/api';
2
+ import {GL} from '@luma.gl/constants';
3
+
4
+ // Returns number of components in a specific readPixels WebGL format
5
+ export function glFormatToComponents(format) {
6
+ switch (format) {
7
+ case GL.ALPHA:
8
+ case GL.R32F:
9
+ case GL.RED:
10
+ return 1;
11
+ case GL.RG32F:
12
+ case GL.RG:
13
+ return 2;
14
+ case GL.RGB:
15
+ case GL.RGB32F:
16
+ return 3;
17
+ case GL.RGBA:
18
+ case GL.RGBA32F:
19
+ return 4;
20
+ // TODO: Add support for additional WebGL2 formats
21
+ default:
22
+ assert(false);
23
+ return 0;
24
+ }
25
+ }
26
+
27
+ // Return byte count for given readPixels WebGL type
28
+ export function glTypeToBytes(type) {
29
+ switch (type) {
30
+ case GL.UNSIGNED_BYTE:
31
+ return 1;
32
+ case GL.UNSIGNED_SHORT_5_6_5:
33
+ case GL.UNSIGNED_SHORT_4_4_4_4:
34
+ case GL.UNSIGNED_SHORT_5_5_5_1:
35
+ return 2;
36
+ case GL.FLOAT:
37
+ return 4;
38
+ // TODO: Add support for additional WebGL2 types
39
+ default:
40
+ assert(false);
41
+ return 0;
42
+ }
43
+ }