Merge pull request #6314 from ahocevar/webgl-define

WebGL conditional compilation
This commit is contained in:
Andreas Hocevar
2017-01-03 00:21:58 +01:00
committed by GitHub
27 changed files with 6370 additions and 6259 deletions
+23 -19
View File
@@ -1,51 +1,53 @@
goog.provide('ol.render.webgl'); goog.provide('ol.render.webgl');
/** if (ol.ENABLE_WEBGL) {
/**
* @const * @const
* @type {ol.Color} * @type {ol.Color}
*/ */
ol.render.webgl.defaultFillStyle = [0.0, 0.0, 0.0, 1.0]; ol.render.webgl.defaultFillStyle = [0.0, 0.0, 0.0, 1.0];
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.defaultLineCap = 'round'; ol.render.webgl.defaultLineCap = 'round';
/** /**
* @const * @const
* @type {Array.<number>} * @type {Array.<number>}
*/ */
ol.render.webgl.defaultLineDash = []; ol.render.webgl.defaultLineDash = [];
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.defaultLineJoin = 'round'; ol.render.webgl.defaultLineJoin = 'round';
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.render.webgl.defaultMiterLimit = 10; ol.render.webgl.defaultMiterLimit = 10;
/** /**
* @const * @const
* @type {ol.Color} * @type {ol.Color}
*/ */
ol.render.webgl.defaultStrokeStyle = [0.0, 0.0, 0.0, 1.0]; ol.render.webgl.defaultStrokeStyle = [0.0, 0.0, 0.0, 1.0];
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.render.webgl.defaultLineWidth = 1; ol.render.webgl.defaultLineWidth = 1;
/** /**
* Calculates the orientation of a triangle based on the determinant method. * Calculates the orientation of a triangle based on the determinant method.
* @param {number} x1 First X coordinate. * @param {number} x1 First X coordinate.
* @param {number} y1 First Y coordinate. * @param {number} y1 First Y coordinate.
@@ -55,14 +57,16 @@ ol.render.webgl.defaultLineWidth = 1;
* @param {number} y3 Third Y coordinate. * @param {number} y3 Third Y coordinate.
* @return {boolean|undefined} Triangle is clockwise. * @return {boolean|undefined} Triangle is clockwise.
*/ */
ol.render.webgl.triangleIsCounterClockwise = function(x1, y1, x2, y2, x3, y3) { ol.render.webgl.triangleIsCounterClockwise = function(x1, y1, x2, y2, x3, y3) {
var area = (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1); var area = (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1);
return (area <= ol.render.webgl.EPSILON && area >= -ol.render.webgl.EPSILON) ? return (area <= ol.render.webgl.EPSILON && area >= -ol.render.webgl.EPSILON) ?
undefined : area > 0; undefined : area > 0;
}; };
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.render.webgl.EPSILON = Number.EPSILON || 2.220446049250313e-16; ol.render.webgl.EPSILON = Number.EPSILON || 2.220446049250313e-16;
}
+44 -40
View File
@@ -13,14 +13,16 @@ goog.require('ol.webgl');
goog.require('ol.webgl.Buffer'); goog.require('ol.webgl.Buffer');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.render.webgl.Replay} * @extends {ol.render.webgl.Replay}
* @param {number} tolerance Tolerance. * @param {number} tolerance Tolerance.
* @param {ol.Extent} maxExtent Max extent. * @param {ol.Extent} maxExtent Max extent.
* @struct * @struct
*/ */
ol.render.webgl.CircleReplay = function(tolerance, maxExtent) { ol.render.webgl.CircleReplay = function(tolerance, maxExtent) {
ol.render.webgl.Replay.call(this, tolerance, maxExtent); ol.render.webgl.Replay.call(this, tolerance, maxExtent);
/** /**
@@ -63,18 +65,18 @@ ol.render.webgl.CircleReplay = function(tolerance, maxExtent) {
changed: false changed: false
}; };
}; };
ol.inherits(ol.render.webgl.CircleReplay, ol.render.webgl.Replay); ol.inherits(ol.render.webgl.CircleReplay, ol.render.webgl.Replay);
/** /**
* @private * @private
* @param {Array.<number>} flatCoordinates Flat coordinates. * @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {number} end End. * @param {number} end End.
* @param {number} stride Stride. * @param {number} stride Stride.
*/ */
ol.render.webgl.CircleReplay.prototype.drawCoordinates_ = function( ol.render.webgl.CircleReplay.prototype.drawCoordinates_ = function(
flatCoordinates, offset, end, stride) { flatCoordinates, offset, end, stride) {
var numVertices = this.vertices.length; var numVertices = this.vertices.length;
var numIndices = this.indices.length; var numIndices = this.indices.length;
@@ -111,13 +113,13 @@ ol.render.webgl.CircleReplay.prototype.drawCoordinates_ = function(
n += 4; n += 4;
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.CircleReplay.prototype.drawCircle = function(circleGeometry, feature) { ol.render.webgl.CircleReplay.prototype.drawCircle = function(circleGeometry, feature) {
var radius = circleGeometry.getRadius(); var radius = circleGeometry.getRadius();
var stride = circleGeometry.getStride(); var stride = circleGeometry.getStride();
if (radius) { if (radius) {
@@ -145,13 +147,13 @@ ol.render.webgl.CircleReplay.prototype.drawCircle = function(circleGeometry, fea
} }
} }
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
**/ **/
ol.render.webgl.CircleReplay.prototype.finish = function(context) { ol.render.webgl.CircleReplay.prototype.finish = function(context) {
// create, bind, and populate the vertices buffer // create, bind, and populate the vertices buffer
this.verticesBuffer = new ol.webgl.Buffer(this.vertices); this.verticesBuffer = new ol.webgl.Buffer(this.vertices);
@@ -167,13 +169,13 @@ ol.render.webgl.CircleReplay.prototype.finish = function(context) {
this.vertices = null; this.vertices = null;
this.indices = null; this.indices = null;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.CircleReplay.prototype.getDeleteResourcesFunction = function(context) { ol.render.webgl.CircleReplay.prototype.getDeleteResourcesFunction = function(context) {
// We only delete our stuff here. The shaders and the program may // We only delete our stuff here. The shaders and the program may
// be used by other CircleReplay instances (for other layers). And // be used by other CircleReplay instances (for other layers). And
// they will be deleted when disposing of the ol.webgl.Context // they will be deleted when disposing of the ol.webgl.Context
@@ -184,13 +186,13 @@ ol.render.webgl.CircleReplay.prototype.getDeleteResourcesFunction = function(con
context.deleteBuffer(verticesBuffer); context.deleteBuffer(verticesBuffer);
context.deleteBuffer(indicesBuffer); context.deleteBuffer(indicesBuffer);
}; };
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.CircleReplay.prototype.setUpProgram = function(gl, context, size, pixelRatio) { ol.render.webgl.CircleReplay.prototype.setUpProgram = function(gl, context, size, pixelRatio) {
// get the program // get the program
var fragmentShader, vertexShader; var fragmentShader, vertexShader;
fragmentShader = ol.render.webgl.circlereplay.defaultshader.fragment; fragmentShader = ol.render.webgl.circlereplay.defaultshader.fragment;
@@ -227,23 +229,23 @@ ol.render.webgl.CircleReplay.prototype.setUpProgram = function(gl, context, size
gl.uniform1f(locations.u_pixelRatio, pixelRatio); gl.uniform1f(locations.u_pixelRatio, pixelRatio);
return locations; return locations;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.CircleReplay.prototype.shutDownProgram = function(gl, locations) { ol.render.webgl.CircleReplay.prototype.shutDownProgram = function(gl, locations) {
gl.disableVertexAttribArray(locations.a_position); gl.disableVertexAttribArray(locations.a_position);
gl.disableVertexAttribArray(locations.a_instruction); gl.disableVertexAttribArray(locations.a_instruction);
gl.disableVertexAttribArray(locations.a_radius); gl.disableVertexAttribArray(locations.a_radius);
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.CircleReplay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) { ol.render.webgl.CircleReplay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) {
if (!ol.obj.isEmpty(skippedFeaturesHash)) { if (!ol.obj.isEmpty(skippedFeaturesHash)) {
this.drawReplaySkipping_(gl, context, skippedFeaturesHash); this.drawReplaySkipping_(gl, context, skippedFeaturesHash);
} else { } else {
@@ -260,13 +262,13 @@ ol.render.webgl.CircleReplay.prototype.drawReplay = function(gl, context, skippe
end = start; end = start;
} }
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.CircleReplay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash, ol.render.webgl.CircleReplay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash,
featureCallback, opt_hitExtent) { featureCallback, opt_hitExtent) {
var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex; var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex;
featureIndex = this.startIndices.length - 2; featureIndex = this.startIndices.length - 2;
@@ -304,16 +306,16 @@ ol.render.webgl.CircleReplay.prototype.drawHitDetectionReplayOneByOne = function
} }
} }
return undefined; return undefined;
}; };
/** /**
* @private * @private
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
* @param {Object} skippedFeaturesHash Ids of features to skip. * @param {Object} skippedFeaturesHash Ids of features to skip.
*/ */
ol.render.webgl.CircleReplay.prototype.drawReplaySkipping_ = function(gl, context, skippedFeaturesHash) { ol.render.webgl.CircleReplay.prototype.drawReplaySkipping_ = function(gl, context, skippedFeaturesHash) {
var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex, featureStart; var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex, featureStart;
featureIndex = this.startIndices.length - 2; featureIndex = this.startIndices.length - 2;
end = start = this.startIndices[featureIndex + 1]; end = start = this.startIndices[featureIndex + 1];
@@ -344,35 +346,35 @@ ol.render.webgl.CircleReplay.prototype.drawReplaySkipping_ = function(gl, contex
} }
start = end = groupStart; start = end = groupStart;
} }
}; };
/** /**
* @private * @private
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
* @param {Array.<number>} color Color. * @param {Array.<number>} color Color.
*/ */
ol.render.webgl.CircleReplay.prototype.setFillStyle_ = function(gl, color) { ol.render.webgl.CircleReplay.prototype.setFillStyle_ = function(gl, color) {
gl.uniform4fv(this.defaultLocations_.u_fillColor, color); gl.uniform4fv(this.defaultLocations_.u_fillColor, color);
}; };
/** /**
* @private * @private
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
* @param {Array.<number>} color Color. * @param {Array.<number>} color Color.
* @param {number} lineWidth Line width. * @param {number} lineWidth Line width.
*/ */
ol.render.webgl.CircleReplay.prototype.setStrokeStyle_ = function(gl, color, lineWidth) { ol.render.webgl.CircleReplay.prototype.setStrokeStyle_ = function(gl, color, lineWidth) {
gl.uniform4fv(this.defaultLocations_.u_strokeColor, color); gl.uniform4fv(this.defaultLocations_.u_strokeColor, color);
gl.uniform1f(this.defaultLocations_.u_lineWidth, lineWidth); gl.uniform1f(this.defaultLocations_.u_lineWidth, lineWidth);
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.CircleReplay.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) { ol.render.webgl.CircleReplay.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {
var strokeStyleColor, strokeStyleWidth; var strokeStyleColor, strokeStyleWidth;
if (strokeStyle) { if (strokeStyle) {
var strokeStyleLineDash = strokeStyle.getLineDash(); var strokeStyleLineDash = strokeStyle.getLineDash();
@@ -412,4 +414,6 @@ ol.render.webgl.CircleReplay.prototype.setFillStrokeStyle = function(fillStyle,
this.state_.lineWidth = strokeStyleWidth; this.state_.lineWidth = strokeStyleWidth;
this.styles_.push([fillStyleColor, strokeStyleColor, strokeStyleWidth]); this.styles_.push([fillStyleColor, strokeStyleColor, strokeStyleWidth]);
} }
}; };
}
@@ -6,83 +6,85 @@ goog.require('ol.webgl.Fragment');
goog.require('ol.webgl.Vertex'); goog.require('ol.webgl.Vertex');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.webgl.Fragment} * @extends {ol.webgl.Fragment}
* @struct * @struct
*/ */
ol.render.webgl.circlereplay.defaultshader.Fragment = function() { ol.render.webgl.circlereplay.defaultshader.Fragment = function() {
ol.webgl.Fragment.call(this, ol.render.webgl.circlereplay.defaultshader.Fragment.SOURCE); ol.webgl.Fragment.call(this, ol.render.webgl.circlereplay.defaultshader.Fragment.SOURCE);
}; };
ol.inherits(ol.render.webgl.circlereplay.defaultshader.Fragment, ol.webgl.Fragment); ol.inherits(ol.render.webgl.circlereplay.defaultshader.Fragment, ol.webgl.Fragment);
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.circlereplay.defaultshader.Fragment.DEBUG_SOURCE = 'precision mediump float;\nvarying vec2 v_center;\nvarying vec2 v_offset;\nvarying float v_halfWidth;\nvarying float v_pixelRatio;\n\n\n\nuniform float u_opacity;\nuniform vec4 u_fillColor;\nuniform vec4 u_strokeColor;\nuniform vec2 u_size;\n\nvoid main(void) {\n vec2 windowCenter = vec2((v_center.x + 1.0) / 2.0 * u_size.x * v_pixelRatio,\n (v_center.y + 1.0) / 2.0 * u_size.y * v_pixelRatio);\n vec2 windowOffset = vec2((v_offset.x + 1.0) / 2.0 * u_size.x * v_pixelRatio,\n (v_offset.y + 1.0) / 2.0 * u_size.y * v_pixelRatio);\n float radius = length(windowCenter - windowOffset);\n float dist = length(windowCenter - gl_FragCoord.xy);\n if (dist > radius + v_halfWidth) {\n if (u_strokeColor.a == 0.0) {\n gl_FragColor = u_fillColor;\n } else {\n gl_FragColor = u_strokeColor;\n }\n gl_FragColor.a = gl_FragColor.a - (dist - (radius + v_halfWidth));\n } else if (u_fillColor.a == 0.0) {\n // Hooray, no fill, just stroke. We can use real antialiasing.\n gl_FragColor = u_strokeColor;\n if (dist < radius - v_halfWidth) {\n gl_FragColor.a = gl_FragColor.a - (radius - v_halfWidth - dist);\n }\n } else {\n gl_FragColor = u_fillColor;\n float strokeDist = radius - v_halfWidth;\n float antialias = 2.0 * v_pixelRatio;\n if (dist > strokeDist) {\n gl_FragColor = u_strokeColor;\n } else if (dist >= strokeDist - antialias) {\n float step = smoothstep(strokeDist - antialias, strokeDist, dist);\n gl_FragColor = mix(u_fillColor, u_strokeColor, step);\n }\n }\n gl_FragColor.a = gl_FragColor.a * u_opacity;\n if (gl_FragColor.a <= 0.0) {\n discard;\n }\n}\n'; ol.render.webgl.circlereplay.defaultshader.Fragment.DEBUG_SOURCE = 'precision mediump float;\nvarying vec2 v_center;\nvarying vec2 v_offset;\nvarying float v_halfWidth;\nvarying float v_pixelRatio;\n\n\n\nuniform float u_opacity;\nuniform vec4 u_fillColor;\nuniform vec4 u_strokeColor;\nuniform vec2 u_size;\n\nvoid main(void) {\n vec2 windowCenter = vec2((v_center.x + 1.0) / 2.0 * u_size.x * v_pixelRatio,\n (v_center.y + 1.0) / 2.0 * u_size.y * v_pixelRatio);\n vec2 windowOffset = vec2((v_offset.x + 1.0) / 2.0 * u_size.x * v_pixelRatio,\n (v_offset.y + 1.0) / 2.0 * u_size.y * v_pixelRatio);\n float radius = length(windowCenter - windowOffset);\n float dist = length(windowCenter - gl_FragCoord.xy);\n if (dist > radius + v_halfWidth) {\n if (u_strokeColor.a == 0.0) {\n gl_FragColor = u_fillColor;\n } else {\n gl_FragColor = u_strokeColor;\n }\n gl_FragColor.a = gl_FragColor.a - (dist - (radius + v_halfWidth));\n } else if (u_fillColor.a == 0.0) {\n // Hooray, no fill, just stroke. We can use real antialiasing.\n gl_FragColor = u_strokeColor;\n if (dist < radius - v_halfWidth) {\n gl_FragColor.a = gl_FragColor.a - (radius - v_halfWidth - dist);\n }\n } else {\n gl_FragColor = u_fillColor;\n float strokeDist = radius - v_halfWidth;\n float antialias = 2.0 * v_pixelRatio;\n if (dist > strokeDist) {\n gl_FragColor = u_strokeColor;\n } else if (dist >= strokeDist - antialias) {\n float step = smoothstep(strokeDist - antialias, strokeDist, dist);\n gl_FragColor = mix(u_fillColor, u_strokeColor, step);\n }\n }\n gl_FragColor.a = gl_FragColor.a * u_opacity;\n if (gl_FragColor.a <= 0.0) {\n discard;\n }\n}\n';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.circlereplay.defaultshader.Fragment.OPTIMIZED_SOURCE = 'precision mediump float;varying vec2 a;varying vec2 b;varying float c;varying float d;uniform float m;uniform vec4 n;uniform vec4 o;uniform vec2 p;void main(void){vec2 windowCenter=vec2((a.x+1.0)/2.0*p.x*d,(a.y+1.0)/2.0*p.y*d);vec2 windowOffset=vec2((b.x+1.0)/2.0*p.x*d,(b.y+1.0)/2.0*p.y*d);float radius=length(windowCenter-windowOffset);float dist=length(windowCenter-gl_FragCoord.xy);if(dist>radius+c){if(o.a==0.0){gl_FragColor=n;}else{gl_FragColor=o;}gl_FragColor.a=gl_FragColor.a-(dist-(radius+c));}else if(n.a==0.0){gl_FragColor=o;if(dist<radius-c){gl_FragColor.a=gl_FragColor.a-(radius-c-dist);}} else{gl_FragColor=n;float strokeDist=radius-c;float antialias=2.0*d;if(dist>strokeDist){gl_FragColor=o;}else if(dist>=strokeDist-antialias){float step=smoothstep(strokeDist-antialias,strokeDist,dist);gl_FragColor=mix(n,o,step);}} gl_FragColor.a=gl_FragColor.a*m;if(gl_FragColor.a<=0.0){discard;}}'; ol.render.webgl.circlereplay.defaultshader.Fragment.OPTIMIZED_SOURCE = 'precision mediump float;varying vec2 a;varying vec2 b;varying float c;varying float d;uniform float m;uniform vec4 n;uniform vec4 o;uniform vec2 p;void main(void){vec2 windowCenter=vec2((a.x+1.0)/2.0*p.x*d,(a.y+1.0)/2.0*p.y*d);vec2 windowOffset=vec2((b.x+1.0)/2.0*p.x*d,(b.y+1.0)/2.0*p.y*d);float radius=length(windowCenter-windowOffset);float dist=length(windowCenter-gl_FragCoord.xy);if(dist>radius+c){if(o.a==0.0){gl_FragColor=n;}else{gl_FragColor=o;}gl_FragColor.a=gl_FragColor.a-(dist-(radius+c));}else if(n.a==0.0){gl_FragColor=o;if(dist<radius-c){gl_FragColor.a=gl_FragColor.a-(radius-c-dist);}} else{gl_FragColor=n;float strokeDist=radius-c;float antialias=2.0*d;if(dist>strokeDist){gl_FragColor=o;}else if(dist>=strokeDist-antialias){float step=smoothstep(strokeDist-antialias,strokeDist,dist);gl_FragColor=mix(n,o,step);}} gl_FragColor.a=gl_FragColor.a*m;if(gl_FragColor.a<=0.0){discard;}}';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.circlereplay.defaultshader.Fragment.SOURCE = ol.render.webgl.circlereplay.defaultshader.Fragment.OPTIMIZED_SOURCE; ol.render.webgl.circlereplay.defaultshader.Fragment.SOURCE = ol.render.webgl.circlereplay.defaultshader.Fragment.OPTIMIZED_SOURCE;
ol.render.webgl.circlereplay.defaultshader.fragment = new ol.render.webgl.circlereplay.defaultshader.Fragment(); ol.render.webgl.circlereplay.defaultshader.fragment = new ol.render.webgl.circlereplay.defaultshader.Fragment();
/** /**
* @constructor * @constructor
* @extends {ol.webgl.Vertex} * @extends {ol.webgl.Vertex}
* @struct * @struct
*/ */
ol.render.webgl.circlereplay.defaultshader.Vertex = function() { ol.render.webgl.circlereplay.defaultshader.Vertex = function() {
ol.webgl.Vertex.call(this, ol.render.webgl.circlereplay.defaultshader.Vertex.SOURCE); ol.webgl.Vertex.call(this, ol.render.webgl.circlereplay.defaultshader.Vertex.SOURCE);
}; };
ol.inherits(ol.render.webgl.circlereplay.defaultshader.Vertex, ol.webgl.Vertex); ol.inherits(ol.render.webgl.circlereplay.defaultshader.Vertex, ol.webgl.Vertex);
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.circlereplay.defaultshader.Vertex.DEBUG_SOURCE = 'varying vec2 v_center;\nvarying vec2 v_offset;\nvarying float v_halfWidth;\nvarying float v_pixelRatio;\n\n\nattribute vec2 a_position;\nattribute float a_instruction;\nattribute float a_radius;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform mat4 u_offsetRotateMatrix;\nuniform float u_lineWidth;\nuniform float u_pixelRatio;\n\nvoid main(void) {\n mat4 offsetMatrix = u_offsetScaleMatrix * u_offsetRotateMatrix;\n v_center = vec4(u_projectionMatrix * vec4(a_position, 0.0, 1.0)).xy;\n v_pixelRatio = u_pixelRatio;\n float lineWidth = u_lineWidth * u_pixelRatio;\n v_halfWidth = lineWidth / 2.0;\n if (lineWidth == 0.0) {\n lineWidth = 2.0 * u_pixelRatio;\n }\n vec2 offset;\n // Radius with anitaliasing (roughly).\n float radius = a_radius + 3.0 * u_pixelRatio;\n // Until we get gl_VertexID in WebGL, we store an instruction.\n if (a_instruction == 0.0) {\n // Offsetting the edges of the triangle by lineWidth / 2 is necessary, however\n // we should also leave some space for the antialiasing, thus we offset by lineWidth.\n offset = vec2(-1.0, 1.0);\n } else if (a_instruction == 1.0) {\n offset = vec2(-1.0, -1.0);\n } else if (a_instruction == 2.0) {\n offset = vec2(1.0, -1.0);\n } else {\n offset = vec2(1.0, 1.0);\n }\n\n gl_Position = u_projectionMatrix * vec4(a_position + offset * radius, 0.0, 1.0) +\n offsetMatrix * vec4(offset * lineWidth, 0.0, 0.0);\n v_offset = vec4(u_projectionMatrix * vec4(a_position.x + a_radius, a_position.y,\n 0.0, 1.0)).xy;\n\n if (distance(v_center, v_offset) > 20000.0) {\n gl_Position = vec4(v_center, 0.0, 1.0);\n }\n}\n\n\n'; ol.render.webgl.circlereplay.defaultshader.Vertex.DEBUG_SOURCE = 'varying vec2 v_center;\nvarying vec2 v_offset;\nvarying float v_halfWidth;\nvarying float v_pixelRatio;\n\n\nattribute vec2 a_position;\nattribute float a_instruction;\nattribute float a_radius;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform mat4 u_offsetRotateMatrix;\nuniform float u_lineWidth;\nuniform float u_pixelRatio;\n\nvoid main(void) {\n mat4 offsetMatrix = u_offsetScaleMatrix * u_offsetRotateMatrix;\n v_center = vec4(u_projectionMatrix * vec4(a_position, 0.0, 1.0)).xy;\n v_pixelRatio = u_pixelRatio;\n float lineWidth = u_lineWidth * u_pixelRatio;\n v_halfWidth = lineWidth / 2.0;\n if (lineWidth == 0.0) {\n lineWidth = 2.0 * u_pixelRatio;\n }\n vec2 offset;\n // Radius with anitaliasing (roughly).\n float radius = a_radius + 3.0 * u_pixelRatio;\n // Until we get gl_VertexID in WebGL, we store an instruction.\n if (a_instruction == 0.0) {\n // Offsetting the edges of the triangle by lineWidth / 2 is necessary, however\n // we should also leave some space for the antialiasing, thus we offset by lineWidth.\n offset = vec2(-1.0, 1.0);\n } else if (a_instruction == 1.0) {\n offset = vec2(-1.0, -1.0);\n } else if (a_instruction == 2.0) {\n offset = vec2(1.0, -1.0);\n } else {\n offset = vec2(1.0, 1.0);\n }\n\n gl_Position = u_projectionMatrix * vec4(a_position + offset * radius, 0.0, 1.0) +\n offsetMatrix * vec4(offset * lineWidth, 0.0, 0.0);\n v_offset = vec4(u_projectionMatrix * vec4(a_position.x + a_radius, a_position.y,\n 0.0, 1.0)).xy;\n\n if (distance(v_center, v_offset) > 20000.0) {\n gl_Position = vec4(v_center, 0.0, 1.0);\n }\n}\n\n\n';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.circlereplay.defaultshader.Vertex.OPTIMIZED_SOURCE = 'varying vec2 a;varying vec2 b;varying float c;varying float d;attribute vec2 e;attribute float f;attribute float g;uniform mat4 h;uniform mat4 i;uniform mat4 j;uniform float k;uniform float l;void main(void){mat4 offsetMatrix=i*j;a=vec4(h*vec4(e,0.0,1.0)).xy;d=l;float lineWidth=k*l;c=lineWidth/2.0;if(lineWidth==0.0){lineWidth=2.0*l;}vec2 offset;float radius=g+3.0*l;if(f==0.0){offset=vec2(-1.0,1.0);}else if(f==1.0){offset=vec2(-1.0,-1.0);}else if(f==2.0){offset=vec2(1.0,-1.0);}else{offset=vec2(1.0,1.0);}gl_Position=h*vec4(e+offset*radius,0.0,1.0)+offsetMatrix*vec4(offset*lineWidth,0.0,0.0);b=vec4(h*vec4(e.x+g,e.y,0.0,1.0)).xy;if(distance(a,b)>20000.0){gl_Position=vec4(a,0.0,1.0);}}'; ol.render.webgl.circlereplay.defaultshader.Vertex.OPTIMIZED_SOURCE = 'varying vec2 a;varying vec2 b;varying float c;varying float d;attribute vec2 e;attribute float f;attribute float g;uniform mat4 h;uniform mat4 i;uniform mat4 j;uniform float k;uniform float l;void main(void){mat4 offsetMatrix=i*j;a=vec4(h*vec4(e,0.0,1.0)).xy;d=l;float lineWidth=k*l;c=lineWidth/2.0;if(lineWidth==0.0){lineWidth=2.0*l;}vec2 offset;float radius=g+3.0*l;if(f==0.0){offset=vec2(-1.0,1.0);}else if(f==1.0){offset=vec2(-1.0,-1.0);}else if(f==2.0){offset=vec2(1.0,-1.0);}else{offset=vec2(1.0,1.0);}gl_Position=h*vec4(e+offset*radius,0.0,1.0)+offsetMatrix*vec4(offset*lineWidth,0.0,0.0);b=vec4(h*vec4(e.x+g,e.y,0.0,1.0)).xy;if(distance(a,b)>20000.0){gl_Position=vec4(a,0.0,1.0);}}';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.circlereplay.defaultshader.Vertex.SOURCE = ol.render.webgl.circlereplay.defaultshader.Vertex.OPTIMIZED_SOURCE; ol.render.webgl.circlereplay.defaultshader.Vertex.SOURCE = ol.render.webgl.circlereplay.defaultshader.Vertex.OPTIMIZED_SOURCE;
ol.render.webgl.circlereplay.defaultshader.vertex = new ol.render.webgl.circlereplay.defaultshader.Vertex(); ol.render.webgl.circlereplay.defaultshader.vertex = new ol.render.webgl.circlereplay.defaultshader.Vertex();
/** /**
* @constructor * @constructor
* @param {WebGLRenderingContext} gl GL. * @param {WebGLRenderingContext} gl GL.
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @struct * @struct
*/ */
ol.render.webgl.circlereplay.defaultshader.Locations = function(gl, program) { ol.render.webgl.circlereplay.defaultshader.Locations = function(gl, program) {
/** /**
* @type {WebGLUniformLocation} * @type {WebGLUniformLocation}
@@ -143,4 +145,6 @@ ol.render.webgl.circlereplay.defaultshader.Locations = function(gl, program) {
* @type {number} * @type {number}
*/ */
this.a_radius = gl.getAttribLocation(program, 'g'); this.a_radius = gl.getAttribLocation(program, 'g');
}; };
}
+44 -40
View File
@@ -11,14 +11,16 @@ goog.require('ol.webgl.Buffer');
goog.require('ol.webgl.Context'); goog.require('ol.webgl.Context');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.render.webgl.Replay} * @extends {ol.render.webgl.Replay}
* @param {number} tolerance Tolerance. * @param {number} tolerance Tolerance.
* @param {ol.Extent} maxExtent Max extent. * @param {ol.Extent} maxExtent Max extent.
* @struct * @struct
*/ */
ol.render.webgl.ImageReplay = function(tolerance, maxExtent) { ol.render.webgl.ImageReplay = function(tolerance, maxExtent) {
ol.render.webgl.Replay.call(this, tolerance, maxExtent); ol.render.webgl.Replay.call(this, tolerance, maxExtent);
/** /**
@@ -134,14 +136,14 @@ ol.render.webgl.ImageReplay = function(tolerance, maxExtent) {
* @private * @private
*/ */
this.width_ = undefined; this.width_ = undefined;
}; };
ol.inherits(ol.render.webgl.ImageReplay, ol.render.webgl.Replay); ol.inherits(ol.render.webgl.ImageReplay, ol.render.webgl.Replay);
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.ImageReplay.prototype.getDeleteResourcesFunction = function(context) { ol.render.webgl.ImageReplay.prototype.getDeleteResourcesFunction = function(context) {
var verticesBuffer = this.verticesBuffer; var verticesBuffer = this.verticesBuffer;
var indicesBuffer = this.indicesBuffer; var indicesBuffer = this.indicesBuffer;
var textures = this.textures_; var textures = this.textures_;
@@ -160,10 +162,10 @@ ol.render.webgl.ImageReplay.prototype.getDeleteResourcesFunction = function(cont
context.deleteBuffer(verticesBuffer); context.deleteBuffer(verticesBuffer);
context.deleteBuffer(indicesBuffer); context.deleteBuffer(indicesBuffer);
}; };
}; };
/** /**
* @param {Array.<number>} flatCoordinates Flat coordinates. * @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {number} end End. * @param {number} end End.
@@ -171,7 +173,7 @@ ol.render.webgl.ImageReplay.prototype.getDeleteResourcesFunction = function(cont
* @return {number} My end. * @return {number} My end.
* @private * @private
*/ */
ol.render.webgl.ImageReplay.prototype.drawCoordinates_ = function(flatCoordinates, offset, end, stride) { ol.render.webgl.ImageReplay.prototype.drawCoordinates_ = function(flatCoordinates, offset, end, stride) {
var anchorX = /** @type {number} */ (this.anchorX_); var anchorX = /** @type {number} */ (this.anchorX_);
var anchorY = /** @type {number} */ (this.anchorY_); var anchorY = /** @type {number} */ (this.anchorY_);
var height = /** @type {number} */ (this.height_); var height = /** @type {number} */ (this.height_);
@@ -263,39 +265,39 @@ ol.render.webgl.ImageReplay.prototype.drawCoordinates_ = function(flatCoordinate
} }
return numVertices; return numVertices;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.ImageReplay.prototype.drawMultiPoint = function(multiPointGeometry, feature) { ol.render.webgl.ImageReplay.prototype.drawMultiPoint = function(multiPointGeometry, feature) {
this.startIndices.push(this.indices.length); this.startIndices.push(this.indices.length);
this.startIndicesFeature.push(feature); this.startIndicesFeature.push(feature);
var flatCoordinates = multiPointGeometry.getFlatCoordinates(); var flatCoordinates = multiPointGeometry.getFlatCoordinates();
var stride = multiPointGeometry.getStride(); var stride = multiPointGeometry.getStride();
this.drawCoordinates_( this.drawCoordinates_(
flatCoordinates, 0, flatCoordinates.length, stride); flatCoordinates, 0, flatCoordinates.length, stride);
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.ImageReplay.prototype.drawPoint = function(pointGeometry, feature) { ol.render.webgl.ImageReplay.prototype.drawPoint = function(pointGeometry, feature) {
this.startIndices.push(this.indices.length); this.startIndices.push(this.indices.length);
this.startIndicesFeature.push(feature); this.startIndicesFeature.push(feature);
var flatCoordinates = pointGeometry.getFlatCoordinates(); var flatCoordinates = pointGeometry.getFlatCoordinates();
var stride = pointGeometry.getStride(); var stride = pointGeometry.getStride();
this.drawCoordinates_( this.drawCoordinates_(
flatCoordinates, 0, flatCoordinates.length, stride); flatCoordinates, 0, flatCoordinates.length, stride);
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.ImageReplay.prototype.finish = function(context) { ol.render.webgl.ImageReplay.prototype.finish = function(context) {
var gl = context.getGL(); var gl = context.getGL();
this.groupIndices_.push(this.indices.length); this.groupIndices_.push(this.indices.length);
@@ -334,10 +336,10 @@ ol.render.webgl.ImageReplay.prototype.finish = function(context) {
this.scale_ = undefined; this.scale_ = undefined;
this.vertices = null; this.vertices = null;
this.width_ = undefined; this.width_ = undefined;
}; };
/** /**
* @private * @private
* @param {Array.<WebGLTexture>} textures Textures. * @param {Array.<WebGLTexture>} textures Textures.
* @param {Array.<HTMLCanvasElement|HTMLImageElement|HTMLVideoElement>} images * @param {Array.<HTMLCanvasElement|HTMLImageElement|HTMLVideoElement>} images
@@ -345,7 +347,7 @@ ol.render.webgl.ImageReplay.prototype.finish = function(context) {
* @param {Object.<string, WebGLTexture>} texturePerImage Texture cache. * @param {Object.<string, WebGLTexture>} texturePerImage Texture cache.
* @param {WebGLRenderingContext} gl Gl. * @param {WebGLRenderingContext} gl Gl.
*/ */
ol.render.webgl.ImageReplay.prototype.createTextures_ = function(textures, images, texturePerImage, gl) { ol.render.webgl.ImageReplay.prototype.createTextures_ = function(textures, images, texturePerImage, gl) {
var texture, image, uid, i; var texture, image, uid, i;
var ii = images.length; var ii = images.length;
for (i = 0; i < ii; ++i) { for (i = 0; i < ii; ++i) {
@@ -361,13 +363,13 @@ ol.render.webgl.ImageReplay.prototype.createTextures_ = function(textures, image
} }
textures[i] = texture; textures[i] = texture;
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.ImageReplay.prototype.setUpProgram = function(gl, context, size, pixelRatio) { ol.render.webgl.ImageReplay.prototype.setUpProgram = function(gl, context, size, pixelRatio) {
// get the program // get the program
var fragmentShader = ol.render.webgl.imagereplay.defaultshader.fragment; var fragmentShader = ol.render.webgl.imagereplay.defaultshader.fragment;
var vertexShader = ol.render.webgl.imagereplay.defaultshader.vertex; var vertexShader = ol.render.webgl.imagereplay.defaultshader.vertex;
@@ -408,25 +410,25 @@ ol.render.webgl.ImageReplay.prototype.setUpProgram = function(gl, context, size,
false, 32, 28); false, 32, 28);
return locations; return locations;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.ImageReplay.prototype.shutDownProgram = function(gl, locations) { ol.render.webgl.ImageReplay.prototype.shutDownProgram = function(gl, locations) {
gl.disableVertexAttribArray(locations.a_position); gl.disableVertexAttribArray(locations.a_position);
gl.disableVertexAttribArray(locations.a_offsets); gl.disableVertexAttribArray(locations.a_offsets);
gl.disableVertexAttribArray(locations.a_texCoord); gl.disableVertexAttribArray(locations.a_texCoord);
gl.disableVertexAttribArray(locations.a_opacity); gl.disableVertexAttribArray(locations.a_opacity);
gl.disableVertexAttribArray(locations.a_rotateWithView); gl.disableVertexAttribArray(locations.a_rotateWithView);
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.ImageReplay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) { ol.render.webgl.ImageReplay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) {
var textures = hitDetection ? this.hitDetectionTextures_ : this.textures_; var textures = hitDetection ? this.hitDetectionTextures_ : this.textures_;
var groupIndices = hitDetection ? this.hitDetectionGroupIndices_ : this.groupIndices_; var groupIndices = hitDetection ? this.hitDetectionGroupIndices_ : this.groupIndices_;
@@ -442,10 +444,10 @@ ol.render.webgl.ImageReplay.prototype.drawReplay = function(gl, context, skipped
start = end; start = end;
} }
} }
}; };
/** /**
* Draw the replay while paying attention to skipped features. * Draw the replay while paying attention to skipped features.
* *
* This functions creates groups of features that can be drawn to together, * This functions creates groups of features that can be drawn to together,
@@ -471,7 +473,7 @@ ol.render.webgl.ImageReplay.prototype.drawReplay = function(gl, context, skipped
* @param {Array.<WebGLTexture>} textures Textures. * @param {Array.<WebGLTexture>} textures Textures.
* @param {Array.<number>} groupIndices Texture group indices. * @param {Array.<number>} groupIndices Texture group indices.
*/ */
ol.render.webgl.ImageReplay.prototype.drawReplaySkipping_ = function(gl, context, skippedFeaturesHash, textures, ol.render.webgl.ImageReplay.prototype.drawReplaySkipping_ = function(gl, context, skippedFeaturesHash, textures,
groupIndices) { groupIndices) {
var featureIndex = 0; var featureIndex = 0;
@@ -512,13 +514,13 @@ ol.render.webgl.ImageReplay.prototype.drawReplaySkipping_ = function(gl, context
this.drawElements(gl, context, start, end); this.drawElements(gl, context, start, end);
} }
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.ImageReplay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash, ol.render.webgl.ImageReplay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash,
featureCallback, opt_hitExtent) { featureCallback, opt_hitExtent) {
var i, groupStart, start, end, feature, featureUid; var i, groupStart, start, end, feature, featureUid;
var featureIndex = this.startIndices.length - 1; var featureIndex = this.startIndices.length - 1;
@@ -553,13 +555,13 @@ ol.render.webgl.ImageReplay.prototype.drawHitDetectionReplayOneByOne = function(
} }
} }
return undefined; return undefined;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.ImageReplay.prototype.setImageStyle = function(imageStyle) { ol.render.webgl.ImageReplay.prototype.setImageStyle = function(imageStyle) {
var anchor = imageStyle.getAnchor(); var anchor = imageStyle.getAnchor();
var image = imageStyle.getImage(1); var image = imageStyle.getImage(1);
var imageSize = imageStyle.getImageSize(); var imageSize = imageStyle.getImageSize();
@@ -605,4 +607,6 @@ ol.render.webgl.ImageReplay.prototype.setImageStyle = function(imageStyle) {
this.rotateWithView_ = rotateWithView; this.rotateWithView_ = rotateWithView;
this.scale_ = scale; this.scale_ = scale;
this.width_ = size[0]; this.width_ = size[0];
}; };
}
@@ -6,83 +6,85 @@ goog.require('ol.webgl.Fragment');
goog.require('ol.webgl.Vertex'); goog.require('ol.webgl.Vertex');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.webgl.Fragment} * @extends {ol.webgl.Fragment}
* @struct * @struct
*/ */
ol.render.webgl.imagereplay.defaultshader.Fragment = function() { ol.render.webgl.imagereplay.defaultshader.Fragment = function() {
ol.webgl.Fragment.call(this, ol.render.webgl.imagereplay.defaultshader.Fragment.SOURCE); ol.webgl.Fragment.call(this, ol.render.webgl.imagereplay.defaultshader.Fragment.SOURCE);
}; };
ol.inherits(ol.render.webgl.imagereplay.defaultshader.Fragment, ol.webgl.Fragment); ol.inherits(ol.render.webgl.imagereplay.defaultshader.Fragment, ol.webgl.Fragment);
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.imagereplay.defaultshader.Fragment.DEBUG_SOURCE = 'precision mediump float;\nvarying vec2 v_texCoord;\nvarying float v_opacity;\n\nuniform float u_opacity;\nuniform sampler2D u_image;\n\nvoid main(void) {\n vec4 texColor = texture2D(u_image, v_texCoord);\n gl_FragColor.rgb = texColor.rgb;\n float alpha = texColor.a * v_opacity * u_opacity;\n if (alpha == 0.0) {\n discard;\n }\n gl_FragColor.a = alpha;\n}\n'; ol.render.webgl.imagereplay.defaultshader.Fragment.DEBUG_SOURCE = 'precision mediump float;\nvarying vec2 v_texCoord;\nvarying float v_opacity;\n\nuniform float u_opacity;\nuniform sampler2D u_image;\n\nvoid main(void) {\n vec4 texColor = texture2D(u_image, v_texCoord);\n gl_FragColor.rgb = texColor.rgb;\n float alpha = texColor.a * v_opacity * u_opacity;\n if (alpha == 0.0) {\n discard;\n }\n gl_FragColor.a = alpha;\n}\n';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.imagereplay.defaultshader.Fragment.OPTIMIZED_SOURCE = 'precision mediump float;varying vec2 a;varying float b;uniform float k;uniform sampler2D l;void main(void){vec4 texColor=texture2D(l,a);gl_FragColor.rgb=texColor.rgb;float alpha=texColor.a*b*k;if(alpha==0.0){discard;}gl_FragColor.a=alpha;}'; ol.render.webgl.imagereplay.defaultshader.Fragment.OPTIMIZED_SOURCE = 'precision mediump float;varying vec2 a;varying float b;uniform float k;uniform sampler2D l;void main(void){vec4 texColor=texture2D(l,a);gl_FragColor.rgb=texColor.rgb;float alpha=texColor.a*b*k;if(alpha==0.0){discard;}gl_FragColor.a=alpha;}';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.imagereplay.defaultshader.Fragment.SOURCE = ol.render.webgl.imagereplay.defaultshader.Fragment.OPTIMIZED_SOURCE; ol.render.webgl.imagereplay.defaultshader.Fragment.SOURCE = ol.render.webgl.imagereplay.defaultshader.Fragment.OPTIMIZED_SOURCE;
ol.render.webgl.imagereplay.defaultshader.fragment = new ol.render.webgl.imagereplay.defaultshader.Fragment(); ol.render.webgl.imagereplay.defaultshader.fragment = new ol.render.webgl.imagereplay.defaultshader.Fragment();
/** /**
* @constructor * @constructor
* @extends {ol.webgl.Vertex} * @extends {ol.webgl.Vertex}
* @struct * @struct
*/ */
ol.render.webgl.imagereplay.defaultshader.Vertex = function() { ol.render.webgl.imagereplay.defaultshader.Vertex = function() {
ol.webgl.Vertex.call(this, ol.render.webgl.imagereplay.defaultshader.Vertex.SOURCE); ol.webgl.Vertex.call(this, ol.render.webgl.imagereplay.defaultshader.Vertex.SOURCE);
}; };
ol.inherits(ol.render.webgl.imagereplay.defaultshader.Vertex, ol.webgl.Vertex); ol.inherits(ol.render.webgl.imagereplay.defaultshader.Vertex, ol.webgl.Vertex);
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.imagereplay.defaultshader.Vertex.DEBUG_SOURCE = 'varying vec2 v_texCoord;\nvarying float v_opacity;\n\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nattribute vec2 a_offsets;\nattribute float a_opacity;\nattribute float a_rotateWithView;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform mat4 u_offsetRotateMatrix;\n\nvoid main(void) {\n mat4 offsetMatrix = u_offsetScaleMatrix;\n if (a_rotateWithView == 1.0) {\n offsetMatrix = u_offsetScaleMatrix * u_offsetRotateMatrix;\n }\n vec4 offsets = offsetMatrix * vec4(a_offsets, 0.0, 0.0);\n gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0) + offsets;\n v_texCoord = a_texCoord;\n v_opacity = a_opacity;\n}\n\n\n'; ol.render.webgl.imagereplay.defaultshader.Vertex.DEBUG_SOURCE = 'varying vec2 v_texCoord;\nvarying float v_opacity;\n\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nattribute vec2 a_offsets;\nattribute float a_opacity;\nattribute float a_rotateWithView;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform mat4 u_offsetRotateMatrix;\n\nvoid main(void) {\n mat4 offsetMatrix = u_offsetScaleMatrix;\n if (a_rotateWithView == 1.0) {\n offsetMatrix = u_offsetScaleMatrix * u_offsetRotateMatrix;\n }\n vec4 offsets = offsetMatrix * vec4(a_offsets, 0.0, 0.0);\n gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0) + offsets;\n v_texCoord = a_texCoord;\n v_opacity = a_opacity;\n}\n\n\n';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.imagereplay.defaultshader.Vertex.OPTIMIZED_SOURCE = 'varying vec2 a;varying float b;attribute vec2 c;attribute vec2 d;attribute vec2 e;attribute float f;attribute float g;uniform mat4 h;uniform mat4 i;uniform mat4 j;void main(void){mat4 offsetMatrix=i;if(g==1.0){offsetMatrix=i*j;}vec4 offsets=offsetMatrix*vec4(e,0.0,0.0);gl_Position=h*vec4(c,0.0,1.0)+offsets;a=d;b=f;}'; ol.render.webgl.imagereplay.defaultshader.Vertex.OPTIMIZED_SOURCE = 'varying vec2 a;varying float b;attribute vec2 c;attribute vec2 d;attribute vec2 e;attribute float f;attribute float g;uniform mat4 h;uniform mat4 i;uniform mat4 j;void main(void){mat4 offsetMatrix=i;if(g==1.0){offsetMatrix=i*j;}vec4 offsets=offsetMatrix*vec4(e,0.0,0.0);gl_Position=h*vec4(c,0.0,1.0)+offsets;a=d;b=f;}';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.imagereplay.defaultshader.Vertex.SOURCE = ol.render.webgl.imagereplay.defaultshader.Vertex.OPTIMIZED_SOURCE; ol.render.webgl.imagereplay.defaultshader.Vertex.SOURCE = ol.render.webgl.imagereplay.defaultshader.Vertex.OPTIMIZED_SOURCE;
ol.render.webgl.imagereplay.defaultshader.vertex = new ol.render.webgl.imagereplay.defaultshader.Vertex(); ol.render.webgl.imagereplay.defaultshader.vertex = new ol.render.webgl.imagereplay.defaultshader.Vertex();
/** /**
* @constructor * @constructor
* @param {WebGLRenderingContext} gl GL. * @param {WebGLRenderingContext} gl GL.
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @struct * @struct
*/ */
ol.render.webgl.imagereplay.defaultshader.Locations = function(gl, program) { ol.render.webgl.imagereplay.defaultshader.Locations = function(gl, program) {
/** /**
* @type {WebGLUniformLocation} * @type {WebGLUniformLocation}
@@ -133,4 +135,6 @@ ol.render.webgl.imagereplay.defaultshader.Locations = function(gl, program) {
* @type {number} * @type {number}
*/ */
this.a_texCoord = gl.getAttribLocation(program, 'd'); this.a_texCoord = gl.getAttribLocation(program, 'd');
}; };
}
+47 -43
View File
@@ -9,7 +9,9 @@ goog.require('ol.render.webgl.ReplayGroup');
goog.require('ol.render.webgl'); goog.require('ol.render.webgl');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.render.VectorContext} * @extends {ol.render.VectorContext}
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
@@ -21,7 +23,7 @@ goog.require('ol.render.webgl');
* @param {number} pixelRatio Pixel ratio. * @param {number} pixelRatio Pixel ratio.
* @struct * @struct
*/ */
ol.render.webgl.Immediate = function(context, center, resolution, rotation, size, extent, pixelRatio) { ol.render.webgl.Immediate = function(context, center, resolution, rotation, size, extent, pixelRatio) {
ol.render.VectorContext.call(this); ol.render.VectorContext.call(this);
/** /**
@@ -77,31 +79,31 @@ ol.render.webgl.Immediate = function(context, center, resolution, rotation, size
*/ */
this.strokeStyle_ = null; this.strokeStyle_ = null;
}; };
ol.inherits(ol.render.webgl.Immediate, ol.render.VectorContext); ol.inherits(ol.render.webgl.Immediate, ol.render.VectorContext);
/** /**
* Set the rendering style. Note that since this is an immediate rendering API, * Set the rendering style. Note that since this is an immediate rendering API,
* any `zIndex` on the provided style will be ignored. * any `zIndex` on the provided style will be ignored.
* *
* @param {ol.style.Style} style The rendering style. * @param {ol.style.Style} style The rendering style.
* @api * @api
*/ */
ol.render.webgl.Immediate.prototype.setStyle = function(style) { ol.render.webgl.Immediate.prototype.setStyle = function(style) {
this.setFillStrokeStyle(style.getFill(), style.getStroke()); this.setFillStrokeStyle(style.getFill(), style.getStroke());
this.setImageStyle(style.getImage()); this.setImageStyle(style.getImage());
}; };
/** /**
* Render a geometry into the canvas. Call * Render a geometry into the canvas. Call
* {@link ol.render.webgl.Immediate#setStyle} first to set the rendering style. * {@link ol.render.webgl.Immediate#setStyle} first to set the rendering style.
* *
* @param {ol.geom.Geometry|ol.render.Feature} geometry The geometry to render. * @param {ol.geom.Geometry|ol.render.Feature} geometry The geometry to render.
* @api * @api
*/ */
ol.render.webgl.Immediate.prototype.drawGeometry = function(geometry) { ol.render.webgl.Immediate.prototype.drawGeometry = function(geometry) {
var type = geometry.getType(); var type = geometry.getType();
switch (type) { switch (type) {
case ol.geom.GeometryType.POINT: case ol.geom.GeometryType.POINT:
@@ -131,14 +133,14 @@ ol.render.webgl.Immediate.prototype.drawGeometry = function(geometry) {
default: default:
// pass // pass
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
* @api * @api
*/ */
ol.render.webgl.Immediate.prototype.drawFeature = function(feature, style) { ol.render.webgl.Immediate.prototype.drawFeature = function(feature, style) {
var geometry = style.getGeometryFunction()(feature); var geometry = style.getGeometryFunction()(feature);
if (!geometry || if (!geometry ||
!ol.extent.intersects(this.extent_, geometry.getExtent())) { !ol.extent.intersects(this.extent_, geometry.getExtent())) {
@@ -146,25 +148,25 @@ ol.render.webgl.Immediate.prototype.drawFeature = function(feature, style) {
} }
this.setStyle(style); this.setStyle(style);
this.drawGeometry(geometry); this.drawGeometry(geometry);
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.Immediate.prototype.drawGeometryCollection = function(geometry, data) { ol.render.webgl.Immediate.prototype.drawGeometryCollection = function(geometry, data) {
var geometries = geometry.getGeometriesArray(); var geometries = geometry.getGeometriesArray();
var i, ii; var i, ii;
for (i = 0, ii = geometries.length; i < ii; ++i) { for (i = 0, ii = geometries.length; i < ii; ++i) {
this.drawGeometry(geometries[i]); this.drawGeometry(geometries[i]);
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.Immediate.prototype.drawPoint = function(geometry, data) { ol.render.webgl.Immediate.prototype.drawPoint = function(geometry, data) {
var context = this.context_; var context = this.context_;
var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_); var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_);
var replay = /** @type {ol.render.webgl.ImageReplay} */ ( var replay = /** @type {ol.render.webgl.ImageReplay} */ (
@@ -181,13 +183,13 @@ ol.render.webgl.Immediate.prototype.drawPoint = function(geometry, data) {
this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback, this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
oneByOne); oneByOne);
replay.getDeleteResourcesFunction(context)(); replay.getDeleteResourcesFunction(context)();
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.Immediate.prototype.drawMultiPoint = function(geometry, data) { ol.render.webgl.Immediate.prototype.drawMultiPoint = function(geometry, data) {
var context = this.context_; var context = this.context_;
var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_); var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_);
var replay = /** @type {ol.render.webgl.ImageReplay} */ ( var replay = /** @type {ol.render.webgl.ImageReplay} */ (
@@ -203,13 +205,13 @@ ol.render.webgl.Immediate.prototype.drawMultiPoint = function(geometry, data) {
this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback, this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
oneByOne); oneByOne);
replay.getDeleteResourcesFunction(context)(); replay.getDeleteResourcesFunction(context)();
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.Immediate.prototype.drawLineString = function(geometry, data) { ol.render.webgl.Immediate.prototype.drawLineString = function(geometry, data) {
var context = this.context_; var context = this.context_;
var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_); var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_);
var replay = /** @type {ol.render.webgl.LineStringReplay} */ ( var replay = /** @type {ol.render.webgl.LineStringReplay} */ (
@@ -225,13 +227,13 @@ ol.render.webgl.Immediate.prototype.drawLineString = function(geometry, data) {
this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback, this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
oneByOne); oneByOne);
replay.getDeleteResourcesFunction(context)(); replay.getDeleteResourcesFunction(context)();
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.Immediate.prototype.drawMultiLineString = function(geometry, data) { ol.render.webgl.Immediate.prototype.drawMultiLineString = function(geometry, data) {
var context = this.context_; var context = this.context_;
var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_); var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_);
var replay = /** @type {ol.render.webgl.LineStringReplay} */ ( var replay = /** @type {ol.render.webgl.LineStringReplay} */ (
@@ -247,13 +249,13 @@ ol.render.webgl.Immediate.prototype.drawMultiLineString = function(geometry, dat
this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback, this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
oneByOne); oneByOne);
replay.getDeleteResourcesFunction(context)(); replay.getDeleteResourcesFunction(context)();
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.Immediate.prototype.drawPolygon = function(geometry, data) { ol.render.webgl.Immediate.prototype.drawPolygon = function(geometry, data) {
var context = this.context_; var context = this.context_;
var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_); var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_);
var replay = /** @type {ol.render.webgl.PolygonReplay} */ ( var replay = /** @type {ol.render.webgl.PolygonReplay} */ (
@@ -269,13 +271,13 @@ ol.render.webgl.Immediate.prototype.drawPolygon = function(geometry, data) {
this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback, this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
oneByOne); oneByOne);
replay.getDeleteResourcesFunction(context)(); replay.getDeleteResourcesFunction(context)();
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.Immediate.prototype.drawMultiPolygon = function(geometry, data) { ol.render.webgl.Immediate.prototype.drawMultiPolygon = function(geometry, data) {
var context = this.context_; var context = this.context_;
var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_); var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_);
var replay = /** @type {ol.render.webgl.PolygonReplay} */ ( var replay = /** @type {ol.render.webgl.PolygonReplay} */ (
@@ -291,13 +293,13 @@ ol.render.webgl.Immediate.prototype.drawMultiPolygon = function(geometry, data)
this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback, this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
oneByOne); oneByOne);
replay.getDeleteResourcesFunction(context)(); replay.getDeleteResourcesFunction(context)();
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.Immediate.prototype.drawCircle = function(geometry, data) { ol.render.webgl.Immediate.prototype.drawCircle = function(geometry, data) {
var context = this.context_; var context = this.context_;
var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_); var replayGroup = new ol.render.webgl.ReplayGroup(1, this.extent_);
var replay = /** @type {ol.render.webgl.CircleReplay} */ ( var replay = /** @type {ol.render.webgl.CircleReplay} */ (
@@ -313,21 +315,23 @@ ol.render.webgl.Immediate.prototype.drawCircle = function(geometry, data) {
this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback, this.size_, this.pixelRatio_, opacity, skippedFeatures, featureCallback,
oneByOne); oneByOne);
replay.getDeleteResourcesFunction(context)(); replay.getDeleteResourcesFunction(context)();
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.Immediate.prototype.setImageStyle = function(imageStyle) { ol.render.webgl.Immediate.prototype.setImageStyle = function(imageStyle) {
this.imageStyle_ = imageStyle; this.imageStyle_ = imageStyle;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.Immediate.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) { ol.render.webgl.Immediate.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {
this.fillStyle_ = fillStyle; this.fillStyle_ = fillStyle;
this.strokeStyle_ = strokeStyle; this.strokeStyle_ = strokeStyle;
}; };
}
+62 -58
View File
@@ -15,14 +15,16 @@ goog.require('ol.webgl');
goog.require('ol.webgl.Buffer'); goog.require('ol.webgl.Buffer');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.render.webgl.Replay} * @extends {ol.render.webgl.Replay}
* @param {number} tolerance Tolerance. * @param {number} tolerance Tolerance.
* @param {ol.Extent} maxExtent Max extent. * @param {ol.Extent} maxExtent Max extent.
* @struct * @struct
*/ */
ol.render.webgl.LineStringReplay = function(tolerance, maxExtent) { ol.render.webgl.LineStringReplay = function(tolerance, maxExtent) {
ol.render.webgl.Replay.call(this, tolerance, maxExtent); ol.render.webgl.Replay.call(this, tolerance, maxExtent);
/** /**
@@ -63,11 +65,11 @@ ol.render.webgl.LineStringReplay = function(tolerance, maxExtent) {
changed: false changed: false
}; };
}; };
ol.inherits(ol.render.webgl.LineStringReplay, ol.render.webgl.Replay); ol.inherits(ol.render.webgl.LineStringReplay, ol.render.webgl.Replay);
/** /**
* Draw one segment. * Draw one segment.
* @private * @private
* @param {Array.<number>} flatCoordinates Flat coordinates. * @param {Array.<number>} flatCoordinates Flat coordinates.
@@ -75,7 +77,7 @@ ol.inherits(ol.render.webgl.LineStringReplay, ol.render.webgl.Replay);
* @param {number} end End. * @param {number} end End.
* @param {number} stride Stride. * @param {number} stride Stride.
*/ */
ol.render.webgl.LineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, offset, end, stride) { ol.render.webgl.LineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, offset, end, stride) {
var i, ii; var i, ii;
var numVertices = this.vertices.length; var numVertices = this.vertices.length;
@@ -248,9 +250,9 @@ ol.render.webgl.LineStringReplay.prototype.drawCoordinates_ = function(flatCoord
this.indices[numIndices++] = n; this.indices[numIndices++] = n;
this.indices[numIndices++] = lastSign * sign > 0 ? lastIndex : lastIndex - 1; this.indices[numIndices++] = lastSign * sign > 0 ? lastIndex : lastIndex - 1;
} }
}; };
/** /**
* @param {Array.<number>} p0 Last coordinates. * @param {Array.<number>} p0 Last coordinates.
* @param {Array.<number>} p1 Current coordinates. * @param {Array.<number>} p1 Current coordinates.
* @param {Array.<number>} p2 Next coordinates. * @param {Array.<number>} p2 Next coordinates.
@@ -259,7 +261,7 @@ ol.render.webgl.LineStringReplay.prototype.drawCoordinates_ = function(flatCoord
* @return {number} Vertex counter. * @return {number} Vertex counter.
* @private * @private
*/ */
ol.render.webgl.LineStringReplay.prototype.addVertices_ = function(p0, p1, p2, product, numVertices) { ol.render.webgl.LineStringReplay.prototype.addVertices_ = function(p0, p1, p2, product, numVertices) {
this.vertices[numVertices++] = p0[0]; this.vertices[numVertices++] = p0[0];
this.vertices[numVertices++] = p0[1]; this.vertices[numVertices++] = p0[1];
this.vertices[numVertices++] = p1[0]; this.vertices[numVertices++] = p1[0];
@@ -269,9 +271,9 @@ ol.render.webgl.LineStringReplay.prototype.addVertices_ = function(p0, p1, p2, p
this.vertices[numVertices++] = product; this.vertices[numVertices++] = product;
return numVertices; return numVertices;
}; };
/** /**
* Check if the linestring can be drawn (i. e. valid). * Check if the linestring can be drawn (i. e. valid).
* @param {Array.<number>} flatCoordinates Flat coordinates. * @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset. * @param {number} offset Offset.
@@ -280,7 +282,7 @@ ol.render.webgl.LineStringReplay.prototype.addVertices_ = function(p0, p1, p2, p
* @return {boolean} The linestring can be drawn. * @return {boolean} The linestring can be drawn.
* @private * @private
*/ */
ol.render.webgl.LineStringReplay.prototype.isValid_ = function(flatCoordinates, offset, end, stride) { ol.render.webgl.LineStringReplay.prototype.isValid_ = function(flatCoordinates, offset, end, stride) {
var range = end - offset; var range = end - offset;
if (range < stride * 2) { if (range < stride * 2) {
return false; return false;
@@ -291,13 +293,13 @@ ol.render.webgl.LineStringReplay.prototype.isValid_ = function(flatCoordinates,
} }
return true; return true;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.LineStringReplay.prototype.drawLineString = function(lineStringGeometry, feature) { ol.render.webgl.LineStringReplay.prototype.drawLineString = function(lineStringGeometry, feature) {
var flatCoordinates = lineStringGeometry.getFlatCoordinates(); var flatCoordinates = lineStringGeometry.getFlatCoordinates();
var stride = lineStringGeometry.getStride(); var stride = lineStringGeometry.getStride();
if (this.isValid_(flatCoordinates, 0, flatCoordinates.length, stride)) { if (this.isValid_(flatCoordinates, 0, flatCoordinates.length, stride)) {
@@ -312,13 +314,13 @@ ol.render.webgl.LineStringReplay.prototype.drawLineString = function(lineStringG
this.drawCoordinates_( this.drawCoordinates_(
flatCoordinates, 0, flatCoordinates.length, stride); flatCoordinates, 0, flatCoordinates.length, stride);
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.LineStringReplay.prototype.drawMultiLineString = function(multiLineStringGeometry, feature) { ol.render.webgl.LineStringReplay.prototype.drawMultiLineString = function(multiLineStringGeometry, feature) {
var indexCount = this.indices.length; var indexCount = this.indices.length;
var lineStringGeometries = multiLineStringGeometry.getLineStrings(); var lineStringGeometries = multiLineStringGeometry.getLineStrings();
var i, ii; var i, ii;
@@ -340,15 +342,15 @@ ol.render.webgl.LineStringReplay.prototype.drawMultiLineString = function(multiL
this.state_.changed = false; this.state_.changed = false;
} }
} }
}; };
/** /**
* @param {Array.<number>} flatCoordinates Flat coordinates. * @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {Array.<Array.<number>>} holeFlatCoordinates Hole flat coordinates. * @param {Array.<Array.<number>>} holeFlatCoordinates Hole flat coordinates.
* @param {number} stride Stride. * @param {number} stride Stride.
*/ */
ol.render.webgl.LineStringReplay.prototype.drawPolygonCoordinates = function( ol.render.webgl.LineStringReplay.prototype.drawPolygonCoordinates = function(
flatCoordinates, holeFlatCoordinates, stride) { flatCoordinates, holeFlatCoordinates, stride) {
if (!ol.geom.flat.topology.lineStringIsClosed(flatCoordinates, 0, if (!ol.geom.flat.topology.lineStringIsClosed(flatCoordinates, 0,
flatCoordinates.length, stride)) { flatCoordinates.length, stride)) {
@@ -368,14 +370,14 @@ ol.render.webgl.LineStringReplay.prototype.drawPolygonCoordinates = function(
holeFlatCoordinates[i].length, stride); holeFlatCoordinates[i].length, stride);
} }
} }
}; };
/** /**
* @param {ol.Feature|ol.render.Feature} feature Feature. * @param {ol.Feature|ol.render.Feature} feature Feature.
* @param {number=} opt_index Index count. * @param {number=} opt_index Index count.
*/ */
ol.render.webgl.LineStringReplay.prototype.setPolygonStyle = function(feature, opt_index) { ol.render.webgl.LineStringReplay.prototype.setPolygonStyle = function(feature, opt_index) {
var index = opt_index === undefined ? this.indices.length : opt_index; var index = opt_index === undefined ? this.indices.length : opt_index;
this.startIndices.push(index); this.startIndices.push(index);
this.startIndicesFeature.push(feature); this.startIndicesFeature.push(feature);
@@ -383,21 +385,21 @@ ol.render.webgl.LineStringReplay.prototype.setPolygonStyle = function(feature, o
this.styleIndices_.push(index); this.styleIndices_.push(index);
this.state_.changed = false; this.state_.changed = false;
} }
}; };
/** /**
* @return {number} Current index. * @return {number} Current index.
*/ */
ol.render.webgl.LineStringReplay.prototype.getCurrentIndex = function() { ol.render.webgl.LineStringReplay.prototype.getCurrentIndex = function() {
return this.indices.length; return this.indices.length;
}; };
/** /**
* @inheritDoc * @inheritDoc
**/ **/
ol.render.webgl.LineStringReplay.prototype.finish = function(context) { ol.render.webgl.LineStringReplay.prototype.finish = function(context) {
// create, bind, and populate the vertices buffer // create, bind, and populate the vertices buffer
this.verticesBuffer = new ol.webgl.Buffer(this.vertices); this.verticesBuffer = new ol.webgl.Buffer(this.vertices);
@@ -413,26 +415,26 @@ ol.render.webgl.LineStringReplay.prototype.finish = function(context) {
this.vertices = null; this.vertices = null;
this.indices = null; this.indices = null;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.LineStringReplay.prototype.getDeleteResourcesFunction = function(context) { ol.render.webgl.LineStringReplay.prototype.getDeleteResourcesFunction = function(context) {
var verticesBuffer = this.verticesBuffer; var verticesBuffer = this.verticesBuffer;
var indicesBuffer = this.indicesBuffer; var indicesBuffer = this.indicesBuffer;
return function() { return function() {
context.deleteBuffer(verticesBuffer); context.deleteBuffer(verticesBuffer);
context.deleteBuffer(indicesBuffer); context.deleteBuffer(indicesBuffer);
}; };
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.LineStringReplay.prototype.setUpProgram = function(gl, context, size, pixelRatio) { ol.render.webgl.LineStringReplay.prototype.setUpProgram = function(gl, context, size, pixelRatio) {
// get the program // get the program
var fragmentShader, vertexShader; var fragmentShader, vertexShader;
fragmentShader = ol.render.webgl.linestringreplay.defaultshader.fragment; fragmentShader = ol.render.webgl.linestringreplay.defaultshader.fragment;
@@ -473,24 +475,24 @@ ol.render.webgl.LineStringReplay.prototype.setUpProgram = function(gl, context,
gl.uniform1f(locations.u_pixelRatio, pixelRatio); gl.uniform1f(locations.u_pixelRatio, pixelRatio);
return locations; return locations;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.LineStringReplay.prototype.shutDownProgram = function(gl, locations) { ol.render.webgl.LineStringReplay.prototype.shutDownProgram = function(gl, locations) {
gl.disableVertexAttribArray(locations.a_lastPos); gl.disableVertexAttribArray(locations.a_lastPos);
gl.disableVertexAttribArray(locations.a_position); gl.disableVertexAttribArray(locations.a_position);
gl.disableVertexAttribArray(locations.a_nextPos); gl.disableVertexAttribArray(locations.a_nextPos);
gl.disableVertexAttribArray(locations.a_direction); gl.disableVertexAttribArray(locations.a_direction);
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.LineStringReplay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) { ol.render.webgl.LineStringReplay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) {
//Save GL parameters. //Save GL parameters.
var tmpDepthFunc = /** @type {number} */ (gl.getParameter(gl.DEPTH_FUNC)); var tmpDepthFunc = /** @type {number} */ (gl.getParameter(gl.DEPTH_FUNC));
var tmpDepthMask = /** @type {boolean} */ (gl.getParameter(gl.DEPTH_WRITEMASK)); var tmpDepthMask = /** @type {boolean} */ (gl.getParameter(gl.DEPTH_WRITEMASK));
@@ -523,16 +525,16 @@ ol.render.webgl.LineStringReplay.prototype.drawReplay = function(gl, context, sk
gl.depthMask(tmpDepthMask); gl.depthMask(tmpDepthMask);
gl.depthFunc(tmpDepthFunc); gl.depthFunc(tmpDepthFunc);
} }
}; };
/** /**
* @private * @private
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
* @param {Object} skippedFeaturesHash Ids of features to skip. * @param {Object} skippedFeaturesHash Ids of features to skip.
*/ */
ol.render.webgl.LineStringReplay.prototype.drawReplaySkipping_ = function(gl, context, skippedFeaturesHash) { ol.render.webgl.LineStringReplay.prototype.drawReplaySkipping_ = function(gl, context, skippedFeaturesHash) {
var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex, featureStart; var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex, featureStart;
featureIndex = this.startIndices.length - 2; featureIndex = this.startIndices.length - 2;
end = start = this.startIndices[featureIndex + 1]; end = start = this.startIndices[featureIndex + 1];
@@ -563,13 +565,13 @@ ol.render.webgl.LineStringReplay.prototype.drawReplaySkipping_ = function(gl, co
} }
start = end = groupStart; start = end = groupStart;
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.LineStringReplay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash, ol.render.webgl.LineStringReplay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash,
featureCallback, opt_hitExtent) { featureCallback, opt_hitExtent) {
var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex; var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex;
featureIndex = this.startIndices.length - 2; featureIndex = this.startIndices.length - 2;
@@ -605,27 +607,27 @@ ol.render.webgl.LineStringReplay.prototype.drawHitDetectionReplayOneByOne = func
} }
} }
return undefined; return undefined;
}; };
/** /**
* @private * @private
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
* @param {Array.<number>} color Color. * @param {Array.<number>} color Color.
* @param {number} lineWidth Line width. * @param {number} lineWidth Line width.
* @param {number} miterLimit Miter limit. * @param {number} miterLimit Miter limit.
*/ */
ol.render.webgl.LineStringReplay.prototype.setStrokeStyle_ = function(gl, color, lineWidth, miterLimit) { ol.render.webgl.LineStringReplay.prototype.setStrokeStyle_ = function(gl, color, lineWidth, miterLimit) {
gl.uniform4fv(this.defaultLocations_.u_color, color); gl.uniform4fv(this.defaultLocations_.u_color, color);
gl.uniform1f(this.defaultLocations_.u_lineWidth, lineWidth); gl.uniform1f(this.defaultLocations_.u_lineWidth, lineWidth);
gl.uniform1f(this.defaultLocations_.u_miterLimit, miterLimit); gl.uniform1f(this.defaultLocations_.u_miterLimit, miterLimit);
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.LineStringReplay.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) { ol.render.webgl.LineStringReplay.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {
var strokeStyleLineCap = strokeStyle.getLineCap(); var strokeStyleLineCap = strokeStyle.getLineCap();
this.state_.lineCap = strokeStyleLineCap !== undefined ? this.state_.lineCap = strokeStyleLineCap !== undefined ?
strokeStyleLineCap : ol.render.webgl.defaultLineCap; strokeStyleLineCap : ol.render.webgl.defaultLineCap;
@@ -658,13 +660,13 @@ ol.render.webgl.LineStringReplay.prototype.setFillStrokeStyle = function(fillSty
this.state_.miterLimit = strokeStyleMiterLimit; this.state_.miterLimit = strokeStyleMiterLimit;
this.styles_.push([strokeStyleColor, strokeStyleWidth, strokeStyleMiterLimit]); this.styles_.push([strokeStyleColor, strokeStyleWidth, strokeStyleMiterLimit]);
} }
}; };
/** /**
* @enum {number} * @enum {number}
* @private * @private
*/ */
ol.render.webgl.LineStringReplay.Instruction_ = { ol.render.webgl.LineStringReplay.Instruction_ = {
ROUND: 2, ROUND: 2,
BEGIN_LINE: 3, BEGIN_LINE: 3,
END_LINE: 5, END_LINE: 5,
@@ -674,4 +676,6 @@ ol.render.webgl.LineStringReplay.Instruction_ = {
BEVEL_SECOND: 17, BEVEL_SECOND: 17,
MITER_BOTTOM: 19, MITER_BOTTOM: 19,
MITER_TOP: 23 MITER_TOP: 23
}; };
}
File diff suppressed because one or more lines are too long
+92 -88
View File
@@ -19,14 +19,16 @@ goog.require('ol.webgl');
goog.require('ol.webgl.Buffer'); goog.require('ol.webgl.Buffer');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.render.webgl.Replay} * @extends {ol.render.webgl.Replay}
* @param {number} tolerance Tolerance. * @param {number} tolerance Tolerance.
* @param {ol.Extent} maxExtent Max extent. * @param {ol.Extent} maxExtent Max extent.
* @struct * @struct
*/ */
ol.render.webgl.PolygonReplay = function(tolerance, maxExtent) { ol.render.webgl.PolygonReplay = function(tolerance, maxExtent) {
ol.render.webgl.Replay.call(this, tolerance, maxExtent); ol.render.webgl.Replay.call(this, tolerance, maxExtent);
this.lineStringReplay = new ol.render.webgl.LineStringReplay( this.lineStringReplay = new ol.render.webgl.LineStringReplay(
@@ -60,18 +62,18 @@ ol.render.webgl.PolygonReplay = function(tolerance, maxExtent) {
changed: false changed: false
}; };
}; };
ol.inherits(ol.render.webgl.PolygonReplay, ol.render.webgl.Replay); ol.inherits(ol.render.webgl.PolygonReplay, ol.render.webgl.Replay);
/** /**
* Draw one polygon. * Draw one polygon.
* @param {Array.<number>} flatCoordinates Flat coordinates. * @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {Array.<Array.<number>>} holeFlatCoordinates Hole flat coordinates. * @param {Array.<Array.<number>>} holeFlatCoordinates Hole flat coordinates.
* @param {number} stride Stride. * @param {number} stride Stride.
* @private * @private
*/ */
ol.render.webgl.PolygonReplay.prototype.drawCoordinates_ = function( ol.render.webgl.PolygonReplay.prototype.drawCoordinates_ = function(
flatCoordinates, holeFlatCoordinates, stride) { flatCoordinates, holeFlatCoordinates, stride) {
// Triangulate the polygon // Triangulate the polygon
var outerRing = new ol.structs.LinkedList(); var outerRing = new ol.structs.LinkedList();
@@ -101,10 +103,10 @@ ol.render.webgl.PolygonReplay.prototype.drawCoordinates_ = function(
} }
this.classifyPoints_(outerRing, rtree, false); this.classifyPoints_(outerRing, rtree, false);
this.triangulate_(outerRing, rtree); this.triangulate_(outerRing, rtree);
}; };
/** /**
* Inserts flat coordinates in a linked list and adds them to the vertex buffer. * Inserts flat coordinates in a linked list and adds them to the vertex buffer.
* @private * @private
* @param {Array.<number>} flatCoordinates Flat coordinates. * @param {Array.<number>} flatCoordinates Flat coordinates.
@@ -114,7 +116,7 @@ ol.render.webgl.PolygonReplay.prototype.drawCoordinates_ = function(
* @param {boolean} clockwise Coordinate order should be clockwise. * @param {boolean} clockwise Coordinate order should be clockwise.
* @return {number} Maximum X value. * @return {number} Maximum X value.
*/ */
ol.render.webgl.PolygonReplay.prototype.processFlatCoordinates_ = function( ol.render.webgl.PolygonReplay.prototype.processFlatCoordinates_ = function(
flatCoordinates, stride, list, rtree, clockwise) { flatCoordinates, stride, list, rtree, clockwise) {
var isClockwise = ol.geom.flat.orient.linearRingIsClockwise(flatCoordinates, var isClockwise = ol.geom.flat.orient.linearRingIsClockwise(flatCoordinates,
0, flatCoordinates.length, stride); 0, flatCoordinates.length, stride);
@@ -163,10 +165,10 @@ ol.render.webgl.PolygonReplay.prototype.processFlatCoordinates_ = function(
rtree.load(extents, segments); rtree.load(extents, segments);
return maxX; return maxX;
}; };
/** /**
* Classifies the points of a polygon list as convex, reflex. Removes collinear vertices. * Classifies the points of a polygon list as convex, reflex. Removes collinear vertices.
* @private * @private
* @param {ol.structs.LinkedList} list Polygon ring. * @param {ol.structs.LinkedList} list Polygon ring.
@@ -174,7 +176,7 @@ ol.render.webgl.PolygonReplay.prototype.processFlatCoordinates_ = function(
* @param {boolean} ccw The orientation of the polygon is counter-clockwise. * @param {boolean} ccw The orientation of the polygon is counter-clockwise.
* @return {boolean} There were reclassified points. * @return {boolean} There were reclassified points.
*/ */
ol.render.webgl.PolygonReplay.prototype.classifyPoints_ = function(list, rtree, ccw) { ol.render.webgl.PolygonReplay.prototype.classifyPoints_ = function(list, rtree, ccw) {
var start = list.firstItem(); var start = list.firstItem();
var s0 = start; var s0 = start;
var s1 = list.nextItem(); var s1 = list.nextItem();
@@ -200,10 +202,10 @@ ol.render.webgl.PolygonReplay.prototype.classifyPoints_ = function(list, rtree,
s1 = list.nextItem(); s1 = list.nextItem();
} while (s0 !== start); } while (s0 !== start);
return pointsReclassified; return pointsReclassified;
}; };
/** /**
* @private * @private
* @param {ol.structs.LinkedList} hole Linked list of the hole. * @param {ol.structs.LinkedList} hole Linked list of the hole.
* @param {number} holeMaxX Maximum X value of the hole. * @param {number} holeMaxX Maximum X value of the hole.
@@ -211,7 +213,7 @@ ol.render.webgl.PolygonReplay.prototype.classifyPoints_ = function(list, rtree,
* @param {number} listMaxX Maximum X value of the polygon. * @param {number} listMaxX Maximum X value of the polygon.
* @param {ol.structs.RBush} rtree R-Tree of the polygon. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
*/ */
ol.render.webgl.PolygonReplay.prototype.bridgeHole_ = function(hole, holeMaxX, ol.render.webgl.PolygonReplay.prototype.bridgeHole_ = function(hole, holeMaxX,
list, listMaxX, rtree) { list, listMaxX, rtree) {
this.classifyPoints_(hole, rtree, true); this.classifyPoints_(hole, rtree, true);
var seg = hole.firstItem(); var seg = hole.firstItem();
@@ -276,15 +278,15 @@ ol.render.webgl.PolygonReplay.prototype.bridgeHole_ = function(hole, holeMaxX,
seg.p1 = p1Bridge; seg.p1 = p1Bridge;
hole.setFirstItem(); hole.setFirstItem();
list.concat(hole); list.concat(hole);
}; };
/** /**
* @private * @private
* @param {ol.structs.LinkedList} list Linked list of the polygon. * @param {ol.structs.LinkedList} list Linked list of the polygon.
* @param {ol.structs.RBush} rtree R-Tree of the polygon. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
*/ */
ol.render.webgl.PolygonReplay.prototype.triangulate_ = function(list, rtree) { ol.render.webgl.PolygonReplay.prototype.triangulate_ = function(list, rtree) {
var ccw = false; var ccw = false;
var simple = this.isSimple_(list, rtree); var simple = this.isSimple_(list, rtree);
@@ -326,10 +328,10 @@ ol.render.webgl.PolygonReplay.prototype.triangulate_ = function(list, rtree) {
this.indices[numIndices++] = list.getCurrItem().p0.i; this.indices[numIndices++] = list.getCurrItem().p0.i;
this.indices[numIndices++] = list.getNextItem().p0.i; this.indices[numIndices++] = list.getNextItem().p0.i;
} }
}; };
/** /**
* @private * @private
* @param {ol.structs.LinkedList} list Linked list of the polygon. * @param {ol.structs.LinkedList} list Linked list of the polygon.
* @param {ol.structs.RBush} rtree R-Tree of the polygon. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
@@ -337,7 +339,7 @@ ol.render.webgl.PolygonReplay.prototype.triangulate_ = function(list, rtree) {
* @param {boolean} ccw Orientation of the polygon is counter-clockwise. * @param {boolean} ccw Orientation of the polygon is counter-clockwise.
* @return {boolean} There were processed ears. * @return {boolean} There were processed ears.
*/ */
ol.render.webgl.PolygonReplay.prototype.clipEars_ = function(list, rtree, simple, ccw) { ol.render.webgl.PolygonReplay.prototype.clipEars_ = function(list, rtree, simple, ccw) {
var numIndices = this.indices.length; var numIndices = this.indices.length;
var start = list.firstItem(); var start = list.firstItem();
var s0 = list.getPrevItem(); var s0 = list.getPrevItem();
@@ -380,17 +382,17 @@ ol.render.webgl.PolygonReplay.prototype.clipEars_ = function(list, rtree, simple
} while (s1 !== start && list.getLength() > 3); } while (s1 !== start && list.getLength() > 3);
return processedEars; return processedEars;
}; };
/** /**
* @private * @private
* @param {ol.structs.LinkedList} list Linked list of the polygon. * @param {ol.structs.LinkedList} list Linked list of the polygon.
* @param {ol.structs.RBush} rtree R-Tree of the polygon. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
* @param {boolean=} opt_touch Resolve touching segments. * @param {boolean=} opt_touch Resolve touching segments.
* @return {boolean} There were resolved intersections. * @return {boolean} There were resolved intersections.
*/ */
ol.render.webgl.PolygonReplay.prototype.resolveLocalSelfIntersections_ = function( ol.render.webgl.PolygonReplay.prototype.resolveLocalSelfIntersections_ = function(
list, rtree, opt_touch) { list, rtree, opt_touch) {
var start = list.firstItem(); var start = list.firstItem();
list.nextItem(); list.nextItem();
@@ -449,16 +451,16 @@ ol.render.webgl.PolygonReplay.prototype.resolveLocalSelfIntersections_ = functio
s1 = list.nextItem(); s1 = list.nextItem();
} while (s0 !== start); } while (s0 !== start);
return resolvedIntersections; return resolvedIntersections;
}; };
/** /**
* @private * @private
* @param {ol.structs.LinkedList} list Linked list of the polygon. * @param {ol.structs.LinkedList} list Linked list of the polygon.
* @param {ol.structs.RBush} rtree R-Tree of the polygon. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
* @return {boolean} The polygon is simple. * @return {boolean} The polygon is simple.
*/ */
ol.render.webgl.PolygonReplay.prototype.isSimple_ = function(list, rtree) { ol.render.webgl.PolygonReplay.prototype.isSimple_ = function(list, rtree) {
var start = list.firstItem(); var start = list.firstItem();
var seg = start; var seg = start;
do { do {
@@ -468,15 +470,15 @@ ol.render.webgl.PolygonReplay.prototype.isSimple_ = function(list, rtree) {
seg = list.nextItem(); seg = list.nextItem();
} while (seg !== start); } while (seg !== start);
return true; return true;
}; };
/** /**
* @private * @private
* @param {ol.structs.LinkedList} list Linked list of the polygon. * @param {ol.structs.LinkedList} list Linked list of the polygon.
* @return {boolean} Orientation is clockwise. * @return {boolean} Orientation is clockwise.
*/ */
ol.render.webgl.PolygonReplay.prototype.isClockwise_ = function(list) { ol.render.webgl.PolygonReplay.prototype.isClockwise_ = function(list) {
var length = list.getLength() * 2; var length = list.getLength() * 2;
var flatCoordinates = new Array(length); var flatCoordinates = new Array(length);
var start = list.firstItem(); var start = list.firstItem();
@@ -488,15 +490,15 @@ ol.render.webgl.PolygonReplay.prototype.isClockwise_ = function(list) {
seg = list.nextItem(); seg = list.nextItem();
} while (seg !== start); } while (seg !== start);
return ol.geom.flat.orient.linearRingIsClockwise(flatCoordinates, 0, length, 2); return ol.geom.flat.orient.linearRingIsClockwise(flatCoordinates, 0, length, 2);
}; };
/** /**
* @private * @private
* @param {ol.structs.LinkedList} list Linked list of the polygon. * @param {ol.structs.LinkedList} list Linked list of the polygon.
* @param {ol.structs.RBush} rtree R-Tree of the polygon. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
*/ */
ol.render.webgl.PolygonReplay.prototype.splitPolygon_ = function(list, rtree) { ol.render.webgl.PolygonReplay.prototype.splitPolygon_ = function(list, rtree) {
var start = list.firstItem(); var start = list.firstItem();
var s0 = start; var s0 = start;
do { do {
@@ -532,17 +534,17 @@ ol.render.webgl.PolygonReplay.prototype.splitPolygon_ = function(list, rtree) {
} }
s0 = list.nextItem(); s0 = list.nextItem();
} while (s0 !== start); } while (s0 !== start);
}; };
/** /**
* @private * @private
* @param {number} x X coordinate. * @param {number} x X coordinate.
* @param {number} y Y coordinate. * @param {number} y Y coordinate.
* @param {number} i Index. * @param {number} i Index.
* @return {ol.WebglPolygonVertex} List item. * @return {ol.WebglPolygonVertex} List item.
*/ */
ol.render.webgl.PolygonReplay.prototype.createPoint_ = function(x, y, i) { ol.render.webgl.PolygonReplay.prototype.createPoint_ = function(x, y, i) {
var numVertices = this.vertices.length; var numVertices = this.vertices.length;
this.vertices[numVertices++] = x; this.vertices[numVertices++] = x;
this.vertices[numVertices++] = y; this.vertices[numVertices++] = y;
@@ -554,10 +556,10 @@ ol.render.webgl.PolygonReplay.prototype.createPoint_ = function(x, y, i) {
reflex: undefined reflex: undefined
}; };
return p; return p;
}; };
/** /**
* @private * @private
* @param {ol.WebglPolygonVertex} p0 First point of segment. * @param {ol.WebglPolygonVertex} p0 First point of segment.
* @param {ol.WebglPolygonVertex} p1 Second point of segment. * @param {ol.WebglPolygonVertex} p1 Second point of segment.
@@ -565,7 +567,7 @@ ol.render.webgl.PolygonReplay.prototype.createPoint_ = function(x, y, i) {
* @param {ol.structs.RBush=} opt_rtree Insert the segment into the R-Tree. * @param {ol.structs.RBush=} opt_rtree Insert the segment into the R-Tree.
* @return {ol.WebglPolygonSegment} segment. * @return {ol.WebglPolygonSegment} segment.
*/ */
ol.render.webgl.PolygonReplay.prototype.insertItem_ = function(p0, p1, list, opt_rtree) { ol.render.webgl.PolygonReplay.prototype.insertItem_ = function(p0, p1, list, opt_rtree) {
var seg = { var seg = {
p0: p0, p0: p0,
p1: p1 p1: p1
@@ -576,7 +578,7 @@ ol.render.webgl.PolygonReplay.prototype.insertItem_ = function(p0, p1, list, opt
Math.max(p0.x, p1.x), Math.max(p0.y, p1.y)], seg); Math.max(p0.x, p1.x), Math.max(p0.y, p1.y)], seg);
} }
return seg; return seg;
}; };
/** /**
@@ -586,7 +588,7 @@ ol.render.webgl.PolygonReplay.prototype.insertItem_ = function(p0, p1, list, opt
* @param {ol.structs.LinkedList} list Polygon ring. * @param {ol.structs.LinkedList} list Polygon ring.
* @param {ol.structs.RBush} rtree R-Tree of the polygon. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
*/ */
ol.render.webgl.PolygonReplay.prototype.removeItem_ = function(s0, s1, list, rtree) { ol.render.webgl.PolygonReplay.prototype.removeItem_ = function(s0, s1, list, rtree) {
if (list.getCurrItem() === s1) { if (list.getCurrItem() === s1) {
list.removeItem(); list.removeItem();
s0.p1 = s1.p1; s0.p1 = s1.p1;
@@ -594,10 +596,10 @@ ol.render.webgl.PolygonReplay.prototype.removeItem_ = function(s0, s1, list, rtr
rtree.update([Math.min(s0.p0.x, s0.p1.x), Math.min(s0.p0.y, s0.p1.y), rtree.update([Math.min(s0.p0.x, s0.p1.x), Math.min(s0.p0.y, s0.p1.y),
Math.max(s0.p0.x, s0.p1.x), Math.max(s0.p0.y, s0.p1.y)], s0); Math.max(s0.p0.x, s0.p1.x), Math.max(s0.p0.y, s0.p1.y)], s0);
} }
}; };
/** /**
* @private * @private
* @param {ol.WebglPolygonVertex} p0 First point. * @param {ol.WebglPolygonVertex} p0 First point.
* @param {ol.WebglPolygonVertex} p1 Second point. * @param {ol.WebglPolygonVertex} p1 Second point.
@@ -606,7 +608,7 @@ ol.render.webgl.PolygonReplay.prototype.removeItem_ = function(s0, s1, list, rtr
* @param {boolean=} opt_reflex Only include reflex points. * @param {boolean=} opt_reflex Only include reflex points.
* @return {Array.<ol.WebglPolygonVertex>} Points in the triangle. * @return {Array.<ol.WebglPolygonVertex>} Points in the triangle.
*/ */
ol.render.webgl.PolygonReplay.prototype.getPointsInTriangle_ = function(p0, p1, ol.render.webgl.PolygonReplay.prototype.getPointsInTriangle_ = function(p0, p1,
p2, rtree, opt_reflex) { p2, rtree, opt_reflex) {
var i, ii, j, p; var i, ii, j, p;
var result = []; var result = [];
@@ -627,17 +629,17 @@ ol.render.webgl.PolygonReplay.prototype.getPointsInTriangle_ = function(p0, p1,
} }
} }
return result; return result;
}; };
/** /**
* @private * @private
* @param {ol.WebglPolygonSegment} segment Segment. * @param {ol.WebglPolygonSegment} segment Segment.
* @param {ol.structs.RBush} rtree R-Tree of the polygon. * @param {ol.structs.RBush} rtree R-Tree of the polygon.
* @param {boolean=} opt_touch Touching segments should be considered an intersection. * @param {boolean=} opt_touch Touching segments should be considered an intersection.
* @return {Array.<ol.WebglPolygonSegment>} Intersecting segments. * @return {Array.<ol.WebglPolygonSegment>} Intersecting segments.
*/ */
ol.render.webgl.PolygonReplay.prototype.getIntersections_ = function(segment, rtree, opt_touch) { ol.render.webgl.PolygonReplay.prototype.getIntersections_ = function(segment, rtree, opt_touch) {
var p0 = segment.p0; var p0 = segment.p0;
var p1 = segment.p1; var p1 = segment.p1;
var segmentsInExtent = rtree.getInExtent([Math.min(p0.x, p1.x), var segmentsInExtent = rtree.getInExtent([Math.min(p0.x, p1.x),
@@ -652,10 +654,10 @@ ol.render.webgl.PolygonReplay.prototype.getIntersections_ = function(segment, rt
} }
} }
return result; return result;
}; };
/** /**
* Line intersection algorithm by Paul Bourke. * Line intersection algorithm by Paul Bourke.
* @see http://paulbourke.net/geometry/pointlineplane/ * @see http://paulbourke.net/geometry/pointlineplane/
* *
@@ -667,7 +669,7 @@ ol.render.webgl.PolygonReplay.prototype.getIntersections_ = function(segment, rt
* @param {boolean=} opt_touch Touching segments should be considered an intersection. * @param {boolean=} opt_touch Touching segments should be considered an intersection.
* @return {Array.<number>|undefined} Intersection coordinates. * @return {Array.<number>|undefined} Intersection coordinates.
*/ */
ol.render.webgl.PolygonReplay.prototype.calculateIntersection_ = function(p0, ol.render.webgl.PolygonReplay.prototype.calculateIntersection_ = function(p0,
p1, p2, p3, opt_touch) { p1, p2, p3, opt_touch) {
var denom = (p3.y - p2.y) * (p1.x - p0.x) - (p3.x - p2.x) * (p1.y - p0.y); var denom = (p3.y - p2.y) * (p1.x - p0.x) - (p3.x - p2.x) * (p1.y - p0.y);
if (denom !== 0) { if (denom !== 0) {
@@ -680,10 +682,10 @@ ol.render.webgl.PolygonReplay.prototype.calculateIntersection_ = function(p0,
} }
} }
return undefined; return undefined;
}; };
/** /**
* @private * @private
* @param {ol.WebglPolygonVertex} p0 Point before the start of the diagonal. * @param {ol.WebglPolygonVertex} p0 Point before the start of the diagonal.
* @param {ol.WebglPolygonVertex} p1 Start point of the diagonal. * @param {ol.WebglPolygonVertex} p1 Start point of the diagonal.
@@ -692,7 +694,7 @@ ol.render.webgl.PolygonReplay.prototype.calculateIntersection_ = function(p0,
* @param {ol.WebglPolygonVertex} p4 Point after the end of the diagonal. * @param {ol.WebglPolygonVertex} p4 Point after the end of the diagonal.
* @return {boolean} Diagonal is inside the polygon. * @return {boolean} Diagonal is inside the polygon.
*/ */
ol.render.webgl.PolygonReplay.prototype.diagonalIsInside_ = function(p0, p1, p2, p3, p4) { ol.render.webgl.PolygonReplay.prototype.diagonalIsInside_ = function(p0, p1, p2, p3, p4) {
if (p1.reflex === undefined || p3.reflex === undefined) { if (p1.reflex === undefined || p3.reflex === undefined) {
return false; return false;
} }
@@ -703,13 +705,13 @@ ol.render.webgl.PolygonReplay.prototype.diagonalIsInside_ = function(p0, p1, p2,
var p1InCone = p3.reflex ? p1IsRightOf || p1IsLeftOf : p1IsRightOf && p1IsLeftOf; var p1InCone = p3.reflex ? p1IsRightOf || p1IsLeftOf : p1IsRightOf && p1IsLeftOf;
var p3InCone = p1.reflex ? p3IsRightOf || p3IsLeftOf : p3IsRightOf && p3IsLeftOf; var p3InCone = p1.reflex ? p3IsRightOf || p3IsLeftOf : p3IsRightOf && p3IsLeftOf;
return p1InCone && p3InCone; return p1InCone && p3InCone;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.PolygonReplay.prototype.drawMultiPolygon = function(multiPolygonGeometry, feature) { ol.render.webgl.PolygonReplay.prototype.drawMultiPolygon = function(multiPolygonGeometry, feature) {
var polygons = multiPolygonGeometry.getPolygons(); var polygons = multiPolygonGeometry.getPolygons();
var stride = multiPolygonGeometry.getStride(); var stride = multiPolygonGeometry.getStride();
var currIndex = this.indices.length; var currIndex = this.indices.length;
@@ -744,13 +746,13 @@ ol.render.webgl.PolygonReplay.prototype.drawMultiPolygon = function(multiPolygon
if (this.lineStringReplay.getCurrentIndex() > currLineIndex) { if (this.lineStringReplay.getCurrentIndex() > currLineIndex) {
this.lineStringReplay.setPolygonStyle(feature, currLineIndex); this.lineStringReplay.setPolygonStyle(feature, currLineIndex);
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.PolygonReplay.prototype.drawPolygon = function(polygonGeometry, feature) { ol.render.webgl.PolygonReplay.prototype.drawPolygon = function(polygonGeometry, feature) {
var linearRings = polygonGeometry.getLinearRings(); var linearRings = polygonGeometry.getLinearRings();
var stride = polygonGeometry.getStride(); var stride = polygonGeometry.getStride();
if (linearRings.length > 0) { if (linearRings.length > 0) {
@@ -776,13 +778,13 @@ ol.render.webgl.PolygonReplay.prototype.drawPolygon = function(polygonGeometry,
this.lineStringReplay.drawPolygonCoordinates(flatCoordinates, holes, stride); this.lineStringReplay.drawPolygonCoordinates(flatCoordinates, holes, stride);
this.drawCoordinates_(flatCoordinates, holes, stride); this.drawCoordinates_(flatCoordinates, holes, stride);
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
**/ **/
ol.render.webgl.PolygonReplay.prototype.finish = function(context) { ol.render.webgl.PolygonReplay.prototype.finish = function(context) {
// create, bind, and populate the vertices buffer // create, bind, and populate the vertices buffer
this.verticesBuffer = new ol.webgl.Buffer(this.vertices); this.verticesBuffer = new ol.webgl.Buffer(this.vertices);
@@ -800,13 +802,13 @@ ol.render.webgl.PolygonReplay.prototype.finish = function(context) {
this.vertices = null; this.vertices = null;
this.indices = null; this.indices = null;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.PolygonReplay.prototype.getDeleteResourcesFunction = function(context) { ol.render.webgl.PolygonReplay.prototype.getDeleteResourcesFunction = function(context) {
var verticesBuffer = this.verticesBuffer; var verticesBuffer = this.verticesBuffer;
var indicesBuffer = this.indicesBuffer; var indicesBuffer = this.indicesBuffer;
var lineDeleter = this.lineStringReplay.getDeleteResourcesFunction(context); var lineDeleter = this.lineStringReplay.getDeleteResourcesFunction(context);
@@ -815,13 +817,13 @@ ol.render.webgl.PolygonReplay.prototype.getDeleteResourcesFunction = function(co
context.deleteBuffer(indicesBuffer); context.deleteBuffer(indicesBuffer);
lineDeleter(); lineDeleter();
}; };
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.PolygonReplay.prototype.setUpProgram = function(gl, context, size, pixelRatio) { ol.render.webgl.PolygonReplay.prototype.setUpProgram = function(gl, context, size, pixelRatio) {
// get the program // get the program
var fragmentShader, vertexShader; var fragmentShader, vertexShader;
fragmentShader = ol.render.webgl.polygonreplay.defaultshader.fragment; fragmentShader = ol.render.webgl.polygonreplay.defaultshader.fragment;
@@ -846,21 +848,21 @@ ol.render.webgl.PolygonReplay.prototype.setUpProgram = function(gl, context, siz
false, 8, 0); false, 8, 0);
return locations; return locations;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.PolygonReplay.prototype.shutDownProgram = function(gl, locations) { ol.render.webgl.PolygonReplay.prototype.shutDownProgram = function(gl, locations) {
gl.disableVertexAttribArray(locations.a_position); gl.disableVertexAttribArray(locations.a_position);
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.PolygonReplay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) { ol.render.webgl.PolygonReplay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) {
//Save GL parameters. //Save GL parameters.
var tmpDepthFunc = /** @type {number} */ (gl.getParameter(gl.DEPTH_FUNC)); var tmpDepthFunc = /** @type {number} */ (gl.getParameter(gl.DEPTH_FUNC));
var tmpDepthMask = /** @type {boolean} */ (gl.getParameter(gl.DEPTH_WRITEMASK)); var tmpDepthMask = /** @type {boolean} */ (gl.getParameter(gl.DEPTH_WRITEMASK));
@@ -892,13 +894,13 @@ ol.render.webgl.PolygonReplay.prototype.drawReplay = function(gl, context, skipp
gl.depthMask(tmpDepthMask); gl.depthMask(tmpDepthMask);
gl.depthFunc(tmpDepthFunc); gl.depthFunc(tmpDepthFunc);
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.PolygonReplay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash, ol.render.webgl.PolygonReplay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash,
featureCallback, opt_hitExtent) { featureCallback, opt_hitExtent) {
var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex; var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex;
featureIndex = this.startIndices.length - 2; featureIndex = this.startIndices.length - 2;
@@ -934,16 +936,16 @@ ol.render.webgl.PolygonReplay.prototype.drawHitDetectionReplayOneByOne = functio
} }
} }
return undefined; return undefined;
}; };
/** /**
* @private * @private
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
* @param {Object} skippedFeaturesHash Ids of features to skip. * @param {Object} skippedFeaturesHash Ids of features to skip.
*/ */
ol.render.webgl.PolygonReplay.prototype.drawReplaySkipping_ = function(gl, context, skippedFeaturesHash) { ol.render.webgl.PolygonReplay.prototype.drawReplaySkipping_ = function(gl, context, skippedFeaturesHash) {
var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex, featureStart; var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex, featureStart;
featureIndex = this.startIndices.length - 2; featureIndex = this.startIndices.length - 2;
end = start = this.startIndices[featureIndex + 1]; end = start = this.startIndices[featureIndex + 1];
@@ -974,23 +976,23 @@ ol.render.webgl.PolygonReplay.prototype.drawReplaySkipping_ = function(gl, conte
} }
start = end = groupStart; start = end = groupStart;
} }
}; };
/** /**
* @private * @private
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
* @param {Array.<number>} color Color. * @param {Array.<number>} color Color.
*/ */
ol.render.webgl.PolygonReplay.prototype.setFillStyle_ = function(gl, color) { ol.render.webgl.PolygonReplay.prototype.setFillStyle_ = function(gl, color) {
gl.uniform4fv(this.defaultLocations_.u_color, color); gl.uniform4fv(this.defaultLocations_.u_color, color);
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.PolygonReplay.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) { ol.render.webgl.PolygonReplay.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {
var fillStyleColor = fillStyle ? fillStyle.getColor() : [0, 0, 0, 0]; var fillStyleColor = fillStyle ? fillStyle.getColor() : [0, 0, 0, 0];
if (!(fillStyleColor instanceof CanvasGradient) && if (!(fillStyleColor instanceof CanvasGradient) &&
!(fillStyleColor instanceof CanvasPattern)) { !(fillStyleColor instanceof CanvasPattern)) {
@@ -1015,4 +1017,6 @@ ol.render.webgl.PolygonReplay.prototype.setFillStrokeStyle = function(fillStyle,
}); });
this.lineStringReplay.setFillStrokeStyle(null, nullStrokeStyle); this.lineStringReplay.setFillStrokeStyle(null, nullStrokeStyle);
} }
}; };
}
@@ -6,83 +6,85 @@ goog.require('ol.webgl.Fragment');
goog.require('ol.webgl.Vertex'); goog.require('ol.webgl.Vertex');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.webgl.Fragment} * @extends {ol.webgl.Fragment}
* @struct * @struct
*/ */
ol.render.webgl.polygonreplay.defaultshader.Fragment = function() { ol.render.webgl.polygonreplay.defaultshader.Fragment = function() {
ol.webgl.Fragment.call(this, ol.render.webgl.polygonreplay.defaultshader.Fragment.SOURCE); ol.webgl.Fragment.call(this, ol.render.webgl.polygonreplay.defaultshader.Fragment.SOURCE);
}; };
ol.inherits(ol.render.webgl.polygonreplay.defaultshader.Fragment, ol.webgl.Fragment); ol.inherits(ol.render.webgl.polygonreplay.defaultshader.Fragment, ol.webgl.Fragment);
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.polygonreplay.defaultshader.Fragment.DEBUG_SOURCE = 'precision mediump float;\n\n\n\nuniform vec4 u_color;\nuniform float u_opacity;\n\nvoid main(void) {\n gl_FragColor = u_color;\n float alpha = u_color.a * u_opacity;\n if (alpha == 0.0) {\n discard;\n }\n gl_FragColor.a = alpha;\n}\n'; ol.render.webgl.polygonreplay.defaultshader.Fragment.DEBUG_SOURCE = 'precision mediump float;\n\n\n\nuniform vec4 u_color;\nuniform float u_opacity;\n\nvoid main(void) {\n gl_FragColor = u_color;\n float alpha = u_color.a * u_opacity;\n if (alpha == 0.0) {\n discard;\n }\n gl_FragColor.a = alpha;\n}\n';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.polygonreplay.defaultshader.Fragment.OPTIMIZED_SOURCE = 'precision mediump float;uniform vec4 e;uniform float f;void main(void){gl_FragColor=e;float alpha=e.a*f;if(alpha==0.0){discard;}gl_FragColor.a=alpha;}'; ol.render.webgl.polygonreplay.defaultshader.Fragment.OPTIMIZED_SOURCE = 'precision mediump float;uniform vec4 e;uniform float f;void main(void){gl_FragColor=e;float alpha=e.a*f;if(alpha==0.0){discard;}gl_FragColor.a=alpha;}';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.polygonreplay.defaultshader.Fragment.SOURCE = ol.render.webgl.polygonreplay.defaultshader.Fragment.OPTIMIZED_SOURCE; ol.render.webgl.polygonreplay.defaultshader.Fragment.SOURCE = ol.render.webgl.polygonreplay.defaultshader.Fragment.OPTIMIZED_SOURCE;
ol.render.webgl.polygonreplay.defaultshader.fragment = new ol.render.webgl.polygonreplay.defaultshader.Fragment(); ol.render.webgl.polygonreplay.defaultshader.fragment = new ol.render.webgl.polygonreplay.defaultshader.Fragment();
/** /**
* @constructor * @constructor
* @extends {ol.webgl.Vertex} * @extends {ol.webgl.Vertex}
* @struct * @struct
*/ */
ol.render.webgl.polygonreplay.defaultshader.Vertex = function() { ol.render.webgl.polygonreplay.defaultshader.Vertex = function() {
ol.webgl.Vertex.call(this, ol.render.webgl.polygonreplay.defaultshader.Vertex.SOURCE); ol.webgl.Vertex.call(this, ol.render.webgl.polygonreplay.defaultshader.Vertex.SOURCE);
}; };
ol.inherits(ol.render.webgl.polygonreplay.defaultshader.Vertex, ol.webgl.Vertex); ol.inherits(ol.render.webgl.polygonreplay.defaultshader.Vertex, ol.webgl.Vertex);
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.polygonreplay.defaultshader.Vertex.DEBUG_SOURCE = '\n\nattribute vec2 a_position;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform mat4 u_offsetRotateMatrix;\n\nvoid main(void) {\n gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0);\n}\n\n\n'; ol.render.webgl.polygonreplay.defaultshader.Vertex.DEBUG_SOURCE = '\n\nattribute vec2 a_position;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform mat4 u_offsetRotateMatrix;\n\nvoid main(void) {\n gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0);\n}\n\n\n';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.polygonreplay.defaultshader.Vertex.OPTIMIZED_SOURCE = 'attribute vec2 a;uniform mat4 b;uniform mat4 c;uniform mat4 d;void main(void){gl_Position=b*vec4(a,0.0,1.0);}'; ol.render.webgl.polygonreplay.defaultshader.Vertex.OPTIMIZED_SOURCE = 'attribute vec2 a;uniform mat4 b;uniform mat4 c;uniform mat4 d;void main(void){gl_Position=b*vec4(a,0.0,1.0);}';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.render.webgl.polygonreplay.defaultshader.Vertex.SOURCE = ol.render.webgl.polygonreplay.defaultshader.Vertex.OPTIMIZED_SOURCE; ol.render.webgl.polygonreplay.defaultshader.Vertex.SOURCE = ol.render.webgl.polygonreplay.defaultshader.Vertex.OPTIMIZED_SOURCE;
ol.render.webgl.polygonreplay.defaultshader.vertex = new ol.render.webgl.polygonreplay.defaultshader.Vertex(); ol.render.webgl.polygonreplay.defaultshader.vertex = new ol.render.webgl.polygonreplay.defaultshader.Vertex();
/** /**
* @constructor * @constructor
* @param {WebGLRenderingContext} gl GL. * @param {WebGLRenderingContext} gl GL.
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @struct * @struct
*/ */
ol.render.webgl.polygonreplay.defaultshader.Locations = function(gl, program) { ol.render.webgl.polygonreplay.defaultshader.Locations = function(gl, program) {
/** /**
* @type {WebGLUniformLocation} * @type {WebGLUniformLocation}
@@ -113,4 +115,6 @@ ol.render.webgl.polygonreplay.defaultshader.Locations = function(gl, program) {
* @type {number} * @type {number}
*/ */
this.a_position = gl.getAttribLocation(program, 'a'); this.a_position = gl.getAttribLocation(program, 'a');
}; };
}
+33 -28
View File
@@ -7,14 +7,17 @@ goog.require('ol.transform');
goog.require('ol.vec.Mat4'); goog.require('ol.vec.Mat4');
goog.require('ol.webgl'); goog.require('ol.webgl');
/**
if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.render.VectorContext} * @extends {ol.render.VectorContext}
* @param {number} tolerance Tolerance. * @param {number} tolerance Tolerance.
* @param {ol.Extent} maxExtent Max extent. * @param {ol.Extent} maxExtent Max extent.
* @struct * @struct
*/ */
ol.render.webgl.Replay = function(tolerance, maxExtent) { ol.render.webgl.Replay = function(tolerance, maxExtent) {
ol.render.VectorContext.call(this); ol.render.VectorContext.call(this);
/** /**
@@ -109,26 +112,26 @@ ol.render.webgl.Replay = function(tolerance, maxExtent) {
*/ */
this.lineStringReplay = undefined; this.lineStringReplay = undefined;
}; };
ol.inherits(ol.render.webgl.Replay, ol.render.VectorContext); ol.inherits(ol.render.webgl.Replay, ol.render.VectorContext);
/** /**
* @abstract * @abstract
* @param {ol.webgl.Context} context WebGL context. * @param {ol.webgl.Context} context WebGL context.
* @return {function()} Delete resources function. * @return {function()} Delete resources function.
*/ */
ol.render.webgl.Replay.prototype.getDeleteResourcesFunction = function(context) {}; ol.render.webgl.Replay.prototype.getDeleteResourcesFunction = function(context) {};
/** /**
* @abstract * @abstract
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
*/ */
ol.render.webgl.Replay.prototype.finish = function(context) {}; ol.render.webgl.Replay.prototype.finish = function(context) {};
/** /**
* @abstract * @abstract
* @protected * @protected
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
@@ -140,10 +143,10 @@ ol.render.webgl.Replay.prototype.finish = function(context) {};
ol.render.webgl.linestringreplay.defaultshader.Locations| ol.render.webgl.linestringreplay.defaultshader.Locations|
ol.render.webgl.polygonreplay.defaultshader.Locations} Locations. ol.render.webgl.polygonreplay.defaultshader.Locations} Locations.
*/ */
ol.render.webgl.Replay.prototype.setUpProgram = function(gl, context, size, pixelRatio) {}; ol.render.webgl.Replay.prototype.setUpProgram = function(gl, context, size, pixelRatio) {};
/** /**
* @abstract * @abstract
* @protected * @protected
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
@@ -152,10 +155,10 @@ ol.render.webgl.Replay.prototype.setUpProgram = function(gl, context, size, pixe
ol.render.webgl.linestringreplay.defaultshader.Locations| ol.render.webgl.linestringreplay.defaultshader.Locations|
ol.render.webgl.polygonreplay.defaultshader.Locations} locations Locations. ol.render.webgl.polygonreplay.defaultshader.Locations} locations Locations.
*/ */
ol.render.webgl.Replay.prototype.shutDownProgram = function(gl, locations) {}; ol.render.webgl.Replay.prototype.shutDownProgram = function(gl, locations) {};
/** /**
* @abstract * @abstract
* @protected * @protected
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
@@ -164,10 +167,10 @@ ol.render.webgl.Replay.prototype.shutDownProgram = function(gl, locations) {};
* to skip. * to skip.
* @param {boolean} hitDetection Hit detection mode. * @param {boolean} hitDetection Hit detection mode.
*/ */
ol.render.webgl.Replay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) {}; ol.render.webgl.Replay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) {};
/** /**
* @abstract * @abstract
* @protected * @protected
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
@@ -180,10 +183,10 @@ ol.render.webgl.Replay.prototype.drawReplay = function(gl, context, skippedFeatu
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template T * @template T
*/ */
ol.render.webgl.Replay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash, featureCallback, opt_hitExtent) {}; ol.render.webgl.Replay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash, featureCallback, opt_hitExtent) {};
/** /**
* @protected * @protected
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
@@ -196,7 +199,7 @@ ol.render.webgl.Replay.prototype.drawHitDetectionReplayOneByOne = function(gl, c
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template T * @template T
*/ */
ol.render.webgl.Replay.prototype.drawHitDetectionReplay = function(gl, context, skippedFeaturesHash, ol.render.webgl.Replay.prototype.drawHitDetectionReplay = function(gl, context, skippedFeaturesHash,
featureCallback, oneByOne, opt_hitExtent) { featureCallback, oneByOne, opt_hitExtent) {
if (!oneByOne) { if (!oneByOne) {
// draw all hit-detection features in "once" (by texture group) // draw all hit-detection features in "once" (by texture group)
@@ -207,10 +210,10 @@ ol.render.webgl.Replay.prototype.drawHitDetectionReplay = function(gl, context,
return this.drawHitDetectionReplayOneByOne(gl, context, return this.drawHitDetectionReplayOneByOne(gl, context,
skippedFeaturesHash, featureCallback, opt_hitExtent); skippedFeaturesHash, featureCallback, opt_hitExtent);
} }
}; };
/** /**
* @protected * @protected
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
@@ -220,7 +223,7 @@ ol.render.webgl.Replay.prototype.drawHitDetectionReplay = function(gl, context,
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template T * @template T
*/ */
ol.render.webgl.Replay.prototype.drawHitDetectionReplayAll = function(gl, context, skippedFeaturesHash, ol.render.webgl.Replay.prototype.drawHitDetectionReplayAll = function(gl, context, skippedFeaturesHash,
featureCallback) { featureCallback) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
this.drawReplay(gl, context, skippedFeaturesHash, true); this.drawReplay(gl, context, skippedFeaturesHash, true);
@@ -231,10 +234,10 @@ ol.render.webgl.Replay.prototype.drawHitDetectionReplayAll = function(gl, contex
} else { } else {
return undefined; return undefined;
} }
}; };
/** /**
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
* @param {ol.Coordinate} center Center. * @param {ol.Coordinate} center Center.
* @param {number} resolution Resolution. * @param {number} resolution Resolution.
@@ -251,7 +254,7 @@ ol.render.webgl.Replay.prototype.drawHitDetectionReplayAll = function(gl, contex
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template T * @template T
*/ */
ol.render.webgl.Replay.prototype.replay = function(context, ol.render.webgl.Replay.prototype.replay = function(context,
center, resolution, rotation, size, pixelRatio, center, resolution, rotation, size, pixelRatio,
opacity, skippedFeaturesHash, opacity, skippedFeaturesHash,
featureCallback, oneByOne, opt_hitExtent) { featureCallback, oneByOne, opt_hitExtent) {
@@ -338,16 +341,16 @@ ol.render.webgl.Replay.prototype.replay = function(context,
} }
return result; return result;
}; };
/** /**
* @protected * @protected
* @param {WebGLRenderingContext} gl gl. * @param {WebGLRenderingContext} gl gl.
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
* @param {number} start Start index. * @param {number} start Start index.
* @param {number} end End index. * @param {number} end End index.
*/ */
ol.render.webgl.Replay.prototype.drawElements = function( ol.render.webgl.Replay.prototype.drawElements = function(
gl, context, start, end) { gl, context, start, end) {
var elementType = context.hasOESElementIndexUint ? var elementType = context.hasOESElementIndexUint ?
ol.webgl.UNSIGNED_INT : ol.webgl.UNSIGNED_SHORT; ol.webgl.UNSIGNED_INT : ol.webgl.UNSIGNED_SHORT;
@@ -356,4 +359,6 @@ ol.render.webgl.Replay.prototype.drawElements = function(
var numItems = end - start; var numItems = end - start;
var offsetInBytes = start * elementSize; var offsetInBytes = start * elementSize;
gl.drawElements(ol.webgl.TRIANGLES, numItems, elementType, offsetInBytes); gl.drawElements(ol.webgl.TRIANGLES, numItems, elementType, offsetInBytes);
}; };
}
+38 -33
View File
@@ -13,7 +13,10 @@ goog.require('ol.render.webgl.LineStringReplay');
goog.require('ol.render.webgl.PolygonReplay'); goog.require('ol.render.webgl.PolygonReplay');
goog.require('ol.render.webgl.TextReplay'); goog.require('ol.render.webgl.TextReplay');
/**
if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.render.ReplayGroup} * @extends {ol.render.ReplayGroup}
* @param {number} tolerance Tolerance. * @param {number} tolerance Tolerance.
@@ -21,7 +24,7 @@ goog.require('ol.render.webgl.TextReplay');
* @param {number=} opt_renderBuffer Render buffer. * @param {number=} opt_renderBuffer Render buffer.
* @struct * @struct
*/ */
ol.render.webgl.ReplayGroup = function(tolerance, maxExtent, opt_renderBuffer) { ol.render.webgl.ReplayGroup = function(tolerance, maxExtent, opt_renderBuffer) {
ol.render.ReplayGroup.call(this); ol.render.ReplayGroup.call(this);
/** /**
@@ -49,15 +52,15 @@ ol.render.webgl.ReplayGroup = function(tolerance, maxExtent, opt_renderBuffer) {
*/ */
this.replaysByZIndex_ = {}; this.replaysByZIndex_ = {};
}; };
ol.inherits(ol.render.webgl.ReplayGroup, ol.render.ReplayGroup); ol.inherits(ol.render.webgl.ReplayGroup, ol.render.ReplayGroup);
/** /**
* @param {ol.webgl.Context} context WebGL context. * @param {ol.webgl.Context} context WebGL context.
* @return {function()} Delete resources function. * @return {function()} Delete resources function.
*/ */
ol.render.webgl.ReplayGroup.prototype.getDeleteResourcesFunction = function(context) { ol.render.webgl.ReplayGroup.prototype.getDeleteResourcesFunction = function(context) {
var functions = []; var functions = [];
var zKey; var zKey;
for (zKey in this.replaysByZIndex_) { for (zKey in this.replaysByZIndex_) {
@@ -76,13 +79,13 @@ ol.render.webgl.ReplayGroup.prototype.getDeleteResourcesFunction = function(cont
} }
return result; return result;
}; };
}; };
/** /**
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
*/ */
ol.render.webgl.ReplayGroup.prototype.finish = function(context) { ol.render.webgl.ReplayGroup.prototype.finish = function(context) {
var zKey; var zKey;
for (zKey in this.replaysByZIndex_) { for (zKey in this.replaysByZIndex_) {
var replays = this.replaysByZIndex_[zKey]; var replays = this.replaysByZIndex_[zKey];
@@ -91,13 +94,13 @@ ol.render.webgl.ReplayGroup.prototype.finish = function(context) {
replays[replayKey].finish(context); replays[replayKey].finish(context);
} }
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.ReplayGroup.prototype.getReplay = function(zIndex, replayType) { ol.render.webgl.ReplayGroup.prototype.getReplay = function(zIndex, replayType) {
var zIndexKey = zIndex !== undefined ? zIndex.toString() : '0'; var zIndexKey = zIndex !== undefined ? zIndex.toString() : '0';
var replays = this.replaysByZIndex_[zIndexKey]; var replays = this.replaysByZIndex_[zIndexKey];
if (replays === undefined) { if (replays === undefined) {
@@ -111,18 +114,18 @@ ol.render.webgl.ReplayGroup.prototype.getReplay = function(zIndex, replayType) {
replays[replayType] = replay; replays[replayType] = replay;
} }
return replay; return replay;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.ReplayGroup.prototype.isEmpty = function() { ol.render.webgl.ReplayGroup.prototype.isEmpty = function() {
return ol.obj.isEmpty(this.replaysByZIndex_); return ol.obj.isEmpty(this.replaysByZIndex_);
}; };
/** /**
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
* @param {ol.Coordinate} center Center. * @param {ol.Coordinate} center Center.
* @param {number} resolution Resolution. * @param {number} resolution Resolution.
@@ -133,7 +136,7 @@ ol.render.webgl.ReplayGroup.prototype.isEmpty = function() {
* @param {Object.<string, boolean>} skippedFeaturesHash Ids of features * @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
* to skip. * to skip.
*/ */
ol.render.webgl.ReplayGroup.prototype.replay = function(context, ol.render.webgl.ReplayGroup.prototype.replay = function(context,
center, resolution, rotation, size, pixelRatio, center, resolution, rotation, size, pixelRatio,
opacity, skippedFeaturesHash) { opacity, skippedFeaturesHash) {
/** @type {Array.<number>} */ /** @type {Array.<number>} */
@@ -153,10 +156,10 @@ ol.render.webgl.ReplayGroup.prototype.replay = function(context,
} }
} }
} }
}; };
/** /**
* @private * @private
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
* @param {ol.Coordinate} center Center. * @param {ol.Coordinate} center Center.
@@ -174,7 +177,7 @@ ol.render.webgl.ReplayGroup.prototype.replay = function(context,
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template T * @template T
*/ */
ol.render.webgl.ReplayGroup.prototype.replayHitDetection_ = function(context, ol.render.webgl.ReplayGroup.prototype.replayHitDetection_ = function(context,
center, resolution, rotation, size, pixelRatio, opacity, center, resolution, rotation, size, pixelRatio, opacity,
skippedFeaturesHash, featureCallback, oneByOne, opt_hitExtent) { skippedFeaturesHash, featureCallback, oneByOne, opt_hitExtent) {
/** @type {Array.<number>} */ /** @type {Array.<number>} */
@@ -199,10 +202,10 @@ ol.render.webgl.ReplayGroup.prototype.replayHitDetection_ = function(context,
} }
} }
return undefined; return undefined;
}; };
/** /**
* @param {ol.Coordinate} coordinate Coordinate. * @param {ol.Coordinate} coordinate Coordinate.
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
* @param {ol.Coordinate} center Center. * @param {ol.Coordinate} center Center.
@@ -217,7 +220,7 @@ ol.render.webgl.ReplayGroup.prototype.replayHitDetection_ = function(context,
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template T * @template T
*/ */
ol.render.webgl.ReplayGroup.prototype.forEachFeatureAtCoordinate = function( ol.render.webgl.ReplayGroup.prototype.forEachFeatureAtCoordinate = function(
coordinate, context, center, resolution, rotation, size, pixelRatio, coordinate, context, center, resolution, rotation, size, pixelRatio,
opacity, skippedFeaturesHash, opacity, skippedFeaturesHash,
callback) { callback) {
@@ -256,10 +259,10 @@ ol.render.webgl.ReplayGroup.prototype.forEachFeatureAtCoordinate = function(
} }
} }
}, true, hitExtent); }, true, hitExtent);
}; };
/** /**
* @param {ol.Coordinate} coordinate Coordinate. * @param {ol.Coordinate} coordinate Coordinate.
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
* @param {ol.Coordinate} center Center. * @param {ol.Coordinate} center Center.
@@ -272,7 +275,7 @@ ol.render.webgl.ReplayGroup.prototype.forEachFeatureAtCoordinate = function(
* to skip. * to skip.
* @return {boolean} Is there a feature at the given coordinate? * @return {boolean} Is there a feature at the given coordinate?
*/ */
ol.render.webgl.ReplayGroup.prototype.hasFeatureAtCoordinate = function( ol.render.webgl.ReplayGroup.prototype.hasFeatureAtCoordinate = function(
coordinate, context, center, resolution, rotation, size, pixelRatio, coordinate, context, center, resolution, rotation, size, pixelRatio,
opacity, skippedFeaturesHash) { opacity, skippedFeaturesHash) {
var gl = context.getGL(); var gl = context.getGL();
@@ -293,26 +296,28 @@ ol.render.webgl.ReplayGroup.prototype.hasFeatureAtCoordinate = function(
}, false); }, false);
return hasFeature !== undefined; return hasFeature !== undefined;
}; };
/** /**
* @const * @const
* @private * @private
* @type {Array.<number>} * @type {Array.<number>}
*/ */
ol.render.webgl.ReplayGroup.HIT_DETECTION_SIZE_ = [1, 1]; ol.render.webgl.ReplayGroup.HIT_DETECTION_SIZE_ = [1, 1];
/** /**
* @const * @const
* @private * @private
* @type {Object.<ol.render.ReplayType, * @type {Object.<ol.render.ReplayType,
* function(new: ol.render.webgl.Replay, number, * function(new: ol.render.webgl.Replay, number,
* ol.Extent)>} * ol.Extent)>}
*/ */
ol.render.webgl.ReplayGroup.BATCH_CONSTRUCTORS_ = { ol.render.webgl.ReplayGroup.BATCH_CONSTRUCTORS_ = {
'Circle': ol.render.webgl.CircleReplay, 'Circle': ol.render.webgl.CircleReplay,
'Image': ol.render.webgl.ImageReplay, 'Image': ol.render.webgl.ImageReplay,
'LineString': ol.render.webgl.LineStringReplay, 'LineString': ol.render.webgl.LineStringReplay,
'Polygon': ol.render.webgl.PolygonReplay, 'Polygon': ol.render.webgl.PolygonReplay,
'Text': ol.render.webgl.TextReplay 'Text': ol.render.webgl.TextReplay
}; };
}
+19 -14
View File
@@ -2,20 +2,23 @@ goog.provide('ol.render.webgl.TextReplay');
goog.require('ol'); goog.require('ol');
/**
if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @param {number} tolerance Tolerance. * @param {number} tolerance Tolerance.
* @param {ol.Extent} maxExtent Max extent. * @param {ol.Extent} maxExtent Max extent.
* @struct * @struct
*/ */
ol.render.webgl.TextReplay = function(tolerance, maxExtent) {}; ol.render.webgl.TextReplay = function(tolerance, maxExtent) {};
/** /**
* @param {ol.style.Text} textStyle Text style. * @param {ol.style.Text} textStyle Text style.
*/ */
ol.render.webgl.TextReplay.prototype.setTextStyle = function(textStyle) {}; ol.render.webgl.TextReplay.prototype.setTextStyle = function(textStyle) {};
/** /**
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
* @param {ol.Coordinate} center Center. * @param {ol.Coordinate} center Center.
* @param {number} resolution Resolution. * @param {number} resolution Resolution.
@@ -32,14 +35,14 @@ ol.render.webgl.TextReplay.prototype.setTextStyle = function(textStyle) {};
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template T * @template T
*/ */
ol.render.webgl.TextReplay.prototype.replay = function(context, ol.render.webgl.TextReplay.prototype.replay = function(context,
center, resolution, rotation, size, pixelRatio, center, resolution, rotation, size, pixelRatio,
opacity, skippedFeaturesHash, opacity, skippedFeaturesHash,
featureCallback, oneByOne, opt_hitExtent) { featureCallback, oneByOne, opt_hitExtent) {
return undefined; return undefined;
}; };
/** /**
* @param {Array.<number>} flatCoordinates Flat coordinates. * @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {number} end End. * @param {number} end End.
@@ -47,19 +50,21 @@ ol.render.webgl.TextReplay.prototype.replay = function(context,
* @param {ol.geom.Geometry|ol.render.Feature} geometry Geometry. * @param {ol.geom.Geometry|ol.render.Feature} geometry Geometry.
* @param {ol.Feature|ol.render.Feature} feature Feature. * @param {ol.Feature|ol.render.Feature} feature Feature.
*/ */
ol.render.webgl.TextReplay.prototype.drawText = function(flatCoordinates, offset, ol.render.webgl.TextReplay.prototype.drawText = function(flatCoordinates, offset,
end, stride, geometry, feature) {}; end, stride, geometry, feature) {};
/** /**
* @abstract * @abstract
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
*/ */
ol.render.webgl.TextReplay.prototype.finish = function(context) {}; ol.render.webgl.TextReplay.prototype.finish = function(context) {};
/** /**
* @param {ol.webgl.Context} context WebGL context. * @param {ol.webgl.Context} context WebGL context.
* @return {function()} Delete resources function. * @return {function()} Delete resources function.
*/ */
ol.render.webgl.TextReplay.prototype.getDeleteResourcesFunction = function(context) { ol.render.webgl.TextReplay.prototype.getDeleteResourcesFunction = function(context) {
return ol.nullFunction; return ol.nullFunction;
}; };
}
+29 -25
View File
@@ -6,83 +6,85 @@ goog.require('ol.webgl.Fragment');
goog.require('ol.webgl.Vertex'); goog.require('ol.webgl.Vertex');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.webgl.Fragment} * @extends {ol.webgl.Fragment}
* @struct * @struct
*/ */
ol.renderer.webgl.defaultmapshader.Fragment = function() { ol.renderer.webgl.defaultmapshader.Fragment = function() {
ol.webgl.Fragment.call(this, ol.renderer.webgl.defaultmapshader.Fragment.SOURCE); ol.webgl.Fragment.call(this, ol.renderer.webgl.defaultmapshader.Fragment.SOURCE);
}; };
ol.inherits(ol.renderer.webgl.defaultmapshader.Fragment, ol.webgl.Fragment); ol.inherits(ol.renderer.webgl.defaultmapshader.Fragment, ol.webgl.Fragment);
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.renderer.webgl.defaultmapshader.Fragment.DEBUG_SOURCE = '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'; ol.renderer.webgl.defaultmapshader.Fragment.DEBUG_SOURCE = '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';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.renderer.webgl.defaultmapshader.Fragment.OPTIMIZED_SOURCE = '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;}'; ol.renderer.webgl.defaultmapshader.Fragment.OPTIMIZED_SOURCE = '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;}';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.renderer.webgl.defaultmapshader.Fragment.SOURCE = ol.renderer.webgl.defaultmapshader.Fragment.OPTIMIZED_SOURCE; ol.renderer.webgl.defaultmapshader.Fragment.SOURCE = ol.renderer.webgl.defaultmapshader.Fragment.OPTIMIZED_SOURCE;
ol.renderer.webgl.defaultmapshader.fragment = new ol.renderer.webgl.defaultmapshader.Fragment(); ol.renderer.webgl.defaultmapshader.fragment = new ol.renderer.webgl.defaultmapshader.Fragment();
/** /**
* @constructor * @constructor
* @extends {ol.webgl.Vertex} * @extends {ol.webgl.Vertex}
* @struct * @struct
*/ */
ol.renderer.webgl.defaultmapshader.Vertex = function() { ol.renderer.webgl.defaultmapshader.Vertex = function() {
ol.webgl.Vertex.call(this, ol.renderer.webgl.defaultmapshader.Vertex.SOURCE); ol.webgl.Vertex.call(this, ol.renderer.webgl.defaultmapshader.Vertex.SOURCE);
}; };
ol.inherits(ol.renderer.webgl.defaultmapshader.Vertex, ol.webgl.Vertex); ol.inherits(ol.renderer.webgl.defaultmapshader.Vertex, ol.webgl.Vertex);
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.renderer.webgl.defaultmapshader.Vertex.DEBUG_SOURCE = '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'; ol.renderer.webgl.defaultmapshader.Vertex.DEBUG_SOURCE = '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';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.renderer.webgl.defaultmapshader.Vertex.OPTIMIZED_SOURCE = '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;}'; ol.renderer.webgl.defaultmapshader.Vertex.OPTIMIZED_SOURCE = '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;}';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.renderer.webgl.defaultmapshader.Vertex.SOURCE = ol.renderer.webgl.defaultmapshader.Vertex.OPTIMIZED_SOURCE; ol.renderer.webgl.defaultmapshader.Vertex.SOURCE = ol.renderer.webgl.defaultmapshader.Vertex.OPTIMIZED_SOURCE;
ol.renderer.webgl.defaultmapshader.vertex = new ol.renderer.webgl.defaultmapshader.Vertex(); ol.renderer.webgl.defaultmapshader.vertex = new ol.renderer.webgl.defaultmapshader.Vertex();
/** /**
* @constructor * @constructor
* @param {WebGLRenderingContext} gl GL. * @param {WebGLRenderingContext} gl GL.
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @struct * @struct
*/ */
ol.renderer.webgl.defaultmapshader.Locations = function(gl, program) { ol.renderer.webgl.defaultmapshader.Locations = function(gl, program) {
/** /**
* @type {WebGLUniformLocation} * @type {WebGLUniformLocation}
@@ -113,4 +115,6 @@ ol.renderer.webgl.defaultmapshader.Locations = function(gl, program) {
* @type {number} * @type {number}
*/ */
this.a_texCoord = gl.getAttribLocation(program, 'c'); this.a_texCoord = gl.getAttribLocation(program, 'c');
}; };
}
+29 -25
View File
@@ -12,13 +12,15 @@ goog.require('ol.webgl');
goog.require('ol.webgl.Context'); goog.require('ol.webgl.Context');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.renderer.webgl.Layer} * @extends {ol.renderer.webgl.Layer}
* @param {ol.renderer.webgl.Map} mapRenderer Map renderer. * @param {ol.renderer.webgl.Map} mapRenderer Map renderer.
* @param {ol.layer.Image} imageLayer Tile layer. * @param {ol.layer.Image} imageLayer Tile layer.
*/ */
ol.renderer.webgl.ImageLayer = function(mapRenderer, imageLayer) { ol.renderer.webgl.ImageLayer = function(mapRenderer, imageLayer) {
ol.renderer.webgl.Layer.call(this, mapRenderer, imageLayer); ol.renderer.webgl.Layer.call(this, mapRenderer, imageLayer);
@@ -41,16 +43,16 @@ ol.renderer.webgl.ImageLayer = function(mapRenderer, imageLayer) {
*/ */
this.hitTransformationMatrix_ = null; this.hitTransformationMatrix_ = null;
}; };
ol.inherits(ol.renderer.webgl.ImageLayer, ol.renderer.webgl.Layer); ol.inherits(ol.renderer.webgl.ImageLayer, ol.renderer.webgl.Layer);
/** /**
* @param {ol.ImageBase} image Image. * @param {ol.ImageBase} image Image.
* @private * @private
* @return {WebGLTexture} Texture. * @return {WebGLTexture} Texture.
*/ */
ol.renderer.webgl.ImageLayer.prototype.createTexture_ = function(image) { ol.renderer.webgl.ImageLayer.prototype.createTexture_ = function(image) {
// We meet the conditions to work with non-power of two textures. // 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://www.khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences#Non-Power_of_Two_Texture_Support
@@ -61,13 +63,13 @@ ol.renderer.webgl.ImageLayer.prototype.createTexture_ = function(image) {
return ol.webgl.Context.createTexture( return ol.webgl.Context.createTexture(
gl, imageElement, ol.webgl.CLAMP_TO_EDGE, ol.webgl.CLAMP_TO_EDGE); gl, imageElement, ol.webgl.CLAMP_TO_EDGE, ol.webgl.CLAMP_TO_EDGE);
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.ImageLayer.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg) { ol.renderer.webgl.ImageLayer.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg) {
var layer = this.getLayer(); var layer = this.getLayer();
var source = layer.getSource(); var source = layer.getSource();
var resolution = frameState.viewState.resolution; var resolution = frameState.viewState.resolution;
@@ -83,13 +85,13 @@ ol.renderer.webgl.ImageLayer.prototype.forEachFeatureAtCoordinate = function(coo
function(feature) { function(feature) {
return callback.call(thisArg, feature, layer); return callback.call(thisArg, feature, layer);
}); });
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.ImageLayer.prototype.prepareFrame = function(frameState, layerState, context) { ol.renderer.webgl.ImageLayer.prototype.prepareFrame = function(frameState, layerState, context) {
var gl = this.mapRenderer.getGL(); var gl = this.mapRenderer.getGL();
@@ -167,10 +169,10 @@ ol.renderer.webgl.ImageLayer.prototype.prepareFrame = function(frameState, layer
} }
return !!image; return !!image;
}; };
/** /**
* @param {number} canvasWidth Canvas width. * @param {number} canvasWidth Canvas width.
* @param {number} canvasHeight Canvas height. * @param {number} canvasHeight Canvas height.
* @param {number} pixelRatio Pixel ratio. * @param {number} pixelRatio Pixel ratio.
@@ -180,7 +182,7 @@ ol.renderer.webgl.ImageLayer.prototype.prepareFrame = function(frameState, layer
* @param {ol.Extent} imageExtent Image extent. * @param {ol.Extent} imageExtent Image extent.
* @private * @private
*/ */
ol.renderer.webgl.ImageLayer.prototype.updateProjectionMatrix_ = function(canvasWidth, canvasHeight, pixelRatio, ol.renderer.webgl.ImageLayer.prototype.updateProjectionMatrix_ = function(canvasWidth, canvasHeight, pixelRatio,
viewCenter, viewResolution, viewRotation, imageExtent) { viewCenter, viewResolution, viewRotation, imageExtent) {
var canvasExtentWidth = canvasWidth * viewResolution; var canvasExtentWidth = canvasWidth * viewResolution;
@@ -200,23 +202,23 @@ ol.renderer.webgl.ImageLayer.prototype.updateProjectionMatrix_ = function(canvas
(imageExtent[3] - imageExtent[1]) / 2); (imageExtent[3] - imageExtent[1]) / 2);
ol.transform.translate(projectionMatrix, 1, 1); ol.transform.translate(projectionMatrix, 1, 1);
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.ImageLayer.prototype.hasFeatureAtCoordinate = function(coordinate, frameState) { ol.renderer.webgl.ImageLayer.prototype.hasFeatureAtCoordinate = function(coordinate, frameState) {
var hasFeature = this.forEachFeatureAtCoordinate( var hasFeature = this.forEachFeatureAtCoordinate(
coordinate, frameState, 0, ol.functions.TRUE, this); coordinate, frameState, 0, ol.functions.TRUE, this);
return hasFeature !== undefined; return hasFeature !== undefined;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) { ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
if (!this.image_ || !this.image_.getImage()) { if (!this.image_ || !this.image_.getImage()) {
return undefined; return undefined;
} }
@@ -267,10 +269,10 @@ ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, fra
return undefined; return undefined;
} }
} }
}; };
/** /**
* The transformation matrix to get the pixel on the image for a * The transformation matrix to get the pixel on the image for a
* pixel on the map. * pixel on the map.
* @param {ol.Size} mapSize The map size. * @param {ol.Size} mapSize The map size.
@@ -278,7 +280,7 @@ ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, fra
* @return {ol.Transform} The transformation matrix. * @return {ol.Transform} The transformation matrix.
* @private * @private
*/ */
ol.renderer.webgl.ImageLayer.prototype.getHitTransformationMatrix_ = function(mapSize, imageSize) { ol.renderer.webgl.ImageLayer.prototype.getHitTransformationMatrix_ = function(mapSize, imageSize) {
// the first matrix takes a map pixel, flips the y-axis and scales to // the first matrix takes a map pixel, flips the y-axis and scales to
// a range between -1 ... 1 // a range between -1 ... 1
var mapCoordTransform = ol.transform.create(); var mapCoordTransform = ol.transform.create();
@@ -302,4 +304,6 @@ ol.renderer.webgl.ImageLayer.prototype.getHitTransformationMatrix_ = function(ma
ol.transform.multiply(transform, mapCoordTransform); ol.transform.multiply(transform, mapCoordTransform);
return transform; return transform;
}; };
}
+33 -29
View File
@@ -13,13 +13,15 @@ goog.require('ol.webgl.Buffer');
goog.require('ol.webgl.Context'); goog.require('ol.webgl.Context');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.renderer.Layer} * @extends {ol.renderer.Layer}
* @param {ol.renderer.webgl.Map} mapRenderer Map renderer. * @param {ol.renderer.webgl.Map} mapRenderer Map renderer.
* @param {ol.layer.Layer} layer Layer. * @param {ol.layer.Layer} layer Layer.
*/ */
ol.renderer.webgl.Layer = function(mapRenderer, layer) { ol.renderer.webgl.Layer = function(mapRenderer, layer) {
ol.renderer.Layer.call(this, layer); ol.renderer.Layer.call(this, layer);
@@ -82,16 +84,16 @@ ol.renderer.webgl.Layer = function(mapRenderer, layer) {
*/ */
this.defaultLocations_ = null; this.defaultLocations_ = null;
}; };
ol.inherits(ol.renderer.webgl.Layer, ol.renderer.Layer); ol.inherits(ol.renderer.webgl.Layer, ol.renderer.Layer);
/** /**
* @param {olx.FrameState} frameState Frame state. * @param {olx.FrameState} frameState Frame state.
* @param {number} framebufferDimension Framebuffer dimension. * @param {number} framebufferDimension Framebuffer dimension.
* @protected * @protected
*/ */
ol.renderer.webgl.Layer.prototype.bindFramebuffer = function(frameState, framebufferDimension) { ol.renderer.webgl.Layer.prototype.bindFramebuffer = function(frameState, framebufferDimension) {
var gl = this.mapRenderer.getGL(); var gl = this.mapRenderer.getGL();
@@ -129,15 +131,15 @@ ol.renderer.webgl.Layer.prototype.bindFramebuffer = function(frameState, framebu
gl.bindFramebuffer(ol.webgl.FRAMEBUFFER, this.framebuffer); gl.bindFramebuffer(ol.webgl.FRAMEBUFFER, this.framebuffer);
} }
}; };
/** /**
* @param {olx.FrameState} frameState Frame state. * @param {olx.FrameState} frameState Frame state.
* @param {ol.LayerState} layerState Layer state. * @param {ol.LayerState} layerState Layer state.
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
*/ */
ol.renderer.webgl.Layer.prototype.composeFrame = function(frameState, layerState, context) { ol.renderer.webgl.Layer.prototype.composeFrame = function(frameState, layerState, context) {
this.dispatchComposeEvent_( this.dispatchComposeEvent_(
ol.render.EventType.PRECOMPOSE, context, frameState); ol.render.EventType.PRECOMPOSE, context, frameState);
@@ -181,16 +183,16 @@ ol.renderer.webgl.Layer.prototype.composeFrame = function(frameState, layerState
this.dispatchComposeEvent_( this.dispatchComposeEvent_(
ol.render.EventType.POSTCOMPOSE, context, frameState); ol.render.EventType.POSTCOMPOSE, context, frameState);
}; };
/** /**
* @param {ol.render.EventType} type Event type. * @param {ol.render.EventType} type Event type.
* @param {ol.webgl.Context} context WebGL context. * @param {ol.webgl.Context} context WebGL context.
* @param {olx.FrameState} frameState Frame state. * @param {olx.FrameState} frameState Frame state.
* @private * @private
*/ */
ol.renderer.webgl.Layer.prototype.dispatchComposeEvent_ = function(type, context, frameState) { ol.renderer.webgl.Layer.prototype.dispatchComposeEvent_ = function(type, context, frameState) {
var layer = this.getLayer(); var layer = this.getLayer();
if (layer.hasListener(type)) { if (layer.hasListener(type)) {
var viewState = frameState.viewState; var viewState = frameState.viewState;
@@ -207,54 +209,54 @@ ol.renderer.webgl.Layer.prototype.dispatchComposeEvent_ = function(type, context
type, render, frameState, null, context); type, render, frameState, null, context);
layer.dispatchEvent(composeEvent); layer.dispatchEvent(composeEvent);
} }
}; };
/** /**
* @return {!ol.Transform} Matrix. * @return {!ol.Transform} Matrix.
*/ */
ol.renderer.webgl.Layer.prototype.getTexCoordMatrix = function() { ol.renderer.webgl.Layer.prototype.getTexCoordMatrix = function() {
return this.texCoordMatrix; return this.texCoordMatrix;
}; };
/** /**
* @return {WebGLTexture} Texture. * @return {WebGLTexture} Texture.
*/ */
ol.renderer.webgl.Layer.prototype.getTexture = function() { ol.renderer.webgl.Layer.prototype.getTexture = function() {
return this.texture; return this.texture;
}; };
/** /**
* @return {!ol.Transform} Matrix. * @return {!ol.Transform} Matrix.
*/ */
ol.renderer.webgl.Layer.prototype.getProjectionMatrix = function() { ol.renderer.webgl.Layer.prototype.getProjectionMatrix = function() {
return this.projectionMatrix; return this.projectionMatrix;
}; };
/** /**
* Handle webglcontextlost. * Handle webglcontextlost.
*/ */
ol.renderer.webgl.Layer.prototype.handleWebGLContextLost = function() { ol.renderer.webgl.Layer.prototype.handleWebGLContextLost = function() {
this.texture = null; this.texture = null;
this.framebuffer = null; this.framebuffer = null;
this.framebufferDimension = undefined; this.framebufferDimension = undefined;
}; };
/** /**
* @abstract * @abstract
* @param {olx.FrameState} frameState Frame state. * @param {olx.FrameState} frameState Frame state.
* @param {ol.LayerState} layerState Layer state. * @param {ol.LayerState} layerState Layer state.
* @param {ol.webgl.Context} context Context. * @param {ol.webgl.Context} context Context.
* @return {boolean} whether composeFrame should be called. * @return {boolean} whether composeFrame should be called.
*/ */
ol.renderer.webgl.Layer.prototype.prepareFrame = function(frameState, layerState, context) {}; ol.renderer.webgl.Layer.prototype.prepareFrame = function(frameState, layerState, context) {};
/** /**
* @abstract * @abstract
* @param {ol.Pixel} pixel Pixel. * @param {ol.Pixel} pixel Pixel.
* @param {olx.FrameState} frameState FrameState. * @param {olx.FrameState} frameState FrameState.
@@ -264,4 +266,6 @@ ol.renderer.webgl.Layer.prototype.prepareFrame = function(frameState, layerState
* @return {T|undefined} Callback result. * @return {T|undefined} Callback result.
* @template S,T,U * @template S,T,U
*/ */
ol.renderer.webgl.Layer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {}; ol.renderer.webgl.Layer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {};
}
+56 -52
View File
@@ -21,13 +21,15 @@ goog.require('ol.webgl.Context');
goog.require('ol.webgl.ContextEventType'); goog.require('ol.webgl.ContextEventType');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.renderer.Map} * @extends {ol.renderer.Map}
* @param {Element} container Container. * @param {Element} container Container.
* @param {ol.Map} map Map. * @param {ol.Map} map Map.
*/ */
ol.renderer.webgl.Map = function(container, map) { ol.renderer.webgl.Map = function(container, map) {
ol.renderer.Map.call(this, container, map); ol.renderer.Map.call(this, container, map);
/** /**
@@ -155,18 +157,18 @@ ol.renderer.webgl.Map = function(container, map) {
this.textureCacheFrameMarkerCount_ = 0; this.textureCacheFrameMarkerCount_ = 0;
this.initializeGL_(); this.initializeGL_();
}; };
ol.inherits(ol.renderer.webgl.Map, ol.renderer.Map); ol.inherits(ol.renderer.webgl.Map, ol.renderer.Map);
/** /**
* @param {ol.Tile} tile Tile. * @param {ol.Tile} tile Tile.
* @param {ol.Size} tileSize Tile size. * @param {ol.Size} tileSize Tile size.
* @param {number} tileGutter Tile gutter. * @param {number} tileGutter Tile gutter.
* @param {number} magFilter Mag filter. * @param {number} magFilter Mag filter.
* @param {number} minFilter Min filter. * @param {number} minFilter Min filter.
*/ */
ol.renderer.webgl.Map.prototype.bindTileTexture = function(tile, tileSize, tileGutter, magFilter, minFilter) { ol.renderer.webgl.Map.prototype.bindTileTexture = function(tile, tileSize, tileGutter, magFilter, minFilter) {
var gl = this.getGL(); var gl = this.getGL();
var tileKey = tile.getKey(); var tileKey = tile.getKey();
if (this.textureCache_.containsKey(tileKey)) { if (this.textureCache_.containsKey(tileKey)) {
@@ -221,15 +223,15 @@ ol.renderer.webgl.Map.prototype.bindTileTexture = function(tile, tileSize, tileG
minFilter: minFilter minFilter: minFilter
}); });
} }
}; };
/** /**
* @param {ol.render.EventType} type Event type. * @param {ol.render.EventType} type Event type.
* @param {olx.FrameState} frameState Frame state. * @param {olx.FrameState} frameState Frame state.
* @private * @private
*/ */
ol.renderer.webgl.Map.prototype.dispatchComposeEvent_ = function(type, frameState) { ol.renderer.webgl.Map.prototype.dispatchComposeEvent_ = function(type, frameState) {
var map = this.getMap(); var map = this.getMap();
if (map.hasListener(type)) { if (map.hasListener(type)) {
var context = this.context_; var context = this.context_;
@@ -249,13 +251,13 @@ ol.renderer.webgl.Map.prototype.dispatchComposeEvent_ = function(type, frameStat
frameState, null, context); frameState, null, context);
map.dispatchEvent(composeEvent); map.dispatchEvent(composeEvent);
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.Map.prototype.disposeInternal = function() { ol.renderer.webgl.Map.prototype.disposeInternal = function() {
var gl = this.getGL(); var gl = this.getGL();
if (!gl.isContextLost()) { if (!gl.isContextLost()) {
this.textureCache_.forEach( this.textureCache_.forEach(
@@ -271,15 +273,15 @@ ol.renderer.webgl.Map.prototype.disposeInternal = function() {
} }
this.context_.dispose(); this.context_.dispose();
ol.renderer.Map.prototype.disposeInternal.call(this); ol.renderer.Map.prototype.disposeInternal.call(this);
}; };
/** /**
* @param {ol.Map} map Map. * @param {ol.Map} map Map.
* @param {olx.FrameState} frameState Frame state. * @param {olx.FrameState} frameState Frame state.
* @private * @private
*/ */
ol.renderer.webgl.Map.prototype.expireCache_ = function(map, frameState) { ol.renderer.webgl.Map.prototype.expireCache_ = function(map, frameState) {
var gl = this.getGL(); var gl = this.getGL();
var textureCacheEntry; var textureCacheEntry;
while (this.textureCache_.getCount() - this.textureCacheFrameMarkerCount_ > while (this.textureCache_.getCount() - this.textureCacheFrameMarkerCount_ >
@@ -296,46 +298,46 @@ ol.renderer.webgl.Map.prototype.expireCache_ = function(map, frameState) {
} }
this.textureCache_.pop(); this.textureCache_.pop();
} }
}; };
/** /**
* @return {ol.webgl.Context} The context. * @return {ol.webgl.Context} The context.
*/ */
ol.renderer.webgl.Map.prototype.getContext = function() { ol.renderer.webgl.Map.prototype.getContext = function() {
return this.context_; return this.context_;
}; };
/** /**
* @return {WebGLRenderingContext} GL. * @return {WebGLRenderingContext} GL.
*/ */
ol.renderer.webgl.Map.prototype.getGL = function() { ol.renderer.webgl.Map.prototype.getGL = function() {
return this.gl_; return this.gl_;
}; };
/** /**
* @return {ol.structs.PriorityQueue.<Array>} Tile texture queue. * @return {ol.structs.PriorityQueue.<Array>} Tile texture queue.
*/ */
ol.renderer.webgl.Map.prototype.getTileTextureQueue = function() { ol.renderer.webgl.Map.prototype.getTileTextureQueue = function() {
return this.tileTextureQueue_; return this.tileTextureQueue_;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.Map.prototype.getType = function() { ol.renderer.webgl.Map.prototype.getType = function() {
return ol.renderer.Type.WEBGL; return ol.renderer.Type.WEBGL;
}; };
/** /**
* @param {ol.events.Event} event Event. * @param {ol.events.Event} event Event.
* @protected * @protected
*/ */
ol.renderer.webgl.Map.prototype.handleWebGLContextLost = function(event) { ol.renderer.webgl.Map.prototype.handleWebGLContextLost = function(event) {
event.preventDefault(); event.preventDefault();
this.textureCache_.clear(); this.textureCache_.clear();
this.textureCacheFrameMarkerCount_ = 0; this.textureCacheFrameMarkerCount_ = 0;
@@ -345,22 +347,22 @@ ol.renderer.webgl.Map.prototype.handleWebGLContextLost = function(event) {
var renderer = /** @type {ol.renderer.webgl.Layer} */ (renderers[id]); var renderer = /** @type {ol.renderer.webgl.Layer} */ (renderers[id]);
renderer.handleWebGLContextLost(); renderer.handleWebGLContextLost();
} }
}; };
/** /**
* @protected * @protected
*/ */
ol.renderer.webgl.Map.prototype.handleWebGLContextRestored = function() { ol.renderer.webgl.Map.prototype.handleWebGLContextRestored = function() {
this.initializeGL_(); this.initializeGL_();
this.getMap().render(); this.getMap().render();
}; };
/** /**
* @private * @private
*/ */
ol.renderer.webgl.Map.prototype.initializeGL_ = function() { ol.renderer.webgl.Map.prototype.initializeGL_ = function() {
var gl = this.gl_; var gl = this.gl_;
gl.activeTexture(ol.webgl.TEXTURE0); gl.activeTexture(ol.webgl.TEXTURE0);
gl.blendFuncSeparate( gl.blendFuncSeparate(
@@ -370,22 +372,22 @@ ol.renderer.webgl.Map.prototype.initializeGL_ = function() {
gl.disable(ol.webgl.DEPTH_TEST); gl.disable(ol.webgl.DEPTH_TEST);
gl.disable(ol.webgl.SCISSOR_TEST); gl.disable(ol.webgl.SCISSOR_TEST);
gl.disable(ol.webgl.STENCIL_TEST); gl.disable(ol.webgl.STENCIL_TEST);
}; };
/** /**
* @param {ol.Tile} tile Tile. * @param {ol.Tile} tile Tile.
* @return {boolean} Is tile texture loaded. * @return {boolean} Is tile texture loaded.
*/ */
ol.renderer.webgl.Map.prototype.isTileTextureLoaded = function(tile) { ol.renderer.webgl.Map.prototype.isTileTextureLoaded = function(tile) {
return this.textureCache_.containsKey(tile.getKey()); return this.textureCache_.containsKey(tile.getKey());
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.Map.prototype.renderFrame = function(frameState) { ol.renderer.webgl.Map.prototype.renderFrame = function(frameState) {
var context = this.getContext(); var context = this.getContext();
var gl = this.getGL(); var gl = this.getGL();
@@ -471,13 +473,13 @@ ol.renderer.webgl.Map.prototype.renderFrame = function(frameState) {
this.scheduleRemoveUnusedLayerRenderers(frameState); this.scheduleRemoveUnusedLayerRenderers(frameState);
this.scheduleExpireIconCache(frameState); this.scheduleExpireIconCache(frameState);
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.Map.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg, ol.renderer.webgl.Map.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg,
layerFilter, thisArg2) { layerFilter, thisArg2) {
var result; var result;
@@ -504,13 +506,13 @@ ol.renderer.webgl.Map.prototype.forEachFeatureAtCoordinate = function(coordinate
} }
} }
return undefined; return undefined;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.Map.prototype.hasFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, layerFilter, thisArg) { ol.renderer.webgl.Map.prototype.hasFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, layerFilter, thisArg) {
var hasFeature = false; var hasFeature = false;
if (this.getGL().isContextLost()) { if (this.getGL().isContextLost()) {
@@ -536,13 +538,13 @@ ol.renderer.webgl.Map.prototype.hasFeatureAtCoordinate = function(coordinate, fr
} }
} }
return hasFeature; return hasFeature;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.Map.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg, ol.renderer.webgl.Map.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg,
layerFilter, thisArg2) { layerFilter, thisArg2) {
if (this.getGL().isContextLost()) { if (this.getGL().isContextLost()) {
return false; return false;
@@ -568,4 +570,6 @@ ol.renderer.webgl.Map.prototype.forEachLayerAtPixel = function(pixel, frameState
} }
} }
return undefined; return undefined;
}; };
}
+23 -19
View File
@@ -17,13 +17,15 @@ goog.require('ol.webgl');
goog.require('ol.webgl.Buffer'); goog.require('ol.webgl.Buffer');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.renderer.webgl.Layer} * @extends {ol.renderer.webgl.Layer}
* @param {ol.renderer.webgl.Map} mapRenderer Map renderer. * @param {ol.renderer.webgl.Map} mapRenderer Map renderer.
* @param {ol.layer.Tile} tileLayer Tile layer. * @param {ol.layer.Tile} tileLayer Tile layer.
*/ */
ol.renderer.webgl.TileLayer = function(mapRenderer, tileLayer) { ol.renderer.webgl.TileLayer = function(mapRenderer, tileLayer) {
ol.renderer.webgl.Layer.call(this, mapRenderer, tileLayer); ol.renderer.webgl.Layer.call(this, mapRenderer, tileLayer);
@@ -80,21 +82,21 @@ ol.renderer.webgl.TileLayer = function(mapRenderer, tileLayer) {
*/ */
this.tmpSize_ = [0, 0]; this.tmpSize_ = [0, 0];
}; };
ol.inherits(ol.renderer.webgl.TileLayer, ol.renderer.webgl.Layer); ol.inherits(ol.renderer.webgl.TileLayer, ol.renderer.webgl.Layer);
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.TileLayer.prototype.disposeInternal = function() { ol.renderer.webgl.TileLayer.prototype.disposeInternal = function() {
var context = this.mapRenderer.getContext(); var context = this.mapRenderer.getContext();
context.deleteBuffer(this.renderArrayBuffer_); context.deleteBuffer(this.renderArrayBuffer_);
ol.renderer.webgl.Layer.prototype.disposeInternal.call(this); ol.renderer.webgl.Layer.prototype.disposeInternal.call(this);
}; };
/** /**
* Create a function that adds loaded tiles to the tile lookup. * Create a function that adds loaded tiles to the tile lookup.
* @param {ol.source.Tile} source Tile source. * @param {ol.source.Tile} source Tile source.
* @param {ol.proj.Projection} projection Projection of the tiles. * @param {ol.proj.Projection} projection Projection of the tiles.
@@ -105,7 +107,7 @@ ol.renderer.webgl.TileLayer.prototype.disposeInternal = function() {
* lookup. * lookup.
* @protected * @protected
*/ */
ol.renderer.webgl.TileLayer.prototype.createLoadedTileFinder = function(source, projection, tiles) { ol.renderer.webgl.TileLayer.prototype.createLoadedTileFinder = function(source, projection, tiles) {
var mapRenderer = this.mapRenderer; var mapRenderer = this.mapRenderer;
return ( return (
@@ -127,22 +129,22 @@ ol.renderer.webgl.TileLayer.prototype.createLoadedTileFinder = function(source,
} }
return source.forEachLoadedTile(projection, zoom, tileRange, callback); return source.forEachLoadedTile(projection, zoom, tileRange, callback);
}); });
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.TileLayer.prototype.handleWebGLContextLost = function() { ol.renderer.webgl.TileLayer.prototype.handleWebGLContextLost = function() {
ol.renderer.webgl.Layer.prototype.handleWebGLContextLost.call(this); ol.renderer.webgl.Layer.prototype.handleWebGLContextLost.call(this);
this.locations_ = null; this.locations_ = null;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.TileLayer.prototype.prepareFrame = function(frameState, layerState, context) { ol.renderer.webgl.TileLayer.prototype.prepareFrame = function(frameState, layerState, context) {
var mapRenderer = this.mapRenderer; var mapRenderer = this.mapRenderer;
var gl = context.getGL(); var gl = context.getGL();
@@ -354,13 +356,13 @@ ol.renderer.webgl.TileLayer.prototype.prepareFrame = function(frameState, layerS
ol.transform.translate(texCoordMatrix, -0.5, -0.5); ol.transform.translate(texCoordMatrix, -0.5, -0.5);
return true; return true;
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.TileLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) { ol.renderer.webgl.TileLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
if (!this.framebuffer) { if (!this.framebuffer) {
return undefined; return undefined;
} }
@@ -386,4 +388,6 @@ ol.renderer.webgl.TileLayer.prototype.forEachLayerAtPixel = function(pixel, fram
} else { } else {
return undefined; return undefined;
} }
}; };
}
+29 -25
View File
@@ -6,83 +6,85 @@ goog.require('ol.webgl.Fragment');
goog.require('ol.webgl.Vertex'); goog.require('ol.webgl.Vertex');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.webgl.Fragment} * @extends {ol.webgl.Fragment}
* @struct * @struct
*/ */
ol.renderer.webgl.tilelayershader.Fragment = function() { ol.renderer.webgl.tilelayershader.Fragment = function() {
ol.webgl.Fragment.call(this, ol.renderer.webgl.tilelayershader.Fragment.SOURCE); ol.webgl.Fragment.call(this, ol.renderer.webgl.tilelayershader.Fragment.SOURCE);
}; };
ol.inherits(ol.renderer.webgl.tilelayershader.Fragment, ol.webgl.Fragment); ol.inherits(ol.renderer.webgl.tilelayershader.Fragment, ol.webgl.Fragment);
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.renderer.webgl.tilelayershader.Fragment.DEBUG_SOURCE = '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'; ol.renderer.webgl.tilelayershader.Fragment.DEBUG_SOURCE = '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';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.renderer.webgl.tilelayershader.Fragment.OPTIMIZED_SOURCE = 'precision mediump float;varying vec2 a;uniform sampler2D e;void main(void){gl_FragColor=texture2D(e,a);}'; ol.renderer.webgl.tilelayershader.Fragment.OPTIMIZED_SOURCE = 'precision mediump float;varying vec2 a;uniform sampler2D e;void main(void){gl_FragColor=texture2D(e,a);}';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.renderer.webgl.tilelayershader.Fragment.SOURCE = ol.renderer.webgl.tilelayershader.Fragment.OPTIMIZED_SOURCE; ol.renderer.webgl.tilelayershader.Fragment.SOURCE = ol.renderer.webgl.tilelayershader.Fragment.OPTIMIZED_SOURCE;
ol.renderer.webgl.tilelayershader.fragment = new ol.renderer.webgl.tilelayershader.Fragment(); ol.renderer.webgl.tilelayershader.fragment = new ol.renderer.webgl.tilelayershader.Fragment();
/** /**
* @constructor * @constructor
* @extends {ol.webgl.Vertex} * @extends {ol.webgl.Vertex}
* @struct * @struct
*/ */
ol.renderer.webgl.tilelayershader.Vertex = function() { ol.renderer.webgl.tilelayershader.Vertex = function() {
ol.webgl.Vertex.call(this, ol.renderer.webgl.tilelayershader.Vertex.SOURCE); ol.webgl.Vertex.call(this, ol.renderer.webgl.tilelayershader.Vertex.SOURCE);
}; };
ol.inherits(ol.renderer.webgl.tilelayershader.Vertex, ol.webgl.Vertex); ol.inherits(ol.renderer.webgl.tilelayershader.Vertex, ol.webgl.Vertex);
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.renderer.webgl.tilelayershader.Vertex.DEBUG_SOURCE = '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'; ol.renderer.webgl.tilelayershader.Vertex.DEBUG_SOURCE = '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';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.renderer.webgl.tilelayershader.Vertex.OPTIMIZED_SOURCE = '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;}'; ol.renderer.webgl.tilelayershader.Vertex.OPTIMIZED_SOURCE = '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;}';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
ol.renderer.webgl.tilelayershader.Vertex.SOURCE = ol.renderer.webgl.tilelayershader.Vertex.OPTIMIZED_SOURCE; ol.renderer.webgl.tilelayershader.Vertex.SOURCE = ol.renderer.webgl.tilelayershader.Vertex.OPTIMIZED_SOURCE;
ol.renderer.webgl.tilelayershader.vertex = new ol.renderer.webgl.tilelayershader.Vertex(); ol.renderer.webgl.tilelayershader.vertex = new ol.renderer.webgl.tilelayershader.Vertex();
/** /**
* @constructor * @constructor
* @param {WebGLRenderingContext} gl GL. * @param {WebGLRenderingContext} gl GL.
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @struct * @struct
*/ */
ol.renderer.webgl.tilelayershader.Locations = function(gl, program) { ol.renderer.webgl.tilelayershader.Locations = function(gl, program) {
/** /**
* @type {WebGLUniformLocation} * @type {WebGLUniformLocation}
@@ -103,4 +105,6 @@ ol.renderer.webgl.tilelayershader.Locations = function(gl, program) {
* @type {number} * @type {number}
*/ */
this.a_texCoord = gl.getAttribLocation(program, 'c'); this.a_texCoord = gl.getAttribLocation(program, 'c');
}; };
}
+32 -28
View File
@@ -9,13 +9,15 @@ goog.require('ol.renderer.webgl.Layer');
goog.require('ol.transform'); goog.require('ol.transform');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.renderer.webgl.Layer} * @extends {ol.renderer.webgl.Layer}
* @param {ol.renderer.webgl.Map} mapRenderer Map renderer. * @param {ol.renderer.webgl.Map} mapRenderer Map renderer.
* @param {ol.layer.Vector} vectorLayer Vector layer. * @param {ol.layer.Vector} vectorLayer Vector layer.
*/ */
ol.renderer.webgl.VectorLayer = function(mapRenderer, vectorLayer) { ol.renderer.webgl.VectorLayer = function(mapRenderer, vectorLayer) {
ol.renderer.webgl.Layer.call(this, mapRenderer, vectorLayer); ol.renderer.webgl.Layer.call(this, mapRenderer, vectorLayer);
@@ -62,14 +64,14 @@ ol.renderer.webgl.VectorLayer = function(mapRenderer, vectorLayer) {
*/ */
this.layerState_ = null; this.layerState_ = null;
}; };
ol.inherits(ol.renderer.webgl.VectorLayer, ol.renderer.webgl.Layer); ol.inherits(ol.renderer.webgl.VectorLayer, ol.renderer.webgl.Layer);
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.VectorLayer.prototype.composeFrame = function(frameState, layerState, context) { ol.renderer.webgl.VectorLayer.prototype.composeFrame = function(frameState, layerState, context) {
this.layerState_ = layerState; this.layerState_ = layerState;
var viewState = frameState.viewState; var viewState = frameState.viewState;
var replayGroup = this.replayGroup_; var replayGroup = this.replayGroup_;
@@ -86,13 +88,13 @@ ol.renderer.webgl.VectorLayer.prototype.composeFrame = function(frameState, laye
gl.disable(gl.SCISSOR_TEST); gl.disable(gl.SCISSOR_TEST);
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.VectorLayer.prototype.disposeInternal = function() { ol.renderer.webgl.VectorLayer.prototype.disposeInternal = function() {
var replayGroup = this.replayGroup_; var replayGroup = this.replayGroup_;
if (replayGroup) { if (replayGroup) {
var context = this.mapRenderer.getContext(); var context = this.mapRenderer.getContext();
@@ -100,13 +102,13 @@ ol.renderer.webgl.VectorLayer.prototype.disposeInternal = function() {
this.replayGroup_ = null; this.replayGroup_ = null;
} }
ol.renderer.webgl.Layer.prototype.disposeInternal.call(this); ol.renderer.webgl.Layer.prototype.disposeInternal.call(this);
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.VectorLayer.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg) { ol.renderer.webgl.VectorLayer.prototype.forEachFeatureAtCoordinate = function(coordinate, frameState, hitTolerance, callback, thisArg) {
if (!this.replayGroup_ || !this.layerState_) { if (!this.replayGroup_ || !this.layerState_) {
return undefined; return undefined;
} else { } else {
@@ -132,13 +134,13 @@ ol.renderer.webgl.VectorLayer.prototype.forEachFeatureAtCoordinate = function(co
} }
}); });
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.VectorLayer.prototype.hasFeatureAtCoordinate = function(coordinate, frameState) { ol.renderer.webgl.VectorLayer.prototype.hasFeatureAtCoordinate = function(coordinate, frameState) {
if (!this.replayGroup_ || !this.layerState_) { if (!this.replayGroup_ || !this.layerState_) {
return false; return false;
} else { } else {
@@ -150,13 +152,13 @@ ol.renderer.webgl.VectorLayer.prototype.hasFeatureAtCoordinate = function(coordi
frameState.size, frameState.pixelRatio, layerState.opacity, frameState.size, frameState.pixelRatio, layerState.opacity,
frameState.skippedFeatureUids); frameState.skippedFeatureUids);
} }
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.VectorLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) { ol.renderer.webgl.VectorLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
var coordinate = ol.transform.apply( var coordinate = ol.transform.apply(
frameState.pixelToCoordinateTransform, pixel.slice()); frameState.pixelToCoordinateTransform, pixel.slice());
var hasFeature = this.hasFeatureAtCoordinate(coordinate, frameState); var hasFeature = this.hasFeatureAtCoordinate(coordinate, frameState);
@@ -166,23 +168,23 @@ ol.renderer.webgl.VectorLayer.prototype.forEachLayerAtPixel = function(pixel, fr
} else { } else {
return undefined; return undefined;
} }
}; };
/** /**
* Handle changes in image style state. * Handle changes in image style state.
* @param {ol.events.Event} event Image style change event. * @param {ol.events.Event} event Image style change event.
* @private * @private
*/ */
ol.renderer.webgl.VectorLayer.prototype.handleStyleImageChange_ = function(event) { ol.renderer.webgl.VectorLayer.prototype.handleStyleImageChange_ = function(event) {
this.renderIfReadyAndVisible(); this.renderIfReadyAndVisible();
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.renderer.webgl.VectorLayer.prototype.prepareFrame = function(frameState, layerState, context) { ol.renderer.webgl.VectorLayer.prototype.prepareFrame = function(frameState, layerState, context) {
var vectorLayer = /** @type {ol.layer.Vector} */ (this.getLayer()); var vectorLayer = /** @type {ol.layer.Vector} */ (this.getLayer());
var vectorSource = vectorLayer.getSource(); var vectorSource = vectorLayer.getSource();
@@ -281,10 +283,10 @@ ol.renderer.webgl.VectorLayer.prototype.prepareFrame = function(frameState, laye
this.replayGroup_ = replayGroup; this.replayGroup_ = replayGroup;
return true; return true;
}; };
/** /**
* @param {ol.Feature} feature Feature. * @param {ol.Feature} feature Feature.
* @param {number} resolution Resolution. * @param {number} resolution Resolution.
* @param {number} pixelRatio Pixel ratio. * @param {number} pixelRatio Pixel ratio.
@@ -293,7 +295,7 @@ ol.renderer.webgl.VectorLayer.prototype.prepareFrame = function(frameState, laye
* @param {ol.render.webgl.ReplayGroup} replayGroup Replay group. * @param {ol.render.webgl.ReplayGroup} replayGroup Replay group.
* @return {boolean} `true` if an image is loading. * @return {boolean} `true` if an image is loading.
*/ */
ol.renderer.webgl.VectorLayer.prototype.renderFeature = function(feature, resolution, pixelRatio, styles, replayGroup) { ol.renderer.webgl.VectorLayer.prototype.renderFeature = function(feature, resolution, pixelRatio, styles, replayGroup) {
if (!styles) { if (!styles) {
return false; return false;
} }
@@ -312,4 +314,6 @@ ol.renderer.webgl.VectorLayer.prototype.renderFeature = function(feature, resolu
this.handleStyleImageChange_, this) || loading; this.handleStyleImageChange_, this) || loading;
} }
return loading; return loading;
}; };
}
+82 -78
View File
@@ -1,278 +1,280 @@
goog.provide('ol.webgl'); goog.provide('ol.webgl');
/** Constants taken from goog.webgl if (ol.ENABLE_WEBGL) {
/** Constants taken from goog.webgl
*/ */
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.ONE = 1; ol.webgl.ONE = 1;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.SRC_ALPHA = 0x0302; ol.webgl.SRC_ALPHA = 0x0302;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.COLOR_ATTACHMENT0 = 0x8CE0; ol.webgl.COLOR_ATTACHMENT0 = 0x8CE0;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.COLOR_BUFFER_BIT = 0x00004000; ol.webgl.COLOR_BUFFER_BIT = 0x00004000;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.TRIANGLES = 0x0004; ol.webgl.TRIANGLES = 0x0004;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.TRIANGLE_STRIP = 0x0005; ol.webgl.TRIANGLE_STRIP = 0x0005;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.ONE_MINUS_SRC_ALPHA = 0x0303; ol.webgl.ONE_MINUS_SRC_ALPHA = 0x0303;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.ARRAY_BUFFER = 0x8892; ol.webgl.ARRAY_BUFFER = 0x8892;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.ELEMENT_ARRAY_BUFFER = 0x8893; ol.webgl.ELEMENT_ARRAY_BUFFER = 0x8893;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.STREAM_DRAW = 0x88E0; ol.webgl.STREAM_DRAW = 0x88E0;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.STATIC_DRAW = 0x88E4; ol.webgl.STATIC_DRAW = 0x88E4;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.DYNAMIC_DRAW = 0x88E8; ol.webgl.DYNAMIC_DRAW = 0x88E8;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.CULL_FACE = 0x0B44; ol.webgl.CULL_FACE = 0x0B44;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.BLEND = 0x0BE2; ol.webgl.BLEND = 0x0BE2;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.STENCIL_TEST = 0x0B90; ol.webgl.STENCIL_TEST = 0x0B90;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.DEPTH_TEST = 0x0B71; ol.webgl.DEPTH_TEST = 0x0B71;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.SCISSOR_TEST = 0x0C11; ol.webgl.SCISSOR_TEST = 0x0C11;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.UNSIGNED_BYTE = 0x1401; ol.webgl.UNSIGNED_BYTE = 0x1401;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.UNSIGNED_SHORT = 0x1403; ol.webgl.UNSIGNED_SHORT = 0x1403;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.UNSIGNED_INT = 0x1405; ol.webgl.UNSIGNED_INT = 0x1405;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.FLOAT = 0x1406; ol.webgl.FLOAT = 0x1406;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.RGBA = 0x1908; ol.webgl.RGBA = 0x1908;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.FRAGMENT_SHADER = 0x8B30; ol.webgl.FRAGMENT_SHADER = 0x8B30;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.VERTEX_SHADER = 0x8B31; ol.webgl.VERTEX_SHADER = 0x8B31;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.LINK_STATUS = 0x8B82; ol.webgl.LINK_STATUS = 0x8B82;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.LINEAR = 0x2601; ol.webgl.LINEAR = 0x2601;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.TEXTURE_MAG_FILTER = 0x2800; ol.webgl.TEXTURE_MAG_FILTER = 0x2800;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.TEXTURE_MIN_FILTER = 0x2801; ol.webgl.TEXTURE_MIN_FILTER = 0x2801;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.TEXTURE_WRAP_S = 0x2802; ol.webgl.TEXTURE_WRAP_S = 0x2802;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.TEXTURE_WRAP_T = 0x2803; ol.webgl.TEXTURE_WRAP_T = 0x2803;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.TEXTURE_2D = 0x0DE1; ol.webgl.TEXTURE_2D = 0x0DE1;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.TEXTURE0 = 0x84C0; ol.webgl.TEXTURE0 = 0x84C0;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.CLAMP_TO_EDGE = 0x812F; ol.webgl.CLAMP_TO_EDGE = 0x812F;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.COMPILE_STATUS = 0x8B81; ol.webgl.COMPILE_STATUS = 0x8B81;
/** /**
* @const * @const
* @type {number} * @type {number}
*/ */
ol.webgl.FRAMEBUFFER = 0x8D40; ol.webgl.FRAMEBUFFER = 0x8D40;
/** end of goog.webgl constants /** end of goog.webgl constants
*/ */
/** /**
* @const * @const
* @private * @private
* @type {Array.<string>} * @type {Array.<string>}
*/ */
ol.webgl.CONTEXT_IDS_ = [ ol.webgl.CONTEXT_IDS_ = [
'experimental-webgl', 'experimental-webgl',
'webgl', 'webgl',
'webkit-3d', 'webkit-3d',
'moz-webgl' 'moz-webgl'
]; ];
/** /**
* @param {HTMLCanvasElement} canvas Canvas. * @param {HTMLCanvasElement} canvas Canvas.
* @param {Object=} opt_attributes Attributes. * @param {Object=} opt_attributes Attributes.
* @return {WebGLRenderingContext} WebGL rendering context. * @return {WebGLRenderingContext} WebGL rendering context.
*/ */
ol.webgl.getContext = function(canvas, opt_attributes) { ol.webgl.getContext = function(canvas, opt_attributes) {
var context, i, ii = ol.webgl.CONTEXT_IDS_.length; var context, i, ii = ol.webgl.CONTEXT_IDS_.length;
for (i = 0; i < ii; ++i) { for (i = 0; i < ii; ++i) {
try { try {
@@ -285,4 +287,6 @@ ol.webgl.getContext = function(canvas, opt_attributes) {
} }
} }
return null; return null;
}; };
}
+16 -12
View File
@@ -4,13 +4,15 @@ goog.require('ol');
goog.require('ol.webgl'); goog.require('ol.webgl');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @param {Array.<number>=} opt_arr Array. * @param {Array.<number>=} opt_arr Array.
* @param {number=} opt_usage Usage. * @param {number=} opt_usage Usage.
* @struct * @struct
*/ */
ol.webgl.Buffer = function(opt_arr, opt_usage) { ol.webgl.Buffer = function(opt_arr, opt_usage) {
/** /**
* @private * @private
@@ -25,31 +27,33 @@ ol.webgl.Buffer = function(opt_arr, opt_usage) {
this.usage_ = opt_usage !== undefined ? this.usage_ = opt_usage !== undefined ?
opt_usage : ol.webgl.Buffer.Usage_.STATIC_DRAW; opt_usage : ol.webgl.Buffer.Usage_.STATIC_DRAW;
}; };
/** /**
* @return {Array.<number>} Array. * @return {Array.<number>} Array.
*/ */
ol.webgl.Buffer.prototype.getArray = function() { ol.webgl.Buffer.prototype.getArray = function() {
return this.arr_; return this.arr_;
}; };
/** /**
* @return {number} Usage. * @return {number} Usage.
*/ */
ol.webgl.Buffer.prototype.getUsage = function() { ol.webgl.Buffer.prototype.getUsage = function() {
return this.usage_; return this.usage_;
}; };
/** /**
* @enum {number} * @enum {number}
* @private * @private
*/ */
ol.webgl.Buffer.Usage_ = { ol.webgl.Buffer.Usage_ = {
STATIC_DRAW: ol.webgl.STATIC_DRAW, STATIC_DRAW: ol.webgl.STATIC_DRAW,
STREAM_DRAW: ol.webgl.STREAM_DRAW, STREAM_DRAW: ol.webgl.STREAM_DRAW,
DYNAMIC_DRAW: ol.webgl.DYNAMIC_DRAW DYNAMIC_DRAW: ol.webgl.DYNAMIC_DRAW
}; };
}
+53 -49
View File
@@ -9,7 +9,9 @@ goog.require('ol.webgl');
goog.require('ol.webgl.ContextEventType'); goog.require('ol.webgl.ContextEventType');
/** if (ol.ENABLE_WEBGL) {
/**
* @classdesc * @classdesc
* A WebGL context for accessing low-level WebGL capabilities. * A WebGL context for accessing low-level WebGL capabilities.
* *
@@ -18,7 +20,7 @@ goog.require('ol.webgl.ContextEventType');
* @param {HTMLCanvasElement} canvas Canvas. * @param {HTMLCanvasElement} canvas Canvas.
* @param {WebGLRenderingContext} gl GL. * @param {WebGLRenderingContext} gl GL.
*/ */
ol.webgl.Context = function(canvas, gl) { ol.webgl.Context = function(canvas, gl) {
/** /**
* @private * @private
@@ -90,18 +92,18 @@ ol.webgl.Context = function(canvas, gl) {
ol.events.listen(this.canvas_, ol.webgl.ContextEventType.RESTORED, ol.events.listen(this.canvas_, ol.webgl.ContextEventType.RESTORED,
this.handleWebGLContextRestored, this); this.handleWebGLContextRestored, this);
}; };
ol.inherits(ol.webgl.Context, ol.Disposable); ol.inherits(ol.webgl.Context, ol.Disposable);
/** /**
* Just bind the buffer if it's in the cache. Otherwise create * 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 WebGL buffer, bind it, populate it, and add an entry to
* the cache. * the cache.
* @param {number} target Target. * @param {number} target Target.
* @param {ol.webgl.Buffer} buf Buffer. * @param {ol.webgl.Buffer} buf Buffer.
*/ */
ol.webgl.Context.prototype.bindBuffer = function(target, buf) { ol.webgl.Context.prototype.bindBuffer = function(target, buf) {
var gl = this.getGL(); var gl = this.getGL();
var arr = buf.getArray(); var arr = buf.getArray();
var bufferKey = String(ol.getUid(buf)); var bufferKey = String(ol.getUid(buf));
@@ -124,13 +126,13 @@ ol.webgl.Context.prototype.bindBuffer = function(target, buf) {
buffer: buffer buffer: buffer
}; };
} }
}; };
/** /**
* @param {ol.webgl.Buffer} buf Buffer. * @param {ol.webgl.Buffer} buf Buffer.
*/ */
ol.webgl.Context.prototype.deleteBuffer = function(buf) { ol.webgl.Context.prototype.deleteBuffer = function(buf) {
var gl = this.getGL(); var gl = this.getGL();
var bufferKey = String(ol.getUid(buf)); var bufferKey = String(ol.getUid(buf));
var bufferCacheEntry = this.bufferCache_[bufferKey]; var bufferCacheEntry = this.bufferCache_[bufferKey];
@@ -138,13 +140,13 @@ ol.webgl.Context.prototype.deleteBuffer = function(buf) {
gl.deleteBuffer(bufferCacheEntry.buffer); gl.deleteBuffer(bufferCacheEntry.buffer);
} }
delete this.bufferCache_[bufferKey]; delete this.bufferCache_[bufferKey];
}; };
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.webgl.Context.prototype.disposeInternal = function() { ol.webgl.Context.prototype.disposeInternal = function() {
ol.events.unlistenAll(this.canvas_); ol.events.unlistenAll(this.canvas_);
var gl = this.getGL(); var gl = this.getGL();
if (!gl.isContextLost()) { if (!gl.isContextLost()) {
@@ -163,46 +165,46 @@ ol.webgl.Context.prototype.disposeInternal = function() {
gl.deleteRenderbuffer(this.hitDetectionRenderbuffer_); gl.deleteRenderbuffer(this.hitDetectionRenderbuffer_);
gl.deleteTexture(this.hitDetectionTexture_); gl.deleteTexture(this.hitDetectionTexture_);
} }
}; };
/** /**
* @return {HTMLCanvasElement} Canvas. * @return {HTMLCanvasElement} Canvas.
*/ */
ol.webgl.Context.prototype.getCanvas = function() { ol.webgl.Context.prototype.getCanvas = function() {
return this.canvas_; return this.canvas_;
}; };
/** /**
* Get the WebGL rendering context * Get the WebGL rendering context
* @return {WebGLRenderingContext} The rendering context. * @return {WebGLRenderingContext} The rendering context.
* @api * @api
*/ */
ol.webgl.Context.prototype.getGL = function() { ol.webgl.Context.prototype.getGL = function() {
return this.gl_; return this.gl_;
}; };
/** /**
* Get the frame buffer for hit detection. * Get the frame buffer for hit detection.
* @return {WebGLFramebuffer} The hit detection frame buffer. * @return {WebGLFramebuffer} The hit detection frame buffer.
*/ */
ol.webgl.Context.prototype.getHitDetectionFramebuffer = function() { ol.webgl.Context.prototype.getHitDetectionFramebuffer = function() {
if (!this.hitDetectionFramebuffer_) { if (!this.hitDetectionFramebuffer_) {
this.initHitDetectionFramebuffer_(); this.initHitDetectionFramebuffer_();
} }
return this.hitDetectionFramebuffer_; return this.hitDetectionFramebuffer_;
}; };
/** /**
* Get shader from the cache if it's in the cache. Otherwise, create * Get shader from the cache if it's in the cache. Otherwise, create
* the WebGL shader, compile it, and add entry to cache. * the WebGL shader, compile it, and add entry to cache.
* @param {ol.webgl.Shader} shaderObject Shader object. * @param {ol.webgl.Shader} shaderObject Shader object.
* @return {WebGLShader} Shader. * @return {WebGLShader} Shader.
*/ */
ol.webgl.Context.prototype.getShader = function(shaderObject) { ol.webgl.Context.prototype.getShader = function(shaderObject) {
var shaderKey = String(ol.getUid(shaderObject)); var shaderKey = String(ol.getUid(shaderObject));
if (shaderKey in this.shaderCache_) { if (shaderKey in this.shaderCache_) {
return this.shaderCache_[shaderKey]; return this.shaderCache_[shaderKey];
@@ -214,10 +216,10 @@ ol.webgl.Context.prototype.getShader = function(shaderObject) {
this.shaderCache_[shaderKey] = shader; this.shaderCache_[shaderKey] = shader;
return shader; return shader;
} }
}; };
/** /**
* Get the program from the cache if it's in the cache. Otherwise create * Get the program from the cache if it's in the cache. Otherwise create
* the WebGL program, attach the shaders to it, and add an entry to the * the WebGL program, attach the shaders to it, and add an entry to the
* cache. * cache.
@@ -225,7 +227,7 @@ ol.webgl.Context.prototype.getShader = function(shaderObject) {
* @param {ol.webgl.Vertex} vertexShaderObject Vertex shader. * @param {ol.webgl.Vertex} vertexShaderObject Vertex shader.
* @return {WebGLProgram} Program. * @return {WebGLProgram} Program.
*/ */
ol.webgl.Context.prototype.getProgram = function( ol.webgl.Context.prototype.getProgram = function(
fragmentShaderObject, vertexShaderObject) { fragmentShaderObject, vertexShaderObject) {
var programKey = var programKey =
ol.getUid(fragmentShaderObject) + '/' + ol.getUid(vertexShaderObject); ol.getUid(fragmentShaderObject) + '/' + ol.getUid(vertexShaderObject);
@@ -240,13 +242,13 @@ ol.webgl.Context.prototype.getProgram = function(
this.programCache_[programKey] = program; this.programCache_[programKey] = program;
return program; return program;
} }
}; };
/** /**
* FIXME empy description for jsdoc * FIXME empy description for jsdoc
*/ */
ol.webgl.Context.prototype.handleWebGLContextLost = function() { ol.webgl.Context.prototype.handleWebGLContextLost = function() {
ol.obj.clear(this.bufferCache_); ol.obj.clear(this.bufferCache_);
ol.obj.clear(this.shaderCache_); ol.obj.clear(this.shaderCache_);
ol.obj.clear(this.programCache_); ol.obj.clear(this.programCache_);
@@ -254,21 +256,21 @@ ol.webgl.Context.prototype.handleWebGLContextLost = function() {
this.hitDetectionFramebuffer_ = null; this.hitDetectionFramebuffer_ = null;
this.hitDetectionTexture_ = null; this.hitDetectionTexture_ = null;
this.hitDetectionRenderbuffer_ = null; this.hitDetectionRenderbuffer_ = null;
}; };
/** /**
* FIXME empy description for jsdoc * FIXME empy description for jsdoc
*/ */
ol.webgl.Context.prototype.handleWebGLContextRestored = function() { ol.webgl.Context.prototype.handleWebGLContextRestored = function() {
}; };
/** /**
* Creates a 1x1 pixel framebuffer for the hit-detection. * Creates a 1x1 pixel framebuffer for the hit-detection.
* @private * @private
*/ */
ol.webgl.Context.prototype.initHitDetectionFramebuffer_ = function() { ol.webgl.Context.prototype.initHitDetectionFramebuffer_ = function() {
var gl = this.gl_; var gl = this.gl_;
var framebuffer = gl.createFramebuffer(); var framebuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
@@ -289,16 +291,16 @@ ol.webgl.Context.prototype.initHitDetectionFramebuffer_ = function() {
this.hitDetectionFramebuffer_ = framebuffer; this.hitDetectionFramebuffer_ = framebuffer;
this.hitDetectionTexture_ = texture; this.hitDetectionTexture_ = texture;
this.hitDetectionRenderbuffer_ = renderbuffer; this.hitDetectionRenderbuffer_ = renderbuffer;
}; };
/** /**
* Use a program. If the program is already in use, this will return `false`. * Use a program. If the program is already in use, this will return `false`.
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @return {boolean} Changed. * @return {boolean} Changed.
* @api * @api
*/ */
ol.webgl.Context.prototype.useProgram = function(program) { ol.webgl.Context.prototype.useProgram = function(program) {
if (program == this.currentProgram_) { if (program == this.currentProgram_) {
return false; return false;
} else { } else {
@@ -307,17 +309,17 @@ ol.webgl.Context.prototype.useProgram = function(program) {
this.currentProgram_ = program; this.currentProgram_ = program;
return true; return true;
} }
}; };
/** /**
* @param {WebGLRenderingContext} gl WebGL rendering context. * @param {WebGLRenderingContext} gl WebGL rendering context.
* @param {number=} opt_wrapS wrapS. * @param {number=} opt_wrapS wrapS.
* @param {number=} opt_wrapT wrapT. * @param {number=} opt_wrapT wrapT.
* @return {WebGLTexture} The texture. * @return {WebGLTexture} The texture.
* @private * @private
*/ */
ol.webgl.Context.createTexture_ = function(gl, opt_wrapS, opt_wrapT) { ol.webgl.Context.createTexture_ = function(gl, opt_wrapS, opt_wrapT) {
var texture = gl.createTexture(); var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture); gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
@@ -333,10 +335,10 @@ ol.webgl.Context.createTexture_ = function(gl, opt_wrapS, opt_wrapT) {
} }
return texture; return texture;
}; };
/** /**
* @param {WebGLRenderingContext} gl WebGL rendering context. * @param {WebGLRenderingContext} gl WebGL rendering context.
* @param {number} width Width. * @param {number} width Width.
* @param {number} height Height. * @param {number} height Height.
@@ -344,7 +346,7 @@ ol.webgl.Context.createTexture_ = function(gl, opt_wrapS, opt_wrapT) {
* @param {number=} opt_wrapT wrapT. * @param {number=} opt_wrapT wrapT.
* @return {WebGLTexture} The texture. * @return {WebGLTexture} The texture.
*/ */
ol.webgl.Context.createEmptyTexture = function( ol.webgl.Context.createEmptyTexture = function(
gl, width, height, opt_wrapS, opt_wrapT) { gl, width, height, opt_wrapS, opt_wrapT) {
var texture = ol.webgl.Context.createTexture_(gl, opt_wrapS, opt_wrapT); var texture = ol.webgl.Context.createTexture_(gl, opt_wrapS, opt_wrapT);
gl.texImage2D( gl.texImage2D(
@@ -352,20 +354,22 @@ ol.webgl.Context.createEmptyTexture = function(
null); null);
return texture; return texture;
}; };
/** /**
* @param {WebGLRenderingContext} gl WebGL rendering context. * @param {WebGLRenderingContext} gl WebGL rendering context.
* @param {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} image Image. * @param {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} image Image.
* @param {number=} opt_wrapS wrapS. * @param {number=} opt_wrapS wrapS.
* @param {number=} opt_wrapT wrapT. * @param {number=} opt_wrapT wrapT.
* @return {WebGLTexture} The texture. * @return {WebGLTexture} The texture.
*/ */
ol.webgl.Context.createTexture = function(gl, image, opt_wrapS, opt_wrapT) { ol.webgl.Context.createTexture = function(gl, image, opt_wrapS, opt_wrapT) {
var texture = ol.webgl.Context.createTexture_(gl, opt_wrapS, opt_wrapT); var texture = ol.webgl.Context.createTexture_(gl, opt_wrapS, opt_wrapT);
gl.texImage2D( gl.texImage2D(
gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
return texture; return texture;
}; };
}
+11 -7
View File
@@ -5,21 +5,25 @@ goog.require('ol.webgl');
goog.require('ol.webgl.Shader'); goog.require('ol.webgl.Shader');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.webgl.Shader} * @extends {ol.webgl.Shader}
* @param {string} source Source. * @param {string} source Source.
* @struct * @struct
*/ */
ol.webgl.Fragment = function(source) { ol.webgl.Fragment = function(source) {
ol.webgl.Shader.call(this, source); ol.webgl.Shader.call(this, source);
}; };
ol.inherits(ol.webgl.Fragment, ol.webgl.Shader); ol.inherits(ol.webgl.Fragment, ol.webgl.Shader);
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.webgl.Fragment.prototype.getType = function() { ol.webgl.Fragment.prototype.getType = function() {
return ol.webgl.FRAGMENT_SHADER; return ol.webgl.FRAGMENT_SHADER;
}; };
}
+14 -10
View File
@@ -4,12 +4,14 @@ goog.require('ol.functions');
goog.require('ol.webgl'); goog.require('ol.webgl');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @param {string} source Source. * @param {string} source Source.
* @struct * @struct
*/ */
ol.webgl.Shader = function(source) { ol.webgl.Shader = function(source) {
/** /**
* @private * @private
@@ -17,25 +19,27 @@ ol.webgl.Shader = function(source) {
*/ */
this.source_ = source; this.source_ = source;
}; };
/** /**
* @abstract * @abstract
* @return {number} Type. * @return {number} Type.
*/ */
ol.webgl.Shader.prototype.getType = function() {}; ol.webgl.Shader.prototype.getType = function() {};
/** /**
* @return {string} Source. * @return {string} Source.
*/ */
ol.webgl.Shader.prototype.getSource = function() { ol.webgl.Shader.prototype.getSource = function() {
return this.source_; return this.source_;
}; };
/** /**
* @return {boolean} Is animated? * @return {boolean} Is animated?
*/ */
ol.webgl.Shader.prototype.isAnimated = ol.functions.FALSE; ol.webgl.Shader.prototype.isAnimated = ol.functions.FALSE;
}
+33 -29
View File
@@ -6,95 +6,99 @@ goog.require('ol.webgl.Fragment');
goog.require('ol.webgl.Vertex'); goog.require('ol.webgl.Vertex');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.webgl.Fragment} * @extends {ol.webgl.Fragment}
* @struct * @struct
*/ */
{{className}}.Fragment = function() { {{className}}.Fragment = function() {
ol.webgl.Fragment.call(this, {{className}}.Fragment.SOURCE); ol.webgl.Fragment.call(this, {{className}}.Fragment.SOURCE);
}; };
ol.inherits({{className}}.Fragment, ol.webgl.Fragment); ol.inherits({{className}}.Fragment, ol.webgl.Fragment);
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
{{className}}.Fragment.DEBUG_SOURCE = 'precision mediump float;\n{{{getOriginalFragmentSource}}}'; {{className}}.Fragment.DEBUG_SOURCE = 'precision mediump float;\n{{{getOriginalFragmentSource}}}';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
{{className}}.Fragment.OPTIMIZED_SOURCE = 'precision mediump float;{{{getFragmentSource}}}'; {{className}}.Fragment.OPTIMIZED_SOURCE = 'precision mediump float;{{{getFragmentSource}}}';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
{{className}}.Fragment.SOURCE = {{className}}.Fragment.OPTIMIZED_SOURCE; {{className}}.Fragment.SOURCE = {{className}}.Fragment.OPTIMIZED_SOURCE;
{{className}}.fragment = new {{className}}.Fragment(); {{className}}.fragment = new {{className}}.Fragment();
/** /**
* @constructor * @constructor
* @extends {ol.webgl.Vertex} * @extends {ol.webgl.Vertex}
* @struct * @struct
*/ */
{{className}}.Vertex = function() { {{className}}.Vertex = function() {
ol.webgl.Vertex.call(this, {{className}}.Vertex.SOURCE); ol.webgl.Vertex.call(this, {{className}}.Vertex.SOURCE);
}; };
ol.inherits({{className}}.Vertex, ol.webgl.Vertex); ol.inherits({{className}}.Vertex, ol.webgl.Vertex);
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
{{className}}.Vertex.DEBUG_SOURCE = '{{{getOriginalVertexSource}}}'; {{className}}.Vertex.DEBUG_SOURCE = '{{{getOriginalVertexSource}}}';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
{{className}}.Vertex.OPTIMIZED_SOURCE = '{{{getVertexSource}}}'; {{className}}.Vertex.OPTIMIZED_SOURCE = '{{{getVertexSource}}}';
/** /**
* @const * @const
* @type {string} * @type {string}
*/ */
{{className}}.Vertex.SOURCE = {{className}}.Vertex.OPTIMIZED_SOURCE; {{className}}.Vertex.SOURCE = {{className}}.Vertex.OPTIMIZED_SOURCE;
{{className}}.vertex = new {{className}}.Vertex(); {{className}}.vertex = new {{className}}.Vertex();
/** /**
* @constructor * @constructor
* @param {WebGLRenderingContext} gl GL. * @param {WebGLRenderingContext} gl GL.
* @param {WebGLProgram} program Program. * @param {WebGLProgram} program Program.
* @struct * @struct
*/ */
{{namespace}}.Locations = function(gl, program) { {{namespace}}.Locations = function(gl, program) {
{{#getUniforms}} {{#getUniforms}}
/** /**
* @type {WebGLUniformLocation} * @type {WebGLUniformLocation}
*/ */
this.{{originalName}} = gl.getUniformLocation(program, '{{shortName}}'); this.{{originalName}} = gl.getUniformLocation(program, '{{shortName}}');
{{/getUniforms}} {{/getUniforms}}
{{#getAttributes}} {{#getAttributes}}
/** /**
* @type {number} * @type {number}
*/ */
this.{{originalName}} = gl.getAttribLocation(program, '{{shortName}}'); this.{{originalName}} = gl.getAttribLocation(program, '{{shortName}}');
{{/getAttributes}} {{/getAttributes}}
}; };
}
+11 -7
View File
@@ -5,21 +5,25 @@ goog.require('ol.webgl');
goog.require('ol.webgl.Shader'); goog.require('ol.webgl.Shader');
/** if (ol.ENABLE_WEBGL) {
/**
* @constructor * @constructor
* @extends {ol.webgl.Shader} * @extends {ol.webgl.Shader}
* @param {string} source Source. * @param {string} source Source.
* @struct * @struct
*/ */
ol.webgl.Vertex = function(source) { ol.webgl.Vertex = function(source) {
ol.webgl.Shader.call(this, source); ol.webgl.Shader.call(this, source);
}; };
ol.inherits(ol.webgl.Vertex, ol.webgl.Shader); ol.inherits(ol.webgl.Vertex, ol.webgl.Shader);
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.webgl.Vertex.prototype.getType = function() { ol.webgl.Vertex.prototype.getType = function() {
return ol.webgl.VERTEX_SHADER; return ol.webgl.VERTEX_SHADER;
}; };
}