Class SpiderGL.WebGL.Buffer
The SpiderGL.WebGL.Buffer is the base class for all WebGLBuffer object wrappers, i.e. SpiderGL.WebGL.VertexBuffer and SpiderGL.WebGL.IndexBuffer.
- Defined in: webgl.js
- Extends SpiderGL.WebGL.ObjectGL
Constructor Attributes | Constructor Name and Description |
---|---|
SpiderGL.WebGL.Buffer(gl, target, options)
Creates a SpiderGL.WebGL.Buffer.
|
Field Attributes | Field Name and Description |
---|---|
<static> |
SpiderGL.WebGL.Buffer.DEFAULT_SUB_DATA_OFFSET
Default buffer offset when specifying buffer subdata.
|
<static> |
SpiderGL.WebGL.Buffer.DEFAULT_USAGE
Default usage hint when specifying buffer size or data.
|
<readonly> |
Tests if the buffer is ready to use.
|
<readonly> |
The size in bytes of the buffer.
|
<static> |
SpiderGL.WebGL.Buffer.TARGET
Default WebGLBuffer target.
|
<readonly> |
The usage hint of the WebGLBuffer.
|
- Fields borrowed from class SpiderGL.WebGL.ObjectGL:
- gl, handle, isValid, target
- Fields borrowed from class SpiderGL.Core.ObjectBase:
- uid
Method Summary
Method Attributes | Method Name and Description |
---|---|
bind()
Binds the wrapped WebGLBuffer to the appropriate target.
|
|
destroy()
Destroys the WebGLBuffer.
|
|
setData(data, usage)
Sets the buffer data and usage.
|
|
setSize(size, usage)
Sets the buffer size and usage.
|
|
setSubData(data, offset)
Sets a range of the buffer data.
|
|
unbind()
Binds "null" to the appropriate target.
|
|
<static> |
SpiderGL.WebGL.Buffer.unbind(gl)
Generic WebGLBuffer unbinding.
|
Class Detail
SpiderGL.WebGL.Buffer(gl, target, options)
Creates a SpiderGL.WebGL.Buffer.
SpiderGL.WebGL.Buffer is the base class for WebGLBuffer object wrappers (SpiderGL.WebGL.VertexBuffer and SpiderGL.WebGL.IndexBuffer) and must not be directly used.
When passing data or size with the options parameter, the data field will have precedence on the size field, which will be ignored.
// create a vertex buffer with a specified size var vbuff = new SpiderGL.WebGL.VertexBuffer(gl, { size : 2 * 1024 * 1024, // 2 MB usage : gl.STATIC_DRAW // if omitted, defaults to SpiderGL.WebGL.Buffer.DEFAULT_USAGE }); // create an index buffer with content var ibuff = new SpiderGL.WebGL.IndexBuffer(gl, { data : new Uint16Array(...) // use a typed array for setting buffer data });
- Parameters:
- {WebGLRenderingContext} gl
- A WebGLRenderingContext hijacked with SpiderGL.WebGL.Context.hijack.
- {number} target
- The WebGLBuffer target. It must be either WebGLRenderingContext.ARRAY_BUFFER or WebGLRenderingContext.ELEMENT_ARRAY_BUFFER.
- {object} options Optional
- Optional parameters.
- {WebGLBuffer} options.handle Optional
- If defined, the provided buffer will be wrapped and its size and usage attributes will be queried to the rendering context. Otherwise an internal buffer will be created.
- {ArrayBuffer|ArrayBufferView} options.data Optional
- Buffer content to be set with WebGLRenderingContext.bufferData (see setData). If present, the data will be set both if a handle is provided or internally created.
- {number} options.size Optional
- Buffer size to be set with WebGLRenderingContext.bufferData (see setData). If present, it will be set both if a handle is provided or internally created. If data parameter is present, the size field is ignored.
- {number} options.usage Optional, Default: SpiderGL.WebGL.Buffer.DEFAULT_USAGE
- WebGL buffer usage hint parameter for WebGLRenderingContext.bufferData.
Field Detail
<static>
{number}
SpiderGL.WebGL.Buffer.DEFAULT_SUB_DATA_OFFSET
Default buffer offset when specifying buffer subdata.
- Default Value:
- 0
<static>
{number}
SpiderGL.WebGL.Buffer.DEFAULT_USAGE
Default usage hint when specifying buffer size or data.
- Default Value:
- WebGLRenderingContext.STATIC_DRAW
<readonly>
{bool}
isReady
Tests if the buffer is ready to use.
A buffer is considered ready if its size is greater than zero.
<readonly>
{number}
size
The size in bytes of the buffer.
<static>
{number}
SpiderGL.WebGL.Buffer.TARGET
Default WebGLBuffer target.
- Default Value:
- WebGLRenderingContext.NONE
<readonly>
{number}
usage
The usage hint of the WebGLBuffer.
It refers to the usage hint as specified in WebGLRenderingContext.bufferData().
Method Detail
-
bind()Binds the wrapped WebGLBuffer to the appropriate target. The used target is set by the derived objects SpiderGL.WebGL.VertexBuffer and SpiderGL.WebGL.IndexBuffer.
- See:
- unbind
-
destroy()Destroys the WebGLBuffer. After destruction, the handle is set to null and this object should not be used anymore.
-
setData(data, usage)Sets the buffer data and usage. The buffer is set up with specified data and usage.
- Parameters:
- {ArrayBuffer|ArrayBufferView} data
- The buffer data.
- {number} usage Optional, Default: SpiderGL.WebGL.Buffer.DEFAULT_USAGE
- WebGL buffer usage hint.
- See:
- setSubData
- setSize
-
setSize(size, usage)Sets the buffer size and usage. The buffer is set up with specified size and usage.
- Parameters:
- {number} size
- The buffer size.
- {number} usage Optional, Default: SpiderGL.WebGL.Buffer.DEFAULT_USAGE
- WebGL buffer usage hint.
- See:
- setData
-
setSubData(data, offset)Sets a range of the buffer data. A range of buffer content can be set by specifying the starting offset and the typed array of values.
- Parameters:
- {ArrayBuffer|ArrayBufferView} data
- The buffer sub data.
- {number} offset Optional, Default: SpiderGL.WebGL.Buffer.DEFAULT_SUB_DATA_OFFSET
- The range starting offset, in bytes.
- See:
- setData
-
unbind()Binds "null" to the appropriate target. This method is provided only for simmetry with bind and is not relative to the object state.
- See:
- bind
-
<static> SpiderGL.WebGL.Buffer.unbind(gl)Generic WebGLBuffer unbinding. This function is empty and it is provided only for completeness.
- Parameters:
- {WebGLRenderingContext} gl
- A WebGLRenderingContext.