@@ -61,53 +61,7 @@ PIXI.CanvasRenderer = function(width, height, options)
6161 */
6262 this . transparent = options . transparent ;
6363
64- if ( ! PIXI . blendModesCanvas )
65- {
66- PIXI . blendModesCanvas = [ ] ;
67-
68- if ( PIXI . canUseNewCanvasBlendModes ( ) )
69- {
70- PIXI . blendModesCanvas [ PIXI . blendModes . NORMAL ] = "source-over" ;
71- PIXI . blendModesCanvas [ PIXI . blendModes . ADD ] = "lighter" ; //IS THIS OK???
72- PIXI . blendModesCanvas [ PIXI . blendModes . MULTIPLY ] = "multiply" ;
73- PIXI . blendModesCanvas [ PIXI . blendModes . SCREEN ] = "screen" ;
74- PIXI . blendModesCanvas [ PIXI . blendModes . OVERLAY ] = "overlay" ;
75- PIXI . blendModesCanvas [ PIXI . blendModes . DARKEN ] = "darken" ;
76- PIXI . blendModesCanvas [ PIXI . blendModes . LIGHTEN ] = "lighten" ;
77- PIXI . blendModesCanvas [ PIXI . blendModes . COLOR_DODGE ] = "color-dodge" ;
78- PIXI . blendModesCanvas [ PIXI . blendModes . COLOR_BURN ] = "color-burn" ;
79- PIXI . blendModesCanvas [ PIXI . blendModes . HARD_LIGHT ] = "hard-light" ;
80- PIXI . blendModesCanvas [ PIXI . blendModes . SOFT_LIGHT ] = "soft-light" ;
81- PIXI . blendModesCanvas [ PIXI . blendModes . DIFFERENCE ] = "difference" ;
82- PIXI . blendModesCanvas [ PIXI . blendModes . EXCLUSION ] = "exclusion" ;
83- PIXI . blendModesCanvas [ PIXI . blendModes . HUE ] = "hue" ;
84- PIXI . blendModesCanvas [ PIXI . blendModes . SATURATION ] = "saturation" ;
85- PIXI . blendModesCanvas [ PIXI . blendModes . COLOR ] = "color" ;
86- PIXI . blendModesCanvas [ PIXI . blendModes . LUMINOSITY ] = "luminosity" ;
87- }
88- else
89- {
90- // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough"
91- PIXI . blendModesCanvas [ PIXI . blendModes . NORMAL ] = "source-over" ;
92- PIXI . blendModesCanvas [ PIXI . blendModes . ADD ] = "lighter" ; //IS THIS OK???
93- PIXI . blendModesCanvas [ PIXI . blendModes . MULTIPLY ] = "source-over" ;
94- PIXI . blendModesCanvas [ PIXI . blendModes . SCREEN ] = "source-over" ;
95- PIXI . blendModesCanvas [ PIXI . blendModes . OVERLAY ] = "source-over" ;
96- PIXI . blendModesCanvas [ PIXI . blendModes . DARKEN ] = "source-over" ;
97- PIXI . blendModesCanvas [ PIXI . blendModes . LIGHTEN ] = "source-over" ;
98- PIXI . blendModesCanvas [ PIXI . blendModes . COLOR_DODGE ] = "source-over" ;
99- PIXI . blendModesCanvas [ PIXI . blendModes . COLOR_BURN ] = "source-over" ;
100- PIXI . blendModesCanvas [ PIXI . blendModes . HARD_LIGHT ] = "source-over" ;
101- PIXI . blendModesCanvas [ PIXI . blendModes . SOFT_LIGHT ] = "source-over" ;
102- PIXI . blendModesCanvas [ PIXI . blendModes . DIFFERENCE ] = "source-over" ;
103- PIXI . blendModesCanvas [ PIXI . blendModes . EXCLUSION ] = "source-over" ;
104- PIXI . blendModesCanvas [ PIXI . blendModes . HUE ] = "source-over" ;
105- PIXI . blendModesCanvas [ PIXI . blendModes . SATURATION ] = "source-over" ;
106- PIXI . blendModesCanvas [ PIXI . blendModes . COLOR ] = "source-over" ;
107- PIXI . blendModesCanvas [ PIXI . blendModes . LUMINOSITY ] = "source-over" ;
108- }
109- }
110-
64+
11165 /**
11266 * The width of the canvas view
11367 *
@@ -169,7 +123,6 @@ PIXI.CanvasRenderer = function(width, height, options)
169123 maskManager : this . maskManager ,
170124 scaleMode : null ,
171125 smoothProperty : null ,
172-
173126 /**
174127 * If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation.
175128 * Handy for crisp pixel art and speed on legacy devices.
@@ -236,7 +189,6 @@ PIXI.CanvasRenderer.prototype.render = function(stage)
236189 stage . interactionManager . setTarget ( this ) ;
237190 }
238191 }
239-
240192} ;
241193
242194/**
@@ -256,7 +208,6 @@ PIXI.CanvasRenderer.prototype.resize = function(width, height)
256208
257209 this . view . style . width = this . width / this . resolution + "px" ;
258210 this . view . style . height = this . height / this . resolution + "px" ;
259-
260211} ;
261212
262213/**
@@ -269,149 +220,59 @@ PIXI.CanvasRenderer.prototype.resize = function(width, height)
269220 */
270221PIXI . CanvasRenderer . prototype . renderDisplayObject = function ( displayObject , context )
271222{
272- // no longer recursive!
273- //var transform;
274- //var context = this.context;
275-
276223 this . renderSession . context = context || this . context ;
277224 this . renderSession . resolution = this . resolution ;
278225 displayObject . _renderCanvas ( this . renderSession ) ;
279226} ;
280227
281- /**
282- * Renders a flat strip
283- *
284- * @method renderStripFlat
285- * @param strip {Strip} The Strip to render
286- * @private
287- */
288- PIXI . CanvasRenderer . prototype . renderStripFlat = function ( strip )
289- {
290- var context = this . context ;
291- var verticies = strip . verticies ;
292228
293- var length = verticies . length / 2 ;
294- this . count ++ ;
295-
296- context . beginPath ( ) ;
297- for ( var i = 1 ; i < length - 2 ; i ++ )
298- {
299- // draw some triangles!
300- var index = i * 2 ;
301229
302- var x0 = verticies [ index ] , x1 = verticies [ index + 2 ] , x2 = verticies [ index + 4 ] ;
303- var y0 = verticies [ index + 1 ] , y1 = verticies [ index + 3 ] , y2 = verticies [ index + 5 ] ;
304-
305- context . moveTo ( x0 , y0 ) ;
306- context . lineTo ( x1 , y1 ) ;
307- context . lineTo ( x2 , y2 ) ;
308- }
309-
310- context . fillStyle = "#FF0000" ;
311- context . fill ( ) ;
312- context . closePath ( ) ;
313- } ;
314-
315- /**
316- * Renders a strip
317- *
318- * @method renderStrip
319- * @param strip {Strip} The Strip to render
320- * @private
321- */
322- PIXI . CanvasRenderer . prototype . renderStrip = function ( strip )
230+ PIXI . CanvasRenderer . prototype . mapBlendModes = function ( )
323231{
324- var context = this . context ;
325-
326- // draw triangles!!
327- var verticies = strip . verticies ;
328- var uvs = strip . uvs ;
329-
330- var length = verticies . length / 2 ;
331- this . count ++ ;
332-
333- for ( var i = 1 ; i < length - 2 ; i ++ )
232+ if ( ! PIXI . blendModesCanvas )
334233 {
335- // draw some triangles!
336- var index = i * 2 ;
337-
338- var x0 = verticies [ index ] , x1 = verticies [ index + 2 ] , x2 = verticies [ index + 4 ] ;
339- var y0 = verticies [ index + 1 ] , y1 = verticies [ index + 3 ] , y2 = verticies [ index + 5 ] ;
340-
341- var u0 = uvs [ index ] * strip . texture . width , u1 = uvs [ index + 2 ] * strip . texture . width , u2 = uvs [ index + 4 ] * strip . texture . width ;
342- var v0 = uvs [ index + 1 ] * strip . texture . height , v1 = uvs [ index + 3 ] * strip . texture . height , v2 = uvs [ index + 5 ] * strip . texture . height ;
343-
344- context . save ( ) ;
345- context . beginPath ( ) ;
346- context . moveTo ( x0 , y0 ) ;
347- context . lineTo ( x1 , y1 ) ;
348- context . lineTo ( x2 , y2 ) ;
349- context . closePath ( ) ;
350-
351- context . clip ( ) ;
352-
353- // Compute matrix transform
354- var delta = u0 * v1 + v0 * u2 + u1 * v2 - v1 * u2 - v0 * u1 - u0 * v2 ;
355- var deltaA = x0 * v1 + v0 * x2 + x1 * v2 - v1 * x2 - v0 * x1 - x0 * v2 ;
356- var deltaB = u0 * x1 + x0 * u2 + u1 * x2 - x1 * u2 - x0 * u1 - u0 * x2 ;
357- var deltaC = u0 * v1 * x2 + v0 * x1 * u2 + x0 * u1 * v2 - x0 * v1 * u2 - v0 * u1 * x2 - u0 * x1 * v2 ;
358- var deltaD = y0 * v1 + v0 * y2 + y1 * v2 - v1 * y2 - v0 * y1 - y0 * v2 ;
359- var deltaE = u0 * y1 + y0 * u2 + u1 * y2 - y1 * u2 - y0 * u1 - u0 * y2 ;
360- var deltaF = u0 * v1 * y2 + v0 * y1 * u2 + y0 * u1 * v2 - y0 * v1 * u2 - v0 * u1 * y2 - u0 * y1 * v2 ;
361-
362- context . transform ( deltaA / delta , deltaD / delta ,
363- deltaB / delta , deltaE / delta ,
364- deltaC / delta , deltaF / delta ) ;
365-
366- context . drawImage ( strip . texture . baseTexture . source , 0 , 0 ) ;
367- context . restore ( ) ;
368- }
369- } ;
370-
371- /**
372- * Creates a Canvas element of the given size
373- *
374- * @method CanvasBuffer
375- * @param width {Number} the width for the newly created canvas
376- * @param height {Number} the height for the newly created canvas
377- * @static
378- * @private
379- */
380- PIXI . CanvasBuffer = function ( width , height )
381- {
382- this . width = width ;
383- this . height = height ;
384-
385- this . canvas = document . createElement ( "canvas" ) ;
386- this . context = this . canvas . getContext ( "2d" ) ;
387-
388- this . canvas . width = width ;
389- this . canvas . height = height ;
390- } ;
391-
392- /**
393- * Clears the canvas that was created by the CanvasBuffer class
394- *
395- * @method clear
396- * @private
397- */
398- PIXI . CanvasBuffer . prototype . clear = function ( )
399- {
400- this . context . clearRect ( 0 , 0 , this . width , this . height ) ;
401- } ;
402-
403- /**
404- * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height
405- *
406- * @method resize
407- * @param width {Number} the new width of the canvas
408- * @param height {Number} the new height of the canvas
409- * @private
410- */
234+ PIXI . blendModesCanvas = [ ] ;
411235
412- PIXI . CanvasBuffer . prototype . resize = function ( width , height )
413- {
414- this . width = this . canvas . width = width ;
415- this . height = this . canvas . height = height ;
236+ if ( PIXI . canUseNewCanvasBlendModes ( ) )
237+ {
238+ PIXI . blendModesCanvas [ PIXI . blendModes . NORMAL ] = "source-over" ;
239+ PIXI . blendModesCanvas [ PIXI . blendModes . ADD ] = "lighter" ; //IS THIS OK???
240+ PIXI . blendModesCanvas [ PIXI . blendModes . MULTIPLY ] = "multiply" ;
241+ PIXI . blendModesCanvas [ PIXI . blendModes . SCREEN ] = "screen" ;
242+ PIXI . blendModesCanvas [ PIXI . blendModes . OVERLAY ] = "overlay" ;
243+ PIXI . blendModesCanvas [ PIXI . blendModes . DARKEN ] = "darken" ;
244+ PIXI . blendModesCanvas [ PIXI . blendModes . LIGHTEN ] = "lighten" ;
245+ PIXI . blendModesCanvas [ PIXI . blendModes . COLOR_DODGE ] = "color-dodge" ;
246+ PIXI . blendModesCanvas [ PIXI . blendModes . COLOR_BURN ] = "color-burn" ;
247+ PIXI . blendModesCanvas [ PIXI . blendModes . HARD_LIGHT ] = "hard-light" ;
248+ PIXI . blendModesCanvas [ PIXI . blendModes . SOFT_LIGHT ] = "soft-light" ;
249+ PIXI . blendModesCanvas [ PIXI . blendModes . DIFFERENCE ] = "difference" ;
250+ PIXI . blendModesCanvas [ PIXI . blendModes . EXCLUSION ] = "exclusion" ;
251+ PIXI . blendModesCanvas [ PIXI . blendModes . HUE ] = "hue" ;
252+ PIXI . blendModesCanvas [ PIXI . blendModes . SATURATION ] = "saturation" ;
253+ PIXI . blendModesCanvas [ PIXI . blendModes . COLOR ] = "color" ;
254+ PIXI . blendModesCanvas [ PIXI . blendModes . LUMINOSITY ] = "luminosity" ;
255+ }
256+ else
257+ {
258+ // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough"
259+ PIXI . blendModesCanvas [ PIXI . blendModes . NORMAL ] = "source-over" ;
260+ PIXI . blendModesCanvas [ PIXI . blendModes . ADD ] = "lighter" ; //IS THIS OK???
261+ PIXI . blendModesCanvas [ PIXI . blendModes . MULTIPLY ] = "source-over" ;
262+ PIXI . blendModesCanvas [ PIXI . blendModes . SCREEN ] = "source-over" ;
263+ PIXI . blendModesCanvas [ PIXI . blendModes . OVERLAY ] = "source-over" ;
264+ PIXI . blendModesCanvas [ PIXI . blendModes . DARKEN ] = "source-over" ;
265+ PIXI . blendModesCanvas [ PIXI . blendModes . LIGHTEN ] = "source-over" ;
266+ PIXI . blendModesCanvas [ PIXI . blendModes . COLOR_DODGE ] = "source-over" ;
267+ PIXI . blendModesCanvas [ PIXI . blendModes . COLOR_BURN ] = "source-over" ;
268+ PIXI . blendModesCanvas [ PIXI . blendModes . HARD_LIGHT ] = "source-over" ;
269+ PIXI . blendModesCanvas [ PIXI . blendModes . SOFT_LIGHT ] = "source-over" ;
270+ PIXI . blendModesCanvas [ PIXI . blendModes . DIFFERENCE ] = "source-over" ;
271+ PIXI . blendModesCanvas [ PIXI . blendModes . EXCLUSION ] = "source-over" ;
272+ PIXI . blendModesCanvas [ PIXI . blendModes . HUE ] = "source-over" ;
273+ PIXI . blendModesCanvas [ PIXI . blendModes . SATURATION ] = "source-over" ;
274+ PIXI . blendModesCanvas [ PIXI . blendModes . COLOR ] = "source-over" ;
275+ PIXI . blendModesCanvas [ PIXI . blendModes . LUMINOSITY ] = "source-over" ;
276+ }
277+ }
416278} ;
417-
0 commit comments