Skip to content

Commit a167cc1

Browse files
committed
Update purego
1 parent 90cf455 commit a167cc1

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

raylib/raylib_purego.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package rl
55

6+
import "C"
67
import (
78
"fmt"
89
"image"
@@ -2849,9 +2850,18 @@ func UnloadRenderTexture(target RenderTexture2D) {
28492850
unloadRenderTexture(uintptr(unsafe.Pointer(&target)))
28502851
}
28512852

2852-
// UpdateTexture - Update GPU texture with new data
2853-
func UpdateTexture(texture Texture2D, pixels []color.RGBA) {
2854-
updateTexture(uintptr(unsafe.Pointer(&texture)), unsafe.SliceData(pixels))
2853+
// UpdateTexture - Update GPU texture with new data ([]color.RGBA, *image.RGBA or []byte)
2854+
func UpdateTexture(texture Texture2D, pixels any) {
2855+
var cpixels unsafe.Pointer
2856+
switch p := pixels.(type) {
2857+
case []color.RGBA:
2858+
cpixels = unsafe.Pointer(&p[0])
2859+
case *image.RGBA:
2860+
cpixels = unsafe.Pointer(&p.Pix[0])
2861+
case []byte:
2862+
cpixels = unsafe.Pointer(&p[0])
2863+
}
2864+
updateTexture(uintptr(unsafe.Pointer(&texture)), cpixels)
28552865
}
28562866

28572867
// UpdateTextureRec - Update GPU texture rectangle with new data
@@ -3829,10 +3839,19 @@ func UnloadAudioStream(stream AudioStream) {
38293839
unloadAudioStream(uintptr(unsafe.Pointer(&stream)))
38303840
}
38313841

3832-
// UpdateAudioStream - Update audio stream buffers with data
3833-
func UpdateAudioStream(stream AudioStream, data []float32) {
3834-
frameCount := int32(len(data))
3835-
updateAudioStream(uintptr(unsafe.Pointer(&stream)), data, frameCount)
3842+
// UpdateAudioStream - Update audio stream buffers with data ([]float32 or []int16)
3843+
func UpdateAudioStream(stream AudioStream, data any) {
3844+
var cdata unsafe.Pointer
3845+
var csamplesCount C.int
3846+
switch d := data.(type) {
3847+
case []float32:
3848+
cdata = unsafe.Pointer(&d[0])
3849+
csamplesCount = (C.int)(len(d))
3850+
case []int16:
3851+
cdata = unsafe.Pointer(&d[0])
3852+
csamplesCount = (C.int)(len(d))
3853+
}
3854+
updateAudioStream(uintptr(unsafe.Pointer(&stream)), cdata, csamplesCount)
38363855
}
38373856

38383857
// IsAudioStreamProcessed - Check if any audio stream buffers requires refill

0 commit comments

Comments
 (0)