Because this might be useful to other people as well, I created
a small module that compiles OpenGL shader programs and shows compilation and linking errors in a more convenient manner. On successful compilation it also list all remaining active attributes and uniforms so you can see which ones have been optimized away (and may cause errors when trying to assign values to them with
batch_for_shader() or
shader.uniform_xxx()
On compiling OpenGL shaders Blender lists errors on the console and (with the --debug-gpu-shaders
option) will dump source code into the /temp directory. That is not very convenient because it is not in one place and the source code does not contain line numbers. When you use the debug_program()
function form the opengl_debug
module the output is all on the console and reorganized for readability.
Nicer error listing
For example, with the code below
vs_syntax_error = '''
in vec3 pos;
void main()
{
gl_Position = pos
}
'''
debug_program(vshader=vs_syntax_error, name="Syntax error sample")
The output will be
GL Error: 0 (Syntax error sample:vertexshader)
0(7) : error C1035: assignment of incompatible types
0(8) : error C0000: syntax error, unexpected '}', expecting ',' or ';' at token "}"
[0001] #version 330
[0002]
[0003] in vec3 pos;
[0004]
[0005] void main()
[0006] {
[0007] gl_Position = pos
[0008] }
[0009]
Active attributes and uniforms
Also, when there are syntax errors it shows the remaining active attributes and uniforms.
For example, with the code below (assuming you have done
import debug_program from opengl_debug
)
vs_opt = '''
in vec3 pos;
in vec3 pos2;
void main()
{
gl_Position = vec4(pos, 1.0);
}
'''
debug_program(vshader=vs_opt, name="Optimized attribute")
The output will be
active attributes
['GL_FLOAT_VEC3'] pos
active uniforms
showing that there are no active uniforms whatsoever and that the
pos2
attribute has been optimized away.
Code availability
The code is available from
my GitHub repository.