Webgl helper / add the possibility to use transforms as custom uniforms
These will be translated into 4x4 matrices in GLSL.
This commit is contained in:
@@ -62,7 +62,7 @@ export const DefaultAttrib = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef {number|Array<number>|HTMLCanvasElement|HTMLImageElement|ImageData} UniformLiteralValue
|
||||
* @typedef {number|Array<number>|HTMLCanvasElement|HTMLImageElement|ImageData|import("../transform").Transform} UniformLiteralValue
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -565,7 +565,9 @@ class WebGLHelper extends Disposable {
|
||||
// fill texture slots by increasing index
|
||||
gl.uniform1i(this.getUniformLocation(uniform.name), textureSlot++);
|
||||
|
||||
} else if (Array.isArray(value)) {
|
||||
} else if (Array.isArray(value) && value.length === 6) {
|
||||
this.setUniformMatrixValue(uniform.name, fromTransform(this.tmpMat4_, value));
|
||||
} else if (Array.isArray(value) && value.length <= 4) {
|
||||
switch (value.length) {
|
||||
case 2:
|
||||
gl.uniform2f(this.getUniformLocation(uniform.name), value[0], value[1]);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import WebGLHelper from '../../../../src/ol/webgl/Helper';
|
||||
import {create as createTransform} from '../../../../src/ol/transform';
|
||||
|
||||
|
||||
const VERTEX_SHADER = `
|
||||
@@ -95,7 +96,8 @@ describe('ol.webgl.WebGLHelper', function() {
|
||||
uniforms: {
|
||||
u_test1: 42,
|
||||
u_test2: [1, 3],
|
||||
u_test3: document.createElement('canvas')
|
||||
u_test3: document.createElement('canvas'),
|
||||
u_test4: createTransform()
|
||||
}
|
||||
});
|
||||
h.useProgram(h.getProgram(FRAGMENT_SHADER, VERTEX_SHADER));
|
||||
@@ -116,13 +118,15 @@ describe('ol.webgl.WebGLHelper', function() {
|
||||
});
|
||||
|
||||
it('has processed uniforms', function() {
|
||||
expect(h.uniforms_.length).to.eql(3);
|
||||
expect(h.uniforms_.length).to.eql(4);
|
||||
expect(h.uniforms_[0].name).to.eql('u_test1');
|
||||
expect(h.uniforms_[1].name).to.eql('u_test2');
|
||||
expect(h.uniforms_[2].name).to.eql('u_test3');
|
||||
expect(h.uniforms_[3].name).to.eql('u_test4');
|
||||
expect(h.uniforms_[0].location).to.not.eql(-1);
|
||||
expect(h.uniforms_[1].location).to.not.eql(-1);
|
||||
expect(h.uniforms_[2].location).to.not.eql(-1);
|
||||
expect(h.uniforms_[3].location).to.not.eql(-1);
|
||||
expect(h.uniforms_[2].texture).to.not.eql(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user