Remove the bulk of the WebGL legacy code.
Things left to do: * redo an icon layer example * redo a clipping layer example * update docs where WebGL renderers are mentioned
This commit is contained in:
@@ -1,271 +0,0 @@
|
||||
/**
|
||||
* @module ol/renderer/webgl/ImageLayer
|
||||
*/
|
||||
import {ENABLE_RASTER_REPROJECTION} from '../../reproj/common.js';
|
||||
import ViewHint from '../../ViewHint.js';
|
||||
import {createCanvasContext2D} from '../../dom.js';
|
||||
import {getIntersection, isEmpty} from '../../extent.js';
|
||||
import WebGLLayerRenderer from './Layer.js';
|
||||
import {
|
||||
create as createTransform,
|
||||
rotate as rotateTransform,
|
||||
translate as translateTransform,
|
||||
scale as scaleTransform,
|
||||
reset as resetTransform,
|
||||
apply as applyTransform,
|
||||
invert as invertTransform,
|
||||
multiply as multiplyTransform
|
||||
} from '../../transform.js';
|
||||
import {CLAMP_TO_EDGE} from '../../webgl.js';
|
||||
import {createTexture} from '../../webgl/Context.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* WebGL renderer for image layers.
|
||||
* @api
|
||||
*/
|
||||
class WebGLImageLayerRenderer extends WebGLLayerRenderer {
|
||||
|
||||
/**
|
||||
* @param {import("./Map.js").default} mapRenderer Map renderer.
|
||||
* @param {import("../../layer/Image.js").default} imageLayer Tile layer.
|
||||
*/
|
||||
constructor(mapRenderer, imageLayer) {
|
||||
|
||||
super(mapRenderer, imageLayer);
|
||||
|
||||
/**
|
||||
* The last rendered image.
|
||||
* @private
|
||||
* @type {?import("../../ImageBase.js").default}
|
||||
*/
|
||||
this.image_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {CanvasRenderingContext2D}
|
||||
*/
|
||||
this.hitCanvasContext_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?import("../../transform.js").Transform}
|
||||
*/
|
||||
this.hitTransformationMatrix_ = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../../ImageBase.js").default} image Image.
|
||||
* @private
|
||||
* @return {WebGLTexture} Texture.
|
||||
*/
|
||||
createTexture_(image) {
|
||||
|
||||
// We meet the conditions to work with non-power of two textures.
|
||||
// http://www.khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences#Non-Power_of_Two_Texture_Support
|
||||
// http://learningwebgl.com/blog/?p=2101
|
||||
|
||||
const imageElement = image.getImage();
|
||||
const gl = this.mapRenderer.getGL();
|
||||
|
||||
return createTexture(
|
||||
gl, imageElement, CLAMP_TO_EDGE, CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
prepareFrame(frameState, layerState, context) {
|
||||
|
||||
const gl = this.mapRenderer.getGL();
|
||||
|
||||
const pixelRatio = frameState.pixelRatio;
|
||||
const viewState = frameState.viewState;
|
||||
const viewCenter = viewState.center;
|
||||
const viewResolution = viewState.resolution;
|
||||
const viewRotation = viewState.rotation;
|
||||
|
||||
let image = this.image_;
|
||||
let texture = this.texture;
|
||||
const imageLayer = /** @type {import("../../layer/Image.js").default} */ (this.getLayer());
|
||||
const imageSource = /** @type {import("../../source/Image.js").default} */ (imageLayer.getSource());
|
||||
|
||||
const hints = frameState.viewHints;
|
||||
|
||||
let renderedExtent = frameState.extent;
|
||||
if (layerState.extent !== undefined) {
|
||||
renderedExtent = getIntersection(renderedExtent, layerState.extent);
|
||||
}
|
||||
if (!hints[ViewHint.ANIMATING] && !hints[ViewHint.INTERACTING] &&
|
||||
!isEmpty(renderedExtent)) {
|
||||
let projection = viewState.projection;
|
||||
if (!ENABLE_RASTER_REPROJECTION) {
|
||||
const sourceProjection = imageSource.getProjection();
|
||||
if (sourceProjection) {
|
||||
projection = sourceProjection;
|
||||
}
|
||||
}
|
||||
const image_ = imageSource.getImage(renderedExtent, viewResolution,
|
||||
pixelRatio, projection);
|
||||
if (image_) {
|
||||
const loaded = this.loadImage(image_);
|
||||
if (loaded) {
|
||||
image = image_;
|
||||
texture = this.createTexture_(image_);
|
||||
if (this.texture) {
|
||||
/**
|
||||
* @param {WebGLRenderingContext} gl GL.
|
||||
* @param {WebGLTexture} texture Texture.
|
||||
*/
|
||||
const postRenderFunction = function(gl, texture) {
|
||||
if (!gl.isContextLost()) {
|
||||
gl.deleteTexture(texture);
|
||||
}
|
||||
}.bind(null, gl, this.texture);
|
||||
frameState.postRenderFunctions.push(
|
||||
/** @type {import("../../PluggableMap.js").PostRenderFunction} */ (postRenderFunction)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (image) {
|
||||
const canvas = this.mapRenderer.getContext().getCanvas();
|
||||
|
||||
this.updateProjectionMatrix_(canvas.width, canvas.height,
|
||||
pixelRatio, viewCenter, viewResolution, viewRotation,
|
||||
image.getExtent());
|
||||
this.hitTransformationMatrix_ = null;
|
||||
|
||||
// Translate and scale to flip the Y coord.
|
||||
const texCoordMatrix = this.texCoordMatrix;
|
||||
resetTransform(texCoordMatrix);
|
||||
scaleTransform(texCoordMatrix, 1, -1);
|
||||
translateTransform(texCoordMatrix, 0, -1);
|
||||
|
||||
this.image_ = image;
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
return !!image;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} canvasWidth Canvas width.
|
||||
* @param {number} canvasHeight Canvas height.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {import("../../coordinate.js").Coordinate} viewCenter View center.
|
||||
* @param {number} viewResolution View resolution.
|
||||
* @param {number} viewRotation View rotation.
|
||||
* @param {import("../../extent.js").Extent} imageExtent Image extent.
|
||||
* @private
|
||||
*/
|
||||
updateProjectionMatrix_(
|
||||
canvasWidth,
|
||||
canvasHeight,
|
||||
pixelRatio,
|
||||
viewCenter,
|
||||
viewResolution,
|
||||
viewRotation,
|
||||
imageExtent
|
||||
) {
|
||||
|
||||
const canvasExtentWidth = canvasWidth * viewResolution;
|
||||
const canvasExtentHeight = canvasHeight * viewResolution;
|
||||
|
||||
const projectionMatrix = this.projectionMatrix;
|
||||
resetTransform(projectionMatrix);
|
||||
scaleTransform(projectionMatrix,
|
||||
pixelRatio * 2 / canvasExtentWidth,
|
||||
pixelRatio * 2 / canvasExtentHeight);
|
||||
rotateTransform(projectionMatrix, -viewRotation);
|
||||
translateTransform(projectionMatrix,
|
||||
imageExtent[0] - viewCenter[0],
|
||||
imageExtent[1] - viewCenter[1]);
|
||||
scaleTransform(projectionMatrix,
|
||||
(imageExtent[2] - imageExtent[0]) / 2,
|
||||
(imageExtent[3] - imageExtent[1]) / 2);
|
||||
translateTransform(projectionMatrix, 1, 1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
forEachLayerAtPixel(pixel, frameState, callback, thisArg) {
|
||||
if (!this.image_ || !this.image_.getImage()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const imageSize =
|
||||
[this.image_.getImage().width, this.image_.getImage().height];
|
||||
|
||||
if (!this.hitTransformationMatrix_) {
|
||||
this.hitTransformationMatrix_ = this.getHitTransformationMatrix_(
|
||||
frameState.size, imageSize);
|
||||
}
|
||||
|
||||
const pixelOnFrameBuffer = applyTransform(
|
||||
this.hitTransformationMatrix_, pixel.slice());
|
||||
|
||||
if (pixelOnFrameBuffer[0] < 0 || pixelOnFrameBuffer[0] > imageSize[0] ||
|
||||
pixelOnFrameBuffer[1] < 0 || pixelOnFrameBuffer[1] > imageSize[1]) {
|
||||
// outside the image, no need to check
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!this.hitCanvasContext_) {
|
||||
this.hitCanvasContext_ = createCanvasContext2D(1, 1);
|
||||
}
|
||||
|
||||
this.hitCanvasContext_.clearRect(0, 0, 1, 1);
|
||||
this.hitCanvasContext_.drawImage(this.image_.getImage(),
|
||||
pixelOnFrameBuffer[0], pixelOnFrameBuffer[1], 1, 1, 0, 0, 1, 1);
|
||||
|
||||
const imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data;
|
||||
if (imageData[3] > 0) {
|
||||
return callback.call(thisArg, this.getLayer(), imageData);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The transformation matrix to get the pixel on the image for a
|
||||
* pixel on the map.
|
||||
* @param {import("../../size.js").Size} mapSize The map size.
|
||||
* @param {import("../../size.js").Size} imageSize The image size.
|
||||
* @return {import("../../transform.js").Transform} The transformation matrix.
|
||||
* @private
|
||||
*/
|
||||
getHitTransformationMatrix_(mapSize, imageSize) {
|
||||
// the first matrix takes a map pixel, flips the y-axis and scales to
|
||||
// a range between -1 ... 1
|
||||
const mapCoordTransform = createTransform();
|
||||
translateTransform(mapCoordTransform, -1, -1);
|
||||
scaleTransform(mapCoordTransform, 2 / mapSize[0], 2 / mapSize[1]);
|
||||
translateTransform(mapCoordTransform, 0, mapSize[1]);
|
||||
scaleTransform(mapCoordTransform, 1, -1);
|
||||
|
||||
// the second matrix is the inverse of the projection matrix used in the
|
||||
// shader for drawing
|
||||
const projectionMatrixInv = invertTransform(this.projectionMatrix.slice());
|
||||
|
||||
// the third matrix scales to the image dimensions and flips the y-axis again
|
||||
const transform = createTransform();
|
||||
translateTransform(transform, 0, imageSize[1]);
|
||||
scaleTransform(transform, 1, -1);
|
||||
scaleTransform(transform, imageSize[0] / 2, imageSize[1] / 2);
|
||||
translateTransform(transform, 1, 1);
|
||||
|
||||
multiplyTransform(transform, projectionMatrixInv);
|
||||
multiplyTransform(transform, mapCoordTransform);
|
||||
|
||||
return transform;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default WebGLImageLayerRenderer;
|
||||
@@ -1,263 +0,0 @@
|
||||
/**
|
||||
* @module ol/renderer/webgl/Layer
|
||||
*/
|
||||
import {abstract} from '../../util.js';
|
||||
import RenderEvent from '../../render/Event.js';
|
||||
import RenderEventType from '../../render/EventType.js';
|
||||
import WebGLImmediateRenderer from '../../render/webgl/Immediate.js';
|
||||
import LayerRenderer from '../Layer.js';
|
||||
import {fragment, vertex} from './defaultmapshader.js';
|
||||
import Locations from './defaultmapshader/Locations.js';
|
||||
import {create as createTransform} from '../../transform.js';
|
||||
import {create, fromTransform} from '../../vec/mat4.js';
|
||||
import {ARRAY_BUFFER, FRAMEBUFFER, FLOAT, TEXTURE_2D,
|
||||
TRIANGLE_STRIP, COLOR_ATTACHMENT0} from '../../webgl.js';
|
||||
import WebGLBuffer from '../../webgl/Buffer.js';
|
||||
import {createEmptyTexture} from '../../webgl/Context.js';
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
*/
|
||||
class WebGLLayerRenderer extends LayerRenderer {
|
||||
|
||||
/**
|
||||
* @param {import("./Map.js").default} mapRenderer Map renderer.
|
||||
* @param {import("../../layer/Layer.js").default} layer Layer.
|
||||
*/
|
||||
constructor(mapRenderer, layer) {
|
||||
|
||||
super(layer);
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {import("./Map.js").default}
|
||||
*/
|
||||
this.mapRenderer = mapRenderer;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../../webgl/Buffer.js").default}
|
||||
*/
|
||||
this.arrayBuffer_ = new WebGLBuffer([
|
||||
-1, -1, 0, 0,
|
||||
1, -1, 1, 0,
|
||||
-1, 1, 0, 1,
|
||||
1, 1, 1, 1
|
||||
]);
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {WebGLTexture}
|
||||
*/
|
||||
this.texture = null;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {WebGLFramebuffer}
|
||||
*/
|
||||
this.framebuffer = null;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.framebufferDimension = undefined;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {import("../../transform.js").Transform}
|
||||
*/
|
||||
this.texCoordMatrix = createTransform();
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {import("../../transform.js").Transform}
|
||||
*/
|
||||
this.projectionMatrix = createTransform();
|
||||
|
||||
/**
|
||||
* @type {Array<number>}
|
||||
* @private
|
||||
*/
|
||||
this.tmpMat4_ = create();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./defaultmapshader/Locations.js").default}
|
||||
*/
|
||||
this.defaultLocations_ = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../../PluggableMap.js").FrameState} frameState Frame state.
|
||||
* @param {number} framebufferDimension Framebuffer dimension.
|
||||
* @protected
|
||||
*/
|
||||
bindFramebuffer(frameState, framebufferDimension) {
|
||||
|
||||
const gl = this.mapRenderer.getGL();
|
||||
|
||||
if (this.framebufferDimension === undefined ||
|
||||
this.framebufferDimension != framebufferDimension) {
|
||||
/**
|
||||
* @param {WebGLRenderingContext} gl GL.
|
||||
* @param {WebGLFramebuffer} framebuffer Framebuffer.
|
||||
* @param {WebGLTexture} texture Texture.
|
||||
*/
|
||||
const postRenderFunction = function(gl, framebuffer, texture) {
|
||||
if (!gl.isContextLost()) {
|
||||
gl.deleteFramebuffer(framebuffer);
|
||||
gl.deleteTexture(texture);
|
||||
}
|
||||
}.bind(null, gl, this.framebuffer, this.texture);
|
||||
|
||||
frameState.postRenderFunctions.push(
|
||||
/** @type {import("../../PluggableMap.js").PostRenderFunction} */ (postRenderFunction)
|
||||
);
|
||||
|
||||
const texture = createEmptyTexture(
|
||||
gl, framebufferDimension, framebufferDimension);
|
||||
|
||||
const framebuffer = gl.createFramebuffer();
|
||||
gl.bindFramebuffer(FRAMEBUFFER, framebuffer);
|
||||
gl.framebufferTexture2D(FRAMEBUFFER,
|
||||
COLOR_ATTACHMENT0, TEXTURE_2D, texture, 0);
|
||||
|
||||
this.texture = texture;
|
||||
this.framebuffer = framebuffer;
|
||||
this.framebufferDimension = framebufferDimension;
|
||||
|
||||
} else {
|
||||
gl.bindFramebuffer(FRAMEBUFFER, this.framebuffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../../PluggableMap.js").FrameState} frameState Frame state.
|
||||
* @param {import("../../layer/Layer.js").State} layerState Layer state.
|
||||
* @param {import("../../webgl/Context.js").default} context Context.
|
||||
*/
|
||||
composeFrame(frameState, layerState, context) {
|
||||
|
||||
this.dispatchComposeEvent_(RenderEventType.PRECOMPOSE, context, frameState);
|
||||
|
||||
context.bindBuffer(ARRAY_BUFFER, this.arrayBuffer_);
|
||||
|
||||
const gl = context.getGL();
|
||||
|
||||
const program = context.getProgram(fragment, vertex);
|
||||
|
||||
let locations;
|
||||
if (!this.defaultLocations_) {
|
||||
locations = new Locations(gl, program);
|
||||
this.defaultLocations_ = locations;
|
||||
} else {
|
||||
locations = this.defaultLocations_;
|
||||
}
|
||||
|
||||
if (context.useProgram(program)) {
|
||||
gl.enableVertexAttribArray(locations.a_position);
|
||||
gl.vertexAttribPointer(
|
||||
locations.a_position, 2, FLOAT, false, 16, 0);
|
||||
gl.enableVertexAttribArray(locations.a_texCoord);
|
||||
gl.vertexAttribPointer(
|
||||
locations.a_texCoord, 2, FLOAT, false, 16, 8);
|
||||
gl.uniform1i(locations.u_texture, 0);
|
||||
}
|
||||
|
||||
gl.uniformMatrix4fv(locations.u_texCoordMatrix, false,
|
||||
fromTransform(this.tmpMat4_, this.getTexCoordMatrix()));
|
||||
gl.uniformMatrix4fv(locations.u_projectionMatrix, false,
|
||||
fromTransform(this.tmpMat4_, this.getProjectionMatrix()));
|
||||
gl.uniform1f(locations.u_opacity, layerState.opacity);
|
||||
gl.bindTexture(TEXTURE_2D, this.getTexture());
|
||||
gl.drawArrays(TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
this.dispatchComposeEvent_(RenderEventType.POSTCOMPOSE, context, frameState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../../render/EventType.js").default} type Event type.
|
||||
* @param {import("../../webgl/Context.js").default} context WebGL context.
|
||||
* @param {import("../../PluggableMap.js").FrameState} frameState Frame state.
|
||||
* @private
|
||||
*/
|
||||
dispatchComposeEvent_(type, context, frameState) {
|
||||
const layer = this.getLayer();
|
||||
if (layer.hasListener(type)) {
|
||||
const viewState = frameState.viewState;
|
||||
const resolution = viewState.resolution;
|
||||
const pixelRatio = frameState.pixelRatio;
|
||||
const extent = frameState.extent;
|
||||
const center = viewState.center;
|
||||
const rotation = viewState.rotation;
|
||||
const size = frameState.size;
|
||||
|
||||
const render = new WebGLImmediateRenderer(
|
||||
context, center, resolution, rotation, size, extent, pixelRatio);
|
||||
const composeEvent = new RenderEvent(
|
||||
type, render, frameState, null, context);
|
||||
layer.dispatchEvent(composeEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!import("../../transform.js").Transform} Matrix.
|
||||
*/
|
||||
getTexCoordMatrix() {
|
||||
return this.texCoordMatrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {WebGLTexture} Texture.
|
||||
*/
|
||||
getTexture() {
|
||||
return this.texture;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!import("../../transform.js").Transform} Matrix.
|
||||
*/
|
||||
getProjectionMatrix() {
|
||||
return this.projectionMatrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle webglcontextlost.
|
||||
*/
|
||||
handleWebGLContextLost() {
|
||||
this.texture = null;
|
||||
this.framebuffer = null;
|
||||
this.framebufferDimension = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {import("../../PluggableMap.js").FrameState} frameState Frame state.
|
||||
* @param {import("../../layer/Layer.js").State} layerState Layer state.
|
||||
* @param {import("../../webgl/Context.js").default} context Context.
|
||||
* @return {boolean} whether composeFrame should be called.
|
||||
*/
|
||||
prepareFrame(frameState, layerState, context) {
|
||||
return abstract();
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {import("../../pixel.js").Pixel} pixel Pixel.
|
||||
* @param {import("../../PluggableMap.js").FrameState} frameState FrameState.
|
||||
* @param {function(this: S, import("../../layer/Layer.js").default, (Uint8ClampedArray|Uint8Array)): T} callback Layer
|
||||
* callback.
|
||||
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
||||
* @return {T|undefined} Callback result.
|
||||
* @template S,T,U
|
||||
*/
|
||||
forEachLayerAtPixel(pixel, frameState, callback, thisArg) {
|
||||
return abstract();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default WebGLLayerRenderer;
|
||||
@@ -1,582 +0,0 @@
|
||||
/**
|
||||
* @module ol/renderer/webgl/Map
|
||||
*/
|
||||
|
||||
import {stableSort} from '../../array.js';
|
||||
import {CLASS_UNSELECTABLE} from '../../css.js';
|
||||
import {createCanvasContext2D} from '../../dom.js';
|
||||
import {listen} from '../../events.js';
|
||||
import {visibleAtResolution} from '../../layer/Layer.js';
|
||||
import RenderEvent from '../../render/Event.js';
|
||||
import RenderEventType from '../../render/EventType.js';
|
||||
import WebGLImmediateRenderer from '../../render/webgl/Immediate.js';
|
||||
import MapRenderer, {sortByZIndex} from '../Map.js';
|
||||
import SourceState from '../../source/State.js';
|
||||
import LRUCache from '../../structs/LRUCache.js';
|
||||
import PriorityQueue from '../../structs/PriorityQueue.js';
|
||||
import {BLEND, CLAMP_TO_EDGE, COLOR_BUFFER_BIT, CULL_FACE, DEPTH_TEST, FRAMEBUFFER,
|
||||
getContext, LINEAR, ONE, ONE_MINUS_SRC_ALPHA, RGBA, SCISSOR_TEST, SRC_ALPHA,
|
||||
STENCIL_TEST, TEXTURE0, TEXTURE_2D, TEXTURE_MAG_FILTER, TEXTURE_MIN_FILTER,
|
||||
TEXTURE_WRAP_S, TEXTURE_WRAP_T, UNSIGNED_BYTE} from '../../webgl.js';
|
||||
import WebGLContext from '../../webgl/Context.js';
|
||||
import ContextEventType from '../../webgl/ContextEventType.js';
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} TextureCacheEntry
|
||||
* @property {number} magFilter
|
||||
* @property {number} minFilter
|
||||
* @property {WebGLTexture} texture
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Texture cache high water mark.
|
||||
* @type {number}
|
||||
*/
|
||||
const WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK = 1024;
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* WebGL map renderer.
|
||||
* @api
|
||||
*/
|
||||
class WebGLMapRenderer extends MapRenderer {
|
||||
|
||||
/**
|
||||
* @param {import("../../PluggableMap.js").default} map Map.
|
||||
*/
|
||||
constructor(map) {
|
||||
super(map);
|
||||
|
||||
const container = map.getViewport();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLCanvasElement}
|
||||
*/
|
||||
this.canvas_ = /** @type {HTMLCanvasElement} */
|
||||
(document.createElement('canvas'));
|
||||
this.canvas_.style.width = '100%';
|
||||
this.canvas_.style.height = '100%';
|
||||
this.canvas_.style.display = 'block';
|
||||
this.canvas_.className = CLASS_UNSELECTABLE;
|
||||
container.insertBefore(this.canvas_, container.childNodes[0] || null);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.clipTileCanvasWidth_ = 0;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.clipTileCanvasHeight_ = 0;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {CanvasRenderingContext2D}
|
||||
*/
|
||||
this.clipTileContext_ = createCanvasContext2D();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.renderedVisible_ = true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {WebGLRenderingContext}
|
||||
*/
|
||||
this.gl_ = getContext(this.canvas_, {
|
||||
antialias: true,
|
||||
depth: true,
|
||||
failIfMajorPerformanceCaveat: true,
|
||||
preserveDrawingBuffer: false,
|
||||
stencil: true
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../../webgl/Context.js").default}
|
||||
*/
|
||||
this.context_ = new WebGLContext(this.canvas_, this.gl_);
|
||||
|
||||
listen(this.canvas_, ContextEventType.LOST,
|
||||
this.handleWebGLContextLost, this);
|
||||
listen(this.canvas_, ContextEventType.RESTORED,
|
||||
this.handleWebGLContextRestored, this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../../structs/LRUCache.js").default<TextureCacheEntry|null>}
|
||||
*/
|
||||
this.textureCache_ = new LRUCache();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../../coordinate.js").Coordinate}
|
||||
*/
|
||||
this.focus_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../../structs/PriorityQueue.js").default<Array>}
|
||||
*/
|
||||
this.tileTextureQueue_ = new PriorityQueue(
|
||||
/**
|
||||
* @param {Array<*>} element Element.
|
||||
* @return {number} Priority.
|
||||
* @this {WebGLMapRenderer}
|
||||
*/
|
||||
(function(element) {
|
||||
const tileCenter = /** @type {import("../../coordinate.js").Coordinate} */ (element[1]);
|
||||
const tileResolution = /** @type {number} */ (element[2]);
|
||||
const deltaX = tileCenter[0] - this.focus_[0];
|
||||
const deltaY = tileCenter[1] - this.focus_[1];
|
||||
return 65536 * Math.log(tileResolution) +
|
||||
Math.sqrt(deltaX * deltaX + deltaY * deltaY) / tileResolution;
|
||||
}).bind(this),
|
||||
/**
|
||||
* @param {Array<*>} element Element.
|
||||
* @return {string} Key.
|
||||
*/
|
||||
function(element) {
|
||||
return (
|
||||
/** @type {import("../../Tile.js").default} */ (element[0]).getKey()
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../../PluggableMap.js").default} map Map.
|
||||
* @param {?import("../../PluggableMap.js").FrameState} frameState Frame state.
|
||||
* @return {boolean} false.
|
||||
* @this {WebGLMapRenderer}
|
||||
*/
|
||||
this.loadNextTileTexture_ =
|
||||
function(map, frameState) {
|
||||
if (!this.tileTextureQueue_.isEmpty()) {
|
||||
this.tileTextureQueue_.reprioritize();
|
||||
const element = this.tileTextureQueue_.dequeue();
|
||||
const tile = /** @type {import("../../Tile.js").default} */ (element[0]);
|
||||
const tileSize = /** @type {import("../../size.js").Size} */ (element[3]);
|
||||
const tileGutter = /** @type {number} */ (element[4]);
|
||||
this.bindTileTexture(
|
||||
tile, tileSize, tileGutter, LINEAR, LINEAR);
|
||||
}
|
||||
return false;
|
||||
}.bind(this);
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.textureCacheFrameMarkerCount_ = 0;
|
||||
|
||||
this.initializeGL_();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../../Tile.js").default} tile Tile.
|
||||
* @param {import("../../size.js").Size} tileSize Tile size.
|
||||
* @param {number} tileGutter Tile gutter.
|
||||
* @param {number} magFilter Mag filter.
|
||||
* @param {number} minFilter Min filter.
|
||||
*/
|
||||
bindTileTexture(tile, tileSize, tileGutter, magFilter, minFilter) {
|
||||
const gl = this.getGL();
|
||||
const tileKey = tile.getKey();
|
||||
if (this.textureCache_.containsKey(tileKey)) {
|
||||
const textureCacheEntry = this.textureCache_.get(tileKey);
|
||||
gl.bindTexture(TEXTURE_2D, textureCacheEntry.texture);
|
||||
if (textureCacheEntry.magFilter != magFilter) {
|
||||
gl.texParameteri(
|
||||
TEXTURE_2D, TEXTURE_MAG_FILTER, magFilter);
|
||||
textureCacheEntry.magFilter = magFilter;
|
||||
}
|
||||
if (textureCacheEntry.minFilter != minFilter) {
|
||||
gl.texParameteri(
|
||||
TEXTURE_2D, TEXTURE_MIN_FILTER, minFilter);
|
||||
textureCacheEntry.minFilter = minFilter;
|
||||
}
|
||||
} else {
|
||||
const texture = gl.createTexture();
|
||||
const imageTile = /** @type {import("../../ImageTile.js").default} */ (tile);
|
||||
gl.bindTexture(TEXTURE_2D, texture);
|
||||
if (tileGutter > 0) {
|
||||
const clipTileCanvas = this.clipTileContext_.canvas;
|
||||
const clipTileContext = this.clipTileContext_;
|
||||
if (this.clipTileCanvasWidth_ !== tileSize[0] ||
|
||||
this.clipTileCanvasHeight_ !== tileSize[1]) {
|
||||
clipTileCanvas.width = tileSize[0];
|
||||
clipTileCanvas.height = tileSize[1];
|
||||
this.clipTileCanvasWidth_ = tileSize[0];
|
||||
this.clipTileCanvasHeight_ = tileSize[1];
|
||||
} else {
|
||||
clipTileContext.clearRect(0, 0, tileSize[0], tileSize[1]);
|
||||
}
|
||||
clipTileContext.drawImage(imageTile.getImage(), tileGutter, tileGutter,
|
||||
tileSize[0], tileSize[1], 0, 0, tileSize[0], tileSize[1]);
|
||||
gl.texImage2D(TEXTURE_2D, 0,
|
||||
RGBA, RGBA,
|
||||
UNSIGNED_BYTE, clipTileCanvas);
|
||||
} else {
|
||||
gl.texImage2D(TEXTURE_2D, 0,
|
||||
RGBA, RGBA,
|
||||
UNSIGNED_BYTE, imageTile.getImage());
|
||||
}
|
||||
gl.texParameteri(
|
||||
TEXTURE_2D, TEXTURE_MAG_FILTER, magFilter);
|
||||
gl.texParameteri(
|
||||
TEXTURE_2D, TEXTURE_MIN_FILTER, minFilter);
|
||||
gl.texParameteri(TEXTURE_2D, TEXTURE_WRAP_S,
|
||||
CLAMP_TO_EDGE);
|
||||
gl.texParameteri(TEXTURE_2D, TEXTURE_WRAP_T,
|
||||
CLAMP_TO_EDGE);
|
||||
this.textureCache_.set(tileKey, {
|
||||
texture: texture,
|
||||
magFilter: magFilter,
|
||||
minFilter: minFilter
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../../render/EventType.js").default} type Event type.
|
||||
* @param {import("../../PluggableMap.js").FrameState} frameState Frame state.
|
||||
*/
|
||||
dispatchRenderEvent(type, frameState) {
|
||||
const map = this.getMap();
|
||||
if (map.hasListener(type)) {
|
||||
const context = this.context_;
|
||||
|
||||
const extent = frameState.extent;
|
||||
const size = frameState.size;
|
||||
const viewState = frameState.viewState;
|
||||
const pixelRatio = frameState.pixelRatio;
|
||||
|
||||
const resolution = viewState.resolution;
|
||||
const center = viewState.center;
|
||||
const rotation = viewState.rotation;
|
||||
|
||||
const vectorContext = new WebGLImmediateRenderer(context,
|
||||
center, resolution, rotation, size, extent, pixelRatio);
|
||||
const composeEvent = new RenderEvent(type, vectorContext,
|
||||
frameState, null, context);
|
||||
map.dispatchEvent(composeEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
disposeInternal() {
|
||||
const gl = this.getGL();
|
||||
if (!gl.isContextLost()) {
|
||||
this.textureCache_.forEach(
|
||||
/**
|
||||
* @param {?TextureCacheEntry} textureCacheEntry
|
||||
* Texture cache entry.
|
||||
*/
|
||||
function(textureCacheEntry) {
|
||||
if (textureCacheEntry) {
|
||||
gl.deleteTexture(textureCacheEntry.texture);
|
||||
}
|
||||
});
|
||||
}
|
||||
this.context_.dispose();
|
||||
super.disposeInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../../PluggableMap.js").default} map Map.
|
||||
* @param {import("../../PluggableMap.js").FrameState} frameState Frame state.
|
||||
* @private
|
||||
*/
|
||||
expireCache_(map, frameState) {
|
||||
const gl = this.getGL();
|
||||
let textureCacheEntry;
|
||||
while (this.textureCache_.getCount() - this.textureCacheFrameMarkerCount_ >
|
||||
WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK) {
|
||||
textureCacheEntry = this.textureCache_.peekLast();
|
||||
if (!textureCacheEntry) {
|
||||
if (+this.textureCache_.peekLastKey() == frameState.index) {
|
||||
break;
|
||||
} else {
|
||||
--this.textureCacheFrameMarkerCount_;
|
||||
}
|
||||
} else {
|
||||
gl.deleteTexture(textureCacheEntry.texture);
|
||||
}
|
||||
this.textureCache_.pop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {import("../../webgl/Context.js").default} The context.
|
||||
*/
|
||||
getContext() {
|
||||
return this.context_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {WebGLRenderingContext} GL.
|
||||
*/
|
||||
getGL() {
|
||||
return this.gl_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {import("../../structs/PriorityQueue.js").default<Array>} Tile texture queue.
|
||||
*/
|
||||
getTileTextureQueue() {
|
||||
return this.tileTextureQueue_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../../events/Event.js").default} event Event.
|
||||
* @protected
|
||||
*/
|
||||
handleWebGLContextLost(event) {
|
||||
event.preventDefault();
|
||||
this.textureCache_.clear();
|
||||
this.textureCacheFrameMarkerCount_ = 0;
|
||||
|
||||
const renderers = this.getLayerRenderers();
|
||||
for (const id in renderers) {
|
||||
const renderer = /** @type {import("./Layer.js").default} */ (renderers[id]);
|
||||
renderer.handleWebGLContextLost();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
handleWebGLContextRestored() {
|
||||
this.initializeGL_();
|
||||
this.getMap().render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
initializeGL_() {
|
||||
const gl = this.gl_;
|
||||
gl.activeTexture(TEXTURE0);
|
||||
gl.blendFuncSeparate(
|
||||
SRC_ALPHA, ONE_MINUS_SRC_ALPHA,
|
||||
ONE, ONE_MINUS_SRC_ALPHA);
|
||||
gl.disable(CULL_FACE);
|
||||
gl.disable(DEPTH_TEST);
|
||||
gl.disable(SCISSOR_TEST);
|
||||
gl.disable(STENCIL_TEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../../Tile.js").default} tile Tile.
|
||||
* @return {boolean} Is tile texture loaded.
|
||||
*/
|
||||
isTileTextureLoaded(tile) {
|
||||
return this.textureCache_.containsKey(tile.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
renderFrame(frameState) {
|
||||
|
||||
const context = this.getContext();
|
||||
const gl = this.getGL();
|
||||
|
||||
if (gl.isContextLost()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!frameState) {
|
||||
if (this.renderedVisible_) {
|
||||
this.canvas_.style.display = 'none';
|
||||
this.renderedVisible_ = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
this.focus_ = frameState.focus;
|
||||
|
||||
this.textureCache_.set((-frameState.index).toString(), null);
|
||||
++this.textureCacheFrameMarkerCount_;
|
||||
|
||||
this.dispatchRenderEvent(RenderEventType.PRECOMPOSE, frameState);
|
||||
|
||||
/** @type {Array<import("../../layer/Layer.js").State>} */
|
||||
const layerStatesToDraw = [];
|
||||
const layerStatesArray = frameState.layerStatesArray;
|
||||
stableSort(layerStatesArray, sortByZIndex);
|
||||
|
||||
const viewResolution = frameState.viewState.resolution;
|
||||
let i, ii;
|
||||
for (i = 0, ii = layerStatesArray.length; i < ii; ++i) {
|
||||
const layerState = layerStatesArray[i];
|
||||
if (visibleAtResolution(layerState, viewResolution) &&
|
||||
layerState.sourceState == SourceState.READY) {
|
||||
const layerRenderer = /** @type {import("./Layer.js").default} */ (this.getLayerRenderer(layerState.layer));
|
||||
if (layerRenderer.prepareFrame(frameState, layerState, context)) {
|
||||
layerStatesToDraw.push(layerState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const width = frameState.size[0] * frameState.pixelRatio;
|
||||
const height = frameState.size[1] * frameState.pixelRatio;
|
||||
if (this.canvas_.width != width || this.canvas_.height != height) {
|
||||
this.canvas_.width = width;
|
||||
this.canvas_.height = height;
|
||||
}
|
||||
|
||||
gl.bindFramebuffer(FRAMEBUFFER, null);
|
||||
|
||||
gl.clearColor(0, 0, 0, 0);
|
||||
gl.clear(COLOR_BUFFER_BIT);
|
||||
gl.enable(BLEND);
|
||||
gl.viewport(0, 0, this.canvas_.width, this.canvas_.height);
|
||||
|
||||
for (i = 0, ii = layerStatesToDraw.length; i < ii; ++i) {
|
||||
const layerState = layerStatesToDraw[i];
|
||||
const layerRenderer = /** @type {import("./Layer.js").default} */ (this.getLayerRenderer(layerState.layer));
|
||||
layerRenderer.composeFrame(frameState, layerState, context);
|
||||
}
|
||||
|
||||
if (!this.renderedVisible_) {
|
||||
this.canvas_.style.display = '';
|
||||
this.renderedVisible_ = true;
|
||||
}
|
||||
|
||||
this.calculateMatrices2D(frameState);
|
||||
|
||||
if (this.textureCache_.getCount() - this.textureCacheFrameMarkerCount_ >
|
||||
WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK) {
|
||||
frameState.postRenderFunctions.push(
|
||||
/** @type {import("../../PluggableMap.js").PostRenderFunction} */ (this.expireCache_.bind(this))
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.tileTextureQueue_.isEmpty()) {
|
||||
frameState.postRenderFunctions.push(this.loadNextTileTexture_);
|
||||
frameState.animate = true;
|
||||
}
|
||||
|
||||
this.dispatchRenderEvent(RenderEventType.POSTCOMPOSE, frameState);
|
||||
|
||||
this.scheduleRemoveUnusedLayerRenderers(frameState);
|
||||
this.scheduleExpireIconCache(frameState);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
forEachFeatureAtCoordinate(
|
||||
coordinate,
|
||||
frameState,
|
||||
hitTolerance,
|
||||
callback,
|
||||
thisArg,
|
||||
layerFilter,
|
||||
thisArg2
|
||||
) {
|
||||
let result;
|
||||
|
||||
if (this.getGL().isContextLost()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const viewState = frameState.viewState;
|
||||
|
||||
const layerStates = frameState.layerStatesArray;
|
||||
const numLayers = layerStates.length;
|
||||
let i;
|
||||
for (i = numLayers - 1; i >= 0; --i) {
|
||||
const layerState = layerStates[i];
|
||||
const layer = layerState.layer;
|
||||
if (visibleAtResolution(layerState, viewState.resolution) &&
|
||||
layerFilter.call(thisArg2, layer)) {
|
||||
const layerRenderer = this.getLayerRenderer(layer);
|
||||
result = layerRenderer.forEachFeatureAtCoordinate(
|
||||
coordinate, frameState, hitTolerance, callback);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
hasFeatureAtCoordinate(coordinate, frameState, hitTolerance, layerFilter, thisArg) {
|
||||
let hasFeature = false;
|
||||
|
||||
if (this.getGL().isContextLost()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const viewState = frameState.viewState;
|
||||
|
||||
const layerStates = frameState.layerStatesArray;
|
||||
const numLayers = layerStates.length;
|
||||
let i;
|
||||
for (i = numLayers - 1; i >= 0; --i) {
|
||||
const layerState = layerStates[i];
|
||||
const layer = layerState.layer;
|
||||
if (visibleAtResolution(layerState, viewState.resolution) &&
|
||||
layerFilter.call(thisArg, layer)) {
|
||||
const layerRenderer = this.getLayerRenderer(layer);
|
||||
hasFeature =
|
||||
layerRenderer.hasFeatureAtCoordinate(coordinate, frameState);
|
||||
if (hasFeature) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasFeature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
forEachLayerAtPixel(pixel, frameState, hitTolerance, callback, thisArg, layerFilter, thisArg2) {
|
||||
if (this.getGL().isContextLost()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const viewState = frameState.viewState;
|
||||
let result;
|
||||
|
||||
const layerStates = frameState.layerStatesArray;
|
||||
const numLayers = layerStates.length;
|
||||
let i;
|
||||
for (i = numLayers - 1; i >= 0; --i) {
|
||||
const layerState = layerStates[i];
|
||||
const layer = layerState.layer;
|
||||
if (visibleAtResolution(layerState, viewState.resolution) &&
|
||||
layerFilter.call(thisArg, layer)) {
|
||||
const layerRenderer = /** @type {import("./Layer.js").default} */ (this.getLayerRenderer(layer));
|
||||
result = layerRenderer.forEachLayerAtPixel(
|
||||
pixel, frameState, callback, thisArg);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default WebGLMapRenderer;
|
||||
@@ -1,398 +0,0 @@
|
||||
/**
|
||||
* @module ol/renderer/webgl/TileLayer
|
||||
*/
|
||||
// FIXME large resolutions lead to too large framebuffers :-(
|
||||
// FIXME animated shaders! check in redraw
|
||||
|
||||
import ImageTile from '../../ImageTile.js';
|
||||
import TileRange from '../../TileRange.js';
|
||||
import TileState from '../../TileState.js';
|
||||
import TileSource from '../../source/Tile.js';
|
||||
import {numberSafeCompareFunction} from '../../array.js';
|
||||
import {createEmpty, intersects} from '../../extent.js';
|
||||
import {roundUpToPowerOfTwo} from '../../math.js';
|
||||
import WebGLLayerRenderer from './Layer.js';
|
||||
import {fragment, vertex} from './tilelayershader.js';
|
||||
import Locations from './tilelayershader/Locations.js';
|
||||
import {toSize} from '../../size.js';
|
||||
import {
|
||||
reset as resetTransform,
|
||||
rotate as rotateTransform,
|
||||
scale as scaleTransform,
|
||||
translate as translateTransform,
|
||||
apply as applyTransform
|
||||
} from '../../transform.js';
|
||||
import {COLOR_BUFFER_BIT, BLEND, ARRAY_BUFFER, FLOAT, LINEAR, TRIANGLE_STRIP} from '../../webgl.js';
|
||||
import WebGLBuffer from '../../webgl/Buffer.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* WebGL renderer for tile layers.
|
||||
* @api
|
||||
*/
|
||||
class WebGLTileLayerRenderer extends WebGLLayerRenderer {
|
||||
|
||||
/**
|
||||
* @param {import("./Map.js").default} mapRenderer Map renderer.
|
||||
* @param {import("../../layer/Tile.js").default} tileLayer Tile layer.
|
||||
*/
|
||||
constructor(mapRenderer, tileLayer) {
|
||||
|
||||
super(mapRenderer, tileLayer);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../../webgl/Fragment.js").default}
|
||||
*/
|
||||
this.fragmentShader_ = fragment;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../../webgl/Vertex.js").default}
|
||||
*/
|
||||
this.vertexShader_ = vertex;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./tilelayershader/Locations.js").default}
|
||||
*/
|
||||
this.locations_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../../webgl/Buffer.js").default}
|
||||
*/
|
||||
this.renderArrayBuffer_ = new WebGLBuffer([
|
||||
0, 0, 0, 1,
|
||||
1, 0, 1, 1,
|
||||
0, 1, 0, 0,
|
||||
1, 1, 1, 0
|
||||
]);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../../TileRange.js").default}
|
||||
*/
|
||||
this.renderedTileRange_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../../extent.js").Extent}
|
||||
*/
|
||||
this.renderedFramebufferExtent_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.renderedRevision_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../../size.js").Size}
|
||||
*/
|
||||
this.tmpSize_ = [0, 0];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
disposeInternal() {
|
||||
const context = this.mapRenderer.getContext();
|
||||
context.deleteBuffer(this.renderArrayBuffer_);
|
||||
super.disposeInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
createLoadedTileFinder(source, projection, tiles) {
|
||||
const mapRenderer = this.mapRenderer;
|
||||
|
||||
return (
|
||||
/**
|
||||
* @param {number} zoom Zoom level.
|
||||
* @param {import("../../TileRange.js").default} tileRange Tile range.
|
||||
* @return {boolean} The tile range is fully loaded.
|
||||
*/
|
||||
function(zoom, tileRange) {
|
||||
function callback(tile) {
|
||||
const loaded = mapRenderer.isTileTextureLoaded(tile);
|
||||
if (loaded) {
|
||||
if (!tiles[zoom]) {
|
||||
tiles[zoom] = {};
|
||||
}
|
||||
tiles[zoom][tile.tileCoord.toString()] = tile;
|
||||
}
|
||||
return loaded;
|
||||
}
|
||||
return source.forEachLoadedTile(projection, zoom, tileRange, callback);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
handleWebGLContextLost() {
|
||||
super.handleWebGLContextLost();
|
||||
this.locations_ = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
prepareFrame(frameState, layerState, context) {
|
||||
|
||||
const mapRenderer = this.mapRenderer;
|
||||
const gl = context.getGL();
|
||||
|
||||
const viewState = frameState.viewState;
|
||||
const projection = viewState.projection;
|
||||
|
||||
const tileLayer = /** @type {import("../../layer/Tile.js").default} */ (this.getLayer());
|
||||
const tileSource = tileLayer.getSource();
|
||||
if (!(tileSource instanceof TileSource)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const tileGrid = tileSource.getTileGridForProjection(projection);
|
||||
const z = tileGrid.getZForResolution(viewState.resolution);
|
||||
const tileResolution = tileGrid.getResolution(z);
|
||||
|
||||
const tilePixelSize =
|
||||
tileSource.getTilePixelSize(z, frameState.pixelRatio, projection);
|
||||
const pixelRatio = tilePixelSize[0] /
|
||||
toSize(tileGrid.getTileSize(z), this.tmpSize_)[0];
|
||||
const tilePixelResolution = tileResolution / pixelRatio;
|
||||
const tileGutter = tileSource.getTilePixelRatio(pixelRatio) * tileSource.getGutterForProjection(projection);
|
||||
|
||||
const center = viewState.center;
|
||||
const extent = frameState.extent;
|
||||
const tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
|
||||
|
||||
let framebufferExtent;
|
||||
if (this.renderedTileRange_ &&
|
||||
this.renderedTileRange_.equals(tileRange) &&
|
||||
this.renderedRevision_ == tileSource.getRevision()) {
|
||||
framebufferExtent = this.renderedFramebufferExtent_;
|
||||
} else {
|
||||
|
||||
const tileRangeSize = tileRange.getSize();
|
||||
|
||||
const maxDimension = Math.max(
|
||||
tileRangeSize[0] * tilePixelSize[0],
|
||||
tileRangeSize[1] * tilePixelSize[1]);
|
||||
const framebufferDimension = roundUpToPowerOfTwo(maxDimension);
|
||||
const framebufferExtentDimension = tilePixelResolution * framebufferDimension;
|
||||
const origin = tileGrid.getOrigin(z);
|
||||
const minX = origin[0] +
|
||||
tileRange.minX * tilePixelSize[0] * tilePixelResolution;
|
||||
const minY = origin[1] +
|
||||
tileRange.minY * tilePixelSize[1] * tilePixelResolution;
|
||||
framebufferExtent = [
|
||||
minX, minY,
|
||||
minX + framebufferExtentDimension, minY + framebufferExtentDimension
|
||||
];
|
||||
|
||||
this.bindFramebuffer(frameState, framebufferDimension);
|
||||
gl.viewport(0, 0, framebufferDimension, framebufferDimension);
|
||||
|
||||
gl.clearColor(0, 0, 0, 0);
|
||||
gl.clear(COLOR_BUFFER_BIT);
|
||||
gl.disable(BLEND);
|
||||
|
||||
const program = context.getProgram(this.fragmentShader_, this.vertexShader_);
|
||||
context.useProgram(program);
|
||||
if (!this.locations_) {
|
||||
this.locations_ = new Locations(gl, program);
|
||||
}
|
||||
|
||||
context.bindBuffer(ARRAY_BUFFER, this.renderArrayBuffer_);
|
||||
gl.enableVertexAttribArray(this.locations_.a_position);
|
||||
gl.vertexAttribPointer(
|
||||
this.locations_.a_position, 2, FLOAT, false, 16, 0);
|
||||
gl.enableVertexAttribArray(this.locations_.a_texCoord);
|
||||
gl.vertexAttribPointer(
|
||||
this.locations_.a_texCoord, 2, FLOAT, false, 16, 8);
|
||||
gl.uniform1i(this.locations_.u_texture, 0);
|
||||
|
||||
/**
|
||||
* @type {Object<number, Object<string, import("../../Tile.js").default>>}
|
||||
*/
|
||||
const tilesToDrawByZ = {};
|
||||
tilesToDrawByZ[z] = {};
|
||||
|
||||
const findLoadedTiles = this.createLoadedTileFinder(
|
||||
tileSource, projection, tilesToDrawByZ);
|
||||
|
||||
const useInterimTilesOnError = tileLayer.getUseInterimTilesOnError();
|
||||
let allTilesLoaded = true;
|
||||
const tmpExtent = createEmpty();
|
||||
const tmpTileRange = new TileRange(0, 0, 0, 0);
|
||||
let childTileRange, drawable, fullyLoaded, tile, tileState;
|
||||
let x, y, tileExtent;
|
||||
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
|
||||
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||
|
||||
tile = tileSource.getTile(z, x, y, pixelRatio, projection);
|
||||
if (layerState.extent !== undefined) {
|
||||
// ignore tiles outside layer extent
|
||||
tileExtent = tileGrid.getTileCoordExtent(tile.tileCoord, tmpExtent);
|
||||
if (!intersects(tileExtent, layerState.extent)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
tileState = tile.getState();
|
||||
drawable = tileState == TileState.LOADED ||
|
||||
tileState == TileState.EMPTY ||
|
||||
tileState == TileState.ERROR && !useInterimTilesOnError;
|
||||
if (!drawable) {
|
||||
tile = tile.getInterimTile();
|
||||
}
|
||||
tileState = tile.getState();
|
||||
if (tileState == TileState.LOADED) {
|
||||
if (mapRenderer.isTileTextureLoaded(tile)) {
|
||||
tilesToDrawByZ[z][tile.tileCoord.toString()] = tile;
|
||||
continue;
|
||||
}
|
||||
} else if (tileState == TileState.EMPTY ||
|
||||
(tileState == TileState.ERROR &&
|
||||
!useInterimTilesOnError)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
allTilesLoaded = false;
|
||||
fullyLoaded = tileGrid.forEachTileCoordParentTileRange(
|
||||
tile.tileCoord, findLoadedTiles, null, tmpTileRange, tmpExtent);
|
||||
if (!fullyLoaded) {
|
||||
childTileRange = tileGrid.getTileCoordChildTileRange(
|
||||
tile.tileCoord, tmpTileRange, tmpExtent);
|
||||
if (childTileRange) {
|
||||
findLoadedTiles(z + 1, childTileRange);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** @type {Array<number>} */
|
||||
const zs = Object.keys(tilesToDrawByZ).map(Number);
|
||||
zs.sort(numberSafeCompareFunction);
|
||||
const u_tileOffset = new Float32Array(4);
|
||||
for (let i = 0, ii = zs.length; i < ii; ++i) {
|
||||
const tilesToDraw = tilesToDrawByZ[zs[i]];
|
||||
for (const tileKey in tilesToDraw) {
|
||||
tile = tilesToDraw[tileKey];
|
||||
|
||||
if (!(tile instanceof ImageTile)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tileExtent = tileGrid.getTileCoordExtent(tile.tileCoord, tmpExtent);
|
||||
u_tileOffset[0] = 2 * (tileExtent[2] - tileExtent[0]) /
|
||||
framebufferExtentDimension;
|
||||
u_tileOffset[1] = 2 * (tileExtent[3] - tileExtent[1]) /
|
||||
framebufferExtentDimension;
|
||||
u_tileOffset[2] = 2 * (tileExtent[0] - framebufferExtent[0]) /
|
||||
framebufferExtentDimension - 1;
|
||||
u_tileOffset[3] = 2 * (tileExtent[1] - framebufferExtent[1]) /
|
||||
framebufferExtentDimension - 1;
|
||||
gl.uniform4fv(this.locations_.u_tileOffset, u_tileOffset);
|
||||
mapRenderer.bindTileTexture(tile, tilePixelSize,
|
||||
tileGutter * pixelRatio, LINEAR, LINEAR);
|
||||
gl.drawArrays(TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
}
|
||||
|
||||
if (allTilesLoaded) {
|
||||
this.renderedTileRange_ = tileRange;
|
||||
this.renderedFramebufferExtent_ = framebufferExtent;
|
||||
this.renderedRevision_ = tileSource.getRevision();
|
||||
} else {
|
||||
this.renderedTileRange_ = null;
|
||||
this.renderedFramebufferExtent_ = null;
|
||||
this.renderedRevision_ = -1;
|
||||
frameState.animate = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||
const tileTextureQueue = mapRenderer.getTileTextureQueue();
|
||||
this.manageTilePyramid(
|
||||
frameState, tileSource, tileGrid, pixelRatio, projection, extent, z,
|
||||
tileLayer.getPreload(),
|
||||
/**
|
||||
* @param {import("../../Tile.js").default} tile Tile.
|
||||
*/
|
||||
function(tile) {
|
||||
if (tile.getState() == TileState.LOADED &&
|
||||
!mapRenderer.isTileTextureLoaded(tile) &&
|
||||
!tileTextureQueue.isKeyQueued(tile.getKey())) {
|
||||
tileTextureQueue.enqueue([
|
||||
tile,
|
||||
tileGrid.getTileCoordCenter(tile.tileCoord),
|
||||
tileGrid.getResolution(tile.tileCoord[0]),
|
||||
tilePixelSize, tileGutter * pixelRatio
|
||||
]);
|
||||
}
|
||||
}, this);
|
||||
this.scheduleExpireCache(frameState, tileSource);
|
||||
|
||||
const texCoordMatrix = this.texCoordMatrix;
|
||||
resetTransform(texCoordMatrix);
|
||||
translateTransform(texCoordMatrix,
|
||||
(Math.round(center[0] / tileResolution) * tileResolution - framebufferExtent[0]) /
|
||||
(framebufferExtent[2] - framebufferExtent[0]),
|
||||
(Math.round(center[1] / tileResolution) * tileResolution - framebufferExtent[1]) /
|
||||
(framebufferExtent[3] - framebufferExtent[1]));
|
||||
if (viewState.rotation !== 0) {
|
||||
rotateTransform(texCoordMatrix, viewState.rotation);
|
||||
}
|
||||
scaleTransform(texCoordMatrix,
|
||||
frameState.size[0] * viewState.resolution /
|
||||
(framebufferExtent[2] - framebufferExtent[0]),
|
||||
frameState.size[1] * viewState.resolution /
|
||||
(framebufferExtent[3] - framebufferExtent[1]));
|
||||
translateTransform(texCoordMatrix, -0.5, -0.5);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
forEachLayerAtPixel(pixel, frameState, callback, thisArg) {
|
||||
if (!this.framebuffer) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const pixelOnMapScaled = [
|
||||
pixel[0] / frameState.size[0],
|
||||
(frameState.size[1] - pixel[1]) / frameState.size[1]];
|
||||
|
||||
const pixelOnFrameBufferScaled = applyTransform(
|
||||
this.texCoordMatrix, pixelOnMapScaled.slice());
|
||||
const pixelOnFrameBuffer = [
|
||||
pixelOnFrameBufferScaled[0] * this.framebufferDimension,
|
||||
pixelOnFrameBufferScaled[1] * this.framebufferDimension];
|
||||
|
||||
const gl = this.mapRenderer.getContext().getGL();
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
|
||||
const imageData = new Uint8Array(4);
|
||||
gl.readPixels(pixelOnFrameBuffer[0], pixelOnFrameBuffer[1], 1, 1,
|
||||
gl.RGBA, gl.UNSIGNED_BYTE, imageData);
|
||||
|
||||
if (imageData[3] > 0) {
|
||||
return callback.call(thisArg, this.getLayer(), imageData);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default WebGLTileLayerRenderer;
|
||||
@@ -1,306 +0,0 @@
|
||||
/**
|
||||
* @module ol/renderer/webgl/VectorLayer
|
||||
*/
|
||||
import {getUid} from '../../util.js';
|
||||
import ViewHint from '../../ViewHint.js';
|
||||
import {buffer, containsExtent, createEmpty} from '../../extent.js';
|
||||
import WebGLReplayGroup from '../../render/webgl/ReplayGroup.js';
|
||||
import {defaultOrder as defaultRenderOrder, getTolerance as getRenderTolerance, getSquaredTolerance as getSquaredRenderTolerance, renderFeature} from '../vector.js';
|
||||
import WebGLLayerRenderer from './Layer.js';
|
||||
import {apply as applyTransform} from '../../transform.js';
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* WebGL renderer for vector layers.
|
||||
* @api
|
||||
*/
|
||||
class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
|
||||
|
||||
/**
|
||||
* @param {import("./Map.js").default} mapRenderer Map renderer.
|
||||
* @param {import("../../layer/Vector.js").default} vectorLayer Vector layer.
|
||||
*/
|
||||
constructor(mapRenderer, vectorLayer) {
|
||||
|
||||
super(mapRenderer, vectorLayer);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.dirty_ = false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.renderedRevision_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.renderedResolution_ = NaN;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../../extent.js").Extent}
|
||||
*/
|
||||
this.renderedExtent_ = createEmpty();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {function(import("../../Feature.js").default, import("../../Feature.js").default): number|null}
|
||||
*/
|
||||
this.renderedRenderOrder_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../../render/webgl/ReplayGroup.js").default}
|
||||
*/
|
||||
this.replayGroup_ = null;
|
||||
|
||||
/**
|
||||
* The last layer state.
|
||||
* @private
|
||||
* @type {?import("../../layer/Layer.js").State}
|
||||
*/
|
||||
this.layerState_ = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
composeFrame(frameState, layerState, context) {
|
||||
this.layerState_ = layerState;
|
||||
const viewState = frameState.viewState;
|
||||
const replayGroup = this.replayGroup_;
|
||||
const size = frameState.size;
|
||||
const pixelRatio = frameState.pixelRatio;
|
||||
const gl = this.mapRenderer.getGL();
|
||||
if (replayGroup && !replayGroup.isEmpty()) {
|
||||
gl.enable(gl.SCISSOR_TEST);
|
||||
gl.scissor(0, 0, size[0] * pixelRatio, size[1] * pixelRatio);
|
||||
replayGroup.replay(context,
|
||||
viewState.center, viewState.resolution, viewState.rotation,
|
||||
size, pixelRatio, layerState.opacity,
|
||||
layerState.managed ? frameState.skippedFeatureUids : {});
|
||||
gl.disable(gl.SCISSOR_TEST);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
disposeInternal() {
|
||||
const replayGroup = this.replayGroup_;
|
||||
if (replayGroup) {
|
||||
const context = this.mapRenderer.getContext();
|
||||
replayGroup.getDeleteResourcesFunction(context)();
|
||||
this.replayGroup_ = null;
|
||||
}
|
||||
super.disposeInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback, thisArg) {
|
||||
if (!this.replayGroup_ || !this.layerState_) {
|
||||
return undefined;
|
||||
} else {
|
||||
const context = this.mapRenderer.getContext();
|
||||
const viewState = frameState.viewState;
|
||||
const layer = this.getLayer();
|
||||
const layerState = this.layerState_;
|
||||
/** @type {!Object<string, boolean>} */
|
||||
const features = {};
|
||||
return this.replayGroup_.forEachFeatureAtCoordinate(coordinate,
|
||||
context, viewState.center, viewState.resolution, viewState.rotation,
|
||||
frameState.size, frameState.pixelRatio, layerState.opacity,
|
||||
{},
|
||||
/**
|
||||
* @param {import("../../Feature.js").FeatureLike} feature Feature.
|
||||
* @return {?} Callback result.
|
||||
*/
|
||||
function(feature) {
|
||||
const key = getUid(feature);
|
||||
if (!(key in features)) {
|
||||
features[key] = true;
|
||||
return callback.call(thisArg, feature, layer);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
hasFeatureAtCoordinate(coordinate, frameState) {
|
||||
if (!this.replayGroup_ || !this.layerState_) {
|
||||
return false;
|
||||
} else {
|
||||
const context = this.mapRenderer.getContext();
|
||||
const viewState = frameState.viewState;
|
||||
const layerState = this.layerState_;
|
||||
return this.replayGroup_.hasFeatureAtCoordinate(coordinate,
|
||||
context, viewState.center, viewState.resolution, viewState.rotation,
|
||||
frameState.size, frameState.pixelRatio, layerState.opacity,
|
||||
frameState.skippedFeatureUids);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
forEachLayerAtPixel(pixel, frameState, callback, thisArg) {
|
||||
const coordinate = applyTransform(
|
||||
frameState.pixelToCoordinateTransform, pixel.slice());
|
||||
const hasFeature = this.hasFeatureAtCoordinate(coordinate, frameState);
|
||||
|
||||
if (hasFeature) {
|
||||
return callback.call(thisArg, this.getLayer(), null);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle changes in image style state.
|
||||
* @param {import("../../events/Event.js").default} event Image style change event.
|
||||
* @private
|
||||
*/
|
||||
handleStyleImageChange_(event) {
|
||||
this.renderIfReadyAndVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
prepareFrame(frameState, layerState, context) {
|
||||
const vectorLayer = /** @type {import("../../layer/Vector.js").default} */ (this.getLayer());
|
||||
const vectorSource = /** @type {import("../../source/Vector.js").default} */ (vectorLayer.getSource());
|
||||
|
||||
const animating = frameState.viewHints[ViewHint.ANIMATING];
|
||||
const interacting = frameState.viewHints[ViewHint.INTERACTING];
|
||||
const updateWhileAnimating = vectorLayer.getUpdateWhileAnimating();
|
||||
const updateWhileInteracting = vectorLayer.getUpdateWhileInteracting();
|
||||
|
||||
if (!this.dirty_ && (!updateWhileAnimating && animating) ||
|
||||
(!updateWhileInteracting && interacting)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const frameStateExtent = frameState.extent;
|
||||
const viewState = frameState.viewState;
|
||||
const projection = viewState.projection;
|
||||
const resolution = viewState.resolution;
|
||||
const pixelRatio = frameState.pixelRatio;
|
||||
const vectorLayerRevision = vectorLayer.getRevision();
|
||||
const vectorLayerRenderBuffer = vectorLayer.getRenderBuffer();
|
||||
let vectorLayerRenderOrder = vectorLayer.getRenderOrder();
|
||||
|
||||
if (vectorLayerRenderOrder === undefined) {
|
||||
vectorLayerRenderOrder = defaultRenderOrder;
|
||||
}
|
||||
|
||||
const extent = buffer(frameStateExtent,
|
||||
vectorLayerRenderBuffer * resolution);
|
||||
|
||||
if (!this.dirty_ &&
|
||||
this.renderedResolution_ == resolution &&
|
||||
this.renderedRevision_ == vectorLayerRevision &&
|
||||
this.renderedRenderOrder_ == vectorLayerRenderOrder &&
|
||||
containsExtent(this.renderedExtent_, extent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.replayGroup_) {
|
||||
frameState.postRenderFunctions.push(
|
||||
this.replayGroup_.getDeleteResourcesFunction(context));
|
||||
}
|
||||
|
||||
this.dirty_ = false;
|
||||
|
||||
const replayGroup = new WebGLReplayGroup(
|
||||
getRenderTolerance(resolution, pixelRatio),
|
||||
extent, vectorLayer.getRenderBuffer());
|
||||
vectorSource.loadFeatures(extent, resolution, projection);
|
||||
/**
|
||||
* @param {import("../../Feature.js").default} feature Feature.
|
||||
* @this {WebGLVectorLayerRenderer}
|
||||
*/
|
||||
const render = function(feature) {
|
||||
let styles;
|
||||
const styleFunction = feature.getStyleFunction() || vectorLayer.getStyleFunction();
|
||||
if (styleFunction) {
|
||||
styles = styleFunction(feature, resolution);
|
||||
}
|
||||
if (styles) {
|
||||
const dirty = this.renderFeature(
|
||||
feature, resolution, pixelRatio, styles, replayGroup);
|
||||
this.dirty_ = this.dirty_ || dirty;
|
||||
}
|
||||
}.bind(this);
|
||||
if (vectorLayerRenderOrder) {
|
||||
/** @type {Array<import("../../Feature.js").default>} */
|
||||
const features = [];
|
||||
vectorSource.forEachFeatureInExtent(extent,
|
||||
/**
|
||||
* @param {import("../../Feature.js").default} feature Feature.
|
||||
*/
|
||||
function(feature) {
|
||||
features.push(feature);
|
||||
});
|
||||
features.sort(vectorLayerRenderOrder);
|
||||
features.forEach(render.bind(this));
|
||||
} else {
|
||||
vectorSource.forEachFeatureInExtent(extent, render);
|
||||
}
|
||||
replayGroup.finish(context);
|
||||
|
||||
this.renderedResolution_ = resolution;
|
||||
this.renderedRevision_ = vectorLayerRevision;
|
||||
this.renderedRenderOrder_ = vectorLayerRenderOrder;
|
||||
this.renderedExtent_ = extent;
|
||||
this.replayGroup_ = replayGroup;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../../Feature.js").default} feature Feature.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {import("../../style/Style.js").default|Array<import("../../style/Style.js").default>} styles The style or array of
|
||||
* styles.
|
||||
* @param {import("../../render/webgl/ReplayGroup.js").default} replayGroup Replay group.
|
||||
* @return {boolean} `true` if an image is loading.
|
||||
*/
|
||||
renderFeature(feature, resolution, pixelRatio, styles, replayGroup) {
|
||||
if (!styles) {
|
||||
return false;
|
||||
}
|
||||
let loading = false;
|
||||
if (Array.isArray(styles)) {
|
||||
for (let i = styles.length - 1, ii = 0; i >= ii; --i) {
|
||||
loading = renderFeature(
|
||||
replayGroup, feature, styles[i],
|
||||
getSquaredRenderTolerance(resolution, pixelRatio),
|
||||
this.handleStyleImageChange_, this) || loading;
|
||||
}
|
||||
} else {
|
||||
loading = renderFeature(
|
||||
replayGroup, feature, styles,
|
||||
getSquaredRenderTolerance(resolution, pixelRatio),
|
||||
this.handleStyleImageChange_, this) || loading;
|
||||
}
|
||||
return loading;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default WebGLVectorLayerRenderer;
|
||||
@@ -1,29 +0,0 @@
|
||||
//! MODULE=ol/renderer/webgl/defaultmapshader
|
||||
|
||||
|
||||
//! COMMON
|
||||
varying vec2 v_texCoord;
|
||||
|
||||
|
||||
//! VERTEX
|
||||
attribute vec2 a_position;
|
||||
attribute vec2 a_texCoord;
|
||||
|
||||
uniform mat4 u_texCoordMatrix;
|
||||
uniform mat4 u_projectionMatrix;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = u_projectionMatrix * vec4(a_position, 0., 1.);
|
||||
v_texCoord = (u_texCoordMatrix * vec4(a_texCoord, 0., 1.)).st;
|
||||
}
|
||||
|
||||
|
||||
//! FRAGMENT
|
||||
uniform float u_opacity;
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
void main(void) {
|
||||
vec4 texColor = texture2D(u_texture, v_texCoord);
|
||||
gl_FragColor.rgb = texColor.rgb;
|
||||
gl_FragColor.a = texColor.a * u_opacity;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* @module ol/renderer/webgl/defaultmapshader
|
||||
*/
|
||||
// This file is automatically generated, do not edit.
|
||||
// Run `make shaders` to generate, and commit the result.
|
||||
|
||||
import {DEBUG as DEBUG_WEBGL} from '../../webgl.js';
|
||||
import WebGLFragment from '../../webgl/Fragment.js';
|
||||
import WebGLVertex from '../../webgl/Vertex.js';
|
||||
|
||||
export const fragment = new WebGLFragment(DEBUG_WEBGL ?
|
||||
'precision mediump float;\nvarying vec2 v_texCoord;\n\n\nuniform float u_opacity;\nuniform sampler2D u_texture;\n\nvoid main(void) {\n vec4 texColor = texture2D(u_texture, v_texCoord);\n gl_FragColor.rgb = texColor.rgb;\n gl_FragColor.a = texColor.a * u_opacity;\n}\n' :
|
||||
'precision mediump float;varying vec2 a;uniform float f;uniform sampler2D g;void main(void){vec4 texColor=texture2D(g,a);gl_FragColor.rgb=texColor.rgb;gl_FragColor.a=texColor.a*f;}');
|
||||
|
||||
export const vertex = new WebGLVertex(DEBUG_WEBGL ?
|
||||
'varying vec2 v_texCoord;\n\n\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\n\nuniform mat4 u_texCoordMatrix;\nuniform mat4 u_projectionMatrix;\n\nvoid main(void) {\n gl_Position = u_projectionMatrix * vec4(a_position, 0., 1.);\n v_texCoord = (u_texCoordMatrix * vec4(a_texCoord, 0., 1.)).st;\n}\n\n\n' :
|
||||
'varying vec2 a;attribute vec2 b;attribute vec2 c;uniform mat4 d;uniform mat4 e;void main(void){gl_Position=e*vec4(b,0.,1.);a=(d*vec4(c,0.,1.)).st;}');
|
||||
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
* @module ol/renderer/webgl/defaultmapshader/Locations
|
||||
*/
|
||||
// This file is automatically generated, do not edit
|
||||
// Run `make shaders` to generate, and commit the result.
|
||||
|
||||
import {DEBUG as DEBUG_WEBGL} from '../../../webgl.js';
|
||||
|
||||
class Locations {
|
||||
|
||||
/**
|
||||
* @param {WebGLRenderingContext} gl GL.
|
||||
* @param {WebGLProgram} program Program.
|
||||
*/
|
||||
constructor(gl, program) {
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_texCoordMatrix = gl.getUniformLocation(
|
||||
program, DEBUG_WEBGL ? 'u_texCoordMatrix' : 'd');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_projectionMatrix = gl.getUniformLocation(
|
||||
program, DEBUG_WEBGL ? 'u_projectionMatrix' : 'e');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_opacity = gl.getUniformLocation(
|
||||
program, DEBUG_WEBGL ? 'u_opacity' : 'f');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_texture = gl.getUniformLocation(
|
||||
program, DEBUG_WEBGL ? 'u_texture' : 'g');
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.a_position = gl.getAttribLocation(
|
||||
program, DEBUG_WEBGL ? 'a_position' : 'b');
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.a_texCoord = gl.getAttribLocation(
|
||||
program, DEBUG_WEBGL ? 'a_texCoord' : 'c');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Locations;
|
||||
@@ -1,24 +0,0 @@
|
||||
//! MODULE=ol/renderer/webgl/tilelayershader
|
||||
|
||||
|
||||
//! COMMON
|
||||
varying vec2 v_texCoord;
|
||||
|
||||
|
||||
//! VERTEX
|
||||
attribute vec2 a_position;
|
||||
attribute vec2 a_texCoord;
|
||||
uniform vec4 u_tileOffset;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = vec4(a_position * u_tileOffset.xy + u_tileOffset.zw, 0., 1.);
|
||||
v_texCoord = a_texCoord;
|
||||
}
|
||||
|
||||
|
||||
//! FRAGMENT
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
void main(void) {
|
||||
gl_FragColor = texture2D(u_texture, v_texCoord);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* @module ol/renderer/webgl/tilelayershader
|
||||
*/
|
||||
// This file is automatically generated, do not edit.
|
||||
// Run `make shaders` to generate, and commit the result.
|
||||
|
||||
import {DEBUG as DEBUG_WEBGL} from '../../webgl.js';
|
||||
import WebGLFragment from '../../webgl/Fragment.js';
|
||||
import WebGLVertex from '../../webgl/Vertex.js';
|
||||
|
||||
export const fragment = new WebGLFragment(DEBUG_WEBGL ?
|
||||
'precision mediump float;\nvarying vec2 v_texCoord;\n\n\nuniform sampler2D u_texture;\n\nvoid main(void) {\n gl_FragColor = texture2D(u_texture, v_texCoord);\n}\n' :
|
||||
'precision mediump float;varying vec2 a;uniform sampler2D e;void main(void){gl_FragColor=texture2D(e,a);}');
|
||||
|
||||
export const vertex = new WebGLVertex(DEBUG_WEBGL ?
|
||||
'varying vec2 v_texCoord;\n\n\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nuniform vec4 u_tileOffset;\n\nvoid main(void) {\n gl_Position = vec4(a_position * u_tileOffset.xy + u_tileOffset.zw, 0., 1.);\n v_texCoord = a_texCoord;\n}\n\n\n' :
|
||||
'varying vec2 a;attribute vec2 b;attribute vec2 c;uniform vec4 d;void main(void){gl_Position=vec4(b*d.xy+d.zw,0.,1.);a=c;}');
|
||||
@@ -1,45 +0,0 @@
|
||||
/**
|
||||
* @module ol/renderer/webgl/tilelayershader/Locations
|
||||
*/
|
||||
// This file is automatically generated, do not edit
|
||||
// Run `make shaders` to generate, and commit the result.
|
||||
|
||||
import {DEBUG as DEBUG_WEBGL} from '../../../webgl.js';
|
||||
|
||||
class Locations {
|
||||
|
||||
/**
|
||||
* @param {WebGLRenderingContext} gl GL.
|
||||
* @param {WebGLProgram} program Program.
|
||||
*/
|
||||
constructor(gl, program) {
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_tileOffset = gl.getUniformLocation(
|
||||
program, DEBUG_WEBGL ? 'u_tileOffset' : 'd');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_texture = gl.getUniformLocation(
|
||||
program, DEBUG_WEBGL ? 'u_texture' : 'e');
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.a_position = gl.getAttribLocation(
|
||||
program, DEBUG_WEBGL ? 'a_position' : 'b');
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.a_texCoord = gl.getAttribLocation(
|
||||
program, DEBUG_WEBGL ? 'a_texCoord' : 'c');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Locations;
|
||||
Reference in New Issue
Block a user