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
+15 -2
View File
@@ -212,12 +212,23 @@ func newOpenGLDevice(api driver.OpenGL) (driver.Device, error) {
return b, nil
}
func (b *Backend) BeginFrame(clear bool, viewport image.Point) driver.Framebuffer {
func (b *Backend) BeginFrame(target driver.RenderTarget, clear bool, viewport image.Point) driver.Framebuffer {
b.clear = clear
b.glstate = b.queryState()
b.savedState = b.glstate
b.state = state{}
renderFBO := b.glstate.drawFBO
var renderFBO gl.Framebuffer
if target != nil {
switch t := target.(type) {
case driver.OpenGLRenderTarget:
renderFBO = gl.Framebuffer(t)
case *gpuFramebuffer:
renderFBO = t.obj
default:
panic(fmt.Errorf("opengl: invalid render target type: %T", target))
}
}
b.glstate.bindFramebuffer(b.funcs, gl.FRAMEBUFFER, renderFBO)
if b.gles {
// If the output framebuffer is not in the sRGB colorspace already, emulate it.
var fbEncoding int
@@ -1244,6 +1255,8 @@ func (f *gpuFramebuffer) Release() {
}
}
func (f *gpuFramebuffer) ImplementsRenderTarget() {}
func toTexFilter(f driver.TextureFilter) int {
switch f {
case driver.FilterNearest: