DrawImageRect() equivalent in WritePixels()?

Monkey Forums/Monkey Programming/DrawImageRect() equivalent in WritePixels()?

Dip(Posted 2013) [#1]
Hi all,

I'm messing around with some simple raycasting and noticing that drawimagerect is just too slow or I'm doing something wrong. I wanted to try writing to an image buffer then putting that on the screen, but when I tried to translate my drawimagerects into writepixels, I kept getting errors about invalid pixel rectangles. I kept reducing the variables in my call until I just had
cameraBufferImage.WritePixels(dataWall,1,1,1,1)
which worked, but when I ran the program with a simple
DrawImage(cameraBufferImage,0,0)
at the end just to see if it would work, my FPS dropped from ~50 to 2.
That was a real head-scratcher, as I hoped it would at least be equivalent, especially since it was doing less work.

If someone can give me a straightforward example of how it should be used so I can figure out where I'm going wrong, I'd appreciate it.

My pixel loading is in a "pregame" state doing this call:
Cls 0,0,0
DrawImage(imgWall,0,0)
dataWall = New Int[64*64]
ReadPixels(dataWall,0,0,64,64)

I'm a bit frustrated that I can't create something that ran on 386's nearly 20 years ago with a decent framerate on today's hardware :)

I also tried looking at Earok's advanced raycaster for some ideas but it doesn't give the same output on the version of Monkey I'm using.


Gerry Quinn(Posted 2013) [#2]
All the code there looks fine, but you haven't said how you created cameraBufferImage. Perhaps it is rather large.

When you use WritePixels to put data into an image, even if the amount of data is tiny, the system is going to push the whole image buffer to graphic memory when you try to draw it (and then it will draw it to the back buffer from graphic memory). So if cameraBufferImage is 1000x1000, that's the amount of data that is getting pumped to graphic memory every render cycle. This seems the most likely issue.

Maybe if you are only changing a small part of the image at a time you can use multiple small buffer images, and only change the ones you want. Or perhaps you can try to do something in native code that will speed matters up, I'm not sure how but it may be possible, i.e. there may be calls that update only a portion of an image in graphic memory.

Modern hardware is powerful, but the pipeline may not flow the way you want it to.


Dip(Posted 2013) [#3]
Hmm that's a really good idea, Gerry. I'll give that a try.
I was using a standard resolution of 800x600 for the screen, and
cameraBufferImage = CreateImage(800,600)
as a result.