ebiten icon indicating copy to clipboard operation
ebiten copied to clipboard

ebiten: add a more friendly API to replace pixels than `ReplacePixels`

Open hajimehoshi opened this issue 2 years ago • 3 comments

ReplacePixels is hard to use as it takes a byte slice.

What about ReplaceByImage(image image.Image)? The cost is still not obvious but is more friendly.

/CC @eihigh

hajimehoshi avatar Jul 04 '22 10:07 hajimehoshi

I think we have to discuss the differences between this approach and the direct use of DrawImage with image.Image instead of ebiten.Image to determine what's the plan in the long run. I think the simplest API would be the one that has only DrawImage and can do ReplacePixels under the hood when image.Image is passed. (Edit: oh, I see it's also discussed on https://github.com/hajimehoshi/ebiten/issues/2127)

The other discussion is how this works with image bounds. Will the bounds of the source image be respected?

tinne26 avatar Jul 06 '22 07:07 tinne26

I think we have to discuss the differences between this approach and the direct use of DrawImage with image.Image instead of ebiten.Image to determine what's the plan in the long run. I think the simplest API would be the one that has only DrawImage and can do ReplacePixels under the hood when image.Image is passed.

This is a balancing issue between 'easy' APIs and 'explicit' APIs. Roughly speaking, there are two types of operations for a GPU: replacing pixels and rendering triangles. ReplacePixels is for the former, while DrawImage is for the latter. Integrating them into DrawImage would be simple, but not explicit in terms of GPU operations. I tend to prefer 'explicit' APIs to 'easy' APIs. So, I'd rather not integrate the APIs. (Then, I'm a little against #2127: this would make the API easy but implicit.)

The other discussion is how this works with image bounds. Will the bounds of the source image be respected?

This is a good point. Probably accepting []color.RGBA might be more explicit rather than image.Image. I don't know this would improve the situation.

hajimehoshi avatar Jul 06 '22 08:07 hajimehoshi

The other discussion is how this works with image bounds. Will the bounds of the source image be respected?

Note that DrawImage doesn't respect a source image's bounds. DrawImage treats the source image as if it is a regular image.

hajimehoshi avatar Jul 06 '22 08:07 hajimehoshi