SetLight() & SetMaterial()

Started by
2 comments, last by circlesoft 19 years, 4 months ago
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.
Chris Z. GPU FX
Advertisement
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].
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
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?



Chris Z. GPU FX
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.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )

This topic is closed to new replies.

Advertisement