make extrusion-layer themeable

This commit is contained in:
Hannes Janetzek 2013-10-07 01:41:09 +02:00
parent a5c3f92826
commit afeaf60c3f
8 changed files with 116 additions and 36 deletions

View File

@ -371,26 +371,8 @@ public class VectorTileLoader extends TileLoader implements IRenderTheme.Callbac
} }
} }
Tag TREE_TAG = new Tag("natural", "tree");
@Override @Override
public void renderPointCircle(Circle circle, int level) { public void renderPointCircle(Circle circle, int level) {
if (mElement.tags.contains(TREE_TAG))
for (int i = 0, n = mElement.getNumPoints(); i < n; i++) {
PointF p = mElement.getPoint(i);
SymbolItem it = SymbolItem.pool.get();
//it.set(p.x, p.y, null, true);
it.x = p.x;
it.y = p.y;
it.tag = mElement.tags.get(TREE_TAG.key);
mTile.addSymbol(it);
}
} }
@Override @Override
@ -438,7 +420,7 @@ public class VectorTileLoader extends TileLoader implements IRenderTheme.Callbac
* MercatorProjection.EARTH_CIRCUMFERENCE * MercatorProjection.EARTH_CIRCUMFERENCE
/ ((long) Tile.SIZE << mTile.zoomLevel)); / ((long) Tile.SIZE << mTile.zoomLevel));
mTile.layers.extrusionLayers = l = new ExtrusionLayer(0, groundScale); mTile.layers.extrusionLayers = l = new ExtrusionLayer(0, groundScale, extrusion.colors);
} }
l.add(mElement, height, minHeight); l.add(mElement, height, minHeight);
} }

View File

@ -188,6 +188,12 @@
<xs:attribute name="src" type="tns:src" use="required" /> <xs:attribute name="src" type="tns:src" use="required" />
</xs:complexType> </xs:complexType>
<xs:complexType name="extrusion">
<xs:attribute name="line-color" type="tns:color" use="optional" />
<xs:attribute name="side-color" type="tns:color" use="required" />
<xs:attribute name="top-color" type="tns:color" use="required" />
</xs:complexType>
<!-- match elements --> <!-- match elements -->
<xs:complexType name="m"> <xs:complexType name="m">
@ -202,10 +208,11 @@
<xs:element name="outline" type="tns:line" /> <xs:element name="outline" type="tns:line" />
<xs:element name="lineSymbol" type="tns:lineSymbol" /> <xs:element name="lineSymbol" type="tns:lineSymbol" />
<xs:element name="text" type="tns:text" /> <xs:element name="text" type="tns:text" />
<!-- <xs:element name="styletext type="xs:string" /> --> <xs:element name="extrusion" type="tns:extrusion" />
<xs:element name="symbol" type="tns:symbol" /> <xs:element name="symbol" type="tns:symbol" />
<!-- outline is defined within rules to match layering --> <!-- outline is defined within rules to match layering -->
<xs:element name="style-outline" type="tns:line" /> <xs:element name="outline-layer" type="tns:line" />
</xs:choice> </xs:choice>
<xs:attribute name="select" type="tns:selectorList" use="optional" default="any"/> <xs:attribute name="select" type="tns:selectorList" use="optional" default="any"/>
@ -236,7 +243,7 @@
<xs:element name="style-text" type="tns:text" /> <xs:element name="style-text" type="tns:text" />
<xs:element name="style-area" type="tns:area" /> <xs:element name="style-area" type="tns:area" />
<xs:element name="style-line" type="tns:line" /> <xs:element name="style-line" type="tns:line" />
<xs:element name="style-outline" type="tns:line" /> <!-- <xs:element name="style-outline" type="tns:line" /> -->
</xs:choice> </xs:choice>
</xs:sequence> </xs:sequence>

View File

@ -68,6 +68,8 @@ public class BuildingLayer extends Layer {
super.update(pos, changed, m); super.update(pos, changed, m);
} }
}; };
//mExtLayer.setColors(Color.LTGRAY, Color.GRAY, Color.DKGRAY);
mRenderer = mExtLayer; mRenderer = mExtLayer;
} }

View File

@ -439,7 +439,7 @@ public class VectorTileLoader extends TileLoader implements IRenderTheme.Callbac
* MercatorProjection.EARTH_CIRCUMFERENCE * MercatorProjection.EARTH_CIRCUMFERENCE
/ ((long) Tile.SIZE << mTile.zoomLevel)); / ((long) Tile.SIZE << mTile.zoomLevel));
mTile.layers.extrusionLayers = l = new ExtrusionLayer(0, groundScale); mTile.layers.extrusionLayers = l = new ExtrusionLayer(0, groundScale, extrusion.colors);
} }
l.add(mElement, height, minHeight); l.add(mElement, height, minHeight);
} }

View File

