MCPcopy
hub / github.com/CesiumGS/cesium / Buffer

Function Buffer

packages/engine/Source/Renderer/Buffer.js:14–73  ·  view source on GitHub ↗

* @private

(options)

Source from the content-addressed store, hash-verified

12 * @private
13 */
14function Buffer(options) {
15 options = options ?? Frozen.EMPTY_OBJECT;
16
17 //>>includeStart('debug', pragmas.debug);
18 Check.defined("options.context", options.context);
19
20 if (!defined(options.typedArray) && !defined(options.sizeInBytes)) {
21 throw new DeveloperError(
22 "Either options.sizeInBytes or options.typedArray is required.",
23 );
24 }
25
26 if (defined(options.typedArray) && defined(options.sizeInBytes)) {
27 throw new DeveloperError(
28 "Cannot pass in both options.sizeInBytes and options.typedArray.",
29 );
30 }
31
32 if (defined(options.typedArray)) {
33 Check.typeOf.object("options.typedArray", options.typedArray);
34 Check.typeOf.number(
35 "options.typedArray.byteLength",
36 options.typedArray.byteLength,
37 );
38 }
39
40 if (!BufferUsage.validate(options.usage)) {
41 throw new DeveloperError("usage is invalid.");
42 }
43 //>>includeEnd('debug');
44
45 const gl = options.context._gl;
46 const bufferTarget = options.bufferTarget;
47 const typedArray = options.typedArray;
48 let sizeInBytes = options.sizeInBytes;
49 const usage = options.usage;
50 const hasArray = defined(typedArray);
51
52 if (hasArray) {
53 sizeInBytes = typedArray.byteLength;
54 }
55
56 //>>includeStart('debug', pragmas.debug);
57 Check.typeOf.number.greaterThan("sizeInBytes", sizeInBytes, 0);
58 //>>includeEnd('debug');
59
60 const buffer = gl.createBuffer();
61 gl.bindBuffer(bufferTarget, buffer);
62 gl.bufferData(bufferTarget, hasArray ? typedArray : sizeInBytes, usage);
63 gl.bindBuffer(bufferTarget, null);
64
65 this._id = createGuid();
66 this._gl = gl;
67 this._webgl2 = options.context._webgl2;
68 this._bufferTarget = bufferTarget;
69 this._sizeInBytes = sizeInBytes;
70 this._usage = usage;
71 this._buffer = buffer;

Callers

nothing calls this directly

Calls 4

createGuidFunction · 0.85
objectMethod · 0.80
greaterThanMethod · 0.80
definedFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…