Last updated

API / geotoolkit / webgl / WebGLRenderer / WebGLRenderer

Class: 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.

Hierarchy

Table of contents

Constructors
Methods

Contents

Constructors

new WebGLRenderer(options)

new WebGLRenderer(options?)

Parameters

Name Type
Optional optionsOptions

Overrides

EventDispatcher.constructor

Methods

dispose

dispose(): void

Immediately free memory without having to wait for garbage collection.

Returns

void

Overrides

EventDispatcher.dispose


draw

draw(): void

Calling render function triggers WebGLRenderer to draw on canvas.
RequestAnimationFrame(render) will render at each animation frame.

Returns

void


getClassName

getClassName(): string

Returns

string

Inherited from

EventDispatcher.getClassName


getContext

getContext(): WebGLRenderingContext

Return the current WebGL context

Returns

WebGLRenderingContext

context


getDomElement

getDomElement(): HTMLCanvasElement

Return the canvas where the renderer draws its output.

Returns

HTMLCanvasElement

canvas


getImageURL

getImageURL(): string

Return the canvas image as data URL
Equivalent to HTMLCanvasElement.toDataURL('image/png')

Returns

string

url


getSize

getSize(): Dimension

Return the dimension of WebGL canvas

Returns

Dimension

size


hasEventListener

hasEventListener(type, callback?): boolean

Check if a list of event listeners for this type contains this listener

Parameters

Name Type Description
typestringtype of event or property
Optional callbackFunctionto be called, if null, check if any callback is registered

Returns

boolean

Inherited from

EventDispatcher.hasEventListener


isDisposed

isDisposed(): boolean

Returns whether this object has been disposed

Returns

boolean

Inherited from

EventDispatcher.isDisposed


isSilent

isSilent(): boolean

Return true if the event dispatcher doesn't notify any events

Returns

boolean

Inherited from

EventDispatcher.isSilent


notify

notify(type, source, args?): WebGLRenderer

Notify listeners

Parameters

Name Type Description
typestringevent types
sourceanyof the event
Optional argsanyarguments of the event

Returns

WebGLRenderer

this

Inherited from

EventDispatcher.notify


off

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.

Parameters

Name Type Description
Optional typestringtype of the event
Optional callbackEventListenerfunction to be called

Returns

WebGLRenderer

this

Inherited from

EventDispatcher.off

off<E>(type, callback): WebGLRenderer

Type parameters

NameType
Eextends string

Parameters

Name Type
typeE
callback(eventType: E, sender: WebGLRenderer, args: EventMap[E]) => void

Returns

WebGLRenderer

Inherited from

EventDispatcher.off


on

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.

Parameters

Name Type Description
typestringtype of event or property
callbackEventListenerto be called
Optional optionsOptionsoptions of subscription

Returns

WebGLRenderer

this

Inherited from

EventDispatcher.on

on<E>(type, callback, options?): WebGLRenderer

Type parameters

NameType
Eextends string

Parameters

Name Type
typeE
callback(eventType: E, sender: WebGLRenderer, args: EventMap[E]) => void
Optional optionsOptions

Returns

WebGLRenderer

Inherited from

EventDispatcher.on


setAttribute

setAttribute(name, buffer): WebGLRenderer

Set attribute by sending information to GPU.

Parameters

Name Type Description
namestringattribute name
bufferBufferAttributebuffer attribute

Returns

WebGLRenderer

this


setColorProvider

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.

Parameters

Name Type Description
colorproviderColorProviderthe colorprovider
Optional accuracyRenderingbooleantrue, if you need to render precise colorbox, it will be slower than general colorbox rendering

Returns

WebGLRenderer

this


setShaders

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

Parameters

Name Type Description
vertexShaderstringvertex shader in glsl
fragmentShaderstringfragment shader in glsl

Returns

WebGLRenderer

this


setSilent

setSilent(bool): WebGLRenderer

Set silent mode

Parameters

Name Type Description
boolbooleanflag to enable silent mode

Returns

WebGLRenderer

this

Inherited from

EventDispatcher.setSilent


setSize

setSize(width, height): WebGLRenderer

Resizes the output canvas to (width, height).
Also sets the viewport to fit that size.

Parameters

Name Type Description
widthnumberthe width of canvas
heightnumberthe height of canvas

Returns

WebGLRenderer

this


setTexture

setTexture(name, texture, unit?): WebGLRenderer

Set texture by sending information to GPU.

Parameters

Name Type Description
namestringthe name of texture in glsl
textureTexturethe texture
Optional unitnumberthe texture unit that binds to

Returns

WebGLRenderer

this


setUniform

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

Parameters

Name Type Description
namestringthe name of uniform
typestringthe type of uniform
v0number | number[]the first value
Optional v1number | number[]the second value (if any)
Optional v2number | number[]the third value (if any)
Optional v3number | number[]the fourth value (if any)

Returns

WebGLRenderer

this


getClassName

Static getClassName(): string

Returns

string

Inherited from

EventDispatcher.getClassName