- use mediump shader for textures

- increase TextureItem width, so that 'USA' label is drawn completely on high dpi.. at least for now
This commit is contained in:
Hannes Janetzek 2013-04-12 05:16:53 +02:00
parent 47ad1d3617
commit 50b37d2342
3 changed files with 36 additions and 28 deletions

View File

@ -15,10 +15,14 @@
package org.oscim.renderer;
import static org.oscim.renderer.GLRenderer.COORD_SCALE;
import static org.oscim.renderer.layer.TextureItem.TEXTURE_HEIGHT;
import static org.oscim.renderer.layer.TextureItem.TEXTURE_WIDTH;
import org.oscim.renderer.GLRenderer.Matrices;
import org.oscim.renderer.layer.Layer;
import org.oscim.renderer.layer.TextureLayer;
import org.oscim.renderer.layer.TextureItem;
import org.oscim.renderer.layer.TextureLayer;
import org.oscim.utils.GlUtils;
import android.opengl.GLES20;
@ -105,8 +109,12 @@ public final class TextureRenderer {
return layer.next;
}
private final static double TEX_COORD_DIV_X = 1.0 / (TEXTURE_WIDTH * COORD_SCALE);
private final static double TEX_COORD_DIV_Y = 1.0 / (TEXTURE_HEIGHT * COORD_SCALE);
private final static double COORD_DIV = 1.0 / GLRenderer.COORD_SCALE;
private final static String textVertexShader = ""
+ "precision highp float; "
+ "precision mediump float; "
+ "attribute vec4 vertex;"
+ "attribute vec2 tex_coord;"
+ "uniform mat4 u_mv;"
@ -114,8 +122,8 @@ public final class TextureRenderer {
+ "uniform float u_scale;"
+ "uniform float u_swidth;"
+ "varying vec2 tex_c;"
+ "const vec2 div = vec2(1.0/2048.0,1.0/2048.0);"
+ "const float coord_scale = 0.125;"
+ "const vec2 div = vec2(" + TEX_COORD_DIV_X + "," + TEX_COORD_DIV_Y + ");"
+ "const float coord_scale = " + COORD_DIV + ";"
+ "void main() {"
+ " vec4 pos;"
+ " vec2 dir = vertex.zw;"
@ -130,7 +138,7 @@ public final class TextureRenderer {
+ "}";
private final static String textFragmentShader = ""
+ "precision highp float;"
+ "precision mediump float;"
+ "uniform sampler2D tex;"
+ "varying vec2 tex_c;"
+ "void main() {"

View File

@ -14,17 +14,17 @@
*/
package org.oscim.renderer.layer;
import static org.oscim.renderer.GLRenderer.COORD_SCALE;
import static org.oscim.renderer.layer.TextureItem.TEXTURE_HEIGHT;
import static org.oscim.renderer.layer.TextureItem.TEXTURE_WIDTH;
import org.oscim.renderer.TextureRenderer;
import android.graphics.Canvas;
public final class TextLayer extends TextureLayer {
//private static String TAG = TextureLayer.class.getName();
private final static int TEXTURE_WIDTH = TextureItem.TEXTURE_WIDTH;
private final static int TEXTURE_HEIGHT = TextureItem.TEXTURE_HEIGHT;
private final static float SCALE = 8.0f;
private final static int LBIT_MASK = 0xfffffffe;
private static int mFontPadX = 1;
@ -151,10 +151,10 @@ public final class TextLayer extends TextureLayer {
//}
// texture coordinates
short u1 = (short) (SCALE * x);
short v1 = (short) (SCALE * y);
short u2 = (short) (SCALE * (x + width));
short v2 = (short) (SCALE * (y + height));
short u1 = (short) (COORD_SCALE * x);
short v1 = (short) (COORD_SCALE * y);
short u2 = (short) (COORD_SCALE * (x + width));
short v2 = (short) (COORD_SCALE * (y + height));
while (it != null) {
@ -162,10 +162,10 @@ public final class TextLayer extends TextureLayer {
if (it.text.caption) {
//if (it.origin == 0) {
x1 = x3 = (short) (SCALE * -hw);
x2 = x4 = (short) (SCALE * hw);
y1 = y2 = (short) (SCALE * hh);
y3 = y4 = (short) (SCALE * -hh);
x1 = x3 = (short) (COORD_SCALE * -hw);
x2 = x4 = (short) (COORD_SCALE * hw);
y1 = y2 = (short) (COORD_SCALE * hh);
y3 = y4 = (short) (COORD_SCALE * -hh);
//} else {
// x1 = x3 = (short) (SCALE * 0);
// x2 = x4 = (short) (SCALE * width);
@ -189,23 +189,23 @@ public final class TextLayer extends TextureLayer {
vy *= hw;
// top-left
x1 = (short) (SCALE * (vx - ux));
y1 = (short) (SCALE * (vy - uy));
x1 = (short) (COORD_SCALE * (vx - ux));
y1 = (short) (COORD_SCALE * (vy - uy));
// top-right
x2 = (short) (SCALE * (-vx - ux));
y2 = (short) (SCALE * (-vy - uy));
x2 = (short) (COORD_SCALE * (-vx - ux));
y2 = (short) (COORD_SCALE * (-vy - uy));
// bot-right
x4 = (short) (SCALE * (-vx + ux2));
y4 = (short) (SCALE * (-vy + uy2));
x4 = (short) (COORD_SCALE * (-vx + ux2));
y4 = (short) (COORD_SCALE * (-vy + uy2));
// bot-left
x3 = (short) (SCALE * (vx + ux2));
y3 = (short) (SCALE * (vy + uy2));
x3 = (short) (COORD_SCALE * (vx + ux2));
y3 = (short) (COORD_SCALE * (vy + uy2));
}
// add vertices
int tmp = (int) (SCALE * it.x) & LBIT_MASK;
int tmp = (int) (COORD_SCALE * it.x) & LBIT_MASK;
short tx = (short) (tmp | (it.text.caption ? 1 : 0));
short ty = (short) (SCALE * it.y);
short ty = (short) (COORD_SCALE * it.y);
if (pos == VertexItem.SIZE) {
vi.used = VertexItem.SIZE;

View File

@ -90,7 +90,7 @@ public class TextureItem extends Inlist<TextureItem> {
private static ArrayList<Bitmap> mBitmaps;
public final static int TEXTURE_WIDTH = 256;
public final static int TEXTURE_WIDTH = 512;
public final static int TEXTURE_HEIGHT = 256;
private static int mBitmapFormat;