cleanup: TextureItem

This commit is contained in:
Hannes Janetzek 2014-01-21 04:41:54 +01:00
parent ec69fc7a68
commit f2e1b33db5

View File

@ -29,7 +29,6 @@ import org.oscim.utils.pool.SyncPool;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
// FIXME needs rewrite!
// TODO use separate pools for different bitmap types and dimensions // TODO use separate pools for different bitmap types and dimensions
public class TextureItem extends Inlist<TextureItem> { public class TextureItem extends Inlist<TextureItem> {
@ -198,8 +197,8 @@ public class TextureItem extends Inlist<TextureItem> {
public final static int TEXTURE_WIDTH = 512; public final static int TEXTURE_WIDTH = 512;
public final static int TEXTURE_HEIGHT = 256; public final static int TEXTURE_HEIGHT = 256;
private static int mBitmapFormat; //private static int mBitmapFormat;
private static int mBitmapType; //private static int mBitmapType;
private static int mTexCnt = 0; private static int mTexCnt = 0;
static void releaseTexture(TextureItem it) { static void releaseTexture(TextureItem it) {
@ -250,42 +249,23 @@ public class TextureItem extends Inlist<TextureItem> {
+ " new texture " + t.id); + " new texture " + t.id);
} }
//log.debug("UPLOAD ID: " + t.id);
uploadTexture(t, t.bitmap,
mBitmapFormat, mBitmapType,
TEXTURE_WIDTH, TEXTURE_HEIGHT);
if (!t.ownBitmap)
TextureItem.releaseBitmap(t);
else {
// FIXME when in doubt
// to.bitmap = null;
}
}
public static void uploadTexture(TextureItem t, Bitmap bitmap,
int format, int type, int w, int h) {
if (t == null) {
log.debug("no texture!");
return;
}
GLState.bindTex2D(t.id); GLState.bindTex2D(t.id);
if (t.ownBitmap) { if (t.ownBitmap) {
bitmap.uploadToTexture(false); t.bitmap.uploadToTexture(false);
} else if (t.width == w && t.height == h) { } else if (t.width == TEXTURE_WIDTH && t.height == TEXTURE_HEIGHT) {
bitmap.uploadToTexture(true); t.bitmap.uploadToTexture(true);
} else { } else {
bitmap.uploadToTexture(false); t.bitmap.uploadToTexture(false);
t.width = w; t.width = TEXTURE_WIDTH;
t.height = h; t.height = TEXTURE_HEIGHT;
} }
if (TextureLayer.Renderer.debug) if (TextureLayer.Renderer.debug)
GLUtils.checkGlError(TextureItem.class.getName()); GLUtils.checkGlError(TextureItem.class.getName());
if (!t.ownBitmap)
TextureItem.releaseBitmap(t);
} }
private static void initTexture(TextureItem t) { private static void initTexture(TextureItem t) {
@ -312,45 +292,20 @@ public class TextureItem extends Inlist<TextureItem> {
static void init(GL20 gl, int num) { static void init(GL20 gl, int num) {
GL = gl; GL = gl;
log.debug("init textures " + num);
mTexCnt = num; mTexCnt = num;
pool.init(num); pool.init(num);
//mTexCnt = num;
mBitmaps.clear(); mBitmaps.clear();
mTextures.clear(); mTextures.clear();
// for (int i = 0; i < 4; i++) {
// Bitmap bitmap = CanvasAdapter.g.getBitmap(TEXTURE_WIDTH,
// TEXTURE_HEIGHT, 0);
// // Bitmap bitmap = Bitmap.createBitmap(
// // TEXTURE_WIDTH, TEXTURE_HEIGHT,
// // Bitmap.Config.ARGB_8888);
// mBitmaps.add(bitmap);
// }
// mBitmapFormat = GLUtils.getInternalFormat(mBitmaps.get(0));
// mBitmapType = GLUtils.getType(mBitmaps.get(0));
} }
static Bitmap getBitmap() { static Bitmap getBitmap() {
synchronized (mBitmaps) { synchronized (mBitmaps) {
int size = mBitmaps.size(); int size = mBitmaps.size();
if (size == 0) { if (size == 0) {
// Bitmap bitmap = Bitmap.createBitmap(
// TEXTURE_WIDTH, TEXTURE_HEIGHT,
// Bitmap.Config.ARGB_8888);
//
// if (TextureRenderer.debug)
// log.debug("alloc bitmap: " +
// android.os.Debug.getNativeHeapAllocatedSize() / (1024 *
// 1024));
return CanvasAdapter.g.getBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT, 0); return CanvasAdapter.g.getBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT, 0);
} }
return mBitmaps.remove(size - 1); return mBitmaps.remove(size - 1);
} }
} }