- rotate multiple bitmaps to draw and upload textures
This commit is contained in:
parent
9efe46e3ba
commit
98246fe50b
@ -662,8 +662,6 @@ public class MapRenderer extends GLSurfaceView {
|
||||
public synchronized boolean passTile(JobTile jobTile) {
|
||||
MapTile tile = (MapTile) jobTile;
|
||||
|
||||
// XXX this is concurrent with updateVisiblelist which set loading false
|
||||
// temporarily
|
||||
// if (!tile.isLoading) {
|
||||
// // no one should be able to use this tile now, TileGenerator passed
|
||||
// // it, GL-Thread does nothing until newdata is set.
|
||||
|
@ -27,8 +27,8 @@ public class TextureObject {
|
||||
// shared bitmap and canvas for default texture size
|
||||
public final static int TEXTURE_WIDTH = 256;
|
||||
public final static int TEXTURE_HEIGHT = 256;
|
||||
private static Bitmap mBitmap;
|
||||
private static Canvas mCanvas;
|
||||
private static Bitmap[] mBitmap;
|
||||
private static Canvas[] mCanvas;
|
||||
private static int mBitmapFormat;
|
||||
private static int mBitmapType;
|
||||
private static int objectCount = 10;
|
||||
@ -64,7 +64,7 @@ public class TextureObject {
|
||||
int format, int type, int w, int h) {
|
||||
|
||||
if (to == null) {
|
||||
Log.d("...", "no fckn texture!");
|
||||
Log.d("...", "no texture!");
|
||||
return;
|
||||
}
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, to.id);
|
||||
@ -100,22 +100,31 @@ public class TextureObject {
|
||||
pool = to;
|
||||
}
|
||||
|
||||
mBitmap = Bitmap.createBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT,
|
||||
mBitmap = new Bitmap[4];
|
||||
mCanvas = new Canvas[4];
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
mBitmap[i] = Bitmap.createBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT,
|
||||
Bitmap.Config.ARGB_8888);
|
||||
mCanvas = new Canvas(mBitmap);
|
||||
mBitmapFormat = GLUtils.getInternalFormat(mBitmap);
|
||||
mBitmapType = GLUtils.getType(mBitmap);
|
||||
mCanvas[i] = new Canvas(mBitmap[i]);
|
||||
}
|
||||
mBitmapFormat = GLUtils.getInternalFormat(mBitmap[0]);
|
||||
mBitmapType = GLUtils.getType(mBitmap[0]);
|
||||
}
|
||||
|
||||
public static Canvas getCanvas() {
|
||||
mBitmap.eraseColor(Color.TRANSPARENT);
|
||||
private static int curCanvas = 0;
|
||||
|
||||
return mCanvas;
|
||||
public static Canvas getCanvas() {
|
||||
curCanvas = ++curCanvas % 4;
|
||||
|
||||
mBitmap[curCanvas].eraseColor(Color.TRANSPARENT);
|
||||
|
||||
return mCanvas[curCanvas];
|
||||
}
|
||||
|
||||
public static TextureObject uploadCanvas(short offset, short indices) {
|
||||
TextureObject to = get();
|
||||
uploadTexture(to, mBitmap,
|
||||
uploadTexture(to, mBitmap[curCanvas],
|
||||
mBitmapFormat, mBitmapType,
|
||||
TEXTURE_WIDTH, TEXTURE_HEIGHT);
|
||||
|
||||
|
@ -89,7 +89,7 @@ public class TextureRenderer {
|
||||
|
||||
static Layer draw(Layer layer, float scale, float[] projection,
|
||||
float matrix[], int offset) {
|
||||
|
||||
GlUtils.checkGlError("draw texture0");
|
||||
GLES20.glUseProgram(mTextureProgram);
|
||||
GlUtils.checkGlError("draw texture1");
|
||||
|
||||
|
@ -21,10 +21,11 @@ import org.oscim.renderer.TextureRenderer;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.util.FloatMath;
|
||||
import android.util.Log;
|
||||
|
||||
public final class TextLayer extends TextureLayer {
|
||||
|
||||
private static String TAG = SymbolLayer.class.getSimpleName();
|
||||
private static String TAG = TextureLayer.class.getSimpleName();
|
||||
|
||||
private final static int TEXTURE_WIDTH = TextureObject.TEXTURE_WIDTH;
|
||||
private final static int TEXTURE_HEIGHT = TextureObject.TEXTURE_HEIGHT;
|
||||
@ -64,8 +65,8 @@ public final class TextLayer extends TextureLayer {
|
||||
|
||||
@Override
|
||||
public void compile(ShortBuffer sbuf) {
|
||||
// int numLabel = 0;
|
||||
|
||||
int numLabel = 0;
|
||||
int numTextures = 0;
|
||||
short numIndices = 0;
|
||||
short offsetIndices = 0;
|
||||
|
||||
@ -80,7 +81,7 @@ public final class TextLayer extends TextureLayer {
|
||||
|
||||
Canvas canvas = TextureObject.getCanvas();
|
||||
for (TextItem it = labels; it != null; it = it.next) {
|
||||
// numLabel++;
|
||||
numLabel++;
|
||||
|
||||
float width = it.width + 2 * mFontPadX;
|
||||
float height = (int) (it.text.fontHeight) + 2 * mFontPadY + 0.5f;
|
||||
@ -94,7 +95,9 @@ public final class TextLayer extends TextureLayer {
|
||||
advanceY = (int) (height + 0.5f);
|
||||
|
||||
if (y + height > TEXTURE_HEIGHT) {
|
||||
// Log.d(TAG, "reached max labels " + numLabel);
|
||||
// Log.d(TAG, "reached max labels " + numTextures + " " +
|
||||
// numLabel + " "
|
||||
// + ((numIndices - offsetIndices) / 6));
|
||||
|
||||
// need to sync bitmap upload somehow???
|
||||
TextureObject to = TextureObject.uploadCanvas(offsetIndices, numIndices);
|
||||
@ -113,6 +116,7 @@ public final class TextLayer extends TextureLayer {
|
||||
// clear bitmap, TODO rotate two canvas to reduce the chance
|
||||
// of having upload lock draing to the canvas?
|
||||
canvas = TextureObject.getCanvas();
|
||||
numTextures++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,11 +210,12 @@ public final class TextLayer extends TextureLayer {
|
||||
// FIXME this does not work, need to draw bitmap on next
|
||||
// texture...
|
||||
if (pos == bufLen) {
|
||||
Log.d(TAG, "--- reached max label per texture " + numLabel);
|
||||
sbuf.put(buf, 0, pos);
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
x += width + 1;
|
||||
x += width;
|
||||
}
|
||||
|
||||
TextureObject to = TextureObject.uploadCanvas(offsetIndices, numIndices);
|
||||
@ -220,7 +225,7 @@ public final class TextLayer extends TextureLayer {
|
||||
|
||||
sbuf.put(buf, 0, pos);
|
||||
|
||||
// Log.d(TAG, "added labels " + numLabel);
|
||||
Log.d(TAG, "added labels " + numTextures + " " + numLabel);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user