mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-13 22:47:26 +01:00
internal/graphicsdriver/directx: bug fix: had to consider strides when copying resources
Closes #2617
This commit is contained in:
parent
0449126c5b
commit
0b0526a05b
@ -113,7 +113,17 @@ func (i *image11) ReadPixels(buf []byte, x, y, width, height int) error {
|
|||||||
if err := i.graphics.deviceContext.Map(unsafe.Pointer(staging), 0, _D3D11_MAP_READ, 0, &mapped); err != nil {
|
if err := i.graphics.deviceContext.Map(unsafe.Pointer(staging), 0, _D3D11_MAP_READ, 0, &mapped); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
copy(buf, unsafe.Slice((*byte)(mapped.pData), 4*width*height))
|
|
||||||
|
stride := int(mapped.RowPitch)
|
||||||
|
src := unsafe.Slice((*byte)(mapped.pData), stride*height)
|
||||||
|
if mapped.RowPitch == uint32(4*width) {
|
||||||
|
copy(buf, src)
|
||||||
|
} else {
|
||||||
|
for j := 0; j < height; j++ {
|
||||||
|
copy(buf[j*4*width:(j+1)*4*width], src[j*stride:j*stride+4*width])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
i.graphics.deviceContext.Unmap(unsafe.Pointer(staging), 0)
|
i.graphics.deviceContext.Unmap(unsafe.Pointer(staging), 0)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user