@ -16,6 +16,7 @@ package org.oscim.renderer;
import org.oscim.backend.GL20; import org.oscim.backend.GL20;
import org.oscim.backend.Log; import org.oscim.backend.Log;
import org.oscim.backend.canvas.Color;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.core.Tile; import org.oscim.core.Tile;
import org.oscim.renderer.MapRenderer.Matrices; import org.oscim.renderer.MapRenderer.Matrices;
@ -97,6 +98,13 @@ public class ExtrusionRenderer extends LayerRenderer {
return; return;
} }
if (mUpdateColors) {
synchronized (this) {
System.arraycopy(mNewColors, 0, mColor, 0, 16);
mUpdateColors = false;
}
}
int activeTiles = 0; int activeTiles = 0;
mTileLayer.getVisibleTiles(mTileSet); mTileLayer.getVisibleTiles(mTileSet);
MapTile[] tiles = mTileSet.tiles; MapTile[] tiles = mTileSet.tiles;
@ -233,8 +241,8 @@ public class ExtrusionRenderer extends LayerRenderer {
} }
GL.glDepthFunc(GL20.GL_LESS); GL.glDepthFunc(GL20.GL_LESS);
GL.glColorMask(false, false, false, false); GL.glColorMask(false, false, false, false);
GL.glUniform1i(uExtMode, 0); GL.glUniform1i(uExtMode, -1);
GLUtils.glUniform4fv(uExtColor, 4, mColor); //GLUtils.glUniform4fv(uExtColor, 4, mColor);
GL.glUniform1f(uExtAlpha, mAlpha); GL.glUniform1f(uExtAlpha, mAlpha);
// draw to depth buffer // draw to depth buffer
@ -262,10 +270,20 @@ public class ExtrusionRenderer extends LayerRenderer {
GL.glDepthMask(false); GL.glDepthMask(false);
GLState.blend(true); GLState.blend(true);
float[] currentColor = null;
for (int i = 0; i < mTileCnt; i++) { for (int i = 0; i < mTileCnt; i++) {
MapTile t = tiles[i]; MapTile t = tiles[i];
ExtrusionLayer el = (ExtrusionLayer) t.layers.extrusionLayers; ExtrusionLayer el = (ExtrusionLayer) t.layers.extrusionLayers;
if (el.colors == null) {
currentColor = mColor;
GLUtils.glUniform4fv(uExtColor, 4, currentColor);
} else if (currentColor != el.colors) {
currentColor = el.colors;
GLUtils.glUniform4fv(uExtColor, 4, currentColor);
}
GL.glDepthFunc(GL20.GL_EQUAL); GL.glDepthFunc(GL20.GL_EQUAL);
int d = MapRenderer.depthOffset(t) * 10; int d = MapRenderer.depthOffset(t) * 10;
setMatrix(pos, m, t, d); setMatrix(pos, m, t, d);
@ -338,6 +356,41 @@ public class ExtrusionRenderer extends LayerRenderer {
m.mvp.addDepthOffset(delta); m.mvp.addDepthOffset(delta);
} }
public synchronized void setColors(float[] colors) {
System.arraycopy(colors, 0, mNewColors, 0, 16);
mUpdateColors = true;
}
public synchronized void setColors(int sides, int top, int lines) {
fillColors(sides, top, lines);
mUpdateColors = true;
}
private void fillColors(int sides, int top, int lines) {
mNewColors[0] = Color.rToFloat(top);
mNewColors[1] = Color.gToFloat(top);
mNewColors[2] = Color.bToFloat(top);
mNewColors[3] = Color.aToFloat(top);
mNewColors[4] = Color.rToFloat(sides);
mNewColors[5] = Color.gToFloat(sides);
mNewColors[6] = Color.bToFloat(sides);
mNewColors[7] = Color.aToFloat(sides);
mNewColors[8] = Color.rToFloat(sides);
mNewColors[9] = Color.gToFloat(sides);
mNewColors[10] = Color.bToFloat(sides);
mNewColors[11] = Color.aToFloat(sides);
mNewColors[12] = Color.rToFloat(lines);
mNewColors[13] = Color.gToFloat(lines);
mNewColors[14] = Color.bToFloat(lines);
mNewColors[15] = Color.aToFloat(lines);
}
private boolean mUpdateColors;
private final float[] mNewColors = new float[16];
private final float _a = 0.88f; private final float _a = 0.88f;
private final float _r = 0xe9; private final float _r = 0xe9;
private final float _g = 0xe8; private final float _g = 0xe8;
@ -383,7 +436,10 @@ public class ExtrusionRenderer extends LayerRenderer {
// change height by u_alpha // change height by u_alpha
+ " gl_Position = u_mvp * vec4(a_pos.xy, a_pos.z * u_alpha, 1.0);" + " gl_Position = u_mvp * vec4(a_pos.xy, a_pos.z * u_alpha, 1.0);"
//+ " depth = gl_Position.z;" //+ " depth = gl_Position.z;"
+ " if (u_mode == 0)" + " if (u_mode == -1) ;"
// roof / depth pass
//+ " color = u_color[0] * u_alpha;"
+ " else if (u_mode == 0)"
// roof / depth pass // roof / depth pass
+ " color = u_color[0] * u_alpha;" + " color = u_color[0] * u_alpha;"
+ " else {" + " else {"

View File

@ -43,6 +43,8 @@ public class ExtrusionLayer extends RenderElement {
private final VertexItem mCurIndices[]; private final VertexItem mCurIndices[];
private LineClipper mClipper; private LineClipper mClipper;
public final float[] colors;
// indices for: // indices for:
// 0. even sides, 1. odd sides, 2. roof, 3. roof outline // 0. even sides, 1. odd sides, 2. roof, 3. roof outline
public int mIndiceCnt[] = { 0, 0, 0, 0 }; public int mIndiceCnt[] = { 0, 0, 0, 0 };
@ -60,9 +62,10 @@ public class ExtrusionLayer extends RenderElement {
public boolean compiled = false; public boolean compiled = false;
private final float mGroundResolution; private final float mGroundResolution;
public ExtrusionLayer(int level, float groundResolution) { public ExtrusionLayer(int level, float groundResolution, float[] colors) {
super(RenderElement.EXTRUSION); super(RenderElement.EXTRUSION);
this.level = level; this.level = level;
this.colors = colors;
mGroundResolution = groundResolution; mGroundResolution = groundResolution;
mVertices = mCurVertices = VertexItem.pool.get(); mVertices = mCurVertices = VertexItem.pool.get();

View File

@ -902,6 +902,7 @@ public class RenderThemeHandler extends DefaultHandler {
int colorSide = 0; int colorSide = 0;
int colorTop = 0; int colorTop = 0;
int colorLine = 0; int colorLine = 0;
int defaultHeight = 0;
for (int i = 0; i < attributes.getLength(); ++i) { for (int i = 0; i < attributes.getLength(); ++i) {
String name = attributes.getLocalName(i); String name = attributes.getLocalName(i);
@ -916,10 +917,13 @@ public class RenderThemeHandler extends DefaultHandler {
else if ("line-color".equals(name)) else if ("line-color".equals(name))
colorLine = Color.parseColor(value); colorLine = Color.parseColor(value);
else if ("default-height".equals(name))
defaultHeight = Integer.parseInt(value);
else else
logUnknownAttribute(elementName, name, value, i); logUnknownAttribute(elementName, name, value, i);
} }
return new Extrusion(level, colorSide, colorTop, colorLine); return new Extrusion(level, colorSide, colorTop, colorLine, defaultHeight);
} }
} }

View File

@ -1,25 +1,51 @@
package org.oscim.theme.renderinstruction; package org.oscim.theme.renderinstruction;
import org.oscim.backend.canvas.Color;
import org.oscim.theme.IRenderTheme.Callback; import org.oscim.theme.IRenderTheme.Callback;
public class Extrusion extends RenderInstruction { public class Extrusion extends RenderInstruction {
public Extrusion(int level, int colorSides, int colorTop, int colorLine) { public Extrusion(int level, int colorSides, int colorTop, int colorLine, int defaultHeight) {
this.colorSide = colorSides;
this.colorTop = colorTop;
this.colorLine = colorLine;
this.colors = new float[16];
fillColors(colorSides, colorTop, colorLine, colors);
this.defaultHeight = defaultHeight;
this.level = level; this.level = level;
} }
public static void fillColors(int sides, int top, int lines, float[] mNewColors) {
float a = Color.aToFloat(top);
mNewColors[0] = a * Color.rToFloat(top);
mNewColors[1] = a * Color.gToFloat(top);
mNewColors[2] = a * Color.bToFloat(top);
mNewColors[3] = a;
a = Color.aToFloat(sides);
mNewColors[4] = a * Color.rToFloat(sides);
mNewColors[5] = a * Color.gToFloat(sides);
mNewColors[6] = a * Color.bToFloat(sides);
mNewColors[7] = a;
a = Color.aToFloat(sides);
mNewColors[8] = a * Color.rToFloat(sides);
mNewColors[9] = a * Color.gToFloat(sides);
mNewColors[10] = a * Color.bToFloat(sides);
mNewColors[11] = a;
a = Color.aToFloat(lines);
mNewColors[12] = a * Color.rToFloat(lines);
mNewColors[13] = a * Color.gToFloat(lines);
mNewColors[14] = a * Color.bToFloat(lines);
mNewColors[15] = a;
}
@Override @Override
public void renderWay(Callback renderCallback) { public void renderWay(Callback renderCallback) {
renderCallback.renderExtrusion(this, this.level); renderCallback.renderExtrusion(this, this.level);
} }
private final int level; private final int level;
public final float[] colors;
public final int colorTop; public final int defaultHeight;
public final int colorSide;
public final int colorLine;
} }