mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
app/internal/egl: support surfaceless contexts
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+29
-13
@@ -26,17 +26,21 @@ type Context struct {
|
|||||||
|
|
||||||
type Driver interface {
|
type Driver interface {
|
||||||
EGLDisplay() NativeDisplayType
|
EGLDisplay() NativeDisplayType
|
||||||
EGLWindow(visID int) (NativeWindowType, int, int, error)
|
|
||||||
EGLDestroy()
|
EGLDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
type WindowDriver interface {
|
||||||
|
EGLWindow(visID int) (NativeWindowType, int, int, error)
|
||||||
NeedVSync() bool
|
NeedVSync() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type eglContext struct {
|
type eglContext struct {
|
||||||
disp _EGLDisplay
|
disp _EGLDisplay
|
||||||
config _EGLConfig
|
config _EGLConfig
|
||||||
ctx _EGLContext
|
ctx _EGLContext
|
||||||
visualID int
|
visualID int
|
||||||
srgb bool
|
srgb bool
|
||||||
|
surfaceless bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -106,6 +110,10 @@ func NewContext(d Driver) (*Context, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if _, windowed := d.(WindowDriver); !windowed && !eglCtx.surfaceless {
|
||||||
|
eglDestroyContext(eglCtx.disp, eglCtx.ctx)
|
||||||
|
return nil, errors.New("EGL_KHR_surfaceless_context not supported")
|
||||||
|
}
|
||||||
c := &Context{
|
c := &Context{
|
||||||
driver: d,
|
driver: d,
|
||||||
eglCtx: eglCtx,
|
eglCtx: eglCtx,
|
||||||
@@ -134,7 +142,14 @@ func (c *Context) destroySurface() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) MakeCurrent() error {
|
func (c *Context) MakeCurrent() error {
|
||||||
win, width, height, err := c.driver.EGLWindow(int(c.eglCtx.visualID))
|
wdriver, ok := c.driver.(WindowDriver)
|
||||||
|
if !ok {
|
||||||
|
if !eglMakeCurrent(c.eglCtx.disp, nilEGLSurface, nilEGLSurface, c.eglCtx.ctx) {
|
||||||
|
return fmt.Errorf("eglMakeCurrent error 0x%x", eglGetError())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
win, width, height, err := wdriver.EGLWindow(int(c.eglCtx.visualID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -163,7 +178,7 @@ func (c *Context) MakeCurrent() error {
|
|||||||
// eglSwapInterval 1 leads to erratic frame rates and unnecessary blocking.
|
// eglSwapInterval 1 leads to erratic frame rates and unnecessary blocking.
|
||||||
// We rely on platform specific frame rate limiting instead, except on Windows
|
// We rely on platform specific frame rate limiting instead, except on Windows
|
||||||
// and X11 where eglSwapInterval is all there is.
|
// and X11 where eglSwapInterval is all there is.
|
||||||
if c.driver.NeedVSync() {
|
if wdriver.NeedVSync() {
|
||||||
eglSwapInterval(c.eglCtx.disp, 1)
|
eglSwapInterval(c.eglCtx.disp, 1)
|
||||||
} else {
|
} else {
|
||||||
eglSwapInterval(c.eglCtx.disp, 0)
|
eglSwapInterval(c.eglCtx.disp, 0)
|
||||||
@@ -253,11 +268,12 @@ func createContext(disp NativeDisplayType) (*eglContext, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &eglContext{
|
return &eglContext{
|
||||||
disp: eglDisp,
|
disp: eglDisp,
|
||||||
config: _EGLConfig(eglCfg),
|
config: _EGLConfig(eglCfg),
|
||||||
ctx: _EGLContext(eglCtx),
|
ctx: _EGLContext(eglCtx),
|
||||||
visualID: int(visID),
|
visualID: int(visID),
|
||||||
srgb: srgb,
|
srgb: srgb,
|
||||||
|
surfaceless: hasExtension(exts, "EGL_KHR_surfaceless_context"),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user