OpenGL: C and D same code - different results
Lionello Lunesu
lio at lunesu.remove.com
Wed Feb 7 03:43:22 PST 2007
dyh wrote:
> recently I've tried few OpenGL examples ported from C to D (on win32)
> and have run into strange problems.
>
> Translated example was built against same C libs as original, using same
> (translated from platform sdk) headers. Resulted binary is using same dlls
> as original. But there are some differences:
>
> 1. Behavior
> In original calls glIndexi() has *no* effect. In translation has.
> In original calls glColor3f() has effect. In translation has *not*.
> In original initial color is white. In translation it is kind of brown.
>
> 2. Performance
> original example performs noticeably faster than translated one.
>
> No matter what compiler switches I've tried (-O, -inline, -release, etc).
> Example is extremely simple, and i do not see any possibilities to have any
> difference in performance. There is no GC used - there are no memory
> allocations array slice at all. Actually there are no array usage. In fact
> there is nothing at all except opengl api calls. And it is literally same
> library in both example and translation.
>
> Here is code (~300 lines)
> original (C) http://paste.dprogramming.com/dpfwrsgw.php
> translation (D) http://paste.dprogramming.com/dpu768pr.php.
>
> Any tips from opengl experts?
No tips, since I'm pretty new at this myself, but I've just finished
translating nVidia's glsl_pseudo_instancing* sample from C++ to D, and
believe it or not, D's version is actually faster (albeit by a mere 1%).
That really surprised me, since the MSVC 2005 compiler is really good at
FPU stuff, plus that whole-program-optimization thing they have.
So I'm confident there must be something else going on in your case. A
literal translation to D should not cause big differences. Well, no
negative differences anyway ;)
By the way, the C++ version had many uninitialized variables. Thanks,
Walter, for making floats default to NaN. It's really easy to track the
source of a uninited variable this way!
L.
(*If anybody wants that app, just say it)
More information about the Digitalmars-d
mailing list