func BufferInit(target Enum, size int, usage Enum) { defer func() { errstr := errDrain() log.Printf("gl.BufferInit(%v, %v, %v) %v", target, size, usage, errstr) }() C.glBufferData(target.c(), C.GLsizeiptr(size), nil, usage.c()) }
func BufferData(target Enum, usage Enum, src []byte) { defer func() { errstr := errDrain() log.Printf("gl.BufferData(%v, %v, len(%d)) %v", target, usage, len(src), errstr) }() C.glBufferData(target.c(), C.GLsizeiptr(len(src)), unsafe.Pointer(&src[0]), usage.c()) }
// Set calls glBufferData with appropriate arguments to load the data pointed to by data into the buffer. usage is passed along verbatim. targ is used for binding and it should most likely be ARRAY_BUFFER. func (buf *Buffer) Set(targ int, data interface{}, usage int) { buf.Bind(targ) p, t, ts, s := toCtype(data) C.glBufferData(C.GLenum(targ), C.GLsizeiptr(s), p, C.GLenum(usage)) buf.t = t buf.ts = ts buf.Unbind(targ) }
// BufferData uses glBufferData to allocate memory for the bound GL buffer, // and fills it with the data in slice. slice can be either a slice or pointer. // Behaviour is undefined if the underlying data type is or contains anything // other than sized numeric types. (Structs and arrays are okay as long as they're // of sized numeric types. Pointers and slices are only allowed at the topmost level.) func BufferData(target GLenum, slice interface{}, usage GLenum) error { data, e := sliceToUintptr(slice) if e != nil { return e } C.glBufferData(C.GLenum(target), C.GLsizeiptr(data.Size*data.Length), unsafe.Pointer(data.Ptr), C.GLenum(usage)) return nil }
func BufferData( target Enum, size SizeiPtr, data Void, usage Enum) { C.glBufferData( C.GLenum(target), C.GLsizeiptr(size), unsafe.Pointer(data), C.GLenum(usage)) }
func (game *game) initGL() { log.Printf("GL_VERSION: %v GL_RENDERER: %v GL_VENDOR %v\n", GetString(C.GL_VERSION), GetString(C.GL_RENDERER), GetString(C.GL_VENDOR)) log.Printf("GL_EXTENSIONS: %v\n", GetString(C.GL_EXTENSIONS)) C.glClearColor(0.0, 0.0, 0.0, 1.0) C.glEnable(C.GL_CULL_FACE) C.glEnable(C.GL_DEPTH_TEST) game.prog = createProgram(vertShaderSrcDef, fragShaderSrcDef) posAttrib := attribLocation(game.prog, "vPosition") game.offsetUni = uniformLocation(game.prog, "offset") game.colorUni = uniformLocation(game.prog, "color") C.glUseProgram(game.prog) C.glEnableVertexAttribArray(C.GLuint(posAttrib)) vertVBO := GenBuffer() checkGLError() C.glBindBuffer(C.GL_ARRAY_BUFFER, vertVBO) verts := []float32{.0, 0.5, -0.5, -0.5, 0.5, -0.5} C.glBufferData(C.GL_ARRAY_BUFFER, C.GLsizeiptr(len(verts)*int(unsafe.Sizeof(verts[0]))), unsafe.Pointer(&verts[0]), C.GL_STATIC_DRAW) C.glVertexAttribPointer(C.GLuint(posAttrib), 2, C.GL_FLOAT, C.GL_FALSE, 0, unsafe.Pointer(uintptr(0))) }
func BufferInit(target Enum, size int, usage Enum) { C.glBufferData(target.c(), C.GLsizeiptr(size), nil, usage.c()) }
func BufferData(target Enum, size int, src unsafe.Pointer, usage Enum) { C.glBufferData(target.c(), C.GLsizeiptr(size), src, usage.c()) }
func BufferData(target BufferTarget, size int, usage BufferUsage) { C.glBufferData(C.GLenum(target), C.GLsizeiptr(size), nil, C.GLenum(usage)) }
func BufferDataf(target BufferTarget, data []float32, usage BufferUsage) { C.glBufferData(C.GLenum(target), C.GLsizeiptr(unsafe.Sizeof(data[0])*uintptr(len(data))), unsafe.Pointer(&data[0]), C.GLenum(usage)) }
func BufferData(target uint, size int, data Void, usage uint) { C.glBufferData( C.GLenum(target), C.GLsizeiptr(size), unsafe.Pointer(data), C.GLenum(usage)) }
// Creates and initializes a buffer object's data store func BufferData(target GLenum, size int, data interface{}, usage GLenum) { C.glBufferData(C.GLenum(target), C.GLsizeiptr(size), ptr(data), C.GLenum(usage)) }
func BufferData(target Enum, src []byte, usage Enum) { C.glBufferData(target.c(), C.GLsizeiptr(len(src)), unsafe.Pointer(&src[0]), usage.c()) }
// BufferData creates and initializes a buffer object's data store. func BufferData(targ BufferTarget, data interface{}, usage BufferDataUsage) { _, sz, ptr := rawData(data) C.glBufferData(C.GLenum(targ), C.GLsizeiptr(sz), ptr, C.GLenum(usage)) }