Sign in to follow this  
ZeroEffect

SetLight() & SetMaterial()

Recommended Posts

When I set a light or a material using IDirect3DDevice9::SetMaterial Method or IDirect3DDevice9::SetLight Method, I'm passing in a pointer to a struct. My question is: Does Direct3D internally keep the pointer to the struct or does it copy the values to an internal struct? Meaning, if I make a change to that struct (color, etc...) will I need to set that light/material again? Or, if it is just accessing the ptr, will it be updated automatically? Thx, Chris Z.

Share this post


Link to post
Share on other sites
Interesting question. After digging deeply, I found that once you call SetLight() or SetMaterial(), the runtime simply references your light or material struct and adds a state to the command buffer in the card's driver. However, the driver then takes this info in your structure and sends it directly onto the hardware. This means that you can't update the data anymore by simply accessing the pointer.

You may be able to change it by accessing the pointer shortly after your call to SetLight() or SetMaterial(), but only until that command in the buffer is serviced. Which is a really, really short time anyways. So, the answer is no [smile].

Share this post


Link to post
Share on other sites
Thanks,

One follow up question then. Being that there is that really short time in which changes to the ptr may be realized, could I get into trouble if a local light/material object falls out of scope before the info is transferred?

eg.
SomeFunction() {
D3D9Material9 material;
// set defaults
...
pd3dDevice->SetMaterial( &material );

// return immediately
}

Or, would the timeframe be so small that the memory wouldn't have time to be reallocated and overwritten?



Share this post


Link to post
Share on other sites
Quote:
Original post by ZeroEffect
Or, would the timeframe be so small that the memory wouldn't have time to be reallocated and overwritten?
Yea, I believe that is the case (the time gap is virtually zero). I've certainly *never* had a problem with it.

Share this post


Link to post
Share on other sites

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