rename ExtrusionLayer public fields

This commit is contained in:
Hannes Janetzek 2014-03-20 16:22:13 +01:00
parent c2112d68aa
commit eb41496c5a
2 changed files with 104 additions and 96 deletions

View File

@ -136,7 +136,7 @@ public class ExtrusionRenderer extends LayerRenderer {
continue; continue;
if (!el.compiled) { if (!el.compiled) {
int numShorts = el.mNumVertices * 8; int numShorts = el.sumVertices * 8;
el.compile(MapRenderer.getShortBuffer(numShorts)); el.compile(MapRenderer.getShortBuffer(numShorts));
GLUtils.checkGlError("..."); GLUtils.checkGlError("...");
} }
@ -160,7 +160,7 @@ public class ExtrusionRenderer extends LayerRenderer {
continue; continue;
if (!el.compiled) { if (!el.compiled) {
int numShorts = el.mNumVertices * 8; int numShorts = el.sumVertices * 8;
el.compile(MapRenderer.getShortBuffer(numShorts)); el.compile(MapRenderer.getShortBuffer(numShorts));
GLUtils.checkGlError("..."); GLUtils.checkGlError("...");
} }
@ -266,12 +266,12 @@ public class ExtrusionRenderer extends LayerRenderer {
GL20.GL_UNSIGNED_BYTE, false, 8, 6); GL20.GL_UNSIGNED_BYTE, false, 8, 6);
GL.glDrawElements(GL20.GL_TRIANGLES, GL.glDrawElements(GL20.GL_TRIANGLES,
(el.mIndiceCnt[0] + el.mIndiceCnt[1] + el.mIndiceCnt[2]), (el.numIndices[0] + el.numIndices[1] + el.numIndices[2]),
GL20.GL_UNSIGNED_SHORT, 0); GL20.GL_UNSIGNED_SHORT, 0);
GL.glDrawElements(GL20.GL_LINES, el.mIndiceCnt[3], GL.glDrawElements(GL20.GL_LINES, el.numIndices[3],
GL20.GL_UNSIGNED_SHORT, GL20.GL_UNSIGNED_SHORT,
(el.mIndiceCnt[0] + el.mIndiceCnt[1] + el.mIndiceCnt[2]) * 2); (el.numIndices[0] + el.numIndices[1] + el.numIndices[2]) * 2);
// just a temporary reference! // just a temporary reference!
tiles[i] = null; tiles[i] = null;
@ -305,20 +305,23 @@ public class ExtrusionRenderer extends LayerRenderer {
// draw to depth buffer // draw to depth buffer
for (int i = 0; i < mTileCnt; i++) { for (int i = 0; i < mTileCnt; i++) {
MapTile t = tiles[i]; MapTile t = tiles[i];
ExtrusionLayer el = t.getLayers().getExtrusionLayers(); ExtrusionLayer el = t.getLayers().getExtrusionLayers();
int d = MapTile.depthOffset(t) * 10; for (; el != null; el = (ExtrusionLayer) el.next) {
setMatrix(v, t, d); int d = MapTile.depthOffset(t) * 10;
v.mvp.setAsUniform(uExtMatrix); setMatrix(v, t, d);
v.mvp.setAsUniform(uExtMatrix);
el.vboIndices.bind(); el.vboIndices.bind();
el.vboVertices.bind(); el.vboVertices.bind();
GL.glVertexAttribPointer(uExtVertexPosition, 3, GL.glVertexAttribPointer(uExtVertexPosition, 3,
GL20.GL_SHORT, false, 8, 0); GL20.GL_SHORT, false, 8, 0);
GL.glDrawElements(GL20.GL_TRIANGLES, GL.glDrawElements(GL20.GL_TRIANGLES,
(el.mIndiceCnt[0] + el.mIndiceCnt[1] + el.mIndiceCnt[2]), (el.numIndices[0] + el.numIndices[1] + el.numIndices[2]),
GL20.GL_UNSIGNED_SHORT, 0); GL20.GL_UNSIGNED_SHORT, 0);
}
} }
GL.glColorMask(true, true, true, true); GL.glColorMask(true, true, true, true);
@ -333,75 +336,80 @@ public class ExtrusionRenderer extends LayerRenderer {
for (int i = 0; i < mTileCnt; i++) { for (int i = 0; i < mTileCnt; i++) {
MapTile t = tiles[i]; MapTile t = tiles[i];
ExtrusionLayer el = t.getLayers().getExtrusionLayers(); ExtrusionLayer el = t.getLayers().getExtrusionLayers();
for (; el != null; el = (ExtrusionLayer) el.next) {
if (el.colors == null) { if (el.colors == null) {
currentColor = mColor; currentColor = mColor;
GLUtils.glUniform4fv(uExtColor, 4, currentColor); GLUtils.glUniform4fv(uExtColor, 4, currentColor);
} else if (currentColor != el.colors) { } else if (currentColor != el.colors) {
currentColor = el.colors; currentColor = el.colors;
GLUtils.glUniform4fv(uExtColor, 4, currentColor); GLUtils.glUniform4fv(uExtColor, 4, currentColor);
}
int d = 1;
if (drawAlpha) {
GL.glDepthFunc(GL20.GL_EQUAL);
d = MapTile.depthOffset(t) * 10;
}
setMatrix(v, t, d);
v.mvp.setAsUniform(uExtMatrix);
el.vboIndices.bind();
el.vboVertices.bind();
GL.glVertexAttribPointer(uExtVertexPosition, 3,
GL20.GL_SHORT, false, 8, 0);
GL.glVertexAttribPointer(uExtLightPosition, 2,
GL20.GL_UNSIGNED_BYTE, false, 8, 6);
// draw extruded outlines
if (el.mIndiceCnt[0] > 0) {
// draw roof
GL.glUniform1i(uExtMode, 0);
GL.glDrawElements(GL20.GL_TRIANGLES, el.mIndiceCnt[2],
GL20.GL_UNSIGNED_SHORT,
(el.mIndiceCnt[0] + el.mIndiceCnt[1]) * 2);
// draw sides 1
GL.glUniform1i(uExtMode, 1);
GL.glDrawElements(GL20.GL_TRIANGLES, el.mIndiceCnt[0],
GL20.GL_UNSIGNED_SHORT, 0);
// draw sides 2
GL.glUniform1i(uExtMode, 2);
GL.glDrawElements(GL20.GL_TRIANGLES, el.mIndiceCnt[1],
GL20.GL_UNSIGNED_SHORT, el.mIndiceCnt[0] * 2);
if (drawAlpha) {
// drawing gl_lines with the same coordinates does not result in
// same depth values as polygons, so add offset and draw gl_lequal:
GL.glDepthFunc(GL20.GL_LEQUAL);
} }
v.mvp.addDepthOffset(100); int d = 1;
if (drawAlpha) {
GL.glDepthFunc(GL20.GL_EQUAL);
d = MapTile.depthOffset(t) * 10;
}
setMatrix(v, t, d);
v.mvp.setAsUniform(uExtMatrix); v.mvp.setAsUniform(uExtMatrix);
GL.glUniform1i(uExtMode, 3); el.vboIndices.bind();
GL.glDrawElements(GL20.GL_LINES, el.mIndiceCnt[3], el.vboVertices.bind();
GL20.GL_UNSIGNED_SHORT,
(el.mIndiceCnt[0] + el.mIndiceCnt[1] + el.mIndiceCnt[2]) * 2);
}
// draw triangle meshes GL.glVertexAttribPointer(uExtVertexPosition, 3,
if (el.mIndiceCnt[4] > 0) { GL20.GL_SHORT, false, 8, 0);
int offset = (el.mIndiceCnt[0] + el.mIndiceCnt[1]
+ el.mIndiceCnt[2] + el.mIndiceCnt[3]) * 2;
GL.glUniform1i(uExtMode, 4); GL.glVertexAttribPointer(uExtLightPosition, 2,
GL.glDrawElements(GL20.GL_TRIANGLES, el.mIndiceCnt[4], GL20.GL_UNSIGNED_BYTE, false, 8, 6);
GL20.GL_UNSIGNED_SHORT, offset);
/* draw extruded outlines */
if (el.numIndices[0] > 0) {
/* draw roof */
GL.glUniform1i(uExtMode, 0);
GL.glDrawElements(GL20.GL_TRIANGLES, el.numIndices[2],
GL20.GL_UNSIGNED_SHORT,
(el.numIndices[0] + el.numIndices[1]) * 2);
/* draw sides 1 */
GL.glUniform1i(uExtMode, 1);
GL.glDrawElements(GL20.GL_TRIANGLES, el.numIndices[0],
GL20.GL_UNSIGNED_SHORT, 0);
/* draw sides 2 */
GL.glUniform1i(uExtMode, 2);
GL.glDrawElements(GL20.GL_TRIANGLES, el.numIndices[1],
GL20.GL_UNSIGNED_SHORT, el.numIndices[0] * 2);
if (drawAlpha) {
/* drawing gl_lines with the same coordinates does not
* result in same depth values as polygons, so add
* offset and draw gl_lequal: */
GL.glDepthFunc(GL20.GL_LEQUAL);
}
v.mvp.addDepthOffset(100);
v.mvp.setAsUniform(uExtMatrix);
GL.glUniform1i(uExtMode, 3);
GL.glDrawElements(GL20.GL_LINES, el.numIndices[3],
GL20.GL_UNSIGNED_SHORT,
(el.numIndices[0] + el.numIndices[1]
+ el.numIndices[2]) * 2);
}
/* draw triangle meshes */
if (el.numIndices[4] > 0) {
int offset = (el.numIndices[0] + el.numIndices[1]
+ el.numIndices[2] + el.numIndices[3]) * 2;
GL.glUniform1i(uExtMode, 4);
GL.glDrawElements(GL20.GL_TRIANGLES, el.numIndices[4],
GL20.GL_UNSIGNED_SHORT, offset);
}
} }
// just a temporary reference! // just a temporary reference!
tiles[i] = null; tiles[i] = null;
@ -557,12 +565,12 @@ public class ExtrusionRenderer extends LayerRenderer {
// recreate face normal vector // recreate face normal vector
///+ " vec3 r_norm = vec3(n.xy, dir * (1.0 - length(n.xy)));" ///+ " vec3 r_norm = vec3(n.xy, dir * (1.0 - length(n.xy)));"
+ " vec3 light = normalize(vec3(-0.4,0.4,1.0));" + " vec3 light = normalize(vec3(-0.2,0.2,1.0));"
+ " float l = (1.0 + dot(r_norm, light)) / 2.0;" + " float l = (1.0 + dot(r_norm, light)) / 2.0;"
/** ambient */ /** ambient */
//+ " l = 0.2 + l * 0.8;" //+ " l = 0.2 + l * 0.8;"
/** fake-ssao by height */ /** extreme fake-ssao by height */
+ " l = l + (clamp(a_pos.z / 8192.0, 0.0, 0.1) - 0.05);" + " l = l + (clamp(a_pos.z / 8192.0, 0.0, 0.1) - 0.05);"
+ " color = vec4(l, l, l-0.02, 1.0);" + " color = vec4(l, l, l-0.02, 1.0);"
+ "}}}"; + "}}}";

View File

@ -52,9 +52,9 @@ public class ExtrusionLayer extends RenderElement {
// 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, 0 }; public int numIndices[] = { 0, 0, 0, 0, 0 };
public int mNumIndices = 0; public int sumIndices = 0;
public int mNumVertices = 0; public int sumVertices = 0;
public BufferObject vboIndices; public BufferObject vboIndices;
public BufferObject vboVertices; public BufferObject vboVertices;
@ -98,7 +98,7 @@ public class ExtrusionLayer extends RenderElement {
// roof indices for convex shapes // roof indices for convex shapes
int i = mCurIndices[IND_MESH].used; int i = mCurIndices[IND_MESH].used;
short[] indices = mCurIndices[IND_MESH].vertices; short[] indices = mCurIndices[IND_MESH].vertices;
int first = mNumVertices; int first = sumVertices;
short[] vertices = mCurVertices.vertices; short[] vertices = mCurVertices.vertices;
int v = mCurVertices.used; int v = mCurVertices.used;
@ -110,7 +110,7 @@ public class ExtrusionLayer extends RenderElement {
break; break;
// FIXME: workaround: dont overflow max index id. // FIXME: workaround: dont overflow max index id.
if (mNumVertices + vertexCnt >= 1 << 16) if (sumVertices + vertexCnt >= 1 << 16)
break; break;
if (i == VertexItem.SIZE) { if (i == VertexItem.SIZE) {
@ -196,7 +196,7 @@ public class ExtrusionLayer extends RenderElement {
mCurIndices[IND_MESH].used = i; mCurIndices[IND_MESH].used = i;
mCurVertices.used = v; mCurVertices.used = v;
mNumVertices += vertexCnt; //(vertexCnt / 3); sumVertices += vertexCnt; //(vertexCnt / 3);
} }
// private void encodeNormal(float v[], int offset) { // private void encodeNormal(float v[], int offset) {
@ -218,7 +218,7 @@ public class ExtrusionLayer extends RenderElement {
//log.debug("add " + Arrays.toString(points)); //log.debug("add " + Arrays.toString(points));
// current vertex id // current vertex id
int startVertex = mNumVertices; int startVertex = sumVertices;
// roof indices for convex shapes // roof indices for convex shapes
int i = mCurIndices[IND_MESH].used; int i = mCurIndices[IND_MESH].used;
@ -264,7 +264,7 @@ public class ExtrusionLayer extends RenderElement {
} }
mCurVertices.used = v; mCurVertices.used = v;
mNumVertices += (vertexCnt / 3); sumVertices += (vertexCnt / 3);
} }
public void add(MapElement element, float height, float minHeight) { public void add(MapElement element, float height, float minHeight) {
@ -286,7 +286,7 @@ public class ExtrusionLayer extends RenderElement {
boolean simpleOutline = true; boolean simpleOutline = true;
// current vertex id // current vertex id
int startVertex = mNumVertices; int startVertex = sumVertices;
int length = 0, ipos = 0, ppos = 0; int length = 0, ipos = 0, ppos = 0;
for (int n = index.length; ipos < n; ipos++, ppos += length) { for (int n = index.length; ipos < n; ipos++, ppos += length) {
@ -298,7 +298,7 @@ public class ExtrusionLayer extends RenderElement {
// start next polygon // start next polygon
if (length == 0) { if (length == 0) {
startVertex = mNumVertices; startVertex = sumVertices;
simpleOutline = true; simpleOutline = true;
complexOutline = false; complexOutline = false;
continue; continue;
@ -404,7 +404,7 @@ public class ExtrusionLayer extends RenderElement {
int angleSign = 0; int angleSign = 0;
// vertex offset for all vertices in layer // vertex offset for all vertices in layer
int vOffset = mNumVertices; int vOffset = sumVertices;
short[] vertices = mCurVertices.vertices; short[] vertices = mCurVertices.vertices;
int v = mCurVertices.used; int v = mCurVertices.used;
@ -542,28 +542,28 @@ public class ExtrusionLayer extends RenderElement {
} }
mCurVertices.used = v; mCurVertices.used = v;
mNumVertices += vertexCnt; sumVertices += vertexCnt;
return convex; return convex;
} }
@Override @Override
public void compile(ShortBuffer sbuf) { public void compile(ShortBuffer sbuf) {
if (mNumVertices == 0 || compiled) if (sumVertices == 0 || compiled)
return; return;
mNumIndices = 0; sumIndices = 0;
for (int i = 0; i <= IND_MESH; i++) { for (int i = 0; i <= IND_MESH; i++) {
for (VertexItem vi = mIndices[i]; vi != null; vi = vi.next) { for (VertexItem vi = mIndices[i]; vi != null; vi = vi.next) {
sbuf.put(vi.vertices, 0, vi.used); sbuf.put(vi.vertices, 0, vi.used);
mIndiceCnt[i] += vi.used; numIndices[i] += vi.used;
} }
mNumIndices += mIndiceCnt[i]; sumIndices += numIndices[i];
} }
//log.debug("compile" + mNumIndices + " / " + mNumVertices); //log.debug("compile" + mNumIndices + " / " + mNumVertices);
int size = mNumIndices * 2; int size = sumIndices * 2;
vboIndices = BufferObject.get(GL20.GL_ELEMENT_ARRAY_BUFFER, size); vboIndices = BufferObject.get(GL20.GL_ELEMENT_ARRAY_BUFFER, size);
vboIndices.loadBufferData(sbuf.flip(), size); vboIndices.loadBufferData(sbuf.flip(), size);
@ -575,7 +575,7 @@ public class ExtrusionLayer extends RenderElement {
for (VertexItem vi = mVertices; vi != null; vi = vi.next) for (VertexItem vi = mVertices; vi != null; vi = vi.next)
sbuf.put(vi.vertices, 0, vi.used); sbuf.put(vi.vertices, 0, vi.used);
size = mNumVertices * 4 * 2; size = sumVertices * 4 * 2;
vboVertices = BufferObject.get(GL20.GL_ARRAY_BUFFER, size); vboVertices = BufferObject.get(GL20.GL_ARRAY_BUFFER, size);
vboVertices.loadBufferData(sbuf.flip(), size); vboVertices.loadBufferData(sbuf.flip(), size);