summaryrefslogtreecommitdiffstats
path: root/src/glsl/glsl_parser_extras.h
diff options
context:
space:
mode:
authorPaul Berry <stereotype441@gmail.com>2012-08-01 19:09:24 -0700
committerIan Romanick <ian.d.romanick@intel.com>2012-12-06 12:13:21 -0800
commit5d0fd3270f028cd93efa5301c998be034826a102 (patch)
tree5dc9af3eba73b093c388f91d68ff9d38e2ea1e2f /src/glsl/glsl_parser_extras.h
parentdc9f9d8e66ac3ec934a82d25da7b76902f775802 (diff)
downloadexternal_mesa3d-5d0fd3270f028cd93efa5301c998be034826a102.zip
external_mesa3d-5d0fd3270f028cd93efa5301c998be034826a102.tar.gz
external_mesa3d-5d0fd3270f028cd93efa5301c998be034826a102.tar.bz2
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 <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Acked-by: Carl Worth <cworth@cworth.org>
Diffstat (limited to 'src/glsl/glsl_parser_extras.h')
-rw-r--r--src/glsl/glsl_parser_extras.h45
1 files changed, 35 insertions, 10 deletions
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index 26fdee1..597b49e 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -59,6 +59,16 @@ struct glsl_switch_state {
const char *
glsl_compute_version_string(void *mem_ctx, bool is_es, unsigned version);
+typedef struct YYLTYPE {
+ int first_line;
+ int first_column;
+ int last_line;
+ int last_column;
+ unsigned source;
+} YYLTYPE;
+# define YYLTYPE_IS_DECLARED 1
+# define YYLTYPE_IS_TRIVIAL 1
+
struct _mesa_glsl_parse_state {
_mesa_glsl_parse_state(struct gl_context *_ctx, GLenum target,
void *mem_ctx);
@@ -90,6 +100,31 @@ struct _mesa_glsl_parse_state {
this->language_version);
}
+ /**
+ * Determine whether the current GLSL version is sufficiently high to
+ * support a certain feature.
+ *
+ * \param required_glsl_version is the desktop GLSL version that is
+ * required to support the feature, or 0 if no version of desktop GLSL
+ * supports the feature.
+ *
+ * \param required_glsl_es_version is the GLSL ES version that is required
+ * to support the feature, or 0 if no version of GLSL ES suports the
+ * feature.
+ */
+ bool is_version(unsigned required_glsl_version,
+ unsigned required_glsl_es_version)
+ {
+ unsigned required_version = this->es_shader ?
+ required_glsl_es_version : required_glsl_version;
+ return required_version != 0
+ && this->language_version >= required_version;
+ }
+
+ bool check_version(unsigned required_glsl_version,
+ unsigned required_glsl_es_version,
+ YYLTYPE *locp, const char *fmt, ...) PRINTFLIKE(5, 6);
+
struct gl_context *const ctx;
void *scanner;
exec_list translation_unit;
@@ -229,16 +264,6 @@ struct _mesa_glsl_parse_state {
unsigned num_builtins_to_link;
};
-typedef struct YYLTYPE {
- int first_line;
- int first_column;
- int last_line;
- int last_column;
- unsigned source;
-} YYLTYPE;
-# define YYLTYPE_IS_DECLARED 1
-# define YYLTYPE_IS_TRIVIAL 1
-
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do { \
if (N) \