Skip to content

Commit

Permalink
Optimize texture data uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars committed Feb 17, 2018
1 parent 3f26535 commit 5aefe96
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions types_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,42 @@ func (r LOCKED_RECT) SetAllBytes(data []byte, srcStride int) {
srcSkip := uintptr(srcStride - stride)
d := dest
s := src
for y := 0; y < height; y++ {
for x := 0; x < stride; x++ {
*((*byte)(unsafe.Pointer(d))) = *((*byte)(unsafe.Pointer(s)))
d++
s++
if stride%8 == 0 {
// in this case we can speed up copying by using 8 byte wide uint64s
// instead of copying byte for byte
for y := 0; y < height; y++ {
for x := 0; x < stride; x += 8 {
*((*uint64)(unsafe.Pointer(d))) = *((*uint64)(unsafe.Pointer(s)))
d += 8
s += 8
}
d += destSkip
s += srcSkip
}
} else if stride%4 == 0 {
// in this case we can speed up copying by using 4 byte wide uint32s
// instead of copying byte for byte
for y := 0; y < height; y++ {
for x := 0; x < stride; x += 4 {
*((*uint32)(unsafe.Pointer(d))) = *((*uint32)(unsafe.Pointer(s)))
d += 4
s += 4
}
d += destSkip
s += srcSkip
}
} else {
// in the unlikely case that stride is neither a multiple of 8 nor 4
// bytes, just copy byte for byte
for y := 0; y < height; y++ {
for x := 0; x < stride; x++ {
*((*byte)(unsafe.Pointer(d))) = *((*byte)(unsafe.Pointer(s)))
d++
s++
}
d += destSkip
s += srcSkip
}
d += destSkip
s += srcSkip
}
}

Expand Down

0 comments on commit 5aefe96

Please sign in to comment.