check size > 0 before deleting texture IDs
- formatting...
This commit is contained in:
parent
52b2fadd7d
commit
0b4aff79c9
@ -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();
|
||||||
@ -114,11 +115,11 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void clearItem(TextureItem it) {
|
protected void clearItem(TextureItem it) {
|
||||||
//Log.d(TAG, it.ownBitmap + " " + (it.bitmap == null));
|
// Log.d(TAG, it.ownBitmap + " " + (it.bitmap == null));
|
||||||
if (it.ownBitmap)
|
if (it.ownBitmap)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (it.isClone){
|
if (it.isClone) {
|
||||||
it.isClone = false;
|
it.isClone = false;
|
||||||
it.id = -1;
|
it.id = -1;
|
||||||
it.width = -1;
|
it.width = -1;
|
||||||
@ -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,13 +181,14 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
|
|
||||||
mTexCnt -= size;
|
mTexCnt -= size;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (to.id < 0) {
|
if (to.id < 0) {
|
||||||
mTexCnt++;
|
mTexCnt++;
|
||||||
int[] textureIds = GlUtils.glGenTextures(1);
|
int[] textureIds = GlUtils.glGenTextures(1);
|
||||||
to.id = textureIds[0];
|
to.id = textureIds[0];
|
||||||
initTexture(to.id);
|
initTexture(to.id);
|
||||||
//if (TextureRenderer.debug)
|
// if (TextureRenderer.debug)
|
||||||
Log.d(TAG, "poolCnt:" + pool.getCount() + " poolFill:" + pool.getFill()
|
Log.d(TAG, "poolCnt:" + pool.getCount() + " poolFill:" + pool.getFill()
|
||||||
+ " texCnt:" + mTexCnt + " new texture " + to.id);
|
+ " texCnt:" + mTexCnt + " new texture " + to.id);
|
||||||
}
|
}
|
||||||
@ -196,7 +200,7 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
TextureItem.releaseBitmap(to);
|
TextureItem.releaseBitmap(to);
|
||||||
else {
|
else {
|
||||||
// FIXME when in doubt
|
// 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);
|
Log.d(TAG, "upload " + to.id);
|
||||||
if (to.ownBitmap) {
|
if (to.ownBitmap) {
|
||||||
bitmap.uploadToTexture(false);
|
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) {
|
} 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;
|
||||||
}
|
}
|
||||||
@ -250,14 +256,14 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
Bitmap bitmap = CanvasAdapter.g.getBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT, 0);
|
Bitmap bitmap = CanvasAdapter.g.getBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT, 0);
|
||||||
//Bitmap bitmap = Bitmap.createBitmap(
|
// Bitmap bitmap = Bitmap.createBitmap(
|
||||||
// TEXTURE_WIDTH, TEXTURE_HEIGHT,
|
// TEXTURE_WIDTH, TEXTURE_HEIGHT,
|
||||||
// Bitmap.Config.ARGB_8888);
|
// Bitmap.Config.ARGB_8888);
|
||||||
mBitmaps.add(bitmap);
|
mBitmaps.add(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
//mBitmapFormat = GLUtils.getInternalFormat(mBitmaps.get(0));
|
// mBitmapFormat = GLUtils.getInternalFormat(mBitmaps.get(0));
|
||||||
//mBitmapType = GLUtils.getType(mBitmaps.get(0));
|
// mBitmapType = GLUtils.getType(mBitmaps.get(0));
|
||||||
|
|
||||||
mTexCnt = num;
|
mTexCnt = num;
|
||||||
}
|
}
|
||||||
@ -267,13 +273,14 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
|
|
||||||
int size = mBitmaps.size();
|
int size = mBitmaps.size();
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
//Bitmap bitmap = Bitmap.createBitmap(
|
// Bitmap bitmap = Bitmap.createBitmap(
|
||||||
// TEXTURE_WIDTH, TEXTURE_HEIGHT,
|
// TEXTURE_WIDTH, TEXTURE_HEIGHT,
|
||||||
// Bitmap.Config.ARGB_8888);
|
// Bitmap.Config.ARGB_8888);
|
||||||
//
|
//
|
||||||
//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);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user