Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Copying memory - backbuffer to backbuffer and mem block to backbuffer.

Author
Message
Felix Matix
19
Years of Service
User Offline
Joined: 9th Jan 2005
Location:
Posted: 10th Jan 2005 08:17
Compare the example below to the Display Showcase example from the DBPro help system. The key difference between the examples is that my modified version (based on the Display Showcase example) first copies the bitmap data to a temporary memory block and then from there copies each horizontal line to the backbuffer. The Display Showcase example copies memory directly form the top half of the backbuffer to the bottom half of the backbuffer. When I run the programs on my machine in a standard 640x480 window, my modified version gets about 165FPS (How can this be? My screen is running at 85Hz) whereas the Display Showcase example gets only about 21FPS. Also note that my example 'waves' the whole window and every horizontal line, not just half of the window and every other horizontal line. It's a rather dramatic difference, no? Now, why is that? I was expecting memory copying to be actually slower when copying between a temporary mem block and the backbuffer than backbuffer to backbuffer directly.

Another question. Because the Display Showcase example copies backbuffer to backbuffer directly, it's easy to have a circle (or anything else for that matter) drawn to the upper half of the window and have it copied and 'waved' in the lower half. How would I 'draw' a circle to the mem block (which acts just like a temporary hidden bitmap) in my modified version? Is there an easy way of doing this without resorting to circle drawing equations and lots of tedious memory copying?
Osiris
20
Years of Service
User Offline
Joined: 6th Aug 2004
Location: Robbinsdale, MN
Posted: 10th Jan 2005 10:25
the source box is bugged badly code box pls

Felix Matix
19
Years of Service
User Offline
Joined: 9th Jan 2005
Location:
Posted: 10th Jan 2005 12:01
Let's try this again...


Felix Matix
19
Years of Service
User Offline
Joined: 9th Jan 2005
Location:
Posted: 17th Jan 2005 10:19
No takers? No problem. I will usually ask a question but will not sit on my hands waiting to be spoon fed. After plowing further through the DBPro help system, command by command, I came to the Bitmap command set wich gave me the set of tools to do what I wanted. Observe the following example.



What the above example does, that is, the difference between the first example program I posted is that it creates a bitmap, copies the loaded JPG to that bitmap to act as a kind of a static clipboard from which to copy from. In the repeat loop it draws a circle to that bitmap and then creates a memblock from that bitmap, gets the pointer to that memblock and then the for loop 'waves' the window by copying memory from the temporarily created memblock to the backbuffer. Note that each time through the repeat loop, after a circle is drawn to the bitmap a memblock is created and it is deleted just before the until statement. When I run this on my machine I get only about 5FPS... extremely slow! But I do get the result I wanted, i.e. it's easy to send graphics functions like the circle command to the bitmap without much hassle. I expected this technique to be very slow even before I ran the program. Creating and deleting large memory blocks does take a fair chunk of the CPU's processing time.

Shortly after completing the above program I realized that there really shouldn't be a need to create a memblock from the created bitmap. Why not just copy graphics directly from the bitmap to the window? Compare the last example to this next one.




Note that the above example does not use the backbuffer, it copies graphics directly from the created bitmap to the window. Running the example in 640x480 windowed mode I get around 300FPS!

However further questions arise. Suppose that for some reason I wanted to copy the graphics from the bitmap to the backbuffer first, is there a way to obtain a pointer to the created bitmap without creating a memblock from the bitmap? I did not see any such commands in the Bitmap command set. And in this last example, is there an accurate way to control the FPS, mostly to slow down the rate, a way that would give you approximately equal frame rates on varying speed machines?
Opus
19
Years of Service
User Offline
Joined: 10th Jan 2005
Location:
Posted: 21st Jan 2005 00:01
To be honest with you Felix, at the moment your code is way over my head. I am just returning to programming after a decade layoff, and my knowledge base is beyond rusty. I just wanted to thank you for this information and I wanted to bump this post in case newbies--somewhat less new than I--could utilize this information in their programming.

Login to post a reply

Server time is: 2024-09-23 08:20:11
Your offset time is: 2024-09-23 08:20:11