summaryrefslogtreecommitdiffstats
path: root/src/glsl/glsl_parser_extras.cpp
diff options
context:
space:
mode:
authorPaul Berry <[email protected]>2012-08-01 19:09:24 -0700
committerIan Romanick <[email protected]>2012-12-06 12:13:21 -0800
commit5d0fd3270f028cd93efa5301c998be034826a102 (patch)
tree5dc9af3eba73b093c388f91d68ff9d38e2ea1e2f /src/glsl/glsl_parser_extras.cpp
parentdc9f9d8e66ac3ec934a82d25da7b76902f775802 (diff)
glsl: Add GLSL version query functions.
With the advent of GLSL 3.00 ES, the version checks we perform in the GLSL compiler (to determine which language features are present) will become more complicated. To reduce the complexity, this patch adds functions check_version() and is_version() to _mesa_glsl_parse_state. These functions take two version numbers: a desktop GLSL version and a GLSL ES version, and return a boolean indicating whether the GLSL version being compiled is at least the required version. So, for example, is_version(130, 300) returns true if the GLSL version being compiled is at least desktop GLSL 1.30 or GLSL 3.00. The check_version() function additionally produces an error message if the version check fails, informing the user of which GLSL version(s) support the given feature. [v2, idr]: Add PRINTFLIKE annotation to the new method. The numbering of th parameters is correct because GCC is silly. [v3, idr]: Fix copy-and-paste error in the comment before _mesa_glsl_parse_state::is_version. Noticed by Ken. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Acked-by: Carl Worth <[email protected]>
Diffstat (limited to 'src/glsl/glsl_parser_extras.cpp')
-rw-r--r--src/glsl/glsl_parser_extras.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 3e192037e0d..14589b02005 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -123,6 +123,57 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
this->default_uniform_qualifier->flags.q.column_major = 1;
}
+/**
+ * Determine whether the current GLSL version is sufficiently high to support
+ * a certain feature, and generate an error message if it isn't.
+ *
+ * \param required_glsl_version and \c required_glsl_es_version are
+ * interpreted as they are in _mesa_glsl_parse_state::is_version().
+ *
+ * \param locp is the parser location where the error should be reported.
+ *
+ * \param fmt (and additional arguments) constitute a printf-style error
+ * message to report if the version check fails. Information about the
+ * current and required GLSL versions will be appended. So, for example, if
+ * the GLSL version being compiled is 1.20, and check_version(130, 300, locp,
+ * "foo unsupported") is called, the error message will be "foo unsupported in
+ * GLSL 1.20 (GLSL 1.30 or GLSL 3.00 ES required)".
+ */
+bool
+_mesa_glsl_parse_state::check_version(unsigned required_glsl_version,
+ unsigned required_glsl_es_version,
+ YYLTYPE *locp, const char *fmt, ...)
+{
+ if (this->is_version(required_glsl_version, required_glsl_es_version))
+ return true;
+
+ va_list args;
+ va_start(args, fmt);
+ char *problem = ralloc_vasprintf(ctx, fmt, args);
+ va_end(args);
+ const char *glsl_version_string
+ = glsl_compute_version_string(ctx, false, required_glsl_version);
+ const char *glsl_es_version_string
+ = glsl_compute_version_string(ctx, true, required_glsl_es_version);
+ const char *requirement_string = "";
+ if (required_glsl_version && required_glsl_es_version) {
+ requirement_string = ralloc_asprintf(ctx, " (%s or %s required)",
+ glsl_version_string,
+ glsl_es_version_string);
+ } else if (required_glsl_version) {
+ requirement_string = ralloc_asprintf(ctx, " (%s required)",
+ glsl_version_string);
+ } else if (required_glsl_es_version) {
+ requirement_string = ralloc_asprintf(ctx, " (%s required)",
+ glsl_es_version_string);
+ }
+ _mesa_glsl_error(locp, this, "%s in %s%s.",
+ problem, this->get_version_string(),
+ requirement_string);
+
+ return false;
+}
+
const char *
_mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target)
{