Jump to content
  • Advertisement
Sign in to follow this  
csvtd

OpenGL Cg, OpenGL, HLSL?

This topic is 4464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Could someone explain to me how Cg, OpenGl Shader Language, and Microsofts HLSL compare and contrast. if i were to learn one which one would offer the best place to start and which is the most sought/standard in the industry? Also please let me know if you have any preferences over the others in terms of performance and features. Thanks

Share this post


Link to post
Share on other sites
Advertisement
Well, are you using DX or OGL? Cg can be used with either, but HLSL only works with DX and GLSL only with OGL.

Share this post


Link to post
Share on other sites
Cg also has interfaces and unsized arrays.

Cg is being used a lot in the industry now. Even more so since we are more actively supporting it. For a while it was stagnating.

Many game companies, like crytek for example, are using it. Big content creation companies like Maya for example are using it. Havok is even using it for HavokFX. Unless you hate external libraries, Cg is the way to go.

Cg also has a GLSL profile so your Cg code will be compiled to GLSL code.

The thing I don't like about GLSL is that any new features to the language forces everyone to wait until new drivers come out that support this feature and this also requires anyone who uses your program to upgrade drivers. With Cg, a new version is as simple as dropping in a new set of dlls and you're ready to go. No requiring everyone to upgrade to buggy beta drivers just for a new feature or performance enhancement to the shading language. Plus you don't get FX style effects in GLSL (at least not yet I guess). Cg has CgFX that's built into the runtime.

HLSL is fine for many D3D apps, but it just doesn't have the features and flexability Cg has (like unsized arrays and interfaces as I mentioned before). CgFX is much more powerfull than D3D's FX as in CgFX you can set MANY more states (pretty much all states/modes possible) that you can't in FX. This is why the FXComposer guys are going to CgFX (well one of the reasons anyway). D3D's FX has a very limited number of states/modes to set in there. This may not matter for doom 3 style bump mapping, but for more advanced/complicated things, this is not a good thing.

Share this post


Link to post
Share on other sites
While everything SirKnight said is true, I'd like to point out one MAJOR flaw with the current release of Cg: It's slow as hell. It makes THOUSANDS of pointless API calls per frame (at least, the OpenGL runtime does!), and WILL cause your app to become completly CPU limited if you're doing anything substantial with it.

Hopefully Nvidia will fix this with a later release, but you should be aware that this will happen (I wasn't, and apparently neither was Nvidia, it's not documented anywhere!).

Good luck!

Share this post


Link to post
Share on other sites
To be honest, they're all pretty easy-to-use. My least favourite is probably GLSL since it goes a bit far with type "safety" and the like. Granted, if you uses GLSL on NVIDIA, it'll just ignore your type errors anyways and compile away with cgc (something which is extremely annoying when trying to write portable code I might add ;).

Anyways Cg is fine too, although I think you'll have more luck managing your own state in the current APIs (for speed mostly). With state sets coming, this will become something that we can easily attach to shaders and "effects", but for now, minimizing API calls is still a huge win.

Share this post


Link to post
Share on other sites
Don't forget Cg is also useful without using its libraries as it is a standalone compiler too. I use it in my current project to compile high-level shader code to OpenGL ARB_*_program assembly offline.

It supports most D3D and OGL shader languages as a target.

Share this post


Link to post
Share on other sites
Quote:
Original post by SirKnight
[Why Cg is better than everything else]
That's all well and good, but until you guys fix the ridiculous number of calls that Cg causes under OpenGL (acknowledged by Cass Everitt here), Cg isn't really a viable choice. So if 1.5 final fixes it, at whatever vague date you guys are planning to do that, then great, but until then I don't think Cg is worth having any substantial interest in.

It doesn't help that the GLSL profile in 1.5 beta 2 crashes (at least under OSX 10.3), either.

Share this post


Link to post
Share on other sites
In the sense of getting a job, I d vote for GLSL. More available since it and OGL are to be supported on non-traditional platforms such as mobile devices. And in an academic setting, I would assume DX+HLSL is the last choice.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!