use of org.andengine.opengl.texture.bitmap.BitmapTexture in project AndEngine by nicolasgramlich.
the class TexturePackParser method parseTexture.
private ITexture parseTexture(final Attributes pAttributes) throws TexturePackParseException {
final String file = SAXUtils.getAttributeOrThrow(pAttributes, TexturePackParser.TAG_TEXTURE_ATTRIBUTE_FILE);
if (this.mTextureManager.hasMappedTexture(file)) {
return this.mTextureManager.getMappedTexture(file);
}
final String type = SAXUtils.getAttributeOrThrow(pAttributes, TexturePackParser.TAG_TEXTURE_ATTRIBUTE_TYPE);
final PixelFormat pixelFormat = TexturePackParser.parsePixelFormat(pAttributes);
final TextureOptions textureOptions = this.parseTextureOptions(pAttributes);
final ITexture texture;
if (type.equals(TexturePackParser.TAG_TEXTURE_ATTRIBUTE_TYPE_VALUE_BITMAP)) {
try {
texture = new BitmapTexture(this.mTextureManager, new IInputStreamOpener() {
@Override
public InputStream open() throws IOException {
return TexturePackParser.this.onGetInputStream(file);
}
}, BitmapTextureFormat.fromPixelFormat(pixelFormat), textureOptions);
} catch (final IOException e) {
throw new TexturePackParseException(e);
}
} else if (type.equals(TexturePackParser.TAG_TEXTURE_ATTRIBUTE_TYPE_VALUE_PVR)) {
try {
texture = new PVRTexture(this.mTextureManager, PVRTextureFormat.fromPixelFormat(pixelFormat), new SmartPVRTexturePixelBufferStrategy(DataConstants.BYTES_PER_MEGABYTE / 8), textureOptions) {
@Override
protected InputStream onGetInputStream() throws IOException {
return TexturePackParser.this.onGetInputStream(file);
}
};
} catch (final IOException e) {
throw new TexturePackParseException(e);
}
} else if (type.equals(TexturePackParser.TAG_TEXTURE_ATTRIBUTE_TYPE_VALUE_PVRGZ)) {
try {
texture = new PVRGZTexture(this.mTextureManager, PVRTextureFormat.fromPixelFormat(pixelFormat), new SmartPVRTexturePixelBufferStrategy(DataConstants.BYTES_PER_MEGABYTE / 8), textureOptions) {
@Override
protected InputStream onGetInputStream() throws IOException {
return TexturePackParser.this.onGetInputStream(file);
}
};
} catch (final IOException e) {
throw new TexturePackParseException(e);
}
} else if (type.equals(TexturePackParser.TAG_TEXTURE_ATTRIBUTE_TYPE_VALUE_PVRCCZ)) {
try {
texture = new PVRCCZTexture(this.mTextureManager, PVRTextureFormat.fromPixelFormat(pixelFormat), new SmartPVRTexturePixelBufferStrategy(DataConstants.BYTES_PER_MEGABYTE / 8), textureOptions) {
@Override
protected InputStream onGetInputStream() throws IOException {
return TexturePackParser.this.onGetInputStream(file);
}
};
} catch (final IOException e) {
throw new TexturePackParseException(e);
}
} else {
throw new TexturePackParseException(new IllegalArgumentException("Unsupported pTextureFormat: '" + type + "'."));
}
this.mTextureManager.addMappedTexture(file, texture);
return texture;
}
use of org.andengine.opengl.texture.bitmap.BitmapTexture in project AndEngine by nicolasgramlich.
the class TextureManager method getTexture.
public synchronized ITexture getTexture(final String pID, final AssetManager pAssetManager, final String pAssetPath, final TextureOptions pTextureOptions) throws IOException {
if (this.hasMappedTexture(pID)) {
return this.getMappedTexture(pID);
} else {
final ITexture texture = new BitmapTexture(this, new AssetInputStreamOpener(pAssetManager, pAssetPath), pTextureOptions);
this.loadTexture(texture);
this.addMappedTexture(pID, texture);
return texture;
}
}
Aggregations