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