From ff3195aadde95c8e89f77f389a7dfb418dd2426c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 20 Oct 2014 21:31:56 -0700 Subject: glamor: Compute GLSL version from GL_SHADING_LANGUAGE_VERSION (v3) Use code from Piglit project to compute GLSL version for either GL or GLES. The Piglit code was originally written by Chad Versace. v2: bail if the parse fails (requested by Eric Anholt) v3: Use version 1.20 for GLES until we fix our programs (Eric Anholt) Signed-off-by: Keith Packard Reviewed-by: Eric Anholt --- glamor/glamor.c | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/glamor/glamor.c b/glamor/glamor.c index 6f4f30927..9d40e3ce5 100644 --- a/glamor/glamor.c +++ b/glamor/glamor.c @@ -1,5 +1,5 @@ /* - * Copyright © 2008 Intel Corporation + * Copyright © 2008,2011 Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -23,7 +23,7 @@ * Authors: * Eric Anholt * Zhigang Gong - * + * Chad Versace */ /** @file glamor.c @@ -336,7 +336,11 @@ glamor_init(ScreenPtr screen, unsigned int flags) { glamor_screen_private *glamor_priv; int gl_version; + int glsl_major, glsl_minor; int max_viewport_size[2]; + const char *shading_version_string; + int shading_version_offset; + PictureScreenPtr ps = GetPictureScreenIfSet(screen); if (flags & ~GLAMOR_VALID_FLAGS) { @@ -380,14 +384,40 @@ glamor_init(ScreenPtr screen, unsigned int flags) gl_version = epoxy_gl_version(); - /* Would be nice to have a cleaner test for GLSL 1.30 support, - * but for now this should suffice - */ - if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP && gl_version >= 30) - glamor_priv->glsl_version = 130; - else - glamor_priv->glsl_version = 120; + shading_version_string = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION); + + if (!shading_version_string) { + LogMessage(X_WARNING, + "glamor%d: Failed to get GLSL version\n", + screen->myNum); + goto fail; + } + shading_version_offset = 0; + if (strncmp("OpenGL ES GLSL ES ", shading_version_string, 18) == 0) + shading_version_offset = 18; + + if (sscanf(shading_version_string + shading_version_offset, + "%i.%i", + &glsl_major, + &glsl_minor) != 2) { + LogMessage(X_WARNING, + "glamor%d: Failed to parse GLSL version string %s\n", + screen->myNum, shading_version_string); + goto fail; + } + glamor_priv->glsl_version = glsl_major * 100 + glsl_minor; + + if (glamor_priv->gl_flavor == GLAMOR_GL_ES2) { + /* Force us back to the base version of our programs on an ES + * context, anyway. Basically glamor only uses desktop 1.20 + * or 1.30 currently. 1.30's new features are also present in + * ES 3.0, but our glamor_program.c constructions use a lot of + * compatibility features (to reduce the diff between 1.20 and + * 1.30 programs). + */ + glamor_priv->glsl_version = 120; + } /* We'd like to require GL_ARB_map_buffer_range or * GL_OES_map_buffer_range, since it offers more information to -- cgit v1.2.3