@@ -50,6 +50,8 @@ this.createjs = this.createjs||{};
5050 * Render___: actual WebGL draw call
5151 * Buffer: WebGL array data
5252 * Cover: A card that covers the entire viewport
53+ * Dst: The existing drawing surface in the shader
54+ * Src: The new data being provided in the shader
5355 *
5456 * - Notes:
5557 * WebGL treats 0,0 as the bottom left, as such there's a lot of co-ordinate space flipping to make regular canvas
@@ -814,7 +816,7 @@ this.createjs = this.createjs||{};
814816 "{{alternates}}" +
815817 "}" +
816818
817- "gl_FragColor = vec4(color.rgb, color.a * alphaValue);" +
819+ "gl_FragColor = vec4(color.rgb * alphaValue , color.a * alphaValue);" +
818820 "}"
819821 ) ;
820822
@@ -1414,7 +1416,7 @@ this.createjs = this.createjs||{};
14141416
14151417 var filterCount = manager . _filterCount , filtersLeft = filterCount ;
14161418 var backupWidth = this . _viewportWidth , backupHeight = this . _viewportHeight ;
1417- this . updateViewport ( manager . _drawWidth , manager . _drawHeight ) ;
1419+ this . _updateDrawingSurface ( manager . _drawWidth , manager . _drawHeight ) ;
14181420
14191421 this . _batchTextureOutput = ( manager . _filterCount % 2 ) ? manager . _bufferTextureConcat : manager . _bufferTextureOutput ;
14201422 this . _batchTextureConcat = ( manager . _filterCount % 2 ) ? manager . _bufferTextureOutput : manager . _bufferTextureConcat ;
@@ -1455,7 +1457,7 @@ this.createjs = this.createjs||{};
14551457 this . _batchTextureConcat = storeBatchConcat ;
14561458 this . _batchTextureTemp = storeBatchTemp ;
14571459
1458- this . updateViewport ( backupWidth , backupHeight ) ;
1460+ this . _updateDrawingSurface ( backupWidth , backupHeight ) ;
14591461 return true ;
14601462 } ;
14611463
@@ -1575,32 +1577,19 @@ this.createjs = this.createjs||{};
15751577 * @param {int } height The height of the render surface in pixels.
15761578 */
15771579 p . updateViewport = function ( width , height ) {
1578- this . _viewportWidth = width | 0 ;
1579- this . _viewportHeight = height | 0 ;
1580- var gl = this . _webGLContext ;
1580+ width = Math . abs ( width | 0 ) || 1 ;
1581+ height = Math . abs ( height | 0 ) || 1 ;
15811582
1582- if ( gl ) {
1583- gl . viewport ( 0 , 0 , this . _viewportWidth , this . _viewportHeight ) ;
1584-
1585- // WebGL works with a -1,1 space on its screen. It also follows Y-Up
1586- // we need to flip the y, scale and then translate the co-ordinates to match this
1587- // additionally we offset into they Y so the polygons are inside the camera's "clipping" plane
1588- this . _projectionMatrix = new Float32Array ( [
1589- 2 / this . _viewportWidth , 0 , 0 , 0 ,
1590- 0 , - 2 / this . _viewportHeight , 0 , 0 ,
1591- 0 , 0 , 1 , 0 ,
1592- - 1 , 1 , 0 , 1
1593- ] ) ;
1594-
1595- if ( this . _bufferTextureOutput !== this && this . _bufferTextureOutput !== null ) {
1596- this . resizeTexture ( this . _bufferTextureOutput , this . _viewportWidth , this . _viewportHeight ) ;
1597- }
1598- if ( this . _bufferTextureConcat !== null ) {
1599- this . resizeTexture ( this . _bufferTextureConcat , this . _viewportWidth , this . _viewportHeight ) ;
1600- }
1601- if ( this . _bufferTextureTemp !== null ) {
1602- this . resizeTexture ( this . _bufferTextureTemp , this . _viewportWidth , this . _viewportHeight ) ;
1603- }
1583+ this . _updateDrawingSurface ( width , height ) ;
1584+
1585+ if ( this . _bufferTextureOutput !== this && this . _bufferTextureOutput !== null ) {
1586+ this . resizeTexture ( this . _bufferTextureOutput , this . _viewportWidth , this . _viewportHeight ) ;
1587+ }
1588+ if ( this . _bufferTextureConcat !== null ) {
1589+ this . resizeTexture ( this . _bufferTextureConcat , this . _viewportWidth , this . _viewportHeight ) ;
1590+ }
1591+ if ( this . _bufferTextureTemp !== null ) {
1592+ this . resizeTexture ( this . _bufferTextureTemp , this . _viewportWidth , this . _viewportHeight ) ;
16041593 }
16051594 } ;
16061595
@@ -1802,6 +1791,29 @@ this.createjs = this.createjs||{};
18021791 } ;
18031792
18041793// private methods:
1794+ /**
1795+ * Changes the active drawing surface and view matrix to the correct parameters without polluting the concept
1796+ * of the current stage size
1797+ * @param {uint } w The width of the surface in pixels, defaults to _viewportWidth
1798+ * @param {uint } h The height of the surface in pixels, defaults to _viewportHeight
1799+ */
1800+ p . _updateDrawingSurface = function ( w , h ) {
1801+ this . _viewportWidth = w ;
1802+ this . _viewportHeight = h ;
1803+
1804+ this . _webGLContext . viewport ( 0 , 0 , this . _viewportWidth , this . _viewportHeight ) ;
1805+
1806+ // WebGL works with a -1,1 space on its screen. It also follows Y-Up
1807+ // we need to flip the y, scale and then translate the co-ordinates to match this
1808+ // additionally we offset into they Y so the polygons are inside the camera's "clipping" plane
1809+ this . _projectionMatrix = new Float32Array ( [
1810+ 2 / w , 0 , 0 , 0 ,
1811+ 0 , - 2 / h , 0 , 0 ,
1812+ 0 , 0 , 1 , 0 ,
1813+ - 1 , 1 , 0 , 1
1814+ ] ) ;
1815+ } ;
1816+
18051817 /**
18061818 * Returns a base texture that has no image or data loaded. Not intended for loading images. In some error cases,
18071819 * the texture creation will fail. This function differs from {{#crossLink "StageGL/getBaseTexture"}}{{/crossLink}}
@@ -2534,6 +2546,7 @@ this.createjs = this.createjs||{};
25342546 var useCache = ( ! ignoreCache && item . cacheCanvas ) || false ;
25352547
25362548 if ( ! ( item . visible && concatAlpha > 0.0035 ) ) { continue ; }
2549+ var itemAlpha = item . alpha ;
25372550
25382551 if ( useCache === false ) {
25392552 if ( item . _updateState ) {
@@ -2551,19 +2564,21 @@ this.createjs = this.createjs||{};
25512564 this . batchReason = "cachelessFilterInterupt" ;
25522565 this . _renderBatch ( ) ; // <----------------------------------------------------
25532566
2567+ item . alpha = 1 ;
25542568 var shaderBackup = this . _activeShader ;
25552569 bounds = bounds || item . getBounds ( ) ;
25562570 item . bitmapCache . define ( item , bounds . x , bounds . y , bounds . width , bounds . height , 1 , { useGL :this } ) ;
25572571 useCache = item . bitmapCache . _cacheCanvas ;
25582572
2573+ item . alpha = itemAlpha ;
25592574 this . _activeShader = shaderBackup ;
25602575 gl . bindFramebuffer ( gl . FRAMEBUFFER , this . _batchTextureOutput . _frameBuffer ) ;
25612576 }
25622577 }
25632578 }
25642579
25652580 if ( useCache === false && item . children ) {
2566- this . _appendToBatch ( item , cMtx , item . alpha * concatAlpha ) ;
2581+ this . _appendToBatch ( item , cMtx , itemAlpha * concatAlpha ) ;
25672582 continue ;
25682583 }
25692584
@@ -2705,7 +2720,7 @@ this.createjs = this.createjs||{};
27052720 texI [ offV1 ] = texI [ offV1 + 1 ] = texI [ offV1 + 2 ] = texI [ offV1 + 3 ] = texI [ offV1 + 4 ] = texI [ offV1 + 5 ] = texIndex ;
27062721
27072722 // apply alpha
2708- alphas [ offV1 ] = alphas [ offV1 + 1 ] = alphas [ offV1 + 2 ] = alphas [ offV1 + 3 ] = alphas [ offV1 + 4 ] = alphas [ offV1 + 5 ] = item . alpha * concatAlpha ;
2723+ alphas [ offV1 ] = alphas [ offV1 + 1 ] = alphas [ offV1 + 2 ] = alphas [ offV1 + 3 ] = alphas [ offV1 + 4 ] = alphas [ offV1 + 5 ] = itemAlpha * concatAlpha ;
27092724
27102725 this . _batchVertexCount += StageGL . INDICIES_PER_CARD ;
27112726
@@ -2796,10 +2811,8 @@ this.createjs = this.createjs||{};
27962811 gl . uniformMatrix4fv ( shaderProgram . pMatrixUniform , gl . FALSE , this . _projectionMatrix ) ;
27972812
27982813 for ( var i = 0 ; i < this . _batchTextureCount ; i ++ ) {
2799- var texture = this . _batchTextures [ i ] ;
28002814 gl . activeTexture ( gl . TEXTURE0 + i ) ;
2801- gl . bindTexture ( gl . TEXTURE_2D , texture ) ;
2802- this . setTextureParams ( gl , texture . isPOT ) ;
2815+ gl . bindTexture ( gl . TEXTURE_2D , this . _batchTextures [ i ] ) ;
28032816 }
28042817
28052818 gl . drawArrays ( gl . TRIANGLES , 0 , this . _batchVertexCount ) ;
0 commit comments