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.

DarkBASIC Professional Discussion / 2D Draw Commands Are Slow!

Author
Message
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 11th Apr 2012 07:35
Just a few words on 2D Draw Commands...

2D Draw Commands like Dot, Line, Box, etc. are slow. I just discovered they are really super slow.

I was timing various parts of my game, like physics, Ai, etc. So I can knuckle down and make things faster, where needed. I saw that the 3rd Person Camera was taking 0ms (less than 1ms) to update positions. However 1st Person Camera would take like 6ms or more. I was like damn I do way more to the 3rd Person Camera but why's it like 100 times faster?

Dot Screen Width() / 2, Screen Height() / 2, RGB(255,255,255)

I cheaped out and used a single white pixel for a cross-hair. I was going to get around to making a proper cross-hair. That one pixel was taking 6ms to draw.

Perspective: That's like going from 60fps to 44fps or 30fps to 25fps.

One white dot. So don't use them. Not even once.
I could paste a cross-hair image a hundred times and still get better fps.


Example Code Below:




Thought I'd spice things up with a screenshot.

TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 11th Apr 2012 10:05
Cheers for pointing that out Comet. I didn't even know that existed.

Yes, never use the 2D commands for speed critical apps.

Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 11th Apr 2012 10:57 Edited at: 11th Apr 2012 11:03
Yeah I was hoping people would post stuff like that, it will really help people out. In my case it's just better sense to not be lazy, and instead paste a cross-hair image.
I included example code, since I figured people might benefit from it.

ShaunRW
DBPro Developer
16
Years of Service
User Offline
Joined: 7th Jan 2008
Location: Brisbane, Australia
Posted: 11th Apr 2012 16:15
Cloggy's D3D func plugin is also pretty good.

SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 14th Apr 2012 20:02 Edited at: 14th Apr 2012 20:03
haha yeah dbp's 2d stuff sucks....lol

I even found that if you had to make a line....it would be faster running a calculation and making it with several boxes wich is extreamly funny! The line command i would 100% stay away from or at least make a function creating a line using the box commands in a loop.

Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 15th Apr 2012 23:33
Yes only use dbp's 2d stuff for debugging. Actually i am using "box" currently for drawing my splitscreen lines, and it's not that bad. If you want to draw horizontal or vertical lines, you should use box instead of line. IIRC box beats dot for drawing dots too!
Statue
17
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 16th Apr 2012 22:56
Hello Ya'all:

Just spotted this and wanted to give my input. I'm kind of in a hurry, so I'll make it brief (sorry, but not giving details here): 1) It is faster to draw 2D onto a background page, then pageflip to that page, rather than drawing on the foreground page; 2) There is a setting in DBT which controls how frequently the screen is refreshed - believe it or not, make that setting slower. 2D is a little CPU-intensive. By slowing down the refresh, it gives the CPU more time to process the 2D commands, so they actually run faster. These two add significant speed. The program I wrote was doing a dot command, scaling down a 4K image to fit into a window. By just doing dot to the foreground window and not tweaking the refresh, it was probably doing 1 scanline every 40 seconds. Switched it to doing the background, and it did about 1 scanline every second. Tweaked the refresh, and it did about 25 scanlines every second. This is all while doing the calculations to color each pixel from Bayer format.

Lance
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 18th Apr 2012 00:58
Quote: "Hello Ya'all:

Just spotted this and wanted to give my input. I'm kind of in a hurry, so I'll make it brief (sorry, but not giving details here): 1) It is faster to draw 2D onto a background page, then pageflip to that page, rather than drawing on the foreground page; 2) There is a setting in DBT which controls how frequently the screen is refreshed - believe it or not, make that setting slower. 2D is a little CPU-intensive. By slowing down the refresh, it gives the CPU more time to process the 2D commands, so they actually run faster. These two add significant speed. The program I wrote was doing a dot command, scaling down a 4K image to fit into a window. By just doing dot to the foreground window and not tweaking the refresh, it was probably doing 1 scanline every 40 seconds. Switched it to doing the background, and it did about 1 scanline every second. Tweaked the refresh, and it did about 25 scanlines every second. This is all while doing the calculations to color each pixel from Bayer format.

Lance "


Thanks, that's a lot of helpful information.

Login to post a reply

Server time is: 2024-05-19 04:04:07
Your offset time is: 2024-05-19 04:04:07