go-qml / qml

QML support for the Go language
Other
1.96k stars 189 forks source link

How to use VertexAttribPointer #93

Closed neclepsio closed 9 years ago

neclepsio commented 9 years ago

There are some issues with OpenGL wrapper.

  1. Is this the way to pass a slice to VertexAttribPointer, without the use of buffers?
gl.VertexAttribPointer(ca.Position, 3, GL.FLOAT, false, 0, int(uintptr(unsafe.Pointer(&m.Vertices[0]))))

(I'm not sure int(uintptr(...)) is correct)

  1. I think GetProgramInfoLog and GetShaderInfoLog should return string and not []byte.

Thank you Ignazio

niemeyer commented 9 years ago

Please see the documentation of the function:

http://gopkg.in/qml.v1/gl/2.0#GL.VertexAttribPointer

The short version is that providing a buffer to VertexAttrbPointer is deprecated. The modern way to do this is via GenBuffer+BindBuffer+BufferData. The painting-es2 example uses it:

https://github.com/go-qml/qml/blob/v1/examples/painting-es2/painting.go

Regarding point 2, I disagree. Using []byte is idiomatic and prevents a copy.

neclepsio commented 9 years ago

It's ok it's deprecated in you api, but if I still want to use it, is int(uintptr(unsafe.Pointer(&slice[0]))) the way to go? Can int(uintptr) overflow/underflow, for example? Il 06/set/2014 00:46 "Gustavo Niemeyer" notifications@github.com ha scritto:

Please see the documentation of the function:

http://gopkg.in/qml.v1/gl/2.0#GL.VertexAttribPointer

The short version is that providing a buffer to VertexAttrbPointer is deprecated. The modern way to do this is via GenBuffer+BindBuffer+BufferData. The painting-es2 example uses it:

https://github.com/go-qml/qml/blob/v1/examples/painting-es2/painting.go

Regarding point 2, I disagree. Using []byte is idiomatic and prevents a copy.

— Reply to this email directly or view it on GitHub https://github.com/go-qml/qml/issues/93#issuecomment-54690928.

niemeyer commented 9 years ago

I meant that my understanding is that the use of the pointer attribute to provide an array is obsoleted in OpenGL in general.

That said, I'd like to support your use of it, if you really want to, and there's no good way to do that while the parameter is an int, because it may not necessarily be sized after the machine word size (although it generally is, right now).

To fix that problem, I'll convert the offset type into a "uintptr", so that the proper way to do what you want would be:

uintptr(unsafe.Pointer(&slice[0]))

That said, I'd still encourage you to provide the array as buffer data instead.