Skip to content

Commit 1e9ef31

Browse files
committed
Added addGLTexture method to save WebGL Textures directly into the Texture Manager.
1 parent b0b5f20 commit 1e9ef31

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/textures/TextureManager.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,38 @@ var TextureManager = new Class({
370370
return texture;
371371
},
372372

373+
/**
374+
* Takes a WebGL Texture and creates a Phaser Texture from it, which is added to the Texture Manager using the given key.
375+
*
376+
* This allows you to then use the Texture as a normal texture for texture based Game Objects like Sprites.
377+
*
378+
* This is a WebGL only feature.
379+
*
380+
* @method Phaser.Textures.TextureManager#addGLTexture
381+
* @fires Phaser.Textures.Events#ADD
382+
* @since 3.19.0
383+
*
384+
* @param {string} key - The unique string-based key of the Texture.
385+
* @param {WebGLTexture} glTexture - The source Render Texture.
386+
*
387+
* @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use.
388+
*/
389+
addGLTexture: function (key, glTexture, width, height)
390+
{
391+
var texture = null;
392+
393+
if (this.checkKey(key))
394+
{
395+
texture = this.create(key, glTexture, width, height);
396+
397+
texture.add('__BASE', 0, 0, 0, width, height);
398+
399+
this.emit(Events.ADD, key, texture);
400+
}
401+
402+
return texture;
403+
},
404+
373405
/**
374406
* Adds a Render Texture to the Texture Manager using the given key.
375407
* This allows you to then use the Render Texture as a normal texture for texture based Game Objects like Sprites.

0 commit comments

Comments
 (0)