bbc / VideoContext

An experimental HTML5 & WebGL video composition and rendering API.
http://bbc.github.io/VideoContext/
Apache License 2.0
1.32k stars 156 forks source link

transparent player, why is alpha set false, with no override #153

Open icyield opened 5 years ago

icyield commented 5 years ago

I would like to play an alpha video on a background, but the VideoContext webglContextAttributes alpha Can't be overriden because it is copied last.

Why is this done? If I change it to true works as expected, giving transparent player.

=====================================

`_classCallCheck(this, VideoContext);

            this._canvas = canvas;
            this._endOnLastSourceEnd = endOnLastSourceEnd;

            this._gl = canvas.getContext("experimental-webgl", Object.assign({ preserveDrawingBuffer: true }, // can be overriden
            webglContextAttributes, { alpha: false // Can't be overriden because it is copied last
            }));`
PTaylour commented 5 years ago

I assume it's set to false to help with performance.

However, I can't think of a reason why it shouldn't be overridable.

@gsouquet do you guys have any opinions on this?

germain-gg commented 5 years ago

I remember seeing a comment from Matthew in the code

if (webglContextAttributes.alpha === true){
  console.error("webglContextAttributes.alpha must be false for correct opeation");
}

I assume it has to do with performance as you said but possible with fidelity of the output. With new APIs like MediaRecorder you could end up with a different output than what you have previewed in your browser.

This would need to be investigated a bit more. I think the default has to be alpha: false for sure. But I can't see major problems that would arise with letting developers override that

germain-gg commented 4 years ago

Actually looking at #154 , it seems like having an alpha set to true could be a risk.

If we decide to make the canvas desynchronised we won't have the ability to stack elements over the VC canvas.

We could probably allow the user to make that override, but the question becomes, how do we now communicate that behaviour to the developers to avoid frustration and hours of debugging?

Check https://developers.google.com/web/updates/2019/05/desynchronized#alpha_channels

How do you think we should move this forward?

icyield commented 4 years ago

The fact that alpha canvas might have some issues that make it more difficult to use is not really a reason to not allow users to override.

If this is really an issue then some code to catch an allowAlphaOverride in the context could be used. But you can't stop "frustration and hours of debugging" by not allowing something that a user requires.

var videoContextOptions = { endOnLastSourceEnd: true, webglContextAttributes: { preserveDrawingBuffer: true, allowAlphaOverride:true, alpha: true } };

germain-gg commented 4 years ago

@icyield I believe I didn't explain myself correctly. We could probably allow an alpha override. However if we are going to allow that I believe we should think about how we can communicate the limitations this brings with the desynchronised rendering.

Maybe through documentation or maybe make the library check if anything is stacked above the canvas. Not sure