[Mesa-dev] [PATCH 2/2] glcpp: Don't treat undefined macros as zero for GLES3

Carl Worth cworth at cworth.org
Thu Nov 22 08:57:52 PST 2012


The specification is clear that an undefined macro in an #if or #elif should
cause an error. This is distinct from the behavior required for recent desktop
OpenGL.

FIXME: This commit isn't compiling for me since I don't have any API_OPENGLES3
symbol in my environment. I'm seeking guidance on how to get such a sumbol or
otherwise what should be changed in this condition.
---
 src/glsl/glcpp/glcpp-parse.y |   16 +++++++++++++++-
 src/glsl/glcpp/glcpp.h       |    1 +
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index 38fe44a..70dec84 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -281,9 +281,21 @@ control_line:
 		if (parser->skip_stack == NULL ||
 		    parser->skip_stack->type == SKIP_NO_SKIP)
 		{
+			int undefined_macro_mode = UNDEFINED_MACRO_IS_ZERO;
+
+			/* Page 11 (page 17 of the PDF) of the OpenGL
+			 * ES Shading Language 3.00 spec says:
+			 *
+			 * "Undefined identifiers not consumed by the
+			 * defined operator do not default to '0'. Use
+			 * of such identifiers causes an error."
+			 */
+			if (parser->api == API_OPENGLES3)
+				undefined_macro_mode = UNDEFINED_MACRO_IS_IDENTIFIER;
+			
 			_glcpp_parser_expand_and_lex_from (parser,
 							   IF_EXPANDED, $2,
-							   UNDEFINED_MACRO_IS_ZERO);
+							   undefined_macro_mode);
 		}	
 		else
 		{
@@ -1151,6 +1163,8 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api)
 	parser->has_new_source_number = 0;
 	parser->new_source_number = 0;
 
+	parser->api = api;
+
 	/* Add pre-defined macros. */
 	if (extensions != NULL) {
 	   if (extensions->OES_EGL_image_external)
diff --git a/src/glsl/glcpp/glcpp.h b/src/glsl/glcpp/glcpp.h
index a459289..7a528dd 100644
--- a/src/glsl/glcpp/glcpp.h
+++ b/src/glsl/glcpp/glcpp.h
@@ -182,6 +182,7 @@ struct glcpp_parser {
 	int new_line_number;
 	bool has_new_source_number;
 	int new_source_number;
+	int api;
 };
 
 struct gl_extensions;
-- 
1.7.10



More information about the mesa-dev mailing list