Skip to content

Commit 2d32480

Browse files
committed
Lots of tidying up, added blend methods
1 parent cfce806 commit 2d32480

1 file changed

Lines changed: 47 additions & 29 deletions

File tree

src/renderer/webgl/pipelines/UtilityPipeline.js

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,9 @@ var UtilityPipeline = new Class({
183183
gl.activeTexture(gl.TEXTURE0);
184184
gl.bindTexture(gl.TEXTURE_2D, source.texture);
185185

186-
gl.bindFramebuffer(gl.FRAMEBUFFER, this.fullFrame1.framebuffer);
187-
188186
if (target)
189187
{
188+
gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);
190189
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, target.texture, 0);
191190
}
192191

@@ -199,75 +198,94 @@ var UtilityPipeline = new Class({
199198
gl.clearColor(0, 0, 0, 1);
200199
}
201200

201+
gl.clear(gl.COLOR_BUFFER_BIT);
202+
202203
gl.bufferData(gl.ARRAY_BUFFER, this.vertexData, gl.STATIC_DRAW);
203204
gl.drawArrays(gl.TRIANGLES, 0, 6);
204205

205206
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
206207
gl.bindTexture(gl.TEXTURE_2D, null);
207208
},
208209

209-
drawFrame: function (source, target)
210+
drawFrame: function (source, target, clearAlpha, colorMatrix)
210211
{
212+
if (clearAlpha === undefined) { clearAlpha = true; }
213+
if (colorMatrix === undefined) { colorMatrix = this.colorMatrix; }
214+
211215
var gl = this.gl;
212216

213217
this.set1i('uMainSampler', 0, this.colorMatrixShader);
214-
this.set1fv('uColorMatrix', this.colorMatrix.getData(), this.colorMatrixShader);
218+
this.set1fv('uColorMatrix', colorMatrix.getData(), this.colorMatrixShader);
215219

216220
gl.activeTexture(gl.TEXTURE0);
217221
gl.bindTexture(gl.TEXTURE_2D, source.texture);
218222

219-
// gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);
220-
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
221-
222223
if (target)
223224
{
225+
gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);
224226
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, target.texture, 0);
225227
}
226228

227-
// if (clearAlpha)
228-
// {
229-
// gl.clearColor(0, 0, 0, 0);
230-
// }
231-
// else
232-
// {
233-
// gl.clearColor(0, 0, 0, 1);
234-
// }
229+
if (clearAlpha)
230+
{
231+
gl.clearColor(0, 0, 0, 0);
232+
}
233+
else
234+
{
235+
gl.clearColor(0, 0, 0, 1);
236+
}
237+
238+
gl.clear(gl.COLOR_BUFFER_BIT);
235239

236240
gl.bufferData(gl.ARRAY_BUFFER, this.vertexData, gl.STATIC_DRAW);
237241
gl.drawArrays(gl.TRIANGLES, 0, 6);
238242

239-
// gl.bindFramebuffer(gl.FRAMEBUFFER, null);
240243
gl.bindTexture(gl.TEXTURE_2D, null);
241244
},
242245

243-
bindAndDraw: function (source, target)
246+
blendFrames: function (source1, source2, target, strength, clearAlpha, blendShader)
244247
{
248+
if (strength === undefined) { strength = 1; }
249+
if (clearAlpha === undefined) { clearAlpha = true; }
250+
if (blendShader === undefined) { blendShader = this.linearShader; }
251+
245252
var gl = this.gl;
246253

254+
this.set1i('uMainSampler1', 0, blendShader);
255+
this.set1i('uMainSampler2', 1, blendShader);
256+
this.set1f('uStrength', strength, blendShader);
257+
247258
gl.activeTexture(gl.TEXTURE0);
248-
gl.bindTexture(gl.TEXTURE_2D, source.texture);
259+
gl.bindTexture(gl.TEXTURE_2D, source1.texture);
249260

250-
// gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);
251-
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
261+
gl.activeTexture(gl.TEXTURE1);
262+
gl.bindTexture(gl.TEXTURE_2D, source2.texture);
252263

253264
if (target)
254265
{
266+
gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);
255267
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, target.texture, 0);
268+
gl.viewport(0, 0, target.width, target.height);
269+
}
270+
else
271+
{
272+
gl.viewport(0, 0, source1.width, source1.height);
273+
}
274+
275+
if (clearAlpha)
276+
{
277+
gl.clearColor(0, 0, 0, 0);
278+
}
279+
else
280+
{
281+
gl.clearColor(0, 0, 0, 1);
256282
}
257283

258-
// if (clearAlpha)
259-
// {
260-
// gl.clearColor(0, 0, 0, 0);
261-
// }
262-
// else
263-
// {
264-
// gl.clearColor(0, 0, 0, 1);
265-
// }
284+
gl.clear(gl.COLOR_BUFFER_BIT);
266285

267286
gl.bufferData(gl.ARRAY_BUFFER, this.vertexData, gl.STATIC_DRAW);
268287
gl.drawArrays(gl.TRIANGLES, 0, 6);
269288

270-
// gl.bindFramebuffer(gl.FRAMEBUFFER, null);
271289
gl.bindTexture(gl.TEXTURE_2D, null);
272290
}
273291

0 commit comments

Comments
 (0)