Improve handling of uniforms in webgl helper

This commit is contained in:
Olivier Guyot
2018-11-16 01:50:44 +01:00
parent 94524fb431
commit 530bcd0c88
3 changed files with 7 additions and 9 deletions

View File

@@ -100,7 +100,7 @@ class WebGLPointsLayerRenderer extends LayerRenderer {
renderFrame(frameState, layerState) {
this.context_.setUniformFloatValue(DefaultUniform.OPACITY, layerState.opacity);
this.context_.drawElements(0, this.indicesBuffer_.getArray().length);
this.context_.finalizeDraw();
this.context_.finalizeDraw(frameState);
return this.context_.getCanvas();
}

View File

@@ -18,8 +18,6 @@ import {
} from "../transform";
import {create, fromTransform} from "../vec/mat4";
import WebGLBuffer from "./Buffer";
import WebGLVertex from "./Vertex";
import WebGLFragment from "./Fragment";
import WebGLPostProcessingPass from "./PostProcessingPass";
@@ -288,10 +286,10 @@ class WebGLHelper extends Disposable {
/**
* Copy the frame buffer to the canvas
*/
finalizeDraw() {
finalizeDraw(frameState) {
// apply post processes using the next one as target
for (let i = 0; i < this.postProcessPasses.length; i++) {
this.postProcessPasses[i].apply(this.postProcessPasses[i + 1] || null);
this.postProcessPasses[i].apply(frameState, this.postProcessPasses[i + 1] || null);
}
}

View File

@@ -143,7 +143,7 @@ class WebGLPostProcessingPass {
// todo
// render to the next postprocessing pass (or to the canvas if final pass)
apply(nextPass) {
apply(frameState, nextPass) {
const gl = this.getGL();
const canvas = gl.canvas;
@@ -166,7 +166,7 @@ class WebGLPostProcessingPass {
gl.uniform2f(this.renderTargetUniformLocation_, canvas.width, canvas.height);
gl.uniform1i(this.renderTargetTextureLocation_, 0);
this.applyUniforms();
this.applyUniforms(frameState);
gl.drawArrays(gl.TRIANGLES, 0, 6);
}
@@ -177,13 +177,13 @@ class WebGLPostProcessingPass {
}
// todo
applyUniforms() {
applyUniforms(frameState) {
const gl = this.getGL();
let value;
let textureSlot = 1;
this.uniforms_.forEach(function(uniform) {
value = typeof uniform.value === 'function' ? uniform.value() : uniform.value;
value = typeof uniform.value === 'function' ? uniform.value(frameState) : uniform.value;
// apply value based on type
if (value instanceof HTMLCanvasElement || value instanceof ImageData) {