Is it viable to replace GLSL with CG?
Asked Answered
M

3

6

http://http.developer.nvidia.com/Cg/TessellationControlShader.html

I have some questions regarding CG.

What OpenGL version does CG support? On their site they state

Opengl Functionality Requirements

OpenGL 1.0

Which seems a little bit odd to me. For me this means that I need to have at least OpenGL 1.0 to use all OpenGL features in CG. So litteraly all new OpenGL features are missing?

Also the compute shader seems to be missing

GeometryShader, PixelShader, TessellationEvaluationShader, VertexShader, FragmentProgram, GeometryProgram, TessellationControlProgram, TessellationEvaluationProgram, VertexProgram

Is CG now a viable alternative to replace GLSL 4.x? Can I write all shaders in CG that I could write in GLSL 4.3?

Mono answered 20/1, 2013 at 1:50 Comment(0)
K
3

I'm pretty sure that OpenGL-1.0 is a typo. DirectX-11 is about the function level you get with OpenGL-4.0. Now look what key is right below the 4 on the numpad.

In fact no single NVidia GPU ever did support only a OpenGL profile as low as OpenGL-1.0. OpenGL-1.0 dates back 20 years.


Is CG now a viable alternative to replace GLSL 4.x?

Well, I personally don't see a reason why to use Cg, except if you want to support both OpenGL and DirectX with a common set of shaders. But why would you want cross API compatibility? If you aim for portability then OpenGL wins clearly over DirectX.

IMHO the main reason to keep using Cg is, if you have to maintain a legacy product that uses Cg already. Remember that Cg was introduced long before OpenGL had a high level shading language.

Can I write all shaders in CG that I could write in GLSL 4.3?

Yes.

Kraemer answered 20/1, 2013 at 2:24 Comment(7)
I agree, just want to add that it's not unreasonable to have an directx backend for windows and opengl for everything else. The thing is, opengl drivers in windows are mostly really bad .. a thing that has bitten me in development many times.Clava
Thanks datenwolf. I usually would use GLSL but I am starting to learn unity3d(game engine) and it uses cg for their shaders. Because unity uses directx under windows and opengl for everything else.(Currenlty supports only opengl2.1). I am a beginner and I want to focus on one language at a time, so I could get proficient in CG without worrying to learn GLSL too. (At least for now)Mono
@fscan: Only the Intel GPU drivers for Windows are IMHO subpar OpenGL quality. Both NVidia and AMD/ATI deliver decent OpenGL quality and performance in Windows. Of course you must install the drivers obtained from their website. The drivers Microsoft ships with Windows are crippled.Kraemer
@MaikKlein: Yes, you can learn Cg perfectly well without knowing GLSL. Later on it will be rather easy to also learn GLSL, but be prepared for a few surprises.Kraemer
@datenwolf, had a bug with cubemap rendering (for shadow mapping) on amd, took them about 5 months to fix. In directx this wouldn't have happened, because many games wouldn't have work and they would have fixed this asap. I'm not saying you shouldn't use opengl, just saying with directx your on the saver side in windows.Clava
@fscan: That's got nothing to do with Windows itself. In DirectX, Microsoft is the one and only implementer of the HLSL compiler. In OpenGL, each IHV implements the GLSL compiler. For all intents and purposes, AMD's GLSL compiler in Windows shares the same codebase as Linux. The thing that has bitten you is not that OpenGL drivers are poor on Windows, but that every part of OpenGL is implemented from scratch by each individual hardware vendor so behavior varies wildly between NV, AMD, Intel, PowerVR, ARM, and so on and so forth. WebGL gets around this by using ANGLE for shader validation.Ouzel
@AndonM.Coleman I never said it was Windows fault (ok .. maybe, but just for deciding to go DirectX instead of OpenGL). I know all this but i don't really care. The end effect is that DirectX drivers for windows are better tested and therefore more stable and have less bugs then the OpenGL drivers. Just as a sidenote, i always use OpenGL, just wanted to hint at the potential drawbacks.Clava
T
4

Is CG now a viable alternative to replace GLSL 4.x? Can I write all shaders in CG that I could write in GLSL 4.3?

No. While some OpenGL 4.x features, such as tessellation, are exposed as of Cg 3.1, others are not.

Notable missing features in Cg 3.1 (and their OpenGL names) include:

  • compute shaders
  • atomic counters
  • shader-writeable storage blocks (shader storage blocks)
  • shader-writable textures (image load / store)
  • runtime shader function selection (shader subroutines)

In general, Cg tends to lag two or three years behind the latest OpenGL release.

Tomboy answered 30/11, 2013 at 19:23 Comment(1)
Funny how things have changed. It used to be (~2002) that the only way to access cutting-edge shader hardware functionality on NV hardware in OpenGL using a high-level language was through Cg. Back then GL lagged behind Cg by 2-3 years, and this was the reason to use Cg. It sure beat writing assembly language shaders.Ouzel
R
4

Cg has been end-of-lifed by NVidia so it will not be developed going forward:

The Cg Toolkit is a legacy NVIDIA toolkit no longer under active development or support. Cg 3.1 is our last release and while we continue to make it available to developers, we do not recommend using it in new development projects because future hardware features may not be supported.

So I think the best answer would be No.

Rudolphrudwik answered 30/7, 2014 at 21:22 Comment(0)
K
3

I'm pretty sure that OpenGL-1.0 is a typo. DirectX-11 is about the function level you get with OpenGL-4.0. Now look what key is right below the 4 on the numpad.

In fact no single NVidia GPU ever did support only a OpenGL profile as low as OpenGL-1.0. OpenGL-1.0 dates back 20 years.


Is CG now a viable alternative to replace GLSL 4.x?

Well, I personally don't see a reason why to use Cg, except if you want to support both OpenGL and DirectX with a common set of shaders. But why would you want cross API compatibility? If you aim for portability then OpenGL wins clearly over DirectX.

IMHO the main reason to keep using Cg is, if you have to maintain a legacy product that uses Cg already. Remember that Cg was introduced long before OpenGL had a high level shading language.

Can I write all shaders in CG that I could write in GLSL 4.3?

Yes.

Kraemer answered 20/1, 2013 at 2:24 Comment(7)
I agree, just want to add that it's not unreasonable to have an directx backend for windows and opengl for everything else. The thing is, opengl drivers in windows are mostly really bad .. a thing that has bitten me in development many times.Clava
Thanks datenwolf. I usually would use GLSL but I am starting to learn unity3d(game engine) and it uses cg for their shaders. Because unity uses directx under windows and opengl for everything else.(Currenlty supports only opengl2.1). I am a beginner and I want to focus on one language at a time, so I could get proficient in CG without worrying to learn GLSL too. (At least for now)Mono
@fscan: Only the Intel GPU drivers for Windows are IMHO subpar OpenGL quality. Both NVidia and AMD/ATI deliver decent OpenGL quality and performance in Windows. Of course you must install the drivers obtained from their website. The drivers Microsoft ships with Windows are crippled.Kraemer
@MaikKlein: Yes, you can learn Cg perfectly well without knowing GLSL. Later on it will be rather easy to also learn GLSL, but be prepared for a few surprises.Kraemer
@datenwolf, had a bug with cubemap rendering (for shadow mapping) on amd, took them about 5 months to fix. In directx this wouldn't have happened, because many games wouldn't have work and they would have fixed this asap. I'm not saying you shouldn't use opengl, just saying with directx your on the saver side in windows.Clava
@fscan: That's got nothing to do with Windows itself. In DirectX, Microsoft is the one and only implementer of the HLSL compiler. In OpenGL, each IHV implements the GLSL compiler. For all intents and purposes, AMD's GLSL compiler in Windows shares the same codebase as Linux. The thing that has bitten you is not that OpenGL drivers are poor on Windows, but that every part of OpenGL is implemented from scratch by each individual hardware vendor so behavior varies wildly between NV, AMD, Intel, PowerVR, ARM, and so on and so forth. WebGL gets around this by using ANGLE for shader validation.Ouzel
@AndonM.Coleman I never said it was Windows fault (ok .. maybe, but just for deciding to go DirectX instead of OpenGL). I know all this but i don't really care. The end effect is that DirectX drivers for windows are better tested and therefore more stable and have less bugs then the OpenGL drivers. Just as a sidenote, i always use OpenGL, just wanted to hint at the potential drawbacks.Clava

© 2022 - 2024 — McMap. All rights reserved.