Getting .fx file value by semantic? FIXED

Started by
4 comments, last by circlesoft 18 years, 2 months ago
It seems that DirectX will not initialize a global matrix in an effect file, even if you specify a semantic for a global matrix. (At least that's what I've noticed.) Is it possible to set the value for a matrix if you know only its semantic? In other words, I would like to be able to specify, in my C++ code, something setWorldMatrix(a matrix in the effect file with a WORLD semantic.) If not, then I suppose I'll have to hard code the matrix name in my application, and just make sure that I use consistent naming through my effects files, but that doesn't seem like the cleanest solution. Any ideas? [Edited by - ITGER on January 28, 2006 4:47:59 PM]
Advertisement
You can use a semantic to set the value of a variable in an .fx file without a problem. Make sure that your .fx file is actually using this variable, though. If the variable is never used, the compiler may be optimizing it out.

Make a call to ID3DXEffect::GetParameterBySemantic and make sure that the handle returned is a valid handle. Using this handle, you should be able to call the appropriate ID3DXEffect::Set* method.

neneboricua
When I do GetParameterBySemantic, I get a bad pointer (or at least visual studio tells me it is) for certain matrices. I'll keep looking into it...
Quote:Original post by neneboricua19
Make sure that your .fx file is actually using this variable, though. If the variable is never used, the compiler may be optimizing it out.

Ah yea, it has done that to me many times, even though I turned off optimizations. So watch out for that.

Quote:When I do GetParameterBySemantic, I get a bad pointer (or at least visual studio tells me it is) for certain matrices. I'll keep looking into it...

When you look at it in the Visual Studio debugger, it may tell you the handle value is a bad pointer. I have had this happen before, because the handle doesn't actually point to any location in system memory. It is just a code for the registers, suposedly.

If ID3DXEffect::GetParameterBySemantic() returns S_OK, you are good to go.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
I fixed my problem. The rule is that strings can always be used as handles, but not vice versa. In fact, I was extracting a handle from the effects file, and then putting it as the key type in a std::map<std::string, something>. This is of course no good, because if the handle is not a valid string pointer, then the std::string construction will go horribly wrong.

Quote:If ID3DXEffect::GetParameterBySemantic() returns S_OK, you are good to go.


Actually, I think that GetParameterBySemantic() returns a handle.
Quote:Original post by ITGER
Actually, I think that GetParameterBySemantic() returns a handle.

Ah my bad, you are correct. If it returns NULL, it couldn't find your constant. Another value is a valid handle.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )

This topic is closed to new replies.

Advertisement