This commit is contained in:
94
node_modules/ol/webgl/Buffer.d.ts
generated
vendored
Normal file
94
node_modules/ol/webgl/Buffer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* Returns a typed array constructor based on the given buffer type
|
||||
* @param {number} type Buffer type, either ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER.
|
||||
* @return {Float32ArrayConstructor|Uint32ArrayConstructor} The typed array class to use for this buffer.
|
||||
*/
|
||||
export function getArrayClassForType(type: number): Float32ArrayConstructor | Uint32ArrayConstructor;
|
||||
/**
|
||||
* Used to describe the intended usage for the data: `STATIC_DRAW`, `STREAM_DRAW`
|
||||
* or `DYNAMIC_DRAW`.
|
||||
*/
|
||||
export type BufferUsage = number;
|
||||
export namespace BufferUsage {
|
||||
export { STATIC_DRAW };
|
||||
export { STREAM_DRAW };
|
||||
export { DYNAMIC_DRAW };
|
||||
}
|
||||
export default WebGLArrayBuffer;
|
||||
import { STATIC_DRAW } from "../webgl.js";
|
||||
import { STREAM_DRAW } from "../webgl.js";
|
||||
import { DYNAMIC_DRAW } from "../webgl.js";
|
||||
/**
|
||||
* @classdesc
|
||||
* Object used to store an array of data as well as usage information for that data.
|
||||
* Stores typed arrays internally, either Float32Array or Uint16/32Array depending on
|
||||
* the buffer type (ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER) and available extensions.
|
||||
*
|
||||
* To populate the array, you can either use:
|
||||
* * A size using `#ofSize(buffer)`
|
||||
* * An `ArrayBuffer` object using `#fromArrayBuffer(buffer)`
|
||||
* * A plain array using `#fromArray(array)`
|
||||
*
|
||||
* Note:
|
||||
* See the documentation of [WebGLRenderingContext.bufferData](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData)
|
||||
* for more info on buffer usage.
|
||||
* @api
|
||||
*/
|
||||
declare class WebGLArrayBuffer {
|
||||
/**
|
||||
* @param {number} type Buffer type, either ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER.
|
||||
* @param {number} [opt_usage] Intended usage, either `STATIC_DRAW`, `STREAM_DRAW` or `DYNAMIC_DRAW`.
|
||||
* Default is `DYNAMIC_DRAW`.
|
||||
*/
|
||||
constructor(type: number, opt_usage?: number | undefined);
|
||||
/**
|
||||
* @private
|
||||
* @type {Float32Array|Uint32Array}
|
||||
*/
|
||||
private array;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
private type;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
private usage;
|
||||
/**
|
||||
* Populates the buffer with an array of the given size (all values will be zeroes).
|
||||
* @param {number} size Array size
|
||||
*/
|
||||
ofSize(size: number): void;
|
||||
/**
|
||||
* Populates the buffer with an array of the given size (all values will be zeroes).
|
||||
* @param {Array<number>} array Numerical array
|
||||
*/
|
||||
fromArray(array: Array<number>): void;
|
||||
/**
|
||||
* Populates the buffer with a raw binary array buffer.
|
||||
* @param {ArrayBuffer} buffer Raw binary buffer to populate the array with. Note that this buffer must have been
|
||||
* initialized for the same typed array class.
|
||||
*/
|
||||
fromArrayBuffer(buffer: ArrayBuffer): void;
|
||||
/**
|
||||
* @return {number} Buffer type.
|
||||
*/
|
||||
getType(): number;
|
||||
/**
|
||||
* Will return null if the buffer was not initialized
|
||||
* @return {Float32Array|Uint32Array} Array.
|
||||
*/
|
||||
getArray(): Float32Array | Uint32Array;
|
||||
/**
|
||||
* @return {number} Usage.
|
||||
*/
|
||||
getUsage(): number;
|
||||
/**
|
||||
* Will return 0 if the buffer is not initialized
|
||||
* @return {number} Array size
|
||||
*/
|
||||
getSize(): number;
|
||||
}
|
||||
//# sourceMappingURL=Buffer.d.ts.map
|
||||
1
node_modules/ol/webgl/Buffer.d.ts.map
generated
vendored
Normal file
1
node_modules/ol/webgl/Buffer.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Buffer.d.ts","sourceRoot":"","sources":["../src/webgl/Buffer.js"],"names":[],"mappings":"AA8HA;;;;GAIG;AACH,2CAHW,MAAM,GACL,uBAAuB,GAAC,sBAAsB,CAWzD;;;;;0BA7HS,MAAM;;;;;;;;;;AAQhB;;;;;;;;;;;;;;;GAeG;AACH;IACE;;;;OAIG;IACH,kBAJW,MAAM,kCAwBhB;IAnBC;;;OAGG;IACH,cAAiB;IAEjB;;;OAGG;IACH,aAAgB;IAIhB;;;OAGG;IACH,cAA0E;IAG5E;;;OAGG;IACH,aAFW,MAAM,QAIhB;IAED;;;OAGG;IACH,iBAFW,MAAM,MAAM,CAAC,QAOvB;IAED;;;;OAIG;IACH,wBAHW,WAAW,QAKrB;IAED;;OAEG;IACH,WAFY,MAAM,CAIjB;IAED;;;OAGG;IACH,YAFY,YAAY,GAAC,WAAW,CAInC;IAED;;OAEG;IACH,YAFY,MAAM,CAIjB;IAED;;;OAGG;IACH,WAFY,MAAM,CAIjB;CACF"}
|
||||
125
node_modules/ol/webgl/Buffer.js
generated
vendored
Normal file
125
node_modules/ol/webgl/Buffer.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* @module ol/webgl/Buffer
|
||||
*/
|
||||
import { ARRAY_BUFFER, DYNAMIC_DRAW, ELEMENT_ARRAY_BUFFER, STATIC_DRAW, STREAM_DRAW, } from '../webgl.js';
|
||||
import { assert } from '../asserts.js';
|
||||
/**
|
||||
* Used to describe the intended usage for the data: `STATIC_DRAW`, `STREAM_DRAW`
|
||||
* or `DYNAMIC_DRAW`.
|
||||
* @enum {number}
|
||||
*/
|
||||
export var BufferUsage = {
|
||||
STATIC_DRAW: STATIC_DRAW,
|
||||
STREAM_DRAW: STREAM_DRAW,
|
||||
DYNAMIC_DRAW: DYNAMIC_DRAW,
|
||||
};
|
||||
/**
|
||||
* @classdesc
|
||||
* Object used to store an array of data as well as usage information for that data.
|
||||
* Stores typed arrays internally, either Float32Array or Uint16/32Array depending on
|
||||
* the buffer type (ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER) and available extensions.
|
||||
*
|
||||
* To populate the array, you can either use:
|
||||
* * A size using `#ofSize(buffer)`
|
||||
* * An `ArrayBuffer` object using `#fromArrayBuffer(buffer)`
|
||||
* * A plain array using `#fromArray(array)`
|
||||
*
|
||||
* Note:
|
||||
* See the documentation of [WebGLRenderingContext.bufferData](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData)
|
||||
* for more info on buffer usage.
|
||||
* @api
|
||||
*/
|
||||
var WebGLArrayBuffer = /** @class */ (function () {
|
||||
/**
|
||||
* @param {number} type Buffer type, either ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER.
|
||||
* @param {number} [opt_usage] Intended usage, either `STATIC_DRAW`, `STREAM_DRAW` or `DYNAMIC_DRAW`.
|
||||
* Default is `DYNAMIC_DRAW`.
|
||||
*/
|
||||
function WebGLArrayBuffer(type, opt_usage) {
|
||||
/**
|
||||
* @private
|
||||
* @type {Float32Array|Uint32Array}
|
||||
*/
|
||||
this.array = null;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.type = type;
|
||||
assert(type === ARRAY_BUFFER || type === ELEMENT_ARRAY_BUFFER, 62);
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.usage = opt_usage !== undefined ? opt_usage : BufferUsage.STATIC_DRAW;
|
||||
}
|
||||
/**
|
||||
* Populates the buffer with an array of the given size (all values will be zeroes).
|
||||
* @param {number} size Array size
|
||||
*/
|
||||
WebGLArrayBuffer.prototype.ofSize = function (size) {
|
||||
this.array = new (getArrayClassForType(this.type))(size);
|
||||
};
|
||||
/**
|
||||
* Populates the buffer with an array of the given size (all values will be zeroes).
|
||||
* @param {Array<number>} array Numerical array
|
||||
*/
|
||||
WebGLArrayBuffer.prototype.fromArray = function (array) {
|
||||
var arrayClass = getArrayClassForType(this.type);
|
||||
this.array = arrayClass.from
|
||||
? arrayClass.from(array)
|
||||
: new arrayClass(array);
|
||||
};
|
||||
/**
|
||||
* Populates the buffer with a raw binary array buffer.
|
||||
* @param {ArrayBuffer} buffer Raw binary buffer to populate the array with. Note that this buffer must have been
|
||||
* initialized for the same typed array class.
|
||||
*/
|
||||
WebGLArrayBuffer.prototype.fromArrayBuffer = function (buffer) {
|
||||
this.array = new (getArrayClassForType(this.type))(buffer);
|
||||
};
|
||||
/**
|
||||
* @return {number} Buffer type.
|
||||
*/
|
||||
WebGLArrayBuffer.prototype.getType = function () {
|
||||
return this.type;
|
||||
};
|
||||
/**
|
||||
* Will return null if the buffer was not initialized
|
||||
* @return {Float32Array|Uint32Array} Array.
|
||||
*/
|
||||
WebGLArrayBuffer.prototype.getArray = function () {
|
||||
return this.array;
|
||||
};
|
||||
/**
|
||||
* @return {number} Usage.
|
||||
*/
|
||||
WebGLArrayBuffer.prototype.getUsage = function () {
|
||||
return this.usage;
|
||||
};
|
||||
/**
|
||||
* Will return 0 if the buffer is not initialized
|
||||
* @return {number} Array size
|
||||
*/
|
||||
WebGLArrayBuffer.prototype.getSize = function () {
|
||||
return this.array ? this.array.length : 0;
|
||||
};
|
||||
return WebGLArrayBuffer;
|
||||
}());
|
||||
/**
|
||||
* Returns a typed array constructor based on the given buffer type
|
||||
* @param {number} type Buffer type, either ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER.
|
||||
* @return {Float32ArrayConstructor|Uint32ArrayConstructor} The typed array class to use for this buffer.
|
||||
*/
|
||||
export function getArrayClassForType(type) {
|
||||
switch (type) {
|
||||
case ARRAY_BUFFER:
|
||||
return Float32Array;
|
||||
case ELEMENT_ARRAY_BUFFER:
|
||||
return Uint32Array;
|
||||
default:
|
||||
return Float32Array;
|
||||
}
|
||||
}
|
||||
export default WebGLArrayBuffer;
|
||||
//# sourceMappingURL=Buffer.js.map
|
||||
1
node_modules/ol/webgl/Buffer.js.map
generated
vendored
Normal file
1
node_modules/ol/webgl/Buffer.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Buffer.js","sourceRoot":"","sources":["../src/webgl/Buffer.js"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,oBAAoB,EACpB,WAAW,EACX,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAErC;;;;GAIG;AACH,MAAM,CAAC,IAAM,WAAW,GAAG;IACzB,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,WAAW;IACxB,YAAY,EAAE,YAAY;CAC3B,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH;IACE;;;;OAIG;IACH,0BAAY,IAAI,EAAE,SAAS;QACzB;;;WAGG;QACH,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAElB;;;WAGG;QACH,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAEjB,MAAM,CAAC,IAAI,KAAK,YAAY,IAAI,IAAI,KAAK,oBAAoB,EAAE,EAAE,CAAC,CAAC;QAEnE;;;WAGG;QACH,IAAI,CAAC,KAAK,GAAG,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC;IAC7E,CAAC;IAED;;;OAGG;IACH,iCAAM,GAAN,UAAO,IAAI;QACT,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;IAED;;;OAGG;IACH,oCAAS,GAAT,UAAU,KAAK;QACb,IAAM,UAAU,GAAG,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,IAAI;YAC1B,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;YACxB,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,0CAAe,GAAf,UAAgB,MAAM;QACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,kCAAO,GAAP;QACE,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,mCAAQ,GAAR;QACE,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,mCAAQ,GAAR;QACE,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,kCAAO,GAAP;QACE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC;IACH,uBAAC;AAAD,CAAC,AArFD,IAqFC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAI;IACvC,QAAQ,IAAI,EAAE;QACZ,KAAK,YAAY;YACf,OAAO,YAAY,CAAC;QACtB,KAAK,oBAAoB;YACvB,OAAO,WAAW,CAAC;QACrB;YACE,OAAO,YAAY,CAAC;KACvB;AACH,CAAC;AAED,eAAe,gBAAgB,CAAC"}
|
||||
6
node_modules/ol/webgl/ContextEventType.d.ts
generated
vendored
Normal file
6
node_modules/ol/webgl/ContextEventType.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
declare namespace _default {
|
||||
const LOST: string;
|
||||
const RESTORED: string;
|
||||
}
|
||||
export default _default;
|
||||
//# sourceMappingURL=ContextEventType.d.ts.map
|
||||
1
node_modules/ol/webgl/ContextEventType.d.ts.map
generated
vendored
Normal file
1
node_modules/ol/webgl/ContextEventType.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ContextEventType.d.ts","sourceRoot":"","sources":["../src/webgl/ContextEventType.js"],"names":[],"mappings":""}
|
||||
11
node_modules/ol/webgl/ContextEventType.js
generated
vendored
Normal file
11
node_modules/ol/webgl/ContextEventType.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* @module ol/webgl/ContextEventType
|
||||
*/
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
export default {
|
||||
LOST: 'webglcontextlost',
|
||||
RESTORED: 'webglcontextrestored',
|
||||
};
|
||||
//# sourceMappingURL=ContextEventType.js.map
|
||||
1
node_modules/ol/webgl/ContextEventType.js.map
generated
vendored
Normal file
1
node_modules/ol/webgl/ContextEventType.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ContextEventType.js","sourceRoot":"","sources":["../src/webgl/ContextEventType.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,eAAe;IACb,IAAI,EAAE,kBAAkB;IACxB,QAAQ,EAAE,sBAAsB;CACjC,CAAC"}
|
||||
557
node_modules/ol/webgl/Helper.d.ts
generated
vendored
Normal file
557
node_modules/ol/webgl/Helper.d.ts
generated
vendored
Normal file
@@ -0,0 +1,557 @@
|
||||
/**
|
||||
* Compute a stride in bytes based on a list of attributes
|
||||
* @param {Array<AttributeDescription>} attributes Ordered list of attributes
|
||||
* @return {number} Stride, ie amount of values for each vertex in the vertex buffer
|
||||
* @api
|
||||
*/
|
||||
export function computeAttributesStride(attributes: Array<AttributeDescription>): number;
|
||||
/**
|
||||
* Shader types, either `FRAGMENT_SHADER` or `VERTEX_SHADER`.
|
||||
*/
|
||||
export type ShaderType = number;
|
||||
export namespace ShaderType {
|
||||
const FRAGMENT_SHADER: number;
|
||||
const VERTEX_SHADER: number;
|
||||
}
|
||||
/**
|
||||
* Uniform names used in the default shaders: `PROJECTION_MATRIX`, `OFFSET_SCALE_MATRIX`.
|
||||
* and `OFFSET_ROTATION_MATRIX`.
|
||||
*/
|
||||
export type DefaultUniform = string;
|
||||
export namespace DefaultUniform {
|
||||
const PROJECTION_MATRIX: string;
|
||||
const OFFSET_SCALE_MATRIX: string;
|
||||
const OFFSET_ROTATION_MATRIX: string;
|
||||
const TIME: string;
|
||||
const ZOOM: string;
|
||||
const RESOLUTION: string;
|
||||
}
|
||||
/**
|
||||
* Attribute types, either `UNSIGNED_BYTE`, `UNSIGNED_SHORT`, `UNSIGNED_INT` or `FLOAT`
|
||||
* Note: an attribute stored in a `Float32Array` should be of type `FLOAT`.
|
||||
*/
|
||||
export type AttributeType = number;
|
||||
export namespace AttributeType {
|
||||
export { UNSIGNED_BYTE };
|
||||
export { UNSIGNED_SHORT };
|
||||
export { UNSIGNED_INT };
|
||||
export { FLOAT };
|
||||
}
|
||||
export default WebGLHelper;
|
||||
export type BufferCacheEntry = {
|
||||
/**
|
||||
* Buffer.
|
||||
*/
|
||||
buffer: import("./Buffer.js").default;
|
||||
/**
|
||||
* WebGlBuffer.
|
||||
*/
|
||||
webGlBuffer: WebGLBuffer;
|
||||
};
|
||||
/**
|
||||
* Description of an attribute in a buffer
|
||||
*/
|
||||
export type AttributeDescription = {
|
||||
/**
|
||||
* Attribute name to use in shaders
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Number of components per attributes
|
||||
*/
|
||||
size: number;
|
||||
/**
|
||||
* Attribute type, i.e. number of bytes used to store the value. This is
|
||||
* determined by the class of typed array which the buffer uses (eg. `Float32Array` for a `FLOAT` attribute).
|
||||
* Default is `FLOAT`.
|
||||
*/
|
||||
type?: number | undefined;
|
||||
};
|
||||
export type UniformLiteralValue = number | Array<number> | HTMLCanvasElement | HTMLImageElement | ImageData | import("../transform").Transform;
|
||||
/**
|
||||
* Uniform value can be a number, array of numbers (2 to 4), canvas element or a callback returning
|
||||
* one of the previous types.
|
||||
*/
|
||||
export type UniformValue = UniformLiteralValue | ((arg0: import("../PluggableMap.js").FrameState) => UniformLiteralValue);
|
||||
export type PostProcessesOptions = {
|
||||
/**
|
||||
* Scale ratio; if < 1, the post process will render to a texture smaller than
|
||||
* the main canvas which will then be sampled up (useful for saving resource on blur steps).
|
||||
*/
|
||||
scaleRatio?: number | undefined;
|
||||
/**
|
||||
* Vertex shader source
|
||||
*/
|
||||
vertexShader?: string | undefined;
|
||||
/**
|
||||
* Fragment shader source
|
||||
*/
|
||||
fragmentShader?: string | undefined;
|
||||
/**
|
||||
* Uniform definitions for the post process step
|
||||
*/
|
||||
uniforms?: {
|
||||
[x: string]: UniformValue;
|
||||
} | undefined;
|
||||
};
|
||||
export type Options = {
|
||||
/**
|
||||
* Uniform definitions; property names must match the uniform
|
||||
* names in the provided or default shaders.
|
||||
*/
|
||||
uniforms?: {
|
||||
[x: string]: UniformValue;
|
||||
} | undefined;
|
||||
/**
|
||||
* Post-processes definitions
|
||||
*/
|
||||
postProcesses?: PostProcessesOptions[] | undefined;
|
||||
/**
|
||||
* The cache key for the canvas.
|
||||
*/
|
||||
canvasCacheKey?: string | undefined;
|
||||
};
|
||||
export type UniformInternalDescription = {
|
||||
/**
|
||||
* Name
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Value
|
||||
*/
|
||||
value?: UniformValue | undefined;
|
||||
/**
|
||||
* Texture
|
||||
*/
|
||||
texture?: WebGLTexture | undefined;
|
||||
};
|
||||
export type CanvasCacheItem = {
|
||||
/**
|
||||
* Canvas element.
|
||||
*/
|
||||
canvas: HTMLCanvasElement;
|
||||
/**
|
||||
* The count of users of this canvas.
|
||||
*/
|
||||
users: number;
|
||||
};
|
||||
import { UNSIGNED_BYTE } from "../webgl.js";
|
||||
import { UNSIGNED_SHORT } from "../webgl.js";
|
||||
import { UNSIGNED_INT } from "../webgl.js";
|
||||
import { FLOAT } from "../webgl.js";
|
||||
/**
|
||||
* @classdesc
|
||||
* This class is intended to provide low-level functions related to WebGL rendering, so that accessing
|
||||
* directly the WebGL API should not be required anymore.
|
||||
*
|
||||
* Several operations are handled by the `WebGLHelper` class:
|
||||
*
|
||||
* ### Define custom shaders and uniforms
|
||||
*
|
||||
* *Shaders* are low-level programs executed on the GPU and written in GLSL. There are two types of shaders:
|
||||
*
|
||||
* Vertex shaders are used to manipulate the position and attribute of *vertices* of rendered primitives (ie. corners of a square).
|
||||
* Outputs are:
|
||||
*
|
||||
* * `gl_Position`: position of the vertex in screen space
|
||||
*
|
||||
* * Varyings usually prefixed with `v_` are passed on to the fragment shader
|
||||
*
|
||||
* Fragment shaders are used to control the actual color of the pixels drawn on screen. Their only output is `gl_FragColor`.
|
||||
*
|
||||
* Both shaders can take *uniforms* or *attributes* as input. Attributes are explained later. Uniforms are common, read-only values that
|
||||
* can be changed at every frame and can be of type float, arrays of float or images.
|
||||
*
|
||||
* Shaders must be compiled and assembled into a program like so:
|
||||
* ```js
|
||||
* // here we simply create two shaders and assemble them in a program which is then used
|
||||
* // for subsequent rendering calls
|
||||
* const vertexShader = new WebGLVertex(VERTEX_SHADER);
|
||||
* const fragmentShader = new WebGLFragment(FRAGMENT_SHADER);
|
||||
* const program = this.context.getProgram(fragmentShader, vertexShader);
|
||||
* helper.useProgram(this.program);
|
||||
* ```
|
||||
*
|
||||
* Uniforms are defined using the `uniforms` option and can either be explicit values or callbacks taking the frame state as argument.
|
||||
* You can also change their value along the way like so:
|
||||
* ```js
|
||||
* helper.setUniformFloatValue('u_value', valueAsNumber);
|
||||
* ```
|
||||
*
|
||||
* ### Defining post processing passes
|
||||
*
|
||||
* *Post processing* describes the act of rendering primitives to a texture, and then rendering this texture to the final canvas
|
||||
* while applying special effects in screen space.
|
||||
* Typical uses are: blurring, color manipulation, depth of field, filtering...
|
||||
*
|
||||
* The `WebGLHelper` class offers the possibility to define post processes at creation time using the `postProcesses` option.
|
||||
* A post process step accepts the following options:
|
||||
*
|
||||
* * `fragmentShader` and `vertexShader`: text literals in GLSL language that will be compiled and used in the post processing step.
|
||||
* * `uniforms`: uniforms can be defined for the post processing steps just like for the main render.
|
||||
* * `scaleRatio`: allows using an intermediate texture smaller or higher than the final canvas in the post processing step.
|
||||
* This is typically used in blur steps to reduce the performance overhead by using an already downsampled texture as input.
|
||||
*
|
||||
* The {@link module:ol/webgl/PostProcessingPass~WebGLPostProcessingPass} class is used internally, refer to its documentation for more info.
|
||||
*
|
||||
* ### Binding WebGL buffers and flushing data into them
|
||||
*
|
||||
* Data that must be passed to the GPU has to be transferred using {@link module:ol/webgl/Buffer~WebGLArrayBuffer} objects.
|
||||
* A buffer has to be created only once, but must be bound every time the buffer content will be used for rendering.
|
||||
* This is done using {@link bindBuffer}.
|
||||
* When the buffer's array content has changed, the new data has to be flushed to the GPU memory; this is done using
|
||||
* {@link flushBufferData}. Note: this operation is expensive and should be done as infrequently as possible.
|
||||
*
|
||||
* When binding an array buffer, a `target` parameter must be given: it should be either {@link module:ol/webgl.ARRAY_BUFFER}
|
||||
* (if the buffer contains vertices data) or {@link module:ol/webgl.ELEMENT_ARRAY_BUFFER} (if the buffer contains indices data).
|
||||
*
|
||||
* Examples below:
|
||||
* ```js
|
||||
* // at initialization phase
|
||||
* const verticesBuffer = new WebGLArrayBuffer([], DYNAMIC_DRAW);
|
||||
* const indicesBuffer = new WebGLArrayBuffer([], DYNAMIC_DRAW);
|
||||
*
|
||||
* // when array values have changed
|
||||
* helper.flushBufferData(ARRAY_BUFFER, this.verticesBuffer);
|
||||
* helper.flushBufferData(ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
|
||||
*
|
||||
* // at rendering phase
|
||||
* helper.bindBuffer(ARRAY_BUFFER, this.verticesBuffer);
|
||||
* helper.bindBuffer(ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
|
||||
* ```
|
||||
*
|
||||
* ### Specifying attributes
|
||||
*
|
||||
* The GPU only receives the data as arrays of numbers. These numbers must be handled differently depending on what it describes (position, texture coordinate...).
|
||||
* Attributes are used to specify these uses. Specify the attribute names with
|
||||
* {@link module:ol/webgl/Helper~WebGLHelper#enableAttributes enableAttributes()} (see code snippet below).
|
||||
*
|
||||
* Please note that you will have to specify the type and offset of the attributes in the data array. You can refer to the documentation of [WebGLRenderingContext.vertexAttribPointer](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer) for more explanation.
|
||||
* ```js
|
||||
* // here we indicate that the data array has the following structure:
|
||||
* // [posX, posY, offsetX, offsetY, texCoordU, texCoordV, posX, posY, ...]
|
||||
* helper.enableAttributes([
|
||||
* {
|
||||
* name: 'a_position',
|
||||
* size: 2
|
||||
* },
|
||||
* {
|
||||
* name: 'a_offset',
|
||||
* size: 2
|
||||
* },
|
||||
* {
|
||||
* name: 'a_texCoord',
|
||||
* size: 2
|
||||
* }
|
||||
* ])
|
||||
* ```
|
||||
*
|
||||
* ### Rendering primitives
|
||||
*
|
||||
* Once all the steps above have been achieved, rendering primitives to the screen is done using {@link prepareDraw}, {@link drawElements} and {@link finalizeDraw}.
|
||||
* ```js
|
||||
* // frame preparation step
|
||||
* helper.prepareDraw(frameState);
|
||||
*
|
||||
* // call this for every data array that has to be rendered on screen
|
||||
* helper.drawElements(0, this.indicesBuffer.getArray().length);
|
||||
*
|
||||
* // finalize the rendering by applying post processes
|
||||
* helper.finalizeDraw(frameState);
|
||||
* ```
|
||||
*
|
||||
* For an example usage of this class, refer to {@link module:ol/renderer/webgl/PointsLayer~WebGLPointsLayerRenderer}.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
declare class WebGLHelper extends Disposable {
|
||||
/**
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options?: Options | undefined);
|
||||
/** @private */
|
||||
private boundHandleWebGLContextLost_;
|
||||
/** @private */
|
||||
private boundHandleWebGLContextRestored_;
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
private canvasCacheKey_;
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLCanvasElement}
|
||||
*/
|
||||
private canvas_;
|
||||
/**
|
||||
* @private
|
||||
* @type {WebGLRenderingContext}
|
||||
*/
|
||||
private gl_;
|
||||
/**
|
||||
* @private
|
||||
* @type {!Object<string, BufferCacheEntry>}
|
||||
*/
|
||||
private bufferCache_;
|
||||
/**
|
||||
* @private
|
||||
* @type {Object<string, Object>}
|
||||
*/
|
||||
private extensionCache_;
|
||||
/**
|
||||
* @private
|
||||
* @type {WebGLProgram}
|
||||
*/
|
||||
private currentProgram_;
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../transform.js").Transform}
|
||||
*/
|
||||
private offsetRotateMatrix_;
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../transform.js").Transform}
|
||||
*/
|
||||
private offsetScaleMatrix_;
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<number>}
|
||||
*/
|
||||
private tmpMat4_;
|
||||
/**
|
||||
* @private
|
||||
* @type {Object<string, WebGLUniformLocation>}
|
||||
*/
|
||||
private uniformLocations_;
|
||||
/**
|
||||
* @private
|
||||
* @type {Object<string, number>}
|
||||
*/
|
||||
private attribLocations_;
|
||||
/**
|
||||
* Holds info about custom uniforms used in the post processing pass.
|
||||
* If the uniform is a texture, the WebGL Texture object will be stored here.
|
||||
* @type {Array<UniformInternalDescription>}
|
||||
* @private
|
||||
*/
|
||||
private uniforms_;
|
||||
/**
|
||||
* An array of PostProcessingPass objects is kept in this variable, built from the steps provided in the
|
||||
* options. If no post process was given, a default one is used (so as not to have to make an exception to
|
||||
* the frame buffer logic).
|
||||
* @type {Array<WebGLPostProcessingPass>}
|
||||
* @private
|
||||
*/
|
||||
private postProcessPasses_;
|
||||
/**
|
||||
* @type {string|null}
|
||||
* @private
|
||||
*/
|
||||
private shaderCompileErrors_;
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
private startTime_;
|
||||
/**
|
||||
* @param {Object<string, UniformValue>} uniforms Uniform definitions.
|
||||
*/
|
||||
setUniforms(uniforms: {
|
||||
[x: string]: UniformValue;
|
||||
}): void;
|
||||
/**
|
||||
* @param {string} canvasCacheKey The canvas cache key.
|
||||
* @return {boolean} The provided key matches the one this helper was constructed with.
|
||||
*/
|
||||
canvasCacheKeyMatches(canvasCacheKey: string): boolean;
|
||||
/**
|
||||
* Get a WebGL extension. If the extension is not supported, null is returned.
|
||||
* Extensions are cached after they are enabled for the first time.
|
||||
* @param {string} name The extension name.
|
||||
* @return {Object|null} The extension or null if not supported.
|
||||
*/
|
||||
getExtension(name: string): any | null;
|
||||
/**
|
||||
* Just bind the buffer if it's in the cache. Otherwise create
|
||||
* the WebGL buffer, bind it, populate it, and add an entry to
|
||||
* the cache.
|
||||
* @param {import("./Buffer").default} buffer Buffer.
|
||||
* @api
|
||||
*/
|
||||
bindBuffer(buffer: import("./Buffer").default): void;
|
||||
/**
|
||||
* Update the data contained in the buffer array; this is required for the
|
||||
* new data to be rendered
|
||||
* @param {import("./Buffer").default} buffer Buffer.
|
||||
* @api
|
||||
*/
|
||||
flushBufferData(buffer: import("./Buffer").default): void;
|
||||
/**
|
||||
* @param {import("./Buffer.js").default} buf Buffer.
|
||||
*/
|
||||
deleteBuffer(buf: import("./Buffer.js").default): void;
|
||||
/**
|
||||
* Clear the buffer & set the viewport to draw.
|
||||
* Post process passes will be initialized here, the first one being bound as a render target for
|
||||
* subsequent draw calls.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState current frame state
|
||||
* @param {boolean} [opt_disableAlphaBlend] If true, no alpha blending will happen.
|
||||
* @api
|
||||
*/
|
||||
prepareDraw(frameState: import("../PluggableMap.js").FrameState, opt_disableAlphaBlend?: boolean | undefined): void;
|
||||
/**
|
||||
* Clear the render target & bind it for future draw operations.
|
||||
* This is similar to `prepareDraw`, only post processes will not be applied.
|
||||
* Note: the whole viewport will be drawn to the render target, regardless of its size.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState current frame state
|
||||
* @param {import("./RenderTarget.js").default} renderTarget Render target to draw to
|
||||
* @param {boolean} [opt_disableAlphaBlend] If true, no alpha blending will happen.
|
||||
*/
|
||||
prepareDrawToRenderTarget(frameState: import("../PluggableMap.js").FrameState, renderTarget: import("./RenderTarget.js").default, opt_disableAlphaBlend?: boolean | undefined): void;
|
||||
/**
|
||||
* Execute a draw call based on the currently bound program, texture, buffers, attributes.
|
||||
* @param {number} start Start index.
|
||||
* @param {number} end End index.
|
||||
* @api
|
||||
*/
|
||||
drawElements(start: number, end: number): void;
|
||||
/**
|
||||
* Apply the successive post process passes which will eventually render to the actual canvas.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState current frame state
|
||||
* @param {function(WebGLRenderingContext, import("../PluggableMap.js").FrameState):void} [preCompose] Called before composing.
|
||||
* @param {function(WebGLRenderingContext, import("../PluggableMap.js").FrameState):void} [postCompose] Called before composing.
|
||||
*/
|
||||
finalizeDraw(frameState: import("../PluggableMap.js").FrameState, preCompose?: ((arg0: WebGLRenderingContext, arg1: import("../PluggableMap.js").FrameState) => void) | undefined, postCompose?: ((arg0: WebGLRenderingContext, arg1: import("../PluggableMap.js").FrameState) => void) | undefined): void;
|
||||
/**
|
||||
* @return {HTMLCanvasElement} Canvas.
|
||||
* @api
|
||||
*/
|
||||
getCanvas(): HTMLCanvasElement;
|
||||
/**
|
||||
* Get the WebGL rendering context
|
||||
* @return {WebGLRenderingContext} The rendering context.
|
||||
* @api
|
||||
*/
|
||||
getGL(): WebGLRenderingContext;
|
||||
/**
|
||||
* Sets the default matrix uniforms for a given frame state. This is called internally in `prepareDraw`.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState Frame state.
|
||||
*/
|
||||
applyFrameState(frameState: import("../PluggableMap.js").FrameState): void;
|
||||
/**
|
||||
* Sets the custom uniforms based on what was given in the constructor. This is called internally in `prepareDraw`.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState Frame state.
|
||||
*/
|
||||
applyUniforms(frameState: import("../PluggableMap.js").FrameState): void;
|
||||
/**
|
||||
* Use a program. If the program is already in use, this will return `false`.
|
||||
* @param {WebGLProgram} program Program.
|
||||
* @return {boolean} Changed.
|
||||
* @api
|
||||
*/
|
||||
useProgram(program: WebGLProgram): boolean;
|
||||
/**
|
||||
* Will attempt to compile a vertex or fragment shader based on source
|
||||
* On error, the shader will be returned but
|
||||
* `gl.getShaderParameter(shader, gl.COMPILE_STATUS)` will return `true`
|
||||
* Use `gl.getShaderInfoLog(shader)` to have details
|
||||
* @param {string} source Shader source
|
||||
* @param {ShaderType} type VERTEX_SHADER or FRAGMENT_SHADER
|
||||
* @return {WebGLShader} Shader object
|
||||
*/
|
||||
compileShader(source: string, type: ShaderType): WebGLShader;
|
||||
/**
|
||||
* Create a program for a vertex and fragment shader. Throws if shader compilation fails.
|
||||
* @param {string} fragmentShaderSource Fragment shader source.
|
||||
* @param {string} vertexShaderSource Vertex shader source.
|
||||
* @return {WebGLProgram} Program
|
||||
* @api
|
||||
*/
|
||||
getProgram(fragmentShaderSource: string, vertexShaderSource: string): WebGLProgram;
|
||||
/**
|
||||
* Will get the location from the shader or the cache
|
||||
* @param {string} name Uniform name
|
||||
* @return {WebGLUniformLocation} uniformLocation
|
||||
* @api
|
||||
*/
|
||||
getUniformLocation(name: string): WebGLUniformLocation;
|
||||
/**
|
||||
* Will get the location from the shader or the cache
|
||||
* @param {string} name Attribute name
|
||||
* @return {number} attribLocation
|
||||
* @api
|
||||
*/
|
||||
getAttributeLocation(name: string): number;
|
||||
/**
|
||||
* Modifies the given transform to apply the rotation/translation/scaling of the given frame state.
|
||||
* The resulting transform can be used to convert world space coordinates to view coordinates.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState Frame state.
|
||||
* @param {import("../transform").Transform} transform Transform to update.
|
||||
* @return {import("../transform").Transform} The updated transform object.
|
||||
* @api
|
||||
*/
|
||||
makeProjectionTransform(frameState: import("../PluggableMap.js").FrameState, transform: import("../transform").Transform): import("../transform").Transform;
|
||||
/**
|
||||
* Give a value for a standard float uniform
|
||||
* @param {string} uniform Uniform name
|
||||
* @param {number} value Value
|
||||
* @api
|
||||
*/
|
||||
setUniformFloatValue(uniform: string, value: number): void;
|
||||
/**
|
||||
* Give a value for a vec4 uniform
|
||||
* @param {string} uniform Uniform name
|
||||
* @param {Array<number>} value Array of length 4.
|
||||
*/
|
||||
setUniformFloatVec4(uniform: string, value: Array<number>): void;
|
||||
/**
|
||||
* Give a value for a standard matrix4 uniform
|
||||
* @param {string} uniform Uniform name
|
||||
* @param {Array<number>} value Matrix value
|
||||
* @api
|
||||
*/
|
||||
setUniformMatrixValue(uniform: string, value: Array<number>): void;
|
||||
/**
|
||||
* Will set the currently bound buffer to an attribute of the shader program. Used by `#enableAttributes`
|
||||
* internally.
|
||||
* @param {string} attribName Attribute name
|
||||
* @param {number} size Number of components per attributes
|
||||
* @param {number} type UNSIGNED_INT, UNSIGNED_BYTE, UNSIGNED_SHORT or FLOAT
|
||||
* @param {number} stride Stride in bytes (0 means attribs are packed)
|
||||
* @param {number} offset Offset in bytes
|
||||
* @private
|
||||
*/
|
||||
private enableAttributeArray_;
|
||||
/**
|
||||
* Will enable the following attributes to be read from the currently bound buffer,
|
||||
* i.e. tell the GPU where to read the different attributes in the buffer. An error in the
|
||||
* size/type/order of attributes will most likely break the rendering and throw a WebGL exception.
|
||||
* @param {Array<AttributeDescription>} attributes Ordered list of attributes to read from the buffer
|
||||
* @api
|
||||
*/
|
||||
enableAttributes(attributes: Array<AttributeDescription>): void;
|
||||
/**
|
||||
* WebGL context was lost
|
||||
* @private
|
||||
*/
|
||||
private handleWebGLContextLost;
|
||||
/**
|
||||
* WebGL context was restored
|
||||
* @private
|
||||
*/
|
||||
private handleWebGLContextRestored;
|
||||
/**
|
||||
* Will create or reuse a given webgl texture and apply the given size. If no image data
|
||||
* specified, the texture will be empty, otherwise image data will be used and the `size`
|
||||
* parameter will be ignored.
|
||||
* Note: wrap parameters are set to clamp to edge, min filter is set to linear.
|
||||
* @param {Array<number>} size Expected size of the texture
|
||||
* @param {ImageData|HTMLImageElement|HTMLCanvasElement} [opt_data] Image data/object to bind to the texture
|
||||
* @param {WebGLTexture} [opt_texture] Existing texture to reuse
|
||||
* @return {WebGLTexture} The generated texture
|
||||
* @api
|
||||
*/
|
||||
createTexture(size: Array<number>, opt_data?: HTMLCanvasElement | HTMLImageElement | ImageData | undefined, opt_texture?: WebGLTexture | undefined): WebGLTexture;
|
||||
}
|
||||
import Disposable from "../Disposable.js";
|
||||
//# sourceMappingURL=Helper.d.ts.map
|
||||
1
node_modules/ol/webgl/Helper.d.ts.map
generated
vendored
Normal file
1
node_modules/ol/webgl/Helper.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Helper.d.ts","sourceRoot":"","sources":["../src/webgl/Helper.js"],"names":[],"mappings":"AA6kCA;;;;;GAKG;AACH,oDAJW,MAAM,oBAAoB,CAAC,GAC1B,MAAM,CAUjB;;;;yBA1jCS,MAAM;;;;;;;;;6BAUN,MAAM;;;;;;;;;;;;;4BAcN,MAAM;;;;;;;;;;;;YA9BF,OAAO,aAAa,EAAE,OAAO;;;;iBAC7B,WAAW;;;;;;;;;UAyCX,MAAM;;;;UACN,MAAM;;;;;;;;kCAOP,MAAM,GAAC,MAAM,MAAM,CAAC,GAAC,iBAAiB,GAAC,gBAAgB,GAAC,SAAS,GAAC,OAAO,cAAc,EAAE,SAAS;;;;;2BAMlG,mBAAmB,WAAU,OAAO,oBAAoB,EAAE,UAAU,KAAE,mBAAmB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAsBxF,MAAM;;;;;;;;;;;;;;YAQN,iBAAiB;;;;WACjB,MAAM;;;;;;AAqEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4HG;AACH;IACE;;OAEG;IACH,+CAmIC;IA/HC,eAAe;IACf,qCAA0E;IAE1E,eAAe;IACf,yCAC4C;IAE5C;;;OAGG;IACH,wBAE6B;IAE7B;;;OAGG;IACH,gBAA8C;IAE9C;;;OAGG;IACH,YAAmC;IAEnC;;;OAGG;IACH,qBAAsB;IAEtB;;;OAGG;IACH,wBAAyB;IAEzB;;;OAGG;IACH,wBAA2B;IAW3B;;;OAGG;IACH,4BAA4C;IAE5C;;;OAGG;IACH,2BAA2C;IAE3C;;;OAGG;IACH,iBAAwB;IAExB;;;OAGG;IACH,0BAA2B;IAE3B;;;OAGG;IACH,yBAA0B;IAE1B;;;;;OAKG;IACH,kBAAmB;IAOnB;;;;;;OAMG;IACH,2BAUqD;IAErD;;;OAGG;IACH,6BAAgC;IAEhC;;;OAGG;IACH,mBAA4B;IAG9B;;OAEG;IACH;YAFkB,MAAM,GAAE,YAAY;aAWrC;IAED;;;OAGG;IACH,sCAHW,MAAM,GACL,OAAO,CAIlB;IAED;;;;;OAKG;IACH,mBAHW,MAAM,GACL,MAAO,IAAI,CAStB;IAED;;;;;;OAMG;IACH,mBAHW,OAAO,UAAU,EAAE,OAAO,QAgBpC;IAED;;;;;OAKG;IACH,wBAHW,OAAO,UAAU,EAAE,OAAO,QAOpC;IAED;;OAEG;IACH,kBAFW,OAAO,aAAa,EAAE,OAAO,QAUvC;IAqBD;;;;;;;OAOG;IACH,wBAJW,OAAO,oBAAoB,EAAE,UAAU,qDAoCjD;IAED;;;;;;;OAOG;IACH,sCAJW,OAAO,oBAAoB,EAAE,UAAU,gBACvC,OAAO,mBAAmB,EAAE,OAAO,qDAqB7C;IAED;;;;;OAKG;IACH,oBAJW,MAAM,OACN,MAAM,QAahB;IAED;;;;;OAKG;IACH,yBAJW,OAAO,oBAAoB,EAAE,UAAU,uBAC9B,qBAAqB,QAAE,OAAO,oBAAoB,EAAE,UAAU,KAAE,IAAI,qCACpE,qBAAqB,QAAE,OAAO,oBAAoB,EAAE,UAAU,KAAE,IAAI,qBAmBvF;IAED;;;OAGG;IACH,aAHY,iBAAiB,CAK5B;IAED;;;;OAIG;IACH,SAHY,qBAAqB,CAKhC;IAED;;;OAGG;IACH,4BAFW,OAAO,oBAAoB,EAAE,UAAU,QAgCjD;IAED;;;OAGG;IACH,0BAFW,OAAO,oBAAoB,EAAE,UAAU,QAuFjD;IAED;;;;;OAKG;IACH,oBAJW,YAAY,GACX,OAAO,CAclB;IAED;;;;;;;;OAQG;IACH,sBAJW,MAAM,QACN,UAAU,GACT,WAAW,CAQtB;IAED;;;;;;OAMG;IACH,iCALW,MAAM,sBACN,MAAM,GACL,YAAY,CA6CvB;IAED;;;;;OAKG;IACH,yBAJW,MAAM,GACL,oBAAoB,CAW/B;IAED;;;;;OAKG;IACH,2BAJW,MAAM,GACL,MAAM,CAWjB;IAED;;;;;;;OAOG;IACH,oCALW,OAAO,oBAAoB,EAAE,UAAU,aACvC,OAAO,cAAc,EAAE,SAAS,GAC/B,OAAO,cAAc,EAAE,SAAS,CAqB3C;IAED;;;;;OAKG;IACH,8BAJW,MAAM,SACN,MAAM,QAKhB;IAED;;;;OAIG;IACH,6BAHW,MAAM,SACN,MAAM,MAAM,CAAC,QAIvB;IAED;;;;;OAKG;IACH,+BAJW,MAAM,SACN,MAAM,MAAM,CAAC,QASvB;IAED;;;;;;;;;OASG;IACH,8BAeC;IAED;;;;;;OAMG;IACH,6BAHW,MAAM,oBAAoB,CAAC,QAiBrC;IAED;;;OAGG;IACH,+BAGC;IAED;;;OAGG;IACH,mCAA+B;IAE/B;;;;;;;;;;OAUG;IACH,oBANW,MAAM,MAAM,CAAC,oHAGZ,YAAY,CAyCvB;CACF"}
|
||||
916
node_modules/ol/webgl/Helper.js
generated
vendored
Normal file
916
node_modules/ol/webgl/Helper.js
generated
vendored
Normal file
@@ -0,0 +1,916 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
/**
|
||||
* @module ol/webgl/Helper
|
||||
*/
|
||||
import ContextEventType from '../webgl/ContextEventType.js';
|
||||
import Disposable from '../Disposable.js';
|
||||
import WebGLPostProcessingPass from './PostProcessingPass.js';
|
||||
import { FLOAT, UNSIGNED_BYTE, UNSIGNED_INT, UNSIGNED_SHORT, getContext, } from '../webgl.js';
|
||||
import { clear } from '../obj.js';
|
||||
import { compose as composeTransform, create as createTransform, reset as resetTransform, rotate as rotateTransform, scale as scaleTransform, } from '../transform.js';
|
||||
import { create, fromTransform } from '../vec/mat4.js';
|
||||
import { getUid } from '../util.js';
|
||||
/**
|
||||
* @typedef {Object} BufferCacheEntry
|
||||
* @property {import("./Buffer.js").default} buffer Buffer.
|
||||
* @property {WebGLBuffer} webGlBuffer WebGlBuffer.
|
||||
*/
|
||||
/**
|
||||
* Shader types, either `FRAGMENT_SHADER` or `VERTEX_SHADER`.
|
||||
* @enum {number}
|
||||
*/
|
||||
export var ShaderType = {
|
||||
FRAGMENT_SHADER: 0x8b30,
|
||||
VERTEX_SHADER: 0x8b31,
|
||||
};
|
||||
/**
|
||||
* Uniform names used in the default shaders: `PROJECTION_MATRIX`, `OFFSET_SCALE_MATRIX`.
|
||||
* and `OFFSET_ROTATION_MATRIX`.
|
||||
* @enum {string}
|
||||
*/
|
||||
export var DefaultUniform = {
|
||||
PROJECTION_MATRIX: 'u_projectionMatrix',
|
||||
OFFSET_SCALE_MATRIX: 'u_offsetScaleMatrix',
|
||||
OFFSET_ROTATION_MATRIX: 'u_offsetRotateMatrix',
|
||||
TIME: 'u_time',
|
||||
ZOOM: 'u_zoom',
|
||||
RESOLUTION: 'u_resolution',
|
||||
};
|
||||
/**
|
||||
* Attribute types, either `UNSIGNED_BYTE`, `UNSIGNED_SHORT`, `UNSIGNED_INT` or `FLOAT`
|
||||
* Note: an attribute stored in a `Float32Array` should be of type `FLOAT`.
|
||||
* @enum {number}
|
||||
*/
|
||||
export var AttributeType = {
|
||||
UNSIGNED_BYTE: UNSIGNED_BYTE,
|
||||
UNSIGNED_SHORT: UNSIGNED_SHORT,
|
||||
UNSIGNED_INT: UNSIGNED_INT,
|
||||
FLOAT: FLOAT,
|
||||
};
|
||||
/**
|
||||
* Description of an attribute in a buffer
|
||||
* @typedef {Object} AttributeDescription
|
||||
* @property {string} name Attribute name to use in shaders
|
||||
* @property {number} size Number of components per attributes
|
||||
* @property {AttributeType} [type] Attribute type, i.e. number of bytes used to store the value. This is
|
||||
* determined by the class of typed array which the buffer uses (eg. `Float32Array` for a `FLOAT` attribute).
|
||||
* Default is `FLOAT`.
|
||||
*/
|
||||
/**
|
||||
* @typedef {number|Array<number>|HTMLCanvasElement|HTMLImageElement|ImageData|import("../transform").Transform} UniformLiteralValue
|
||||
*/
|
||||
/**
|
||||
* Uniform value can be a number, array of numbers (2 to 4), canvas element or a callback returning
|
||||
* one of the previous types.
|
||||
* @typedef {UniformLiteralValue|function(import("../PluggableMap.js").FrameState):UniformLiteralValue} UniformValue
|
||||
*/
|
||||
/**
|
||||
* @typedef {Object} PostProcessesOptions
|
||||
* @property {number} [scaleRatio] Scale ratio; if < 1, the post process will render to a texture smaller than
|
||||
* the main canvas which will then be sampled up (useful for saving resource on blur steps).
|
||||
* @property {string} [vertexShader] Vertex shader source
|
||||
* @property {string} [fragmentShader] Fragment shader source
|
||||
* @property {Object<string,UniformValue>} [uniforms] Uniform definitions for the post process step
|
||||
*/
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {Object<string,UniformValue>} [uniforms] Uniform definitions; property names must match the uniform
|
||||
* names in the provided or default shaders.
|
||||
* @property {Array<PostProcessesOptions>} [postProcesses] Post-processes definitions
|
||||
* @property {string} [canvasCacheKey] The cache key for the canvas.
|
||||
*/
|
||||
/**
|
||||
* @typedef {Object} UniformInternalDescription
|
||||
* @property {string} name Name
|
||||
* @property {UniformValue} [value] Value
|
||||
* @property {WebGLTexture} [texture] Texture
|
||||
* @private
|
||||
*/
|
||||
/**
|
||||
* @typedef {Object} CanvasCacheItem
|
||||
* @property {HTMLCanvasElement} canvas Canvas element.
|
||||
* @property {number} users The count of users of this canvas.
|
||||
*/
|
||||
/**
|
||||
* @type {Object<string,CanvasCacheItem>}
|
||||
*/
|
||||
var canvasCache = {};
|
||||
/**
|
||||
* @param {string} key The cache key for the canvas.
|
||||
* @return {string} The shared cache key.
|
||||
*/
|
||||
function getSharedCanvasCacheKey(key) {
|
||||
return 'shared/' + key;
|
||||
}
|
||||
var uniqueCanvasCacheKeyCount = 0;
|
||||
/**
|
||||
* @return {string} The unique cache key.
|
||||
*/
|
||||
function getUniqueCanvasCacheKey() {
|
||||
var key = 'unique/' + uniqueCanvasCacheKeyCount;
|
||||
uniqueCanvasCacheKeyCount += 1;
|
||||
return key;
|
||||
}
|
||||
/**
|
||||
* @param {string} key The cache key for the canvas.
|
||||
* @return {HTMLCanvasElement} The canvas.
|
||||
*/
|
||||
function getCanvas(key) {
|
||||
var cacheItem = canvasCache[key];
|
||||
if (!cacheItem) {
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.style.position = 'absolute';
|
||||
canvas.style.left = '0';
|
||||
cacheItem = { users: 0, canvas: canvas };
|
||||
canvasCache[key] = cacheItem;
|
||||
}
|
||||
cacheItem.users += 1;
|
||||
return cacheItem.canvas;
|
||||
}
|
||||
/**
|
||||
* @param {string} key The cache key for the canvas.
|
||||
*/
|
||||
function releaseCanvas(key) {
|
||||
var cacheItem = canvasCache[key];
|
||||
if (!cacheItem) {
|
||||
return;
|
||||
}
|
||||
cacheItem.users -= 1;
|
||||
if (cacheItem.users > 0) {
|
||||
return;
|
||||
}
|
||||
var canvas = cacheItem.canvas;
|
||||
var gl = getContext(canvas);
|
||||
var extension = gl.getExtension('WEBGL_lose_context');
|
||||
if (extension) {
|
||||
extension.loseContext();
|
||||
}
|
||||
delete canvasCache[key];
|
||||
}
|
||||
/**
|
||||
* @classdesc
|
||||
* This class is intended to provide low-level functions related to WebGL rendering, so that accessing
|
||||
* directly the WebGL API should not be required anymore.
|
||||
*
|
||||
* Several operations are handled by the `WebGLHelper` class:
|
||||
*
|
||||
* ### Define custom shaders and uniforms
|
||||
*
|
||||
* *Shaders* are low-level programs executed on the GPU and written in GLSL. There are two types of shaders:
|
||||
*
|
||||
* Vertex shaders are used to manipulate the position and attribute of *vertices* of rendered primitives (ie. corners of a square).
|
||||
* Outputs are:
|
||||
*
|
||||
* * `gl_Position`: position of the vertex in screen space
|
||||
*
|
||||
* * Varyings usually prefixed with `v_` are passed on to the fragment shader
|
||||
*
|
||||
* Fragment shaders are used to control the actual color of the pixels drawn on screen. Their only output is `gl_FragColor`.
|
||||
*
|
||||
* Both shaders can take *uniforms* or *attributes* as input. Attributes are explained later. Uniforms are common, read-only values that
|
||||
* can be changed at every frame and can be of type float, arrays of float or images.
|
||||
*
|
||||
* Shaders must be compiled and assembled into a program like so:
|
||||
* ```js
|
||||
* // here we simply create two shaders and assemble them in a program which is then used
|
||||
* // for subsequent rendering calls
|
||||
* const vertexShader = new WebGLVertex(VERTEX_SHADER);
|
||||
* const fragmentShader = new WebGLFragment(FRAGMENT_SHADER);
|
||||
* const program = this.context.getProgram(fragmentShader, vertexShader);
|
||||
* helper.useProgram(this.program);
|
||||
* ```
|
||||
*
|
||||
* Uniforms are defined using the `uniforms` option and can either be explicit values or callbacks taking the frame state as argument.
|
||||
* You can also change their value along the way like so:
|
||||
* ```js
|
||||
* helper.setUniformFloatValue('u_value', valueAsNumber);
|
||||
* ```
|
||||
*
|
||||
* ### Defining post processing passes
|
||||
*
|
||||
* *Post processing* describes the act of rendering primitives to a texture, and then rendering this texture to the final canvas
|
||||
* while applying special effects in screen space.
|
||||
* Typical uses are: blurring, color manipulation, depth of field, filtering...
|
||||
*
|
||||
* The `WebGLHelper` class offers the possibility to define post processes at creation time using the `postProcesses` option.
|
||||
* A post process step accepts the following options:
|
||||
*
|
||||
* * `fragmentShader` and `vertexShader`: text literals in GLSL language that will be compiled and used in the post processing step.
|
||||
* * `uniforms`: uniforms can be defined for the post processing steps just like for the main render.
|
||||
* * `scaleRatio`: allows using an intermediate texture smaller or higher than the final canvas in the post processing step.
|
||||
* This is typically used in blur steps to reduce the performance overhead by using an already downsampled texture as input.
|
||||
*
|
||||
* The {@link module:ol/webgl/PostProcessingPass~WebGLPostProcessingPass} class is used internally, refer to its documentation for more info.
|
||||
*
|
||||
* ### Binding WebGL buffers and flushing data into them
|
||||
*
|
||||
* Data that must be passed to the GPU has to be transferred using {@link module:ol/webgl/Buffer~WebGLArrayBuffer} objects.
|
||||
* A buffer has to be created only once, but must be bound every time the buffer content will be used for rendering.
|
||||
* This is done using {@link bindBuffer}.
|
||||
* When the buffer's array content has changed, the new data has to be flushed to the GPU memory; this is done using
|
||||
* {@link flushBufferData}. Note: this operation is expensive and should be done as infrequently as possible.
|
||||
*
|
||||
* When binding an array buffer, a `target` parameter must be given: it should be either {@link module:ol/webgl.ARRAY_BUFFER}
|
||||
* (if the buffer contains vertices data) or {@link module:ol/webgl.ELEMENT_ARRAY_BUFFER} (if the buffer contains indices data).
|
||||
*
|
||||
* Examples below:
|
||||
* ```js
|
||||
* // at initialization phase
|
||||
* const verticesBuffer = new WebGLArrayBuffer([], DYNAMIC_DRAW);
|
||||
* const indicesBuffer = new WebGLArrayBuffer([], DYNAMIC_DRAW);
|
||||
*
|
||||
* // when array values have changed
|
||||
* helper.flushBufferData(ARRAY_BUFFER, this.verticesBuffer);
|
||||
* helper.flushBufferData(ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
|
||||
*
|
||||
* // at rendering phase
|
||||
* helper.bindBuffer(ARRAY_BUFFER, this.verticesBuffer);
|
||||
* helper.bindBuffer(ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
|
||||
* ```
|
||||
*
|
||||
* ### Specifying attributes
|
||||
*
|
||||
* The GPU only receives the data as arrays of numbers. These numbers must be handled differently depending on what it describes (position, texture coordinate...).
|
||||
* Attributes are used to specify these uses. Specify the attribute names with
|
||||
* {@link module:ol/webgl/Helper~WebGLHelper#enableAttributes enableAttributes()} (see code snippet below).
|
||||
*
|
||||
* Please note that you will have to specify the type and offset of the attributes in the data array. You can refer to the documentation of [WebGLRenderingContext.vertexAttribPointer](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer) for more explanation.
|
||||
* ```js
|
||||
* // here we indicate that the data array has the following structure:
|
||||
* // [posX, posY, offsetX, offsetY, texCoordU, texCoordV, posX, posY, ...]
|
||||
* helper.enableAttributes([
|
||||
* {
|
||||
* name: 'a_position',
|
||||
* size: 2
|
||||
* },
|
||||
* {
|
||||
* name: 'a_offset',
|
||||
* size: 2
|
||||
* },
|
||||
* {
|
||||
* name: 'a_texCoord',
|
||||
* size: 2
|
||||
* }
|
||||
* ])
|
||||
* ```
|
||||
*
|
||||
* ### Rendering primitives
|
||||
*
|
||||
* Once all the steps above have been achieved, rendering primitives to the screen is done using {@link prepareDraw}, {@link drawElements} and {@link finalizeDraw}.
|
||||
* ```js
|
||||
* // frame preparation step
|
||||
* helper.prepareDraw(frameState);
|
||||
*
|
||||
* // call this for every data array that has to be rendered on screen
|
||||
* helper.drawElements(0, this.indicesBuffer.getArray().length);
|
||||
*
|
||||
* // finalize the rendering by applying post processes
|
||||
* helper.finalizeDraw(frameState);
|
||||
* ```
|
||||
*
|
||||
* For an example usage of this class, refer to {@link module:ol/renderer/webgl/PointsLayer~WebGLPointsLayerRenderer}.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
var WebGLHelper = /** @class */ (function (_super) {
|
||||
__extends(WebGLHelper, _super);
|
||||
/**
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
function WebGLHelper(opt_options) {
|
||||
var _this = _super.call(this) || this;
|
||||
var options = opt_options || {};
|
||||
/** @private */
|
||||
_this.boundHandleWebGLContextLost_ = _this.handleWebGLContextLost.bind(_this);
|
||||
/** @private */
|
||||
_this.boundHandleWebGLContextRestored_ =
|
||||
_this.handleWebGLContextRestored.bind(_this);
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
_this.canvasCacheKey_ = options.canvasCacheKey
|
||||
? getSharedCanvasCacheKey(options.canvasCacheKey)
|
||||
: getUniqueCanvasCacheKey();
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLCanvasElement}
|
||||
*/
|
||||
_this.canvas_ = getCanvas(_this.canvasCacheKey_);
|
||||
/**
|
||||
* @private
|
||||
* @type {WebGLRenderingContext}
|
||||
*/
|
||||
_this.gl_ = getContext(_this.canvas_);
|
||||
/**
|
||||
* @private
|
||||
* @type {!Object<string, BufferCacheEntry>}
|
||||
*/
|
||||
_this.bufferCache_ = {};
|
||||
/**
|
||||
* @private
|
||||
* @type {Object<string, Object>}
|
||||
*/
|
||||
_this.extensionCache_ = {};
|
||||
/**
|
||||
* @private
|
||||
* @type {WebGLProgram}
|
||||
*/
|
||||
_this.currentProgram_ = null;
|
||||
_this.canvas_.addEventListener(ContextEventType.LOST, _this.boundHandleWebGLContextLost_);
|
||||
_this.canvas_.addEventListener(ContextEventType.RESTORED, _this.boundHandleWebGLContextRestored_);
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../transform.js").Transform}
|
||||
*/
|
||||
_this.offsetRotateMatrix_ = createTransform();
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../transform.js").Transform}
|
||||
*/
|
||||
_this.offsetScaleMatrix_ = createTransform();
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<number>}
|
||||
*/
|
||||
_this.tmpMat4_ = create();
|
||||
/**
|
||||
* @private
|
||||
* @type {Object<string, WebGLUniformLocation>}
|
||||
*/
|
||||
_this.uniformLocations_ = {};
|
||||
/**
|
||||
* @private
|
||||
* @type {Object<string, number>}
|
||||
*/
|
||||
_this.attribLocations_ = {};
|
||||
/**
|
||||
* Holds info about custom uniforms used in the post processing pass.
|
||||
* If the uniform is a texture, the WebGL Texture object will be stored here.
|
||||
* @type {Array<UniformInternalDescription>}
|
||||
* @private
|
||||
*/
|
||||
_this.uniforms_ = [];
|
||||
if (options.uniforms) {
|
||||
_this.setUniforms(options.uniforms);
|
||||
}
|
||||
var gl = _this.getGL();
|
||||
/**
|
||||
* An array of PostProcessingPass objects is kept in this variable, built from the steps provided in the
|
||||
* options. If no post process was given, a default one is used (so as not to have to make an exception to
|
||||
* the frame buffer logic).
|
||||
* @type {Array<WebGLPostProcessingPass>}
|
||||
* @private
|
||||
*/
|
||||
_this.postProcessPasses_ = options.postProcesses
|
||||
? options.postProcesses.map(function (options) {
|
||||
return new WebGLPostProcessingPass({
|
||||
webGlContext: gl,
|
||||
scaleRatio: options.scaleRatio,
|
||||
vertexShader: options.vertexShader,
|
||||
fragmentShader: options.fragmentShader,
|
||||
uniforms: options.uniforms,
|
||||
});
|
||||
})
|
||||
: [new WebGLPostProcessingPass({ webGlContext: gl })];
|
||||
/**
|
||||
* @type {string|null}
|
||||
* @private
|
||||
*/
|
||||
_this.shaderCompileErrors_ = null;
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
_this.startTime_ = Date.now();
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* @param {Object<string, UniformValue>} uniforms Uniform definitions.
|
||||
*/
|
||||
WebGLHelper.prototype.setUniforms = function (uniforms) {
|
||||
this.uniforms_ = [];
|
||||
for (var name_1 in uniforms) {
|
||||
this.uniforms_.push({
|
||||
name: name_1,
|
||||
value: uniforms[name_1],
|
||||
});
|
||||
}
|
||||
this.uniformLocations_ = {};
|
||||
};
|
||||
/**
|
||||
* @param {string} canvasCacheKey The canvas cache key.
|
||||
* @return {boolean} The provided key matches the one this helper was constructed with.
|
||||
*/
|
||||
WebGLHelper.prototype.canvasCacheKeyMatches = function (canvasCacheKey) {
|
||||
return this.canvasCacheKey_ === getSharedCanvasCacheKey(canvasCacheKey);
|
||||
};
|
||||
/**
|
||||
* Get a WebGL extension. If the extension is not supported, null is returned.
|
||||
* Extensions are cached after they are enabled for the first time.
|
||||
* @param {string} name The extension name.
|
||||
* @return {Object|null} The extension or null if not supported.
|
||||
*/
|
||||
WebGLHelper.prototype.getExtension = function (name) {
|
||||
if (name in this.extensionCache_) {
|
||||
return this.extensionCache_[name];
|
||||
}
|
||||
var extension = this.gl_.getExtension(name);
|
||||
this.extensionCache_[name] = extension;
|
||||
return extension;
|
||||
};
|
||||
/**
|
||||
* Just bind the buffer if it's in the cache. Otherwise create
|
||||
* the WebGL buffer, bind it, populate it, and add an entry to
|
||||
* the cache.
|
||||
* @param {import("./Buffer").default} buffer Buffer.
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.bindBuffer = function (buffer) {
|
||||
var gl = this.getGL();
|
||||
var bufferKey = getUid(buffer);
|
||||
var bufferCache = this.bufferCache_[bufferKey];
|
||||
if (!bufferCache) {
|
||||
var webGlBuffer = gl.createBuffer();
|
||||
bufferCache = {
|
||||
buffer: buffer,
|
||||
webGlBuffer: webGlBuffer,
|
||||
};
|
||||
this.bufferCache_[bufferKey] = bufferCache;
|
||||
}
|
||||
gl.bindBuffer(buffer.getType(), bufferCache.webGlBuffer);
|
||||
};
|
||||
/**
|
||||
* Update the data contained in the buffer array; this is required for the
|
||||
* new data to be rendered
|
||||
* @param {import("./Buffer").default} buffer Buffer.
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.flushBufferData = function (buffer) {
|
||||
var gl = this.getGL();
|
||||
this.bindBuffer(buffer);
|
||||
gl.bufferData(buffer.getType(), buffer.getArray(), buffer.getUsage());
|
||||
};
|
||||
/**
|
||||
* @param {import("./Buffer.js").default} buf Buffer.
|
||||
*/
|
||||
WebGLHelper.prototype.deleteBuffer = function (buf) {
|
||||
var gl = this.getGL();
|
||||
var bufferKey = getUid(buf);
|
||||
var bufferCacheEntry = this.bufferCache_[bufferKey];
|
||||
if (bufferCacheEntry && !gl.isContextLost()) {
|
||||
gl.deleteBuffer(bufferCacheEntry.webGlBuffer);
|
||||
}
|
||||
delete this.bufferCache_[bufferKey];
|
||||
};
|
||||
/**
|
||||
* Clean up.
|
||||
*/
|
||||
WebGLHelper.prototype.disposeInternal = function () {
|
||||
this.canvas_.removeEventListener(ContextEventType.LOST, this.boundHandleWebGLContextLost_);
|
||||
this.canvas_.removeEventListener(ContextEventType.RESTORED, this.boundHandleWebGLContextRestored_);
|
||||
releaseCanvas(this.canvasCacheKey_);
|
||||
delete this.gl_;
|
||||
delete this.canvas_;
|
||||
};
|
||||
/**
|
||||
* Clear the buffer & set the viewport to draw.
|
||||
* Post process passes will be initialized here, the first one being bound as a render target for
|
||||
* subsequent draw calls.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState current frame state
|
||||
* @param {boolean} [opt_disableAlphaBlend] If true, no alpha blending will happen.
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.prepareDraw = function (frameState, opt_disableAlphaBlend) {
|
||||
var gl = this.getGL();
|
||||
var canvas = this.getCanvas();
|
||||
var size = frameState.size;
|
||||
var pixelRatio = frameState.pixelRatio;
|
||||
canvas.width = size[0] * pixelRatio;
|
||||
canvas.height = size[1] * pixelRatio;
|
||||
canvas.style.width = size[0] + 'px';
|
||||
canvas.style.height = size[1] + 'px';
|
||||
gl.useProgram(this.currentProgram_);
|
||||
// loop backwards in post processes list
|
||||
for (var i = this.postProcessPasses_.length - 1; i >= 0; i--) {
|
||||
this.postProcessPasses_[i].init(frameState);
|
||||
}
|
||||
gl.bindTexture(gl.TEXTURE_2D, null);
|
||||
gl.clearColor(0.0, 0.0, 0.0, 0.0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(gl.ONE, opt_disableAlphaBlend ? gl.ZERO : gl.ONE_MINUS_SRC_ALPHA);
|
||||
gl.useProgram(this.currentProgram_);
|
||||
this.applyFrameState(frameState);
|
||||
this.applyUniforms(frameState);
|
||||
};
|
||||
/**
|
||||
* Clear the render target & bind it for future draw operations.
|
||||
* This is similar to `prepareDraw`, only post processes will not be applied.
|
||||
* Note: the whole viewport will be drawn to the render target, regardless of its size.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState current frame state
|
||||
* @param {import("./RenderTarget.js").default} renderTarget Render target to draw to
|
||||
* @param {boolean} [opt_disableAlphaBlend] If true, no alpha blending will happen.
|
||||
*/
|
||||
WebGLHelper.prototype.prepareDrawToRenderTarget = function (frameState, renderTarget, opt_disableAlphaBlend) {
|
||||
var gl = this.getGL();
|
||||
var size = renderTarget.getSize();
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, renderTarget.getFramebuffer());
|
||||
gl.viewport(0, 0, size[0], size[1]);
|
||||
gl.bindTexture(gl.TEXTURE_2D, renderTarget.getTexture());
|
||||
gl.clearColor(0.0, 0.0, 0.0, 0.0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(gl.ONE, opt_disableAlphaBlend ? gl.ZERO : gl.ONE_MINUS_SRC_ALPHA);
|
||||
gl.useProgram(this.currentProgram_);
|
||||
this.applyFrameState(frameState);
|
||||
this.applyUniforms(frameState);
|
||||
};
|
||||
/**
|
||||
* Execute a draw call based on the currently bound program, texture, buffers, attributes.
|
||||
* @param {number} start Start index.
|
||||
* @param {number} end End index.
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.drawElements = function (start, end) {
|
||||
var gl = this.getGL();
|
||||
this.getExtension('OES_element_index_uint');
|
||||
var elementType = gl.UNSIGNED_INT;
|
||||
var elementSize = 4;
|
||||
var numItems = end - start;
|
||||
var offsetInBytes = start * elementSize;
|
||||
gl.drawElements(gl.TRIANGLES, numItems, elementType, offsetInBytes);
|
||||
};
|
||||
/**
|
||||
* Apply the successive post process passes which will eventually render to the actual canvas.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState current frame state
|
||||
* @param {function(WebGLRenderingContext, import("../PluggableMap.js").FrameState):void} [preCompose] Called before composing.
|
||||
* @param {function(WebGLRenderingContext, import("../PluggableMap.js").FrameState):void} [postCompose] Called before composing.
|
||||
*/
|
||||
WebGLHelper.prototype.finalizeDraw = function (frameState, preCompose, postCompose) {
|
||||
// apply post processes using the next one as target
|
||||
for (var i = 0, ii = this.postProcessPasses_.length; i < ii; i++) {
|
||||
if (i === ii - 1) {
|
||||
this.postProcessPasses_[i].apply(frameState, null, preCompose, postCompose);
|
||||
}
|
||||
else {
|
||||
this.postProcessPasses_[i].apply(frameState, this.postProcessPasses_[i + 1]);
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @return {HTMLCanvasElement} Canvas.
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.getCanvas = function () {
|
||||
return this.canvas_;
|
||||
};
|
||||
/**
|
||||
* Get the WebGL rendering context
|
||||
* @return {WebGLRenderingContext} The rendering context.
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.getGL = function () {
|
||||
return this.gl_;
|
||||
};
|
||||
/**
|
||||
* Sets the default matrix uniforms for a given frame state. This is called internally in `prepareDraw`.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState Frame state.
|
||||
*/
|
||||
WebGLHelper.prototype.applyFrameState = function (frameState) {
|
||||
var size = frameState.size;
|
||||
var rotation = frameState.viewState.rotation;
|
||||
var offsetScaleMatrix = resetTransform(this.offsetScaleMatrix_);
|
||||
scaleTransform(offsetScaleMatrix, 2 / size[0], 2 / size[1]);
|
||||
var offsetRotateMatrix = resetTransform(this.offsetRotateMatrix_);
|
||||
if (rotation !== 0) {
|
||||
rotateTransform(offsetRotateMatrix, -rotation);
|
||||
}
|
||||
this.setUniformMatrixValue(DefaultUniform.OFFSET_SCALE_MATRIX, fromTransform(this.tmpMat4_, offsetScaleMatrix));
|
||||
this.setUniformMatrixValue(DefaultUniform.OFFSET_ROTATION_MATRIX, fromTransform(this.tmpMat4_, offsetRotateMatrix));
|
||||
this.setUniformFloatValue(DefaultUniform.TIME, (Date.now() - this.startTime_) * 0.001);
|
||||
this.setUniformFloatValue(DefaultUniform.ZOOM, frameState.viewState.zoom);
|
||||
this.setUniformFloatValue(DefaultUniform.RESOLUTION, frameState.viewState.resolution);
|
||||
};
|
||||
/**
|
||||
* Sets the custom uniforms based on what was given in the constructor. This is called internally in `prepareDraw`.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState Frame state.
|
||||
*/
|
||||
WebGLHelper.prototype.applyUniforms = function (frameState) {
|
||||
var gl = this.getGL();
|
||||
var value;
|
||||
var textureSlot = 0;
|
||||
this.uniforms_.forEach(function (uniform) {
|
||||
value =
|
||||
typeof uniform.value === 'function'
|
||||
? uniform.value(frameState)
|
||||
: uniform.value;
|
||||
// apply value based on type
|
||||
if (value instanceof HTMLCanvasElement ||
|
||||
value instanceof HTMLImageElement ||
|
||||
value instanceof ImageData) {
|
||||
// create a texture & put data
|
||||
if (!uniform.texture) {
|
||||
uniform.prevValue = undefined;
|
||||
uniform.texture = gl.createTexture();
|
||||
}
|
||||
gl.activeTexture(gl["TEXTURE".concat(textureSlot)]);
|
||||
gl.bindTexture(gl.TEXTURE_2D, uniform.texture);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
var imageReady = !(value instanceof HTMLImageElement) ||
|
||||
/** @type {HTMLImageElement} */ (value).complete;
|
||||
if (imageReady && uniform.prevValue !== value) {
|
||||
uniform.prevValue = value;
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, value);
|
||||
}
|
||||
// fill texture slots by increasing index
|
||||
gl.uniform1i(this.getUniformLocation(uniform.name), textureSlot++);
|
||||
}
|
||||
else if (Array.isArray(value) && value.length === 6) {
|
||||
this.setUniformMatrixValue(uniform.name, fromTransform(this.tmpMat4_, value));
|
||||
}
|
||||
else if (Array.isArray(value) && value.length <= 4) {
|
||||
switch (value.length) {
|
||||
case 2:
|
||||
gl.uniform2f(this.getUniformLocation(uniform.name), value[0], value[1]);
|
||||
return;
|
||||
case 3:
|
||||
gl.uniform3f(this.getUniformLocation(uniform.name), value[0], value[1], value[2]);
|
||||
return;
|
||||
case 4:
|
||||
gl.uniform4f(this.getUniformLocation(uniform.name), value[0], value[1], value[2], value[3]);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (typeof value === 'number') {
|
||||
gl.uniform1f(this.getUniformLocation(uniform.name), value);
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
/**
|
||||
* Use a program. If the program is already in use, this will return `false`.
|
||||
* @param {WebGLProgram} program Program.
|
||||
* @return {boolean} Changed.
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.useProgram = function (program) {
|
||||
if (program == this.currentProgram_) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
var gl = this.getGL();
|
||||
gl.useProgram(program);
|
||||
this.currentProgram_ = program;
|
||||
this.uniformLocations_ = {};
|
||||
this.attribLocations_ = {};
|
||||
return true;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Will attempt to compile a vertex or fragment shader based on source
|
||||
* On error, the shader will be returned but
|
||||
* `gl.getShaderParameter(shader, gl.COMPILE_STATUS)` will return `true`
|
||||
* Use `gl.getShaderInfoLog(shader)` to have details
|
||||
* @param {string} source Shader source
|
||||
* @param {ShaderType} type VERTEX_SHADER or FRAGMENT_SHADER
|
||||
* @return {WebGLShader} Shader object
|
||||
*/
|
||||
WebGLHelper.prototype.compileShader = function (source, type) {
|
||||
var gl = this.getGL();
|
||||
var shader = gl.createShader(type);
|
||||
gl.shaderSource(shader, source);
|
||||
gl.compileShader(shader);
|
||||
return shader;
|
||||
};
|
||||
/**
|
||||
* Create a program for a vertex and fragment shader. Throws if shader compilation fails.
|
||||
* @param {string} fragmentShaderSource Fragment shader source.
|
||||
* @param {string} vertexShaderSource Vertex shader source.
|
||||
* @return {WebGLProgram} Program
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.getProgram = function (fragmentShaderSource, vertexShaderSource) {
|
||||
var gl = this.getGL();
|
||||
var fragmentShader = this.compileShader(fragmentShaderSource, gl.FRAGMENT_SHADER);
|
||||
var vertexShader = this.compileShader(vertexShaderSource, gl.VERTEX_SHADER);
|
||||
var program = gl.createProgram();
|
||||
gl.attachShader(program, fragmentShader);
|
||||
gl.attachShader(program, vertexShader);
|
||||
gl.linkProgram(program);
|
||||
if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
|
||||
var message = "Fragment shader compliation failed: ".concat(gl.getShaderInfoLog(fragmentShader));
|
||||
throw new Error(message);
|
||||
}
|
||||
gl.deleteShader(fragmentShader);
|
||||
if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
|
||||
var message = "Vertex shader compilation failed: ".concat(gl.getShaderInfoLog(vertexShader));
|
||||
throw new Error(message);
|
||||
}
|
||||
gl.deleteShader(vertexShader);
|
||||
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
||||
var message = "GL program linking failed: ".concat(gl.getShaderInfoLog(vertexShader));
|
||||
throw new Error(message);
|
||||
}
|
||||
return program;
|
||||
};
|
||||
/**
|
||||
* Will get the location from the shader or the cache
|
||||
* @param {string} name Uniform name
|
||||
* @return {WebGLUniformLocation} uniformLocation
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.getUniformLocation = function (name) {
|
||||
if (this.uniformLocations_[name] === undefined) {
|
||||
this.uniformLocations_[name] = this.getGL().getUniformLocation(this.currentProgram_, name);
|
||||
}
|
||||
return this.uniformLocations_[name];
|
||||
};
|
||||
/**
|
||||
* Will get the location from the shader or the cache
|
||||
* @param {string} name Attribute name
|
||||
* @return {number} attribLocation
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.getAttributeLocation = function (name) {
|
||||
if (this.attribLocations_[name] === undefined) {
|
||||
this.attribLocations_[name] = this.getGL().getAttribLocation(this.currentProgram_, name);
|
||||
}
|
||||
return this.attribLocations_[name];
|
||||
};
|
||||
/**
|
||||
* Modifies the given transform to apply the rotation/translation/scaling of the given frame state.
|
||||
* The resulting transform can be used to convert world space coordinates to view coordinates.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState Frame state.
|
||||
* @param {import("../transform").Transform} transform Transform to update.
|
||||
* @return {import("../transform").Transform} The updated transform object.
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.makeProjectionTransform = function (frameState, transform) {
|
||||
var size = frameState.size;
|
||||
var rotation = frameState.viewState.rotation;
|
||||
var resolution = frameState.viewState.resolution;
|
||||
var center = frameState.viewState.center;
|
||||
resetTransform(transform);
|
||||
composeTransform(transform, 0, 0, 2 / (resolution * size[0]), 2 / (resolution * size[1]), -rotation, -center[0], -center[1]);
|
||||
return transform;
|
||||
};
|
||||
/**
|
||||
* Give a value for a standard float uniform
|
||||
* @param {string} uniform Uniform name
|
||||
* @param {number} value Value
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.setUniformFloatValue = function (uniform, value) {
|
||||
this.getGL().uniform1f(this.getUniformLocation(uniform), value);
|
||||
};
|
||||
/**
|
||||
* Give a value for a vec4 uniform
|
||||
* @param {string} uniform Uniform name
|
||||
* @param {Array<number>} value Array of length 4.
|
||||
*/
|
||||
WebGLHelper.prototype.setUniformFloatVec4 = function (uniform, value) {
|
||||
this.getGL().uniform4fv(this.getUniformLocation(uniform), value);
|
||||
};
|
||||
/**
|
||||
* Give a value for a standard matrix4 uniform
|
||||
* @param {string} uniform Uniform name
|
||||
* @param {Array<number>} value Matrix value
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.setUniformMatrixValue = function (uniform, value) {
|
||||
this.getGL().uniformMatrix4fv(this.getUniformLocation(uniform), false, value);
|
||||
};
|
||||
/**
|
||||
* Will set the currently bound buffer to an attribute of the shader program. Used by `#enableAttributes`
|
||||
* internally.
|
||||
* @param {string} attribName Attribute name
|
||||
* @param {number} size Number of components per attributes
|
||||
* @param {number} type UNSIGNED_INT, UNSIGNED_BYTE, UNSIGNED_SHORT or FLOAT
|
||||
* @param {number} stride Stride in bytes (0 means attribs are packed)
|
||||
* @param {number} offset Offset in bytes
|
||||
* @private
|
||||
*/
|
||||
WebGLHelper.prototype.enableAttributeArray_ = function (attribName, size, type, stride, offset) {
|
||||
var location = this.getAttributeLocation(attribName);
|
||||
// the attribute has not been found in the shaders; do not enable it
|
||||
if (location < 0) {
|
||||
return;
|
||||
}
|
||||
this.getGL().enableVertexAttribArray(location);
|
||||
this.getGL().vertexAttribPointer(location, size, type, false, stride, offset);
|
||||
};
|
||||
/**
|
||||
* Will enable the following attributes to be read from the currently bound buffer,
|
||||
* i.e. tell the GPU where to read the different attributes in the buffer. An error in the
|
||||
* size/type/order of attributes will most likely break the rendering and throw a WebGL exception.
|
||||
* @param {Array<AttributeDescription>} attributes Ordered list of attributes to read from the buffer
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.enableAttributes = function (attributes) {
|
||||
var stride = computeAttributesStride(attributes);
|
||||
var offset = 0;
|
||||
for (var i = 0; i < attributes.length; i++) {
|
||||
var attr = attributes[i];
|
||||
this.enableAttributeArray_(attr.name, attr.size, attr.type || FLOAT, stride, offset);
|
||||
offset += attr.size * getByteSizeFromType(attr.type);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* WebGL context was lost
|
||||
* @private
|
||||
*/
|
||||
WebGLHelper.prototype.handleWebGLContextLost = function () {
|
||||
clear(this.bufferCache_);
|
||||
this.currentProgram_ = null;
|
||||
};
|
||||
/**
|
||||
* WebGL context was restored
|
||||
* @private
|
||||
*/
|
||||
WebGLHelper.prototype.handleWebGLContextRestored = function () { };
|
||||
/**
|
||||
* Will create or reuse a given webgl texture and apply the given size. If no image data
|
||||
* specified, the texture will be empty, otherwise image data will be used and the `size`
|
||||
* parameter will be ignored.
|
||||
* Note: wrap parameters are set to clamp to edge, min filter is set to linear.
|
||||
* @param {Array<number>} size Expected size of the texture
|
||||
* @param {ImageData|HTMLImageElement|HTMLCanvasElement} [opt_data] Image data/object to bind to the texture
|
||||
* @param {WebGLTexture} [opt_texture] Existing texture to reuse
|
||||
* @return {WebGLTexture} The generated texture
|
||||
* @api
|
||||
*/
|
||||
WebGLHelper.prototype.createTexture = function (size, opt_data, opt_texture) {
|
||||
var gl = this.getGL();
|
||||
var texture = opt_texture || gl.createTexture();
|
||||
// set params & size
|
||||
var level = 0;
|
||||
var internalFormat = gl.RGBA;
|
||||
var border = 0;
|
||||
var format = gl.RGBA;
|
||||
var type = gl.UNSIGNED_BYTE;
|
||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||
if (opt_data) {
|
||||
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, format, type, opt_data);
|
||||
}
|
||||
else {
|
||||
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, size[0], size[1], border, format, type, null);
|
||||
}
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
return texture;
|
||||
};
|
||||
return WebGLHelper;
|
||||
}(Disposable));
|
||||
/**
|
||||
* Compute a stride in bytes based on a list of attributes
|
||||
* @param {Array<AttributeDescription>} attributes Ordered list of attributes
|
||||
* @return {number} Stride, ie amount of values for each vertex in the vertex buffer
|
||||
* @api
|
||||
*/
|
||||
export function computeAttributesStride(attributes) {
|
||||
var stride = 0;
|
||||
for (var i = 0; i < attributes.length; i++) {
|
||||
var attr = attributes[i];
|
||||
stride += attr.size * getByteSizeFromType(attr.type);
|
||||
}
|
||||
return stride;
|
||||
}
|
||||
/**
|
||||
* Computes the size in byte of an attribute type.
|
||||
* @param {AttributeType} type Attribute type
|
||||
* @return {number} The size in bytes
|
||||
*/
|
||||
function getByteSizeFromType(type) {
|
||||
switch (type) {
|
||||
case AttributeType.UNSIGNED_BYTE:
|
||||
return Uint8Array.BYTES_PER_ELEMENT;
|
||||
case AttributeType.UNSIGNED_SHORT:
|
||||
return Uint16Array.BYTES_PER_ELEMENT;
|
||||
case AttributeType.UNSIGNED_INT:
|
||||
return Uint32Array.BYTES_PER_ELEMENT;
|
||||
case AttributeType.FLOAT:
|
||||
default:
|
||||
return Float32Array.BYTES_PER_ELEMENT;
|
||||
}
|
||||
}
|
||||
export default WebGLHelper;
|
||||
//# sourceMappingURL=Helper.js.map
|
||||
1
node_modules/ol/webgl/Helper.js.map
generated
vendored
Normal file
1
node_modules/ol/webgl/Helper.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
24
node_modules/ol/webgl/PaletteTexture.d.ts
generated
vendored
Normal file
24
node_modules/ol/webgl/PaletteTexture.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
export default PaletteTexture;
|
||||
/**
|
||||
* @module ol/webgl/PaletteTexture
|
||||
*/
|
||||
declare class PaletteTexture {
|
||||
/**
|
||||
* @param {string} name The name of the texture.
|
||||
* @param {Uint8Array} data The texture data.
|
||||
*/
|
||||
constructor(name: string, data: Uint8Array);
|
||||
name: string;
|
||||
data: Uint8Array;
|
||||
/**
|
||||
* @type {WebGLTexture}
|
||||
* @private
|
||||
*/
|
||||
private texture_;
|
||||
/**
|
||||
* @param {WebGLRenderingContext} gl Rendering context.
|
||||
* @return {WebGLTexture} The texture.
|
||||
*/
|
||||
getTexture(gl: WebGLRenderingContext): WebGLTexture;
|
||||
}
|
||||
//# sourceMappingURL=PaletteTexture.d.ts.map
|
||||
1
node_modules/ol/webgl/PaletteTexture.d.ts.map
generated
vendored
Normal file
1
node_modules/ol/webgl/PaletteTexture.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PaletteTexture.d.ts","sourceRoot":"","sources":["../src/webgl/PaletteTexture.js"],"names":[],"mappings":";AAAA;;GAEG;AAEH;IACE;;;OAGG;IACH,kBAHW,MAAM,QACN,UAAU,EAWpB;IARC,aAAgB;IAChB,iBAAgB;IAEhB;;;OAGG;IACH,iBAAoB;IAGtB;;;OAGG;IACH,eAHW,qBAAqB,GACpB,YAAY,CAwBvB;CACF"}
|
||||
38
node_modules/ol/webgl/PaletteTexture.js
generated
vendored
Normal file
38
node_modules/ol/webgl/PaletteTexture.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @module ol/webgl/PaletteTexture
|
||||
*/
|
||||
var PaletteTexture = /** @class */ (function () {
|
||||
/**
|
||||
* @param {string} name The name of the texture.
|
||||
* @param {Uint8Array} data The texture data.
|
||||
*/
|
||||
function PaletteTexture(name, data) {
|
||||
this.name = name;
|
||||
this.data = data;
|
||||
/**
|
||||
* @type {WebGLTexture}
|
||||
* @private
|
||||
*/
|
||||
this.texture_ = null;
|
||||
}
|
||||
/**
|
||||
* @param {WebGLRenderingContext} gl Rendering context.
|
||||
* @return {WebGLTexture} The texture.
|
||||
*/
|
||||
PaletteTexture.prototype.getTexture = function (gl) {
|
||||
if (!this.texture_) {
|
||||
var texture = gl.createTexture();
|
||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.data.length / 4, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, this.data);
|
||||
this.texture_ = texture;
|
||||
}
|
||||
return this.texture_;
|
||||
};
|
||||
return PaletteTexture;
|
||||
}());
|
||||
export default PaletteTexture;
|
||||
//# sourceMappingURL=PaletteTexture.js.map
|
||||
1
node_modules/ol/webgl/PaletteTexture.js.map
generated
vendored
Normal file
1
node_modules/ol/webgl/PaletteTexture.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PaletteTexture.js","sourceRoot":"","sources":["../src/webgl/PaletteTexture.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;IACE;;;OAGG;IACH,wBAAY,IAAI,EAAE,IAAI;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAEjB;;;WAGG;QACH,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,mCAAU,GAAV,UAAW,EAAE;QACX,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAM,OAAO,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC;YACnC,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YACvC,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC;YACrE,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC;YACrE,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,kBAAkB,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;YACnE,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,kBAAkB,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;YACnE,EAAE,CAAC,UAAU,CACX,EAAE,CAAC,UAAU,EACb,CAAC,EACD,EAAE,CAAC,IAAI,EACP,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EACpB,CAAC,EACD,CAAC,EACD,EAAE,CAAC,IAAI,EACP,EAAE,CAAC,aAAa,EAChB,IAAI,CAAC,IAAI,CACV,CAAC;YACF,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;SACzB;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IACH,qBAAC;AAAD,CAAC,AA3CD,IA2CC;AAED,eAAe,cAAc,CAAC"}
|
||||
163
node_modules/ol/webgl/PostProcessingPass.d.ts
generated
vendored
Normal file
163
node_modules/ol/webgl/PostProcessingPass.d.ts
generated
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
export default WebGLPostProcessingPass;
|
||||
export type Options = {
|
||||
/**
|
||||
* WebGL context; mandatory.
|
||||
*/
|
||||
webGlContext: WebGLRenderingContext;
|
||||
/**
|
||||
* Scale ratio; if < 1, the post process will render to a texture smaller than
|
||||
* the main canvas that will then be sampled up (useful for saving resource on blur steps).
|
||||
*/
|
||||
scaleRatio?: number | undefined;
|
||||
/**
|
||||
* Vertex shader source
|
||||
*/
|
||||
vertexShader?: string | undefined;
|
||||
/**
|
||||
* Fragment shader source
|
||||
*/
|
||||
fragmentShader?: string | undefined;
|
||||
/**
|
||||
* Uniform definitions for the post process step
|
||||
*/
|
||||
uniforms?: {
|
||||
[x: string]: import("./Helper").UniformValue;
|
||||
} | undefined;
|
||||
};
|
||||
export type UniformInternalDescription = {
|
||||
/**
|
||||
* Value
|
||||
*/
|
||||
value: import("./Helper").UniformValue;
|
||||
/**
|
||||
* Location
|
||||
*/
|
||||
location: number;
|
||||
/**
|
||||
* Texture
|
||||
*/
|
||||
texture?: WebGLTexture | undefined;
|
||||
};
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {WebGLRenderingContext} webGlContext WebGL context; mandatory.
|
||||
* @property {number} [scaleRatio] Scale ratio; if < 1, the post process will render to a texture smaller than
|
||||
* the main canvas that will then be sampled up (useful for saving resource on blur steps).
|
||||
* @property {string} [vertexShader] Vertex shader source
|
||||
* @property {string} [fragmentShader] Fragment shader source
|
||||
* @property {Object<string,import("./Helper").UniformValue>} [uniforms] Uniform definitions for the post process step
|
||||
*/
|
||||
/**
|
||||
* @typedef {Object} UniformInternalDescription
|
||||
* @property {import("./Helper").UniformValue} value Value
|
||||
* @property {number} location Location
|
||||
* @property {WebGLTexture} [texture] Texture
|
||||
* @private
|
||||
*/
|
||||
/**
|
||||
* @classdesc
|
||||
* This class is used to define Post Processing passes with custom shaders and uniforms.
|
||||
* This is used internally by {@link module:ol/webgl/Helper~WebGLHelper}.
|
||||
*
|
||||
* Please note that the final output on the DOM canvas is expected to have premultiplied alpha, which means that
|
||||
* a pixel which is 100% red with an opacity of 50% must have a color of (r=0.5, g=0, b=0, a=0.5).
|
||||
* Failing to provide pixel colors with premultiplied alpha will result in render anomalies.
|
||||
*
|
||||
* The default post-processing pass does *not* multiply color values with alpha value, it expects color values to be
|
||||
* premultiplied.
|
||||
*
|
||||
* Default shaders are shown hereafter:
|
||||
*
|
||||
* * Vertex shader:
|
||||
*
|
||||
* ```
|
||||
* precision mediump float;
|
||||
*
|
||||
* attribute vec2 a_position;
|
||||
* varying vec2 v_texCoord;
|
||||
* varying vec2 v_screenCoord;
|
||||
*
|
||||
* uniform vec2 u_screenSize;
|
||||
*
|
||||
* void main() {
|
||||
* v_texCoord = a_position * 0.5 + 0.5;
|
||||
* v_screenCoord = v_texCoord * u_screenSize;
|
||||
* gl_Position = vec4(a_position, 0.0, 1.0);
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* * Fragment shader:
|
||||
*
|
||||
* ```
|
||||
* precision mediump float;
|
||||
*
|
||||
* uniform sampler2D u_image;
|
||||
* uniform float u_opacity;
|
||||
*
|
||||
* varying vec2 v_texCoord;
|
||||
*
|
||||
* void main() {
|
||||
* gl_FragColor = texture2D(u_image, v_texCoord) * u_opacity;
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
declare class WebGLPostProcessingPass {
|
||||
/**
|
||||
* @param {Options} options Options.
|
||||
*/
|
||||
constructor(options: Options);
|
||||
gl_: WebGLRenderingContext;
|
||||
scaleRatio_: number;
|
||||
renderTargetTexture_: WebGLTexture | null;
|
||||
renderTargetTextureSize_: number[] | null;
|
||||
frameBuffer_: WebGLFramebuffer | null;
|
||||
renderTargetProgram_: WebGLProgram | null;
|
||||
renderTargetVerticesBuffer_: WebGLBuffer | null;
|
||||
renderTargetAttribLocation_: number;
|
||||
renderTargetUniformLocation_: WebGLUniformLocation | null;
|
||||
renderTargetOpacityLocation_: WebGLUniformLocation | null;
|
||||
renderTargetTextureLocation_: WebGLUniformLocation | null;
|
||||
/**
|
||||
* Holds info about custom uniforms used in the post processing pass
|
||||
* @type {Array<UniformInternalDescription>}
|
||||
* @private
|
||||
*/
|
||||
private uniforms_;
|
||||
/**
|
||||
* Get the WebGL rendering context
|
||||
* @return {WebGLRenderingContext} The rendering context.
|
||||
* @api
|
||||
*/
|
||||
getGL(): WebGLRenderingContext;
|
||||
/**
|
||||
* Initialize the render target texture of the post process, make sure it is at the
|
||||
* right size and bind it as a render target for the next draw calls.
|
||||
* The last step to be initialized will be the one where the primitives are rendered.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState current frame state
|
||||
* @api
|
||||
*/
|
||||
init(frameState: import("../PluggableMap.js").FrameState): void;
|
||||
/**
|
||||
* Render to the next postprocessing pass (or to the canvas if final pass).
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState current frame state
|
||||
* @param {WebGLPostProcessingPass} [nextPass] Next pass, optional
|
||||
* @param {function(WebGLRenderingContext, import("../PluggableMap.js").FrameState):void} [preCompose] Called before composing.
|
||||
* @param {function(WebGLRenderingContext, import("../PluggableMap.js").FrameState):void} [postCompose] Called before composing.
|
||||
* @api
|
||||
*/
|
||||
apply(frameState: import("../PluggableMap.js").FrameState, nextPass?: WebGLPostProcessingPass | undefined, preCompose?: ((arg0: WebGLRenderingContext, arg1: import("../PluggableMap.js").FrameState) => void) | undefined, postCompose?: ((arg0: WebGLRenderingContext, arg1: import("../PluggableMap.js").FrameState) => void) | undefined): void;
|
||||
/**
|
||||
* @return {WebGLFramebuffer} Frame buffer
|
||||
* @api
|
||||
*/
|
||||
getFrameBuffer(): WebGLFramebuffer;
|
||||
/**
|
||||
* Sets the custom uniforms based on what was given in the constructor.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState Frame state.
|
||||
* @private
|
||||
*/
|
||||
private applyUniforms;
|
||||
}
|
||||
//# sourceMappingURL=PostProcessingPass.d.ts.map
|
||||
1
node_modules/ol/webgl/PostProcessingPass.d.ts.map
generated
vendored
Normal file
1
node_modules/ol/webgl/PostProcessingPass.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PostProcessingPass.d.ts","sourceRoot":"","sources":["../src/webgl/PostProcessingPass.js"],"names":[],"mappings":";;;;;kBAqCc,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;WAUrB,OAAO,UAAU,EAAE,YAAY;;;;cAC/B,MAAM;;;;;;AAbpB;;;;;;;;GAQG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH;IACE;;OAEG;IACH,qBAFW,OAAO,EA0EjB;IAvEC,2BAA+B;IAG/B,oBAA0C;IAE1C,0CAA8C;IAC9C,0CAAoC;IAEpC,sCAA0C;IAgB1C,0CAA8C;IAM9C,gDAAoD;IASpD,oCAGC;IACD,0DAGC;IACD,0DAGC;IACD,0DAGC;IAED;;;;OAIG;IACH,kBAAmB;IAYrB;;;;OAIG;IACH,SAHY,qBAAqB,CAKhC;IAED;;;;;;OAMG;IACH,iBAHW,OAAO,oBAAoB,EAAE,UAAU,QAuDjD;IAED;;;;;;;OAOG;IACH,kBANW,OAAO,oBAAoB,EAAE,UAAU,uEAE9B,qBAAqB,QAAE,OAAO,oBAAoB,EAAE,UAAU,KAAE,IAAI,qCACpE,qBAAqB,QAAE,OAAO,oBAAoB,EAAE,UAAU,KAAE,IAAI,qBA4DvF;IAED;;;OAGG;IACH,kBAHY,gBAAgB,CAK3B;IAED;;;;OAIG;IACH,sBAwEC;CACF"}
|
||||
274
node_modules/ol/webgl/PostProcessingPass.js
generated
vendored
Normal file
274
node_modules/ol/webgl/PostProcessingPass.js
generated
vendored
Normal file
@@ -0,0 +1,274 @@
|
||||
/**
|
||||
* @module ol/webgl/PostProcessingPass
|
||||
*/
|
||||
import { getUid } from '../util.js';
|
||||
var DEFAULT_VERTEX_SHADER = "\n precision mediump float;\n \n attribute vec2 a_position;\n varying vec2 v_texCoord;\n varying vec2 v_screenCoord;\n \n uniform vec2 u_screenSize;\n \n void main() {\n v_texCoord = a_position * 0.5 + 0.5;\n v_screenCoord = v_texCoord * u_screenSize;\n gl_Position = vec4(a_position, 0.0, 1.0);\n }\n";
|
||||
var DEFAULT_FRAGMENT_SHADER = "\n precision mediump float;\n \n uniform sampler2D u_image;\n uniform float u_opacity;\n \n varying vec2 v_texCoord;\n \n void main() {\n gl_FragColor = texture2D(u_image, v_texCoord) * u_opacity;\n }\n";
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {WebGLRenderingContext} webGlContext WebGL context; mandatory.
|
||||
* @property {number} [scaleRatio] Scale ratio; if < 1, the post process will render to a texture smaller than
|
||||
* the main canvas that will then be sampled up (useful for saving resource on blur steps).
|
||||
* @property {string} [vertexShader] Vertex shader source
|
||||
* @property {string} [fragmentShader] Fragment shader source
|
||||
* @property {Object<string,import("./Helper").UniformValue>} [uniforms] Uniform definitions for the post process step
|
||||
*/
|
||||
/**
|
||||
* @typedef {Object} UniformInternalDescription
|
||||
* @property {import("./Helper").UniformValue} value Value
|
||||
* @property {number} location Location
|
||||
* @property {WebGLTexture} [texture] Texture
|
||||
* @private
|
||||
*/
|
||||
/**
|
||||
* @classdesc
|
||||
* This class is used to define Post Processing passes with custom shaders and uniforms.
|
||||
* This is used internally by {@link module:ol/webgl/Helper~WebGLHelper}.
|
||||
*
|
||||
* Please note that the final output on the DOM canvas is expected to have premultiplied alpha, which means that
|
||||
* a pixel which is 100% red with an opacity of 50% must have a color of (r=0.5, g=0, b=0, a=0.5).
|
||||
* Failing to provide pixel colors with premultiplied alpha will result in render anomalies.
|
||||
*
|
||||
* The default post-processing pass does *not* multiply color values with alpha value, it expects color values to be
|
||||
* premultiplied.
|
||||
*
|
||||
* Default shaders are shown hereafter:
|
||||
*
|
||||
* * Vertex shader:
|
||||
*
|
||||
* ```
|
||||
* precision mediump float;
|
||||
*
|
||||
* attribute vec2 a_position;
|
||||
* varying vec2 v_texCoord;
|
||||
* varying vec2 v_screenCoord;
|
||||
*
|
||||
* uniform vec2 u_screenSize;
|
||||
*
|
||||
* void main() {
|
||||
* v_texCoord = a_position * 0.5 + 0.5;
|
||||
* v_screenCoord = v_texCoord * u_screenSize;
|
||||
* gl_Position = vec4(a_position, 0.0, 1.0);
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* * Fragment shader:
|
||||
*
|
||||
* ```
|
||||
* precision mediump float;
|
||||
*
|
||||
* uniform sampler2D u_image;
|
||||
* uniform float u_opacity;
|
||||
*
|
||||
* varying vec2 v_texCoord;
|
||||
*
|
||||
* void main() {
|
||||
* gl_FragColor = texture2D(u_image, v_texCoord) * u_opacity;
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
var WebGLPostProcessingPass = /** @class */ (function () {
|
||||
/**
|
||||
* @param {Options} options Options.
|
||||
*/
|
||||
function WebGLPostProcessingPass(options) {
|
||||
this.gl_ = options.webGlContext;
|
||||
var gl = this.gl_;
|
||||
this.scaleRatio_ = options.scaleRatio || 1;
|
||||
this.renderTargetTexture_ = gl.createTexture();
|
||||
this.renderTargetTextureSize_ = null;
|
||||
this.frameBuffer_ = gl.createFramebuffer();
|
||||
// compile the program for the frame buffer
|
||||
// TODO: make compilation errors show up
|
||||
var vertexShader = gl.createShader(gl.VERTEX_SHADER);
|
||||
gl.shaderSource(vertexShader, options.vertexShader || DEFAULT_VERTEX_SHADER);
|
||||
gl.compileShader(vertexShader);
|
||||
var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
|
||||
gl.shaderSource(fragmentShader, options.fragmentShader || DEFAULT_FRAGMENT_SHADER);
|
||||
gl.compileShader(fragmentShader);
|
||||
this.renderTargetProgram_ = gl.createProgram();
|
||||
gl.attachShader(this.renderTargetProgram_, vertexShader);
|
||||
gl.attachShader(this.renderTargetProgram_, fragmentShader);
|
||||
gl.linkProgram(this.renderTargetProgram_);
|
||||
// bind the vertices buffer for the frame buffer
|
||||
this.renderTargetVerticesBuffer_ = gl.createBuffer();
|
||||
var verticesArray = [-1, -1, 1, -1, -1, 1, 1, -1, 1, 1, -1, 1];
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.renderTargetVerticesBuffer_);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(verticesArray), gl.STATIC_DRAW);
|
||||
this.renderTargetAttribLocation_ = gl.getAttribLocation(this.renderTargetProgram_, 'a_position');
|
||||
this.renderTargetUniformLocation_ = gl.getUniformLocation(this.renderTargetProgram_, 'u_screenSize');
|
||||
this.renderTargetOpacityLocation_ = gl.getUniformLocation(this.renderTargetProgram_, 'u_opacity');
|
||||
this.renderTargetTextureLocation_ = gl.getUniformLocation(this.renderTargetProgram_, 'u_image');
|
||||
/**
|
||||
* Holds info about custom uniforms used in the post processing pass
|
||||
* @type {Array<UniformInternalDescription>}
|
||||
* @private
|
||||
*/
|
||||
this.uniforms_ = [];
|
||||
options.uniforms &&
|
||||
Object.keys(options.uniforms).forEach(function (name) {
|
||||
this.uniforms_.push({
|
||||
value: options.uniforms[name],
|
||||
location: gl.getUniformLocation(this.renderTargetProgram_, name),
|
||||
});
|
||||
}.bind(this));
|
||||
}
|
||||
/**
|
||||
* Get the WebGL rendering context
|
||||
* @return {WebGLRenderingContext} The rendering context.
|
||||
* @api
|
||||
*/
|
||||
WebGLPostProcessingPass.prototype.getGL = function () {
|
||||
return this.gl_;
|
||||
};
|
||||
/**
|
||||
* Initialize the render target texture of the post process, make sure it is at the
|
||||
* right size and bind it as a render target for the next draw calls.
|
||||
* The last step to be initialized will be the one where the primitives are rendered.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState current frame state
|
||||
* @api
|
||||
*/
|
||||
WebGLPostProcessingPass.prototype.init = function (frameState) {
|
||||
var gl = this.getGL();
|
||||
var textureSize = [
|
||||
gl.drawingBufferWidth * this.scaleRatio_,
|
||||
gl.drawingBufferHeight * this.scaleRatio_,
|
||||
];
|
||||
// rendering goes to my buffer
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this.getFrameBuffer());
|
||||
gl.viewport(0, 0, textureSize[0], textureSize[1]);
|
||||
// if size has changed: adjust canvas & render target texture
|
||||
if (!this.renderTargetTextureSize_ ||
|
||||
this.renderTargetTextureSize_[0] !== textureSize[0] ||
|
||||
this.renderTargetTextureSize_[1] !== textureSize[1]) {
|
||||
this.renderTargetTextureSize_ = textureSize;
|
||||
// create a new texture
|
||||
var level = 0;
|
||||
var internalFormat = gl.RGBA;
|
||||
var border = 0;
|
||||
var format = gl.RGBA;
|
||||
var type = gl.UNSIGNED_BYTE;
|
||||
var data = null;
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.renderTargetTexture_);
|
||||
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, textureSize[0], textureSize[1], border, format, type, data);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
// bind the texture to the framebuffer
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.renderTargetTexture_, 0);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Render to the next postprocessing pass (or to the canvas if final pass).
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState current frame state
|
||||
* @param {WebGLPostProcessingPass} [nextPass] Next pass, optional
|
||||
* @param {function(WebGLRenderingContext, import("../PluggableMap.js").FrameState):void} [preCompose] Called before composing.
|
||||
* @param {function(WebGLRenderingContext, import("../PluggableMap.js").FrameState):void} [postCompose] Called before composing.
|
||||
* @api
|
||||
*/
|
||||
WebGLPostProcessingPass.prototype.apply = function (frameState, nextPass, preCompose, postCompose) {
|
||||
var gl = this.getGL();
|
||||
var size = frameState.size;
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, nextPass ? nextPass.getFrameBuffer() : null);
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.renderTargetTexture_);
|
||||
if (!nextPass) {
|
||||
// clear the canvas if we are the first to render to it
|
||||
// and preserveDrawingBuffer is true
|
||||
var canvasId = getUid(gl.canvas);
|
||||
if (!frameState.renderTargets[canvasId]) {
|
||||
var attributes = gl.getContextAttributes();
|
||||
if (attributes && attributes.preserveDrawingBuffer) {
|
||||
gl.clearColor(0.0, 0.0, 0.0, 0.0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
}
|
||||
frameState.renderTargets[canvasId] = true;
|
||||
}
|
||||
}
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
||||
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.renderTargetVerticesBuffer_);
|
||||
gl.useProgram(this.renderTargetProgram_);
|
||||
gl.enableVertexAttribArray(this.renderTargetAttribLocation_);
|
||||
gl.vertexAttribPointer(this.renderTargetAttribLocation_, 2, gl.FLOAT, false, 0, 0);
|
||||
gl.uniform2f(this.renderTargetUniformLocation_, size[0], size[1]);
|
||||
gl.uniform1i(this.renderTargetTextureLocation_, 0);
|
||||
var opacity = frameState.layerStatesArray[frameState.layerIndex].opacity;
|
||||
gl.uniform1f(this.renderTargetOpacityLocation_, opacity);
|
||||
this.applyUniforms(frameState);
|
||||
if (preCompose) {
|
||||
preCompose(gl, frameState);
|
||||
}
|
||||
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
||||
if (postCompose) {
|
||||
postCompose(gl, frameState);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @return {WebGLFramebuffer} Frame buffer
|
||||
* @api
|
||||
*/
|
||||
WebGLPostProcessingPass.prototype.getFrameBuffer = function () {
|
||||
return this.frameBuffer_;
|
||||
};
|
||||
/**
|
||||
* Sets the custom uniforms based on what was given in the constructor.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState Frame state.
|
||||
* @private
|
||||
*/
|
||||
WebGLPostProcessingPass.prototype.applyUniforms = function (frameState) {
|
||||
var gl = this.getGL();
|
||||
var value;
|
||||
var textureSlot = 1;
|
||||
this.uniforms_.forEach(function (uniform) {
|
||||
value =
|
||||
typeof uniform.value === 'function'
|
||||
? uniform.value(frameState)
|
||||
: uniform.value;
|
||||
// apply value based on type
|
||||
if (value instanceof HTMLCanvasElement || value instanceof ImageData) {
|
||||
// create a texture & put data
|
||||
if (!uniform.texture) {
|
||||
uniform.texture = gl.createTexture();
|
||||
}
|
||||
gl.activeTexture(gl["TEXTURE".concat(textureSlot)]);
|
||||
gl.bindTexture(gl.TEXTURE_2D, uniform.texture);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
if (value instanceof ImageData) {
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, value.width, value.height, 0, gl.UNSIGNED_BYTE, new Uint8Array(value.data));
|
||||
}
|
||||
else {
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, value);
|
||||
}
|
||||
// fill texture slots
|
||||
gl.uniform1i(uniform.location, textureSlot++);
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
switch (value.length) {
|
||||
case 2:
|
||||
gl.uniform2f(uniform.location, value[0], value[1]);
|
||||
return;
|
||||
case 3:
|
||||
gl.uniform3f(uniform.location, value[0], value[1], value[2]);
|
||||
return;
|
||||
case 4:
|
||||
gl.uniform4f(uniform.location, value[0], value[1], value[2], value[3]);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (typeof value === 'number') {
|
||||
gl.uniform1f(uniform.location, value);
|
||||
}
|
||||
});
|
||||
};
|
||||
return WebGLPostProcessingPass;
|
||||
}());
|
||||
export default WebGLPostProcessingPass;
|
||||
//# sourceMappingURL=PostProcessingPass.js.map
|
||||
1
node_modules/ol/webgl/PostProcessingPass.js.map
generated
vendored
Normal file
1
node_modules/ol/webgl/PostProcessingPass.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
94
node_modules/ol/webgl/RenderTarget.d.ts
generated
vendored
Normal file
94
node_modules/ol/webgl/RenderTarget.d.ts
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
export default WebGLRenderTarget;
|
||||
/**
|
||||
* @classdesc
|
||||
* This class is a wrapper around the association of both a `WebGLTexture` and a `WebGLFramebuffer` instances,
|
||||
* simplifying initialization and binding for rendering.
|
||||
* @api
|
||||
*/
|
||||
declare class WebGLRenderTarget {
|
||||
/**
|
||||
* @param {import("./Helper.js").default} helper WebGL helper; mandatory.
|
||||
* @param {Array<number>} [opt_size] Expected size of the render target texture; note: this can be changed later on.
|
||||
*/
|
||||
constructor(helper: import("./Helper.js").default, opt_size?: number[] | undefined);
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./Helper.js").default}
|
||||
*/
|
||||
private helper_;
|
||||
/**
|
||||
* @private
|
||||
* @type {WebGLTexture}
|
||||
*/
|
||||
private texture_;
|
||||
/**
|
||||
* @private
|
||||
* @type {WebGLFramebuffer}
|
||||
*/
|
||||
private framebuffer_;
|
||||
/**
|
||||
* @type {Array<number>}
|
||||
* @private
|
||||
*/
|
||||
private size_;
|
||||
/**
|
||||
* @type {Uint8Array}
|
||||
* @private
|
||||
*/
|
||||
private data_;
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
private dataCacheDirty_;
|
||||
/**
|
||||
* Changes the size of the render target texture. Note: will do nothing if the size
|
||||
* is already the same.
|
||||
* @param {Array<number>} size Expected size of the render target texture
|
||||
* @api
|
||||
*/
|
||||
setSize(size: Array<number>): void;
|
||||
/**
|
||||
* Returns the size of the render target texture
|
||||
* @return {Array<number>} Size of the render target texture
|
||||
* @api
|
||||
*/
|
||||
getSize(): Array<number>;
|
||||
/**
|
||||
* This will cause following calls to `#readAll` or `#readPixel` to download the content of the
|
||||
* render target into memory, which is an expensive operation.
|
||||
* This content will be kept in cache but should be cleared after each new render.
|
||||
* @api
|
||||
*/
|
||||
clearCachedData(): void;
|
||||
/**
|
||||
* Returns the full content of the frame buffer as a series of r, g, b, a components
|
||||
* in the 0-255 range (unsigned byte).
|
||||
* @return {Uint8Array} Integer array of color values
|
||||
* @api
|
||||
*/
|
||||
readAll(): Uint8Array;
|
||||
/**
|
||||
* Reads one pixel of the frame buffer as an array of r, g, b, a components
|
||||
* in the 0-255 range (unsigned byte).
|
||||
* If x and/or y are outside of existing data, an array filled with 0 is returned.
|
||||
* @param {number} x Pixel coordinate
|
||||
* @param {number} y Pixel coordinate
|
||||
* @return {Uint8Array} Integer array with one color value (4 components)
|
||||
* @api
|
||||
*/
|
||||
readPixel(x: number, y: number): Uint8Array;
|
||||
/**
|
||||
* @return {WebGLTexture} Texture to render to
|
||||
*/
|
||||
getTexture(): WebGLTexture;
|
||||
/**
|
||||
* @return {WebGLFramebuffer} Frame buffer of the render target
|
||||
*/
|
||||
getFramebuffer(): WebGLFramebuffer;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
private updateSize_;
|
||||
}
|
||||
//# sourceMappingURL=RenderTarget.d.ts.map
|
||||
1
node_modules/ol/webgl/RenderTarget.d.ts.map
generated
vendored
Normal file
1
node_modules/ol/webgl/RenderTarget.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"RenderTarget.d.ts","sourceRoot":"","sources":["../src/webgl/RenderTarget.js"],"names":[],"mappings":";AASA;;;;;GAKG;AACH;IACE;;;OAGG;IACH,oBAHW,OAAO,aAAa,EAAE,OAAO,mCA0CvC;IAtCC;;;OAGG;IACH,gBAAqB;IAGrB;;;OAGG;IACH,iBAAkC;IAElC;;;OAGG;IACH,qBAA0C;IAE1C;;;OAGG;IACH,cAA+B;IAE/B;;;OAGG;IACH,cAA8B;IAE9B;;;OAGG;IACH,wBAA2B;IAK7B;;;;;OAKG;IACH,cAHW,MAAM,MAAM,CAAC,QAUvB;IAED;;;;OAIG;IACH,WAHY,MAAM,MAAM,CAAC,CAKxB;IAED;;;;;OAKG;IACH,wBAEC;IAED;;;;;OAKG;IACH,WAHY,UAAU,CAqBrB;IAED;;;;;;;;OAQG;IACH,aALW,MAAM,KACN,MAAM,GACL,UAAU,CAoBrB;IAED;;OAEG;IACH,cAFY,YAAY,CAIvB;IAED;;OAEG;IACH,kBAFY,gBAAgB,CAI3B;IAED;;OAEG;IACH,oBAiBC;CACF"}
|
||||
152
node_modules/ol/webgl/RenderTarget.js
generated
vendored
Normal file
152
node_modules/ol/webgl/RenderTarget.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
* A wrapper class to simplify rendering to a texture instead of the final canvas
|
||||
* @module ol/webgl/RenderTarget
|
||||
*/
|
||||
import { equals } from '../array.js';
|
||||
// for pixel color reading
|
||||
var tmpArray4 = new Uint8Array(4);
|
||||
/**
|
||||
* @classdesc
|
||||
* This class is a wrapper around the association of both a `WebGLTexture` and a `WebGLFramebuffer` instances,
|
||||
* simplifying initialization and binding for rendering.
|
||||
* @api
|
||||
*/
|
||||
var WebGLRenderTarget = /** @class */ (function () {
|
||||
/**
|
||||
* @param {import("./Helper.js").default} helper WebGL helper; mandatory.
|
||||
* @param {Array<number>} [opt_size] Expected size of the render target texture; note: this can be changed later on.
|
||||
*/
|
||||
function WebGLRenderTarget(helper, opt_size) {
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./Helper.js").default}
|
||||
*/
|
||||
this.helper_ = helper;
|
||||
var gl = helper.getGL();
|
||||
/**
|
||||
* @private
|
||||
* @type {WebGLTexture}
|
||||
*/
|
||||
this.texture_ = gl.createTexture();
|
||||
/**
|
||||
* @private
|
||||
* @type {WebGLFramebuffer}
|
||||
*/
|
||||
this.framebuffer_ = gl.createFramebuffer();
|
||||
/**
|
||||
* @type {Array<number>}
|
||||
* @private
|
||||
*/
|
||||
this.size_ = opt_size || [1, 1];
|
||||
/**
|
||||
* @type {Uint8Array}
|
||||
* @private
|
||||
*/
|
||||
this.data_ = new Uint8Array(0);
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.dataCacheDirty_ = true;
|
||||
this.updateSize_();
|
||||
}
|
||||
/**
|
||||
* Changes the size of the render target texture. Note: will do nothing if the size
|
||||
* is already the same.
|
||||
* @param {Array<number>} size Expected size of the render target texture
|
||||
* @api
|
||||
*/
|
||||
WebGLRenderTarget.prototype.setSize = function (size) {
|
||||
if (equals(size, this.size_)) {
|
||||
return;
|
||||
}
|
||||
this.size_[0] = size[0];
|
||||
this.size_[1] = size[1];
|
||||
this.updateSize_();
|
||||
};
|
||||
/**
|
||||
* Returns the size of the render target texture
|
||||
* @return {Array<number>} Size of the render target texture
|
||||
* @api
|
||||
*/
|
||||
WebGLRenderTarget.prototype.getSize = function () {
|
||||
return this.size_;
|
||||
};
|
||||
/**
|
||||
* This will cause following calls to `#readAll` or `#readPixel` to download the content of the
|
||||
* render target into memory, which is an expensive operation.
|
||||
* This content will be kept in cache but should be cleared after each new render.
|
||||
* @api
|
||||
*/
|
||||
WebGLRenderTarget.prototype.clearCachedData = function () {
|
||||
this.dataCacheDirty_ = true;
|
||||
};
|
||||
/**
|
||||
* Returns the full content of the frame buffer as a series of r, g, b, a components
|
||||
* in the 0-255 range (unsigned byte).
|
||||
* @return {Uint8Array} Integer array of color values
|
||||
* @api
|
||||
*/
|
||||
WebGLRenderTarget.prototype.readAll = function () {
|
||||
if (this.dataCacheDirty_) {
|
||||
var size = this.size_;
|
||||
var gl = this.helper_.getGL();
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer_);
|
||||
gl.readPixels(0, 0, size[0], size[1], gl.RGBA, gl.UNSIGNED_BYTE, this.data_);
|
||||
this.dataCacheDirty_ = false;
|
||||
}
|
||||
return this.data_;
|
||||
};
|
||||
/**
|
||||
* Reads one pixel of the frame buffer as an array of r, g, b, a components
|
||||
* in the 0-255 range (unsigned byte).
|
||||
* If x and/or y are outside of existing data, an array filled with 0 is returned.
|
||||
* @param {number} x Pixel coordinate
|
||||
* @param {number} y Pixel coordinate
|
||||
* @return {Uint8Array} Integer array with one color value (4 components)
|
||||
* @api
|
||||
*/
|
||||
WebGLRenderTarget.prototype.readPixel = function (x, y) {
|
||||
if (x < 0 || y < 0 || x > this.size_[0] || y >= this.size_[1]) {
|
||||
tmpArray4[0] = 0;
|
||||
tmpArray4[1] = 0;
|
||||
tmpArray4[2] = 0;
|
||||
tmpArray4[3] = 0;
|
||||
return tmpArray4;
|
||||
}
|
||||
this.readAll();
|
||||
var index = Math.floor(x) + (this.size_[1] - Math.floor(y) - 1) * this.size_[0];
|
||||
tmpArray4[0] = this.data_[index * 4];
|
||||
tmpArray4[1] = this.data_[index * 4 + 1];
|
||||
tmpArray4[2] = this.data_[index * 4 + 2];
|
||||
tmpArray4[3] = this.data_[index * 4 + 3];
|
||||
return tmpArray4;
|
||||
};
|
||||
/**
|
||||
* @return {WebGLTexture} Texture to render to
|
||||
*/
|
||||
WebGLRenderTarget.prototype.getTexture = function () {
|
||||
return this.texture_;
|
||||
};
|
||||
/**
|
||||
* @return {WebGLFramebuffer} Frame buffer of the render target
|
||||
*/
|
||||
WebGLRenderTarget.prototype.getFramebuffer = function () {
|
||||
return this.framebuffer_;
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
WebGLRenderTarget.prototype.updateSize_ = function () {
|
||||
var size = this.size_;
|
||||
var gl = this.helper_.getGL();
|
||||
this.texture_ = this.helper_.createTexture(size, null, this.texture_);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer_);
|
||||
gl.viewport(0, 0, size[0], size[1]);
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture_, 0);
|
||||
this.data_ = new Uint8Array(size[0] * size[1] * 4);
|
||||
};
|
||||
return WebGLRenderTarget;
|
||||
}());
|
||||
export default WebGLRenderTarget;
|
||||
//# sourceMappingURL=RenderTarget.js.map
|
||||
1
node_modules/ol/webgl/RenderTarget.js.map
generated
vendored
Normal file
1
node_modules/ol/webgl/RenderTarget.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"RenderTarget.js","sourceRoot":"","sources":["../src/webgl/RenderTarget.js"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAEnC,0BAA0B;AAC1B,IAAM,SAAS,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAEpC;;;;;GAKG;AACH;IACE;;;OAGG;IACH,2BAAY,MAAM,EAAE,QAAQ;QAC1B;;;WAGG;QACH,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAM,EAAE,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;QAE1B;;;WAGG;QACH,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC;QAEnC;;;WAGG;QACH,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAC;QAE3C;;;WAGG;QACH,IAAI,CAAC,KAAK,GAAG,QAAQ,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAEhC;;;WAGG;QACH,IAAI,CAAC,KAAK,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;QAE/B;;;WAGG;QACH,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAE5B,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IAED;;;;;OAKG;IACH,mCAAO,GAAP,UAAQ,IAAI;QACV,IAAI,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE;YAC5B,OAAO;SACR;QACD,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,mCAAO,GAAP;QACE,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;;;OAKG;IACH,2CAAe,GAAf;QACE,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACH,mCAAO,GAAP;QACE,IAAI,IAAI,CAAC,eAAe,EAAE;YACxB,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;YACxB,IAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YAEhC,EAAE,CAAC,eAAe,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;YACtD,EAAE,CAAC,UAAU,CACX,CAAC,EACD,CAAC,EACD,IAAI,CAAC,CAAC,CAAC,EACP,IAAI,CAAC,CAAC,CAAC,EACP,EAAE,CAAC,IAAI,EACP,EAAE,CAAC,aAAa,EAChB,IAAI,CAAC,KAAK,CACX,CAAC;YACF,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;SAC9B;QACD,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;;;;;;OAQG;IACH,qCAAS,GAAT,UAAU,CAAC,EAAE,CAAC;QACZ,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;YAC7D,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACjB,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACjB,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACjB,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACjB,OAAO,SAAS,CAAC;SAClB;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAM,KAAK,GACT,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACtE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QACrC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,sCAAU,GAAV;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,0CAAc,GAAd;QACE,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,uCAAW,GAAX;QACE,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAEhC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEtE,EAAE,CAAC,eAAe,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QACtD,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,EAAE,CAAC,oBAAoB,CACrB,EAAE,CAAC,WAAW,EACd,EAAE,CAAC,iBAAiB,EACpB,EAAE,CAAC,UAAU,EACb,IAAI,CAAC,QAAQ,EACb,CAAC,CACF,CAAC;QAEF,IAAI,CAAC,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,CAAC;IACH,wBAAC;AAAD,CAAC,AAzKD,IAyKC;AAED,eAAe,iBAAiB,CAAC"}
|
||||
257
node_modules/ol/webgl/ShaderBuilder.d.ts
generated
vendored
Normal file
257
node_modules/ol/webgl/ShaderBuilder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,257 @@
|
||||
/**
|
||||
* @typedef {Object} StyleParseResult
|
||||
* @property {ShaderBuilder} builder Shader builder pre-configured according to a given style
|
||||
* @property {Object<string,import("./Helper").UniformValue>} uniforms Uniform definitions.
|
||||
* @property {Array<import("../renderer/webgl/PointsLayer").CustomAttribute>} attributes Attribute descriptions.
|
||||
*/
|
||||
/**
|
||||
* Parses a {@link import("../style/literal").LiteralStyle} object and returns a {@link ShaderBuilder}
|
||||
* object that has been configured according to the given style, as well as `attributes` and `uniforms`
|
||||
* arrays to be fed to the `WebGLPointsRenderer` class.
|
||||
*
|
||||
* Also returns `uniforms` and `attributes` properties as expected by the
|
||||
* {@link module:ol/renderer/webgl/PointsLayer~WebGLPointsLayerRenderer}.
|
||||
*
|
||||
* @param {import("../style/literal").LiteralStyle} style Literal style.
|
||||
* @return {StyleParseResult} Result containing shader params, attributes and uniforms.
|
||||
*/
|
||||
export function parseLiteralStyle(style: import("../style/literal").LiteralStyle): StyleParseResult;
|
||||
/**
|
||||
* @typedef {Object} VaryingDescription
|
||||
* @property {string} name Varying name, as will be declared in the header.
|
||||
* @property {string} type Varying type, either `float`, `vec2`, `vec4`...
|
||||
* @property {string} expression Expression which will be assigned to the varying in the vertex shader, and
|
||||
* passed on to the fragment shader.
|
||||
*/
|
||||
/**
|
||||
* @classdesc
|
||||
* This class implements a classic builder pattern for generating many different types of shaders.
|
||||
* Methods can be chained, e. g.:
|
||||
*
|
||||
* ```js
|
||||
* const shader = new ShaderBuilder()
|
||||
* .addVarying('v_width', 'float', 'a_width')
|
||||
* .addUniform('u_time')
|
||||
* .setColorExpression('...')
|
||||
* .setSizeExpression('...')
|
||||
* .outputSymbolFragmentShader();
|
||||
* ```
|
||||
*/
|
||||
export class ShaderBuilder {
|
||||
/**
|
||||
* Uniforms; these will be declared in the header (should include the type).
|
||||
* @type {Array<string>}
|
||||
* @private
|
||||
*/
|
||||
private uniforms;
|
||||
/**
|
||||
* Attributes; these will be declared in the header (should include the type).
|
||||
* @type {Array<string>}
|
||||
* @private
|
||||
*/
|
||||
private attributes;
|
||||
/**
|
||||
* Varyings with a name, a type and an expression.
|
||||
* @type {Array<VaryingDescription>}
|
||||
* @private
|
||||
*/
|
||||
private varyings;
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
private sizeExpression;
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
private rotationExpression;
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
private offsetExpression;
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
private colorExpression;
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
private texCoordExpression;
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
private discardExpression;
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
private rotateWithView;
|
||||
/**
|
||||
* Adds a uniform accessible in both fragment and vertex shaders.
|
||||
* The given name should include a type, such as `sampler2D u_texture`.
|
||||
* @param {string} name Uniform name
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
addUniform(name: string): ShaderBuilder;
|
||||
/**
|
||||
* Adds an attribute accessible in the vertex shader, read from the geometry buffer.
|
||||
* The given name should include a type, such as `vec2 a_position`.
|
||||
* @param {string} name Attribute name
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
addAttribute(name: string): ShaderBuilder;
|
||||
/**
|
||||
* Adds a varying defined in the vertex shader and accessible from the fragment shader.
|
||||
* The type and expression of the varying have to be specified separately.
|
||||
* @param {string} name Varying name
|
||||
* @param {'float'|'vec2'|'vec3'|'vec4'} type Type
|
||||
* @param {string} expression Expression used to assign a value to the varying.
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
addVarying(name: string, type: 'float' | 'vec2' | 'vec3' | 'vec4', expression: string): ShaderBuilder;
|
||||
/**
|
||||
* Sets an expression to compute the size of the shape.
|
||||
* This expression can use all the uniforms and attributes available
|
||||
* in the vertex shader, and should evaluate to a `vec2` value.
|
||||
* @param {string} expression Size expression
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
setSizeExpression(expression: string): ShaderBuilder;
|
||||
/**
|
||||
* Sets an expression to compute the rotation of the shape.
|
||||
* This expression can use all the uniforms and attributes available
|
||||
* in the vertex shader, and should evaluate to a `float` value in radians.
|
||||
* @param {string} expression Size expression
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
setRotationExpression(expression: string): ShaderBuilder;
|
||||
/**
|
||||
* Sets an expression to compute the offset of the symbol from the point center.
|
||||
* This expression can use all the uniforms and attributes available
|
||||
* in the vertex shader, and should evaluate to a `vec2` value.
|
||||
* Note: will only be used for point geometry shaders.
|
||||
* @param {string} expression Offset expression
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
setSymbolOffsetExpression(expression: string): ShaderBuilder;
|
||||
/**
|
||||
* Sets an expression to compute the color of the shape.
|
||||
* This expression can use all the uniforms, varyings and attributes available
|
||||
* in the fragment shader, and should evaluate to a `vec4` value.
|
||||
* @param {string} expression Color expression
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
setColorExpression(expression: string): ShaderBuilder;
|
||||
/**
|
||||
* Sets an expression to compute the texture coordinates of the vertices.
|
||||
* This expression can use all the uniforms and attributes available
|
||||
* in the vertex shader, and should evaluate to a `vec4` value.
|
||||
* @param {string} expression Texture coordinate expression
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
setTextureCoordinateExpression(expression: string): ShaderBuilder;
|
||||
/**
|
||||
* Sets an expression to determine whether a fragment (pixel) should be discarded,
|
||||
* i.e. not drawn at all.
|
||||
* This expression can use all the uniforms, varyings and attributes available
|
||||
* in the fragment shader, and should evaluate to a `bool` value (it will be
|
||||
* used in an `if` statement)
|
||||
* @param {string} expression Fragment discard expression
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
setFragmentDiscardExpression(expression: string): ShaderBuilder;
|
||||
/**
|
||||
* Sets whether the symbols should rotate with the view or stay aligned with the map.
|
||||
* Note: will only be used for point geometry shaders.
|
||||
* @param {boolean} rotateWithView Rotate with view
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
setSymbolRotateWithView(rotateWithView: boolean): ShaderBuilder;
|
||||
/**
|
||||
* @return {string} Previously set size expression
|
||||
*/
|
||||
getSizeExpression(): string;
|
||||
/**
|
||||
* @return {string} Previously set symbol offset expression
|
||||
*/
|
||||
getOffsetExpression(): string;
|
||||
/**
|
||||
* @return {string} Previously set color expression
|
||||
*/
|
||||
getColorExpression(): string;
|
||||
/**
|
||||
* @return {string} Previously set texture coordinate expression
|
||||
*/
|
||||
getTextureCoordinateExpression(): string;
|
||||
/**
|
||||
* @return {string} Previously set fragment discard expression
|
||||
*/
|
||||
getFragmentDiscardExpression(): string;
|
||||
/**
|
||||
* Generates a symbol vertex shader from the builder parameters,
|
||||
* intended to be used on point geometries.
|
||||
*
|
||||
* Three uniforms are hardcoded in all shaders: `u_projectionMatrix`, `u_offsetScaleMatrix`,
|
||||
* `u_offsetRotateMatrix`, `u_time`.
|
||||
*
|
||||
* The following attributes are hardcoded and expected to be present in the vertex buffers:
|
||||
* `vec2 a_position`, `float a_index` (being the index of the vertex in the quad, 0 to 3).
|
||||
*
|
||||
* The following varyings are hardcoded and gives the coordinate of the pixel both in the quad and on the texture:
|
||||
* `vec2 v_quadCoord`, `vec2 v_texCoord`
|
||||
*
|
||||
* @param {boolean} [forHitDetection] If true, the shader will be modified to include hit detection variables
|
||||
* (namely, hit color with encoded feature id).
|
||||
* @return {string} The full shader as a string.
|
||||
*/
|
||||
getSymbolVertexShader(forHitDetection?: boolean | undefined): string;
|
||||
/**
|
||||
* Generates a symbol fragment shader from the builder parameters,
|
||||
* intended to be used on point geometries.
|
||||
*
|
||||
* Expects the following varyings to be transmitted by the vertex shader:
|
||||
* `vec2 v_quadCoord`, `vec2 v_texCoord`
|
||||
*
|
||||
* @param {boolean} [forHitDetection] If true, the shader will be modified to include hit detection variables
|
||||
* (namely, hit color with encoded feature id).
|
||||
* @return {string} The full shader as a string.
|
||||
*/
|
||||
getSymbolFragmentShader(forHitDetection?: boolean | undefined): string;
|
||||
}
|
||||
export type StyleParseResult = {
|
||||
/**
|
||||
* Shader builder pre-configured according to a given style
|
||||
*/
|
||||
builder: ShaderBuilder;
|
||||
/**
|
||||
* Uniform definitions.
|
||||
*/
|
||||
uniforms: {
|
||||
[x: string]: import("./Helper").UniformValue;
|
||||
};
|
||||
/**
|
||||
* Attribute descriptions.
|
||||
*/
|
||||
attributes: Array<import("../renderer/webgl/PointsLayer").CustomAttribute>;
|
||||
};
|
||||
export type VaryingDescription = {
|
||||
/**
|
||||
* Varying name, as will be declared in the header.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Varying type, either `float`, `vec2`, `vec4`...
|
||||
*/
|
||||
type: string;
|
||||
/**
|
||||
* Expression which will be assigned to the varying in the vertex shader, and
|
||||
* passed on to the fragment shader.
|
||||
*/
|
||||
expression: string;
|
||||
};
|
||||
//# sourceMappingURL=ShaderBuilder.d.ts.map
|
||||
1
node_modules/ol/webgl/ShaderBuilder.d.ts.map
generated
vendored
Normal file
1
node_modules/ol/webgl/ShaderBuilder.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ShaderBuilder.d.ts","sourceRoot":"","sources":["../src/webgl/ShaderBuilder.js"],"names":[],"mappings":"AAwZA;;;;;GAKG;AAEH;;;;;;;;;;GAUG;AACH,yCAHW,OAAO,kBAAkB,EAAE,YAAY,GACtC,gBAAgB,CAuK3B;AAnkBD;;;;;;GAMG;AAEH;;;;;;;;;;;;;GAaG;AACH;IAEI;;;;OAIG;IACH,iBAAkB;IAElB;;;;OAIG;IACH,mBAAoB;IAEpB;;;;OAIG;IACH,iBAAkB;IAElB;;;OAGG;IACH,uBAAiC;IAEjC;;;OAGG;IACH,2BAA+B;IAE/B;;;OAGG;IACH,yBAAmC;IAEnC;;;OAGG;IACH,wBAAkC;IAElC;;;OAGG;IACH,2BAAoD;IAEpD;;;OAGG;IACH,0BAAgC;IAEhC;;;OAGG;IACH,uBAA2B;IAG7B;;;;;OAKG;IACH,iBAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;;OAKG;IACH,mBAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;;;;OAOG;IACH,iBALW,MAAM,QACN,OAAO,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,cAC5B,MAAM,GACL,aAAa,CASxB;IAED;;;;;;OAMG;IACH,8BAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;;;OAMG;IACH,kCAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;;;;OAOG;IACH,sCAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;;;OAMG;IACH,+BAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;;;OAMG;IACH,2CAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;;;;;OAQG;IACH,yCAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;;OAKG;IACH,wCAHW,OAAO,GACN,aAAa,CAKxB;IAED;;OAEG;IACH,qBAFY,MAAM,CAIjB;IAED;;OAEG;IACH,uBAFY,MAAM,CAIjB;IAED;;OAEG;IACH,sBAFY,MAAM,CAIjB;IAED;;OAEG;IACH,kCAFY,MAAM,CAIjB;IAED;;OAEG;IACH,gCAFY,MAAM,CAIjB;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,8DAFY,MAAM,CAgFjB;IAED;;;;;;;;;;OAUG;IACH,gEAFY,MAAM,CAuCjB;CACF;;;;;aAIa,aAAa;;;;;YACN,MAAM,GAAC,OAAO,UAAU,EAAE,YAAY;;;;;gBAC7C,MAAM,OAAO,+BAA+B,EAAE,eAAe,CAAC;;;;;;UA9Y9D,MAAM;;;;UACN,MAAM;;;;;gBACN,MAAM"}
|
||||
450
node_modules/ol/webgl/ShaderBuilder.js
generated
vendored
Normal file
450
node_modules/ol/webgl/ShaderBuilder.js
generated
vendored
Normal file
@@ -0,0 +1,450 @@
|
||||
/**
|
||||
* Classes and utilities for generating shaders from literal style objects
|
||||
* @module ol/webgl/ShaderBuilder
|
||||
*/
|
||||
import { ValueTypes, expressionToGlsl, getStringNumberEquivalent, uniformNameForVariable, } from '../style/expressions.js';
|
||||
/**
|
||||
* @typedef {Object} VaryingDescription
|
||||
* @property {string} name Varying name, as will be declared in the header.
|
||||
* @property {string} type Varying type, either `float`, `vec2`, `vec4`...
|
||||
* @property {string} expression Expression which will be assigned to the varying in the vertex shader, and
|
||||
* passed on to the fragment shader.
|
||||
*/
|
||||
/**
|
||||
* @classdesc
|
||||
* This class implements a classic builder pattern for generating many different types of shaders.
|
||||
* Methods can be chained, e. g.:
|
||||
*
|
||||
* ```js
|
||||
* const shader = new ShaderBuilder()
|
||||
* .addVarying('v_width', 'float', 'a_width')
|
||||
* .addUniform('u_time')
|
||||
* .setColorExpression('...')
|
||||
* .setSizeExpression('...')
|
||||
* .outputSymbolFragmentShader();
|
||||
* ```
|
||||
*/
|
||||
var ShaderBuilder = /** @class */ (function () {
|
||||
function ShaderBuilder() {
|
||||
/**
|
||||
* Uniforms; these will be declared in the header (should include the type).
|
||||
* @type {Array<string>}
|
||||
* @private
|
||||
*/
|
||||
this.uniforms = [];
|
||||
/**
|
||||
* Attributes; these will be declared in the header (should include the type).
|
||||
* @type {Array<string>}
|
||||
* @private
|
||||
*/
|
||||
this.attributes = [];
|
||||
/**
|
||||
* Varyings with a name, a type and an expression.
|
||||
* @type {Array<VaryingDescription>}
|
||||
* @private
|
||||
*/
|
||||
this.varyings = [];
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
this.sizeExpression = 'vec2(1.0)';
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
this.rotationExpression = '0.0';
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
this.offsetExpression = 'vec2(0.0)';
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
this.colorExpression = 'vec4(1.0)';
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
this.texCoordExpression = 'vec4(0.0, 0.0, 1.0, 1.0)';
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
this.discardExpression = 'false';
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.rotateWithView = false;
|
||||
}
|
||||
/**
|
||||
* Adds a uniform accessible in both fragment and vertex shaders.
|
||||
* The given name should include a type, such as `sampler2D u_texture`.
|
||||
* @param {string} name Uniform name
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
ShaderBuilder.prototype.addUniform = function (name) {
|
||||
this.uniforms.push(name);
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* Adds an attribute accessible in the vertex shader, read from the geometry buffer.
|
||||
* The given name should include a type, such as `vec2 a_position`.
|
||||
* @param {string} name Attribute name
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
ShaderBuilder.prototype.addAttribute = function (name) {
|
||||
this.attributes.push(name);
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* Adds a varying defined in the vertex shader and accessible from the fragment shader.
|
||||
* The type and expression of the varying have to be specified separately.
|
||||
* @param {string} name Varying name
|
||||
* @param {'float'|'vec2'|'vec3'|'vec4'} type Type
|
||||
* @param {string} expression Expression used to assign a value to the varying.
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
ShaderBuilder.prototype.addVarying = function (name, type, expression) {
|
||||
this.varyings.push({
|
||||
name: name,
|
||||
type: type,
|
||||
expression: expression,
|
||||
});
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* Sets an expression to compute the size of the shape.
|
||||
* This expression can use all the uniforms and attributes available
|
||||
* in the vertex shader, and should evaluate to a `vec2` value.
|
||||
* @param {string} expression Size expression
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
ShaderBuilder.prototype.setSizeExpression = function (expression) {
|
||||
this.sizeExpression = expression;
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* Sets an expression to compute the rotation of the shape.
|
||||
* This expression can use all the uniforms and attributes available
|
||||
* in the vertex shader, and should evaluate to a `float` value in radians.
|
||||
* @param {string} expression Size expression
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
ShaderBuilder.prototype.setRotationExpression = function (expression) {
|
||||
this.rotationExpression = expression;
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* Sets an expression to compute the offset of the symbol from the point center.
|
||||
* This expression can use all the uniforms and attributes available
|
||||
* in the vertex shader, and should evaluate to a `vec2` value.
|
||||
* Note: will only be used for point geometry shaders.
|
||||
* @param {string} expression Offset expression
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
ShaderBuilder.prototype.setSymbolOffsetExpression = function (expression) {
|
||||
this.offsetExpression = expression;
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* Sets an expression to compute the color of the shape.
|
||||
* This expression can use all the uniforms, varyings and attributes available
|
||||
* in the fragment shader, and should evaluate to a `vec4` value.
|
||||
* @param {string} expression Color expression
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
ShaderBuilder.prototype.setColorExpression = function (expression) {
|
||||
this.colorExpression = expression;
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* Sets an expression to compute the texture coordinates of the vertices.
|
||||
* This expression can use all the uniforms and attributes available
|
||||
* in the vertex shader, and should evaluate to a `vec4` value.
|
||||
* @param {string} expression Texture coordinate expression
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
ShaderBuilder.prototype.setTextureCoordinateExpression = function (expression) {
|
||||
this.texCoordExpression = expression;
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* Sets an expression to determine whether a fragment (pixel) should be discarded,
|
||||
* i.e. not drawn at all.
|
||||
* This expression can use all the uniforms, varyings and attributes available
|
||||
* in the fragment shader, and should evaluate to a `bool` value (it will be
|
||||
* used in an `if` statement)
|
||||
* @param {string} expression Fragment discard expression
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
ShaderBuilder.prototype.setFragmentDiscardExpression = function (expression) {
|
||||
this.discardExpression = expression;
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* Sets whether the symbols should rotate with the view or stay aligned with the map.
|
||||
* Note: will only be used for point geometry shaders.
|
||||
* @param {boolean} rotateWithView Rotate with view
|
||||
* @return {ShaderBuilder} the builder object
|
||||
*/
|
||||
ShaderBuilder.prototype.setSymbolRotateWithView = function (rotateWithView) {
|
||||
this.rotateWithView = rotateWithView;
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* @return {string} Previously set size expression
|
||||
*/
|
||||
ShaderBuilder.prototype.getSizeExpression = function () {
|
||||
return this.sizeExpression;
|
||||
};
|
||||
/**
|
||||
* @return {string} Previously set symbol offset expression
|
||||
*/
|
||||
ShaderBuilder.prototype.getOffsetExpression = function () {
|
||||
return this.offsetExpression;
|
||||
};
|
||||
/**
|
||||
* @return {string} Previously set color expression
|
||||
*/
|
||||
ShaderBuilder.prototype.getColorExpression = function () {
|
||||
return this.colorExpression;
|
||||
};
|
||||
/**
|
||||
* @return {string} Previously set texture coordinate expression
|
||||
*/
|
||||
ShaderBuilder.prototype.getTextureCoordinateExpression = function () {
|
||||
return this.texCoordExpression;
|
||||
};
|
||||
/**
|
||||
* @return {string} Previously set fragment discard expression
|
||||
*/
|
||||
ShaderBuilder.prototype.getFragmentDiscardExpression = function () {
|
||||
return this.discardExpression;
|
||||
};
|
||||
/**
|
||||
* Generates a symbol vertex shader from the builder parameters,
|
||||
* intended to be used on point geometries.
|
||||
*
|
||||
* Three uniforms are hardcoded in all shaders: `u_projectionMatrix`, `u_offsetScaleMatrix`,
|
||||
* `u_offsetRotateMatrix`, `u_time`.
|
||||
*
|
||||
* The following attributes are hardcoded and expected to be present in the vertex buffers:
|
||||
* `vec2 a_position`, `float a_index` (being the index of the vertex in the quad, 0 to 3).
|
||||
*
|
||||
* The following varyings are hardcoded and gives the coordinate of the pixel both in the quad and on the texture:
|
||||
* `vec2 v_quadCoord`, `vec2 v_texCoord`
|
||||
*
|
||||
* @param {boolean} [forHitDetection] If true, the shader will be modified to include hit detection variables
|
||||
* (namely, hit color with encoded feature id).
|
||||
* @return {string} The full shader as a string.
|
||||
*/
|
||||
ShaderBuilder.prototype.getSymbolVertexShader = function (forHitDetection) {
|
||||
var offsetMatrix = this.rotateWithView
|
||||
? 'u_offsetScaleMatrix * u_offsetRotateMatrix'
|
||||
: 'u_offsetScaleMatrix';
|
||||
var attributes = this.attributes;
|
||||
var varyings = this.varyings;
|
||||
if (forHitDetection) {
|
||||
attributes = attributes.concat('vec4 a_hitColor');
|
||||
varyings = varyings.concat({
|
||||
name: 'v_hitColor',
|
||||
type: 'vec4',
|
||||
expression: 'a_hitColor',
|
||||
});
|
||||
}
|
||||
return "precision mediump float;\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform mat4 u_offsetRotateMatrix;\nuniform float u_time;\nuniform float u_zoom;\nuniform float u_resolution;\n".concat(this.uniforms
|
||||
.map(function (uniform) {
|
||||
return 'uniform ' + uniform + ';';
|
||||
})
|
||||
.join('\n'), "\nattribute vec2 a_position;\nattribute float a_index;\n").concat(attributes
|
||||
.map(function (attribute) {
|
||||
return 'attribute ' + attribute + ';';
|
||||
})
|
||||
.join('\n'), "\nvarying vec2 v_texCoord;\nvarying vec2 v_quadCoord;\n").concat(varyings
|
||||
.map(function (varying) {
|
||||
return 'varying ' + varying.type + ' ' + varying.name + ';';
|
||||
})
|
||||
.join('\n'), "\nvoid main(void) {\n mat4 offsetMatrix = ").concat(offsetMatrix, ";\n vec2 halfSize = ").concat(this.sizeExpression, " * 0.5;\n vec2 offset = ").concat(this.offsetExpression, ";\n float angle = ").concat(this.rotationExpression, ";\n float offsetX;\n float offsetY;\n if (a_index == 0.0) {\n offsetX = (offset.x - halfSize.x) * cos(angle) + (offset.y - halfSize.y) * sin(angle);\n offsetY = (offset.y - halfSize.y) * cos(angle) - (offset.x - halfSize.x) * sin(angle);\n } else if (a_index == 1.0) {\n offsetX = (offset.x + halfSize.x) * cos(angle) + (offset.y - halfSize.y) * sin(angle);\n offsetY = (offset.y - halfSize.y) * cos(angle) - (offset.x + halfSize.x) * sin(angle);\n } else if (a_index == 2.0) {\n offsetX = (offset.x + halfSize.x) * cos(angle) + (offset.y + halfSize.y) * sin(angle);\n offsetY = (offset.y + halfSize.y) * cos(angle) - (offset.x + halfSize.x) * sin(angle);\n } else {\n offsetX = (offset.x - halfSize.x) * cos(angle) + (offset.y + halfSize.y) * sin(angle);\n offsetY = (offset.y + halfSize.y) * cos(angle) - (offset.x - halfSize.x) * sin(angle);\n }\n vec4 offsets = offsetMatrix * vec4(offsetX, offsetY, 0.0, 0.0);\n gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0) + offsets;\n vec4 texCoord = ").concat(this.texCoordExpression, ";\n float u = a_index == 0.0 || a_index == 3.0 ? texCoord.s : texCoord.p;\n float v = a_index == 2.0 || a_index == 3.0 ? texCoord.t : texCoord.q;\n v_texCoord = vec2(u, v);\n u = a_index == 0.0 || a_index == 3.0 ? 0.0 : 1.0;\n v = a_index == 2.0 || a_index == 3.0 ? 0.0 : 1.0;\n v_quadCoord = vec2(u, v);\n").concat(varyings
|
||||
.map(function (varying) {
|
||||
return ' ' + varying.name + ' = ' + varying.expression + ';';
|
||||
})
|
||||
.join('\n'), "\n}");
|
||||
};
|
||||
/**
|
||||
* Generates a symbol fragment shader from the builder parameters,
|
||||
* intended to be used on point geometries.
|
||||
*
|
||||
* Expects the following varyings to be transmitted by the vertex shader:
|
||||
* `vec2 v_quadCoord`, `vec2 v_texCoord`
|
||||
*
|
||||
* @param {boolean} [forHitDetection] If true, the shader will be modified to include hit detection variables
|
||||
* (namely, hit color with encoded feature id).
|
||||
* @return {string} The full shader as a string.
|
||||
*/
|
||||
ShaderBuilder.prototype.getSymbolFragmentShader = function (forHitDetection) {
|
||||
var hitDetectionBypass = forHitDetection
|
||||
? ' if (gl_FragColor.a < 0.1) { discard; } gl_FragColor = v_hitColor;'
|
||||
: '';
|
||||
var varyings = this.varyings;
|
||||
if (forHitDetection) {
|
||||
varyings = varyings.concat({
|
||||
name: 'v_hitColor',
|
||||
type: 'vec4',
|
||||
expression: 'a_hitColor',
|
||||
});
|
||||
}
|
||||
return "precision mediump float;\nuniform float u_time;\nuniform float u_zoom;\nuniform float u_resolution;\n".concat(this.uniforms
|
||||
.map(function (uniform) {
|
||||
return 'uniform ' + uniform + ';';
|
||||
})
|
||||
.join('\n'), "\nvarying vec2 v_texCoord;\nvarying vec2 v_quadCoord;\n").concat(varyings
|
||||
.map(function (varying) {
|
||||
return 'varying ' + varying.type + ' ' + varying.name + ';';
|
||||
})
|
||||
.join('\n'), "\nvoid main(void) {\n if (").concat(this.discardExpression, ") { discard; }\n gl_FragColor = ").concat(this.colorExpression, ";\n gl_FragColor.rgb *= gl_FragColor.a;\n").concat(hitDetectionBypass, "\n}");
|
||||
};
|
||||
return ShaderBuilder;
|
||||
}());
|
||||
export { ShaderBuilder };
|
||||
/**
|
||||
* @typedef {Object} StyleParseResult
|
||||
* @property {ShaderBuilder} builder Shader builder pre-configured according to a given style
|
||||
* @property {Object<string,import("./Helper").UniformValue>} uniforms Uniform definitions.
|
||||
* @property {Array<import("../renderer/webgl/PointsLayer").CustomAttribute>} attributes Attribute descriptions.
|
||||
*/
|
||||
/**
|
||||
* Parses a {@link import("../style/literal").LiteralStyle} object and returns a {@link ShaderBuilder}
|
||||
* object that has been configured according to the given style, as well as `attributes` and `uniforms`
|
||||
* arrays to be fed to the `WebGLPointsRenderer` class.
|
||||
*
|
||||
* Also returns `uniforms` and `attributes` properties as expected by the
|
||||
* {@link module:ol/renderer/webgl/PointsLayer~WebGLPointsLayerRenderer}.
|
||||
*
|
||||
* @param {import("../style/literal").LiteralStyle} style Literal style.
|
||||
* @return {StyleParseResult} Result containing shader params, attributes and uniforms.
|
||||
*/
|
||||
export function parseLiteralStyle(style) {
|
||||
var symbStyle = style.symbol;
|
||||
var size = symbStyle.size !== undefined ? symbStyle.size : 1;
|
||||
var color = symbStyle.color || 'white';
|
||||
var texCoord = symbStyle.textureCoord || [0, 0, 1, 1];
|
||||
var offset = symbStyle.offset || [0, 0];
|
||||
var opacity = symbStyle.opacity !== undefined ? symbStyle.opacity : 1;
|
||||
var rotation = symbStyle.rotation !== undefined ? symbStyle.rotation : 0;
|
||||
/**
|
||||
* @type {import("../style/expressions.js").ParsingContext}
|
||||
*/
|
||||
var vertContext = {
|
||||
inFragmentShader: false,
|
||||
variables: [],
|
||||
attributes: [],
|
||||
stringLiteralsMap: {},
|
||||
functions: {},
|
||||
};
|
||||
var parsedSize = expressionToGlsl(vertContext, size, ValueTypes.NUMBER_ARRAY | ValueTypes.NUMBER);
|
||||
var parsedOffset = expressionToGlsl(vertContext, offset, ValueTypes.NUMBER_ARRAY);
|
||||
var parsedTexCoord = expressionToGlsl(vertContext, texCoord, ValueTypes.NUMBER_ARRAY);
|
||||
var parsedRotation = expressionToGlsl(vertContext, rotation, ValueTypes.NUMBER);
|
||||
/**
|
||||
* @type {import("../style/expressions.js").ParsingContext}
|
||||
*/
|
||||
var fragContext = {
|
||||
inFragmentShader: true,
|
||||
variables: vertContext.variables,
|
||||
attributes: [],
|
||||
stringLiteralsMap: vertContext.stringLiteralsMap,
|
||||
functions: {},
|
||||
};
|
||||
var parsedColor = expressionToGlsl(fragContext, color, ValueTypes.COLOR);
|
||||
var parsedOpacity = expressionToGlsl(fragContext, opacity, ValueTypes.NUMBER);
|
||||
var opacityFilter = '1.0';
|
||||
var visibleSize = "vec2(".concat(expressionToGlsl(fragContext, size, ValueTypes.NUMBER_ARRAY | ValueTypes.NUMBER), ").x");
|
||||
switch (symbStyle.symbolType) {
|
||||
case 'square':
|
||||
break;
|
||||
case 'image':
|
||||
break;
|
||||
// taken from https://thebookofshaders.com/07/
|
||||
case 'circle':
|
||||
opacityFilter = "(1.0-smoothstep(1.-4./".concat(visibleSize, ",1.,dot(v_quadCoord-.5,v_quadCoord-.5)*4.))");
|
||||
break;
|
||||
case 'triangle':
|
||||
var st = '(v_quadCoord*2.-1.)';
|
||||
var a = "(atan(".concat(st, ".x,").concat(st, ".y))");
|
||||
opacityFilter = "(1.0-smoothstep(.5-3./".concat(visibleSize, ",.5,cos(floor(.5+").concat(a, "/2.094395102)*2.094395102-").concat(a, ")*length(").concat(st, ")))");
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unexpected symbol type: ' + symbStyle.symbolType);
|
||||
}
|
||||
var builder = new ShaderBuilder()
|
||||
.setSizeExpression("vec2(".concat(parsedSize, ")"))
|
||||
.setRotationExpression(parsedRotation)
|
||||
.setSymbolOffsetExpression(parsedOffset)
|
||||
.setTextureCoordinateExpression(parsedTexCoord)
|
||||
.setSymbolRotateWithView(!!symbStyle.rotateWithView)
|
||||
.setColorExpression("vec4(".concat(parsedColor, ".rgb, ").concat(parsedColor, ".a * ").concat(parsedOpacity, " * ").concat(opacityFilter, ")"));
|
||||
if (style.filter) {
|
||||
var parsedFilter = expressionToGlsl(fragContext, style.filter, ValueTypes.BOOLEAN);
|
||||
builder.setFragmentDiscardExpression("!".concat(parsedFilter));
|
||||
}
|
||||
/** @type {Object<string,import("../webgl/Helper").UniformValue>} */
|
||||
var uniforms = {};
|
||||
// define one uniform per variable
|
||||
fragContext.variables.forEach(function (varName) {
|
||||
var uniformName = uniformNameForVariable(varName);
|
||||
builder.addUniform("float ".concat(uniformName));
|
||||
uniforms[uniformName] = function () {
|
||||
if (!style.variables || style.variables[varName] === undefined) {
|
||||
throw new Error("The following variable is missing from the style: ".concat(varName));
|
||||
}
|
||||
var value = style.variables[varName];
|
||||
if (typeof value === 'string') {
|
||||
value = getStringNumberEquivalent(vertContext, value);
|
||||
}
|
||||
return value !== undefined ? value : -9999999; // to avoid matching with the first string literal
|
||||
};
|
||||
});
|
||||
if (symbStyle.symbolType === 'image' && symbStyle.src) {
|
||||
var texture = new Image();
|
||||
texture.crossOrigin =
|
||||
symbStyle.crossOrigin === undefined ? 'anonymous' : symbStyle.crossOrigin;
|
||||
texture.src = symbStyle.src;
|
||||
builder
|
||||
.addUniform('sampler2D u_texture')
|
||||
.setColorExpression(builder.getColorExpression() + ' * texture2D(u_texture, v_texCoord)');
|
||||
uniforms['u_texture'] = texture;
|
||||
}
|
||||
// for each feature attribute used in the fragment shader, define a varying that will be used to pass data
|
||||
// from the vertex to the fragment shader, as well as an attribute in the vertex shader (if not already present)
|
||||
fragContext.attributes.forEach(function (attrName) {
|
||||
if (vertContext.attributes.indexOf(attrName) === -1) {
|
||||
vertContext.attributes.push(attrName);
|
||||
}
|
||||
builder.addVarying("v_".concat(attrName), 'float', "a_".concat(attrName));
|
||||
});
|
||||
// for each feature attribute used in the vertex shader, define an attribute in the vertex shader.
|
||||
vertContext.attributes.forEach(function (attrName) {
|
||||
builder.addAttribute("float a_".concat(attrName));
|
||||
});
|
||||
return {
|
||||
builder: builder,
|
||||
attributes: vertContext.attributes.map(function (attributeName) {
|
||||
return {
|
||||
name: attributeName,
|
||||
callback: function (feature, props) {
|
||||
var value = props[attributeName];
|
||||
if (typeof value === 'string') {
|
||||
value = getStringNumberEquivalent(vertContext, value);
|
||||
}
|
||||
return value !== undefined ? value : -9999999; // to avoid matching with the first string literal
|
||||
},
|
||||
};
|
||||
}),
|
||||
uniforms: uniforms,
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=ShaderBuilder.js.map
|
||||
1
node_modules/ol/webgl/ShaderBuilder.js.map
generated
vendored
Normal file
1
node_modules/ol/webgl/ShaderBuilder.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
86
node_modules/ol/webgl/TileTexture.d.ts
generated
vendored
Normal file
86
node_modules/ol/webgl/TileTexture.d.ts
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
export default TileTexture;
|
||||
export type TileType = import("../DataTile.js").default | ImageTile | ReprojTile;
|
||||
export type Options = {
|
||||
/**
|
||||
* The tile.
|
||||
*/
|
||||
tile: TileType;
|
||||
/**
|
||||
* Tile grid.
|
||||
*/
|
||||
grid: import("../tilegrid/TileGrid.js").default;
|
||||
/**
|
||||
* WebGL helper.
|
||||
*/
|
||||
helper: import("../webgl/Helper.js").default;
|
||||
/**
|
||||
* The size in pixels of the gutter around image tiles to ignore.
|
||||
*/
|
||||
gutter?: number | undefined;
|
||||
};
|
||||
/**
|
||||
* @typedef {import("../DataTile.js").default|ImageTile|ReprojTile} TileType
|
||||
*/
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {TileType} tile The tile.
|
||||
* @property {import("../tilegrid/TileGrid.js").default} grid Tile grid.
|
||||
* @property {import("../webgl/Helper.js").default} helper WebGL helper.
|
||||
* @property {number} [gutter=0] The size in pixels of the gutter around image tiles to ignore.
|
||||
*/
|
||||
declare class TileTexture extends EventTarget {
|
||||
/**
|
||||
* @param {Options} options The tile texture options.
|
||||
*/
|
||||
constructor(options: Options);
|
||||
/**
|
||||
* @type {TileType}
|
||||
*/
|
||||
tile: TileType;
|
||||
/**
|
||||
* @type {Array<WebGLTexture>}
|
||||
*/
|
||||
textures: Array<WebGLTexture>;
|
||||
handleTileChange_(): void;
|
||||
/**
|
||||
* @type {import("../size.js").Size}
|
||||
* @private
|
||||
*/
|
||||
private renderSize_;
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
private gutter_;
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
bandCount: number;
|
||||
/**
|
||||
* @type {import("../webgl/Helper.js").default}
|
||||
* @private
|
||||
*/
|
||||
private helper_;
|
||||
/**
|
||||
* @type {WebGLArrayBuffer}
|
||||
*/
|
||||
coords: WebGLArrayBuffer;
|
||||
/**
|
||||
* @param {TileType} tile Tile.
|
||||
*/
|
||||
setTile(tile: TileType): void;
|
||||
loaded: boolean | undefined;
|
||||
uploadTile_(): void;
|
||||
/**
|
||||
* Get data for a pixel. If the tile is not loaded, null is returned.
|
||||
* @param {number} renderCol The column index (in rendered tile space).
|
||||
* @param {number} renderRow The row index (in rendered tile space).
|
||||
* @return {import("../DataTile.js").Data|null} The data.
|
||||
*/
|
||||
getPixelData(renderCol: number, renderRow: number): import("../DataTile.js").Data | null;
|
||||
}
|
||||
import ImageTile from "../ImageTile.js";
|
||||
import ReprojTile from "../reproj/Tile.js";
|
||||
import EventTarget from "../events/Target.js";
|
||||
import WebGLArrayBuffer from "./Buffer.js";
|
||||
//# sourceMappingURL=TileTexture.d.ts.map
|
||||
1
node_modules/ol/webgl/TileTexture.d.ts.map
generated
vendored
Normal file
1
node_modules/ol/webgl/TileTexture.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"TileTexture.d.ts","sourceRoot":"","sources":["../src/webgl/TileTexture.js"],"names":[],"mappings":";uBAoIa,OAAO,gBAAgB,EAAE,OAAO,GAAC,SAAS,GAAC,UAAU;;;;;UAKpD,QAAQ;;;;UACR,OAAO,yBAAyB,EAAE,OAAO;;;;YACzC,OAAO,oBAAoB,EAAE,OAAO;;;;;;AARlD;;GAEG;AAEH;;;;;;GAMG;AAEH;IACE;;OAEG;IACH,qBAFW,OAAO,EA4DjB;IAvDC;;OAEG;IACH,MAFU,QAAQ,CAET;IAET;;OAEG;IACH,UAFU,MAAM,YAAY,CAAC,CAEX;IAiKpB,0BAMC;IApKC;;;OAGG;IACH,oBAEC;IAED;;;OAGG;IACH,gBAAkC;IAElC;;OAEG;IACH,WAFU,MAAM,CAEI;IAEpB;;;OAGG;IACH,gBAA6B;IAe7B;;OAEG;IACH,QAFU,gBAAgB,CAEN;IAKtB;;OAEG;IACH,cAFW,QAAQ,QAsBlB;IAbG,4BAAkD;IAetD,oBAqFC;IAmBD;;;;;OAKG;IACH,wBAJW,MAAM,aACN,MAAM,GACL,OAAO,gBAAgB,EAAE,IAAI,GAAC,IAAI,CAkE7C;CACF"}
|
||||
346
node_modules/ol/webgl/TileTexture.js
generated
vendored
Normal file
346
node_modules/ol/webgl/TileTexture.js
generated
vendored
Normal file
@@ -0,0 +1,346 @@
|
||||
/**
|
||||
* @module ol/webgl/TileTexture
|
||||
*/
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import DataTile from '../DataTile.js';
|
||||
import EventTarget from '../events/Target.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import ImageTile from '../ImageTile.js';
|
||||
import ReprojTile from '../reproj/Tile.js';
|
||||
import TileState from '../TileState.js';
|
||||
import WebGLArrayBuffer from './Buffer.js';
|
||||
import { ARRAY_BUFFER, STATIC_DRAW } from '../webgl.js';
|
||||
import { toSize } from '../size.js';
|
||||
/**
|
||||
* @param {WebGLRenderingContext} gl The WebGL context.
|
||||
* @param {WebGLTexture} texture The texture.
|
||||
* @param {boolean} interpolate Interpolate when resampling.
|
||||
*/
|
||||
function bindAndConfigure(gl, texture, interpolate) {
|
||||
var resampleFilter = interpolate ? gl.LINEAR : gl.NEAREST;
|
||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, resampleFilter);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, resampleFilter);
|
||||
}
|
||||
/**
|
||||
* @param {WebGLRenderingContext} gl The WebGL context.
|
||||
* @param {WebGLTexture} texture The texture.
|
||||
* @param {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} image The image.
|
||||
* @param {boolean} interpolate Interpolate when resampling.
|
||||
*/
|
||||
function uploadImageTexture(gl, texture, image, interpolate) {
|
||||
bindAndConfigure(gl, texture, interpolate);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
||||
}
|
||||
/**
|
||||
* @param {import("./Helper.js").default} helper The WebGL helper.
|
||||
* @param {WebGLTexture} texture The texture.
|
||||
* @param {import("../DataTile.js").Data} data The pixel data.
|
||||
* @param {import("../size.js").Size} size The pixel size.
|
||||
* @param {number} bandCount The band count.
|
||||
* @param {boolean} interpolate Interpolate when resampling.
|
||||
*/
|
||||
function uploadDataTexture(helper, texture, data, size, bandCount, interpolate) {
|
||||
var gl = helper.getGL();
|
||||
var textureType;
|
||||
var canInterpolate;
|
||||
if (data instanceof Float32Array) {
|
||||
textureType = gl.FLOAT;
|
||||
helper.getExtension('OES_texture_float');
|
||||
var extension = helper.getExtension('OES_texture_float_linear');
|
||||
canInterpolate = extension !== null;
|
||||
}
|
||||
else {
|
||||
textureType = gl.UNSIGNED_BYTE;
|
||||
canInterpolate = true;
|
||||
}
|
||||
bindAndConfigure(gl, texture, interpolate && canInterpolate);
|
||||
var bytesPerRow = data.byteLength / size[1];
|
||||
var unpackAlignment = 1;
|
||||
if (bytesPerRow % 8 === 0) {
|
||||
unpackAlignment = 8;
|
||||
}
|
||||
else if (bytesPerRow % 4 === 0) {
|
||||
unpackAlignment = 4;
|
||||
}
|
||||
else if (bytesPerRow % 2 === 0) {
|
||||
unpackAlignment = 2;
|
||||
}
|
||||
var format;
|
||||
switch (bandCount) {
|
||||
case 1: {
|
||||
format = gl.LUMINANCE;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
format = gl.LUMINANCE_ALPHA;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
format = gl.RGB;
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
format = gl.RGBA;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error("Unsupported number of bands: ".concat(bandCount));
|
||||
}
|
||||
}
|
||||
var oldUnpackAlignment = gl.getParameter(gl.UNPACK_ALIGNMENT);
|
||||
gl.pixelStorei(gl.UNPACK_ALIGNMENT, unpackAlignment);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, format, size[0], size[1], 0, format, textureType, data);
|
||||
gl.pixelStorei(gl.UNPACK_ALIGNMENT, oldUnpackAlignment);
|
||||
}
|
||||
/**
|
||||
* @type {CanvasRenderingContext2D}
|
||||
*/
|
||||
var pixelContext = null;
|
||||
function createPixelContext() {
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = 1;
|
||||
canvas.height = 1;
|
||||
pixelContext = canvas.getContext('2d');
|
||||
}
|
||||
/**
|
||||
* @typedef {import("../DataTile.js").default|ImageTile|ReprojTile} TileType
|
||||
*/
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {TileType} tile The tile.
|
||||
* @property {import("../tilegrid/TileGrid.js").default} grid Tile grid.
|
||||
* @property {import("../webgl/Helper.js").default} helper WebGL helper.
|
||||
* @property {number} [gutter=0] The size in pixels of the gutter around image tiles to ignore.
|
||||
*/
|
||||
var TileTexture = /** @class */ (function (_super) {
|
||||
__extends(TileTexture, _super);
|
||||
/**
|
||||
* @param {Options} options The tile texture options.
|
||||
*/
|
||||
function TileTexture(options) {
|
||||
var _this = _super.call(this) || this;
|
||||
/**
|
||||
* @type {TileType}
|
||||
*/
|
||||
_this.tile;
|
||||
/**
|
||||
* @type {Array<WebGLTexture>}
|
||||
*/
|
||||
_this.textures = [];
|
||||
_this.handleTileChange_ = _this.handleTileChange_.bind(_this);
|
||||
/**
|
||||
* @type {import("../size.js").Size}
|
||||
* @private
|
||||
*/
|
||||
_this.renderSize_ = toSize(options.grid.getTileSize(options.tile.tileCoord[0]));
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
_this.gutter_ = options.gutter || 0;
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
_this.bandCount = NaN;
|
||||
/**
|
||||
* @type {import("../webgl/Helper.js").default}
|
||||
* @private
|
||||
*/
|
||||
_this.helper_ = options.helper;
|
||||
var coords = new WebGLArrayBuffer(ARRAY_BUFFER, STATIC_DRAW);
|
||||
coords.fromArray([
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
]);
|
||||
_this.helper_.flushBufferData(coords);
|
||||
/**
|
||||
* @type {WebGLArrayBuffer}
|
||||
*/
|
||||
_this.coords = coords;
|
||||
_this.setTile(options.tile);
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* @param {TileType} tile Tile.
|
||||
*/
|
||||
TileTexture.prototype.setTile = function (tile) {
|
||||
if (tile !== this.tile) {
|
||||
if (this.tile) {
|
||||
this.tile.removeEventListener(EventType.CHANGE, this.handleTileChange_);
|
||||
}
|
||||
this.tile = tile;
|
||||
this.textures.length = 0;
|
||||
this.loaded = tile.getState() === TileState.LOADED;
|
||||
if (this.loaded) {
|
||||
this.uploadTile_();
|
||||
}
|
||||
else {
|
||||
if (tile instanceof ImageTile) {
|
||||
var image = tile.getImage();
|
||||
if (image instanceof Image && !image.crossOrigin) {
|
||||
image.crossOrigin = 'anonymous';
|
||||
}
|
||||
}
|
||||
tile.addEventListener(EventType.CHANGE, this.handleTileChange_);
|
||||
}
|
||||
}
|
||||
};
|
||||
TileTexture.prototype.uploadTile_ = function () {
|
||||
var helper = this.helper_;
|
||||
var gl = helper.getGL();
|
||||
var tile = this.tile;
|
||||
if (tile instanceof ImageTile || tile instanceof ReprojTile) {
|
||||
var texture = gl.createTexture();
|
||||
this.textures.push(texture);
|
||||
this.bandCount = 4;
|
||||
uploadImageTexture(gl, texture, tile.getImage(), tile.interpolate);
|
||||
return;
|
||||
}
|
||||
var sourceTileSize = tile.getSize();
|
||||
var pixelSize = [
|
||||
sourceTileSize[0] + 2 * this.gutter_,
|
||||
sourceTileSize[1] + 2 * this.gutter_,
|
||||
];
|
||||
var data = tile.getData();
|
||||
var isFloat = data instanceof Float32Array;
|
||||
var pixelCount = pixelSize[0] * pixelSize[1];
|
||||
var DataType = isFloat ? Float32Array : Uint8Array;
|
||||
var bytesPerElement = DataType.BYTES_PER_ELEMENT;
|
||||
var bytesPerRow = data.byteLength / pixelSize[1];
|
||||
this.bandCount = Math.floor(bytesPerRow / bytesPerElement / pixelSize[0]);
|
||||
var textureCount = Math.ceil(this.bandCount / 4);
|
||||
if (textureCount === 1) {
|
||||
var texture = gl.createTexture();
|
||||
this.textures.push(texture);
|
||||
uploadDataTexture(helper, texture, data, pixelSize, this.bandCount, tile.interpolate);
|
||||
return;
|
||||
}
|
||||
var textureDataArrays = new Array(textureCount);
|
||||
for (var textureIndex = 0; textureIndex < textureCount; ++textureIndex) {
|
||||
var texture = gl.createTexture();
|
||||
this.textures.push(texture);
|
||||
var bandCount = textureIndex < textureCount - 1 ? 4 : this.bandCount % 4;
|
||||
textureDataArrays[textureIndex] = new DataType(pixelCount * bandCount);
|
||||
}
|
||||
var dataIndex = 0;
|
||||
var rowOffset = 0;
|
||||
var colCount = pixelSize[0] * this.bandCount;
|
||||
for (var rowIndex = 0; rowIndex < pixelSize[1]; ++rowIndex) {
|
||||
for (var colIndex = 0; colIndex < colCount; ++colIndex) {
|
||||
var dataValue = data[rowOffset + colIndex];
|
||||
var pixelIndex = Math.floor(dataIndex / this.bandCount);
|
||||
var bandIndex = colIndex % this.bandCount;
|
||||
var textureIndex = Math.floor(bandIndex / 4);
|
||||
var textureData = textureDataArrays[textureIndex];
|
||||
var bandCount = textureData.length / pixelCount;
|
||||
var textureBandIndex = bandIndex % 4;
|
||||
textureData[pixelIndex * bandCount + textureBandIndex] = dataValue;
|
||||
++dataIndex;
|
||||
}
|
||||
rowOffset += bytesPerRow / bytesPerElement;
|
||||
}
|
||||
for (var textureIndex = 0; textureIndex < textureCount; ++textureIndex) {
|
||||
var texture = this.textures[textureIndex];
|
||||
var textureData = textureDataArrays[textureIndex];
|
||||
var bandCount = textureData.length / pixelCount;
|
||||
uploadDataTexture(helper, texture, textureData, pixelSize, bandCount, tile.interpolate);
|
||||
}
|
||||
};
|
||||
TileTexture.prototype.handleTileChange_ = function () {
|
||||
if (this.tile.getState() === TileState.LOADED) {
|
||||
this.loaded = true;
|
||||
this.uploadTile_();
|
||||
this.dispatchEvent(EventType.CHANGE);
|
||||
}
|
||||
};
|
||||
TileTexture.prototype.disposeInternal = function () {
|
||||
var gl = this.helper_.getGL();
|
||||
this.helper_.deleteBuffer(this.coords);
|
||||
for (var i = 0; i < this.textures.length; ++i) {
|
||||
gl.deleteTexture(this.textures[i]);
|
||||
}
|
||||
this.tile.removeEventListener(EventType.CHANGE, this.handleTileChange_);
|
||||
};
|
||||
/**
|
||||
* Get data for a pixel. If the tile is not loaded, null is returned.
|
||||
* @param {number} renderCol The column index (in rendered tile space).
|
||||
* @param {number} renderRow The row index (in rendered tile space).
|
||||
* @return {import("../DataTile.js").Data|null} The data.
|
||||
*/
|
||||
TileTexture.prototype.getPixelData = function (renderCol, renderRow) {
|
||||
if (!this.loaded) {
|
||||
return null;
|
||||
}
|
||||
var renderWidth = this.renderSize_[0];
|
||||
var renderHeight = this.renderSize_[1];
|
||||
var gutter = this.gutter_;
|
||||
if (this.tile instanceof DataTile) {
|
||||
var sourceSize = this.tile.getSize();
|
||||
var sourceWidthWithoutGutter_1 = sourceSize[0];
|
||||
var sourceHeightWithoutGutter_1 = sourceSize[1];
|
||||
var sourceWidth_1 = sourceWidthWithoutGutter_1 + 2 * gutter;
|
||||
var sourceHeight_1 = sourceHeightWithoutGutter_1 + 2 * gutter;
|
||||
var sourceCol_1 = gutter +
|
||||
Math.floor(sourceWidthWithoutGutter_1 * (renderCol / renderWidth));
|
||||
var sourceRow_1 = gutter +
|
||||
Math.floor(sourceHeightWithoutGutter_1 * (renderRow / renderHeight));
|
||||
var data_1 = this.tile.getData();
|
||||
if (data_1 instanceof DataView) {
|
||||
var bytesPerPixel = data_1.byteLength / (sourceWidth_1 * sourceHeight_1);
|
||||
var offset_1 = bytesPerPixel * (sourceRow_1 * sourceWidth_1 + sourceCol_1);
|
||||
var buffer = data_1.buffer.slice(offset_1, offset_1 + bytesPerPixel);
|
||||
return new DataView(buffer);
|
||||
}
|
||||
var offset = this.bandCount * (sourceRow_1 * sourceWidth_1 + sourceCol_1);
|
||||
return data_1.slice(offset, offset + this.bandCount);
|
||||
}
|
||||
if (!pixelContext) {
|
||||
createPixelContext();
|
||||
}
|
||||
pixelContext.clearRect(0, 0, 1, 1);
|
||||
var image = this.tile.getImage();
|
||||
var sourceWidth = image.width;
|
||||
var sourceHeight = image.height;
|
||||
var sourceWidthWithoutGutter = sourceWidth - 2 * gutter;
|
||||
var sourceHeightWithoutGutter = sourceHeight - 2 * gutter;
|
||||
var sourceCol = gutter + Math.floor(sourceWidthWithoutGutter * (renderCol / renderWidth));
|
||||
var sourceRow = gutter +
|
||||
Math.floor(sourceHeightWithoutGutter * (renderRow / renderHeight));
|
||||
var data;
|
||||
try {
|
||||
pixelContext.drawImage(image, sourceCol, sourceRow, 1, 1, 0, 0, 1, 1);
|
||||
data = pixelContext.getImageData(0, 0, 1, 1).data;
|
||||
}
|
||||
catch (err) {
|
||||
pixelContext = null;
|
||||
return null;
|
||||
}
|
||||
return data;
|
||||
};
|
||||
return TileTexture;
|
||||
}(EventTarget));
|
||||
export default TileTexture;
|
||||
//# sourceMappingURL=TileTexture.js.map
|
||||
1
node_modules/ol/webgl/TileTexture.js.map
generated
vendored
Normal file
1
node_modules/ol/webgl/TileTexture.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user