Skip to content

Conversation

PurSnake
Copy link

@PurSnake PurSnake commented Sep 18, 2025

Adds ability to load bitmapdata via vram :steamhappy:
But only for desktop targets

Also its part of that Funkin PR

@ACrazyTown
Copy link

Why not just use the disposeImage() method from BitmapData? I see the point of calling getTexture() as afaik it'll force a hardware texture to be created and uploaded to the GPU but this seems needlessly complex:

Maybe I'm missing something?

@EliteMasterEric
Copy link
Member

Here's the snippet from the branch where I was experimenting with this functionality:

    trace('Uploading bitmap data to GPU... ${bitmapData?.image?.premultiplied}');

    // Retrieve the render context.
    var context:Context3D = FlxG.stage.context3D;

    // Create a new texture object using the render context.
    var texture:Texture = context.createTexture(bitmapData.width, bitmapData.height, Context3DTextureFormat.BGRA, optimizeForRender);

    // TODO: Figure out how to use texture.uploadCompressedTextureFromByteArray to save GPU memory?

    // Upload the texture to the GPU.
    // This is an expensive operation so don't do it in the UI thread if you can help it.
    texture.uploadFromBitmapData(bitmapData);

    // Now that the texture is uploaded, the `Texture` object is all we need to render it in-game.
    // We can dispose of the BitmapData object now.
    bitmapData.dispose();
    bitmapData.disposeImage();

    // Build a new, optimized BitmapData object using the Texture object.
    var output:BitmapData = BitmapData.fromTexture(texture);

    return output;

Note that this takes the bitmap data (which has already been loaded into memory from the disk), then creates a NEW texture, uploads the bitmap data to it, then creates a new BitmapData from that texture.

It looks like PurSnake's approach is trying to remove the BitmapData from the existing Bitmap so you don't have to swap to a new BitmapData like I was doing here.

@EliteMasterEric
Copy link
Member

Also, important: It would be prudent to make the same pull request to the upstream OpenFL repository, so all users can benefit from the new feature.

Co-Authored-By: Mihai Alexandru <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants