refactor: utils.GlUtils -> renderer.GLUtils, utils.Matrix4 -> renderer.GLMatrix
- init 'GL' handle of rendering classes in MapRenderer.onSurfaceCreated, at this point handle is safe to use, i.e. GL context is available - all LayerRenderer share one static 'GL' field now
This commit is contained in:
parent
83a276becf
commit
7dde869f4a
@ -15,19 +15,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
package org.oscim.utils;
|
package org.oscim.renderer;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
|
|
||||||
|
public class GLMatrix {
|
||||||
public class Matrix4 {
|
|
||||||
|
|
||||||
private static GL20 GL = GLAdapter.get();
|
|
||||||
|
|
||||||
public static final int M00 = 0;// 0;
|
public static final int M00 = 0;// 0;
|
||||||
public static final int M01 = 4;// 1;
|
public static final int M01 = 4;// 1;
|
||||||
@ -96,7 +91,7 @@ public class Matrix4 {
|
|||||||
*
|
*
|
||||||
* @param mat Matrix to copy
|
* @param mat Matrix to copy
|
||||||
*/
|
*/
|
||||||
public void copy(Matrix4 m) {
|
public void copy(GLMatrix m) {
|
||||||
if (m == null || m.val.length != 16)
|
if (m == null || m.val.length != 16)
|
||||||
throw new IllegalArgumentException(INVALID_INPUT);
|
throw new IllegalArgumentException(INVALID_INPUT);
|
||||||
|
|
||||||
@ -130,7 +125,7 @@ public class Matrix4 {
|
|||||||
*
|
*
|
||||||
* @param rhs right hand side
|
* @param rhs right hand side
|
||||||
*/
|
*/
|
||||||
public void multiplyRhs(Matrix4 rhs) {
|
public void multiplyRhs(GLMatrix rhs) {
|
||||||
matrix4_mul(val, rhs.val);
|
matrix4_mul(val, rhs.val);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +134,7 @@ public class Matrix4 {
|
|||||||
*
|
*
|
||||||
* @param lhs right hand side
|
* @param lhs right hand side
|
||||||
*/
|
*/
|
||||||
public void multiplyLhs(Matrix4 lhs) {
|
public void multiplyLhs(GLMatrix lhs) {
|
||||||
System.arraycopy(lhs.val, 0, tmp, 0, 16);
|
System.arraycopy(lhs.val, 0, tmp, 0, 16);
|
||||||
matrix4_mul(tmp, val);
|
matrix4_mul(tmp, val);
|
||||||
System.arraycopy(tmp, 0, val, 0, 16);
|
System.arraycopy(tmp, 0, val, 0, 16);
|
||||||
@ -156,7 +151,7 @@ public class Matrix4 {
|
|||||||
* @param lhs left hand side
|
* @param lhs left hand side
|
||||||
* @param rhs right hand side
|
* @param rhs right hand side
|
||||||
*/
|
*/
|
||||||
public void multiplyMM(Matrix4 lhs, Matrix4 rhs) {
|
public void multiplyMM(GLMatrix lhs, GLMatrix rhs) {
|
||||||
System.arraycopy(lhs.val, 0, tmp, 0, 16);
|
System.arraycopy(lhs.val, 0, tmp, 0, 16);
|
||||||
matrix4_mul(tmp, rhs.val);
|
matrix4_mul(tmp, rhs.val);
|
||||||
System.arraycopy(tmp, 0, val, 0, 16);
|
System.arraycopy(tmp, 0, val, 0, 16);
|
||||||
@ -167,7 +162,7 @@ public class Matrix4 {
|
|||||||
*
|
*
|
||||||
* @param mat to transpose
|
* @param mat to transpose
|
||||||
*/
|
*/
|
||||||
public void transposeM(Matrix4 mat) {
|
public void transposeM(GLMatrix mat) {
|
||||||
val[M00] = mat.val[M00];
|
val[M00] = mat.val[M00];
|
||||||
val[M01] = mat.val[M10];
|
val[M01] = mat.val[M10];
|
||||||
val[M02] = mat.val[M20];
|
val[M02] = mat.val[M20];
|
||||||
@ -251,8 +246,7 @@ public class Matrix4 {
|
|||||||
buffer.clear();
|
buffer.clear();
|
||||||
buffer.put(val, 0, 16);
|
buffer.put(val, 0, 16);
|
||||||
buffer.position(0);
|
buffer.position(0);
|
||||||
GL = GLAdapter.get();
|
MapRenderer.GL.glUniformMatrix4fv(location, 1, false, buffer);
|
||||||
GL.glUniformMatrix4fv(location, 1, false, buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,7 +72,7 @@ void JNI(setColorBlend)(JNIEnv *env, jclass* clazz, jint location, jint c1, jint
|
|||||||
#endif // 0
|
#endif // 0
|
||||||
|
|
||||||
#undef JNI
|
#undef JNI
|
||||||
#define JNI(X) JNIEXPORT Java_org_oscim_utils_Matrix4_##X
|
#define JNI(X) JNIEXPORT Java_org_oscim_renderer_GLMatrix_##X
|
||||||
|
|
||||||
#define CAST(x) (float *)(uintptr_t) x
|
#define CAST(x) (float *)(uintptr_t) x
|
||||||
#define MAT_SIZE 16 * sizeof(float)
|
#define MAT_SIZE 16 * sizeof(float)
|
||||||
|
|||||||
@ -25,6 +25,9 @@ public class GLAdapter {
|
|||||||
public static boolean NON_PREMUL_CANVAS;
|
public static boolean NON_PREMUL_CANVAS;
|
||||||
|
|
||||||
public static GL20 get(){
|
public static GL20 get(){
|
||||||
|
if (g == null)
|
||||||
|
throw new IllegalStateException();
|
||||||
|
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,8 +21,8 @@ import org.oscim.core.MapPosition;
|
|||||||
import org.oscim.core.MercatorProjection;
|
import org.oscim.core.MercatorProjection;
|
||||||
import org.oscim.core.Point;
|
import org.oscim.core.Point;
|
||||||
import org.oscim.core.Tile;
|
import org.oscim.core.Tile;
|
||||||
|
import org.oscim.renderer.GLMatrix;
|
||||||
import org.oscim.utils.FastMath;
|
import org.oscim.utils.FastMath;
|
||||||
import org.oscim.utils.Matrix4;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Viewport class contains a MapPosition and the projection matrices.
|
* The Viewport class contains a MapPosition and the projection matrices.
|
||||||
@ -44,13 +44,13 @@ public class Viewport {
|
|||||||
|
|
||||||
private final MapPosition mPos = new MapPosition();
|
private final MapPosition mPos = new MapPosition();
|
||||||
|
|
||||||
private final Matrix4 mProjMatrix = new Matrix4();
|
private final GLMatrix mProjMatrix = new GLMatrix();
|
||||||
private final Matrix4 mProjMatrixI = new Matrix4();
|
private final GLMatrix mProjMatrixI = new GLMatrix();
|
||||||
private final Matrix4 mRotMatrix = new Matrix4();
|
private final GLMatrix mRotMatrix = new GLMatrix();
|
||||||
private final Matrix4 mViewMatrix = new Matrix4();
|
private final GLMatrix mViewMatrix = new GLMatrix();
|
||||||
private final Matrix4 mVPMatrix = new Matrix4();
|
private final GLMatrix mVPMatrix = new GLMatrix();
|
||||||
private final Matrix4 mUnprojMatrix = new Matrix4();
|
private final GLMatrix mUnprojMatrix = new GLMatrix();
|
||||||
private final Matrix4 mTmpMatrix = new Matrix4();
|
private final GLMatrix mTmpMatrix = new GLMatrix();
|
||||||
|
|
||||||
// temporary vars: only use in synchronized functions!
|
// temporary vars: only use in synchronized functions!
|
||||||
private final Point mMovePoint = new Point();
|
private final Point mMovePoint = new Point();
|
||||||
@ -81,7 +81,7 @@ public class Viewport {
|
|||||||
float aspect = height / (float) width;
|
float aspect = height / (float) width;
|
||||||
float[] tmp = new float[16];
|
float[] tmp = new float[16];
|
||||||
|
|
||||||
Matrix4.frustumM(tmp, 0, -s, s,
|
GLMatrix.frustumM(tmp, 0, -s, s,
|
||||||
aspect * s, -aspect * s, VIEW_NEAR, VIEW_FAR);
|
aspect * s, -aspect * s, VIEW_NEAR, VIEW_FAR);
|
||||||
|
|
||||||
mProjMatrix.set(tmp);
|
mProjMatrix.set(tmp);
|
||||||
@ -89,7 +89,7 @@ public class Viewport {
|
|||||||
mProjMatrix.multiplyRhs(mTmpMatrix);
|
mProjMatrix.multiplyRhs(mTmpMatrix);
|
||||||
mProjMatrix.get(tmp);
|
mProjMatrix.get(tmp);
|
||||||
|
|
||||||
Matrix4.invertM(tmp, 0, tmp, 0);
|
GLMatrix.invertM(tmp, 0, tmp, 0);
|
||||||
mProjMatrixI.set(tmp);
|
mProjMatrixI.set(tmp);
|
||||||
|
|
||||||
mHeight = height;
|
mHeight = height;
|
||||||
@ -130,7 +130,7 @@ public class Viewport {
|
|||||||
* @param proj projection Matrix
|
* @param proj projection Matrix
|
||||||
* @param vp view and projection
|
* @param vp view and projection
|
||||||
*/
|
*/
|
||||||
public synchronized void getMatrix(Matrix4 view, Matrix4 proj, Matrix4 vp) {
|
public synchronized void getMatrix(GLMatrix view, GLMatrix proj, GLMatrix vp) {
|
||||||
if (view != null)
|
if (view != null)
|
||||||
view.copy(mViewMatrix);
|
view.copy(mViewMatrix);
|
||||||
|
|
||||||
|
|||||||
@ -18,9 +18,7 @@ package org.oscim.renderer;
|
|||||||
import java.nio.Buffer;
|
import java.nio.Buffer;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.backend.Log;
|
import org.oscim.backend.Log;
|
||||||
import org.oscim.utils.GlUtils;
|
|
||||||
|
|
||||||
public final class BufferObject {
|
public final class BufferObject {
|
||||||
private final static String TAG = BufferObject.class.getName();
|
private final static String TAG = BufferObject.class.getName();
|
||||||
@ -176,7 +174,7 @@ public final class BufferObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (removed > 0) {
|
if (removed > 0) {
|
||||||
GlUtils.glDeleteBuffers(removed, vboIds);
|
GLUtils.glDeleteBuffers(removed, vboIds);
|
||||||
counter[t] -= removed;
|
counter[t] -= removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +184,7 @@ public final class BufferObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void createBuffers(int target, int num) {
|
static void createBuffers(int target, int num) {
|
||||||
int[] mVboIds = GlUtils.glGenBuffers(num);
|
int[] mVboIds = GLUtils.glGenBuffers(num);
|
||||||
|
|
||||||
int t = (target == GL20.GL_ARRAY_BUFFER) ? 0 : 1;
|
int t = (target == GL20.GL_ARRAY_BUFFER) ? 0 : 1;
|
||||||
|
|
||||||
@ -207,8 +205,8 @@ public final class BufferObject {
|
|||||||
counter[1] = 0;
|
counter[1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static synchronized void init(int num) {
|
static synchronized void init(GL20 gl, int num) {
|
||||||
GL = GLAdapter.get();
|
GL = gl;
|
||||||
|
|
||||||
createBuffers(GL20.GL_ARRAY_BUFFER, num);
|
createBuffers(GL20.GL_ARRAY_BUFFER, num);
|
||||||
counter[0] += num;
|
counter[0] += num;
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
package org.oscim.renderer;
|
package org.oscim.renderer;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.backend.Log;
|
import org.oscim.backend.Log;
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.core.Tile;
|
import org.oscim.core.Tile;
|
||||||
@ -24,7 +23,6 @@ import org.oscim.renderer.elements.ExtrusionLayer;
|
|||||||
import org.oscim.tiling.MapTile;
|
import org.oscim.tiling.MapTile;
|
||||||
import org.oscim.tiling.TileRenderer;
|
import org.oscim.tiling.TileRenderer;
|
||||||
import org.oscim.tiling.TileSet;
|
import org.oscim.tiling.TileSet;
|
||||||
import org.oscim.utils.GlUtils;
|
|
||||||
|
|
||||||
// TODO move MapTile part to BuildingLayer and make
|
// TODO move MapTile part to BuildingLayer and make
|
||||||
// this class work on ExtrusionLayers
|
// this class work on ExtrusionLayers
|
||||||
@ -32,8 +30,6 @@ import org.oscim.utils.GlUtils;
|
|||||||
public class ExtrusionRenderer extends LayerRenderer {
|
public class ExtrusionRenderer extends LayerRenderer {
|
||||||
private final static String TAG = ExtrusionRenderer.class.getName();
|
private final static String TAG = ExtrusionRenderer.class.getName();
|
||||||
|
|
||||||
private static final GL20 GL = GLAdapter.get();
|
|
||||||
|
|
||||||
private final TileRenderer mTileLayer;
|
private final TileRenderer mTileLayer;
|
||||||
|
|
||||||
protected float mAlpha = 1;
|
protected float mAlpha = 1;
|
||||||
@ -64,10 +60,10 @@ public class ExtrusionRenderer extends LayerRenderer {
|
|||||||
|
|
||||||
for (int i = 0; i <= SHADER; i++) {
|
for (int i = 0; i <= SHADER; i++) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
shaderProgram[i] = GlUtils.createProgram(extrusionVertexShader,
|
shaderProgram[i] = GLUtils.createProgram(extrusionVertexShader,
|
||||||
extrusionFragmentShader);
|
extrusionFragmentShader);
|
||||||
} else {
|
} else {
|
||||||
shaderProgram[i] = GlUtils.createProgram(extrusionVertexShader,
|
shaderProgram[i] = GLUtils.createProgram(extrusionVertexShader,
|
||||||
extrusionFragmentShaderZ);
|
extrusionFragmentShaderZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +124,7 @@ public class ExtrusionRenderer extends LayerRenderer {
|
|||||||
if (!el.compiled) {
|
if (!el.compiled) {
|
||||||
int numShorts = el.mNumVertices * 8;
|
int numShorts = el.mNumVertices * 8;
|
||||||
el.compile(MapRenderer.getShortBuffer(numShorts));
|
el.compile(MapRenderer.getShortBuffer(numShorts));
|
||||||
GlUtils.checkGlError("...");
|
GLUtils.checkGlError("...");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (el.compiled)
|
if (el.compiled)
|
||||||
@ -196,7 +192,7 @@ public class ExtrusionRenderer extends LayerRenderer {
|
|||||||
|
|
||||||
GLState.enableVertexArrays(uExtVertexPosition, uExtLightPosition);
|
GLState.enableVertexArrays(uExtVertexPosition, uExtLightPosition);
|
||||||
GL.glUniform1i(uExtMode, 0);
|
GL.glUniform1i(uExtMode, 0);
|
||||||
GlUtils.glUniform4fv(uExtColor, 4, mColor);
|
GLUtils.glUniform4fv(uExtColor, 4, mColor);
|
||||||
|
|
||||||
GLState.test(false, false);
|
GLState.test(false, false);
|
||||||
|
|
||||||
@ -247,7 +243,7 @@ public class ExtrusionRenderer extends LayerRenderer {
|
|||||||
GL.glDepthFunc(GL20.GL_LESS);
|
GL.glDepthFunc(GL20.GL_LESS);
|
||||||
GL.glColorMask(false, false, false, false);
|
GL.glColorMask(false, false, false, false);
|
||||||
GL.glUniform1i(uExtMode, 0);
|
GL.glUniform1i(uExtMode, 0);
|
||||||
GlUtils.glUniform4fv(uExtColor, 4, mColor);
|
GLUtils.glUniform4fv(uExtColor, 4, mColor);
|
||||||
GL.glUniform1f(uExtAlpha, mAlpha);
|
GL.glUniform1f(uExtAlpha, mAlpha);
|
||||||
|
|
||||||
// draw to depth buffer
|
// draw to depth buffer
|
||||||
|
|||||||
@ -12,20 +12,15 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.oscim.utils;
|
package org.oscim.renderer;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
public class GLMatrix {
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
|
|
||||||
public class Matrix4 {
|
private final static String TAG = GLMatrix.class.getName();
|
||||||
|
|
||||||
private static final GL20 GL = GLAdapter.get();
|
|
||||||
|
|
||||||
private final static String TAG = Matrix4.class.getName();
|
|
||||||
private final static boolean dbg = false;
|
private final static boolean dbg = false;
|
||||||
|
|
||||||
private final long pointer;
|
private final long pointer;
|
||||||
@ -33,7 +28,7 @@ public class Matrix4 {
|
|||||||
|
|
||||||
private final static String INVALID_INPUT = "Bad Array!";
|
private final static String INVALID_INPUT = "Bad Array!";
|
||||||
|
|
||||||
public Matrix4() {
|
public GLMatrix() {
|
||||||
pointer = alloc();
|
pointer = alloc();
|
||||||
buffer = (getBuffer(pointer)).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
buffer = (getBuffer(pointer)).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
||||||
}
|
}
|
||||||
@ -67,7 +62,7 @@ public class Matrix4 {
|
|||||||
*
|
*
|
||||||
* @param mat Matrix to copy
|
* @param mat Matrix to copy
|
||||||
*/
|
*/
|
||||||
public void copy(Matrix4 mat) {
|
public void copy(GLMatrix mat) {
|
||||||
copy(pointer, mat.pointer);
|
copy(pointer, mat.pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +83,7 @@ public class Matrix4 {
|
|||||||
*
|
*
|
||||||
* @param rhs right hand side
|
* @param rhs right hand side
|
||||||
*/
|
*/
|
||||||
public void multiplyRhs(Matrix4 rhs) {
|
public void multiplyRhs(GLMatrix rhs) {
|
||||||
smulrhs(pointer, rhs.pointer);
|
smulrhs(pointer, rhs.pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +92,7 @@ public class Matrix4 {
|
|||||||
*
|
*
|
||||||
* @param lhs right hand side
|
* @param lhs right hand side
|
||||||
*/
|
*/
|
||||||
public void multiplyLhs(Matrix4 lhs) {
|
public void multiplyLhs(GLMatrix lhs) {
|
||||||
smullhs(pointer, lhs.pointer);
|
smullhs(pointer, lhs.pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +107,7 @@ public class Matrix4 {
|
|||||||
* @param lhs left hand side
|
* @param lhs left hand side
|
||||||
* @param rhs right hand side
|
* @param rhs right hand side
|
||||||
*/
|
*/
|
||||||
public void multiplyMM(Matrix4 lhs, Matrix4 rhs) {
|
public void multiplyMM(GLMatrix lhs, GLMatrix rhs) {
|
||||||
smul(pointer, lhs.pointer, rhs.pointer);
|
smul(pointer, lhs.pointer, rhs.pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +116,7 @@ public class Matrix4 {
|
|||||||
*
|
*
|
||||||
* @param mat to transpose
|
* @param mat to transpose
|
||||||
*/
|
*/
|
||||||
public void transposeM(Matrix4 mat) {
|
public void transposeM(GLMatrix mat) {
|
||||||
strans(pointer, mat.pointer);
|
strans(pointer, mat.pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +171,7 @@ public class Matrix4 {
|
|||||||
* @param location GL location id
|
* @param location GL location id
|
||||||
*/
|
*/
|
||||||
public void setAsUniform(int location) {
|
public void setAsUniform(int location) {
|
||||||
GL.glUniformMatrix4fv(location, 1, false, buffer);
|
MapRenderer.GL.glUniformMatrix4fv(location, 1, false, buffer);
|
||||||
//setAsUniform(pointer, location);
|
//setAsUniform(pointer, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,14 +15,13 @@
|
|||||||
package org.oscim.renderer;
|
package org.oscim.renderer;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.backend.Log;
|
import org.oscim.backend.Log;
|
||||||
|
|
||||||
public class GLState {
|
public class GLState {
|
||||||
private final static GL20 GL = GLAdapter.get();
|
|
||||||
|
|
||||||
private final static String TAG = GLState.class.getName();
|
private final static String TAG = GLState.class.getName();
|
||||||
|
|
||||||
|
private static GL20 GL;
|
||||||
|
|
||||||
private final static boolean[] vertexArray = { false, false };
|
private final static boolean[] vertexArray = { false, false };
|
||||||
private static boolean blend = false;
|
private static boolean blend = false;
|
||||||
private static boolean depth = false;
|
private static boolean depth = false;
|
||||||
@ -31,7 +30,8 @@ public class GLState {
|
|||||||
|
|
||||||
private static int currentTexId;
|
private static int currentTexId;
|
||||||
|
|
||||||
public static void init() {
|
static void init(GL20 gl) {
|
||||||
|
GL = gl;
|
||||||
vertexArray[0] = false;
|
vertexArray[0] = false;
|
||||||
vertexArray[1] = false;
|
vertexArray[1] = false;
|
||||||
blend = false;
|
blend = false;
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
* Copyright 2013 Hannes Janetzek
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
* This program is free software: you can redistribute it and/or modify it under the
|
||||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
@ -12,7 +12,7 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.oscim.utils;
|
package org.oscim.renderer;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
@ -22,19 +22,21 @@ import java.nio.IntBuffer;
|
|||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
import org.oscim.backend.GLAdapter;
|
||||||
import org.oscim.backend.Log;
|
import org.oscim.backend.Log;
|
||||||
import org.oscim.renderer.MapRenderer;
|
import org.oscim.utils.FastMath;
|
||||||
import org.oscim.renderer.GLState;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility functions
|
* Utility functions
|
||||||
*/
|
*/
|
||||||
public class GlUtils {
|
public class GLUtils {
|
||||||
private static String TAG = GlUtils.class.getName();
|
private static String TAG = GLUtils.class.getName();
|
||||||
|
|
||||||
private static GL20 GL = GLAdapter.get();
|
|
||||||
|
|
||||||
|
private static GL20 GL;
|
||||||
|
|
||||||
|
static void init(GL20 gl){
|
||||||
|
GL = gl;
|
||||||
|
}
|
||||||
|
|
||||||
public static void setColor(int location, int color, float alpha) {
|
public static void setColor(int location, int color, float alpha) {
|
||||||
GL = GLAdapter.get();
|
|
||||||
if (alpha >= 1)
|
if (alpha >= 1)
|
||||||
alpha = ((color >>> 24) & 0xff) / 255f;
|
alpha = ((color >>> 24) & 0xff) / 255f;
|
||||||
else if (alpha < 0)
|
else if (alpha < 0)
|
||||||
@ -60,7 +62,6 @@ public class GlUtils {
|
|||||||
public static void setColorBlend(int location, int color1, int color2, float mix) {
|
public static void setColorBlend(int location, int color1, int color2, float mix) {
|
||||||
float a1 = (((color1 >>> 24) & 0xff) / 255f) * (1 - mix);
|
float a1 = (((color1 >>> 24) & 0xff) / 255f) * (1 - mix);
|
||||||
float a2 = (((color2 >>> 24) & 0xff) / 255f) * mix;
|
float a2 = (((color2 >>> 24) & 0xff) / 255f) * mix;
|
||||||
GL = GLAdapter.get();
|
|
||||||
GL.glUniform4f
|
GL.glUniform4f
|
||||||
(location,
|
(location,
|
||||||
((((color1 >>> 16) & 0xff) / 255f) * a1 + (((color2 >>> 16) & 0xff) / 255f) * a2),
|
((((color1 >>> 16) & 0xff) / 255f) * a1 + (((color2 >>> 16) & 0xff) / 255f) * a2),
|
||||||
@ -70,7 +71,6 @@ public class GlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setTextureParameter(int min_filter, int mag_filter, int wrap_s, int wrap_t) {
|
public static void setTextureParameter(int min_filter, int mag_filter, int wrap_s, int wrap_t) {
|
||||||
GL = GLAdapter.get();
|
|
||||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D,
|
GL.glTexParameterf(GL20.GL_TEXTURE_2D,
|
||||||
GL20.GL_TEXTURE_MIN_FILTER,
|
GL20.GL_TEXTURE_MIN_FILTER,
|
||||||
min_filter);
|
min_filter);
|
||||||
@ -87,9 +87,8 @@ public class GlUtils {
|
|||||||
|
|
||||||
public static int loadTexture(byte[] pixel, int width, int height, int format,
|
public static int loadTexture(byte[] pixel, int width, int height, int format,
|
||||||
int min_filter, int mag_filter, int wrap_s, int wrap_t) {
|
int min_filter, int mag_filter, int wrap_s, int wrap_t) {
|
||||||
int[] textureIds = GlUtils.glGenTextures(1);
|
|
||||||
GL = GLAdapter.get();
|
|
||||||
|
|
||||||
|
int[] textureIds = GLUtils.glGenTextures(1);
|
||||||
GLState.bindTex2D(textureIds[0]);
|
GLState.bindTex2D(textureIds[0]);
|
||||||
|
|
||||||
setTextureParameter(min_filter, mag_filter, wrap_s, wrap_t);
|
setTextureParameter(min_filter, mag_filter, wrap_s, wrap_t);
|
||||||
@ -107,8 +106,6 @@ public class GlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int loadStippleTexture(byte[] stipple) {
|
public static int loadStippleTexture(byte[] stipple) {
|
||||||
GL = GLAdapter.get();
|
|
||||||
|
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
for (byte flip : stipple)
|
for (byte flip : stipple)
|
||||||
sum += flip;
|
sum += flip;
|
||||||
@ -186,8 +183,6 @@ public class GlUtils {
|
|||||||
* @return gl identifier
|
* @return gl identifier
|
||||||
*/
|
*/
|
||||||
public static int createProgram(String vertexSource, String fragmentSource) {
|
public static int createProgram(String vertexSource, String fragmentSource) {
|
||||||
GL = GLAdapter.get();
|
|
||||||
|
|
||||||
int vertexShader = loadShader(GL20.GL_VERTEX_SHADER, vertexSource);
|
int vertexShader = loadShader(GL20.GL_VERTEX_SHADER, vertexSource);
|
||||||
if (vertexShader == 0) {
|
if (vertexShader == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -224,7 +219,7 @@ public class GlUtils {
|
|||||||
* ...
|
* ...
|
||||||
*/
|
*/
|
||||||
public static void checkGlError(String op) {
|
public static void checkGlError(String op) {
|
||||||
GL = GLAdapter.get();
|
//GL = GLAdapter.get();
|
||||||
|
|
||||||
int error;
|
int error;
|
||||||
while ((error = GL.glGetError()) != 0) { // GL20.GL_NO_ERROR) {
|
while ((error = GL.glGetError()) != 0) { // GL20.GL_NO_ERROR) {
|
||||||
@ -234,8 +229,6 @@ public class GlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkGlOutOfMemory(String op) {
|
public static boolean checkGlOutOfMemory(String op) {
|
||||||
GL = GLAdapter.get();
|
|
||||||
|
|
||||||
int error;
|
int error;
|
||||||
boolean oom = false;
|
boolean oom = false;
|
||||||
while ((error = GL.glGetError()) != 0) {// GL20.GL_NO_ERROR) {
|
while ((error = GL.glGetError()) != 0) {// GL20.GL_NO_ERROR) {
|
||||||
@ -248,8 +241,6 @@ public class GlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setColor(int handle, float[] c, float alpha) {
|
public static void setColor(int handle, float[] c, float alpha) {
|
||||||
GL = GLAdapter.get();
|
|
||||||
|
|
||||||
if (alpha >= 1) {
|
if (alpha >= 1) {
|
||||||
GL.glUniform4f(handle, c[0], c[1], c[2], c[3]);
|
GL.glUniform4f(handle, c[0], c[1], c[2], c[3]);
|
||||||
} else {
|
} else {
|
||||||
@ -307,8 +298,6 @@ public class GlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void glUniform4fv(int location, int count, float[] val) {
|
public static void glUniform4fv(int location, int count, float[] val) {
|
||||||
GL = GLAdapter.get();
|
|
||||||
|
|
||||||
FloatBuffer buf = MapRenderer.getFloatBuffer(count * 4);
|
FloatBuffer buf = MapRenderer.getFloatBuffer(count * 4);
|
||||||
buf.put(val);
|
buf.put(val);
|
||||||
buf.flip();
|
buf.flip();
|
||||||
@ -316,8 +305,6 @@ public class GlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int[] glGenBuffers(int num) {
|
public static int[] glGenBuffers(int num) {
|
||||||
GL = GLAdapter.get();
|
|
||||||
|
|
||||||
IntBuffer buf = MapRenderer.getIntBuffer(num);
|
IntBuffer buf = MapRenderer.getIntBuffer(num);
|
||||||
buf.position(0);
|
buf.position(0);
|
||||||
buf.limit(num);
|
buf.limit(num);
|
||||||
@ -330,8 +317,6 @@ public class GlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void glDeleteBuffers(int num, int[] ids) {
|
public static void glDeleteBuffers(int num, int[] ids) {
|
||||||
GL = GLAdapter.get();
|
|
||||||
|
|
||||||
IntBuffer buf = MapRenderer.getIntBuffer(num);
|
IntBuffer buf = MapRenderer.getIntBuffer(num);
|
||||||
buf.put(ids, 0, num);
|
buf.put(ids, 0, num);
|
||||||
buf.position(0);
|
buf.position(0);
|
||||||
@ -342,7 +327,6 @@ public class GlUtils {
|
|||||||
if (num <= 0)
|
if (num <= 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
GL = GLAdapter.get();
|
|
||||||
int[] ret = new int[num];
|
int[] ret = new int[num];
|
||||||
IntBuffer buf = MapRenderer.getIntBuffer(num);
|
IntBuffer buf = MapRenderer.getIntBuffer(num);
|
||||||
|
|
||||||
@ -363,8 +347,6 @@ public class GlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void glDeleteTextures(int num, int[] ids) {
|
public static void glDeleteTextures(int num, int[] ids) {
|
||||||
GL = GLAdapter.get();
|
|
||||||
|
|
||||||
IntBuffer buf = MapRenderer.getIntBuffer(num);
|
IntBuffer buf = MapRenderer.getIntBuffer(num);
|
||||||
buf.put(ids, 0, num);
|
buf.put(ids, 0, num);
|
||||||
buf.position(0);
|
buf.position(0);
|
||||||
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.renderer;
|
package org.oscim.renderer;
|
||||||
|
|
||||||
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.core.Tile;
|
import org.oscim.core.Tile;
|
||||||
import org.oscim.renderer.MapRenderer.Matrices;
|
import org.oscim.renderer.MapRenderer.Matrices;
|
||||||
@ -43,12 +44,22 @@ public abstract class LayerRenderer {
|
|||||||
return isReady;
|
return isReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isInitialized;
|
||||||
|
|
||||||
public LayerRenderer() {
|
public LayerRenderer() {
|
||||||
mMapPosition = new MapPosition();
|
mMapPosition = new MapPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////// MapRender Thread ///////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called on GL Thread before first update().
|
||||||
|
* */
|
||||||
|
protected boolean setup() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ////////////////////// MapRender Thread ///////////////////////////
|
|
||||||
* 1. Called first by MapRenderer: Update the state here.
|
* 1. Called first by MapRenderer: Update the state here.
|
||||||
*
|
*
|
||||||
* @param position current MapPosition
|
* @param position current MapPosition
|
||||||
@ -74,7 +85,7 @@ public abstract class LayerRenderer {
|
|||||||
* @param matrices contains the current view- and projection-matrices.
|
* @param matrices contains the current view- and projection-matrices.
|
||||||
* 'matrices.mvp' is for temporary use to build the model-
|
* 'matrices.mvp' is for temporary use to build the model-
|
||||||
* view-projection to set as uniform.
|
* view-projection to set as uniform.
|
||||||
*/
|
*/
|
||||||
protected abstract void render(MapPosition position, Matrices matrices);
|
protected abstract void render(MapPosition position, Matrices matrices);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -120,4 +131,10 @@ public abstract class LayerRenderer {
|
|||||||
protected void setMatrix(MapPosition position, Matrices matrices) {
|
protected void setMatrix(MapPosition position, Matrices matrices) {
|
||||||
setMatrix(position, matrices, true);
|
setMatrix(position, matrices, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static GL20 GL;
|
||||||
|
|
||||||
|
static void init(GL20 gl) {
|
||||||
|
GL = gl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,15 +29,13 @@ import org.oscim.map.Map;
|
|||||||
import org.oscim.map.Viewport;
|
import org.oscim.map.Viewport;
|
||||||
import org.oscim.renderer.elements.ElementLayers;
|
import org.oscim.renderer.elements.ElementLayers;
|
||||||
import org.oscim.tiling.MapTile;
|
import org.oscim.tiling.MapTile;
|
||||||
import org.oscim.utils.GlUtils;
|
|
||||||
import org.oscim.utils.Matrix4;
|
|
||||||
import org.oscim.utils.pool.Inlist;
|
import org.oscim.utils.pool.Inlist;
|
||||||
import org.oscim.utils.pool.Pool;
|
import org.oscim.utils.pool.Pool;
|
||||||
|
|
||||||
public class MapRenderer {
|
public class MapRenderer {
|
||||||
private static final String TAG = MapRenderer.class.getName();
|
private static final String TAG = MapRenderer.class.getName();
|
||||||
|
|
||||||
private static GL20 GL = GLAdapter.get();
|
static GL20 GL;
|
||||||
|
|
||||||
private static final int SHORT_BYTES = 2;
|
private static final int SHORT_BYTES = 2;
|
||||||
private static final int CACHE_TILES_MAX = 250;
|
private static final int CACHE_TILES_MAX = 250;
|
||||||
@ -56,17 +54,17 @@ public class MapRenderer {
|
|||||||
|
|
||||||
public class Matrices {
|
public class Matrices {
|
||||||
|
|
||||||
/** do not modify! */
|
/** Do not modify! */
|
||||||
public final Matrix4 viewproj = new Matrix4();
|
public final GLMatrix viewproj = new GLMatrix();
|
||||||
/** do not modify! */
|
/** Do not modify! */
|
||||||
public final Matrix4 proj = new Matrix4();
|
public final GLMatrix proj = new GLMatrix();
|
||||||
/** do not modify! */
|
/** Do not modify! */
|
||||||
public final Matrix4 view = new Matrix4();
|
public final GLMatrix view = new GLMatrix();
|
||||||
/** do not modify! */
|
/** Do not modify! */
|
||||||
public final float[] mapPlane = new float[8];
|
public final float[] mapPlane = new float[8];
|
||||||
|
|
||||||
/** for temporary use by callee */
|
/** For temporary use, to setup MVP-Matrix */
|
||||||
public final Matrix4 mvp = new Matrix4();
|
public final GLMatrix mvp = new GLMatrix();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set MVP so that coordinates are in screen pixel coordinates with 0,0
|
* Set MVP so that coordinates are in screen pixel coordinates with 0,0
|
||||||
@ -177,7 +175,7 @@ public class MapRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setBackgroundColor(int color) {
|
public static void setBackgroundColor(int color) {
|
||||||
mClearColor = GlUtils.colorToFloat(color);
|
mClearColor = GLUtils.colorToFloat(color);
|
||||||
mUpdateColor = true;
|
mUpdateColor = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +324,7 @@ public class MapRenderer {
|
|||||||
renderLayer.render(mMapPosition, mMatrices);
|
renderLayer.render(mMapPosition, mMatrices);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GlUtils.checkGlOutOfMemory("finish")) {
|
if (GLUtils.checkGlOutOfMemory("finish")) {
|
||||||
BufferObject.checkBufferUsage(true);
|
BufferObject.checkBufferUsage(true);
|
||||||
// FIXME also throw out some textures etc
|
// FIXME also throw out some textures etc
|
||||||
}
|
}
|
||||||
@ -353,7 +351,7 @@ public class MapRenderer {
|
|||||||
mMatrices.mvp.setScale(0.5f, 0.5f, 1);
|
mMatrices.mvp.setScale(0.5f, 0.5f, 1);
|
||||||
mMatrices.proj.multiplyLhs(mMatrices.mvp);
|
mMatrices.proj.multiplyLhs(mMatrices.mvp);
|
||||||
}
|
}
|
||||||
GL = GLAdapter.get();
|
|
||||||
GL.glViewport(0, 0, width, height);
|
GL.glViewport(0, 0, width, height);
|
||||||
GL.glScissor(0, 0, width, height);
|
GL.glScissor(0, 0, width, height);
|
||||||
GL.glEnable(GL20.GL_SCISSOR_TEST);
|
GL.glEnable(GL20.GL_SCISSOR_TEST);
|
||||||
@ -371,7 +369,7 @@ public class MapRenderer {
|
|||||||
mNewSurface = false;
|
mNewSurface = false;
|
||||||
|
|
||||||
// upload quad indices used by Texture- and LineTexRenderer
|
// upload quad indices used by Texture- and LineTexRenderer
|
||||||
int[] vboIds = GlUtils.glGenBuffers(2);
|
int[] vboIds = GLUtils.glGenBuffers(2);
|
||||||
|
|
||||||
mQuadIndicesID = vboIds[0];
|
mQuadIndicesID = vboIds[0];
|
||||||
int maxIndices = maxQuads * 6;
|
int maxIndices = maxQuads * 6;
|
||||||
@ -411,22 +409,27 @@ public class MapRenderer {
|
|||||||
if (mClearColor != null)
|
if (mClearColor != null)
|
||||||
mUpdateColor = true;
|
mUpdateColor = true;
|
||||||
|
|
||||||
GLState.init();
|
GLState.init(GL);
|
||||||
|
|
||||||
mMap.updateMap(true);
|
mMap.updateMap(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSurfaceCreated() {
|
public void onSurfaceCreated() {
|
||||||
|
GL = GLAdapter.get();
|
||||||
|
|
||||||
Log.d(TAG, "surface created");
|
// Log.d(TAG, "surface created");
|
||||||
|
|
||||||
// Log.d(TAG, GL.glGetString(GL20.GL_EXTENSIONS));
|
// Log.d(TAG, GL.glGetString(GL20.GL_EXTENSIONS));
|
||||||
|
|
||||||
// classes that require GL context for initialization
|
GLState.init(GL);
|
||||||
ElementLayers.initRenderer();
|
GLUtils.init(GL);
|
||||||
|
|
||||||
// Set up some vertex buffer objects
|
// Set up some vertex buffer objects
|
||||||
BufferObject.init(CACHE_TILES);
|
BufferObject.init(GL, CACHE_TILES);
|
||||||
|
|
||||||
|
// classes that require GL context for initialization
|
||||||
|
ElementLayers.initRenderer(GL);
|
||||||
|
|
||||||
|
LayerRenderer.init(GL);
|
||||||
|
|
||||||
mNewSurface = true;
|
mNewSurface = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,12 +17,11 @@ package org.oscim.renderer.elements;
|
|||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.backend.canvas.Bitmap;
|
import org.oscim.backend.canvas.Bitmap;
|
||||||
import org.oscim.renderer.MapRenderer;
|
|
||||||
import org.oscim.renderer.GLState;
|
import org.oscim.renderer.GLState;
|
||||||
|
import org.oscim.renderer.GLUtils;
|
||||||
|
import org.oscim.renderer.MapRenderer;
|
||||||
import org.oscim.renderer.MapRenderer.Matrices;
|
import org.oscim.renderer.MapRenderer.Matrices;
|
||||||
import org.oscim.utils.GlUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderer for a single bitmap, width and height must be power of 2.
|
* Renderer for a single bitmap, width and height must be power of 2.
|
||||||
@ -152,7 +151,7 @@ public class BitmapLayer extends TextureLayer {
|
|||||||
public static final class Renderer {
|
public static final class Renderer {
|
||||||
|
|
||||||
//private final static String TAG = BitmapRenderer.class.getName();
|
//private final static String TAG = BitmapRenderer.class.getName();
|
||||||
private static final GL20 GL = GLAdapter.get();
|
private static GL20 GL;
|
||||||
|
|
||||||
public final static boolean debug = true;
|
public final static boolean debug = true;
|
||||||
|
|
||||||
@ -170,8 +169,10 @@ public class BitmapLayer extends TextureLayer {
|
|||||||
final static int VERTICES_PER_SPRITE = 4;
|
final static int VERTICES_PER_SPRITE = 4;
|
||||||
final static int SHORTS_PER_VERTICE = 6;
|
final static int SHORTS_PER_VERTICE = 6;
|
||||||
|
|
||||||
static void init() {
|
static void init(GL20 gl) {
|
||||||
mTextureProgram = GlUtils.createProgram(textVertexShader,
|
GL = gl;
|
||||||
|
|
||||||
|
mTextureProgram = GLUtils.createProgram(textVertexShader,
|
||||||
textFragmentShader);
|
textFragmentShader);
|
||||||
|
|
||||||
hTextureMVMatrix = GL.glGetUniformLocation(mTextureProgram, "u_mv");
|
hTextureMVMatrix = GL.glGetUniformLocation(mTextureProgram, "u_mv");
|
||||||
@ -183,7 +184,8 @@ public class BitmapLayer extends TextureLayer {
|
|||||||
hAlpha = GL.glGetUniformLocation(mTextureProgram, "u_alpha");
|
hAlpha = GL.glGetUniformLocation(mTextureProgram, "u_alpha");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RenderElement draw(RenderElement renderElement, Matrices m, float scale, float alpha) {
|
public static RenderElement draw(RenderElement renderElement, Matrices m, float scale,
|
||||||
|
float alpha) {
|
||||||
//GLState.test(false, false);
|
//GLState.test(false, false);
|
||||||
GLState.blend(true);
|
GLState.blend(true);
|
||||||
|
|
||||||
|
|||||||
@ -16,21 +16,21 @@ package org.oscim.renderer.elements;
|
|||||||
|
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
|
import org.oscim.backend.GL20;
|
||||||
|
import org.oscim.backend.Log;
|
||||||
import org.oscim.renderer.BufferObject;
|
import org.oscim.renderer.BufferObject;
|
||||||
import org.oscim.theme.renderinstruction.Line;
|
import org.oscim.theme.renderinstruction.Line;
|
||||||
|
|
||||||
import org.oscim.backend.Log;
|
|
||||||
|
|
||||||
public class ElementLayers {
|
public class ElementLayers {
|
||||||
private final static String TAG = ElementLayers.class.getName();
|
private final static String TAG = ElementLayers.class.getName();
|
||||||
|
|
||||||
public static void initRenderer() {
|
public static void initRenderer(GL20 gl) {
|
||||||
LineLayer.Renderer.init();
|
LineLayer.Renderer.init(gl);
|
||||||
LineTexLayer.Renderer.init();
|
LineTexLayer.Renderer.init(gl);
|
||||||
PolygonLayer.Renderer.init();
|
PolygonLayer.Renderer.init(gl);
|
||||||
TextureLayer.Renderer.init();
|
TextureLayer.Renderer.init(gl);
|
||||||
BitmapLayer.Renderer.init();
|
BitmapLayer.Renderer.init(gl);
|
||||||
TextureItem.init(0);
|
TextureItem.init(gl, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// mixed Polygon- and LineLayer
|
// mixed Polygon- and LineLayer
|
||||||
|
|||||||
@ -35,8 +35,6 @@ import org.oscim.utils.geom.Triangulator;
|
|||||||
public class ExtrusionLayer extends RenderElement {
|
public class ExtrusionLayer extends RenderElement {
|
||||||
private final static String TAG = ExtrusionLayer.class.getName();
|
private final static String TAG = ExtrusionLayer.class.getName();
|
||||||
|
|
||||||
private static final GL20 GL = GLAdapter.get();
|
|
||||||
|
|
||||||
private static final float S = MapRenderer.COORD_SCALE;
|
private static final float S = MapRenderer.COORD_SCALE;
|
||||||
private VertexItem mVertices;
|
private VertexItem mVertices;
|
||||||
private VertexItem mCurVertices;
|
private VertexItem mCurVertices;
|
||||||
@ -399,6 +397,7 @@ public class ExtrusionLayer extends RenderElement {
|
|||||||
vboIndices = BufferObject.get(GL20.GL_ELEMENT_ARRAY_BUFFER, size);
|
vboIndices = BufferObject.get(GL20.GL_ELEMENT_ARRAY_BUFFER, size);
|
||||||
vboIndices.loadBufferData(sbuf, size);
|
vboIndices.loadBufferData(sbuf, size);
|
||||||
|
|
||||||
|
GL20 GL = GLAdapter.get();
|
||||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
// upload vertices
|
// upload vertices
|
||||||
|
|||||||
@ -23,12 +23,12 @@ import org.oscim.backend.canvas.Paint.Cap;
|
|||||||
import org.oscim.core.GeometryBuffer;
|
import org.oscim.core.GeometryBuffer;
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.core.Tile;
|
import org.oscim.core.Tile;
|
||||||
|
import org.oscim.renderer.GLUtils;
|
||||||
import org.oscim.renderer.MapRenderer;
|
import org.oscim.renderer.MapRenderer;
|
||||||
import org.oscim.renderer.GLState;
|
import org.oscim.renderer.GLState;
|
||||||
import org.oscim.renderer.MapRenderer.Matrices;
|
import org.oscim.renderer.MapRenderer.Matrices;
|
||||||
import org.oscim.theme.renderinstruction.Line;
|
import org.oscim.theme.renderinstruction.Line;
|
||||||
import org.oscim.utils.FastMath;
|
import org.oscim.utils.FastMath;
|
||||||
import org.oscim.utils.GlUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@ -64,9 +64,7 @@ public final class LineLayer extends RenderElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* line extrusion is based on code from GLMap
|
* @deprecated
|
||||||
* (https://github.com/olofsj/GLMap/)
|
|
||||||
*
|
|
||||||
* @param points
|
* @param points
|
||||||
* array of points as x,y pairs.
|
* array of points as x,y pairs.
|
||||||
* @param index
|
* @param index
|
||||||
@ -86,6 +84,8 @@ public final class LineLayer extends RenderElement {
|
|||||||
addLine(geom.points, geom.index, -1, true);
|
addLine(geom.points, geom.index, -1, true);
|
||||||
else if (geom.isLine())
|
else if (geom.isLine())
|
||||||
addLine(geom.points, geom.index, -1, false);
|
addLine(geom.points, geom.index, -1, false);
|
||||||
|
else
|
||||||
|
Log.d(TAG, "geometry must be LINE or POLYGON");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLine(float[] points, int numPoints, boolean closed) {
|
public void addLine(float[] points, int numPoints, boolean closed) {
|
||||||
@ -598,17 +598,17 @@ public final class LineLayer extends RenderElement {
|
|||||||
private static int[] hLineMode = new int[2];
|
private static int[] hLineMode = new int[2];
|
||||||
public static int mTexID;
|
public static int mTexID;
|
||||||
|
|
||||||
static boolean init() {
|
static boolean init(GL20 gl) {
|
||||||
GL = GLAdapter.get();
|
GL = gl;
|
||||||
|
|
||||||
lineProgram[0] = GlUtils.createProgram(lineVertexShader,
|
lineProgram[0] = GLUtils.createProgram(lineVertexShader,
|
||||||
lineFragmentShader);
|
lineFragmentShader);
|
||||||
if (lineProgram[0] == 0) {
|
if (lineProgram[0] == 0) {
|
||||||
Log.e(TAG, "Could not create line program.");
|
Log.e(TAG, "Could not create line program.");
|
||||||
//return false;
|
//return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
lineProgram[1] = GlUtils.createProgram(lineVertexShader,
|
lineProgram[1] = GLUtils.createProgram(lineVertexShader,
|
||||||
lineSimpleFragmentShader);
|
lineSimpleFragmentShader);
|
||||||
if (lineProgram[1] == 0) {
|
if (lineProgram[1] == 0) {
|
||||||
Log.e(TAG, "Could not create simple line program.");
|
Log.e(TAG, "Could not create simple line program.");
|
||||||
@ -642,7 +642,7 @@ public final class LineLayer extends RenderElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mTexID = GlUtils.loadTexture(pixel, 128, 128, GL20.GL_ALPHA,
|
mTexID = GLUtils.loadTexture(pixel, 128, 128, GL20.GL_ALPHA,
|
||||||
GL20.GL_NEAREST, GL20.GL_NEAREST,
|
GL20.GL_NEAREST, GL20.GL_NEAREST,
|
||||||
GL20.GL_MIRRORED_REPEAT, GL20.GL_MIRRORED_REPEAT);
|
GL20.GL_MIRRORED_REPEAT, GL20.GL_MIRRORED_REPEAT);
|
||||||
|
|
||||||
@ -650,7 +650,8 @@ public final class LineLayer extends RenderElement {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RenderElement draw(ElementLayers layers, RenderElement curLayer, MapPosition pos,
|
public static RenderElement draw(ElementLayers layers, RenderElement curLayer,
|
||||||
|
MapPosition pos,
|
||||||
Matrices m, float div, int mode) {
|
Matrices m, float div, int mode) {
|
||||||
|
|
||||||
if (curLayer == null)
|
if (curLayer == null)
|
||||||
@ -717,12 +718,12 @@ public final class LineLayer extends RenderElement {
|
|||||||
float width;
|
float width;
|
||||||
|
|
||||||
if (line.fade < zoom) {
|
if (line.fade < zoom) {
|
||||||
GlUtils.setColor(uLineColor, line.color, 1);
|
GLUtils.setColor(uLineColor, line.color, 1);
|
||||||
} else if (line.fade > zoom) {
|
} else if (line.fade > zoom) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
float alpha = (float) (scale > 1.2 ? scale : 1.2) - 1;
|
float alpha = (float) (scale > 1.2 ? scale : 1.2) - 1;
|
||||||
GlUtils.setColor(uLineColor, line.color, alpha);
|
GLUtils.setColor(uLineColor, line.color, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == 0 && blur && line.blur == 0) {
|
if (mode == 0 && blur && line.blur == 0) {
|
||||||
|
|||||||
@ -19,18 +19,17 @@ import java.nio.ByteOrder;
|
|||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.backend.Log;
|
import org.oscim.backend.Log;
|
||||||
|
import org.oscim.core.GeometryBuffer;
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.renderer.MapRenderer;
|
|
||||||
import org.oscim.renderer.GLState;
|
import org.oscim.renderer.GLState;
|
||||||
|
import org.oscim.renderer.GLUtils;
|
||||||
|
import org.oscim.renderer.MapRenderer;
|
||||||
import org.oscim.renderer.MapRenderer.Matrices;
|
import org.oscim.renderer.MapRenderer.Matrices;
|
||||||
import org.oscim.theme.renderinstruction.Line;
|
import org.oscim.theme.renderinstruction.Line;
|
||||||
import org.oscim.utils.GlUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RenderElement for textured or stippled lines
|
* RenderElement for textured or stippled lines
|
||||||
*
|
|
||||||
* this would be all so much simpler with geometry shaders...
|
* this would be all so much simpler with geometry shaders...
|
||||||
*/
|
*/
|
||||||
public final class LineTexLayer extends RenderElement {
|
public final class LineTexLayer extends RenderElement {
|
||||||
@ -99,6 +98,10 @@ public final class LineTexLayer extends RenderElement {
|
|||||||
this.evenSegment = true;
|
this.evenSegment = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addLine(GeometryBuffer geom) {
|
||||||
|
addLine(geom.points, geom.index);
|
||||||
|
}
|
||||||
|
|
||||||
public void addLine(float[] points, short[] index) {
|
public void addLine(float[] points, short[] index) {
|
||||||
|
|
||||||
if (vertexItems == null) {
|
if (vertexItems == null) {
|
||||||
@ -247,11 +250,12 @@ public final class LineTexLayer extends RenderElement {
|
|||||||
|
|
||||||
public final static class Renderer {
|
public final static class Renderer {
|
||||||
|
|
||||||
private static final GL20 GL = GLAdapter.get();
|
private static GL20 GL;
|
||||||
|
|
||||||
// factor to normalize extrusion vector and scale to coord scale
|
// factor to normalize extrusion vector and scale to coord scale
|
||||||
private final static float COORD_SCALE_BY_DIR_SCALE =
|
private final static float COORD_SCALE_BY_DIR_SCALE =
|
||||||
MapRenderer.COORD_SCALE / LineLayer.DIR_SCALE;
|
MapRenderer.COORD_SCALE
|
||||||
|
/ LineLayer.DIR_SCALE;
|
||||||
|
|
||||||
private static int shader;
|
private static int shader;
|
||||||
private static int hVertexPosition0;
|
private static int hVertexPosition0;
|
||||||
@ -269,8 +273,10 @@ public final class LineTexLayer extends RenderElement {
|
|||||||
|
|
||||||
private static int mVertexFlipID;
|
private static int mVertexFlipID;
|
||||||
|
|
||||||
public static void init() {
|
public static void init(GL20 gl) {
|
||||||
shader = GlUtils.createProgram(vertexShader, fragmentShader);
|
GL = gl;
|
||||||
|
|
||||||
|
shader = GLUtils.createProgram(vertexShader, fragmentShader);
|
||||||
if (shader == 0) {
|
if (shader == 0) {
|
||||||
Log.e(TAG, "Could not create program.");
|
Log.e(TAG, "Could not create program.");
|
||||||
return;
|
return;
|
||||||
@ -290,13 +296,13 @@ public final class LineTexLayer extends RenderElement {
|
|||||||
hVertexLength1 = GL.glGetAttribLocation(shader, "a_len1");
|
hVertexLength1 = GL.glGetAttribLocation(shader, "a_len1");
|
||||||
hVertexFlip = GL.glGetAttribLocation(shader, "a_flip");
|
hVertexFlip = GL.glGetAttribLocation(shader, "a_flip");
|
||||||
|
|
||||||
int[] vboIds = GlUtils.glGenBuffers(1);
|
int[] vboIds = GLUtils.glGenBuffers(1);
|
||||||
mVertexFlipID = vboIds[0];
|
mVertexFlipID = vboIds[0];
|
||||||
|
|
||||||
// bytes: 0, 1, 0, 1, 0, ...
|
// bytes: 0, 1, 0, 1, 0, ...
|
||||||
byte[] flip = new byte[MapRenderer.maxQuads * 4];
|
byte[] flip = new byte[MapRenderer.maxQuads * 4];
|
||||||
for (int i = 0; i < flip.length; i++)
|
for (int i = 0; i < flip.length; i++)
|
||||||
flip[i] = (byte)(i % 2);
|
flip[i] = (byte) (i % 2);
|
||||||
|
|
||||||
ByteBuffer buf = ByteBuffer.allocateDirect(flip.length)
|
ByteBuffer buf = ByteBuffer.allocateDirect(flip.length)
|
||||||
.order(ByteOrder.nativeOrder());
|
.order(ByteOrder.nativeOrder());
|
||||||
@ -306,7 +312,7 @@ public final class LineTexLayer extends RenderElement {
|
|||||||
ShortBuffer sbuf = buf.asShortBuffer();
|
ShortBuffer sbuf = buf.asShortBuffer();
|
||||||
|
|
||||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, mVertexFlipID);
|
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, mVertexFlipID);
|
||||||
GL.glBufferData(GL20.GL_ARRAY_BUFFER, flip.length , sbuf,
|
GL.glBufferData(GL20.GL_ARRAY_BUFFER, flip.length, sbuf,
|
||||||
GL20.GL_STATIC_DRAW);
|
GL20.GL_STATIC_DRAW);
|
||||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
@ -361,8 +367,8 @@ public final class LineTexLayer extends RenderElement {
|
|||||||
LineTexLayer ll = (LineTexLayer) l;
|
LineTexLayer ll = (LineTexLayer) l;
|
||||||
Line line = ll.line;
|
Line line = ll.line;
|
||||||
|
|
||||||
GlUtils.setColor(hTexColor, line.stippleColor, 1);
|
GLUtils.setColor(hTexColor, line.stippleColor, 1);
|
||||||
GlUtils.setColor(hBgColor, line.color, 1);
|
GLUtils.setColor(hBgColor, line.color, 1);
|
||||||
|
|
||||||
float pScale = (int) (s + 0.5f);
|
float pScale = (int) (s + 0.5f);
|
||||||
if (pScale < 1)
|
if (pScale < 1)
|
||||||
@ -500,8 +506,7 @@ public final class LineTexLayer extends RenderElement {
|
|||||||
+ " gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));"
|
+ " gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));"
|
||||||
+ " } "; //*/
|
+ " } "; //*/
|
||||||
|
|
||||||
/*
|
/* final static String fragmentShader = ""
|
||||||
* final static String fragmentShader = ""
|
|
||||||
* + "#extension GL_OES_standard_derivatives : enable\n"
|
* + "#extension GL_OES_standard_derivatives : enable\n"
|
||||||
* + " precision mediump float;"
|
* + " precision mediump float;"
|
||||||
* + " uniform sampler2D tex;"
|
* + " uniform sampler2D tex;"
|
||||||
@ -522,10 +527,8 @@ public final class LineTexLayer extends RenderElement {
|
|||||||
* + " gl_FragColor = u_bgcolor * stipple_p;"
|
* + " gl_FragColor = u_bgcolor * stipple_p;"
|
||||||
* // +
|
* // +
|
||||||
* " gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));"
|
* " gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));"
|
||||||
* + "}"; //
|
* + "}"; // */
|
||||||
*/
|
/* final static String fragmentShader = ""
|
||||||
/*
|
|
||||||
* final static String fragmentShader = ""
|
|
||||||
* + "#extension GL_OES_standard_derivatives : enable\n"
|
* + "#extension GL_OES_standard_derivatives : enable\n"
|
||||||
* + " precision mediump float;"
|
* + " precision mediump float;"
|
||||||
* + " uniform sampler2D tex;"
|
* + " uniform sampler2D tex;"
|
||||||
@ -544,8 +547,7 @@ public final class LineTexLayer extends RenderElement {
|
|||||||
* + " float stipple_p = smoothstep(0.495, 0.505, dist);"
|
* + " float stipple_p = smoothstep(0.495, 0.505, dist);"
|
||||||
* +
|
* +
|
||||||
* " gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));"
|
* " gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));"
|
||||||
* + " } "; //
|
* + " } "; // */
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,18 +20,17 @@ import java.nio.FloatBuffer;
|
|||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.backend.Log;
|
import org.oscim.backend.Log;
|
||||||
import org.oscim.core.GeometryBuffer;
|
import org.oscim.core.GeometryBuffer;
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.core.Tile;
|
import org.oscim.core.Tile;
|
||||||
import org.oscim.renderer.MapRenderer;
|
import org.oscim.renderer.GLMatrix;
|
||||||
import org.oscim.renderer.GLState;
|
import org.oscim.renderer.GLState;
|
||||||
|
import org.oscim.renderer.GLUtils;
|
||||||
|
import org.oscim.renderer.MapRenderer;
|
||||||
import org.oscim.renderer.MapRenderer.Matrices;
|
import org.oscim.renderer.MapRenderer.Matrices;
|
||||||
import org.oscim.theme.renderinstruction.Area;
|
import org.oscim.theme.renderinstruction.Area;
|
||||||
import org.oscim.utils.FastMath;
|
import org.oscim.utils.FastMath;
|
||||||
import org.oscim.utils.GlUtils;
|
|
||||||
import org.oscim.utils.Matrix4;
|
|
||||||
|
|
||||||
public final class PolygonLayer extends RenderElement {
|
public final class PolygonLayer extends RenderElement {
|
||||||
private static final String TAG = PolygonLayer.class.getName();
|
private static final String TAG = PolygonLayer.class.getName();
|
||||||
@ -144,21 +143,21 @@ public final class PolygonLayer extends RenderElement {
|
|||||||
|
|
||||||
private static boolean enableTexture = false;
|
private static boolean enableTexture = false;
|
||||||
|
|
||||||
static boolean init() {
|
static boolean init(GL20 gl) {
|
||||||
GL = GLAdapter.get();
|
GL = gl;
|
||||||
|
|
||||||
for (int i = 0; i < numShaders; i++) {
|
for (int i = 0; i < numShaders; i++) {
|
||||||
|
|
||||||
// Set up the program for rendering polygons
|
// Set up the program for rendering polygons
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
if (MapRenderer.debugView)
|
if (MapRenderer.debugView)
|
||||||
polygonProgram[i] = GlUtils.createProgram(polygonVertexShaderZ,
|
polygonProgram[i] = GLUtils.createProgram(polygonVertexShaderZ,
|
||||||
polygonFragmentShaderZ);
|
polygonFragmentShaderZ);
|
||||||
else
|
else
|
||||||
polygonProgram[i] = GlUtils.createProgram(polygonVertexShader,
|
polygonProgram[i] = GLUtils.createProgram(polygonVertexShader,
|
||||||
polygonFragmentShader);
|
polygonFragmentShader);
|
||||||
} else if (i == 1) {
|
} else if (i == 1) {
|
||||||
polygonProgram[i] = GlUtils.createProgram(textureVertexShader,
|
polygonProgram[i] = GLUtils.createProgram(textureVertexShader,
|
||||||
textureFragmentShader);
|
textureFragmentShader);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -210,17 +209,17 @@ public final class PolygonLayer extends RenderElement {
|
|||||||
}
|
}
|
||||||
GLState.blend(true);
|
GLState.blend(true);
|
||||||
|
|
||||||
GlUtils.setColor(hPolygonColor[shader], a.color, f);
|
GLUtils.setColor(hPolygonColor[shader], a.color, f);
|
||||||
|
|
||||||
} else if (a.blend > 0 && a.blend <= zoom) {
|
} else if (a.blend > 0 && a.blend <= zoom) {
|
||||||
/* blend colors (not alpha) */
|
/* blend colors (not alpha) */
|
||||||
GLState.blend(false);
|
GLState.blend(false);
|
||||||
|
|
||||||
if (a.blend == zoom)
|
if (a.blend == zoom)
|
||||||
GlUtils.setColorBlend(hPolygonColor[shader],
|
GLUtils.setColorBlend(hPolygonColor[shader],
|
||||||
a.color, a.blendColor, scale - 1.0f);
|
a.color, a.blendColor, scale - 1.0f);
|
||||||
else
|
else
|
||||||
GlUtils.setColor(hPolygonColor[shader], a.blendColor, 1);
|
GLUtils.setColor(hPolygonColor[shader], a.blendColor, 1);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (a.color < 0xff000000)
|
if (a.color < 0xff000000)
|
||||||
@ -228,7 +227,7 @@ public final class PolygonLayer extends RenderElement {
|
|||||||
else
|
else
|
||||||
GLState.blend(false);
|
GLState.blend(false);
|
||||||
|
|
||||||
GlUtils.setColor(hPolygonColor[shader], a.color, 1);
|
GLUtils.setColor(hPolygonColor[shader], a.color, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set stencil buffer mask used to draw this layer
|
// set stencil buffer mask used to draw this layer
|
||||||
@ -433,7 +432,7 @@ public final class PolygonLayer extends RenderElement {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (color != 0) {
|
if (color != 0) {
|
||||||
GlUtils.setColor(hPolygonColor[0], color, 1);
|
GLUtils.setColor(hPolygonColor[0], color, 1);
|
||||||
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)
|
||||||
@ -458,7 +457,7 @@ public final class PolygonLayer extends RenderElement {
|
|||||||
private static float[] debugFillColor2 = { .8f, .8f, .8f, .8f };
|
private static float[] debugFillColor2 = { .8f, .8f, .8f, .8f };
|
||||||
private static FloatBuffer mDebugFill;
|
private static FloatBuffer mDebugFill;
|
||||||
|
|
||||||
static void debugDraw(Matrix4 m, float[] coords, int color) {
|
static void debugDraw(GLMatrix m, float[] coords, int color) {
|
||||||
GLState.test(false, false);
|
GLState.test(false, false);
|
||||||
if (mDebugFill == null) {
|
if (mDebugFill == null) {
|
||||||
mDebugFill = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder())
|
mDebugFill = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder())
|
||||||
@ -478,13 +477,13 @@ public final class PolygonLayer extends RenderElement {
|
|||||||
m.setAsUniform(hPolygonMatrix[0]);
|
m.setAsUniform(hPolygonMatrix[0]);
|
||||||
|
|
||||||
if (color == 0)
|
if (color == 0)
|
||||||
GlUtils.glUniform4fv(hPolygonColor[0], 1, debugFillColor);
|
GLUtils.glUniform4fv(hPolygonColor[0], 1, debugFillColor);
|
||||||
else
|
else
|
||||||
GlUtils.glUniform4fv(hPolygonColor[0], 1, debugFillColor2);
|
GLUtils.glUniform4fv(hPolygonColor[0], 1, debugFillColor2);
|
||||||
|
|
||||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4);
|
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
|
||||||
GlUtils.checkGlError("draw debug");
|
GLUtils.checkGlError("draw debug");
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String polygonVertexShader = ""
|
private final static String polygonVertexShader = ""
|
||||||
|
|||||||
@ -18,12 +18,11 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import org.oscim.backend.CanvasAdapter;
|
import org.oscim.backend.CanvasAdapter;
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.backend.Log;
|
import org.oscim.backend.Log;
|
||||||
import org.oscim.backend.canvas.Bitmap;
|
import org.oscim.backend.canvas.Bitmap;
|
||||||
import org.oscim.backend.canvas.Color;
|
import org.oscim.backend.canvas.Color;
|
||||||
import org.oscim.renderer.GLState;
|
import org.oscim.renderer.GLState;
|
||||||
import org.oscim.utils.GlUtils;
|
import org.oscim.renderer.GLUtils;
|
||||||
import org.oscim.utils.pool.Inlist;
|
import org.oscim.utils.pool.Inlist;
|
||||||
import org.oscim.utils.pool.SyncPool;
|
import org.oscim.utils.pool.SyncPool;
|
||||||
|
|
||||||
@ -31,7 +30,8 @@ import org.oscim.utils.pool.SyncPool;
|
|||||||
|
|
||||||
public class TextureItem extends Inlist<TextureItem> {
|
public class TextureItem extends Inlist<TextureItem> {
|
||||||
private final static String TAG = TextureItem.class.getName();
|
private final static String TAG = TextureItem.class.getName();
|
||||||
private static final GL20 GL = GLAdapter.get();
|
|
||||||
|
private static GL20 GL;
|
||||||
|
|
||||||
// texture ID
|
// texture ID
|
||||||
public int id;
|
public int id;
|
||||||
@ -135,7 +135,7 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
pool = null;
|
pool = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int[] textureIds = GlUtils.glGenTextures(num);
|
int[] textureIds = GLUtils.glGenTextures(num);
|
||||||
|
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
TextureItem to = new TextureItem(textureIds[i]);
|
TextureItem to = new TextureItem(textureIds[i]);
|
||||||
@ -216,7 +216,7 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This function may only be used in GLRenderer Thread.
|
* This function may only be used in GLRenderer Thread.
|
||||||
*
|
*
|
||||||
* @param t
|
* @param t
|
||||||
* the TextureObjet to compile and upload
|
* the TextureObjet to compile and upload
|
||||||
*/
|
*/
|
||||||
@ -231,11 +231,11 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
int size = mTextures.size();
|
int size = mTextures.size();
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
int[] tmp = new int[size];
|
int[] tmp = new int[size];
|
||||||
for (int i = 0; i < size; i++){
|
for (int i = 0; i < size; i++) {
|
||||||
tmp[i] = mTextures.get(i).intValue();
|
tmp[i] = mTextures.get(i).intValue();
|
||||||
}
|
}
|
||||||
mTextures.clear();
|
mTextures.clear();
|
||||||
GlUtils.glDeleteTextures(size, tmp);
|
GLUtils.glDeleteTextures(size, tmp);
|
||||||
|
|
||||||
mTexCnt -= size;
|
mTexCnt -= size;
|
||||||
}
|
}
|
||||||
@ -243,20 +243,20 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
|
|
||||||
if (t.id < 0) {
|
if (t.id < 0) {
|
||||||
mTexCnt++;
|
mTexCnt++;
|
||||||
int[] textureIds = GlUtils.glGenTextures(1);
|
int[] textureIds = GLUtils.glGenTextures(1);
|
||||||
t.id = textureIds[0];
|
t.id = textureIds[0];
|
||||||
initTexture(t);
|
initTexture(t);
|
||||||
if (TextureLayer.Renderer.debug)
|
if (TextureLayer.Renderer.debug)
|
||||||
Log.d(TAG, "fill:" + pool.getFill()
|
Log.d(TAG, "fill:" + pool.getFill()
|
||||||
+ " count:" + mTexCnt
|
+ " count:" + mTexCnt
|
||||||
+ " new texture " + t.id);
|
+ " new texture " + t.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Log.d(TAG, "UPLOAD ID: " + t.id);
|
//Log.d(TAG, "UPLOAD ID: " + t.id);
|
||||||
|
|
||||||
uploadTexture(t, t.bitmap,
|
uploadTexture(t, t.bitmap,
|
||||||
mBitmapFormat, mBitmapType,
|
mBitmapFormat, mBitmapType,
|
||||||
TEXTURE_WIDTH, TEXTURE_HEIGHT);
|
TEXTURE_WIDTH, TEXTURE_HEIGHT);
|
||||||
|
|
||||||
if (!t.ownBitmap)
|
if (!t.ownBitmap)
|
||||||
TextureItem.releaseBitmap(t);
|
TextureItem.releaseBitmap(t);
|
||||||
@ -267,7 +267,7 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void uploadTexture(TextureItem t, Bitmap bitmap,
|
public static void uploadTexture(TextureItem t, Bitmap bitmap,
|
||||||
int format, int type, int w, int h) {
|
int format, int type, int w, int h) {
|
||||||
|
|
||||||
if (t == null) {
|
if (t == null) {
|
||||||
Log.d(TAG, "no texture!");
|
Log.d(TAG, "no texture!");
|
||||||
@ -287,31 +287,33 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (TextureLayer.Renderer.debug)
|
if (TextureLayer.Renderer.debug)
|
||||||
GlUtils.checkGlError(TAG);
|
GLUtils.checkGlError(TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initTexture(TextureItem t) {
|
private static void initTexture(TextureItem t) {
|
||||||
GLState.bindTex2D(t.id);
|
GLState.bindTex2D(t.id);
|
||||||
|
|
||||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER,
|
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER,
|
||||||
GL20.GL_LINEAR);
|
GL20.GL_LINEAR);
|
||||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MAG_FILTER,
|
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MAG_FILTER,
|
||||||
GL20.GL_LINEAR);
|
GL20.GL_LINEAR);
|
||||||
|
|
||||||
if (t.repeat) {
|
if (t.repeat) {
|
||||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_S,
|
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_S,
|
||||||
GL20.GL_REPEAT);
|
GL20.GL_REPEAT);
|
||||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_T,
|
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_T,
|
||||||
GL20.GL_REPEAT);
|
GL20.GL_REPEAT);
|
||||||
} else {
|
} else {
|
||||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_S,
|
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_S,
|
||||||
GL20.GL_CLAMP_TO_EDGE);
|
GL20.GL_CLAMP_TO_EDGE);
|
||||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_T,
|
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_T,
|
||||||
GL20.GL_CLAMP_TO_EDGE);
|
GL20.GL_CLAMP_TO_EDGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init(int num) {
|
static void init(GL20 gl, int num) {
|
||||||
|
GL = gl;
|
||||||
|
|
||||||
Log.d(TAG, "init textures " + num);
|
Log.d(TAG, "init textures " + num);
|
||||||
mTexCnt = num;
|
mTexCnt = num;
|
||||||
pool.init(num);
|
pool.init(num);
|
||||||
|
|||||||
@ -19,11 +19,10 @@ import static org.oscim.renderer.MapRenderer.COORD_SCALE;
|
|||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.renderer.MapRenderer;
|
|
||||||
import org.oscim.renderer.GLState;
|
import org.oscim.renderer.GLState;
|
||||||
|
import org.oscim.renderer.GLUtils;
|
||||||
|
import org.oscim.renderer.MapRenderer;
|
||||||
import org.oscim.renderer.MapRenderer.Matrices;
|
import org.oscim.renderer.MapRenderer.Matrices;
|
||||||
import org.oscim.utils.GlUtils;
|
|
||||||
|
|
||||||
public abstract class TextureLayer extends RenderElement {
|
public abstract class TextureLayer extends RenderElement {
|
||||||
// holds textures and offset in vbo
|
// holds textures and offset in vbo
|
||||||
@ -88,7 +87,7 @@ public abstract class TextureLayer extends RenderElement {
|
|||||||
public static final class Renderer {
|
public static final class Renderer {
|
||||||
//private final static String TAG = TextureRenderer.class.getName();
|
//private final static String TAG = TextureRenderer.class.getName();
|
||||||
|
|
||||||
private static final GL20 GL = GLAdapter.get();
|
private static GL20 GL;
|
||||||
|
|
||||||
public final static boolean debug = false;
|
public final static boolean debug = false;
|
||||||
|
|
||||||
@ -105,8 +104,10 @@ public abstract class TextureLayer extends RenderElement {
|
|||||||
final static int VERTICES_PER_SPRITE = 4;
|
final static int VERTICES_PER_SPRITE = 4;
|
||||||
final static int SHORTS_PER_VERTICE = 6;
|
final static int SHORTS_PER_VERTICE = 6;
|
||||||
|
|
||||||
static void init() {
|
static void init(GL20 gl) {
|
||||||
mTextureProgram = GlUtils.createProgram(textVertexShader,
|
GL = gl;
|
||||||
|
|
||||||
|
mTextureProgram = GLUtils.createProgram(textVertexShader,
|
||||||
textFragmentShader);
|
textFragmentShader);
|
||||||
|
|
||||||
hTextureMVMatrix = GL.glGetUniformLocation(mTextureProgram, "u_mv");
|
hTextureMVMatrix = GL.glGetUniformLocation(mTextureProgram, "u_mv");
|
||||||
|
|||||||
@ -19,13 +19,12 @@ import java.nio.ByteOrder;
|
|||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.map.Map;
|
import org.oscim.map.Map;
|
||||||
import org.oscim.renderer.MapRenderer.Matrices;
|
|
||||||
import org.oscim.renderer.GLState;
|
import org.oscim.renderer.GLState;
|
||||||
|
import org.oscim.renderer.GLUtils;
|
||||||
import org.oscim.renderer.LayerRenderer;
|
import org.oscim.renderer.LayerRenderer;
|
||||||
import org.oscim.utils.GlUtils;
|
import org.oscim.renderer.MapRenderer.Matrices;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -37,8 +36,6 @@ import org.oscim.utils.GlUtils;
|
|||||||
|
|
||||||
public class CustomRenderer extends LayerRenderer {
|
public class CustomRenderer extends LayerRenderer {
|
||||||
|
|
||||||
private static final GL20 GL = GLAdapter.get();
|
|
||||||
|
|
||||||
private final Map mMap;
|
private final Map mMap;
|
||||||
|
|
||||||
private int mProgramObject;
|
private int mProgramObject;
|
||||||
@ -118,12 +115,12 @@ public class CustomRenderer extends LayerRenderer {
|
|||||||
// Draw the triangle
|
// Draw the triangle
|
||||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4);
|
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
|
||||||
GlUtils.checkGlError("...");
|
GLUtils.checkGlError("...");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean init() {
|
private boolean init() {
|
||||||
// Load the vertex/fragment shaders
|
// Load the vertex/fragment shaders
|
||||||
int programObject = GlUtils.createProgram(vShaderStr, fShaderStr);
|
int programObject = GLUtils.createProgram(vShaderStr, fShaderStr);
|
||||||
|
|
||||||
if (programObject == 0)
|
if (programObject == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -17,16 +17,15 @@ package org.oscim.renderer.test;
|
|||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.backend.canvas.Color;
|
import org.oscim.backend.canvas.Color;
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.renderer.BufferObject;
|
import org.oscim.renderer.BufferObject;
|
||||||
|
import org.oscim.renderer.GLState;
|
||||||
|
import org.oscim.renderer.GLUtils;
|
||||||
|
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;
|
||||||
import org.oscim.renderer.GLState;
|
|
||||||
import org.oscim.renderer.LayerRenderer;
|
|
||||||
import org.oscim.utils.FastMath;
|
import org.oscim.utils.FastMath;
|
||||||
import org.oscim.utils.GlUtils;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -38,8 +37,6 @@ import org.oscim.utils.GlUtils;
|
|||||||
|
|
||||||
public class CustomRenderer2 extends LayerRenderer {
|
public class CustomRenderer2 extends LayerRenderer {
|
||||||
|
|
||||||
private static final GL20 GL = GLAdapter.get();
|
|
||||||
|
|
||||||
private int mProgramObject;
|
private int mProgramObject;
|
||||||
private int hVertexPosition;
|
private int hVertexPosition;
|
||||||
private int hMatrixPosition;
|
private int hMatrixPosition;
|
||||||
@ -143,13 +140,13 @@ public class CustomRenderer2 extends LayerRenderer {
|
|||||||
| (int) (0xff * fx) << 8
|
| (int) (0xff * fx) << 8
|
||||||
| (int) (0xff * fz);
|
| (int) (0xff * fz);
|
||||||
|
|
||||||
GlUtils.setColor(hColorPosition, c, alpha);
|
GLUtils.setColor(hColorPosition, c, alpha);
|
||||||
|
|
||||||
GL.glDrawArrays(GL20.GL_TRIANGLE_FAN, 0, 6);
|
GL.glDrawArrays(GL20.GL_TRIANGLE_FAN, 0, 6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GlUtils.setColor(hColorPosition, Color.DKGRAY, 0.3f);
|
GLUtils.setColor(hColorPosition, Color.DKGRAY, 0.3f);
|
||||||
|
|
||||||
for (int y = -offset_y; y < offset_y; y++) {
|
for (int y = -offset_y; y < offset_y; y++) {
|
||||||
for (int x = -offset_x; x < offset_x; x++) {
|
for (int x = -offset_x; x < offset_x; x++) {
|
||||||
@ -161,12 +158,12 @@ public class CustomRenderer2 extends LayerRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GlUtils.checkGlError("...");
|
GLUtils.checkGlError("...");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean init() {
|
private boolean init() {
|
||||||
// Load the vertex/fragment shaders
|
// Load the vertex/fragment shaders
|
||||||
int programObject = GlUtils.createProgram(vShaderStr, fShaderStr);
|
int programObject = GLUtils.createProgram(vShaderStr, fShaderStr);
|
||||||
|
|
||||||
if (programObject == 0)
|
if (programObject == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -18,21 +18,20 @@ import static org.oscim.tiling.MapTile.STATE_NEW_DATA;
|
|||||||
import static org.oscim.tiling.MapTile.STATE_READY;
|
import static org.oscim.tiling.MapTile.STATE_READY;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.backend.Log;
|
import org.oscim.backend.Log;
|
||||||
import org.oscim.core.MapPosition;
|
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.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;
|
||||||
import org.oscim.renderer.elements.BitmapLayer;
|
import org.oscim.renderer.elements.BitmapLayer;
|
||||||
import org.oscim.renderer.elements.RenderElement;
|
|
||||||
import org.oscim.renderer.elements.LineLayer;
|
import org.oscim.renderer.elements.LineLayer;
|
||||||
import org.oscim.renderer.elements.LineTexLayer;
|
import org.oscim.renderer.elements.LineTexLayer;
|
||||||
import org.oscim.renderer.elements.PolygonLayer;
|
import org.oscim.renderer.elements.PolygonLayer;
|
||||||
|
import org.oscim.renderer.elements.RenderElement;
|
||||||
import org.oscim.utils.FastMath;
|
import org.oscim.utils.FastMath;
|
||||||
import org.oscim.utils.Matrix4;
|
|
||||||
import org.oscim.utils.ScanBox;
|
import org.oscim.utils.ScanBox;
|
||||||
import org.oscim.utils.quadtree.QuadTree;
|
import org.oscim.utils.quadtree.QuadTree;
|
||||||
|
|
||||||
@ -335,8 +334,6 @@ public class TileRenderer extends LayerRenderer {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final GL20 GL = GLAdapter.get();
|
|
||||||
|
|
||||||
// Counter increases polygon-offset for each tile drawn.
|
// Counter increases polygon-offset for each tile drawn.
|
||||||
private int mOffsetCnt;
|
private int mOffsetCnt;
|
||||||
|
|
||||||
@ -345,7 +342,7 @@ public class TileRenderer extends LayerRenderer {
|
|||||||
private int mDrawSerial = 0;
|
private int mDrawSerial = 0;
|
||||||
|
|
||||||
private Matrices mMatrices;
|
private Matrices mMatrices;
|
||||||
private final Matrix4 mProjMatrix = new Matrix4();
|
private final GLMatrix mProjMatrix = new GLMatrix();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw tiles:
|
* Draw tiles:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user