go-gl / gl

Go bindings for OpenGL (generated via glow)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Hperigo opened this issue · comments

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: #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!

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.

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