Skip to content

Commit

Permalink
x/exp/shiny/driver/gldriver: allow ES2 on Linux and ES3 on Windows
Browse files Browse the repository at this point in the history
The previous check for GL_ES_2_0 was compile-time, which makes no sense.
The lack of support for OpenGL ES 2.0 contexts on Linux also makes no
sense as gldriver supports OpenGL ES 2.0 on other platforms.
  • Loading branch information
BenLubar committed Jul 2, 2021
1 parent fa9d1d1 commit 7efbff0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
Empty file modified shiny/driver/gldriver/egl.go
100755 → 100644
Empty file.
15 changes: 14 additions & 1 deletion shiny/driver/gldriver/win32.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func createEGLSurface(hwnd syscall.Handle, w *windowImpl) error {
}

contextAttribs := [...]eglInt{
_EGL_CONTEXT_CLIENT_VERSION, 2,
_EGL_CONTEXT_CLIENT_VERSION, 3,
_EGL_NONE,
}
context, _, _ := eglCreateContext.Call(
Expand All @@ -338,6 +338,19 @@ func createEGLSurface(hwnd syscall.Handle, w *windowImpl) error {
_EGL_NO_CONTEXT,
uintptr(unsafe.Pointer(&contextAttribs[0])),
)
if context == _EGL_NO_CONTEXT {
// Try again with OpenGL ES 2.0.
context2Attribs := [...]eglInt{
_EGL_CONTEXT_CLIENT_VERSION, 2,
_EGL_NONE,
}
context, _, _ = eglCreateContext.Call(
display,
uintptr(config),
_EGL_NO_CONTEXT,
uintptr(unsafe.Pointer(&context2Attribs[0])),
)
}
if context == _EGL_NO_CONTEXT {
return fmt.Errorf("eglCreateContext failed: %v", eglErr())
}
Expand Down
9 changes: 9 additions & 0 deletions shiny/driver/gldriver/x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ startDriver() {
EGL_NONE
};
e_ctx = eglCreateContext(e_dpy, e_config, EGL_NO_CONTEXT, ctx_attribs);
if (!e_ctx) {
// Try again with OpenGL ES 2.0.
static const EGLint ctx2_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};

e_ctx = eglCreateContext(e_dpy, e_config, EGL_NO_CONTEXT, ctx2_attribs);
}
if (!e_ctx) {
fprintf(stderr, "eglCreateContext failed: %s\n", eglGetErrorStr());
exit(1);
Expand Down
3 changes: 0 additions & 3 deletions shiny/driver/gldriver/x11.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ type uiClosure struct {
}

func main(f func(screen.Screen)) error {
if gl.Version() == "GL_ES_2_0" {
return errors.New("gldriver: ES 3 required on X11")
}
C.startDriver()
glctx, worker = gl.NewContext()

Expand Down

0 comments on commit 7efbff0

Please sign in to comment.