Skip to content

Share WebGL Context Across Multiple Surfaces to Avoid Maximum WebGL Context Issues #120156

@jezell

Description

@jezell

Use case

Because browsers limit the number of active WebGL contexts, it's not a good idea for any app to create more than one of them, let alone an undefined number of them. Because the current renderer is wasteful with WebGL resources, any app that embeds any HTML elements inside a view can quickly exhaust the available web GL contexts, which can make this useful feature of flutter on web hard to use in practice.

Proposal

Don't create more than one WebGL context in the first place so that users don't bump up against these limits by creating additional layers. Here's an example of a javascript framework that virtualizes webGL contexts to accomplish this:

https://github.com/greggman/virtual-webgl

All of the WebGL rendering can be done with a single context, and then the buffers can be drawn to 2d canvas elements for each surface. While some browsers do limit the amount of canvas memory that apps can use, it's a lot harder to run out of 2d canvas memory than it is to burn through 8 WebGL contexts. This strategy would ensure that a single flutter app only ever uses a single webgl context and be a big improvement to engine reliability for scenarios where people need to mix and match flutter rendered layers with HTML layers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterengineflutter/engine related. See also e: labels.has partial patchThere is a PR awaiting someone to take it across the finish lineplatform-webWeb applications specificallyteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions