Skip to content

Commit

Permalink
imporve gpu cache
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesisfeline committed Feb 17, 2024
1 parent b0371ad commit 3953670
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions source/backend/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3953670

Please sign in to comment.