Creates a zero initialized buffer with the given size.
Context used for all GPU operations.
Size of the buffer in bytes.
Usage hint for allocation of the GPU-sided buffer.
Threshold in which all updates will get merged.
Unique identifier for this UnifiedBuffer.
Asserts the objects initialization status to be true. Note that the implementation is cached and forwarded to either an empty function when initialized and to an acutal assert(false) otherwise.
Asserts the objects initialization status to be false. Note that the implementation is cached and forwarded to either an empty function when uninitialized and to an acutal assert(false) otherwise.
Property getter for readonly access to the initialization status of an initializable instance.
Returns the threshold used to determine whether two ranges have to be merged.
Sets the threshold determining whether two ranges have to be merged. If the mergeThreshold is set to -1 all ranges will get merged disregarding their distance to each other.
Returns the size of the CPU-sided buffer. This is not necessarily the same as the size of the GPU-sided buffer, if update has not been called after resizing the buffer.
Resizes the buffer. Note, that this does not resize the GPU-sided buffer. To update the size of the GPU-sided buffer update has to be called.
Target to which the buffer object is bound (either GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER). Readonly access to the target (as specified on initialization) the buffer will be bound to.
Returns the usage hint used for allocation of the GPU-sided buffer.
Sets the usage hint used for allocation of the GPU-sided buffer.
Adds a range to recorded updates. Transitively merges all already recorded updates within the mergeThreshold of the added range.
Range to add to the updates.
Disables a buffer binding point.
Index of the vertex attribute that is to be disabled.
Allows to skip binding the object (e.g., when binding is handled outside).
Allows to skip unbinding the object (e.g., when binding is handled outside).
Specifies the memory layout of the buffer for a binding point.
Index of the vertex attribute that is to be setup and enabled.
Number of components per vertex attribute.
Data type of each component in the array.
Whether integer data values should be normalized when being casted to a float.
Offset in bytes between the beginning of consecutive vertex attributes.
Offset in bytes of the first component in the vertex attribute array.
Allows to skip binding the object (e.g., when binding is handled outside).
Allows to skip unbinding the object (e.g., when binding is handled outside).
Binds the buffer object as buffer to predefined target.
Create the buffer object on the GPU.
Target used as binding point.
Merges all recorded subData ranges.
Merges all updates left of index transitively with the update at index until there are no more updates within the merge threshold.
Index of the update that should get merged.
Merges all updates right of index transitively with the update at index until there are no more updates within the merge threshold.
Index of the update that should get merged.
Copies the new data into the CPU-sided buffer and records the range as changed. All previously added ranges will get merged transitively with the new one, if they are within the set mergeThreshold. Note: This does not transfer anything to the GPU-sided buffer yet.
Offset of bytes into the destination buffer.
Data that will be copied into the destination buffer.
Binds null as current buffer to predefined target;
Delete the buffer object on the GPU. This should have the reverse effect of create
.
Copies all previously recorded ranges and their data to the GPU. (Re-)Allocate the GPU-sided buffer if the size changed or the object was reinitialized.
Allows to skip binding the object (e.g., when binding is handled outside).
Allows to skip unbinding the object (e.g., when binding is handled outside).
Method decorator for asserting the initialization status of an initializable to be true.
Method decorator for asserting the initialization status of an initializable to be false.
Method decorator for discarding of Initializable inheritors. This decorator asserts the initialization
status of the instance that is to be discarded, invokes its uninitialization, and falsifies the
initialization status. In order to encourage the use of assertInitialized
and assertUninitialized
they are
dynamically bound to a static, always-failing assert and an empty/undefined function respectively.
Method decorator for initialization of Initializable inheritors. This decorator asserts the initialization status
of the instance that is to be initialized, invokes its initialization with arbitrary number of parameters,
and sets the initialization status to the initialization success (either false or true).
In order to encourage the use of assertInitialized
and assertUninitialized
they are dynamically
bound to either a static, always-failing assert or an empty/undefined function.
Method decorator for uninitialization of Initializable inheritors. This decorator asserts the initialization
status of the instance that is to be uninitialized, invokes its uninitialization, and falsifies the
initialization status. In order to encourage the use of assertInitialized
and assertUninitialized
they are
dynamically bound to a static, always-failing assert and an empty/undefined function respectively.
Checks if two updates have to be merged according to the mergeThreshold. Note: lhsUpdate.begin has to be smaller than rhsUpdate.begin.
First update
Second update
Threshold considered for merging.
Class to encapsulating a WebGL buffer adding functionality to record changes to the underlying buffer without instantly propagating them to the WebGL buffer. It is intended to be a direct replacement for Buffer. When calling subData the data will be copied to an internal, CPU-sided buffer and the affecting range will be recorded. If the newly recorded range overrides a part of or the whole of a previously recorded range the older one will either be discarded completely or merged with the new one according to a specifiable merge threshold. To propagate all recorded changes to the GPU-sided buffer, update has to be called. This will take care of both the allocation of the GPU-sided buffer and the transfer of the changed data. While update can must only be called after initializing the object, subData, mergeSubDataRanges and resizing (@seesize) can be called on the unitialized object. The GPU-sided buffer is created on initialization and deleted on uninitialization. A typical usage could look like this:
``` // Create a unified buffer with the size of 1028 bytes and a mergeThreshold of 32 bytes const unifiedBuffer = new UnifiedBuffer(context, 1028, gl.STATIC_DRAW, 32, 'UnifiedBuffer'); unifiedBuffer.initialize(gl.ARRAY_BUFFER); unifiedBuffer.attribEnable(0, 1, gl.FLOAT, gl.FALSE, 0, 0, true, false); unifiedBuffer.attribEnable(1, 1, gl.SHORT, gl.FALSE, 0, 512, false, true);
unifiedBuffer.subData(0, new Float32Array(64).fill(3.14)); unifiedBuffer.subData(512, new Int16Array(128).fill(1200));
unifiedBuffer.update(true, true);
unifiedBuffer.subData(128, new Float32Array(32).fill(1.57)); unifiedBuffer.subData(640, new Int36Array(64).fill(600));
unifiedBuffer.mergeThreshold = -1; // This will merge both already existing ranges resulting in a single update unifiedBuffer.mergeSubDataRanges();
unifiedBuffer.bind(); unifiedBuffer.update(); unifiedBuffer.unbind();