Return to the Change Log index.
Phaser now performs a WebGL context restore.
WebGL can lose context when the browser wants to reclaim resources. This happens most often when a browser tab is inactive. When it happens is beyond the control of web developers.
When context is lost, the game canvas goes blank. A lost context loses all the data that was sent to the WebGL system. It cannot do anything until the browser restores the context, usually when the user returns to their tab.
Phaser now restores this data, with a few exceptions, allowing your games to seamlessly resume. For the most part, your WebGL games should now simply recover when the browser restores the WebGL context.
Key concepts:
WebGLRenderer
emits LOSE_WEBGL
and RESTORE_WEBGL
events.Phaser.Renderers.WebGL.WebGLRenderer
now emits events that you can use to stay informed about context loss.
Phaser.Renderer.Events#LOSE_WEBGL
is emitted when context is lost. This would be a good time to pause the game, or otherwise avoid making changes that the player cannot see.Phaser.Renderer.Events#RESTORE_WEBGL
is emitted when context is restored. This would be a good time to restore dynamic textures, and start things moving again.Dynamic textures and render textures are stored on the GPU. When context is lost, the texture is erased. When context is restored, the texture is re-enabled, but it remains blank.
A render texture which is redrawn every frame will naturally redraw itself.
Textures which are drawn once, however, will stay blank. You should listen for the RESTORE_WEBGL
event to know when to redraw them.
It is safe to draw while the context is lost, but nothing will be drawn. Snapshots will return blank.
WebGL objects are now wrapped. The wrapper holds the necessary information to automatically recreate the object when context is restored.
This is only relevant if you need deep access to the WebGL renderer.
Wrappers are created and managed by the WebGLRenderer
. They have the following qualities:
createResource()
, which will create a new WebGL object from stored information.destroy()
, which will remove the object. Do not call this directly; it is managed by the WebGLRenderer
.The following wrappers are available in the Phaser.Renderer.WebGL.Wrappers
namespace:
WebGLAttribLocationWrapper
WebGLBufferWrapper
WebGLFramebufferWrapper
WebGLProgramWrapper
WebGLTextureWrapper
WebGLUniformLocationWrapper
You can test context loss and restore with a built-in WebGL extension. The following code snippet should be useful for testing purposes. It shows how to get the built-in extension, and simulate losing and restoring the context after 1 and 2 seconds respectively.
const webGLLoseContextExtension = game.renderer.getExtension('WEBGL_lose_context');
setTimeout(function () {
webGLLoseContextExtension.loseContext();
setTimeout(function () {
webGLLoseContextExtension.restoreContext();
}, 1000)
}, 1000);
Several changes were made to the rendering system to support these improvements. In particular, many properties were changed to use wrappers instead of raw WebGL objects. The full list of changes is as follows:
Phaser.FX.Displacement
glTexture
property type changed from WebGLTexture
to WebGLTextureWrapper
BatchChar
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
Phaser.GameObjects.Shader
vertexBuffer
property type changed from WebGLBuffer
to WebGLBufferWrapper
program
property type changed from WebGLProgram
to WebGLProgramWrapper
framebuffer
property type changed from WebGLFramebuffer
to WebGLFramebufferWrapper
glTexture
property type changed from WebGLTexture
to WebGLTextureWrapper
#initUniforms
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
Phaser.GameObjects.TileSprite
fillPattern
property type changed from ?(WebGLTexture|CanvasPattern)
to ?(WebGLTextureWrapper|CanvasPattern)
Phaser.Renderer.WebGL.PipelineManager
postPipelineInstances
of type PostFXPipeline[]
removePostPipeline(pipeline: PostFXPipeline)
restoreContext()
, used after context is restoredPhaser.Renderer.WebGL.RenderTarget
framebuffer
property type changed from WebGLFramebuffer
to WebGLFramebufferWrapper
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
#unbind
method:
WebGLFramebuffer
to WebGLFramebufferWrapper
Phaser.Renderer.WebGL.WebGLPipeline
vertexBuffer
property type changed from WebGLBuffer
to WebGLBufferWrapper
activeBuffer
property type changed from WebGLBuffer
to WebGLBufferWrapper
currentTexture
property type changed from WebGLTexture
to WebGLTextureWrapper
activeTextures
property type changed from WebGLTexture[]
to WebGLTextureWrapper[]
#setShader
method:
vertexBuffer
parameter type changed from WebGLBuffer
to WebGLBufferWrapper
#createBatch
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
#addTextureToBatch
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
#pushBatch
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
restoreContext()
, used after context is restored#setVertexBuffer
method:
buffer
parameter type changed from WebGLBuffer
to WebGLBufferWrapper
#batchQuad
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
#batchTri
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
#drawFillRect
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
#setTexture2D
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
#bindTexture
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
Phaser.Renderer.WebGL.WebGLRenderer
glBufferWrappers
of type WebGLBufferWrapper[]
glProgramWrappers
of type WebGLProgramWrapper[]
glTextureWrappers
of type WebGLTextureWrapper[]
glFramebufferWrappers
of type WebGLFramebufferWrapper[]
glAttribLocationWrappers
of type WebGLAttribLocationWrapper[]
glUniformLocationWrappers
of type WebGLUniformLocationWrapper[]
normalTexture
of type WebGLTextureWrapper
currentFramebuffer
property type changed from WebGLFramebuffer
to WebGLFramebufferWrapper
fboStack
property type changed from WebGLFramebuffer[]
to WebGLFramebufferWrapper[]
currentProgram
property type changed from WebGLProgram
to WebGLProgramWrapper
blankTexture
property type changed from WebGLTexture
to WebGLTextureWrapper
whiteTexture
property type changed from WebGLTexture
to WebGLTextureWrapper
createTemporaryTextures()
, used when booting on MacOS#pushFramebuffer
method:
framebuffer
parameter changed from WebGLFramebuffer
to WebGLFramebufferWrapper
texture
parameter changed from WebGLTexture
to WebGLTextureWrapper
#setFramebuffer
method:
framebuffer
parameter changed from WebGLFramebuffer
to WebGLFramebufferWrapper
texture
parameter changed from WebGLTexture
to WebGLTextureWrapper
#popFramebuffer
method:
WebGLFramebuffer
to WebGLFramebufferWrapper
#setProgram
method:
program
parameter changed from WebGLProgram
to WebGLFramebufferWrapper
#createTextureFromSource
method:
WebGLTexture
to WebGLTextureWrapper
#createTexture2D
method:
width
parameter made optionalheight
parameter made optionalWebGLTexture
to WebGLTextureWrapper
#createFramebuffer
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
WebGLFramebuffer
to WebGLFramebufferWrapper
#createProgram
method:
WebGLProgram
to WebGLProgramWrapper
#createVertexBuffer
method:
WebGLBuffer
to WebGLBufferWrapper
createAttribLocation
createUniformLocation
#createIndexBuffer
method:
WebGLBuffer
to WebGLBufferWrapper
#deleteTexture
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
#deleteFramebuffer
method:
framebuffer
parameter type changed from WebGLFramebuffer
to WebGLFramebufferWrapper
#deleteProgram
method:
program
parameter type changed from WebGLProgram
to WebGLProgramWrapper
deleteAttribLocation
deleteUniformLocation
#deleteBuffer
method:
vertexBuffer
parameter type changed from WebGLBuffer
to WebGLBufferWrapper
#snapshotFramebuffer
method:
framebuffer
parameter changed from WebGLFramebuffer
to WebGLFramebufferWrapper
#canvasToTexture
method:
dstTexture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
WebGLTexture
to WebGLTextureWrapper
#createCanvasTexture
method:
WebGLTexture
to WebGLTextureWrapper
#updateCanvasTexture
method:
dstTexture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
WebGLTexture
to WebGLTextureWrapper
#createVideoTexture
method:
WebGLTexture
to WebGLTextureWrapper
#updateCanvasTexture
method:
dstTexture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
WebGLTexture
to WebGLTextureWrapper
createUint8ArrayTexture
#setTextureFilter
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
Phaser.Renderers.WebGL.WebGLShader
program
property type changed from WebGLProgram
to WebGLProgramWrapper
syncUniforms
for use during context recoveryPhaser.Renderers.WebGL.Pipelines.LightPipeline
defaultNormalMap
. There is now a default normal map at WebGLRenderer.normalTexture
, or the texture key '__NORMAL'
.currentNormalMap
property type changed from WebGLTexture
to WebGLTextureWrapper
#setTexture2D
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
#isNewNormalMap
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
normalMap
parameter type changed from WebGLTexture
to WebGLTextureWrapper
#getNormalMap
method:
WebGLTexture
to WebGLTextureWrapper
#batchTexture
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
Phaser.Renderers.WebGL.Pipelines.MultiPipeline
#batchTexture
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
Phaser.Renderers.WebGL.Pipelines.PreFXPipeline
quadVertexBuffer
property type changed from WebGLBuffer
to WebGLBufferWrapper
#batchQuad
method:
texture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
Phaser.Renderers.WebGL.Pipelines.DisplacementFXPipeline
glTexture
property type changed from WebGLTexture
to WebGLTextureWrapper
WebGLPipelineAttribute
location
property changed from number
to -1|WebGLAttribLocationWrapper
WebGLPipelineBatchEntry
texture
property changed from WebGLTexture
to WebGLTextureWrapper
WebGLPipelineUniformsConfig
setter
of type ?function
for use in restoring contextPhaser.Textures.DynamicTexture
#getWebGLTexture
method:
WebGLTexture
to WebGLTextureWrapper
Phaser.Textures.Frame
glTexture
property type changed from WebGLTexture
to WebGLTextureWrapper
Phaser.Textures.Texture
source
parameter type options added WebGLTextureWrapper
Phaser.Textures.TextureManager
'__NORMAL'
is created on boot if the WebGL renderer is being used. This is a 1x1 texture of colour #7f7fff, or a flat normal map.#addGLTexture
method:
glTexture
parameter type changed from WebGLTexture
to WebGLTextureWrapper
width
parameter removedheight
parameter removed#getTextureKeys
now excludes '__NORMAL'
as well as '__DEFAULT'
, '__MISSING'
, and '__WHITE'
.addUint8Array
for creating textures from raw colour dataPhaser.Textures.TextureSource
glTexture
property type changed from WebGLTexture
to WebGLTextureWrapper
Phaser.Tilemaps.Tileset
glTexture
property type changed from WebGLTexture
to WebGLTextureWrapper
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )