mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
gpu: support forced OpenGL ES mode, for ANGLE on macOS
macOS is the only platform where desktop OpenGL is used. To support foreign ANGLE contexts add a setting to override Gio's selection of OpenGL implementation. The bulk of this change is making all function pointers per-context instead of global, and loading the OpenGL library dynamically. As a side effect we're closer to Gio tolerating a platform without any OpenGL implementation. For example, Apple has deprecated OpenGL and OpenGL ES on its platforms and may remove them in the future. Note that as a side-effect of this change, Gio needs Go 1.16 or newer to run on iOS. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -47,7 +47,7 @@ func newContext(w *window) (*context, error) {
|
|||||||
return nil, fmt.Errorf("failed to create EAGLContext")
|
return nil, fmt.Errorf("failed to create EAGLContext")
|
||||||
}
|
}
|
||||||
api := contextAPI()
|
api := contextAPI()
|
||||||
f, err := gl.NewFunctions(api.Context)
|
f, err := gl.NewFunctions(api.Context, api.ES)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,13 +9,16 @@ import (
|
|||||||
"gioui.org/internal/gl"
|
"gioui.org/internal/gl"
|
||||||
)
|
)
|
||||||
|
|
||||||
// See gpu/api.go for documentation for the API types
|
// See gpu/api.go for documentation for the API types.
|
||||||
|
|
||||||
type API interface {
|
type API interface {
|
||||||
implementsAPI()
|
implementsAPI()
|
||||||
}
|
}
|
||||||
|
|
||||||
type OpenGL struct {
|
type OpenGL struct {
|
||||||
|
// ES forces the use of ANGLE OpenGL ES libraries on macOS. It is
|
||||||
|
// ignored on all other platforms.
|
||||||
|
ES bool
|
||||||
// Context contains the WebGL context for WebAssembly platforms. It is
|
// Context contains the WebGL context for WebAssembly platforms. It is
|
||||||
// empty for all other platforms; an OpenGL context is assumed current when
|
// empty for all other platforms; an OpenGL context is assumed current when
|
||||||
// calling NewDevice.
|
// calling NewDevice.
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newOpenGLDevice(api driver.OpenGL) (driver.Device, error) {
|
func newOpenGLDevice(api driver.OpenGL) (driver.Device, error) {
|
||||||
f, err := gl.NewFunctions(api.Context)
|
f, err := gl.NewFunctions(api.Context, api.ES)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ type Functions struct {
|
|||||||
|
|
||||||
type Context js.Value
|
type Context js.Value
|
||||||
|
|
||||||
func NewFunctions(ctx Context) (*Functions, error) {
|
func NewFunctions(ctx Context, forceES bool) (*Functions, error) {
|
||||||
f := &Functions{
|
f := &Functions{
|
||||||
Ctx: js.Value(ctx),
|
Ctx: js.Value(ctx),
|
||||||
uint8Array: js.Global().Get("Uint8Array"),
|
uint8Array: js.Global().Get("Uint8Array"),
|
||||||
|
|||||||
+664
-216
File diff suppressed because it is too large
Load Diff
@@ -98,7 +98,7 @@ type Functions struct {
|
|||||||
|
|
||||||
type Context interface{}
|
type Context interface{}
|
||||||
|
|
||||||
func NewFunctions(ctx Context) (*Functions, error) {
|
func NewFunctions(ctx Context, forceES bool) (*Functions, error) {
|
||||||
if ctx != nil {
|
if ctx != nil {
|
||||||
panic("non-nil context")
|
panic("non-nil context")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user