import {WebGLUtils} from 'gisplay-es6-webpack/src/Gisplay/Helpers/WebglUtils.js'
WebGLUtils
Class with static methods that will help with WebGL related stuff(Matrices, web mercator projection and shaders). Always remeber WebGL is column major when reading the matrix code.
Static Method Summary
Static Public Methods | ||
public static |
createAndCompileShader(type: string, source_code: string, webgl: _webgl): WebGLShader Creates and compiles a shader. |
|
public static |
createWebGLProgram(webgl: {gl: WebGLRenderingContext, program: WebGLProgram}): void Initializes: 1)WebGLProgram, 2) Generates shadders, 3) Attaches shaders to the program, 4) links program, 5) uses program. |
|
public static |
finalMatrix(scale: number, width: number, height: number, offsetX: number, offsetY: number): Float32Array This is the result matrix from the multiplication of M1M2M3 |
|
public static |
generateShadersSourceCode(): {vertexCode: string, fragmentCode: string} Creates shaders(Vertex + Fragment) source code. |
|
public static |
webMercatorProjection(longitudeCenter: number, latitudeCenter: number, zoom: number, tileSize: number, width: number, height: number): {scale: number, offsetX: number, offsetY: number} Calculates the scale and offset(X and Y) for the Web Mercator projection. |
Static Public Methods
public static createAndCompileShader(type: string, source_code: string, webgl: _webgl): WebGLShader source
Creates and compiles a shader.
Return:
WebGLShader | The shader(vertex of fragment). |
public static createWebGLProgram(webgl: {gl: WebGLRenderingContext, program: WebGLProgram}): void source
Initializes: 1)WebGLProgram, 2) Generates shadders, 3) Attaches shaders to the program, 4) links program, 5) uses program.
Params:
Name | Type | Attribute | Description |
webgl | {gl: WebGLRenderingContext, program: WebGLProgram} |
Return:
void |
public static finalMatrix(scale: number, width: number, height: number, offsetX: number, offsetY: number): Float32Array source
This is the result matrix from the multiplication of M1M2M3
Params:
Name | Type | Attribute | Description |
scale | number | The scale calculated with WebMercator projection. |
|
width | number | The width of the canvas. |
|
height | number | The height of the canvas. |
|
offsetX | number | The offsetX calculated with WebMercator projection. |
|
offsetY | number | The offsetY calculated with WebMercator projection. |
Return:
Float32Array | The resulting matrix (M1M2M3) in a single matrix to send to WebGL in order to calculate the resulting position. |
See:
public static generateShadersSourceCode(): {vertexCode: string, fragmentCode: string} source
Creates shaders(Vertex + Fragment) source code.
public static webMercatorProjection(longitudeCenter: number, latitudeCenter: number, zoom: number, tileSize: number, width: number, height: number): {scale: number, offsetX: number, offsetY: number} source
Calculates the scale and offset(X and Y) for the Web Mercator projection.
Params:
Name | Type | Attribute | Description |
longitudeCenter | number | Longitude of the given position. |
|
latitudeCenter | number | Latitude of the given position. |
|
zoom | number | Current zoom level of the background map. |
|
tileSize | number | The size of each tile in the background map. Usually is 256. If different should be given in the API options. |
|
width | number | Width of the current canvas. |
|
height | number | Height of the current canvas. |