Improve handling of uniforms in webgl helper
This commit is contained in:
@@ -100,7 +100,7 @@ class WebGLPointsLayerRenderer extends LayerRenderer {
|
|||||||
renderFrame(frameState, layerState) {
|
renderFrame(frameState, layerState) {
|
||||||
this.context_.setUniformFloatValue(DefaultUniform.OPACITY, layerState.opacity);
|
this.context_.setUniformFloatValue(DefaultUniform.OPACITY, layerState.opacity);
|
||||||
this.context_.drawElements(0, this.indicesBuffer_.getArray().length);
|
this.context_.drawElements(0, this.indicesBuffer_.getArray().length);
|
||||||
this.context_.finalizeDraw();
|
this.context_.finalizeDraw(frameState);
|
||||||
return this.context_.getCanvas();
|
return this.context_.getCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ import {
|
|||||||
} from "../transform";
|
} from "../transform";
|
||||||
import {create, fromTransform} from "../vec/mat4";
|
import {create, fromTransform} from "../vec/mat4";
|
||||||
import WebGLBuffer from "./Buffer";
|
import WebGLBuffer from "./Buffer";
|
||||||
import WebGLVertex from "./Vertex";
|
|
||||||
import WebGLFragment from "./Fragment";
|
|
||||||
import WebGLPostProcessingPass from "./PostProcessingPass";
|
import WebGLPostProcessingPass from "./PostProcessingPass";
|
||||||
|
|
||||||
|
|
||||||
@@ -288,10 +286,10 @@ class WebGLHelper extends Disposable {
|
|||||||
/**
|
/**
|
||||||
* Copy the frame buffer to the canvas
|
* Copy the frame buffer to the canvas
|
||||||
*/
|
*/
|
||||||
finalizeDraw() {
|
finalizeDraw(frameState) {
|
||||||
// apply post processes using the next one as target
|
// apply post processes using the next one as target
|
||||||
for (let i = 0; i < this.postProcessPasses.length; i++) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ class WebGLPostProcessingPass {
|
|||||||
|
|
||||||
// todo
|
// todo
|
||||||
// render to the next postprocessing pass (or to the canvas if final pass)
|
// render to the next postprocessing pass (or to the canvas if final pass)
|
||||||
apply(nextPass) {
|
apply(frameState, nextPass) {
|
||||||
const gl = this.getGL();
|
const gl = this.getGL();
|
||||||
const canvas = gl.canvas;
|
const canvas = gl.canvas;
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ class WebGLPostProcessingPass {
|
|||||||
gl.uniform2f(this.renderTargetUniformLocation_, canvas.width, canvas.height);
|
gl.uniform2f(this.renderTargetUniformLocation_, canvas.width, canvas.height);
|
||||||
gl.uniform1i(this.renderTargetTextureLocation_, 0);
|
gl.uniform1i(this.renderTargetTextureLocation_, 0);
|
||||||
|
|
||||||
this.applyUniforms();
|
this.applyUniforms(frameState);
|
||||||
|
|
||||||
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
||||||
}
|
}
|
||||||
@@ -177,13 +177,13 @@ class WebGLPostProcessingPass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// todo
|
// todo
|
||||||
applyUniforms() {
|
applyUniforms(frameState) {
|
||||||
const gl = this.getGL();
|
const gl = this.getGL();
|
||||||
|
|
||||||
let value;
|
let value;
|
||||||
let textureSlot = 1;
|
let textureSlot = 1;
|
||||||
this.uniforms_.forEach(function(uniform) {
|
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
|
// apply value based on type
|
||||||
if (value instanceof HTMLCanvasElement || value instanceof ImageData) {
|
if (value instanceof HTMLCanvasElement || value instanceof ImageData) {
|
||||||
|
|||||||
Reference in New Issue
Block a user