Skip to content

Commit 701ad1f

Browse files
committed
ColorMatrix alpha support and viewport setting
1 parent 7458031 commit 701ad1f

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

src/renderer/webgl/pipelines/UtilityPipeline.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ var UtilityPipeline = new Class({
106106
fragShader: ColorMatrixFS,
107107
uniforms: [
108108
'uMainSampler',
109-
'uColorMatrix'
109+
'uColorMatrix',
110+
'uAlpha'
110111
]
111112
}
112113
]);
@@ -303,23 +304,19 @@ var UtilityPipeline = new Class({
303304
this.set1i('uMainSampler', 0, this.copyShader);
304305
this.set1f('uBrightness', brightness, this.copyShader);
305306

306-
if (target)
307-
{
308-
gl.viewport(0, 0, target.width, target.height);
309-
}
310-
else
311-
{
312-
gl.viewport(0, 0, source.width, source.height);
313-
}
314-
315307
gl.activeTexture(gl.TEXTURE0);
316308
gl.bindTexture(gl.TEXTURE_2D, source.texture);
317309

318310
if (target)
319311
{
312+
gl.viewport(0, 0, target.width, target.height);
320313
gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);
321314
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, target.texture, 0);
322315
}
316+
else
317+
{
318+
gl.viewport(0, 0, source.width, source.height);
319+
}
323320

324321
if (clearAlpha)
325322
{
@@ -365,15 +362,21 @@ var UtilityPipeline = new Class({
365362

366363
this.set1i('uMainSampler', 0, this.colorMatrixShader);
367364
this.set1fv('uColorMatrix', colorMatrix.getData(), this.colorMatrixShader);
365+
this.set1f('uAlpha', colorMatrix.alpha, this.colorMatrixShader);
368366

369367
gl.activeTexture(gl.TEXTURE0);
370368
gl.bindTexture(gl.TEXTURE_2D, source.texture);
371369

372370
if (target)
373371
{
372+
gl.viewport(0, 0, target.width, target.height);
374373
gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);
375374
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, target.texture, 0);
376375
}
376+
else
377+
{
378+
gl.viewport(0, 0, source.width, source.height);
379+
}
377380

378381
if (clearAlpha)
379382
{
@@ -389,6 +392,7 @@ var UtilityPipeline = new Class({
389392
gl.bufferData(gl.ARRAY_BUFFER, this.vertexData, gl.STATIC_DRAW);
390393
gl.drawArrays(gl.TRIANGLES, 0, 6);
391394

395+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
392396
gl.bindTexture(gl.TEXTURE_2D, null);
393397
},
394398

0 commit comments

Comments
 (0)