39
votes

In C, I can debug code like:

fprintf(stderr, "blah: %f", some_var);

in GLSL ... is there anyway for me to just dump out a value in a Vertex or Fragment shader? I don't care if it's slow; I just want to dump out the value. Ideally, I want a setup like the following:

  • normal state = run GLSL shader normally
  • press key 'd' = next frame is generated in ULTRA slow mode, where the "printfs" in the Vertex/Fragment shader are executed and dumped out.

Is this feasible? (I don't care about performance; I just want to do this for one frame).

Thanks!

4

4 Answers

25
votes

Unfortunately it's not possible directly. One possible solution though, that I end up using a lot (but I'm sure it's pretty common among GLSL developers) is to "print" values as colors, in place of your intended final result.

Of course this has many limitations; for one, you have to make sure that your value maps in a (0,1.0) range. Functions as mod, fract etc. turn out useful in these cases. But, in general, this is what I see as the "printf" equivalent in GLSL.

21
votes

Instead of printing values, have you thought of trying a GLSL debugger?

For example, glslDevil will let you step through your shader's execution and examine the variables at each step.

3
votes

Check out AMD CodeXL. It will let you step frame by frame to inspect opengl state values, shader code, and texture memory.

http://developer.amd.com/tools-and-sdks/heterogeneous-computing/codexl/

-3
votes

You can see the variable you want to check by copying its value in a uniform and then get that uniform with glGetUniformfv