remove depth-buffer tile clipping
not needed anymore, yay!
This commit is contained in:
parent
a0111e09b7
commit
f5c162330a
@ -39,7 +39,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special Renderer for drawing tile polygons
|
* Special Renderer for drawing tile polygons using a stencil buffer method
|
||||||
*/
|
*/
|
||||||
public final class PolygonLayer extends RenderElement {
|
public final class PolygonLayer extends RenderElement {
|
||||||
static final Logger log = LoggerFactory.getLogger(PolygonLayer.class);
|
static final Logger log = LoggerFactory.getLogger(PolygonLayer.class);
|
||||||
@ -260,8 +260,9 @@ public final class PolygonLayer extends RenderElement {
|
|||||||
|
|
||||||
GLState.enableVertexArrays(hPolygonVertexPosition[shader], -1);
|
GLState.enableVertexArrays(hPolygonVertexPosition[shader], -1);
|
||||||
|
|
||||||
GL.glVertexAttribPointer(hPolygonVertexPosition[shader], 2, GL20.GL_SHORT,
|
GL.glVertexAttribPointer(hPolygonVertexPosition[shader], 2,
|
||||||
false, 0, POLYGON_VERTICES_DATA_POS_OFFSET);
|
GL20.GL_SHORT, false, 0,
|
||||||
|
POLYGON_VERTICES_DATA_POS_OFFSET);
|
||||||
|
|
||||||
m.mvp.setAsUniform(hPolygonMatrix[shader]);
|
m.mvp.setAsUniform(hPolygonMatrix[shader]);
|
||||||
}
|
}
|
||||||
@ -374,14 +375,6 @@ public final class PolygonLayer extends RenderElement {
|
|||||||
*/
|
*/
|
||||||
static void drawStencilRegion(boolean first) {
|
static void drawStencilRegion(boolean first) {
|
||||||
|
|
||||||
// if (!first) {
|
|
||||||
// GL.glStencilMask(0x7F);
|
|
||||||
// GL.glClear(GL20.GL_STENCIL_BUFFER_BIT);
|
|
||||||
// // disable drawing to color buffer
|
|
||||||
// GL.glColorMask(false, false, false, false);
|
|
||||||
// GL.glStencilFunc(GL_EQUAL, CLIP_BIT, CLIP_BIT);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// disable drawing to color buffer
|
// disable drawing to color buffer
|
||||||
GL.glColorMask(false, false, false, false);
|
GL.glColorMask(false, false, false, false);
|
||||||
|
|
||||||
@ -389,20 +382,6 @@ public final class PolygonLayer extends RenderElement {
|
|||||||
GL.glStencilMask(0xFF);
|
GL.glStencilMask(0xFF);
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
// clear previous clip-region from stencil buffer
|
|
||||||
//GL.glClear(GL20.GL_STENCIL_BUFFER_BIT);
|
|
||||||
|
|
||||||
// Draw clip-region into depth and stencil buffer
|
|
||||||
// this is used for tile line and polygon layers.
|
|
||||||
// Depth offset is increased for each tile. Together
|
|
||||||
// with depth test (GL_LESS) this ensures to only
|
|
||||||
// draw where no other tile has drawn yet.
|
|
||||||
GL.glEnable(GL20.GL_POLYGON_OFFSET_FILL);
|
|
||||||
|
|
||||||
// test GL_LESS and write to depth buffer
|
|
||||||
GLState.test(true, true);
|
|
||||||
GL.glDepthMask(true);
|
|
||||||
|
|
||||||
// always pass stencil test and set clip bit
|
// always pass stencil test and set clip bit
|
||||||
GL.glStencilFunc(GL20.GL_ALWAYS, CLIP_BIT, 0x00);
|
GL.glStencilFunc(GL20.GL_ALWAYS, CLIP_BIT, 0x00);
|
||||||
} else {
|
} else {
|
||||||
@ -418,25 +397,18 @@ public final class PolygonLayer extends RenderElement {
|
|||||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4);
|
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
// dont modify depth buffer
|
|
||||||
GL.glDepthMask(false);
|
|
||||||
// test only stencil
|
|
||||||
GLState.test(false, true);
|
|
||||||
|
|
||||||
GL.glDisable(GL20.GL_POLYGON_OFFSET_FILL);
|
|
||||||
|
|
||||||
GL.glStencilFunc(GL20.GL_EQUAL, CLIP_BIT, CLIP_BIT);
|
GL.glStencilFunc(GL20.GL_EQUAL, CLIP_BIT, CLIP_BIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear stencilbuffer for a tile region by drawing
|
||||||
|
* a quad with func 'always' and op 'zero'. Using 'color'
|
||||||
|
* and 'alpha' for a fake fade effect.
|
||||||
|
*/
|
||||||
public static void drawOver(Matrices m, int color, float alpha) {
|
public static void drawOver(Matrices m, int color, float alpha) {
|
||||||
setShader(polyShader, m);
|
setShader(polyShader, m);
|
||||||
|
|
||||||
/*
|
|
||||||
* clear stencilbuffer (tile region) by drawing
|
|
||||||
* a quad with func 'always' and op 'zero'
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (color != 0) {
|
if (color != 0) {
|
||||||
GLUtils.setColor(hPolygonColor[0], color, alpha);
|
GLUtils.setColor(hPolygonColor[0], color, alpha);
|
||||||
GLState.blend(true);
|
GLState.blend(true);
|
||||||
|
|||||||
@ -25,7 +25,6 @@ import org.oscim.core.MapPosition;
|
|||||||
import org.oscim.core.Tile;
|
import org.oscim.core.Tile;
|
||||||
import org.oscim.renderer.BufferObject;
|
import org.oscim.renderer.BufferObject;
|
||||||
import org.oscim.renderer.ElementRenderer;
|
import org.oscim.renderer.ElementRenderer;
|
||||||
import org.oscim.renderer.GLMatrix;
|
|
||||||
import org.oscim.renderer.LayerRenderer;
|
import org.oscim.renderer.LayerRenderer;
|
||||||
import org.oscim.renderer.MapRenderer;
|
import org.oscim.renderer.MapRenderer;
|
||||||
import org.oscim.renderer.MapRenderer.Matrices;
|
import org.oscim.renderer.MapRenderer.Matrices;
|
||||||
@ -361,15 +360,10 @@ public class TileRenderer extends LayerRenderer {
|
|||||||
return maxFade;
|
return maxFade;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Counter increases polygon-offset for each tile drawn.
|
|
||||||
private int mOffsetCnt;
|
|
||||||
|
|
||||||
// Current number of frames drawn, used to not draw a
|
// Current number of frames drawn, used to not draw a
|
||||||
// tile twice per frame.
|
// tile twice per frame.
|
||||||
private int mDrawSerial = 0;
|
private int mDrawSerial = 0;
|
||||||
|
|
||||||
private Matrices mMatrices;
|
private Matrices mMatrices;
|
||||||
private final GLMatrix mProjMatrix = new GLMatrix();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw tiles:
|
* Draw tiles:
|
||||||
@ -381,33 +375,23 @@ public class TileRenderer extends LayerRenderer {
|
|||||||
*/
|
*/
|
||||||
private void draw(MapTile[] tiles, int tileCnt, MapPosition pos, Matrices m) {
|
private void draw(MapTile[] tiles, int tileCnt, MapPosition pos, Matrices m) {
|
||||||
|
|
||||||
mOffsetCnt = -2048;
|
|
||||||
mMatrices = m;
|
mMatrices = m;
|
||||||
|
|
||||||
mProjMatrix.copy(m.proj);
|
/** draw visible tiles */
|
||||||
// discard depth projection from tilt, we use depth buffer
|
|
||||||
// for clipping
|
|
||||||
mProjMatrix.setValue(10, 0);
|
|
||||||
mProjMatrix.setValue(14, 0);
|
|
||||||
mProjMatrix.multiplyRhs(m.view);
|
|
||||||
|
|
||||||
GL.glDepthMask(true);
|
|
||||||
GL.glClear(GL20.GL_DEPTH_BUFFER_BIT);
|
|
||||||
GL.glDepthFunc(GL20.GL_LESS);
|
|
||||||
|
|
||||||
// Draw visible tiles
|
|
||||||
for (int i = 0; i < tileCnt; i++) {
|
for (int i = 0; i < tileCnt; i++) {
|
||||||
MapTile t = tiles[i];
|
MapTile t = tiles[i];
|
||||||
if (t.isVisible && t.state == STATE_READY)
|
if (t.isVisible && t.state == STATE_READY)
|
||||||
drawTile(t, pos);
|
drawTile(t, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* draw parent or children as proxy for visibile tiles that dont
|
||||||
|
* have data yet. Proxies are clipped to the region where nothing
|
||||||
|
* was drawn to depth buffer.
|
||||||
|
* TODO draw proxies for placeholder
|
||||||
|
*/
|
||||||
double scale = pos.getZoomScale();
|
double scale = pos.getZoomScale();
|
||||||
|
|
||||||
// Draw parent or children as proxy for visibile tiles that dont
|
|
||||||
// have data yet. Proxies are clipped to the region where nothing
|
|
||||||
// was drawn to depth buffer.
|
|
||||||
// TODO draw proxies for placeholder
|
|
||||||
for (int i = 0; i < tileCnt; i++) {
|
for (int i = 0; i < tileCnt; i++) {
|
||||||
MapTile t = tiles[i];
|
MapTile t = tiles[i];
|
||||||
if (t.isVisible && (t.state != STATE_READY) && (t.holder == null)) {
|
if (t.isVisible && (t.state != STATE_READY) && (t.holder == null)) {
|
||||||
@ -416,20 +400,18 @@ public class TileRenderer extends LayerRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw grandparents
|
/** draw grandparents */
|
||||||
for (int i = 0; i < tileCnt; i++) {
|
for (int i = 0; i < tileCnt; i++) {
|
||||||
MapTile t = tiles[i];
|
MapTile t = tiles[i];
|
||||||
if (t.isVisible && (t.state != STATE_READY) && (t.holder == null))
|
if (t.isVisible && (t.state != STATE_READY) && (t.holder == null))
|
||||||
drawProxyTile(t, pos, false, false);
|
drawProxyTile(t, pos, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure stencil buffer write is disabled
|
/** make sure stencil buffer write is disabled */
|
||||||
GL.glStencilMask(0x00);
|
GL.glStencilMask(0x00);
|
||||||
GL.glDepthMask(false);
|
GL.glDepthMask(false);
|
||||||
|
|
||||||
mDrawSerial++;
|
mDrawSerial++;
|
||||||
|
|
||||||
// clear reference
|
|
||||||
mMatrices = null;
|
mMatrices = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,10 +447,7 @@ public class TileRenderer extends LayerRenderer {
|
|||||||
|
|
||||||
Matrices m = mMatrices;
|
Matrices m = mMatrices;
|
||||||
m.mvp.setTransScale(x, y, scale / MapRenderer.COORD_SCALE);
|
m.mvp.setTransScale(x, y, scale / MapRenderer.COORD_SCALE);
|
||||||
m.mvp.multiplyLhs(mProjMatrix);
|
m.mvp.multiplyLhs(m.viewproj);
|
||||||
|
|
||||||
// set depth offset (used for clipping to tile boundaries)
|
|
||||||
GL.glPolygonOffset(0, mOffsetCnt++);
|
|
||||||
|
|
||||||
boolean clipped = false;
|
boolean clipped = false;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user