mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 08:55:35 +00:00
gpu,gpu/backend: implement generic backend.NewDevice
NewDevice creates a Device given an API, which is the necessary GPU resources for a backend. Convert gpu.New to take an API instead of a backend.Device directly. In turn, this frees us to later unexport the backend package along with the backend implementations (for now just gioui.org/gpu/gl for OpenGL). It also allows programs that embed Gio (such as gioui.org/example/glfw) to freely choose a backend, not just OpenGL. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+11
-4
@@ -28,6 +28,9 @@ import (
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/clip"
|
||||
|
||||
// Register backend.
|
||||
_ "gioui.org/gpu/gl"
|
||||
)
|
||||
|
||||
type GPU interface {
|
||||
@@ -380,14 +383,18 @@ const (
|
||||
materialTexture
|
||||
)
|
||||
|
||||
func New(ctx backend.Device) (GPU, error) {
|
||||
func New(api API) (GPU, error) {
|
||||
d, err := backend.NewDevice(api)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
forceCompute := os.Getenv("GIORENDERER") == "forcecompute"
|
||||
feats := ctx.Caps().Features
|
||||
feats := d.Caps().Features
|
||||
switch {
|
||||
case !forceCompute && feats.Has(backend.FeatureFloatRenderTargets):
|
||||
return newGPU(ctx)
|
||||
return newGPU(d)
|
||||
case feats.Has(backend.FeatureCompute):
|
||||
return newCompute(ctx)
|
||||
return newCompute(d)
|
||||
default:
|
||||
return nil, errors.New("gpu: no support for float render targets nor compute")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user