go-gl / gl

Go bindings for OpenGL (generated via glow)
MIT License
1.09k stars 73 forks source link

How can I cast a []byte to []mgl32.Vec3? #115

Closed Hperigo closed 5 years ago

Hperigo commented 6 years ago

Hi there, thank you for this wonderful lib.

Im trying to implement the glMapBuffer function and I’ve managed to retrieve the vbo buffer similar to what’s described in here: https://github.com/go-gl/gl/issues/28 My question is, how can I cast the []byte to a []mgl32.Vec3?

    gl.BindBuffer(gl.ARRAY_BUFFER, vbo.VboHandle)
    ptr := gl.MapBuffer(gl.ARRAY_BUFFER, gl.READ_WRITE)
    return (*[1 << 30]byte)(ptr)[:length:length]

thanks!

dmitshur commented 6 years ago

You can either use type conversions, or use unsafe package to try and cast more directly.

See the source of https://godoc.org/golang.org/x/mobile/exp/f32#Bytes for an example of the conversion approach.

pwaller commented 5 years ago

I'm going to close this thread since there was no further and @dmitshur's comment looks to answer the question.