Bitmap rendering could be sped up
Closed this issue · 2 comments
I'm working on code that dynamically builds a bitmap every frame. I can du this by generating a native Go image.RGBA
, then use PictureDataFromImage
, turn it into a sprite and draw it to my canvas. Doing that, my pixels are copied at least three times. I could speed it up by building my own PictureData
without taking the extra step via an Image
. However, my profiling shows that I still spend a considerable amount of time in NewGLPicture
.
I could easily build my image as a flat array of uint8
which could be mapped directly to a Texture.
For this, I propose we either introduce a FlatArrayPicture
type that simply contains a flat array of uint8 that NewGLPicture
can just map to the texture - or - that we expose the underlying Texture
object so code that needs to render bitmaps VERY quickly can access them directly.
I am willing to make this any of these changes in a PR.
Unless I'm misunderstanding your usecase, I think the functionality you want already exists in the glhf
backend that Pixel uses. Specifically looking at glhf.NewTexture()
, which allows you to build a new texture from an array of uint8. Not sure how you would render that as opengl confuses me to no end. Otherwise, you can access the glhf.Texture
of a pixel.Canvas
with the .Texture()
method.
Yeah, I eventually figured that out. There's still a few copies made internally in the code that could you probably avoid, but I'm getting the performance I need out of it now, so I'm closing this.