Add line string rendering
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
//! NAMESPACE=ol.renderer.webgl.vectorlayer2.shader.LineStringCollection
|
||||
//! CLASS=ol.renderer.webgl.vectorlayer2.shader.LineStringCollection
|
||||
|
||||
|
||||
//! VERTEX
|
||||
attribute vec2 a_position;
|
||||
uniform mat4 u_modelViewMatrix;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = u_modelViewMatrix * vec4(a_position, 0., 1.);
|
||||
}
|
||||
|
||||
|
||||
//! FRAGMENT
|
||||
uniform vec4 u_color;
|
||||
|
||||
void main(void) {
|
||||
gl_FragColor = u_color;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// This file is automatically generated, do not edit
|
||||
goog.provide('ol.renderer.webgl.vectorlayer2.shader.LineStringCollection');
|
||||
goog.require('ol.webgl.shader');
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.webgl.shader.Fragment}
|
||||
*/
|
||||
ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionFragment = function() {
|
||||
goog.base(this, ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionFragment.SOURCE);
|
||||
};
|
||||
goog.inherits(ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionFragment, ol.webgl.shader.Fragment);
|
||||
goog.addSingletonGetter(ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionFragment);
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionFragment.DEBUG_SOURCE = 'precision mediump float;\n//! NAMESPACE=ol.renderer.webgl.vectorlayer2.shader.LineStringCollection\n//! CLASS=ol.renderer.webgl.vectorlayer2.shader.LineStringCollection\n\n\n//! FRAGMENT\nuniform vec4 u_color;\n\nvoid main(void) {\n gl_FragColor = u_color;\n}\n\n';
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionFragment.OPTIMIZED_SOURCE = 'precision mediump float;uniform vec4 b;void main(){gl_FragColor=b;}';
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionFragment.SOURCE = goog.DEBUG ?
|
||||
ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionFragment.DEBUG_SOURCE :
|
||||
ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionFragment.OPTIMIZED_SOURCE;
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.webgl.shader.Vertex}
|
||||
*/
|
||||
ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionVertex = function() {
|
||||
goog.base(this, ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionVertex.SOURCE);
|
||||
};
|
||||
goog.inherits(ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionVertex, ol.webgl.shader.Vertex);
|
||||
goog.addSingletonGetter(ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionVertex);
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionVertex.DEBUG_SOURCE = '//! NAMESPACE=ol.renderer.webgl.vectorlayer2.shader.LineStringCollection\n//! CLASS=ol.renderer.webgl.vectorlayer2.shader.LineStringCollection\n\n\n//! VERTEX\nattribute vec2 a_position;\nuniform mat4 u_modelViewMatrix;\n\nvoid main(void) {\n gl_Position = u_modelViewMatrix * vec4(a_position, 0., 1.);\n}\n\n\n';
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionVertex.OPTIMIZED_SOURCE = 'attribute vec2 b;uniform mat4 a;void main(){gl_Position=a*vec4(b,0,1);}';
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionVertex.SOURCE = goog.DEBUG ?
|
||||
ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionVertex.DEBUG_SOURCE :
|
||||
ol.renderer.webgl.vectorlayer2.shader.LineStringCollectionVertex.OPTIMIZED_SOURCE;
|
||||
/**
|
||||
* @constructor
|
||||
* @param {WebGLRenderingContext} gl GL.
|
||||
* @param {WebGLProgram} program Program.
|
||||
*/
|
||||
ol.renderer.webgl.vectorlayer2.shader.LineStringCollection.Locations = function(gl, program) {
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_modelViewMatrix = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_modelViewMatrix' : 'a');
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_color = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_color' : 'b');
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.a_position = gl.getAttribLocation(
|
||||
program, goog.DEBUG ? 'a_position' : 'b');
|
||||
};
|
||||
@@ -4,6 +4,7 @@ goog.require('goog.vec.Mat4');
|
||||
goog.require('goog.webgl');
|
||||
goog.require('ol.math');
|
||||
goog.require('ol.renderer.webgl.Layer');
|
||||
goog.require('ol.renderer.webgl.vectorlayer2.shader.LineStringCollection');
|
||||
goog.require('ol.renderer.webgl.vectorlayer2.shader.PointCollection');
|
||||
|
||||
|
||||
@@ -26,6 +27,13 @@ ol.renderer.webgl.VectorLayer2 = function(mapRenderer, vectorLayer2) {
|
||||
*/
|
||||
this.modelViewMatrix_ = goog.vec.Mat4.createNumberIdentity();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type
|
||||
* {ol.renderer.webgl.vectorlayer2.shader.LineStringCollection.Locations}
|
||||
*/
|
||||
this.lineStringCollectionLocations_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.renderer.webgl.vectorlayer2.shader.PointCollection.Locations}
|
||||
@@ -95,6 +103,10 @@ ol.renderer.webgl.VectorLayer2.prototype.renderFrame =
|
||||
if (pointCollections.length > 0) {
|
||||
this.renderPointCollections(pointCollections);
|
||||
}
|
||||
var lineStringCollections = vectorSource.getLineStringCollections();
|
||||
if (lineStringCollections.length > 0) {
|
||||
this.renderLineStringCollections(lineStringCollections);
|
||||
}
|
||||
|
||||
goog.vec.Mat4.makeIdentity(this.texCoordMatrix);
|
||||
goog.vec.Mat4.translate(this.texCoordMatrix,
|
||||
@@ -113,6 +125,49 @@ ol.renderer.webgl.VectorLayer2.prototype.renderFrame =
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<ol.geom2.LineStringCollection>} lineStringCollections Line
|
||||
* string collections.
|
||||
*/
|
||||
ol.renderer.webgl.VectorLayer2.prototype.renderLineStringCollections =
|
||||
function(lineStringCollections) {
|
||||
|
||||
var mapRenderer = this.getWebGLMapRenderer();
|
||||
var gl = mapRenderer.getGL();
|
||||
|
||||
var fragmentShader = ol.renderer.webgl.vectorlayer2.shader.
|
||||
LineStringCollectionFragment.getInstance();
|
||||
var vertexShader = ol.renderer.webgl.vectorlayer2.shader.
|
||||
LineStringCollectionVertex.getInstance();
|
||||
var program = mapRenderer.getProgram(fragmentShader, vertexShader);
|
||||
gl.useProgram(program);
|
||||
if (goog.isNull(this.lineStringCollectionLocations_)) {
|
||||
this.lineStringCollectionLocations_ =
|
||||
new ol.renderer.webgl.vectorlayer2.shader.LineStringCollection.
|
||||
Locations(gl, program);
|
||||
}
|
||||
|
||||
gl.uniformMatrix4fv(this.lineStringCollectionLocations_.u_modelViewMatrix,
|
||||
false, this.modelViewMatrix_);
|
||||
|
||||
var buf, dim, i, lineStringCollection;
|
||||
for (i = 0; i < lineStringCollections.length; ++i) {
|
||||
lineStringCollection = lineStringCollections[i];
|
||||
buf = lineStringCollection.buf;
|
||||
dim = lineStringCollection.dim;
|
||||
mapRenderer.bindBuffer(goog.webgl.ARRAY_BUFFER, buf);
|
||||
gl.enableVertexAttribArray(this.lineStringCollectionLocations_.a_position);
|
||||
gl.vertexAttribPointer(this.lineStringCollectionLocations_.a_position, 2,
|
||||
goog.webgl.FLOAT, false, 4 * dim, 0);
|
||||
gl.uniform4fv(this.lineStringCollectionLocations_.u_color, [1, 1, 0, 0.75]);
|
||||
buf.forEachRange(function(start, stop) {
|
||||
gl.drawArrays(goog.webgl.LINES, start / dim, (stop - start) / dim);
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<ol.geom2.PointCollection>} pointCollections Point collections.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user