remove android dependencies from lib
This commit is contained in:
parent
10425ff232
commit
83025d3365
468
src/com/badlogic/gdx/backends/android/AndroidGL20.java
Normal file
468
src/com/badlogic/gdx/backends/android/AndroidGL20.java
Normal file
@ -0,0 +1,468 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011 See AUTHORS file.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
|
||||
package com.badlogic.gdx.backends.android;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
|
||||
public class AndroidGL20 implements GL20 {
|
||||
static {
|
||||
System.loadLibrary("androidgl20");
|
||||
init();
|
||||
}
|
||||
|
||||
private static native void init ();
|
||||
|
||||
@Override
|
||||
public native void glActiveTexture (int texture);
|
||||
|
||||
@Override
|
||||
public native void glAttachShader (int program, int shader);
|
||||
|
||||
@Override
|
||||
public native void glBindAttribLocation (int program, int index, String name);
|
||||
|
||||
@Override
|
||||
public native void glBindBuffer (int target, int buffer);
|
||||
|
||||
@Override
|
||||
public native void glBindFramebuffer (int target, int framebuffer);
|
||||
|
||||
@Override
|
||||
public native void glBindRenderbuffer (int target, int renderbuffer);
|
||||
|
||||
@Override
|
||||
public native void glBindTexture (int target, int texture);
|
||||
|
||||
@Override
|
||||
public native void glBlendColor (float red, float green, float blue, float alpha);
|
||||
|
||||
@Override
|
||||
public native void glBlendEquation (int mode);
|
||||
|
||||
@Override
|
||||
public native void glBlendEquationSeparate (int modeRGB, int modeAlpha);
|
||||
|
||||
@Override
|
||||
public native void glBlendFunc (int sfactor, int dfactor);
|
||||
|
||||
@Override
|
||||
public native void glBlendFuncSeparate (int srcRGB, int dstRGB, int srcAlpha, int dstAlpha);
|
||||
|
||||
@Override
|
||||
public native void glBufferData (int target, int size, Buffer data, int usage);
|
||||
|
||||
@Override
|
||||
public native void glBufferSubData (int target, int offset, int size, Buffer data);
|
||||
|
||||
@Override
|
||||
public native int glCheckFramebufferStatus (int target);
|
||||
|
||||
@Override
|
||||
public native void glClear (int mask);
|
||||
|
||||
@Override
|
||||
public native void glClearColor (float red, float green, float blue, float alpha);
|
||||
|
||||
@Override
|
||||
public native void glClearDepthf (float depth);
|
||||
|
||||
@Override
|
||||
public native void glClearStencil (int s);
|
||||
|
||||
@Override
|
||||
public native void glColorMask (boolean red, boolean green, boolean blue, boolean alpha);
|
||||
|
||||
@Override
|
||||
public native void glCompileShader (int shader);
|
||||
|
||||
@Override
|
||||
public native void glCompressedTexImage2D (int target, int level, int internalformat, int width, int height, int border,
|
||||
int imageSize, Buffer data);
|
||||
|
||||
@Override
|
||||
public native void glCompressedTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height,
|
||||
int format, int imageSize, Buffer data);
|
||||
|
||||
@Override
|
||||
public native void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border);
|
||||
|
||||
@Override
|
||||
public native void glCopyTexSubImage2D (int target, int level, int xoffset, int yoffset, int x, int y, int width, int height);
|
||||
|
||||
@Override
|
||||
public native int glCreateProgram ();
|
||||
|
||||
@Override
|
||||
public native int glCreateShader (int type);
|
||||
|
||||
@Override
|
||||
public native void glCullFace (int mode);
|
||||
|
||||
@Override
|
||||
public native void glDeleteBuffers (int n, IntBuffer buffers);
|
||||
|
||||
@Override
|
||||
public native void glDeleteFramebuffers (int n, IntBuffer framebuffers);
|
||||
|
||||
@Override
|
||||
public native void glDeleteProgram (int program);
|
||||
|
||||
@Override
|
||||
public native void glDeleteRenderbuffers (int n, IntBuffer renderbuffers);
|
||||
|
||||
@Override
|
||||
public native void glDeleteShader (int shader);
|
||||
|
||||
@Override
|
||||
public native void glDeleteTextures (int n, IntBuffer textures);
|
||||
|
||||
@Override
|
||||
public native void glDepthFunc (int func);
|
||||
|
||||
@Override
|
||||
public native void glDepthMask (boolean flag);
|
||||
|
||||
@Override
|
||||
public native void glDepthRangef (float zNear, float zFar);
|
||||
|
||||
@Override
|
||||
public native void glDetachShader (int program, int shader);
|
||||
|
||||
@Override
|
||||
public native void glDisable (int cap);
|
||||
|
||||
@Override
|
||||
public native void glDisableVertexAttribArray (int index);
|
||||
|
||||
@Override
|
||||
public native void glDrawArrays (int mode, int first, int count);
|
||||
|
||||
@Override
|
||||
public native void glDrawElements (int mode, int count, int type, Buffer indices);
|
||||
|
||||
@Override
|
||||
public native void glDrawElements (int mode, int count, int type, int indices);
|
||||
|
||||
@Override
|
||||
public native void glEnable (int cap);
|
||||
|
||||
@Override
|
||||
public native void glEnableVertexAttribArray (int index);
|
||||
|
||||
@Override
|
||||
public native void glFinish ();
|
||||
|
||||
@Override
|
||||
public native void glFlush ();
|
||||
|
||||
@Override
|
||||
public native void glFramebufferRenderbuffer (int target, int attachment, int renderbuffertarget, int renderbuffer);
|
||||
|
||||
@Override
|
||||
public native void glFramebufferTexture2D (int target, int attachment, int textarget, int texture, int level);
|
||||
|
||||
@Override
|
||||
public native void glFrontFace (int mode);
|
||||
|
||||
@Override
|
||||
public native void glGenBuffers (int n, IntBuffer buffers);
|
||||
|
||||
@Override
|
||||
public native void glGenerateMipmap (int target);
|
||||
|
||||
@Override
|
||||
public native void glGenFramebuffers (int n, IntBuffer framebuffers);
|
||||
|
||||
@Override
|
||||
public native void glGenRenderbuffers (int n, IntBuffer renderbuffers);
|
||||
|
||||
@Override
|
||||
public native void glGenTextures (int n, IntBuffer textures);
|
||||
|
||||
@Override
|
||||
public native String glGetActiveAttrib (int program, int index, IntBuffer size, Buffer type);
|
||||
|
||||
@Override
|
||||
public native String glGetActiveUniform (int program, int index, IntBuffer size, Buffer type);
|
||||
|
||||
@Override
|
||||
public native void glGetAttachedShaders (int program, int maxcount, Buffer count, IntBuffer shaders);
|
||||
|
||||
@Override
|
||||
public native int glGetAttribLocation (int program, String name);
|
||||
|
||||
@Override
|
||||
public native void glGetBooleanv (int pname, Buffer params);
|
||||
|
||||
@Override
|
||||
public native void glGetBufferParameteriv (int target, int pname, IntBuffer params);
|
||||
|
||||
@Override
|
||||
public native int glGetError ();
|
||||
|
||||
@Override
|
||||
public native void glGetFloatv (int pname, FloatBuffer params);
|
||||
|
||||
@Override
|
||||
public native void glGetFramebufferAttachmentParameteriv (int target, int attachment, int pname, IntBuffer params);
|
||||
|
||||
@Override
|
||||
public native void glGetIntegerv (int pname, IntBuffer params);
|
||||
|
||||
@Override
|
||||
public native void glGetProgramiv (int program, int pname, IntBuffer params);
|
||||
|
||||
@Override
|
||||
public native String glGetProgramInfoLog (int program);
|
||||
|
||||
@Override
|
||||
public native void glGetRenderbufferParameteriv (int target, int pname, IntBuffer params);
|
||||
|
||||
@Override
|
||||
public native void glGetShaderiv (int shader, int pname, IntBuffer params);
|
||||
|
||||
@Override
|
||||
public native String glGetShaderInfoLog (int shader);
|
||||
|
||||
@Override
|
||||
public native void glGetShaderPrecisionFormat (int shadertype, int precisiontype, IntBuffer range, IntBuffer precision);
|
||||
|
||||
@Override
|
||||
public native void glGetShaderSource (int shader, int bufsize, Buffer length, String source);
|
||||
|
||||
@Override
|
||||
public native String glGetString (int name);
|
||||
|
||||
@Override
|
||||
public native void glGetTexParameterfv (int target, int pname, FloatBuffer params);
|
||||
|
||||
@Override
|
||||
public native void glGetTexParameteriv (int target, int pname, IntBuffer params);
|
||||
|
||||
@Override
|
||||
public native void glGetUniformfv (int program, int location, FloatBuffer params);
|
||||
|
||||
@Override
|
||||
public native void glGetUniformiv (int program, int location, IntBuffer params);
|
||||
|
||||
@Override
|
||||
public native int glGetUniformLocation (int program, String name);
|
||||
|
||||
@Override
|
||||
public native void glGetVertexAttribfv (int index, int pname, FloatBuffer params);
|
||||
|
||||
@Override
|
||||
public native void glGetVertexAttribiv (int index, int pname, IntBuffer params);
|
||||
|
||||
@Override
|
||||
public native void glGetVertexAttribPointerv (int index, int pname, Buffer pointer);
|
||||
|
||||
@Override
|
||||
public native void glHint (int target, int mode);
|
||||
|
||||
@Override
|
||||
public native boolean glIsBuffer (int buffer);
|
||||
|
||||
@Override
|
||||
public native boolean glIsEnabled (int cap);
|
||||
|
||||
@Override
|
||||
public native boolean glIsFramebuffer (int framebuffer);
|
||||
|
||||
@Override
|
||||
public native boolean glIsProgram (int program);
|
||||
|
||||
@Override
|
||||
public native boolean glIsRenderbuffer (int renderbuffer);
|
||||
|
||||
@Override
|
||||
public native boolean glIsShader (int shader);
|
||||
|
||||
@Override
|
||||
public native boolean glIsTexture (int texture);
|
||||
|
||||
@Override
|
||||
public native void glLineWidth (float width);
|
||||
|
||||
@Override
|
||||
public native void glLinkProgram (int program);
|
||||
|
||||
@Override
|
||||
public native void glPixelStorei (int pname, int param);
|
||||
|
||||
@Override
|
||||
public native void glPolygonOffset (float factor, float units);
|
||||
|
||||
@Override
|
||||
public native void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels);
|
||||
|
||||
@Override
|
||||
public native void glReleaseShaderCompiler ();
|
||||
|
||||
@Override
|
||||
public native void glRenderbufferStorage (int target, int internalformat, int width, int height);
|
||||
|
||||
@Override
|
||||
public native void glSampleCoverage (float value, boolean invert);
|
||||
|
||||
@Override
|
||||
public native void glScissor (int x, int y, int width, int height);
|
||||
|
||||
@Override
|
||||
public native void glShaderBinary (int n, IntBuffer shaders, int binaryformat, Buffer binary, int length);
|
||||
|
||||
@Override
|
||||
public native void glShaderSource (int shader, String string);
|
||||
|
||||
@Override
|
||||
public native void glStencilFunc (int func, int ref, int mask);
|
||||
|
||||
@Override
|
||||
public native void glStencilFuncSeparate (int face, int func, int ref, int mask);
|
||||
|
||||
@Override
|
||||
public native void glStencilMask (int mask);
|
||||
|
||||
@Override
|
||||
public native void glStencilMaskSeparate (int face, int mask);
|
||||
|
||||
@Override
|
||||
public native void glStencilOp (int fail, int zfail, int zpass);
|
||||
|
||||
@Override
|
||||
public native void glStencilOpSeparate (int face, int fail, int zfail, int zpass);
|
||||
|
||||
@Override
|
||||
public native void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format,
|
||||
int type, Buffer pixels);
|
||||
|
||||
@Override
|
||||
public native void glTexParameterf (int target, int pname, float param);
|
||||
|
||||
@Override
|
||||
public native void glTexParameterfv (int target, int pname, FloatBuffer params);
|
||||
|
||||
@Override
|
||||
public native void glTexParameteri (int target, int pname, int param);
|
||||
|
||||
@Override
|
||||
public native void glTexParameteriv (int target, int pname, IntBuffer params);
|
||||
|
||||
@Override
|
||||
public native void glTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format,
|
||||
int type, Buffer pixels);
|
||||
|
||||
@Override
|
||||
public native void glUniform1f (int location, float x);
|
||||
|
||||
@Override
|
||||
public native void glUniform1fv (int location, int count, FloatBuffer v);
|
||||
|
||||
@Override
|
||||
public native void glUniform1i (int location, int x);
|
||||
|
||||
@Override
|
||||
public native void glUniform1iv (int location, int count, IntBuffer v);
|
||||
|
||||
@Override
|
||||
public native void glUniform2f (int location, float x, float y);
|
||||
|
||||
@Override
|
||||
public native void glUniform2fv (int location, int count, FloatBuffer v);
|
||||
|
||||
@Override
|
||||
public native void glUniform2i (int location, int x, int y);
|
||||
|
||||
@Override
|
||||
public native void glUniform2iv (int location, int count, IntBuffer v);
|
||||
|
||||
@Override
|
||||
public native void glUniform3f (int location, float x, float y, float z);
|
||||
|
||||
@Override
|
||||
public native void glUniform3fv (int location, int count, FloatBuffer v);
|
||||
|
||||
@Override
|
||||
public native void glUniform3i (int location, int x, int y, int z);
|
||||
|
||||
@Override
|
||||
public native void glUniform3iv (int location, int count, IntBuffer v);
|
||||
|
||||
@Override
|
||||
public native void glUniform4f (int location, float x, float y, float z, float w);
|
||||
|
||||
@Override
|
||||
public native void glUniform4fv (int location, int count, FloatBuffer v);
|
||||
|
||||
@Override
|
||||
public native void glUniform4i (int location, int x, int y, int z, int w);
|
||||
|
||||
@Override
|
||||
public native void glUniform4iv (int location, int count, IntBuffer v);
|
||||
|
||||
@Override
|
||||
public native void glUniformMatrix2fv (int location, int count, boolean transpose, FloatBuffer value);
|
||||
|
||||
@Override
|
||||
public native void glUniformMatrix3fv (int location, int count, boolean transpose, FloatBuffer value);
|
||||
|
||||
@Override
|
||||
public native void glUniformMatrix4fv (int location, int count, boolean transpose, FloatBuffer value);
|
||||
|
||||
@Override
|
||||
public native void glUseProgram (int program);
|
||||
|
||||
@Override
|
||||
public native void glValidateProgram (int program);
|
||||
|
||||
@Override
|
||||
public native void glVertexAttrib1f (int indx, float x);
|
||||
|
||||
@Override
|
||||
public native void glVertexAttrib1fv (int indx, FloatBuffer values);
|
||||
|
||||
@Override
|
||||
public native void glVertexAttrib2f (int indx, float x, float y);
|
||||
|
||||
@Override
|
||||
public native void glVertexAttrib2fv (int indx, FloatBuffer values);
|
||||
|
||||
@Override
|
||||
public native void glVertexAttrib3f (int indx, float x, float y, float z);
|
||||
|
||||
@Override
|
||||
public native void glVertexAttrib3fv (int indx, FloatBuffer values);
|
||||
|
||||
@Override
|
||||
public native void glVertexAttrib4f (int indx, float x, float y, float z, float w);
|
||||
|
||||
@Override
|
||||
public native void glVertexAttrib4fv (int indx, FloatBuffer values);
|
||||
|
||||
@Override
|
||||
public native void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, Buffer ptr);
|
||||
|
||||
@Override
|
||||
public native void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, int ptr);
|
||||
|
||||
@Override
|
||||
public native void glViewport (int x, int y, int width, int height);
|
||||
}
|
42
src/org/oscim/android/AndroidLog.java
Normal file
42
src/org/oscim/android/AndroidLog.java
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2013
|
||||
*
|
||||
* 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
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package org.oscim.android;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class AndroidLog implements org.oscim.backend.Log.Logger{
|
||||
|
||||
@Override
|
||||
public void d(String tag, String msg) {
|
||||
Log.d(tag, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void w(String tag, String msg) {
|
||||
Log.w(tag, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void e(String tag, String msg) {
|
||||
Log.e(tag, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void i(String tag, String msg) {
|
||||
Log.i(tag, msg);
|
||||
}
|
||||
|
||||
}
|
@ -15,7 +15,9 @@
|
||||
*/
|
||||
package org.oscim.android;
|
||||
|
||||
import org.oscim.android.canvas.AndroidGraphics;
|
||||
import org.oscim.android.input.AndroidMotionEvent;
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.view.MapRenderCallback;
|
||||
@ -48,10 +50,14 @@ public class AndroidMapView extends RelativeLayout implements MapRenderCallback
|
||||
private int mHeight;
|
||||
private boolean mInitialized;
|
||||
|
||||
public static float dpi;
|
||||
|
||||
private final MapView mMapView;
|
||||
|
||||
static {
|
||||
CanvasAdapter.g = AndroidGraphics.INSTANCE;
|
||||
Log.logger = new AndroidLog();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* the enclosing MapActivity instance.
|
||||
@ -85,7 +91,7 @@ public class AndroidMapView extends RelativeLayout implements MapRenderCallback
|
||||
this.setWillNotDraw(true);
|
||||
|
||||
DisplayMetrics metrics = getResources().getDisplayMetrics();
|
||||
dpi = Math.max(metrics.xdpi, metrics.ydpi);
|
||||
CanvasAdapter.dpi = (int)Math.max(metrics.xdpi, metrics.ydpi);
|
||||
|
||||
// TODO make this dpi dependent
|
||||
Tile.SIZE = 400;
|
||||
|
@ -14,7 +14,6 @@
|
||||
*/
|
||||
package org.oscim.android;
|
||||
|
||||
import org.oscim.utils.GlConfigChooser;
|
||||
import org.oscim.view.MapView;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.oscim.utils;
|
||||
package org.oscim.android;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* 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
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
@ -16,14 +17,15 @@ package org.oscim.backend;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.oscim.android.canvas.AndroidGraphics;
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.backend.canvas.Canvas;
|
||||
import org.oscim.backend.canvas.Paint;
|
||||
|
||||
|
||||
public abstract class CanvasAdapter {
|
||||
public static CanvasAdapter g = AndroidGraphics.INSTANCE;
|
||||
public static CanvasAdapter g;
|
||||
|
||||
public static float dpi = 240;
|
||||
|
||||
public enum Color {
|
||||
BLACK, CYAN, TRANSPARENT, WHITE;
|
||||
|
@ -14,6 +14,8 @@
|
||||
*/
|
||||
package org.oscim.backend;
|
||||
|
||||
public class GLAdapter {
|
||||
import com.badlogic.gdx.backends.android.AndroidGL20;
|
||||
|
||||
public class GLAdapter {
|
||||
public static GL20 INSTANCE = new AndroidGL20();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* 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
|
||||
@ -15,17 +15,25 @@
|
||||
package org.oscim.backend;
|
||||
|
||||
public class Log {
|
||||
public static Logger logger;
|
||||
|
||||
public static void d(String tag, String msg){
|
||||
android.util.Log.d(tag, msg);
|
||||
logger.d(tag, msg);
|
||||
}
|
||||
public static void w(String tag, String msg){
|
||||
android.util.Log.w(tag, msg);
|
||||
logger.w(tag, msg);
|
||||
}
|
||||
public static void e(String tag, String msg){
|
||||
android.util.Log.e(tag, msg);
|
||||
logger.e(tag, msg);
|
||||
}
|
||||
public static void i(String tag, String msg){
|
||||
android.util.Log.i(tag, msg);
|
||||
logger.i(tag, msg);
|
||||
}
|
||||
|
||||
public interface Logger{
|
||||
void d(String tag, String msg);
|
||||
void w(String tag, String msg);
|
||||
void e(String tag, String msg);
|
||||
void i(String tag, String msg);
|
||||
}
|
||||
}
|
||||
|
@ -18,14 +18,11 @@ import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.util.List;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
/**
|
||||
* A BoundingBox represents an immutable set of two latitude and two longitude
|
||||
* coordinates.
|
||||
*/
|
||||
public class BoundingBox implements Parcelable {
|
||||
public class BoundingBox {
|
||||
/**
|
||||
* Conversion factor from degrees to microdegrees.
|
||||
*/
|
||||
@ -231,30 +228,30 @@ public class BoundingBox implements Parcelable {
|
||||
return new BoundingBox(minLat, minLon, maxLat, maxLon);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<BoundingBox> CREATOR = new Parcelable.Creator<BoundingBox>() {
|
||||
@Override
|
||||
public BoundingBox createFromParcel(final Parcel in) {
|
||||
return new BoundingBox(in.readInt(), in.readInt(), in.readInt(), in.readInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BoundingBox[] newArray(final int size) {
|
||||
return new BoundingBox[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(minLatitudeE6);
|
||||
dest.writeInt(minLongitudeE6);
|
||||
dest.writeInt(maxLatitudeE6);
|
||||
dest.writeInt(maxLongitudeE6);
|
||||
}
|
||||
// public static final Parcelable.Creator<BoundingBox> CREATOR = new Parcelable.Creator<BoundingBox>() {
|
||||
// @Override
|
||||
// public BoundingBox createFromParcel(final Parcel in) {
|
||||
// return new BoundingBox(in.readInt(), in.readInt(), in.readInt(), in.readInt());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public BoundingBox[] newArray(final int size) {
|
||||
// return new BoundingBox[size];
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// @Override
|
||||
// public int describeContents() {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void writeToParcel(Parcel dest, int flags) {
|
||||
// dest.writeInt(minLatitudeE6);
|
||||
// dest.writeInt(minLongitudeE6);
|
||||
// dest.writeInt(maxLatitudeE6);
|
||||
// dest.writeInt(maxLongitudeE6);
|
||||
// }
|
||||
|
||||
// public BoundingBox(final double north, final double east, final double south,
|
||||
// final double west) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
* Copyright 2012 osmdroid authors: Nicolas Gramlich, Theodore Hong
|
||||
* Copyright 2012 Hannes Janetzek
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
@ -16,15 +15,11 @@
|
||||
*/
|
||||
package org.oscim.core;
|
||||
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
/**
|
||||
* A GeoPoint represents an immutable pair of latitude and longitude
|
||||
* coordinates.
|
||||
*/
|
||||
public class GeoPoint implements Parcelable, Comparable<GeoPoint> {
|
||||
public class GeoPoint implements Comparable<GeoPoint> {
|
||||
/**
|
||||
* Conversion factor from degrees to microdegrees.
|
||||
*/
|
||||
@ -40,8 +35,6 @@ public class GeoPoint implements Parcelable, Comparable<GeoPoint> {
|
||||
*/
|
||||
public final int longitudeE6;
|
||||
|
||||
// public final int altitude;
|
||||
|
||||
/**
|
||||
* The hash code of this object.
|
||||
*/
|
||||
@ -155,6 +148,8 @@ public class GeoPoint implements Parcelable, Comparable<GeoPoint> {
|
||||
|
||||
// ===========================================================
|
||||
// Methods from osmdroid
|
||||
// Copyright 2012 osmdroid authors: Nicolas Gramlich,
|
||||
// Theodore Hong
|
||||
// ===========================================================
|
||||
|
||||
public static final float DEG2RAD = (float) (Math.PI / 180.0);
|
||||
@ -192,26 +187,26 @@ public class GeoPoint implements Parcelable, Comparable<GeoPoint> {
|
||||
// Parcelable
|
||||
// ===========================================================
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(final Parcel out, final int flags) {
|
||||
out.writeInt(latitudeE6);
|
||||
out.writeInt(longitudeE6);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<GeoPoint> CREATOR = new Parcelable.Creator<GeoPoint>() {
|
||||
@Override
|
||||
public GeoPoint createFromParcel(final Parcel in) {
|
||||
return new GeoPoint(in.readInt(), in.readInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeoPoint[] newArray(final int size) {
|
||||
return new GeoPoint[size];
|
||||
}
|
||||
};
|
||||
// @Override
|
||||
// public int describeContents() {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void writeToParcel(final Parcel out, final int flags) {
|
||||
// out.writeInt(latitudeE6);
|
||||
// out.writeInt(longitudeE6);
|
||||
// }
|
||||
//
|
||||
// public static final Parcelable.Creator<GeoPoint> CREATOR = new Parcelable.Creator<GeoPoint>() {
|
||||
// @Override
|
||||
// public GeoPoint createFromParcel(final Parcel in) {
|
||||
// return new GeoPoint(in.readInt(), in.readInt());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public GeoPoint[] newArray(final int size) {
|
||||
// return new GeoPoint[size];
|
||||
// }
|
||||
// };
|
||||
}
|
||||
|
@ -14,13 +14,13 @@
|
||||
*/
|
||||
package org.oscim.layers;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.backend.input.MotionEvent;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.view.MapView;
|
||||
import org.oscim.view.MapViewPosition;
|
||||
|
||||
import org.oscim.backend.Log;
|
||||
|
||||
/**
|
||||
* Changes MapViewPosition for scroll, fling, scale, rotation and tilt gestures
|
||||
*
|
||||
@ -132,8 +132,16 @@ public class MapEventLayer extends InputLayer {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (e.getPointerCount() < 2)
|
||||
if (e.getPointerCount() < 2) {
|
||||
if (mx > 1 || mx < -1 || my > 1 || my < -1) {
|
||||
mMapPosition.moveMap(mx, my);
|
||||
mMapView.updateMap(true);
|
||||
|
||||
mPrevX = x1;
|
||||
mPrevY = y1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
float x2 = e.getX(1);
|
||||
float y2 = e.getY(1);
|
||||
@ -295,7 +303,7 @@ public class MapEventLayer extends InputLayer {
|
||||
// float move = Math.min(mMapView.getWidth(), mMapView.getHeight()) * 2 / 3;
|
||||
// mMapPosition.animateTo(vx * move, vy * move, 250);
|
||||
//} else {
|
||||
float s = (200 / MapView.dpi);
|
||||
float s = (200 / CanvasAdapter.dpi);
|
||||
|
||||
mMapPosition.animateFling(
|
||||
Math.round(velocityX * s),
|
||||
|
@ -28,6 +28,8 @@ package org.oscim.layers.labeling;
|
||||
// 5 R-Tree might be handy
|
||||
//
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.layers.tile.MapTile;
|
||||
@ -53,13 +55,14 @@ import org.oscim.utils.pool.Pool;
|
||||
import org.oscim.view.MapView;
|
||||
import org.oscim.view.MapViewPosition;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
//import android.os.AsyncTask;
|
||||
//import android.os.Handler;
|
||||
//import android.os.Looper;
|
||||
|
||||
class TextRenderLayer extends BasicRenderLayer {
|
||||
private final static String TAG = TextRenderLayer.class.getName();
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
private final static float MIN_CAPTION_DIST = 5;
|
||||
private final static float MIN_WAY_DIST = 3;
|
||||
|
||||
@ -623,33 +626,30 @@ class TextRenderLayer extends BasicRenderLayer {
|
||||
this.newData = true;
|
||||
}
|
||||
|
||||
if (!mHolding)
|
||||
postLabelTask((mLastRun + MAX_RELABEL_DELAY) - System.currentTimeMillis());
|
||||
//if (!mHolding)
|
||||
// postLabelTask((mLastRun + MAX_RELABEL_DELAY) - System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/* private */LabelTask mLabelTask;
|
||||
/* private */long mLastRun;
|
||||
|
||||
class LabelTask extends AsyncTask<Void, Void, Integer> {
|
||||
class LabelTask implements Runnable {
|
||||
boolean isCancelled;
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(Void... unused) {
|
||||
public void run() {
|
||||
boolean labelsChanged = false;
|
||||
if (isCancelled){
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isCancelled())
|
||||
labelsChanged = updateLabels();
|
||||
|
||||
if (!isCancelled() && labelsChanged)
|
||||
if (!isCancelled && labelsChanged)
|
||||
mMapView.render();
|
||||
|
||||
mLastRun = System.currentTimeMillis();
|
||||
mLabelTask = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
@ -660,36 +660,37 @@ class TextRenderLayer extends BasicRenderLayer {
|
||||
mLabelTask = null;
|
||||
}
|
||||
|
||||
private final Runnable mLabelUpdate = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mLabelTask == null) {
|
||||
mLabelTask = new LabelTask();
|
||||
mLabelTask.execute();
|
||||
} else {
|
||||
postLabelTask(50);
|
||||
}
|
||||
}
|
||||
};
|
||||
private Handler mLabelHandler;
|
||||
|
||||
/* private */void postLabelTask(long delay) {
|
||||
if (mLabelHandler == null) {
|
||||
mLabelHandler = new Handler(Looper.getMainLooper());
|
||||
}
|
||||
|
||||
mLabelHandler.removeCallbacks(mLabelUpdate);
|
||||
|
||||
if (delay > 0)
|
||||
mLabelHandler.postDelayed(mLabelUpdate, delay);
|
||||
else
|
||||
mLabelHandler.post(mLabelUpdate);
|
||||
}
|
||||
// private final Runnable mLabelUpdate = new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (mLabelTask == null) {
|
||||
// mLabelTask = new LabelTask();
|
||||
// mLabelTask.execute();
|
||||
// Log.d(TAG, "relabel run");
|
||||
// } else {
|
||||
// postLabelTask(50);
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// private Handler mLabelHandler;
|
||||
//
|
||||
// /* private */void postLabelTask(long delay) {
|
||||
// if (mLabelHandler == null) {
|
||||
// mLabelHandler = new Handler(Looper.getMainLooper());
|
||||
// }
|
||||
//
|
||||
// mLabelHandler.removeCallbacks(mLabelUpdate);
|
||||
//
|
||||
// if (delay > 0)
|
||||
// mLabelHandler.postDelayed(mLabelUpdate, delay);
|
||||
// else
|
||||
// mLabelHandler.post(mLabelUpdate);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public synchronized void render(MapPosition pos, Matrices m) {
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, layers.vbo.id);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, layers.vbo.id);
|
||||
GLState.test(false, false);
|
||||
|
||||
float scale = (float) (mMapPosition.scale / pos.scale);
|
||||
@ -725,13 +726,13 @@ class TextRenderLayer extends BasicRenderLayer {
|
||||
}
|
||||
|
||||
public synchronized void clearLabels() {
|
||||
if (mLabelHandler != null)
|
||||
mLabelHandler.removeCallbacks(mLabelUpdate);
|
||||
|
||||
if (mLabelTask == null) {
|
||||
cleanup();
|
||||
} else {
|
||||
mLabelTask.cancel(false);
|
||||
}
|
||||
// if (mLabelHandler != null)
|
||||
// mLabelHandler.removeCallbacks(mLabelUpdate);
|
||||
//
|
||||
// if (mLabelTask == null) {
|
||||
// cleanup();
|
||||
// } else {
|
||||
// mLabelTask.cancel(false);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,7 @@ import org.oscim.core.MapPosition;
|
||||
import org.oscim.renderer.layers.ExtrusionRenderLayer;
|
||||
import org.oscim.view.MapView;
|
||||
|
||||
import android.os.CountDownTimer;
|
||||
import org.oscim.backend.Log;
|
||||
//import android.os.CountDownTimer;
|
||||
|
||||
/**
|
||||
* @author Hannes Janetzek
|
||||
@ -45,24 +44,24 @@ public class BuildingOverlay extends Overlay {
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent e) {
|
||||
int action = e.getAction() & MotionEvent.ACTION_MASK;
|
||||
if (action == MotionEvent.ACTION_POINTER_DOWN) {
|
||||
multi++;
|
||||
} else if (action == MotionEvent.ACTION_POINTER_UP) {
|
||||
multi--;
|
||||
if (!mActive && mAlpha > 0) {
|
||||
// finish hiding
|
||||
//Log.d(TAG, "add multi hide timer " + mAlpha);
|
||||
addShowTimer(mFadeTime * mAlpha, false);
|
||||
}
|
||||
} else if (action == MotionEvent.ACTION_CANCEL) {
|
||||
multi = 0;
|
||||
Log.d(TAG, "cancel " + multi);
|
||||
if (mTimer != null) {
|
||||
mTimer.cancel();
|
||||
mTimer = null;
|
||||
}
|
||||
}
|
||||
// int action = e.getAction() & MotionEvent.ACTION_MASK;
|
||||
// if (action == MotionEvent.ACTION_POINTER_DOWN) {
|
||||
// multi++;
|
||||
// } else if (action == MotionEvent.ACTION_POINTER_UP) {
|
||||
// multi--;
|
||||
// if (!mActive && mAlpha > 0) {
|
||||
// // finish hiding
|
||||
// //Log.d(TAG, "add multi hide timer " + mAlpha);
|
||||
// addShowTimer(mFadeTime * mAlpha, false);
|
||||
// }
|
||||
// } else if (action == MotionEvent.ACTION_CANCEL) {
|
||||
// multi = 0;
|
||||
// Log.d(TAG, "cancel " + multi);
|
||||
// if (mTimer != null) {
|
||||
// mTimer.cancel();
|
||||
// mTimer = null;
|
||||
// }
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -76,20 +75,20 @@ public class BuildingOverlay extends Overlay {
|
||||
if (show && mActive)
|
||||
return;
|
||||
|
||||
if (show) {
|
||||
// start showing
|
||||
//Log.d(TAG, "add show timer " + mAlpha);
|
||||
addShowTimer(mFadeTime * (1 - mAlpha), true);
|
||||
} else if (mActive) {
|
||||
// indicate hiding
|
||||
if (multi > 0) {
|
||||
//Log.d(TAG, "add fade timer " + mAlpha);
|
||||
addFadeTimer(mFadeTime * mAlpha, false);
|
||||
} else {
|
||||
//Log.d(TAG, "add hide timer " + mAlpha);
|
||||
addShowTimer(mFadeTime * mAlpha, false);
|
||||
}
|
||||
}
|
||||
// if (show) {
|
||||
// // start showing
|
||||
// //Log.d(TAG, "add show timer " + mAlpha);
|
||||
// addShowTimer(mFadeTime * (1 - mAlpha), true);
|
||||
// } else if (mActive) {
|
||||
// // indicate hiding
|
||||
// if (multi > 0) {
|
||||
// //Log.d(TAG, "add fade timer " + mAlpha);
|
||||
// addFadeTimer(mFadeTime * mAlpha, false);
|
||||
// } else {
|
||||
// //Log.d(TAG, "add hide timer " + mAlpha);
|
||||
// addShowTimer(mFadeTime * mAlpha, false);
|
||||
// }
|
||||
// }
|
||||
mActive = show;
|
||||
}
|
||||
|
||||
@ -108,43 +107,43 @@ public class BuildingOverlay extends Overlay {
|
||||
mMapView.render();
|
||||
}
|
||||
|
||||
/* package */CountDownTimer mTimer;
|
||||
|
||||
private void addFadeTimer(final float ms, final boolean dir) {
|
||||
if (mTimer != null)
|
||||
mTimer.cancel();
|
||||
|
||||
mTimer = new CountDownTimer((long) ms, 16) {
|
||||
@Override
|
||||
public void onTick(long tick) {
|
||||
fade(ms, tick, dir, 0.2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
fade(ms, 0, dir, 0.2f);
|
||||
mTimer = null;
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
private void addShowTimer(final float ms, final boolean dir) {
|
||||
final float d = mFadeTime;
|
||||
if (mTimer != null)
|
||||
mTimer.cancel();
|
||||
|
||||
mTimer = new CountDownTimer((long) ms, 16) {
|
||||
@Override
|
||||
public void onTick(long tick) {
|
||||
fade(d, tick, dir, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
fade(d, 0, dir, 1);
|
||||
mTimer = null;
|
||||
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
// /* package */CountDownTimer mTimer;
|
||||
//
|
||||
// private void addFadeTimer(final float ms, final boolean dir) {
|
||||
// if (mTimer != null)
|
||||
// mTimer.cancel();
|
||||
//
|
||||
// mTimer = new CountDownTimer((long) ms, 16) {
|
||||
// @Override
|
||||
// public void onTick(long tick) {
|
||||
// fade(ms, tick, dir, 0.2f);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onFinish() {
|
||||
// fade(ms, 0, dir, 0.2f);
|
||||
// mTimer = null;
|
||||
// }
|
||||
// }.start();
|
||||
// }
|
||||
//
|
||||
// private void addShowTimer(final float ms, final boolean dir) {
|
||||
// final float d = mFadeTime;
|
||||
// if (mTimer != null)
|
||||
// mTimer.cancel();
|
||||
//
|
||||
// mTimer = new CountDownTimer((long) ms, 16) {
|
||||
// @Override
|
||||
// public void onTick(long tick) {
|
||||
// fade(d, tick, dir, 1);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onFinish() {
|
||||
// fade(d, 0, dir, 1);
|
||||
// mTimer = null;
|
||||
//
|
||||
// }
|
||||
// }.start();
|
||||
// }
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.MercatorProjection;
|
||||
import org.oscim.core.PointD;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.layers.overlay.OverlayItem.HotspotPlace;
|
||||
import org.oscim.renderer.GLRenderer.Matrices;
|
||||
import org.oscim.renderer.layers.BasicRenderLayer;
|
||||
import org.oscim.renderer.sublayers.SymbolItem;
|
||||
@ -33,9 +32,6 @@ import org.oscim.renderer.sublayers.SymbolLayer;
|
||||
import org.oscim.utils.GeometryUtils;
|
||||
import org.oscim.view.MapView;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
/* @author Marc Kurtz
|
||||
* @author Nicolas Gramlich
|
||||
* @author Theodore Hong
|
||||
@ -190,6 +186,7 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
|
||||
layers.textureLayers = mSymbolLayer;
|
||||
newData = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void compile() {
|
||||
super.compile();
|
||||
@ -346,63 +343,63 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
|
||||
return mFocusedItem;
|
||||
}
|
||||
|
||||
private static final Rect mRect = new Rect();
|
||||
|
||||
/**
|
||||
* Adjusts a drawable's bounds so that (0,0) is a pixel in the location
|
||||
* described by the hotspot parameter. Useful for "pin"-like graphics. For
|
||||
* convenience, returns the same drawable that was passed in.
|
||||
*
|
||||
* @param marker
|
||||
* the drawable to adjust
|
||||
* @param hotspot
|
||||
* the hotspot for the drawable
|
||||
* @return the same drawable that was passed in.
|
||||
*/
|
||||
public static synchronized Drawable boundToHotspot(final Drawable marker, HotspotPlace hotspot) {
|
||||
final int markerWidth = marker.getIntrinsicWidth();
|
||||
final int markerHeight = marker.getIntrinsicHeight();
|
||||
|
||||
mRect.set(0, 0, 0 + markerWidth, 0 + markerHeight);
|
||||
|
||||
if (hotspot == null) {
|
||||
hotspot = HotspotPlace.BOTTOM_CENTER;
|
||||
}
|
||||
|
||||
switch (hotspot) {
|
||||
default:
|
||||
case NONE:
|
||||
break;
|
||||
case CENTER:
|
||||
mRect.offset(-markerWidth / 2, -markerHeight / 2);
|
||||
break;
|
||||
case BOTTOM_CENTER:
|
||||
mRect.offset(-markerWidth / 2, -markerHeight);
|
||||
break;
|
||||
case TOP_CENTER:
|
||||
mRect.offset(-markerWidth / 2, 0);
|
||||
break;
|
||||
case RIGHT_CENTER:
|
||||
mRect.offset(-markerWidth, -markerHeight / 2);
|
||||
break;
|
||||
case LEFT_CENTER:
|
||||
mRect.offset(0, -markerHeight / 2);
|
||||
break;
|
||||
case UPPER_RIGHT_CORNER:
|
||||
mRect.offset(-markerWidth, 0);
|
||||
break;
|
||||
case LOWER_RIGHT_CORNER:
|
||||
mRect.offset(-markerWidth, -markerHeight);
|
||||
break;
|
||||
case UPPER_LEFT_CORNER:
|
||||
mRect.offset(0, 0);
|
||||
break;
|
||||
case LOWER_LEFT_CORNER:
|
||||
mRect.offset(0, -markerHeight);
|
||||
break;
|
||||
}
|
||||
marker.setBounds(mRect);
|
||||
return marker;
|
||||
}
|
||||
// private static final Rect mRect = new Rect();
|
||||
//
|
||||
// /**
|
||||
// * Adjusts a drawable's bounds so that (0,0) is a pixel in the location
|
||||
// * described by the hotspot parameter. Useful for "pin"-like graphics. For
|
||||
// * convenience, returns the same drawable that was passed in.
|
||||
// *
|
||||
// * @param marker
|
||||
// * the drawable to adjust
|
||||
// * @param hotspot
|
||||
// * the hotspot for the drawable
|
||||
// * @return the same drawable that was passed in.
|
||||
// */
|
||||
// public static synchronized Drawable boundToHotspot(final Drawable marker, HotspotPlace hotspot) {
|
||||
// final int markerWidth = marker.getIntrinsicWidth();
|
||||
// final int markerHeight = marker.getIntrinsicHeight();
|
||||
//
|
||||
// mRect.set(0, 0, 0 + markerWidth, 0 + markerHeight);
|
||||
//
|
||||
// if (hotspot == null) {
|
||||
// hotspot = HotspotPlace.BOTTOM_CENTER;
|
||||
// }
|
||||
//
|
||||
// switch (hotspot) {
|
||||
// default:
|
||||
// case NONE:
|
||||
// break;
|
||||
// case CENTER:
|
||||
// mRect.offset(-markerWidth / 2, -markerHeight / 2);
|
||||
// break;
|
||||
// case BOTTOM_CENTER:
|
||||
// mRect.offset(-markerWidth / 2, -markerHeight);
|
||||
// break;
|
||||
// case TOP_CENTER:
|
||||
// mRect.offset(-markerWidth / 2, 0);
|
||||
// break;
|
||||
// case RIGHT_CENTER:
|
||||
// mRect.offset(-markerWidth, -markerHeight / 2);
|
||||
// break;
|
||||
// case LEFT_CENTER:
|
||||
// mRect.offset(0, -markerHeight / 2);
|
||||
// break;
|
||||
// case UPPER_RIGHT_CORNER:
|
||||
// mRect.offset(-markerWidth, 0);
|
||||
// break;
|
||||
// case LOWER_RIGHT_CORNER:
|
||||
// mRect.offset(-markerWidth, -markerHeight);
|
||||
// break;
|
||||
// case UPPER_LEFT_CORNER:
|
||||
// mRect.offset(0, 0);
|
||||
// break;
|
||||
// case LOWER_LEFT_CORNER:
|
||||
// mRect.offset(0, -markerHeight);
|
||||
// break;
|
||||
// }
|
||||
// marker.setBounds(mRect);
|
||||
// return marker;
|
||||
// }
|
||||
|
||||
}
|
||||
|
@ -14,9 +14,10 @@
|
||||
*/
|
||||
package org.oscim.layers.tile;
|
||||
|
||||
import static android.opengl.GLES20.glStencilMask;
|
||||
import static org.oscim.layers.tile.MapTile.STATE_READY;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
@ -30,7 +31,6 @@ import org.oscim.utils.FastMath;
|
||||
import org.oscim.utils.Matrix4;
|
||||
import org.oscim.utils.quadtree.QuadTree;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
/**
|
||||
* This class is for rendering the Line- and PolygonLayers of visible MapTiles.
|
||||
* For visible tiles that do not have data available yet its parent in children
|
||||
@ -40,6 +40,8 @@ import android.opengl.GLES20;
|
||||
public class TileRenderer {
|
||||
//private final static String TAG = TileRenderer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
// Counter increases polygon-offset for each tile drawn.
|
||||
private static int mOffsetCnt;
|
||||
|
||||
@ -64,9 +66,9 @@ public class TileRenderer {
|
||||
mProjMatrix.setValue(14, 0);
|
||||
mProjMatrix.multiplyRhs(m.view);
|
||||
|
||||
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT);
|
||||
GL.glClear(GL20.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
GLES20.glDepthFunc(GLES20.GL_LESS);
|
||||
GL.glDepthFunc(GL20.GL_LESS);
|
||||
|
||||
// load texture for line caps
|
||||
LineRenderer.beginLines();
|
||||
@ -100,7 +102,7 @@ public class TileRenderer {
|
||||
}
|
||||
|
||||
// make sure stencil buffer write is disabled
|
||||
glStencilMask(0x00);
|
||||
GL.glStencilMask(0x00);
|
||||
|
||||
LineRenderer.endLines();
|
||||
|
||||
@ -145,7 +147,7 @@ public class TileRenderer {
|
||||
m.mvp.multiplyLhs(mProjMatrix);
|
||||
|
||||
// set depth offset (used for clipping to tile boundaries)
|
||||
GLES20.glPolygonOffset(0, mOffsetCnt++);
|
||||
GL.glPolygonOffset(0, mOffsetCnt++);
|
||||
|
||||
// simple line shader does not take forward shortening into
|
||||
// account. only used when tilt is 0.
|
||||
|
@ -20,7 +20,8 @@ import java.io.InputStream;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.oscim.view.MapView;
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.GeoPoint;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.layers.tile.TileLayer;
|
||||
@ -35,11 +36,9 @@ import org.oscim.tilesource.ITileDataSource;
|
||||
import org.oscim.tilesource.MapInfo;
|
||||
import org.oscim.tilesource.TileSource;
|
||||
import org.oscim.tilesource.TileSource.OpenResult;
|
||||
import org.oscim.tilesource.oscimap.OSciMap1TileSource;
|
||||
import org.oscim.view.MapView;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import org.oscim.backend.Log;
|
||||
|
||||
public class MapTileLayer extends TileLayer<MapTileLoader> {
|
||||
private final static String TAG = MapTileLayer.class.getName();
|
||||
|
||||
@ -87,10 +86,10 @@ public class MapTileLayer extends TileLayer<MapTileLoader> {
|
||||
mTileLoader.get(i).setTileDataSource(tileDataSource);
|
||||
}
|
||||
|
||||
if (tileSource instanceof OSciMap1TileSource)
|
||||
MapView.enableClosePolygons = false;
|
||||
else
|
||||
MapView.enableClosePolygons = true;
|
||||
//if (tileSource instanceof OSciMap1TileSource)
|
||||
// MapView.enableClosePolygons = false;
|
||||
//else
|
||||
// MapView.enableClosePolygons = true;
|
||||
|
||||
mTileManager.setZoomTable(mTileSource.getMapInfo().zoomLevel);
|
||||
|
||||
@ -191,7 +190,7 @@ public class MapTileLayer extends TileLayer<MapTileLoader> {
|
||||
try {
|
||||
inputStream = theme.getRenderThemeAsStream();
|
||||
IRenderTheme t = RenderThemeHandler.getRenderTheme(inputStream);
|
||||
t.scaleTextSize(1 + (MapView.dpi / 240 - 1) * 0.5f);
|
||||
t.scaleTextSize(1 + (CanvasAdapter.dpi / 240 - 1) * 0.5f);
|
||||
|
||||
// FIXME !!!
|
||||
GLRenderer.setRenderTheme(t);
|
||||
|
@ -17,13 +17,16 @@ package org.oscim.renderer;
|
||||
|
||||
import java.nio.Buffer;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
import org.oscim.utils.GlUtils;
|
||||
|
||||
public final class BufferObject {
|
||||
private final static String TAG = BufferObject.class.getName();
|
||||
|
||||
private final static GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
private static final int MB = 1024 * 1024;
|
||||
private static final int LIMIT_BUFFERS = 16 * MB;
|
||||
|
||||
@ -49,27 +52,27 @@ public final class BufferObject {
|
||||
bufferType = type;
|
||||
}
|
||||
|
||||
GLES20.glBindBuffer(type, id);
|
||||
GL.glBindBuffer(type, id);
|
||||
|
||||
// reuse memory allocated for vbo when possible and allocated
|
||||
// memory is less then four times the new data
|
||||
if (!clear && (size > newSize) && (size < newSize * 4)) {
|
||||
GLES20.glBufferSubData(type, 0, newSize, buf);
|
||||
GL.glBufferSubData(type, 0, newSize, buf);
|
||||
} else {
|
||||
mBufferMemoryUsage += newSize - size;
|
||||
|
||||
size = newSize;
|
||||
|
||||
GLES20.glBufferData(type, size, buf, GLES20.GL_DYNAMIC_DRAW);
|
||||
GL.glBufferData(type, size, buf, GL20.GL_DYNAMIC_DRAW);
|
||||
}
|
||||
}
|
||||
|
||||
public void bindArrayBuffer() {
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, id);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, id);
|
||||
}
|
||||
|
||||
public void bindIndexBuffer() {
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, id);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, id);
|
||||
}
|
||||
|
||||
// ---------------------------- pool ----------------------------
|
||||
@ -167,8 +170,9 @@ public final class BufferObject {
|
||||
bo = bo.next;
|
||||
}
|
||||
}
|
||||
|
||||
if (removed > 0) {
|
||||
GLES20.glDeleteBuffers(removed, vboIds, 0);
|
||||
GlUtils.glDeleteBuffers(removed, vboIds);
|
||||
counter -= removed;
|
||||
}
|
||||
|
||||
@ -176,8 +180,7 @@ public final class BufferObject {
|
||||
}
|
||||
|
||||
static void createBuffers(int num) {
|
||||
int[] mVboIds = new int[num];
|
||||
GLES20.glGenBuffers(num, mVboIds, 0);
|
||||
int[] mVboIds = GlUtils.glGenBuffers(num);
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
BufferObject bo = new BufferObject(mVboIds[i]);
|
||||
|
@ -14,16 +14,16 @@
|
||||
*/
|
||||
package org.oscim.renderer;
|
||||
|
||||
import static android.opengl.GLES20.GL_ARRAY_BUFFER;
|
||||
import static android.opengl.GLES20.GL_ONE;
|
||||
import static android.opengl.GLES20.GL_ONE_MINUS_SRC_ALPHA;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ShortBuffer;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
@ -35,14 +35,12 @@ import org.oscim.utils.Matrix4;
|
||||
import org.oscim.view.MapView;
|
||||
import org.oscim.view.MapViewPosition;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
|
||||
//import android.os.SystemClock;
|
||||
|
||||
public class GLRenderer {
|
||||
|
||||
private static final String TAG = GLRenderer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
private static final int MB = 1024 * 1024;
|
||||
private static final int SHORT_BYTES = 2;
|
||||
private static final int CACHE_TILES_MAX = 250;
|
||||
@ -59,6 +57,7 @@ public class GLRenderer {
|
||||
|
||||
private static ShortBuffer shortBuffer;
|
||||
private static FloatBuffer floatBuffer;
|
||||
private static IntBuffer intBuffer;
|
||||
private static int tmpBufferSize;
|
||||
|
||||
private static short[] mFillCoords;
|
||||
@ -163,6 +162,19 @@ public class GLRenderer {
|
||||
return floatBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only use on GL Thread!
|
||||
* Get a native IntBuffer for temporary use.
|
||||
*/
|
||||
public static IntBuffer getIntBuffer(int size) {
|
||||
if (tmpBufferSize < size * 4)
|
||||
growBuffer(size * 4);
|
||||
else
|
||||
intBuffer.clear();
|
||||
|
||||
return intBuffer;
|
||||
}
|
||||
|
||||
private static void growBuffer(int size) {
|
||||
Log.d(TAG, "grow buffer " + size);
|
||||
ByteBuffer buf = ByteBuffer
|
||||
@ -171,6 +183,7 @@ public class GLRenderer {
|
||||
|
||||
floatBuffer = buf.asFloatBuffer();
|
||||
shortBuffer = buf.asShortBuffer();
|
||||
intBuffer = buf.asIntBuffer();
|
||||
tmpBufferSize = size;
|
||||
}
|
||||
|
||||
@ -199,7 +212,7 @@ public class GLRenderer {
|
||||
}
|
||||
newSize *= SHORT_BYTES;
|
||||
|
||||
layers.vbo.loadBufferData(sbuf, newSize, GL_ARRAY_BUFFER);
|
||||
layers.vbo.loadBufferData(sbuf, newSize, GL20.GL_ARRAY_BUFFER);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -233,15 +246,15 @@ public class GLRenderer {
|
||||
|
||||
if (mUpdateColor) {
|
||||
float cc[] = mClearColor;
|
||||
GLES20.glClearColor(cc[0], cc[1], cc[2], cc[3]);
|
||||
GL.glClearColor(cc[0], cc[1], cc[2], cc[3]);
|
||||
mUpdateColor = false;
|
||||
}
|
||||
|
||||
GLES20.glDepthMask(true);
|
||||
GLES20.glStencilMask(0xFF);
|
||||
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT
|
||||
| GLES20.GL_DEPTH_BUFFER_BIT
|
||||
| GLES20.GL_STENCIL_BUFFER_BIT);
|
||||
GL.glDepthMask(true);
|
||||
GL.glStencilMask(0xFF);
|
||||
GL.glClear(GL20.GL_COLOR_BUFFER_BIT
|
||||
| GL20.GL_DEPTH_BUFFER_BIT
|
||||
| GL20.GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
@ -285,7 +298,7 @@ public class GLRenderer {
|
||||
}
|
||||
|
||||
//if (MapView.debugFrameTime) {
|
||||
// GLES20.glFinish();
|
||||
// GL.glFinish();
|
||||
// Log.d(TAG, "draw took " + (SystemClock.uptimeMillis() - start));
|
||||
//}
|
||||
|
||||
@ -317,14 +330,14 @@ public class GLRenderer {
|
||||
mMatrices.proj.multiplyLhs(mMatrices.mvp);
|
||||
}
|
||||
|
||||
GLES20.glViewport(0, 0, width, height);
|
||||
GLES20.glScissor(0, 0, width, height);
|
||||
GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
|
||||
GL.glViewport(0, 0, width, height);
|
||||
GL.glScissor(0, 0, width, height);
|
||||
GL.glEnable(GL20.GL_SCISSOR_TEST);
|
||||
|
||||
GLES20.glClearStencil(0x00);
|
||||
GL.glClearStencil(0x00);
|
||||
|
||||
GLES20.glDisable(GLES20.GL_CULL_FACE);
|
||||
GLES20.glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL.glDisable(GL20.GL_CULL_FACE);
|
||||
GL.glBlendFunc(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
//mBufferMemoryUsage = 0;
|
||||
|
||||
@ -339,8 +352,8 @@ public class GLRenderer {
|
||||
growBuffer(MB >> 2);
|
||||
|
||||
// upload quad indices used by Texture- and LineTexRenderer
|
||||
int[] vboIds = new int[1];
|
||||
GLES20.glGenBuffers(1, vboIds, 0);
|
||||
int[] vboIds = GlUtils.glGenBuffers(1);
|
||||
|
||||
mQuadIndicesID = vboIds[0];
|
||||
int maxIndices = maxQuads * 6;
|
||||
short[] indices = new short[maxIndices];
|
||||
@ -357,11 +370,11 @@ public class GLRenderer {
|
||||
shortBuffer.put(indices);
|
||||
shortBuffer.flip();
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER,
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER,
|
||||
mQuadIndicesID);
|
||||
GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER,
|
||||
indices.length * 2, shortBuffer, GLES20.GL_STATIC_DRAW);
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
GL.glBufferData(GL20.GL_ELEMENT_ARRAY_BUFFER,
|
||||
indices.length * 2, shortBuffer, GL20.GL_STATIC_DRAW);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
if (mClearColor != null)
|
||||
mUpdateColor = true;
|
||||
@ -372,7 +385,7 @@ public class GLRenderer {
|
||||
}
|
||||
|
||||
public void onSurfaceCreated() {
|
||||
// Log.d(TAG, GLES20.glGetString(GLES20.GL_EXTENSIONS));
|
||||
// Log.d(TAG, GL.glGetString(GL20.GL_EXTENSIONS));
|
||||
|
||||
// classes that require GL context for initialization
|
||||
Layers.initRenderer();
|
||||
|
@ -14,10 +14,13 @@
|
||||
*/
|
||||
package org.oscim.renderer;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
|
||||
public class GLState {
|
||||
private final static GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
private final static String TAG = GLState.class.getName();
|
||||
|
||||
private final static boolean[] vertexArray = { false, false };
|
||||
@ -33,13 +36,13 @@ public class GLState {
|
||||
depth = false;
|
||||
stencil = false;
|
||||
shader = -1;
|
||||
GLES20.glDisable(GLES20.GL_STENCIL_TEST);
|
||||
GLES20.glDisable(GLES20.GL_DEPTH_TEST);
|
||||
GL.glDisable(GL20.GL_STENCIL_TEST);
|
||||
GL.glDisable(GL20.GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
public static boolean useProgram(int shaderProgram) {
|
||||
if (shaderProgram != shader) {
|
||||
GLES20.glUseProgram(shaderProgram);
|
||||
GL.glUseProgram(shaderProgram);
|
||||
shader = shaderProgram;
|
||||
return true;
|
||||
}
|
||||
@ -51,9 +54,9 @@ public class GLState {
|
||||
return;
|
||||
|
||||
if (enable)
|
||||
GLES20.glEnable(GLES20.GL_BLEND);
|
||||
GL.glEnable(GL20.GL_BLEND);
|
||||
else
|
||||
GLES20.glDisable(GLES20.GL_BLEND);
|
||||
GL.glDisable(GL20.GL_BLEND);
|
||||
blend = enable;
|
||||
}
|
||||
|
||||
@ -61,9 +64,9 @@ public class GLState {
|
||||
if (depth != depthTest) {
|
||||
|
||||
if (depthTest)
|
||||
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
|
||||
GL.glEnable(GL20.GL_DEPTH_TEST);
|
||||
else
|
||||
GLES20.glDisable(GLES20.GL_DEPTH_TEST);
|
||||
GL.glDisable(GL20.GL_DEPTH_TEST);
|
||||
|
||||
depth = depthTest;
|
||||
}
|
||||
@ -71,9 +74,9 @@ public class GLState {
|
||||
if (stencil != stencilTest) {
|
||||
|
||||
if (stencilTest)
|
||||
GLES20.glEnable(GLES20.GL_STENCIL_TEST);
|
||||
GL.glEnable(GL20.GL_STENCIL_TEST);
|
||||
else
|
||||
GLES20.glDisable(GLES20.GL_STENCIL_TEST);
|
||||
GL.glDisable(GL20.GL_STENCIL_TEST);
|
||||
|
||||
stencil = stencilTest;
|
||||
}
|
||||
@ -85,24 +88,24 @@ public class GLState {
|
||||
|
||||
if ((va1 == 0 || va2 == 0)) {
|
||||
if (!vertexArray[0]) {
|
||||
GLES20.glEnableVertexAttribArray(0);
|
||||
GL.glEnableVertexAttribArray(0);
|
||||
vertexArray[0] = true;
|
||||
}
|
||||
} else {
|
||||
if (vertexArray[0]) {
|
||||
GLES20.glDisableVertexAttribArray(0);
|
||||
GL.glDisableVertexAttribArray(0);
|
||||
vertexArray[0] = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((va1 == 1 || va2 == 1)) {
|
||||
if (!vertexArray[1]) {
|
||||
GLES20.glEnableVertexAttribArray(1);
|
||||
GL.glEnableVertexAttribArray(1);
|
||||
vertexArray[1] = true;
|
||||
}
|
||||
} else {
|
||||
if (vertexArray[1]) {
|
||||
GLES20.glDisableVertexAttribArray(1);
|
||||
GL.glDisableVertexAttribArray(1);
|
||||
vertexArray[1] = false;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,8 @@
|
||||
*/
|
||||
package org.oscim.renderer.layers;
|
||||
|
||||
import org.oscim.view.MapView;
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.renderer.BufferObject;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
@ -29,14 +30,15 @@ import org.oscim.renderer.sublayers.LineTexRenderer;
|
||||
import org.oscim.renderer.sublayers.PolygonRenderer;
|
||||
import org.oscim.renderer.sublayers.TextureRenderer;
|
||||
import org.oscim.utils.FastMath;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
import org.oscim.view.MapView;
|
||||
|
||||
/**
|
||||
* Base class to use the renderer.sublayers for drawing
|
||||
*/
|
||||
public abstract class BasicRenderLayer extends RenderLayer {
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
public final Layers layers;
|
||||
|
||||
public BasicRenderLayer(MapView mapView) {
|
||||
@ -53,7 +55,7 @@ public abstract class BasicRenderLayer extends RenderLayer {
|
||||
|
||||
float div = FastMath.pow(pos.zoomLevel - curPos.zoomLevel);
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, layers.vbo.id);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, layers.vbo.id);
|
||||
GLState.test(false, false);
|
||||
GLState.blend(true);
|
||||
int simple = (curPos.tilt < 1 ? 1 : 0);
|
||||
|
@ -18,14 +18,15 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import org.oscim.view.MapView;
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.renderer.GLRenderer.Matrices;
|
||||
import org.oscim.renderer.GLState;
|
||||
import org.oscim.renderer.RenderLayer;
|
||||
import org.oscim.utils.GlUtils;
|
||||
import org.oscim.view.MapView;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
|
||||
/*
|
||||
* This is an example how to integrate custom OpenGL drawing routines as map overlay
|
||||
@ -36,6 +37,8 @@ import android.opengl.GLES20;
|
||||
|
||||
public class CustomRenderLayer extends RenderLayer {
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
private int mProgramObject;
|
||||
private int hVertexPosition;
|
||||
private int hMatrixPosition;
|
||||
@ -94,13 +97,13 @@ public class CustomRenderLayer extends RenderLayer {
|
||||
GLState.test(false, false);
|
||||
|
||||
// unbind previously bound VBOs
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
// Load the vertex data
|
||||
//mVertices.position(0);
|
||||
GLES20.glVertexAttribPointer(hVertexPosition, 3, GLES20.GL_FLOAT, false, 0, mVertices);
|
||||
GL.glVertexAttribPointer(hVertexPosition, 3, GL20.GL_FLOAT, false, 0, mVertices);
|
||||
//mVertices.position(2);
|
||||
//GLES20.glVertexAttribPointer(hVertexPosition, 2, GLES20.GL_FLOAT, false, 4, mVertices);
|
||||
//GL.glVertexAttribPointer(hVertexPosition, 2, GL20.GL_FLOAT, false, 4, mVertices);
|
||||
|
||||
GLState.enableVertexArrays(hVertexPosition, -1);
|
||||
|
||||
@ -115,7 +118,7 @@ public class CustomRenderLayer extends RenderLayer {
|
||||
m.mvp.setAsUniform(hMatrixPosition);
|
||||
|
||||
// Draw the triangle
|
||||
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
GlUtils.checkGlError("...");
|
||||
}
|
||||
@ -128,9 +131,9 @@ public class CustomRenderLayer extends RenderLayer {
|
||||
return false;
|
||||
|
||||
// Handle for vertex position in shader
|
||||
hVertexPosition = GLES20.glGetAttribLocation(programObject, "a_pos");
|
||||
hVertexPosition = GL.glGetAttribLocation(programObject, "a_pos");
|
||||
|
||||
hMatrixPosition = GLES20.glGetUniformLocation(programObject, "u_mvp");
|
||||
hMatrixPosition = GL.glGetUniformLocation(programObject, "u_mvp");
|
||||
|
||||
// Store the program object
|
||||
mProgramObject = programObject;
|
||||
|
@ -16,6 +16,9 @@ package org.oscim.renderer.layers;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.renderer.BufferObject;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
@ -26,8 +29,6 @@ import org.oscim.utils.FastMath;
|
||||
import org.oscim.utils.GlUtils;
|
||||
import org.oscim.view.MapView;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.opengl.GLES20;
|
||||
|
||||
/*
|
||||
* This is an example how to integrate custom OpenGL drawing routines as map overlay
|
||||
@ -38,6 +39,8 @@ import android.opengl.GLES20;
|
||||
|
||||
public class CustomRenderLayer2 extends RenderLayer {
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
private int mProgramObject;
|
||||
private int hVertexPosition;
|
||||
private int hMatrixPosition;
|
||||
@ -93,7 +96,7 @@ public class CustomRenderLayer2 extends RenderLayer {
|
||||
buf.flip();
|
||||
|
||||
mVBO = BufferObject.get(0);
|
||||
mVBO.loadBufferData(buf, 12 * 4, GLES20.GL_ARRAY_BUFFER);
|
||||
mVBO.loadBufferData(buf, 12 * 4, GL20.GL_ARRAY_BUFFER);
|
||||
newData = false;
|
||||
|
||||
// tell GLRender to call 'render'
|
||||
@ -110,10 +113,10 @@ public class CustomRenderLayer2 extends RenderLayer {
|
||||
GLState.test(false, false);
|
||||
|
||||
// bind VBO data
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVBO.id);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, mVBO.id);
|
||||
|
||||
// set VBO vertex layout
|
||||
GLES20.glVertexAttribPointer(hVertexPosition, 2, GLES20.GL_FLOAT, false, 0, 0);
|
||||
GL.glVertexAttribPointer(hVertexPosition, 2, GL20.GL_FLOAT, false, 0, 0);
|
||||
|
||||
GLState.enableVertexArrays(hVertexPosition, -1);
|
||||
|
||||
@ -132,7 +135,7 @@ public class CustomRenderLayer2 extends RenderLayer {
|
||||
float xx = x * 2 + (y % 2 == 0 ? 1 : 0);
|
||||
float yy = y * h + h / 2;
|
||||
|
||||
GLES20.glUniform2f(hCenterPosition, xx * (mCellScale * 1.5f), yy * mCellScale);
|
||||
GL.glUniform2f(hCenterPosition, xx * (mCellScale * 1.5f), yy * mCellScale);
|
||||
|
||||
//float alpha = 1 + (float) Math.log10(FastMath.clamp(
|
||||
// (float) Math.sqrt(xx * xx + yy * yy) / offset_y, 0.0f, 1.0f)) * 2;
|
||||
@ -151,7 +154,7 @@ public class CustomRenderLayer2 extends RenderLayer {
|
||||
|
||||
GlUtils.setColor(hColorPosition, c, alpha);
|
||||
|
||||
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, 6);
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_FAN, 0, 6);
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,8 +165,8 @@ public class CustomRenderLayer2 extends RenderLayer {
|
||||
float xx = x * 2 + (y % 2 == 0 ? 1 : 0);
|
||||
float yy = y * h + h / 2;
|
||||
|
||||
GLES20.glUniform2f(hCenterPosition, xx * (mCellScale * 1.5f), yy * mCellScale);
|
||||
GLES20.glDrawArrays(GLES20.GL_LINE_LOOP, 0, 6);
|
||||
GL.glUniform2f(hCenterPosition, xx * (mCellScale * 1.5f), yy * mCellScale);
|
||||
GL.glDrawArrays(GL20.GL_LINE_LOOP, 0, 6);
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,13 +181,13 @@ public class CustomRenderLayer2 extends RenderLayer {
|
||||
return false;
|
||||
|
||||
// Handle for vertex position in shader
|
||||
hVertexPosition = GLES20.glGetAttribLocation(programObject, "a_pos");
|
||||
hVertexPosition = GL.glGetAttribLocation(programObject, "a_pos");
|
||||
|
||||
hMatrixPosition = GLES20.glGetUniformLocation(programObject, "u_mvp");
|
||||
hMatrixPosition = GL.glGetUniformLocation(programObject, "u_mvp");
|
||||
|
||||
hColorPosition = GLES20.glGetUniformLocation(programObject, "u_color");
|
||||
hColorPosition = GL.glGetUniformLocation(programObject, "u_color");
|
||||
|
||||
hCenterPosition = GLES20.glGetUniformLocation(programObject, "u_center");
|
||||
hCenterPosition = GL.glGetUniformLocation(programObject, "u_center");
|
||||
|
||||
// Store the program object
|
||||
mProgramObject = programObject;
|
||||
|
@ -14,7 +14,9 @@
|
||||
*/
|
||||
package org.oscim.renderer.layers;
|
||||
|
||||
import org.oscim.view.MapView;
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.layers.tile.MapTile;
|
||||
@ -26,13 +28,13 @@ import org.oscim.renderer.GLState;
|
||||
import org.oscim.renderer.RenderLayer;
|
||||
import org.oscim.renderer.sublayers.ExtrusionLayer;
|
||||
import org.oscim.utils.GlUtils;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.view.MapView;
|
||||
|
||||
public class ExtrusionRenderLayer extends RenderLayer {
|
||||
private final static String TAG = ExtrusionRenderLayer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
private final TileRenderLayer mTileLayer;
|
||||
|
||||
public ExtrusionRenderLayer(MapView mapView,
|
||||
@ -75,12 +77,12 @@ public class ExtrusionRenderLayer extends RenderLayer {
|
||||
return false;
|
||||
}
|
||||
|
||||
hMatrix[i] = GLES20.glGetUniformLocation(shaderProgram[i], "u_mvp");
|
||||
hColor[i] = GLES20.glGetUniformLocation(shaderProgram[i], "u_color");
|
||||
hAlpha[i] = GLES20.glGetUniformLocation(shaderProgram[i], "u_alpha");
|
||||
hMode[i] = GLES20.glGetUniformLocation(shaderProgram[i], "u_mode");
|
||||
hVertexPosition[i] = GLES20.glGetAttribLocation(shaderProgram[i], "a_pos");
|
||||
hLightPosition[i] = GLES20.glGetAttribLocation(shaderProgram[i], "a_light");
|
||||
hMatrix[i] = GL.glGetUniformLocation(shaderProgram[i], "u_mvp");
|
||||
hColor[i] = GL.glGetUniformLocation(shaderProgram[i], "u_color");
|
||||
hAlpha[i] = GL.glGetUniformLocation(shaderProgram[i], "u_alpha");
|
||||
hMode[i] = GL.glGetUniformLocation(shaderProgram[i], "u_mode");
|
||||
hVertexPosition[i] = GL.glGetAttribLocation(shaderProgram[i], "a_pos");
|
||||
hLightPosition[i] = GL.glGetAttribLocation(shaderProgram[i], "a_light");
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -186,8 +188,8 @@ public class ExtrusionRenderLayer extends RenderLayer {
|
||||
GLState.useProgram(shaderProgram[SHADER]);
|
||||
|
||||
GLState.enableVertexArrays(uExtVertexPosition, uExtLightPosition);
|
||||
GLES20.glUniform1i(uExtMode, 0);
|
||||
GLES20.glUniform4fv(uExtColor, 4, mColor, 0);
|
||||
GL.glUniform1i(uExtMode, 0);
|
||||
GlUtils.glUniform4fv(uExtColor, 4, mColor);
|
||||
|
||||
GLState.test(false, false);
|
||||
|
||||
@ -197,21 +199,21 @@ public class ExtrusionRenderLayer extends RenderLayer {
|
||||
setMatrix(pos, m, tiles[i], 0);
|
||||
m.mvp.setAsUniform(uExtMatrix);
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, el.vboIndices.id);
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, el.vboVertices.id);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, el.vboIndices.id);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, el.vboVertices.id);
|
||||
|
||||
GLES20.glVertexAttribPointer(uExtVertexPosition, 3,
|
||||
GLES20.GL_SHORT, false, 8, 0);
|
||||
GL.glVertexAttribPointer(uExtVertexPosition, 3,
|
||||
GL20.GL_SHORT, false, 8, 0);
|
||||
|
||||
GLES20.glVertexAttribPointer(uExtLightPosition, 2,
|
||||
GLES20.GL_UNSIGNED_BYTE, false, 8, 6);
|
||||
GL.glVertexAttribPointer(uExtLightPosition, 2,
|
||||
GL20.GL_UNSIGNED_BYTE, false, 8, 6);
|
||||
|
||||
GLES20.glDrawElements(GLES20.GL_TRIANGLES,
|
||||
GL.glDrawElements(GL20.GL_TRIANGLES,
|
||||
(el.mIndiceCnt[0] + el.mIndiceCnt[1] + el.mIndiceCnt[2]),
|
||||
GLES20.GL_UNSIGNED_SHORT, 0);
|
||||
GL20.GL_UNSIGNED_SHORT, 0);
|
||||
|
||||
GLES20.glDrawElements(GLES20.GL_LINES, el.mIndiceCnt[3],
|
||||
GLES20.GL_UNSIGNED_SHORT,
|
||||
GL.glDrawElements(GL20.GL_LINES, el.mIndiceCnt[3],
|
||||
GL20.GL_UNSIGNED_SHORT,
|
||||
(el.mIndiceCnt[0] + el.mIndiceCnt[1] + el.mIndiceCnt[2]) * 2);
|
||||
|
||||
// just a temporary reference!
|
||||
@ -220,10 +222,10 @@ public class ExtrusionRenderLayer extends RenderLayer {
|
||||
return;
|
||||
}
|
||||
|
||||
GLES20.glDepthMask(true);
|
||||
//GLES20.glStencilMask(0xff);
|
||||
//GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_STENCIL_BUFFER_BIT);
|
||||
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT);
|
||||
GL.glDepthMask(true);
|
||||
//GL.glStencilMask(0xff);
|
||||
//GL.glClear(GL20.GL_DEPTH_BUFFER_BIT | GL20.GL_STENCIL_BUFFER_BIT);
|
||||
GL.glClear(GL20.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
GLState.test(true, false);
|
||||
|
||||
@ -232,14 +234,14 @@ public class ExtrusionRenderLayer extends RenderLayer {
|
||||
if (pos.scale < (1 << 18)) {
|
||||
// chances are high that one moves through a building
|
||||
// with scale > 2 also draw back sides in this case.
|
||||
GLES20.glEnable(GLES20.GL_CULL_FACE);
|
||||
GLES20.glCullFace(GLES20.GL_FRONT);
|
||||
GL.glEnable(GL20.GL_CULL_FACE);
|
||||
GL.glCullFace(GL20.GL_FRONT);
|
||||
}
|
||||
GLES20.glDepthFunc(GLES20.GL_LESS);
|
||||
GLES20.glColorMask(false, false, false, false);
|
||||
GLES20.glUniform1i(uExtMode, 0);
|
||||
GLES20.glUniform4fv(uExtColor, 4, mColor, 0);
|
||||
GLES20.glUniform1f(uExtAlpha, mAlpha);
|
||||
GL.glDepthFunc(GL20.GL_LESS);
|
||||
GL.glColorMask(false, false, false, false);
|
||||
GL.glUniform1i(uExtMode, 0);
|
||||
GlUtils.glUniform4fv(uExtColor, 4, mColor);
|
||||
GL.glUniform1f(uExtAlpha, mAlpha);
|
||||
|
||||
// draw to depth buffer
|
||||
for (int i = 0; i < mTileCnt; i++) {
|
||||
@ -249,66 +251,66 @@ public class ExtrusionRenderLayer extends RenderLayer {
|
||||
setMatrix(pos, m, t, d);
|
||||
m.mvp.setAsUniform(uExtMatrix);
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, el.vboIndices.id);
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, el.vboVertices.id);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, el.vboIndices.id);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, el.vboVertices.id);
|
||||
|
||||
GLES20.glVertexAttribPointer(uExtVertexPosition, 3,
|
||||
GLES20.GL_SHORT, false, 8, 0);
|
||||
GL.glVertexAttribPointer(uExtVertexPosition, 3,
|
||||
GL20.GL_SHORT, false, 8, 0);
|
||||
|
||||
GLES20.glDrawElements(GLES20.GL_TRIANGLES,
|
||||
GL.glDrawElements(GL20.GL_TRIANGLES,
|
||||
(el.mIndiceCnt[0] + el.mIndiceCnt[1] + el.mIndiceCnt[2]),
|
||||
GLES20.GL_UNSIGNED_SHORT, 0);
|
||||
GL20.GL_UNSIGNED_SHORT, 0);
|
||||
}
|
||||
|
||||
// enable color buffer, use depth mask
|
||||
GLState.enableVertexArrays(uExtVertexPosition, uExtLightPosition);
|
||||
GLES20.glColorMask(true, true, true, true);
|
||||
GLES20.glDepthMask(false);
|
||||
GL.glColorMask(true, true, true, true);
|
||||
GL.glDepthMask(false);
|
||||
GLState.blend(true);
|
||||
|
||||
for (int i = 0; i < mTileCnt; i++) {
|
||||
MapTile t = tiles[i];
|
||||
ExtrusionLayer el = (ExtrusionLayer) t.layers.extrusionLayers;
|
||||
|
||||
GLES20.glDepthFunc(GLES20.GL_EQUAL);
|
||||
GL.glDepthFunc(GL20.GL_EQUAL);
|
||||
int d = GLRenderer.depthOffset(t) * 10;
|
||||
setMatrix(pos, m, t, d);
|
||||
m.mvp.setAsUniform(uExtMatrix);
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, el.vboIndices.id);
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, el.vboVertices.id);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, el.vboIndices.id);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, el.vboVertices.id);
|
||||
|
||||
GLES20.glVertexAttribPointer(uExtVertexPosition, 3,
|
||||
GLES20.GL_SHORT, false, 8, 0);
|
||||
GL.glVertexAttribPointer(uExtVertexPosition, 3,
|
||||
GL20.GL_SHORT, false, 8, 0);
|
||||
|
||||
GLES20.glVertexAttribPointer(uExtLightPosition, 2,
|
||||
GLES20.GL_UNSIGNED_BYTE, false, 8, 6);
|
||||
GL.glVertexAttribPointer(uExtLightPosition, 2,
|
||||
GL20.GL_UNSIGNED_BYTE, false, 8, 6);
|
||||
|
||||
// draw roof
|
||||
GLES20.glUniform1i(uExtMode, 0);
|
||||
GLES20.glDrawElements(GLES20.GL_TRIANGLES, el.mIndiceCnt[2],
|
||||
GLES20.GL_UNSIGNED_SHORT, (el.mIndiceCnt[0] + el.mIndiceCnt[1]) * 2);
|
||||
GL.glUniform1i(uExtMode, 0);
|
||||
GL.glDrawElements(GL20.GL_TRIANGLES, el.mIndiceCnt[2],
|
||||
GL20.GL_UNSIGNED_SHORT, (el.mIndiceCnt[0] + el.mIndiceCnt[1]) * 2);
|
||||
|
||||
// draw sides 1
|
||||
GLES20.glUniform1i(uExtMode, 1);
|
||||
GLES20.glDrawElements(GLES20.GL_TRIANGLES, el.mIndiceCnt[0],
|
||||
GLES20.GL_UNSIGNED_SHORT, 0);
|
||||
GL.glUniform1i(uExtMode, 1);
|
||||
GL.glDrawElements(GL20.GL_TRIANGLES, el.mIndiceCnt[0],
|
||||
GL20.GL_UNSIGNED_SHORT, 0);
|
||||
|
||||
// draw sides 2
|
||||
GLES20.glUniform1i(uExtMode, 2);
|
||||
GLES20.glDrawElements(GLES20.GL_TRIANGLES, el.mIndiceCnt[1],
|
||||
GLES20.GL_UNSIGNED_SHORT, el.mIndiceCnt[0] * 2);
|
||||
GL.glUniform1i(uExtMode, 2);
|
||||
GL.glDrawElements(GL20.GL_TRIANGLES, el.mIndiceCnt[1],
|
||||
GL20.GL_UNSIGNED_SHORT, el.mIndiceCnt[0] * 2);
|
||||
|
||||
// drawing gl_lines with the same coordinates does not result in
|
||||
// same depth values as polygons, so add offset and draw gl_lequal:
|
||||
GLES20.glDepthFunc(GLES20.GL_LEQUAL);
|
||||
GL.glDepthFunc(GL20.GL_LEQUAL);
|
||||
|
||||
m.mvp.addDepthOffset(100);
|
||||
m.mvp.setAsUniform(uExtMatrix);
|
||||
|
||||
GLES20.glUniform1i(uExtMode, 3);
|
||||
GLES20.glDrawElements(GLES20.GL_LINES, el.mIndiceCnt[3],
|
||||
GLES20.GL_UNSIGNED_SHORT,
|
||||
GL.glUniform1i(uExtMode, 3);
|
||||
GL.glDrawElements(GL20.GL_LINES, el.mIndiceCnt[3],
|
||||
GL20.GL_UNSIGNED_SHORT,
|
||||
(el.mIndiceCnt[0] + el.mIndiceCnt[1] + el.mIndiceCnt[2]) * 2);
|
||||
|
||||
// just a temporary reference!
|
||||
@ -316,9 +318,9 @@ public class ExtrusionRenderLayer extends RenderLayer {
|
||||
}
|
||||
|
||||
if (pos.scale < (1 << 18))
|
||||
GLES20.glDisable(GLES20.GL_CULL_FACE);
|
||||
GL.glDisable(GL20.GL_CULL_FACE);
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
mTileLayer.releaseTiles(mTileSet);
|
||||
}
|
||||
|
@ -28,7 +28,8 @@ package org.oscim.renderer.layers;
|
||||
// 5 R-Tree might be handy
|
||||
//
|
||||
|
||||
import org.oscim.view.MapView;
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
@ -50,17 +51,14 @@ import org.oscim.utils.FastMath;
|
||||
import org.oscim.utils.OBB2D;
|
||||
import org.oscim.utils.pool.LList;
|
||||
import org.oscim.utils.pool.Pool;
|
||||
import org.oscim.view.MapView;
|
||||
import org.oscim.view.MapViewPosition;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.SystemClock;
|
||||
import org.oscim.backend.Log;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
public class TextRenderLayer extends BasicRenderLayer {
|
||||
private final static String TAG = TextRenderLayer.class.getName();
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
private final static float MIN_CAPTION_DIST = 5;
|
||||
private final static float MIN_WAY_DIST = 3;
|
||||
|
||||
@ -666,77 +664,77 @@ public class TextRenderLayer extends BasicRenderLayer {
|
||||
this.newData = true;
|
||||
}
|
||||
|
||||
if (!mHolding)
|
||||
postLabelTask((mLastRun + MAX_RELABEL_DELAY) - System.currentTimeMillis());
|
||||
// if (!mHolding)
|
||||
// postLabelTask((mLastRun + MAX_RELABEL_DELAY) - System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/* private */LabelTask mLabelTask;
|
||||
/* private */long mLastRun;
|
||||
|
||||
class LabelTask extends AsyncTask<Void, Void, Integer> {
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(Void... unused) {
|
||||
boolean labelsChanged = false;
|
||||
|
||||
if (!isCancelled())
|
||||
labelsChanged = updateLabels();
|
||||
|
||||
if (!isCancelled() && labelsChanged)
|
||||
mMapView.render();
|
||||
|
||||
//Log.d(TAG, "relabel " + labelsChanged);
|
||||
|
||||
mLastRun = System.currentTimeMillis();
|
||||
mLabelTask = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
/*private */void cleanup() {
|
||||
mPool.releaseAll(mPrevLabels);
|
||||
mPrevLabels = null;
|
||||
mTileSet.clear();
|
||||
mLabelTask = null;
|
||||
}
|
||||
|
||||
private final Runnable mLabelUpdate = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (mLabelTask == null) {
|
||||
mLabelTask = new LabelTask();
|
||||
mLabelTask.execute();
|
||||
} else {
|
||||
postLabelTask(50);
|
||||
//Log.d(TAG, "repost");
|
||||
}
|
||||
}
|
||||
};
|
||||
private Handler mLabelHandler;
|
||||
|
||||
/* private */void postLabelTask(long delay) {
|
||||
if (mLabelHandler == null) {
|
||||
mLabelHandler = new Handler(Looper.getMainLooper());
|
||||
}
|
||||
|
||||
mLabelHandler.removeCallbacks(mLabelUpdate);
|
||||
|
||||
if (delay > 0)
|
||||
mLabelHandler.postDelayed(mLabelUpdate, delay);
|
||||
else
|
||||
mLabelHandler.post(mLabelUpdate);
|
||||
}
|
||||
// /* private */LabelTask mLabelTask;
|
||||
// /* private */long mLastRun;
|
||||
//
|
||||
// class LabelTask extends AsyncTask<Void, Void, Integer> {
|
||||
//
|
||||
// @Override
|
||||
// protected Integer doInBackground(Void... unused) {
|
||||
// boolean labelsChanged = false;
|
||||
//
|
||||
// if (!isCancelled())
|
||||
// labelsChanged = updateLabels();
|
||||
//
|
||||
// if (!isCancelled() && labelsChanged)
|
||||
// mMapView.render();
|
||||
//
|
||||
// //Log.d(TAG, "relabel " + labelsChanged);
|
||||
//
|
||||
// mLastRun = System.currentTimeMillis();
|
||||
// mLabelTask = null;
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onCancelled() {
|
||||
// cleanup();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /*private */void cleanup() {
|
||||
// mPool.releaseAll(mPrevLabels);
|
||||
// mPrevLabels = null;
|
||||
// mTileSet.clear();
|
||||
// mLabelTask = null;
|
||||
// }
|
||||
//
|
||||
// private final Runnable mLabelUpdate = new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
//
|
||||
// if (mLabelTask == null) {
|
||||
// mLabelTask = new LabelTask();
|
||||
// mLabelTask.execute();
|
||||
// } else {
|
||||
// postLabelTask(50);
|
||||
// //Log.d(TAG, "repost");
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// private Handler mLabelHandler;
|
||||
//
|
||||
// /* private */void postLabelTask(long delay) {
|
||||
// if (mLabelHandler == null) {
|
||||
// mLabelHandler = new Handler(Looper.getMainLooper());
|
||||
// }
|
||||
//
|
||||
// mLabelHandler.removeCallbacks(mLabelUpdate);
|
||||
//
|
||||
// if (delay > 0)
|
||||
// mLabelHandler.postDelayed(mLabelUpdate, delay);
|
||||
// else
|
||||
// mLabelHandler.post(mLabelUpdate);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public synchronized void render(MapPosition pos, Matrices m) {
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, layers.vbo.id);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, layers.vbo.id);
|
||||
GLState.test(false, false);
|
||||
|
||||
float scale = (float) (mMapPosition.scale / pos.scale);
|
||||
@ -772,13 +770,13 @@ public class TextRenderLayer extends BasicRenderLayer {
|
||||
}
|
||||
|
||||
public synchronized void clearLabels() {
|
||||
if (mLabelHandler != null)
|
||||
mLabelHandler.removeCallbacks(mLabelUpdate);
|
||||
|
||||
if (mLabelTask == null) {
|
||||
cleanup();
|
||||
} else {
|
||||
mLabelTask.cancel(false);
|
||||
}
|
||||
// if (mLabelHandler != null)
|
||||
// mLabelHandler.removeCallbacks(mLabelUpdate);
|
||||
//
|
||||
// if (mLabelTask == null) {
|
||||
// cleanup();
|
||||
// } else {
|
||||
// mLabelTask.cancel(false);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -15,18 +15,20 @@
|
||||
|
||||
package org.oscim.renderer.sublayers;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
import org.oscim.renderer.GLRenderer.Matrices;
|
||||
import org.oscim.renderer.GLState;
|
||||
import org.oscim.utils.GlUtils;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
|
||||
// TODO merge with TextureRenderer
|
||||
|
||||
public final class BitmapRenderer {
|
||||
|
||||
//private final static String TAG = BitmapRenderer.class.getName();
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
public final static boolean debug = true;
|
||||
|
||||
private static int mTextureProgram;
|
||||
@ -45,12 +47,12 @@ public final class BitmapRenderer {
|
||||
mTextureProgram = GlUtils.createProgram(textVertexShader,
|
||||
textFragmentShader);
|
||||
|
||||
hTextureMVMatrix = GLES20.glGetUniformLocation(mTextureProgram, "u_mv");
|
||||
hTextureProjMatrix = GLES20.glGetUniformLocation(mTextureProgram, "u_proj");
|
||||
hTextureScale = GLES20.glGetUniformLocation(mTextureProgram, "u_scale");
|
||||
hTextureScreenScale = GLES20.glGetUniformLocation(mTextureProgram, "u_swidth");
|
||||
hTextureVertex = GLES20.glGetAttribLocation(mTextureProgram, "vertex");
|
||||
hTextureTexCoord = GLES20.glGetAttribLocation(mTextureProgram, "tex_coord");
|
||||
hTextureMVMatrix = GL.glGetUniformLocation(mTextureProgram, "u_mv");
|
||||
hTextureProjMatrix = GL.glGetUniformLocation(mTextureProgram, "u_proj");
|
||||
hTextureScale = GL.glGetUniformLocation(mTextureProgram, "u_scale");
|
||||
hTextureScreenScale = GL.glGetUniformLocation(mTextureProgram, "u_swidth");
|
||||
hTextureVertex = GL.glGetAttribLocation(mTextureProgram, "vertex");
|
||||
hTextureTexCoord = GL.glGetAttribLocation(mTextureProgram, "tex_coord");
|
||||
}
|
||||
|
||||
public static Layer draw(Layer layer, float scale, Matrices m) {
|
||||
@ -64,22 +66,22 @@ public final class BitmapRenderer {
|
||||
TextureLayer tl = (TextureLayer) layer;
|
||||
|
||||
if (tl.fixed)
|
||||
GLES20.glUniform1f(hTextureScale, (float) Math.sqrt(scale));
|
||||
GL.glUniform1f(hTextureScale, (float) Math.sqrt(scale));
|
||||
else
|
||||
GLES20.glUniform1f(hTextureScale, 1);
|
||||
GL.glUniform1f(hTextureScale, 1);
|
||||
|
||||
GLES20.glUniform1f(hTextureScreenScale, 1f / GLRenderer.screenWidth);
|
||||
GL.glUniform1f(hTextureScreenScale, 1f / GLRenderer.screenWidth);
|
||||
|
||||
m.proj.setAsUniform(hTextureProjMatrix);
|
||||
|
||||
m.mvp.setAsUniform(hTextureMVMatrix);
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, GLRenderer.mQuadIndicesID);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, GLRenderer.mQuadIndicesID);
|
||||
|
||||
for (TextureItem ti = tl.textures; ti != null; ti = ti.next) {
|
||||
//Log.d(TAG, "render texture " + ti.id);
|
||||
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, ti.id);
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, ti.id);
|
||||
int maxVertices = GLRenderer.maxQuads * INDICES_PER_SPRITE;
|
||||
|
||||
// draw up to maxVertices in each iteration
|
||||
@ -87,22 +89,22 @@ public final class BitmapRenderer {
|
||||
// to.offset * (24(shorts) * 2(short-bytes) / 6(indices) == 8)
|
||||
int off = (ti.offset + i) * 8 + tl.offset;
|
||||
|
||||
GLES20.glVertexAttribPointer(hTextureVertex, 4,
|
||||
GLES20.GL_SHORT, false, 12, off);
|
||||
GL.glVertexAttribPointer(hTextureVertex, 4,
|
||||
GL20.GL_SHORT, false, 12, off);
|
||||
|
||||
GLES20.glVertexAttribPointer(hTextureTexCoord, 2,
|
||||
GLES20.GL_SHORT, false, 12, off + 8);
|
||||
GL.glVertexAttribPointer(hTextureTexCoord, 2,
|
||||
GL20.GL_SHORT, false, 12, off + 8);
|
||||
|
||||
int numVertices = ti.vertices - i;
|
||||
if (numVertices > maxVertices)
|
||||
numVertices = maxVertices;
|
||||
|
||||
GLES20.glDrawElements(GLES20.GL_TRIANGLES, numVertices,
|
||||
GLES20.GL_UNSIGNED_SHORT, 0);
|
||||
GL.glDrawElements(GL20.GL_TRIANGLES, numVertices,
|
||||
GL20.GL_UNSIGNED_SHORT, 0);
|
||||
}
|
||||
}
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
return layer.next;
|
||||
}
|
||||
|
@ -18,7 +18,9 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
import org.oscim.view.MapView;
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.Tile;
|
||||
@ -26,9 +28,6 @@ import org.oscim.renderer.BufferObject;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
import org.oscim.utils.LineClipper;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
import org.oscim.backend.Log;
|
||||
|
||||
/**
|
||||
* @author Hannes Janetzek
|
||||
* FIXME check if polygon has self intersections or 0/180 degree
|
||||
@ -36,6 +35,9 @@ import org.oscim.backend.Log;
|
||||
*/
|
||||
public class ExtrusionLayer extends Layer {
|
||||
private final static String TAG = ExtrusionLayer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
private static final float S = GLRenderer.COORD_SCALE;
|
||||
private VertexItem mVertices;
|
||||
private VertexItem mCurVertices;
|
||||
@ -126,9 +128,10 @@ public class ExtrusionLayer extends Layer {
|
||||
|
||||
// check: drop last point from explicitly closed rings
|
||||
int len = length;
|
||||
if (!MapView.enableClosePolygons) {
|
||||
len -= 2;
|
||||
} else if (points[ppos] == points[ppos + len - 2]
|
||||
// if (!MapView.enableClosePolygons) {
|
||||
// len -= 2;
|
||||
// } else
|
||||
if (points[ppos] == points[ppos + len - 2]
|
||||
&& points[ppos + 1] == points[ppos + len - 1]) {
|
||||
// vector-tile-map does not produce implicty closed
|
||||
// polygons (yet)
|
||||
@ -399,7 +402,7 @@ public class ExtrusionLayer extends Layer {
|
||||
sbuf.flip();
|
||||
int size = mNumIndices * 2;
|
||||
vboIndices = BufferObject.get(size);
|
||||
vboIndices.loadBufferData(sbuf,size, GLES20.GL_ELEMENT_ARRAY_BUFFER);
|
||||
vboIndices.loadBufferData(sbuf, size, GL20.GL_ELEMENT_ARRAY_BUFFER);
|
||||
|
||||
// upload vertices
|
||||
sbuf.clear();
|
||||
@ -409,10 +412,10 @@ public class ExtrusionLayer extends Layer {
|
||||
sbuf.flip();
|
||||
size = mNumVertices * 4 * 2;
|
||||
vboVertices = BufferObject.get(size);
|
||||
vboVertices.loadBufferData(sbuf, size, GLES20.GL_ARRAY_BUFFER);
|
||||
vboVertices.loadBufferData(sbuf, size, GL20.GL_ARRAY_BUFFER);
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
VertexItem.pool.releaseAll(mIndices[i]);
|
||||
|
@ -16,7 +16,6 @@ package org.oscim.renderer.sublayers;
|
||||
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
import org.oscim.view.MapView;
|
||||
import org.oscim.backend.canvas.Paint.Cap;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.core.Tile;
|
||||
@ -108,8 +107,8 @@ public final class LineLayer extends Layer {
|
||||
int opos = si.used;
|
||||
|
||||
// FIXME: remove this when switching to oscimap MapDatabase
|
||||
if (!MapView.enableClosePolygons)
|
||||
closed = false;
|
||||
//if (!MapView.enableClosePolygons)
|
||||
// closed = false;
|
||||
|
||||
// Note: just a hack to save some vertices, when there are more than 200 lines
|
||||
// per type
|
||||
|
@ -14,14 +14,9 @@
|
||||
*/
|
||||
package org.oscim.renderer.sublayers;
|
||||
|
||||
import static android.opengl.GLES20.GL_SHORT;
|
||||
import static android.opengl.GLES20.GL_TRIANGLE_STRIP;
|
||||
import static android.opengl.GLES20.glDrawArrays;
|
||||
import static android.opengl.GLES20.glGetAttribLocation;
|
||||
import static android.opengl.GLES20.glGetUniformLocation;
|
||||
import static android.opengl.GLES20.glUniform1f;
|
||||
import static android.opengl.GLES20.glVertexAttribPointer;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
import org.oscim.renderer.GLRenderer.Matrices;
|
||||
@ -29,12 +24,11 @@ import org.oscim.renderer.GLState;
|
||||
import org.oscim.theme.renderinstruction.Line;
|
||||
import org.oscim.utils.GlUtils;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
import org.oscim.backend.Log;
|
||||
|
||||
public final class LineRenderer {
|
||||
private final static String TAG = LineRenderer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
private static final int LINE_VERTICES_DATA_POS_OFFSET = 0;
|
||||
|
||||
// factor to normalize extrusion vector and scale to coord scale
|
||||
@ -67,12 +61,12 @@ public final class LineRenderer {
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
hLineMatrix[i] = glGetUniformLocation(lineProgram[i], "u_mvp");
|
||||
hLineScale[i] = glGetUniformLocation(lineProgram[i], "u_wscale");
|
||||
hLineWidth[i] = glGetUniformLocation(lineProgram[i], "u_width");
|
||||
hLineColor[i] = glGetUniformLocation(lineProgram[i], "u_color");
|
||||
hLineMode[i] = glGetUniformLocation(lineProgram[i], "u_mode");
|
||||
hLineVertexPosition[i] = glGetAttribLocation(lineProgram[i], "a_pos");
|
||||
hLineMatrix[i] = GL.glGetUniformLocation(lineProgram[i], "u_mvp");
|
||||
hLineScale[i] = GL.glGetUniformLocation(lineProgram[i], "u_wscale");
|
||||
hLineWidth[i] = GL.glGetUniformLocation(lineProgram[i], "u_width");
|
||||
hLineColor[i] = GL.glGetUniformLocation(lineProgram[i], "u_color");
|
||||
hLineMode[i] = GL.glGetUniformLocation(lineProgram[i], "u_mode");
|
||||
hLineVertexPosition[i] = GL.glGetAttribLocation(lineProgram[i], "a_pos");
|
||||
}
|
||||
|
||||
// create lookup table as texture for 'length(0..1,0..1)'
|
||||
@ -90,19 +84,19 @@ public final class LineRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
mTexID = GlUtils.loadTexture(pixel, 128, 128, GLES20.GL_ALPHA,
|
||||
GLES20.GL_NEAREST, GLES20.GL_NEAREST,
|
||||
GLES20.GL_MIRRORED_REPEAT, GLES20.GL_MIRRORED_REPEAT);
|
||||
mTexID = GlUtils.loadTexture(pixel, 128, 128, GL20.GL_ALPHA,
|
||||
GL20.GL_NEAREST, GL20.GL_NEAREST,
|
||||
GL20.GL_MIRRORED_REPEAT, GL20.GL_MIRRORED_REPEAT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void beginLines() {
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexID);
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, mTexID);
|
||||
}
|
||||
|
||||
public static void endLines() {
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
public static Layer draw(Layers layers, Layer curLayer, MapPosition pos,
|
||||
@ -124,7 +118,7 @@ public final class LineRenderer {
|
||||
|
||||
GLState.enableVertexArrays(hLineVertexPosition[mode], -1);
|
||||
|
||||
glVertexAttribPointer(hLineVertexPosition[mode], 4, GL_SHORT,
|
||||
GL.glVertexAttribPointer(hLineVertexPosition[mode], 4, GL20.GL_SHORT,
|
||||
false, 0, layers.lineOffset + LINE_VERTICES_DATA_POS_OFFSET);
|
||||
|
||||
//glUniformMatrix4fv(hLineMatrix[mode], 1, false, matrix, 0);
|
||||
@ -150,9 +144,9 @@ public final class LineRenderer {
|
||||
if (mode == 1)
|
||||
pixel = (float) (1.5 / s);
|
||||
|
||||
glUniform1f(uLineScale, pixel);
|
||||
GL.glUniform1f(uLineScale, pixel);
|
||||
int lineMode = 0;
|
||||
glUniform1f(uLineMode, lineMode);
|
||||
GL.glUniform1f(uLineMode, lineMode);
|
||||
|
||||
boolean blur = false;
|
||||
|
||||
@ -172,7 +166,7 @@ public final class LineRenderer {
|
||||
}
|
||||
|
||||
if (mode == 0 && blur && line.blur == 0) {
|
||||
glUniform1f(uLineScale, 0);
|
||||
GL.glUniform1f(uLineScale, 0);
|
||||
blur = false;
|
||||
}
|
||||
|
||||
@ -190,25 +184,25 @@ public final class LineRenderer {
|
||||
continue;
|
||||
}
|
||||
|
||||
glUniform1f(uLineWidth, width * COORD_SCALE_BY_DIR_SCALE);
|
||||
GL.glUniform1f(uLineWidth, width * COORD_SCALE_BY_DIR_SCALE);
|
||||
|
||||
if (line.blur != 0) {
|
||||
glUniform1f(uLineScale, (float) (1 - (line.blur / s)));
|
||||
GL.glUniform1f(uLineScale, (float) (1 - (line.blur / s)));
|
||||
blur = true;
|
||||
} else if (mode == 1) {
|
||||
glUniform1f(uLineScale, pixel / width);
|
||||
GL.glUniform1f(uLineScale, pixel / width);
|
||||
}
|
||||
|
||||
if (o.roundCap) {
|
||||
if (lineMode != 1) {
|
||||
lineMode = 1;
|
||||
glUniform1f(uLineMode, lineMode);
|
||||
GL.glUniform1f(uLineMode, lineMode);
|
||||
}
|
||||
} else if (lineMode != 0) {
|
||||
lineMode = 0;
|
||||
glUniform1f(uLineMode, lineMode);
|
||||
GL.glUniform1f(uLineMode, lineMode);
|
||||
}
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, o.offset, o.verticesCnt);
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, o.offset, o.verticesCnt);
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -227,26 +221,26 @@ public final class LineRenderer {
|
||||
width = (ll.width - 0.2f) / lineScale;
|
||||
}
|
||||
|
||||
glUniform1f(uLineWidth, width * COORD_SCALE_BY_DIR_SCALE);
|
||||
GL.glUniform1f(uLineWidth, width * COORD_SCALE_BY_DIR_SCALE);
|
||||
|
||||
if (line.blur != 0) {
|
||||
glUniform1f(uLineScale, line.blur);
|
||||
GL.glUniform1f(uLineScale, line.blur);
|
||||
blur = true;
|
||||
} else if (mode == 1) {
|
||||
glUniform1f(uLineScale, pixel / width);
|
||||
GL.glUniform1f(uLineScale, pixel / width);
|
||||
}
|
||||
|
||||
if (ll.roundCap) {
|
||||
if (lineMode != 1) {
|
||||
lineMode = 1;
|
||||
glUniform1f(uLineMode, lineMode);
|
||||
GL.glUniform1f(uLineMode, lineMode);
|
||||
}
|
||||
} else if (lineMode != 0) {
|
||||
lineMode = 0;
|
||||
glUniform1f(uLineMode, lineMode);
|
||||
GL.glUniform1f(uLineMode, lineMode);
|
||||
}
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, l.offset, l.verticesCnt);
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, l.offset, l.verticesCnt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,19 +17,21 @@ package org.oscim.renderer.sublayers;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
import org.oscim.renderer.GLState;
|
||||
import org.oscim.renderer.GLRenderer.Matrices;
|
||||
import org.oscim.renderer.GLState;
|
||||
import org.oscim.theme.renderinstruction.Line;
|
||||
import org.oscim.utils.GlUtils;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
import org.oscim.backend.Log;
|
||||
|
||||
public class LineTexRenderer {
|
||||
private final static String TAG = LineTexRenderer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
// factor to normalize extrusion vector and scale to coord scale
|
||||
private final static float COORD_SCALE_BY_DIR_SCALE =
|
||||
GLRenderer.COORD_SCALE / LineLayer.DIR_SCALE;
|
||||
@ -57,22 +59,21 @@ public class LineTexRenderer {
|
||||
return;
|
||||
}
|
||||
|
||||
hMatrix = GLES20.glGetUniformLocation(shader, "u_mvp");
|
||||
hTexColor = GLES20.glGetUniformLocation(shader, "u_color");
|
||||
hBgColor = GLES20.glGetUniformLocation(shader, "u_bgcolor");
|
||||
hScale = GLES20.glGetUniformLocation(shader, "u_scale");
|
||||
hWidth = GLES20.glGetUniformLocation(shader, "u_width");
|
||||
hPatternScale = GLES20.glGetUniformLocation(shader, "u_pscale");
|
||||
hPatternWidth = GLES20.glGetUniformLocation(shader, "u_pwidth");
|
||||
hMatrix = GL.glGetUniformLocation(shader, "u_mvp");
|
||||
hTexColor = GL.glGetUniformLocation(shader, "u_color");
|
||||
hBgColor = GL.glGetUniformLocation(shader, "u_bgcolor");
|
||||
hScale = GL.glGetUniformLocation(shader, "u_scale");
|
||||
hWidth = GL.glGetUniformLocation(shader, "u_width");
|
||||
hPatternScale = GL.glGetUniformLocation(shader, "u_pscale");
|
||||
hPatternWidth = GL.glGetUniformLocation(shader, "u_pwidth");
|
||||
|
||||
hVertexPosition0 = GLES20.glGetAttribLocation(shader, "a_pos0");
|
||||
hVertexPosition1 = GLES20.glGetAttribLocation(shader, "a_pos1");
|
||||
hVertexLength0 = GLES20.glGetAttribLocation(shader, "a_len0");
|
||||
hVertexLength1 = GLES20.glGetAttribLocation(shader, "a_len1");
|
||||
hVertexFlip = GLES20.glGetAttribLocation(shader, "a_flip");
|
||||
hVertexPosition0 = GL.glGetAttribLocation(shader, "a_pos0");
|
||||
hVertexPosition1 = GL.glGetAttribLocation(shader, "a_pos1");
|
||||
hVertexLength0 = GL.glGetAttribLocation(shader, "a_len0");
|
||||
hVertexLength1 = GL.glGetAttribLocation(shader, "a_len1");
|
||||
hVertexFlip = GL.glGetAttribLocation(shader, "a_flip");
|
||||
|
||||
int[] vboIds = new int[1];
|
||||
GLES20.glGenBuffers(1, vboIds, 0);
|
||||
int[] vboIds = GlUtils.glGenBuffers(1);
|
||||
mVertexFlipID = vboIds[0];
|
||||
|
||||
// 0, 1, 0, 1, 0, ...
|
||||
@ -85,11 +86,10 @@ public class LineTexRenderer {
|
||||
|
||||
buf.put(flip);
|
||||
buf.flip();
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVertexFlipID);
|
||||
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, flip.length, buf,
|
||||
GLES20.GL_STATIC_DRAW);
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, mVertexFlipID);
|
||||
GL.glBufferData(GL20.GL_ARRAY_BUFFER, flip.length, buf,
|
||||
GL20.GL_STATIC_DRAW);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
// mTexID = new int[10];
|
||||
// byte[] stipple = new byte[2];
|
||||
@ -109,29 +109,29 @@ public class LineTexRenderer {
|
||||
|
||||
GLState.enableVertexArrays(-1, -1);
|
||||
|
||||
GLES20.glEnableVertexAttribArray(hVertexPosition0);
|
||||
GLES20.glEnableVertexAttribArray(hVertexPosition1);
|
||||
GLES20.glEnableVertexAttribArray(hVertexLength0);
|
||||
GLES20.glEnableVertexAttribArray(hVertexLength1);
|
||||
GLES20.glEnableVertexAttribArray(hVertexFlip);
|
||||
GL.glEnableVertexAttribArray(hVertexPosition0);
|
||||
GL.glEnableVertexAttribArray(hVertexPosition1);
|
||||
GL.glEnableVertexAttribArray(hVertexLength0);
|
||||
GL.glEnableVertexAttribArray(hVertexLength1);
|
||||
GL.glEnableVertexAttribArray(hVertexFlip);
|
||||
|
||||
m.mvp.setAsUniform(hMatrix);
|
||||
|
||||
int maxIndices = GLRenderer.maxQuads * 6;
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER,
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER,
|
||||
GLRenderer.mQuadIndicesID);
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVertexFlipID);
|
||||
GLES20.glVertexAttribPointer(hVertexFlip, 1,
|
||||
GLES20.GL_BYTE, false, 0, 0);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, mVertexFlipID);
|
||||
GL.glVertexAttribPointer(hVertexFlip, 1,
|
||||
GL20.GL_BYTE, false, 0, 0);
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, layers.vbo.id);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, layers.vbo.id);
|
||||
|
||||
float scale = (float) pos.getZoomScale();
|
||||
|
||||
float s = scale / div;
|
||||
|
||||
//GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexID[0]);
|
||||
//GL.glBindTexture(GL20.GL_TEXTURE_2D, mTexID[0]);
|
||||
|
||||
Layer l = curLayer;
|
||||
for (; l != null && l.type == Layer.TEXLINE; l = l.next) {
|
||||
@ -145,12 +145,12 @@ public class LineTexRenderer {
|
||||
if (pScale < 1)
|
||||
pScale = 1;
|
||||
|
||||
GLES20.glUniform1f(hPatternScale, (GLRenderer.COORD_SCALE * line.stipple) / pScale);
|
||||
GLES20.glUniform1f(hPatternWidth, line.stippleWidth);
|
||||
GL.glUniform1f(hPatternScale, (GLRenderer.COORD_SCALE * line.stipple) / pScale);
|
||||
GL.glUniform1f(hPatternWidth, line.stippleWidth);
|
||||
|
||||
GLES20.glUniform1f(hScale, scale);
|
||||
GL.glUniform1f(hScale, scale);
|
||||
// keep line width fixed
|
||||
GLES20.glUniform1f(hWidth, ll.width / s * COORD_SCALE_BY_DIR_SCALE);
|
||||
GL.glUniform1f(hWidth, ll.width / s * COORD_SCALE_BY_DIR_SCALE);
|
||||
|
||||
// add offset vertex
|
||||
int vOffset = -STRIDE;
|
||||
@ -165,24 +165,24 @@ public class LineTexRenderer {
|
||||
// i / 6 * (24 shorts per block * 2 short bytes)
|
||||
int add = (l.offset + i * 8) + vOffset;
|
||||
|
||||
GLES20.glVertexAttribPointer(hVertexPosition0,
|
||||
4, GLES20.GL_SHORT, false, STRIDE,
|
||||
GL.glVertexAttribPointer(hVertexPosition0,
|
||||
4, GL20.GL_SHORT, false, STRIDE,
|
||||
add + STRIDE);
|
||||
|
||||
GLES20.glVertexAttribPointer(hVertexLength0,
|
||||
2, GLES20.GL_SHORT, false, STRIDE,
|
||||
GL.glVertexAttribPointer(hVertexLength0,
|
||||
2, GL20.GL_SHORT, false, STRIDE,
|
||||
add + STRIDE + LEN_OFFSET);
|
||||
|
||||
GLES20.glVertexAttribPointer(hVertexPosition1,
|
||||
4, GLES20.GL_SHORT, false, STRIDE,
|
||||
GL.glVertexAttribPointer(hVertexPosition1,
|
||||
4, GL20.GL_SHORT, false, STRIDE,
|
||||
add);
|
||||
|
||||
GLES20.glVertexAttribPointer(hVertexLength1,
|
||||
2, GLES20.GL_SHORT, false, STRIDE,
|
||||
GL.glVertexAttribPointer(hVertexLength1,
|
||||
2, GL20.GL_SHORT, false, STRIDE,
|
||||
add + LEN_OFFSET);
|
||||
|
||||
GLES20.glDrawElements(GLES20.GL_TRIANGLES, numIndices,
|
||||
GLES20.GL_UNSIGNED_SHORT, 0);
|
||||
GL.glDrawElements(GL20.GL_TRIANGLES, numIndices,
|
||||
GL20.GL_UNSIGNED_SHORT, 0);
|
||||
}
|
||||
|
||||
// second pass
|
||||
@ -194,37 +194,37 @@ public class LineTexRenderer {
|
||||
// i / 6 * (24 shorts per block * 2 short bytes)
|
||||
int add = (l.offset + i * 8) + vOffset;
|
||||
|
||||
GLES20.glVertexAttribPointer(hVertexPosition0,
|
||||
4, GLES20.GL_SHORT, false, STRIDE,
|
||||
GL.glVertexAttribPointer(hVertexPosition0,
|
||||
4, GL20.GL_SHORT, false, STRIDE,
|
||||
add + 2 * STRIDE);
|
||||
|
||||
GLES20.glVertexAttribPointer(hVertexLength0,
|
||||
2, GLES20.GL_SHORT, false, STRIDE,
|
||||
GL.glVertexAttribPointer(hVertexLength0,
|
||||
2, GL20.GL_SHORT, false, STRIDE,
|
||||
add + 2 * STRIDE + LEN_OFFSET);
|
||||
|
||||
GLES20.glVertexAttribPointer(hVertexPosition1,
|
||||
4, GLES20.GL_SHORT, false, STRIDE,
|
||||
GL.glVertexAttribPointer(hVertexPosition1,
|
||||
4, GL20.GL_SHORT, false, STRIDE,
|
||||
add + STRIDE);
|
||||
|
||||
GLES20.glVertexAttribPointer(hVertexLength1,
|
||||
2, GLES20.GL_SHORT, false, STRIDE,
|
||||
GL.glVertexAttribPointer(hVertexLength1,
|
||||
2, GL20.GL_SHORT, false, STRIDE,
|
||||
add + STRIDE + LEN_OFFSET);
|
||||
|
||||
GLES20.glDrawElements(GLES20.GL_TRIANGLES, numIndices,
|
||||
GLES20.GL_UNSIGNED_SHORT, 0);
|
||||
GL.glDrawElements(GL20.GL_TRIANGLES, numIndices,
|
||||
GL20.GL_UNSIGNED_SHORT, 0);
|
||||
}
|
||||
//GlUtils.checkGlError(TAG);
|
||||
}
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
GLES20.glDisableVertexAttribArray(hVertexPosition0);
|
||||
GLES20.glDisableVertexAttribArray(hVertexPosition1);
|
||||
GLES20.glDisableVertexAttribArray(hVertexLength0);
|
||||
GLES20.glDisableVertexAttribArray(hVertexLength1);
|
||||
GLES20.glDisableVertexAttribArray(hVertexFlip);
|
||||
GL.glDisableVertexAttribArray(hVertexPosition0);
|
||||
GL.glDisableVertexAttribArray(hVertexPosition1);
|
||||
GL.glDisableVertexAttribArray(hVertexLength0);
|
||||
GL.glDisableVertexAttribArray(hVertexLength1);
|
||||
GL.glDisableVertexAttribArray(hVertexFlip);
|
||||
|
||||
//GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
|
||||
//GL.glBindTexture(GL20.GL_TEXTURE_2D, 0);
|
||||
|
||||
return l;
|
||||
}
|
||||
@ -278,44 +278,50 @@ public class LineTexRenderer {
|
||||
+ " } "; //*/
|
||||
|
||||
/*
|
||||
final static String fragmentShader = ""
|
||||
+ "#extension GL_OES_standard_derivatives : enable\n"
|
||||
+ " precision mediump float;"
|
||||
+ " uniform sampler2D tex;"
|
||||
+ " uniform float u_scale;"
|
||||
+ " uniform vec4 u_color;"
|
||||
+ " uniform vec4 u_bgcolor;"
|
||||
+ " varying vec2 v_st;"
|
||||
+ " void main() {"
|
||||
+ " float len = texture2D(tex, v_st).a;"
|
||||
+ " float tex_w = abs(v_st.t);"
|
||||
+ " vec2 st_width = fwidth(v_st);"
|
||||
+ " float fuzz = max(st_width.s, st_width.t);"
|
||||
//+ " float fuzz = fwidth(v_st.t);"
|
||||
//+ " float line_w = 1.0 - smoothstep(1.0 - fuzz, 1.0, tex_w);"
|
||||
//+ " float stipple_w = 1.0 - smoothstep(0.7 - fuzz, 0.7, tex_w);"
|
||||
+ " float stipple_p = 1.0 - smoothstep(1.0 - fuzz, 1.0, length(vec2(len*u_scale, v_st.t)));"
|
||||
+ " gl_FragColor = u_bgcolor * stipple_p;"
|
||||
// + " gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));"
|
||||
+ "}"; //*/
|
||||
* final static String fragmentShader = ""
|
||||
* + "#extension GL_OES_standard_derivatives : enable\n"
|
||||
* + " precision mediump float;"
|
||||
* + " uniform sampler2D tex;"
|
||||
* + " uniform float u_scale;"
|
||||
* + " uniform vec4 u_color;"
|
||||
* + " uniform vec4 u_bgcolor;"
|
||||
* + " varying vec2 v_st;"
|
||||
* + " void main() {"
|
||||
* + " float len = texture2D(tex, v_st).a;"
|
||||
* + " float tex_w = abs(v_st.t);"
|
||||
* + " vec2 st_width = fwidth(v_st);"
|
||||
* + " float fuzz = max(st_width.s, st_width.t);"
|
||||
* //+ " float fuzz = fwidth(v_st.t);"
|
||||
* //+ " float line_w = 1.0 - smoothstep(1.0 - fuzz, 1.0, tex_w);"
|
||||
* //+ " float stipple_w = 1.0 - smoothstep(0.7 - fuzz, 0.7, tex_w);"
|
||||
* +
|
||||
* " float stipple_p = 1.0 - smoothstep(1.0 - fuzz, 1.0, length(vec2(len*u_scale, v_st.t)));"
|
||||
* + " gl_FragColor = u_bgcolor * stipple_p;"
|
||||
* // +
|
||||
* " gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));"
|
||||
* + "}"; //
|
||||
*/
|
||||
/*
|
||||
final static String fragmentShader = ""
|
||||
+ "#extension GL_OES_standard_derivatives : enable\n"
|
||||
+ " precision mediump float;"
|
||||
+ " uniform sampler2D tex;"
|
||||
+ " uniform vec4 u_color;"
|
||||
+ " uniform vec4 u_bgcolor;"
|
||||
+ " uniform float u_pwidth;"
|
||||
+ " varying vec2 v_st;"
|
||||
+ " void main() {"
|
||||
+ " float dist = texture2D(tex, v_st).a;"
|
||||
+ " float tex_w = abs(v_st.t);"
|
||||
+ " vec2 st_width = fwidth(v_st);"
|
||||
+ " float fuzz = max(st_width.s, st_width.t);"
|
||||
+ " float line_w = (1.0 - smoothstep(1.0 - fuzz, 1.0, tex_w));"
|
||||
+ " float stipple_w = (1.0 - smoothstep(u_pwidth - fuzz, u_pwidth, tex_w));"
|
||||
+ " float stipple_p = smoothstep(0.495, 0.505, dist);"
|
||||
+ " gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));"
|
||||
+ " } "; //*/
|
||||
* final static String fragmentShader = ""
|
||||
* + "#extension GL_OES_standard_derivatives : enable\n"
|
||||
* + " precision mediump float;"
|
||||
* + " uniform sampler2D tex;"
|
||||
* + " uniform vec4 u_color;"
|
||||
* + " uniform vec4 u_bgcolor;"
|
||||
* + " uniform float u_pwidth;"
|
||||
* + " varying vec2 v_st;"
|
||||
* + " void main() {"
|
||||
* + " float dist = texture2D(tex, v_st).a;"
|
||||
* + " float tex_w = abs(v_st.t);"
|
||||
* + " vec2 st_width = fwidth(v_st);"
|
||||
* + " float fuzz = max(st_width.s, st_width.t);"
|
||||
* + " float line_w = (1.0 - smoothstep(1.0 - fuzz, 1.0, tex_w));"
|
||||
* +
|
||||
* " float stipple_w = (1.0 - smoothstep(u_pwidth - fuzz, u_pwidth, tex_w));"
|
||||
* + " float stipple_p = smoothstep(0.495, 0.505, dist);"
|
||||
* +
|
||||
* " gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));"
|
||||
* + " } "; //
|
||||
*/
|
||||
|
||||
}
|
||||
|
@ -17,10 +17,10 @@ package org.oscim.renderer.sublayers;
|
||||
import java.nio.ShortBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.core.Tile;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class MeshLayer extends Layer {
|
||||
GeometryBuffer mGeom = new GeometryBuffer(10,10);
|
||||
|
@ -14,27 +14,12 @@
|
||||
*/
|
||||
package org.oscim.renderer.sublayers;
|
||||
|
||||
import static android.opengl.GLES20.GL_ALWAYS;
|
||||
import static android.opengl.GLES20.GL_EQUAL;
|
||||
import static android.opengl.GLES20.GL_INVERT;
|
||||
import static android.opengl.GLES20.GL_SHORT;
|
||||
import static android.opengl.GLES20.GL_TRIANGLE_FAN;
|
||||
import static android.opengl.GLES20.GL_TRIANGLE_STRIP;
|
||||
import static android.opengl.GLES20.glColorMask;
|
||||
import static android.opengl.GLES20.glDepthMask;
|
||||
import static android.opengl.GLES20.glDrawArrays;
|
||||
import static android.opengl.GLES20.glGetAttribLocation;
|
||||
import static android.opengl.GLES20.glGetUniformLocation;
|
||||
import static android.opengl.GLES20.glStencilFunc;
|
||||
import static android.opengl.GLES20.glStencilMask;
|
||||
import static android.opengl.GLES20.glStencilOp;
|
||||
import static android.opengl.GLES20.glUniform4fv;
|
||||
import static android.opengl.GLES20.glVertexAttribPointer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
import org.oscim.renderer.GLRenderer.Matrices;
|
||||
@ -44,14 +29,14 @@ import org.oscim.utils.FastMath;
|
||||
import org.oscim.utils.GlUtils;
|
||||
import org.oscim.utils.Matrix4;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
|
||||
/**
|
||||
* Special Renderer for drawing tile polygon layers
|
||||
*/
|
||||
public final class PolygonRenderer {
|
||||
private static final String TAG = PolygonRenderer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
private static final int POLYGON_VERTICES_DATA_POS_OFFSET = 0;
|
||||
private static final int STENCIL_BITS = 8;
|
||||
private final static int CLIP_BIT = 0x80;
|
||||
@ -98,11 +83,11 @@ public final class PolygonRenderer {
|
||||
// Log.e(TAG, "Could not create polygon program.");
|
||||
return false;
|
||||
}
|
||||
hPolygonMatrix[i] = glGetUniformLocation(polygonProgram[i], "u_mvp");
|
||||
hPolygonColor[i] = glGetUniformLocation(polygonProgram[i], "u_color");
|
||||
hPolygonScale[i] = glGetUniformLocation(polygonProgram[i], "u_scale");
|
||||
hPolygonMatrix[i] = GL.glGetUniformLocation(polygonProgram[i], "u_mvp");
|
||||
hPolygonColor[i] = GL.glGetUniformLocation(polygonProgram[i], "u_color");
|
||||
hPolygonScale[i] = GL.glGetUniformLocation(polygonProgram[i], "u_scale");
|
||||
|
||||
hPolygonVertexPosition[i] = glGetAttribLocation(polygonProgram[i], "a_pos");
|
||||
hPolygonVertexPosition[i] = GL.glGetAttribLocation(polygonProgram[i], "a_pos");
|
||||
}
|
||||
|
||||
mFillPolys = new PolygonLayer[STENCIL_BITS];
|
||||
@ -119,16 +104,16 @@ public final class PolygonRenderer {
|
||||
//
|
||||
// try {
|
||||
// Bitmap b = BitmapUtils.createBitmap(name);
|
||||
// GLES20.glGenTextures(1, textures, 0);
|
||||
// GL.glGenTextures(1, textures, 0);
|
||||
//
|
||||
// GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
|
||||
// GL.glBindTexture(GL20.GL_TEXTURE_2D, textures[0]);
|
||||
//
|
||||
// GlUtils.setTextureParameter(GLES20.GL_LINEAR, GLES20.GL_LINEAR,
|
||||
// GLES20.GL_REPEAT, GLES20.GL_REPEAT);
|
||||
// GlUtils.setTextureParameter(GL20.GL_LINEAR, GL20.GL_LINEAR,
|
||||
// GL20.GL_REPEAT, GL20.GL_REPEAT);
|
||||
//
|
||||
// b.uploadToTexture(false);
|
||||
//
|
||||
// //GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, b, 0);
|
||||
// //GLUtils.texImage2D(GL20.GL_TEXTURE_2D, 0, b, 0);
|
||||
//
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
@ -140,10 +125,10 @@ public final class PolygonRenderer {
|
||||
float div) {
|
||||
|
||||
/* draw to framebuffer */
|
||||
glColorMask(true, true, true, true);
|
||||
GL.glColorMask(true, true, true, true);
|
||||
|
||||
/* do not modify stencil buffer */
|
||||
glStencilMask(0x00);
|
||||
GL.glStencilMask(0x00);
|
||||
int shader = polyShader;
|
||||
|
||||
for (int c = start; c < end; c++) {
|
||||
@ -154,13 +139,13 @@ public final class PolygonRenderer {
|
||||
shader = texShader;
|
||||
setShader(texShader, m);
|
||||
|
||||
GLES20.glUniform2f(hPolygonScale[1], FastMath.clamp(scale - 1, 0, 1), div);
|
||||
GL.glUniform2f(hPolygonScale[1], FastMath.clamp(scale - 1, 0, 1), div);
|
||||
if (a.color == 0xFFAFC5E3)
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexWater);
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, mTexWater);
|
||||
else if (a.color == 0xffd1dbc7)
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexWood);
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, mTexWood);
|
||||
else
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexGrass);
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, mTexGrass);
|
||||
} else if (a.fade >= zoom) {
|
||||
float f = 1.0f;
|
||||
/* fade in/out */
|
||||
@ -196,10 +181,10 @@ public final class PolygonRenderer {
|
||||
// set stencil buffer mask used to draw this layer
|
||||
// also check that clip bit is set to avoid overdraw
|
||||
// of other tiles
|
||||
glStencilFunc(GL_EQUAL, 0xff, CLIP_BIT | 1 << c);
|
||||
GL.glStencilFunc(GL20.GL_EQUAL, 0xff, CLIP_BIT | 1 << c);
|
||||
|
||||
/* draw tile fill coordinates */
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
if (shader != polyShader) {
|
||||
setShader(polyShader, m);
|
||||
@ -218,7 +203,7 @@ public final class PolygonRenderer {
|
||||
|
||||
GLState.enableVertexArrays(hPolygonVertexPosition[shader], -1);
|
||||
|
||||
glVertexAttribPointer(hPolygonVertexPosition[shader], 2, GL_SHORT,
|
||||
GL.glVertexAttribPointer(hPolygonVertexPosition[shader], 2, GL20.GL_SHORT,
|
||||
false, 0, POLYGON_VERTICES_DATA_POS_OFFSET);
|
||||
|
||||
m.mvp.setAsUniform(hPolygonMatrix[shader]);
|
||||
@ -276,15 +261,15 @@ public final class PolygonRenderer {
|
||||
first = false;
|
||||
|
||||
// op for stencil method polygon drawing
|
||||
glStencilOp(GLES20.GL_KEEP, GLES20.GL_KEEP, GL_INVERT);
|
||||
GL.glStencilOp(GL20.GL_KEEP, GL20.GL_KEEP, GL20.GL_INVERT);
|
||||
}
|
||||
|
||||
mFillPolys[cur] = pl;
|
||||
|
||||
// set stencil mask to draw to
|
||||
glStencilMask(1 << cur++);
|
||||
GL.glStencilMask(1 << cur++);
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_FAN, l.offset, l.verticesCnt);
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_FAN, l.offset, l.verticesCnt);
|
||||
|
||||
// draw up to 7 layers into stencil buffer
|
||||
if (cur == STENCIL_BITS - 1) {
|
||||
@ -300,12 +285,12 @@ public final class PolygonRenderer {
|
||||
if (first) {
|
||||
drawStencilRegion(first);
|
||||
// disable writes to stencil buffer
|
||||
glStencilMask(0x00);
|
||||
GL.glStencilMask(0x00);
|
||||
// enable writes to color buffer
|
||||
glColorMask(true, true, true, true);
|
||||
GL.glColorMask(true, true, true, true);
|
||||
} else {
|
||||
// set test for clip to tile region
|
||||
glStencilFunc(GL_EQUAL, CLIP_BIT, CLIP_BIT);
|
||||
GL.glStencilFunc(GL20.GL_EQUAL, CLIP_BIT, CLIP_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
@ -324,57 +309,57 @@ public final class PolygonRenderer {
|
||||
static void drawStencilRegion(boolean first) {
|
||||
|
||||
// if (!first) {
|
||||
// glStencilMask(0x7F);
|
||||
// GLES20.glClear(GLES20.GL_STENCIL_BUFFER_BIT);
|
||||
// GL.glStencilMask(0x7F);
|
||||
// GL.glClear(GL20.GL_STENCIL_BUFFER_BIT);
|
||||
// // disable drawing to color buffer
|
||||
// glColorMask(false, false, false, false);
|
||||
// glStencilFunc(GL_EQUAL, CLIP_BIT, CLIP_BIT);
|
||||
// GL.glColorMask(false, false, false, false);
|
||||
// GL.glStencilFunc(GL_EQUAL, CLIP_BIT, CLIP_BIT);
|
||||
// }
|
||||
|
||||
// disable drawing to color buffer
|
||||
glColorMask(false, false, false, false);
|
||||
GL.glColorMask(false, false, false, false);
|
||||
|
||||
// write to all stencil bits
|
||||
glStencilMask(0xFF);
|
||||
GL.glStencilMask(0xFF);
|
||||
|
||||
if (first) {
|
||||
// clear previous clip-region from stencil buffer
|
||||
//GLES20.glClear(GLES20.GL_STENCIL_BUFFER_BIT);
|
||||
//GL.glClear(GL20.GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
// Draw clip-region into depth and stencil buffer
|
||||
// this is used for tile line and polygon layers.
|
||||
// Depth offset is increased for each tile. Together
|
||||
// with depth test (GL_LESS) this ensures to only
|
||||
// draw where no other tile has drawn yet.
|
||||
GLES20.glEnable(GLES20.GL_POLYGON_OFFSET_FILL);
|
||||
GL.glEnable(GL20.GL_POLYGON_OFFSET_FILL);
|
||||
|
||||
// test GL_LESS and write to depth buffer
|
||||
GLState.test(true, true);
|
||||
glDepthMask(true);
|
||||
GL.glDepthMask(true);
|
||||
|
||||
// always pass stencil test and set clip bit
|
||||
glStencilFunc(GL_ALWAYS, CLIP_BIT, 0x00);
|
||||
GL.glStencilFunc(GL20.GL_ALWAYS, CLIP_BIT, 0x00);
|
||||
} else {
|
||||
// use clip bit from stencil buffer
|
||||
// to clear stencil 'layer-bits' (0x7f)
|
||||
glStencilFunc(GL_EQUAL, CLIP_BIT, CLIP_BIT);
|
||||
GL.glStencilFunc(GL20.GL_EQUAL, CLIP_BIT, CLIP_BIT);
|
||||
}
|
||||
|
||||
// set clip bit (0x80) for draw region
|
||||
glStencilOp(GLES20.GL_KEEP, GLES20.GL_KEEP, GLES20.GL_REPLACE);
|
||||
GL.glStencilOp(GL20.GL_KEEP, GL20.GL_KEEP, GL20.GL_REPLACE);
|
||||
|
||||
// draw a quad for the tile region
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
if (first) {
|
||||
// dont modify depth buffer
|
||||
glDepthMask(false);
|
||||
GL.glDepthMask(false);
|
||||
// test only stencil
|
||||
GLState.test(false, true);
|
||||
|
||||
GLES20.glDisable(GLES20.GL_POLYGON_OFFSET_FILL);
|
||||
GL.glDisable(GL20.GL_POLYGON_OFFSET_FILL);
|
||||
|
||||
glStencilFunc(GL_EQUAL, CLIP_BIT, CLIP_BIT);
|
||||
GL.glStencilFunc(GL20.GL_EQUAL, CLIP_BIT, CLIP_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
@ -391,21 +376,21 @@ public final class PolygonRenderer {
|
||||
GLState.blend(true);
|
||||
} else {
|
||||
// disable drawing to framebuffer (will be re-enabled in fill)
|
||||
glColorMask(false, false, false, false);
|
||||
GL.glColorMask(false, false, false, false);
|
||||
}
|
||||
// always pass stencil test:
|
||||
//glStencilFunc(GL_ALWAYS, 0x00, 0x00);
|
||||
glStencilFunc(GL_EQUAL, CLIP_BIT, CLIP_BIT);
|
||||
GL.glStencilFunc(GL20.GL_EQUAL, CLIP_BIT, CLIP_BIT);
|
||||
|
||||
// write to all bits
|
||||
glStencilMask(0xFF);
|
||||
GL.glStencilMask(0xFF);
|
||||
// zero out area to draw to
|
||||
glStencilOp(GLES20.GL_KEEP, GLES20.GL_KEEP, GLES20.GL_ZERO);
|
||||
GL.glStencilOp(GL20.GL_KEEP, GL20.GL_KEEP, GL20.GL_ZERO);
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
if (!drawColor)
|
||||
glColorMask(true, true, true, true);
|
||||
GL.glColorMask(true, true, true, true);
|
||||
}
|
||||
|
||||
private static float[] debugFillColor = { 0.3f, 0.0f, 0.0f, 0.3f };
|
||||
@ -420,23 +405,23 @@ public final class PolygonRenderer {
|
||||
mDebugFill.put(coords);
|
||||
}
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
mDebugFill.position(0);
|
||||
GLState.useProgram(polygonProgram[0]);
|
||||
GLES20.glEnableVertexAttribArray(hPolygonVertexPosition[0]);
|
||||
GL.glEnableVertexAttribArray(hPolygonVertexPosition[0]);
|
||||
|
||||
glVertexAttribPointer(hPolygonVertexPosition[0], 2, GLES20.GL_FLOAT,
|
||||
GL.glVertexAttribPointer(hPolygonVertexPosition[0], 2, GL20.GL_FLOAT,
|
||||
false, 0, mDebugFill);
|
||||
|
||||
m.setAsUniform(hPolygonMatrix[0]);
|
||||
|
||||
if (color == 0)
|
||||
glUniform4fv(hPolygonColor[0], 1, debugFillColor, 0);
|
||||
GlUtils.glUniform4fv(hPolygonColor[0], 1, debugFillColor);
|
||||
else
|
||||
glUniform4fv(hPolygonColor[0], 1, debugFillColor2, 0);
|
||||
GlUtils.glUniform4fv(hPolygonColor[0], 1, debugFillColor2);
|
||||
|
||||
glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
GlUtils.checkGlError("draw debug");
|
||||
}
|
||||
|
@ -16,19 +16,20 @@ package org.oscim.renderer.sublayers;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.utils.GlUtils;
|
||||
import org.oscim.utils.pool.Inlist;
|
||||
import org.oscim.utils.pool.SyncPool;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
import org.oscim.backend.Log;
|
||||
|
||||
// FIXME
|
||||
|
||||
public class TextureItem extends Inlist<TextureItem> {
|
||||
private final static String TAG = TextureItem.class.getName();
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
// texture ID
|
||||
public int id;
|
||||
@ -94,9 +95,7 @@ public class TextureItem extends Inlist<TextureItem> {
|
||||
|
||||
@Override
|
||||
public void init(int num) {
|
||||
|
||||
int[] textureIds = new int[num];
|
||||
GLES20.glGenTextures(num, textureIds, 0);
|
||||
int[] textureIds = GlUtils.glGenTextures(num);
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
initTexture(textureIds[i]);
|
||||
@ -173,13 +172,12 @@ public class TextureItem extends Inlist<TextureItem> {
|
||||
for (int i = 0; i < size; i++)
|
||||
tmp[i] = mTextures.get(i).intValue();
|
||||
mTextures.clear();
|
||||
GLES20.glDeleteTextures(size, tmp, 0);
|
||||
GlUtils.glDeleteTextures(size, tmp);
|
||||
}
|
||||
|
||||
if (to.id < 0) {
|
||||
mTexCnt++;
|
||||
int[] textureIds = new int[1];
|
||||
GLES20.glGenTextures(1, textureIds, 0);
|
||||
int[] textureIds = GlUtils.glGenTextures(1);
|
||||
to.id = textureIds[0];
|
||||
initTexture(to.id);
|
||||
if (TextureRenderer.debug)
|
||||
@ -205,19 +203,19 @@ public class TextureItem extends Inlist<TextureItem> {
|
||||
Log.d(TAG, "no texture!");
|
||||
return;
|
||||
}
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, to.id);
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, to.id);
|
||||
|
||||
if (to.ownBitmap) {
|
||||
bitmap.uploadToTexture(false);
|
||||
//GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
|
||||
//GLUtils.texImage2D(GL20.GL_TEXTURE_2D, 0, bitmap, 0);
|
||||
|
||||
} else if (to.width == w && to.height == h) {
|
||||
bitmap.uploadToTexture(true);
|
||||
//GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, bitmap, format, type);
|
||||
//GLUtils.texSubImage2D(GL20.GL_TEXTURE_2D, 0, 0, 0, bitmap, format, type);
|
||||
|
||||
} else {
|
||||
bitmap.uploadToTexture(false);
|
||||
//GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, format, bitmap, type, 0);
|
||||
//GLUtils.texImage2D(GL20.GL_TEXTURE_2D, 0, format, bitmap, type, 0);
|
||||
to.width = w;
|
||||
to.height = h;
|
||||
}
|
||||
@ -227,16 +225,16 @@ public class TextureItem extends Inlist<TextureItem> {
|
||||
}
|
||||
|
||||
static void initTexture(int id) {
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, id);
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, id);
|
||||
|
||||
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
|
||||
GLES20.GL_LINEAR);
|
||||
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER,
|
||||
GLES20.GL_LINEAR);
|
||||
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,
|
||||
GLES20.GL_CLAMP_TO_EDGE); // Set U Wrapping
|
||||
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
|
||||
GLES20.GL_CLAMP_TO_EDGE); // Set V Wrapping
|
||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER,
|
||||
GL20.GL_LINEAR);
|
||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MAG_FILTER,
|
||||
GL20.GL_LINEAR);
|
||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_S,
|
||||
GL20.GL_CLAMP_TO_EDGE); // Set U Wrapping
|
||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_T,
|
||||
GL20.GL_CLAMP_TO_EDGE); // Set V Wrapping
|
||||
}
|
||||
|
||||
static void init(int num) {
|
||||
|
@ -17,15 +17,18 @@ package org.oscim.renderer.sublayers;
|
||||
|
||||
import static org.oscim.renderer.GLRenderer.COORD_SCALE;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
import org.oscim.renderer.GLRenderer.Matrices;
|
||||
import org.oscim.renderer.GLState;
|
||||
import org.oscim.utils.GlUtils;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
|
||||
public final class TextureRenderer {
|
||||
//private final static String TAG = TextureRenderer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
public final static boolean debug = false;
|
||||
|
||||
private static int mTextureProgram;
|
||||
@ -45,13 +48,13 @@ public final class TextureRenderer {
|
||||
mTextureProgram = GlUtils.createProgram(textVertexShader,
|
||||
textFragmentShader);
|
||||
|
||||
hTextureMVMatrix = GLES20.glGetUniformLocation(mTextureProgram, "u_mv");
|
||||
hTextureProjMatrix = GLES20.glGetUniformLocation(mTextureProgram, "u_proj");
|
||||
hTextureScale = GLES20.glGetUniformLocation(mTextureProgram, "u_scale");
|
||||
hTextureSize = GLES20.glGetUniformLocation(mTextureProgram, "u_div");
|
||||
hTextureScreenScale = GLES20.glGetUniformLocation(mTextureProgram, "u_swidth");
|
||||
hTextureVertex = GLES20.glGetAttribLocation(mTextureProgram, "vertex");
|
||||
hTextureTexCoord = GLES20.glGetAttribLocation(mTextureProgram, "tex_coord");
|
||||
hTextureMVMatrix = GL.glGetUniformLocation(mTextureProgram, "u_mv");
|
||||
hTextureProjMatrix = GL.glGetUniformLocation(mTextureProgram, "u_proj");
|
||||
hTextureScale = GL.glGetUniformLocation(mTextureProgram, "u_scale");
|
||||
hTextureSize = GL.glGetUniformLocation(mTextureProgram, "u_div");
|
||||
hTextureScreenScale = GL.glGetUniformLocation(mTextureProgram, "u_swidth");
|
||||
hTextureVertex = GL.glGetAttribLocation(mTextureProgram, "vertex");
|
||||
hTextureTexCoord = GL.glGetAttribLocation(mTextureProgram, "tex_coord");
|
||||
}
|
||||
|
||||
public static Layer draw(Layer layer, float scale, Matrices m) {
|
||||
@ -65,23 +68,23 @@ public final class TextureRenderer {
|
||||
TextureLayer tl = (TextureLayer) layer;
|
||||
|
||||
if (tl.fixed)
|
||||
GLES20.glUniform1f(hTextureScale, (float) Math.sqrt(scale));
|
||||
GL.glUniform1f(hTextureScale, (float) Math.sqrt(scale));
|
||||
else
|
||||
GLES20.glUniform1f(hTextureScale, 1);
|
||||
GL.glUniform1f(hTextureScale, 1);
|
||||
|
||||
GLES20.glUniform1f(hTextureScreenScale, 1f / GLRenderer.screenWidth);
|
||||
GL.glUniform1f(hTextureScreenScale, 1f / GLRenderer.screenWidth);
|
||||
|
||||
m.proj.setAsUniform(hTextureProjMatrix);
|
||||
m.mvp.setAsUniform(hTextureMVMatrix);
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, GLRenderer.mQuadIndicesID);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, GLRenderer.mQuadIndicesID);
|
||||
|
||||
for (TextureItem ti = tl.textures; ti != null; ti = ti.next) {
|
||||
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, ti.id);
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, ti.id);
|
||||
int maxVertices = GLRenderer.maxQuads * INDICES_PER_SPRITE;
|
||||
|
||||
GLES20.glUniform2f(hTextureSize,
|
||||
GL.glUniform2f(hTextureSize,
|
||||
1f / (ti.width * COORD_SCALE),
|
||||
1f / (ti.height * COORD_SCALE));
|
||||
|
||||
@ -90,22 +93,22 @@ public final class TextureRenderer {
|
||||
// to.offset * (24(shorts) * 2(short-bytes) / 6(indices) == 8)
|
||||
int off = (ti.offset + i) * 8 + tl.offset;
|
||||
|
||||
GLES20.glVertexAttribPointer(hTextureVertex, 4,
|
||||
GLES20.GL_SHORT, false, 12, off);
|
||||
GL.glVertexAttribPointer(hTextureVertex, 4,
|
||||
GL20.GL_SHORT, false, 12, off);
|
||||
|
||||
GLES20.glVertexAttribPointer(hTextureTexCoord, 2,
|
||||
GLES20.GL_SHORT, false, 12, off + 8);
|
||||
GL.glVertexAttribPointer(hTextureTexCoord, 2,
|
||||
GL20.GL_SHORT, false, 12, off + 8);
|
||||
|
||||
int numVertices = ti.vertices - i;
|
||||
if (numVertices > maxVertices)
|
||||
numVertices = maxVertices;
|
||||
|
||||
GLES20.glDrawElements(GLES20.GL_TRIANGLES, numVertices,
|
||||
GLES20.GL_UNSIGNED_SHORT, 0);
|
||||
GL.glDrawElements(GL20.GL_TRIANGLES, numVertices,
|
||||
GL20.GL_UNSIGNED_SHORT, 0);
|
||||
}
|
||||
}
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
return layer.next;
|
||||
}
|
||||
|
@ -130,9 +130,6 @@ public final class Text extends RenderInstruction {
|
||||
|
||||
Text t = new Text("", "", FontFamily.DEFAULT, FontStyle.NORMAL,
|
||||
fontSize, fill, outline, strokeWidth, 0, billboard, null, Integer.MAX_VALUE);
|
||||
//FontMetrics fm = t.paint.getFontMetrics();
|
||||
//t.fontHeight = (float) Math.ceil(Math.abs(fm.bottom) + Math.abs(fm.top));
|
||||
//t.fontDescent = (float) Math.ceil(Math.abs(fm.bottom));
|
||||
|
||||
t.fontHeight = t.paint.getFontHeight();
|
||||
t.fontDescent = t.paint.getFontDescent();
|
||||
@ -140,38 +137,6 @@ public final class Text extends RenderInstruction {
|
||||
return t;
|
||||
}
|
||||
|
||||
//private static int getStyle(FontStyle fontStyle) {
|
||||
// switch (fontStyle) {
|
||||
// case BOLD:
|
||||
// return 1;
|
||||
// case BOLD_ITALIC:
|
||||
// return 3;
|
||||
// case ITALIC:
|
||||
// return 2;
|
||||
// case NORMAL:
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// throw new IllegalArgumentException("unknown font style: " + fontStyle);
|
||||
//}
|
||||
|
||||
//private static Typeface getTypeface(FontFamily fontFamily) {
|
||||
// switch (fontFamily) {
|
||||
// case DEFAULT:
|
||||
// return Typeface.DEFAULT;
|
||||
// case DEFAULT_BOLD:
|
||||
// return Typeface.DEFAULT_BOLD;
|
||||
// case MONOSPACE:
|
||||
// return Typeface.MONOSPACE;
|
||||
// case SANS_SERIF:
|
||||
// return Typeface.SANS_SERIF;
|
||||
// case SERIF:
|
||||
// return Typeface.SERIF;
|
||||
// }
|
||||
//
|
||||
// throw new IllegalArgumentException("unknown font family: " + fontFamily);
|
||||
//}
|
||||
|
||||
private Text(String style, String textKey, FontFamily fontFamily, FontStyle fontStyle,
|
||||
float fontSize, int fill, int outline, float strokeWidth, float dy, boolean caption,
|
||||
String symbol, int priority) {
|
||||
@ -185,9 +150,7 @@ public final class Text extends RenderInstruction {
|
||||
|
||||
paint = CanvasAdapter.g.getPaint();
|
||||
paint.setTextAlign(Align.CENTER);
|
||||
//Typeface typeFace = Typeface.create(Text.getTypeface(fontFamily), Text.getStyle(fontStyle));
|
||||
paint.setTypeface(fontFamily, fontStyle);
|
||||
//paint.setTypeface(typeFace);
|
||||
|
||||
paint.setColor(fill);
|
||||
paint.setTextSize(fontSize);
|
||||
@ -197,7 +160,6 @@ public final class Text extends RenderInstruction {
|
||||
stroke.setStyle(Style.STROKE);
|
||||
stroke.setTextAlign(Align.CENTER);
|
||||
stroke.setTypeface(fontFamily, fontStyle);
|
||||
//stroke.setTypeface(typeFace);
|
||||
stroke.setColor(outline);
|
||||
stroke.setStrokeWidth(strokeWidth);
|
||||
stroke.setTextSize(fontSize);
|
||||
@ -205,6 +167,9 @@ public final class Text extends RenderInstruction {
|
||||
stroke = null;
|
||||
|
||||
this.fontSize = fontSize;
|
||||
|
||||
//fontHeight = paint.getFontHeight();
|
||||
//fontDescent = paint.getFontDescent();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -227,10 +192,6 @@ public final class Text extends RenderInstruction {
|
||||
if (stroke != null)
|
||||
stroke.setTextSize(fontSize * scaleFactor);
|
||||
|
||||
//FontMetrics fm = paint.getFontMetrics();
|
||||
//fontHeight = (float) Math.ceil(Math.abs(fm.bottom) + Math.abs(fm.top));
|
||||
//fontDescent = (float) Math.ceil(Math.abs(fm.bottom));
|
||||
|
||||
fontHeight = paint.getFontHeight();
|
||||
fontDescent = paint.getFontDescent();
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import java.util.zip.InflaterInputStream;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.Tile;
|
||||
|
||||
import android.os.SystemClock;
|
||||
//import android.os.SystemClock;
|
||||
|
||||
public class LwHttp {
|
||||
private static final String TAG = LwHttp.class.getName();
|
||||
@ -36,7 +36,7 @@ public class LwHttp {
|
||||
private final static byte[] HEADER_CONTENT_TYPE = "Content-Type".getBytes();
|
||||
private final static byte[] HEADER_CONTENT_LENGTH = "Content-Length".getBytes();
|
||||
private final static int RESPONSE_EXPECTED_LIVES = 100;
|
||||
private final static int RESPONSE_TIMEOUT = 10000;
|
||||
private final static long RESPONSE_TIMEOUT = (long)10E9; // 10 second in nanosecond (I guess)
|
||||
|
||||
private final static int BUFFER_SIZE = 1024;
|
||||
private final byte[] buffer = new byte[BUFFER_SIZE];
|
||||
@ -194,7 +194,7 @@ public class LwHttp {
|
||||
public boolean sendRequest(Tile tile) throws IOException {
|
||||
|
||||
if (mSocket != null && ((mMaxReq-- <= 0)
|
||||
|| (SystemClock.elapsedRealtime() - mLastRequest > RESPONSE_TIMEOUT))) {
|
||||
|| (System.nanoTime() - mLastRequest > RESPONSE_TIMEOUT))) {
|
||||
|
||||
try {
|
||||
mSocket.close();
|
||||
@ -316,7 +316,7 @@ public class LwHttp {
|
||||
}
|
||||
|
||||
public void requestCompleted() {
|
||||
mLastRequest = SystemClock.elapsedRealtime();
|
||||
mLastRequest = System.nanoTime();
|
||||
}
|
||||
|
||||
public int getContentLength() {
|
||||
|
@ -16,14 +16,20 @@ package org.oscim.utils;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
|
||||
/**
|
||||
* Utility functions
|
||||
*/
|
||||
public class GlUtils {
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
|
||||
public static native void setColor(int location, int color, float alpha);
|
||||
public static native void setColorBlend(int location, int color1, int color2, float mix);
|
||||
@ -31,17 +37,17 @@ public class GlUtils {
|
||||
private static String TAG = "GlUtils";
|
||||
|
||||
public static void setTextureParameter(int min_filter, int mag_filter, int wrap_s, int wrap_t) {
|
||||
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
|
||||
GLES20.GL_TEXTURE_MIN_FILTER,
|
||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D,
|
||||
GL20.GL_TEXTURE_MIN_FILTER,
|
||||
min_filter);
|
||||
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
|
||||
GLES20.GL_TEXTURE_MAG_FILTER,
|
||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D,
|
||||
GL20.GL_TEXTURE_MAG_FILTER,
|
||||
mag_filter);
|
||||
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
|
||||
GLES20.GL_TEXTURE_WRAP_S,
|
||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D,
|
||||
GL20.GL_TEXTURE_WRAP_S,
|
||||
wrap_s); // Set U Wrapping
|
||||
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
|
||||
GLES20.GL_TEXTURE_WRAP_T,
|
||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D,
|
||||
GL20.GL_TEXTURE_WRAP_T,
|
||||
wrap_t); // Set V Wrapping
|
||||
}
|
||||
|
||||
@ -69,10 +75,9 @@ public class GlUtils {
|
||||
|
||||
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[] textureIds = new int[1];
|
||||
GLES20.glGenTextures(1, textureIds, 0);
|
||||
int[] textureIds = GlUtils.glGenTextures(1);
|
||||
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureIds[0]);
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, textureIds[0]);
|
||||
|
||||
setTextureParameter(min_filter, mag_filter, wrap_s, wrap_t);
|
||||
|
||||
@ -80,10 +85,10 @@ public class GlUtils {
|
||||
buf.put(pixel);
|
||||
buf.position(0);
|
||||
|
||||
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, format, width, height, 0, format,
|
||||
GLES20.GL_UNSIGNED_BYTE, buf);
|
||||
GL.glTexImage2D(GL20.GL_TEXTURE_2D, 0, format, width, height, 0, format,
|
||||
GL20.GL_UNSIGNED_BYTE, buf);
|
||||
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, 0);
|
||||
return textureIds[0];
|
||||
}
|
||||
|
||||
@ -112,10 +117,10 @@ public class GlUtils {
|
||||
pos += flip;
|
||||
}
|
||||
|
||||
return loadTexture(pixel, sum, 1, GLES20.GL_ALPHA,
|
||||
GLES20.GL_LINEAR, GLES20.GL_LINEAR,
|
||||
return loadTexture(pixel, sum, 1, GL20.GL_ALPHA,
|
||||
GL20.GL_LINEAR, GL20.GL_LINEAR,
|
||||
//GLES20.GL_NEAREST, GLES20.GL_NEAREST,
|
||||
GLES20.GL_REPEAT, GLES20.GL_REPEAT);
|
||||
GL20.GL_REPEAT, GL20.GL_REPEAT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,16 +131,17 @@ public class GlUtils {
|
||||
* @return gl identifier
|
||||
*/
|
||||
public static int loadShader(int shaderType, String source) {
|
||||
int shader = GLES20.glCreateShader(shaderType);
|
||||
int shader = GL.glCreateShader(shaderType);
|
||||
if (shader != 0) {
|
||||
GLES20.glShaderSource(shader, source);
|
||||
GLES20.glCompileShader(shader);
|
||||
int[] compiled = new int[1];
|
||||
GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
|
||||
if (compiled[0] == 0) {
|
||||
GL.glShaderSource(shader, source);
|
||||
GL.glCompileShader(shader);
|
||||
IntBuffer compiled = GLRenderer.getIntBuffer(1);
|
||||
|
||||
GL.glGetShaderiv(shader, GL20.GL_COMPILE_STATUS, compiled);
|
||||
if (compiled.get() == 0) {
|
||||
Log.e(TAG, "Could not compile shader " + shaderType + ":");
|
||||
Log.e(TAG, GLES20.glGetShaderInfoLog(shader));
|
||||
GLES20.glDeleteShader(shader);
|
||||
Log.e(TAG, GL.glGetShaderInfoLog(shader));
|
||||
GL.glDeleteShader(shader);
|
||||
shader = 0;
|
||||
}
|
||||
}
|
||||
@ -150,30 +156,30 @@ public class GlUtils {
|
||||
* @return gl identifier
|
||||
*/
|
||||
public static int createProgram(String vertexSource, String fragmentSource) {
|
||||
int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
|
||||
int vertexShader = loadShader(GL20.GL_VERTEX_SHADER, vertexSource);
|
||||
if (vertexShader == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
|
||||
int pixelShader = loadShader(GL20.GL_FRAGMENT_SHADER, fragmentSource);
|
||||
if (pixelShader == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int program = GLES20.glCreateProgram();
|
||||
int program = GL.glCreateProgram();
|
||||
if (program != 0) {
|
||||
checkGlError("glCreateProgram");
|
||||
GLES20.glAttachShader(program, vertexShader);
|
||||
GL.glAttachShader(program, vertexShader);
|
||||
checkGlError("glAttachShader");
|
||||
GLES20.glAttachShader(program, pixelShader);
|
||||
GL.glAttachShader(program, pixelShader);
|
||||
checkGlError("glAttachShader");
|
||||
GLES20.glLinkProgram(program);
|
||||
int[] linkStatus = new int[1];
|
||||
GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
|
||||
if (linkStatus[0] != GLES20.GL_TRUE) {
|
||||
GL.glLinkProgram(program);
|
||||
IntBuffer linkStatus = GLRenderer.getIntBuffer(1);
|
||||
GL.glGetProgramiv(program, GL20.GL_LINK_STATUS, linkStatus);
|
||||
if (linkStatus.get() != GL20.GL_TRUE) {
|
||||
Log.e(TAG, "Could not link program: ");
|
||||
Log.e(TAG, GLES20.glGetProgramInfoLog(program));
|
||||
GLES20.glDeleteProgram(program);
|
||||
Log.e(TAG, GL.glGetProgramInfoLog(program));
|
||||
GL.glDeleteProgram(program);
|
||||
program = 0;
|
||||
}
|
||||
}
|
||||
@ -186,7 +192,7 @@ public class GlUtils {
|
||||
*/
|
||||
public static void checkGlError(String op) {
|
||||
int error;
|
||||
while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
|
||||
while ((error = GL.glGetError()) != GL20.GL_NO_ERROR) {
|
||||
Log.e(TAG, op + ": glError " + error);
|
||||
// throw new RuntimeException(op + ": glError " + error);
|
||||
}
|
||||
@ -195,7 +201,7 @@ public class GlUtils {
|
||||
public static boolean checkGlOutOfMemory(String op) {
|
||||
int error;
|
||||
boolean oom = false;
|
||||
while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
|
||||
while ((error = GL.glGetError()) != GL20.GL_NO_ERROR) {
|
||||
Log.e(TAG, op + ": glError " + error);
|
||||
// throw new RuntimeException(op + ": glError " + error);
|
||||
if (error == 1285)
|
||||
@ -205,31 +211,31 @@ public class GlUtils {
|
||||
}
|
||||
|
||||
|
||||
public static void setBlendColors(int handle, float[] c1, float[] c2, float mix) {
|
||||
if (mix <= 0f)
|
||||
GLES20.glUniform4fv(handle, 1, c1, 0);
|
||||
else if (mix >= 1f)
|
||||
GLES20.glUniform4fv(handle, 1, c2, 0);
|
||||
else {
|
||||
GLES20.glUniform4f(handle,
|
||||
c1[0] * (1 - mix) + c2[0] * mix,
|
||||
c1[1] * (1 - mix) + c2[1] * mix,
|
||||
c1[2] * (1 - mix) + c2[2] * mix,
|
||||
c1[3] * (1 - mix) + c2[3] * mix);
|
||||
}
|
||||
}
|
||||
// public static void setBlendColors(int handle, float[] c1, float[] c2, float mix) {
|
||||
// if (mix <= 0f)
|
||||
// GLES20.glUniform4fv(handle, 1, c1, 0);
|
||||
// else if (mix >= 1f)
|
||||
// GLES20.glUniform4fv(handle, 1, c2, 0);
|
||||
// else {
|
||||
// GLES20.glUniform4f(handle,
|
||||
// c1[0] * (1 - mix) + c2[0] * mix,
|
||||
// c1[1] * (1 - mix) + c2[1] * mix,
|
||||
// c1[2] * (1 - mix) + c2[2] * mix,
|
||||
// c1[3] * (1 - mix) + c2[3] * mix);
|
||||
// }
|
||||
// }
|
||||
|
||||
public static void setColor(int handle, float[] c, float alpha) {
|
||||
if (alpha >= 1) {
|
||||
GLES20.glUniform4f(handle, c[0], c[1], c[2], c[3]);
|
||||
GL.glUniform4f(handle, c[0], c[1], c[2], c[3]);
|
||||
} else {
|
||||
if (alpha < 0) {
|
||||
Log.d(TAG, "setColor: " + alpha);
|
||||
alpha = 0;
|
||||
GLES20.glUniform4f(handle, 0, 0, 0, 0);
|
||||
GL.glUniform4f(handle, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
GLES20.glUniform4f(handle,
|
||||
GL.glUniform4f(handle,
|
||||
c[0] * alpha, c[1] * alpha,
|
||||
c[2] * alpha, c[3] * alpha);
|
||||
}
|
||||
@ -277,6 +283,40 @@ public class GlUtils {
|
||||
color[2] = FastMath.clampN((float) (p + (b - p) * change));
|
||||
}
|
||||
|
||||
|
||||
public static void glUniform4fv(int location, int count, float[] val) {
|
||||
FloatBuffer buf = GLRenderer.getFloatBuffer(count * 4);
|
||||
buf.put(val);
|
||||
buf.flip();
|
||||
GL.glUniform4fv(location, count, buf);
|
||||
}
|
||||
|
||||
public static int[] glGenBuffers(int num) {
|
||||
IntBuffer buf = GLRenderer.getIntBuffer(num);
|
||||
GL.glGenBuffers(num, buf);
|
||||
int[] ret = new int[num];
|
||||
buf.get(ret);
|
||||
return ret;
|
||||
}
|
||||
public static void glDeleteBuffers(int num, int[] ids) {
|
||||
IntBuffer buf = GLRenderer.getIntBuffer(num);
|
||||
buf.put(ids, 0, num);
|
||||
GL.glDeleteBuffers(num, buf);
|
||||
}
|
||||
|
||||
public static int[] glGenTextures(int num) {
|
||||
IntBuffer buf = GLRenderer.getIntBuffer(num);
|
||||
GL.glGenTextures(num, buf);
|
||||
int[] ret = new int[num];
|
||||
buf.get(ret);
|
||||
return ret;
|
||||
}
|
||||
public static void glDeleteTextures(int num, int[] ids) {
|
||||
IntBuffer buf = GLRenderer.getIntBuffer(num);
|
||||
buf.put(ids, 0, num);
|
||||
GL.glDeleteTextures(num, buf);
|
||||
}
|
||||
|
||||
// private final static float[] mIdentity = {
|
||||
// 1, 0, 0, 0,
|
||||
// 0, 1, 0, 0,
|
||||
|
@ -18,10 +18,14 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
|
||||
|
||||
public class Matrix4 {
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
|
||||
static {
|
||||
System.loadLibrary("glutils");
|
||||
}
|
||||
@ -217,7 +221,7 @@ public class Matrix4 {
|
||||
* @param location GL location id
|
||||
*/
|
||||
public void setAsUniform(int location) {
|
||||
GLES20.glUniformMatrix4fv(location, 1, false, buffer);
|
||||
GL.glUniformMatrix4fv(location, 1, false, buffer);
|
||||
//setAsUniform(pointer, location);
|
||||
}
|
||||
|
||||
@ -252,4 +256,204 @@ public class Matrix4 {
|
||||
if (pointer != 0)
|
||||
delete(pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define a projection matrix in terms of six clip planes
|
||||
* @param m the float array that holds the perspective matrix
|
||||
* @param offset the offset into float array m where the perspective
|
||||
* matrix data is written
|
||||
*/
|
||||
public static void frustumM(float[] m, int offset,
|
||||
float left, float right, float bottom, float top,
|
||||
float near, float far) {
|
||||
if (left == right) {
|
||||
throw new IllegalArgumentException("left == right");
|
||||
}
|
||||
if (top == bottom) {
|
||||
throw new IllegalArgumentException("top == bottom");
|
||||
}
|
||||
if (near == far) {
|
||||
throw new IllegalArgumentException("near == far");
|
||||
}
|
||||
if (near <= 0.0f) {
|
||||
throw new IllegalArgumentException("near <= 0.0f");
|
||||
}
|
||||
if (far <= 0.0f) {
|
||||
throw new IllegalArgumentException("far <= 0.0f");
|
||||
}
|
||||
final float r_width = 1.0f / (right - left);
|
||||
final float r_height = 1.0f / (top - bottom);
|
||||
final float r_depth = 1.0f / (near - far);
|
||||
final float x = 2.0f * (near * r_width);
|
||||
final float y = 2.0f * (near * r_height);
|
||||
final float A = (right + left) * r_width;
|
||||
final float B = (top + bottom) * r_height;
|
||||
final float C = (far + near) * r_depth;
|
||||
final float D = 2.0f * (far * near * r_depth);
|
||||
m[offset + 0] = x;
|
||||
m[offset + 5] = y;
|
||||
m[offset + 8] = A;
|
||||
m[offset + 9] = B;
|
||||
m[offset + 10] = C;
|
||||
m[offset + 14] = D;
|
||||
m[offset + 11] = -1.0f;
|
||||
m[offset + 1] = 0.0f;
|
||||
m[offset + 2] = 0.0f;
|
||||
m[offset + 3] = 0.0f;
|
||||
m[offset + 4] = 0.0f;
|
||||
m[offset + 6] = 0.0f;
|
||||
m[offset + 7] = 0.0f;
|
||||
m[offset + 12] = 0.0f;
|
||||
m[offset + 13] = 0.0f;
|
||||
m[offset + 15] = 0.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverts a 4 x 4 matrix.
|
||||
*
|
||||
* @param mInv the array that holds the output inverted matrix
|
||||
* @param mInvOffset an offset into mInv where the inverted matrix is
|
||||
* stored.
|
||||
* @param m the input array
|
||||
* @param mOffset an offset into m where the matrix is stored.
|
||||
* @return true if the matrix could be inverted, false if it could not.
|
||||
*/
|
||||
public static boolean invertM(float[] mInv, int mInvOffset, float[] m,
|
||||
int mOffset) {
|
||||
// Invert a 4 x 4 matrix using Cramer's Rule
|
||||
|
||||
// transpose matrix
|
||||
final float src0 = m[mOffset + 0];
|
||||
final float src4 = m[mOffset + 1];
|
||||
final float src8 = m[mOffset + 2];
|
||||
final float src12 = m[mOffset + 3];
|
||||
|
||||
final float src1 = m[mOffset + 4];
|
||||
final float src5 = m[mOffset + 5];
|
||||
final float src9 = m[mOffset + 6];
|
||||
final float src13 = m[mOffset + 7];
|
||||
|
||||
final float src2 = m[mOffset + 8];
|
||||
final float src6 = m[mOffset + 9];
|
||||
final float src10 = m[mOffset + 10];
|
||||
final float src14 = m[mOffset + 11];
|
||||
|
||||
final float src3 = m[mOffset + 12];
|
||||
final float src7 = m[mOffset + 13];
|
||||
final float src11 = m[mOffset + 14];
|
||||
final float src15 = m[mOffset + 15];
|
||||
|
||||
// calculate pairs for first 8 elements (cofactors)
|
||||
final float atmp0 = src10 * src15;
|
||||
final float atmp1 = src11 * src14;
|
||||
final float atmp2 = src9 * src15;
|
||||
final float atmp3 = src11 * src13;
|
||||
final float atmp4 = src9 * src14;
|
||||
final float atmp5 = src10 * src13;
|
||||
final float atmp6 = src8 * src15;
|
||||
final float atmp7 = src11 * src12;
|
||||
final float atmp8 = src8 * src14;
|
||||
final float atmp9 = src10 * src12;
|
||||
final float atmp10 = src8 * src13;
|
||||
final float atmp11 = src9 * src12;
|
||||
|
||||
// calculate first 8 elements (cofactors)
|
||||
final float dst0 = (atmp0 * src5 + atmp3 * src6 + atmp4 * src7)
|
||||
- (atmp1 * src5 + atmp2 * src6 + atmp5 * src7);
|
||||
final float dst1 = (atmp1 * src4 + atmp6 * src6 + atmp9 * src7)
|
||||
- (atmp0 * src4 + atmp7 * src6 + atmp8 * src7);
|
||||
final float dst2 = (atmp2 * src4 + atmp7 * src5 + atmp10 * src7)
|
||||
- (atmp3 * src4 + atmp6 * src5 + atmp11 * src7);
|
||||
final float dst3 = (atmp5 * src4 + atmp8 * src5 + atmp11 * src6)
|
||||
- (atmp4 * src4 + atmp9 * src5 + atmp10 * src6);
|
||||
final float dst4 = (atmp1 * src1 + atmp2 * src2 + atmp5 * src3)
|
||||
- (atmp0 * src1 + atmp3 * src2 + atmp4 * src3);
|
||||
final float dst5 = (atmp0 * src0 + atmp7 * src2 + atmp8 * src3)
|
||||
- (atmp1 * src0 + atmp6 * src2 + atmp9 * src3);
|
||||
final float dst6 = (atmp3 * src0 + atmp6 * src1 + atmp11 * src3)
|
||||
- (atmp2 * src0 + atmp7 * src1 + atmp10 * src3);
|
||||
final float dst7 = (atmp4 * src0 + atmp9 * src1 + atmp10 * src2)
|
||||
- (atmp5 * src0 + atmp8 * src1 + atmp11 * src2);
|
||||
|
||||
// calculate pairs for second 8 elements (cofactors)
|
||||
final float btmp0 = src2 * src7;
|
||||
final float btmp1 = src3 * src6;
|
||||
final float btmp2 = src1 * src7;
|
||||
final float btmp3 = src3 * src5;
|
||||
final float btmp4 = src1 * src6;
|
||||
final float btmp5 = src2 * src5;
|
||||
final float btmp6 = src0 * src7;
|
||||
final float btmp7 = src3 * src4;
|
||||
final float btmp8 = src0 * src6;
|
||||
final float btmp9 = src2 * src4;
|
||||
final float btmp10 = src0 * src5;
|
||||
final float btmp11 = src1 * src4;
|
||||
|
||||
// calculate second 8 elements (cofactors)
|
||||
final float dst8 = (btmp0 * src13 + btmp3 * src14 + btmp4 * src15)
|
||||
- (btmp1 * src13 + btmp2 * src14 + btmp5 * src15);
|
||||
final float dst9 = (btmp1 * src12 + btmp6 * src14 + btmp9 * src15)
|
||||
- (btmp0 * src12 + btmp7 * src14 + btmp8 * src15);
|
||||
final float dst10 = (btmp2 * src12 + btmp7 * src13 + btmp10 * src15)
|
||||
- (btmp3 * src12 + btmp6 * src13 + btmp11 * src15);
|
||||
final float dst11 = (btmp5 * src12 + btmp8 * src13 + btmp11 * src14)
|
||||
- (btmp4 * src12 + btmp9 * src13 + btmp10 * src14);
|
||||
final float dst12 = (btmp2 * src10 + btmp5 * src11 + btmp1 * src9 )
|
||||
- (btmp4 * src11 + btmp0 * src9 + btmp3 * src10);
|
||||
final float dst13 = (btmp8 * src11 + btmp0 * src8 + btmp7 * src10)
|
||||
- (btmp6 * src10 + btmp9 * src11 + btmp1 * src8 );
|
||||
final float dst14 = (btmp6 * src9 + btmp11 * src11 + btmp3 * src8 )
|
||||
- (btmp10 * src11 + btmp2 * src8 + btmp7 * src9 );
|
||||
final float dst15 = (btmp10 * src10 + btmp4 * src8 + btmp9 * src9 )
|
||||
- (btmp8 * src9 + btmp11 * src10 + btmp5 * src8 );
|
||||
|
||||
// calculate determinant
|
||||
final float det =
|
||||
src0 * dst0 + src1 * dst1 + src2 * dst2 + src3 * dst3;
|
||||
|
||||
if (det == 0.0f) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// calculate matrix inverse
|
||||
final float invdet = 1.0f / det;
|
||||
mInv[ mInvOffset] = dst0 * invdet;
|
||||
mInv[ 1 + mInvOffset] = dst1 * invdet;
|
||||
mInv[ 2 + mInvOffset] = dst2 * invdet;
|
||||
mInv[ 3 + mInvOffset] = dst3 * invdet;
|
||||
|
||||
mInv[ 4 + mInvOffset] = dst4 * invdet;
|
||||
mInv[ 5 + mInvOffset] = dst5 * invdet;
|
||||
mInv[ 6 + mInvOffset] = dst6 * invdet;
|
||||
mInv[ 7 + mInvOffset] = dst7 * invdet;
|
||||
|
||||
mInv[ 8 + mInvOffset] = dst8 * invdet;
|
||||
mInv[ 9 + mInvOffset] = dst9 * invdet;
|
||||
mInv[10 + mInvOffset] = dst10 * invdet;
|
||||
mInv[11 + mInvOffset] = dst11 * invdet;
|
||||
|
||||
mInv[12 + mInvOffset] = dst12 * invdet;
|
||||
mInv[13 + mInvOffset] = dst13 * invdet;
|
||||
mInv[14 + mInvOffset] = dst14 * invdet;
|
||||
mInv[15 + mInvOffset] = dst15 * invdet;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
|
||||
import org.openstreetmap.osmosis.osmbinary.BinaryParser;
|
||||
import org.openstreetmap.osmosis.osmbinary.Osmformat;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.core.TagSet;
|
||||
import org.oscim.utils.osm.OSMData;
|
||||
@ -15,7 +16,6 @@ import org.oscim.utils.osm.OSMNode;
|
||||
import org.oscim.utils.osm.OSMRelation;
|
||||
import org.oscim.utils.osm.OSMWay;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
|
||||
|
@ -175,7 +175,6 @@ public class LayerManager extends AbstractList<Layer>
|
||||
//
|
||||
// mCancelGesture = false;
|
||||
// }
|
||||
Log.d(TAG, "motionEvent");
|
||||
|
||||
if (onTouchEvent(e))
|
||||
return true;
|
||||
|
@ -31,8 +31,7 @@ import org.oscim.tilesource.TileSource;
|
||||
|
||||
public class MapView {
|
||||
|
||||
public static int dpi;
|
||||
public static boolean enableClosePolygons;
|
||||
//public static boolean enableClosePolygons;
|
||||
private final LayerManager mLayerManager;
|
||||
private final MapViewPosition mMapViewPosition;
|
||||
private final MapPosition mMapPosition;
|
||||
|
@ -26,8 +26,6 @@ import org.oscim.core.Tile;
|
||||
import org.oscim.utils.FastMath;
|
||||
import org.oscim.utils.Matrix4;
|
||||
|
||||
import android.opengl.Matrix;
|
||||
|
||||
|
||||
public class MapViewPosition {
|
||||
private static final String TAG = MapViewPosition.class.getName();
|
||||
@ -109,7 +107,7 @@ public class MapViewPosition {
|
||||
float aspect = height / (float) width;
|
||||
float[] tmp = new float[16];
|
||||
|
||||
Matrix.frustumM(tmp, 0, -s, s,
|
||||
Matrix4.frustumM(tmp, 0, -s, s,
|
||||
aspect * s, -aspect * s, VIEW_NEAR, VIEW_FAR);
|
||||
|
||||
mProjMatrix.set(tmp);
|
||||
@ -117,7 +115,7 @@ public class MapViewPosition {
|
||||
mProjMatrix.multiplyRhs(mTmpMatrix);
|
||||
mProjMatrix.get(tmp);
|
||||
|
||||
Matrix.invertM(tmp, 0, tmp, 0);
|
||||
Matrix4.invertM(tmp, 0, tmp, 0);
|
||||
mProjMatrixI.set(tmp);
|
||||
|
||||
mHeight = height;
|
||||
|
Loading…
x
Reference in New Issue
Block a user