Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shader compile errors

I am trying to compile a "garbage" shader, feeding in some garbage code to WebGL (see here for a fiddle):

gl = $('canvas')[0].getContext('experimental-webgl');

source = 'garbage12398sv;aa[]|\[12';

shader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(shader, source);
gl.compileShader(shader);

console.log(gl.getError() === gl.NO_ERROR);

Surprisingly, gl.getError() === gl.NO_ERROR is true despite asking WebGL to compile some garbage.

Why doesn't getError flag an error? How can I get error information regarding the compilation status of my shaders?

like image 252
Randomblue Avatar asked Oct 05 '12 22:10

Randomblue


People also ask

What is shader compile?

Shader Compilation is the term used to describe the process by which OpenGL Shading Language scripts are loaded into OpenGL to be used as shaders. OpenGL has three ways to compile shader text into usable OpenGL objects. All of these forms of compilation produce a Program Object.

How long does it take for shaders to compile?

It might take 30 minutes to compile shaders.


1 Answers

gl.getError only returns errors for the OpenGL pipeline. A shader failing to compile does not cause an error in the pipeline. You can read about gl.getError here. You can query the status of shader like so:

var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
console.log('Shader compiled successfully: ' + compiled);
var compilationLog = gl.getShaderInfoLog(shader);
console.log('Shader compiler log: ' + compilationLog);

Similarly, shader program linking errors do not invalidate the OpenGL pipeline and can't be detected with gl.getError() you must call the object (shader, program, render buffer, etc) specific error query functions.

like image 166
Cutch Avatar answered Oct 21 '22 23:10

Cutch