diff --git a/src/openfl/utils/Assets.hx b/src/openfl/utils/Assets.hx index e40857e629..5ea640911c 100644 --- a/src/openfl/utils/Assets.hx +++ b/src/openfl/utils/Assets.hx @@ -49,6 +49,10 @@ import lime.media.vorbis.VorbisFile; @:access(openfl.utils.AssetLibrary) class Assets { + public static var allowCompressedTextures:Bool = true; + + public static var allowUncompressedTextures:Bool = #if desktop true #else false #end; + public static var cache:IAssetCache = new AssetCache(); @:noCompletion private static var dispatcher:EventDispatcher #if !macro = new EventDispatcher() #end; @@ -82,7 +86,7 @@ class Assets { #if lime #if !flash - if (allowCompressedTextures) + if (allowCompressedTextures && Assets.allowCompressedTextures) { if (id != null && haxe.io.Path.extension(id) == "png") { @@ -114,11 +118,13 @@ class Assets @param id The ID or asset path for the bitmap @param useCache (Optional) Whether to allow use of the asset cache (Default: true) @param allowCompressedTextures (Optional) Wether to allow compressed textures to be used to get this bitmap (Default: true) + @param allowUncompressedTextures (Optional) Wether to allow uncompressed textures to be used (Default: true) + We wont load graphic to GPU, if it Compressed. @return A new BitmapData object @see [Working with bitmap assets](https://books.openfl.org/openfl-developers-guide/working-with-bitmaps/working-with-bitmap-assets.html) **/ - public static function getBitmapData(id:String, useCache:Bool = true, allowCompressedTextures:Bool = true):BitmapData + public static function getBitmapData(id:String, useCache:Bool = true, allowCompressedTextures:Bool = true, allowUncompressedTextures:Bool = true):BitmapData { #if (lime && tools && !display) if (useCache && cache.enabled && cache.hasBitmapData(id)) @@ -132,7 +138,7 @@ class Assets } #if !flash - if (allowCompressedTextures || haxe.io.Path.extension(id) == "astc") + if ((allowCompressedTextures && Assets.allowCompressedTextures) || haxe.io.Path.extension(id) == "astc") { final astcTexture:String = haxe.io.Path.withExtension(id, "astc"); @@ -163,6 +169,15 @@ class Assets var bitmapData = image.src; #else var bitmapData = BitmapData.fromImage(image); + + if (allowUncompressedTextures && Assets.allowUncompressedTextures) + { + var uncompressedTexture = openfl.Lib.current.stage.context3D.createTexture(bitmapData.width, bitmapData.height, BGRA, false); + + uncompressedTexture.uploadFromBitmapData(bitmapData); + + bitmapData = BitmapData.fromTexture(uncompressedTexture, false); + } #end if (useCache && cache.enabled) @@ -548,11 +563,12 @@ class Assets @param id The ID or asset path for the asset @param useCache (Optional) Whether to allow use of the asset cache (Default: true) + @param allowUncompressedTextures (Optional) Wether to allow uncompressed textures to be used (Default: true) @return Returns a Future @see [Working with bitmap assets](https://books.openfl.org/openfl-developers-guide/working-with-bitmaps/working-with-bitmap-assets.html) **/ - public static function loadBitmapData(id:String, useCache:Null = true):Future + public static function loadBitmapData(id:String, useCache:Null = true, allowUncompressedTextures:Bool = true):Future { if (useCache == null) useCache = true; @@ -578,6 +594,15 @@ class Assets var bitmapData = image.src; #else var bitmapData = BitmapData.fromImage(image); + + if (allowUncompressedTextures && Assets.allowUncompressedTextures) + { + var uncompressedTexture = openfl.Lib.current.stage.context3D.createTexture(bitmapData.width, bitmapData.height, BGRA, false); + + uncompressedTexture.uploadFromBitmapData(bitmapData); + + bitmapData = BitmapData.fromTexture(uncompressedTexture, false); + } #end if (useCache && cache.enabled) @@ -885,8 +910,7 @@ class Assets public static function loadText(id:String):Future { #if lime - var future = LimeAssets.loadText(id); - return future; + return LimeAssets.loadText(id); #else return Future.withValue(getText(id)); #end