better error checking

This commit is contained in:
faiface 2016-11-26 22:51:20 +01:00
parent c6e2d67aba
commit 6253156e24
1 changed files with 4 additions and 5 deletions

View File

@ -215,14 +215,13 @@ func (va *VertexArray) SetVertexAttribute(vertex int, attr VertexAttribute, data
if vertex < 0 || vertex >= va.count {
panic("set vertex attribute error: invalid vertex index")
}
if _, ok := va.attrs[attr]; !ok {
panic("set vertex attribute error: invalid vertex attribute")
}
DoNoBlock(func() {
gl.BindBuffer(gl.ARRAY_BUFFER, va.vbo)
attrOffset, ok := va.attrs[attr]
if !ok {
panic("set vertex attribute error: invalid vertex attribute")
}
offset := 8*va.stride*vertex + 8*attrOffset
offset := 8*va.stride*vertex + 8*va.attrs[attr]
gl.BufferSubData(gl.ARRAY_BUFFER, offset, 8*len(data), gl.Ptr(data))
gl.BindBuffer(gl.ARRAY_BUFFER, 0)