Skip to main content
gamedev.net
🔒 Locked

Effect Handles

Started by Jiia Oct 5, 2004 at 3:22 PM 1 replies 500+ views
Original Post
Jiia
Jiia
Bah, MS [disturbed] Can anyone make sense of this?
Quote:
DirectX Documentation: ID3DXEffect::GetParameterByName Method -------------------------------------------------------------------------------- Gets the handle of a top-level parameter or a structure member parameter by looking up its name. Syntax D3DXHANDLE GetParameterByName( D3DXHANDLE hParameter, LPCSTR pName ); hParameter [in] Handle of the parameter, or NULL for top-level parameters. See Handles. pName [in] String containing the parameter name.
vs
Quote:
DirectX Documentation: When setting uniform shader constants, it is more efficient to cache a handle to the parameter by calling ID3DXEffect::GetParameterByName. This avoids the string lookup that is necessary when calling effect methods like ID3DXEffect::SetMatrix. // Instead of setting a uniform constant like this in the render loop g_pEffect->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection ); // Get a handle to a uniform constant outside of the render loop D3DXHANDLE hParameter; GetParameterByName( hParameter,"g_mWorldViewProjection"); ... // Use the handle to set the uniform constant in the render loop g_pEffect->SetMatrix(hParameter);
I don't understand what's going on. D3DXHANDLE is defined as "const char*". How could GetParameterByName( hParameter,"g_mWorldViewProjection"); be filling hParameter with a handle? The parameter is even accepted as [in]. Also, what is up with "g_pEffect->SetMatrix(hParameter);". How exactly is that setting a matrix in the shader? There isn't even a matrix being passed? I've tried using the return value, but it turns out null. There are no error codes to speak of. Anyone know how to do this? [smile]
fiskbil
fiskbil
D3DXHANDLE h;ID3DXEffect* effect=<foo>;h=effect->GetParameterByName(0, "g_mWorldViewProjection");


That should work, that will give you the handle in h. Instead of using h as a pointer to a string they use it as an integer since a pointer is just an integer.

Works for me at least :)

edit: Perhaps I should clarify that 0 there. That means that you want to search for the parameter from the beginning of the effect. You could pass in a valid handle to start searching from that point on. If you get 0 as return value something went wrong.

Good luck
Jiia
Jiia
Hmmm. It's not working for me. That's what I tried originally, but the return values are null. I guess that means I'm screwing up somewhere before this, heh.

Thanks much for your help [smile]

EDIT: Thanks for the EDIT to clear up that first parameter [lol]

EDIT2: Damn. I was trying to get a technique handle using this method. That's why one of the return values was null. I didn't realize there was an entirely different function for that.

Thanks again!

[Edited by - Jiia on October 5, 2004 4:35:19 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.