@@ -311,15 +311,6 @@ this.createjs = this.createjs||{};
311311 */
312312 this . _vertices = null ;
313313
314- /**
315- * The WebGL vertex attribute buffer attached to {{#crossLink "StageGL/_vertices:property"}}{{/crossLink}}.
316- * @property _vertexPositionAttribute
317- * @protected
318- * @type {WebGLBuffer }
319- * @default null
320- */
321- this . _vertexPositionAttribute = null ;
322-
323314 /**
324315 * The vertex UV data for the current draw call.
325316 * @property _uvs
@@ -329,15 +320,6 @@ this.createjs = this.createjs||{};
329320 */
330321 this . _uvs = null ;
331322
332- /**
333- * The WebGL vertex attribute buffer attached to {{#crossLink "StageGL/_uvs:property"}}{{/crossLink}}.
334- * @property _uvPositionAttribute
335- * @protected
336- * @type {WebGLBuffer }
337- * @default null
338- */
339- this . _uvPositionAttribute = null ;
340-
341323 /**
342324 * The vertex indices data for the current draw call.
343325 * @property _indices
@@ -347,15 +329,6 @@ this.createjs = this.createjs||{};
347329 */
348330 this . _indices = null ;
349331
350- /**
351- * The WebGL vertex attribute buffer attached to {{#crossLink "StageGL/_indices:property"}}{{/crossLink}}.
352- * @property _textureIndexAttribute
353- * @protected
354- * @type {WebGLBuffer }
355- * @default null
356- */
357- this . _textureIndexAttribute = null ;
358-
359332 /**
360333 * The vertices data for the current draw call.
361334 * @property _alphas
@@ -365,15 +338,6 @@ this.createjs = this.createjs||{};
365338 */
366339 this . _alphas = null ;
367340
368- /**
369- * The WebGL vertex attribute buffer attached to {{#crossLink "StageGL/_alphas:property"}}{{/crossLink}}.
370- * @property _alphaAttribute
371- * @protected
372- * @type {WebGLBuffer }
373- * @default null
374- */
375- this . _alphaAttribute = null ;
376-
377341 /**
378342 * All the different vertex attribute sets that can be used with the render buffer. Currently only internal,
379343 * if/when alternate main shaders are possible, they'll register themselves here.
@@ -383,6 +347,14 @@ this.createjs = this.createjs||{};
383347 */
384348 this . _attributeConfig = { } ;
385349
350+ /**
351+ * Which of the configs in {{#crossLink "StageGL/_attributeConfig:property"}}{{/crossLink}} is currently active.
352+ * @property _activeConfig
353+ * @protected
354+ * @type {Object }
355+ */
356+ this . _activeConfig = null ;
357+
386358 /**
387359 * One of the major render buffers used in composite blending drawing. Do not expect this to always be the same object.
388360 * "What you're drawing to", object occasionally swaps with concat.
@@ -2137,73 +2109,61 @@ this.createjs = this.createjs||{};
21372109 p . _createBuffers = function ( ) {
21382110 var gl = this . _webGLContext ;
21392111 var groupCount = this . _maxBatchVertexCount ;
2140- var groupSize , i , l , config , atrBuffer , stride ;
2141-
2142- // INFO:
2143- // all buffers are created using this pattern
2144- // create a WebGL buffer
2145- // attach it to context
2146- // figure out how many parts it has to an entry
2147- // fill it with empty data to reserve the memory
2148- // attach the empty data to the GPU
2149- // track the sizes on the buffer object
2150-
2151- // INFO:
2152- // a single buffer may be optimal in some situations and would be approached like this,
2153- // currently not implemented due to lack of need and potential complications with drawCover
2154-
2155- // var vertexBuffer = this._vertexBuffer = gl.createBuffer();
2156- // gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
2157- // groupSize = 2 + 2 + 1 + 1; //{x,y}, {u,v}, index, alpha
2158- // var vertexData = this._vertexData = new Float32Array(groupCount * groupSize);
2159- // for (i=0; i<vertexData.length; i+=groupSize) {
2160- // vertexData[i+0] = vertexData[i+1] = 0;
2161- // vertexData[i+2] = vertexData[i+3] = 0.5;
2162- // vertexData[i+4] = 0;
2163- // vertexData[i+5] = 1;
2164- // }
2165- // TODO benchmark and test using unified buffer
2112+ var groupSize , i , l , config , atrBuffer ;
2113+
2114+ // TODO benchmark and test using unified main buffer
21662115
21672116 config = this . _attributeConfig [ "default" ] = { } ;
2168- stride = 0 ;
21692117
21702118 // the actual position information
2171- atrBuffer = this . _vertexPositionAttribute = gl . createBuffer ( ) ;
2172- gl . bindBuffer ( gl . ARRAY_BUFFER , atrBuffer ) ;
2173- stride += 4 * ( groupSize = 2 ) ;
2174- var vertices = this . _vertices = new Float32Array ( groupCount * groupSize ) ;
2119+ groupSize = 2 ;
2120+ var vertices = new Float32Array ( groupCount * groupSize ) ;
21752121 for ( i = 0 , l = vertices . length ; i < l ; i += groupSize ) { vertices [ i ] = vertices [ i + 1 ] = 0 ; }
2122+ atrBuffer = gl . createBuffer ( ) ;
2123+ gl . bindBuffer ( gl . ARRAY_BUFFER , atrBuffer ) ;
21762124 gl . bufferData ( gl . ARRAY_BUFFER , vertices , gl . DYNAMIC_DRAW ) ;
2177- config [ "position" ] = { array : vertices , buffer : atrBuffer , offset : 0 , size : groupSize } ;
2125+ config [ "position" ] = { array : vertices ,
2126+ buffer : atrBuffer , type : gl . FLOAT , size : groupSize , spacing : groupSize , stride : 0 , offset : 0
2127+ } ;
21782128
21792129 // where on the texture it gets its information
2180- atrBuffer = this . _uvPositionAttribute = gl . createBuffer ( ) ;
2181- gl . bindBuffer ( gl . ARRAY_BUFFER , atrBuffer ) ;
2182- stride += 4 * ( groupSize = 2 ) ;
2183- var uvs = this . _uvs = new Float32Array ( groupCount * groupSize ) ;
2130+ groupSize = 2 ;
2131+ var uvs = new Float32Array ( groupCount * groupSize ) ;
21842132 for ( i = 0 , l = uvs . length ; i < l ; i += groupSize ) { uvs [ i ] = uvs [ i + 1 ] = 0 ; }
2133+ atrBuffer = gl . createBuffer ( ) ;
2134+ gl . bindBuffer ( gl . ARRAY_BUFFER , atrBuffer ) ;
21852135 gl . bufferData ( gl . ARRAY_BUFFER , uvs , gl . DYNAMIC_DRAW ) ;
2186- config [ "uv" ] = { array : uvs , buffer : atrBuffer , offset : 0 , size : groupSize } ;
2136+ config [ "uv" ] = { array : uvs ,
2137+ buffer : atrBuffer , type : gl . FLOAT , size : groupSize , spacing : groupSize , stride : 0 , offset : 0
2138+ } ;
21872139
21882140 // what texture it should use
2189- atrBuffer = this . _textureIndexAttribute = gl . createBuffer ( ) ;
2190- gl . bindBuffer ( gl . ARRAY_BUFFER , atrBuffer ) ;
2191- stride += 4 * ( groupSize = 1 ) ;
2192- var indices = this . _indices = new Float32Array ( groupCount * groupSize ) ;
2141+ groupSize = 1 ;
2142+ var indices = new Float32Array ( groupCount * groupSize ) ;
21932143 for ( i = 0 , l = indices . length ; i < l ; i ++ ) { indices [ i ] = 0 ; }
2144+ atrBuffer = gl . createBuffer ( ) ;
2145+ gl . bindBuffer ( gl . ARRAY_BUFFER , atrBuffer ) ;
21942146 gl . bufferData ( gl . ARRAY_BUFFER , indices , gl . DYNAMIC_DRAW ) ;
2195- config [ "texture" ] = { array : indices , buffer : atrBuffer , offset : 0 , size : groupSize } ;
2147+ config [ "texture" ] = { array : indices ,
2148+ buffer : atrBuffer , type : gl . FLOAT , size : groupSize , spacing : groupSize , stride : 0 , offset : 0
2149+ } ;
21962150
21972151 // what alpha it should have
2198- atrBuffer = this . _alphaAttribute = gl . createBuffer ( ) ;
2199- gl . bindBuffer ( gl . ARRAY_BUFFER , atrBuffer ) ;
2200- stride += 4 * ( groupSize = 1 ) ;
2201- var alphas = this . _alphas = new Float32Array ( groupCount * groupSize ) ;
2152+ groupSize = 1 ;
2153+ var alphas = new Float32Array ( groupCount * groupSize ) ;
22022154 for ( i = 0 , l = alphas . length ; i < l ; i ++ ) { alphas [ i ] = 1.0 ; }
2155+ atrBuffer = gl . createBuffer ( ) ;
2156+ gl . bindBuffer ( gl . ARRAY_BUFFER , atrBuffer ) ;
22032157 gl . bufferData ( gl . ARRAY_BUFFER , alphas , gl . DYNAMIC_DRAW ) ;
2204- config [ "alpha" ] = { array : alphas , buffer : atrBuffer , offset : 0 , size : groupSize } ;
2205-
2206- config [ "_shared_" ] = { stride : stride } ;
2158+ config [ "alpha" ] = { array : alphas ,
2159+ buffer : atrBuffer , type : gl . FLOAT , size : groupSize , spacing : groupSize , stride : 0 , offset : 0
2160+ } ;
2161+
2162+ this . _activeConfig = config ;
2163+ this . _vertices = vertices ;
2164+ this . _indices = indices ;
2165+ this . _alphas = alphas ;
2166+ this . _uvs = uvs ;
22072167 } ;
22082168
22092169 /**
@@ -2911,28 +2871,29 @@ this.createjs = this.createjs||{};
29112871 console . log ( "Batch[" + this . _drawID + ":" + this . _batchID + "] : " + this . batchReason ) ;
29122872 }
29132873 var shaderProgram = this . _activeShader ;
2914- var vertexPositionBuffer = this . _vertexPositionAttribute ;
2915- var textureIndexBuffer = this . _textureIndexAttribute ;
2916- var uvPositionBuffer = this . _uvPositionAttribute ;
2917- var alphaBuffer = this . _alphaAttribute ;
2874+ var pc , config = this . _activeConfig ;
29182875
29192876 gl . useProgram ( shaderProgram ) ;
29202877
2921- gl . bindBuffer ( gl . ARRAY_BUFFER , vertexPositionBuffer ) ;
2922- gl . vertexAttribPointer ( shaderProgram . positionAttribute , 2 , gl . FLOAT , false , 0 , 0 ) ;
2923- gl . bufferSubData ( gl . ARRAY_BUFFER , 0 , this . _vertices ) ;
2878+ pc = config . position ;
2879+ gl . bindBuffer ( gl . ARRAY_BUFFER , pc . buffer ) ;
2880+ gl . vertexAttribPointer ( shaderProgram . positionAttribute , pc . size , pc . type , false , pc . stride , pc . offset ) ;
2881+ gl . bufferSubData ( gl . ARRAY_BUFFER , 0 , pc . array ) ;
29242882
2925- gl . bindBuffer ( gl . ARRAY_BUFFER , textureIndexBuffer ) ;
2926- gl . vertexAttribPointer ( shaderProgram . textureIndexAttribute , 1 , gl . FLOAT , false , 0 , 0 ) ;
2927- gl . bufferSubData ( gl . ARRAY_BUFFER , 0 , this . _indices ) ;
2883+ pc = config . texture ;
2884+ gl . bindBuffer ( gl . ARRAY_BUFFER , pc . buffer ) ;
2885+ gl . vertexAttribPointer ( shaderProgram . textureIndexAttribute , pc . size , pc . type , false , pc . stride , pc . offset ) ;
2886+ gl . bufferSubData ( gl . ARRAY_BUFFER , 0 , pc . array ) ;
29282887
2929- gl . bindBuffer ( gl . ARRAY_BUFFER , uvPositionBuffer ) ;
2930- gl . vertexAttribPointer ( shaderProgram . uvPositionAttribute , 2 , gl . FLOAT , false , 0 , 0 ) ;
2931- gl . bufferSubData ( gl . ARRAY_BUFFER , 0 , this . _uvs ) ;
2888+ pc = config . uv ;
2889+ gl . bindBuffer ( gl . ARRAY_BUFFER , pc . buffer ) ;
2890+ gl . vertexAttribPointer ( shaderProgram . uvPositionAttribute , pc . size , pc . type , false , pc . stride , pc . offset ) ;
2891+ gl . bufferSubData ( gl . ARRAY_BUFFER , 0 , pc . array ) ;
29322892
2933- gl . bindBuffer ( gl . ARRAY_BUFFER , alphaBuffer ) ;
2934- gl . vertexAttribPointer ( shaderProgram . alphaAttribute , 1 , gl . FLOAT , false , 0 , 0 ) ;
2935- gl . bufferSubData ( gl . ARRAY_BUFFER , 0 , this . _alphas ) ;
2893+ pc = config . alpha ;
2894+ gl . bindBuffer ( gl . ARRAY_BUFFER , pc . buffer ) ;
2895+ gl . vertexAttribPointer ( shaderProgram . alphaAttribute , pc . size , pc . type , false , pc . stride , pc . offset ) ;
2896+ gl . bufferSubData ( gl . ARRAY_BUFFER , 0 , pc . array ) ;
29362897
29372898 gl . uniformMatrix4fv ( shaderProgram . pMatrixUniform , gl . FALSE , this . _projectionMatrix ) ;
29382899
@@ -2960,16 +2921,18 @@ this.createjs = this.createjs||{};
29602921 console . log ( "Cover[" + this . _drawID + ":" + this . _batchID + "] : " + this . batchReason ) ;
29612922 }
29622923 var shaderProgram = this . _activeShader ;
2963- var vertexPositionBuffer = this . _vertexPositionAttribute ;
2964- var uvPositionBuffer = this . _uvPositionAttribute ;
2924+ var pc , config = this . _attributeConfig . default ;
29652925
29662926 gl . useProgram ( shaderProgram ) ;
29672927
2968- gl . bindBuffer ( gl . ARRAY_BUFFER , vertexPositionBuffer ) ;
2969- gl . vertexAttribPointer ( shaderProgram . positionAttribute , 2 , gl . FLOAT , false , 0 , 0 ) ;
2928+ pc = config . position ;
2929+ gl . bindBuffer ( gl . ARRAY_BUFFER , pc . buffer ) ;
2930+ gl . vertexAttribPointer ( shaderProgram . positionAttribute , pc . size , pc . type , false , pc . stride , pc . offset ) ;
29702931 gl . bufferSubData ( gl . ARRAY_BUFFER , 0 , StageGL . COVER_VERT ) ;
2971- gl . bindBuffer ( gl . ARRAY_BUFFER , uvPositionBuffer ) ;
2972- gl . vertexAttribPointer ( shaderProgram . uvPositionAttribute , 2 , gl . FLOAT , false , 0 , 0 ) ;
2932+
2933+ pc = config . uv ;
2934+ gl . bindBuffer ( gl . ARRAY_BUFFER , pc . buffer ) ;
2935+ gl . vertexAttribPointer ( shaderProgram . uvPositionAttribute , pc . size , pc . type , false , pc . stride , pc . offset ) ;
29732936 gl . bufferSubData ( gl . ARRAY_BUFFER , 0 , StageGL . COVER_UV ) ;
29742937
29752938 gl . uniform1i ( shaderProgram . samplerUniform , 0 ) ;
0 commit comments