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:
Elias Naur
2020-02-27 18:24:09 +01:00
parent 8dce81d8fd
commit a0c4688d0c
3 changed files with 17 additions and 17 deletions
+17
View File
@@ -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)
}