Esempio n. 1
0
func uploadGeometry(mesh *geometry) {
	gl.GenVertexArrays(1, &mesh.glVao)
	gl.BindVertexArray(mesh.glVao)
	gl.GenBuffers(1, &mesh.glVertBuf)
	gl.BindBuffer(gl.ARRAY_BUFFER, mesh.glVertBuf)
	gl.EnableVertexAttribArray(progPosAttrLoc)
	gl.VertexAttribPointer(progPosAttrLoc, 3, gl.FLOAT, gl.FALSE, 0, gl.Ptr(nil))
	gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(4*len(mesh.glVerts)), gl.Ptr(&mesh.glVerts[0]), gl.STATIC_DRAW)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0)
	gl.BindVertexArray(0)
}
Esempio n. 2
0
//	Sets up this vertex array object. Unless atts are specified, prog can be be nil.
//	To specify element/index buffer and vertex/attribute buffers (if applicable), pass them via bufs.
func (me *VertexArray) Setup(prog *Program, atts []VertexAttribPointer, bufs ...*Buffer) (err error) {
	var (
		buf  *Buffer
		aloc gl.Uint
	)
	me.Bind()
	for _, buf = range bufs {
		buf.Bind()
	}
	for i := 0; i < len(atts); i++ {
		if aloc = prog.AttrLocs[atts[i].Name]; prog.HasAttr(atts[i].Name) {
			gl.EnableVertexAttribArray(aloc)
			gl.VertexAttribPointer(aloc, atts[i].Size, atts[i].Type, atts[i].Normalized, atts[i].Stride, atts[i].Offset)
		}
	}
	me.Unbind()
	for _, buf = range bufs {
		buf.Unbind()
	}
	err = Util.LastError("VertexArray.Setup()")
	return
}