@@ -65,7 +65,7 @@ var Text = new Class({
6565 this . width = 1 ;
6666 this . height = 1 ;
6767
68- this . gpuBuffer = null ;
68+ this . canvasTexture = null ;
6969 this . prevWidth = this . canvas . width ;
7070 this . prevHeight = this . canvas . height ;
7171
@@ -260,45 +260,19 @@ var Text = new Class({
260260
261261 if ( this . state . game . config . renderType === Phaser . WEBGL )
262262 {
263- this . uploadToGPU ( ) ;
263+ this . canvasTexture = this . state . game . renderer . uploadCanvasToGPU (
264+ this . canvas ,
265+ this . canvasTexture ,
266+ ! ( this . prevWidth < canvas . width || this . prevHeight < canvas . height )
267+ ) ;
268+ this . prevWidth = canvas . width ;
269+ this . prevHeight = canvas . height ;
264270 }
265271
266272 return this ;
267273 } ,
268274
269- uploadToGPU : function ( )
270- {
271- var gl = this . state . game . renderer . gl ;
272- var currentTexture2D = this . state . game . renderer . currentTexture2D ;
273- var canvas = this . canvas ;
274-
275- if ( this . gpuBuffer === null )
276- {
277- this . gpuBuffer = gl . createTexture ( ) ;
278- }
279-
280- if ( this . prevWidth < canvas . width || this . prevHeight < canvas . height )
281- {
282- /* New canvas is too big. We need to reallocate the texture */
283- gl . bindTexture ( gl . TEXTURE_2D , this . gpuBuffer ) ;
284- gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , gl . RGBA , gl . UNSIGNED_BYTE , canvas ) ;
285- gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . LINEAR ) ;
286- gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , gl . LINEAR ) ;
287- gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
288- gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_T , gl . CLAMP_TO_EDGE ) ;
289- this . prevWidth = canvas . width ;
290- this . prevHeight = canvas . height ;
291- }
292- else
293- {
294- /* if the canvas is smaller we just update the resource */
295- gl . bindTexture ( gl . TEXTURE_2D , this . gpuBuffer ) ;
296- gl . texSubImage2D ( gl . TEXTURE_2D , 0 , 0 , 0 , gl . RGBA , gl . UNSIGNED_BYTE , canvas ) ;
297- }
298-
299- /* we must rebind old texture */
300- gl . bindTexture ( gl . TEXTURE_2D , currentTexture2D ) ;
301- }
275+
302276} ) ;
303277
304278module . exports = Text ;
0 commit comments