From 3953670a23cd3eb5192407dc96a3c50207308ff4 Mon Sep 17 00:00:00 2001 From: CharlesCatYT Date: Sat, 17 Feb 2024 14:44:41 -0500 Subject: [PATCH] imporve gpu cache --- source/backend/Paths.hx | 54 +++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/source/backend/Paths.hx b/source/backend/Paths.hx index 4d2e52d..572752d 100644 --- a/source/backend/Paths.hx +++ b/source/backend/Paths.hx @@ -284,46 +284,48 @@ class Paths bitmap = OpenFlAssets.getBitmapData(file); } - if (bitmap != null) - { - var retVal = cacheBitmap(file, bitmap, allowGPU); - if(retVal != null) return retVal; - } + if (bitmap != null) return cacheBitmap(file, bitmap, allowGPU); - trace('Image with key "$key" could not be found' + (library == null ? '' : ' in the library "$library"') + '! ' + '(${posInfos.fileName}, ${posInfos.lineNumber})'); + trace('oh no its returning null NOOOO'); + trace('oh no "$key" is returning null NOOOO' + (library == null ? '' : '(library: "$library")') + '! ' + '(${posInfos.fileName}, ${posInfos.lineNumber})'); return null; } - static public function cacheBitmap(file:String, ?bitmap:BitmapData = null, ?allowGPU:Bool = true) + public static function cacheBitmap(file:String, ?bitmap:BitmapData, ?allowGPU:Bool = true):FlxGraphic { - if(bitmap == null) + if (bitmap == null) { #if MODS_ALLOWED if (FileSystem.exists(file)) bitmap = BitmapData.fromFile(file); - #else - if (OpenFlAssets.exists(file, IMAGE)) - bitmap = OpenFlAssets.getBitmapData(file); - #end + else + #end + if (OpenFlAssets.exists(file, IMAGE)) + bitmap = OpenFlAssets.getBitmapData(file); - if(bitmap == null) return null; + if (bitmap == null) return null; } - localTrackedAssets.push(file); - if (allowGPU && ClientPrefs.data.cacheOnGPU) - { - var texture:RectangleTexture = FlxG.stage.context3D.createRectangleTexture(bitmap.width, bitmap.height, BGRA, true); - texture.uploadFromBitmapData(bitmap); - bitmap.image.data = null; - bitmap.dispose(); + if (allowGPU && ClientPrefs.data.cacheOnGPU && bitmap.image != null) + @:privateAccess { + bitmap.lock(); + if (bitmap.__texture == null) { + bitmap.image.premultiplied = true; + bitmap.getTexture(FlxG.stage.context3D); + } + bitmap.getSurface(); bitmap.disposeImage(); - bitmap = BitmapData.fromTexture(texture); + bitmap.image.data = null; + bitmap.image = null; } - var newGraphic:FlxGraphic = FlxGraphic.fromBitmapData(bitmap, false, file); - newGraphic.persist = true; - newGraphic.destroyOnNoUse = false; - currentTrackedAssets.set(file, newGraphic); - return newGraphic; + + var graph:FlxGraphic = FlxGraphic.fromBitmapData(bitmap, false, file); + graph.persist = true; + graph.destroyOnNoUse = false; + + currentTrackedAssets.set(file, graph); + localTrackedAssets.push(file); + return graph; } static public function getTextFromFile(key:String, ?ignoreMods:Bool = false):String