Has anyone been able to run fragment shaders (Cg)?

Vertex programs works just fine, but when I try to bind a fragment program, the jvm crashes.

I load the following fragment program:

void mainf (
                  float4 iColor : COLOR,
            out float4 oColor : COLOR            )
{
      oColor = iColor;
}

IE just a passthrough.
CgGL loads the program just fine and compiles it.

CgGL.cgGetProgramString(fragmentProgram, CgGL.CG_COMPILED_PROGRAM) shows the following:

// nvparse 1.0 output generated by NVIDIA Cg compiler
// cgc version 1.2.1001, build date Mar 17 2004  10:32:28
// command line args: -q -profile fp20 -entry mainf
//vendor NVIDIA Corporation
//version 1.0.02
//profile fp20
//program mainf
//var float4 iColor : $vin.COLOR : COLOR0 : 0 : 1
//var float4 oColor : $vout.COLOR : COLOR : 1 : 1
!!RC1.0
out.rgb = unsigned(col0.rgb);
out.a = unsigned(col0.a);
// 0 instructions
// End of program

Seems fine to me.

The rendering:

System.out.println("1");            
CgGL.cgGLEnableProfile(fragmentProfile);
System.out.println("2");            
CgGL.cgGLBindProgram(fragmentProgram);
System.out.println("3");            

renderModel(gl, glu);
        
CgGL.cgGLDisableProfile(fragmentProfile);

The output:

1
2
An unrecoverable stack overflow has occurred.

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_STACK_OVERFLOW (0xc00000fd) occurred at PC=0x2E74587
Function=[Unknown.]
Library=C:\Program Files\NVIDIA Corporation\Cg\bin\cgGL.dll

NOTE: We are unable to locate the function name symbol for the error
      just occurred. Please refer to release documentation for possible
      reason and solutions.


Current Java thread:
        at net.java.games.cg.CgGL.cgGLBindProgram0(Native Method)
        at net.java.games.cg.CgGL.cgGLBindProgram(CgGL.java:894)
        at CgTest.display(CgTest.java:77)
        at net.java.games.jogl.impl.GLDrawableHelper.display(GLDrawableHelper.java:74)
        at net.java.games.jogl.GLCanvas$DisplayAction.run(GLCanvas.java:221)
        at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:290)
        - locked <0x100901b8> (a net.java.games.jogl.impl.windows.WindowsOnscreenGLContext)
        at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:208)
        at net.java.games.jogl.GLCanvas.display(GLCanvas.java:75)
        at net.java.games.jogl.Animator$1.run(Animator.java:107)
        at java.lang.Thread.run(Thread.java:534)

Vertex programs work just fine, and the Cg effects browser thingie works without crashing.

Has anyone gotten this to work?

Would be useful to know what hardware you’re using, and what compile target you’re using. Some hardware, particularly GF2-class hardware, can’t support fragment shaders.

That’s not it. I’ve run the exact same fragment shader via the Cg effect browser thingie.

The target is fp20 (ie NV_texture_shader + NV_register_combiners), the call to CgGL.cgGLIsProfileSupported() returns true, the program compiles and loads just fine, and I’ve got a GF Ti4800. The only problem is a jvm crash when I bind it.

I can bind vertex programs just fine.

Even if you don’t know the solution to my problem, I’d really appreciate it if anyone who has managed to get fragment programs to work from jogl would say so. =)

We have them working fine, but not done any work with Cg. Whether or not a shader works is entirely dependent on the hardware and compile targets.

Er, ok. So what did you use? HLSL?

Everything but Cg… HLSL, GLSL and GL vp/fp. All work fine, including some rather complex work involving shaders being used on pbuffers before applying to the final surface.

Ah, 'fcourse.

starts pondering alternatives

Hi
I have seen cg fragmentshaders running in jogl, and as far as I can understand, once CG an GLSL and the like are compiled there should be no difference? (please correct me if i’m wrong)

// Gregof

That’s sort of correct. Cg currently compiles down to the OpenGL Vertex/Fragment Program capabilities which are part of the core API for GL 1.4. Even the new Cg 1.3 beta spec does not have a GLSL compile target yet. The profile may say it supports it, but you really have to check the hardware and drivers to know whether it really does.