Sign in to follow this  
Trenki

OpenGL Cg vs. GLSL

Recommended Posts

Trenki    345
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
n00body    345
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
Yann L    1802
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
AverageJoeSSU    564
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  

  • Similar Content

    • By povilaslt2
      Hello. I'm Programmer who is in search of 2D game project who preferably uses OpenGL and C++. You can see my projects in GitHub. Project genre doesn't matter (except MMO's :D).
    • By ZeldaFan555
      Hello, My name is Matt. I am a programmer. I mostly use Java, but can use C++ and various other languages. I'm looking for someone to partner up with for random projects, preferably using OpenGL, though I'd be open to just about anything. If you're interested you can contact me on Skype or on here, thank you!
      Skype: Mangodoor408
    • By tyhender
      Hello, my name is Mark. I'm hobby programmer. 
      So recently,I thought that it's good idea to find people to create a full 3D engine. I'm looking for people experienced in scripting 3D shaders and implementing physics into engine(game)(we are going to use the React physics engine). 
      And,ye,no money =D I'm just looking for hobbyists that will be proud of their work. If engine(or game) will have financial succes,well,then maybe =D
      Sorry for late replies.
      I mostly give more information when people PM me,but this post is REALLY short,even for me =D
      So here's few more points:
      Engine will use openGL and SDL for graphics. It will use React3D physics library for physics simulation. Engine(most probably,atleast for the first part) won't have graphical fron-end,it will be a framework . I think final engine should be enough to set up an FPS in a couple of minutes. A bit about my self:
      I've been programming for 7 years total. I learned very slowly it as "secondary interesting thing" for like 3 years, but then began to script more seriously.  My primary language is C++,which we are going to use for the engine. Yes,I did 3D graphics with physics simulation before. No, my portfolio isn't very impressive. I'm working on that No,I wasn't employed officially. If anybody need to know more PM me. 
       
    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
  • Popular Now