mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 02:15:34 +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:
@@ -25,7 +25,7 @@ type Window struct {
|
||||
}
|
||||
|
||||
type context interface {
|
||||
Backend() (backend.Device, error)
|
||||
API() gpu.API
|
||||
MakeCurrent() error
|
||||
ReleaseCurrent()
|
||||
Release()
|
||||
@@ -42,7 +42,8 @@ func NewWindow(width, height int) (*Window, error) {
|
||||
ctx: ctx,
|
||||
}
|
||||
err = contextDo(ctx, func() error {
|
||||
dev, err := ctx.Backend()
|
||||
api := ctx.API()
|
||||
dev, err := backend.NewDevice(api)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -62,7 +63,7 @@ func NewWindow(width, height int) (*Window, error) {
|
||||
fboTex.Release()
|
||||
return err
|
||||
}
|
||||
gp, err := gpu.New(dev)
|
||||
gp, err := gpu.New(api)
|
||||
if err != nil {
|
||||
fbo.Release()
|
||||
fboTex.Release()
|
||||
|
||||
Reference in New Issue
Block a user