Esempio n. 1
0
func (buf *uintBuffer) Update(ctx gl.Context, data []uint32) {
	buf.count = len(data)
	subok := len(buf.bin) > 0 && len(data)*4 <= len(buf.bin)
	if !subok {
		buf.bin = make([]byte, len(data)*4)
	}
	for i, u := range data {
		buf.bin[4*i+0] = byte(u >> 0)
		buf.bin[4*i+1] = byte(u >> 8)
		buf.bin[4*i+2] = byte(u >> 16)
		buf.bin[4*i+3] = byte(u >> 24)
	}
	if subok {
		ctx.BufferSubData(gl.ELEMENT_ARRAY_BUFFER, 0, buf.bin)
	} else {
		ctx.BufferData(gl.ELEMENT_ARRAY_BUFFER, buf.bin, buf.usage)
	}
}
Esempio n. 2
0
func (wf *Waveform) Paint(ctx gl.Context, xps, yps, width, height float32) {
	// TODO this is racey and samples can be in the middle of changing
	// move the slice copy to Prepare and sync with playback, or feed over chan
	// TODO assumes mono

	var (
		xstep float32 = width / float32(len(wf.samples))
		xpos  float32 = xps
	)

	for i, x := range wf.samples {
		// clip
		if x > 1 {
			x = 1
		} else if x < -1 {
			x = -1
		}

		wf.verts[i*3] = float32(xpos)
		wf.verts[i*3+1] = yps + (height * float32((x+1)/2))
		wf.verts[i*3+2] = 0
		xpos += xstep
	}

	for i, x := range wf.verts {
		u := math.Float32bits(x)
		wf.data[4*i+0] = byte(u >> 0)
		wf.data[4*i+1] = byte(u >> 8)
		wf.data[4*i+2] = byte(u >> 16)
		wf.data[4*i+3] = byte(u >> 24)
	}

	ctx.UseProgram(wf.program)
	ctx.Uniform4f(wf.color, 1, 1, 1, 1)

	// update hw buf and draw
	ctx.BindBuffer(gl.ARRAY_BUFFER, wf.buf)
	ctx.EnableVertexAttribArray(wf.position)
	ctx.VertexAttribPointer(wf.position, 3, gl.FLOAT, false, 0, 0)
	ctx.BufferSubData(gl.ARRAY_BUFFER, 0, wf.data)
	ctx.DrawArrays(gl.LINE_STRIP, 0, len(wf.samples))
	ctx.DisableVertexAttribArray(wf.position)
}
Esempio n. 3
0
func (btn *Button) Paint(ctx gl.Context) {
	for i, x := range btn.verts {
		u := math.Float32bits(x)
		btn.data[4*i+0] = byte(u >> 0)
		btn.data[4*i+1] = byte(u >> 8)
		btn.data[4*i+2] = byte(u >> 16)
		btn.data[4*i+3] = byte(u >> 24)
	}

	ctx.UseProgram(btn.program)
	if btn.active {
		ctx.Uniform4f(btn.color, btn.r, btn.g, btn.b, btn.a)
	} else {
		ctx.Uniform4f(btn.color, 0.4, 0.4, 0.4, 0.5)
	}

	// update hw buf and draw
	ctx.BindBuffer(gl.ARRAY_BUFFER, btn.buf)
	ctx.EnableVertexAttribArray(btn.position)
	ctx.VertexAttribPointer(btn.position, 3, gl.FLOAT, false, 0, 0)
	ctx.BufferSubData(gl.ARRAY_BUFFER, 0, btn.data)
	ctx.DrawArrays(gl.TRIANGLES, 0, len(btn.verts))
	ctx.DisableVertexAttribArray(btn.position)
}