Use unsafe Slice/SliceData

This commit is contained in:
Milan Nikolic 2023-11-07 14:25:51 +01:00
parent e3d8d6dd12
commit 040d87fb79
No known key found for this signature in database
GPG key ID: 9229D0EAA3AA4E75
2 changed files with 6 additions and 14 deletions

View file

@ -11,7 +11,6 @@ package rl
*/
import "C"
import (
"reflect"
"unsafe"
)
@ -228,16 +227,10 @@ func WaveCrop(wave Wave, initSample int32, finalSample int32) {
// LoadWaveSamples - Get samples data from wave as a floats array
func LoadWaveSamples(wave Wave) []float32 {
var data []float32
cwave := wave.cptr()
ret := C.LoadWaveSamples(*cwave)
sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&data)))
sliceHeader.Cap = int(wave.FrameCount)
sliceHeader.Len = int(wave.FrameCount)
sliceHeader.Data = uintptr(unsafe.Pointer(ret))
return data
v := unsafe.Slice((*float32)(unsafe.Pointer(ret)), wave.FrameCount)
return v
}
// UnloadWaveSamples - Unload samples data loaded with LoadWaveSamples()

View file

@ -7,7 +7,6 @@ package rl
*/
import "C"
import (
"reflect"
"unsafe"
)
@ -100,19 +99,19 @@ func GetShaderLocationAttrib(shader Shader, attribName string) int32 {
func SetShaderValue(shader Shader, locIndex int32, value []float32, uniformType ShaderUniformDataType) {
cshader := shader.cptr()
clocIndex := (C.int)(locIndex)
cvalue := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&value)).Data)
cvalue := unsafe.SliceData(value)
cuniformType := (C.int)(uniformType)
C.SetShaderValue(*cshader, clocIndex, cvalue, cuniformType)
C.SetShaderValue(*cshader, clocIndex, unsafe.Pointer(cvalue), cuniformType)
}
// SetShaderValueV - Set shader uniform value (float)
func SetShaderValueV(shader Shader, locIndex int32, value []float32, uniformType ShaderUniformDataType, count int32) {
cshader := shader.cptr()
clocIndex := (C.int)(locIndex)
cvalue := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&value)).Data)
cvalue := unsafe.SliceData(value)
cuniformType := (C.int)(uniformType)
ccount := (C.int)(count)
C.SetShaderValueV(*cshader, clocIndex, cvalue, cuniformType, ccount)
C.SetShaderValueV(*cshader, clocIndex, unsafe.Pointer(cvalue), cuniformType, ccount)
}
// SetShaderValueMatrix - Set shader uniform value (matrix 4x4)