Skip to content

Commit 6dc07da

Browse files
committed
Added ColorMatrix class and proper verts
1 parent d50afad commit 6dc07da

1 file changed

Lines changed: 76 additions & 25 deletions

File tree

src/renderer/webgl/pipelines/UtilityPipeline.js

Lines changed: 76 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
var AddBlendFS = require('../shaders/AddBlend-frag.js');
88
var Class = require('../../../utils/Class');
9+
var ColorMatrix = require('../../../display/ColorMatrix');
910
var ColorMatrixFS = require('../shaders/ColorMatrix-frag.js');
1011
var CopyFS = require('../shaders/Copy-frag.js');
1112
var GetFastValue = require('../../../utils/object/GetFastValue');
@@ -67,7 +68,6 @@ var UtilityPipeline = new Class({
6768
name: 'Copy',
6869
fragShader: CopyFS,
6970
uniforms: [
70-
'uProjectionMatrix',
7171
'uMainSampler',
7272
'uBrightness'
7373
]
@@ -76,7 +76,6 @@ var UtilityPipeline = new Class({
7676
name: 'AddBlend',
7777
fragShader: AddBlendFS,
7878
uniforms: [
79-
'uProjectionMatrix',
8079
'uMainSampler1',
8180
'uMainSampler2',
8281
'uStrength'
@@ -86,7 +85,6 @@ var UtilityPipeline = new Class({
8685
name: 'LinearBlend',
8786
fragShader: LinearBlendFS,
8887
uniforms: [
89-
'uProjectionMatrix',
9088
'uMainSampler1',
9189
'uMainSampler2',
9290
'uStrength'
@@ -96,7 +94,6 @@ var UtilityPipeline = new Class({
9694
name: 'ColorMatrix',
9795
fragShader: ColorMatrixFS,
9896
uniforms: [
99-
'uProjectionMatrix',
10097
'uMainSampler',
10198
'uColorMatrix'
10299
]
@@ -115,11 +112,23 @@ var UtilityPipeline = new Class({
115112
}
116113
]);
117114

118-
config.vertices = new Float32Array([ -1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1 ]);
115+
// x, y, u, v (x/y in NDC)
116+
117+
config.vertices = new Float32Array([
118+
-1, -1, 0, 0,
119+
-1, 1, 0, 1,
120+
1, 1, 1, 1,
121+
-1, -1, 0, 0,
122+
1, 1, 1, 1,
123+
1, -1, 1, 0
124+
]);
125+
119126
config.batchSize = 1;
120127

121128
WebGLPipeline.call(this, config);
122129

130+
this.colorMatrix = new ColorMatrix();
131+
123132
this.copyShader;
124133
this.addShader;
125134
this.linearShader;
@@ -159,9 +168,7 @@ var UtilityPipeline = new Class({
159168

160169
var gl = this.gl;
161170

162-
window.spector.setMarker('cf1');
163-
164-
this.set1i('uMainSampler', 1, this.copyShader);
171+
this.set1i('uMainSampler', 0, this.copyShader);
165172
this.set1f('uBrightness', brightness, this.copyShader);
166173

167174
if (target)
@@ -173,51 +180,95 @@ var UtilityPipeline = new Class({
173180
gl.viewport(0, 0, source.width, source.height);
174181
}
175182

176-
window.spector.clearMarker();
177-
window.spector.setMarker('cf2');
178-
179-
gl.activeTexture(gl.TEXTURE1);
183+
gl.activeTexture(gl.TEXTURE0);
180184
gl.bindTexture(gl.TEXTURE_2D, source.texture);
181185

182186
gl.bindFramebuffer(gl.FRAMEBUFFER, this.fullFrame1.framebuffer);
183187

184-
// gl.bindFramebuffer(gl.FRAMEBUFFER, null);
185-
186188
if (target)
187189
{
188190
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, target.texture, 0);
189191
}
190192

191193
if (clearAlpha)
192194
{
193-
// gl.clearColor(0, 0, 0, 0);
195+
gl.clearColor(0, 0, 0, 0);
194196
}
195197
else
196198
{
197-
// gl.clearColor(0, 0, 0, 1);
199+
gl.clearColor(0, 0, 0, 1);
198200
}
199201

200202
gl.bufferData(gl.ARRAY_BUFFER, this.vertexData, gl.STATIC_DRAW);
201203
gl.drawArrays(gl.TRIANGLES, 0, 6);
202204

203205
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
204206
gl.bindTexture(gl.TEXTURE_2D, null);
207+
},
208+
209+
drawFrame: function (source, target)
210+
{
211+
var gl = this.gl;
212+
213+
this.set1i('uMainSampler', 0, this.colorMatrixShader);
214+
this.set1fv('uColorMatrix', this.colorMatrix.getData(), this.colorMatrixShader);
215+
216+
gl.activeTexture(gl.TEXTURE0);
217+
gl.bindTexture(gl.TEXTURE_2D, source.texture);
218+
219+
// gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);
220+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
221+
222+
if (target)
223+
{
224+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, target.texture, 0);
225+
}
205226

206-
window.spector.clearMarker();
227+
// if (clearAlpha)
228+
// {
229+
// gl.clearColor(0, 0, 0, 0);
230+
// }
231+
// else
232+
// {
233+
// gl.clearColor(0, 0, 0, 1);
234+
// }
235+
236+
gl.bufferData(gl.ARRAY_BUFFER, this.vertexData, gl.STATIC_DRAW);
237+
gl.drawArrays(gl.TRIANGLES, 0, 6);
238+
239+
// gl.bindFramebuffer(gl.FRAMEBUFFER, null);
240+
gl.bindTexture(gl.TEXTURE_2D, null);
207241
},
208242

209-
batchVert: function (x, y, u, v)
243+
bindAndDraw: function (source, target)
210244
{
211-
var vertexViewF32 = this.vertexViewF32;
245+
var gl = this.gl;
246+
247+
gl.activeTexture(gl.TEXTURE0);
248+
gl.bindTexture(gl.TEXTURE_2D, source.texture);
249+
250+
// gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);
251+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
252+
253+
if (target)
254+
{
255+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, target.texture, 0);
256+
}
212257

213-
var vertexOffset = (this.vertexCount * this.currentShader.vertexComponentCount) - 1;
258+
// if (clearAlpha)
259+
// {
260+
// gl.clearColor(0, 0, 0, 0);
261+
// }
262+
// else
263+
// {
264+
// gl.clearColor(0, 0, 0, 1);
265+
// }
214266

215-
vertexViewF32[++vertexOffset] = x;
216-
vertexViewF32[++vertexOffset] = y;
217-
vertexViewF32[++vertexOffset] = u;
218-
vertexViewF32[++vertexOffset] = v;
267+
gl.bufferData(gl.ARRAY_BUFFER, this.vertexData, gl.STATIC_DRAW);
268+
gl.drawArrays(gl.TRIANGLES, 0, 6);
219269

220-
this.vertexCount++;
270+
// gl.bindFramebuffer(gl.FRAMEBUFFER, null);
271+
gl.bindTexture(gl.TEXTURE_2D, null);
221272
}
222273

223274
});

0 commit comments

Comments
 (0)