aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Waller <p@pwaller.net>2014-04-30 16:13:15 +0100
committerPeter Waller <p@pwaller.net>2014-04-30 16:13:15 +0100
commit38537f1ab9406d0349dde5dc4abc32c3926d3e80 (patch)
tree1dfa25aed3329df4731f9979a294bc4db8666610
parent492ce621db79a5f85dcb6d07fceae598dba3eb75 (diff)
parentbf02117a1e15dcefb8a0478b8f82b0eb4fd396d0 (diff)
downloadgl-38537f1ab9406d0349dde5dc4abc32c3926d3e80.tar.gz
Merge pull request #144 from PolyFloyd/buffermap
Added MapBuffer convenience functions for slices
-rw-r--r--buffer.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/buffer.go b/buffer.go
index 88936c7..b9cffde 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,30 @@ 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.
+// WARNING: This function makes use of reflect.SliceHeader which may reduce
+// portability of your application. See the reflect.SliceHeader documentation
+// for more information.
+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)))