@luma.gl/webgl 9.0.0-alpha.53 → 9.0.0-alpha.54

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.
@@ -18,18 +18,15 @@ export declare class WEBGLBuffer extends Buffer {
18
18
  byteLength: number;
19
19
  /** Number of bytes used */
20
20
  bytesUsed: number;
21
- /** A partial CPU-side copy of the data in this buffer, for debugging purposes */
22
- debugData: ArrayBuffer | null;
23
21
  constructor(device: WebGLDevice, props?: BufferProps);
24
22
  /** Allocate a new buffer and initialize to contents of typed array */
25
- _initWithData(data: any, byteOffset?: number, byteLength?: number): this;
23
+ _initWithData(data: ArrayBuffer | ArrayBufferView, byteOffset?: number, byteLength?: number): void;
26
24
  _initWithByteLength(byteLength: number): this;
27
25
  destroy(): void;
28
26
  write(data: ArrayBufferView, byteOffset?: number): void;
29
- /** Read data from the buffer */
27
+ /** Asynchronously read data from the buffer */
30
28
  readAsync(byteOffset?: number, byteLength?: number): Promise<Uint8Array>;
31
- _invalidateDebugData(): void;
32
- _getWriteTarget(): GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER;
33
- _getReadTarget(): GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER;
29
+ /** Synchronously read data from the buffer. WebGL only. */
30
+ readSyncWebGL2(byteOffset?: number, byteLength?: number): Uint8Array;
34
31
  }
35
32
  //# sourceMappingURL=webgl-buffer.d.ts.map
@@ -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,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAC;AACtC,OAAO,EAAC,WAAW,EAAC,MAAM,iB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+C;IAChC,SAAS,CAAC,UAAU,SAAI,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAIlF,2DAA2D;IAClD,cAAc,CAAC,UAAU,SAAI,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,UAAU;CAiBzE"}
@@ -1,5 +1,4 @@
1
1
  import { Buffer, assert } from '@luma.gl/core';
