@@ -628,6 +628,46 @@ this.createjs = this.createjs||{};
628628 typeof WebGLRenderingContext !== 'undefined' ;
629629 } ;
630630
631+ /**
632+ * Utility used to convert the colour values the Context2D API accepts into WebGL color values.
633+ * @param {String | Number } color
634+ * @static
635+ * @return {Object } Object with r, g, b, a in 0-1 values of the color.
636+ */
637+ StageGL . colorToObj = function ( color ) {
638+ var r , g , b , a ;
639+
640+ if ( typeof color === "string" ) {
641+ if ( color . indexOf ( "#" ) === 0 ) {
642+ if ( color . length === 4 ) {
643+ color = "#" + color . charAt ( 1 ) + color . charAt ( 1 ) + color . charAt ( 2 ) + color . charAt ( 2 ) + color . charAt ( 3 ) + color . charAt ( 3 )
644+ }
645+ r = Number ( "0x" + color . slice ( 1 , 3 ) ) / 255 ;
646+ g = Number ( "0x" + color . slice ( 3 , 5 ) ) / 255 ;
647+ b = Number ( "0x" + color . slice ( 5 , 7 ) ) / 255 ;
648+ a = color . length > 7 ? Number ( "0x" + color . slice ( 7 , 9 ) ) / 255 : 1 ;
649+ } else if ( color . indexOf ( "rgba(" ) === 0 ) {
650+ var output = color . slice ( 5 , - 1 ) . split ( "," ) ;
651+ r = Number ( output [ 0 ] ) / 255 ;
652+ g = Number ( output [ 1 ] ) / 255 ;
653+ b = Number ( output [ 2 ] ) / 255 ;
654+ a = Number ( output [ 3 ] ) ;
655+ }
656+ } else { // >>> is an unsigned shift which is what we want as 0x80000000 and up are negative values
657+ r = ( ( color & 0xFF000000 ) >>> 24 ) / 255 ;
658+ g = ( ( color & 0x00FF0000 ) >>> 16 ) / 255 ;
659+ b = ( ( color & 0x0000FF00 ) >>> 8 ) / 255 ;
660+ a = ( color & 0x000000FF ) / 255 ;
661+ }
662+
663+ return {
664+ r : Math . min ( Math . max ( 0 , r ) , 1 ) ,
665+ g : Math . min ( Math . max ( 0 , g ) , 1 ) ,
666+ b : Math . min ( Math . max ( 0 , b ) , 1 ) ,
667+ a : Math . min ( Math . max ( 0 , a ) , 1 )
668+ }
669+ } ;
670+
631671// static properties:
632672 /**
633673 * The number of properties defined per vertex (x, y, textureU, textureV, textureIndex, alpha)
@@ -1172,7 +1212,7 @@ this.createjs = this.createjs||{};
11721212
11731213 "hue" : {
11741214 shader : ( StageGL . BLEND_FRAGMENT_HSL_UTIL + StageGL . BLEND_FRAGMENT_COMPLEX +
1175- "setLum(setSat(srcClr, getSat(dstClr)), getLum(dstClr))"
1215+ "setLum(setSat(srcClr, getSat(dstClr)), getLum(dstClr))"
11761216 + StageGL . BLEND_FRAGMENT_COMPLEX_CAP )
11771217 } ,
11781218 "saturation" : {
@@ -1410,6 +1450,12 @@ this.createjs = this.createjs||{};
14101450 return false ;
14111451 }
14121452
1453+ for ( var i = 0 ; i < this . _gpuTextureCount ; i ++ ) {
1454+ if ( this . _batchTextures [ i ] . _frameBuffer ) {
1455+ this . _batchTextures [ i ] = this . _baseTextures [ i ] ;
1456+ }
1457+ }
1458+
14131459 var storeBatchOutput = this . _batchTextureOutput ;
14141460 var storeBatchConcat = this . _batchTextureConcat ;
14151461 var storeBatchTemp = this . _batchTextureTemp ;
@@ -1754,35 +1800,64 @@ this.createjs = this.createjs||{};
17541800 * @param {String|int } [color=0x00000000] The new color to use as the background
17551801 */
17561802 p . setClearColor = function ( color ) {
1757- var r , g , b , a , output ;
1803+ this . _clearColor = StageGL . colorToObj ( color ) ;
1804+ } ;
17581805
1759- if ( typeof color === "string" ) {
1760- if ( color . indexOf ( "#" ) === 0 ) {
1761- if ( color . length === 4 ) {
1762- color = "#" + color . charAt ( 1 ) + color . charAt ( 1 ) + color . charAt ( 2 ) + color . charAt ( 2 ) + color . charAt ( 3 ) + color . charAt ( 3 )
1763- }
1764- r = Number ( "0x" + color . slice ( 1 , 3 ) ) / 255 ;
1765- g = Number ( "0x" + color . slice ( 3 , 5 ) ) / 255 ;
1766- b = Number ( "0x" + color . slice ( 5 , 7 ) ) / 255 ;
1767- a = Number ( "0x" + color . slice ( 7 , 9 ) ) / 255 ;
1768- } else if ( color . indexOf ( "rgba(" ) === 0 ) {
1769- output = color . slice ( 5 , - 1 ) . split ( "," ) ;
1770- r = Number ( output [ 0 ] ) / 255 ;
1771- g = Number ( output [ 1 ] ) / 255 ;
1772- b = Number ( output [ 2 ] ) / 255 ;
1773- a = Number ( output [ 3 ] ) ;
1806+ /**
1807+ * Returns a data url that contains a Base64-encoded image of the contents of the stage. The returned data url can
1808+ * be specified as the src value of an image element. StageGL renders differently than Context2D and the information
1809+ * of the last render is harder to get. For best results turn directDraw to false, or preserveBuffer to true and no
1810+ * backgorund color.
1811+ * @method toDataURL
1812+ * @param {String } [backgroundColor=undefined] The background color to be used for the generated image. See setClearColor
1813+ * for valid values. A value of undefined will make no adjustments to the existing background which may be significantly faster.
1814+ * @param {String } [mimeType="image/png"] The MIME type of the image format to be create. The default is "image/png". If an unknown MIME type
1815+ * is passed in, or if the browser does not support the specified MIME type, the default value will be used.
1816+ * @return {String } a Base64 encoded image.
1817+ **/
1818+ p . toDataURL = function ( backgroundColor , mimeType ) {
1819+ var dataURL , gl = this . _webGLContext ;
1820+ this . batchReason = "dataURL" ;
1821+ var clearBackup = this . _clearColor ;
1822+
1823+ if ( ! this . canvas ) { return ; }
1824+ if ( ! StageGL . isWebGLActive ( gl ) ) {
1825+ return this . Stage_toDataURL ( backgroundColor , mimeType ) ;
1826+ }
1827+
1828+ // if the buffer is preserved and we don't want a background we can just output what we have, otherwise we'll have to render it
1829+ if ( ! this . _preserveBuffer || backgroundColor !== undefined ) {
1830+ // render it onto the right background
1831+ if ( backgroundColor !== undefined ) {
1832+ this . _clearColor = StageGL . colorToObj ( backgroundColor ) ;
1833+ }
1834+ this . clear ( ) ;
1835+ // if we're not using directDraw then we can just trust the last buffer content
1836+ if ( ! this . _directDraw ) {
1837+ this . _drawCover ( null , this . _bufferTextureOutput ) ;
1838+ } else {
1839+ console . log ( "No stored/useable gl render info, result may be incorrect if content was changed since render" ) ;
1840+ this . draw ( gl ) ;
17741841 }
1775- } else { // >>> is an unsigned shift which is what we want as 0x80000000 and up are negative values
1776- r = ( ( color & 0xFF000000 ) >>> 24 ) / 255 ;
1777- g = ( ( color & 0x00FF0000 ) >>> 16 ) / 255 ;
1778- b = ( ( color & 0x0000FF00 ) >>> 8 ) / 255 ;
1779- a = ( color & 0x000000FF ) / 255 ;
17801842 }
17811843
1782- this . _clearColor . r = r || 0 ;
1783- this . _clearColor . g = g || 0 ;
1784- this . _clearColor . b = b || 0 ;
1785- this . _clearColor . a = a || 0 ;
1844+ // create the dataurl
1845+ dataURL = this . canvas . toDataURL ( mimeType || "image/png" ) ;
1846+
1847+ // reset the picture in the canvas
1848+ if ( ! this . _preserveBuffer || backgroundColor !== undefined ) {
1849+ if ( backgroundColor !== undefined ) {
1850+ this . _clearColor = clearBackup ;
1851+ }
1852+ this . clear ( ) ;
1853+ if ( ! this . _directDraw ) {
1854+ this . _drawCover ( null , this . _bufferTextureOutput ) ;
1855+ } else {
1856+ this . draw ( gl ) ;
1857+ }
1858+ }
1859+
1860+ return dataURL ;
17861861 } ;
17871862
17881863 // Docced in subclass
@@ -2582,7 +2657,8 @@ this.createjs = this.createjs||{};
25822657 continue ;
25832658 }
25842659
2585- if ( item . compositeOperation !== null ) {
2660+ var containerRenderMode = this . _renderMode ;
2661+ if ( item . compositeOperation ) {
25862662 this . _updateRenderMode ( item . compositeOperation ) ;
25872663 }
25882664
@@ -2727,6 +2803,10 @@ this.createjs = this.createjs||{};
27272803 if ( this . _immediateRender ) {
27282804 this . _immediateBatchRender ( ) ;
27292805 }
2806+
2807+ if ( this . _renderMode !== containerRenderMode ) {
2808+ this . _updateRenderMode ( containerRenderMode ) ;
2809+ }
27302810 }
27312811
27322812 if ( this . _renderMode !== previousRenderMode ) {
0 commit comments