Sign in to follow this  

Getting .fx file value by semantic? FIXED

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

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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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