mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 00:16:15 +00:00
app/headless,gpu/gl: make ReadPixels y-flipping backend specific
The Direct3D backend doesn't need y-flipping, so don't do it unconditionally in package app/headless. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -640,9 +640,26 @@ func (f *gpuFramebuffer) ReadPixels(src image.Rectangle, pixels []byte) error {
|
||||
return errors.New("unexpected RGBA size")
|
||||
}
|
||||
f.backend.funcs.ReadPixels(src.Min.X, src.Min.Y, src.Dx(), src.Dy(), RGBA, UNSIGNED_BYTE, pixels)
|
||||
// OpenGL origin is in the lower-left corner. Flip the image to
|
||||
// match.
|
||||
flipImageY(src.Dx()*4, src.Dy(), pixels)
|
||||
return glErr(f.backend.funcs)
|
||||
}
|
||||
|
||||
func flipImageY(stride int, height int, pixels []byte) {
|
||||
// Flip image in y-direction. OpenGL's origin is in the lower
|
||||
// left corner.
|
||||
row := make([]uint8, stride)
|
||||
for y := 0; y < height/2; y++ {
|
||||
y1 := height - y - 1
|
||||
dest := y1 * stride
|
||||
src := y * stride
|
||||
copy(row, pixels[dest:])
|
||||
copy(pixels[dest:], pixels[src:src+len(row)])
|
||||
copy(pixels[src:], row)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Backend) BindFramebuffer(fbo backend.Framebuffer) {
|
||||
b.funcs.BindFramebuffer(FRAMEBUFFER, fbo.(*gpuFramebuffer).obj)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user