Hello,
Goal: I want to be able to access the glsl shader source error messages when trying link a program for THREE.ShaderMaterial.
Reason: The error message can be parsed to get the line number that will allow me to highlight the syntax error in a browser editor.
I’m working on my own browser IDE for editing GLSL shader code. And I’m using THREE.ShaderMaterial applied to a GLTF object to preview the shader source changes in real time.
What I tried: I’m able to ‘intercept’ calls made with gl.attachShader
gl.attachShader = function(program, shader) {
interceptingAttachShader(shader);
return originalAttachShader(program, shader);
};
This is perfect for being able to see the full shader source being linked to a program. I thought I could apply the same intercepting technique to either hook into the console error call inside three.module.js
console.error('three.module.js:17432 THREE.WebGLProgram: shader error:...)
OR… hook into gl.linkProgram( program );
then read the error myself with webgl’s getProgramInfoLog
.
However, it looks like caching is getting in the way…
The Challenge: If I change the GLSL source code in my browser editor, this causes a new THREE.ShaderMaterial
to be generated with the updated GLSL source code. But if this source code has already been used… a new program will not be created. Instead the cached program is used. And when a chached program is used, my hooks into either console.error
or gl.linkProgram
won’t be called.
There are many different ways I can think of to get around this. But, I wanted to check with you to see if there is a simple way (the question I have below).
Question: Is there some event/function/property I can use in order to see when a program
is changed (either cached or brand new)… every time I recreate the material with new THREE.ShaderMaterial
?
Cheers!