PolygonBucket: enable fade and tinting of textured polygons

This commit is contained in:
Hannes Janetzek 2014-10-10 00:14:57 +02:00
parent 01a41d5f87
commit 7b9301d479
2 changed files with 23 additions and 25 deletions

View File

@ -24,5 +24,5 @@ varying vec2 v_st;
varying vec2 v_st2; varying vec2 v_st2;
void void
main(){ main(){
gl_FragColor = mix(texture2D(tex, v_st), texture2D(tex, v_st2), u_scale.x); gl_FragColor = mix(texture2D(tex, v_st), texture2D(tex, v_st2), u_scale.x) * u_color;
} }

View File

@ -147,11 +147,9 @@ public final class PolygonBucket extends RenderBucket {
uMVP = getUniform("u_mvp"); uMVP = getUniform("u_mvp");
aPos = getAttrib("a_pos"); aPos = getAttrib("a_pos");
uColor = getUniform("u_color");
if (shaderFile == "polygon_layer_tex") if (shaderFile == "polygon_layer_tex")
uScale = getUniform("u_scale"); uScale = getUniform("u_scale");
else
uColor = getUniform("u_color");
} }
} }
@ -191,7 +189,6 @@ public final class PolygonBucket extends RenderBucket {
if (enableTexture && (a.texture != null)) { if (enableTexture && (a.texture != null)) {
s = setShader(texShader, v.mvp, false); s = setShader(texShader, v.mvp, false);
float num = clamp((Tile.SIZE / a.texture.width) >> 1, 1, Tile.SIZE); float num = clamp((Tile.SIZE / a.texture.width) >> 1, 1, Tile.SIZE);
float scale = (float) pos.getZoomScale(); float scale = (float) pos.getZoomScale();
@ -199,31 +196,32 @@ public final class PolygonBucket extends RenderBucket {
transition = Interpolation.exp5.apply(transition); transition = Interpolation.exp5.apply(transition);
gl.uniform2f(s.uScale, transition, div / num); gl.uniform2f(s.uScale, transition, div / num);
GLState.blend(true);
a.texture.bind(); a.texture.bind();
} else { } else {
s = setShader(polyShader, v.mvp, false); s = setShader(polyShader, v.mvp, false);
}
float fade = a.getFade(pos.scale); float fade = a.getFade(pos.scale);
float blend = a.getBlend(pos.scale); float blendFill = a.getBlend(pos.scale);
boolean blend = (s == texShader || fade < 1.0);
if (fade < 1.0f) { if (fade < 1.0) {
GLState.blend(true);
GLUtils.setColor(s.uColor, a.color, fade); GLUtils.setColor(s.uColor, a.color, fade);
} else if (blend > 0.0f) { } else if (blendFill > 0.0f) {
if (blend == 1.0f) if (blendFill == 1.0f) {
GLUtils.setColor(s.uColor, a.blendColor, 1); GLUtils.setColor(s.uColor, a.blendColor, 1);
else
GLUtils.setColorBlend(s.uColor, a.color,
a.blendColor, blend);
} else { } else {
/* test if color contains alpha */ GLUtils.setColorBlend(s.uColor, a.color,
GLState.blend((a.color & OPAQUE) != OPAQUE); a.blendColor, blendFill);
GLUtils.setColor(s.uColor, a.color, 1);
} }
} else {
blend |= (a.color & OPAQUE) != OPAQUE;
GLUtils.setColor(s.uColor, a.color, fade);
} }
GLState.blend(blend);
/* set stencil buffer mask used to draw this layer /* set stencil buffer mask used to draw this layer
* also check that clip bit is set to avoid overdraw * also check that clip bit is set to avoid overdraw
* of other tiles */ * of other tiles */