Sign in to follow this  

CgFx interface as function parameter.

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

I want to be able to pass an interface through from my main shader function (vertProgram below), to another function called within it (useTestInterface below). In my main shader when I try to do this I get an error within the function that has the interface as a parameter: "../Data/Shaders/L_AtmosphericScattering.cg(80) : error C1010: expression left of ."fixCameraPos" is not a struct or array" The code below is a test case I put together to demonstrate the problem. Unfortunately when I try to compile this code the compiler returns CG_COMPILER_ERROR but the cgGetLastListing returns NULL. Could anyone else confirm this for me, or tell me if I should be able to pass interfaces as function parameters (rather than just as uniform shader parameters to the main shader functions)? Thanks!
interface TestInterface
{
	float func();
};

struct TestImpl : TestInterface
{
	float func()
	{
		return 0.0;
	}
};

float useTestInterface(TestInterface iface)
{
	return iface.func();
}

void vertProgram(float3 pos : POSITION, 
				 uniform float4x4 modelViewProj,
				 uniform TestInterface iface,
				 out float4 OUTposition : POSITION)
{
	OUTposition = mul(modelViewProj, float4(pos, 1));
	OUTposition.w = useTestInterface(iface);
}

void fragProgram(out float4 destPixel : COLOR)
{
	destPixel = float4(0);
}

float4x4 ModelViewProj : ModelViewProjectionMat;
TestImpl testImpl;

technique nv40
{
	pass
	{
		VertexProgram = compile glslv vertProgram(ModelViewProj, testImpl);
		FragmentProgram = compile glslf fragProgram();
	}
}

Share this post


Link to post
Share on other sites
I have no experience with interfaces so I can't issue a verdict with utmost certainty, but compiling your effect with the command-line compiler returned no error. Here's the syntax in case you want to give it a shot:

cgc -fx -strict -noentry [filename]

Bear in mind though that when compiling effects (as opposed to shaders), many of compile errors are revealed when the target technique is actually validated (via cgValidateTechnique) meaning that compiling the effect with the command-line compiler doesn't guarantee that your program is indeed error-free, although it's understood that codes that compile with no errors with cgc should pass cgCreateEffectFromFile or any of its variations nonetheless.

Have you actually compiled and validated the posted test case to see whether it too contains an error or is it just guesswork? I understand that you are pretty frustrated with Cg. Believe me, I've also had my own share of nightmares problems with it. Working with Cg involves exploring dark uncharted territories so be patient. :)

Share this post


Link to post
Share on other sites
I get the same result, it compiles using the command line, but when using cgCreateEffectFromFile() the error state gets set, CG_COMPILE_ERROR, but cgGetLastListing returns NULL.
(Another) API bug I guess.
I have been using Cg on and off for a few years now, and its definitly a love hate relationship. I think nVidia only has two people working on. They haven't updated the users manual since 1.4, and from what I can tell there is no proper documentation for CgFx. I am tempted to try and write a guide to all its gotchas but even after years of using it I still don't know them all!
Anyway I can fix the interface problem by using the declared variable as a global instead of passing it through. Its messy, but I don't have a choice :/

Thanks for trying this out for me and replying!

Share this post


Link to post
Share on other sites

This topic is 3291 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this