Skip to content

Commit 601573b

Browse files
committed
working on setting up texture index on vertex buffer object.
1 parent bb53624 commit 601573b

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/pixi/renderers/webgl/shaders/PixiShader.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,13 @@ PIXI.PixiShader.prototype.init = function()
9595
'varying vec4 vColor;',
9696
'varying float vTextureIndex;',
9797
'uniform sampler2D uSamplerArray[' + MAX_TEXTURES + '];',
98+
'const vec4 PINK = vec4(1.0, 0.0, 1.0, 1.0);',
99+
'const vec4 GREEN = vec4(0.0, 1.0, 0.0, 1.0);',
98100
'void main(void) {',
99-
dynamicIfs,
100-
'\telse gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;',
101+
//dynamicIfs,
102+
'if (vTextureIndex == 0.0) gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;',
103+
'else if(vTextureIndex == 1.0) gl_FragColor = PINK;',
104+
'else gl_FragColor = GREEN;',
101105
'}'
102106
];
103107

@@ -119,7 +123,7 @@ PIXI.PixiShader.prototype.init = function()
119123
this.aTextureIndex = gl.getAttribLocation(program, 'aTextureIndex');
120124

121125
var indices = [];
122-
for (var i = 0; i < /*MAX_TEXTURES*/2; ++i) {
126+
for (var i = 0; i < MAX_TEXTURES; ++i) {
123127
indices.push(i);
124128
}
125129
// NOTE:!!!

src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ PIXI.WebGLSpriteBatch.prototype.render = function (sprite, matrix) {
260260
h1 = texture.frame.height * -aY;
261261
}
262262

263-
var i = this.currentBatchSize * 4 * this.vertSize;
263+
var i = this.currentBatchSize * this.vertexSize;//4 * this.vertSize;
264264
var tiOffset = this.currentBatchSize * 4;
265265
var resolution = texture.baseTexture.resolution;
266266
var textureIndex = texture.baseTexture.textureIndex;
@@ -409,7 +409,7 @@ PIXI.WebGLSpriteBatch.prototype.renderTilingSprite = function (sprite) {
409409
var h0 = height * (1 - aY);
410410
var h1 = height * -aY;
411411

412-
var i = this.currentBatchSize * 4 * this.vertSize;
412+
var i = this.currentBatchSize * this.vertexSize;//4 * this.vertSize;
413413

414414
var resolution = texture.baseTexture.resolution;
415415

@@ -495,9 +495,8 @@ PIXI.WebGLSpriteBatch.prototype.flush = function () {
495495
// bind the buffers
496496
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
497497
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
498-
499498
// this is the same for each shader?
500-
var stride = this.vertexSize;//this.vertSize * 4;
499+
var stride = this.vertexSize; //this.vertSize * 4;
501500
gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, stride, 0);
502501
gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, stride, 8);
503502

@@ -513,7 +512,7 @@ PIXI.WebGLSpriteBatch.prototype.flush = function () {
513512
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.vertices);
514513
} else {
515514
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
516-
var view = this.positions.subarray(0, this.currentBatchSize * 4 * this.vertSize);
515+
var view = this.positions.subarray(0, this.currentBatchSize * this.vertexSize);
517516
gl.bufferSubData(gl.ARRAY_BUFFER, 0, view);
518517
}
519518

@@ -551,7 +550,7 @@ PIXI.WebGLSpriteBatch.prototype.flush = function () {
551550
skip = false;
552551
}
553552

554-
if (( /*currentBaseTexture !== nextTexture &&*/ !skip) || blendSwap || shaderSwap) {
553+
if (( currentBaseTexture !== nextTexture && !skip) || blendSwap || shaderSwap) {
555554
this.renderBatch(currentBaseTexture, batchSize, start);
556555

557556
start = i;
@@ -628,7 +627,6 @@ PIXI.WebGLSpriteBatch.prototype.renderBatch = function (texture, size, startInde
628627
}
629628
} else {
630629
gl.activeTexture(gl.TEXTURE0 + texture.textureIndex);
631-
//console.log(texture.textureIndex);
632630
// bind the current texture
633631
gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);
634632
}
@@ -666,7 +664,6 @@ PIXI.WebGLSpriteBatch.prototype.destroy = function () {
666664

667665
this.gl.deleteBuffer(this.vertexBuffer);
668666
this.gl.deleteBuffer(this.indexBuffer);
669-
this.gl.deleteBuffer(this.texIndexBuffer);
670667

671668
this.currentBaseTexture = null;
672669

0 commit comments

Comments
 (0)