Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Direct 3D affecting data type double

Tags:

c++

direct3d

I recently added some DirectX code to my program, and now my double data type variables only have the range/resolution of a float (.. or atleast less range/resolution than they used to). If I remove the direct3D initialization - "Direct3DCreate9(D3D_SDK_VERSION)" - the problem goes away. Any insight? Thanks.

like image 311
Jeff Avatar asked Dec 14 '25 19:12

Jeff


2 Answers

Direct3D will modify the FPU state to force single precision mode.

If you want to preserve double-precision mode, use D3DCREATE_FPU_PRESERVE when you create the D3D device. That will have an effect on the performance of D3D though:

http://msdn.microsoft.com/en-us/library/bb172527(VS.85).aspx

like image 82
MSN Avatar answered Dec 16 '25 10:12

MSN


As explained in this blog entry: Direct3D and the FPU, you can tell Direct3D not to change the FPU mode to single precision:

Luckily, you can avoid all of this by simply telling Direct3D not to mess with the FPU at all. When creating the device you should use the CreateFlags.FpuPreserve flag to keep the CLR's double precision, and have your code functioning as you expect it.

like image 20
Greg Hewgill Avatar answered Dec 16 '25 09:12

Greg Hewgill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!