Remove use of goog.vec.*

This commit is contained in:
Andreas Hocevar
2016-06-22 09:14:53 +02:00
parent 55edf4003f
commit cf7ff841a7
36 changed files with 511 additions and 412 deletions

View File

@@ -1,7 +1,7 @@
goog.provide('ol.renderer.webgl.ImageLayer');
goog.require('goog.asserts');
goog.require('goog.vec.Mat4');
goog.require('ol.matrix');
goog.require('goog.webgl');
goog.require('ol.ImageBase');
goog.require('ol.ViewHint');
@@ -12,7 +12,6 @@ goog.require('ol.layer.Image');
goog.require('ol.proj');
goog.require('ol.renderer.webgl.Layer');
goog.require('ol.source.ImageVector');
goog.require('ol.vec.Mat4');
goog.require('ol.webgl.Context');
@@ -41,7 +40,7 @@ ol.renderer.webgl.ImageLayer = function(mapRenderer, imageLayer) {
/**
* @private
* @type {?goog.vec.Mat4.Number}
* @type {?ol.Matrix}
*/
this.hitTransformationMatrix_ = null;
@@ -165,9 +164,9 @@ ol.renderer.webgl.ImageLayer.prototype.prepareFrame = function(frameState, layer
// Translate and scale to flip the Y coord.
var texCoordMatrix = this.texCoordMatrix;
goog.vec.Mat4.makeIdentity(texCoordMatrix);
goog.vec.Mat4.scale(texCoordMatrix, 1, -1, 1);
goog.vec.Mat4.translate(texCoordMatrix, 0, -1, 0);
ol.matrix.makeIdentity(texCoordMatrix);
ol.matrix.scale(texCoordMatrix, 1, -1);
ol.matrix.translate(texCoordMatrix, 0, -1);
this.image_ = image;
this.texture = texture;
@@ -197,20 +196,18 @@ ol.renderer.webgl.ImageLayer.prototype.updateProjectionMatrix_ = function(canvas
var canvasExtentHeight = canvasHeight * viewResolution;
var projectionMatrix = this.projectionMatrix;
goog.vec.Mat4.makeIdentity(projectionMatrix);
goog.vec.Mat4.scale(projectionMatrix,
ol.matrix.makeIdentity(projectionMatrix);
ol.matrix.scale(projectionMatrix,
pixelRatio * 2 / canvasExtentWidth,
pixelRatio * 2 / canvasExtentHeight, 1);
goog.vec.Mat4.rotateZ(projectionMatrix, -viewRotation);
goog.vec.Mat4.translate(projectionMatrix,
pixelRatio * 2 / canvasExtentHeight);
ol.matrix.rotate(projectionMatrix, -viewRotation);
ol.matrix.translate(projectionMatrix,
imageExtent[0] - viewCenter[0],
imageExtent[1] - viewCenter[1],
0);
goog.vec.Mat4.scale(projectionMatrix,
imageExtent[1] - viewCenter[1]);
ol.matrix.scale(projectionMatrix,
(imageExtent[2] - imageExtent[0]) / 2,
(imageExtent[3] - imageExtent[1]) / 2,
1);
goog.vec.Mat4.translate(projectionMatrix, 1, 1, 0);
(imageExtent[3] - imageExtent[1]) / 2);
ol.matrix.translate(projectionMatrix, 1, 1);
};
@@ -237,7 +234,7 @@ ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, fra
// for ImageVector sources use the original hit-detection logic,
// so that for example also transparent polygons are detected
var coordinate = pixel.slice();
ol.vec.Mat4.multVec2(
ol.matrix.multVec2(
frameState.pixelToCoordinateMatrix, coordinate, coordinate);
var hasFeature = this.forEachFeatureAtCoordinate(
coordinate, frameState, ol.functions.TRUE, this);
@@ -257,7 +254,7 @@ ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, fra
}
var pixelOnFrameBuffer = [0, 0];
ol.vec.Mat4.multVec2(
ol.matrix.multVec2(
this.hitTransformationMatrix_, pixel, pixelOnFrameBuffer);
if (pixelOnFrameBuffer[0] < 0 || pixelOnFrameBuffer[0] > imageSize[0] ||
@@ -289,36 +286,34 @@ ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, fra
* pixel on the map.
* @param {ol.Size} mapSize The map size.
* @param {ol.Size} imageSize The image size.
* @return {goog.vec.Mat4.Number} The transformation matrix.
* @return {ol.Matrix} The transformation matrix.
* @private
*/
ol.renderer.webgl.ImageLayer.prototype.getHitTransformationMatrix_ = function(mapSize, imageSize) {
// the first matrix takes a map pixel, flips the y-axis and scales to
// a range between -1 ... 1
var mapCoordMatrix = goog.vec.Mat4.createNumber();
goog.vec.Mat4.makeIdentity(mapCoordMatrix);
goog.vec.Mat4.translate(mapCoordMatrix, -1, -1, 0);
goog.vec.Mat4.scale(mapCoordMatrix, 2 / mapSize[0], 2 / mapSize[1], 1);
goog.vec.Mat4.translate(mapCoordMatrix, 0, mapSize[1], 0);
goog.vec.Mat4.scale(mapCoordMatrix, 1, -1, 1);
var mapCoordMatrix = ol.matrix.create();
ol.matrix.translate(mapCoordMatrix, -1, -1);
ol.matrix.scale(mapCoordMatrix, 2 / mapSize[0], 2 / mapSize[1]);
ol.matrix.translate(mapCoordMatrix, 0, mapSize[1]);
ol.matrix.scale(mapCoordMatrix, 1, -1);
// the second matrix is the inverse of the projection matrix used in the
// shader for drawing
var projectionMatrixInv = goog.vec.Mat4.createNumber();
goog.vec.Mat4.invert(this.projectionMatrix, projectionMatrixInv);
var projectionMatrixInv = ol.matrix.create();
ol.matrix.invert(this.projectionMatrix, projectionMatrixInv);
// the third matrix scales to the image dimensions and flips the y-axis again
var imageCoordMatrix = goog.vec.Mat4.createNumber();
goog.vec.Mat4.makeIdentity(imageCoordMatrix);
goog.vec.Mat4.translate(imageCoordMatrix, 0, imageSize[1], 0);
goog.vec.Mat4.scale(imageCoordMatrix, 1, -1, 1);
goog.vec.Mat4.scale(imageCoordMatrix, imageSize[0] / 2, imageSize[1] / 2, 1);
goog.vec.Mat4.translate(imageCoordMatrix, 1, 1, 0);
var imageCoordMatrix = ol.matrix.create();
ol.matrix.translate(imageCoordMatrix, 0, imageSize[1]);
ol.matrix.scale(imageCoordMatrix, 1, -1);
ol.matrix.scale(imageCoordMatrix, imageSize[0] / 2, imageSize[1] / 2);
ol.matrix.translate(imageCoordMatrix, 1, 1);
var transformMatrix = goog.vec.Mat4.createNumber();
goog.vec.Mat4.multMat(
var transformMatrix = ol.matrix.create();
ol.matrix.multiply(
imageCoordMatrix, projectionMatrixInv, transformMatrix);
goog.vec.Mat4.multMat(
ol.matrix.multiply(
transformMatrix, mapCoordMatrix, transformMatrix);
return transformMatrix;

View File

@@ -1,8 +1,8 @@
goog.provide('ol.renderer.webgl.Layer');
goog.require('goog.vec.Mat4');
goog.require('goog.webgl');
goog.require('ol.layer.Layer');
goog.require('ol.matrix');
goog.require('ol.render.Event');
goog.require('ol.render.EventType');
goog.require('ol.render.webgl.Immediate');
@@ -11,6 +11,7 @@ goog.require('ol.renderer.webgl.map.shader.Default');
goog.require('ol.renderer.webgl.map.shader.Default.Locations');
goog.require('ol.renderer.webgl.map.shader.DefaultFragment');
goog.require('ol.renderer.webgl.map.shader.DefaultVertex');
goog.require('ol.vec.Mat4');
goog.require('ol.webgl.Buffer');
goog.require('ol.webgl.Context');
@@ -62,15 +63,15 @@ ol.renderer.webgl.Layer = function(mapRenderer, layer) {
/**
* @protected
* @type {!goog.vec.Mat4.Number}
* @type {ol.Matrix}
*/
this.texCoordMatrix = goog.vec.Mat4.createNumber();
this.texCoordMatrix = ol.matrix.create();
/**
* @protected
* @type {!goog.vec.Mat4.Number}
* @type {ol.Matrix}
*/
this.projectionMatrix = goog.vec.Mat4.createNumberIdentity();
this.projectionMatrix = ol.matrix.create();
/**
* @private
@@ -167,10 +168,10 @@ ol.renderer.webgl.Layer.prototype.composeFrame = function(frameState, layerState
gl.uniform1i(locations.u_texture, 0);
}
gl.uniformMatrix4fv(
locations.u_texCoordMatrix, false, this.getTexCoordMatrix());
gl.uniformMatrix4fv(locations.u_texCoordMatrix, false,
ol.vec.Mat4.fromMatrix(this.getTexCoordMatrix()));
gl.uniformMatrix4fv(locations.u_projectionMatrix, false,
this.getProjectionMatrix());
ol.vec.Mat4.fromMatrix(this.getProjectionMatrix()));
gl.uniform1f(locations.u_opacity, layerState.opacity);
gl.bindTexture(goog.webgl.TEXTURE_2D, this.getTexture());
gl.drawArrays(goog.webgl.TRIANGLE_STRIP, 0, 4);
@@ -208,7 +209,7 @@ ol.renderer.webgl.Layer.prototype.dispatchComposeEvent_ = function(type, context
/**
* @return {!goog.vec.Mat4.Number} Matrix.
* @return {!ol.Matrix} Matrix.
*/
ol.renderer.webgl.Layer.prototype.getTexCoordMatrix = function() {
return this.texCoordMatrix;
@@ -224,7 +225,7 @@ ol.renderer.webgl.Layer.prototype.getTexture = function() {
/**
* @return {!goog.vec.Mat4.Number} Matrix.
* @return {!ol.Matrix} Matrix.
*/
ol.renderer.webgl.Layer.prototype.getProjectionMatrix = function() {
return this.projectionMatrix;

View File

@@ -4,8 +4,7 @@
goog.provide('ol.renderer.webgl.TileLayer');
goog.require('goog.asserts');
goog.require('goog.vec.Mat4');
goog.require('goog.vec.Vec4');
goog.require('ol.matrix');
goog.require('goog.webgl');
goog.require('ol.TileRange');
goog.require('ol.TileState');
@@ -18,7 +17,6 @@ goog.require('ol.renderer.webgl.tilelayer.shader.Fragment');
goog.require('ol.renderer.webgl.tilelayer.shader.Locations');
goog.require('ol.renderer.webgl.tilelayer.shader.Vertex');
goog.require('ol.size');
goog.require('ol.vec.Mat4');
goog.require('ol.webgl.Buffer');
@@ -294,22 +292,21 @@ ol.renderer.webgl.TileLayer.prototype.prepareFrame = function(frameState, layerS
/** @type {Array.<number>} */
var zs = Object.keys(tilesToDrawByZ).map(Number);
zs.sort(ol.array.numberSafeCompareFunction);
var u_tileOffset = goog.vec.Vec4.createFloat32();
var i, ii, sx, sy, tileKey, tilesToDraw, tx, ty;
var u_tileOffset = new Float32Array(4);
var i, ii, tileKey, tilesToDraw;
for (i = 0, ii = zs.length; i < ii; ++i) {
tilesToDraw = tilesToDrawByZ[zs[i]];
for (tileKey in tilesToDraw) {
tile = tilesToDraw[tileKey];
tileExtent = tileGrid.getTileCoordExtent(tile.tileCoord, tmpExtent);
sx = 2 * (tileExtent[2] - tileExtent[0]) /
u_tileOffset[0] = 2 * (tileExtent[2] - tileExtent[0]) /
framebufferExtentDimension;
sy = 2 * (tileExtent[3] - tileExtent[1]) /
u_tileOffset[1] = 2 * (tileExtent[3] - tileExtent[1]) /
framebufferExtentDimension;
tx = 2 * (tileExtent[0] - framebufferExtent[0]) /
u_tileOffset[2] = 2 * (tileExtent[0] - framebufferExtent[0]) /
framebufferExtentDimension - 1;
ty = 2 * (tileExtent[1] - framebufferExtent[1]) /
u_tileOffset[3] = 2 * (tileExtent[1] - framebufferExtent[1]) /
framebufferExtentDimension - 1;
goog.vec.Vec4.setFromValues(u_tileOffset, sx, sy, tx, ty);
gl.uniform4fv(this.locations_.u_tileOffset, u_tileOffset);
mapRenderer.bindTileTexture(tile, tilePixelSize,
tileGutter * pixelRatio, goog.webgl.LINEAR, goog.webgl.LINEAR);
@@ -354,26 +351,21 @@ ol.renderer.webgl.TileLayer.prototype.prepareFrame = function(frameState, layerS
this.updateLogos(frameState, tileSource);
var texCoordMatrix = this.texCoordMatrix;
goog.vec.Mat4.makeIdentity(texCoordMatrix);
goog.vec.Mat4.translate(texCoordMatrix,
ol.matrix.makeIdentity(texCoordMatrix);
ol.matrix.translate(texCoordMatrix,
(center[0] - framebufferExtent[0]) /
(framebufferExtent[2] - framebufferExtent[0]),
(center[1] - framebufferExtent[1]) /
(framebufferExtent[3] - framebufferExtent[1]),
0);
(framebufferExtent[3] - framebufferExtent[1]));
if (viewState.rotation !== 0) {
goog.vec.Mat4.rotateZ(texCoordMatrix, viewState.rotation);
ol.matrix.rotate(texCoordMatrix, viewState.rotation);
}
goog.vec.Mat4.scale(texCoordMatrix,
ol.matrix.scale(texCoordMatrix,
frameState.size[0] * viewState.resolution /
(framebufferExtent[2] - framebufferExtent[0]),
frameState.size[1] * viewState.resolution /
(framebufferExtent[3] - framebufferExtent[1]),
1);
goog.vec.Mat4.translate(texCoordMatrix,
-0.5,
-0.5,
0);
(framebufferExtent[3] - framebufferExtent[1]));
ol.matrix.translate(texCoordMatrix, -0.5, -0.5);
return true;
};
@@ -392,7 +384,7 @@ ol.renderer.webgl.TileLayer.prototype.forEachLayerAtPixel = function(pixel, fram
(frameState.size[1] - pixel[1]) / frameState.size[1]];
var pixelOnFrameBufferScaled = [0, 0];
ol.vec.Mat4.multVec2(
ol.matrix.multVec2(
this.texCoordMatrix, pixelOnMapScaled, pixelOnFrameBufferScaled);
var pixelOnFrameBuffer = [
pixelOnFrameBufferScaled[0] * this.framebufferDimension,

View File

@@ -5,10 +5,10 @@ goog.require('ol.events');
goog.require('ol.ViewHint');
goog.require('ol.extent');
goog.require('ol.layer.Vector');
goog.require('ol.matrix');
goog.require('ol.render.webgl.ReplayGroup');
goog.require('ol.renderer.vector');
goog.require('ol.renderer.webgl.Layer');
goog.require('ol.vec.Mat4');
/**
@@ -155,7 +155,7 @@ ol.renderer.webgl.VectorLayer.prototype.hasFeatureAtCoordinate = function(coordi
*/
ol.renderer.webgl.VectorLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
var coordinate = pixel.slice();
ol.vec.Mat4.multVec2(
ol.matrix.multVec2(
frameState.pixelToCoordinateMatrix, coordinate, coordinate);
var hasFeature = this.hasFeatureAtCoordinate(coordinate, frameState);