Read/WritePixels bottleneck

Monkey Forums/Monkey Programming/Read/WritePixels bottleneck

Raudius(Posted 2015) [#1]
Hello

I have this feature where I'm building an image using different image components.

My current method consists on drawing the image to the buffer and then taking a "ReadPixels" from the rendered area. Then with "WritePixels" I can create the final Image object.

However It's a fairly big bottleneck in my code, I assume that loading images, drawing them on the drawbuffer and then reading the area just takes too much processing to do seamlessly.

My hope was to use the threading module from diddy to fix this, but of course I cannot use Draw functions outside of OnRender.

Any suggestions around this issue?


ImmutableOctet(SKNG)(Posted 2015) [#2]
Your issue is that you're transferring data back and forth from the CPU and GPU. That's your bottleneck right there. Multiple threads won't help the driver be any faster at performing a task like this. Threading is also a bit of an issue on some targets, but that's a different topic.

Honestly, if you were using Mojo 2, then you could use "render-to-texture" properly. That seems to be what you want to do, but the original Mojo module's graphical functionality really can't handle it. There are ways of getting that working, but the nicest option isn't all that great. Without Mojo 2, you'll need to use custom OpenGL code. SKN3 made his 'imagebuffer' module a long while ago (GLFW only), but you'll need to hack that to get it working again. There's also 'nDrawExts', but it doesn't do much for dynamic image generation.

If you want to learn how to get SKN3's old module working, you can follow the posts in this thread, and in this thread.

Honestly, your best bet is to switch to Mojo 2. Mojo 2 is available to anyone who owns Monkey X, and can be found with the latest release.


Raudius(Posted 2015) [#3]
I downloaded MonkeyXPro84d, and I've been looking through the mojo2 overview.

Im assuming that the solution you suggest is to create a Canvas with the image as the target and then I can Draw things to the Canvas. Then when DrawImage(target) is invoked all the things previously rendered to the canvas will now render as the image.

It sounds like the perfect solution. Also perfect timing that mojo2 has just recently come out.

Thanks a lot, will try this out this afternoon.