Throw an error if shaders fail to compile or program fails to link

This commit is contained in:
Tim Schaub
2021-01-05 14:13:26 -07:00
parent 98a8e8e5be
commit afd0b8f757
3 changed files with 49 additions and 53 deletions

View File

@@ -46,7 +46,14 @@ const FRAGMENT_SHADER = `
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}`;
describe('ol.webgl.WebGLHelper', function () {
const INVALID_FRAGMENT_SHADER = `
precision mediump float;
void main(void) {
gl_FragColor = vec4(oops, 1.0, 1.0, 1.0);
}`;
describe('ol/webgl/WebGLHelper', function () {
describe('constructor', function () {
describe('without an argument', function () {
let h;
@@ -177,25 +184,22 @@ describe('ol.webgl.WebGLHelper', function () {
});
describe('invalid shader compiling', function () {
let h;
let p;
beforeEach(function () {
h = new WebGLHelper();
p = h.getProgram(FRAGMENT_SHADER, INVALID_VERTEX_SHADER);
h.useProgram(p);
it('throws for an invalid vertex shader', function () {
const helper = new WebGLHelper();
expect(() =>
helper.getProgram(FRAGMENT_SHADER, INVALID_VERTEX_SHADER)
).to.throwException(
/Vertex shader compilation failed: ERROR: 0:10: 'bla' : syntax error/
);
});
it('has saved the program', function () {
expect(h.currentProgram_).to.eql(p);
});
it('has shader compilation errors', function () {
expect(h.shaderCompileErrors_).to.not.eql(null);
});
it('cannot find the uniform location', function () {
expect(h.getUniformLocation('u_test')).to.eql(null);
it('throws for an invalid fragment shader', function () {
const helper = new WebGLHelper();
expect(() =>
helper.getProgram(INVALID_FRAGMENT_SHADER, VERTEX_SHADER)
).to.throwException(
/Fragment shader compliation failed: ERROR: 0:5: 'oops' : undeclared identifier/
);
});
});
@@ -354,7 +358,7 @@ describe('ol.webgl.WebGLHelper', function () {
uniform float u_test;
void main(void) {
gl_Position = vec4(u_test, a_test, 0.0, 1.0);
gl_Position = vec4(u_test, attr3, 0.0, 1.0);
}`
)
);