API / geotoolkit / webgl / WebGLRenderer / WebGLRenderer
webgl.WebGLRenderer.WebGLRenderer
A WebGl class that initialize HTML Canvas and WebGL context for 2D rendering.
For WebGL parameters, it follows the name convention as MDN.
↳
WebGLRenderer
Constructors
Methods
Constructors
• new WebGLRenderer(options?)
| Name | Type |
|---|---|
Optional options | Options |
EventDispatcher.constructor
Methods
▸ dispose(): void
Immediately free memory without having to wait for garbage collection.
void
▸ draw(): void
Calling render function triggers WebGLRenderer to draw on canvas.
RequestAnimationFrame(render) will render at each animation frame.
void
▸ getClassName(): string
string
▸ getContext(): WebGLRenderingContext
Return the current WebGL context
WebGLRenderingContext
context
▸ getDomElement(): HTMLCanvasElement
Return the canvas where the renderer draws its output.
HTMLCanvasElement
canvas
▸ getImageURL(): string
Return the canvas image as data URL
Equivalent to HTMLCanvasElement.toDataURL('image/png')
string
url
▸ getSize(): Dimension
Return the dimension of WebGL canvas
size
▸ hasEventListener(type, callback?): boolean
Check if a list of event listeners for this type contains this listener
| Name | Type | Description |
|---|---|---|
type | string | type of event or property |
Optional callback | Function | to be called, if null, check if any callback is registered |
boolean
EventDispatcher.hasEventListener
▸ isDisposed(): boolean
Returns whether this object has been disposed
boolean
▸ isSilent(): boolean
Return true if the event dispatcher doesn't notify any events
boolean
▸ notify(type, source, args?): WebGLRenderer
Notify listeners
| Name | Type | Description |
|---|---|---|
type | string | event types |
source | any | of the event |
Optional args | any | arguments of the event |
this
▸ off(type?, callback?): WebGLRenderer
Detach listener on event. Calling .off() with no arguments removes all attached listeners. Calling .off(type) with no callback removes all attached listeners for specific type.
| Name | Type | Description |
|---|---|---|
Optional type | string | type of the event |
Optional callback | EventListener | function to be called |
this
▸ off<E>(type, callback): WebGLRenderer
| Name | Type |
|---|---|
E | extends string |
| Name | Type |
|---|---|
type | E |
callback | (eventType: E, sender: WebGLRenderer, args: EventMap[E]) => void |
▸ on(type, callback, options?): WebGLRenderer
Attach listener on event that will be called whenever the specified event is delivered to the target
If the callback function is already in the list of event listeners for this target, the function is not added a second time.
If a particular anonymous function is in the list of event listeners registered for a certain target, and then later in the code, an identical anonymous function is given in an "on" call, the second function will also be added to the list of event listeners for that target.
| Name | Type | Description |
|---|---|---|
type | string | type of event or property |
callback | EventListener | to be called |
Optional options | Options | options of subscription |
this
▸ on<E>(type, callback, options?): WebGLRenderer
| Name | Type |
|---|---|
E | extends string |
| Name | Type |
|---|---|
type | E |
callback | (eventType: E, sender: WebGLRenderer, args: EventMap[E]) => void |
Optional options | Options |
▸ setAttribute(name, buffer): WebGLRenderer
Set attribute by sending information to GPU.
| Name | Type | Description |
|---|---|---|
name | string | attribute name |
buffer | BufferAttribute | buffer attribute |
this
▸ setColorProvider(colorprovider, accuracyRendering?): WebGLRenderer
A colorprovider converts a value to a color based on its configuration. It's generally created by associating some colors to WebGL Texture.
Then it will interpolate those colors on the fly to find the actual color corresponding to a coordinate in the texture.
To make it work as intended, the related glsl must define CG_USE_COLOR_MAP.
| Name | Type | Description |
|---|---|---|
colorprovider | ColorProvider | the colorprovider |
Optional accuracyRendering | boolean | true, if you need to render precise colorbox, it will be slower than general colorbox rendering |
this
▸ setShaders(vertexShader, fragmentShader): WebGLRenderer
Attach the provided vertexShader and fragmentShader to webGL program.
Also output any error found in shader compilation.
A WebGL program links to corresponding shaders.
Throws
failed to compile shaders
| Name | Type | Description |
|---|---|---|
vertexShader | string | vertex shader in glsl |
fragmentShader | string | fragment shader in glsl |
this
▸ setSilent(bool): WebGLRenderer
Set silent mode
| Name | Type | Description |
|---|---|---|
bool | boolean | flag to enable silent mode |
this
▸ setSize(width, height): WebGLRenderer
Resizes the output canvas to (width, height).
Also sets the viewport to fit that size.
| Name | Type | Description |
|---|---|---|
width | number | the width of canvas |
height | number | the height of canvas |
this
▸ setTexture(name, texture, unit?): WebGLRenderer
Set texture by sending information to GPU.
| Name | Type | Description |
|---|---|---|
name | string | the name of texture in glsl |
texture | Texture | the texture |
Optional unit | number | the texture unit that binds to |
this
▸ setUniform(name, type, v0, v1?, v2?, v3?): WebGLRenderer
Set uniform by sending information to GPU.
The WebGLRenderingContext.uniform[1234][uif][v]() methods of the WebGL API specify values of uniform variables.
[ui] stands for unsigned integer, [i] for integer, [f] for float, and [v] for array.
Not all combinations are valid: [u] cannot be combined with [f].
For example, the type of uniform2f is string '2f'.
https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/uniform
| Name | Type | Description |
|---|---|---|
name | string | the name of uniform |
type | string | the type of uniform |
v0 | number | number[] | the first value |
Optional v1 | number | number[] | the second value (if any) |
Optional v2 | number | number[] | the third value (if any) |
Optional v3 | number | number[] | the fourth value (if any) |
this
▸ Static getClassName(): string
string