Skip to content

Compatibility with foreign JS execution context and avoiding page reload #9

@Winchestro

Description

@Winchestro

After a quick look into the source I figured the solution of hooking into the methods of the WebGLRenderingContext prototype might not work for contexts created in foreign execution contexts, namely inside an iframe and exported to the main JS context. One possible workaround I can think of is to check the DOM for canvas elements and then set up a mutation observer to check for canvas elements added to the main DOM. That won't work for a canvas inside an iframe and offscreen rendering contexts though.

But calling getContext on a canvas of a foreign exceution context should always give you the proper foreign rendering context as far as I know.

As a hook into the program info I suggest useProgram in any case, because that would catch already compiled programs without refreshig the page and is usually called during rendering.To query the attached shaders you could use gl.getProgramParameter( programRef, gl.ATTACHED_SHADERS ) to get the shader references and then gl.getShaderSource( shaderRef ) and all other relevant states.

In case of simple scenes with only one program you can get that in any case by querying gl.getParameter( gl.CURRENT_PROGRAM ) first. So you would ge those already linked and used before you could reach them.

If the canvas doesn't leave the iframe or prevents writes on the prototpe nothing really helps, but that'd still make your implementation a bit more robust for most cases. Hope it helps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions