-
Notifications
You must be signed in to change notification settings - Fork 3.8k
BufferPrimitiveCollection: Add 3D renderers #13213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0cc9073
2f2afaa
23b65df
1b52d63
24ec625
c8ca2a2
bcc2a9c
7fa2641
dab8c4a
b1a075c
c37037e
ab2076d
072f8d4
bf049df
2f9d0fe
b443692
8e76838
5d91189
3ab955a
56bb70e
7fce3db
a471873
283e394
e5d43a9
a6ededf
ee98e8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,9 @@ import Buffer from "./Buffer.js"; | |
| import BufferUsage from "./BufferUsage.js"; | ||
| import ContextLimits from "./ContextLimits.js"; | ||
| import AttributeType from "../Scene/AttributeType.js"; | ||
| import assert from "../Core/assert.js"; | ||
|
|
||
| /** @import {TypedArray, TypedArrayConstructor} from "../Core/globalTypes.js"; */ | ||
|
|
||
| function addAttribute(attributes, attribute, index, context) { | ||
| const hasVertexBuffer = defined(attribute.vertexBuffer); | ||
|
|
@@ -801,6 +804,83 @@ function setConstantAttributes(vertexArray, gl) { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Copies into a vertex attribute buffer from the given array, at a given | ||
| * range specified as offset and count, in number of (VECN) vertices. Array | ||
| * and vertex attribute must have the same length, which can be larger | ||
| * than the specified range to update. | ||
| * @param {number} attributeIndex | ||
| * @param {TypedArray} array | ||
| * @param {number} vertexOffset | ||
| * @param {number} vertexCount | ||
| */ | ||
| VertexArray.prototype.copyAttributeFromRange = function ( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These methods could be moved somewhere else, but seemed like they might be generally helpful? The use case here is to hold an array of the same size as the buffer in memory, and to re-upload only the dirty range after updates. Avoids memory allocation (and potential GC stalls) during rendering. This would be harder to guarantee if the array were created dynamically in the render loop, or sized to only include the updated range of elements. |
||
| attributeIndex, | ||
| array, | ||
| vertexOffset, | ||
| vertexCount, | ||
| ) { | ||
| const attribute = this.getAttribute(attributeIndex); | ||
| const buffer = /** @type {Buffer} */ (attribute.vertexBuffer); | ||
| const elementsPerVertex = attribute.componentsPerAttribute; | ||
|
|
||
| //>>includeStart('debug', pragmas.debug); | ||
| assert(buffer.sizeInBytes === array.byteLength, "Invalid buffer length"); | ||
| //>>includeEnd('debug'); | ||
|
|
||
| const ArrayConstructor = /** @type {TypedArrayConstructor} */ ( | ||
| array.constructor | ||
| ); | ||
|
|
||
| const byteOffset = | ||
| vertexOffset * elementsPerVertex * ArrayConstructor.BYTES_PER_ELEMENT; | ||
|
|
||
| // Create a zero-copy ArrayView onto the specified range of the source array. | ||
| const rangeArrayView = new ArrayConstructor( | ||
| /** @type {ArrayBuffer} */ (array.buffer), | ||
| array.byteOffset + byteOffset, | ||
| vertexCount * elementsPerVertex, | ||
| ); | ||
|
|
||
| buffer.copyFromArrayView(rangeArrayView, byteOffset); | ||
| }; | ||
|
|
||
| /** | ||
| * Copies into the index buffer from the given array, at a given range | ||
| * specified as offset and count, in number of (uint) indices. Array | ||
| * and index buffer must have the same length, which can be larger | ||
| * than the specified range to update. | ||
| * @param {TypedArray} array | ||
| * @param {number} indexOffset | ||
| * @param {number} indexCount | ||
| */ | ||
| VertexArray.prototype.copyIndexFromRange = function ( | ||
| array, | ||
| indexOffset, | ||
| indexCount, | ||
| ) { | ||
| const buffer = /** @type {Buffer} */ (this._indexBuffer); | ||
|
|
||
| //>>includeStart('debug', pragmas.debug); | ||
| assert(buffer.sizeInBytes === array.byteLength, "Invalid buffer length"); | ||
| //>>includeEnd('debug'); | ||
|
|
||
| const ArrayConstructor = /** @type {TypedArrayConstructor} */ ( | ||
| array.constructor | ||
| ); | ||
|
|
||
| const byteOffset = indexOffset * ArrayConstructor.BYTES_PER_ELEMENT; | ||
|
|
||
| // Create a zero-copy ArrayView onto the specified range of the source array. | ||
| const rangeArrayView = new ArrayConstructor( | ||
| /** @type {ArrayBuffer} */ (array.buffer), | ||
| array.byteOffset + byteOffset, | ||
| indexCount, | ||
| ); | ||
|
|
||
| buffer.copyFromArrayView(rangeArrayView, byteOffset); | ||
| }; | ||
|
|
||
| VertexArray.prototype._bind = function () { | ||
| if (defined(this._vao)) { | ||
| this._context.glBindVertexArray(this._vao); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to build before running
npm run tscso the type checker can see built outputs from*.glslfiles.