8000 Removed the GPU texture handlers out of the Texture Manager, and into… · ITCSsDeveloper/phaser@271aab1 · GitHub < 8000 meta name="twitter:title" content="Removed the GPU texture handlers out of the Texture Manager, and into… · ITCSsDeveloper/phaser@271aab1" />
Skip to content

Commit 271aab1

Browse files
committed
Removed the GPU texture handlers out of the Texture Manager, and into the WebGL Renderer.
1 parent 379b54b commit 271aab1

2 files changed

Lines changed: 21 additions & 101 deletions

File tree

src/renderer/webgl/WebGLRenderer.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,27 @@ Phaser.Renderer.WebGL.prototype = {
422422
// Add Post-render hook
423423
},
424424

425+
/**
426+
* Removes the base texture from the GPU, useful for managing resources on the GPU.
427+
* A texture is still 100% usable and will simply be re-uploaded if there is a sprite on screen that is using it.
428+
*
429+
* @method unloadTexture
430+
*/
431+
unloadTexture: function (texture)
432+
{
433+
var gl = this.gl;
434+
435+
var glTexture = texture._glTexture;
436+
437+
if (gl && glTexture)
438+
{
439+
gl.deleteTexture(glTexture);
440+
}
441+
442+
texture._glTexture = null;
443+
texture._dirty = false;
444+
},
445+
425446
updateTexture: function (texture)
426447
{
427448
if (!texture.hasLoaded)
@@ -696,8 +717,6 @@ Phaser.Renderer.WebGL.prototype = {
696717

697718
destroy: function ()
698719
{
699-
PIXI.glContexts[this.glContextId] = null;
700-
701720
this.projection = null;
702721
this.offset = null;
703722

@@ -715,10 +734,6 @@ Phaser.Renderer.WebGL.prototype = {
715734
this.renderSession = null;
716735

717736
Phaser.CanvasPool.remove(this);
718-
719-
PIXI.instances[this.glContextId] = null;
720-
721-
PIXI.WebGLRenderer.glContextId--;
722737
}
723738

724739
};

src/textures/TextureManager.js

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -208,101 +208,6 @@ Phaser.TextureManager.prototype = {
208208

209209
callback.apply(thisArg, args);
210210
}
211-
},
212-
213-
/**
214-
* TODO: This should move to the WebGL Renderer class.
215-
*
216-
* Removes the base texture from the GPU, useful for managing resources on the GPU.
217-
* A texture is still 100% usable and will simply be re-uploaded if there is a sprite on screen that is using it.
218-
*
219-
* @method unloadFromGPU
220-
*/
221-
unloadFromGPU: function ()
222-
{
223-
this.dirty();
224-
225-
// delete the webGL textures if any.
226-
for (var i = this._glTextures.length - 1; i >= 0; i--)
227-
{
228-
var glTexture = this._glTextures[i];
229-
var gl = PIXI.glContexts[i];
230-
231-
if (gl && glTexture)
232-
{
233-
gl.deleteTexture(glTexture);
234-
}
235-
}
236-
237-
this._glTextures.length = 0;
238-
239-
this.dirty();
240-
},
241-
242-
/**
243-
* TODO: This should move to the WebGL Renderer class.
244-
*
245-
* Updates and Creates a WebGL texture for the renderers context.
246-
*
247-
* @method updateTexture
248-
* @param texture {Texture} the texture to update
249-
* @return {boolean} True if the texture was successfully bound, otherwise false.
250-
*/
251-
loadToGPU: function (texture)
252-
{
253-
if (!texture.hasLoaded)
254-
{
255-
return false;
256-
}
257-
258-
if (texture.source.compressionAlgorithm)
259-
{
260-
return this.updateCompressedTexture(texture);
261-
}
262-
263-
var gl = this.gl;
264-
265-
if (!texture._glTextures[gl.id])
266-
{
267-
texture._glTextures[gl.id] = gl.createTexture();
268-
}
269-
270-
gl.activeTexture(gl.TEXTURE0 + texture.textureIndex);
271-
272-
gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);
273-
274-
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultipliedAlpha);
275-
276-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source);
277-
278-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === Phaser.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST);
279-
280-
if (texture.mipmap && Phaser.Math.isPowerOfTwo(texture.width, texture.height))
281-
{
282-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === Phaser.scaleModes.LINEAR ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST);
283-
gl.generateMipmap(gl.TEXTURE_2D);
284-
}
285-
else
286-
{
287-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === Phaser.scaleModes 8096 .LINEAR ? gl.LINEAR : gl.NEAREST);
288-
}
289-
290-
if (!texture._powerOf2)
291-
{
292-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
293-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
294-
}
295-
else
296-
{
297-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
298-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
299-
}
300-
301-
texture._dirty[gl.id] = false;
302-
303-
// return texture._glTextures[gl.id];
304-
return true;
305-
306211
}
307212

308213
};

0 commit comments

Comments
 (0)