love.image.ImageData to love.graphics.Image update propagation
0 reputation · 01 Jul 2021, 10:34 UTC
0 reputation · 01 Jul 2021, 10:34 UTC
Designing a dynamic texture workflow in LÖVE requires a clear contract between love.image.ImageData as a CPU-side pixel buffer and love.graphics.Image as the GPU texture used for drawing.
love.graphics.newImage(imageData) is documented to upload pixel data at creation time. The integration boundary is unclear regarding whether the Image retains a reference to the source ImageData or holds an independent GPU copy, and whether subsequent mutations via :setPixel or :paste are expected to be visible without recreating the Image. Version assumptions cover LÖVE 0.10.x, 0.11.x and 1.1.x where texture handling differs but the API surface is stable. File-path caching for newImage(filename) is distinct from ImageData-based creation.
What is the expected relationship between a mutated ImageData and an Image created from it?
35275 reputation · 01 Jul 2021, 16:03 UTC
The Image created with love.graphics.newImage(imageData) stores a copy of the pixel data at upload time; subsequent modifications to the original ImageData are not reflected in the Image.
newImage the GPU texture is immutable.ImageData.newImage(imageData) always creates a distinct GPU texture; file‑path caching applies only to newImage(filename).Because the texture is uploaded once and never re‑read, changing the source ImageData does not affect the already‑bound texture. The engine treats the Image as a snapshot of the data at creation.
ImageData, call love.graphics.newImage(imageData) to obtain an Image.ImageData with :setPixel or :paste.Image visual unchanged.Image from the updated ImageData; it will show the new pixels while the first remains static, confirming immutability.Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 01 Jul 2021, 15:10 UTC
A love.graphics.Image created from ImageData is a one-time GPU snapshot, not a live reference to the CPU buffer. In LÖVE 0.10.x, 0.11.x and 1.1.x, newImage(imageData) uploads pixels at creation; later :setPixel or :paste edits to the source ImageData do not change the existing texture. To display updated pixels, recreate the Image or draw to a Canvas and paste fresh ImageData each frame. File-path caching applies only to newImage(filename); each newImage(imageData) call produces a distinct texture. Verify by drawing the Image, mutating the buffer, redrawing, then comparing with a newly created Image from the same buffer.