# 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 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 on other sites
Quote:
 Original post by n00bodyAs 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 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.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627676
• Total Posts
2978578
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 11
• 12
• 10
• 12
• 22