@@ -6831,7 +6831,7 @@ this.createjs = this.createjs||{};
68316831 * @return {String} The image data url for the cache.
68326832 **/
68336833 p.getCacheDataURL = function() {
6834- return this.bitmapCache?this.bitmapCache.getDataURL ():null;
6834+ return this.bitmapCache?this.bitmapCache.getCacheDataURL ():null;
68356835 };
68366836
68376837 /**
@@ -9461,6 +9461,46 @@ this.createjs = this.createjs||{};
94619461 typeof WebGLRenderingContext !== 'undefined';
94629462 };
94639463
9464+ /**
9465+ * Utility used to convert the colour values the Context2D API accepts into WebGL color values.
9466+ * @param {String | Number} color
9467+ * @static
9468+ * @return {Object} Object with r, g, b, a in 0-1 values of the color.
9469+ */
9470+ StageGL.colorToObj = function (color) {
9471+ var r, g, b, a;
9472+
9473+ if (typeof color === "string") {
9474+ if (color.indexOf("#") === 0) {
9475+ if (color.length === 4) {
9476+ color = "#" + color.charAt(1)+color.charAt(1) + color.charAt(2)+color.charAt(2) + color.charAt(3)+color.charAt(3)
9477+ }
9478+ r = Number("0x"+color.slice(1, 3))/255;
9479+ g = Number("0x"+color.slice(3, 5))/255;
9480+ b = Number("0x"+color.slice(5, 7))/255;
9481+ a = color.length > 7 ? Number("0x"+color.slice(7, 9))/255 : 1;
9482+ } else if (color.indexOf("rgba(") === 0) {
9483+ var output = color.slice(5, -1).split(",");
9484+ r = Number(output[0])/255;
9485+ g = Number(output[1])/255;
9486+ b = Number(output[2])/255;
9487+ a = Number(output[3]);
9488+ }
9489+ } else { // >>> is an unsigned shift which is what we want as 0x80000000 and up are negative values
9490+ r = ((color & 0xFF000000) >>> 24)/255;
9491+ g = ((color & 0x00FF0000) >>> 16)/255;
9492+ b = ((color & 0x0000FF00) >>> 8)/255;
9493+ a = (color & 0x000000FF)/255;
9494+ }
9495+
9496+ return {
9497+ r: Math.min(Math.max(0, r), 1),
9498+ g: Math.min(Math.max(0, g), 1),
9499+ b: Math.min(Math.max(0, b), 1),
9500+ a: Math.min(Math.max(0, a), 1)
9501+ }
9502+ };
9503+
94649504// static properties:
94659505 /**
94669506 * The number of properties defined per vertex (x, y, textureU, textureV, textureIndex, alpha)
@@ -10005,7 +10045,7 @@ this.createjs = this.createjs||{};
1000510045
1000610046 "hue": {
1000710047 shader: (StageGL.BLEND_FRAGMENT_HSL_UTIL + StageGL.BLEND_FRAGMENT_COMPLEX +
10008- "setLum(setSat(srcClr, getSat(dstClr)), getLum(dstClr))"
10048+ "setLum(setSat(srcClr, getSat(dstClr)), getLum(dstClr))"
1000910049 + StageGL.BLEND_FRAGMENT_COMPLEX_CAP)
1001010050 },
1001110051 "saturation": {
@@ -10243,6 +10283,12 @@ this.createjs = this.createjs||{};
1024310283 return false;
1024410284 }
1024510285
10286+ for (var i = 0; i < this._gpuTextureCount; i++) {
10287+ if(this._batchTextures[i]._frameBuffer) {
10288+ this._batchTextures[i] = this._baseTextures[i];
10289+ }
10290+ }
10291+
1024610292 var storeBatchOutput = this._batchTextureOutput;
1024710293 var storeBatchConcat = this._batchTextureConcat;
1024810294 var storeBatchTemp = this._batchTextureTemp;
@@ -10587,35 +10633,64 @@ this.createjs = this.createjs||{};
1058710633 * @param {String|int} [color=0x00000000] The new color to use as the background
1058810634 */
1058910635 p.setClearColor = function (color) {
10590- var r, g, b, a, output;
10636+ this._clearColor = StageGL.colorToObj(color);
10637+ };
1059110638
10592- if (typeof color === "string") {
10593- if (color.indexOf("#") === 0) {
10594- if (color.length === 4) {
10595- color = "#" + color.charAt(1)+color.charAt(1) + color.charAt(2)+color.charAt(2) + color.charAt(3)+color.charAt(3)
10596- }
10597- r = Number("0x"+color.slice(1, 3))/255;
10598- g = Number("0x"+color.slice(3, 5))/255;
10599- b = Number("0x"+color.slice(5, 7))/255;
10600- a = Number("0x"+color.slice(7, 9))/255;
10601- } else if (color.indexOf("rgba(") === 0) {
10602- output = color.slice(5, -1).split(",");
10603- r = Number(output[0])/255;
10604- g = Number(output[1])/255;
10605- b = Number(output[2])/255;
10606- a = Number(output[3]);
10639+ /**
10640+ * Returns a data url that contains a Base64-encoded image of the contents of the stage. The returned data url can
10641+ * be specified as the src value of an image element. StageGL renders differently than Context2D and the information
10642+ * of the last render is harder to get. For best results turn directDraw to false, or preserveBuffer to true and no
10643+ * backgorund color.
10644+ * @method toDataURL
10645+ * @param {String} [backgroundColor=undefined] The background color to be used for the generated image. See setClearColor
10646+ * for valid values. A value of undefined will make no adjustments to the existing background which may be significantly faster.
10647+ * @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
10648+ * is passed in, or if the browser does not support the specified MIME type, the default value will be used.
10649+ * @return {String} a Base64 encoded image.
10650+ **/
10651+ p.toDataURL = function(backgroundColor, mimeType) {
10652+ var dataURL, gl = this._webGLContext;
10653+ this.batchReason = "dataURL";
10654+ var clearBackup = this._clearColor;
10655+
10656+ if (!this.canvas) { return; }
10657+ if (!StageGL.isWebGLActive(gl)) {
10658+ return this.Stage_toDataURL(backgroundColor, mimeType);
10659+ }
10660+
10661+ // 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
10662+ if(!this._preserveBuffer || backgroundColor !== undefined) {
10663+ // render it onto the right background
10664+ if(backgroundColor !== undefined) {
10665+ this._clearColor = StageGL.colorToObj(backgroundColor);
10666+ }
10667+ this.clear();
10668+ // if we're not using directDraw then we can just trust the last buffer content
10669+ if(!this._directDraw) {
10670+ this._drawCover(null, this._bufferTextureOutput);
10671+ } else {
10672+ console.log("No stored/useable gl render info, result may be incorrect if content was changed since render");
10673+ this.draw(gl);
1060710674 }
10608- } else { // >>> is an unsigned shift which is what we want as 0x80000000 and up are negative values
10609- r = ((color & 0xFF000000) >>> 24)/255;
10610- g = ((color & 0x00FF0000) >>> 16)/255;
10611- b = ((color & 0x0000FF00) >>> 8)/255;
10612- a = (color & 0x000000FF)/255;
1061310675 }
1061410676
10615- this._clearColor.r = r || 0;
10616- this._clearColor.g = g || 0;
10617- this._clearColor.b = b || 0;
10618- this._clearColor.a = a || 0;
10677+ // create the dataurl
10678+ dataURL = this.canvas.toDataURL(mimeType||"image/png");
10679+
10680+ // reset the picture in the canvas
10681+ if(!this._preserveBuffer || backgroundColor !== undefined) {
10682+ if(backgroundColor !== undefined) {
10683+ this._clearColor = clearBackup;
10684+ }
10685+ this.clear();
10686+ if(!this._directDraw) {
10687+ this._drawCover(null, this._bufferTextureOutput);
10688+ } else {
10689+ this.draw(gl);
10690+ }
10691+ }
10692+
10693+ return dataURL;
1061910694 };
1062010695
1062110696 // Docced in subclass
@@ -11415,7 +11490,8 @@ this.createjs = this.createjs||{};
1141511490 continue;
1141611491 }
1141711492
11418- if (item.compositeOperation !== null) {
11493+ var containerRenderMode = this._renderMode;
11494+ if (item.compositeOperation) {
1141911495 this._updateRenderMode(item.compositeOperation);
1142011496 }
1142111497
@@ -11560,6 +11636,10 @@ this.createjs = this.createjs||{};
1156011636 if (this._immediateRender) {
1156111637 this._immediateBatchRender();
1156211638 }
11639+
11640+ if (this._renderMode !== containerRenderMode) {
11641+ this._updateRenderMode(containerRenderMode);
11642+ }
1156311643 }
1156411644
1156511645 if (this._renderMode !== previousRenderMode) {
@@ -15557,8 +15637,8 @@ this.createjs = this.createjs||{};
1555715637 p.getBounds = function() {
1555815638 var scale = this.scale;
1555915639 return this._boundRect.setValues(
15560- this._filterOffX/scale , this._filterOffY/scale ,
15561- this.width/scale, this.height/scale
15640+ this.x , this.y ,
15641+ this.width/scale, this.height/scale
1556215642 );
1556315643 };
1556415644
@@ -17541,6 +17621,6 @@ this.createjs = this.createjs || {};
1754117621 * @type String
1754217622 * @static
1754317623 **/
17544- s.buildDate = /*=date*/"Wed, 23 May 2018 21:52 :20 GMT"; // injected by build process
17624+ s.buildDate = /*=date*/"Thu, 14 Jun 2018 21:18 :20 GMT"; // injected by build process
1754517625
1754617626})();
0 commit comments