func (a *VertexArray) ID() uint32 {
	return a.id
}
ID returns VertexArray identifier (aka name)
package gl
import (
	"github.com/jacekolszak/pixiq/image"
)
func NewContext(api API) *Context {
	if api == nil {
		panic("nil api")
	}
	return &Context{
		api:             api,
		vertexBufferIDs: vertexBufferIDs{},
		allImages:       allImages{},
		capabilities:    gatherCapabilities(api),
	}
}
func gatherCapabilities(api API) *Capabilities {
	var maxTextureSizeVal int32
	api.GetIntegerv(maxTextureSize, &maxTextureSizeVal)
	return &Capabilities{
		maxTextureSize: int(maxTextureSizeVal),
	}
}
type VertexBuffer interface {
	ID() uint32
}
type vertexBufferIDs map[VertexBuffer]uint32
type allImages map[image.AcceleratedImage]*AcceleratedImage
type FloatVertexBuffer struct {
	id      uint32
	deleted bool
	size    int
	api     API
}
func (b *FloatVertexBuffer) Size() int {
	return b.size
}
func (b *FloatVertexBuffer) ID() uint32 {
	return b.id
}
func (b *FloatVertexBuffer) Upload(offset int, data []float32) {
	if offset < 0 {
		panic("negative offset")
	}
	if b.size < len(data)+offset {
		panic("FloatVertexBuffer is to small to store data")
	}
	b.api.BindBuffer(arrayBuffer, b.id)
	b.api.BufferSubData(arrayBuffer, offset*4, len(data)*4, b.api.Ptr(data))
}
func (b *FloatVertexBuffer) Delete() {
	b.api.DeleteBuffers(1, &b.id)
	b.deleted = true
}
func (b *FloatVertexBuffer) Download(offset int, output []float32) {
	if b.deleted {
		panic("deleted buffer")
	}
	if offset < 0 {
		panic("negative offset")
	}
	if len(output) == 0 {
		return
	}
	size := len(output)
	if size+offset > b.size {
		size = b.size - offset
	}
	b.api.BindBuffer(arrayBuffer, b.id)
	b.api.GetBufferSubData(arrayBuffer, offset*4, size*4, b.api.Ptr(output))
}
type VertexLayout []Type
type Type struct {
	components int32
	xtype      uint32
	name       string
}
func valueOf(xtype uint32) Type {
	switch xtype {
	case float:
		return Float
	case floatVec2:
		return Vec2
	case floatVec3:
		return Vec3
	case floatVec4:
		return Vec4
	}
	panic("not supported type")
}
func (t Type) String() string {
	return t.name
}
var (
	Float = Type{components: 1, xtype: float, name: "Float"}
	Vec2 = Type{components: 2, xtype: float, name: "Vec2"}
	Vec3 = Type{components: 3, xtype: float, name: "Vec3"}
	Vec4 = Type{components: 4, xtype: float, name: "Vec4"}
)
type VertexArray struct {
	id              uint32
	layout          VertexLayout
	vertexBufferIDs vertexBufferIDs
	api             API
}
func (a *VertexArray) Delete() {
	a.api.DeleteVertexArrays(1, &a.id)
}
type VertexBufferPointer struct {
	Buffer VertexBuffer
	Offset int
	Stride int
}
func (a *VertexArray) Set(location int, pointer VertexBufferPointer) {
	if pointer.Offset < 0 {
		panic("negative pointer offset")
	}
	if pointer.Stride < 0 {
		panic("negative pointer stride")
	}
	if pointer.Buffer == nil {
		panic("nil pointer buffer")
	}
	if location < 0 {
		panic("negative location")
	}
	if location >= len(a.layout) {
		panic("location out-of-bounds")
	}
	bufferID, ok := a.vertexBufferIDs[pointer.Buffer]
	if !ok {
		panic("vertex buffer has not been created in this context")
	}
	a.api.BindVertexArray(a.id)
	a.api.BindBuffer(arrayBuffer, bufferID)
	typ := a.layout[location]
	components := typ.components
	a.api.VertexAttribPointer(
		uint32(location),
		components,
		typ.xtype,
		false,
		int32(pointer.Stride*4),
		a.api.PtrOffset(pointer.Offset*4),
	)
}