Canvas Animation Trouble with Invalidate vs Refresh

These 2 statements appear to contradict each other. If you can create 1000 pictures per second without drawing them, but significantly fewer when you put them on the screen, wouldn’t that indicate that the problem lies in the screen update?

Hi Tim,

Ah yes, your right.

Drawing with invalidate is creating pictures fast, and showing the pictures on the Canvas is slow… Good catch!

I think I would be correct in saying that updating the canvas with the picture using refresh is slowing the process down.

Does that make more sense? Ok… going to get more coffee :slight_smile:

This makes no sense… UNLESS you are drawing in a PICTURE object and NOT directly to the canvas during the PAINT event
IF you are drawing directly in the Paint Event, then “creating” and “showing” the picture is virtually the same process.
Remember you can issue 1000 “invalidate” during a run cycle, but it will only refresh the canvas ONCE, meaning the PAINT event is called ONCE…

However if the PAINT event contains

g.drawpicture myPicture,0,0

and myPicture is drawn and redrawn 1000 times , and displayed once, then that statement makes a little more sense.

Note : I have written Xojo programs that redrew (in the PAINT event) hundreds of objects, and was able to obtain 60FPS

Hi Dave,

I like what your saying, and here is my interpretation.

It appears that “creating” a new picture (Dim PBuffer as New Picture) is fast, and populating the picture is fast when drawing many objects (circles) on the picture.

Once the picture has been created, then it is to be “shown” in the Canvas by copying the picture into the Canvas by drawing (g.DrawPicture(PBuffer,0,0,me.Width, me.Height)) which seems to be the slow step.

This is what I meant … and not necessarily what I said :slight_smile:

The example programs that are attached seems to start slowing down in drawing speed at about 400 objects. Usually below 400 objects the frame rate is about 60 fps, which reinforces what you said.

Thanks!

I think I have been able to get a little closer to having faster speeds with Xojo, and it looks like it might be with an OpenGLSurface that loads the circles into memory, and uses the GPU to perform the drawing function while the CPU performs calculations for the new position of the circles. The GPU can be forced to work hard, as I can hear the cooling fan start spinning.
The code is not optimized, and it does seem to have quite a performance increase.
Explaining running of the program:
The default number of circles (ball) is 100. If you want to change this number, stop the program, go into the Xojo IDE and change the text to 200, or 50, or whatever number you would like. This step is needed because the circles have been loaded when opening the program. This can be changed in the future when given more thought (I am out of coffee at the moment)

AAAHHHHHHHGGGGG !!! STOP CODING AND GET COFFEE !!! :stuck_out_tongue:

Hmm… thats wierd… Only half my message appeared… With a fresh cup of coffee in hand, lets try this again… :slight_smile:

I think I have been able to get a little closer to having faster speeds with Xojo, and it looks like it might be with an OpenGLSurface that loads the circles into memory, and uses the GPU to perform the drawing function while the CPU performs calculations for the new position of the circles. The GPU can be forced to work hard, as I can hear the cooling fan start spinning.

The code is not optimized, and it does seem to have quite a performance increase.

Explaining running of the program:
The default number of circles (ball) is 100. If you want to change this number, stop the program, go into the Xojo IDE and change the text to 200, or 50, or whatever number you would like. This step is needed because the circles have been loaded when opening the program. This can be changed in the future when given more thought (I am out of coffee at the moment). Here is the link to download the program.

OpenGL GPU

Number of Circles Target FPS Measured FPS 300 300 145 200 300 222 100 300 239

Steps to change the Target FPS are: Change the number in the textbox, press ‘Reset Ball’ pushbutton, and wait until the animation stops. Press ‘Run test’ to start animation with the new parameters.

The GPU is working harder because I can hear the GPU fan starting on my computer when running the program for a while - this is good news!

Something I forgot to mention was the OpenGLSurface fires on every render. No skipping of timing is involved. This is similar to the refresh event firing on a canvas all the time.