forked from joejulian/gio
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:
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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)}
|
||||
}
|
||||
|
||||
@@ -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{}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ type Callbacks interface {
|
||||
|
||||
type Context interface {
|
||||
API() gpu.API
|
||||
RenderTarget() gpu.RenderTarget
|
||||
Present() error
|
||||
Refresh() error
|
||||
Release()
|
||||
|
||||
+1
-1
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user