Posted: 12th Jun 2007 16:55
I don't understand it. Even if I create a routine using FreeBASIC, DevC++, or PureBASIC, drawing to DBPro's backbuffer or any of its bitmaps is so slow. I'm even using pointers, (Get BackBuffer Ptr(), Get Pixels Pointer()). DBPro must have sume backbuffer/bitmap security routines running in the background. Is there anyway to disable these? The slowness is ridiculous.
Posted: 12th Jun 2007 17:02
I have even just tried copying a bitmap to a memory buffer using the bitmap's pointer, (Get Pixels Pointer()). This simple act reduced my games FPS to 9- . Why on Earth would this happen?
Posted: 12th Jun 2007 17:03
Putting lock pixels and unlock pixels around certain bitmap commands can speed things up.
Posted: 12th Jun 2007 17:07
Thank you, Crit. That is what I've been told. However, it hasn't increased my routines any. The simpley bitmap-to-memory routine still slows my program's FPS to 9-. I'm truly at a loss.
Posted: 12th Jun 2007 17:09
Apparently there is a lock backbuffer command also. Have you tried that?
Posted: 12th Jun 2007 17:14
Yes, Sir. I did. Oddly enough, the slowdown occurs when I read from the backbuffer or a bitmap. Not nearly as much as when I write to either.
Posted: 12th Jun 2007 17:24
Is your Get Pixels Pointer() outside the loop? Also, are you manually syncing at the end of each loop?

I'm out of ideas.
Posted: 12th Jun 2007 17:28
If I were ever in doubt that DBPro was acting funny, now I'm not. Even the following command, alone, is reducing my program's FPS to 11-.

+ Code Snippet
Make MemBlock From Bitmap My_MemBlock, My_Bitmap


If I comment-out this, (and only this) command, my program's FPS increases from 11- to 99. I even tryed Lock BackBuffer and Lock Pixels. To no avail. Has anyone encountered a similar problem?
Posted: 12th Jun 2007 17:29
@Crit

1) My Get Pixels Pinter() is outside the loop.
2) I am manually syncing at the end of each loop.
Posted: 12th Jun 2007 17:52
Has no one ever worked with 2D functions in DBPro?
Posted: 12th Jun 2007 17:57
The problem is one of PC architecture. The back buffer (and bitmap apparently) will be in video memory. So their local to the GPU, the problem is that the video bus is designed virtually a one way gate, which makes attempting to read pixels it with the CPU a waste of time. So you can write, you just can't read them back effectively.
Posted: 12th Jun 2007 18:02
@Kevin Picone

In which case, is there any faster way to copy DBPro's output? Basically, I'm manipulating DBPro's output, (or rendered image). I need access its rendered image.
Posted: 12th Jun 2007 18:08
Maybe you should just render the output to an image. I personally wouldn't want to use a plugin that forcefully commandeered my backbuffer. I could render the output to a sprite faster than to the backbuffer.
Posted: 12th Jun 2007 18:13
How do I render to a sprite, Sir? I always preferred to redirect the rendering, but I never knew how.
Posted: 12th Jun 2007 18:55
this should show you the bottleneck problem with these functions

+ Code Snippet
sync on
sync rate void

type ScreenState
   Width as dword
   Height as dword
   Framerate as dword
   Depth as dword
   Bits as dword
endtype

global Screen as ScreenState

backdrop on

repeat
   Screen.Width = screen width()
   Screen.Height = screen height()
   Screen.Framerate = screen fps()
   Screen.Depth = screen depth()
   Screen.Bits = int(screen depth() / 8)

   if scancode() = 0 then isKey = 0

   if spacekey() = 1 and isKey = 0
      Method = Method - 1
      isKey = 1
   endif

   if Method
      center text int(Screen.Width * 0.5), int(Screen.Height * 0.5), str$(Screen.Framerate) + "fps :: Method 1"
      Method1()
   else
      center text int(Screen.Width * 0.5), int(Screen.Height * 0.5), str$(Screen.Framerate) + "fps :: Method 2"
      Method2()
   endif

   sync
until escapekey()
   // remove loaded memory
end   // exit

function Method1()
   lock pixels
      pPixel = get pixels pointer()

      for X = 0 to 63
         for Y = 0 to 63
            Draw(X, Y, pPixel)
         next Y
      next X
   unlock pixels
endfunction

function Method2()
   local pCache as integer
   local SizeOf as integer

   SizeOf = (Screen.Width * Screen.Height) * Screen.Bits
   pCache = make memory(SizeOf)

   lock pixels
      pPixel = get pixels pointer()
      copy memory pCache, pPixel, SizeOf

      for X = 0 to 63
         for Y = 0 to 63
            Draw(X, Y, pCache)
         next Y
      next X

      copy memory pPixel, pCache, SizeOf
   unlock pixels

   delete memory pCache
endfunction

function Draw(X as dword, Y as dword, pPixel as integer)
   local pBuffer as integer
   local Colour as dword

   pBuffer = Screen.Bits * ((Y * Screen.Width) + X)
   pBuffer = pBuffer + pPixel

   // Colour = *pBuffer    // Get Pixel Colour

   // ScreenSpace Operation
   Colour = 0x8c8c8c

   *pBuffer = Colour    // Set Pixel Colour
endfunction
Posted: 12th Jun 2007 19:25
It all worked OK in my 2 tutorials, maybe there's something in there that will help you figure it out...

http://www.thegamecreators.com/data/newsletter/newsletter_issue_32.html#9

http://www.thegamecreators.com/data/newsletter/newsletter_issue_33.html#12
Posted: 12th Jun 2007 19:37
Your tutorials don't read from video memory - that's why they run at a reasonable speed.

@man id unknown,
You can use the SET CAMERA TO IMAGE command to redirect your rendering to an image, then display the image using a sprite. Try to render to one image, convert to a memblock, manipulate the memblock, then convert back to a different image - show that final image as a sprite, or paste it to the display.

If you absolutely have to read from the backbuffer, then don't do it a pixel at a time - read the whole thing into a memblock, manipulate the memblock, then write it all back at once. It's better to have one long read than many small ones.
Posted: 12th Jun 2007 19:46
@Raven & BatVink

Thank you for the code & tutorials.

@IanM

Thank you. That sounds like it should work. I didn't know about that command, (Set Camera To Image()). I'll try it, now.
Posted: 12th Jun 2007 20:23
@IamM

After I used Set Camera To Image, DBPro will not allow me to copy that image to a MemBlock. Apparently, DBPro locks the image.
Posted: 12th Jun 2007 21:36
There must be a way to perform faster 2D modifications.