## How do I efficiently update an image?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Sky_Render
Prole
Posts: 48
Joined: Fri Jul 05, 2019 2:59 am

### How do I efficiently update an image?

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?
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

### Re: How do I efficiently update an image?

ImageData holds information in RAM. In order to render anything, it needs to be on the GPU. You see my point?
Sky_Render
Prole
Posts: 48
Joined: Fri Jul 05, 2019 2:59 am

### Re: How do I efficiently update an image?

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.
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

### Re: How do I efficiently update an image?

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.
Sky_Render
Prole
Posts: 48
Joined: Fri Jul 05, 2019 2:59 am

### Re: How do I efficiently update an image?

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?
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

### Re: How do I efficiently update an image?

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.
Sky_Render
Prole
Posts: 48
Joined: Fri Jul 05, 2019 2:59 am

### Re: How do I efficiently update an image?

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.
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

### Re: How do I efficiently update an image?

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.
Sky_Render
Prole
Posts: 48
Joined: Fri Jul 05, 2019 2:59 am

### Re: How do I efficiently update an image?

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?
steVeRoll
Party member
Posts: 125
Joined: Sun Feb 14, 2016 1:13 pm

### Re: How do I efficiently update an image?

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.

### Who is online

Users browsing this forum: darkfrei and 47 guests