N
N
NNn1312021-02-07 15:03:51
JavaScript
NNn131, 2021-02-07 15:03:51

What is the loss of webgl context and what is it eaten with?

I'm trying to create a drawing tool on webgl2
Support for a large number of layers (> 10) at 128 bits / pix is ​​desirable. I read the format

on the Internet, it turns out that such a terrible thing as the loss of webgl context can happen to everyone.
In this regard, several questions have matured

1: Should the handling of context loss in webgl and webgl2 be somehow different?
2: Here I lost the context, which means that all the programs and shaders of the current context just crashed and the context variable itself (usually gl) remained available and I have to somehow restore all the data in it
or I need to get a completely new context by callinggl = canvas.getContext("webgl2");, and only then restore it? Then the old context will be automatically deleted or will it hang in oblivion?
3: The most important question, what happens to the data when the context is lost? If I store the layers as 2d textures, will they all be destroyed? How can I save them then? Duplicate them also in RAM? Isn't it too fat? Then, when changing (and this will often happen), the textures will have to be copied through gl.readPixels? Wouldn't this hurt performance too much? How can I continue to live?
4: Maybe even score on this loss of context? How often does it happen? Once in a million? What if I don't need mobile phone support?
Thanks and sorry for the copied question.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Bogachev, 2021-02-07
@sfi0zy

I'm trying to create a drawing tool on webgl2

It's worth looking at Safari's WebGL2 support , realizing that an experimental feature is not stable even with "green" support, and thinking again before it's too late. But this is so, by the way. Since we are talking about quality and reliability.
What happens to the data when the context is lost? ...then restore it? ... will the old context be automatically deleted or will it hang in oblivion?

There is a good first-hand article on the topic . There are answers to your questions with details and code examples.
Can generally score on this loss of context? How often does it happen? Once in a million?

It happens really rarely. For all the time I have experimented with WebGL, I have never encountered it. That is, it seems that the browser is more likely to hang tightly than reset the context. Whether you need super reliability with handling this rare scenario in your particular case is up to you. But in general, few people care about it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question