Skip to content

Commit ca99c45

Browse files
committed
Added reset property to Bind to get new vertex attrib locations
1 parent e4ec0bd commit ca99c45

6 files changed

Lines changed: 58 additions & 41 deletions

File tree

src/renderer/webgl/WebGLPipeline.js

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -277,33 +277,12 @@ var WebGLPipeline = new Class({
277277
*/
278278
boot: function ()
279279
{
280-
var gl = this.gl;
281-
var vertexBuffer = this.vertexBuffer;
282-
var attributes = this.attributes;
283-
var program = this.program;
284280
var renderer = this.renderer;
285-
var vertexSize = this.vertexSize;
286281

287-
renderer.setProgram(program);
288-
renderer.setVertexBuffer(vertexBuffer);
282+
renderer.setProgram(this.program);
283+
renderer.setVertexBuffer(this.vertexBuffer);
289284

290-
for (var i = 0; i < attributes.length; i++)
291-
{
292-
var element = attributes[i];
293-
var location = gl.getAttribLocation(program, element.name);
294-
295-
if (location >= 0)
296-
{
297-
gl.enableVertexAttribArray(location);
298-
gl.vertexAttribPointer(location, element.size, element.type, element.normalized, vertexSize, element.offset);
299-
element.enabled = true;
300-
element.location = location;
301-
}
302-
else if (location !== -1)
303-
{
304-
gl.disableVertexAttribArray(location);
305-
}
306-
}
285+
this.setAttribPointers(true);
307286

308287
this.hasBooted = true;
309288

@@ -404,18 +383,22 @@ var WebGLPipeline = new Class({
404383
* @method Phaser.Renderer.WebGL.WebGLPipeline#bind
405384
* @since 3.0.0
406385
*
386+
* @param {boolean} [reset=false] - Should the pipeline be fully re-bound after a renderer pipeline clear?
387+
*
407388
* @return {this} This WebGLPipeline instance.
408389
*/
409-
bind: function ()
390+
bind: function (reset)
410391
{
392+
if (reset === undefined) { reset = false; }
393+
411394
var vertexBuffer = this.vertexBuffer;
412395
var program = this.program;
413396
var renderer = this.renderer;
414397

415398
renderer.setProgram(program);
416399
renderer.setVertexBuffer(vertexBuffer);
417400

418-
this.setAttribPointers();
401+
this.setAttribPointers(reset);
419402

420403
return this;
421404
},
@@ -427,19 +410,40 @@ var WebGLPipeline = new Class({
427410
* @method Phaser.Renderer.WebGL.WebGLPipeline#setAttribPointers
428411
* @since 3.50.0
429412
*
413+
* @param {boolean} [reset=false] - Reset the vertex attribute locations?
414+
*
430415
* @return {this} This WebGLPipeline instance.
431416
*/
432-
setAttribPointers: function ()
417+
setAttribPointers: function (reset)
433418
{
419+
if (reset === undefined) { reset = false; }
420+
434421
var gl = this.gl;
435422
var attributes = this.attributes;
436423
var vertexSize = this.vertexSize;
424+
var program = this.program;
437425

438426
for (var i = 0; i < attributes.length; i++)
439427
{
440428
var element = attributes[i];
441429

442-
if (element.enabled)
430+
if (reset)
431+
{
432+
var location = gl.getAttribLocation(program, element.name);
433+
434+
if (location >= 0)
435+
{
436+
gl.enableVertexAttribArray(location);
437+
gl.vertexAttribPointer(location, element.size, element.type, element.normalized, vertexSize, element.offset);
438+
element.enabled = true;
439+
element.location = location;
440+
}
441+
else if (location !== -1)
442+
{
443+
gl.disableVertexAttribArray(location);
444+
}
445+
}
446+
else if (element.enabled)
443447
{
444448
gl.vertexAttribPointer(element.location, element.size, element.type, element.normalized, vertexSize, element.offset);
445449
}

src/renderer/webgl/WebGLRenderer.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,13 +1221,10 @@ var WebGLRenderer = new Class({
12211221

12221222
this.setBlendMode(0, true);
12231223

1224-
this.resetTextures(true);
1225-
1226-
this.currentActiveTexture = 1;
1227-
this.startActiveTexture++;
1224+
this.resetTextures();
12281225

12291226
this.currentPipeline = pipelineInstance;
1230-
this.currentPipeline.bind();
1227+
this.currentPipeline.bind(true);
12311228
this.currentPipeline.onBind();
12321229
},
12331230

src/renderer/webgl/pipelines/BitmapMaskPipeline.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ var BitmapMaskPipeline = new Class({
110110
* @method Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#bind
111111
* @since 3.50.0
112112
*
113+
* @param {boolean} [reset=false] - Should the pipeline be fully re-bound after a renderer pipeline clear?
114+
*
113115
* @return {this} This WebGLPipeline instance.
114116
*/
115-
bind: function ()
117+
bind: function (reset)
116118
{
117-
WebGLPipeline.prototype.bind.call(this);
119+
if (reset === undefined) { reset = false; }
120+
121+
WebGLPipeline.prototype.bind.call(this, reset);
118122

119123
var renderer = this.renderer;
120124
var program = this.program;

src/renderer/webgl/pipelines/LightPipeline.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,15 @@ var LightPipeline = new Class({
149149
* @method Phaser.Renderer.WebGL.Pipelines.LightPipeline#bind
150150
* @since 3.50.0
151151
*
152+
* @param {boolean} [reset=false] - Should the pipeline be fully re-bound after a renderer pipeline clear?
153+
*
152154
* @return {this} This WebGLPipeline instance.
153155
*/
154-
bind: function ()
156+
bind: function (reset)
155157
{
156-
WebGLPipeline.prototype.bind.call(this);
158+
if (reset === undefined) { reset = false; }
159+
160+
WebGLPipeline.prototype.bind.call(this, reset);
157161

158162
var renderer = this.renderer;
159163
var program = this.program;

src/renderer/webgl/pipelines/MultiPipeline.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,15 @@ var MultiPipeline = new Class({
298298
* @method Phaser.Renderer.WebGL.Pipelines.MultiPipeline#bind
299299
* @since 3.50.0
300300
*
301+
* @param {boolean} [reset=false] - Should the pipeline be fully re-bound after a renderer pipeline clear?
302+
*
301303
* @return {this} This WebGLPipeline instance.
302304
*/
303-
bind: function ()
305+
bind: function (reset)
304306
{
305-
WebGLPipeline.prototype.bind.call(this);
307+
if (reset === undefined) { reset = false; }
308+
309+
WebGLPipeline.prototype.bind.call(this, reset);
306310

307311
this.renderer.setInt1iv(this.program, 'uMainSampler', this.renderer.textureIndexes);
308312

src/renderer/webgl/pipelines/SinglePipeline.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,15 @@ var SinglePipeline = new Class({
308308
* @method Phaser.Renderer.WebGL.Pipelines.SinglePipeline#bind
309309
* @since 3.50.0
310310
*
311+
* @param {boolean} [reset=false] - Should the pipeline be fully re-bound after a renderer pipeline clear?
312+
*
311313
* @return {this} This WebGLPipeline instance.
312314
*/
313-
bind: function ()
315+
bind: function (reset)
314316
{
315-
WebGLPipeline.prototype.bind.call(this);
317+
if (reset === undefined) { reset = false; }
318+
319+
WebGLPipeline.prototype.bind.call(this, reset);
316320

317321
return this;
318322
}

0 commit comments

Comments
 (0)