I am trying to draw the same WebGL scene using two canvases side-by-side. Is it possible? So far I haven't been lucky.
The idea goes as follows:
gl
context, one per canvasdrawElements
on the first context passing my geometrydrawElements
on the second context passing my geometryResults:
Only the first invocation is successful. The second context executes gl.clear
correctly but no geometry is displayed.
What am I missing? is this a spec constrain? or a limitation in the Firefox and Safari's implementations?
Thanks,
Mobile browsers have a limit of eight WebGL contexts.
The WebGL context is a JavaScript object that stores the current state of the graphics library. WebGL is a state machine. That means that if you set a WebGL variable to a specific value, that value will not change until you change it. For example, you can set the color used to clear the canvas background once.
Yes, you can have more than one WebGL context on a page, but each context must manage it's own resources. You cannot create buffers or textures on one context and then use them on the other, so to use this approach if you wanted to render the same scene you would need to load all your resources twice.
That's certainly doable, but it will be very memory intensive (as you might imagine). A better solution would be to create a context that is 2x the width you need and use gl.viewport and gl.scissor to render to half of it for each view of the scene.
Or, make a full viewport size canvas and use the scissor/viewport settings to match other html elements. See this Q&A: How can we have display of same objects in two canvas in webgl?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With