Skip to content

Commit b761936

Browse files
committed
Allow more types for UpdateTextureRec
1 parent a167cc1 commit b761936

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

raylib/raylib_purego.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2866,7 +2866,16 @@ func UpdateTexture(texture Texture2D, pixels any) {
28662866

28672867
// UpdateTextureRec - Update GPU texture rectangle with new data
28682868
func UpdateTextureRec(texture Texture2D, rec Rectangle, pixels []color.RGBA) {
2869-
updateTextureRec(uintptr(unsafe.Pointer(&texture)), uintptr(unsafe.Pointer(&rec)), unsafe.SliceData(pixels))
2869+
var cpixels unsafe.Pointer
2870+
switch p := pixels.(type) {
2871+
case []color.RGBA:
2872+
cpixels = unsafe.Pointer(&p[0])
2873+
case *image.RGBA:
2874+
cpixels = unsafe.Pointer(&p.Pix[0])
2875+
case []byte:
2876+
cpixels = unsafe.Pointer(&p[0])
2877+
}
2878+
updateTextureRec(uintptr(unsafe.Pointer(&texture)), uintptr(unsafe.Pointer(&rec)), cpixels)
28702879
}
28712880

28722881
// GenTextureMipmaps - Generate GPU mipmaps for a texture

raylib/rtextures.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,18 @@ func UpdateTexture(texture Texture2D, pixels any) {
255255
C.UpdateTexture(*ctexture, cpixels)
256256
}
257257

258-
// UpdateTextureRec - Update GPU texture rectangle with new data
259-
func UpdateTextureRec(texture Texture2D, rec Rectangle, pixels []color.RGBA) {
258+
// UpdateTextureRec - Update GPU texture rectangle with new data ([]color.RGBA, *image.RGBA or []byte)
259+
func UpdateTextureRec(texture Texture2D, rec Rectangle, pixels any) {
260+
var cpixels unsafe.Pointer
261+
switch p := pixels.(type) {
262+
case []color.RGBA:
263+
cpixels = unsafe.Pointer(&p[0])
264+
case *image.RGBA:
265+
cpixels = unsafe.Pointer(&p.Pix[0])
266+
case []byte:
267+
cpixels = unsafe.Pointer(&p[0])
268+
}
260269
ctexture := texture.cptr()
261-
cpixels := unsafe.Pointer(&pixels[0])
262270
crec := rec.cptr()
263271
C.UpdateTextureRec(*ctexture, *crec, cpixels)
264272
}

0 commit comments

Comments
 (0)