Creating a webgl.Replay struct, making the WebGL LineString renderer compilable

This commit is contained in:
GaborFarkas
2016-06-01 14:10:06 +02:00
parent f5978c659c
commit 628db9146d
3 changed files with 93 additions and 62 deletions

View File

@@ -1,6 +1,7 @@
goog.provide('ol.render.webgl.ImageReplay'); goog.provide('ol.render.webgl.ImageReplay');
goog.provide('ol.render.webgl.LineStringReplay'); goog.provide('ol.render.webgl.LineStringReplay');
goog.provide('ol.render.webgl.PolygonReplay'); goog.provide('ol.render.webgl.PolygonReplay');
goog.provide('ol.render.webgl.Replay');
goog.provide('ol.render.webgl.ReplayGroup'); goog.provide('ol.render.webgl.ReplayGroup');
goog.require('ol'); goog.require('ol');
@@ -13,6 +14,7 @@ goog.require('ol.render.VectorContext');
goog.require('ol.render.replay'); goog.require('ol.render.replay');
goog.require('ol.render.webgl.imagereplay.defaultshader'); goog.require('ol.render.webgl.imagereplay.defaultshader');
goog.require('ol.transform'); goog.require('ol.transform');
goog.require('ol.render.webgl');
goog.require('ol.render.webgl.polygonreplay.shader.Default'); goog.require('ol.render.webgl.polygonreplay.shader.Default');
goog.require('ol.render.webgl.polygonreplay.shader.Default.Locations'); goog.require('ol.render.webgl.polygonreplay.shader.Default.Locations');
goog.require('ol.render.webgl.polygonreplay.shader.DefaultFragment'); goog.require('ol.render.webgl.polygonreplay.shader.DefaultFragment');
@@ -21,8 +23,6 @@ goog.require('ol.vec.Mat4');
goog.require('ol.webgl'); goog.require('ol.webgl');
goog.require('ol.webgl.Buffer'); goog.require('ol.webgl.Buffer');
goog.require('ol.webgl.Context'); goog.require('ol.webgl.Context');
goog.require('ol.render.webgl');
/** /**
* @constructor * @constructor
@@ -36,16 +36,23 @@ ol.render.webgl.ImageReplay = function(tolerance, maxExtent) {
ol.render.VectorContext.call(this); ol.render.VectorContext.call(this);
/** /**
* @type {number|undefined} * @protected
* @private * @type {number}
*/ */
this.anchorX_ = undefined; this.tolerance = tolerance;
/** /**
* @type {number|undefined} * @protected
* @private * @const
* @type {ol.Extent}
*/ */
this.anchorY_ = undefined; this.maxExtent = maxExtent;
/**
* @private
* @type {ol.Extent}
*/
this.bufferedMaxExtent_ = null;
/** /**
* The origin of the coordinate system for the point coordinates sent to * The origin of the coordinate system for the point coordinates sent to
@@ -57,6 +64,43 @@ ol.render.webgl.ImageReplay = function(tolerance, maxExtent) {
*/ */
this.origin_ = ol.extent.getCenter(maxExtent); this.origin_ = ol.extent.getCenter(maxExtent);
/**
* @type {!goog.vec.Mat4.Number}
* @private
*/
this.projectionMatrix_ = goog.vec.Mat4.createNumberIdentity();
};
goog.inherits(ol.render.webgl.Replay, ol.render.VectorContext);
ol.render.webgl.Replay.prototype.getDeleteResourcesFunction = goog.abstractMethod;
ol.render.webgl.Replay.prototype.finish = goog.abstractMethod;
ol.render.webgl.Replay.prototype.replay = goog.abstractMethod;
/**
* @constructor
* @extends {ol.render.webgl.Replay}
* @param {number} tolerance Tolerance.
* @param {ol.Extent} maxExtent Max extent.
* @protected
* @struct
*/
ol.render.webgl.ImageReplay = function(tolerance, maxExtent) {
goog.base(this, tolerance, maxExtent);
/**
* @type {number|undefined}
* @private
*/
this.anchorX_ = undefined;
/**
* @type {number|undefined}
* @private
*/
this.anchorY_ = undefined;
/** /**
* @type {Array.<number>} * @type {Array.<number>}
* @private * @private
@@ -916,14 +960,14 @@ ol.render.webgl.ImageReplay.prototype.setImageStyle = function(imageStyle) {
/** /**
* @constructor * @constructor
* @extends {ol.render.VectorContext} * @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.
* @protected * @protected
* @struct * @struct
*/ */
ol.render.webgl.LineStringReplay = function(tolerance, maxExtent) { ol.render.webgl.LineStringReplay = function(tolerance, maxExtent) {
goog.base(this); goog.base(this, tolerance, maxExtent);
/** /**
* @private * @private
@@ -931,28 +975,12 @@ ol.render.webgl.LineStringReplay = function(tolerance, maxExtent) {
*/ */
this.strokeColor_ = undefined; this.strokeColor_ = undefined;
/**
* The origin of the coordinate system for the point coordinates sent to
* the GPU.
* @private
* @type {ol.Coordinate}
*/
this.origin_ = ol.extent.getCenter(maxExtent);
/** /**
* @private * @private
* @type {ol.render.webgl.polygonreplay.shader.Default.Locations} * @type {ol.render.webgl.polygonreplay.shader.Default.Locations}
*/ */
this.defaultLocations_ = null; this.defaultLocations_ = null;
/**
* @type {!goog.vec.Mat4.Number}
* @private
*/
this.projectionMatrix_ = goog.vec.Mat4.createNumberIdentity();
/** /**
* @type {Array.<number>} * @type {Array.<number>}
* @private * @private
@@ -965,16 +993,15 @@ ol.render.webgl.LineStringReplay = function(tolerance, maxExtent) {
*/ */
this.verticesBuffer_ = null; this.verticesBuffer_ = null;
}; };
goog.inherits(ol.render.webgl.LineStringReplay, ol.render.VectorContext); goog.inherits(ol.render.webgl.LineStringReplay, ol.render.webgl.Replay);
/** /**
* Draw one line. * Draw one line.
* @param {Array.<ol.Coordinate>} coordinates * @param {Array.<ol.Coordinate>} coordinates Coordinates.
* @private * @private
*/ */
ol.render.webgl.LineStringReplay.prototype.drawCoordinates_ = ol.render.webgl.LineStringReplay.prototype.drawCoordinates_ = function(coordinates) {
function(coordinates) {
var i, ii; var i, ii;
// Shift the indices to take into account previously handled lines // Shift the indices to take into account previously handled lines
@@ -1001,8 +1028,7 @@ ol.render.webgl.LineStringReplay.prototype.drawCoordinates_ =
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.LineStringReplay.prototype.drawLineString = ol.render.webgl.LineStringReplay.prototype.drawLineString = function(geometry, feature) {
function(geometry, feature) {
this.drawCoordinates_(geometry.getCoordinates()); this.drawCoordinates_(geometry.getCoordinates());
}; };
@@ -1010,8 +1036,7 @@ ol.render.webgl.LineStringReplay.prototype.drawLineString =
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.LineStringReplay.prototype.drawMultiLineString = ol.render.webgl.LineStringReplay.prototype.drawMultiLineString = function(geometry, feature) {
function(geometry, feature) {
var coordinatess = geometry.getCoordinates(); var coordinatess = geometry.getCoordinates();
var i, ii; var i, ii;
for (i = 0, ii = coordinatess.length; i < ii; ++i) { for (i = 0, ii = coordinatess.length; i < ii; ++i) {
@@ -1034,8 +1059,7 @@ ol.render.webgl.LineStringReplay.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.LineStringReplay.prototype.getDeleteResourcesFunction = ol.render.webgl.LineStringReplay.prototype.getDeleteResourcesFunction = function(context) {
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 LineStringReplay instances (for other layers). And // be used by other LineStringReplay 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
@@ -1143,8 +1167,7 @@ ol.render.webgl.LineStringReplay.prototype.replay = function(context,
* @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.drawReplay_ = ol.render.webgl.LineStringReplay.prototype.drawReplay_ = function(gl, context, skippedFeaturesHash) {
function(gl, context, skippedFeaturesHash) {
if (!goog.object.isEmpty(skippedFeaturesHash)) { if (!goog.object.isEmpty(skippedFeaturesHash)) {
// TODO: draw by blocks to skip features // TODO: draw by blocks to skip features
} else { } else {
@@ -1160,8 +1183,7 @@ ol.render.webgl.LineStringReplay.prototype.drawReplay_ =
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.LineStringReplay.prototype.setFillStrokeStyle = ol.render.webgl.LineStringReplay.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {
function(fillStyle, strokeStyle) {
if (strokeStyle) { if (strokeStyle) {
var strokeStyleColor = strokeStyle.getColor(); var strokeStyleColor = strokeStyle.getColor();
this.strokeColor_ = !goog.isNull(strokeStyleColor) ? this.strokeColor_ = !goog.isNull(strokeStyleColor) ?
@@ -1174,7 +1196,6 @@ ol.render.webgl.LineStringReplay.prototype.setFillStrokeStyle =
}; };
/** /**
* @constructor * @constructor
* @extends {ol.render.VectorContext} * @extends {ol.render.VectorContext}
@@ -1192,6 +1213,11 @@ ol.render.webgl.PolygonReplay = function(tolerance, maxExtent) {
*/ */
this.fillColor_ = undefined; this.fillColor_ = undefined;
/**
* @private
* @type {ol.Color|undefined}
*/
this.strokeColor_ = undefined;
/** /**
* @private * @private
@@ -1262,11 +1288,10 @@ goog.inherits(ol.render.webgl.PolygonReplay, ol.render.VectorContext);
/** /**
* Draw one polygon. * Draw one polygon.
* @param {Array.<Array.<ol.Coordinate>>} coordinates * @param {Array.<Array.<ol.Coordinate>>} coordinates Coordinates.
* @private * @private
*/ */
ol.render.webgl.PolygonReplay.prototype.drawCoordinates_ = ol.render.webgl.PolygonReplay.prototype.drawCoordinates_ = function(coordinates) {
function(coordinates) {
// Triangulate the polgon // Triangulate the polgon
var triangulation = ol.ext.earcut(coordinates, true); var triangulation = ol.ext.earcut(coordinates, true);
var i, ii; var i, ii;
@@ -1295,8 +1320,7 @@ ol.render.webgl.PolygonReplay.prototype.drawCoordinates_ =
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.PolygonReplay.prototype.drawMultiPolygon = ol.render.webgl.PolygonReplay.prototype.drawMultiPolygon = function(geometry, feature) {
function(geometry, feature) {
if (goog.isNull(this.fillColor_)) { if (goog.isNull(this.fillColor_)) {
return; return;
} }
@@ -1313,8 +1337,7 @@ ol.render.webgl.PolygonReplay.prototype.drawMultiPolygon =
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.PolygonReplay.prototype.drawPolygon = ol.render.webgl.PolygonReplay.prototype.drawPolygon = function(polygonGeometry, feature) {
function(polygonGeometry, feature) {
if (goog.isNull(this.fillColor_)) { if (goog.isNull(this.fillColor_)) {
return; return;
} }
@@ -1358,8 +1381,7 @@ ol.render.webgl.PolygonReplay.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.PolygonReplay.prototype.getDeleteResourcesFunction = ol.render.webgl.PolygonReplay.prototype.getDeleteResourcesFunction = function(context) {
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 PolygonReplay instances (for other layers). And // be used by other PolygonReplay 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
@@ -1483,8 +1505,7 @@ ol.render.webgl.PolygonReplay.prototype.replay = function(context,
* @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.drawReplay_ = ol.render.webgl.PolygonReplay.prototype.drawReplay_ = function(gl, context, skippedFeaturesHash) {
function(gl, context, skippedFeaturesHash) {
var elementType = context.hasOESElementIndexUint ? var elementType = context.hasOESElementIndexUint ?
goog.webgl.UNSIGNED_INT : goog.webgl.UNSIGNED_SHORT; goog.webgl.UNSIGNED_INT : goog.webgl.UNSIGNED_SHORT;
// var elementSize = context.hasOESElementIndexUint ? 4 : 2; // var elementSize = context.hasOESElementIndexUint ? 4 : 2;
@@ -1502,8 +1523,7 @@ ol.render.webgl.PolygonReplay.prototype.drawReplay_ =
* @inheritDoc * @inheritDoc
*/ */
ol.render.webgl.PolygonReplay.prototype.setFillStrokeStyle = ol.render.webgl.PolygonReplay.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {
function(fillStyle, strokeStyle) {
// TODO implement // TODO implement
if (fillStyle) { if (fillStyle) {
var fillStyleColor = fillStyle.getColor(); var fillStyleColor = fillStyle.getColor();
@@ -1514,11 +1534,19 @@ ol.render.webgl.PolygonReplay.prototype.setFillStrokeStyle =
} else { } else {
this.fillColor_ = undefined; this.fillColor_ = undefined;
} }
if (strokeStyle) {
var strokeStyleColor = strokeStyle.getColor();
this.strokeColor_ = !goog.isNull(strokeStyleColor) ?
ol.color.asArray(strokeStyleColor).map(function(c, i) {
return i != 3 ? c / 255 : c;
}) : ol.render.webgl.defaultStrokeStyle;
} else {
this.strokeColor_ = undefined;
}
this.lineStringReplay_.setFillStrokeStyle(fillStyle, strokeStyle); this.lineStringReplay_.setFillStrokeStyle(fillStyle, strokeStyle);
}; };
/** /**
* @constructor * @constructor
* @extends {ol.render.ReplayGroup} * @extends {ol.render.ReplayGroup}
@@ -1550,7 +1578,7 @@ ol.render.webgl.ReplayGroup = function(tolerance, maxExtent, opt_renderBuffer) {
/** /**
* ImageReplay only is supported at this point. * ImageReplay only is supported at this point.
* @type {Object.<ol.render.ReplayType, ol.render.webgl.ImageReplay>} * @type {Object.<ol.render.ReplayType, ol.render.webgl.Replay>}
* @private * @private
*/ */
this.replays_ = {}; this.replays_ = {};
@@ -1776,13 +1804,13 @@ ol.render.webgl.ReplayGroup.prototype.hasFeatureAtCoordinate = function(
* @const * @const
* @private * @private
* @type {Object.<ol.render.ReplayType, * @type {Object.<ol.render.ReplayType,
* function(new: ol.render.webgl.ImageReplay, number, * function(new: ol.render.webgl.Replay, number,
* ol.Extent)>} * ol.Extent)>}
*/ */
ol.render.webgl.BATCH_CONSTRUCTORS_ = { ol.render.webgl.BATCH_CONSTRUCTORS_ = {
'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
}; };

View File

@@ -11,3 +11,9 @@ ol.render.webgl.defaultFillStyle = [0.0, 0.0, 0.0, 1.0];
* @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
* @type {number}
*/
ol.render.webgl.defaultLineWidth = 1;

View File

@@ -7,7 +7,6 @@ goog.provide('ol.render.webgl.polygonreplay.shader.DefaultVertex');
goog.require('ol.webgl.shader'); goog.require('ol.webgl.shader');
/** /**
* @constructor * @constructor
* @extends {ol.webgl.shader.Fragment} * @extends {ol.webgl.shader.Fragment}
@@ -43,7 +42,6 @@ ol.render.webgl.polygonreplay.shader.DefaultFragment.SOURCE = goog.DEBUG ?
ol.render.webgl.polygonreplay.shader.DefaultFragment.OPTIMIZED_SOURCE; ol.render.webgl.polygonreplay.shader.DefaultFragment.OPTIMIZED_SOURCE;
/** /**
* @constructor * @constructor
* @extends {ol.webgl.shader.Vertex} * @extends {ol.webgl.shader.Vertex}
@@ -79,7 +77,6 @@ ol.render.webgl.polygonreplay.shader.DefaultVertex.SOURCE = goog.DEBUG ?
ol.render.webgl.polygonreplay.shader.DefaultVertex.OPTIMIZED_SOURCE; ol.render.webgl.polygonreplay.shader.DefaultVertex.OPTIMIZED_SOURCE;
/** /**
* @constructor * @constructor
* @param {WebGLRenderingContext} gl GL. * @param {WebGLRenderingContext} gl GL.