Skip to content

Single WebGL Context for all elements #10

Closed

Description

@smalls

We need to decide on a technical approach, @cdata @jsantell @mrdoob started a discussion.

[Edit @jsantell: Previously "Ensure that we can have as many instances of <xr-model> on a page as desired", using a single webgl context to circumvent the 16 context limit, and for performance improvements]

Activity

  1. cdata commented on Oct 18, 2018

    @cdata
    Contributor

    @jsantell @mrdoob could you take a stab at describing the approaches you each mentioned to using a shared context?

  2. jsantell commented on Oct 19, 2018

    @jsantell
    Contributor

    There is a limit of how many WebGL contexts a single document can have. I think it's 12.

    One WebGLRenderingContext can be used to render all scenes by using Canvas2DRenderingContext's drawImage (three.js example, webxr-polyfill does the same thing to fake having two canvases). Might be a bit weird if elements are different sizes, may have to have the WebGL context at fullscreen size and change the viewport for every element. The WebGL context could be from an OffscreenCanvas on the main thread. Doesn't matter in this case.

    I have a PR out for the webxr-polyfill that improves perf that handles the canvas copying with ImageBitmapRenderingContexts instead of Canvas2DRenderingContexts, using an async createImageBitmap(). In this case, each model element would be have an image bitmap and async create bitmaps from the WebGL context, which should be cheaper than drawImage. Bonus points, because then an OffscreenCanvas in a worker could be implemented resulting in the best perf option that won't block the main thread unless the GPU is completely clogged -- more info on this solution in the PR. OffscreenCanvas is still Chrome only, I think in 69.

    An orthogonal solution could be using an Intersection Observer and lazily draw only models in view, but this probably not necessary off the bat.

  3. cdata commented on Oct 19, 2018

    @cdata
    Contributor

    @jsantell I like the fullscreen-sized context idea. Do you think that could obviate the need for post-processing antialiasing?

  4. jsantell commented on Oct 19, 2018

    @jsantell
    Contributor

    @cdata not using post processing, we can use the regular WebGL context attribute antialias which works, but if we do use PP, then we'll use render targets which do not work with antialias, which means if we use any sort of PP, we'll need to add SSAA in the chain

  5. changed the title [-]Ensure that we can have as many instances of `<xr-model>` on a page as desired[/-] [+]Single WebGL Context for all elements[/+] on Oct 23, 2018
  6. jsantell commented on Oct 23, 2018

    @jsantell
    Contributor

    Updated this issue to directly address the single webgl context solution. Opening issues for other performance improvements.

    FWIW 16 is the max WebGL contexts I could create without things breaking

  7. mrdoob commented on Oct 24, 2018

    @mrdoob
    Collaborator

    FWIW 16 is the max WebGL contexts I could create without things breaking

    I think it's 8 in mobile.

    Try loading https://mrdoob.github.io/rome-gltf/ on mobile.

  8. added 10 commits that reference this issue on Oct 29, 2018
    f03cfb3
    0bef3c6
    b0afba0
    78dcf77
    d7740be
    d907bdc
    4ec1034
    c41149a
    7e3feb5
    1c1e2bc
  9. added a commit that references this issue on Feb 4, 2020
    45bc4b6
  10. added a commit that references this issue on Jun 27, 2025
    25cefed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions