mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
8999747ad2
This change implements a Vulkan port for the two renderers, old and compute. Run with GIORENDERER=forcecompute to test the compute renderer. To shake out bugs faster, it is also made the default on systems that support it. To disable Vulkan and force the use of OpenGL, use the `novulkan` tag: $ go run -tags novulkan gioui.org/example/kitchen Don't forget to file an issue describing the issue that prompted the use of the tag. Signed-off-by: Elias Naur <mail@eliasnaur.com>
48 lines
797 B
Go
48 lines
797 B
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package headless
|
|
|
|
import (
|
|
"errors"
|
|
"syscall/js"
|
|
|
|
"gioui.org/gpu"
|
|
"gioui.org/internal/gl"
|
|
)
|
|
|
|
type jsContext struct {
|
|
ctx js.Value
|
|
}
|
|
|
|
func init() {
|
|
newContextPrimary = func() (context, error) {
|
|
doc := js.Global().Get("document")
|
|
cnv := doc.Call("createElement", "canvas")
|
|
ctx := cnv.Call("getContext", "webgl2")
|
|
if ctx.IsNull() {
|
|
ctx = cnv.Call("getContext", "webgl")
|
|
}
|
|
if ctx.IsNull() {
|
|
return nil, errors.New("headless: webgl is not supported")
|
|
}
|
|
c := &jsContext{
|
|
ctx: ctx,
|
|
}
|
|
return c, nil
|
|
}
|
|
}
|
|
|
|
func (c *jsContext) API() gpu.API {
|
|
return gpu.OpenGL{Context: gl.Context(c.ctx)}
|
|
}
|
|
|
|
func (c *jsContext) Release() {
|
|
}
|
|
|
|
func (c *jsContext) ReleaseCurrent() {
|
|
}
|
|
|
|
func (c *jsContext) MakeCurrent() error {
|
|
return nil
|
|
}
|