use of org.anddev.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource in project AndEngine by nicolasgramlich.
the class BitmapTextureAtlas method writeTextureToHardware.
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
// ===========================================================
// Methods
// ===========================================================
@Override
protected void writeTextureToHardware(final GL10 pGL) {
final Config bitmapConfig = this.mBitmapTextureFormat.getBitmapConfig();
final int glFormat = this.mPixelFormat.getGLFormat();
final int glType = this.mPixelFormat.getGLType();
final boolean preMultipyAlpha = this.mTextureOptions.mPreMultipyAlpha;
final ArrayList<IBitmapTextureAtlasSource> textureSources = this.mTextureAtlasSources;
final int textureSourceCount = textureSources.size();
for (int j = 0; j < textureSourceCount; j++) {
final IBitmapTextureAtlasSource bitmapTextureAtlasSource = textureSources.get(j);
if (bitmapTextureAtlasSource != null) {
final Bitmap bitmap = bitmapTextureAtlasSource.onLoadBitmap(bitmapConfig);
try {
if (bitmap == null) {
throw new IllegalArgumentException(bitmapTextureAtlasSource.getClass().getSimpleName() + ": " + bitmapTextureAtlasSource.toString() + " returned a null Bitmap.");
}
if (preMultipyAlpha) {
GLUtils.texSubImage2D(GL10.GL_TEXTURE_2D, 0, bitmapTextureAtlasSource.getTexturePositionX(), bitmapTextureAtlasSource.getTexturePositionY(), bitmap, glFormat, glType);
} else {
GLHelper.glTexSubImage2D(pGL, GL10.GL_TEXTURE_2D, 0, bitmapTextureAtlasSource.getTexturePositionX(), bitmapTextureAtlasSource.getTexturePositionY(), bitmap, this.mPixelFormat);
}
bitmap.recycle();
} catch (final IllegalArgumentException iae) {
// TODO Load some static checkerboard or so to visualize that loading the texture has failed.
// private Buffer createImage(final int width, final int height) {
// final int stride = 3 * width;
// final ByteBuffer image = ByteBuffer.allocateDirect(height * stride)
// .order(ByteOrder.nativeOrder());
//
// // Fill with a pretty "munching squares" pattern:
// for (int t = 0; t < height; t++) {
// final byte red = (byte) (255 - 2 * t);
// final byte green = (byte) (2 * t);
// final byte blue = 0;
// for (int x = 0; x < width; x++) {
// final int y = x ^ t;
// image.position(stride * y + x * 3);
// image.put(red);
// image.put(green);
// image.put(blue);
// }
// }
// image.position(0);
// return image;
// }
Debug.e("Error loading: " + bitmapTextureAtlasSource.toString(), iae);
if (this.getTextureStateListener() != null) {
this.getTextureStateListener().onTextureAtlasSourceLoadExeption(this, bitmapTextureAtlasSource, iae);
} else {
throw iae;
}
}
}
}
}
Aggregations