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
+7
View File
@@ -54,6 +54,13 @@ func (c *d3d11Context) API() gpu.API {
return gpu.Direct3D11{Device: unsafe.Pointer(c.dev)}
}
func (c *d3d11Context) RenderTarget() gpu.RenderTarget {
return gpu.Direct3D11RenderTarget{
RenderTarget: unsafe.Pointer(c.renderTarget),
DepthStencilView: unsafe.Pointer(c.depthView),
}
}
func (c *d3d11Context) Present() error {
err := c.swchain.Present(1, 0)
if err == nil {
+4
View File
@@ -65,6 +65,10 @@ func contextAPI() gpu.OpenGL {
return gpu.OpenGL{}
}
func (c *context) RenderTarget() gpu.RenderTarget {
return gpu.OpenGLRenderTarget(c.frameBuffer)
}
func (c *context) API() gpu.API {
return contextAPI()
}
+4
View File
@@ -36,6 +36,10 @@ func newContext(w *window) (*context, error) {
return c, nil
}
func (c *context) RenderTarget() gpu.RenderTarget {
return gpu.OpenGLRenderTarget{}
}
func (c *context) API() gpu.API {
return gpu.OpenGL{Context: gl.Context(c.ctx)}
}
+4
View File
@@ -52,6 +52,10 @@ func newContext(w *window) (*context, error) {
return c, nil
}
func (c *context) RenderTarget() gpu.RenderTarget {
return gpu.OpenGLRenderTarget{}
}
func (c *context) API() gpu.API {
return gpu.OpenGL{}
}
+1
View File
@@ -68,6 +68,7 @@ type Callbacks interface {
type Context interface {
API() gpu.API
RenderTarget() gpu.RenderTarget
Present() error
Refresh() error
Release()
+1 -1
View File
@@ -100,7 +100,7 @@ func (l *renderLoop) renderLoop(ctx wm.Context) error {
g.Collect(frame.viewport, frame.ops)
// Signal that we're done with the frame ops.
l.ack <- struct{}{}
res.err = g.Frame()
res.err = g.Frame(ctx.RenderTarget())
if res.err == nil {
res.err = ctx.Present()
}