Working with floating-point precision
I don't recommend to use the D3DCREATE_FPU_PRESERVE flags in IDirect3D9::CreateDevice(), because many errors can happen as usually libraries and drivers suppose that FPU is in single precision as D3D changes it.
Another solution, and the best, is that if we want to use 'double' vars (double FPU precision) we can do this:
{
unsigned int uiTemp=(_controlfp(0,0) & _MCW_PC); //save the FPU precision
_controlfp(_PC_53,_MCW_PC); //change to default 64-bit
.... code with 'double' data
_controlfp(uiTemp,_MCW_PC); //restore
}
If you try to use 'double' within D3D apps, you can notice that you have 'float' results for 'double' data, because D3D has changed the FPU precision to single.
Or more generic:
{
unsigned int uiTemp=_controlfp(0,0); //save the FPU state
_controlfp(); //changes
...
_controlfp(); //changes
.... code with 'double' data
_controlfp(uiTemp,0xffffffff); //restore
}
{
unsigned int uiTemp=_controlfp(0,0); //save the FPU state
_controlfp(); //changes
...
_controlfp(); //changes
.... code with 'double' data
_controlfp(uiTemp,0xffffffff); //restore
}
Perhaps a more important question is why you need to use double precision in code that's communicating with D3D in the first place...
I can't think of any game graphics situations where double precision really is the only answer or even most appropriate over single precision.
If you really do have one of those rare cases, it's best to split as much of your code into two parts so that you preserve/toggle/restore the FPCW only as much as is really necessary.
I can't think of any game graphics situations where double precision really is the only answer or even most appropriate over single precision.
If you really do have one of those rare cases, it's best to split as much of your code into two parts so that you preserve/toggle/restore the FPCW only as much as is really necessary.
Quote:Perhaps a more important question is why you need to use double precision in code that's communicating with D3D in the first place...
That is not covered in this POST, but as you ask, an aswer could be for exampe an application that uses D3D for screen drawing but that uses complex computations (maybe maths applications?) with high need precision for internal computation.
Quote:If you really do have one of those rare cases, it's best to split as much of your code into two parts so that you preserve/toggle/restore the FPCW only as much as is really necessary.
That is not exactly what this POST says?, for that the 'code' example is so generic, anyone can later to adapt it to their programs.
Many people don't know that when you create a D3D device it changes the FPU precision, and I think is important to note it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement