mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
8ff6546285
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>
39 lines
606 B
Go
39 lines
606 B
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package headless
|
|
|
|
import (
|
|
"unsafe"
|
|
|
|
"gioui.org/gpu"
|
|
"gioui.org/app/internal/d3d11"
|
|
)
|
|
|
|
type d3d11Context struct {
|
|
dev *d3d11.Device
|
|
}
|
|
|
|
func newContext() (context, error) {
|
|
dev, err := d3d11.NewDevice()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &d3d11Context{dev: dev}, nil
|
|
}
|
|
|
|
func (c *d3d11Context) API() gpu.API {
|
|
return gpu.Direct3D11{Device: unsafe.Pointer(c.dev.Handle)}
|
|
}
|
|
|
|
func (c *d3d11Context) MakeCurrent() error {
|
|
return nil
|
|
}
|
|
|
|
func (c *d3d11Context) ReleaseCurrent() {
|
|
}
|
|
|
|
func (c *d3d11Context) Release() {
|
|
c.dev.Release()
|
|
c.dev = nil
|
|
}
|