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/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.oscim.renderer.sublayers; package org.oscim.renderer.sublayers;
import java.util.ArrayList; import java.util.ArrayList;
import org.oscim.backend.CanvasAdapter; import org.oscim.backend.CanvasAdapter;
@ -76,8 +77,8 @@ public class TextureItem extends Inlist<TextureItem> {
} }
/** /**
* Retrieve a TextureItem from pool with default Bitmap * Retrieve a TextureItem from pool with default Bitmap with dimension
* with dimension TextureRenderer.TEXTURE_WIDTH/HEIGHT. * TextureRenderer.TEXTURE_WIDTH/HEIGHT.
*/ */
public synchronized static TextureItem get(boolean initBitmap) { public synchronized static TextureItem get(boolean initBitmap) {
TextureItem ti = pool.get(); TextureItem ti = pool.get();
@ -162,13 +163,15 @@ public class TextureItem extends Inlist<TextureItem> {
/** /**
* This function may only be used in GLRenderer Thread. * 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) { public static void uploadTexture(TextureItem to) {
// free unused textures, find a better place for this TODO // free unused textures, find a better place for this TODO
synchronized (mTextures) { synchronized (mTextures) {
int size = mTextures.size(); int size = mTextures.size();
if (size > 0) {
int[] tmp = new int[size]; int[] tmp = new int[size];
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
tmp[i] = mTextures.get(i).intValue(); tmp[i] = mTextures.get(i).intValue();
@ -178,6 +181,7 @@ public class TextureItem extends Inlist<TextureItem> {
mTexCnt -= size; mTexCnt -= size;
} }
}
if (to.id < 0) { if (to.id < 0) {
mTexCnt++; mTexCnt++;
@ -216,11 +220,13 @@ public class TextureItem extends Inlist<TextureItem> {
} else if (to.width == w && to.height == h) { } else if (to.width == w && to.height == h) {
bitmap.uploadToTexture(true); 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 { } else {
bitmap.uploadToTexture(false); 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.width = w;
to.height = h; to.height = h;
} }
@ -273,7 +279,8 @@ public class TextureItem extends Inlist<TextureItem> {
// //
// if (TextureRenderer.debug) // if (TextureRenderer.debug)
// Log.d(TAG, "alloc bitmap: " + // 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); return CanvasAdapter.g.getBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT, 0);
} }