开发者

printf in GLSL?

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 o开发者_如何转开发ut.

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

Thanks!


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.


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.


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/


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