2
- const DEBUG_DATA_LENGTH = 10;
3
2
  export class WEBGLBuffer extends Buffer {
4
3
  constructor(device) {
5
4
  let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -13,7 +12,6 @@ export class WEBGLBuffer extends Buffer {
13
12
  this.glIndexType = 5123;
14
13
  this.byteLength = void 0;
15
14
  this.bytesUsed = void 0;
16
- this.debugData = null;
17
15
  this.device = device;
18
16
  this.gl = this.device.gl;
19
17
  this.gl2 = this.device.gl2;
@@ -26,7 +24,6 @@ export class WEBGLBuffer extends Buffer {
26
24
  this.glTarget = getWebGLTarget(this.props.usage);
27
25
  this.glUsage = getWebGLUsage(this.props.usage);
28
26
  this.glIndexType = this.props.indexType === 'uint32' ? 5125 : 5123;
29
- this.debugData = null;
30
27
  if (props.data) {
31
28
  this._initWithData(props.data, props.byteOffset, props.byteLength);
32
29
  } else {
@@ -36,17 +33,15 @@ export class WEBGLBuffer extends Buffer {
36
33
  _initWithData(data) {
37
34
  let byteOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
38
35
  let byteLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : data.byteLength + byteOffset;
39
- assert(ArrayBuffer.isView(data));
40
- const glTarget = this._getWriteTarget();
36
+ const glTarget = this.glTarget;
41
37
  this.gl.bindBuffer(glTarget, this.handle);
42
38
  this.gl.bufferData(glTarget, byteLength, this.glUsage);
43
39
  this.gl.bufferSubData(glTarget, byteOffset, data);
44
40
  this.gl.bindBuffer(glTarget, null);
45
- this.debugData = data.slice(0, DEBUG_DATA_LENGTH);
46
41
  this.bytesUsed = byteLength;
47
42
  this.byteLength = byteLength;
43
+ this._setDebugData(data, byteOffset, byteLength);
48
44
  this.trackAllocatedMemory(byteLength);
49
- return this;
50
45
  }
51
46
  _initWithByteLength(byteLength) {
52
47
  assert(byteLength >= 0);
@@ -54,13 +49,14 @@ export class WEBGLBuffer extends Buffer {
54
49
  if (byteLength === 0) {
55
50
  data = new Float32Array(0);
56
51
  }
57
- const glTarget = this._getWriteTarget();
52
+ const glTarget = this.glTarget;
58
53
  this.gl.bindBuffer(glTarget, this.handle);
59
54
  this.gl.bufferData(glTarget, data, this.glUsage);
60
55
  this.gl.bindBuffer(glTarget, null);
61
- this.debugData = null;
62
56
  this.bytesUsed = byteLength;
63
57
  this.byteLength = byteLength;
58
+ this._setDebugData(null, 0, byteLength);
59
+ this.trackAllocatedMemory(byteLength);
64
60
  return this;
65
61
  }
66
62
  destroy() {
@@ -85,29 +81,27 @@ export class WEBGLBuffer extends Buffer {
85
81
  this.gl.bufferSubData(glTarget, byteOffset, data);
86
82
  }
87
83
  this.gl.bindBuffer(glTarget, null);
84
+ this._setDebugData(data, byteOffset, data.byteLength);
88
85
  }
89
86
  async readAsync() {
87
+ let byteOffset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
88
+ let byteLength = arguments.length > 1 ? arguments[1] : undefined;
89
+ return this.readSyncWebGL2(byteOffset, byteLength);
90
+ }
91
+ readSyncWebGL2() {
90
92
  var _byteLength;
91
93
  let byteOffset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
92
94
  let byteLength = arguments.length > 1 ? arguments[1] : undefined;
93
95
  this.device.assertWebGL2();
94
- byteLength = (_byteLength = byteLength) !== null && _byteLength !== void 0 ? _byteLength : this.byteLength;
96
+ byteLength = (_byteLength = byteLength) !== null && _byteLength !== void 0 ? _byteLength : this.byteLength - byteOffset;
95
97
  const data = new Uint8Array(byteLength);
96
98
  const dstOffset = 0;
97
99
  this.gl.bindBuffer(36662, this.handle);
98
100
  this.gl2.getBufferSubData(36662, byteOffset, data, dstOffset, byteLength);
99
101
  this.gl.bindBuffer(36662, null);
102
+ this._setDebugData(data, byteOffset, byteLength);
100
103
  return data;
101
104
  }
102
- _invalidateDebugData() {
103
- this.debugData = null;
104
- }
105
- _getWriteTarget() {
106
- return this.glTarget;
107
- }
108
- _getReadTarget() {
109
- return this.glTarget;
110
- }
111
105
  }
112
106
  function getWebGLTarget(usage) {
113
107
  if (usage & Buffer.INDEX) {
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-buffer.js","names":["Buffer","assert","DEBUG_DATA_LENGTH","WEBGLBuffer","constructor","device","props","arguments","length","undefined","gl","gl2","handle","glTarget","glUsage","glIndexType","byteLength","bytesUsed","debugData","createBuffer","setSpectorMetadata","data","getWebGLTarget","usage","getWebGLUsage","indexType","_initWithData","byteOffset","_initWithByteLength","ArrayBuffer","isView","_getWriteTarget","bindBuffer","bufferData","bufferSubData","slice","trackAllocatedMemory","Float32Array","destroy","destroyed","removeStats","trackDeallocatedMemory","deleteBuffer","write","srcOffset","isWebGL2","assertWebGL2","readAsync","_byteLength","Uint8Array","dstOffset","getBufferSubData","_invalidateDebugData","_getReadTarget","INDEX","VERTEX","UNIFORM"],"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;AAI5C,MAAMC,iBAAiB,GAAG,EAAE;AAG5B,OAAO,MAAMC,WAAW,SAASH,MAAM,CAAC;EAoBtCI,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;IAAA,KAGpBC,UAAU;IAAA,KAEVC,SAAS;IAAA,KAETC,SAAS,GAAuB,IAAI;IAKlC,IAAI,CAACb,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACK,EAAE,GAAG,IAAI,CAACL,MAAM,CAACK,EAAE;IACxB,IAAI,CAACC,GAAG,GAAG,IAAI,CAACN,MAAM,CAACM,GAAG;IAE1B,MAAMC,MAAM,GAAG,OAAON,KAAK,KAAK,QAAQ,GAAGA,KAAK,CAACM,MAAM,GAAGH,SAAS;IACnE,IAAI,CAACG,MAAM,GAAGA,MAAM,IAAI,IAAI,CAACF,EAAE,CAACS,YAAY,CAAC,CAAC;IAC9Cd,MAAM,CAACe,kBAAkB,CAAC,IAAI,CAACR,MAAM,EAAE;MAAC,GAAG,IAAI,CAACN,KAAK;MAAEe,IAAI,EAAE,OAAO,IAAI,CAACf,KAAK,CAACe;IAAI,CAAC,CAAC;IAKrF,IAAI,CAACR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S,GAAG,CAAC;IAGnB,IAAI,CAACxC,EAAE,CAACsB,UAAU,QAAsB,IAAI,CAACpB,MAAM,CAAC;IACpD,IAAI,CAACD,GAAG,CAACwC,gBAAgB,QAAsBxB,UAAU,EAAEN,IAAI,EAAE6B,SAAS,EAAElC,UAAU,CAAC;IACvF,IAAI,CAACN,EAAE,CAACsB,UAAU,QAAsB,IAAI,CAAC;IAK7C,OAAOX,IAAI;EACb;EAIA+B,oBAAoBA,CAAA,EAAG;IACrB,IAAI,CAAClC,SAAS,GAAG,IAAI;EACvB;EAEAa,eAAeA,CAAA,EAAG;IAChB,OAAO,IAAI,CAAClB,QAAQ;EAEtB;EAEAwC,cAAcA,CAAA,EAAG;IACf,OAAO,IAAI,CAACxC,QAAQ;EAEtB;AACF;AAaA,SAASS,cAAcA,CACrBC,KAAa,EACkD;EAC/D,IAAIA,KAAK,GAAGvB,MAAM,CAACsD,KAAK,EAAE;IACxB;EACF;EACA,IAAI/B,KAAK,GAAGvB,MAAM,CAACuD,MAAM,EAAE;IACzB;EACF;EACA,IAAIhC,KAAK,GAAGvB,MAAM,CAACwD,OAAO,EAAE;IAC1B;EACF;EAUA;AACF;AAGA,SAAShC,aAAaA,CAACD,KAAa,EAAoC;EACtE,IAAIA,KAAK,GAAGvB,MAAM,CAACsD,KAAK,EAAE;IACxB;EACF;EACA,IAAI/B,KAAK,GAAGvB,MAAM,CAACuD,MAAM,EAAE;IACzB;EACF;EACA,IAAIhC,KAAK,GAAGvB,MAAM,CAACwD,OAAO,EAAE;IAC1B;EACF;EACA;AACF"}
1
+ {"version":3,"file":"webgl-buffer.js","names":["Buffer","assert","WEBGLBuffer","constructor","device","props","arguments","length","undefined","gl","gl2","handle","glTarget","glUsage","glIndexType","byteLength","bytesUsed","createBuffer","setSpectorMetadata","data","getWebGLTarget","usage","getWebGLUsage","indexType","_initWithData","byteOffset","_initWithByteLength","bindBuffer","bufferData","bufferSubData","_setDebugData","trackAllocatedMemory","Float32Array","destroy","destroyed","removeStats","trackDeallocatedMemory","deleteBuffer","write","srcOffset","isWebGL2","assertWebGL2","readAsync","readSyncWebGL2","_byteLength","Uint8Array","dstOffset","getBufferSubData","INDEX","VERTEX","UNIFORM"],"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\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\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 // 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: ArrayBuffer | ArrayBufferView,\n byteOffset: number = 0,\n byteLength: number = data.byteLength + byteOffset\n ): void {\n // const glTarget = this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;\n const glTarget = this.glTarget;\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.bytesUsed = byteLength;\n this.byteLength = byteLength;\n\n this._setDebugData(data, byteOffset, byteLength);\n this.trackAllocatedMemory(byteLength);\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.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;\n const glTarget = this.glTarget;\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.bytesUsed = byteLength;\n this.byteLength = byteLength;\n\n this._setDebugData(null, 0, byteLength);\n this.trackAllocatedMemory(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 this._setDebugData(data, byteOffset, data.byteLength);\n }\n\n /** Asynchronously read data from the buffer */\n override async readAsync(byteOffset = 0, byteLength?: number): Promise<Uint8Array> {\n return this.readSyncWebGL2(byteOffset, byteLength);\n }\n\n /** Synchronously read data from the buffer. WebGL only. */\n override readSyncWebGL2(byteOffset = 0, byteLength?: number): Uint8Array {\n this.device.assertWebGL2();\n\n byteLength = byteLength ?? this.byteLength - byteOffset;\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 // Update local `data` if offsets are 0\n this._setDebugData(data, byteOffset, byteLength);\n\n return data;\n }\n}\n\n/**\n * Returns a WebGL buffer target\n *\n * @param usage\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 * \n * @returns WebGL buffer targe\n * \n * Buffer bind points in WebGL2\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 */\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 // Binding a buffer for the first time locks the type\n // In WebGL2, we can 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;AAK5C,OAAO,MAAMC,WAAW,SAASF,MAAM,CAAC;EAkBtCG,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,KAlBdD,MAAM;IAAA,KACNK,EAAE;IAAA,KACFC,GAAG;IAAA,KACHC,MAAM;IAAA,KAGNC,QAAQ;IAAA,KAERC,OAAO;IAAA,KAEPC,WAAW;IAAA,KAGpBC,UAAU;IAAA,KAEVC,S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EAAE;IACxB;EACF;EACA,IAAI3B,KAAK,GAAGrB,MAAM,CAACiD,MAAM,EAAE;IACzB;EACF;EACA,IAAI5B,KAAK,GAAGrB,MAAM,CAACkD,OAAO,EAAE;IAC1B;EACF;EAIA;AACF;AAGA,SAAS5B,aAAaA,CAACD,KAAa,EAAoC;EACtE,IAAIA,KAAK,GAAGrB,MAAM,CAACgD,KAAK,EAAE;IACxB;EACF;EACA,IAAI3B,KAAK,GAAGrB,MAAM,CAACiD,MAAM,EAAE;IACzB;EACF;EACA,IAAI5B,KAAK,GAAGrB,MAAM,CAACkD,OAAO,EAAE;IAC1B;EACF;EACA;AACF"}
package/dist/dist.dev.js CHANGED
@@ -1051,14 +1051,20 @@ var __exports__ = (() => {
1051
1051
  this.usage = props.usage || 0;
1052
1052
  this.indexType = deducedProps.indexType;
1053
1053
  }
1054
- write(data, byteOffset) {
1054
+ readSyncWebGL2(byteOffset, byteLength) {
1055
1055
  throw new Error("not implemented");
1056
1056
  }
1057
- readAsync(byteOffset, byteLength) {
1058
- throw new Error("not implemented");
1059
- }
1060
- getData() {
1061
- throw new Error("not implemented");
1057
+ debugData = new ArrayBuffer(0);
1058
+ _setDebugData(data, byteOffset, byteLength) {
1059
+ const buffer = ArrayBuffer.isView(data) ? data.buffer : data;
1060
+ const debugDataLength = Math.min(data ? data.byteLength : byteLength, _Buffer.DEBUG_DATA_MAX_LENGTH);
1061
+ if (data === null) {
1062
+ this.debugData = new ArrayBuffer(debugDataLength);
1063
+ } else if (byteOffset === 0 && byteLength === data.byteLength) {
1064
+ this.debugData = buffer.slice(0, debugDataLength);
1065
+ } else {
1066
+ this.debugData = buffer.slice(byteOffset, byteOffset + debugDataLength);
1067
+ }
1062
1068
  }
1063
1069
  };
1064
1070
  var Buffer2 = _Buffer;
@@ -1081,6 +1087,7 @@ var __exports__ = (() => {
1081
1087
  __publicField(Buffer2, "STORAGE", 128);
1082
1088
  __publicField(Buffer2, "INDIRECT", 256);
1083
1089
  __publicField(Buffer2, "QUERY_RESOLVE", 512);
1090
+ __publicField(Buffer2, "DEBUG_DATA_MAX_LENGTH", 32);
1084
1091
 
1085
1092
  // ../core/src/adapter/device.ts
1086
1093
  var _Device = class {
@@ -5099,10 +5106,8 @@ void main(void) {}`;
5099
5106
  }
5100
5107
 
5101
5108
  // src/adapter/resources/webgl-buffer.ts
5102
- var DEBUG_DATA_LENGTH = 10;
5103
5109
  var WEBGLBuffer = class extends Buffer2 {
5104
5110
  glIndexType = 5123;
5105
- debugData = null;
5106
5111
  constructor(device, props = {}) {
5107
5112
  super(device, props);
5108
5113
  this.device = device;
@@ -5117,7 +5122,6 @@ void main(void) {}`;
5117
5122
  this.glTarget = getWebGLTarget(this.props.usage);
5118
5123
  this.glUsage = getWebGLUsage(this.props.usage);
5119
5124
  this.glIndexType = this.props.indexType === "uint32" ? 5125 : 5123;
5120
- this.debugData = null;
5121
5125
  if (props.data) {
5122
5126
  this._initWithData(props.data, props.byteOffset, props.byteLength);
5123
5127
  } else {
@@ -5125,17 +5129,15 @@ void main(void) {}`;
5125
5129
  }
5126
5130
  }
5127
5131
  _initWithData(data, byteOffset = 0, byteLength = data.byteLength + byteOffset) {
5128
- assert2(ArrayBuffer.isView(data));
5129
- const glTarget = this._getWriteTarget();
5132
+ const glTarget = this.glTarget;
5130
5133
  this.gl.bindBuffer(glTarget, this.handle);
5131
5134
  this.gl.bufferData(glTarget, byteLength, this.glUsage);
5132
5135
  this.gl.bufferSubData(glTarget, byteOffset, data);
5133
5136
  this.gl.bindBuffer(glTarget, null);
5134
- this.debugData = data.slice(0, DEBUG_DATA_LENGTH);
5135
5137
  this.bytesUsed = byteLength;
5136
5138
  this.byteLength = byteLength;
5139
+ this._setDebugData(data, byteOffset, byteLength);
5137
5140
  this.trackAllocatedMemory(byteLength);
5138
- return this;
5139
5141
  }
5140
5142
  _initWithByteLength(byteLength) {
5141
5143
  assert2(byteLength >= 0);
@@ -5143,13 +5145,14 @@ void main(void) {}`;
5143
5145
  if (byteLength === 0) {
5144
5146
  data = new Float32Array(0);
5145
5147
  }
5146
- const glTarget = this._getWriteTarget();
5148
+ const glTarget = this.glTarget;
5147
5149
  this.gl.bindBuffer(glTarget, this.handle);
5148
5150
  this.gl.bufferData(glTarget, data, this.glUsage);
5149
5151
  this.gl.bindBuffer(glTarget, null);
5150
- this.debugData = null;
5151
5152
  this.bytesUsed = byteLength;
5152
5153
  this.byteLength = byteLength;
5154
+ this._setDebugData(null, 0, byteLength);
5155
+ this.trackAllocatedMemory(byteLength);
5153
5156
  return this;
5154
5157
  }
5155
5158
  destroy() {
@@ -5173,26 +5176,22 @@ void main(void) {}`;
5173
5176
  this.gl.bufferSubData(glTarget, byteOffset, data);
5174
5177
  }
5175
5178
  this.gl.bindBuffer(glTarget, null);
5179
+ this._setDebugData(data, byteOffset, data.byteLength);
5176
5180
  }
5177
5181
  async readAsync(byteOffset = 0, byteLength) {
5182
+ return this.readSyncWebGL2(byteOffset, byteLength);
5183
+ }
5184
+ readSyncWebGL2(byteOffset = 0, byteLength) {
5178
5185
  this.device.assertWebGL2();
5179
- byteLength = byteLength ?? this.byteLength;
5186
+ byteLength = byteLength ?? this.byteLength - byteOffset;
5180
5187
  const data = new Uint8Array(byteLength);
5181
5188
  const dstOffset = 0;
5182
5189
  this.gl.bindBuffer(36662, this.handle);
5183
5190
  this.gl2.getBufferSubData(36662, byteOffset, data, dstOffset, byteLength);
5184
5191
  this.gl.bindBuffer(36662, null);
5192
+ this._setDebugData(data, byteOffset, byteLength);
5185
5193
  return data;
5186
5194
  }
5187
- _invalidateDebugData() {
5188
- this.debugData = null;
5189
- }
5190
- _getWriteTarget() {
5191
- return this.glTarget;
5192
- }
5193
- _getReadTarget() {
5194
- return this.glTarget;
5195
- }
5196
5195
  };
5197
5196
  function getWebGLTarget(usage) {
5198
5197
  if (usage & Buffer2.INDEX) {
package/dist/index.cjs CHANGED
@@ -2574,7 +2574,6 @@ function convertMinFilterMode(minFilter, mipmapFilter) {
2574
2574
  // src/adapter/resources/webgl-buffer.ts
2575
2575
  var import_core7 = require("@luma.gl/core");
2576
2576
  var import_constants10 = require("@luma.gl/constants");
2577
- var DEBUG_DATA_LENGTH = 10;
2578
2577
  var WEBGLBuffer = class extends import_core7.Buffer {
2579
2578
  device;
2580
2579
  gl;
@@ -2590,8 +2589,6 @@ var WEBGLBuffer = class extends import_core7.Buffer {
2590
2589
  byteLength;
2591
2590
  /** Number of bytes used */
2592
2591
  bytesUsed;
2593
- /** A partial CPU-side copy of the data in this buffer, for debugging purposes */
2594
- debugData = null;
2595
2592
  constructor(device, props = {}) {
2596
2593
  super(device, props);
2597
2594
  this.device = device;
@@ -2603,7 +2600,6 @@ var WEBGLBuffer = class extends import_core7.Buffer {
2603
2600
  this.glTarget = getWebGLTarget(this.props.usage);
2604
2601
  this.glUsage = getWebGLUsage(this.props.usage);
2605
2602
  this.glIndexType = this.props.indexType === "uint32" ? import_constants10.GL.UNSIGNED_INT : import_constants10.GL.UNSIGNED_SHORT;
2606
- this.debugData = null;
2607
2603
  if (props.data) {
2608
2604
  this._initWithData(props.data, props.byteOffset, props.byteLength);
2609
2605
  } else {
@@ -2613,17 +2609,15 @@ var WEBGLBuffer = class extends import_core7.Buffer {
2613
2609
  // PRIVATE METHODS
2614
2610
  /** Allocate a new buffer and initialize to contents of typed array */
2615
2611
  _initWithData(data, byteOffset = 0, byteLength = data.byteLength + byteOffset) {
2616
- (0, import_core7.assert)(ArrayBuffer.isView(data));
2617
- const glTarget = this._getWriteTarget();
2612
+ const glTarget = this.glTarget;
2618
2613
  this.gl.bindBuffer(glTarget, this.handle);
2619
2614
  this.gl.bufferData(glTarget, byteLength, this.glUsage);
2620
2615
  this.gl.bufferSubData(glTarget, byteOffset, data);
2621
2616
  this.gl.bindBuffer(glTarget, null);
2622
- this.debugData = data.slice(0, DEBUG_DATA_LENGTH);
2623
2617
  this.bytesUsed = byteLength;
2624
2618
  this.byteLength = byteLength;
2619
+ this._setDebugData(data, byteOffset, byteLength);
2625
2620
  this.trackAllocatedMemory(byteLength);
2626
- return this;
2627
2621
  }
2628
2622
  // Allocate a GPU buffer of specified size.
2629
2623
  _initWithByteLength(byteLength) {
@@ -2632,13 +2626,14 @@ var WEBGLBuffer = class extends import_core7.Buffer {
2632
2626
  if (byteLength === 0) {
2633
2627
  data = new Float32Array(0);
2634
2628
  }
2635
- const glTarget = this._getWriteTarget();
2629
+ const glTarget = this.glTarget;
2636
2630
  this.gl.bindBuffer(glTarget, this.handle);
2637
2631
  this.gl.bufferData(glTarget, data, this.glUsage);
2638
2632
  this.gl.bindBuffer(glTarget, null);
2639
- this.debugData = null;
2640
2633
  this.bytesUsed = byteLength;
2641
2634
  this.byteLength = byteLength;
2635
+ this._setDebugData(null, 0, byteLength);
2636
+ this.trackAllocatedMemory(byteLength);
2642
2637
  return this;
2643
2638
  }
2644
2639
  destroy() {
@@ -2662,28 +2657,24 @@ var WEBGLBuffer = class extends import_core7.Buffer {
2662
2657
  this.gl.bufferSubData(glTarget, byteOffset, data);
2663
2658
  }
2664
2659
  this.gl.bindBuffer(glTarget, null);
2660
+ this._setDebugData(data, byteOffset, data.byteLength);
2665
2661
  }
2666
- /** Read data from the buffer */
2662
+ /** Asynchronously read data from the buffer */
2667
2663
  async readAsync(byteOffset = 0, byteLength) {
2664
+ return this.readSyncWebGL2(byteOffset, byteLength);
2665
+ }
2666
+ /** Synchronously read data from the buffer. WebGL only. */
2667
+ readSyncWebGL2(byteOffset = 0, byteLength) {
2668
2668
  this.device.assertWebGL2();
2669
- byteLength = byteLength ?? this.byteLength;
2669
+ byteLength = byteLength ?? this.byteLength - byteOffset;
2670
2670
  const data = new Uint8Array(byteLength);
2671
2671
  const dstOffset = 0;
2672
2672
  this.gl.bindBuffer(import_constants10.GL.COPY_READ_BUFFER, this.handle);
2673
2673
  this.gl2.getBufferSubData(import_constants10.GL.COPY_READ_BUFFER, byteOffset, data, dstOffset, byteLength);
2674
2674
  this.gl.bindBuffer(import_constants10.GL.COPY_READ_BUFFER, null);
2675
+ this._setDebugData(data, byteOffset, byteLength);
2675
2676
  return data;
2676
2677
  }
2677
- // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)
2678
- _invalidateDebugData() {
2679
- this.debugData = null;
2680
- }
2681
- _getWriteTarget() {
2682
- return this.glTarget;
2683
- }
2684
- _getReadTarget() {
2685
- return this.glTarget;
2686
- }
2687
2678
  };
2688
2679
  function getWebGLTarget(usage) {
2689
2680
  if (usage & import_core7.Buffer.INDEX) {