func bufferSetUp(buffer bufferSetUpInt, program gl.Program) { buffer.gen() buffer.bind() // Collect the attrib locations for each attrib name. atts_names := buffer.names() // Expected GLSL variable names. atts := make([]gl.AttribLocation, len(atts_names)) for i, att_name := range atts_names { atts[i] = program.GetAttribLocation(att_name) if err := CheckGlError(); err != nil { err.Description = fmt.Sprintf("program.GetAttribLocation(%#v)", att_name) panic(err) } if atts[i] == -1 { panic(fmt.Sprintf("attrib location %#v not found", att_name)) } } // Now that the locations are known, we can relate them to vertex data. buffer.attribPointers(atts) buffer.unbind() }
// renderBuffered uses VBO's. This is the preferred mode for systems // where shader support is not present or deemed necessary. func (mb *MeshBuffer) renderBuffered(mode gl.GLenum, m Mesh, program gl.Program) { is, ic := m[mbIndexKey][0], m[mbIndexKey][1] program.Use() var attribLocation gl.AttribLocation for _, value := range mb.attr { if value.name == "index" { continue } value.bind() if value.Invalid() { value.buffer() } attribLocation = program.GetAttribLocation(value.name) attribLocation.EnableArray() attribLocation.AttribPointer(value.size, value.typ, false, 0, uintptr(0)) value.unbind() } ia := mb.find(mbIndexKey) ia.bind() if ia.Invalid() { ia.buffer() } gl.DrawElements(mode, ic, ia.typ, uintptr(is*ia.stride)) ia.unbind() for _, value := range mb.attr { if value.name == "index" { continue } attribLocation := program.GetAttribLocation(value.name) attribLocation.DisableArray() } }