[PATCH v2 weston 2/3] gl-renderer: try to create a GLES3 context

Arnaud Vrac rawoul at gmail.com
Mon Dec 11 12:18:22 UTC 2017


GL drivers might allow using GLES3 features even in GLES2 contexts, but
that's not always the case. To make sure we can use GLES3, first try to
create a GLES3 context and then fallback to GLES2 on failure.

The reported GL version is used to determine which GLES version is
actually available.

Signed-off-by: Arnaud Vrac <avrac at freebox.fr>
---
 libweston/gl-renderer.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/libweston/gl-renderer.c b/libweston/gl-renderer.c
index 38ae7d60..7ec97b95 100644
--- a/libweston/gl-renderer.c
+++ b/libweston/gl-renderer.c
@@ -3618,8 +3618,8 @@ gl_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface)
 	EGLConfig context_config;
 	EGLBoolean ret;
 
-	static const EGLint context_attribs[] = {
-		EGL_CONTEXT_CLIENT_VERSION, 2,
+	EGLint context_attribs[] = {
+		EGL_CONTEXT_CLIENT_VERSION, 0,
 		EGL_NONE
 	};
 
@@ -3634,12 +3634,22 @@ gl_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface)
 	if (gr->has_configless_context)
 		context_config = EGL_NO_CONFIG_KHR;
 
+	/* try to create an OpenGLES 3 context first */
+	context_attribs[1] = 3;
 	gr->egl_context = eglCreateContext(gr->egl_display, context_config,
 					   EGL_NO_CONTEXT, context_attribs);
 	if (gr->egl_context == NULL) {
-		weston_log("failed to create context\n");
-		gl_renderer_print_egl_error_state();
-		return -1;
+		/* and then fallback to OpenGLES 2 */
+		context_attribs[1] = 2;
+		gr->egl_context = eglCreateContext(gr->egl_display,
+						   context_config,
+						   EGL_NO_CONTEXT,
+						   context_attribs);
+		if (gr->egl_context == NULL) {
+			weston_log("failed to create context\n");
+			gl_renderer_print_egl_error_state();
+			return -1;
+		}
 	}
 
 	ret = eglMakeCurrent(gr->egl_display, egl_surface,
-- 
2.15.0



More information about the wayland-devel mailing list