5

I have a pretty complicated piece of GLSL code (about 5000 lines), different sections of which are flagged with different macros. Since the code base is large and there are many flags, it is little difficult for me to understand the code flow. Wondering if there is a tool that will show me the preprocessed GLSL output. I tried using gDebugger to see the source but there too it shows up un-preprocessed code.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Subhransu
  • 449
  • 1
  • 4
  • 12

3 Answers3

3

cpp is the stand-alone command line C preprocessor on Linux and MacOS 10 systems with the normal dev tools installed.

It's supposed to only be used for C code, but the man page says that it will work on C-like source and GLSL qualifies. (A quick test with one of my shaders gave a warning message for #version though.) You could try running it on your shader.

Hope this helps.

Hugh Fisher
  • 2,321
  • 13
  • 8
1

If you do not want to install any C/C++ compiler on your computer just to see the preprocessed output, or if you find using online IDE easier, you can use some of the online C++ compilers. I have good experience with Coliru.

Just remove && a.out and add -E -P, or replace the whole command line with just g++ main.cpp -E -P or cpp main.cpp -P and press Compile, link and run....

If your source contains some # commands specific to GLSL (like a #version), you will get an error, but you will still see the output.

Credit for the idea goes to a comment to Online Preprocessor for C++ by Predelnik

Coliru settings to preprocess only

Suma
  • 33,181
  • 16
  • 123
  • 191
-2

you have different tools to debug GLSL. Following are some - gDebugger - APITrace - GLIntercept - BuGLe tool

How to debug a GLSL shader? is link similar to your question

Community
  • 1
  • 1
viewport
  • 1
  • 3
  • For preprocess, you need to add your shaders to tools such as FX-composer, TyphoonLabs OpenGL Shader Designer, http://www.geeks3d.com/glslhacker/ and Render monkey – viewport Mar 19 '14 at 06:11