@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/webgl",
3
- "version": "9.0.0-alpha.53",
3
+ "version": "9.0.0-alpha.54",
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/constants": "9.0.0-alpha.53",
48
- "@luma.gl/core": "9.0.0-alpha.53",
47
+ "@luma.gl/constants": "9.0.0-alpha.54",
48
+ "@luma.gl/core": "9.0.0-alpha.54",
49
49
  "@probe.gl/env": "^4.0.2"
50
50
  },
51
51
  "devDependencies": {
52
- "@luma.gl/test-utils": "9.0.0-alpha.53"
52
+ "@luma.gl/test-utils": "9.0.0-alpha.54"
53
53
  },
54
- "gitHead": "f8939f1cf52a15f11ec053d4906e40f0b2a86836"
54
+ "gitHead": "6028eb651303eadbc8f25e86d135d28f118fa3cf"
55
55
  }
@@ -6,8 +6,6 @@ import {Buffer, assert} from '@luma.gl/core';
6
6
  import {GL} from '@luma.gl/constants';
7
7
  import {WebGLDevice} from '../webgl-device';
8
8
 
9
- const DEBUG_DATA_LENGTH = 10;
10
-
11
9
  /** WebGL Buffer interface */
12
10
  export class WEBGLBuffer extends Buffer {
13
11
  readonly device: WebGLDevice;
@@ -26,8 +24,6 @@ export class WEBGLBuffer extends Buffer {
26
24
  byteLength: number;
27
25
  /** Number of bytes used */
28
26
  bytesUsed: number;
29
- /** A partial CPU-side copy of the data in this buffer, for debugging purposes */
30
- debugData: ArrayBuffer | null = null;
31
27
 
32
28
  constructor(device: WebGLDevice, props: BufferProps = {}) {
33
29
  super(device, props);
@@ -47,8 +43,6 @@ export class WEBGLBuffer extends Buffer {
47
43
  this.glUsage = getWebGLUsage(this.props.usage);
48
44
  this.glIndexType = this.props.indexType === 'uint32' ? GL.UNSIGNED_INT : GL.UNSIGNED_SHORT;
49
45
 
50
- this.debugData = null;
51
-
52
46
  // Set data: (re)initializes the buffer
53
47
  if (props.data) {
54
48
  this._initWithData(props.data, props.byteOffset, props.byteLength);
@@ -61,24 +55,22 @@ export class WEBGLBuffer extends Buffer {
61
55
 
62
56
  /** Allocate a new buffer and initialize to contents of typed array */
63
57
  _initWithData(
64
- data,
58
+ data: ArrayBuffer | ArrayBufferView,
65
59
  byteOffset: number = 0,
66
60
  byteLength: number = data.byteLength + byteOffset
67
- ): this {
68
- assert(ArrayBuffer.isView(data));
69
-
70
- const glTarget = this._getWriteTarget();
61
+ ): void {
62
+ // const glTarget = this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;
63
+ const glTarget = this.glTarget;
71
64
  this.gl.bindBuffer(glTarget, this.handle);
72
65
  this.gl.bufferData(glTarget, byteLength, this.glUsage);
73
66
  this.gl.bufferSubData(glTarget, byteOffset, data);
74
67
  this.gl.bindBuffer(glTarget, null);
75
68
 
76
- this.debugData = data.slice(0, DEBUG_DATA_LENGTH);
77
69
  this.bytesUsed = byteLength;
78
70
  this.byteLength = byteLength;
79
- this.trackAllocatedMemory(byteLength);
80
71
 
81
- return this;
72
+ this._setDebugData(data, byteOffset, byteLength);
73
+ this.trackAllocatedMemory(byteLength);
82
74
  }
83
75
 
84
76
  // Allocate a GPU buffer of specified size.
@@ -93,16 +85,19 @@ export class WEBGLBuffer extends Buffer {
93
85
  data = new Float32Array(0);
94
86
  }
95
87
 
96
- const glTarget = this._getWriteTarget();
88
+ // const glTarget = this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;
89
+ const glTarget = this.glTarget;
97
90
 
98
91
  this.gl.bindBuffer(glTarget, this.handle);
99
92
  this.gl.bufferData(glTarget, data, this.glUsage);
100
93
  this.gl.bindBuffer(glTarget, null);
101
94
 
102
- this.debugData = null;
103
95
  this.bytesUsed = byteLength;
104
96
  this.byteLength = byteLength;
105
97
 
98
+ this._setDebugData(null, 0, byteLength);
99
+ this.trackAllocatedMemory(byteLength);
100
+
106
101
  return this;
107
102
  }
108
103
 
@@ -134,15 +129,19 @@ export class WEBGLBuffer extends Buffer {
134
129
  }
135
130
  this.gl.bindBuffer(glTarget, null);
136
131
 
137
- // TODO - update local `data` if offsets are right
138
- // this.debugData = data.slice(byteOffset, 40);
132
+ this._setDebugData(data, byteOffset, data.byteLength);
139
133
  }
140
134
 
141
- /** Read data from the buffer */
135
+ /** Asynchronously read data from the buffer */
142
136
  override async readAsync(byteOffset = 0, byteLength?: number): Promise<Uint8Array> {
137
+ return this.readSyncWebGL2(byteOffset, byteLength);
138
+ }
139
+
140
+ /** Synchronously read data from the buffer. WebGL only. */
141
+ override readSyncWebGL2(byteOffset = 0, byteLength?: number): Uint8Array {
143
142
  this.device.assertWebGL2();
144
143
 
145
- byteLength = byteLength ?? this.byteLength;
144
+ byteLength = byteLength ?? this.byteLength - byteOffset;
146
145
  const data = new Uint8Array(byteLength);
147
146
  const dstOffset = 0;
148
147
 
@@ -151,40 +150,37 @@ export class WEBGLBuffer extends Buffer {
151
150
  this.gl2.getBufferSubData(GL.COPY_READ_BUFFER, byteOffset, data, dstOffset, byteLength);
152
151
  this.gl.bindBuffer(GL.COPY_READ_BUFFER, null);
153
152
 
154
- // TODO - update local `data` if offsets are 0
155
- // this.debugData = null;
153
+ // Update local `data` if offsets are 0
154
+ this._setDebugData(data, byteOffset, byteLength);
156
155
 
157
156
  return data;
158
157
  }
159
-
160
- // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)
161
-
162
- _invalidateDebugData() {
163
- this.debugData = null;
164
- }
165
-
166
- _getWriteTarget() {
167
- return this.glTarget;
168
- // return this.device.isWebGL2 ? GL.COPY_WRITE_BUFFER : this.glTarget;
169
- }
170
-
171
- _getReadTarget() {
172
- return this.glTarget;
173
- // return this.device.isWebGL2 ? GL.COPY_READ_BUFFER : this.glTarget;
174
- }
175
158
  }
176
159
 
177
- // static MAP_READ = 0x01;
178
- // static MAP_WRITE = 0x02;
179
- // static COPY_SRC = 0x0004;
180
- // static COPY_DST = 0x0008;
181
- // static INDEX = 0x0010;
182
- // static VERTEX = 0x0020;
183
- // static UNIFORM = 0x0040;
184
- // static STORAGE = 0x0080;
185
- // static INDIRECT = 0x0100;
186
- // static QUERY_RESOLVE = 0x0200;
187
-
160
+ /**
161
+ * Returns a WebGL buffer target
162
+ *
163
+ * @param usage
164
+ * static MAP_READ = 0x01;
165
+ * static MAP_WRITE = 0x02;
166
+ * static COPY_SRC = 0x0004;
167
+ * static COPY_DST = 0x0008;
168
+ * static INDEX = 0x0010;
169
+ * static VERTEX = 0x0020;
170
+ * static UNIFORM = 0x0040;
171
+ * static STORAGE = 0x0080;
172
+ * static INDIRECT = 0x0100;
173
+ * static QUERY_RESOLVE = 0x0200;
174
+ *
175
+ * @returns WebGL buffer targe
176
+ *
177
+ * Buffer bind points in WebGL2
178
+ * gl.COPY_READ_BUFFER: Buffer for copying from one buffer object to another.
179
+ * gl.COPY_WRITE_BUFFER: Buffer for copying from one buffer object to another.
180
+ * gl.TRANSFORM_FEEDBACK_BUFFER: Buffer for transform feedback operations.
181
+ * gl.PIXEL_PACK_BUFFER: Buffer used for pixel transfer operations.
182
+ * gl.PIXEL_UNPACK_BUFFER: Buffer used for pixel transfer operations.
183
+ */
188
184
  function getWebGLTarget(
189
185
  usage: number
190
186
  ): GL.ARRAY_BUFFER | GL.ELEMENT_ARRAY_BUFFER | GL.UNIFORM_BUFFER {
@@ -198,14 +194,8 @@ function getWebGLTarget(
198
194
  return GL.UNIFORM_BUFFER;
199
195
  }
200
196
 
201
- // gl.COPY_READ_BUFFER: Buffer for copying from one buffer object to another.
202
- // gl.COPY_WRITE_BUFFER: Buffer for copying from one buffer object to another.
203
- // gl.TRANSFORM_FEEDBACK_BUFFER: Buffer for transform feedback operations.
204
- // gl.PIXEL_PACK_BUFFER: Buffer used for pixel transfer operations.
205
- // gl.PIXEL_UNPACK_BUFFER: Buffer used for pixel transfer operations.
206
-
207
197
  // Binding a buffer for the first time locks the type
208
- // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type
198
+ // In WebGL2, we can use GL.COPY_WRITE_BUFFER to avoid locking the type
209
199
  return GL.ARRAY_BUFFER;
210
200
  }
211
201