Exemple #1
0
// bindEnabledAttributes will take the enabled attrib flags and use them to enable
// all the attributes that we need.
func (mesh *Mesh) bindEnabledAttributes() {
	useVertexAttribArrays(mesh.enabledattribs)

	mesh.vbo.bind()
	defer mesh.vbo.unbind()

	offset := 0
	if (mesh.enabledattribs & attribflag_pos) > 0 {
		gl.VertexAttribPointer(attrib_pos, 2, gl.FLOAT, false, mesh.vertexStride*4, gl.PtrOffset(offset))
		offset += 2 * 4
	}
	if (mesh.enabledattribs & attribflag_texcoord) > 0 {
		gl.VertexAttribPointer(attrib_texcoord, 2, gl.FLOAT, false, mesh.vertexStride*4, gl.PtrOffset(offset))
		offset += 2 * 4
	}
	if (mesh.enabledattribs & attribflag_color) > 0 {
		gl.VertexAttribPointer(attrib_color, 4, gl.FLOAT, false, mesh.vertexStride*4, gl.PtrOffset(offset))
	}
}
Exemple #2
0
// Draw satisfies the Drawable interface. Inputs are as follows
// x, y, r, sx, sy, ox, oy, kx, ky
// x, y are position
// r is rotation
// sx, sy is the scale, if sy is not given sy will equal sx
// ox, oy are offset
// kx, ky are the shear. If ky is not given ky will equal kx
func (sprite_batch *SpriteBatch) Draw(args ...float32) {
	if sprite_batch.count == 0 {
		return
	}

	prepareDraw(generateModelMatFromArgs(args))
	bindTexture(sprite_batch.texture.getHandle())
	useVertexAttribArrays(attribflag_pos | attribflag_texcoord | attribflag_color)

	sprite_batch.array_buf.bind()
	defer sprite_batch.array_buf.unbind()

	gl.VertexAttribPointer(attrib_pos, 2, gl.FLOAT, false, 8*4, gl.PtrOffset(0))
	gl.VertexAttribPointer(attrib_texcoord, 2, gl.FLOAT, false, 8*4, gl.PtrOffset(2*4))
	gl.VertexAttribPointer(attrib_color, 4, gl.FLOAT, false, 8*4, gl.PtrOffset(4*4))

	min, max := sprite_batch.GetDrawRange()
	sprite_batch.quad_indices.drawElements(gl.TRIANGLES, min, max-min+1)
}
Exemple #3
0
func (buffer *indexBuffer) drawElements(mode uint32, offset, size int) {
	buffer.bind()
	defer buffer.unbind()
	gl.DrawElements(gl.Enum(mode), size, gl.UNSIGNED_INT, gl.PtrOffset(offset*4))
}