[fpc-pascal] Fastest way of drawing 2D graphs

Marco van de Voort marcov at stack.nl
Sat Sep 13 15:43:04 CEST 2014

In our previous episode, Hunter1972 said:
> > > I assume your polylines are basically an array of X,Y coordinates in single
> > precision + color information? If you supply examples of those, I'll see if
> > I can hack something together. (binary only, since it is a work codebase,
> > more to get you an idea of how workable it would be)
> Ok, I will describe the task in details (test code with sample data file is here: https://yadi.sk/d/ET9fp8AobSfXy).
> Sample file is CSV(Excel) where the first line is data field names, the first column is time, the other are detection values.
> Time (X coord) is float in seconds but actual time step is always 250 microseconds (0,00025 sec) precisely.
> Detections (Y coord) are always integers.


This is a Delphi (XE3) binary, but older versions of this codebase ran fine
under Lazarus.  The opengl code was originally done by Ales Kantona for our

It requires opengl3 and nonpower2 textures, and the upload will be slower on
integrated gfx, but if those are new enough (anything i3/i5/i7 and HD4500+
should work)

I hope it works, I had some problem with the CSV loading code that wasn't
aware of decimal separators.  Press "load" to load, then draw to draw.

Then clicking in the picture centers, and the top slider (or + and -
buttons) zoom.  ( from -64 to +64 magnification).
My zoom system is a bit specialized, so I hacked this in quickly. Not very
elegant, but this is just a demo.

I map the whole shebang on a 4096*4096 coordinate system, but this is
floating point.

On my I7-3770 I had the following timings:

load took 945.9 ms  (the CSV loading with your routines in Unicode delphi,
		     probably slower than lazarus)
canvas prepare took 222.8 ms ( the new draw routine)
upload to card took 334.8 ms (uploading to the GPU)

drawing/panning/zooming is not timed, but probably negible.

Total time +/- 45min. 

More information about the fpc-pascal mailing list