Restructure webgl replays
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
//! NAMESPACE=ol.render.webgl.linestringreplay.shader.Default
|
||||
//! CLASS=ol.render.webgl.linestringreplay.shader.Default
|
||||
//! NAMESPACE=ol.render.webgl.linestringreplay.defaultshader
|
||||
//! CLASS=ol.render.webgl.linestringreplay.defaultshader
|
||||
|
||||
|
||||
//! COMMON
|
||||
@@ -1,80 +1,83 @@
|
||||
// This file is automatically generated, do not edit
|
||||
goog.provide('ol.render.webgl.linestringreplay.shader.Default');
|
||||
goog.provide('ol.render.webgl.linestringreplay.shader.Default.Locations');
|
||||
goog.provide('ol.render.webgl.linestringreplay.shader.DefaultFragment');
|
||||
goog.provide('ol.render.webgl.linestringreplay.shader.DefaultVertex');
|
||||
goog.provide('ol.render.webgl.linestringreplay.defaultshader');
|
||||
|
||||
goog.require('ol.webgl.shader');
|
||||
goog.require('ol');
|
||||
goog.require('ol.webgl.Fragment');
|
||||
goog.require('ol.webgl.Vertex');
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.webgl.shader.Fragment}
|
||||
* @extends {ol.webgl.Fragment}
|
||||
* @struct
|
||||
*/
|
||||
ol.render.webgl.linestringreplay.shader.DefaultFragment = function() {
|
||||
ol.webgl.shader.Fragment.call(this, ol.render.webgl.linestringreplay.shader.DefaultFragment.SOURCE);
|
||||
ol.render.webgl.linestringreplay.defaultshader.Fragment = function() {
|
||||
ol.webgl.Fragment.call(this, ol.render.webgl.linestringreplay.defaultshader.Fragment.SOURCE);
|
||||
};
|
||||
ol.inherits(ol.render.webgl.linestringreplay.shader.DefaultFragment, ol.webgl.shader.Fragment);
|
||||
goog.addSingletonGetter(ol.render.webgl.linestringreplay.shader.DefaultFragment);
|
||||
ol.inherits(ol.render.webgl.linestringreplay.defaultshader.Fragment, ol.webgl.Fragment);
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.render.webgl.linestringreplay.shader.DefaultFragment.DEBUG_SOURCE = 'precision mediump float;\nvarying float v_round;\nvarying vec2 v_roundVertex;\nvarying float v_halfWidth;\n\n\n\nuniform float u_opacity;\nuniform vec4 u_color;\nuniform vec2 u_size;\nuniform float u_pixelRatio;\n\nvoid main(void) {\n if (v_round > 0.0) {\n vec2 windowCoords = vec2((v_roundVertex.x + 1.0) / 2.0 * u_size.x * u_pixelRatio,\n (v_roundVertex.y + 1.0) / 2.0 * u_size.y * u_pixelRatio);\n if (length(windowCoords - gl_FragCoord.xy) > v_halfWidth * u_pixelRatio) {\n discard;\n }\n }\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.linestringreplay.defaultshader.Fragment.DEBUG_SOURCE = 'precision mediump float;\nvarying float v_round;\nvarying vec2 v_roundVertex;\nvarying float v_halfWidth;\n\n\n\nuniform float u_opacity;\nuniform vec4 u_color;\nuniform vec2 u_size;\nuniform float u_pixelRatio;\n\nvoid main(void) {\n if (v_round > 0.0) {\n vec2 windowCoords = vec2((v_roundVertex.x + 1.0) / 2.0 * u_size.x * u_pixelRatio,\n (v_roundVertex.y + 1.0) / 2.0 * u_size.y * u_pixelRatio);\n if (length(windowCoords - gl_FragCoord.xy) > v_halfWidth * u_pixelRatio) {\n discard;\n }\n }\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
|
||||
* @type {string}
|
||||
*/
|
||||
ol.render.webgl.linestringreplay.shader.DefaultFragment.OPTIMIZED_SOURCE = 'precision mediump float;varying float a;varying vec2 b;varying float c;uniform float l;uniform vec4 m;uniform vec2 n;uniform float o;void main(void){if(a>0.0){vec2 windowCoords=vec2((b.x+1.0)/2.0*n.x*o,(b.y+1.0)/2.0*n.y*o);if(length(windowCoords-gl_FragCoord.xy)>c*o){discard;}} gl_FragColor=m;float alpha=m.a*l;if(alpha==0.0){discard;}gl_FragColor.a=alpha;}';
|
||||
ol.render.webgl.linestringreplay.defaultshader.Fragment.OPTIMIZED_SOURCE = 'precision mediump float;varying float a;varying vec2 b;varying float c;uniform float l;uniform vec4 m;uniform vec2 n;uniform float o;void main(void){if(a>0.0){vec2 windowCoords=vec2((b.x+1.0)/2.0*n.x*o,(b.y+1.0)/2.0*n.y*o);if(length(windowCoords-gl_FragCoord.xy)>c*o){discard;}} gl_FragColor=m;float alpha=m.a*l;if(alpha==0.0){discard;}gl_FragColor.a=alpha;}';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.render.webgl.linestringreplay.shader.DefaultFragment.SOURCE = goog.DEBUG ?
|
||||
ol.render.webgl.linestringreplay.shader.DefaultFragment.DEBUG_SOURCE :
|
||||
ol.render.webgl.linestringreplay.shader.DefaultFragment.OPTIMIZED_SOURCE;
|
||||
ol.render.webgl.linestringreplay.defaultshader.Fragment.SOURCE = ol.DEBUG ?
|
||||
ol.render.webgl.linestringreplay.defaultshader.Fragment.DEBUG_SOURCE :
|
||||
ol.render.webgl.linestringreplay.defaultshader.Fragment.OPTIMIZED_SOURCE;
|
||||
|
||||
|
||||
ol.render.webgl.linestringreplay.defaultshader.fragment = new ol.render.webgl.linestringreplay.defaultshader.Fragment();
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.webgl.shader.Vertex}
|
||||
* @extends {ol.webgl.Vertex}
|
||||
* @struct
|
||||
*/
|
||||
ol.render.webgl.linestringreplay.shader.DefaultVertex = function() {
|
||||
ol.webgl.shader.Vertex.call(this, ol.render.webgl.linestringreplay.shader.DefaultVertex.SOURCE);
|
||||
ol.render.webgl.linestringreplay.defaultshader.Vertex = function() {
|
||||
ol.webgl.Vertex.call(this, ol.render.webgl.linestringreplay.defaultshader.Vertex.SOURCE);
|
||||
};
|
||||
ol.inherits(ol.render.webgl.linestringreplay.shader.DefaultVertex, ol.webgl.shader.Vertex);
|
||||
goog.addSingletonGetter(ol.render.webgl.linestringreplay.shader.DefaultVertex);
|
||||
ol.inherits(ol.render.webgl.linestringreplay.defaultshader.Vertex, ol.webgl.Vertex);
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.render.webgl.linestringreplay.shader.DefaultVertex.DEBUG_SOURCE = 'varying float v_round;\nvarying vec2 v_roundVertex;\nvarying float v_halfWidth;\n\n\nattribute vec2 a_lastPos;\nattribute vec2 a_position;\nattribute vec2 a_nextPos;\nattribute float a_direction;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform float u_lineWidth;\nuniform float u_miterLimit;\n\nvoid main(void) {\n bool degenerate = false;\n v_halfWidth = u_lineWidth / 2.0;\n float miterLimit = u_miterLimit + u_lineWidth;\n vec2 offset;\n v_round = 0.0;\n float direction = a_direction / abs(a_direction);\n vec4 projPos = u_projectionMatrix * vec4(a_position, 0., 1.);\n v_roundVertex = projPos.xy;\n if (mod(a_direction, 3.0) == 0.0 || mod(a_direction, 17.0) == 0.0) {\n vec2 dirVect = a_nextPos - a_position;\n vec2 normal = normalize(vec2(-dirVect.y, dirVect.x));\n offset = v_halfWidth * normal * direction;\n } else if (mod(a_direction, 5.0) == 0.0 || mod(a_direction, 13.0) == 0.0) {\n vec2 dirVect = a_lastPos - a_position;\n vec2 normal = normalize(vec2(dirVect.y, -dirVect.x));\n offset = v_halfWidth * normal * direction;\n } else if (mod(a_direction, 19.0) == 0.0 || mod(a_direction, 23.0) == 0.0) {\n vec2 dirVect = a_nextPos - a_position;\n vec2 tmpNormal = normalize(vec2(-dirVect.y, dirVect.x));\n vec2 tangent = normalize(normalize(a_nextPos - a_position) + normalize(a_position - a_lastPos));\n vec2 normal = vec2(-tangent.y, tangent.x);\n float miterLength = abs(v_halfWidth / dot(normal, tmpNormal));\n if (mod(a_direction, 23.0) == 0.0) {\n offset = normal * direction * miterLength;\n if (mod(a_direction, 2.0) == 0.0) {\n v_round = 1.0;\n } else if (miterLength > miterLimit) {\n offset = tmpNormal * direction * v_halfWidth;\n }\n } else {\n dirVect = a_lastPos - a_position;\n vec2 longOffset, shortOffset, longVertex;\n vec4 shortProjVertex;\n if (length(a_nextPos - a_position) > length(a_lastPos - a_position)) {\n longOffset = tmpNormal * direction * v_halfWidth;\n shortOffset = normalize(vec2(dirVect.y, -dirVect.x)) * direction * v_halfWidth;\n longVertex = a_nextPos;\n shortProjVertex = u_projectionMatrix * vec4(a_lastPos, 0., 1.);\n } else {\n shortOffset = tmpNormal * direction * v_halfWidth;\n longOffset = normalize(vec2(dirVect.y, -dirVect.x)) * direction * v_halfWidth;\n longVertex = a_lastPos;\n shortProjVertex = u_projectionMatrix * vec4(a_nextPos, 0., 1.);\n }\n //Intersection algorithm based on theory by Paul Bourke (http://paulbourke.net/geometry/pointlineplane/).\n vec4 p1 = u_projectionMatrix * vec4(longVertex, 0., 1.) + u_offsetScaleMatrix * vec4(longOffset, 0., 0.);\n vec4 p2 = projPos + u_offsetScaleMatrix * vec4(longOffset, 0., 0.);\n vec4 p3 = shortProjVertex + u_offsetScaleMatrix * vec4(-shortOffset, 0., 0.);\n vec4 p4 = shortProjVertex + u_offsetScaleMatrix * vec4(shortOffset, 0., 0.);\n float denom = (p4.y - p3.y) * (p2.x - p1.x) - (p4.x - p3.x) * (p2.y - p1.y);\n float epsilon = 0.000000000001;\n float firstU = ((p4.x - p3.x) * (p1.y - p3.y) - (p4.y - p3.y) * (p1.x - p3.x)) / denom;\n float secondU = ((p2.x - p1.x) * (p1.y - p3.y) - (p2.y - p1.y) * (p1.x - p3.x)) / denom;\n if (firstU > epsilon && firstU < 1.0 - epsilon && secondU > epsilon && secondU < 1.0 - epsilon) {\n gl_Position = shortProjVertex;\n gl_Position.x = p1.x + firstU * (p2.x - p1.x);\n gl_Position.y = p1.y + firstU * (p2.y - p1.y);\n degenerate = true;\n } else {\n offset = normal * direction * miterLength;\n }\n }\n } else if (mod(a_direction, 7.0) == 0.0 || mod(a_direction, 11.0) == 0.0) {\n vec2 normal;\n if (mod(a_direction, 7.0) == 0.0) {\n vec2 dirVect = a_position - a_nextPos;\n vec2 firstNormal = normalize(dirVect);\n vec2 secondNormal = vec2(firstNormal.y * direction, -firstNormal.x * direction);\n vec2 hypotenuse = normalize(firstNormal - secondNormal);\n normal = vec2(hypotenuse.y * direction, -hypotenuse.x * direction);\n } else {\n vec2 dirVect = a_position - a_lastPos;\n vec2 firstNormal = normalize(dirVect);\n vec2 secondNormal = vec2(-firstNormal.y * direction, firstNormal.x * direction);\n vec2 hypotenuse = normalize(firstNormal - secondNormal);\n normal = vec2(-hypotenuse.y * direction, hypotenuse.x * direction);\n }\n float length = sqrt(v_halfWidth * v_halfWidth * 2.0);\n offset = normal * length;\n if (mod(a_direction, 2.0) == 0.0) {\n v_round = 1.0;\n }\n }\n if (!degenerate) {\n vec4 offsets = u_offsetScaleMatrix * vec4(offset, 0., 0.);\n gl_Position = projPos + offsets;\n }\n}\n\n\n';
|
||||
ol.render.webgl.linestringreplay.defaultshader.Vertex.DEBUG_SOURCE = 'varying float v_round;\nvarying vec2 v_roundVertex;\nvarying float v_halfWidth;\n\n\nattribute vec2 a_lastPos;\nattribute vec2 a_position;\nattribute vec2 a_nextPos;\nattribute float a_direction;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform float u_lineWidth;\nuniform float u_miterLimit;\n\nvoid main(void) {\n bool degenerate = false;\n v_halfWidth = u_lineWidth / 2.0;\n float miterLimit = u_miterLimit + u_lineWidth;\n vec2 offset;\n v_round = 0.0;\n float direction = a_direction / abs(a_direction);\n vec4 projPos = u_projectionMatrix * vec4(a_position, 0., 1.);\n v_roundVertex = projPos.xy;\n if (mod(a_direction, 3.0) == 0.0 || mod(a_direction, 17.0) == 0.0) {\n vec2 dirVect = a_nextPos - a_position;\n vec2 normal = normalize(vec2(-dirVect.y, dirVect.x));\n offset = v_halfWidth * normal * direction;\n } else if (mod(a_direction, 5.0) == 0.0 || mod(a_direction, 13.0) == 0.0) {\n vec2 dirVect = a_lastPos - a_position;\n vec2 normal = normalize(vec2(dirVect.y, -dirVect.x));\n offset = v_halfWidth * normal * direction;\n } else if (mod(a_direction, 19.0) == 0.0 || mod(a_direction, 23.0) == 0.0) {\n vec2 dirVect = a_nextPos - a_position;\n vec2 tmpNormal = normalize(vec2(-dirVect.y, dirVect.x));\n vec2 tangent = normalize(normalize(a_nextPos - a_position) + normalize(a_position - a_lastPos));\n vec2 normal = vec2(-tangent.y, tangent.x);\n float miterLength = abs(v_halfWidth / dot(normal, tmpNormal));\n if (mod(a_direction, 23.0) == 0.0) {\n offset = normal * direction * miterLength;\n if (mod(a_direction, 2.0) == 0.0) {\n v_round = 1.0;\n } else if (miterLength > miterLimit) {\n offset = tmpNormal * direction * v_halfWidth;\n }\n } else {\n dirVect = a_lastPos - a_position;\n vec2 longOffset, shortOffset, longVertex;\n vec4 shortProjVertex;\n if (length(a_nextPos - a_position) > length(a_lastPos - a_position)) {\n longOffset = tmpNormal * direction * v_halfWidth;\n shortOffset = normalize(vec2(dirVect.y, -dirVect.x)) * direction * v_halfWidth;\n longVertex = a_nextPos;\n shortProjVertex = u_projectionMatrix * vec4(a_lastPos, 0., 1.);\n } else {\n shortOffset = tmpNormal * direction * v_halfWidth;\n longOffset = normalize(vec2(dirVect.y, -dirVect.x)) * direction * v_halfWidth;\n longVertex = a_lastPos;\n shortProjVertex = u_projectionMatrix * vec4(a_nextPos, 0., 1.);\n }\n //Intersection algorithm based on theory by Paul Bourke (http://paulbourke.net/geometry/pointlineplane/).\n vec4 p1 = u_projectionMatrix * vec4(longVertex, 0., 1.) + u_offsetScaleMatrix * vec4(longOffset, 0., 0.);\n vec4 p2 = projPos + u_offsetScaleMatrix * vec4(longOffset, 0., 0.);\n vec4 p3 = shortProjVertex + u_offsetScaleMatrix * vec4(-shortOffset, 0., 0.);\n vec4 p4 = shortProjVertex + u_offsetScaleMatrix * vec4(shortOffset, 0., 0.);\n float denom = (p4.y - p3.y) * (p2.x - p1.x) - (p4.x - p3.x) * (p2.y - p1.y);\n float epsilon = 0.000000000001;\n float firstU = ((p4.x - p3.x) * (p1.y - p3.y) - (p4.y - p3.y) * (p1.x - p3.x)) / denom;\n float secondU = ((p2.x - p1.x) * (p1.y - p3.y) - (p2.y - p1.y) * (p1.x - p3.x)) / denom;\n if (firstU > epsilon && firstU < 1.0 - epsilon && secondU > epsilon && secondU < 1.0 - epsilon) {\n gl_Position = shortProjVertex;\n gl_Position.x = p1.x + firstU * (p2.x - p1.x);\n gl_Position.y = p1.y + firstU * (p2.y - p1.y);\n degenerate = true;\n } else {\n offset = normal * direction * miterLength;\n }\n }\n } else if (mod(a_direction, 7.0) == 0.0 || mod(a_direction, 11.0) == 0.0) {\n vec2 normal;\n if (mod(a_direction, 7.0) == 0.0) {\n vec2 dirVect = a_position - a_nextPos;\n vec2 firstNormal = normalize(dirVect);\n vec2 secondNormal = vec2(firstNormal.y * direction, -firstNormal.x * direction);\n vec2 hypotenuse = normalize(firstNormal - secondNormal);\n normal = vec2(hypotenuse.y * direction, -hypotenuse.x * direction);\n } else {\n vec2 dirVect = a_position - a_lastPos;\n vec2 firstNormal = normalize(dirVect);\n vec2 secondNormal = vec2(-firstNormal.y * direction, firstNormal.x * direction);\n vec2 hypotenuse = normalize(firstNormal - secondNormal);\n normal = vec2(-hypotenuse.y * direction, hypotenuse.x * direction);\n }\n float length = sqrt(v_halfWidth * v_halfWidth * 2.0);\n offset = normal * length;\n if (mod(a_direction, 2.0) == 0.0) {\n v_round = 1.0;\n }\n }\n if (!degenerate) {\n vec4 offsets = u_offsetScaleMatrix * vec4(offset, 0., 0.);\n gl_Position = projPos + offsets;\n }\n}\n\n\n';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.render.webgl.linestringreplay.shader.DefaultVertex.OPTIMIZED_SOURCE = 'varying float a;varying vec2 b;varying float c;attribute vec2 d;attribute vec2 e;attribute vec2 f;attribute float g;uniform mat4 h;uniform mat4 i;uniform float j;uniform float k;void main(void){bool degenerate=false;c=j/2.0;float miterLimit=k+j;vec2 offset;a=0.0;float direction=g/abs(g);vec4 projPos=h*vec4(e,0.,1.);b=projPos.xy;if(mod(g,3.0)==0.0||mod(g,17.0)==0.0){vec2 dirVect=f-e;vec2 normal=normalize(vec2(-dirVect.y,dirVect.x));offset=c*normal*direction;}else if(mod(g,5.0)==0.0||mod(g,13.0)==0.0){vec2 dirVect=d-e;vec2 normal=normalize(vec2(dirVect.y,-dirVect.x));offset=c*normal*direction;}else if(mod(g,19.0)==0.0||mod(g,23.0)==0.0){vec2 dirVect=f-e;vec2 tmpNormal=normalize(vec2(-dirVect.y,dirVect.x));vec2 tangent=normalize(normalize(f-e)+normalize(e-d));vec2 normal=vec2(-tangent.y,tangent.x);float miterLength=abs(c/dot(normal,tmpNormal));if(mod(g,23.0)==0.0){offset=normal*direction*miterLength;if(mod(g,2.0)==0.0){a=1.0;}else if(miterLength>miterLimit){offset=tmpNormal*direction*c;}} else{dirVect=d-e;vec2 longOffset,shortOffset,longVertex;vec4 shortProjVertex;if(length(f-e)>length(d-e)){longOffset=tmpNormal*direction*c;shortOffset=normalize(vec2(dirVect.y,-dirVect.x))*direction*c;longVertex=f;shortProjVertex=h*vec4(d,0.,1.);}else{shortOffset=tmpNormal*direction*c;longOffset=normalize(vec2(dirVect.y,-dirVect.x))*direction*c;longVertex=d;shortProjVertex=h*vec4(f,0.,1.);}vec4 p1=h*vec4(longVertex,0.,1.)+i*vec4(longOffset,0.,0.);vec4 p2=projPos+i*vec4(longOffset,0.,0.);vec4 p3=shortProjVertex+i*vec4(-shortOffset,0.,0.);vec4 p4=shortProjVertex+i*vec4(shortOffset,0.,0.);float denom=(p4.y-p3.y)*(p2.x-p1.x)-(p4.x-p3.x)*(p2.y-p1.y);float epsilon=0.000000000001;float firstU=((p4.x-p3.x)*(p1.y-p3.y)-(p4.y-p3.y)*(p1.x-p3.x))/denom;float secondU=((p2.x-p1.x)*(p1.y-p3.y)-(p2.y-p1.y)*(p1.x-p3.x))/denom;if(firstU>epsilon&&firstU<1.0-epsilon&&secondU>epsilon&&secondU<1.0-epsilon){gl_Position=shortProjVertex;gl_Position.x=p1.x+firstU*(p2.x-p1.x);gl_Position.y=p1.y+firstU*(p2.y-p1.y);degenerate=true;}else{offset=normal*direction*miterLength;}}}else if(mod(g,7.0)==0.0||mod(g,11.0)==0.0){vec2 normal;if(mod(g,7.0)==0.0){vec2 dirVect=e-f;vec2 firstNormal=normalize(dirVect);vec2 secondNormal=vec2(firstNormal.y*direction,-firstNormal.x*direction);vec2 hypotenuse=normalize(firstNormal-secondNormal);normal=vec2(hypotenuse.y*direction,-hypotenuse.x*direction);}else{vec2 dirVect=e-d;vec2 firstNormal=normalize(dirVect);vec2 secondNormal=vec2(-firstNormal.y*direction,firstNormal.x*direction);vec2 hypotenuse=normalize(firstNormal-secondNormal);normal=vec2(-hypotenuse.y*direction,hypotenuse.x*direction);}float length=sqrt(c*c*2.0);offset=normal*length;if(mod(g,2.0)==0.0){a=1.0;}} if(!degenerate){vec4 offsets=i*vec4(offset,0.,0.);gl_Position=projPos+offsets;}}';
|
||||
ol.render.webgl.linestringreplay.defaultshader.Vertex.OPTIMIZED_SOURCE = 'varying float a;varying vec2 b;varying float c;attribute vec2 d;attribute vec2 e;attribute vec2 f;attribute float g;uniform mat4 h;uniform mat4 i;uniform float j;uniform float k;void main(void){bool degenerate=false;c=j/2.0;float miterLimit=k+j;vec2 offset;a=0.0;float direction=g/abs(g);vec4 projPos=h*vec4(e,0.,1.);b=projPos.xy;if(mod(g,3.0)==0.0||mod(g,17.0)==0.0){vec2 dirVect=f-e;vec2 normal=normalize(vec2(-dirVect.y,dirVect.x));offset=c*normal*direction;}else if(mod(g,5.0)==0.0||mod(g,13.0)==0.0){vec2 dirVect=d-e;vec2 normal=normalize(vec2(dirVect.y,-dirVect.x));offset=c*normal*direction;}else if(mod(g,19.0)==0.0||mod(g,23.0)==0.0){vec2 dirVect=f-e;vec2 tmpNormal=normalize(vec2(-dirVect.y,dirVect.x));vec2 tangent=normalize(normalize(f-e)+normalize(e-d));vec2 normal=vec2(-tangent.y,tangent.x);float miterLength=abs(c/dot(normal,tmpNormal));if(mod(g,23.0)==0.0){offset=normal*direction*miterLength;if(mod(g,2.0)==0.0){a=1.0;}else if(miterLength>miterLimit){offset=tmpNormal*direction*c;}} else{dirVect=d-e;vec2 longOffset,shortOffset,longVertex;vec4 shortProjVertex;if(length(f-e)>length(d-e)){longOffset=tmpNormal*direction*c;shortOffset=normalize(vec2(dirVect.y,-dirVect.x))*direction*c;longVertex=f;shortProjVertex=h*vec4(d,0.,1.);}else{shortOffset=tmpNormal*direction*c;longOffset=normalize(vec2(dirVect.y,-dirVect.x))*direction*c;longVertex=d;shortProjVertex=h*vec4(f,0.,1.);}vec4 p1=h*vec4(longVertex,0.,1.)+i*vec4(longOffset,0.,0.);vec4 p2=projPos+i*vec4(longOffset,0.,0.);vec4 p3=shortProjVertex+i*vec4(-shortOffset,0.,0.);vec4 p4=shortProjVertex+i*vec4(shortOffset,0.,0.);float denom=(p4.y-p3.y)*(p2.x-p1.x)-(p4.x-p3.x)*(p2.y-p1.y);float epsilon=0.000000000001;float firstU=((p4.x-p3.x)*(p1.y-p3.y)-(p4.y-p3.y)*(p1.x-p3.x))/denom;float secondU=((p2.x-p1.x)*(p1.y-p3.y)-(p2.y-p1.y)*(p1.x-p3.x))/denom;if(firstU>epsilon&&firstU<1.0-epsilon&&secondU>epsilon&&secondU<1.0-epsilon){gl_Position=shortProjVertex;gl_Position.x=p1.x+firstU*(p2.x-p1.x);gl_Position.y=p1.y+firstU*(p2.y-p1.y);degenerate=true;}else{offset=normal*direction*miterLength;}}}else if(mod(g,7.0)==0.0||mod(g,11.0)==0.0){vec2 normal;if(mod(g,7.0)==0.0){vec2 dirVect=e-f;vec2 firstNormal=normalize(dirVect);vec2 secondNormal=vec2(firstNormal.y*direction,-firstNormal.x*direction);vec2 hypotenuse=normalize(firstNormal-secondNormal);normal=vec2(hypotenuse.y*direction,-hypotenuse.x*direction);}else{vec2 dirVect=e-d;vec2 firstNormal=normalize(dirVect);vec2 secondNormal=vec2(-firstNormal.y*direction,firstNormal.x*direction);vec2 hypotenuse=normalize(firstNormal-secondNormal);normal=vec2(-hypotenuse.y*direction,hypotenuse.x*direction);}float length=sqrt(c*c*2.0);offset=normal*length;if(mod(g,2.0)==0.0){a=1.0;}} if(!degenerate){vec4 offsets=i*vec4(offset,0.,0.);gl_Position=projPos+offsets;}}';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.render.webgl.linestringreplay.shader.DefaultVertex.SOURCE = goog.DEBUG ?
|
||||
ol.render.webgl.linestringreplay.shader.DefaultVertex.DEBUG_SOURCE :
|
||||
ol.render.webgl.linestringreplay.shader.DefaultVertex.OPTIMIZED_SOURCE;
|
||||
ol.render.webgl.linestringreplay.defaultshader.Vertex.SOURCE = ol.DEBUG ?
|
||||
ol.render.webgl.linestringreplay.defaultshader.Vertex.DEBUG_SOURCE :
|
||||
ol.render.webgl.linestringreplay.defaultshader.Vertex.OPTIMIZED_SOURCE;
|
||||
|
||||
|
||||
ol.render.webgl.linestringreplay.defaultshader.vertex = new ol.render.webgl.linestringreplay.defaultshader.Vertex();
|
||||
|
||||
|
||||
/**
|
||||
@@ -83,77 +86,77 @@ ol.render.webgl.linestringreplay.shader.DefaultVertex.SOURCE = goog.DEBUG ?
|
||||
* @param {WebGLProgram} program Program.
|
||||
* @struct
|
||||
*/
|
||||
ol.render.webgl.linestringreplay.shader.Default.Locations = function(gl, program) {
|
||||
ol.render.webgl.linestringreplay.defaultshader.Locations = function(gl, program) {
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_color = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_color' : 'm');
|
||||
program, ol.DEBUG ? 'u_color' : 'm');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_lineWidth = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_lineWidth' : 'j');
|
||||
program, ol.DEBUG ? 'u_lineWidth' : 'j');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_miterLimit = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_miterLimit' : 'k');
|
||||
program, ol.DEBUG ? 'u_miterLimit' : 'k');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_offsetScaleMatrix = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_offsetScaleMatrix' : 'i');
|
||||
program, ol.DEBUG ? 'u_offsetScaleMatrix' : 'i');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_opacity = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_opacity' : 'l');
|
||||
program, ol.DEBUG ? 'u_opacity' : 'l');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_pixelRatio = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_pixelRatio' : 'o');
|
||||
program, ol.DEBUG ? 'u_pixelRatio' : 'o');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_projectionMatrix = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_projectionMatrix' : 'h');
|
||||
program, ol.DEBUG ? 'u_projectionMatrix' : 'h');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_size = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_size' : 'n');
|
||||
program, ol.DEBUG ? 'u_size' : 'n');
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.a_direction = gl.getAttribLocation(
|
||||
program, goog.DEBUG ? 'a_direction' : 'g');
|
||||
program, ol.DEBUG ? 'a_direction' : 'g');
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.a_lastPos = gl.getAttribLocation(
|
||||
program, goog.DEBUG ? 'a_lastPos' : 'd');
|
||||
program, ol.DEBUG ? 'a_lastPos' : 'd');
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.a_nextPos = gl.getAttribLocation(
|
||||
program, goog.DEBUG ? 'a_nextPos' : 'f');
|
||||
program, ol.DEBUG ? 'a_nextPos' : 'f');
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.a_position = gl.getAttribLocation(
|
||||
program, goog.DEBUG ? 'a_position' : 'e');
|
||||
program, ol.DEBUG ? 'a_position' : 'e');
|
||||
};
|
||||
654
src/ol/render/webgl/linestringreplay/index.js
Normal file
654
src/ol/render/webgl/linestringreplay/index.js
Normal file
@@ -0,0 +1,654 @@
|
||||
goog.provide('ol.render.webgl.LineStringReplay');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.color');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.flat.orient');
|
||||
goog.require('ol.geom.flat.transform');
|
||||
goog.require('ol.geom.flat.topology');
|
||||
goog.require('ol.obj');
|
||||
goog.require('ol.render.webgl');
|
||||
goog.require('ol.render.webgl.Replay');
|
||||
goog.require('ol.render.webgl.linestringreplay.defaultshader');
|
||||
goog.require('ol.webgl');
|
||||
goog.require('ol.webgl.Buffer');
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.render.webgl.Replay}
|
||||
* @param {number} tolerance Tolerance.
|
||||
* @param {ol.Extent} maxExtent Max extent.
|
||||
* @struct
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay = function(tolerance, maxExtent) {
|
||||
ol.render.webgl.Replay.call(this, tolerance, maxExtent);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.render.webgl.linestringreplay.defaultshader.Locations}
|
||||
*/
|
||||
this.defaultLocations_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<Array.<?>>}
|
||||
*/
|
||||
this.styles_ = [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.styleIndices_ = [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {{strokeColor: (Array.<number>|null),
|
||||
* lineCap: (string|undefined),
|
||||
* lineDash: Array.<number>,
|
||||
* lineJoin: (string|undefined),
|
||||
* lineWidth: (number|undefined),
|
||||
* miterLimit: (number|undefined),
|
||||
* changed: boolean}|null}
|
||||
*/
|
||||
this.state_ = {
|
||||
strokeColor: null,
|
||||
lineCap: undefined,
|
||||
lineDash: null,
|
||||
lineJoin: undefined,
|
||||
lineWidth: undefined,
|
||||
miterLimit: undefined,
|
||||
changed: false
|
||||
};
|
||||
|
||||
};
|
||||
ol.inherits(ol.render.webgl.LineStringReplay, ol.render.webgl.Replay);
|
||||
|
||||
|
||||
/**
|
||||
* Draw one segment.
|
||||
* @private
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
* @param {number} end End.
|
||||
* @param {number} stride Stride.
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.drawCoordinates_ = function(flatCoordinates, offset, end, stride) {
|
||||
|
||||
var i, ii;
|
||||
var numVertices = this.vertices.length;
|
||||
var numIndices = this.indices.length;
|
||||
//To save a vertex, the direction of a point is a product of the sign (1 or -1), a prime from
|
||||
//ol.render.webgl.lineStringInstruction, and a rounding factor (1 or 2). If the product is even,
|
||||
//we round it. If it is odd, we don't.
|
||||
var lineJoin = this.state_.lineJoin === 'bevel' ? 0 :
|
||||
this.state_.lineJoin === 'miter' ? 1 : 2;
|
||||
var lineCap = this.state_.lineCap === 'butt' ? 0 :
|
||||
this.state_.lineCap === 'square' ? 1 : 2;
|
||||
var closed = ol.geom.flat.topology.lineStringIsClosed(flatCoordinates, offset, end, stride);
|
||||
var startCoords, sign, n;
|
||||
var lastIndex = numIndices;
|
||||
var lastSign = 1;
|
||||
//We need the adjacent vertices to define normals in joins. p0 = last, p1 = current, p2 = next.
|
||||
var p0, p1, p2;
|
||||
|
||||
for (i = offset, ii = end; i < ii; i += stride) {
|
||||
|
||||
n = numVertices / 7;
|
||||
|
||||
p0 = p1;
|
||||
p1 = p2 || [flatCoordinates[i], flatCoordinates[i + 1]];
|
||||
//First vertex.
|
||||
if (i === offset) {
|
||||
p2 = [flatCoordinates[i + stride], flatCoordinates[i + stride + 1]];
|
||||
if (end - offset === stride * 2 && ol.array.equals(p1, p2)) {
|
||||
break;
|
||||
}
|
||||
if (closed) {
|
||||
//A closed line! Complete the circle.
|
||||
p0 = [flatCoordinates[end - stride * 2],
|
||||
flatCoordinates[end - stride * 2 + 1]];
|
||||
|
||||
startCoords = p2;
|
||||
} else {
|
||||
//Add the first two/four vertices.
|
||||
|
||||
if (lineCap) {
|
||||
numVertices = this.addVertices_([0, 0], p1, p2,
|
||||
lastSign * ol.render.webgl.lineStringInstruction.BEGIN_LINE_CAP * lineCap, numVertices);
|
||||
|
||||
numVertices = this.addVertices_([0, 0], p1, p2,
|
||||
-lastSign * ol.render.webgl.lineStringInstruction.BEGIN_LINE_CAP * lineCap, numVertices);
|
||||
|
||||
this.indices[numIndices++] = n + 2;
|
||||
this.indices[numIndices++] = n;
|
||||
this.indices[numIndices++] = n + 1;
|
||||
|
||||
this.indices[numIndices++] = n + 1;
|
||||
this.indices[numIndices++] = n + 3;
|
||||
this.indices[numIndices++] = n + 2;
|
||||
|
||||
}
|
||||
|
||||
numVertices = this.addVertices_([0, 0], p1, p2,
|
||||
lastSign * ol.render.webgl.lineStringInstruction.BEGIN_LINE * (lineCap || 1), numVertices);
|
||||
|
||||
numVertices = this.addVertices_([0, 0], p1, p2,
|
||||
-lastSign * ol.render.webgl.lineStringInstruction.BEGIN_LINE * (lineCap || 1), numVertices);
|
||||
|
||||
lastIndex = numVertices / 7 - 1;
|
||||
|
||||
continue;
|
||||
}
|
||||
} else if (i === end - stride) {
|
||||
//Last vertex.
|
||||
if (closed) {
|
||||
//Same as the first vertex.
|
||||
p2 = startCoords;
|
||||
break;
|
||||
} else {
|
||||
//For the compiler not to complain. This will never be [0, 0].
|
||||
p0 = p0 || [0, 0];
|
||||
|
||||
numVertices = this.addVertices_(p0, p1, [0, 0],
|
||||
lastSign * ol.render.webgl.lineStringInstruction.END_LINE * (lineCap || 1), numVertices);
|
||||
|
||||
numVertices = this.addVertices_(p0, p1, [0, 0],
|
||||
-lastSign * ol.render.webgl.lineStringInstruction.END_LINE * (lineCap || 1), numVertices);
|
||||
|
||||
this.indices[numIndices++] = n;
|
||||
this.indices[numIndices++] = lastIndex - 1;
|
||||
this.indices[numIndices++] = lastIndex;
|
||||
|
||||
this.indices[numIndices++] = lastIndex;
|
||||
this.indices[numIndices++] = n + 1;
|
||||
this.indices[numIndices++] = n;
|
||||
|
||||
if (lineCap) {
|
||||
numVertices = this.addVertices_(p0, p1, [0, 0],
|
||||
lastSign * ol.render.webgl.lineStringInstruction.END_LINE_CAP * lineCap, numVertices);
|
||||
|
||||
numVertices = this.addVertices_(p0, p1, [0, 0],
|
||||
-lastSign * ol.render.webgl.lineStringInstruction.END_LINE_CAP * lineCap, numVertices);
|
||||
|
||||
this.indices[numIndices++] = n + 2;
|
||||
this.indices[numIndices++] = n;
|
||||
this.indices[numIndices++] = n + 1;
|
||||
|
||||
this.indices[numIndices++] = n + 1;
|
||||
this.indices[numIndices++] = n + 3;
|
||||
this.indices[numIndices++] = n + 2;
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
p2 = [flatCoordinates[i + stride], flatCoordinates[i + stride + 1]];
|
||||
}
|
||||
|
||||
sign = ol.render.webgl.triangleIsCounterClockwise(p0[0], p0[1], p1[0], p1[1], p2[0], p2[1])
|
||||
? -1 : 1;
|
||||
|
||||
numVertices = this.addVertices_(p0, p1, p2,
|
||||
sign * ol.render.webgl.lineStringInstruction.BEVEL_FIRST * (lineJoin || 1), numVertices);
|
||||
|
||||
numVertices = this.addVertices_(p0, p1, p2,
|
||||
sign * ol.render.webgl.lineStringInstruction.BEVEL_SECOND * (lineJoin || 1), numVertices);
|
||||
|
||||
numVertices = this.addVertices_(p0, p1, p2,
|
||||
-sign * ol.render.webgl.lineStringInstruction.MITER_BOTTOM * (lineJoin || 1), numVertices);
|
||||
|
||||
if (i > offset) {
|
||||
this.indices[numIndices++] = n;
|
||||
this.indices[numIndices++] = lastIndex - 1;
|
||||
this.indices[numIndices++] = lastIndex;
|
||||
|
||||
this.indices[numIndices++] = n + 2;
|
||||
this.indices[numIndices++] = n;
|
||||
this.indices[numIndices++] = lastSign * sign > 0 ? lastIndex : lastIndex - 1;
|
||||
}
|
||||
|
||||
this.indices[numIndices++] = n;
|
||||
this.indices[numIndices++] = n + 2;
|
||||
this.indices[numIndices++] = n + 1;
|
||||
|
||||
lastIndex = n + 2;
|
||||
lastSign = sign;
|
||||
|
||||
//Add miter
|
||||
if (lineJoin) {
|
||||
numVertices = this.addVertices_(p0, p1, p2,
|
||||
sign * ol.render.webgl.lineStringInstruction.MITER_TOP * lineJoin, numVertices);
|
||||
|
||||
this.indices[numIndices++] = n + 1;
|
||||
this.indices[numIndices++] = n + 3;
|
||||
this.indices[numIndices++] = n;
|
||||
}
|
||||
}
|
||||
|
||||
if (closed) {
|
||||
//Link the last triangle/rhombus to the first one.
|
||||
//n will never be numVertices / 7 here. However, the compiler complains otherwise.
|
||||
n = n || numVertices / 7;
|
||||
sign = ol.geom.flat.orient.linearRingIsClockwise([p0[0], p0[1], p1[0], p1[1], p2[0], p2[1]], 0, 6, 2)
|
||||
? 1 : -1;
|
||||
|
||||
numVertices = this.addVertices_(p0, p1, p2,
|
||||
sign * ol.render.webgl.lineStringInstruction.BEVEL_FIRST * (lineJoin || 1), numVertices);
|
||||
|
||||
numVertices = this.addVertices_(p0, p1, p2,
|
||||
-sign * ol.render.webgl.lineStringInstruction.MITER_BOTTOM * (lineJoin || 1), numVertices);
|
||||
|
||||
this.indices[numIndices++] = n;
|
||||
this.indices[numIndices++] = lastIndex - 1;
|
||||
this.indices[numIndices++] = lastIndex;
|
||||
|
||||
this.indices[numIndices++] = n + 1;
|
||||
this.indices[numIndices++] = n;
|
||||
this.indices[numIndices++] = lastSign * sign > 0 ? lastIndex : lastIndex - 1;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} p0 Last coordinates.
|
||||
* @param {Array.<number>} p1 Current coordinates.
|
||||
* @param {Array.<number>} p2 Next coordinates.
|
||||
* @param {number} product Sign, instruction, and rounding product.
|
||||
* @param {number} numVertices Vertex counter.
|
||||
* @return {number} Vertex counter.
|
||||
* @private
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.addVertices_ = function(p0, p1, p2, product, numVertices) {
|
||||
this.vertices[numVertices++] = p0[0];
|
||||
this.vertices[numVertices++] = p0[1];
|
||||
this.vertices[numVertices++] = p1[0];
|
||||
this.vertices[numVertices++] = p1[1];
|
||||
this.vertices[numVertices++] = p2[0];
|
||||
this.vertices[numVertices++] = p2[1];
|
||||
this.vertices[numVertices++] = product;
|
||||
|
||||
return numVertices;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the linestring can be drawn (i. e. valid).
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
* @param {number} end End.
|
||||
* @param {number} stride Stride.
|
||||
* @return {boolean} The linestring can be drawn.
|
||||
* @private
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.isValid_ = function(flatCoordinates, offset, end, stride) {
|
||||
var range = end - offset;
|
||||
if (range < stride * 2) {
|
||||
return false;
|
||||
} else if (range === stride * 2) {
|
||||
var firstP = [flatCoordinates[offset], flatCoordinates[offset + 1]];
|
||||
var lastP = [flatCoordinates[offset + stride], flatCoordinates[offset + stride + 1]];
|
||||
return !ol.array.equals(firstP, lastP);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.drawLineString = function(lineStringGeometry, feature) {
|
||||
var flatCoordinates = lineStringGeometry.getFlatCoordinates();
|
||||
var stride = lineStringGeometry.getStride();
|
||||
if (this.isValid_(flatCoordinates, 0, flatCoordinates.length, stride)) {
|
||||
flatCoordinates = ol.geom.flat.transform.translate(flatCoordinates, 0, flatCoordinates.length,
|
||||
stride, -this.origin[0], -this.origin[1]);
|
||||
if (this.state_.changed) {
|
||||
this.styleIndices_.push(this.indices.length);
|
||||
this.state_.changed = false;
|
||||
}
|
||||
this.startIndices.push(this.indices.length);
|
||||
this.startIndicesFeature.push(feature);
|
||||
this.drawCoordinates_(
|
||||
flatCoordinates, 0, flatCoordinates.length, stride);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.drawMultiLineString = function(multiLineStringGeometry, feature) {
|
||||
var indexCount = this.indices.length;
|
||||
var lineStringGeometries = multiLineStringGeometry.getLineStrings();
|
||||
var i, ii;
|
||||
for (i = 0, ii = lineStringGeometries.length; i < ii; ++i) {
|
||||
var flatCoordinates = lineStringGeometries[i].getFlatCoordinates();
|
||||
var stride = lineStringGeometries[i].getStride();
|
||||
if (this.isValid_(flatCoordinates, 0, flatCoordinates.length, stride)) {
|
||||
flatCoordinates = ol.geom.flat.transform.translate(flatCoordinates, 0, flatCoordinates.length,
|
||||
stride, -this.origin[0], -this.origin[1]);
|
||||
this.drawCoordinates_(
|
||||
flatCoordinates, 0, flatCoordinates.length, stride);
|
||||
}
|
||||
}
|
||||
if (this.indices.length > indexCount) {
|
||||
this.startIndices.push(indexCount);
|
||||
this.startIndicesFeature.push(feature);
|
||||
if (this.state_.changed) {
|
||||
this.styleIndices_.push(indexCount);
|
||||
this.state_.changed = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {Array.<Array.<number>>} holeFlatCoordinates Hole flat coordinates.
|
||||
* @param {number} stride Stride.
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.drawPolygonCoordinates = function(
|
||||
flatCoordinates, holeFlatCoordinates, stride) {
|
||||
this.drawCoordinates_(flatCoordinates, 0, flatCoordinates.length, stride);
|
||||
if (holeFlatCoordinates.length) {
|
||||
var i, ii;
|
||||
for (i = 0, ii = holeFlatCoordinates.length; i < ii; ++i) {
|
||||
this.drawCoordinates_(holeFlatCoordinates[i], 0,
|
||||
holeFlatCoordinates[i].length, stride);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Feature|ol.render.Feature} feature Feature.
|
||||
* @param {number=} opt_index Index count.
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.setPolygonStyle = function(feature, opt_index) {
|
||||
var index = opt_index === undefined ? this.indices.length : opt_index;
|
||||
this.startIndices.push(index);
|
||||
this.startIndicesFeature.push(feature);
|
||||
if (this.state_.changed) {
|
||||
this.styleIndices_.push(index);
|
||||
this.state_.changed = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Current index.
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.getCurrentIndex = function() {
|
||||
return this.indices.length;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
**/
|
||||
ol.render.webgl.LineStringReplay.prototype.finish = function(context) {
|
||||
// create, bind, and populate the vertices buffer
|
||||
this.verticesBuffer = new ol.webgl.Buffer(this.vertices);
|
||||
|
||||
// create, bind, and populate the indices buffer
|
||||
this.indicesBuffer = new ol.webgl.Buffer(this.indices);
|
||||
|
||||
this.startIndices.push(this.indices.length);
|
||||
|
||||
//Clean up, if there is nothing to draw
|
||||
if (this.styleIndices_.length === 0 && this.styles_.length > 0) {
|
||||
this.styles_ = [];
|
||||
}
|
||||
|
||||
this.vertices = null;
|
||||
this.indices = null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.getDeleteResourcesFunction = function(context) {
|
||||
// We only delete our stuff here. The shaders and the program may
|
||||
// be used by other LineStringReplay instances (for other layers). And
|
||||
// they will be deleted when disposing of the ol.webgl.Context
|
||||
// object.
|
||||
ol.DEBUG && console.assert(this.verticesBuffer, 'verticesBuffer must not be null');
|
||||
var verticesBuffer = this.verticesBuffer;
|
||||
var indicesBuffer = this.indicesBuffer;
|
||||
return function() {
|
||||
context.deleteBuffer(verticesBuffer);
|
||||
context.deleteBuffer(indicesBuffer);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.setUpProgram = function(gl, context, size, pixelRatio) {
|
||||
// get the program
|
||||
var fragmentShader, vertexShader;
|
||||
fragmentShader = ol.render.webgl.linestringreplay.defaultshader.fragment;
|
||||
vertexShader = ol.render.webgl.linestringreplay.defaultshader.vertex;
|
||||
var program = context.getProgram(fragmentShader, vertexShader);
|
||||
|
||||
// get the locations
|
||||
var locations;
|
||||
if (!this.defaultLocations_) {
|
||||
locations =
|
||||
new ol.render.webgl.linestringreplay.defaultshader.Locations(gl, program);
|
||||
this.defaultLocations_ = locations;
|
||||
} else {
|
||||
locations = this.defaultLocations_;
|
||||
}
|
||||
|
||||
context.useProgram(program);
|
||||
|
||||
// enable the vertex attrib arrays
|
||||
gl.enableVertexAttribArray(locations.a_lastPos);
|
||||
gl.vertexAttribPointer(locations.a_lastPos, 2, ol.webgl.FLOAT,
|
||||
false, 28, 0);
|
||||
|
||||
gl.enableVertexAttribArray(locations.a_position);
|
||||
gl.vertexAttribPointer(locations.a_position, 2, ol.webgl.FLOAT,
|
||||
false, 28, 8);
|
||||
|
||||
gl.enableVertexAttribArray(locations.a_nextPos);
|
||||
gl.vertexAttribPointer(locations.a_nextPos, 2, ol.webgl.FLOAT,
|
||||
false, 28, 16);
|
||||
|
||||
gl.enableVertexAttribArray(locations.a_direction);
|
||||
gl.vertexAttribPointer(locations.a_direction, 1, ol.webgl.FLOAT,
|
||||
false, 28, 24);
|
||||
|
||||
// Enable renderer specific uniforms.
|
||||
gl.uniform2fv(locations.u_size, size);
|
||||
gl.uniform1f(locations.u_pixelRatio, pixelRatio);
|
||||
|
||||
return locations;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) {
|
||||
//Save GL parameters.
|
||||
var tmpDepthFunc = /** @type {number} */ (gl.getParameter(gl.DEPTH_FUNC));
|
||||
var tmpDepthMask = /** @type {boolean} */ (gl.getParameter(gl.DEPTH_WRITEMASK));
|
||||
|
||||
if (!hitDetection) {
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.depthMask(true);
|
||||
gl.depthFunc(gl.NOTEQUAL);
|
||||
}
|
||||
|
||||
if (!ol.obj.isEmpty(skippedFeaturesHash)) {
|
||||
this.drawReplaySkipping_(gl, context, skippedFeaturesHash);
|
||||
} else {
|
||||
ol.DEBUG && console.assert(this.styles_.length === this.styleIndices_.length,
|
||||
'number of styles and styleIndices match');
|
||||
|
||||
//Draw by style groups to minimize drawElements() calls.
|
||||
var i, start, end, nextStyle;
|
||||
end = this.startIndices[this.startIndices.length - 1];
|
||||
for (i = this.styleIndices_.length - 1; i >= 0; --i) {
|
||||
start = this.styleIndices_[i];
|
||||
nextStyle = this.styles_[i];
|
||||
this.setStrokeStyle_(gl, nextStyle[0], nextStyle[1], nextStyle[2]);
|
||||
this.drawElements(gl, context, start, end);
|
||||
end = start;
|
||||
}
|
||||
}
|
||||
if (!hitDetection) {
|
||||
gl.clear(gl.DEPTH_BUFFER_BIT);
|
||||
gl.disable(gl.DEPTH_TEST);
|
||||
//Restore GL parameters.
|
||||
gl.depthMask(tmpDepthMask);
|
||||
gl.depthFunc(tmpDepthFunc);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {WebGLRenderingContext} gl gl.
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
* @param {Object} skippedFeaturesHash Ids of features to skip.
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.drawReplaySkipping_ = function(gl, context, skippedFeaturesHash) {
|
||||
ol.DEBUG && console.assert(this.startIndices.length - 1 === this.startIndicesFeature.length,
|
||||
'number of startIndices and startIndicesFeature match');
|
||||
|
||||
var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex, featureStart;
|
||||
featureIndex = this.startIndices.length - 2;
|
||||
end = start = this.startIndices[featureIndex + 1];
|
||||
for (i = this.styleIndices_.length - 1; i >= 0; --i) {
|
||||
nextStyle = this.styles_[i];
|
||||
this.setStrokeStyle_(gl, nextStyle[0], nextStyle[1], nextStyle[2]);
|
||||
groupStart = this.styleIndices_[i];
|
||||
|
||||
while (featureIndex >= 0 &&
|
||||
this.startIndices[featureIndex] >= groupStart) {
|
||||
featureStart = this.startIndices[featureIndex];
|
||||
feature = this.startIndicesFeature[featureIndex];
|
||||
featureUid = ol.getUid(feature).toString();
|
||||
|
||||
if (skippedFeaturesHash[featureUid]) {
|
||||
if (start !== end) {
|
||||
this.drawElements(gl, context, start, end);
|
||||
}
|
||||
end = featureStart;
|
||||
}
|
||||
featureIndex--;
|
||||
start = featureStart;
|
||||
}
|
||||
if (start !== end) {
|
||||
this.drawElements(gl, context, start, end);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash,
|
||||
featureCallback, opt_hitExtent) {
|
||||
ol.DEBUG && console.assert(this.styles_.length === this.styleIndices_.length,
|
||||
'number of styles and styleIndices match');
|
||||
ol.DEBUG && console.assert(this.startIndices.length - 1 === this.startIndicesFeature.length,
|
||||
'number of startIndices and startIndicesFeature match');
|
||||
|
||||
var i, start, end, nextStyle, groupStart, feature, featureUid, featureIndex;
|
||||
featureIndex = this.startIndices.length - 2;
|
||||
end = this.startIndices[featureIndex + 1];
|
||||
for (i = this.styleIndices_.length - 1; i >= 0; --i) {
|
||||
nextStyle = this.styles_[i];
|
||||
this.setStrokeStyle_(gl, nextStyle[0], nextStyle[1], nextStyle[2]);
|
||||
groupStart = this.styleIndices_[i];
|
||||
|
||||
while (featureIndex >= 0 &&
|
||||
this.startIndices[featureIndex] >= groupStart) {
|
||||
start = this.startIndices[featureIndex];
|
||||
feature = this.startIndicesFeature[featureIndex];
|
||||
featureUid = ol.getUid(feature).toString();
|
||||
|
||||
if (skippedFeaturesHash[featureUid] === undefined &&
|
||||
feature.getGeometry() &&
|
||||
(opt_hitExtent === undefined || ol.extent.intersects(
|
||||
/** @type {Array<number>} */ (opt_hitExtent),
|
||||
feature.getGeometry().getExtent()))) {
|
||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||
this.drawElements(gl, context, start, end);
|
||||
|
||||
var result = featureCallback(feature);
|
||||
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
featureIndex--;
|
||||
end = start;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {WebGLRenderingContext} gl gl.
|
||||
* @param {Array.<number>} color Color.
|
||||
* @param {number} lineWidth Line width.
|
||||
* @param {number} miterLimit Miter limit.
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.setStrokeStyle_ = function(gl, color, lineWidth, miterLimit) {
|
||||
gl.uniform4fv(this.defaultLocations_.u_color, color);
|
||||
gl.uniform1f(this.defaultLocations_.u_lineWidth, lineWidth);
|
||||
gl.uniform1f(this.defaultLocations_.u_miterLimit, miterLimit);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.webgl.LineStringReplay.prototype.setFillStrokeStyle = function(fillStyle, strokeStyle) {
|
||||
ol.DEBUG && console.assert(this.state_, 'this.state_ should not be null');
|
||||
var strokeStyleLineCap = strokeStyle.getLineCap();
|
||||
this.state_.lineCap = strokeStyleLineCap !== undefined ?
|
||||
strokeStyleLineCap : ol.render.webgl.defaultLineCap;
|
||||
var strokeStyleLineDash = strokeStyle.getLineDash();
|
||||
this.state_.lineDash = strokeStyleLineDash ?
|
||||
strokeStyleLineDash : ol.render.webgl.defaultLineDash;
|
||||
var strokeStyleLineJoin = strokeStyle.getLineJoin();
|
||||
this.state_.lineJoin = strokeStyleLineJoin !== undefined ?
|
||||
strokeStyleLineJoin : ol.render.webgl.defaultLineJoin;
|
||||
var strokeStyleColor = strokeStyle.getColor();
|
||||
if (!(strokeStyleColor instanceof CanvasGradient) &&
|
||||
!(strokeStyleColor instanceof CanvasPattern)) {
|
||||
strokeStyleColor = ol.color.asArray(strokeStyleColor).map(function(c, i) {
|
||||
return i != 3 ? c / 255 : c;
|
||||
}) || ol.render.webgl.defaultStrokeStyle;
|
||||
} else {
|
||||
strokeStyleColor = ol.render.webgl.defaultStrokeStyle;
|
||||
}
|
||||
var strokeStyleWidth = strokeStyle.getWidth();
|
||||
strokeStyleWidth = strokeStyleWidth !== undefined ?
|
||||
strokeStyleWidth : ol.render.webgl.defaultLineWidth;
|
||||
var strokeStyleMiterLimit = strokeStyle.getMiterLimit();
|
||||
strokeStyleMiterLimit = strokeStyleMiterLimit !== undefined ?
|
||||
strokeStyleMiterLimit : ol.render.webgl.defaultMiterLimit;
|
||||
if (!this.state_.strokeColor || !ol.array.equals(this.state_.strokeColor, strokeStyleColor) ||
|
||||
this.state_.lineWidth !== strokeStyleWidth || this.state_.miterLimit !== strokeStyleMiterLimit) {
|
||||
this.state_.changed = true;
|
||||
this.state_.strokeColor = strokeStyleColor;
|
||||
this.state_.lineWidth = strokeStyleWidth;
|
||||
this.state_.miterLimit = strokeStyleMiterLimit;
|
||||
this.styles_.push([strokeStyleColor, strokeStyleWidth, strokeStyleMiterLimit]);
|
||||
}
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
//! NAMESPACE=ol.render.webgl.polygonreplay.shader.Default
|
||||
//! CLASS=ol.render.webgl.polygonreplay.shader.Default
|
||||
//! NAMESPACE=ol.render.webgl.polygonreplay.defaultshader
|
||||
//! CLASS=ol.render.webgl.polygonreplay.defaultshader
|
||||
|
||||
|
||||
//! COMMON
|
||||
126
src/ol/render/webgl/polygonreplay/defaultshader.js
Normal file
126
src/ol/render/webgl/polygonreplay/defaultshader.js
Normal file
@@ -0,0 +1,126 @@
|
||||
// This file is automatically generated, do not edit
|
||||
goog.provide('ol.render.webgl.polygonreplay.defaultshader');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.webgl.Fragment');
|
||||
goog.require('ol.webgl.Vertex');
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.webgl.Fragment}
|
||||
* @struct
|
||||
*/
|
||||
ol.render.webgl.polygonreplay.defaultshader.Fragment = function() {
|
||||
ol.webgl.Fragment.call(this, ol.render.webgl.polygonreplay.defaultshader.Fragment.SOURCE);
|
||||
};
|
||||
ol.inherits(ol.render.webgl.polygonreplay.defaultshader.Fragment, ol.webgl.Fragment);
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @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';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @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;}';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.render.webgl.polygonreplay.defaultshader.Fragment.SOURCE = ol.DEBUG ?
|
||||
ol.render.webgl.polygonreplay.defaultshader.Fragment.DEBUG_SOURCE :
|
||||
ol.render.webgl.polygonreplay.defaultshader.Fragment.OPTIMIZED_SOURCE;
|
||||
|
||||
|
||||
ol.render.webgl.polygonreplay.defaultshader.fragment = new ol.render.webgl.polygonreplay.defaultshader.Fragment();
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.webgl.Vertex}
|
||||
* @struct
|
||||
*/
|
||||
ol.render.webgl.polygonreplay.defaultshader.Vertex = function() {
|
||||
ol.webgl.Vertex.call(this, ol.render.webgl.polygonreplay.defaultshader.Vertex.SOURCE);
|
||||
};
|
||||
ol.inherits(ol.render.webgl.polygonreplay.defaultshader.Vertex, ol.webgl.Vertex);
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @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 vec4 offsets = u_offsetScaleMatrix * vec4(0., 0., 0., 0.);\n gl_Position = u_projectionMatrix * vec4(a_position, 0., 1.) + offsets;\n}\n\n\n';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @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){vec4 offsets=c*vec4(0.,0.,0.,0.);gl_Position=b*vec4(a,0.,1.)+offsets;}';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.render.webgl.polygonreplay.defaultshader.Vertex.SOURCE = ol.DEBUG ?
|
||||
ol.render.webgl.polygonreplay.defaultshader.Vertex.DEBUG_SOURCE :
|
||||
ol.render.webgl.polygonreplay.defaultshader.Vertex.OPTIMIZED_SOURCE;
|
||||
|
||||
|
||||
ol.render.webgl.polygonreplay.defaultshader.vertex = new ol.render.webgl.polygonreplay.defaultshader.Vertex();
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {WebGLRenderingContext} gl GL.
|
||||
* @param {WebGLProgram} program Program.
|
||||
* @struct
|
||||
*/
|
||||
ol.render.webgl.polygonreplay.defaultshader.Locations = function(gl, program) {
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_color = gl.getUniformLocation(
|
||||
program, ol.DEBUG ? 'u_color' : 'e');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_offsetRotateMatrix = gl.getUniformLocation(
|
||||
program, ol.DEBUG ? 'u_offsetRotateMatrix' : 'd');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_offsetScaleMatrix = gl.getUniformLocation(
|
||||
program, ol.DEBUG ? 'u_offsetScaleMatrix' : 'c');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_opacity = gl.getUniformLocation(
|
||||
program, ol.DEBUG ? 'u_opacity' : 'f');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_projectionMatrix = gl.getUniformLocation(
|
||||
program, ol.DEBUG ? 'u_projectionMatrix' : 'b');
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.a_position = gl.getAttribLocation(
|
||||
program, ol.DEBUG ? 'a_position' : 'a');
|
||||
};
|
||||
1018
src/ol/render/webgl/polygonreplay/index.js
Normal file
1018
src/ol/render/webgl/polygonreplay/index.js
Normal file
File diff suppressed because it is too large
Load Diff
321
src/ol/render/webgl/replay.js
Normal file
321
src/ol/render/webgl/replay.js
Normal file
@@ -0,0 +1,321 @@
|
||||
goog.provide('ol.render.webgl.Replay');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.render.VectorContext');
|
||||
goog.require('ol.transform');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.render.VectorContext}
|
||||
* @param {number} tolerance Tolerance.
|
||||
* @param {ol.Extent} maxExtent Max extent.
|
||||
* @struct
|
||||
*/
|
||||
ol.render.webgl.Replay = function(tolerance, maxExtent) {
|
||||
ol.render.VectorContext.call(this);
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.tolerance = tolerance;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @const
|
||||
* @type {ol.Extent}
|
||||
*/
|
||||
this.maxExtent = maxExtent;
|
||||
|
||||
/**
|
||||
* The origin of the coordinate system for the point coordinates sent to
|
||||
* the GPU. To eliminate jitter caused by precision problems in the GPU
|
||||
* we use the "Rendering Relative to Eye" technique described in the "3D
|
||||
* Engine Design for Virtual Globes" book.
|
||||
* @protected
|
||||
* @type {ol.Coordinate}
|
||||
*/
|
||||
this.origin = ol.extent.getCenter(maxExtent);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Transform}
|
||||
*/
|
||||
this.projectionMatrix_ = ol.transform.create();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Transform}
|
||||
*/
|
||||
this.offsetRotateMatrix_ = ol.transform.create();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Transform}
|
||||
*/
|
||||
this.offsetScaleMatrix_ = ol.transform.create();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.tmpMat4_ = ol.vec.Mat4.create();
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.indices = [];
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {?ol.webgl.Buffer}
|
||||
*/
|
||||
this.indicesBuffer = null;
|
||||
|
||||
/**
|
||||
* Start index per feature (the index).
|
||||
* @protected
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.startIndices = [];
|
||||
|
||||
/**
|
||||
* Start index per feature (the feature).
|
||||
* @protected
|
||||
* @type {Array.<ol.Feature|ol.render.Feature>}
|
||||
*/
|
||||
this.startIndicesFeature = [];
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.vertices = [];
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {?ol.webgl.Buffer}
|
||||
*/
|
||||
this.verticesBuffer = null;
|
||||
|
||||
/**
|
||||
* Optional parameter for PolygonReplay instances.
|
||||
* @protected
|
||||
* @type {ol.render.webgl.LineStringReplay|undefined}
|
||||
*/
|
||||
this.lineStringReplay = undefined;
|
||||
|
||||
};
|
||||
ol.inherits(ol.render.webgl.Replay, ol.render.VectorContext);
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {ol.webgl.Context} context WebGL context.
|
||||
* @return {function()} Delete resources function.
|
||||
*/
|
||||
ol.render.webgl.Replay.prototype.getDeleteResourcesFunction = function(context) {};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
*/
|
||||
ol.render.webgl.Replay.prototype.finish = function(context) {};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @protected
|
||||
* @param {WebGLRenderingContext} gl gl.
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
* @param {ol.Size} size Size.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @return {ol.render.webgl.imagereplay.defaultshader.Locations|
|
||||
ol.render.webgl.linestringreplay.defaultshader.Locations|
|
||||
ol.render.webgl.polygonreplay.defaultshader.Locations} Locations.
|
||||
*/
|
||||
ol.render.webgl.Replay.prototype.setUpProgram = function(gl, context, size, pixelRatio) {};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @protected
|
||||
* @param {WebGLRenderingContext} gl gl.
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
* @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
|
||||
* to skip.
|
||||
* @param {boolean} hitDetection Hit detection mode.
|
||||
*/
|
||||
ol.render.webgl.Replay.prototype.drawReplay = function(gl, context, skippedFeaturesHash, hitDetection) {};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @protected
|
||||
* @param {WebGLRenderingContext} gl gl.
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
* @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
|
||||
* to skip.
|
||||
* @param {function((ol.Feature|ol.render.Feature)): T|undefined} featureCallback Feature callback.
|
||||
* @param {ol.Extent=} opt_hitExtent Hit extent: Only features intersecting
|
||||
* this extent are checked.
|
||||
* @return {T|undefined} Callback result.
|
||||
* @template T
|
||||
*/
|
||||
ol.render.webgl.Replay.prototype.drawHitDetectionReplayOneByOne = function(gl, context, skippedFeaturesHash, featureCallback, opt_hitExtent) {};
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @param {WebGLRenderingContext} gl gl.
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
* @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
|
||||
* to skip.
|
||||
* @param {function((ol.Feature|ol.render.Feature)): T|undefined} featureCallback Feature callback.
|
||||
* @param {boolean} oneByOne Draw features one-by-one for the hit-detecion.
|
||||
* @param {ol.Extent=} opt_hitExtent Hit extent: Only features intersecting
|
||||
* this extent are checked.
|
||||
* @return {T|undefined} Callback result.
|
||||
* @template T
|
||||
*/
|
||||
ol.render.webgl.Replay.prototype.drawHitDetectionReplay = function(gl, context, skippedFeaturesHash,
|
||||
featureCallback, oneByOne, opt_hitExtent) {
|
||||
if (!oneByOne) {
|
||||
// draw all hit-detection features in "once" (by texture group)
|
||||
return this.drawHitDetectionReplayAll(gl, context,
|
||||
skippedFeaturesHash, featureCallback);
|
||||
} else {
|
||||
// draw hit-detection features one by one
|
||||
return this.drawHitDetectionReplayOneByOne(gl, context,
|
||||
skippedFeaturesHash, featureCallback, opt_hitExtent);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @param {WebGLRenderingContext} gl gl.
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
* @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
|
||||
* to skip.
|
||||
* @param {function((ol.Feature|ol.render.Feature)): T|undefined} featureCallback Feature callback.
|
||||
* @return {T|undefined} Callback result.
|
||||
* @template T
|
||||
*/
|
||||
ol.render.webgl.Replay.prototype.drawHitDetectionReplayAll = function(gl, context, skippedFeaturesHash,
|
||||
featureCallback) {
|
||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||
this.drawReplay(gl, context, skippedFeaturesHash, true);
|
||||
|
||||
var result = featureCallback(null);
|
||||
if (result) {
|
||||
return result;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
* @param {ol.Coordinate} center Center.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} rotation Rotation.
|
||||
* @param {ol.Size} size Size.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {number} opacity Global opacity.
|
||||
* @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
|
||||
* to skip.
|
||||
* @param {function((ol.Feature|ol.render.Feature)): T|undefined} featureCallback Feature callback.
|
||||
* @param {boolean} oneByOne Draw features one-by-one for the hit-detecion.
|
||||
* @param {ol.Extent=} opt_hitExtent Hit extent: Only features intersecting
|
||||
* this extent are checked.
|
||||
* @return {T|undefined} Callback result.
|
||||
* @template T
|
||||
*/
|
||||
ol.render.webgl.Replay.prototype.replay = function(context,
|
||||
center, resolution, rotation, size, pixelRatio,
|
||||
opacity, skippedFeaturesHash,
|
||||
featureCallback, oneByOne, opt_hitExtent) {
|
||||
var gl = context.getGL();
|
||||
|
||||
// bind the vertices buffer
|
||||
ol.DEBUG && console.assert(this.verticesBuffer,
|
||||
'verticesBuffer must not be null');
|
||||
context.bindBuffer(ol.webgl.ARRAY_BUFFER, this.verticesBuffer);
|
||||
|
||||
// bind the indices buffer
|
||||
ol.DEBUG && console.assert(this.indicesBuffer,
|
||||
'indicesBuffer must not be null');
|
||||
context.bindBuffer(ol.webgl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
|
||||
|
||||
var locations = this.setUpProgram(gl, context, size, pixelRatio);
|
||||
|
||||
// set the "uniform" values
|
||||
var projectionMatrix = ol.transform.reset(this.projectionMatrix_);
|
||||
ol.transform.scale(projectionMatrix, 2 / (resolution * size[0]), 2 / (resolution * size[1]));
|
||||
ol.transform.rotate(projectionMatrix, -rotation);
|
||||
ol.transform.translate(projectionMatrix, -(center[0] - this.origin[0]), -(center[1] - this.origin[1]));
|
||||
|
||||
var offsetScaleMatrix = ol.transform.reset(this.offsetScaleMatrix_);
|
||||
ol.transform.scale(offsetScaleMatrix, 2 / size[0], 2 / size[1]);
|
||||
|
||||
var offsetRotateMatrix = ol.transform.reset(this.offsetRotateMatrix_);
|
||||
if (rotation !== 0) {
|
||||
ol.transform.rotate(offsetRotateMatrix, -rotation);
|
||||
}
|
||||
|
||||
gl.uniformMatrix4fv(locations.u_projectionMatrix, false,
|
||||
ol.vec.Mat4.fromTransform(this.tmpMat4_, projectionMatrix));
|
||||
gl.uniformMatrix4fv(locations.u_offsetScaleMatrix, false,
|
||||
ol.vec.Mat4.fromTransform(this.tmpMat4_, offsetScaleMatrix));
|
||||
gl.uniformMatrix4fv(locations.u_offsetRotateMatrix, false,
|
||||
ol.vec.Mat4.fromTransform(this.tmpMat4_, offsetRotateMatrix));
|
||||
gl.uniform1f(locations.u_opacity, opacity);
|
||||
|
||||
// draw!
|
||||
var result;
|
||||
if (featureCallback === undefined) {
|
||||
this.drawReplay(gl, context, skippedFeaturesHash, false);
|
||||
} else {
|
||||
// draw feature by feature for the hit-detection
|
||||
result = this.drawHitDetectionReplay(gl, context, skippedFeaturesHash,
|
||||
featureCallback, oneByOne, opt_hitExtent);
|
||||
}
|
||||
|
||||
// disable the vertex attrib arrays
|
||||
for (var i in locations) {
|
||||
if (typeof locations[i] === 'number') {
|
||||
gl.disableVertexAttribArray(locations[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.lineStringReplay) {
|
||||
this.lineStringReplay.replay(context,
|
||||
center, resolution, rotation, size, pixelRatio,
|
||||
opacity, skippedFeaturesHash,
|
||||
featureCallback, oneByOne, opt_hitExtent);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @param {WebGLRenderingContext} gl gl.
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
* @param {number} start Start index.
|
||||
* @param {number} end End index.
|
||||
*/
|
||||
ol.render.webgl.Replay.prototype.drawElements = function(
|
||||
gl, context, start, end) {
|
||||
var elementType = context.hasOESElementIndexUint ?
|
||||
ol.webgl.UNSIGNED_INT : ol.webgl.UNSIGNED_SHORT;
|
||||
var elementSize = context.hasOESElementIndexUint ? 4 : 2;
|
||||
|
||||
var numItems = end - start;
|
||||
var offsetInBytes = start * elementSize;
|
||||
gl.drawElements(ol.webgl.TRIANGLES, numItems, elementType, offsetInBytes);
|
||||
};
|
||||
280
src/ol/render/webgl/replaygroup.js
Normal file
280
src/ol/render/webgl/replaygroup.js
Normal file
@@ -0,0 +1,280 @@
|
||||
goog.provide('ol.render.webgl.ReplayGroup');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.render.ReplayGroup');
|
||||
goog.require('ol.render.webgl');
|
||||
goog.require('ol.render.webgl.ImageReplay');
|
||||
goog.require('ol.render.webgl.LineStringReplay');
|
||||
goog.require('ol.render.webgl.PolygonReplay');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.render.ReplayGroup}
|
||||
* @param {number} tolerance Tolerance.
|
||||
* @param {ol.Extent} maxExtent Max extent.
|
||||
* @param {number=} opt_renderBuffer Render buffer.
|
||||
* @struct
|
||||
*/
|
||||
ol.render.webgl.ReplayGroup = function(tolerance, maxExtent, opt_renderBuffer) {
|
||||
ol.render.ReplayGroup.call(this);
|
||||
|
||||
/**
|
||||
* @type {ol.Extent}
|
||||
* @private
|
||||
*/
|
||||
this.maxExtent_ = maxExtent;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.tolerance_ = tolerance;
|
||||
|
||||
/**
|
||||
* @type {number|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.renderBuffer_ = opt_renderBuffer;
|
||||
|
||||
/**
|
||||
* ImageReplay only is supported at this point.
|
||||
* @type {Object.<ol.render.ReplayType, ol.render.webgl.Replay>}
|
||||
* @private
|
||||
*/
|
||||
this.replays_ = {};
|
||||
|
||||
};
|
||||
ol.inherits(ol.render.webgl.ReplayGroup, ol.render.ReplayGroup);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.webgl.Context} context WebGL context.
|
||||
* @return {function()} Delete resources function.
|
||||
*/
|
||||
ol.render.webgl.ReplayGroup.prototype.getDeleteResourcesFunction = function(context) {
|
||||
var functions = [];
|
||||
var replayKey;
|
||||
for (replayKey in this.replays_) {
|
||||
functions.push(
|
||||
this.replays_[replayKey].getDeleteResourcesFunction(context));
|
||||
}
|
||||
return function() {
|
||||
var length = functions.length;
|
||||
var result;
|
||||
for (var i = 0; i < length; i++) {
|
||||
result = functions[i].apply(this, arguments);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
*/
|
||||
ol.render.webgl.ReplayGroup.prototype.finish = function(context) {
|
||||
var replayKey;
|
||||
for (replayKey in this.replays_) {
|
||||
this.replays_[replayKey].finish(context);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.webgl.ReplayGroup.prototype.getReplay = function(zIndex, replayType) {
|
||||
var replay = this.replays_[replayType];
|
||||
if (replay === undefined) {
|
||||
var constructor = ol.render.webgl.ReplayGroup.BATCH_CONSTRUCTORS_[replayType];
|
||||
replay = new constructor(this.tolerance_, this.maxExtent_);
|
||||
this.replays_[replayType] = replay;
|
||||
}
|
||||
return replay;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.webgl.ReplayGroup.prototype.isEmpty = function() {
|
||||
return ol.obj.isEmpty(this.replays_);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
* @param {ol.Coordinate} center Center.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} rotation Rotation.
|
||||
* @param {ol.Size} size Size.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {number} opacity Global opacity.
|
||||
* @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
|
||||
* to skip.
|
||||
*/
|
||||
ol.render.webgl.ReplayGroup.prototype.replay = function(context,
|
||||
center, resolution, rotation, size, pixelRatio,
|
||||
opacity, skippedFeaturesHash) {
|
||||
var i, ii, replay;
|
||||
for (i = 0, ii = ol.render.replay.ORDER.length; i < ii; ++i) {
|
||||
replay = this.replays_[ol.render.replay.ORDER[i]];
|
||||
if (replay !== undefined) {
|
||||
replay.replay(context,
|
||||
center, resolution, rotation, size, pixelRatio,
|
||||
opacity, skippedFeaturesHash,
|
||||
undefined, false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
* @param {ol.Coordinate} center Center.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} rotation Rotation.
|
||||
* @param {ol.Size} size Size.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {number} opacity Global opacity.
|
||||
* @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
|
||||
* to skip.
|
||||
* @param {function((ol.Feature|ol.render.Feature)): T|undefined} featureCallback Feature callback.
|
||||
* @param {boolean} oneByOne Draw features one-by-one for the hit-detecion.
|
||||
* @param {ol.Extent=} opt_hitExtent Hit extent: Only features intersecting
|
||||
* this extent are checked.
|
||||
* @return {T|undefined} Callback result.
|
||||
* @template T
|
||||
*/
|
||||
ol.render.webgl.ReplayGroup.prototype.replayHitDetection_ = function(context,
|
||||
center, resolution, rotation, size, pixelRatio, opacity,
|
||||
skippedFeaturesHash, featureCallback, oneByOne, opt_hitExtent) {
|
||||
var i, replay, result;
|
||||
for (i = ol.render.replay.ORDER.length - 1; i >= 0; --i) {
|
||||
replay = this.replays_[ol.render.replay.ORDER[i]];
|
||||
if (replay !== undefined) {
|
||||
result = replay.replay(context,
|
||||
center, resolution, rotation, size, pixelRatio, opacity,
|
||||
skippedFeaturesHash, featureCallback, oneByOne, opt_hitExtent);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
* @param {ol.Coordinate} center Center.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} rotation Rotation.
|
||||
* @param {ol.Size} size Size.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {number} opacity Global opacity.
|
||||
* @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
|
||||
* to skip.
|
||||
* @param {function((ol.Feature|ol.render.Feature)): T|undefined} callback Feature callback.
|
||||
* @return {T|undefined} Callback result.
|
||||
* @template T
|
||||
*/
|
||||
ol.render.webgl.ReplayGroup.prototype.forEachFeatureAtCoordinate = function(
|
||||
coordinate, context, center, resolution, rotation, size, pixelRatio,
|
||||
opacity, skippedFeaturesHash,
|
||||
callback) {
|
||||
var gl = context.getGL();
|
||||
gl.bindFramebuffer(
|
||||
gl.FRAMEBUFFER, context.getHitDetectionFramebuffer());
|
||||
|
||||
|
||||
/**
|
||||
* @type {ol.Extent}
|
||||
*/
|
||||
var hitExtent;
|
||||
if (this.renderBuffer_ !== undefined) {
|
||||
// build an extent around the coordinate, so that only features that
|
||||
// intersect this extent are checked
|
||||
hitExtent = ol.extent.buffer(
|
||||
ol.extent.createOrUpdateFromCoordinate(coordinate),
|
||||
resolution * this.renderBuffer_);
|
||||
}
|
||||
|
||||
return this.replayHitDetection_(context,
|
||||
coordinate, resolution, rotation, ol.render.webgl.ReplayGroup.HIT_DETECTION_SIZE_,
|
||||
pixelRatio, opacity, skippedFeaturesHash,
|
||||
/**
|
||||
* @param {ol.Feature|ol.render.Feature} feature Feature.
|
||||
* @return {?} Callback result.
|
||||
*/
|
||||
function(feature) {
|
||||
var imageData = new Uint8Array(4);
|
||||
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, imageData);
|
||||
|
||||
if (imageData[3] > 0) {
|
||||
var result = callback(feature);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}, true, hitExtent);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
* @param {ol.Coordinate} center Center.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} rotation Rotation.
|
||||
* @param {ol.Size} size Size.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {number} opacity Global opacity.
|
||||
* @param {Object.<string, boolean>} skippedFeaturesHash Ids of features
|
||||
* to skip.
|
||||
* @return {boolean} Is there a feature at the given coordinate?
|
||||
*/
|
||||
ol.render.webgl.ReplayGroup.prototype.hasFeatureAtCoordinate = function(
|
||||
coordinate, context, center, resolution, rotation, size, pixelRatio,
|
||||
opacity, skippedFeaturesHash) {
|
||||
var gl = context.getGL();
|
||||
gl.bindFramebuffer(
|
||||
gl.FRAMEBUFFER, context.getHitDetectionFramebuffer());
|
||||
|
||||
var hasFeature = this.replayHitDetection_(context,
|
||||
coordinate, resolution, rotation, ol.render.webgl.ReplayGroup.HIT_DETECTION_SIZE_,
|
||||
pixelRatio, opacity, skippedFeaturesHash,
|
||||
/**
|
||||
* @param {ol.Feature|ol.render.Feature} feature Feature.
|
||||
* @return {boolean} Is there a feature?
|
||||
*/
|
||||
function(feature) {
|
||||
var imageData = new Uint8Array(4);
|
||||
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, imageData);
|
||||
return imageData[3] > 0;
|
||||
}, false);
|
||||
|
||||
return hasFeature !== undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
ol.render.webgl.ReplayGroup.HIT_DETECTION_SIZE_ = [1, 1];
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @private
|
||||
* @type {Object.<ol.render.ReplayType,
|
||||
* function(new: ol.render.webgl.Replay, number,
|
||||
* ol.Extent)>}
|
||||
*/
|
||||
ol.render.webgl.ReplayGroup.BATCH_CONSTRUCTORS_ = {
|
||||
'Image': ol.render.webgl.ImageReplay,
|
||||
'LineString': ol.render.webgl.LineStringReplay,
|
||||
'Polygon': ol.render.webgl.PolygonReplay
|
||||
};
|
||||
@@ -1,123 +0,0 @@
|
||||
// This file is automatically generated, do not edit
|
||||
goog.provide('ol.render.webgl.polygonreplay.shader.Default');
|
||||
goog.provide('ol.render.webgl.polygonreplay.shader.Default.Locations');
|
||||
goog.provide('ol.render.webgl.polygonreplay.shader.DefaultFragment');
|
||||
goog.provide('ol.render.webgl.polygonreplay.shader.DefaultVertex');
|
||||
|
||||
goog.require('ol.webgl.shader');
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.webgl.shader.Fragment}
|
||||
* @struct
|
||||
*/
|
||||
ol.render.webgl.polygonreplay.shader.DefaultFragment = function() {
|
||||
ol.webgl.shader.Fragment.call(this, ol.render.webgl.polygonreplay.shader.DefaultFragment.SOURCE);
|
||||
};
|
||||
ol.inherits(ol.render.webgl.polygonreplay.shader.DefaultFragment, ol.webgl.shader.Fragment);
|
||||
goog.addSingletonGetter(ol.render.webgl.polygonreplay.shader.DefaultFragment);
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.render.webgl.polygonreplay.shader.DefaultFragment.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
|
||||
* @type {string}
|
||||
*/
|
||||
ol.render.webgl.polygonreplay.shader.DefaultFragment.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
|
||||
* @type {string}
|
||||
*/
|
||||
ol.render.webgl.polygonreplay.shader.DefaultFragment.SOURCE = goog.DEBUG ?
|
||||
ol.render.webgl.polygonreplay.shader.DefaultFragment.DEBUG_SOURCE :
|
||||
ol.render.webgl.polygonreplay.shader.DefaultFragment.OPTIMIZED_SOURCE;
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.webgl.shader.Vertex}
|
||||
* @struct
|
||||
*/
|
||||
ol.render.webgl.polygonreplay.shader.DefaultVertex = function() {
|
||||
ol.webgl.shader.Vertex.call(this, ol.render.webgl.polygonreplay.shader.DefaultVertex.SOURCE);
|
||||
};
|
||||
ol.inherits(ol.render.webgl.polygonreplay.shader.DefaultVertex, ol.webgl.shader.Vertex);
|
||||
goog.addSingletonGetter(ol.render.webgl.polygonreplay.shader.DefaultVertex);
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.render.webgl.polygonreplay.shader.DefaultVertex.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 vec4 offsets = u_offsetScaleMatrix * vec4(0., 0., 0., 0.);\n gl_Position = u_projectionMatrix * vec4(a_position, 0., 1.) + offsets;\n}\n\n\n';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.render.webgl.polygonreplay.shader.DefaultVertex.OPTIMIZED_SOURCE = 'attribute vec2 a;uniform mat4 b;uniform mat4 c;uniform mat4 d;void main(void){vec4 offsets=c*vec4(0.,0.,0.,0.);gl_Position=b*vec4(a,0.,1.)+offsets;}';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
ol.render.webgl.polygonreplay.shader.DefaultVertex.SOURCE = goog.DEBUG ?
|
||||
ol.render.webgl.polygonreplay.shader.DefaultVertex.DEBUG_SOURCE :
|
||||
ol.render.webgl.polygonreplay.shader.DefaultVertex.OPTIMIZED_SOURCE;
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {WebGLRenderingContext} gl GL.
|
||||
* @param {WebGLProgram} program Program.
|
||||
* @struct
|
||||
*/
|
||||
ol.render.webgl.polygonreplay.shader.Default.Locations = function(gl, program) {
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_color = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_color' : 'e');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_offsetRotateMatrix = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_offsetRotateMatrix' : 'd');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_offsetScaleMatrix = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_offsetScaleMatrix' : 'c');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_opacity = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_opacity' : 'f');
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.u_projectionMatrix = gl.getUniformLocation(
|
||||
program, goog.DEBUG ? 'u_projectionMatrix' : 'b');
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.a_position = gl.getAttribLocation(
|
||||
program, goog.DEBUG ? 'a_position' : 'a');
|
||||
};
|
||||
Reference in New Issue
Block a user