File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed
Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -2866,7 +2866,16 @@ func UpdateTexture(texture Texture2D, pixels any) {
28662866
28672867// UpdateTextureRec - Update GPU texture rectangle with new data
28682868func 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments