Split rendering of buffer & blitting it to the display.
This commit is contained in:
parent
480e864b53
commit
dbeacc3794
23
ui/buffer.go
23
ui/buffer.go
@ -1,6 +1,10 @@
|
||||
package ui
|
||||
|
||||
import "opslag.de/schobers/geom"
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"opslag.de/schobers/geom"
|
||||
)
|
||||
|
||||
type RenderBufferFn func(ctx Context, size geom.PointF32)
|
||||
|
||||
@ -9,6 +13,8 @@ type Buffer struct {
|
||||
size geom.PointF32
|
||||
}
|
||||
|
||||
var ErrNewBufferSize = errors.New("buffer has been resized")
|
||||
|
||||
func (b *Buffer) Update(ctx Context, size geom.PointF32) error {
|
||||
if b.texture != nil {
|
||||
if size == b.size {
|
||||
@ -24,19 +30,30 @@ func (b *Buffer) Update(ctx Context, size geom.PointF32) error {
|
||||
}
|
||||
b.texture = texture
|
||||
b.size = size
|
||||
return nil
|
||||
return ErrNewBufferSize
|
||||
}
|
||||
|
||||
func (b *Buffer) Render(ctx Context, pos geom.PointF32, fn RenderBufferFn) {
|
||||
if b.texture == nil {
|
||||
return
|
||||
}
|
||||
b.RenderContent(ctx, fn)
|
||||
b.RenderToDisplay(ctx, pos)
|
||||
}
|
||||
|
||||
func (b *Buffer) RenderContent(ctx Context, fn RenderBufferFn) {
|
||||
renderer := ctx.Renderer()
|
||||
currTarget := renderer.Target()
|
||||
renderer.RenderTo(b.texture)
|
||||
fn(ctx, b.size)
|
||||
renderer.RenderTo(currTarget)
|
||||
renderer.DrawTexturePoint(b.texture, pos)
|
||||
}
|
||||
|
||||
func (b *Buffer) RenderToDisplay(ctx Context, pos geom.PointF32) {
|
||||
if b.texture == nil {
|
||||
return
|
||||
}
|
||||
ctx.Renderer().DrawTexturePoint(b.texture, pos)
|
||||
}
|
||||
|
||||
type BufferControl struct {
|
||||
|
Loading…
Reference in New Issue
Block a user