How would one write to the *gl.Pointer returned by glMapBuffer()?
Specifically I wanted to try streaming texture transfers as described here:
http://ogltotd.blogspot.com/2006/12/streaming-texture-updates.html
I don't get any GL errors with implementing that, but also no pixel transfer seems to happen (black geometry instead of textured).
Now the interesting part of his snippet the author doesn't go into:
writeImage(pboMappedMemory)"
-- but I've seen this part in other tutorials typically as just a single:
memcpy(myPixPtr, pboMappedBuffer)
call. Obviously that's C and I presume in Go one would just emulate that by doing
*dstPtr = *srcPtr
Now, since in gogl the glMapBuffer returns a *gl.Pointer, all I knew to do was:
var myPicPtr gl.Pointer = getPix0Ptr(...)
var pboPtr *gl.Pointer = gl.MapBuffer(...)
*pboPtr = myPicPtr
But while not causing any errors, it does also not result in the desired pixel transfer from what I can tell...
I just wanted to ask if you (or anyone else here) has any other ideas on how to emulate memcpy here -- since you definitely know your C and its pointers way better than me....
If you don't have anything come to mind off the top of your head but would be interested in a minimal sample app for this scenario, I'll be happy to code one up for further experimentation...
Hi,
like in the C version you have to copy the data from myPixPtr to your mapped memory. A simple pointer assignment doesn’t work. I think the best way is to convert the pointer to a slices/array and copy it using the builtin copy(des, src) function. Something like this (not tested):
func PointerToByteSlice(p gl.Pointer, start, end int) []byte {
return *[0x7FFFFFFF]byte(p)[start:end];
}
mappedMemory := PointerToByteSlice(pMapPtr, 0, size)
data := PointerToByteSlice(myPixPtr, 0, size)
copy(mappedMemory, data)
Hope this helps. BTW: I think this conversion function could be added as a new utility function.
Thanks for your thoughts, gonna play with that some more in a day or two and keep you updated =)