WEBGL_lose_context
Members of the WebGL working group
Glenn Maynard
Last modified date: February 06, 2020
Revision: 15
WebGL extension #3
Written against the WebGL API 1.0 specification.
This extension exposes new functions which simulate losing and restoring the WebGL context, even on platforms where the context can never be lost. Consult the WebGL specification for documentation about the webglcontextlost
and webglcontextrestored
events.
When this extension is enabled:
loseContext
and restoreContext
are allowed to generate INVALID_OPERATION errors even when the context is lost.Note that this extension is not disconnected from the WebGLRenderingContext if that object loses its context as described in "The Context Lost Event" of the WebGL specification, either through use of this API or via actual circumstances such as a system failure.
[Exposed=(Window,Worker), LegacyNoInterfaceObject] interface WEBGL_lose_context { undefined loseContext(); undefined restoreContext(); };
When this function is called and the context is not lost, simulate
losing the context so as to trigger the steps described in the WebGL
spec for handling context lost. The context will remain in the lost
state according to the WebGL specification until
restoreContext()
is called. If the context is already
lost when this function is called, generate an
INVALID_OPERATION
error.
Implementations should destroy the underlying graphics context and all graphics resources when this method is called. This is the recommended mechanism for applications to programmatically halt their use of the WebGL API.
When this function is called while the context is lost, and the conditions
defined by the WebGL specification for restoring the context are
met, simulate the context being restored so as to trigger the steps
described in the WebGL spec for handling the context being restored.
Because this only enqueues the 'webglcontextrestored' event, the context will not be
immediately restored after restoreContext()
, but rather is first usably restored
within the 'webglcontextrestored' event callback.
(i.e. ext.restoreContext(), gl.isContextLost()
returns true
)
If the context is already restored when this function is called, or if
the conditions in the WebGL specification for restoring the
context are not satisfied, or if the context was not lost via loseContext()
,
generate an INVALID_OPERATION
error.
For example, if e.preventDefault()
is not called on the 'webglcontextlost'
event, the context will not be marked restorable, and restoreContext()
will fail.
Additionally, the context is not restorable before the 'webglcontextlost' event is complete:
calling restoreContext()
before 'webglcontextlost' has completed will fail.
Revision 1, 2011/01/11
Revision 2, 2011/04/14
Revision 3, 2011/11/08
Revision 4, 2011/11/11
Revision 5, 2011/12/06
Revision 6, 2011/12/07
Revision 7, 2012/01/03
Revision 8, 2013/01/26
Revision 9, 2013/05/15
Revision 10, 2013/06/05
Revision 11, 2013/08/02
Revision 12, 2014/05/08
Revision 13, 2014/07/15
Revision 14, 2017/02/03
Revision 15, 2020/02/06