gpu,gpu/headless,app/internal/wm: add explicit RenderTarget API

Both the OpenGL and the Direct3D API are stateful and gpu.GPU renders to
the render target current when Frame is called.

Modern GPU API such as Metal don't have a concept of a current render
target, and the target even changes each frame.

Add RenderTarget and add an explicit target argument to GPU.Frame as
well as the underlying driver.Device.BeginFrame.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-08-04 14:10:07 +02:00
parent 0bdc2e0432
commit 7d84e419c9
16 changed files with 95 additions and 23 deletions
+5 -5
View File
@@ -42,8 +42,8 @@ type GPU interface {
Clear(color color.NRGBA)
// Collect the graphics operations from frame, given the viewport.
Collect(viewport image.Point, frame *op.Ops)
// Frame clears the color buffer and draws the collected operations.
Frame() error
// Frame draws the collected operations to target.
Frame(target RenderTarget) error
// Profile returns the last available profiling information. Profiling
// information is requested when Collect sees a ProfileOp, and the result
// is available through Profile at some later time.
@@ -356,7 +356,7 @@ func New(api API) (GPU, error) {
if err != nil {
return nil, err
}
d.BeginFrame(false, image.Point{})
d.BeginFrame(nil, false, image.Point{})
defer d.EndFrame()
forceCompute := os.Getenv("GIORENDERER") == "forcecompute"
feats := d.Caps().Features
@@ -414,9 +414,9 @@ func (g *gpu) Collect(viewport image.Point, frameOps *op.Ops) {
}
}
func (g *gpu) Frame() error {
func (g *gpu) Frame(target RenderTarget) error {
viewport := g.renderer.blitter.viewport
defFBO := g.ctx.BeginFrame(g.drawOps.clear, viewport)
defFBO := g.ctx.BeginFrame(target, g.drawOps.clear, viewport)
defer g.ctx.EndFrame()
for _, img := range g.drawOps.imageOps {
expandPathOp(img.path, img.clip)