reworking the gl projection/unprojection stuff

This commit is contained in:
Hannes Janetzek
2013-01-10 06:56:25 +01:00
parent dd3c0a71c3
commit 80de20a423
3 changed files with 146 additions and 58 deletions

View File

@@ -68,7 +68,8 @@ public class BaseLayer {
}
GLES20.glDisable(GL_POLYGON_OFFSET_FILL);
//GLES20.glFinish()
//Log.d(TAG, "building took " + (end - start));
mDrawSerial++;
}
@@ -90,18 +91,18 @@ public class BaseLayer {
if (tile.layers == null)
return;
GLES20.glPolygonOffset(0, GLRenderer.depthOffset(tile));
// set depth offset (used for clipping to tile boundaries)
GLES20.glPolygonOffset(-1, -GLRenderer.depthOffset(tile));
GLES20.glBindBuffer(GL_ARRAY_BUFFER, tile.vbo.id);
boolean clipped = false;
int simpleShader = 0; // mRotate ? 0 : 1;
int simpleShader = (pos.tilt == 0 ? 1 : 0);
for (Layer l = tile.layers.layers; l != null;) {
switch (l.type) {
case Layer.POLYGON:
GLES20.glDisable(GL_BLEND);
l = PolygonRenderer.draw(pos, l, mvp, !clipped, true);
clipped = true;
@@ -114,6 +115,7 @@ public class BaseLayer {
}
// clip lines to quad in depth buffer
GLState.test(true, false);
GLES20.glEnable(GL_BLEND);
l = LineRenderer.draw(pos, l, mvp, div, simpleShader,
tile.layers.lineOffset);
@@ -138,7 +140,6 @@ public class BaseLayer {
float y = (float) (tile.pixelY - pos.y * div);
float scale = pos.scale / div;
//Matrix.setIdentityM(matrix, 0);
for (int i = 0; i < 16; i++)
matrix[i] = 0;
@@ -153,8 +154,6 @@ public class BaseLayer {
matrix[10] = 1;
matrix[15] = 1;
// Matrix.multiplyMM(matrix, 0, pos.viewMatrix, 0, matrix, 0);
// Matrix.multiplyMM(matrix, 0, mfProjMatrix, 0, matrix, 0);
Matrix.multiplyMM(matrix, 0, mVPMatrix, 0, matrix, 0);
}

View File

@@ -494,7 +494,9 @@ public class GLRenderer implements GLSurfaceView.Renderer {
}
if (debugView) {
float mm = 0.5f;
GLState.test(false, false);
float mm = 0.25f; // * mHeight;
float min = -mm;
float max = mm;
float ymax = mm * mHeight / mWidth;
@@ -511,10 +513,12 @@ public class GLRenderer implements GLSurfaceView.Renderer {
pos.zoomLevel = -1;
mMapViewPosition.getMapPosition(pos, mDebugCoords);
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0,
pos.viewMatrix, 0);
PolygonRenderer.debugDraw(mMVPMatrix, mDebugCoords, 1);
}
if (GlUtils.checkGlOutOfMemory("finish")) {
@@ -524,7 +528,7 @@ public class GLRenderer implements GLSurfaceView.Renderer {
}
public static int depthOffset(MapTile t) {
return ((t.tileX % 4) + (t.tileY % 4 * 4) * 2) * 20;
return ((t.tileX % 4) + (t.tileY % 4 * 4) + 1);
}
@Override
@@ -547,16 +551,16 @@ public class GLRenderer implements GLSurfaceView.Renderer {
MapViewPosition.VIEW_FAR);
Matrix.setIdentityM(mTmpMatrix, 0);
Matrix.translateM(mTmpMatrix, 0, 0, 0, -MapViewPosition.VIEW_DISTANCE * 2);
Matrix.translateM(mTmpMatrix, 0, 0, 0, -MapViewPosition.VIEW_DISTANCE);
Matrix.multiplyMM(mProjMatrix, 0, mProjMatrix, 0, mTmpMatrix, 0);
if (debugView) {
// modify this to scale only the view, to see better which tiles are
// rendered
Matrix.setIdentityM(mMVPMatrix, 0);
Matrix.scaleM(mMVPMatrix, 0, 0.5f, 0.5f, 1);
Matrix.multiplyMM(mProjMatrix, 0, mMVPMatrix, 0, mProjMatrix, 0);
}
// if (debugView) {
// // modify this to scale only the view, to see better which tiles are
// // rendered
// Matrix.setIdentityM(mMVPMatrix, 0);
// Matrix.scaleM(mMVPMatrix, 0, 0.75f, 0.75f, 1);
// Matrix.multiplyMM(mProjMatrix, 0, mMVPMatrix, 0, mProjMatrix, 0);
// }
BaseLayer.setProjection(mProjMatrix);
@@ -578,17 +582,11 @@ public class GLRenderer implements GLSurfaceView.Renderer {
int numVBO = (CACHE_TILES + (numTiles * 2));
BufferObject.init(numVBO);
// Set up textures
// TextRenderer.setup(numTiles);
if (mClearColor != null)
mUpdateColor = true;
GLState.init();
//vertexArray[0] = false;
//vertexArray[1] = false;
mMapView.redrawMap();
}