Interface: WebGLImplementation

WebGLModule.WebGLImplementation

Methods

generateVisualization(order, visualization, withHtml) → {object}

Create a visualization from the given JSON params
Parameters:
Name Type Description
order Array.<string> keys of visualization.shader in which order to build the visualization the order: painter's algorithm: the last drawn is the most visible
visualization object
withHtml boolean whether html should be also created (false if no UI controls are desired)
Source:
Returns:
{string} object.vertex_shader vertex shader code {string} object.fragment_shader fragment shader code {string} object.html html for the UI {number} object.usableShaders how many layers are going to be visualized {(array|string[])} object.dataUrls ID's of data in use (keys of visualization.shaders object) in desired order the data is guaranteed to arrive in this order (images stacked below each other in imageElement)
Type
object

getTextureDimensionXY(order) → {string}

Get GLSL texture XY dimension
Parameters:
Name Type Description
order string order number in the shader, available in vis.shaders[id].index
Source:
Returns:
vec2
Type
string

getTextureSamplingCode(order, textureCoords) → {string}

Get GLSL texture sampling code
Parameters:
Name Type Description
order string order number in the shader, available in vis.shaders[id].index
textureCoords string string representing GLSL code of valid texture coordinates e.g. 'tex_coords' or 'vec2(1.0, 0.0)'
Source:
Returns:
GLSL code that is correct in texture sampling wrt. WebGL version used
Type
string

getVersion() → {string}

Source:
Returns:
WebGL version used
Type
string

globalCodeRequiredByShaderType(type) → {object}

Code to be included only once, required by given shader type (keys are considered global)
Parameters:
Name Type Description
type string shader type
Source:
Returns:
global-scope code used by the shader in format
Type
object

setBlendEquation(glslCode)

Blend equation sent from the outside, must be respected
Parameters:
Name Type Description
glslCode code for blending, using two variables: 'foreground', 'background'
Source:
Example
//The shader context must define the following:

vec4 some_blending_name_etc(in vec4 background, in vec4 foreground) {
    // << glslCode >>
}

void blend_clip(vec4 input) {
    //for details on clipping mask approach see show() below
    // <>
}

void blend(vec4 input) { //must be called blend, API
    // <>
}

//Also, default alpha blending equation 'show' must be implemented:
void show(vec4 color) {
   //pseudocode
   //note that the blending output should not immediatelly work with 'color' but perform caching of the color,
   //render the color given in previous call and at the execution end of main call show(vec4(.0))
   //this way, the previous color is not yet blended for the next layer show/blend/blend_clip which can use it to create a clipping mask

   compute t = color.a + background.a - color.a*background.a;
   output vec4((color.rgb * color.a + background.rgb * background.a - background.rgb * (background.a * color.a)) / t, t)
}

toBuffers(program, currentVisualization)

Called once program is switched to: initialize all necessary items
Parameters:
Name Type Description
program WebGLProgram used program
currentVisualization Visualization JSON parameters used for this visualization
Source:

toCanvas(program, currentVisualization, imageElement, tileDimension, zoomLevel, pixelSize)

Draw on the canvas using given program
Parameters:
Name Type Description
program WebGLProgram used program
currentVisualization WebGLModule.VisualizationConfig JSON parameters used for this visualization
imageElement object image data
tileDimension object
Properties
Name Type Description
width number width of the result
height number height of the result
zoomLevel number arbitrary number 1 (this is not very clean design, pass object load properties of?) used to pass OSD zoom level value
pixelSize number arbitrary number 2 (this is not very clean design, pass object load properties of?) used to pass ratio of how many screen pixels a fragment spans on
Source: