Question

I' have the following CgFx file:

struct VertIn {
  float4 pos   : POSITION;
  float4 color : COLOR0;
};
struct VertOut {
  float4 pos   : POSITION;
  float4 color : COLOR0;
};
VertOut vert(VertIn IN) {
  VertOut OUT;
  OUT.pos     = IN.pos;
  OUT.color   = IN.color;
  OUT.color.z = 0.0f;
  return OUT;
}
struct FragIn {
  float4 color: COLOR;
};
struct FragOut {
  float4 color : COLOR;
};
FragOut frag(FragIn IN) {
  FragOut OUT;
  OUT.color = IN.color;
  OUT.color.y = 0.0f;
  return OUT;
}
struct GeomIn {
  float4 position : POSITION;
  float4 color : COLOR0;
};
TRIANGLE void geom(AttribArray<GeomIn> IN) {
  for(int i=0; i<IN.length; i++) {
    emitVertex(IN[i]);
  }
}
technique technique0 {
  pass p0 {
    VertexShader = compile gp4vp vert();    //line 47
    FragmentShader = compile gp4fp frag();  //line 48
    GeometryShader = compile gp4gp geom();  //line 49
  }
}

when using cgc to verify the 3 shaders, they all compile fine.

but when I try to compile the whole effect using:

context=cgCreateContext();
effect=cgCreateEffectFromFile(context, "my_shader.cgfx", NULL);
if(!effect) {
  printf(ygl.cgGetLastErrorString(NULL));
  printf(cgGetLastListing(context));
}

then I get the following errors:

CG ERROR : The compile returned an error.
my_shader.cgfx(47) : error C8001: Unknown state 'VertexShader'
my_shader.cgfx(48) : error C8001: Unknown state 'FragmentShader'
my_shader.cgfx(49) : error C8001: Unknown state 'GeometryShader'

What do I do wrong?

Was it helpful?

Solution

After creating your context, you need to call

cgGLRegisterStates(handle);

where handle is your CG context handle. This will register things like VertexShader, PixelShader, FillMode, etc. I'm not sure why those aren't registered by default, but there you have it.

OTHER TIPS

well, solved it, but don't know how. I think the compiler didn't expect CgFx because i did load a cg profile earlier, so it tried to use that one. but not sure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top