Page 1 of 2

How do I efficiently update an image?

Posted: Fri Feb 28, 2020 6:39 pm
by Sky_Render
So here's the deal: I have an ImageData that takes a chunk of another ImageData that's exactly the size of the user's screen, because rendering everything offscreen as well as onscreen is for chumps. But I cannot for the life of me figure out how I can efficiently render this, because as best I can tell, the only way to render an ImageData is to declare a new Image, which does not appear to update when the ImageData updates. What am I missing here?

Re: How do I efficiently update an image?

Posted: Fri Feb 28, 2020 6:43 pm
by raidho36
ImageData holds information in RAM. In order to render anything, it needs to be on the GPU. You see my point?

Re: How do I efficiently update an image?

Posted: Fri Feb 28, 2020 6:50 pm
by Sky_Render
I get that. That's not the problem. The problem (at least as best I can tell, it might be something with my code that's wrong) is that a declared Image does not update when the ImageData that it was declared with updates. Let's say we have this:

Code: Select all

fooimage = love.image.newImageData("foo.png", 16, 16)
fooimage2 = love.image.newImageData("foo2.png", 16, 16)
foorender = love.graphics.newImage(fooimage)
fooimage:paste(fooimage2, 0, 0, 0, 0, 16, 16)
This doesn't make foorender change even though fooimage changed? Or does it? Is this entirely the wrong way to do this? Please, help me understand this.

Re: How do I efficiently update an image?

Posted: Fri Feb 28, 2020 6:54 pm
by raidho36
You changed the data that sits in RAM, of course this does nothing about the data that sits on the GPU. In case it's not clear, they're physically separate.

Re: How do I efficiently update an image?

Posted: Fri Feb 28, 2020 6:56 pm
by Sky_Render
Well then how am I supposed to DO this? I do not understand. Declaring a new image every time I need to update the on-screen image is not acceptable, but you're telling me basically that this is the only way I can do what I'm trying to do. How am I supposed to render a changed image to screen without completely re-declaring the image?

Re: How do I efficiently update an image?

Posted: Fri Feb 28, 2020 7:01 pm
by raidho36
You don't. You need to push the contents to the GPU before they can be rendered. GPU is a physically separate extension board, remember? You push data to it, and you push commands to it, and it executes your commands on your data, and then you can fetch the results (by default it outputs results to a physically separate output device, too - the monitor).

You do effects like these on the GPU.

Re: How do I efficiently update an image?

Posted: Fri Feb 28, 2020 7:04 pm
by Sky_Render
That doesn't help me, at all. I'm not asking for a lesson on PC architecture here, I'm trying to figure out how the hell I update an Image with changed ImageData and not have it be crazy-slow. I'd even settle for a way to render ImageData that doesn't involve the absurdly limited Image object.

Re: How do I efficiently update an image?

Posted: Fri Feb 28, 2020 7:09 pm
by raidho36
I'm giving you PC architecture lesson because you fail to understand limitations of the hardware. There's no way to shovel large amounts of data over PCI bus without it being crazy-slow (compared to RAM-to-RAM anyway), particularly when GPU is involved because it's heavily bottlenecked by driver's throughput. So you do these effects on the GPU so that no data shoveling is involved.

Re: How do I efficiently update an image?

Posted: Fri Feb 28, 2020 7:11 pm
by Sky_Render
Fine, then let's try a different approach: how do I efficiently render an image that changes constantly to screen, without throwing the entire original massive image at the GPU every draw cycle?

Re: How do I efficiently update an image?

Posted: Fri Feb 28, 2020 7:12 pm
by steVeRoll
If you want an Image that you can change, a Canvas might be more useful. You can both draw onto a canvas, and draw the canvas onto the screen.