name clipMode magic-numbers, docs

This commit is contained in:
Hannes Janetzek 2014-03-08 23:38:17 +01:00
parent bd96c018f7
commit 77d33bb02c
2 changed files with 41 additions and 30 deletions

View File

@ -43,18 +43,25 @@ public class VectorTileRenderer extends TileRenderer {
mViewProj.setValue(14, 0); mViewProj.setValue(14, 0);
mViewProj.multiplyRhs(v.view); mViewProj.multiplyRhs(v.view);
mClipMode = 1; mClipMode = PolygonLayer.CLIP_STENCIL;
/* */ /* */
int tileCnt = mDrawTiles.cnt + mProxyTileCnt; int tileCnt = mDrawTiles.cnt + mProxyTileCnt;
MapTile[] tiles = mDrawTiles.tiles; MapTile[] tiles = mDrawTiles.tiles;
boolean drawProxies = false;
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 != READY) { if (t.isVisible && t.state != READY) {
GL.glDepthMask(true); GL.glDepthMask(true);
GL.glClear(GL20.GL_DEPTH_BUFFER_BIT); GL.glClear(GL20.GL_DEPTH_BUFFER_BIT);
mClipMode = 2;
/* always write depth for non-proxy tiles */
GL.glDepthFunc(GL20.GL_ALWAYS);
mClipMode = PolygonLayer.CLIP_DEPTH;
drawProxies = true;
break; break;
} }
} }
@ -71,8 +78,8 @@ public class VectorTileRenderer extends TileRenderer {
* have data yet. Proxies are clipped to the region where nothing * have data yet. Proxies are clipped to the region where nothing
* was drawn to depth buffer. * was drawn to depth buffer.
* TODO draw proxies for placeholder */ * TODO draw proxies for placeholder */
if (mClipMode > 1) { if (drawProxies) {
mClipMode = 3; /* only draw where no other tile is drawn */
GL.glDepthFunc(GL20.GL_LESS); GL.glDepthFunc(GL20.GL_LESS);
/* draw child or parent proxies */ /* draw child or parent proxies */

View File

@ -42,6 +42,9 @@ import org.slf4j.LoggerFactory;
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);
public final static int CLIP_STENCIL = 1;
public final static int CLIP_DEPTH = 2;
private static final float S = MapRenderer.COORD_SCALE; private static final float S = MapRenderer.COORD_SCALE;
private static final boolean enableTexture = true; private static final boolean enableTexture = true;
@ -274,6 +277,7 @@ public final class PolygonLayer extends RenderElement {
* pass true to clear stencil buffer region * pass true to clear stencil buffer region
* @param clipMode * @param clipMode
* clip to first quad in current vbo * clip to first quad in current vbo
* using CLIP_STENCIL / CLIP_DEPTH
* *
* @return * @return
* next layer * next layer
@ -366,47 +370,43 @@ public final class PolygonLayer extends RenderElement {
*/ */
static void drawStencilRegion(boolean first, int clipMode) { static void drawStencilRegion(boolean first, int clipMode) {
// disable drawing to color buffer /* disable drawing to color buffer */
GL.glColorMask(false, false, false, false); GL.glColorMask(false, false, false, false);
// write to all stencil bits /* write to all stencil bits */
GL.glStencilMask(0xFF); GL.glStencilMask(0xFF);
if (first) { if (first) {
// clear previous clip-region from stencil buffer /* Draw clip-region into depth and stencil buffer.
//GL.glClear(GL20.GL_STENCIL_BUFFER_BIT); * This is used for tile line and polygon layers.
*
* Together with depth test (GL_LESS) this ensures to
* only draw where no other tile has drawn yet. */
// Draw clip-region into depth and stencil buffer if (clipMode == CLIP_DEPTH) {
// this is used for tile line and polygon layers. /* test GL_LESS/GL_ALWAYS to write to depth buffer */
// 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);
if (clipMode > 1) {
// test GL_LESS and write to depth buffer
GLState.test(true, true); GLState.test(true, true);
GL.glDepthMask(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 {
// use clip bit from stencil buffer /* use clip bit from stencil buffer to clear stencil
// to clear stencil 'layer-bits' (0x7f) * 'layer-bits' (0x7f) */
GL.glStencilFunc(GL20.GL_EQUAL, CLIP_BIT, CLIP_BIT); GL.glStencilFunc(GL20.GL_EQUAL, CLIP_BIT, CLIP_BIT);
} }
// set clip bit (0x80) for draw region /* set clip bit (0x80) for draw region */
GL.glStencilOp(GL20.GL_KEEP, GL20.GL_KEEP, GL20.GL_REPLACE); GL.glStencilOp(GL20.GL_KEEP, GL20.GL_KEEP, GL20.GL_REPLACE);
// draw a quad for the tile region /* draw a quad for the tile region */
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4); GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4);
if (first) { if (first) {
if (clipMode > 1) { if (clipMode == CLIP_DEPTH) {
// dont modify depth buffer /* dont modify depth buffer */
GL.glDepthMask(false); GL.glDepthMask(false);
// test only stencil
GLState.test(false, true); GLState.test(false, true);
} }
GL.glStencilFunc(GL20.GL_EQUAL, CLIP_BIT, CLIP_BIT); GL.glStencilFunc(GL20.GL_EQUAL, CLIP_BIT, CLIP_BIT);
@ -416,7 +416,7 @@ public final class PolygonLayer extends RenderElement {
/** /**
* Clear stencilbuffer for a tile region by drawing * Clear stencilbuffer for a tile region by drawing
* a quad with func 'always' and op 'zero'. Using 'color' * a quad with func 'always' and op 'zero'. Using 'color'
* and 'alpha' for a fake fade effect. * and 'alpha' to fake a fade effect.
*/ */
public static void drawOver(GLViewport v, int color, float alpha) { public static void drawOver(GLViewport v, int color, float alpha) {
setShader(polyShader, v); setShader(polyShader, v);
@ -425,20 +425,24 @@ public final class PolygonLayer extends RenderElement {
GLUtils.setColor(hPolygonColor[0], color, alpha); GLUtils.setColor(hPolygonColor[0], color, alpha);
GLState.blend(true); GLState.blend(true);
} else { } else {
// disable drawing to framebuffer (will be re-enabled in fill) /* disable drawing to framebuffer (will be re-enabled in fill) */
GL.glColorMask(false, false, false, false); GL.glColorMask(false, false, false, false);
} }
// always pass stencil test:
//glStencilFunc(GL_ALWAYS, 0x00, 0x00); // TODO always pass stencil test: <-- only if not proxy?
//GL.glStencilFunc(GL_ALWAYS, 0x00, 0x00);
GL.glStencilFunc(GL20.GL_EQUAL, CLIP_BIT, CLIP_BIT); GL.glStencilFunc(GL20.GL_EQUAL, CLIP_BIT, CLIP_BIT);
// write to all bits /* write to all bits */
GL.glStencilMask(0xFF); GL.glStencilMask(0xFF);
// zero out area to draw to
/* zero out area to draw to */
GL.glStencilOp(GL20.GL_KEEP, GL20.GL_KEEP, GL20.GL_ZERO); GL.glStencilOp(GL20.GL_KEEP, GL20.GL_KEEP, GL20.GL_ZERO);
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4); GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4);
// FIXME needed here?
if (color == 0) if (color == 0)
GL.glColorMask(true, true, true, true); GL.glColorMask(true, true, true, true);
} }