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
+17 -2
View File
@@ -15,6 +15,19 @@ type API interface {
implementsAPI()
}
type RenderTarget interface {
ImplementsRenderTarget()
}
type OpenGLRenderTarget gl.Framebuffer
type Direct3D11RenderTarget struct {
// RenderTarget is a *ID3D11RenderTargetView.
RenderTarget unsafe.Pointer
// DepthStencilView is a *ID3D11DepthStencilView.
DepthStencilView unsafe.Pointer
}
type OpenGL struct {
// ES forces the use of ANGLE OpenGL ES libraries on macOS. It is
// ignored on all other platforms.
@@ -55,5 +68,7 @@ func NewDevice(api API) (Device, error) {
return nil, fmt.Errorf("driver: no driver available for the API %T", api)
}
func (OpenGL) implementsAPI() {}
func (Direct3D11) implementsAPI() {}
func (OpenGL) implementsAPI() {}
func (Direct3D11) implementsAPI() {}
func (OpenGLRenderTarget) ImplementsRenderTarget() {}
func (Direct3D11RenderTarget) ImplementsRenderTarget() {}
+2 -1
View File
@@ -12,7 +12,7 @@ import (
// APIs such as OpenGL, Direct3D useful for rendering Gio
// operations.
type Device interface {
BeginFrame(clear bool, viewport image.Point) Framebuffer
BeginFrame(target RenderTarget, clear bool, viewport image.Point) Framebuffer
EndFrame()
Caps() Caps
NewTimer() Timer
@@ -155,6 +155,7 @@ type Buffer interface {
}
type Framebuffer interface {
RenderTarget
Invalidate()
Release()
ReadPixels(src image.Rectangle, pixels []byte) error