|
3 | 3 |
|
4 | 4 | package rl |
5 | 5 |
|
| 6 | +import "C" |
6 | 7 | import ( |
7 | 8 | "fmt" |
8 | 9 | "image" |
@@ -2849,9 +2850,18 @@ func UnloadRenderTexture(target RenderTexture2D) { |
2849 | 2850 | unloadRenderTexture(uintptr(unsafe.Pointer(&target))) |
2850 | 2851 | } |
2851 | 2852 |
|
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) |
2855 | 2865 | } |
2856 | 2866 |
|
2857 | 2867 | // UpdateTextureRec - Update GPU texture rectangle with new data |
@@ -3829,10 +3839,19 @@ func UnloadAudioStream(stream AudioStream) { |
3829 | 3839 | unloadAudioStream(uintptr(unsafe.Pointer(&stream))) |
3830 | 3840 | } |
3831 | 3841 |
|
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) |
3836 | 3855 | } |
3837 | 3856 |
|
3838 | 3857 | // IsAudioStreamProcessed - Check if any audio stream buffers requires refill |
|
0 commit comments