FAQ

On Monday, December 29, 2014 3:22:22 AM UTC-6, Thomas Bruyelle wrote:
I'm migrating an app I wrote from github.com/go-gl/gl to
golang.org/x/mobile/gl and one frustration I had was the type of data in
the gl.BufferData functions.

The current signature requires a []byte for the data :

func BufferData(target Enum, usage Enum, src []byte) {
C.glBufferData(target.c(), C.GLsizeiptr(len(src)),
unsafe.Pointer(&src[0]), usage.c())

}

but I think it would be more flexible with a interface{} type

func BufferData(target Enum, usage Enum, size int, src interface{}) {
C.glBufferData(target.c(), C.GLsizeiptr(size), ptr(src), usage.c())
}

The parameter size is needed because len(interface{}) is not allowed. Also
a small function ptr() needs to be added, you can see its code here
https://github.com/go-gl/gl/blob/master/gl.go#L55
Of course this change should be applied to all the BufferData kind
functions.


The benefit of this change is to allow to pass custom structs to the
function. In my app I use custom structs to define the vertices and the
colors easily.

WDYT?
[]byte accurately describes what was a byte count and void*
You just need to turn your struct (or []struct) into a []byte with unsafe.
https://code.google.com/p/go-wiki/wiki/cgo read the "Turning C arrays into
Go slices" section.

Until more is known about future state of the GC you should use C memory if
you are going to be passing in structs or arrays of structs.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 10 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 29, '14 at 9:22a
activeJan 1, '15 at 5:19a
posts10
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase