Recent

Author Topic: intercepting exceptions  (Read 14988 times)

Rik

  • Jr. Member
  • **
  • Posts: 67
Re: intercepting exceptions
« Reply #45 on: August 21, 2018, 04:05:30 pm »
You mentioned that the reason you were doing this is because your computer was too slow to render the images in real time.  Using 10,000 handles and several gigabytes of memory is not going to make any computer faster, on the contrary, that guarantees that most machines would be overwhelmed if it worked.
I agree, there are 2 problems: too many handles and too much memory.
I did some tests and with 8GB RAM things work fine up to 3000 Bitmaps (about 2.5GB RAM consumption). But for sure this limit will depend on the computer used and on what other applications are running.

TBitmap and his brothers and sisters are relatively heavy consumers of system ressources: pen, brush, font, canvas, etc. And for graphics-heavy applications the answer to "how many ressources do I have" is always "not enough"  ;D
That is right! A 500 by 500 pixel Bitmap takes about 800kB, that is over 3 bytes/pixel. I would be more that happy to use 1 byte/pixel (256 colors). Even 16 colors (4 bits) would do the job. But I need to get it into an Image (or otherwise on to the screen) within 20 milliseconds.

Rik

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: intercepting exceptions
« Reply #46 on: August 21, 2018, 04:05:51 pm »
BTW, if you are trying to create a game, there are some good frameworks out there. Eg. http://wiki.freepascal.org/Castle_Game_Engine

Those should offer good tools to deal with those kind of issues. But you will have to do the reading up.


----------------
For starters: You do not want the images in your normal ram. You wont them in the ram of the gfx card.
« Last Edit: August 21, 2018, 04:07:48 pm by Martin_fr »

Rik

  • Jr. Member
  • **
  • Posts: 67
Re: intercepting exceptions
« Reply #47 on: August 21, 2018, 04:13:41 pm »
BTW, if you are trying to create a game, there are some good frameworks out there. Eg. http://wiki.freepascal.org/Castle_Game_Engine

Those should offer good tools to deal with those kind of issues. But you will have to do the reading up.


----------------
For starters: You do not want the images in your normal ram. You wont them in the ram of the gfx card.
It's not a game, but a "oscilloscope like" didactic tool. Nevertheless it might be useful to know how graphics are handled in games. Thanks for the hint.

Rik

440bx

  • Hero Member
  • *****
  • Posts: 3921
Re: intercepting exceptions
« Reply #48 on: August 21, 2018, 05:14:22 pm »
It's not a game, but a "oscilloscope like" didactic tool. Nevertheless it might be useful to know how graphics are handled in games. Thanks for the hint.

Rik
An "oscilloscope like"... what an oscilloscope shows is almost always representable by mathematical formulas.    It sounds like you could have just a few bitmaps to render the oscilloscope device and the oscilloscope screen.  What goes on the oscilloscope screen is often possible to draw very rapidly with Polyline or one of its variations.

Post one of the images.  If we could see a representative sample of the images you want to display, it may be possible to suggest a way of generating them that would have good performance without the large memory, resource and CPU impact of storing every image in a bitmap.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: intercepting exceptions
« Reply #49 on: August 21, 2018, 05:34:05 pm »
It's not a game, but a "oscilloscope like" didactic tool. Nevertheless it might be useful to know how graphics are handled in games. Thanks for the hint.

In game programming, OpenGL and DirectX are the most preferable because (almost) all graphics hardware are optimized for both of them. They have they own image buffers, which are very lightweight. For example, we use these in OpenGL
https://www.khronos.org/opengl/wiki/Image_Load_Store#Image_variables

I think maybe you can post a new thread on the Graphics forum and give it a catchy title "Graphics Challenge". Provide all the info we need, what are the inputs and outputs, requirements, how the results being calculated/processed. I believe you will received many great solutions from the masters in graphics programming.

Thaddy

  • Hero Member
  • *****
  • Posts: 14159
  • Probably until I exterminate Putin.
Re: intercepting exceptions
« Reply #50 on: August 21, 2018, 05:43:59 pm »

