Jump to content
  • Advertisement
Sign in to follow this  
PinkFish

nvidia cg runtime question

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

Howdy, I am using the cg runtime + direct3d9 the issue is this: cgD3D9SetUniform() and cgD3D9SetUniformArray() only accept float values, but i am planning to have the values stored in a more felxible way, float, ints ... (is that bad?) so to set values that are not floats as shader constants i will have to bypass cgD3D9SetUniform() and use the interface minimally, the cg reference manual (1.4.1) suggests:
 // Get the D3D resource locations for parameters
  // This can be done earlier and saved 
  DWORD vsReg = cgGetParameterResourceIndex(vsModelView);
  DWORD stage = cgGetParameterResourceIndex(psBaseTexture);
  DWORD psReg = cgGetParameterResourceIndex(psColor);

  // Set the D3D state 
  pDev->SetVertexShaderConstantF(vsReg, &mv, 4);
  pDev->SetPixelShaderConstantF(psReg, &color, 1);

this is all nice, but can i also use SetVertexShaderConstantB or SetVertexShaderConstantI after getting the register index with cgGetParameterResourceIndex? AND how do i handle offsets the way cgD3D9SetUniformArray() handles them? can i use the parameter sizes to determin register offsets? if a cg struct like this { float3 dummy[16]; } returns a cgGetParameterResourceIndex() of lets say 0, can i then say that the register index for dummy[1] is 0 + sizeof(float3) ? I guess not? then my problem is how do i implement functionality that can use offset values like cgD3D9SetUniformArray ?

Share this post


Link to post
Share on other sites
Advertisement
i think i figured it out, i should iterate thru the leaf parameters and use cgD3D9TypeToSize ? will that work?

and one more question: is cgGetParameterResourceIndex 'fast enough' to be used at run time or is tit better to cache its result?

[Edited by - PinkFish on September 23, 2006 1:28:56 PM]

Share this post


Link to post
Share on other sites
You could always use the "generic" parameter setter functions defined in cg.h. Like cgSetParameter3f, etc...

These are actually recommended over the API specific setters like cgD3D9SetUniform.

Share this post


Link to post
Share on other sites
Quote:
Original post by SirKnight
You could always use the "generic" parameter setter functions defined in cg.h. Like cgSetParameter3f, etc...

These are actually recommended over the API specific setters like cgD3D9SetUniform.


Ah thx! i didnt know those would work, and since u mentioned it, how do they handle setting per exmaple only one float value?? since the underlying d3d9 functions dont take anything that is not a group of 4 floats, or?

Share this post


Link to post
Share on other sites
ok so cgSetParameterValue isnt working for me

this doesnt work, the value (a simple color) isnt taken into account
produces no d3d warnings/errors in debug window,


//vf is a float[3]
cgSetParameterValuefr(param, 1, vf);



now this, works like a charm!!


DWORD vsReg = cgGetParameterResourceIndex(param);

float test[] = {fv[0], vf[1], vf[2], 0.0f};

DWORD ret = pDev->SetVertexShaderConstantF(vsReg, test, 1);



i didnt try cgD3D9SetUniform yet.

what should i do? am i using cgSetParameterValuefr the wrong way?
or is it a bug?

Share this post


Link to post
Share on other sites
ok cgD3D9SetUniform works as well,

but cgSetParameterValue doesnt seem to do anything! any ideas?

[Edited by - PinkFish on September 25, 2006 4:31:23 AM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!