aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPolyFloyd <floyd@polyfloyd.net>2014-04-29 22:40:27 +0200
committerPolyFloyd <floyd@polyfloyd.net>2014-04-29 22:40:27 +0200
commit35e82469106d2bc6391736ddcc18559c1cb81532 (patch)
tree65efd13a7cd4e958bb497b2891eee5b029abdee0
parentc06827a70e7bc851e492935456d35cec7ee27abd (diff)
downloadgl-35e82469106d2bc6391736ddcc18559c1cb81532.tar.gz
Added MapBuffer convenience functions for slices
-rw-r--r--buffer.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/buffer.go b/buffer.go
index 88936c7..8d13e25 100644
--- a/buffer.go
+++ b/buffer.go
@@ -7,6 +7,7 @@ package gl
// #include "gl.h"
import "C"
import "unsafe"
+import "reflect"
// Buffer Objects
@@ -81,6 +82,27 @@ func MapBuffer(target GLenum, access GLenum) unsafe.Pointer {
return unsafe.Pointer(C.glMapBuffer(C.GLenum(target), C.GLenum(access)))
}
+// Maps the buffer with MapBuffer() and returns a pointer to the slice pointing
+// to the mapped buffer. See also the MapBuffer<Type> convenience functions.
+func MapBufferSlice(target GLenum, access GLenum, bytesPerElement int) unsafe.Pointer {
+ rawLength := int(GetBufferParameteriv(target, BUFFER_SIZE))
+ return unsafe.Pointer(&reflect.SliceHeader{
+ Data: uintptr(MapBuffer(target, access)),
+ Len: rawLength / bytesPerElement,
+ Cap: rawLength / bytesPerElement,
+ })
+}
+
+// Map a buffer object's data store and return it as a slice
+func MapBufferFloat32(target GLenum, access GLenum) []float32 {
+ return *(*[]float32)(MapBufferSlice(target, access, 4))
+}
+
+// Map a buffer object's data store and return it as a slice
+func MapBufferUint32(target GLenum, access GLenum) []uint32 {
+ return *(*[]uint32)(MapBufferSlice(target, access, 4))
+}
+
// Unmap a buffer object's data store
func UnmapBuffer(target GLenum) bool {
return goBool(C.glUnmapBuffer(C.GLenum(target)))