Jump to content
  • Advertisement
Sign in to follow this  
pcmaster

OpenGL NVIDIA Cg vs. HLSL vs. GLSL

This topic is 2618 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

Greetings, community!

I've worked with both HLSL (4.0+) and GLSL (1.5/3.x) but NVIDIA Cg has barely gone around me. I'll be in need of porting a DirectX 11 software to GNU/Linux and probably OS X, therefore, somehow, into OpenGL. The SW has dozens of HLSL über-shaders and a resource system built on top of DirectX 11 resources. The SW does not use any swap-chain, everything is rendered to buffers and textures, not to screen. It isn't really real-time.

Now, it'd be of much help, if you, guys, helped me explain the state of the art with Cg, for example, and a few other things. So:

1. Does Cg really support all the current features of DirectX 11 (HLSL 5) and OpenGL 4.x (GLSL 4.x)? I read it should. I'm only targeting SM5.0 HW, nothing lower.
2. Does Cg work seamlessly on GNU/Linux and Apple desktop platforms? I read it should.
3. What's its main difference to DirectX API and OpenGL API which themselves are conceptually different? Does Cg abstract DX10+ concepts such as devices, contexts or views anyhow?
4. Do you think there's another, better, way? In any sense. Anything abstracting the aforementioned concepts, so they'd work with OpenGL platforms, too?
5. What about ATI/AMD GPUs with NVIDIA Cg?
6. How about shader compilation? Will still OpenGL drivers need to compile each shader on-the-fly, unlike the DX fxc.exe?

Cg came to my mind for this purpose since it's supposed to "output DirectX and OpenGL code" and it looks like HLSL, obviously :-) I know I'd get to the answers myself eventually but I'm still hoping for any insights.

Share this post


Link to post
Share on other sites
Advertisement

1. Does Cg really support all the current features of DirectX 11 (HLSL 5) and OpenGL 4.x (GLSL 4.x)? I read it should. I'm only targeting SM5.0 HW, nothing lower.
2. Does Cg work seamlessly on GNU/Linux and Apple desktop platforms? I read it should.
3. What's its main difference to DirectX API and OpenGL API which themselves are conceptually different? Does Cg abstract DX10+ concepts such as devices, contexts or views anyhow?
4. Do you think there's another, better, way? In any sense. Anything abstracting the aforementioned concepts, so they'd work with OpenGL platforms, too?
5. What about ATI/AMD GPUs with NVIDIA Cg?
6. How about shader compilation? Will still OpenGL drivers need to compile each shader on-the-fly, unlike the DX fxc.exe?

Cg came to my mind for this purpose since it's supposed to "output DirectX and OpenGL code" and it looks like HLSL, obviously :-) I know I'd get to the answers myself eventually but I'm still hoping for any insights.


1 & 2) Should as that's the point of Cg, but I don't have first hand experience.

3 & 4) If you look at the Cg API reference manual, the Cg runtime is broken into a "core" runtime and specific modules for Direct3D 8-11, and OpenGL. Its in those that things get specific like setting a device, binding/unbinding the shaders (since you need the device), setting shader resource views, etc. So if your application can switch between rendering systems, this is the part you'd need to use in an abstraction.

5) I would assume ATI shouldn't have any problem, because by that time Cg shaders will be compiled down into the respective representations that HLSL/GLSL would be in. Getting your Cg shaders into that state and using them at runtime however, is what's different - and that's all CPU based.

6) The Cg toolkit does come with a compiler similar to fxc, but the output would be GL/D3D specific compiled code. I believe if you keep with the Cg source programs to be loaded at runtime, it will always be on the fly since it'll have to be translated at some point.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!