gpu,gpu/internal: support variable strides in ReadPixels

It saves a roundtrip to scratch memory when the CPU fallback renderer
downloads rendered materials.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-08-26 19:18:29 +02:00
parent 06ffa42d16
commit 7f6e376424
6 changed files with 25 additions and 23 deletions
+2 -2
View File
@@ -593,7 +593,7 @@ func (b *Buffer) Release() {
b.buf = nil
}
func (f *Framebuffer) ReadPixels(src image.Rectangle, pixels []byte) error {
func (f *Framebuffer) ReadPixels(src image.Rectangle, pixels []byte, stride int) error {
if f.resource == nil {
return errors.New("framebuffer does not support ReadPixels")
}
@@ -636,7 +636,7 @@ func (f *Framebuffer) ReadPixels(src image.Rectangle, pixels []byte) error {
return fmt.Errorf("ReadPixels: %v", err)
}
defer f.ctx.Unmap(res, 0)
srcPitch := w * 4
srcPitch := stride
dstPitch := int(resMap.RowPitch)
mapSize := dstPitch * h
data := sliceOf(resMap.PData, mapSize)