Class SpiderGL.WebGL.ObjectGL
The SpiderGL.WebGL.ObjectGL is the base class for all WebGL object wrappers.
- Defined in: webgl.js
- Extends SpiderGL.Core.ObjectBase
Constructor Attributes | Constructor Name and Description |
---|---|
SpiderGL.WebGL.ObjectGL(gl, target, options)
Creates a SpiderGL.WebGL.ObjectGL.
|
Field Attributes | Field Name and Description |
---|---|
<readonly> |
The WebGLRenderingContext used at costruction.
|
<readonly> |
The native WebObjectGL.
|
<readonly> |
Tests if the object is ready to use.
|
<readonly> |
Tests for non-null handle.
|
<readonly> |
The WebObjectGL default target.
|
<static> |
SpiderGL.WebGL.ObjectGL.TARGET
Default WebObjectGL target.
|
- Fields borrowed from class SpiderGL.Core.ObjectBase:
- uid
Method Summary
Method Attributes | Method Name and Description |
---|---|
bind()
Binds the object to the rendering pipeline.
|
|
destroy()
Destroys the wrapped WebObjectGL.
|
|
unbind()
Binds the null object to the rendering pipeline.
|
|
<static> |
SpiderGL.WebGL.ObjectGL.unbind(gl)
Generic null WebObjectGL binding.
|
Class Detail
SpiderGL.WebGL.ObjectGL(gl, target, options)
Creates a SpiderGL.WebGL.ObjectGL.
SpiderGL.WebGL.ObjectGL is the base class for every WebObjectGL wrapper and must not be directly used.
In general, every SpiderGL.WebGL.ObjectGL-derived constructor takes two arguments: a hijacked WebGLRenderingContext ("gl")
and an optional object argument ("options") that is used to wrap an existing native WebObjectGL and to set object-specific parameters or data.
If the options parameter has a propery named "handle" referencing a WebObjectGL, the constructed SpiderGL.WebGL.ObjectGL will use the provided WebObjectGL as the underlying resource.
Otherwise, a new WebObjectGL is created. In both cases, the internal WebObjectGL can be accessed with the handle read-only property and directly used in WebGLRenderingContext calls.
With a notification mechanism built into the hijacked WebGLRenderingContext, every direct access is communicated to the wrapper to keep up-to-date the internal state of the wrapper.
// create a native vertex WebGLBuffer var vbo = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, vbo); // ... use buffer ... // create a SpiderGL wrapper from an existing object; // the native object can be accessed through the "handle" property. var wrappedVBO = new SpiderGL.WebGL.VertexBuffer(gl, {handle: vbo}); // it is not mandatory to bind the object before setting parameters or data as the hijacked WebGLRendering context takes care of it and does not break previous bindings wrappedVBO.setSize(sizeInBytes, gl.STATIC_DRAW); wrappedVBO.bind(); // equivalent to gl.bindBuffer(gl.ARRAY_BUFFER, wrappedVBO.handle) // create another SpiderGL.WebGL.VertexBuffer without specifying an existing object, // thus letting the wrapper to create one var anotherVBO = new SpiderGL.WebGL.VertexBuffer(gl, {size: someSizeInBytes});
- Parameters:
- {WebGLRenderingContext} gl
- A WebGLRenderingContext hijacked with SpiderGL.WebGL.Context.hijack.
- {number} target
- The WebObjectGL default target.
- {object} options Optional
- Object-specific parameters.
Field Detail
<readonly>
{WebGLRenderingContext}
gl
The WebGLRenderingContext used at costruction.
- See:
- #handle
<readonly>
{WebObjectGL}
handle
The native WebObjectGL.
The native handle can be used with WebGLRenderingContext methods.
- See:
- #gl
<readonly>
{bool}
isReady
Tests if the object is ready to use.
It is reimplemented on each derived classes with object-specific semantic.
<readonly>
{bool}
isValid
Tests for non-null handle.
<readonly>
{number}
target
The WebObjectGL default target.
<static>
{number}
SpiderGL.WebGL.ObjectGL.TARGET
Default WebObjectGL target.
- Default Value:
- WebGLRenderingContext.NONE
Method Detail
-
bind()Binds the object to the rendering pipeline. The wrapped WebObjectGL is bound to its default target in the WebGLRenderingContext.
-
destroy()Destroys the wrapped WebObjectGL. After calling this method, the object must not be accessed anymore.
-
unbind()Binds the null object to the rendering pipeline. This method is provided for symmetry with SpiderGL.WebGL.ObjectGL#bind. It binds the null object to the per-object webGL target.
-
<static> SpiderGL.WebGL.ObjectGL.unbind(gl)Generic null WebObjectGL binding. This function is empty and provided only for completeness.
- Parameters:
- {WebGLRenderingContext} gl
- A WebGLRenderingContext.