When I'm making my OpenGL library, should I use float or double? I know I
will never have any use for double precision. But I keep thinking "what
if...". Some of my libraries are pretty nifty - like my camera library.
Maybe other people could benefit from it. And then I keep thinking "what if
they...". Float size vs double size is nothing in a camera library, so I'm
down to speed. How slow is double calculations vs float calculations?
CPU-wise and GPU-wise? Maybe the GPU is optimized for double? Maybe the
GPU only do floats, so it shorten all double to floats? Etc...?
Anyway, for now, I will use floats where it might slow down due to bandwith.
Like I will not use double for vertexes - unless someone convince me
otherwise. So I'm mainly interesting in calculation speed on the CPU. But
also, if someone got anything on using float vs double gl functions. Like
glTranslatef() vs glTranslated()
Just hit me with anything you got - though I already know the answer...
TIA!
, Espen
|
|
0
|
|
|
|
Reply
|
Espen
|
6/30/2003 12:28:07 PM |
|
Espen Ruud Schultz wrote:
>
> When I'm making my OpenGL library, should I use float or double? I know I
> will never have any use for double precision. But I keep thinking "what
> if...". Some of my libraries are pretty nifty - like my camera library.
> Maybe other people could benefit from it. And then I keep thinking "what if
> they...". Float size vs double size is nothing in a camera library, so I'm
> down to speed. How slow is double calculations vs float calculations?
> CPU-wise and GPU-wise? Maybe the GPU is optimized for double? Maybe the
> GPU only do floats, so it shorten all double to floats? Etc...?
>
> Anyway, for now, I will use floats where it might slow down due to bandwith.
> Like I will not use double for vertexes - unless someone convince me
> otherwise. So I'm mainly interesting in calculation speed on the CPU. But
> also, if someone got anything on using float vs double gl functions. Like
> glTranslatef() vs glTranslated()
What does your camera class look like? Can you parameterize it with C++
templates so you can use doubles or floats?
|
|
0
|
|
|
|
Reply
|
Starman
|
6/30/2003 1:14:23 PM
|
|
OpenGL uses intern (matrix calculation) matrices with data-type float. As
long as OpenGL takes the rotation, translation, and scale matrix
calculation, float precision is enough. But if you have large areas, like
flight simulation terrains, the translation must be done by the engine (not
OpenGL) to achieve double precision positions.
I believe OpenGL 2.0 calculates in double precision, but I�m not sure.
Regards,
Tom
"Espen Ruud Schultz" <default@nospam.invalid> wrote in message
news:h0WLa.9998$Hb.174009@news4.e.nsc.no...
> When I'm making my OpenGL library, should I use float or double? I know I
> will never have any use for double precision. But I keep thinking "what
> if...". Some of my libraries are pretty nifty - like my camera library.
> Maybe other people could benefit from it. And then I keep thinking "what
if
> they...". Float size vs double size is nothing in a camera library, so
I'm
> down to speed. How slow is double calculations vs float calculations?
> CPU-wise and GPU-wise? Maybe the GPU is optimized for double? Maybe the
> GPU only do floats, so it shorten all double to floats? Etc...?
>
> Anyway, for now, I will use floats where it might slow down due to
bandwith.
> Like I will not use double for vertexes - unless someone convince me
> otherwise. So I'm mainly interesting in calculation speed on the CPU.
But
> also, if someone got anything on using float vs double gl functions. Like
> glTranslatef() vs glTranslated()
>
> Just hit me with anything you got - though I already know the answer...
>
> TIA!
>
> , Espen
>
>
|
|
0
|
|
|
|
Reply
|
Tom
|
6/30/2003 1:44:36 PM
|
|
>>Camera<float> camera_float(0.0f, 0.0f, 0.0f, 20.0f, 30.0f, 40.0f); // A
>>float camera
>>
>>Camera<double> camera_double(0.0, 0.0, 0.0, 20.0, 30.0, 40.0); // A
>>double camera
>>
>
This seems like total overkill to me and a classic
example of the abuse of C++ templates.
For a camera class, use double, period. The reasons
why seem very very obvious to me - you're not worried
about memory usage, speed isn't an issue (I defy you
to measure a difference!) but accuracy most definitely
*is* an issue.
The same reasoning applies at all other similar classes
like lights, matrices, etc.
Vertex storage is another matter because doubles
occupy twice the memory and OpenGL is almost certainly
going to convert them to floats before use. For vertices,
use floats.
I don't personally know of any OpenGL implementation
which uses doubles, and I don't ever expect to see one
for the same reason that I don't see a fast glReadPixels()
anytime soon - nobody is really interested in it.
FWIW, my program uses doubles for modelling things,
then produces a "compiled" version of the data which
is stored as floats in the final data files.
PS: To answer the original question, Floats and doubles
are basically the same speed on a Pentium CPU because
inside the CPU there's only one number format - the
80 bit Intel format. Both floats and doubles are
converted to this format for calculations. There are
also no float versions of any of the "slow" functions
- division, sin(), cos(), sqrt(), etc.
The only time when floats are faster than doubles on
a Pentium is when you're working with massive arrays
and memory bandwidth becomes an issue. A camera class
has half a dozen numbers in it so it probably fits in
a cache line and there will be *zero* difference in
speed. None whatsoever.
--
<\___/> For email, remove my socks.
/ O O \
\_____/ FTB. Why isn't there mouse-flavored cat food?
|
|
0
|
|
|
|
Reply
|
fungus
|
6/30/2003 11:24:32 PM
|
|
"fungus" <openglMY@SOCKSartlum.com> wrote in message
news:QE3Ma.197131$SS4.223140@telenews.teleline.es
>>> Camera<float> camera_float(0.0f, 0.0f, 0.0f, 20.0f, 30.0f, 40.0f); //
>>> A float camera
>>>
>>> Camera<double> camera_double(0.0, 0.0, 0.0, 20.0, 30.0, 40.0); // A
>>> double camera
>>>
>>
>
> This seems like total overkill to me and a classic
> example of the abuse of C++ templates.
>
> For a camera class, use double, period. The reasons
> why seem very very obvious to me - you're not worried
> about memory usage, speed isn't an issue (I defy you
> to measure a difference!) but accuracy most definitely
> *is* an issue.
>
> The same reasoning applies at all other similar classes
> like lights, matrices, etc.
>
> Vertex storage is another matter because doubles
> occupy twice the memory and OpenGL is almost certainly
> going to convert them to floats before use. For vertices,
> use floats.
>
> I don't personally know of any OpenGL implementation
> which uses doubles, and I don't ever expect to see one
> for the same reason that I don't see a fast glReadPixels()
> anytime soon - nobody is really interested in it.
>
> FWIW, my program uses doubles for modelling things,
> then produces a "compiled" version of the data which
> is stored as floats in the final data files.
>
>
> PS: To answer the original question, Floats and doubles
> are basically the same speed on a Pentium CPU because
> inside the CPU there's only one number format - the
> 80 bit Intel format. Both floats and doubles are
> converted to this format for calculations. There are
> also no float versions of any of the "slow" functions
> - division, sin(), cos(), sqrt(), etc.
>
> The only time when floats are faster than doubles on
> a Pentium is when you're working with massive arrays
> and memory bandwidth becomes an issue. A camera class
> has half a dozen numbers in it so it probably fits in
> a cache line and there will be *zero* difference in
> speed. None whatsoever.
>
Thanx for an excellent and stright forward explanation of floats vs doubles!
And I am relieved to hear that using doubles instead of floats in my code
( except where memory and bandwith is an issue ) will not degrade or slow
down my program...
, Espen
|
|
0
|
|
|
|
Reply
|
Espen
|
6/30/2003 11:40:24 PM
|
|
|
4 Replies
435 Views
(page loaded in 0.581 seconds)
|