bug fix: really clear depth buffer, forgot to enable depth mask

This commit is contained in:
Hannes Janetzek 2012-09-04 20:35:49 +02:00
parent 7647e1827e
commit 32e9d366ac
4 changed files with 31 additions and 38 deletions

View File

@ -18,7 +18,6 @@ import static android.opengl.GLES20.GL_ARRAY_BUFFER;
import static android.opengl.GLES20.GL_BLEND;
import static android.opengl.GLES20.GL_DITHER;
import static android.opengl.GLES20.GL_DYNAMIC_DRAW;
import static android.opengl.GLES20.GL_ONE;
import static android.opengl.GLES20.GL_ONE_MINUS_SRC_ALPHA;
import static android.opengl.GLES20.GL_SCISSOR_TEST;
import static android.opengl.GLES20.GL_SRC_ALPHA;
@ -29,7 +28,6 @@ import static android.opengl.GLES20.glBufferData;
import static android.opengl.GLES20.glClear;
import static android.opengl.GLES20.glClearColor;
import static android.opengl.GLES20.glClearStencil;
import static android.opengl.GLES20.glDepthMask;
import static android.opengl.GLES20.glDisable;
import static android.opengl.GLES20.glEnable;
import static android.opengl.GLES20.glFinish;
@ -602,7 +600,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
return true;
}
private static void setMatrix(GLMapTile tile, float div) {
private static void setMatrix(GLMapTile tile, float div, int offset) {
float x, y, scale;
scale = (float) (2.0 * mDrawPosition.scale / (mHeight * div));
@ -611,6 +609,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
mMVPMatrix[12] = x * scale * mAspect;
mMVPMatrix[13] = -(y + Tile.TILE_SIZE) * scale;
mMVPMatrix[14] = offset * 0.01f;
mMVPMatrix[0] = scale * mAspect / COORD_MULTIPLIER;
mMVPMatrix[5] = scale / COORD_MULTIPLIER;
@ -801,6 +800,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
mUpdateColor = false;
}
GLES20.glDepthMask(true);
glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
if (mInitial)
@ -864,7 +864,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
glEnable(GLES20.GL_POLYGON_OFFSET_FILL);
// glEnable(GLES20.GL_POLYGON_OFFSET_FILL);
for (int i = 0; i < tileCnt; i++) {
if (tiles[i].isVisible && tiles[i].isReady) {
@ -879,14 +879,15 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
drawProxyTile(tiles[i]);
}
}
// GlUtils.checkGlError("end draw");
glDisable(GLES20.GL_POLYGON_OFFSET_FILL);
// glDisable(GLES20.GL_POLYGON_OFFSET_FILL);
glDisable(GLES20.GL_DEPTH_TEST);
mDrawCount = 0;
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GLES20.GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
int z = mDrawPosition.zoomLevel;
float s = mDrawPosition.scale;
@ -906,7 +907,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
if (!tiles[i].isVisible || tiles[i].texture == null)
continue;
setMatrix(tiles[i], 1);
setMatrix(tiles[i], 1, 0);
TextRenderer.drawTile(tiles[i], mMVPMatrix);
}
TextRenderer.endDraw();
@ -929,10 +930,10 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
tile.lastDraw = mRedrawCnt;
setMatrix(tile, div);
setMatrix(tile, div, mDrawCount++);
glBindBuffer(GL_ARRAY_BUFFER, tile.vbo.id);
GLES20.glPolygonOffset(0, mDrawCount);
// GLES20.glPolygonOffset(0, mDrawCount);
LineLayer ll = tile.lineLayers;
PolygonLayer pl = tile.polygonLayers;
@ -968,8 +969,6 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
ll = LineLayers.drawLines(tile, ll, pnext, mMVPMatrix, div, z, s);
}
}
mDrawCount++;
}
private static boolean drawProxyChild(GLMapTile tile) {
@ -1054,7 +1053,7 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
mHeight = height;
mAspect = (float) height / width;
Matrix.orthoM(mProjMatrix, 0, -0.5f / mAspect, 0.5f / mAspect, -0.5f, 0.5f, -1, 1);
// Matrix.orthoM(mProjMatrix, 0, -0.5f / mAspect, 0.5f / mAspect, -0.5f, 0.5f, -1, 1);
glViewport(0, 0, width, height);
@ -1084,10 +1083,10 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GLES20.GL_DEPTH_TEST);
glDepthMask(false);
// GLES20.glDepthRangef(0, 1);
// GLES20.glClearDepthf(1);
// glDisable(GLES20.GL_DEPTH_TEST);
// glDepthMask(false);
// GLES20.glDepthRangef(1, 0);
// GLES20.glClearDepthf(0);
glDisable(GL_DITHER);
@ -1109,8 +1108,8 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// String ext = GLES20.glGetString(GLES20.GL_EXTENSIONS);
// Log.d(TAG, "Extensions: " + ext);
String ext = GLES20.glGetString(GLES20.GL_EXTENSIONS);
Log.d(TAG, "Extensions: " + ext);
shortBuffer = new ShortBuffer[rotateBuffers];
@ -1128,6 +1127,10 @@ public class MapRenderer implements org.mapsforge.android.IMapRenderer {
mFillCoords[6] = max;
mFillCoords[7] = min;
int i[] = new int[1];
// GLES20.glGetIntegerv(GLES20.GL_, i, 0);
Log.d(TAG, " >>>> " + i[0]);
LineLayers.init();
PolygonLayers.init();
}

View File

@ -82,7 +82,7 @@ class PolygonLayers {
// do not modify stencil buffer
glStencilMask(0);
GLES20.glEnable(GLES20.GL_POLYGON_OFFSET_FILL);
// GLES20.glEnable(GLES20.GL_POLYGON_OFFSET_FILL);
for (int c = 0; c < count; c++) {
PolygonLayer l = mFillPolys[c];
@ -193,12 +193,7 @@ class PolygonLayers {
// stencil op for stencil method polygon drawing
glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT);
GLES20.glDisable(GLES20.GL_POLYGON_OFFSET_FILL);
}
//
mFillPolys[cnt] = l;
// set stencil mask to draw to
@ -228,7 +223,6 @@ class PolygonLayers {
}
static void drawDepthClip() {
glColorMask(false, false, false, false);
GLES20.glDepthMask(true);
GLES20.glDepthFunc(GLES20.GL_LESS);

View File

@ -24,7 +24,6 @@ class Shaders {
+ "attribute vec2 a_st;"
+ "varying vec2 v_st;"
+ "uniform float u_width;"
+ "uniform float u_offset;"
+ "const float dscale = 8.0/1000.0;"
+ "void main() {"
+ " vec2 dir = dscale * u_width * a_position.zw;"
@ -76,7 +75,6 @@ class Shaders {
+ "precision mediump float;"
+ "uniform mat4 mvp;"
+ "attribute vec4 a_position;"
+ "uniform float u_offset;"
+ "void main() {"
+ " gl_Position = mvp * a_position;"
+ "}";

View File

@ -25,11 +25,11 @@ public class GlConfigChooser implements GLSurfaceView.EGLConfigChooser {
// Try to find a normal multisample configuration first.
int[] configSpec = {
EGL10.EGL_RED_SIZE, 5,
EGL10.EGL_GREEN_SIZE, 6,
EGL10.EGL_BLUE_SIZE, 5,
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
EGL10.EGL_ALPHA_SIZE, 0,
EGL10.EGL_DEPTH_SIZE, 16,
EGL10.EGL_DEPTH_SIZE, 24,
// Requires that setEGLContextClientVersion(2) is called on the view.
EGL10.EGL_RENDERABLE_TYPE, 4 /* EGL_OPENGL_ES2_BIT */,
// EGL10.EGL_SAMPLE_BUFFERS, 1 /* true */,
@ -50,9 +50,9 @@ public class GlConfigChooser implements GLSurfaceView.EGLConfigChooser {
EGL10.EGL_GREEN_SIZE, 6,
EGL10.EGL_BLUE_SIZE, 5,
EGL10.EGL_ALPHA_SIZE, 0,
EGL10.EGL_DEPTH_SIZE, 16,
EGL10.EGL_DEPTH_SIZE, 24,
EGL10.EGL_RENDERABLE_TYPE, 4 /* EGL_OPENGL_ES2_BIT */,
EGL10.EGL_STENCIL_SIZE, 4,
EGL10.EGL_STENCIL_SIZE, 8,
EGL10.EGL_NONE };
if (!egl.eglChooseConfig(display, configSpec, null, 0, mValue)) {
@ -91,17 +91,15 @@ public class GlConfigChooser implements GLSurfaceView.EGLConfigChooser {
// // break;
// // }
// // else
// if (findConfigAttrib(egl, display, configs[i], EGL10.EGL_RED_SIZE, 0) == 5
// if (findConfigAttrib(egl, display, configs[i], EGL10.EGL_RED_SIZE, 0) == 8
// &&
// findConfigAttrib(egl, display, configs[i], EGL10.EGL_ALPHA_SIZE, 0) == 0
// // &&
// // findConfigAttrib(egl, display, configs[i], EGL10.EGL_DEPTH_SIZE, 0) == 16
// ) {
// &&
// findConfigAttrib(egl, display, configs[i], EGL10.EGL_DEPTH_SIZE, 0) == 24) {
// index = i;
// break;
// }
// }
//
// if (index == -1) {
// Log.w(TAG, "Did not find sane config, using first");
// index = 0;