It's not a game, but a "oscilloscope like" didactic tool. Nevertheless it might be useful to know how graphics are handled in games. Thanks for the hint.

Rik
Then why are you using data that the human eye can't follow?
Although you can store the actual information, you have to allow - on display - for the human eye, which means you can throw away 99% of it....

I wrote a scope in KOL (works also in Lazarus+KOL). Here's the display component: http://members.chello.nl/t.koning8/kol_scope.jpg (very old but works and easy to translate to LCL)

You need to learn to scale and throw away data before you display. That's called sampling.
« Last Edit: August 21, 2018, 05:53:14 pm by Thaddy »
Specialize a type, not a var.

Rik

  • Jr. Member
  • **
  • Posts: 67
Re: intercepting exceptions
« Reply #51 on: August 21, 2018, 07:29:24 pm »
Then why are you using data that the human eye can't follow?
Although you can store the actual information, you have to allow - on display - for the human eye, which means you can throw away 99% of it....
I tried several refresh rates, anything below 50ms  or 20fps (frames per second) is "jumpy". Old school analog TV (PAL) uses 25fps (40ms), digital TV goes up to 60fps (17ms).
25 fps (40ms) works fine for me, but I want also to provide "half speed" option and therefore a need a 50 fps or a frame every 20ms to have that in good quality.

I wrote a scope in KOL (works also in Lazarus+KOL). Here's the display component: http://members.chello.nl/t.koning8/kol_scope.jpg (very old but works and easy to translate to LCL)
I also wrote a soundcard based scope many years ago, in Delphi5. Still available (http://www.qsl.net/on7yd/zip/RScope101.zip), but I am not sure it will work properly on recent OS.
But what I have in mind is not a real scope but an application that shows some (rather complicated) calculated functions in "real time".
First I tried calculations and drawing into an Image on the fly, but that was far too slow (on a 3.5GHz peintium with 8MB RAM).
So I opted for calculating and drawing on a Bitmap ahead of showing the images at fast rate ... and that is where my problems begun ...  :(

I think I will have a look how it is done in game programming, as suggested by several members.

Thanks to all for your help, it was a pleasant surprise to find such a helpful community.

Rik


« Last Edit: August 21, 2018, 07:31:38 pm by Rik »

440bx

  • Hero Member
  • *****
  • Posts: 3921
Re: intercepting exceptions
« Reply #52 on: August 21, 2018, 07:58:14 pm »
But what I have in mind is not a real scope but an application that shows some (rather complicated) calculated functions in "real time".
First I tried calculations and drawing into an Image on the fly, but that was far too slow (on a 3.5GHz peintium with 8MB RAM).
So I opted for calculating and drawing on a Bitmap ahead of showing the images at fast rate ... and that is where my problems begun ...  :(

I think I will have a look how it is done in game programming, as suggested by several members.

Thanks to all for your help, it was a pleasant surprise to find such a helpful community.

Rik
Techniques used in Game development may very well solve the problem.  From what you describe, it seems you had the right idea but ended up going too far with it.

You may not need 6000 bitmaps, just one that you draw on and bitblt onto the screen.  That method is usually fast enough for most purposes.  Of course, I have no idea how long your calculations take but, if you can pre-calculate what the ending values should be, chances are, a single bitmap in a memory device context will be fast enough.  Even on a Pentium at 3.5Ghz, you should be able to get around 60fps using a screen compatible bitmap in a memory device context.

If the calculations are what is slowing the screen updating process down then, what you really need is to take a page out of the cryptomining book and use the GPU to do the calculations (that's no simple task... but, it will be _fast_ if done right.... of course, the speed is directly related to the GPU's capabilities.)

Try the simplest approach first, one screen compatible bitmap rendered in a memory device context bitblt-ed as necessary onto the screen.  Odds are reasonably good, you'll get enough speed out of that (except if you're running the code on a single core, 400Mhz dinosaur, in that case, going to church to pray for speed might be the only solution.... and as you know, churches are well known for not offering any guarantees.)



(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018