check size > 0 before deleting texture IDs

- formatting...
This commit is contained in:
Hannes Janetzek 2013-06-25 07:24:32 +02:00
parent 52b2fadd7d
commit 0b4aff79c9

View File

@ -13,6 +13,7 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.sublayers;
import java.util.ArrayList;
import org.oscim.backend.CanvasAdapter;
@ -76,8 +77,8 @@ public class TextureItem extends Inlist<TextureItem> {
}
/**
* Retrieve a TextureItem from pool with default Bitmap
* with dimension TextureRenderer.TEXTURE_WIDTH/HEIGHT.
* Retrieve a TextureItem from pool with default Bitmap with dimension
* TextureRenderer.TEXTURE_WIDTH/HEIGHT.
*/
public synchronized static TextureItem get(boolean initBitmap) {
TextureItem ti = pool.get();
@ -114,11 +115,11 @@ public class TextureItem extends Inlist<TextureItem> {
@Override
protected void clearItem(TextureItem it) {
//Log.d(TAG, it.ownBitmap + " " + (it.bitmap == null));
// Log.d(TAG, it.ownBitmap + " " + (it.bitmap == null));
if (it.ownBitmap)
return;
if (it.isClone){
if (it.isClone) {
it.isClone = false;
it.id = -1;
it.width = -1;
@ -162,13 +163,15 @@ public class TextureItem extends Inlist<TextureItem> {
/**
* This function may only be used in GLRenderer Thread.
*
* @param to the TextureObjet to compile and upload
* @param to
* the TextureObjet to compile and upload
*/
public static void uploadTexture(TextureItem to) {
// free unused textures, find a better place for this TODO
synchronized (mTextures) {
int size = mTextures.size();
if (size > 0) {
int[] tmp = new int[size];
for (int i = 0; i < size; i++)
tmp[i] = mTextures.get(i).intValue();
@ -178,13 +181,14 @@ public class TextureItem extends Inlist<TextureItem> {
mTexCnt -= size;
}
}
if (to.id < 0) {
mTexCnt++;
int[] textureIds = GlUtils.glGenTextures(1);
to.id = textureIds[0];
initTexture(to.id);
//if (TextureRenderer.debug)
// if (TextureRenderer.debug)
Log.d(TAG, "poolCnt:" + pool.getCount() + " poolFill:" + pool.getFill()
+ " texCnt:" + mTexCnt + " new texture " + to.id);
}
@ -196,7 +200,7 @@ public class TextureItem extends Inlist<TextureItem> {
TextureItem.releaseBitmap(to);
else {
// FIXME when in doubt
//to.bitmap = null;
// to.bitmap = null;
}
}
@ -212,15 +216,17 @@ public class TextureItem extends Inlist<TextureItem> {
Log.d(TAG, "upload " + to.id);
if (to.ownBitmap) {
bitmap.uploadToTexture(false);
//GLUtils.texImage2D(GL20.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(GL20.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(GL20.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;
}
@ -250,14 +256,14 @@ public class TextureItem extends Inlist<TextureItem> {
for (int i = 0; i < 4; i++) {
Bitmap bitmap = CanvasAdapter.g.getBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT, 0);
//Bitmap bitmap = Bitmap.createBitmap(
// 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));
// mBitmapFormat = GLUtils.getInternalFormat(mBitmaps.get(0));
// mBitmapType = GLUtils.getType(mBitmaps.get(0));
mTexCnt = num;
}
@ -267,13 +273,14 @@ public class TextureItem extends Inlist<TextureItem> {
int size = mBitmaps.size();
if (size == 0) {
//Bitmap bitmap = Bitmap.createBitmap(
// Bitmap bitmap = Bitmap.createBitmap(
// TEXTURE_WIDTH, TEXTURE_HEIGHT,
// Bitmap.Config.ARGB_8888);
//
//if (TextureRenderer.debug)
// if (TextureRenderer.debug)
// Log.d(TAG, "alloc bitmap: " +
// android.os.Debug.getNativeHeapAllocatedSize() / (1024 * 1024));
// android.os.Debug.getNativeHeapAllocatedSize() / (1024 *
// 1024));
return CanvasAdapter.g.getBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT, 0);
}