Sign in to follow this  
Trenki

OpenGL Cg vs. GLSL

Recommended Posts

Hi! I would like if it is worth to learn Cg and its API when I already know GLSL and how to interface it with OpenGL. I mean I know of some possible advantages:
  • multiple target profiles: for instance targetting ARB vertex and fragment programs would basically ensure your shader will run on SM 2.0 cards which you can't easily know from a GLSL shader unless you try to compile on a card that only supports SM 2.0. This is probably the biggest advantage over GLSL.
  • you can use #includes in you Cg shaders. This is not possible in GLSL at the moment but would not be too hard to add emulate either.
  • There is GgFX similar to DirectX FX files. I never tried this but it might be a nice feature although for a big application one would probably roll its own anyway.
Do you know of any other advantages or disatvantages compared to GLSL. Is it worth to learn it. What about OpenGL 3.0 which hopefully will appear soon. Will Cg work with GL3 or is it a dead end?

Share this post


Link to post
Share on other sites
Whether or not it is "worth it" is a highly subjective thing. If all you wish to do is just have programmable shaders, then GLSL is more than sufficient for your needs. The only reason to go after Cg at this point would be if you saw some feature it supported that you either feel could improve your productivity, or that you really want to play around with.

As for its features vs GLSL, Cg 2.0, the latest version, added support for bindable uniform buffers. Basically a way to pass in a lot of uniforms all at once, rather than individually. There's also the ability to compile Cg to a binary for a small speed gain. Then there's support for interfaces, and some ability for Cg to talk back to your code. Finally, as far as I know, it is currently the only way to access SM 4.0 features from OpenGL.

For the most part, Cg is the more mature platform.

However, there is the added annoyance of having to include another lib in your programs. Also, how Cg might not be on all the platforms that OpenGL reaches (ex. no BSD implementation). GLSL is intimately tied to and integrated with OpenGL, so it will always be available where there is OpenGL(ES).

As for whether or not Cg will work with OpenGL 3.0, NVIDIA will definitely make efforts to integrate it with the new API (might already be working on it). Whether it will be available when the first OG 3.0 implementations come out, or some time after, only time will tell.

Although, the question this raises is, will it be worth it at that point. Basically, some of the upcoming features for OG 3.0 include an FX framework, compiled shaders, and expansions to the shading language itself. At that point, the deciding factors will be: the narrowed feature gap between them, the quantities of example code and tutorials, and availability of working implementations.

So until OG 3.0 becomes standardized and widely available, the Cg platform is just more mature for some of those features. If you need said features for something you're working on now, and don't have time to wait on OG 3.0, then I see no reason not consider Cg. If it will meet your needs, and you feel comfortable with the constraints, then have at it.

Share this post


Link to post
Share on other sites
Quote:
Original post by n00body
As for its features vs GLSL, Cg 2.0, the latest version, added support for bindable uniform buffers. Basically a way to pass in a lot of uniforms all at once, rather than individually. There's also the ability to compile Cg to a binary for a small speed gain. Then there's support for interfaces, and some ability for Cg to talk back to your code. Finally, as far as I know, it is currently the only way to access SM 4.0 features from OpenGL.

Incorrect. SM4.0 features, such as geometry shaders, bindable uniforms, texture arrays, etc, are all exposed via GLSL.

Share this post


Link to post
Share on other sites
I have been using Cg for an advanced OpenGL engine... and i have to say i am somewhat annoyed with its "distance" from the OpenGL pipeline....

finding out how to access OpenGL states and all that was annoying...

Other then that Cg is not so bad.

One thing i like / look forward to is the fact that Nvidia is going to release a shader debugger eventually (yes its not out yet and yes it could be a while, but does GLSL have debugging support? i dunno) And in seeing perfHud for DX, if the shader debugger was 1/10th that... it would be awesome.

Bottom line... LEARNING Cg is different then implementing it... if i were you... i would pick it up slowly and then decide once you've learned i bit.

Plus you already know GLSL... so the most puzzling part for you will be OpenGL states and CgFX. Prolly not that bad.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this