[PATCH v3 weston 1/4] gl-renderer: save OpenGL version in renderer context

Arnaud Vrac rawoul at gmail.com
Wed Jan 17 18:36:32 UTC 2018


This will allow to make some assumptions in further patches when GLES3
is available.

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

diff --git a/libweston/gl-renderer.c b/libweston/gl-renderer.c
index abf556f0..c4b6af18 100644
--- a/libweston/gl-renderer.c
+++ b/libweston/gl-renderer.c
@@ -60,6 +60,12 @@
 #include "shared/timespec-util.h"
 #include "weston-egl-ext.h"
 
+#define GR_GL_VERSION(major, minor) \
+	(((uint32_t)(major) << 16) | (uint32_t)(minor))
+
+#define GR_GL_VERSION_INVALID \
+	GR_GL_VERSION(0, 0)
+
 struct gl_shader {
 	GLuint program;
 	GLuint vertex_shader, fragment_shader;
@@ -199,6 +205,8 @@ struct gl_renderer {
 
 	EGLSurface dummy_surface;
 
+	uint32_t gl_version;
+
 	struct wl_array vertices;
 	struct wl_array vtxcnt;
 
@@ -3586,6 +3594,22 @@ fan_debug_repaint_binding(struct weston_keyboard *keyboard,
 	weston_compositor_damage_all(compositor);
 }
 
+static uint32_t
+get_gl_version(void)
+{
+	const char *version;
+	int major, minor;
+
+	version = (const char *) glGetString(GL_VERSION);
+	if (version &&
+	    (sscanf(version, "%d.%d", &major, &minor) == 2 ||
+	     sscanf(version, "OpenGL ES %d.%d", &major, &minor) == 2)) {
+		return GR_GL_VERSION(major, minor);
+	}
+
+	return GR_GL_VERSION_INVALID;
+}
+
 static int
 gl_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface)
 {
@@ -3626,6 +3650,13 @@ gl_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface)
 		return -1;
 	}
 
+	gr->gl_version = get_gl_version();
+	if (gr->gl_version == GR_GL_VERSION_INVALID) {
+		weston_log("warning: failed to detect GLES version, "
+			   "defaulting to 2.0.\n");
+		gr->gl_version = GR_GL_VERSION(2, 0);
+	}
+
 	log_egl_gl_info(gr->egl_display);
 
 	gr->image_target_texture_2d =
-- 
2.15.1



More information about the wayland-devel mailing list