From cacf23d832a26e35851c9cc666304ac72cf8fe34 Mon Sep 17 00:00:00 2001
From: marha <marha@users.sourceforge.net>
Date: Sat, 29 Jan 2011 18:43:24 +0000
Subject: libXext libfontenc libXau libX11 libXinerama mesa libXdmcp git update
 28 jan 2011

---
 mesalib/Makefile                                   |    4 +-
 mesalib/docs/relnotes-7.11.html                    |    6 +-
 mesalib/src/glsl/glcpp/README                      |   87 +-
 mesalib/src/glsl/glcpp/glcpp-parse.c               | 8432 ++++++++++----------
 mesalib/src/glsl/glcpp/glcpp-parse.y               | 3780 ++++-----
 mesalib/src/mapi/glapi/Makefile                    |  144 +-
 mesalib/src/mesa/main/extensions.c                 | 1830 ++---
 mesalib/src/mesa/main/fbobject.c                   | 4973 ++++++------
 .../src/mesa/state_tracker/st_atom_pixeltransfer.c |    2 +-
 mesalib/src/mesa/state_tracker/st_cb_bitmap.c      |    4 +-
 mesalib/src/mesa/state_tracker/st_cb_drawpixels.c  |    2 +-
 mesalib/src/mesa/state_tracker/st_cb_texture.c     | 4054 +++++-----
 mesalib/src/mesa/state_tracker/st_gen_mipmap.c     |    1 +
 mesalib/src/mesa/state_tracker/st_texture.c        |   94 +-
 mesalib/src/mesa/state_tracker/st_texture.h        |  456 +-
 15 files changed, 11984 insertions(+), 11885 deletions(-)

(limited to 'mesalib')

diff --git a/mesalib/Makefile b/mesalib/Makefile
index 2e4875bca..726dd5554 100644
--- a/mesalib/Makefile
+++ b/mesalib/Makefile
@@ -232,6 +232,7 @@ MAIN_FILES = \
 	$(DIRECTORY)/src/glsl/README					\
 	$(DIRECTORY)/src/glsl/glcpp/*.[chly]				\
 	$(DIRECTORY)/src/glsl/glcpp/README				\
+	$(DIRECTORY)/src/glsl/builtins					\
 	$(DIRECTORY)/src/Makefile					\
 	$(DIRECTORY)/src/mesa/Makefile*					\
 	$(DIRECTORY)/src/mesa/sources.mak				\
@@ -283,8 +284,7 @@ MAIN_FILES = \
 	$(DIRECTORY)/src/mesa/x86/*.S					\
 	$(DIRECTORY)/src/mesa/x86/rtasm/*.[ch]				\
 	$(DIRECTORY)/src/mesa/x86-64/*.[chS]				\
-	$(DIRECTORY)/src/mesa/x86-64/Makefile				\
-	$(DIRECTORY)/windows/VC8/
+	$(DIRECTORY)/src/mesa/x86-64/Makefile
 
 MAPI_FILES = \
 	$(DIRECTORY)/include/GLES/*.h					\
diff --git a/mesalib/docs/relnotes-7.11.html b/mesalib/docs/relnotes-7.11.html
index 6393f6270..8bc3e2997 100644
--- a/mesalib/docs/relnotes-7.11.html
+++ b/mesalib/docs/relnotes-7.11.html
@@ -49,8 +49,10 @@ tbd
 
 
 <h2>Changes</h2>
-
-<p>tbd</p>
+<ul>
+<li>The Windows MSVC project files have been removed.  They haven't been maintained
+in quite a while.  Building with SCons is an alterantive.
+</ul>
 
 
 </body>
diff --git a/mesalib/src/glsl/glcpp/README b/mesalib/src/glsl/glcpp/README
index 9cc00e927..735b27d44 100644
--- a/mesalib/src/glsl/glcpp/README
+++ b/mesalib/src/glsl/glcpp/README
@@ -1,55 +1,32 @@
-glcpp -- GLSL "C" preprocessor
-
-This is a simple preprocessor designed to provide the preprocessing
-needs of the GLSL language. The requirements for this preprocessor are
-specified in the GLSL 1.30 specification availble from:
-
-http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.30.10.pdf
-
-This specification is not precise on some semantics, (for example,
-#define and #if), defining these merely "as is standard for C++
-preprocessors". To fill in these details, I've been using a draft of
-the C99 standard as available from:
-
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
-
-Any downstream compiler accepting output from glcpp should be prepared
-to encounter and deal with the following preprocessor macros:
-
-	#line
-	#pragma
-	#extension
-
-All other macros will be handles according to the GLSL specification
-and will not appear in the output.
-
-Known limitations
------------------
-The __LINE__ and __FILE__ macros are not yet supported.
-
-A file that ends with a function-like macro name as the last
-non-whitespace token will result in a parse error, (where it should be
-passed through as is).
-
-Known deviations from the specification
----------------------------------------
-As mentoned above, the GLSL specification (as of 1.30.10) is fairly
-vague on some aspects of the preprocessor, and we've been using C99 to
-fill in details. Here is a list of cases where we have deviated from
-the behavior specified in C99 to obtain better compatibility with
-other GLSL implementations:
-
-  * Redefining a macro with a different value
-
-    C89 says that a macro "may be redefined ... provided that the
-    second definition [is equivalent]" (Section 3.8.3 Macro
-    Replacement/constraints)
-
-    C99 is even more explicit, saying tthat a macro "shall not be
-    redefined by another #define preprocessing directive unless the
-    second definition [is equivalent]" (Section 6.10.3 Macro
-    Replacement/Constraints)
-
-    In spite of this, glcpp emits a warning rather than an error for
-    non-equivalent redefinition of macros since this matches the
-    behavior of other, widely-used implementations.
+glcpp -- GLSL "C" preprocessor
+
+This is a simple preprocessor designed to provide the preprocessing
+needs of the GLSL language. The requirements for this preprocessor are
+specified in the GLSL 1.30 specification availble from:
+
+http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.30.10.pdf
+
+This specification is not precise on some semantics, (for example,
+#define and #if), defining these merely "as is standard for C++
+preprocessors". To fill in these details, I've been using a draft of
+the C99 standard as available from:
+
+http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
+
+Any downstream compiler accepting output from glcpp should be prepared
+to encounter and deal with the following preprocessor macros:
+
+	#line
+	#pragma
+	#extension
+
+All other macros will be handles according to the GLSL specification
+and will not appear in the output.
+
+Known limitations
+-----------------
+The __LINE__ and __FILE__ macros are not yet supported.
+
+A file that ends with a function-like macro name as the last
+non-whitespace token will result in a parse error, (where it should be
+passed through as is).
\ No newline at end of file
diff --git a/mesalib/src/glsl/glcpp/glcpp-parse.c b/mesalib/src/glsl/glcpp/glcpp-parse.c
index 2bf96e035..e46fc91e1 100644
--- a/mesalib/src/glsl/glcpp/glcpp-parse.c
+++ b/mesalib/src/glsl/glcpp/glcpp-parse.c
@@ -1,4216 +1,4216 @@
-/* A Bison parser, made by GNU Bison 2.4.3.  */
-
-/* Skeleton implementation for Bison's Yacc-like parsers in C
-   
-      Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-   2009, 2010 Free Software Foundation, Inc.
-   
-   This program is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation, either version 3 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-/* As a special exception, you may create a larger work that contains
-   part or all of the Bison parser skeleton and distribute that work
-   under terms of your choice, so long as that work isn't itself a
-   parser generator using the skeleton or a modified version thereof
-   as a parser skeleton.  Alternatively, if you modify or redistribute
-   the parser skeleton itself, you may (at your option) remove this
-   special exception, which will cause the skeleton and the resulting
-   Bison output files to be licensed under the GNU General Public
-   License without this special exception.
-   
-   This special exception was added by the Free Software Foundation in
-   version 2.2 of Bison.  */
-
-/* C LALR(1) parser skeleton written by Richard Stallman, by
-   simplifying the original so-called "semantic" parser.  */
-
-/* All symbols defined below should begin with yy or YY, to avoid
-   infringing on user name space.  This should be done even for local
-   variables, as they might otherwise be expanded by user macros.
-   There are some unavoidable exceptions within include files to
-   define necessary library symbols; they are noted "INFRINGES ON
-   USER NAME SPACE" below.  */
-
-/* Identify Bison output.  */
-#define YYBISON 1
-
-/* Bison version.  */
-#define YYBISON_VERSION "2.4.3"
-
-/* Skeleton name.  */
-#define YYSKELETON_NAME "yacc.c"
-
-/* Pure parsers.  */
-#define YYPURE 1
-
-/* Push parsers.  */
-#define YYPUSH 0
-
-/* Pull parsers.  */
-#define YYPULL 1
-
-/* Using locations.  */
-#define YYLSP_NEEDED 1
-
-
-
-/* Copy the first part of user declarations.  */
-
-/* Line 189 of yacc.c  */
-#line 1 "glcpp/glcpp-parse.y"
-
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <inttypes.h>
-
-#include "glcpp.h"
-#include "main/core.h" /* for struct gl_extensions */
-#include "main/mtypes.h" /* for gl_api enum */
-
-#define glcpp_print(stream, str) stream = talloc_strdup_append(stream, str)
-#define glcpp_printf(stream, fmt, args, ...) \
-	stream = talloc_asprintf_append(stream, fmt, args)
-
-static void
-yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
-
-static void
-_define_object_macro (glcpp_parser_t *parser,
-		      YYLTYPE *loc,
-		      const char *macro,
-		      token_list_t *replacements);
-
-static void
-_define_function_macro (glcpp_parser_t *parser,
-			YYLTYPE *loc,
-			const char *macro,
-			string_list_t *parameters,
-			token_list_t *replacements);
-
-static string_list_t *
-_string_list_create (void *ctx);
-
-static void
-_string_list_append_item (string_list_t *list, const char *str);
-
-static int
-_string_list_contains (string_list_t *list, const char *member, int *index);
-
-static int
-_string_list_length (string_list_t *list);
-
-static int
-_string_list_equal (string_list_t *a, string_list_t *b);
-
-static argument_list_t *
-_argument_list_create (void *ctx);
-
-static void
-_argument_list_append (argument_list_t *list, token_list_t *argument);
-
-static int
-_argument_list_length (argument_list_t *list);
-
-static token_list_t *
-_argument_list_member_at (argument_list_t *list, int index);
-
-/* Note: This function talloc_steal()s the str pointer. */
-static token_t *
-_token_create_str (void *ctx, int type, char *str);
-
-static token_t *
-_token_create_ival (void *ctx, int type, int ival);
-
-static token_list_t *
-_token_list_create (void *ctx);
-
-/* Note: This function calls talloc_steal on token. */
-static void
-_token_list_append (token_list_t *list, token_t *token);
-
-static void
-_token_list_append_list (token_list_t *list, token_list_t *tail);
-
-static int
-_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b);
-
-static active_list_t *
-_active_list_push (active_list_t *list,
-		   const char *identifier,
-		   token_node_t *marker);
-
-static active_list_t *
-_active_list_pop (active_list_t *list);
-
-int
-_active_list_contains (active_list_t *list, const char *identifier);
-
-static void
-_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list);
-
-static void
-_glcpp_parser_expand_token_list (glcpp_parser_t *parser,
-				 token_list_t *list);
-
-static void
-_glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
-					 token_list_t *list);
-
-static void
-_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
-				  int condition);
-
-static void
-_glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
-				    const char *type, int condition);
-
-static void
-_glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc);
-
-#define yylex glcpp_parser_lex
-
-static int
-glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser);
-
-static void
-glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list);
-
-static void
-add_builtin_define(glcpp_parser_t *parser, const char *name, int value);
-
-
-
-/* Line 189 of yacc.c  */
-#line 220 "glcpp/glcpp-parse.c"
-
-/* Enabling traces.  */
-#ifndef YYDEBUG
-# define YYDEBUG 0
-#endif
-
-/* Enabling verbose error messages.  */
-#ifdef YYERROR_VERBOSE
-# undef YYERROR_VERBOSE
-# define YYERROR_VERBOSE 1
-#else
-# define YYERROR_VERBOSE 1
-#endif
-
-/* Enabling the token table.  */
-#ifndef YYTOKEN_TABLE
-# define YYTOKEN_TABLE 0
-#endif
-
-
-/* Tokens.  */
-#ifndef YYTOKENTYPE
-# define YYTOKENTYPE
-   /* Put the tokens into the symbol table, so that GDB and other debuggers
-      know about them.  */
-   enum yytokentype {
-     COMMA_FINAL = 258,
-     DEFINED = 259,
-     ELIF_EXPANDED = 260,
-     HASH = 261,
-     HASH_DEFINE_FUNC = 262,
-     HASH_DEFINE_OBJ = 263,
-     HASH_ELIF = 264,
-     HASH_ELSE = 265,
-     HASH_ENDIF = 266,
-     HASH_IF = 267,
-     HASH_IFDEF = 268,
-     HASH_IFNDEF = 269,
-     HASH_UNDEF = 270,
-     HASH_VERSION = 271,
-     IDENTIFIER = 272,
-     IF_EXPANDED = 273,
-     INTEGER = 274,
-     INTEGER_STRING = 275,
-     NEWLINE = 276,
-     OTHER = 277,
-     PLACEHOLDER = 278,
-     SPACE = 279,
-     PASTE = 280,
-     OR = 281,
-     AND = 282,
-     NOT_EQUAL = 283,
-     EQUAL = 284,
-     GREATER_OR_EQUAL = 285,
-     LESS_OR_EQUAL = 286,
-     RIGHT_SHIFT = 287,
-     LEFT_SHIFT = 288,
-     UNARY = 289
-   };
-#endif
-
-
-
-#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
-
-# define yystype YYSTYPE /* obsolescent; will be withdrawn */
-# define YYSTYPE_IS_DECLARED 1
-#endif
-
-#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
-typedef struct YYLTYPE
-{
-  int first_line;
-  int first_column;
-  int last_line;
-  int last_column;
-} YYLTYPE;
-# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
-# define YYLTYPE_IS_DECLARED 1
-# define YYLTYPE_IS_TRIVIAL 1
-#endif
-
-
-/* Copy the second part of user declarations.  */
-
-
-/* Line 264 of yacc.c  */
-#line 308 "glcpp/glcpp-parse.c"
-
-#ifdef short
-# undef short
-#endif
-
-#ifdef YYTYPE_UINT8
-typedef YYTYPE_UINT8 yytype_uint8;
-#else
-typedef unsigned char yytype_uint8;
-#endif
-
-#ifdef YYTYPE_INT8
-typedef YYTYPE_INT8 yytype_int8;
-#elif (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-typedef signed char yytype_int8;
-#else
-typedef short int yytype_int8;
-#endif
-
-#ifdef YYTYPE_UINT16
-typedef YYTYPE_UINT16 yytype_uint16;
-#else
-typedef unsigned short int yytype_uint16;
-#endif
-
-#ifdef YYTYPE_INT16
-typedef YYTYPE_INT16 yytype_int16;
-#else
-typedef short int yytype_int16;
-#endif
-
-#ifndef YYSIZE_T
-# ifdef __SIZE_TYPE__
-#  define YYSIZE_T __SIZE_TYPE__
-# elif defined size_t
-#  define YYSIZE_T size_t
-# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
-#  define YYSIZE_T size_t
-# else
-#  define YYSIZE_T unsigned int
-# endif
-#endif
-
-#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
-
-#ifndef YY_
-# if defined YYENABLE_NLS && YYENABLE_NLS
-#  if ENABLE_NLS
-#   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
-#   define YY_(msgid) dgettext ("bison-runtime", msgid)
-#  endif
-# endif
-# ifndef YY_
-#  define YY_(msgid) msgid
-# endif
-#endif
-
-/* Suppress unused-variable warnings by "using" E.  */
-#if ! defined lint || defined __GNUC__
-# define YYUSE(e) ((void) (e))
-#else
-# define YYUSE(e) /* empty */
-#endif
-
-/* Identity function, used to suppress warnings about constant conditions.  */
-#ifndef lint
-# define YYID(n) (n)
-#else
-#if (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-static int
-YYID (int yyi)
-#else
-static int
-YYID (yyi)
-    int yyi;
-#endif
-{
-  return yyi;
-}
-#endif
-
-#if ! defined yyoverflow || YYERROR_VERBOSE
-
-/* The parser invokes alloca or malloc; define the necessary symbols.  */
-
-# ifdef YYSTACK_USE_ALLOCA
-#  if YYSTACK_USE_ALLOCA
-#   ifdef __GNUC__
-#    define YYSTACK_ALLOC __builtin_alloca
-#   elif defined __BUILTIN_VA_ARG_INCR
-#    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
-#   elif defined _AIX
-#    define YYSTACK_ALLOC __alloca
-#   elif defined _MSC_VER
-#    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
-#    define alloca _alloca
-#   else
-#    define YYSTACK_ALLOC alloca
-#    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-#     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
-#     ifndef _STDLIB_H
-#      define _STDLIB_H 1
-#     endif
-#    endif
-#   endif
-#  endif
-# endif
-
-# ifdef YYSTACK_ALLOC
-   /* Pacify GCC's `empty if-body' warning.  */
-#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
-#  ifndef YYSTACK_ALLOC_MAXIMUM
-    /* The OS might guarantee only one guard page at the bottom of the stack,
-       and a page size can be as small as 4096 bytes.  So we cannot safely
-       invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
-       to allow for a few compiler-allocated temporary stack slots.  */
-#   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
-#  endif
-# else
-#  define YYSTACK_ALLOC YYMALLOC
-#  define YYSTACK_FREE YYFREE
-#  ifndef YYSTACK_ALLOC_MAXIMUM
-#   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
-#  endif
-#  if (defined __cplusplus && ! defined _STDLIB_H \
-       && ! ((defined YYMALLOC || defined malloc) \
-	     && (defined YYFREE || defined free)))
-#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
-#   ifndef _STDLIB_H
-#    define _STDLIB_H 1
-#   endif
-#  endif
-#  ifndef YYMALLOC
-#   define YYMALLOC malloc
-#   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
-#   endif
-#  endif
-#  ifndef YYFREE
-#   define YYFREE free
-#   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-void free (void *); /* INFRINGES ON USER NAME SPACE */
-#   endif
-#  endif
-# endif
-#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
-
-
-#if (! defined yyoverflow \
-     && (! defined __cplusplus \
-	 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
-	     && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
-
-/* A type that is properly aligned for any stack member.  */
-union yyalloc
-{
-  yytype_int16 yyss_alloc;
-  YYSTYPE yyvs_alloc;
-  YYLTYPE yyls_alloc;
-};
-
-/* The size of the maximum gap between one aligned stack and the next.  */
-# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
-
-/* The size of an array large to enough to hold all stacks, each with
-   N elements.  */
-# define YYSTACK_BYTES(N) \
-     ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
-      + 2 * YYSTACK_GAP_MAXIMUM)
-
-/* Copy COUNT objects from FROM to TO.  The source and destination do
-   not overlap.  */
-# ifndef YYCOPY
-#  if defined __GNUC__ && 1 < __GNUC__
-#   define YYCOPY(To, From, Count) \
-      __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
-#  else
-#   define YYCOPY(To, From, Count)		\
-      do					\
-	{					\
-	  YYSIZE_T yyi;				\
-	  for (yyi = 0; yyi < (Count); yyi++)	\
-	    (To)[yyi] = (From)[yyi];		\
-	}					\
-      while (YYID (0))
-#  endif
-# endif
-
-/* Relocate STACK from its old location to the new one.  The
-   local variables YYSIZE and YYSTACKSIZE give the old and new number of
-   elements in the stack, and YYPTR gives the new location of the
-   stack.  Advance YYPTR to a properly aligned location for the next
-   stack.  */
-# define YYSTACK_RELOCATE(Stack_alloc, Stack)				\
-    do									\
-      {									\
-	YYSIZE_T yynewbytes;						\
-	YYCOPY (&yyptr->Stack_alloc, Stack, yysize);			\
-	Stack = &yyptr->Stack_alloc;					\
-	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
-	yyptr += yynewbytes / sizeof (*yyptr);				\
-      }									\
-    while (YYID (0))
-
-#endif
-
-/* YYFINAL -- State number of the termination state.  */
-#define YYFINAL  2
-/* YYLAST -- Last index in YYTABLE.  */
-#define YYLAST   606
-
-/* YYNTOKENS -- Number of terminals.  */
-#define YYNTOKENS  57
-/* YYNNTS -- Number of nonterminals.  */
-#define YYNNTS  17
-/* YYNRULES -- Number of rules.  */
-#define YYNRULES  101
-/* YYNRULES -- Number of states.  */
-#define YYNSTATES  162
-
-/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
-#define YYUNDEFTOK  2
-#define YYMAXUTOK   289
-
-#define YYTRANSLATE(YYX)						\
-  ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
-
-/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
-static const yytype_uint8 yytranslate[] =
-{
-       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,    47,     2,     2,     2,    43,    30,     2,
-      45,    46,    41,    39,    49,    40,    54,    42,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,    55,
-      33,    56,    34,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,    50,     2,    51,    29,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,    52,    28,    53,    48,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
-       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
-      15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
-      25,    26,    27,    31,    32,    35,    36,    37,    38,    44
-};
-
-#if YYDEBUG
-/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
-   YYRHS.  */
-static const yytype_uint16 yyprhs[] =
-{
-       0,     0,     3,     4,     7,     9,    11,    13,    16,    20,
-      24,    29,    36,    44,    48,    52,    55,    60,    65,    69,
-      72,    75,    78,    82,    85,    87,    89,    91,    95,    99,
-     103,   107,   111,   115,   119,   123,   127,   131,   135,   139,
-     143,   147,   151,   155,   159,   163,   166,   169,   172,   175,
-     179,   181,   185,   187,   190,   193,   194,   196,   197,   199,
-     202,   207,   209,   211,   214,   216,   219,   221,   223,   225,
-     227,   229,   231,   233,   235,   237,   239,   241,   243,   245,
-     247,   249,   251,   253,   255,   257,   259,   261,   263,   265,
-     267,   269,   271,   273,   275,   277,   279,   281,   283,   285,
-     287,   289
-};
-
-/* YYRHS -- A `-1'-separated list of the rules' RHS.  */
-static const yytype_int8 yyrhs[] =
-{
-      58,     0,    -1,    -1,    58,    59,    -1,    61,    -1,    65,
-      -1,    60,    -1,     6,    66,    -1,    18,    63,    21,    -1,
-       5,    63,    21,    -1,     8,    17,    67,    21,    -1,     7,
-      17,    45,    46,    67,    21,    -1,     7,    17,    45,    64,
-      46,    67,    21,    -1,    15,    17,    21,    -1,    12,    70,
-      21,    -1,    12,    21,    -1,    13,    17,    68,    21,    -1,
-      14,    17,    68,    21,    -1,     9,    70,    21,    -1,     9,
-      21,    -1,    10,    21,    -1,    11,    21,    -1,    16,    62,
-      21,    -1,     6,    21,    -1,    20,    -1,    19,    -1,    62,
-      -1,    63,    26,    63,    -1,    63,    27,    63,    -1,    63,
-      28,    63,    -1,    63,    29,    63,    -1,    63,    30,    63,
-      -1,    63,    31,    63,    -1,    63,    32,    63,    -1,    63,
-      35,    63,    -1,    63,    36,    63,    -1,    63,    34,    63,
-      -1,    63,    33,    63,    -1,    63,    37,    63,    -1,    63,
-      38,    63,    -1,    63,    40,    63,    -1,    63,    39,    63,
-      -1,    63,    43,    63,    -1,    63,    42,    63,    -1,    63,
-      41,    63,    -1,    47,    63,    -1,    48,    63,    -1,    40,
-      63,    -1,    39,    63,    -1,    45,    63,    46,    -1,    17,
-      -1,    64,    49,    17,    -1,    21,    -1,    71,    21,    -1,
-      71,    21,    -1,    -1,    71,    -1,    -1,    71,    -1,     4,
-      17,    -1,     4,    45,    17,    46,    -1,    72,    -1,    69,
-      -1,    70,    69,    -1,    72,    -1,    71,    72,    -1,    17,
-      -1,    20,    -1,    73,    -1,    22,    -1,    24,    -1,    50,
-      -1,    51,    -1,    45,    -1,    46,    -1,    52,    -1,    53,
-      -1,    54,    -1,    30,    -1,    41,    -1,    39,    -1,    40,
-      -1,    48,    -1,    47,    -1,    42,    -1,    43,    -1,    38,
-      -1,    37,    -1,    33,    -1,    34,    -1,    36,    -1,    35,
-      -1,    32,    -1,    31,    -1,    29,    -1,    28,    -1,    27,
-      -1,    26,    -1,    55,    -1,    49,    -1,    56,    -1,    25,
-      -1
-};
-
-/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
-static const yytype_uint16 yyrline[] =
-{
-       0,   185,   185,   187,   191,   194,   199,   200,   204,   207,
-     213,   216,   219,   222,   230,   249,   259,   264,   269,   288,
-     303,   306,   309,   330,   334,   343,   348,   349,   352,   355,
-     358,   361,   364,   367,   370,   373,   376,   379,   382,   385,
-     388,   391,   394,   397,   405,   408,   411,   414,   417,   420,
-     426,   431,   439,   440,   444,   450,   451,   454,   456,   463,
-     467,   471,   476,   480,   487,   492,   499,   503,   507,   511,
-     515,   522,   523,   524,   525,   526,   527,   528,   529,   530,
-     531,   532,   533,   534,   535,   536,   537,   538,   539,   540,
-     541,   542,   543,   544,   545,   546,   547,   548,   549,   550,
-     551,   552
-};
-#endif
-
-#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
-/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
-   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
-static const char *const yytname[] =
-{
-  "$end", "error", "$undefined", "COMMA_FINAL", "DEFINED",
-  "ELIF_EXPANDED", "HASH", "HASH_DEFINE_FUNC", "HASH_DEFINE_OBJ",
-  "HASH_ELIF", "HASH_ELSE", "HASH_ENDIF", "HASH_IF", "HASH_IFDEF",
-  "HASH_IFNDEF", "HASH_UNDEF", "HASH_VERSION", "IDENTIFIER", "IF_EXPANDED",
-  "INTEGER", "INTEGER_STRING", "NEWLINE", "OTHER", "PLACEHOLDER", "SPACE",
-  "PASTE", "OR", "AND", "'|'", "'^'", "'&'", "NOT_EQUAL", "EQUAL", "'<'",
-  "'>'", "GREATER_OR_EQUAL", "LESS_OR_EQUAL", "RIGHT_SHIFT", "LEFT_SHIFT",
-  "'+'", "'-'", "'*'", "'/'", "'%'", "UNARY", "'('", "')'", "'!'", "'~'",
-  "','", "'['", "']'", "'{'", "'}'", "'.'", "';'", "'='", "$accept",
-  "input", "line", "expanded_line", "control_line", "integer_constant",
-  "expression", "identifier_list", "text_line", "non_directive",
-  "replacement_list", "junk", "conditional_token", "conditional_tokens",
-  "pp_tokens", "preprocessing_token", "operator", 0
-};
-#endif
-
-# ifdef YYPRINT
-/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
-   token YYLEX-NUM.  */
-static const yytype_uint16 yytoknum[] =
-{
-       0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
-     265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
-     275,   276,   277,   278,   279,   280,   281,   282,   124,    94,
-      38,   283,   284,    60,    62,   285,   286,   287,   288,    43,
-      45,    42,    47,    37,   289,    40,    41,    33,   126,    44,
-      91,    93,   123,   125,    46,    59,    61
-};
-# endif
-
-/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
-static const yytype_uint8 yyr1[] =
-{
-       0,    57,    58,    58,    59,    59,    59,    59,    60,    60,
-      61,    61,    61,    61,    61,    61,    61,    61,    61,    61,
-      61,    61,    61,    61,    62,    62,    63,    63,    63,    63,
-      63,    63,    63,    63,    63,    63,    63,    63,    63,    63,
-      63,    63,    63,    63,    63,    63,    63,    63,    63,    63,
-      64,    64,    65,    65,    66,    67,    67,    68,    68,    69,
-      69,    69,    70,    70,    71,    71,    72,    72,    72,    72,
-      72,    73,    73,    73,    73,    73,    73,    73,    73,    73,
-      73,    73,    73,    73,    73,    73,    73,    73,    73,    73,
-      73,    73,    73,    73,    73,    73,    73,    73,    73,    73,
-      73,    73
-};
-
-/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
-static const yytype_uint8 yyr2[] =
-{
-       0,     2,     0,     2,     1,     1,     1,     2,     3,     3,
-       4,     6,     7,     3,     3,     2,     4,     4,     3,     2,
-       2,     2,     3,     2,     1,     1,     1,     3,     3,     3,
-       3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
-       3,     3,     3,     3,     3,     2,     2,     2,     2,     3,
-       1,     3,     1,     2,     2,     0,     1,     0,     1,     2,
-       4,     1,     1,     2,     1,     2,     1,     1,     1,     1,
-       1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
-       1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
-       1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
-       1,     1
-};
-
-/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
-   STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
-   means the default is an error.  */
-static const yytype_uint8 yydefact[] =
-{
-       2,     0,     1,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,    66,     0,    67,    52,    69,
-      70,   101,    97,    96,    95,    94,    78,    93,    92,    88,
-      89,    91,    90,    87,    86,    80,    81,    79,    84,    85,
-      73,    74,    83,    82,    99,    71,    72,    75,    76,    77,
-      98,   100,     3,     6,     4,     5,     0,    64,    68,    25,
-      24,     0,     0,     0,     0,     0,    26,     0,    23,     7,
-       0,     0,    55,     0,    19,    62,     0,    61,    20,    21,
-      15,     0,    57,    57,     0,     0,     0,    53,    65,    48,
-      47,     0,    45,    46,     9,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,    54,     0,     0,    56,    59,     0,    18,
-      63,    14,     0,    58,     0,    13,    22,     8,    49,    27,
-      28,    29,    30,    31,    32,    33,    37,    36,    34,    35,
-      38,    39,    41,    40,    44,    43,    42,    50,    55,     0,
-      10,     0,    16,    17,     0,    55,     0,    60,    11,     0,
-      51,    12
-};
-
-/* YYDEFGOTO[NTERM-NUM].  */
-static const yytype_int16 yydefgoto[] =
-{
-      -1,     1,    52,    53,    54,    66,    67,   149,    55,    69,
-     115,   122,    75,    76,   116,    57,    58
-};
-
-/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
-   STATE-NUM.  */
-#define YYPACT_NINF -147
-static const yytype_int16 yypact[] =
-{
-    -147,   112,  -147,    28,   -10,    55,    62,   152,   -15,    59,
-     192,    85,    86,    87,    51,  -147,    28,  -147,  -147,  -147,
-    -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,
-    -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,
-    -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,
-    -147,  -147,  -147,  -147,  -147,  -147,   312,  -147,  -147,  -147,
-    -147,    28,    28,    28,    28,    28,  -147,   428,  -147,  -147,
-     352,    63,   392,    17,  -147,  -147,   232,  -147,  -147,  -147,
-    -147,   272,   392,   392,    84,    89,   451,  -147,  -147,  -147,
-    -147,   469,  -147,  -147,  -147,    28,    28,    28,    28,    28,
-      28,    28,    28,    28,    28,    28,    28,    28,    28,    28,
-      28,    28,    28,  -147,    60,    90,   392,  -147,    96,  -147,
-    -147,  -147,    93,   392,    94,  -147,  -147,  -147,  -147,   489,
-     505,   520,   534,   547,   558,   558,    18,    18,    18,    18,
-     563,   563,    23,    23,  -147,  -147,  -147,  -147,   392,    32,
-    -147,    61,  -147,  -147,   110,   392,   118,  -147,  -147,   149,
-    -147,  -147
-};
-
-/* YYPGOTO[NTERM-NUM].  */
-static const yytype_int16 yypgoto[] =
-{
-    -147,  -147,  -147,  -147,  -147,   157,   -11,  -147,  -147,  -147,
-    -146,    92,   -68,   200,     0,    -7,  -147
-};
-
-/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
-   positive, shift that token.  If negative, reduce the rule which
-   number is the opposite.  If zero, do what YYDEFACT says.
-   If YYTABLE_NINF, syntax error.  */
-#define YYTABLE_NINF -1
-static const yytype_uint8 yytable[] =
-{
-      77,    56,   154,    77,    70,    86,    78,    15,   120,   159,
-      17,    68,    19,   120,    20,    21,    22,    23,    24,    25,
-      26,    27,    28,    29,    30,    31,    32,    33,    34,    35,
-      36,    37,    38,    39,   117,    40,    41,    42,    43,    44,
-      45,    46,    47,    48,    49,    50,    51,    59,    60,    88,
-      89,    90,    91,    92,    93,   106,   107,   108,   109,   110,
-     111,   112,   118,    88,   110,   111,   112,    61,    62,    77,
-      59,    60,    71,    63,    77,    64,    65,   147,   155,    72,
-      79,   156,   123,   123,   129,   130,   131,   132,   133,   134,
-     135,   136,   137,   138,   139,   140,   141,   142,   143,   144,
-     145,   146,    82,    83,    84,   125,   148,   157,   114,    88,
-     126,   150,     2,   151,   152,   153,    88,     3,     4,     5,
-       6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
-      16,   158,    17,    18,    19,   160,    20,    21,    22,    23,
-      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
-      34,    35,    36,    37,    38,    39,    73,    40,    41,    42,
-      43,    44,    45,    46,    47,    48,    49,    50,    51,    15,
-     161,    85,    17,    74,    19,   124,    20,    21,    22,    23,
-      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
-      34,    35,    36,    37,    38,    39,    73,    40,    41,    42,
-      43,    44,    45,    46,    47,    48,    49,    50,    51,    15,
-      81,     0,    17,    80,    19,     0,    20,    21,    22,    23,
-      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
-      34,    35,    36,    37,    38,    39,    73,    40,    41,    42,
-      43,    44,    45,    46,    47,    48,    49,    50,    51,    15,
-       0,     0,    17,   119,    19,     0,    20,    21,    22,    23,
-      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
-      34,    35,    36,    37,    38,    39,    73,    40,    41,    42,
-      43,    44,    45,    46,    47,    48,    49,    50,    51,    15,
-       0,     0,    17,   121,    19,     0,    20,    21,    22,    23,
-      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
-      34,    35,    36,    37,    38,    39,     0,    40,    41,    42,
-      43,    44,    45,    46,    47,    48,    49,    50,    51,    15,
-       0,     0,    17,    87,    19,     0,    20,    21,    22,    23,
-      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
-      34,    35,    36,    37,    38,    39,     0,    40,    41,    42,
-      43,    44,    45,    46,    47,    48,    49,    50,    51,    15,
-       0,     0,    17,   113,    19,     0,    20,    21,    22,    23,
-      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
-      34,    35,    36,    37,    38,    39,     0,    40,    41,    42,
-      43,    44,    45,    46,    47,    48,    49,    50,    51,    15,
-       0,     0,    17,     0,    19,     0,    20,    21,    22,    23,
-      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
-      34,    35,    36,    37,    38,    39,     0,    40,    41,    42,
-      43,    44,    45,    46,    47,    48,    49,    50,    51,    94,
-       0,     0,     0,     0,    95,    96,    97,    98,    99,   100,
-     101,   102,   103,   104,   105,   106,   107,   108,   109,   110,
-     111,   112,   127,     0,     0,     0,     0,    95,    96,    97,
-      98,    99,   100,   101,   102,   103,   104,   105,   106,   107,
-     108,   109,   110,   111,   112,    95,    96,    97,    98,    99,
-     100,   101,   102,   103,   104,   105,   106,   107,   108,   109,
-     110,   111,   112,     0,     0,   128,    96,    97,    98,    99,
-     100,   101,   102,   103,   104,   105,   106,   107,   108,   109,
-     110,   111,   112,    97,    98,    99,   100,   101,   102,   103,
-     104,   105,   106,   107,   108,   109,   110,   111,   112,    98,
-      99,   100,   101,   102,   103,   104,   105,   106,   107,   108,
-     109,   110,   111,   112,    99,   100,   101,   102,   103,   104,
-     105,   106,   107,   108,   109,   110,   111,   112,   100,   101,
-     102,   103,   104,   105,   106,   107,   108,   109,   110,   111,
-     112,   102,   103,   104,   105,   106,   107,   108,   109,   110,
-     111,   112,   108,   109,   110,   111,   112
-};
-
-static const yytype_int16 yycheck[] =
-{
-       7,     1,   148,    10,     4,    16,    21,    17,    76,   155,
-      20,    21,    22,    81,    24,    25,    26,    27,    28,    29,
-      30,    31,    32,    33,    34,    35,    36,    37,    38,    39,
-      40,    41,    42,    43,    17,    45,    46,    47,    48,    49,
-      50,    51,    52,    53,    54,    55,    56,    19,    20,    56,
-      61,    62,    63,    64,    65,    37,    38,    39,    40,    41,
-      42,    43,    45,    70,    41,    42,    43,    39,    40,    76,
-      19,    20,    17,    45,    81,    47,    48,    17,    46,    17,
-      21,    49,    82,    83,    95,    96,    97,    98,    99,   100,
-     101,   102,   103,   104,   105,   106,   107,   108,   109,   110,
-     111,   112,    17,    17,    17,    21,    46,    46,    45,   116,
-      21,    21,     0,    17,    21,    21,   123,     5,     6,     7,
-       8,     9,    10,    11,    12,    13,    14,    15,    16,    17,
-      18,    21,    20,    21,    22,    17,    24,    25,    26,    27,
-      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
-      38,    39,    40,    41,    42,    43,     4,    45,    46,    47,
-      48,    49,    50,    51,    52,    53,    54,    55,    56,    17,
-      21,    14,    20,    21,    22,    83,    24,    25,    26,    27,
-      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
-      38,    39,    40,    41,    42,    43,     4,    45,    46,    47,
-      48,    49,    50,    51,    52,    53,    54,    55,    56,    17,
-      10,    -1,    20,    21,    22,    -1,    24,    25,    26,    27,
-      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
-      38,    39,    40,    41,    42,    43,     4,    45,    46,    47,
-      48,    49,    50,    51,    52,    53,    54,    55,    56,    17,
-      -1,    -1,    20,    21,    22,    -1,    24,    25,    26,    27,
-      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
-      38,    39,    40,    41,    42,    43,     4,    45,    46,    47,
-      48,    49,    50,    51,    52,    53,    54,    55,    56,    17,
-      -1,    -1,    20,    21,    22,    -1,    24,    25,    26,    27,
-      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
-      38,    39,    40,    41,    42,    43,    -1,    45,    46,    47,
-      48,    49,    50,    51,    52,    53,    54,    55,    56,    17,
-      -1,    -1,    20,    21,    22,    -1,    24,    25,    26,    27,
-      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
-      38,    39,    40,    41,    42,    43,    -1,    45,    46,    47,
-      48,    49,    50,    51,    52,    53,    54,    55,    56,    17,
-      -1,    -1,    20,    21,    22,    -1,    24,    25,    26,    27,
-      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
-      38,    39,    40,    41,    42,    43,    -1,    45,    46,    47,
-      48,    49,    50,    51,    52,    53,    54,    55,    56,    17,
-      -1,    -1,    20,    -1,    22,    -1,    24,    25,    26,    27,
-      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
-      38,    39,    40,    41,    42,    43,    -1,    45,    46,    47,
-      48,    49,    50,    51,    52,    53,    54,    55,    56,    21,
-      -1,    -1,    -1,    -1,    26,    27,    28,    29,    30,    31,
-      32,    33,    34,    35,    36,    37,    38,    39,    40,    41,
-      42,    43,    21,    -1,    -1,    -1,    -1,    26,    27,    28,
-      29,    30,    31,    32,    33,    34,    35,    36,    37,    38,
-      39,    40,    41,    42,    43,    26,    27,    28,    29,    30,
-      31,    32,    33,    34,    35,    36,    37,    38,    39,    40,
-      41,    42,    43,    -1,    -1,    46,    27,    28,    29,    30,
-      31,    32,    33,    34,    35,    36,    37,    38,    39,    40,
-      41,    42,    43,    28,    29,    30,    31,    32,    33,    34,
-      35,    36,    37,    38,    39,    40,    41,    42,    43,    29,
-      30,    31,    32,    33,    34,    35,    36,    37,    38,    39,
-      40,    41,    42,    43,    30,    31,    32,    33,    34,    35,
-      36,    37,    38,    39,    40,    41,    42,    43,    31,    32,
-      33,    34,    35,    36,    37,    38,    39,    40,    41,    42,
-      43,    33,    34,    35,    36,    37,    38,    39,    40,    41,
-      42,    43,    39,    40,    41,    42,    43
-};
-
-/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
-   symbol of state STATE-NUM.  */
-static const yytype_uint8 yystos[] =
-{
-       0,    58,     0,     5,     6,     7,     8,     9,    10,    11,
-      12,    13,    14,    15,    16,    17,    18,    20,    21,    22,
-      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
-      34,    35,    36,    37,    38,    39,    40,    41,    42,    43,
-      45,    46,    47,    48,    49,    50,    51,    52,    53,    54,
-      55,    56,    59,    60,    61,    65,    71,    72,    73,    19,
-      20,    39,    40,    45,    47,    48,    62,    63,    21,    66,
-      71,    17,    17,     4,    21,    69,    70,    72,    21,    21,
-      21,    70,    17,    17,    17,    62,    63,    21,    72,    63,
-      63,    63,    63,    63,    21,    26,    27,    28,    29,    30,
-      31,    32,    33,    34,    35,    36,    37,    38,    39,    40,
-      41,    42,    43,    21,    45,    67,    71,    17,    45,    21,
-      69,    21,    68,    71,    68,    21,    21,    21,    46,    63,
-      63,    63,    63,    63,    63,    63,    63,    63,    63,    63,
-      63,    63,    63,    63,    63,    63,    63,    17,    46,    64,
-      21,    17,    21,    21,    67,    46,    49,    46,    21,    67,
-      17,    21
-};
-
-#define yyerrok		(yyerrstatus = 0)
-#define yyclearin	(yychar = YYEMPTY)
-#define YYEMPTY		(-2)
-#define YYEOF		0
-
-#define YYACCEPT	goto yyacceptlab
-#define YYABORT		goto yyabortlab
-#define YYERROR		goto yyerrorlab
-
-
-/* Like YYERROR except do call yyerror.  This remains here temporarily
-   to ease the transition to the new meaning of YYERROR, for GCC.
-   Once GCC version 2 has supplanted version 1, this can go.  However,
-   YYFAIL appears to be in use.  Nevertheless, it is formally deprecated
-   in Bison 2.4.2's NEWS entry, where a plan to phase it out is
-   discussed.  */
-
-#define YYFAIL		goto yyerrlab
-#if defined YYFAIL
-  /* This is here to suppress warnings from the GCC cpp's
-     -Wunused-macros.  Normally we don't worry about that warning, but
-     some users do, and we want to make it easy for users to remove
-     YYFAIL uses, which will produce warnings from Bison 2.5.  */
-#endif
-
-#define YYRECOVERING()  (!!yyerrstatus)
-
-#define YYBACKUP(Token, Value)					\
-do								\
-  if (yychar == YYEMPTY && yylen == 1)				\
-    {								\
-      yychar = (Token);						\
-      yylval = (Value);						\
-      yytoken = YYTRANSLATE (yychar);				\
-      YYPOPSTACK (1);						\
-      goto yybackup;						\
-    }								\
-  else								\
-    {								\
-      yyerror (&yylloc, parser, YY_("syntax error: cannot back up")); \
-      YYERROR;							\
-    }								\
-while (YYID (0))
-
-
-#define YYTERROR	1
-#define YYERRCODE	256
-
-
-/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
-   If N is 0, then set CURRENT to the empty location which ends
-   the previous symbol: RHS[0] (always defined).  */
-
-#define YYRHSLOC(Rhs, K) ((Rhs)[K])
-#ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N)				\
-    do									\
-      if (YYID (N))                                                    \
-	{								\
-	  (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;	\
-	  (Current).first_column = YYRHSLOC (Rhs, 1).first_column;	\
-	  (Current).last_line    = YYRHSLOC (Rhs, N).last_line;		\
-	  (Current).last_column  = YYRHSLOC (Rhs, N).last_column;	\
-	}								\
-      else								\
-	{								\
-	  (Current).first_line   = (Current).last_line   =		\
-	    YYRHSLOC (Rhs, 0).last_line;				\
-	  (Current).first_column = (Current).last_column =		\
-	    YYRHSLOC (Rhs, 0).last_column;				\
-	}								\
-    while (YYID (0))
-#endif
-
-
-/* YY_LOCATION_PRINT -- Print the location on the stream.
-   This macro was not mandated originally: define only if we know
-   we won't break user code: when these are the locations we know.  */
-
-#ifndef YY_LOCATION_PRINT
-# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
-#  define YY_LOCATION_PRINT(File, Loc)			\
-     fprintf (File, "%d.%d-%d.%d",			\
-	      (Loc).first_line, (Loc).first_column,	\
-	      (Loc).last_line,  (Loc).last_column)
-# else
-#  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
-# endif
-#endif
-
-
-/* YYLEX -- calling `yylex' with the right arguments.  */
-
-#ifdef YYLEX_PARAM
-# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
-#else
-# define YYLEX yylex (&yylval, &yylloc, parser)
-#endif
-
-/* Enable debugging if requested.  */
-#if YYDEBUG
-
-# ifndef YYFPRINTF
-#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
-#  define YYFPRINTF fprintf
-# endif
-
-# define YYDPRINTF(Args)			\
-do {						\
-  if (yydebug)					\
-    YYFPRINTF Args;				\
-} while (YYID (0))
-
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location)			  \
-do {									  \
-  if (yydebug)								  \
-    {									  \
-      YYFPRINTF (stderr, "%s ", Title);					  \
-      yy_symbol_print (stderr,						  \
-		  Type, Value, Location, parser); \
-      YYFPRINTF (stderr, "\n");						  \
-    }									  \
-} while (YYID (0))
-
-
-/*--------------------------------.
-| Print this symbol on YYOUTPUT.  |
-`--------------------------------*/
-
-/*ARGSUSED*/
-#if (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-static void
-yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, glcpp_parser_t *parser)
-#else
-static void
-yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, parser)
-    FILE *yyoutput;
-    int yytype;
-    YYSTYPE const * const yyvaluep;
-    YYLTYPE const * const yylocationp;
-    glcpp_parser_t *parser;
-#endif
-{
-  if (!yyvaluep)
-    return;
-  YYUSE (yylocationp);
-  YYUSE (parser);
-# ifdef YYPRINT
-  if (yytype < YYNTOKENS)
-    YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
-# else
-  YYUSE (yyoutput);
-# endif
-  switch (yytype)
-    {
-      default:
-	break;
-    }
-}
-
-
-/*--------------------------------.
-| Print this symbol on YYOUTPUT.  |
-`--------------------------------*/
-
-#if (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-static void
-yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, glcpp_parser_t *parser)
-#else
-static void
-yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, parser)
-    FILE *yyoutput;
-    int yytype;
-    YYSTYPE const * const yyvaluep;
-    YYLTYPE const * const yylocationp;
-    glcpp_parser_t *parser;
-#endif
-{
-  if (yytype < YYNTOKENS)
-    YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
-  else
-    YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
-
-  YY_LOCATION_PRINT (yyoutput, *yylocationp);
-  YYFPRINTF (yyoutput, ": ");
-  yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, parser);
-  YYFPRINTF (yyoutput, ")");
-}
-
-/*------------------------------------------------------------------.
-| yy_stack_print -- Print the state stack from its BOTTOM up to its |
-| TOP (included).                                                   |
-`------------------------------------------------------------------*/
-
-#if (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-static void
-yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
-#else
-static void
-yy_stack_print (yybottom, yytop)
-    yytype_int16 *yybottom;
-    yytype_int16 *yytop;
-#endif
-{
-  YYFPRINTF (stderr, "Stack now");
-  for (; yybottom <= yytop; yybottom++)
-    {
-      int yybot = *yybottom;
-      YYFPRINTF (stderr, " %d", yybot);
-    }
-  YYFPRINTF (stderr, "\n");
-}
-
-# define YY_STACK_PRINT(Bottom, Top)				\
-do {								\
-  if (yydebug)							\
-    yy_stack_print ((Bottom), (Top));				\
-} while (YYID (0))
-
-
-/*------------------------------------------------.
-| Report that the YYRULE is going to be reduced.  |
-`------------------------------------------------*/
-
-#if (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-static void
-yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, glcpp_parser_t *parser)
-#else
-static void
-yy_reduce_print (yyvsp, yylsp, yyrule, parser)
-    YYSTYPE *yyvsp;
-    YYLTYPE *yylsp;
-    int yyrule;
-    glcpp_parser_t *parser;
-#endif
-{
-  int yynrhs = yyr2[yyrule];
-  int yyi;
-  unsigned long int yylno = yyrline[yyrule];
-  YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
-	     yyrule - 1, yylno);
-  /* The symbols being reduced.  */
-  for (yyi = 0; yyi < yynrhs; yyi++)
-    {
-      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
-      yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
-		       &(yyvsp[(yyi + 1) - (yynrhs)])
-		       , &(yylsp[(yyi + 1) - (yynrhs)])		       , parser);
-      YYFPRINTF (stderr, "\n");
-    }
-}
-
-# define YY_REDUCE_PRINT(Rule)		\
-do {					\
-  if (yydebug)				\
-    yy_reduce_print (yyvsp, yylsp, Rule, parser); \
-} while (YYID (0))
-
-/* Nonzero means print parse trace.  It is left uninitialized so that
-   multiple parsers can coexist.  */
-int yydebug;
-#else /* !YYDEBUG */
-# define YYDPRINTF(Args)
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
-# define YY_STACK_PRINT(Bottom, Top)
-# define YY_REDUCE_PRINT(Rule)
-#endif /* !YYDEBUG */
-
-
-/* YYINITDEPTH -- initial size of the parser's stacks.  */
-#ifndef	YYINITDEPTH
-# define YYINITDEPTH 200
-#endif
-
-/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
-   if the built-in stack extension method is used).
-
-   Do not make this value too large; the results are undefined if
-   YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
-   evaluated with infinite-precision integer arithmetic.  */
-
-#ifndef YYMAXDEPTH
-# define YYMAXDEPTH 10000
-#endif
-
-
-
-#if YYERROR_VERBOSE
-
-# ifndef yystrlen
-#  if defined __GLIBC__ && defined _STRING_H
-#   define yystrlen strlen
-#  else
-/* Return the length of YYSTR.  */
-#if (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-static YYSIZE_T
-yystrlen (const char *yystr)
-#else
-static YYSIZE_T
-yystrlen (yystr)
-    const char *yystr;
-#endif
-{
-  YYSIZE_T yylen;
-  for (yylen = 0; yystr[yylen]; yylen++)
-    continue;
-  return yylen;
-}
-#  endif
-# endif
-
-# ifndef yystpcpy
-#  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
-#   define yystpcpy stpcpy
-#  else
-/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
-   YYDEST.  */
-#if (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-static char *
-yystpcpy (char *yydest, const char *yysrc)
-#else
-static char *
-yystpcpy (yydest, yysrc)
-    char *yydest;
-    const char *yysrc;
-#endif
-{
-  char *yyd = yydest;
-  const char *yys = yysrc;
-
-  while ((*yyd++ = *yys++) != '\0')
-    continue;
-
-  return yyd - 1;
-}
-#  endif
-# endif
-
-# ifndef yytnamerr
-/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
-   quotes and backslashes, so that it's suitable for yyerror.  The
-   heuristic is that double-quoting is unnecessary unless the string
-   contains an apostrophe, a comma, or backslash (other than
-   backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
-   null, do not copy; instead, return the length of what the result
-   would have been.  */
-static YYSIZE_T
-yytnamerr (char *yyres, const char *yystr)
-{
-  if (*yystr == '"')
-    {
-      YYSIZE_T yyn = 0;
-      char const *yyp = yystr;
-
-      for (;;)
-	switch (*++yyp)
-	  {
-	  case '\'':
-	  case ',':
-	    goto do_not_strip_quotes;
-
-	  case '\\':
-	    if (*++yyp != '\\')
-	      goto do_not_strip_quotes;
-	    /* Fall through.  */
-	  default:
-	    if (yyres)
-	      yyres[yyn] = *yyp;
-	    yyn++;
-	    break;
-
-	  case '"':
-	    if (yyres)
-	      yyres[yyn] = '\0';
-	    return yyn;
-	  }
-    do_not_strip_quotes: ;
-    }
-
-  if (! yyres)
-    return yystrlen (yystr);
-
-  return yystpcpy (yyres, yystr) - yyres;
-}
-# endif
-
-/* Copy into YYRESULT an error message about the unexpected token
-   YYCHAR while in state YYSTATE.  Return the number of bytes copied,
-   including the terminating null byte.  If YYRESULT is null, do not
-   copy anything; just return the number of bytes that would be
-   copied.  As a special case, return 0 if an ordinary "syntax error"
-   message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
-   size calculation.  */
-static YYSIZE_T
-yysyntax_error (char *yyresult, int yystate, int yychar)
-{
-  int yyn = yypact[yystate];
-
-  if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
-    return 0;
-  else
-    {
-      int yytype = YYTRANSLATE (yychar);
-      YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
-      YYSIZE_T yysize = yysize0;
-      YYSIZE_T yysize1;
-      int yysize_overflow = 0;
-      enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
-      char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
-      int yyx;
-
-# if 0
-      /* This is so xgettext sees the translatable formats that are
-	 constructed on the fly.  */
-      YY_("syntax error, unexpected %s");
-      YY_("syntax error, unexpected %s, expecting %s");
-      YY_("syntax error, unexpected %s, expecting %s or %s");
-      YY_("syntax error, unexpected %s, expecting %s or %s or %s");
-      YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
-# endif
-      char *yyfmt;
-      char const *yyf;
-      static char const yyunexpected[] = "syntax error, unexpected %s";
-      static char const yyexpecting[] = ", expecting %s";
-      static char const yyor[] = " or %s";
-      char yyformat[sizeof yyunexpected
-		    + sizeof yyexpecting - 1
-		    + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
-		       * (sizeof yyor - 1))];
-      char const *yyprefix = yyexpecting;
-
-      /* Start YYX at -YYN if negative to avoid negative indexes in
-	 YYCHECK.  */
-      int yyxbegin = yyn < 0 ? -yyn : 0;
-
-      /* Stay within bounds of both yycheck and yytname.  */
-      int yychecklim = YYLAST - yyn + 1;
-      int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
-      int yycount = 1;
-
-      yyarg[0] = yytname[yytype];
-      yyfmt = yystpcpy (yyformat, yyunexpected);
-
-      for (yyx = yyxbegin; yyx < yyxend; ++yyx)
-	if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
-	  {
-	    if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
-	      {
-		yycount = 1;
-		yysize = yysize0;
-		yyformat[sizeof yyunexpected - 1] = '\0';
-		break;
-	      }
-	    yyarg[yycount++] = yytname[yyx];
-	    yysize1 = yysize + yytnamerr (0, yytname[yyx]);
-	    yysize_overflow |= (yysize1 < yysize);
-	    yysize = yysize1;
-	    yyfmt = yystpcpy (yyfmt, yyprefix);
-	    yyprefix = yyor;
-	  }
-
-      yyf = YY_(yyformat);
-      yysize1 = yysize + yystrlen (yyf);
-      yysize_overflow |= (yysize1 < yysize);
-      yysize = yysize1;
-
-      if (yysize_overflow)
-	return YYSIZE_MAXIMUM;
-
-      if (yyresult)
-	{
-	  /* Avoid sprintf, as that infringes on the user's name space.
-	     Don't have undefined behavior even if the translation
-	     produced a string with the wrong number of "%s"s.  */
-	  char *yyp = yyresult;
-	  int yyi = 0;
-	  while ((*yyp = *yyf) != '\0')
-	    {
-	      if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
-		{
-		  yyp += yytnamerr (yyp, yyarg[yyi++]);
-		  yyf += 2;
-		}
-	      else
-		{
-		  yyp++;
-		  yyf++;
-		}
-	    }
-	}
-      return yysize;
-    }
-}
-#endif /* YYERROR_VERBOSE */
-
-
-/*-----------------------------------------------.
-| Release the memory associated to this symbol.  |
-`-----------------------------------------------*/
-
-/*ARGSUSED*/
-#if (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-static void
-yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, glcpp_parser_t *parser)
-#else
-static void
-yydestruct (yymsg, yytype, yyvaluep, yylocationp, parser)
-    const char *yymsg;
-    int yytype;
-    YYSTYPE *yyvaluep;
-    YYLTYPE *yylocationp;
-    glcpp_parser_t *parser;
-#endif
-{
-  YYUSE (yyvaluep);
-  YYUSE (yylocationp);
-  YYUSE (parser);
-
-  if (!yymsg)
-    yymsg = "Deleting";
-  YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
-
-  switch (yytype)
-    {
-
-      default:
-	break;
-    }
-}
-
-/* Prevent warnings from -Wmissing-prototypes.  */
-#ifdef YYPARSE_PARAM
-#if defined __STDC__ || defined __cplusplus
-int yyparse (void *YYPARSE_PARAM);
-#else
-int yyparse ();
-#endif
-#else /* ! YYPARSE_PARAM */
-#if defined __STDC__ || defined __cplusplus
-int yyparse (glcpp_parser_t *parser);
-#else
-int yyparse ();
-#endif
-#endif /* ! YYPARSE_PARAM */
-
-
-
-
-
-/*-------------------------.
-| yyparse or yypush_parse.  |
-`-------------------------*/
-
-#ifdef YYPARSE_PARAM
-#if (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-int
-yyparse (void *YYPARSE_PARAM)
-#else
-int
-yyparse (YYPARSE_PARAM)
-    void *YYPARSE_PARAM;
-#endif
-#else /* ! YYPARSE_PARAM */
-#if (defined __STDC__ || defined __C99__FUNC__ \
-     || defined __cplusplus || defined _MSC_VER)
-int
-yyparse (glcpp_parser_t *parser)
-#else
-int
-yyparse (parser)
-    glcpp_parser_t *parser;
-#endif
-#endif
-{
-/* The lookahead symbol.  */
-int yychar;
-
-/* The semantic value of the lookahead symbol.  */
-YYSTYPE yylval;
-
-/* Location data for the lookahead symbol.  */
-YYLTYPE yylloc;
-
-    /* Number of syntax errors so far.  */
-    int yynerrs;
-
-    int yystate;
-    /* Number of tokens to shift before error messages enabled.  */
-    int yyerrstatus;
-
-    /* The stacks and their tools:
-       `yyss': related to states.
-       `yyvs': related to semantic values.
-       `yyls': related to locations.
-
-       Refer to the stacks thru separate pointers, to allow yyoverflow
-       to reallocate them elsewhere.  */
-
-    /* The state stack.  */
-    yytype_int16 yyssa[YYINITDEPTH];
-    yytype_int16 *yyss;
-    yytype_int16 *yyssp;
-
-    /* The semantic value stack.  */
-    YYSTYPE yyvsa[YYINITDEPTH];
-    YYSTYPE *yyvs;
-    YYSTYPE *yyvsp;
-
-    /* The location stack.  */
-    YYLTYPE yylsa[YYINITDEPTH];
-    YYLTYPE *yyls;
-    YYLTYPE *yylsp;
-
-    /* The locations where the error started and ended.  */
-    YYLTYPE yyerror_range[3];
-
-    YYSIZE_T yystacksize;
-
-  int yyn;
-  int yyresult;
-  /* Lookahead token as an internal (translated) token number.  */
-  int yytoken;
-  /* The variables used to return semantic value and location from the
-     action routines.  */
-  YYSTYPE yyval;
-  YYLTYPE yyloc;
-
-#if YYERROR_VERBOSE
-  /* Buffer for error messages, and its allocated size.  */
-  char yymsgbuf[128];
-  char *yymsg = yymsgbuf;
-  YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
-#endif
-
-#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
-
-  /* The number of symbols on the RHS of the reduced rule.
-     Keep to zero when no symbol should be popped.  */
-  int yylen = 0;
-
-  yytoken = 0;
-  yyss = yyssa;
-  yyvs = yyvsa;
-  yyls = yylsa;
-  yystacksize = YYINITDEPTH;
-
-  YYDPRINTF ((stderr, "Starting parse\n"));
-
-  yystate = 0;
-  yyerrstatus = 0;
-  yynerrs = 0;
-  yychar = YYEMPTY; /* Cause a token to be read.  */
-
-  /* Initialize stack pointers.
-     Waste one element of value and location stack
-     so that they stay on the same level as the state stack.
-     The wasted elements are never initialized.  */
-  yyssp = yyss;
-  yyvsp = yyvs;
-  yylsp = yyls;
-
-#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
-  /* Initialize the default location before parsing starts.  */
-  yylloc.first_line   = yylloc.last_line   = 1;
-  yylloc.first_column = yylloc.last_column = 1;
-#endif
-
-/* User initialization code.  */
-
-/* Line 1251 of yacc.c  */
-#line 152 "glcpp/glcpp-parse.y"
-{
-	yylloc.first_line = 1;
-	yylloc.first_column = 1;
-	yylloc.last_line = 1;
-	yylloc.last_column = 1;
-	yylloc.source = 0;
-}
-
-/* Line 1251 of yacc.c  */
-#line 1622 "glcpp/glcpp-parse.c"
-  yylsp[0] = yylloc;
-
-  goto yysetstate;
-
-/*------------------------------------------------------------.
-| yynewstate -- Push a new state, which is found in yystate.  |
-`------------------------------------------------------------*/
- yynewstate:
-  /* In all cases, when you get here, the value and location stacks
-     have just been pushed.  So pushing a state here evens the stacks.  */
-  yyssp++;
-
- yysetstate:
-  *yyssp = yystate;
-
-  if (yyss + yystacksize - 1 <= yyssp)
-    {
-      /* Get the current used size of the three stacks, in elements.  */
-      YYSIZE_T yysize = yyssp - yyss + 1;
-
-#ifdef yyoverflow
-      {
-	/* Give user a chance to reallocate the stack.  Use copies of
-	   these so that the &'s don't force the real ones into
-	   memory.  */
-	YYSTYPE *yyvs1 = yyvs;
-	yytype_int16 *yyss1 = yyss;
-	YYLTYPE *yyls1 = yyls;
-
-	/* Each stack pointer address is followed by the size of the
-	   data in use in that stack, in bytes.  This used to be a
-	   conditional around just the two extra args, but that might
-	   be undefined if yyoverflow is a macro.  */
-	yyoverflow (YY_("memory exhausted"),
-		    &yyss1, yysize * sizeof (*yyssp),
-		    &yyvs1, yysize * sizeof (*yyvsp),
-		    &yyls1, yysize * sizeof (*yylsp),
-		    &yystacksize);
-
-	yyls = yyls1;
-	yyss = yyss1;
-	yyvs = yyvs1;
-      }
-#else /* no yyoverflow */
-# ifndef YYSTACK_RELOCATE
-      goto yyexhaustedlab;
-# else
-      /* Extend the stack our own way.  */
-      if (YYMAXDEPTH <= yystacksize)
-	goto yyexhaustedlab;
-      yystacksize *= 2;
-      if (YYMAXDEPTH < yystacksize)
-	yystacksize = YYMAXDEPTH;
-
-      {
-	yytype_int16 *yyss1 = yyss;
-	union yyalloc *yyptr =
-	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
-	if (! yyptr)
-	  goto yyexhaustedlab;
-	YYSTACK_RELOCATE (yyss_alloc, yyss);
-	YYSTACK_RELOCATE (yyvs_alloc, yyvs);
-	YYSTACK_RELOCATE (yyls_alloc, yyls);
-#  undef YYSTACK_RELOCATE
-	if (yyss1 != yyssa)
-	  YYSTACK_FREE (yyss1);
-      }
-# endif
-#endif /* no yyoverflow */
-
-      yyssp = yyss + yysize - 1;
-      yyvsp = yyvs + yysize - 1;
-      yylsp = yyls + yysize - 1;
-
-      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
-		  (unsigned long int) yystacksize));
-
-      if (yyss + yystacksize - 1 <= yyssp)
-	YYABORT;
-    }
-
-  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
-
-  if (yystate == YYFINAL)
-    YYACCEPT;
-
-  goto yybackup;
-
-/*-----------.
-| yybackup.  |
-`-----------*/
-yybackup:
-
-  /* Do appropriate processing given the current state.  Read a
-     lookahead token if we need one and don't already have one.  */
-
-  /* First try to decide what to do without reference to lookahead token.  */
-  yyn = yypact[yystate];
-  if (yyn == YYPACT_NINF)
-    goto yydefault;
-
-  /* Not known => get a lookahead token if don't already have one.  */
-
-  /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
-  if (yychar == YYEMPTY)
-    {
-      YYDPRINTF ((stderr, "Reading a token: "));
-      yychar = YYLEX;
-    }
-
-  if (yychar <= YYEOF)
-    {
-      yychar = yytoken = YYEOF;
-      YYDPRINTF ((stderr, "Now at end of input.\n"));
-    }
-  else
-    {
-      yytoken = YYTRANSLATE (yychar);
-      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
-    }
-
-  /* If the proper action on seeing token YYTOKEN is to reduce or to
-     detect an error, take that action.  */
-  yyn += yytoken;
-  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
-    goto yydefault;
-  yyn = yytable[yyn];
-  if (yyn <= 0)
-    {
-      if (yyn == 0 || yyn == YYTABLE_NINF)
-	goto yyerrlab;
-      yyn = -yyn;
-      goto yyreduce;
-    }
-
-  /* Count tokens shifted since error; after three, turn off error
-     status.  */
-  if (yyerrstatus)
-    yyerrstatus--;
-
-  /* Shift the lookahead token.  */
-  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
-
-  /* Discard the shifted token.  */
-  yychar = YYEMPTY;
-
-  yystate = yyn;
-  *++yyvsp = yylval;
-  *++yylsp = yylloc;
-  goto yynewstate;
-
-
-/*-----------------------------------------------------------.
-| yydefault -- do the default action for the current state.  |
-`-----------------------------------------------------------*/
-yydefault:
-  yyn = yydefact[yystate];
-  if (yyn == 0)
-    goto yyerrlab;
-  goto yyreduce;
-
-
-/*-----------------------------.
-| yyreduce -- Do a reduction.  |
-`-----------------------------*/
-yyreduce:
-  /* yyn is the number of a rule to reduce with.  */
-  yylen = yyr2[yyn];
-
-  /* If YYLEN is nonzero, implement the default value of the action:
-     `$$ = $1'.
-
-     Otherwise, the following line sets YYVAL to garbage.
-     This behavior is undocumented and Bison
-     users should not rely upon it.  Assigning to YYVAL
-     unconditionally makes the parser a bit smaller, and it avoids a
-     GCC warning that YYVAL may be used uninitialized.  */
-  yyval = yyvsp[1-yylen];
-
-  /* Default location.  */
-  YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
-  YY_REDUCE_PRINT (yyn);
-  switch (yyn)
-    {
-        case 4:
-
-/* Line 1464 of yacc.c  */
-#line 191 "glcpp/glcpp-parse.y"
-    {
-		glcpp_print(parser->output, "\n");
-	;}
-    break;
-
-  case 5:
-
-/* Line 1464 of yacc.c  */
-#line 194 "glcpp/glcpp-parse.y"
-    {
-		_glcpp_parser_print_expanded_token_list (parser, (yyvsp[(1) - (1)].token_list));
-		glcpp_print(parser->output, "\n");
-		talloc_free ((yyvsp[(1) - (1)].token_list));
-	;}
-    break;
-
-  case 8:
-
-/* Line 1464 of yacc.c  */
-#line 204 "glcpp/glcpp-parse.y"
-    {
-		_glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (3)]), (yyvsp[(2) - (3)].ival));
-	;}
-    break;
-
-  case 9:
-
-/* Line 1464 of yacc.c  */
-#line 207 "glcpp/glcpp-parse.y"
-    {
-		_glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (3)]), "elif", (yyvsp[(2) - (3)].ival));
-	;}
-    break;
-
-  case 10:
-
-/* Line 1464 of yacc.c  */
-#line 213 "glcpp/glcpp-parse.y"
-    {
-		_define_object_macro (parser, & (yylsp[(2) - (4)]), (yyvsp[(2) - (4)].str), (yyvsp[(3) - (4)].token_list));
-	;}
-    break;
-
-  case 11:
-
-/* Line 1464 of yacc.c  */
-#line 216 "glcpp/glcpp-parse.y"
-    {
-		_define_function_macro (parser, & (yylsp[(2) - (6)]), (yyvsp[(2) - (6)].str), NULL, (yyvsp[(5) - (6)].token_list));
-	;}
-    break;
-
-  case 12:
-
-/* Line 1464 of yacc.c  */
-#line 219 "glcpp/glcpp-parse.y"
-    {
-		_define_function_macro (parser, & (yylsp[(2) - (7)]), (yyvsp[(2) - (7)].str), (yyvsp[(4) - (7)].string_list), (yyvsp[(6) - (7)].token_list));
-	;}
-    break;
-
-  case 13:
-
-/* Line 1464 of yacc.c  */
-#line 222 "glcpp/glcpp-parse.y"
-    {
-		macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (3)].str));
-		if (macro) {
-			hash_table_remove (parser->defines, (yyvsp[(2) - (3)].str));
-			talloc_free (macro);
-		}
-		talloc_free ((yyvsp[(2) - (3)].str));
-	;}
-    break;
-
-  case 14:
-
-/* Line 1464 of yacc.c  */
-#line 230 "glcpp/glcpp-parse.y"
-    {
-		/* Be careful to only evaluate the 'if' expression if
-		 * we are not skipping. When we are skipping, we
-		 * simply push a new 0-valued 'if' onto the skip
-		 * stack.
-		 *
-		 * This avoids generating diagnostics for invalid
-		 * expressions that are being skipped. */
-		if (parser->skip_stack == NULL ||
-		    parser->skip_stack->type == SKIP_NO_SKIP)
-		{
-			_glcpp_parser_expand_if (parser, IF_EXPANDED, (yyvsp[(2) - (3)].token_list));
-		}	
-		else
-		{
-			_glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (3)]), 0);
-			parser->skip_stack->type = SKIP_TO_ENDIF;
-		}
-	;}
-    break;
-
-  case 15:
-
-/* Line 1464 of yacc.c  */
-#line 249 "glcpp/glcpp-parse.y"
-    {
-		/* #if without an expression is only an error if we
-		 *  are not skipping */
-		if (parser->skip_stack == NULL ||
-		    parser->skip_stack->type == SKIP_NO_SKIP)
-		{
-			glcpp_error(& (yylsp[(1) - (2)]), parser, "#if with no expression");
-		}	
-		_glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (2)]), 0);
-	;}
-    break;
-
-  case 16:
-
-/* Line 1464 of yacc.c  */
-#line 259 "glcpp/glcpp-parse.y"
-    {
-		macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (4)].str));
-		talloc_free ((yyvsp[(2) - (4)].str));
-		_glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (4)]), macro != NULL);
-	;}
-    break;
-
-  case 17:
-
-/* Line 1464 of yacc.c  */
-#line 264 "glcpp/glcpp-parse.y"
-    {
-		macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (4)].str));
-		talloc_free ((yyvsp[(2) - (4)].str));
-		_glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (4)]), macro == NULL);
-	;}
-    break;
-
-  case 18:
-
-/* Line 1464 of yacc.c  */
-#line 269 "glcpp/glcpp-parse.y"
-    {
-		/* Be careful to only evaluate the 'elif' expression
-		 * if we are not skipping. When we are skipping, we
-		 * simply change to a 0-valued 'elif' on the skip
-		 * stack.
-		 *
-		 * This avoids generating diagnostics for invalid
-		 * expressions that are being skipped. */
-		if (parser->skip_stack &&
-		    parser->skip_stack->type == SKIP_TO_ELSE)
-		{
-			_glcpp_parser_expand_if (parser, ELIF_EXPANDED, (yyvsp[(2) - (3)].token_list));
-		}
-		else
-		{
-			_glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (3)]),
-							    "elif", 0);
-		}
-	;}
-    break;
-
-  case 19:
-
-/* Line 1464 of yacc.c  */
-#line 288 "glcpp/glcpp-parse.y"
-    {
-		/* #elif without an expression is an error unless we
-		 * are skipping. */
-		if (parser->skip_stack &&
-		    parser->skip_stack->type == SKIP_TO_ELSE)
-		{
-			glcpp_error(& (yylsp[(1) - (2)]), parser, "#elif with no expression");
-		}
-		else
-		{
-			_glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (2)]),
-							    "elif", 0);
-			glcpp_warning(& (yylsp[(1) - (2)]), parser, "ignoring illegal #elif without expression");
-		}
-	;}
-    break;
-
-  case 20:
-
-/* Line 1464 of yacc.c  */
-#line 303 "glcpp/glcpp-parse.y"
-    {
-		_glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (2)]), "else", 1);
-	;}
-    break;
-
-  case 21:
-
-/* Line 1464 of yacc.c  */
-#line 306 "glcpp/glcpp-parse.y"
-    {
-		_glcpp_parser_skip_stack_pop (parser, & (yylsp[(1) - (2)]));
-	;}
-    break;
-
-  case 22:
-
-/* Line 1464 of yacc.c  */
-#line 309 "glcpp/glcpp-parse.y"
-    {
-		macro_t *macro = hash_table_find (parser->defines, "__VERSION__");
-		if (macro) {
-			hash_table_remove (parser->defines, "__VERSION__");
-			talloc_free (macro);
-		}
-		add_builtin_define (parser, "__VERSION__", (yyvsp[(2) - (3)].ival));
-
-		if ((yyvsp[(2) - (3)].ival) == 100)
-			add_builtin_define (parser, "GL_ES", 1);
-
-		/* Currently, all ES2 implementations support highp in the
-		 * fragment shader, so we always define this macro in ES2.
-		 * If we ever get a driver that doesn't support highp, we'll
-		 * need to add a flag to the gl_context and check that here.
-		 */
-		if ((yyvsp[(2) - (3)].ival) >= 130 || (yyvsp[(2) - (3)].ival) == 100)
-			add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1);
-
-		glcpp_printf(parser->output, "#version %" PRIiMAX, (yyvsp[(2) - (3)].ival));
-	;}
-    break;
-
-  case 24:
-
-/* Line 1464 of yacc.c  */
-#line 334 "glcpp/glcpp-parse.y"
-    {
-		if (strlen ((yyvsp[(1) - (1)].str)) >= 3 && strncmp ((yyvsp[(1) - (1)].str), "0x", 2) == 0) {
-			(yyval.ival) = strtoll ((yyvsp[(1) - (1)].str) + 2, NULL, 16);
-		} else if ((yyvsp[(1) - (1)].str)[0] == '0') {
-			(yyval.ival) = strtoll ((yyvsp[(1) - (1)].str), NULL, 8);
-		} else {
-			(yyval.ival) = strtoll ((yyvsp[(1) - (1)].str), NULL, 10);
-		}
-	;}
-    break;
-
-  case 25:
-
-/* Line 1464 of yacc.c  */
-#line 343 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (1)].ival);
-	;}
-    break;
-
-  case 27:
-
-/* Line 1464 of yacc.c  */
-#line 349 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) || (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 28:
-
-/* Line 1464 of yacc.c  */
-#line 352 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) && (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 29:
-
-/* Line 1464 of yacc.c  */
-#line 355 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) | (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 30:
-
-/* Line 1464 of yacc.c  */
-#line 358 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) ^ (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 31:
-
-/* Line 1464 of yacc.c  */
-#line 361 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) & (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 32:
-
-/* Line 1464 of yacc.c  */
-#line 364 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) != (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 33:
-
-/* Line 1464 of yacc.c  */
-#line 367 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) == (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 34:
-
-/* Line 1464 of yacc.c  */
-#line 370 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) >= (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 35:
-
-/* Line 1464 of yacc.c  */
-#line 373 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) <= (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 36:
-
-/* Line 1464 of yacc.c  */
-#line 376 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) > (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 37:
-
-/* Line 1464 of yacc.c  */
-#line 379 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) < (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 38:
-
-/* Line 1464 of yacc.c  */
-#line 382 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) >> (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 39:
-
-/* Line 1464 of yacc.c  */
-#line 385 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) << (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 40:
-
-/* Line 1464 of yacc.c  */
-#line 388 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) - (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 41:
-
-/* Line 1464 of yacc.c  */
-#line 391 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) + (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 42:
-
-/* Line 1464 of yacc.c  */
-#line 394 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) % (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 43:
-
-/* Line 1464 of yacc.c  */
-#line 397 "glcpp/glcpp-parse.y"
-    {
-		if ((yyvsp[(3) - (3)].ival) == 0) {
-			yyerror (& (yylsp[(1) - (3)]), parser,
-				 "division by 0 in preprocessor directive");
-		} else {
-			(yyval.ival) = (yyvsp[(1) - (3)].ival) / (yyvsp[(3) - (3)].ival);
-		}
-	;}
-    break;
-
-  case 44:
-
-/* Line 1464 of yacc.c  */
-#line 405 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(1) - (3)].ival) * (yyvsp[(3) - (3)].ival);
-	;}
-    break;
-
-  case 45:
-
-/* Line 1464 of yacc.c  */
-#line 408 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = ! (yyvsp[(2) - (2)].ival);
-	;}
-    break;
-
-  case 46:
-
-/* Line 1464 of yacc.c  */
-#line 411 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = ~ (yyvsp[(2) - (2)].ival);
-	;}
-    break;
-
-  case 47:
-
-/* Line 1464 of yacc.c  */
-#line 414 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = - (yyvsp[(2) - (2)].ival);
-	;}
-    break;
-
-  case 48:
-
-/* Line 1464 of yacc.c  */
-#line 417 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = + (yyvsp[(2) - (2)].ival);
-	;}
-    break;
-
-  case 49:
-
-/* Line 1464 of yacc.c  */
-#line 420 "glcpp/glcpp-parse.y"
-    {
-		(yyval.ival) = (yyvsp[(2) - (3)].ival);
-	;}
-    break;
-
-  case 50:
-
-/* Line 1464 of yacc.c  */
-#line 426 "glcpp/glcpp-parse.y"
-    {
-		(yyval.string_list) = _string_list_create (parser);
-		_string_list_append_item ((yyval.string_list), (yyvsp[(1) - (1)].str));
-		talloc_steal ((yyval.string_list), (yyvsp[(1) - (1)].str));
-	;}
-    break;
-
-  case 51:
-
-/* Line 1464 of yacc.c  */
-#line 431 "glcpp/glcpp-parse.y"
-    {
-		(yyval.string_list) = (yyvsp[(1) - (3)].string_list);	
-		_string_list_append_item ((yyval.string_list), (yyvsp[(3) - (3)].str));
-		talloc_steal ((yyval.string_list), (yyvsp[(3) - (3)].str));
-	;}
-    break;
-
-  case 52:
-
-/* Line 1464 of yacc.c  */
-#line 439 "glcpp/glcpp-parse.y"
-    { (yyval.token_list) = NULL; ;}
-    break;
-
-  case 54:
-
-/* Line 1464 of yacc.c  */
-#line 444 "glcpp/glcpp-parse.y"
-    {
-		yyerror (& (yylsp[(1) - (2)]), parser, "Invalid tokens after #");
-	;}
-    break;
-
-  case 55:
-
-/* Line 1464 of yacc.c  */
-#line 450 "glcpp/glcpp-parse.y"
-    { (yyval.token_list) = NULL; ;}
-    break;
-
-  case 58:
-
-/* Line 1464 of yacc.c  */
-#line 456 "glcpp/glcpp-parse.y"
-    {
-		glcpp_warning(&(yylsp[(1) - (1)]), parser, "extra tokens at end of directive");
-	;}
-    break;
-
-  case 59:
-
-/* Line 1464 of yacc.c  */
-#line 463 "glcpp/glcpp-parse.y"
-    {
-		int v = hash_table_find (parser->defines, (yyvsp[(2) - (2)].str)) ? 1 : 0;
-		(yyval.token) = _token_create_ival (parser, INTEGER, v);
-	;}
-    break;
-
-  case 60:
-
-/* Line 1464 of yacc.c  */
-#line 467 "glcpp/glcpp-parse.y"
-    {
-		int v = hash_table_find (parser->defines, (yyvsp[(3) - (4)].str)) ? 1 : 0;
-		(yyval.token) = _token_create_ival (parser, INTEGER, v);
-	;}
-    break;
-
-  case 62:
-
-/* Line 1464 of yacc.c  */
-#line 476 "glcpp/glcpp-parse.y"
-    {
-		(yyval.token_list) = _token_list_create (parser);
-		_token_list_append ((yyval.token_list), (yyvsp[(1) - (1)].token));
-	;}
-    break;
-
-  case 63:
-
-/* Line 1464 of yacc.c  */
-#line 480 "glcpp/glcpp-parse.y"
-    {
-		(yyval.token_list) = (yyvsp[(1) - (2)].token_list);
-		_token_list_append ((yyval.token_list), (yyvsp[(2) - (2)].token));
-	;}
-    break;
-
-  case 64:
-
-/* Line 1464 of yacc.c  */
-#line 487 "glcpp/glcpp-parse.y"
-    {
-		parser->space_tokens = 1;
-		(yyval.token_list) = _token_list_create (parser);
-		_token_list_append ((yyval.token_list), (yyvsp[(1) - (1)].token));
-	;}
-    break;
-
-  case 65:
-
-/* Line 1464 of yacc.c  */
-#line 492 "glcpp/glcpp-parse.y"
-    {
-		(yyval.token_list) = (yyvsp[(1) - (2)].token_list);
-		_token_list_append ((yyval.token_list), (yyvsp[(2) - (2)].token));
-	;}
-    break;
-
-  case 66:
-
-/* Line 1464 of yacc.c  */
-#line 499 "glcpp/glcpp-parse.y"
-    {
-		(yyval.token) = _token_create_str (parser, IDENTIFIER, (yyvsp[(1) - (1)].str));
-		(yyval.token)->location = yylloc;
-	;}
-    break;
-
-  case 67:
-
-/* Line 1464 of yacc.c  */
-#line 503 "glcpp/glcpp-parse.y"
-    {
-		(yyval.token) = _token_create_str (parser, INTEGER_STRING, (yyvsp[(1) - (1)].str));
-		(yyval.token)->location = yylloc;
-	;}
-    break;
-
-  case 68:
-
-/* Line 1464 of yacc.c  */
-#line 507 "glcpp/glcpp-parse.y"
-    {
-		(yyval.token) = _token_create_ival (parser, (yyvsp[(1) - (1)].ival), (yyvsp[(1) - (1)].ival));
-		(yyval.token)->location = yylloc;
-	;}
-    break;
-
-  case 69:
-
-/* Line 1464 of yacc.c  */
-#line 511 "glcpp/glcpp-parse.y"
-    {
-		(yyval.token) = _token_create_str (parser, OTHER, (yyvsp[(1) - (1)].str));
-		(yyval.token)->location = yylloc;
-	;}
-    break;
-
-  case 70:
-
-/* Line 1464 of yacc.c  */
-#line 515 "glcpp/glcpp-parse.y"
-    {
-		(yyval.token) = _token_create_ival (parser, SPACE, SPACE);
-		(yyval.token)->location = yylloc;
-	;}
-    break;
-
-  case 71:
-
-/* Line 1464 of yacc.c  */
-#line 522 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '['; ;}
-    break;
-
-  case 72:
-
-/* Line 1464 of yacc.c  */
-#line 523 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = ']'; ;}
-    break;
-
-  case 73:
-
-/* Line 1464 of yacc.c  */
-#line 524 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '('; ;}
-    break;
-
-  case 74:
-
-/* Line 1464 of yacc.c  */
-#line 525 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = ')'; ;}
-    break;
-
-  case 75:
-
-/* Line 1464 of yacc.c  */
-#line 526 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '{'; ;}
-    break;
-
-  case 76:
-
-/* Line 1464 of yacc.c  */
-#line 527 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '}'; ;}
-    break;
-
-  case 77:
-
-/* Line 1464 of yacc.c  */
-#line 528 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '.'; ;}
-    break;
-
-  case 78:
-
-/* Line 1464 of yacc.c  */
-#line 529 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '&'; ;}
-    break;
-
-  case 79:
-
-/* Line 1464 of yacc.c  */
-#line 530 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '*'; ;}
-    break;
-
-  case 80:
-
-/* Line 1464 of yacc.c  */
-#line 531 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '+'; ;}
-    break;
-
-  case 81:
-
-/* Line 1464 of yacc.c  */
-#line 532 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '-'; ;}
-    break;
-
-  case 82:
-
-/* Line 1464 of yacc.c  */
-#line 533 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '~'; ;}
-    break;
-
-  case 83:
-
-/* Line 1464 of yacc.c  */
-#line 534 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '!'; ;}
-    break;
-
-  case 84:
-
-/* Line 1464 of yacc.c  */
-#line 535 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '/'; ;}
-    break;
-
-  case 85:
-
-/* Line 1464 of yacc.c  */
-#line 536 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '%'; ;}
-    break;
-
-  case 86:
-
-/* Line 1464 of yacc.c  */
-#line 537 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = LEFT_SHIFT; ;}
-    break;
-
-  case 87:
-
-/* Line 1464 of yacc.c  */
-#line 538 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = RIGHT_SHIFT; ;}
-    break;
-
-  case 88:
-
-/* Line 1464 of yacc.c  */
-#line 539 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '<'; ;}
-    break;
-
-  case 89:
-
-/* Line 1464 of yacc.c  */
-#line 540 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '>'; ;}
-    break;
-
-  case 90:
-
-/* Line 1464 of yacc.c  */
-#line 541 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = LESS_OR_EQUAL; ;}
-    break;
-
-  case 91:
-
-/* Line 1464 of yacc.c  */
-#line 542 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = GREATER_OR_EQUAL; ;}
-    break;
-
-  case 92:
-
-/* Line 1464 of yacc.c  */
-#line 543 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = EQUAL; ;}
-    break;
-
-  case 93:
-
-/* Line 1464 of yacc.c  */
-#line 544 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = NOT_EQUAL; ;}
-    break;
-
-  case 94:
-
-/* Line 1464 of yacc.c  */
-#line 545 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '^'; ;}
-    break;
-
-  case 95:
-
-/* Line 1464 of yacc.c  */
-#line 546 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '|'; ;}
-    break;
-
-  case 96:
-
-/* Line 1464 of yacc.c  */
-#line 547 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = AND; ;}
-    break;
-
-  case 97:
-
-/* Line 1464 of yacc.c  */
-#line 548 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = OR; ;}
-    break;
-
-  case 98:
-
-/* Line 1464 of yacc.c  */
-#line 549 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = ';'; ;}
-    break;
-
-  case 99:
-
-/* Line 1464 of yacc.c  */
-#line 550 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = ','; ;}
-    break;
-
-  case 100:
-
-/* Line 1464 of yacc.c  */
-#line 551 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = '='; ;}
-    break;
-
-  case 101:
-
-/* Line 1464 of yacc.c  */
-#line 552 "glcpp/glcpp-parse.y"
-    { (yyval.ival) = PASTE; ;}
-    break;
-
-
-
-/* Line 1464 of yacc.c  */
-#line 2661 "glcpp/glcpp-parse.c"
-      default: break;
-    }
-  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
-
-  YYPOPSTACK (yylen);
-  yylen = 0;
-  YY_STACK_PRINT (yyss, yyssp);
-
-  *++yyvsp = yyval;
-  *++yylsp = yyloc;
-
-  /* Now `shift' the result of the reduction.  Determine what state
-     that goes to, based on the state we popped back to and the rule
-     number reduced by.  */
-
-  yyn = yyr1[yyn];
-
-  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
-  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
-    yystate = yytable[yystate];
-  else
-    yystate = yydefgoto[yyn - YYNTOKENS];
-
-  goto yynewstate;
-
-
-/*------------------------------------.
-| yyerrlab -- here on detecting error |
-`------------------------------------*/
-yyerrlab:
-  /* If not already recovering from an error, report this error.  */
-  if (!yyerrstatus)
-    {
-      ++yynerrs;
-#if ! YYERROR_VERBOSE
-      yyerror (&yylloc, parser, YY_("syntax error"));
-#else
-      {
-	YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
-	if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
-	  {
-	    YYSIZE_T yyalloc = 2 * yysize;
-	    if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
-	      yyalloc = YYSTACK_ALLOC_MAXIMUM;
-	    if (yymsg != yymsgbuf)
-	      YYSTACK_FREE (yymsg);
-	    yymsg = (char *) YYSTACK_ALLOC (yyalloc);
-	    if (yymsg)
-	      yymsg_alloc = yyalloc;
-	    else
-	      {
-		yymsg = yymsgbuf;
-		yymsg_alloc = sizeof yymsgbuf;
-	      }
-	  }
-
-	if (0 < yysize && yysize <= yymsg_alloc)
-	  {
-	    (void) yysyntax_error (yymsg, yystate, yychar);
-	    yyerror (&yylloc, parser, yymsg);
-	  }
-	else
-	  {
-	    yyerror (&yylloc, parser, YY_("syntax error"));
-	    if (yysize != 0)
-	      goto yyexhaustedlab;
-	  }
-      }
-#endif
-    }
-
-  yyerror_range[1] = yylloc;
-
-  if (yyerrstatus == 3)
-    {
-      /* If just tried and failed to reuse lookahead token after an
-	 error, discard it.  */
-
-      if (yychar <= YYEOF)
-	{
-	  /* Return failure if at end of input.  */
-	  if (yychar == YYEOF)
-	    YYABORT;
-	}
-      else
-	{
-	  yydestruct ("Error: discarding",
-		      yytoken, &yylval, &yylloc, parser);
-	  yychar = YYEMPTY;
-	}
-    }
-
-  /* Else will try to reuse lookahead token after shifting the error
-     token.  */
-  goto yyerrlab1;
-
-
-/*---------------------------------------------------.
-| yyerrorlab -- error raised explicitly by YYERROR.  |
-`---------------------------------------------------*/
-yyerrorlab:
-
-  /* Pacify compilers like GCC when the user code never invokes
-     YYERROR and the label yyerrorlab therefore never appears in user
-     code.  */
-  if (/*CONSTCOND*/ 0)
-     goto yyerrorlab;
-
-  yyerror_range[1] = yylsp[1-yylen];
-  /* Do not reclaim the symbols of the rule which action triggered
-     this YYERROR.  */
-  YYPOPSTACK (yylen);
-  yylen = 0;
-  YY_STACK_PRINT (yyss, yyssp);
-  yystate = *yyssp;
-  goto yyerrlab1;
-
-
-/*-------------------------------------------------------------.
-| yyerrlab1 -- common code for both syntax error and YYERROR.  |
-`-------------------------------------------------------------*/
-yyerrlab1:
-  yyerrstatus = 3;	/* Each real token shifted decrements this.  */
-
-  for (;;)
-    {
-      yyn = yypact[yystate];
-      if (yyn != YYPACT_NINF)
-	{
-	  yyn += YYTERROR;
-	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
-	    {
-	      yyn = yytable[yyn];
-	      if (0 < yyn)
-		break;
-	    }
-	}
-
-      /* Pop the current state because it cannot handle the error token.  */
-      if (yyssp == yyss)
-	YYABORT;
-
-      yyerror_range[1] = *yylsp;
-      yydestruct ("Error: popping",
-		  yystos[yystate], yyvsp, yylsp, parser);
-      YYPOPSTACK (1);
-      yystate = *yyssp;
-      YY_STACK_PRINT (yyss, yyssp);
-    }
-
-  *++yyvsp = yylval;
-
-  yyerror_range[2] = yylloc;
-  /* Using YYLLOC is tempting, but would change the location of
-     the lookahead.  YYLOC is available though.  */
-  YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
-  *++yylsp = yyloc;
-
-  /* Shift the error token.  */
-  YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
-
-  yystate = yyn;
-  goto yynewstate;
-
-
-/*-------------------------------------.
-| yyacceptlab -- YYACCEPT comes here.  |
-`-------------------------------------*/
-yyacceptlab:
-  yyresult = 0;
-  goto yyreturn;
-
-/*-----------------------------------.
-| yyabortlab -- YYABORT comes here.  |
-`-----------------------------------*/
-yyabortlab:
-  yyresult = 1;
-  goto yyreturn;
-
-#if !defined(yyoverflow) || YYERROR_VERBOSE
-/*-------------------------------------------------.
-| yyexhaustedlab -- memory exhaustion comes here.  |
-`-------------------------------------------------*/
-yyexhaustedlab:
-  yyerror (&yylloc, parser, YY_("memory exhausted"));
-  yyresult = 2;
-  /* Fall through.  */
-#endif
-
-yyreturn:
-  if (yychar != YYEMPTY)
-     yydestruct ("Cleanup: discarding lookahead",
-		 yytoken, &yylval, &yylloc, parser);
-  /* Do not reclaim the symbols of the rule which action triggered
-     this YYABORT or YYACCEPT.  */
-  YYPOPSTACK (yylen);
-  YY_STACK_PRINT (yyss, yyssp);
-  while (yyssp != yyss)
-    {
-      yydestruct ("Cleanup: popping",
-		  yystos[*yyssp], yyvsp, yylsp, parser);
-      YYPOPSTACK (1);
-    }
-#ifndef yyoverflow
-  if (yyss != yyssa)
-    YYSTACK_FREE (yyss);
-#endif
-#if YYERROR_VERBOSE
-  if (yymsg != yymsgbuf)
-    YYSTACK_FREE (yymsg);
-#endif
-  /* Make sure YYID is used.  */
-  return YYID (yyresult);
-}
-
-
-
-/* Line 1684 of yacc.c  */
-#line 555 "glcpp/glcpp-parse.y"
-
-
-string_list_t *
-_string_list_create (void *ctx)
-{
-	string_list_t *list;
-
-	list = talloc (ctx, string_list_t);
-	list->head = NULL;
-	list->tail = NULL;
-
-	return list;
-}
-
-void
-_string_list_append_item (string_list_t *list, const char *str)
-{
-	string_node_t *node;
-
-	node = talloc (list, string_node_t);
-	node->str = talloc_strdup (node, str);
-
-	node->next = NULL;
-
-	if (list->head == NULL) {
-		list->head = node;
-	} else {
-		list->tail->next = node;
-	}
-
-	list->tail = node;
-}
-
-int
-_string_list_contains (string_list_t *list, const char *member, int *index)
-{
-	string_node_t *node;
-	int i;
-
-	if (list == NULL)
-		return 0;
-
-	for (i = 0, node = list->head; node; i++, node = node->next) {
-		if (strcmp (node->str, member) == 0) {
-			if (index)
-				*index = i;
-			return 1;
-		}
-	}
-
-	return 0;
-}
-
-int
-_string_list_length (string_list_t *list)
-{
-	int length = 0;
-	string_node_t *node;
-
-	if (list == NULL)
-		return 0;
-
-	for (node = list->head; node; node = node->next)
-		length++;
-
-	return length;
-}
-
-int
-_string_list_equal (string_list_t *a, string_list_t *b)
-{
-	string_node_t *node_a, *node_b;
-
-	if (a == NULL && b == NULL)
-		return 1;
-
-	if (a == NULL || b == NULL)
-		return 0;
-
-	for (node_a = a->head, node_b = b->head;
-	     node_a && node_b;
-	     node_a = node_a->next, node_b = node_b->next)
-	{
-		if (strcmp (node_a->str, node_b->str))
-			return 0;
-	}
-
-	/* Catch the case of lists being different lengths, (which
-	 * would cause the loop above to terminate after the shorter
-	 * list). */
-	return node_a == node_b;
-}
-
-argument_list_t *
-_argument_list_create (void *ctx)
-{
-	argument_list_t *list;
-
-	list = talloc (ctx, argument_list_t);
-	list->head = NULL;
-	list->tail = NULL;
-
-	return list;
-}
-
-void
-_argument_list_append (argument_list_t *list, token_list_t *argument)
-{
-	argument_node_t *node;
-
-	node = talloc (list, argument_node_t);
-	node->argument = argument;
-
-	node->next = NULL;
-
-	if (list->head == NULL) {
-		list->head = node;
-	} else {
-		list->tail->next = node;
-	}
-
-	list->tail = node;
-}
-
-int
-_argument_list_length (argument_list_t *list)
-{
-	int length = 0;
-	argument_node_t *node;
-
-	if (list == NULL)
-		return 0;
-
-	for (node = list->head; node; node = node->next)
-		length++;
-
-	return length;
-}
-
-token_list_t *
-_argument_list_member_at (argument_list_t *list, int index)
-{
-	argument_node_t *node;
-	int i;
-
-	if (list == NULL)
-		return NULL;
-
-	node = list->head;
-	for (i = 0; i < index; i++) {
-		node = node->next;
-		if (node == NULL)
-			break;
-	}
-
-	if (node)
-		return node->argument;
-
-	return NULL;
-}
-
-/* Note: This function talloc_steal()s the str pointer. */
-token_t *
-_token_create_str (void *ctx, int type, char *str)
-{
-	token_t *token;
-
-	token = talloc (ctx, token_t);
-	token->type = type;
-	token->value.str = talloc_steal (token, str);
-
-	return token;
-}
-
-token_t *
-_token_create_ival (void *ctx, int type, int ival)
-{
-	token_t *token;
-
-	token = talloc (ctx, token_t);
-	token->type = type;
-	token->value.ival = ival;
-
-	return token;
-}
-
-token_list_t *
-_token_list_create (void *ctx)
-{
-	token_list_t *list;
-
-	list = talloc (ctx, token_list_t);
-	list->head = NULL;
-	list->tail = NULL;
-	list->non_space_tail = NULL;
-
-	return list;
-}
-
-void
-_token_list_append (token_list_t *list, token_t *token)
-{
-	token_node_t *node;
-
-	node = talloc (list, token_node_t);
-	node->token = talloc_steal (list, token);
-
-	node->next = NULL;
-
-	if (list->head == NULL) {
-		list->head = node;
-	} else {
-		list->tail->next = node;
-	}
-
-	list->tail = node;
-	if (token->type != SPACE)
-		list->non_space_tail = node;
-}
-
-void
-_token_list_append_list (token_list_t *list, token_list_t *tail)
-{
-	if (tail == NULL || tail->head == NULL)
-		return;
-
-	if (list->head == NULL) {
-		list->head = tail->head;
-	} else {
-		list->tail->next = tail->head;
-	}
-
-	list->tail = tail->tail;
-	list->non_space_tail = tail->non_space_tail;
-}
-
-static token_list_t *
-_token_list_copy (void *ctx, token_list_t *other)
-{
-	token_list_t *copy;
-	token_node_t *node;
-
-	if (other == NULL)
-		return NULL;
-
-	copy = _token_list_create (ctx);
-	for (node = other->head; node; node = node->next) {
-		token_t *new_token = talloc (copy, token_t);
-		*new_token = *node->token;
-		_token_list_append (copy, new_token);
-	}
-
-	return copy;
-}
-
-static void
-_token_list_trim_trailing_space (token_list_t *list)
-{
-	token_node_t *tail, *next;
-
-	if (list->non_space_tail) {
-		tail = list->non_space_tail->next;
-		list->non_space_tail->next = NULL;
-		list->tail = list->non_space_tail;
-
-		while (tail) {
-			next = tail->next;
-			talloc_free (tail);
-			tail = next;
-		}
-	}
-}
-
-int
-_token_list_is_empty_ignoring_space (token_list_t *l)
-{
-	token_node_t *n;
-
-	if (l == NULL)
-		return 1;
-
-	n = l->head;
-	while (n != NULL && n->token->type == SPACE)
-		n = n->next;
-
-	return n == NULL;
-}
-
-int
-_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b)
-{
-	token_node_t *node_a, *node_b;
-
-	if (a == NULL || b == NULL) {
-		int a_empty = _token_list_is_empty_ignoring_space(a);
-		int b_empty = _token_list_is_empty_ignoring_space(b);
-		return a_empty == b_empty;
-	}
-
-	node_a = a->head;
-	node_b = b->head;
-
-	while (1)
-	{
-		if (node_a == NULL && node_b == NULL)
-			break;
-
-		if (node_a == NULL || node_b == NULL)
-			return 0;
-
-		if (node_a->token->type == SPACE) {
-			node_a = node_a->next;
-			continue;
-		}
-
-		if (node_b->token->type == SPACE) {
-			node_b = node_b->next;
-			continue;
-		}
-
-		if (node_a->token->type != node_b->token->type)
-			return 0;
-
-		switch (node_a->token->type) {
-		case INTEGER:
-			if (node_a->token->value.ival != 
-			    node_b->token->value.ival)
-			{
-				return 0;
-			}
-			break;
-		case IDENTIFIER:
-		case INTEGER_STRING:
-		case OTHER:
-			if (strcmp (node_a->token->value.str,
-				    node_b->token->value.str))
-			{
-				return 0;
-			}
-			break;
-		}
-
-		node_a = node_a->next;
-		node_b = node_b->next;
-	}
-
-	return 1;
-}
-
-static void
-_token_print (char **out, token_t *token)
-{
-	if (token->type < 256) {
-		glcpp_printf (*out, "%c", token->type);
-		return;
-	}
-
-	switch (token->type) {
-	case INTEGER:
-		glcpp_printf (*out, "%" PRIiMAX, token->value.ival);
-		break;
-	case IDENTIFIER:
-	case INTEGER_STRING:
-	case OTHER:
-		glcpp_print (*out, token->value.str);
-		break;
-	case SPACE:
-		glcpp_print (*out, " ");
-		break;
-	case LEFT_SHIFT:
-		glcpp_print (*out, "<<");
-		break;
-	case RIGHT_SHIFT:
-		glcpp_print (*out, ">>");
-		break;
-	case LESS_OR_EQUAL:
-		glcpp_print (*out, "<=");
-		break;
-	case GREATER_OR_EQUAL:
-		glcpp_print (*out, ">=");
-		break;
-	case EQUAL:
-		glcpp_print (*out, "==");
-		break;
-	case NOT_EQUAL:
-		glcpp_print (*out, "!=");
-		break;
-	case AND:
-		glcpp_print (*out, "&&");
-		break;
-	case OR:
-		glcpp_print (*out, "||");
-		break;
-	case PASTE:
-		glcpp_print (*out, "##");
-		break;
-	case COMMA_FINAL:
-		glcpp_print (*out, ",");
-		break;
-	case PLACEHOLDER:
-		/* Nothing to print. */
-		break;
-	default:
-		assert(!"Error: Don't know how to print token.");
-		break;
-	}
-}
-
-/* Return a new token (talloc()ed off of 'token') formed by pasting
- * 'token' and 'other'. Note that this function may return 'token' or
- * 'other' directly rather than allocating anything new.
- *
- * Caution: Only very cursory error-checking is performed to see if
- * the final result is a valid single token. */
-static token_t *
-_token_paste (glcpp_parser_t *parser, token_t *token, token_t *other)
-{
-	token_t *combined = NULL;
-
-	/* Pasting a placeholder onto anything makes no change. */
-	if (other->type == PLACEHOLDER)
-		return token;
-
-	/* When 'token' is a placeholder, just return 'other'. */
-	if (token->type == PLACEHOLDER)
-		return other;
-
-	/* A very few single-character punctuators can be combined
-	 * with another to form a multi-character punctuator. */
-	switch (token->type) {
-	case '<':
-		if (other->type == '<')
-			combined = _token_create_ival (token, LEFT_SHIFT, LEFT_SHIFT);
-		else if (other->type == '=')
-			combined = _token_create_ival (token, LESS_OR_EQUAL, LESS_OR_EQUAL);
-		break;
-	case '>':
-		if (other->type == '>')
-			combined = _token_create_ival (token, RIGHT_SHIFT, RIGHT_SHIFT);
-		else if (other->type == '=')
-			combined = _token_create_ival (token, GREATER_OR_EQUAL, GREATER_OR_EQUAL);
-		break;
-	case '=':
-		if (other->type == '=')
-			combined = _token_create_ival (token, EQUAL, EQUAL);
-		break;
-	case '!':
-		if (other->type == '=')
-			combined = _token_create_ival (token, NOT_EQUAL, NOT_EQUAL);
-		break;
-	case '&':
-		if (other->type == '&')
-			combined = _token_create_ival (token, AND, AND);
-		break;
-	case '|':
-		if (other->type == '|')
-			combined = _token_create_ival (token, OR, OR);
-		break;
-	}
-
-	if (combined != NULL) {
-		/* Inherit the location from the first token */
-		combined->location = token->location;
-		return combined;
-	}
-
-	/* Two string-valued tokens can usually just be mashed
-	 * together.
-	 *
-	 * XXX: This isn't actually legitimate. Several things here
-	 * should result in a diagnostic since the result cannot be a
-	 * valid, single pre-processing token. For example, pasting
-	 * "123" and "abc" is not legal, but we don't catch that
-	 * here. */
-	if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING) &&
-	    (other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING))
-	{
-		char *str;
-
-		str = talloc_asprintf (token, "%s%s", token->value.str,
-				       other->value.str);
-		combined = _token_create_str (token, token->type, str);
-		combined->location = token->location;
-		return combined;
-	}
-
-	glcpp_error (&token->location, parser, "");
-	glcpp_print (parser->info_log, "Pasting \"");
-	_token_print (&parser->info_log, token);
-	glcpp_print (parser->info_log, "\" and \"");
-	_token_print (&parser->info_log, other);
-	glcpp_print (parser->info_log, "\" does not give a valid preprocessing token.\n");
-
-	return token;
-}
-
-static void
-_token_list_print (glcpp_parser_t *parser, token_list_t *list)
-{
-	token_node_t *node;
-
-	if (list == NULL)
-		return;
-
-	for (node = list->head; node; node = node->next)
-		_token_print (&parser->output, node->token);
-}
-
-void
-yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
-{
-	glcpp_error(locp, parser, "%s", error);
-}
-
-static void add_builtin_define(glcpp_parser_t *parser,
-			       const char *name, int value)
-{
-   token_t *tok;
-   token_list_t *list;
-
-   tok = _token_create_ival (parser, INTEGER, value);
-
-   list = _token_list_create(parser);
-   _token_list_append(list, tok);
-   _define_object_macro(parser, NULL, name, list);
-}
-
-glcpp_parser_t *
-glcpp_parser_create (const struct gl_extensions *extensions, int api)
-{
-	glcpp_parser_t *parser;
-	int language_version;
-
-	parser = talloc (NULL, glcpp_parser_t);
-
-	glcpp_lex_init_extra (parser, &parser->scanner);
-	parser->defines = hash_table_ctor (32, hash_table_string_hash,
-					   hash_table_string_compare);
-	parser->active = NULL;
-	parser->lexing_if = 0;
-	parser->space_tokens = 1;
-	parser->newline_as_space = 0;
-	parser->in_control_line = 0;
-	parser->paren_count = 0;
-
-	parser->skip_stack = NULL;
-
-	parser->lex_from_list = NULL;
-	parser->lex_from_node = NULL;
-
-	parser->output = talloc_strdup(parser, "");
-	parser->info_log = talloc_strdup(parser, "");
-	parser->error = 0;
-
-	/* Add pre-defined macros. */
-	add_builtin_define(parser, "GL_ARB_draw_buffers", 1);
-	add_builtin_define(parser, "GL_ARB_texture_rectangle", 1);
-
-	if (api == API_OPENGLES2)
-		add_builtin_define(parser, "GL_ES", 1);
-
-	if (extensions != NULL) {
-	   if (extensions->EXT_texture_array) {
-	      add_builtin_define(parser, "GL_EXT_texture_array", 1);
-	   }
-
-	   if (extensions->ARB_fragment_coord_conventions)
-	      add_builtin_define(parser, "GL_ARB_fragment_coord_conventions",
-				 1);
-
-	   if (extensions->ARB_explicit_attrib_location)
-	      add_builtin_define(parser, "GL_ARB_explicit_attrib_location", 1);
-	   if (extensions->AMD_conservative_depth)
-	      add_builtin_define(parser, "GL_AMD_conservative_depth", 1);
-	}
-
-	language_version = 110;
-	add_builtin_define(parser, "__VERSION__", language_version);
-
-	return parser;
-}
-
-int
-glcpp_parser_parse (glcpp_parser_t *parser)
-{
-	return yyparse (parser);
-}
-
-void
-glcpp_parser_destroy (glcpp_parser_t *parser)
-{
-	glcpp_lex_destroy (parser->scanner);
-	hash_table_dtor (parser->defines);
-	talloc_free (parser);
-}
-
-typedef enum function_status
-{
-	FUNCTION_STATUS_SUCCESS,
-	FUNCTION_NOT_A_FUNCTION,
-	FUNCTION_UNBALANCED_PARENTHESES
-} function_status_t;
-
-/* Find a set of function-like macro arguments by looking for a
- * balanced set of parentheses.
- *
- * When called, 'node' should be the opening-parenthesis token, (or
- * perhaps preceeding SPACE tokens). Upon successful return *last will
- * be the last consumed node, (corresponding to the closing right
- * parenthesis).
- *
- * Return values:
- *
- *   FUNCTION_STATUS_SUCCESS:
- *
- *	Successfully parsed a set of function arguments.	
- *
- *   FUNCTION_NOT_A_FUNCTION:
- *
- *	Macro name not followed by a '('. This is not an error, but
- *	simply that the macro name should be treated as a non-macro.
- *
- *   FUNCTION_UNBALANCED_PARENTHESES
- *
- *	Macro name is not followed by a balanced set of parentheses.
- */
-static function_status_t
-_arguments_parse (argument_list_t *arguments,
-		  token_node_t *node,
-		  token_node_t **last)
-{
-	token_list_t *argument;
-	int paren_count;
-
-	node = node->next;
-
-	/* Ignore whitespace before first parenthesis. */
-	while (node && node->token->type == SPACE)
-		node = node->next;
-
-	if (node == NULL || node->token->type != '(')
-		return FUNCTION_NOT_A_FUNCTION;
-
-	node = node->next;
-
-	argument = _token_list_create (arguments);
-	_argument_list_append (arguments, argument);
-
-	for (paren_count = 1; node; node = node->next) {
-		if (node->token->type == '(')
-		{
-			paren_count++;
-		}
-		else if (node->token->type == ')')
-		{
-			paren_count--;
-			if (paren_count == 0)
-				break;
-		}
-
-		if (node->token->type == ',' &&
-			 paren_count == 1)
-		{
-			_token_list_trim_trailing_space (argument);
-			argument = _token_list_create (arguments);
-			_argument_list_append (arguments, argument);
-		}
-		else {
-			if (argument->head == NULL) {
-				/* Don't treat initial whitespace as
-				 * part of the arguement. */
-				if (node->token->type == SPACE)
-					continue;
-			}
-			_token_list_append (argument, node->token);
-		}
-	}
-
-	if (paren_count)
-		return FUNCTION_UNBALANCED_PARENTHESES;
-
-	*last = node;
-
-	return FUNCTION_STATUS_SUCCESS;
-}
-
-static token_list_t *
-_token_list_create_with_one_space (void *ctx)
-{
-	token_list_t *list;
-	token_t *space;
-
-	list = _token_list_create (ctx);
-	space = _token_create_ival (list, SPACE, SPACE);
-	_token_list_append (list, space);
-
-	return list;
-}
-
-static void
-_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list)
-{
-	token_list_t *expanded;
-	token_t *token;
-
-	expanded = _token_list_create (parser);
-	token = _token_create_ival (parser, type, type);
-	_token_list_append (expanded, token);
-	_glcpp_parser_expand_token_list (parser, list);
-	_token_list_append_list (expanded, list);
-	glcpp_parser_lex_from (parser, expanded);
-}
-
-/* This is a helper function that's essentially part of the
- * implementation of _glcpp_parser_expand_node. It shouldn't be called
- * except for by that function.
- *
- * Returns NULL if node is a simple token with no expansion, (that is,
- * although 'node' corresponds to an identifier defined as a
- * function-like macro, it is not followed with a parenthesized
- * argument list).
- *
- * Compute the complete expansion of node (which is a function-like
- * macro) and subsequent nodes which are arguments.
- *
- * Returns the token list that results from the expansion and sets
- * *last to the last node in the list that was consumed by the
- * expansion. Specifically, *last will be set as follows: as the
- * token of the closing right parenthesis.
- */
-static token_list_t *
-_glcpp_parser_expand_function (glcpp_parser_t *parser,
-			       token_node_t *node,
-			       token_node_t **last)
-			       
-{
-	macro_t *macro;
-	const char *identifier;
-	argument_list_t *arguments;
-	function_status_t status;
-	token_list_t *substituted;
-	int parameter_index;
-
-	identifier = node->token->value.str;
-
-	macro = hash_table_find (parser->defines, identifier);
-
-	assert (macro->is_function);
-
-	arguments = _argument_list_create (parser);
-	status = _arguments_parse (arguments, node, last);
-
-	switch (status) {
-	case FUNCTION_STATUS_SUCCESS:
-		break;
-	case FUNCTION_NOT_A_FUNCTION:
-		return NULL;
-	case FUNCTION_UNBALANCED_PARENTHESES:
-		glcpp_error (&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identifier);
-		return NULL;
-	}
-
-	/* Replace a macro defined as empty with a SPACE token. */
-	if (macro->replacements == NULL) {
-		talloc_free (arguments);
-		return _token_list_create_with_one_space (parser);
-	}
-
-	if (! ((_argument_list_length (arguments) == 
-		_string_list_length (macro->parameters)) ||
-	       (_string_list_length (macro->parameters) == 0 &&
-		_argument_list_length (arguments) == 1 &&
-		arguments->head->argument->head == NULL)))
-	{
-		glcpp_error (&node->token->location, parser,
-			      "Error: macro %s invoked with %d arguments (expected %d)\n",
-			      identifier,
-			      _argument_list_length (arguments),
-			      _string_list_length (macro->parameters));
-		return NULL;
-	}
-
-	/* Perform argument substitution on the replacement list. */
-	substituted = _token_list_create (arguments);
-
-	for (node = macro->replacements->head; node; node = node->next)
-	{
-		if (node->token->type == IDENTIFIER &&
-		    _string_list_contains (macro->parameters,
-					   node->token->value.str,
-					   &parameter_index))
-		{
-			token_list_t *argument;
-			argument = _argument_list_member_at (arguments,
-							     parameter_index);
-			/* Before substituting, we expand the argument
-			 * tokens, or append a placeholder token for
-			 * an empty argument. */
-			if (argument->head) {
-				token_list_t *expanded_argument;
-				expanded_argument = _token_list_copy (parser,
-								      argument);
-				_glcpp_parser_expand_token_list (parser,
-								 expanded_argument);
-				_token_list_append_list (substituted,
-							 expanded_argument);
-			} else {
-				token_t *new_token;
-
-				new_token = _token_create_ival (substituted,
-								PLACEHOLDER,
-								PLACEHOLDER);
-				_token_list_append (substituted, new_token);
-			}
-		} else {
-			_token_list_append (substituted, node->token);
-		}
-	}
-
-	/* After argument substitution, and before further expansion
-	 * below, implement token pasting. */
-
-	_token_list_trim_trailing_space (substituted);
-
-	node = substituted->head;
-	while (node)
-	{
-		token_node_t *next_non_space;
-
-		/* Look ahead for a PASTE token, skipping space. */
-		next_non_space = node->next;
-		while (next_non_space && next_non_space->token->type == SPACE)
-			next_non_space = next_non_space->next;
-
-		if (next_non_space == NULL)
-			break;
-
-		if (next_non_space->token->type != PASTE) {
-			node = next_non_space;
-			continue;
-		}
-
-		/* Now find the next non-space token after the PASTE. */
-		next_non_space = next_non_space->next;
-		while (next_non_space && next_non_space->token->type == SPACE)
-			next_non_space = next_non_space->next;
-
-		if (next_non_space == NULL) {
-			yyerror (&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n");
-			return NULL;
-		}
-
-		node->token = _token_paste (parser, node->token, next_non_space->token);
-		node->next = next_non_space->next;
-		if (next_non_space == substituted->tail)
-			substituted->tail = node;
-
-		node = node->next;
-	}
-
-	substituted->non_space_tail = substituted->tail;
-
-	return substituted;
-}
-
-/* Compute the complete expansion of node, (and subsequent nodes after
- * 'node' in the case that 'node' is a function-like macro and
- * subsequent nodes are arguments).
- *
- * Returns NULL if node is a simple token with no expansion.
- *
- * Otherwise, returns the token list that results from the expansion
- * and sets *last to the last node in the list that was consumed by
- * the expansion. Specifically, *last will be set as follows:
- *
- *	As 'node' in the case of object-like macro expansion.
- *
- *	As the token of the closing right parenthesis in the case of
- *	function-like macro expansion.
- */
-static token_list_t *
-_glcpp_parser_expand_node (glcpp_parser_t *parser,
-			   token_node_t *node,
-			   token_node_t **last)
-{
-	token_t *token = node->token;
-	const char *identifier;
-	macro_t *macro;
-
-	/* We only expand identifiers */
-	if (token->type != IDENTIFIER) {
-		/* We change any COMMA into a COMMA_FINAL to prevent
-		 * it being mistaken for an argument separator
-		 * later. */
-		if (token->type == ',') {
-			token->type = COMMA_FINAL;
-			token->value.ival = COMMA_FINAL;
-		}
-
-		return NULL;
-	}
-
-	/* Look up this identifier in the hash table. */
-	identifier = token->value.str;
-	macro = hash_table_find (parser->defines, identifier);
-
-	/* Not a macro, so no expansion needed. */
-	if (macro == NULL)
-		return NULL;
-
-	/* Finally, don't expand this macro if we're already actively
-	 * expanding it, (to avoid infinite recursion). */
-	if (_active_list_contains (parser->active, identifier)) {
-		/* We change the token type here from IDENTIFIER to
-		 * OTHER to prevent any future expansion of this
-		 * unexpanded token. */
-		char *str;
-		token_list_t *expansion;
-		token_t *final;
-
-		str = talloc_strdup (parser, token->value.str);
-		final = _token_create_str (parser, OTHER, str);
-		expansion = _token_list_create (parser);
-		_token_list_append (expansion, final);
-		*last = node;
-		return expansion;
-	}
-
-	if (! macro->is_function)
-	{
-		*last = node;
-
-		/* Replace a macro defined as empty with a SPACE token. */
-		if (macro->replacements == NULL)
-			return _token_list_create_with_one_space (parser);
-
-		return _token_list_copy (parser, macro->replacements);
-	}
-
-	return _glcpp_parser_expand_function (parser, node, last);
-}
-
-/* Push a new identifier onto the active list, returning the new list.
- *
- * Here, 'marker' is the token node that appears in the list after the
- * expansion of 'identifier'. That is, when the list iterator begins
- * examinging 'marker', then it is time to pop this node from the
- * active stack.
- */
-active_list_t *
-_active_list_push (active_list_t *list,
-		   const char *identifier,
-		   token_node_t *marker)
-{
-	active_list_t *node;
-
-	node = talloc (list, active_list_t);
-	node->identifier = talloc_strdup (node, identifier);
-	node->marker = marker;
-	node->next = list;
-
-	return node;
-}
-
-active_list_t *
-_active_list_pop (active_list_t *list)
-{
-	active_list_t *node = list;
-
-	if (node == NULL)
-		return NULL;
-
-	node = list->next;
-	talloc_free (list);
-
-	return node;
-}
-
-int
-_active_list_contains (active_list_t *list, const char *identifier)
-{
-	active_list_t *node;
-
-	if (list == NULL)
-		return 0;
-
-	for (node = list; node; node = node->next)
-		if (strcmp (node->identifier, identifier) == 0)
-			return 1;
-
-	return 0;
-}
-
-/* Walk over the token list replacing nodes with their expansion.
- * Whenever nodes are expanded the walking will walk over the new
- * nodes, continuing to expand as necessary. The results are placed in
- * 'list' itself;
- */
-static void
-_glcpp_parser_expand_token_list (glcpp_parser_t *parser,
-				 token_list_t *list)
-{
-	token_node_t *node_prev;
-	token_node_t *node, *last = NULL;
-	token_list_t *expansion;
-
-	if (list == NULL)
-		return;
-
-	_token_list_trim_trailing_space (list);
-
-	node_prev = NULL;
-	node = list->head;
-
-	while (node) {
-
-		while (parser->active && parser->active->marker == node)
-			parser->active = _active_list_pop (parser->active);
-
-		/* Find the expansion for node, which will replace all
-		 * nodes from node to last, inclusive. */
-		expansion = _glcpp_parser_expand_node (parser, node, &last);
-		if (expansion) {
-			token_node_t *n;
-
-			for (n = node; n != last->next; n = n->next)
-				while (parser->active &&
-				       parser->active->marker == n)
-				{
-					parser->active = _active_list_pop (parser->active);
-				}
-
-			parser->active = _active_list_push (parser->active,
-							    node->token->value.str,
-							    last->next);
-			
-			/* Splice expansion into list, supporting a
-			 * simple deletion if the expansion is
-			 * empty. */
-			if (expansion->head) {
-				if (node_prev)
-					node_prev->next = expansion->head;
-				else
-					list->head = expansion->head;
-				expansion->tail->next = last->next;
-				if (last == list->tail)
-					list->tail = expansion->tail;
-			} else {
-				if (node_prev)
-					node_prev->next = last->next;
-				else
-					list->head = last->next;
-				if (last == list->tail)
-					list->tail = NULL;
-			}
-		} else {
-			node_prev = node;
-		}
-		node = node_prev ? node_prev->next : list->head;
-	}
-
-	while (parser->active)
-		parser->active = _active_list_pop (parser->active);
-
-	list->non_space_tail = list->tail;
-}
-
-void
-_glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
-					 token_list_t *list)
-{
-	if (list == NULL)
-		return;
-
-	_glcpp_parser_expand_token_list (parser, list);
-
-	_token_list_trim_trailing_space (list);
-
-	_token_list_print (parser, list);
-}
-
-static void
-_check_for_reserved_macro_name (glcpp_parser_t *parser, YYLTYPE *loc,
-				const char *identifier)
-{
-	/* According to the GLSL specification, macro names starting with "__"
-	 * or "GL_" are reserved for future use.  So, don't allow them.
-	 */
-	if (strncmp(identifier, "__", 2) == 0) {
-		glcpp_error (loc, parser, "Macro names starting with \"__\" are reserved.\n");
-	}
-	if (strncmp(identifier, "GL_", 3) == 0) {
-		glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n");
-	}
-}
-
-static int
-_macro_equal (macro_t *a, macro_t *b)
-{
-	if (a->is_function != b->is_function)
-		return 0;
-
-	if (a->is_function) {
-		if (! _string_list_equal (a->parameters, b->parameters))
-			return 0;
-	}
-
-	return _token_list_equal_ignoring_space (a->replacements,
-						 b->replacements);
-}
-
-void
-_define_object_macro (glcpp_parser_t *parser,
-		      YYLTYPE *loc,
-		      const char *identifier,
-		      token_list_t *replacements)
-{
-	macro_t *macro, *previous;
-
-	if (loc != NULL)
-		_check_for_reserved_macro_name(parser, loc, identifier);
-
-	macro = talloc (parser, macro_t);
-
-	macro->is_function = 0;
-	macro->parameters = NULL;
-	macro->identifier = talloc_strdup (macro, identifier);
-	macro->replacements = talloc_steal (macro, replacements);
-
-	previous = hash_table_find (parser->defines, identifier);
-	if (previous) {
-		if (_macro_equal (macro, previous)) {
-			talloc_free (macro);
-			return;
-		}
-		glcpp_warning (loc, parser, "Redefinition of macro %s\n",
-			       identifier);
-	}
-
-	hash_table_insert (parser->defines, macro, identifier);
-}
-
-void
-_define_function_macro (glcpp_parser_t *parser,
-			YYLTYPE *loc,
-			const char *identifier,
-			string_list_t *parameters,
-			token_list_t *replacements)
-{
-	macro_t *macro, *previous;
-
-	_check_for_reserved_macro_name(parser, loc, identifier);
-
-	macro = talloc (parser, macro_t);
-
-	macro->is_function = 1;
-	macro->parameters = talloc_steal (macro, parameters);
-	macro->identifier = talloc_strdup (macro, identifier);
-	macro->replacements = talloc_steal (macro, replacements);
-
-	previous = hash_table_find (parser->defines, identifier);
-	if (previous) {
-		if (_macro_equal (macro, previous)) {
-			talloc_free (macro);
-			return;
-		}
-		glcpp_warning (loc, parser, "Redefinition of macro %s\n",
-			       identifier);
-	}
-
-	hash_table_insert (parser->defines, macro, identifier);
-}
-
-static int
-glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
-{
-	token_node_t *node;
-	int ret;
-
-	if (parser->lex_from_list == NULL) {
-		ret = glcpp_lex (yylval, yylloc, parser->scanner);
-
-		/* XXX: This ugly block of code exists for the sole
-		 * purpose of converting a NEWLINE token into a SPACE
-		 * token, but only in the case where we have seen a
-		 * function-like macro name, but have not yet seen its
-		 * closing parenthesis.
-		 *
-		 * There's perhaps a more compact way to do this with
-		 * mid-rule actions in the grammar.
-		 *
-		 * I'm definitely not pleased with the complexity of
-		 * this code here.
-		 */
-		if (parser->newline_as_space)
-		{
-			if (ret == '(') {
-				parser->paren_count++;
-			} else if (ret == ')') {
-				parser->paren_count--;
-				if (parser->paren_count == 0)
-					parser->newline_as_space = 0;
-			} else if (ret == NEWLINE) {
-				ret = SPACE;
-			} else if (ret != SPACE) {
-				if (parser->paren_count == 0)
-					parser->newline_as_space = 0;
-			}
-		}
-		else if (parser->in_control_line)
-		{
-			if (ret == NEWLINE)
-				parser->in_control_line = 0;
-		}
-		else if (ret == HASH_DEFINE_OBJ || ret == HASH_DEFINE_FUNC ||
-			   ret == HASH_UNDEF || ret == HASH_IF ||
-			   ret == HASH_IFDEF || ret == HASH_IFNDEF ||
-			   ret == HASH_ELIF || ret == HASH_ELSE ||
-			   ret == HASH_ENDIF || ret == HASH)
-		{
-			parser->in_control_line = 1;
-		}
-		else if (ret == IDENTIFIER)
-		{
-			macro_t *macro;
-			macro = hash_table_find (parser->defines,
-						 yylval->str);
-			if (macro && macro->is_function) {
-				parser->newline_as_space = 1;
-				parser->paren_count = 0;
-			}
-		}
-
-		return ret;
-	}
-
-	node = parser->lex_from_node;
-
-	if (node == NULL) {
-		talloc_free (parser->lex_from_list);
-		parser->lex_from_list = NULL;
-		return NEWLINE;
-	}
-
-	*yylval = node->token->value;
-	ret = node->token->type;
-
-	parser->lex_from_node = node->next;
-
-	return ret;
-}
-
-static void
-glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list)
-{
-	token_node_t *node;
-
-	assert (parser->lex_from_list == NULL);
-
-	/* Copy list, eliminating any space tokens. */
-	parser->lex_from_list = _token_list_create (parser);
-
-	for (node = list->head; node; node = node->next) {
-		if (node->token->type == SPACE)
-			continue;
-		_token_list_append (parser->lex_from_list, node->token);
-	}
-
-	talloc_free (list);
-
-	parser->lex_from_node = parser->lex_from_list->head;
-
-	/* It's possible the list consisted of nothing but whitespace. */
-	if (parser->lex_from_node == NULL) {
-		talloc_free (parser->lex_from_list);
-		parser->lex_from_list = NULL;
-	}
-}
-
-static void
-_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
-				  int condition)
-{
-	skip_type_t current = SKIP_NO_SKIP;
-	skip_node_t *node;
-
-	if (parser->skip_stack)
-		current = parser->skip_stack->type;
-
-	node = talloc (parser, skip_node_t);
-	node->loc = *loc;
-
-	if (current == SKIP_NO_SKIP) {
-		if (condition)
-			node->type = SKIP_NO_SKIP;
-		else
-			node->type = SKIP_TO_ELSE;
-	} else {
-		node->type = SKIP_TO_ENDIF;
-	}
-
-	node->next = parser->skip_stack;
-	parser->skip_stack = node;
-}
-
-static void
-_glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
-				    const char *type, int condition)
-{
-	if (parser->skip_stack == NULL) {
-		glcpp_error (loc, parser, "%s without #if\n", type);
-		return;
-	}
-
-	if (parser->skip_stack->type == SKIP_TO_ELSE) {
-		if (condition)
-			parser->skip_stack->type = SKIP_NO_SKIP;
-	} else {
-		parser->skip_stack->type = SKIP_TO_ENDIF;
-	}
-}
-
-static void
-_glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc)
-{
-	skip_node_t *node;
-
-	if (parser->skip_stack == NULL) {
-		glcpp_error (loc, parser, "#endif without #if\n");
-		return;
-	}
-
-	node = parser->skip_stack;
-	parser->skip_stack = node->next;
-	talloc_free (node);
-}
-
+/* A Bison parser, made by GNU Bison 2.4.3.  */
+
+/* Skeleton implementation for Bison's Yacc-like parsers in C
+   
+      Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+   2009, 2010 Free Software Foundation, Inc.
+   
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* As a special exception, you may create a larger work that contains
+   part or all of the Bison parser skeleton and distribute that work
+   under terms of your choice, so long as that work isn't itself a
+   parser generator using the skeleton or a modified version thereof
+   as a parser skeleton.  Alternatively, if you modify or redistribute
+   the parser skeleton itself, you may (at your option) remove this
+   special exception, which will cause the skeleton and the resulting
+   Bison output files to be licensed under the GNU General Public
+   License without this special exception.
+   
+   This special exception was added by the Free Software Foundation in
+   version 2.2 of Bison.  */
+
+/* C LALR(1) parser skeleton written by Richard Stallman, by
+   simplifying the original so-called "semantic" parser.  */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+   infringing on user name space.  This should be done even for local
+   variables, as they might otherwise be expanded by user macros.
+   There are some unavoidable exceptions within include files to
+   define necessary library symbols; they are noted "INFRINGES ON
+   USER NAME SPACE" below.  */
+
+/* Identify Bison output.  */
+#define YYBISON 1
+
+/* Bison version.  */
+#define YYBISON_VERSION "2.4.3"
+
+/* Skeleton name.  */
+#define YYSKELETON_NAME "yacc.c"
+
+/* Pure parsers.  */
+#define YYPURE 1
+
+/* Push parsers.  */
+#define YYPUSH 0
+
+/* Pull parsers.  */
+#define YYPULL 1
+
+/* Using locations.  */
+#define YYLSP_NEEDED 1
+
+
+
+/* Copy the first part of user declarations.  */
+
+/* Line 189 of yacc.c  */
+#line 1 "glcpp/glcpp-parse.y"
+
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <inttypes.h>
+
+#include "glcpp.h"
+#include "main/core.h" /* for struct gl_extensions */
+#include "main/mtypes.h" /* for gl_api enum */
+
+#define glcpp_print(stream, str) stream = talloc_strdup_append(stream, str)
+#define glcpp_printf(stream, fmt, args, ...) \
+	stream = talloc_asprintf_append(stream, fmt, args)
+
+static void
+yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
+
+static void
+_define_object_macro (glcpp_parser_t *parser,
+		      YYLTYPE *loc,
+		      const char *macro,
+		      token_list_t *replacements);
+
+static void
+_define_function_macro (glcpp_parser_t *parser,
+			YYLTYPE *loc,
+			const char *macro,
+			string_list_t *parameters,
+			token_list_t *replacements);
+
+static string_list_t *
+_string_list_create (void *ctx);
+
+static void
+_string_list_append_item (string_list_t *list, const char *str);
+
+static int
+_string_list_contains (string_list_t *list, const char *member, int *index);
+
+static int
+_string_list_length (string_list_t *list);
+
+static int
+_string_list_equal (string_list_t *a, string_list_t *b);
+
+static argument_list_t *
+_argument_list_create (void *ctx);
+
+static void
+_argument_list_append (argument_list_t *list, token_list_t *argument);
+
+static int
+_argument_list_length (argument_list_t *list);
+
+static token_list_t *
+_argument_list_member_at (argument_list_t *list, int index);
+
+/* Note: This function talloc_steal()s the str pointer. */
+static token_t *
+_token_create_str (void *ctx, int type, char *str);
+
+static token_t *
+_token_create_ival (void *ctx, int type, int ival);
+
+static token_list_t *
+_token_list_create (void *ctx);
+
+/* Note: This function calls talloc_steal on token. */
+static void
+_token_list_append (token_list_t *list, token_t *token);
+
+static void
+_token_list_append_list (token_list_t *list, token_list_t *tail);
+
+static int
+_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b);
+
+static active_list_t *
+_active_list_push (active_list_t *list,
+		   const char *identifier,
+		   token_node_t *marker);
+
+static active_list_t *
+_active_list_pop (active_list_t *list);
+
+int
+_active_list_contains (active_list_t *list, const char *identifier);
+
+static void
+_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list);
+
+static void
+_glcpp_parser_expand_token_list (glcpp_parser_t *parser,
+				 token_list_t *list);
+
+static void
+_glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
+					 token_list_t *list);
+
+static void
+_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
+				  int condition);
+
+static void
+_glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
+				    const char *type, int condition);
+
+static void
+_glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc);
+
+#define yylex glcpp_parser_lex
+
+static int
+glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser);
+
+static void
+glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list);
+
+static void
+add_builtin_define(glcpp_parser_t *parser, const char *name, int value);
+
+
+
+/* Line 189 of yacc.c  */
+#line 220 "glcpp/glcpp-parse.c"
+
+/* Enabling traces.  */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+
+/* Enabling verbose error messages.  */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 1
+#endif
+
+/* Enabling the token table.  */
+#ifndef YYTOKEN_TABLE
+# define YYTOKEN_TABLE 0
+#endif
+
+
+/* Tokens.  */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+   /* Put the tokens into the symbol table, so that GDB and other debuggers
+      know about them.  */
+   enum yytokentype {
+     COMMA_FINAL = 258,
+     DEFINED = 259,
+     ELIF_EXPANDED = 260,
+     HASH = 261,
+     HASH_DEFINE_FUNC = 262,
+     HASH_DEFINE_OBJ = 263,
+     HASH_ELIF = 264,
+     HASH_ELSE = 265,
+     HASH_ENDIF = 266,
+     HASH_IF = 267,
+     HASH_IFDEF = 268,
+     HASH_IFNDEF = 269,
+     HASH_UNDEF = 270,
+     HASH_VERSION = 271,
+     IDENTIFIER = 272,
+     IF_EXPANDED = 273,
+     INTEGER = 274,
+     INTEGER_STRING = 275,
+     NEWLINE = 276,
+     OTHER = 277,
+     PLACEHOLDER = 278,
+     SPACE = 279,
+     PASTE = 280,
+     OR = 281,
+     AND = 282,
+     NOT_EQUAL = 283,
+     EQUAL = 284,
+     GREATER_OR_EQUAL = 285,
+     LESS_OR_EQUAL = 286,
+     RIGHT_SHIFT = 287,
+     LEFT_SHIFT = 288,
+     UNARY = 289
+   };
+#endif
+
+
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+#endif
+
+#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
+typedef struct YYLTYPE
+{
+  int first_line;
+  int first_column;
+  int last_line;
+  int last_column;
+} YYLTYPE;
+# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
+# define YYLTYPE_IS_DECLARED 1
+# define YYLTYPE_IS_TRIVIAL 1
+#endif
+
+
+/* Copy the second part of user declarations.  */
+
+
+/* Line 264 of yacc.c  */
+#line 308 "glcpp/glcpp-parse.c"
+
+#ifdef short
+# undef short
+#endif
+
+#ifdef YYTYPE_UINT8
+typedef YYTYPE_UINT8 yytype_uint8;
+#else
+typedef unsigned char yytype_uint8;
+#endif
+
+#ifdef YYTYPE_INT8
+typedef YYTYPE_INT8 yytype_int8;
+#elif (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+typedef signed char yytype_int8;
+#else
+typedef short int yytype_int8;
+#endif
+
+#ifdef YYTYPE_UINT16
+typedef YYTYPE_UINT16 yytype_uint16;
+#else
+typedef unsigned short int yytype_uint16;
+#endif
+
+#ifdef YYTYPE_INT16
+typedef YYTYPE_INT16 yytype_int16;
+#else
+typedef short int yytype_int16;
+#endif
+
+#ifndef YYSIZE_T
+# ifdef __SIZE_TYPE__
+#  define YYSIZE_T __SIZE_TYPE__
+# elif defined size_t
+#  define YYSIZE_T size_t
+# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+#  define YYSIZE_T size_t
+# else
+#  define YYSIZE_T unsigned int
+# endif
+#endif
+
+#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
+
+#ifndef YY_
+# if defined YYENABLE_NLS && YYENABLE_NLS
+#  if ENABLE_NLS
+#   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
+#   define YY_(msgid) dgettext ("bison-runtime", msgid)
+#  endif
+# endif
+# ifndef YY_
+#  define YY_(msgid) msgid
+# endif
+#endif
+
+/* Suppress unused-variable warnings by "using" E.  */
+#if ! defined lint || defined __GNUC__
+# define YYUSE(e) ((void) (e))
+#else
+# define YYUSE(e) /* empty */
+#endif
+
+/* Identity function, used to suppress warnings about constant conditions.  */
+#ifndef lint
+# define YYID(n) (n)
+#else
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+static int
+YYID (int yyi)
+#else
+static int
+YYID (yyi)
+    int yyi;
+#endif
+{
+  return yyi;
+}
+#endif
+
+#if ! defined yyoverflow || YYERROR_VERBOSE
+
+/* The parser invokes alloca or malloc; define the necessary symbols.  */
+
+# ifdef YYSTACK_USE_ALLOCA
+#  if YYSTACK_USE_ALLOCA
+#   ifdef __GNUC__
+#    define YYSTACK_ALLOC __builtin_alloca
+#   elif defined __BUILTIN_VA_ARG_INCR
+#    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
+#   elif defined _AIX
+#    define YYSTACK_ALLOC __alloca
+#   elif defined _MSC_VER
+#    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
+#    define alloca _alloca
+#   else
+#    define YYSTACK_ALLOC alloca
+#    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+#     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+#     ifndef _STDLIB_H
+#      define _STDLIB_H 1
+#     endif
+#    endif
+#   endif
+#  endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+   /* Pacify GCC's `empty if-body' warning.  */
+#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
+#  ifndef YYSTACK_ALLOC_MAXIMUM
+    /* The OS might guarantee only one guard page at the bottom of the stack,
+       and a page size can be as small as 4096 bytes.  So we cannot safely
+       invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
+       to allow for a few compiler-allocated temporary stack slots.  */
+#   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
+#  endif
+# else
+#  define YYSTACK_ALLOC YYMALLOC
+#  define YYSTACK_FREE YYFREE
+#  ifndef YYSTACK_ALLOC_MAXIMUM
+#   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
+#  endif
+#  if (defined __cplusplus && ! defined _STDLIB_H \
+       && ! ((defined YYMALLOC || defined malloc) \
+	     && (defined YYFREE || defined free)))
+#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+#   ifndef _STDLIB_H
+#    define _STDLIB_H 1
+#   endif
+#  endif
+#  ifndef YYMALLOC
+#   define YYMALLOC malloc
+#   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+#   endif
+#  endif
+#  ifndef YYFREE
+#   define YYFREE free
+#   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+void free (void *); /* INFRINGES ON USER NAME SPACE */
+#   endif
+#  endif
+# endif
+#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
+
+
+#if (! defined yyoverflow \
+     && (! defined __cplusplus \
+	 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
+	     && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member.  */
+union yyalloc
+{
+  yytype_int16 yyss_alloc;
+  YYSTYPE yyvs_alloc;
+  YYLTYPE yyls_alloc;
+};
+
+/* The size of the maximum gap between one aligned stack and the next.  */
+# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+   N elements.  */
+# define YYSTACK_BYTES(N) \
+     ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
+      + 2 * YYSTACK_GAP_MAXIMUM)
+
+/* Copy COUNT objects from FROM to TO.  The source and destination do
+   not overlap.  */
+# ifndef YYCOPY
+#  if defined __GNUC__ && 1 < __GNUC__
+#   define YYCOPY(To, From, Count) \
+      __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+#  else
+#   define YYCOPY(To, From, Count)		\
+      do					\
+	{					\
+	  YYSIZE_T yyi;				\
+	  for (yyi = 0; yyi < (Count); yyi++)	\
+	    (To)[yyi] = (From)[yyi];		\
+	}					\
+      while (YYID (0))
+#  endif
+# endif
+
+/* Relocate STACK from its old location to the new one.  The
+   local variables YYSIZE and YYSTACKSIZE give the old and new number of
+   elements in the stack, and YYPTR gives the new location of the
+   stack.  Advance YYPTR to a properly aligned location for the next
+   stack.  */
+# define YYSTACK_RELOCATE(Stack_alloc, Stack)				\
+    do									\
+      {									\
+	YYSIZE_T yynewbytes;						\
+	YYCOPY (&yyptr->Stack_alloc, Stack, yysize);			\
+	Stack = &yyptr->Stack_alloc;					\
+	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+	yyptr += yynewbytes / sizeof (*yyptr);				\
+      }									\
+    while (YYID (0))
+
+#endif
+
+/* YYFINAL -- State number of the termination state.  */
+#define YYFINAL  2
+/* YYLAST -- Last index in YYTABLE.  */
+#define YYLAST   606
+
+/* YYNTOKENS -- Number of terminals.  */
+#define YYNTOKENS  57
+/* YYNNTS -- Number of nonterminals.  */
+#define YYNNTS  17
+/* YYNRULES -- Number of rules.  */
+#define YYNRULES  101
+/* YYNRULES -- Number of states.  */
+#define YYNSTATES  162
+
+/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
+#define YYUNDEFTOK  2
+#define YYMAXUTOK   289
+
+#define YYTRANSLATE(YYX)						\
+  ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
+static const yytype_uint8 yytranslate[] =
+{
+       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,    47,     2,     2,     2,    43,    30,     2,
+      45,    46,    41,    39,    49,    40,    54,    42,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,    55,
+      33,    56,    34,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,    50,     2,    51,    29,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,    52,    28,    53,    48,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
+       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
+      15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
+      25,    26,    27,    31,    32,    35,    36,    37,    38,    44
+};
+
+#if YYDEBUG
+/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+   YYRHS.  */
+static const yytype_uint16 yyprhs[] =
+{
+       0,     0,     3,     4,     7,     9,    11,    13,    16,    20,
+      24,    29,    36,    44,    48,    52,    55,    60,    65,    69,
+      72,    75,    78,    82,    85,    87,    89,    91,    95,    99,
+     103,   107,   111,   115,   119,   123,   127,   131,   135,   139,
+     143,   147,   151,   155,   159,   163,   166,   169,   172,   175,
+     179,   181,   185,   187,   190,   193,   194,   196,   197,   199,
+     202,   207,   209,   211,   214,   216,   219,   221,   223,   225,
+     227,   229,   231,   233,   235,   237,   239,   241,   243,   245,
+     247,   249,   251,   253,   255,   257,   259,   261,   263,   265,
+     267,   269,   271,   273,   275,   277,   279,   281,   283,   285,
+     287,   289
+};
+
+/* YYRHS -- A `-1'-separated list of the rules' RHS.  */
+static const yytype_int8 yyrhs[] =
+{
+      58,     0,    -1,    -1,    58,    59,    -1,    61,    -1,    65,
+      -1,    60,    -1,     6,    66,    -1,    18,    63,    21,    -1,
+       5,    63,    21,    -1,     8,    17,    67,    21,    -1,     7,
+      17,    45,    46,    67,    21,    -1,     7,    17,    45,    64,
+      46,    67,    21,    -1,    15,    17,    21,    -1,    12,    70,
+      21,    -1,    12,    21,    -1,    13,    17,    68,    21,    -1,
+      14,    17,    68,    21,    -1,     9,    70,    21,    -1,     9,
+      21,    -1,    10,    21,    -1,    11,    21,    -1,    16,    62,
+      21,    -1,     6,    21,    -1,    20,    -1,    19,    -1,    62,
+      -1,    63,    26,    63,    -1,    63,    27,    63,    -1,    63,
+      28,    63,    -1,    63,    29,    63,    -1,    63,    30,    63,
+      -1,    63,    31,    63,    -1,    63,    32,    63,    -1,    63,
+      35,    63,    -1,    63,    36,    63,    -1,    63,    34,    63,
+      -1,    63,    33,    63,    -1,    63,    37,    63,    -1,    63,
+      38,    63,    -1,    63,    40,    63,    -1,    63,    39,    63,
+      -1,    63,    43,    63,    -1,    63,    42,    63,    -1,    63,
+      41,    63,    -1,    47,    63,    -1,    48,    63,    -1,    40,
+      63,    -1,    39,    63,    -1,    45,    63,    46,    -1,    17,
+      -1,    64,    49,    17,    -1,    21,    -1,    71,    21,    -1,
+      71,    21,    -1,    -1,    71,    -1,    -1,    71,    -1,     4,
+      17,    -1,     4,    45,    17,    46,    -1,    72,    -1,    69,
+      -1,    70,    69,    -1,    72,    -1,    71,    72,    -1,    17,
+      -1,    20,    -1,    73,    -1,    22,    -1,    24,    -1,    50,
+      -1,    51,    -1,    45,    -1,    46,    -1,    52,    -1,    53,
+      -1,    54,    -1,    30,    -1,    41,    -1,    39,    -1,    40,
+      -1,    48,    -1,    47,    -1,    42,    -1,    43,    -1,    38,
+      -1,    37,    -1,    33,    -1,    34,    -1,    36,    -1,    35,
+      -1,    32,    -1,    31,    -1,    29,    -1,    28,    -1,    27,
+      -1,    26,    -1,    55,    -1,    49,    -1,    56,    -1,    25,
+      -1
+};
+
+/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
+static const yytype_uint16 yyrline[] =
+{
+       0,   185,   185,   187,   191,   194,   199,   200,   204,   207,
+     213,   216,   219,   222,   230,   249,   259,   264,   269,   288,
+     303,   306,   309,   330,   334,   343,   348,   349,   352,   355,
+     358,   361,   364,   367,   370,   373,   376,   379,   382,   385,
+     388,   391,   394,   397,   405,   408,   411,   414,   417,   420,
+     426,   431,   439,   440,   444,   450,   451,   454,   456,   463,
+     467,   471,   476,   480,   487,   492,   499,   503,   507,   511,
+     515,   522,   523,   524,   525,   526,   527,   528,   529,   530,
+     531,   532,   533,   534,   535,   536,   537,   538,   539,   540,
+     541,   542,   543,   544,   545,   546,   547,   548,   549,   550,
+     551,   552
+};
+#endif
+
+#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
+/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
+static const char *const yytname[] =
+{
+  "$end", "error", "$undefined", "COMMA_FINAL", "DEFINED",
+  "ELIF_EXPANDED", "HASH", "HASH_DEFINE_FUNC", "HASH_DEFINE_OBJ",
+  "HASH_ELIF", "HASH_ELSE", "HASH_ENDIF", "HASH_IF", "HASH_IFDEF",
+  "HASH_IFNDEF", "HASH_UNDEF", "HASH_VERSION", "IDENTIFIER", "IF_EXPANDED",
+  "INTEGER", "INTEGER_STRING", "NEWLINE", "OTHER", "PLACEHOLDER", "SPACE",
+  "PASTE", "OR", "AND", "'|'", "'^'", "'&'", "NOT_EQUAL", "EQUAL", "'<'",
+  "'>'", "GREATER_OR_EQUAL", "LESS_OR_EQUAL", "RIGHT_SHIFT", "LEFT_SHIFT",
+  "'+'", "'-'", "'*'", "'/'", "'%'", "UNARY", "'('", "')'", "'!'", "'~'",
+  "','", "'['", "']'", "'{'", "'}'", "'.'", "';'", "'='", "$accept",
+  "input", "line", "expanded_line", "control_line", "integer_constant",
+  "expression", "identifier_list", "text_line", "non_directive",
+  "replacement_list", "junk", "conditional_token", "conditional_tokens",
+  "pp_tokens", "preprocessing_token", "operator", 0
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
+   token YYLEX-NUM.  */
+static const yytype_uint16 yytoknum[] =
+{
+       0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
+     265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
+     275,   276,   277,   278,   279,   280,   281,   282,   124,    94,
+      38,   283,   284,    60,    62,   285,   286,   287,   288,    43,
+      45,    42,    47,    37,   289,    40,    41,    33,   126,    44,
+      91,    93,   123,   125,    46,    59,    61
+};
+# endif
+
+/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
+static const yytype_uint8 yyr1[] =
+{
+       0,    57,    58,    58,    59,    59,    59,    59,    60,    60,
+      61,    61,    61,    61,    61,    61,    61,    61,    61,    61,
+      61,    61,    61,    61,    62,    62,    63,    63,    63,    63,
+      63,    63,    63,    63,    63,    63,    63,    63,    63,    63,
+      63,    63,    63,    63,    63,    63,    63,    63,    63,    63,
+      64,    64,    65,    65,    66,    67,    67,    68,    68,    69,
+      69,    69,    70,    70,    71,    71,    72,    72,    72,    72,
+      72,    73,    73,    73,    73,    73,    73,    73,    73,    73,
+      73,    73,    73,    73,    73,    73,    73,    73,    73,    73,
+      73,    73,    73,    73,    73,    73,    73,    73,    73,    73,
+      73,    73
+};
+
+/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
+static const yytype_uint8 yyr2[] =
+{
+       0,     2,     0,     2,     1,     1,     1,     2,     3,     3,
+       4,     6,     7,     3,     3,     2,     4,     4,     3,     2,
+       2,     2,     3,     2,     1,     1,     1,     3,     3,     3,
+       3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
+       3,     3,     3,     3,     3,     2,     2,     2,     2,     3,
+       1,     3,     1,     2,     2,     0,     1,     0,     1,     2,
+       4,     1,     1,     2,     1,     2,     1,     1,     1,     1,
+       1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
+       1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
+       1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
+       1,     1
+};
+
+/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
+   STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
+   means the default is an error.  */
+static const yytype_uint8 yydefact[] =
+{
+       2,     0,     1,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,    66,     0,    67,    52,    69,
+      70,   101,    97,    96,    95,    94,    78,    93,    92,    88,
+      89,    91,    90,    87,    86,    80,    81,    79,    84,    85,
+      73,    74,    83,    82,    99,    71,    72,    75,    76,    77,
+      98,   100,     3,     6,     4,     5,     0,    64,    68,    25,
+      24,     0,     0,     0,     0,     0,    26,     0,    23,     7,
+       0,     0,    55,     0,    19,    62,     0,    61,    20,    21,
+      15,     0,    57,    57,     0,     0,     0,    53,    65,    48,
+      47,     0,    45,    46,     9,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,    54,     0,     0,    56,    59,     0,    18,
+      63,    14,     0,    58,     0,    13,    22,     8,    49,    27,
+      28,    29,    30,    31,    32,    33,    37,    36,    34,    35,
+      38,    39,    41,    40,    44,    43,    42,    50,    55,     0,
+      10,     0,    16,    17,     0,    55,     0,    60,    11,     0,
+      51,    12
+};
+
+/* YYDEFGOTO[NTERM-NUM].  */
+static const yytype_int16 yydefgoto[] =
+{
+      -1,     1,    52,    53,    54,    66,    67,   149,    55,    69,
+     115,   122,    75,    76,   116,    57,    58
+};
+
+/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+   STATE-NUM.  */
+#define YYPACT_NINF -147
+static const yytype_int16 yypact[] =
+{
+    -147,   112,  -147,    28,   -10,    55,    62,   152,   -15,    59,
+     192,    85,    86,    87,    51,  -147,    28,  -147,  -147,  -147,
+    -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,
+    -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,
+    -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,  -147,
+    -147,  -147,  -147,  -147,  -147,  -147,   312,  -147,  -147,  -147,
+    -147,    28,    28,    28,    28,    28,  -147,   428,  -147,  -147,
+     352,    63,   392,    17,  -147,  -147,   232,  -147,  -147,  -147,
+    -147,   272,   392,   392,    84,    89,   451,  -147,  -147,  -147,
+    -147,   469,  -147,  -147,  -147,    28,    28,    28,    28,    28,
+      28,    28,    28,    28,    28,    28,    28,    28,    28,    28,
+      28,    28,    28,  -147,    60,    90,   392,  -147,    96,  -147,
+    -147,  -147,    93,   392,    94,  -147,  -147,  -147,  -147,   489,
+     505,   520,   534,   547,   558,   558,    18,    18,    18,    18,
+     563,   563,    23,    23,  -147,  -147,  -147,  -147,   392,    32,
+    -147,    61,  -147,  -147,   110,   392,   118,  -147,  -147,   149,
+    -147,  -147
+};
+
+/* YYPGOTO[NTERM-NUM].  */
+static const yytype_int16 yypgoto[] =
+{
+    -147,  -147,  -147,  -147,  -147,   157,   -11,  -147,  -147,  -147,
+    -146,    92,   -68,   200,     0,    -7,  -147
+};
+
+/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
+   positive, shift that token.  If negative, reduce the rule which
+   number is the opposite.  If zero, do what YYDEFACT says.
+   If YYTABLE_NINF, syntax error.  */
+#define YYTABLE_NINF -1
+static const yytype_uint8 yytable[] =
+{
+      77,    56,   154,    77,    70,    86,    78,    15,   120,   159,
+      17,    68,    19,   120,    20,    21,    22,    23,    24,    25,
+      26,    27,    28,    29,    30,    31,    32,    33,    34,    35,
+      36,    37,    38,    39,   117,    40,    41,    42,    43,    44,
+      45,    46,    47,    48,    49,    50,    51,    59,    60,    88,
+      89,    90,    91,    92,    93,   106,   107,   108,   109,   110,
+     111,   112,   118,    88,   110,   111,   112,    61,    62,    77,
+      59,    60,    71,    63,    77,    64,    65,   147,   155,    72,
+      79,   156,   123,   123,   129,   130,   131,   132,   133,   134,
+     135,   136,   137,   138,   139,   140,   141,   142,   143,   144,
+     145,   146,    82,    83,    84,   125,   148,   157,   114,    88,
+     126,   150,     2,   151,   152,   153,    88,     3,     4,     5,
+       6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
+      16,   158,    17,    18,    19,   160,    20,    21,    22,    23,
+      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
+      34,    35,    36,    37,    38,    39,    73,    40,    41,    42,
+      43,    44,    45,    46,    47,    48,    49,    50,    51,    15,
+     161,    85,    17,    74,    19,   124,    20,    21,    22,    23,
+      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
+      34,    35,    36,    37,    38,    39,    73,    40,    41,    42,
+      43,    44,    45,    46,    47,    48,    49,    50,    51,    15,
+      81,     0,    17,    80,    19,     0,    20,    21,    22,    23,
+      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
+      34,    35,    36,    37,    38,    39,    73,    40,    41,    42,
+      43,    44,    45,    46,    47,    48,    49,    50,    51,    15,
+       0,     0,    17,   119,    19,     0,    20,    21,    22,    23,
+      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
+      34,    35,    36,    37,    38,    39,    73,    40,    41,    42,
+      43,    44,    45,    46,    47,    48,    49,    50,    51,    15,
+       0,     0,    17,   121,    19,     0,    20,    21,    22,    23,
+      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
+      34,    35,    36,    37,    38,    39,     0,    40,    41,    42,
+      43,    44,    45,    46,    47,    48,    49,    50,    51,    15,
+       0,     0,    17,    87,    19,     0,    20,    21,    22,    23,
+      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
+      34,    35,    36,    37,    38,    39,     0,    40,    41,    42,
+      43,    44,    45,    46,    47,    48,    49,    50,    51,    15,
+       0,     0,    17,   113,    19,     0,    20,    21,    22,    23,
+      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
+      34,    35,    36,    37,    38,    39,     0,    40,    41,    42,
+      43,    44,    45,    46,    47,    48,    49,    50,    51,    15,
+       0,     0,    17,     0,    19,     0,    20,    21,    22,    23,
+      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
+      34,    35,    36,    37,    38,    39,     0,    40,    41,    42,
+      43,    44,    45,    46,    47,    48,    49,    50,    51,    94,
+       0,     0,     0,     0,    95,    96,    97,    98,    99,   100,
+     101,   102,   103,   104,   105,   106,   107,   108,   109,   110,
+     111,   112,   127,     0,     0,     0,     0,    95,    96,    97,
+      98,    99,   100,   101,   102,   103,   104,   105,   106,   107,
+     108,   109,   110,   111,   112,    95,    96,    97,    98,    99,
+     100,   101,   102,   103,   104,   105,   106,   107,   108,   109,
+     110,   111,   112,     0,     0,   128,    96,    97,    98,    99,
+     100,   101,   102,   103,   104,   105,   106,   107,   108,   109,
+     110,   111,   112,    97,    98,    99,   100,   101,   102,   103,
+     104,   105,   106,   107,   108,   109,   110,   111,   112,    98,
+      99,   100,   101,   102,   103,   104,   105,   106,   107,   108,
+     109,   110,   111,   112,    99,   100,   101,   102,   103,   104,
+     105,   106,   107,   108,   109,   110,   111,   112,   100,   101,
+     102,   103,   104,   105,   106,   107,   108,   109,   110,   111,
+     112,   102,   103,   104,   105,   106,   107,   108,   109,   110,
+     111,   112,   108,   109,   110,   111,   112
+};
+
+static const yytype_int16 yycheck[] =
+{
+       7,     1,   148,    10,     4,    16,    21,    17,    76,   155,
+      20,    21,    22,    81,    24,    25,    26,    27,    28,    29,
+      30,    31,    32,    33,    34,    35,    36,    37,    38,    39,
+      40,    41,    42,    43,    17,    45,    46,    47,    48,    49,
+      50,    51,    52,    53,    54,    55,    56,    19,    20,    56,
+      61,    62,    63,    64,    65,    37,    38,    39,    40,    41,
+      42,    43,    45,    70,    41,    42,    43,    39,    40,    76,
+      19,    20,    17,    45,    81,    47,    48,    17,    46,    17,
+      21,    49,    82,    83,    95,    96,    97,    98,    99,   100,
+     101,   102,   103,   104,   105,   106,   107,   108,   109,   110,
+     111,   112,    17,    17,    17,    21,    46,    46,    45,   116,
+      21,    21,     0,    17,    21,    21,   123,     5,     6,     7,
+       8,     9,    10,    11,    12,    13,    14,    15,    16,    17,
+      18,    21,    20,    21,    22,    17,    24,    25,    26,    27,
+      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
+      38,    39,    40,    41,    42,    43,     4,    45,    46,    47,
+      48,    49,    50,    51,    52,    53,    54,    55,    56,    17,
+      21,    14,    20,    21,    22,    83,    24,    25,    26,    27,
+      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
+      38,    39,    40,    41,    42,    43,     4,    45,    46,    47,
+      48,    49,    50,    51,    52,    53,    54,    55,    56,    17,
+      10,    -1,    20,    21,    22,    -1,    24,    25,    26,    27,
+      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
+      38,    39,    40,    41,    42,    43,     4,    45,    46,    47,
+      48,    49,    50,    51,    52,    53,    54,    55,    56,    17,
+      -1,    -1,    20,    21,    22,    -1,    24,    25,    26,    27,
+      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
+      38,    39,    40,    41,    42,    43,     4,    45,    46,    47,
+      48,    49,    50,    51,    52,    53,    54,    55,    56,    17,
+      -1,    -1,    20,    21,    22,    -1,    24,    25,    26,    27,
+      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
+      38,    39,    40,    41,    42,    43,    -1,    45,    46,    47,
+      48,    49,    50,    51,    52,    53,    54,    55,    56,    17,
+      -1,    -1,    20,    21,    22,    -1,    24,    25,    26,    27,
+      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
+      38,    39,    40,    41,    42,    43,    -1,    45,    46,    47,
+      48,    49,    50,    51,    52,    53,    54,    55,    56,    17,
+      -1,    -1,    20,    21,    22,    -1,    24,    25,    26,    27,
+      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
+      38,    39,    40,    41,    42,    43,    -1,    45,    46,    47,
+      48,    49,    50,    51,    52,    53,    54,    55,    56,    17,
+      -1,    -1,    20,    -1,    22,    -1,    24,    25,    26,    27,
+      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
+      38,    39,    40,    41,    42,    43,    -1,    45,    46,    47,
+      48,    49,    50,    51,    52,    53,    54,    55,    56,    21,
+      -1,    -1,    -1,    -1,    26,    27,    28,    29,    30,    31,
+      32,    33,    34,    35,    36,    37,    38,    39,    40,    41,
+      42,    43,    21,    -1,    -1,    -1,    -1,    26,    27,    28,
+      29,    30,    31,    32,    33,    34,    35,    36,    37,    38,
+      39,    40,    41,    42,    43,    26,    27,    28,    29,    30,
+      31,    32,    33,    34,    35,    36,    37,    38,    39,    40,
+      41,    42,    43,    -1,    -1,    46,    27,    28,    29,    30,
+      31,    32,    33,    34,    35,    36,    37,    38,    39,    40,
+      41,    42,    43,    28,    29,    30,    31,    32,    33,    34,
+      35,    36,    37,    38,    39,    40,    41,    42,    43,    29,
+      30,    31,    32,    33,    34,    35,    36,    37,    38,    39,
+      40,    41,    42,    43,    30,    31,    32,    33,    34,    35,
+      36,    37,    38,    39,    40,    41,    42,    43,    31,    32,
+      33,    34,    35,    36,    37,    38,    39,    40,    41,    42,
+      43,    33,    34,    35,    36,    37,    38,    39,    40,    41,
+      42,    43,    39,    40,    41,    42,    43
+};
+
+/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+   symbol of state STATE-NUM.  */
+static const yytype_uint8 yystos[] =
+{
+       0,    58,     0,     5,     6,     7,     8,     9,    10,    11,
+      12,    13,    14,    15,    16,    17,    18,    20,    21,    22,
+      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
+      34,    35,    36,    37,    38,    39,    40,    41,    42,    43,
+      45,    46,    47,    48,    49,    50,    51,    52,    53,    54,
+      55,    56,    59,    60,    61,    65,    71,    72,    73,    19,
+      20,    39,    40,    45,    47,    48,    62,    63,    21,    66,
+      71,    17,    17,     4,    21,    69,    70,    72,    21,    21,
+      21,    70,    17,    17,    17,    62,    63,    21,    72,    63,
+      63,    63,    63,    63,    21,    26,    27,    28,    29,    30,
+      31,    32,    33,    34,    35,    36,    37,    38,    39,    40,
+      41,    42,    43,    21,    45,    67,    71,    17,    45,    21,
+      69,    21,    68,    71,    68,    21,    21,    21,    46,    63,
+      63,    63,    63,    63,    63,    63,    63,    63,    63,    63,
+      63,    63,    63,    63,    63,    63,    63,    17,    46,    64,
+      21,    17,    21,    21,    67,    46,    49,    46,    21,    67,
+      17,    21
+};
+
+#define yyerrok		(yyerrstatus = 0)
+#define yyclearin	(yychar = YYEMPTY)
+#define YYEMPTY		(-2)
+#define YYEOF		0
+
+#define YYACCEPT	goto yyacceptlab
+#define YYABORT		goto yyabortlab
+#define YYERROR		goto yyerrorlab
+
+
+/* Like YYERROR except do call yyerror.  This remains here temporarily
+   to ease the transition to the new meaning of YYERROR, for GCC.
+   Once GCC version 2 has supplanted version 1, this can go.  However,
+   YYFAIL appears to be in use.  Nevertheless, it is formally deprecated
+   in Bison 2.4.2's NEWS entry, where a plan to phase it out is
+   discussed.  */
+
+#define YYFAIL		goto yyerrlab
+#if defined YYFAIL
+  /* This is here to suppress warnings from the GCC cpp's
+     -Wunused-macros.  Normally we don't worry about that warning, but
+     some users do, and we want to make it easy for users to remove
+     YYFAIL uses, which will produce warnings from Bison 2.5.  */
+#endif
+
+#define YYRECOVERING()  (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value)					\
+do								\
+  if (yychar == YYEMPTY && yylen == 1)				\
+    {								\
+      yychar = (Token);						\
+      yylval = (Value);						\
+      yytoken = YYTRANSLATE (yychar);				\
+      YYPOPSTACK (1);						\
+      goto yybackup;						\
+    }								\
+  else								\
+    {								\
+      yyerror (&yylloc, parser, YY_("syntax error: cannot back up")); \
+      YYERROR;							\
+    }								\
+while (YYID (0))
+
+
+#define YYTERROR	1
+#define YYERRCODE	256
+
+
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+   If N is 0, then set CURRENT to the empty location which ends
+   the previous symbol: RHS[0] (always defined).  */
+
+#define YYRHSLOC(Rhs, K) ((Rhs)[K])
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N)				\
+    do									\
+      if (YYID (N))                                                    \
+	{								\
+	  (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;	\
+	  (Current).first_column = YYRHSLOC (Rhs, 1).first_column;	\
+	  (Current).last_line    = YYRHSLOC (Rhs, N).last_line;		\
+	  (Current).last_column  = YYRHSLOC (Rhs, N).last_column;	\
+	}								\
+      else								\
+	{								\
+	  (Current).first_line   = (Current).last_line   =		\
+	    YYRHSLOC (Rhs, 0).last_line;				\
+	  (Current).first_column = (Current).last_column =		\
+	    YYRHSLOC (Rhs, 0).last_column;				\
+	}								\
+    while (YYID (0))
+#endif
+
+
+/* YY_LOCATION_PRINT -- Print the location on the stream.
+   This macro was not mandated originally: define only if we know
+   we won't break user code: when these are the locations we know.  */
+
+#ifndef YY_LOCATION_PRINT
+# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
+#  define YY_LOCATION_PRINT(File, Loc)			\
+     fprintf (File, "%d.%d-%d.%d",			\
+	      (Loc).first_line, (Loc).first_column,	\
+	      (Loc).last_line,  (Loc).last_column)
+# else
+#  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+# endif
+#endif
+
+
+/* YYLEX -- calling `yylex' with the right arguments.  */
+
+#ifdef YYLEX_PARAM
+# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
+#else
+# define YYLEX yylex (&yylval, &yylloc, parser)
+#endif
+
+/* Enable debugging if requested.  */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+#  define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args)			\
+do {						\
+  if (yydebug)					\
+    YYFPRINTF Args;				\
+} while (YYID (0))
+
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)			  \
+do {									  \
+  if (yydebug)								  \
+    {									  \
+      YYFPRINTF (stderr, "%s ", Title);					  \
+      yy_symbol_print (stderr,						  \
+		  Type, Value, Location, parser); \
+      YYFPRINTF (stderr, "\n");						  \
+    }									  \
+} while (YYID (0))
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT.  |
+`--------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, glcpp_parser_t *parser)
+#else
+static void
+yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, parser)
+    FILE *yyoutput;
+    int yytype;
+    YYSTYPE const * const yyvaluep;
+    YYLTYPE const * const yylocationp;
+    glcpp_parser_t *parser;
+#endif
+{
+  if (!yyvaluep)
+    return;
+  YYUSE (yylocationp);
+  YYUSE (parser);
+# ifdef YYPRINT
+  if (yytype < YYNTOKENS)
+    YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# else
+  YYUSE (yyoutput);
+# endif
+  switch (yytype)
+    {
+      default:
+	break;
+    }
+}
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT.  |
+`--------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, glcpp_parser_t *parser)
+#else
+static void
+yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, parser)
+    FILE *yyoutput;
+    int yytype;
+    YYSTYPE const * const yyvaluep;
+    YYLTYPE const * const yylocationp;
+    glcpp_parser_t *parser;
+#endif
+{
+  if (yytype < YYNTOKENS)
+    YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+  else
+    YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+
+  YY_LOCATION_PRINT (yyoutput, *yylocationp);
+  YYFPRINTF (yyoutput, ": ");
+  yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, parser);
+  YYFPRINTF (yyoutput, ")");
+}
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (included).                                                   |
+`------------------------------------------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+static void
+yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
+#else
+static void
+yy_stack_print (yybottom, yytop)
+    yytype_int16 *yybottom;
+    yytype_int16 *yytop;
+#endif
+{
+  YYFPRINTF (stderr, "Stack now");
+  for (; yybottom <= yytop; yybottom++)
+    {
+      int yybot = *yybottom;
+      YYFPRINTF (stderr, " %d", yybot);
+    }
+  YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top)				\
+do {								\
+  if (yydebug)							\
+    yy_stack_print ((Bottom), (Top));				\
+} while (YYID (0))
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced.  |
+`------------------------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+static void
+yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, glcpp_parser_t *parser)
+#else
+static void
+yy_reduce_print (yyvsp, yylsp, yyrule, parser)
+    YYSTYPE *yyvsp;
+    YYLTYPE *yylsp;
+    int yyrule;
+    glcpp_parser_t *parser;
+#endif
+{
+  int yynrhs = yyr2[yyrule];
+  int yyi;
+  unsigned long int yylno = yyrline[yyrule];
+  YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
+	     yyrule - 1, yylno);
+  /* The symbols being reduced.  */
+  for (yyi = 0; yyi < yynrhs; yyi++)
+    {
+      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
+      yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
+		       &(yyvsp[(yyi + 1) - (yynrhs)])
+		       , &(yylsp[(yyi + 1) - (yynrhs)])		       , parser);
+      YYFPRINTF (stderr, "\n");
+    }
+}
+
+# define YY_REDUCE_PRINT(Rule)		\
+do {					\
+  if (yydebug)				\
+    yy_reduce_print (yyvsp, yylsp, Rule, parser); \
+} while (YYID (0))
+
+/* Nonzero means print parse trace.  It is left uninitialized so that
+   multiple parsers can coexist.  */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !YYDEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks.  */
+#ifndef	YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+   if the built-in stack extension method is used).
+
+   Do not make this value too large; the results are undefined if
+   YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
+   evaluated with infinite-precision integer arithmetic.  */
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+#  if defined __GLIBC__ && defined _STRING_H
+#   define yystrlen strlen
+#  else
+/* Return the length of YYSTR.  */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+static YYSIZE_T
+yystrlen (const char *yystr)
+#else
+static YYSIZE_T
+yystrlen (yystr)
+    const char *yystr;
+#endif
+{
+  YYSIZE_T yylen;
+  for (yylen = 0; yystr[yylen]; yylen++)
+    continue;
+  return yylen;
+}
+#  endif
+# endif
+
+# ifndef yystpcpy
+#  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
+#   define yystpcpy stpcpy
+#  else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+   YYDEST.  */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+static char *
+yystpcpy (char *yydest, const char *yysrc)
+#else
+static char *
+yystpcpy (yydest, yysrc)
+    char *yydest;
+    const char *yysrc;
+#endif
+{
+  char *yyd = yydest;
+  const char *yys = yysrc;
+
+  while ((*yyd++ = *yys++) != '\0')
+    continue;
+
+  return yyd - 1;
+}
+#  endif
+# endif
+
+# ifndef yytnamerr
+/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
+   quotes and backslashes, so that it's suitable for yyerror.  The
+   heuristic is that double-quoting is unnecessary unless the string
+   contains an apostrophe, a comma, or backslash (other than
+   backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
+   null, do not copy; instead, return the length of what the result
+   would have been.  */
+static YYSIZE_T
+yytnamerr (char *yyres, const char *yystr)
+{
+  if (*yystr == '"')
+    {
+      YYSIZE_T yyn = 0;
+      char const *yyp = yystr;
+
+      for (;;)
+	switch (*++yyp)
+	  {
+	  case '\'':
+	  case ',':
+	    goto do_not_strip_quotes;
+
+	  case '\\':
+	    if (*++yyp != '\\')
+	      goto do_not_strip_quotes;
+	    /* Fall through.  */
+	  default:
+	    if (yyres)
+	      yyres[yyn] = *yyp;
+	    yyn++;
+	    break;
+
+	  case '"':
+	    if (yyres)
+	      yyres[yyn] = '\0';
+	    return yyn;
+	  }
+    do_not_strip_quotes: ;
+    }
+
+  if (! yyres)
+    return yystrlen (yystr);
+
+  return yystpcpy (yyres, yystr) - yyres;
+}
+# endif
+
+/* Copy into YYRESULT an error message about the unexpected token
+   YYCHAR while in state YYSTATE.  Return the number of bytes copied,
+   including the terminating null byte.  If YYRESULT is null, do not
+   copy anything; just return the number of bytes that would be
+   copied.  As a special case, return 0 if an ordinary "syntax error"
+   message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
+   size calculation.  */
+static YYSIZE_T
+yysyntax_error (char *yyresult, int yystate, int yychar)
+{
+  int yyn = yypact[yystate];
+
+  if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
+    return 0;
+  else
+    {
+      int yytype = YYTRANSLATE (yychar);
+      YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
+      YYSIZE_T yysize = yysize0;
+      YYSIZE_T yysize1;
+      int yysize_overflow = 0;
+      enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+      char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+      int yyx;
+
+# if 0
+      /* This is so xgettext sees the translatable formats that are
+	 constructed on the fly.  */
+      YY_("syntax error, unexpected %s");
+      YY_("syntax error, unexpected %s, expecting %s");
+      YY_("syntax error, unexpected %s, expecting %s or %s");
+      YY_("syntax error, unexpected %s, expecting %s or %s or %s");
+      YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
+# endif
+      char *yyfmt;
+      char const *yyf;
+      static char const yyunexpected[] = "syntax error, unexpected %s";
+      static char const yyexpecting[] = ", expecting %s";
+      static char const yyor[] = " or %s";
+      char yyformat[sizeof yyunexpected
+		    + sizeof yyexpecting - 1
+		    + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
+		       * (sizeof yyor - 1))];
+      char const *yyprefix = yyexpecting;
+
+      /* Start YYX at -YYN if negative to avoid negative indexes in
+	 YYCHECK.  */
+      int yyxbegin = yyn < 0 ? -yyn : 0;
+
+      /* Stay within bounds of both yycheck and yytname.  */
+      int yychecklim = YYLAST - yyn + 1;
+      int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+      int yycount = 1;
+
+      yyarg[0] = yytname[yytype];
+      yyfmt = yystpcpy (yyformat, yyunexpected);
+
+      for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+	if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+	  {
+	    if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+	      {
+		yycount = 1;
+		yysize = yysize0;
+		yyformat[sizeof yyunexpected - 1] = '\0';
+		break;
+	      }
+	    yyarg[yycount++] = yytname[yyx];
+	    yysize1 = yysize + yytnamerr (0, yytname[yyx]);
+	    yysize_overflow |= (yysize1 < yysize);
+	    yysize = yysize1;
+	    yyfmt = yystpcpy (yyfmt, yyprefix);
+	    yyprefix = yyor;
+	  }
+
+      yyf = YY_(yyformat);
+      yysize1 = yysize + yystrlen (yyf);
+      yysize_overflow |= (yysize1 < yysize);
+      yysize = yysize1;
+
+      if (yysize_overflow)
+	return YYSIZE_MAXIMUM;
+
+      if (yyresult)
+	{
+	  /* Avoid sprintf, as that infringes on the user's name space.
+	     Don't have undefined behavior even if the translation
+	     produced a string with the wrong number of "%s"s.  */
+	  char *yyp = yyresult;
+	  int yyi = 0;
+	  while ((*yyp = *yyf) != '\0')
+	    {
+	      if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
+		{
+		  yyp += yytnamerr (yyp, yyarg[yyi++]);
+		  yyf += 2;
+		}
+	      else
+		{
+		  yyp++;
+		  yyf++;
+		}
+	    }
+	}
+      return yysize;
+    }
+}
+#endif /* YYERROR_VERBOSE */
+
+
+/*-----------------------------------------------.
+| Release the memory associated to this symbol.  |
+`-----------------------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+static void
+yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, glcpp_parser_t *parser)
+#else
+static void
+yydestruct (yymsg, yytype, yyvaluep, yylocationp, parser)
+    const char *yymsg;
+    int yytype;
+    YYSTYPE *yyvaluep;
+    YYLTYPE *yylocationp;
+    glcpp_parser_t *parser;
+#endif
+{
+  YYUSE (yyvaluep);
+  YYUSE (yylocationp);
+  YYUSE (parser);
+
+  if (!yymsg)
+    yymsg = "Deleting";
+  YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+
+  switch (yytype)
+    {
+
+      default:
+	break;
+    }
+}
+
+/* Prevent warnings from -Wmissing-prototypes.  */
+#ifdef YYPARSE_PARAM
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *YYPARSE_PARAM);
+#else
+int yyparse ();
+#endif
+#else /* ! YYPARSE_PARAM */
+#if defined __STDC__ || defined __cplusplus
+int yyparse (glcpp_parser_t *parser);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+
+
+
+
+
+/*-------------------------.
+| yyparse or yypush_parse.  |
+`-------------------------*/
+
+#ifdef YYPARSE_PARAM
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (void *YYPARSE_PARAM)
+#else
+int
+yyparse (YYPARSE_PARAM)
+    void *YYPARSE_PARAM;
+#endif
+#else /* ! YYPARSE_PARAM */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+     || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (glcpp_parser_t *parser)
+#else
+int
+yyparse (parser)
+    glcpp_parser_t *parser;
+#endif
+#endif
+{
+/* The lookahead symbol.  */
+int yychar;
+
+/* The semantic value of the lookahead symbol.  */
+YYSTYPE yylval;
+
+/* Location data for the lookahead symbol.  */
+YYLTYPE yylloc;
+
+    /* Number of syntax errors so far.  */
+    int yynerrs;
+
+    int yystate;
+    /* Number of tokens to shift before error messages enabled.  */
+    int yyerrstatus;
+
+    /* The stacks and their tools:
+       `yyss': related to states.
+       `yyvs': related to semantic values.
+       `yyls': related to locations.
+
+       Refer to the stacks thru separate pointers, to allow yyoverflow
+       to reallocate them elsewhere.  */
+
+    /* The state stack.  */
+    yytype_int16 yyssa[YYINITDEPTH];
+    yytype_int16 *yyss;
+    yytype_int16 *yyssp;
+
+    /* The semantic value stack.  */
+    YYSTYPE yyvsa[YYINITDEPTH];
+    YYSTYPE *yyvs;
+    YYSTYPE *yyvsp;
+
+    /* The location stack.  */
+    YYLTYPE yylsa[YYINITDEPTH];
+    YYLTYPE *yyls;
+    YYLTYPE *yylsp;
+
+    /* The locations where the error started and ended.  */
+    YYLTYPE yyerror_range[3];
+
+    YYSIZE_T yystacksize;
+
+  int yyn;
+  int yyresult;
+  /* Lookahead token as an internal (translated) token number.  */
+  int yytoken;
+  /* The variables used to return semantic value and location from the
+     action routines.  */
+  YYSTYPE yyval;
+  YYLTYPE yyloc;
+
+#if YYERROR_VERBOSE
+  /* Buffer for error messages, and its allocated size.  */
+  char yymsgbuf[128];
+  char *yymsg = yymsgbuf;
+  YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
+#endif
+
+#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
+
+  /* The number of symbols on the RHS of the reduced rule.
+     Keep to zero when no symbol should be popped.  */
+  int yylen = 0;
+
+  yytoken = 0;
+  yyss = yyssa;
+  yyvs = yyvsa;
+  yyls = yylsa;
+  yystacksize = YYINITDEPTH;
+
+  YYDPRINTF ((stderr, "Starting parse\n"));
+
+  yystate = 0;
+  yyerrstatus = 0;
+  yynerrs = 0;
+  yychar = YYEMPTY; /* Cause a token to be read.  */
+
+  /* Initialize stack pointers.
+     Waste one element of value and location stack
+     so that they stay on the same level as the state stack.
+     The wasted elements are never initialized.  */
+  yyssp = yyss;
+  yyvsp = yyvs;
+  yylsp = yyls;
+
+#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
+  /* Initialize the default location before parsing starts.  */
+  yylloc.first_line   = yylloc.last_line   = 1;
+  yylloc.first_column = yylloc.last_column = 1;
+#endif
+
+/* User initialization code.  */
+
+/* Line 1251 of yacc.c  */
+#line 152 "glcpp/glcpp-parse.y"
+{
+	yylloc.first_line = 1;
+	yylloc.first_column = 1;
+	yylloc.last_line = 1;
+	yylloc.last_column = 1;
+	yylloc.source = 0;
+}
+
+/* Line 1251 of yacc.c  */
+#line 1622 "glcpp/glcpp-parse.c"
+  yylsp[0] = yylloc;
+
+  goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate.  |
+`------------------------------------------------------------*/
+ yynewstate:
+  /* In all cases, when you get here, the value and location stacks
+     have just been pushed.  So pushing a state here evens the stacks.  */
+  yyssp++;
+
+ yysetstate:
+  *yyssp = yystate;
+
+  if (yyss + yystacksize - 1 <= yyssp)
+    {
+      /* Get the current used size of the three stacks, in elements.  */
+      YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+      {
+	/* Give user a chance to reallocate the stack.  Use copies of
+	   these so that the &'s don't force the real ones into
+	   memory.  */
+	YYSTYPE *yyvs1 = yyvs;
+	yytype_int16 *yyss1 = yyss;
+	YYLTYPE *yyls1 = yyls;
+
+	/* Each stack pointer address is followed by the size of the
+	   data in use in that stack, in bytes.  This used to be a
+	   conditional around just the two extra args, but that might
+	   be undefined if yyoverflow is a macro.  */
+	yyoverflow (YY_("memory exhausted"),
+		    &yyss1, yysize * sizeof (*yyssp),
+		    &yyvs1, yysize * sizeof (*yyvsp),
+		    &yyls1, yysize * sizeof (*yylsp),
+		    &yystacksize);
+
+	yyls = yyls1;
+	yyss = yyss1;
+	yyvs = yyvs1;
+      }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+      goto yyexhaustedlab;
+# else
+      /* Extend the stack our own way.  */
+      if (YYMAXDEPTH <= yystacksize)
+	goto yyexhaustedlab;
+      yystacksize *= 2;
+      if (YYMAXDEPTH < yystacksize)
+	yystacksize = YYMAXDEPTH;
+
+      {
+	yytype_int16 *yyss1 = yyss;
+	union yyalloc *yyptr =
+	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+	if (! yyptr)
+	  goto yyexhaustedlab;
+	YYSTACK_RELOCATE (yyss_alloc, yyss);
+	YYSTACK_RELOCATE (yyvs_alloc, yyvs);
+	YYSTACK_RELOCATE (yyls_alloc, yyls);
+#  undef YYSTACK_RELOCATE
+	if (yyss1 != yyssa)
+	  YYSTACK_FREE (yyss1);
+      }
+# endif
+#endif /* no yyoverflow */
+
+      yyssp = yyss + yysize - 1;
+      yyvsp = yyvs + yysize - 1;
+      yylsp = yyls + yysize - 1;
+
+      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+		  (unsigned long int) yystacksize));
+
+      if (yyss + yystacksize - 1 <= yyssp)
+	YYABORT;
+    }
+
+  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+  if (yystate == YYFINAL)
+    YYACCEPT;
+
+  goto yybackup;
+
+/*-----------.
+| yybackup.  |
+`-----------*/
+yybackup:
+
+  /* Do appropriate processing given the current state.  Read a
+     lookahead token if we need one and don't already have one.  */
+
+  /* First try to decide what to do without reference to lookahead token.  */
+  yyn = yypact[yystate];
+  if (yyn == YYPACT_NINF)
+    goto yydefault;
+
+  /* Not known => get a lookahead token if don't already have one.  */
+
+  /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
+  if (yychar == YYEMPTY)
+    {
+      YYDPRINTF ((stderr, "Reading a token: "));
+      yychar = YYLEX;
+    }
+
+  if (yychar <= YYEOF)
+    {
+      yychar = yytoken = YYEOF;
+      YYDPRINTF ((stderr, "Now at end of input.\n"));
+    }
+  else
+    {
+      yytoken = YYTRANSLATE (yychar);
+      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+    }
+
+  /* If the proper action on seeing token YYTOKEN is to reduce or to
+     detect an error, take that action.  */
+  yyn += yytoken;
+  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+    goto yydefault;
+  yyn = yytable[yyn];
+  if (yyn <= 0)
+    {
+      if (yyn == 0 || yyn == YYTABLE_NINF)
+	goto yyerrlab;
+      yyn = -yyn;
+      goto yyreduce;
+    }
+
+  /* Count tokens shifted since error; after three, turn off error
+     status.  */
+  if (yyerrstatus)
+    yyerrstatus--;
+
+  /* Shift the lookahead token.  */
+  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+
+  /* Discard the shifted token.  */
+  yychar = YYEMPTY;
+
+  yystate = yyn;
+  *++yyvsp = yylval;
+  *++yylsp = yylloc;
+  goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state.  |
+`-----------------------------------------------------------*/
+yydefault:
+  yyn = yydefact[yystate];
+  if (yyn == 0)
+    goto yyerrlab;
+  goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction.  |
+`-----------------------------*/
+yyreduce:
+  /* yyn is the number of a rule to reduce with.  */
+  yylen = yyr2[yyn];
+
+  /* If YYLEN is nonzero, implement the default value of the action:
+     `$$ = $1'.
+
+     Otherwise, the following line sets YYVAL to garbage.
+     This behavior is undocumented and Bison
+     users should not rely upon it.  Assigning to YYVAL
+     unconditionally makes the parser a bit smaller, and it avoids a
+     GCC warning that YYVAL may be used uninitialized.  */
+  yyval = yyvsp[1-yylen];
+
+  /* Default location.  */
+  YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
+  YY_REDUCE_PRINT (yyn);
+  switch (yyn)
+    {
+        case 4:
+
+/* Line 1464 of yacc.c  */
+#line 191 "glcpp/glcpp-parse.y"
+    {
+		glcpp_print(parser->output, "\n");
+	;}
+    break;
+
+  case 5:
+
+/* Line 1464 of yacc.c  */
+#line 194 "glcpp/glcpp-parse.y"
+    {
+		_glcpp_parser_print_expanded_token_list (parser, (yyvsp[(1) - (1)].token_list));
+		glcpp_print(parser->output, "\n");
+		talloc_free ((yyvsp[(1) - (1)].token_list));
+	;}
+    break;
+
+  case 8:
+
+/* Line 1464 of yacc.c  */
+#line 204 "glcpp/glcpp-parse.y"
+    {
+		_glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (3)]), (yyvsp[(2) - (3)].ival));
+	;}
+    break;
+
+  case 9:
+
+/* Line 1464 of yacc.c  */
+#line 207 "glcpp/glcpp-parse.y"
+    {
+		_glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (3)]), "elif", (yyvsp[(2) - (3)].ival));
+	;}
+    break;
+
+  case 10:
+
+/* Line 1464 of yacc.c  */
+#line 213 "glcpp/glcpp-parse.y"
+    {
+		_define_object_macro (parser, & (yylsp[(2) - (4)]), (yyvsp[(2) - (4)].str), (yyvsp[(3) - (4)].token_list));
+	;}
+    break;
+
+  case 11:
+
+/* Line 1464 of yacc.c  */
+#line 216 "glcpp/glcpp-parse.y"
+    {
+		_define_function_macro (parser, & (yylsp[(2) - (6)]), (yyvsp[(2) - (6)].str), NULL, (yyvsp[(5) - (6)].token_list));
+	;}
+    break;
+
+  case 12:
+
+/* Line 1464 of yacc.c  */
+#line 219 "glcpp/glcpp-parse.y"
+    {
+		_define_function_macro (parser, & (yylsp[(2) - (7)]), (yyvsp[(2) - (7)].str), (yyvsp[(4) - (7)].string_list), (yyvsp[(6) - (7)].token_list));
+	;}
+    break;
+
+  case 13:
+
+/* Line 1464 of yacc.c  */
+#line 222 "glcpp/glcpp-parse.y"
+    {
+		macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (3)].str));
+		if (macro) {
+			hash_table_remove (parser->defines, (yyvsp[(2) - (3)].str));
+			talloc_free (macro);
+		}
+		talloc_free ((yyvsp[(2) - (3)].str));
+	;}
+    break;
+
+  case 14:
+
+/* Line 1464 of yacc.c  */
+#line 230 "glcpp/glcpp-parse.y"
+    {
+		/* Be careful to only evaluate the 'if' expression if
+		 * we are not skipping. When we are skipping, we
+		 * simply push a new 0-valued 'if' onto the skip
+		 * stack.
+		 *
+		 * This avoids generating diagnostics for invalid
+		 * expressions that are being skipped. */
+		if (parser->skip_stack == NULL ||
+		    parser->skip_stack->type == SKIP_NO_SKIP)
+		{
+			_glcpp_parser_expand_if (parser, IF_EXPANDED, (yyvsp[(2) - (3)].token_list));
+		}	
+		else
+		{
+			_glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (3)]), 0);
+			parser->skip_stack->type = SKIP_TO_ENDIF;
+		}
+	;}
+    break;
+
+  case 15:
+
+/* Line 1464 of yacc.c  */
+#line 249 "glcpp/glcpp-parse.y"
+    {
+		/* #if without an expression is only an error if we
+		 *  are not skipping */
+		if (parser->skip_stack == NULL ||
+		    parser->skip_stack->type == SKIP_NO_SKIP)
+		{
+			glcpp_error(& (yylsp[(1) - (2)]), parser, "#if with no expression");
+		}	
+		_glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (2)]), 0);
+	;}
+    break;
+
+  case 16:
+
+/* Line 1464 of yacc.c  */
+#line 259 "glcpp/glcpp-parse.y"
+    {
+		macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (4)].str));
+		talloc_free ((yyvsp[(2) - (4)].str));
+		_glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (4)]), macro != NULL);
+	;}
+    break;
+
+  case 17:
+
+/* Line 1464 of yacc.c  */
+#line 264 "glcpp/glcpp-parse.y"
+    {
+		macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (4)].str));
+		talloc_free ((yyvsp[(2) - (4)].str));
+		_glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (4)]), macro == NULL);
+	;}
+    break;
+
+  case 18:
+
+/* Line 1464 of yacc.c  */
+#line 269 "glcpp/glcpp-parse.y"
+    {
+		/* Be careful to only evaluate the 'elif' expression
+		 * if we are not skipping. When we are skipping, we
+		 * simply change to a 0-valued 'elif' on the skip
+		 * stack.
+		 *
+		 * This avoids generating diagnostics for invalid
+		 * expressions that are being skipped. */
+		if (parser->skip_stack &&
+		    parser->skip_stack->type == SKIP_TO_ELSE)
+		{
+			_glcpp_parser_expand_if (parser, ELIF_EXPANDED, (yyvsp[(2) - (3)].token_list));
+		}
+		else
+		{
+			_glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (3)]),
+							    "elif", 0);
+		}
+	;}
+    break;
+
+  case 19:
+
+/* Line 1464 of yacc.c  */
+#line 288 "glcpp/glcpp-parse.y"
+    {
+		/* #elif without an expression is an error unless we
+		 * are skipping. */
+		if (parser->skip_stack &&
+		    parser->skip_stack->type == SKIP_TO_ELSE)
+		{
+			glcpp_error(& (yylsp[(1) - (2)]), parser, "#elif with no expression");
+		}
+		else
+		{
+			_glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (2)]),
+							    "elif", 0);
+			glcpp_warning(& (yylsp[(1) - (2)]), parser, "ignoring illegal #elif without expression");
+		}
+	;}
+    break;
+
+  case 20:
+
+/* Line 1464 of yacc.c  */
+#line 303 "glcpp/glcpp-parse.y"
+    {
+		_glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (2)]), "else", 1);
+	;}
+    break;
+
+  case 21:
+
+/* Line 1464 of yacc.c  */
+#line 306 "glcpp/glcpp-parse.y"
+    {
+		_glcpp_parser_skip_stack_pop (parser, & (yylsp[(1) - (2)]));
+	;}
+    break;
+
+  case 22:
+
+/* Line 1464 of yacc.c  */
+#line 309 "glcpp/glcpp-parse.y"
+    {
+		macro_t *macro = hash_table_find (parser->defines, "__VERSION__");
+		if (macro) {
+			hash_table_remove (parser->defines, "__VERSION__");
+			talloc_free (macro);
+		}
+		add_builtin_define (parser, "__VERSION__", (yyvsp[(2) - (3)].ival));
+
+		if ((yyvsp[(2) - (3)].ival) == 100)
+			add_builtin_define (parser, "GL_ES", 1);
+
+		/* Currently, all ES2 implementations support highp in the
+		 * fragment shader, so we always define this macro in ES2.
+		 * If we ever get a driver that doesn't support highp, we'll
+		 * need to add a flag to the gl_context and check that here.
+		 */
+		if ((yyvsp[(2) - (3)].ival) >= 130 || (yyvsp[(2) - (3)].ival) == 100)
+			add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1);
+
+		glcpp_printf(parser->output, "#version %" PRIiMAX, (yyvsp[(2) - (3)].ival));
+	;}
+    break;
+
+  case 24:
+
+/* Line 1464 of yacc.c  */
+#line 334 "glcpp/glcpp-parse.y"
+    {
+		if (strlen ((yyvsp[(1) - (1)].str)) >= 3 && strncmp ((yyvsp[(1) - (1)].str), "0x", 2) == 0) {
+			(yyval.ival) = strtoll ((yyvsp[(1) - (1)].str) + 2, NULL, 16);
+		} else if ((yyvsp[(1) - (1)].str)[0] == '0') {
+			(yyval.ival) = strtoll ((yyvsp[(1) - (1)].str), NULL, 8);
+		} else {
+			(yyval.ival) = strtoll ((yyvsp[(1) - (1)].str), NULL, 10);
+		}
+	;}
+    break;
+
+  case 25:
+
+/* Line 1464 of yacc.c  */
+#line 343 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (1)].ival);
+	;}
+    break;
+
+  case 27:
+
+/* Line 1464 of yacc.c  */
+#line 349 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) || (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 28:
+
+/* Line 1464 of yacc.c  */
+#line 352 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) && (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 29:
+
+/* Line 1464 of yacc.c  */
+#line 355 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) | (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 30:
+
+/* Line 1464 of yacc.c  */
+#line 358 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) ^ (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 31:
+
+/* Line 1464 of yacc.c  */
+#line 361 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) & (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 32:
+
+/* Line 1464 of yacc.c  */
+#line 364 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) != (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 33:
+
+/* Line 1464 of yacc.c  */
+#line 367 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) == (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 34:
+
+/* Line 1464 of yacc.c  */
+#line 370 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) >= (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 35:
+
+/* Line 1464 of yacc.c  */
+#line 373 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) <= (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 36:
+
+/* Line 1464 of yacc.c  */
+#line 376 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) > (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 37:
+
+/* Line 1464 of yacc.c  */
+#line 379 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) < (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 38:
+
+/* Line 1464 of yacc.c  */
+#line 382 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) >> (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 39:
+
+/* Line 1464 of yacc.c  */
+#line 385 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) << (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 40:
+
+/* Line 1464 of yacc.c  */
+#line 388 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) - (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 41:
+
+/* Line 1464 of yacc.c  */
+#line 391 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) + (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 42:
+
+/* Line 1464 of yacc.c  */
+#line 394 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) % (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 43:
+
+/* Line 1464 of yacc.c  */
+#line 397 "glcpp/glcpp-parse.y"
+    {
+		if ((yyvsp[(3) - (3)].ival) == 0) {
+			yyerror (& (yylsp[(1) - (3)]), parser,
+				 "division by 0 in preprocessor directive");
+		} else {
+			(yyval.ival) = (yyvsp[(1) - (3)].ival) / (yyvsp[(3) - (3)].ival);
+		}
+	;}
+    break;
+
+  case 44:
+
+/* Line 1464 of yacc.c  */
+#line 405 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(1) - (3)].ival) * (yyvsp[(3) - (3)].ival);
+	;}
+    break;
+
+  case 45:
+
+/* Line 1464 of yacc.c  */
+#line 408 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = ! (yyvsp[(2) - (2)].ival);
+	;}
+    break;
+
+  case 46:
+
+/* Line 1464 of yacc.c  */
+#line 411 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = ~ (yyvsp[(2) - (2)].ival);
+	;}
+    break;
+
+  case 47:
+
+/* Line 1464 of yacc.c  */
+#line 414 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = - (yyvsp[(2) - (2)].ival);
+	;}
+    break;
+
+  case 48:
+
+/* Line 1464 of yacc.c  */
+#line 417 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = + (yyvsp[(2) - (2)].ival);
+	;}
+    break;
+
+  case 49:
+
+/* Line 1464 of yacc.c  */
+#line 420 "glcpp/glcpp-parse.y"
+    {
+		(yyval.ival) = (yyvsp[(2) - (3)].ival);
+	;}
+    break;
+
+  case 50:
+
+/* Line 1464 of yacc.c  */
+#line 426 "glcpp/glcpp-parse.y"
+    {
+		(yyval.string_list) = _string_list_create (parser);
+		_string_list_append_item ((yyval.string_list), (yyvsp[(1) - (1)].str));
+		talloc_steal ((yyval.string_list), (yyvsp[(1) - (1)].str));
+	;}
+    break;
+
+  case 51:
+
+/* Line 1464 of yacc.c  */
+#line 431 "glcpp/glcpp-parse.y"
+    {
+		(yyval.string_list) = (yyvsp[(1) - (3)].string_list);	
+		_string_list_append_item ((yyval.string_list), (yyvsp[(3) - (3)].str));
+		talloc_steal ((yyval.string_list), (yyvsp[(3) - (3)].str));
+	;}
+    break;
+
+  case 52:
+
+/* Line 1464 of yacc.c  */
+#line 439 "glcpp/glcpp-parse.y"
+    { (yyval.token_list) = NULL; ;}
+    break;
+
+  case 54:
+
+/* Line 1464 of yacc.c  */
+#line 444 "glcpp/glcpp-parse.y"
+    {
+		yyerror (& (yylsp[(1) - (2)]), parser, "Invalid tokens after #");
+	;}
+    break;
+
+  case 55:
+
+/* Line 1464 of yacc.c  */
+#line 450 "glcpp/glcpp-parse.y"
+    { (yyval.token_list) = NULL; ;}
+    break;
+
+  case 58:
+
+/* Line 1464 of yacc.c  */
+#line 456 "glcpp/glcpp-parse.y"
+    {
+		glcpp_warning(&(yylsp[(1) - (1)]), parser, "extra tokens at end of directive");
+	;}
+    break;
+
+  case 59:
+
+/* Line 1464 of yacc.c  */
+#line 463 "glcpp/glcpp-parse.y"
+    {
+		int v = hash_table_find (parser->defines, (yyvsp[(2) - (2)].str)) ? 1 : 0;
+		(yyval.token) = _token_create_ival (parser, INTEGER, v);
+	;}
+    break;
+
+  case 60:
+
+/* Line 1464 of yacc.c  */
+#line 467 "glcpp/glcpp-parse.y"
+    {
+		int v = hash_table_find (parser->defines, (yyvsp[(3) - (4)].str)) ? 1 : 0;
+		(yyval.token) = _token_create_ival (parser, INTEGER, v);
+	;}
+    break;
+
+  case 62:
+
+/* Line 1464 of yacc.c  */
+#line 476 "glcpp/glcpp-parse.y"
+    {
+		(yyval.token_list) = _token_list_create (parser);
+		_token_list_append ((yyval.token_list), (yyvsp[(1) - (1)].token));
+	;}
+    break;
+
+  case 63:
+
+/* Line 1464 of yacc.c  */
+#line 480 "glcpp/glcpp-parse.y"
+    {
+		(yyval.token_list) = (yyvsp[(1) - (2)].token_list);
+		_token_list_append ((yyval.token_list), (yyvsp[(2) - (2)].token));
+	;}
+    break;
+
+  case 64:
+
+/* Line 1464 of yacc.c  */
+#line 487 "glcpp/glcpp-parse.y"
+    {
+		parser->space_tokens = 1;
+		(yyval.token_list) = _token_list_create (parser);
+		_token_list_append ((yyval.token_list), (yyvsp[(1) - (1)].token));
+	;}
+    break;
+
+  case 65:
+
+/* Line 1464 of yacc.c  */
+#line 492 "glcpp/glcpp-parse.y"
+    {
+		(yyval.token_list) = (yyvsp[(1) - (2)].token_list);
+		_token_list_append ((yyval.token_list), (yyvsp[(2) - (2)].token));
+	;}
+    break;
+
+  case 66:
+
+/* Line 1464 of yacc.c  */
+#line 499 "glcpp/glcpp-parse.y"
+    {
+		(yyval.token) = _token_create_str (parser, IDENTIFIER, (yyvsp[(1) - (1)].str));
+		(yyval.token)->location = yylloc;
+	;}
+    break;
+
+  case 67:
+
+/* Line 1464 of yacc.c  */
+#line 503 "glcpp/glcpp-parse.y"
+    {
+		(yyval.token) = _token_create_str (parser, INTEGER_STRING, (yyvsp[(1) - (1)].str));
+		(yyval.token)->location = yylloc;
+	;}
+    break;
+
+  case 68:
+
+/* Line 1464 of yacc.c  */
+#line 507 "glcpp/glcpp-parse.y"
+    {
+		(yyval.token) = _token_create_ival (parser, (yyvsp[(1) - (1)].ival), (yyvsp[(1) - (1)].ival));
+		(yyval.token)->location = yylloc;
+	;}
+    break;
+
+  case 69:
+
+/* Line 1464 of yacc.c  */
+#line 511 "glcpp/glcpp-parse.y"
+    {
+		(yyval.token) = _token_create_str (parser, OTHER, (yyvsp[(1) - (1)].str));
+		(yyval.token)->location = yylloc;
+	;}
+    break;
+
+  case 70:
+
+/* Line 1464 of yacc.c  */
+#line 515 "glcpp/glcpp-parse.y"
+    {
+		(yyval.token) = _token_create_ival (parser, SPACE, SPACE);
+		(yyval.token)->location = yylloc;
+	;}
+    break;
+
+  case 71:
+
+/* Line 1464 of yacc.c  */
+#line 522 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '['; ;}
+    break;
+
+  case 72:
+
+/* Line 1464 of yacc.c  */
+#line 523 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = ']'; ;}
+    break;
+
+  case 73:
+
+/* Line 1464 of yacc.c  */
+#line 524 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '('; ;}
+    break;
+
+  case 74:
+
+/* Line 1464 of yacc.c  */
+#line 525 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = ')'; ;}
+    break;
+
+  case 75:
+
+/* Line 1464 of yacc.c  */
+#line 526 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '{'; ;}
+    break;
+
+  case 76:
+
+/* Line 1464 of yacc.c  */
+#line 527 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '}'; ;}
+    break;
+
+  case 77:
+
+/* Line 1464 of yacc.c  */
+#line 528 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '.'; ;}
+    break;
+
+  case 78:
+
+/* Line 1464 of yacc.c  */
+#line 529 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '&'; ;}
+    break;
+
+  case 79:
+
+/* Line 1464 of yacc.c  */
+#line 530 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '*'; ;}
+    break;
+
+  case 80:
+
+/* Line 1464 of yacc.c  */
+#line 531 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '+'; ;}
+    break;
+
+  case 81:
+
+/* Line 1464 of yacc.c  */
+#line 532 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '-'; ;}
+    break;
+
+  case 82:
+
+/* Line 1464 of yacc.c  */
+#line 533 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '~'; ;}
+    break;
+
+  case 83:
+
+/* Line 1464 of yacc.c  */
+#line 534 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '!'; ;}
+    break;
+
+  case 84:
+
+/* Line 1464 of yacc.c  */
+#line 535 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '/'; ;}
+    break;
+
+  case 85:
+
+/* Line 1464 of yacc.c  */
+#line 536 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '%'; ;}
+    break;
+
+  case 86:
+
+/* Line 1464 of yacc.c  */
+#line 537 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = LEFT_SHIFT; ;}
+    break;
+
+  case 87:
+
+/* Line 1464 of yacc.c  */
+#line 538 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = RIGHT_SHIFT; ;}
+    break;
+
+  case 88:
+
+/* Line 1464 of yacc.c  */
+#line 539 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '<'; ;}
+    break;
+
+  case 89:
+
+/* Line 1464 of yacc.c  */
+#line 540 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '>'; ;}
+    break;
+
+  case 90:
+
+/* Line 1464 of yacc.c  */
+#line 541 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = LESS_OR_EQUAL; ;}
+    break;
+
+  case 91:
+
+/* Line 1464 of yacc.c  */
+#line 542 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = GREATER_OR_EQUAL; ;}
+    break;
+
+  case 92:
+
+/* Line 1464 of yacc.c  */
+#line 543 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = EQUAL; ;}
+    break;
+
+  case 93:
+
+/* Line 1464 of yacc.c  */
+#line 544 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = NOT_EQUAL; ;}
+    break;
+
+  case 94:
+
+/* Line 1464 of yacc.c  */
+#line 545 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '^'; ;}
+    break;
+
+  case 95:
+
+/* Line 1464 of yacc.c  */
+#line 546 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '|'; ;}
+    break;
+
+  case 96:
+
+/* Line 1464 of yacc.c  */
+#line 547 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = AND; ;}
+    break;
+
+  case 97:
+
+/* Line 1464 of yacc.c  */
+#line 548 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = OR; ;}
+    break;
+
+  case 98:
+
+/* Line 1464 of yacc.c  */
+#line 549 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = ';'; ;}
+    break;
+
+  case 99:
+
+/* Line 1464 of yacc.c  */
+#line 550 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = ','; ;}
+    break;
+
+  case 100:
+
+/* Line 1464 of yacc.c  */
+#line 551 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = '='; ;}
+    break;
+
+  case 101:
+
+/* Line 1464 of yacc.c  */
+#line 552 "glcpp/glcpp-parse.y"
+    { (yyval.ival) = PASTE; ;}
+    break;
+
+
+
+/* Line 1464 of yacc.c  */
+#line 2661 "glcpp/glcpp-parse.c"
+      default: break;
+    }
+  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
+
+  YYPOPSTACK (yylen);
+  yylen = 0;
+  YY_STACK_PRINT (yyss, yyssp);
+
+  *++yyvsp = yyval;
+  *++yylsp = yyloc;
+
+  /* Now `shift' the result of the reduction.  Determine what state
+     that goes to, based on the state we popped back to and the rule
+     number reduced by.  */
+
+  yyn = yyr1[yyn];
+
+  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+    yystate = yytable[yystate];
+  else
+    yystate = yydefgoto[yyn - YYNTOKENS];
+
+  goto yynewstate;
+
+
+/*------------------------------------.
+| yyerrlab -- here on detecting error |
+`------------------------------------*/
+yyerrlab:
+  /* If not already recovering from an error, report this error.  */
+  if (!yyerrstatus)
+    {
+      ++yynerrs;
+#if ! YYERROR_VERBOSE
+      yyerror (&yylloc, parser, YY_("syntax error"));
+#else
+      {
+	YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
+	if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
+	  {
+	    YYSIZE_T yyalloc = 2 * yysize;
+	    if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
+	      yyalloc = YYSTACK_ALLOC_MAXIMUM;
+	    if (yymsg != yymsgbuf)
+	      YYSTACK_FREE (yymsg);
+	    yymsg = (char *) YYSTACK_ALLOC (yyalloc);
+	    if (yymsg)
+	      yymsg_alloc = yyalloc;
+	    else
+	      {
+		yymsg = yymsgbuf;
+		yymsg_alloc = sizeof yymsgbuf;
+	      }
+	  }
+
+	if (0 < yysize && yysize <= yymsg_alloc)
+	  {
+	    (void) yysyntax_error (yymsg, yystate, yychar);
+	    yyerror (&yylloc, parser, yymsg);
+	  }
+	else
+	  {
+	    yyerror (&yylloc, parser, YY_("syntax error"));
+	    if (yysize != 0)
+	      goto yyexhaustedlab;
+	  }
+      }
+#endif
+    }
+
+  yyerror_range[1] = yylloc;
+
+  if (yyerrstatus == 3)
+    {
+      /* If just tried and failed to reuse lookahead token after an
+	 error, discard it.  */
+
+      if (yychar <= YYEOF)
+	{
+	  /* Return failure if at end of input.  */
+	  if (yychar == YYEOF)
+	    YYABORT;
+	}
+      else
+	{
+	  yydestruct ("Error: discarding",
+		      yytoken, &yylval, &yylloc, parser);
+	  yychar = YYEMPTY;
+	}
+    }
+
+  /* Else will try to reuse lookahead token after shifting the error
+     token.  */
+  goto yyerrlab1;
+
+
+/*---------------------------------------------------.
+| yyerrorlab -- error raised explicitly by YYERROR.  |
+`---------------------------------------------------*/
+yyerrorlab:
+
+  /* Pacify compilers like GCC when the user code never invokes
+     YYERROR and the label yyerrorlab therefore never appears in user
+     code.  */
+  if (/*CONSTCOND*/ 0)
+     goto yyerrorlab;
+
+  yyerror_range[1] = yylsp[1-yylen];
+  /* Do not reclaim the symbols of the rule which action triggered
+     this YYERROR.  */
+  YYPOPSTACK (yylen);
+  yylen = 0;
+  YY_STACK_PRINT (yyss, yyssp);
+  yystate = *yyssp;
+  goto yyerrlab1;
+
+
+/*-------------------------------------------------------------.
+| yyerrlab1 -- common code for both syntax error and YYERROR.  |
+`-------------------------------------------------------------*/
+yyerrlab1:
+  yyerrstatus = 3;	/* Each real token shifted decrements this.  */
+
+  for (;;)
+    {
+      yyn = yypact[yystate];
+      if (yyn != YYPACT_NINF)
+	{
+	  yyn += YYTERROR;
+	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+	    {
+	      yyn = yytable[yyn];
+	      if (0 < yyn)
+		break;
+	    }
+	}
+
+      /* Pop the current state because it cannot handle the error token.  */
+      if (yyssp == yyss)
+	YYABORT;
+
+      yyerror_range[1] = *yylsp;
+      yydestruct ("Error: popping",
+		  yystos[yystate], yyvsp, yylsp, parser);
+      YYPOPSTACK (1);
+      yystate = *yyssp;
+      YY_STACK_PRINT (yyss, yyssp);
+    }
+
+  *++yyvsp = yylval;
+
+  yyerror_range[2] = yylloc;
+  /* Using YYLLOC is tempting, but would change the location of
+     the lookahead.  YYLOC is available though.  */
+  YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
+  *++yylsp = yyloc;
+
+  /* Shift the error token.  */
+  YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
+
+  yystate = yyn;
+  goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here.  |
+`-------------------------------------*/
+yyacceptlab:
+  yyresult = 0;
+  goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here.  |
+`-----------------------------------*/
+yyabortlab:
+  yyresult = 1;
+  goto yyreturn;
+
+#if !defined(yyoverflow) || YYERROR_VERBOSE
+/*-------------------------------------------------.
+| yyexhaustedlab -- memory exhaustion comes here.  |
+`-------------------------------------------------*/
+yyexhaustedlab:
+  yyerror (&yylloc, parser, YY_("memory exhausted"));
+  yyresult = 2;
+  /* Fall through.  */
+#endif
+
+yyreturn:
+  if (yychar != YYEMPTY)
+     yydestruct ("Cleanup: discarding lookahead",
+		 yytoken, &yylval, &yylloc, parser);
+  /* Do not reclaim the symbols of the rule which action triggered
+     this YYABORT or YYACCEPT.  */
+  YYPOPSTACK (yylen);
+  YY_STACK_PRINT (yyss, yyssp);
+  while (yyssp != yyss)
+    {
+      yydestruct ("Cleanup: popping",
+		  yystos[*yyssp], yyvsp, yylsp, parser);
+      YYPOPSTACK (1);
+    }
+#ifndef yyoverflow
+  if (yyss != yyssa)
+    YYSTACK_FREE (yyss);
+#endif
+#if YYERROR_VERBOSE
+  if (yymsg != yymsgbuf)
+    YYSTACK_FREE (yymsg);
+#endif
+  /* Make sure YYID is used.  */
+  return YYID (yyresult);
+}
+
+
+
+/* Line 1684 of yacc.c  */
+#line 555 "glcpp/glcpp-parse.y"
+
+
+string_list_t *
+_string_list_create (void *ctx)
+{
+	string_list_t *list;
+
+	list = talloc (ctx, string_list_t);
+	list->head = NULL;
+	list->tail = NULL;
+
+	return list;
+}
+
+void
+_string_list_append_item (string_list_t *list, const char *str)
+{
+	string_node_t *node;
+
+	node = talloc (list, string_node_t);
+	node->str = talloc_strdup (node, str);
+
+	node->next = NULL;
+
+	if (list->head == NULL) {
+		list->head = node;
+	} else {
+		list->tail->next = node;
+	}
+
+	list->tail = node;
+}
+
+int
+_string_list_contains (string_list_t *list, const char *member, int *index)
+{
+	string_node_t *node;
+	int i;
+
+	if (list == NULL)
+		return 0;
+
+	for (i = 0, node = list->head; node; i++, node = node->next) {
+		if (strcmp (node->str, member) == 0) {
+			if (index)
+				*index = i;
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
+int
+_string_list_length (string_list_t *list)
+{
+	int length = 0;
+	string_node_t *node;
+
+	if (list == NULL)
+		return 0;
+
+	for (node = list->head; node; node = node->next)
+		length++;
+
+	return length;
+}
+
+int
+_string_list_equal (string_list_t *a, string_list_t *b)
+{
+	string_node_t *node_a, *node_b;
+
+	if (a == NULL && b == NULL)
+		return 1;
+
+	if (a == NULL || b == NULL)
+		return 0;
+
+	for (node_a = a->head, node_b = b->head;
+	     node_a && node_b;
+	     node_a = node_a->next, node_b = node_b->next)
+	{
+		if (strcmp (node_a->str, node_b->str))
+			return 0;
+	}
+
+	/* Catch the case of lists being different lengths, (which
+	 * would cause the loop above to terminate after the shorter
+	 * list). */
+	return node_a == node_b;
+}
+
+argument_list_t *
+_argument_list_create (void *ctx)
+{
+	argument_list_t *list;
+
+	list = talloc (ctx, argument_list_t);
+	list->head = NULL;
+	list->tail = NULL;
+
+	return list;
+}
+
+void
+_argument_list_append (argument_list_t *list, token_list_t *argument)
+{
+	argument_node_t *node;
+
+	node = talloc (list, argument_node_t);
+	node->argument = argument;
+
+	node->next = NULL;
+
+	if (list->head == NULL) {
+		list->head = node;
+	} else {
+		list->tail->next = node;
+	}
+
+	list->tail = node;
+}
+
+int
+_argument_list_length (argument_list_t *list)
+{
+	int length = 0;
+	argument_node_t *node;
+
+	if (list == NULL)
+		return 0;
+
+	for (node = list->head; node; node = node->next)
+		length++;
+
+	return length;
+}
+
+token_list_t *
+_argument_list_member_at (argument_list_t *list, int index)
+{
+	argument_node_t *node;
+	int i;
+
+	if (list == NULL)
+		return NULL;
+
+	node = list->head;
+	for (i = 0; i < index; i++) {
+		node = node->next;
+		if (node == NULL)
+			break;
+	}
+
+	if (node)
+		return node->argument;
+
+	return NULL;
+}
+
+/* Note: This function talloc_steal()s the str pointer. */
+token_t *
+_token_create_str (void *ctx, int type, char *str)
+{
+	token_t *token;
+
+	token = talloc (ctx, token_t);
+	token->type = type;
+	token->value.str = talloc_steal (token, str);
+
+	return token;
+}
+
+token_t *
+_token_create_ival (void *ctx, int type, int ival)
+{
+	token_t *token;
+
+	token = talloc (ctx, token_t);
+	token->type = type;
+	token->value.ival = ival;
+
+	return token;
+}
+
+token_list_t *
+_token_list_create (void *ctx)
+{
+	token_list_t *list;
+
+	list = talloc (ctx, token_list_t);
+	list->head = NULL;
+	list->tail = NULL;
+	list->non_space_tail = NULL;
+
+	return list;
+}
+
+void
+_token_list_append (token_list_t *list, token_t *token)
+{
+	token_node_t *node;
+
+	node = talloc (list, token_node_t);
+	node->token = talloc_steal (list, token);
+
+	node->next = NULL;
+
+	if (list->head == NULL) {
+		list->head = node;
+	} else {
+		list->tail->next = node;
+	}
+
+	list->tail = node;
+	if (token->type != SPACE)
+		list->non_space_tail = node;
+}
+
+void
+_token_list_append_list (token_list_t *list, token_list_t *tail)
+{
+	if (tail == NULL || tail->head == NULL)
+		return;
+
+	if (list->head == NULL) {
+		list->head = tail->head;
+	} else {
+		list->tail->next = tail->head;
+	}
+
+	list->tail = tail->tail;
+	list->non_space_tail = tail->non_space_tail;
+}
+
+static token_list_t *
+_token_list_copy (void *ctx, token_list_t *other)
+{
+	token_list_t *copy;
+	token_node_t *node;
+
+	if (other == NULL)
+		return NULL;
+
+	copy = _token_list_create (ctx);
+	for (node = other->head; node; node = node->next) {
+		token_t *new_token = talloc (copy, token_t);
+		*new_token = *node->token;
+		_token_list_append (copy, new_token);
+	}
+
+	return copy;
+}
+
+static void
+_token_list_trim_trailing_space (token_list_t *list)
+{
+	token_node_t *tail, *next;
+
+	if (list->non_space_tail) {
+		tail = list->non_space_tail->next;
+		list->non_space_tail->next = NULL;
+		list->tail = list->non_space_tail;
+
+		while (tail) {
+			next = tail->next;
+			talloc_free (tail);
+			tail = next;
+		}
+	}
+}
+
+int
+_token_list_is_empty_ignoring_space (token_list_t *l)
+{
+	token_node_t *n;
+
+	if (l == NULL)
+		return 1;
+
+	n = l->head;
+	while (n != NULL && n->token->type == SPACE)
+		n = n->next;
+
+	return n == NULL;
+}
+
+int
+_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b)
+{
+	token_node_t *node_a, *node_b;
+
+	if (a == NULL || b == NULL) {
+		int a_empty = _token_list_is_empty_ignoring_space(a);
+		int b_empty = _token_list_is_empty_ignoring_space(b);
+		return a_empty == b_empty;
+	}
+
+	node_a = a->head;
+	node_b = b->head;
+
+	while (1)
+	{
+		if (node_a == NULL && node_b == NULL)
+			break;
+
+		if (node_a == NULL || node_b == NULL)
+			return 0;
+
+		if (node_a->token->type == SPACE) {
+			node_a = node_a->next;
+			continue;
+		}
+
+		if (node_b->token->type == SPACE) {
+			node_b = node_b->next;
+			continue;
+		}
+
+		if (node_a->token->type != node_b->token->type)
+			return 0;
+
+		switch (node_a->token->type) {
+		case INTEGER:
+			if (node_a->token->value.ival != 
+			    node_b->token->value.ival)
+			{
+				return 0;
+			}
+			break;
+		case IDENTIFIER:
+		case INTEGER_STRING:
+		case OTHER:
+			if (strcmp (node_a->token->value.str,
+				    node_b->token->value.str))
+			{
+				return 0;
+			}
+			break;
+		}
+
+		node_a = node_a->next;
+		node_b = node_b->next;
+	}
+
+	return 1;
+}
+
+static void
+_token_print (char **out, token_t *token)
+{
+	if (token->type < 256) {
+		glcpp_printf (*out, "%c", token->type);
+		return;
+	}
+
+	switch (token->type) {
+	case INTEGER:
+		glcpp_printf (*out, "%" PRIiMAX, token->value.ival);
+		break;
+	case IDENTIFIER:
+	case INTEGER_STRING:
+	case OTHER:
+		glcpp_print (*out, token->value.str);
+		break;
+	case SPACE:
+		glcpp_print (*out, " ");
+		break;
+	case LEFT_SHIFT:
+		glcpp_print (*out, "<<");
+		break;
+	case RIGHT_SHIFT:
+		glcpp_print (*out, ">>");
+		break;
+	case LESS_OR_EQUAL:
+		glcpp_print (*out, "<=");
+		break;
+	case GREATER_OR_EQUAL:
+		glcpp_print (*out, ">=");
+		break;
+	case EQUAL:
+		glcpp_print (*out, "==");
+		break;
+	case NOT_EQUAL:
+		glcpp_print (*out, "!=");
+		break;
+	case AND:
+		glcpp_print (*out, "&&");
+		break;
+	case OR:
+		glcpp_print (*out, "||");
+		break;
+	case PASTE:
+		glcpp_print (*out, "##");
+		break;
+	case COMMA_FINAL:
+		glcpp_print (*out, ",");
+		break;
+	case PLACEHOLDER:
+		/* Nothing to print. */
+		break;
+	default:
+		assert(!"Error: Don't know how to print token.");
+		break;
+	}
+}
+
+/* Return a new token (talloc()ed off of 'token') formed by pasting
+ * 'token' and 'other'. Note that this function may return 'token' or
+ * 'other' directly rather than allocating anything new.
+ *
+ * Caution: Only very cursory error-checking is performed to see if
+ * the final result is a valid single token. */
+static token_t *
+_token_paste (glcpp_parser_t *parser, token_t *token, token_t *other)
+{
+	token_t *combined = NULL;
+
+	/* Pasting a placeholder onto anything makes no change. */
+	if (other->type == PLACEHOLDER)
+		return token;
+
+	/* When 'token' is a placeholder, just return 'other'. */
+	if (token->type == PLACEHOLDER)
+		return other;
+
+	/* A very few single-character punctuators can be combined
+	 * with another to form a multi-character punctuator. */
+	switch (token->type) {
+	case '<':
+		if (other->type == '<')
+			combined = _token_create_ival (token, LEFT_SHIFT, LEFT_SHIFT);
+		else if (other->type == '=')
+			combined = _token_create_ival (token, LESS_OR_EQUAL, LESS_OR_EQUAL);
+		break;
+	case '>':
+		if (other->type == '>')
+			combined = _token_create_ival (token, RIGHT_SHIFT, RIGHT_SHIFT);
+		else if (other->type == '=')
+			combined = _token_create_ival (token, GREATER_OR_EQUAL, GREATER_OR_EQUAL);
+		break;
+	case '=':
+		if (other->type == '=')
+			combined = _token_create_ival (token, EQUAL, EQUAL);
+		break;
+	case '!':
+		if (other->type == '=')
+			combined = _token_create_ival (token, NOT_EQUAL, NOT_EQUAL);
+		break;
+	case '&':
+		if (other->type == '&')
+			combined = _token_create_ival (token, AND, AND);
+		break;
+	case '|':
+		if (other->type == '|')
+			combined = _token_create_ival (token, OR, OR);
+		break;
+	}
+
+	if (combined != NULL) {
+		/* Inherit the location from the first token */
+		combined->location = token->location;
+		return combined;
+	}
+
+	/* Two string-valued tokens can usually just be mashed
+	 * together.
+	 *
+	 * XXX: This isn't actually legitimate. Several things here
+	 * should result in a diagnostic since the result cannot be a
+	 * valid, single pre-processing token. For example, pasting
+	 * "123" and "abc" is not legal, but we don't catch that
+	 * here. */
+	if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING) &&
+	    (other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING))
+	{
+		char *str;
+
+		str = talloc_asprintf (token, "%s%s", token->value.str,
+				       other->value.str);
+		combined = _token_create_str (token, token->type, str);
+		combined->location = token->location;
+		return combined;
+	}
+
+	glcpp_error (&token->location, parser, "");
+	glcpp_print (parser->info_log, "Pasting \"");
+	_token_print (&parser->info_log, token);
+	glcpp_print (parser->info_log, "\" and \"");
+	_token_print (&parser->info_log, other);
+	glcpp_print (parser->info_log, "\" does not give a valid preprocessing token.\n");
+
+	return token;
+}
+
+static void
+_token_list_print (glcpp_parser_t *parser, token_list_t *list)
+{
+	token_node_t *node;
+
+	if (list == NULL)
+		return;
+
+	for (node = list->head; node; node = node->next)
+		_token_print (&parser->output, node->token);
+}
+
+void
+yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
+{
+	glcpp_error(locp, parser, "%s", error);
+}
+
+static void add_builtin_define(glcpp_parser_t *parser,
+			       const char *name, int value)
+{
+   token_t *tok;
+   token_list_t *list;
+
+   tok = _token_create_ival (parser, INTEGER, value);
+
+   list = _token_list_create(parser);
+   _token_list_append(list, tok);
+   _define_object_macro(parser, NULL, name, list);
+}
+
+glcpp_parser_t *
+glcpp_parser_create (const struct gl_extensions *extensions, int api)
+{
+	glcpp_parser_t *parser;
+	int language_version;
+
+	parser = talloc (NULL, glcpp_parser_t);
+
+	glcpp_lex_init_extra (parser, &parser->scanner);
+	parser->defines = hash_table_ctor (32, hash_table_string_hash,
+					   hash_table_string_compare);
+	parser->active = NULL;
+	parser->lexing_if = 0;
+	parser->space_tokens = 1;
+	parser->newline_as_space = 0;
+	parser->in_control_line = 0;
+	parser->paren_count = 0;
+
+	parser->skip_stack = NULL;
+
+	parser->lex_from_list = NULL;
+	parser->lex_from_node = NULL;
+
+	parser->output = talloc_strdup(parser, "");
+	parser->info_log = talloc_strdup(parser, "");
+	parser->error = 0;
+
+	/* Add pre-defined macros. */
+	add_builtin_define(parser, "GL_ARB_draw_buffers", 1);
+	add_builtin_define(parser, "GL_ARB_texture_rectangle", 1);
+
+	if (api == API_OPENGLES2)
+		add_builtin_define(parser, "GL_ES", 1);
+
+	if (extensions != NULL) {
+	   if (extensions->EXT_texture_array) {
+	      add_builtin_define(parser, "GL_EXT_texture_array", 1);
+	   }
+
+	   if (extensions->ARB_fragment_coord_conventions)
+	      add_builtin_define(parser, "GL_ARB_fragment_coord_conventions",
+				 1);
+
+	   if (extensions->ARB_explicit_attrib_location)
+	      add_builtin_define(parser, "GL_ARB_explicit_attrib_location", 1);
+	   if (extensions->AMD_conservative_depth)
+	      add_builtin_define(parser, "GL_AMD_conservative_depth", 1);
+	}
+
+	language_version = 110;
+	add_builtin_define(parser, "__VERSION__", language_version);
+
+	return parser;
+}
+
+int
+glcpp_parser_parse (glcpp_parser_t *parser)
+{
+	return yyparse (parser);
+}
+
+void
+glcpp_parser_destroy (glcpp_parser_t *parser)
+{
+	glcpp_lex_destroy (parser->scanner);
+	hash_table_dtor (parser->defines);
+	talloc_free (parser);
+}
+
+typedef enum function_status
+{
+	FUNCTION_STATUS_SUCCESS,
+	FUNCTION_NOT_A_FUNCTION,
+	FUNCTION_UNBALANCED_PARENTHESES
+} function_status_t;
+
+/* Find a set of function-like macro arguments by looking for a
+ * balanced set of parentheses.
+ *
+ * When called, 'node' should be the opening-parenthesis token, (or
+ * perhaps preceeding SPACE tokens). Upon successful return *last will
+ * be the last consumed node, (corresponding to the closing right
+ * parenthesis).
+ *
+ * Return values:
+ *
+ *   FUNCTION_STATUS_SUCCESS:
+ *
+ *	Successfully parsed a set of function arguments.	
+ *
+ *   FUNCTION_NOT_A_FUNCTION:
+ *
+ *	Macro name not followed by a '('. This is not an error, but
+ *	simply that the macro name should be treated as a non-macro.
+ *
+ *   FUNCTION_UNBALANCED_PARENTHESES
+ *
+ *	Macro name is not followed by a balanced set of parentheses.
+ */
+static function_status_t
+_arguments_parse (argument_list_t *arguments,
+		  token_node_t *node,
+		  token_node_t **last)
+{
+	token_list_t *argument;
+	int paren_count;
+
+	node = node->next;
+
+	/* Ignore whitespace before first parenthesis. */
+	while (node && node->token->type == SPACE)
+		node = node->next;
+
+	if (node == NULL || node->token->type != '(')
+		return FUNCTION_NOT_A_FUNCTION;
+
+	node = node->next;
+
+	argument = _token_list_create (arguments);
+	_argument_list_append (arguments, argument);
+
+	for (paren_count = 1; node; node = node->next) {
+		if (node->token->type == '(')
+		{
+			paren_count++;
+		}
+		else if (node->token->type == ')')
+		{
+			paren_count--;
+			if (paren_count == 0)
+				break;
+		}
+
+		if (node->token->type == ',' &&
+			 paren_count == 1)
+		{
+			_token_list_trim_trailing_space (argument);
+			argument = _token_list_create (arguments);
+			_argument_list_append (arguments, argument);
+		}
+		else {
+			if (argument->head == NULL) {
+				/* Don't treat initial whitespace as
+				 * part of the arguement. */
+				if (node->token->type == SPACE)
+					continue;
+			}
+			_token_list_append (argument, node->token);
+		}
+	}
+
+	if (paren_count)
+		return FUNCTION_UNBALANCED_PARENTHESES;
+
+	*last = node;
+
+	return FUNCTION_STATUS_SUCCESS;
+}
+
+static token_list_t *
+_token_list_create_with_one_space (void *ctx)
+{
+	token_list_t *list;
+	token_t *space;
+
+	list = _token_list_create (ctx);
+	space = _token_create_ival (list, SPACE, SPACE);
+	_token_list_append (list, space);
+
+	return list;
+}
+
+static void
+_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list)
+{
+	token_list_t *expanded;
+	token_t *token;
+
+	expanded = _token_list_create (parser);
+	token = _token_create_ival (parser, type, type);
+	_token_list_append (expanded, token);
+	_glcpp_parser_expand_token_list (parser, list);
+	_token_list_append_list (expanded, list);
+	glcpp_parser_lex_from (parser, expanded);
+}
+
+/* This is a helper function that's essentially part of the
+ * implementation of _glcpp_parser_expand_node. It shouldn't be called
+ * except for by that function.
+ *
+ * Returns NULL if node is a simple token with no expansion, (that is,
+ * although 'node' corresponds to an identifier defined as a
+ * function-like macro, it is not followed with a parenthesized
+ * argument list).
+ *
+ * Compute the complete expansion of node (which is a function-like
+ * macro) and subsequent nodes which are arguments.
+ *
+ * Returns the token list that results from the expansion and sets
+ * *last to the last node in the list that was consumed by the
+ * expansion. Specifically, *last will be set as follows: as the
+ * token of the closing right parenthesis.
+ */
+static token_list_t *
+_glcpp_parser_expand_function (glcpp_parser_t *parser,
+			       token_node_t *node,
+			       token_node_t **last)
+			       
+{
+	macro_t *macro;
+	const char *identifier;
+	argument_list_t *arguments;
+	function_status_t status;
+	token_list_t *substituted;
+	int parameter_index;
+
+	identifier = node->token->value.str;
+
+	macro = hash_table_find (parser->defines, identifier);
+
+	assert (macro->is_function);
+
+	arguments = _argument_list_create (parser);
+	status = _arguments_parse (arguments, node, last);
+
+	switch (status) {
+	case FUNCTION_STATUS_SUCCESS:
+		break;
+	case FUNCTION_NOT_A_FUNCTION:
+		return NULL;
+	case FUNCTION_UNBALANCED_PARENTHESES:
+		glcpp_error (&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identifier);
+		return NULL;
+	}
+
+	/* Replace a macro defined as empty with a SPACE token. */
+	if (macro->replacements == NULL) {
+		talloc_free (arguments);
+		return _token_list_create_with_one_space (parser);
+	}
+
+	if (! ((_argument_list_length (arguments) == 
+		_string_list_length (macro->parameters)) ||
+	       (_string_list_length (macro->parameters) == 0 &&
+		_argument_list_length (arguments) == 1 &&
+		arguments->head->argument->head == NULL)))
+	{
+		glcpp_error (&node->token->location, parser,
+			      "Error: macro %s invoked with %d arguments (expected %d)\n",
+			      identifier,
+			      _argument_list_length (arguments),
+			      _string_list_length (macro->parameters));
+		return NULL;
+	}
+
+	/* Perform argument substitution on the replacement list. */
+	substituted = _token_list_create (arguments);
+
+	for (node = macro->replacements->head; node; node = node->next)
+	{
+		if (node->token->type == IDENTIFIER &&
+		    _string_list_contains (macro->parameters,
+					   node->token->value.str,
+					   &parameter_index))
+		{
+			token_list_t *argument;
+			argument = _argument_list_member_at (arguments,
+							     parameter_index);
+			/* Before substituting, we expand the argument
+			 * tokens, or append a placeholder token for
+			 * an empty argument. */
+			if (argument->head) {
+				token_list_t *expanded_argument;
+				expanded_argument = _token_list_copy (parser,
+								      argument);
+				_glcpp_parser_expand_token_list (parser,
+								 expanded_argument);
+				_token_list_append_list (substituted,
+							 expanded_argument);
+			} else {
+				token_t *new_token;
+
+				new_token = _token_create_ival (substituted,
+								PLACEHOLDER,
+								PLACEHOLDER);
+				_token_list_append (substituted, new_token);
+			}
+		} else {
+			_token_list_append (substituted, node->token);
+		}
+	}
+
+	/* After argument substitution, and before further expansion
+	 * below, implement token pasting. */
+
+	_token_list_trim_trailing_space (substituted);
+
+	node = substituted->head;
+	while (node)
+	{
+		token_node_t *next_non_space;
+
+		/* Look ahead for a PASTE token, skipping space. */
+		next_non_space = node->next;
+		while (next_non_space && next_non_space->token->type == SPACE)
+			next_non_space = next_non_space->next;
+
+		if (next_non_space == NULL)
+			break;
+
+		if (next_non_space->token->type != PASTE) {
+			node = next_non_space;
+			continue;
+		}
+
+		/* Now find the next non-space token after the PASTE. */
+		next_non_space = next_non_space->next;
+		while (next_non_space && next_non_space->token->type == SPACE)
+			next_non_space = next_non_space->next;
+
+		if (next_non_space == NULL) {
+			yyerror (&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n");
+			return NULL;
+		}
+
+		node->token = _token_paste (parser, node->token, next_non_space->token);
+		node->next = next_non_space->next;
+		if (next_non_space == substituted->tail)
+			substituted->tail = node;
+
+		node = node->next;
+	}
+
+	substituted->non_space_tail = substituted->tail;
+
+	return substituted;
+}
+
+/* Compute the complete expansion of node, (and subsequent nodes after
+ * 'node' in the case that 'node' is a function-like macro and
+ * subsequent nodes are arguments).
+ *
+ * Returns NULL if node is a simple token with no expansion.
+ *
+ * Otherwise, returns the token list that results from the expansion
+ * and sets *last to the last node in the list that was consumed by
+ * the expansion. Specifically, *last will be set as follows:
+ *
+ *	As 'node' in the case of object-like macro expansion.
+ *
+ *	As the token of the closing right parenthesis in the case of
+ *	function-like macro expansion.
+ */
+static token_list_t *
+_glcpp_parser_expand_node (glcpp_parser_t *parser,
+			   token_node_t *node,
+			   token_node_t **last)
+{
+	token_t *token = node->token;
+	const char *identifier;
+	macro_t *macro;
+
+	/* We only expand identifiers */
+	if (token->type != IDENTIFIER) {
+		/* We change any COMMA into a COMMA_FINAL to prevent
+		 * it being mistaken for an argument separator
+		 * later. */
+		if (token->type == ',') {
+			token->type = COMMA_FINAL;
+			token->value.ival = COMMA_FINAL;
+		}
+
+		return NULL;
+	}
+
+	/* Look up this identifier in the hash table. */
+	identifier = token->value.str;
+	macro = hash_table_find (parser->defines, identifier);
+
+	/* Not a macro, so no expansion needed. */
+	if (macro == NULL)
+		return NULL;
+
+	/* Finally, don't expand this macro if we're already actively
+	 * expanding it, (to avoid infinite recursion). */
+	if (_active_list_contains (parser->active, identifier)) {
+		/* We change the token type here from IDENTIFIER to
+		 * OTHER to prevent any future expansion of this
+		 * unexpanded token. */
+		char *str;
+		token_list_t *expansion;
+		token_t *final;
+
+		str = talloc_strdup (parser, token->value.str);
+		final = _token_create_str (parser, OTHER, str);
+		expansion = _token_list_create (parser);
+		_token_list_append (expansion, final);
+		*last = node;
+		return expansion;
+	}
+
+	if (! macro->is_function)
+	{
+		*last = node;
+
+		/* Replace a macro defined as empty with a SPACE token. */
+		if (macro->replacements == NULL)
+			return _token_list_create_with_one_space (parser);
+
+		return _token_list_copy (parser, macro->replacements);
+	}
+
+	return _glcpp_parser_expand_function (parser, node, last);
+}
+
+/* Push a new identifier onto the active list, returning the new list.
+ *
+ * Here, 'marker' is the token node that appears in the list after the
+ * expansion of 'identifier'. That is, when the list iterator begins
+ * examinging 'marker', then it is time to pop this node from the
+ * active stack.
+ */
+active_list_t *
+_active_list_push (active_list_t *list,
+		   const char *identifier,
+		   token_node_t *marker)
+{
+	active_list_t *node;
+
+	node = talloc (list, active_list_t);
+	node->identifier = talloc_strdup (node, identifier);
+	node->marker = marker;
+	node->next = list;
+
+	return node;
+}
+
+active_list_t *
+_active_list_pop (active_list_t *list)
+{
+	active_list_t *node = list;
+
+	if (node == NULL)
+		return NULL;
+
+	node = list->next;
+	talloc_free (list);
+
+	return node;
+}
+
+int
+_active_list_contains (active_list_t *list, const char *identifier)
+{
+	active_list_t *node;
+
+	if (list == NULL)
+		return 0;
+
+	for (node = list; node; node = node->next)
+		if (strcmp (node->identifier, identifier) == 0)
+			return 1;
+
+	return 0;
+}
+
+/* Walk over the token list replacing nodes with their expansion.
+ * Whenever nodes are expanded the walking will walk over the new
+ * nodes, continuing to expand as necessary. The results are placed in
+ * 'list' itself;
+ */
+static void
+_glcpp_parser_expand_token_list (glcpp_parser_t *parser,
+				 token_list_t *list)
+{
+	token_node_t *node_prev;
+	token_node_t *node, *last = NULL;
+	token_list_t *expansion;
+
+	if (list == NULL)
+		return;
+
+	_token_list_trim_trailing_space (list);
+
+	node_prev = NULL;
+	node = list->head;
+
+	while (node) {
+
+		while (parser->active && parser->active->marker == node)
+			parser->active = _active_list_pop (parser->active);
+
+		/* Find the expansion for node, which will replace all
+		 * nodes from node to last, inclusive. */
+		expansion = _glcpp_parser_expand_node (parser, node, &last);
+		if (expansion) {
+			token_node_t *n;
+
+			for (n = node; n != last->next; n = n->next)
+				while (parser->active &&
+				       parser->active->marker == n)
+				{
+					parser->active = _active_list_pop (parser->active);
+				}
+
+			parser->active = _active_list_push (parser->active,
+							    node->token->value.str,
+							    last->next);
+			
+			/* Splice expansion into list, supporting a
+			 * simple deletion if the expansion is
+			 * empty. */
+			if (expansion->head) {
+				if (node_prev)
+					node_prev->next = expansion->head;
+				else
+					list->head = expansion->head;
+				expansion->tail->next = last->next;
+				if (last == list->tail)
+					list->tail = expansion->tail;
+			} else {
+				if (node_prev)
+					node_prev->next = last->next;
+				else
+					list->head = last->next;
+				if (last == list->tail)
+					list->tail = NULL;
+			}
+		} else {
+			node_prev = node;
+		}
+		node = node_prev ? node_prev->next : list->head;
+	}
+
+	while (parser->active)
+		parser->active = _active_list_pop (parser->active);
+
+	list->non_space_tail = list->tail;
+}
+
+void
+_glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
+					 token_list_t *list)
+{
+	if (list == NULL)
+		return;
+
+	_glcpp_parser_expand_token_list (parser, list);
+
+	_token_list_trim_trailing_space (list);
+
+	_token_list_print (parser, list);
+}
+
+static void
+_check_for_reserved_macro_name (glcpp_parser_t *parser, YYLTYPE *loc,
+				const char *identifier)
+{
+	/* According to the GLSL specification, macro names starting with "__"
+	 * or "GL_" are reserved for future use.  So, don't allow them.
+	 */
+	if (strncmp(identifier, "__", 2) == 0) {
+		glcpp_error (loc, parser, "Macro names starting with \"__\" are reserved.\n");
+	}
+	if (strncmp(identifier, "GL_", 3) == 0) {
+		glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n");
+	}
+}
+
+static int
+_macro_equal (macro_t *a, macro_t *b)
+{
+	if (a->is_function != b->is_function)
+		return 0;
+
+	if (a->is_function) {
+		if (! _string_list_equal (a->parameters, b->parameters))
+			return 0;
+	}
+
+	return _token_list_equal_ignoring_space (a->replacements,
+						 b->replacements);
+}
+
+void
+_define_object_macro (glcpp_parser_t *parser,
+		      YYLTYPE *loc,
+		      const char *identifier,
+		      token_list_t *replacements)
+{
+	macro_t *macro, *previous;
+
+	if (loc != NULL)
+		_check_for_reserved_macro_name(parser, loc, identifier);
+
+	macro = talloc (parser, macro_t);
+
+	macro->is_function = 0;
+	macro->parameters = NULL;
+	macro->identifier = talloc_strdup (macro, identifier);
+	macro->replacements = talloc_steal (macro, replacements);
+
+	previous = hash_table_find (parser->defines, identifier);
+	if (previous) {
+		if (_macro_equal (macro, previous)) {
+			talloc_free (macro);
+			return;
+		}
+		glcpp_error (loc, parser, "Redefinition of macro %s\n",
+			     identifier);
+	}
+
+	hash_table_insert (parser->defines, macro, identifier);
+}
+
+void
+_define_function_macro (glcpp_parser_t *parser,
+			YYLTYPE *loc,
+			const char *identifier,
+			string_list_t *parameters,
+			token_list_t *replacements)
+{
+	macro_t *macro, *previous;
+
+	_check_for_reserved_macro_name(parser, loc, identifier);
+
+	macro = talloc (parser, macro_t);
+
+	macro->is_function = 1;
+	macro->parameters = talloc_steal (macro, parameters);
+	macro->identifier = talloc_strdup (macro, identifier);
+	macro->replacements = talloc_steal (macro, replacements);
+
+	previous = hash_table_find (parser->defines, identifier);
+	if (previous) {
+		if (_macro_equal (macro, previous)) {
+			talloc_free (macro);
+			return;
+		}
+		glcpp_error (loc, parser, "Redefinition of macro %s\n",
+			     identifier);
+	}
+
+	hash_table_insert (parser->defines, macro, identifier);
+}
+
+static int
+glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
+{
+	token_node_t *node;
+	int ret;
+
+	if (parser->lex_from_list == NULL) {
+		ret = glcpp_lex (yylval, yylloc, parser->scanner);
+
+		/* XXX: This ugly block of code exists for the sole
+		 * purpose of converting a NEWLINE token into a SPACE
+		 * token, but only in the case where we have seen a
+		 * function-like macro name, but have not yet seen its
+		 * closing parenthesis.
+		 *
+		 * There's perhaps a more compact way to do this with
+		 * mid-rule actions in the grammar.
+		 *
+		 * I'm definitely not pleased with the complexity of
+		 * this code here.
+		 */
+		if (parser->newline_as_space)
+		{
+			if (ret == '(') {
+				parser->paren_count++;
+			} else if (ret == ')') {
+				parser->paren_count--;
+				if (parser->paren_count == 0)
+					parser->newline_as_space = 0;
+			} else if (ret == NEWLINE) {
+				ret = SPACE;
+			} else if (ret != SPACE) {
+				if (parser->paren_count == 0)
+					parser->newline_as_space = 0;
+			}
+		}
+		else if (parser->in_control_line)
+		{
+			if (ret == NEWLINE)
+				parser->in_control_line = 0;
+		}
+		else if (ret == HASH_DEFINE_OBJ || ret == HASH_DEFINE_FUNC ||
+			   ret == HASH_UNDEF || ret == HASH_IF ||
+			   ret == HASH_IFDEF || ret == HASH_IFNDEF ||
+			   ret == HASH_ELIF || ret == HASH_ELSE ||
+			   ret == HASH_ENDIF || ret == HASH)
+		{
+			parser->in_control_line = 1;
+		}
+		else if (ret == IDENTIFIER)
+		{
+			macro_t *macro;
+			macro = hash_table_find (parser->defines,
+						 yylval->str);
+			if (macro && macro->is_function) {
+				parser->newline_as_space = 1;
+				parser->paren_count = 0;
+			}
+		}
+
+		return ret;
+	}
+
+	node = parser->lex_from_node;
+
+	if (node == NULL) {
+		talloc_free (parser->lex_from_list);
+		parser->lex_from_list = NULL;
+		return NEWLINE;
+	}
+
+	*yylval = node->token->value;
+	ret = node->token->type;
+
+	parser->lex_from_node = node->next;
+
+	return ret;
+}
+
+static void
+glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list)
+{
+	token_node_t *node;
+
+	assert (parser->lex_from_list == NULL);
+
+	/* Copy list, eliminating any space tokens. */
+	parser->lex_from_list = _token_list_create (parser);
+
+	for (node = list->head; node; node = node->next) {
+		if (node->token->type == SPACE)
+			continue;
+		_token_list_append (parser->lex_from_list, node->token);
+	}
+
+	talloc_free (list);
+
+	parser->lex_from_node = parser->lex_from_list->head;
+
+	/* It's possible the list consisted of nothing but whitespace. */
+	if (parser->lex_from_node == NULL) {
+		talloc_free (parser->lex_from_list);
+		parser->lex_from_list = NULL;
+	}
+}
+
+static void
+_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
+				  int condition)
+{
+	skip_type_t current = SKIP_NO_SKIP;
+	skip_node_t *node;
+
+	if (parser->skip_stack)
+		current = parser->skip_stack->type;
+
+	node = talloc (parser, skip_node_t);
+	node->loc = *loc;
+
+	if (current == SKIP_NO_SKIP) {
+		if (condition)
+			node->type = SKIP_NO_SKIP;
+		else
+			node->type = SKIP_TO_ELSE;
+	} else {
+		node->type = SKIP_TO_ENDIF;
+	}
+
+	node->next = parser->skip_stack;
+	parser->skip_stack = node;
+}
+
+static void
+_glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
+				    const char *type, int condition)
+{
+	if (parser->skip_stack == NULL) {
+		glcpp_error (loc, parser, "%s without #if\n", type);
+		return;
+	}
+
+	if (parser->skip_stack->type == SKIP_TO_ELSE) {
+		if (condition)
+			parser->skip_stack->type = SKIP_NO_SKIP;
+	} else {
+		parser->skip_stack->type = SKIP_TO_ENDIF;
+	}
+}
+
+static void
+_glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc)
+{
+	skip_node_t *node;
+
+	if (parser->skip_stack == NULL) {
+		glcpp_error (loc, parser, "#endif without #if\n");
+		return;
+	}
+
+	node = parser->skip_stack;
+	parser->skip_stack = node->next;
+	talloc_free (node);
+}
+
diff --git a/mesalib/src/glsl/glcpp/glcpp-parse.y b/mesalib/src/glsl/glcpp/glcpp-parse.y
index 797e61428..7976101bc 100644
--- a/mesalib/src/glsl/glcpp/glcpp-parse.y
+++ b/mesalib/src/glsl/glcpp/glcpp-parse.y
@@ -1,1890 +1,1890 @@
-%{
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <inttypes.h>
-
-#include "glcpp.h"
-#include "main/core.h" /* for struct gl_extensions */
-#include "main/mtypes.h" /* for gl_api enum */
-
-#define glcpp_print(stream, str) stream = talloc_strdup_append(stream, str)
-#define glcpp_printf(stream, fmt, args, ...) \
-	stream = talloc_asprintf_append(stream, fmt, args)
-
-static void
-yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
-
-static void
-_define_object_macro (glcpp_parser_t *parser,
-		      YYLTYPE *loc,
-		      const char *macro,
-		      token_list_t *replacements);
-
-static void
-_define_function_macro (glcpp_parser_t *parser,
-			YYLTYPE *loc,
-			const char *macro,
-			string_list_t *parameters,
-			token_list_t *replacements);
-
-static string_list_t *
-_string_list_create (void *ctx);
-
-static void
-_string_list_append_item (string_list_t *list, const char *str);
-
-static int
-_string_list_contains (string_list_t *list, const char *member, int *index);
-
-static int
-_string_list_length (string_list_t *list);
-
-static int
-_string_list_equal (string_list_t *a, string_list_t *b);
-
-static argument_list_t *
-_argument_list_create (void *ctx);
-
-static void
-_argument_list_append (argument_list_t *list, token_list_t *argument);
-
-static int
-_argument_list_length (argument_list_t *list);
-
-static token_list_t *
-_argument_list_member_at (argument_list_t *list, int index);
-
-/* Note: This function talloc_steal()s the str pointer. */
-static token_t *
-_token_create_str (void *ctx, int type, char *str);
-
-static token_t *
-_token_create_ival (void *ctx, int type, int ival);
-
-static token_list_t *
-_token_list_create (void *ctx);
-
-/* Note: This function calls talloc_steal on token. */
-static void
-_token_list_append (token_list_t *list, token_t *token);
-
-static void
-_token_list_append_list (token_list_t *list, token_list_t *tail);
-
-static int
-_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b);
-
-static active_list_t *
-_active_list_push (active_list_t *list,
-		   const char *identifier,
-		   token_node_t *marker);
-
-static active_list_t *
-_active_list_pop (active_list_t *list);
-
-int
-_active_list_contains (active_list_t *list, const char *identifier);
-
-static void
-_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list);
-
-static void
-_glcpp_parser_expand_token_list (glcpp_parser_t *parser,
-				 token_list_t *list);
-
-static void
-_glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
-					 token_list_t *list);
-
-static void
-_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
-				  int condition);
-
-static void
-_glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
-				    const char *type, int condition);
-
-static void
-_glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc);
-
-#define yylex glcpp_parser_lex
-
-static int
-glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser);
-
-static void
-glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list);
-
-static void
-add_builtin_define(glcpp_parser_t *parser, const char *name, int value);
-
-%}
-
-%pure-parser
-%error-verbose
-
-%locations
-%initial-action {
-	@$.first_line = 1;
-	@$.first_column = 1;
-	@$.last_line = 1;
-	@$.last_column = 1;
-	@$.source = 0;
-}
-
-%parse-param {glcpp_parser_t *parser}
-%lex-param {glcpp_parser_t *parser}
-
-%expect 0
-%token COMMA_FINAL DEFINED ELIF_EXPANDED HASH HASH_DEFINE_FUNC HASH_DEFINE_OBJ HASH_ELIF HASH_ELSE HASH_ENDIF HASH_IF HASH_IFDEF HASH_IFNDEF HASH_UNDEF HASH_VERSION IDENTIFIER IF_EXPANDED INTEGER INTEGER_STRING NEWLINE OTHER PLACEHOLDER SPACE
-%token PASTE
-%type <ival> expression INTEGER operator SPACE integer_constant
-%type <str> IDENTIFIER INTEGER_STRING OTHER
-%type <string_list> identifier_list
-%type <token> preprocessing_token conditional_token
-%type <token_list> pp_tokens replacement_list text_line conditional_tokens
-%left OR
-%left AND
-%left '|'
-%left '^'
-%left '&'
-%left EQUAL NOT_EQUAL
-%left '<' '>' LESS_OR_EQUAL GREATER_OR_EQUAL
-%left LEFT_SHIFT RIGHT_SHIFT
-%left '+' '-'
-%left '*' '/' '%'
-%right UNARY
-
-%%
-
-input:
-	/* empty */
-|	input line
-;
-
-line:
-	control_line {
-		glcpp_print(parser->output, "\n");
-	}
-|	text_line {
-		_glcpp_parser_print_expanded_token_list (parser, $1);
-		glcpp_print(parser->output, "\n");
-		talloc_free ($1);
-	}
-|	expanded_line
-|	HASH non_directive
-;
-
-expanded_line:
-	IF_EXPANDED expression NEWLINE {
-		_glcpp_parser_skip_stack_push_if (parser, & @1, $2);
-	}
-|	ELIF_EXPANDED expression NEWLINE {
-		_glcpp_parser_skip_stack_change_if (parser, & @1, "elif", $2);
-	}
-;
-
-control_line:
-	HASH_DEFINE_OBJ	IDENTIFIER replacement_list NEWLINE {
-		_define_object_macro (parser, & @2, $2, $3);
-	}
-|	HASH_DEFINE_FUNC IDENTIFIER '(' ')' replacement_list NEWLINE {
-		_define_function_macro (parser, & @2, $2, NULL, $5);
-	}
-|	HASH_DEFINE_FUNC IDENTIFIER '(' identifier_list ')' replacement_list NEWLINE {
-		_define_function_macro (parser, & @2, $2, $4, $6);
-	}
-|	HASH_UNDEF IDENTIFIER NEWLINE {
-		macro_t *macro = hash_table_find (parser->defines, $2);
-		if (macro) {
-			hash_table_remove (parser->defines, $2);
-			talloc_free (macro);
-		}
-		talloc_free ($2);
-	}
-|	HASH_IF conditional_tokens NEWLINE {
-		/* Be careful to only evaluate the 'if' expression if
-		 * we are not skipping. When we are skipping, we
-		 * simply push a new 0-valued 'if' onto the skip
-		 * stack.
-		 *
-		 * This avoids generating diagnostics for invalid
-		 * expressions that are being skipped. */
-		if (parser->skip_stack == NULL ||
-		    parser->skip_stack->type == SKIP_NO_SKIP)
-		{
-			_glcpp_parser_expand_if (parser, IF_EXPANDED, $2);
-		}	
-		else
-		{
-			_glcpp_parser_skip_stack_push_if (parser, & @1, 0);
-			parser->skip_stack->type = SKIP_TO_ENDIF;
-		}
-	}
-|	HASH_IF NEWLINE {
-		/* #if without an expression is only an error if we
-		 *  are not skipping */
-		if (parser->skip_stack == NULL ||
-		    parser->skip_stack->type == SKIP_NO_SKIP)
-		{
-			glcpp_error(& @1, parser, "#if with no expression");
-		}	
-		_glcpp_parser_skip_stack_push_if (parser, & @1, 0);
-	}
-|	HASH_IFDEF IDENTIFIER junk NEWLINE {
-		macro_t *macro = hash_table_find (parser->defines, $2);
-		talloc_free ($2);
-		_glcpp_parser_skip_stack_push_if (parser, & @1, macro != NULL);
-	}
-|	HASH_IFNDEF IDENTIFIER junk NEWLINE {
-		macro_t *macro = hash_table_find (parser->defines, $2);
-		talloc_free ($2);
-		_glcpp_parser_skip_stack_push_if (parser, & @1, macro == NULL);
-	}
-|	HASH_ELIF conditional_tokens NEWLINE {
-		/* Be careful to only evaluate the 'elif' expression
-		 * if we are not skipping. When we are skipping, we
-		 * simply change to a 0-valued 'elif' on the skip
-		 * stack.
-		 *
-		 * This avoids generating diagnostics for invalid
-		 * expressions that are being skipped. */
-		if (parser->skip_stack &&
-		    parser->skip_stack->type == SKIP_TO_ELSE)
-		{
-			_glcpp_parser_expand_if (parser, ELIF_EXPANDED, $2);
-		}
-		else
-		{
-			_glcpp_parser_skip_stack_change_if (parser, & @1,
-							    "elif", 0);
-		}
-	}
-|	HASH_ELIF NEWLINE {
-		/* #elif without an expression is an error unless we
-		 * are skipping. */
-		if (parser->skip_stack &&
-		    parser->skip_stack->type == SKIP_TO_ELSE)
-		{
-			glcpp_error(& @1, parser, "#elif with no expression");
-		}
-		else
-		{
-			_glcpp_parser_skip_stack_change_if (parser, & @1,
-							    "elif", 0);
-			glcpp_warning(& @1, parser, "ignoring illegal #elif without expression");
-		}
-	}
-|	HASH_ELSE NEWLINE {
-		_glcpp_parser_skip_stack_change_if (parser, & @1, "else", 1);
-	}
-|	HASH_ENDIF NEWLINE {
-		_glcpp_parser_skip_stack_pop (parser, & @1);
-	}
-|	HASH_VERSION integer_constant NEWLINE {
-		macro_t *macro = hash_table_find (parser->defines, "__VERSION__");
-		if (macro) {
-			hash_table_remove (parser->defines, "__VERSION__");
-			talloc_free (macro);
-		}
-		add_builtin_define (parser, "__VERSION__", $2);
-
-		if ($2 == 100)
-			add_builtin_define (parser, "GL_ES", 1);
-
-		/* Currently, all ES2 implementations support highp in the
-		 * fragment shader, so we always define this macro in ES2.
-		 * If we ever get a driver that doesn't support highp, we'll
-		 * need to add a flag to the gl_context and check that here.
-		 */
-		if ($2 >= 130 || $2 == 100)
-			add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1);
-
-		glcpp_printf(parser->output, "#version %" PRIiMAX, $2);
-	}
-|	HASH NEWLINE
-;
-
-integer_constant:
-	INTEGER_STRING {
-		if (strlen ($1) >= 3 && strncmp ($1, "0x", 2) == 0) {
-			$$ = strtoll ($1 + 2, NULL, 16);
-		} else if ($1[0] == '0') {
-			$$ = strtoll ($1, NULL, 8);
-		} else {
-			$$ = strtoll ($1, NULL, 10);
-		}
-	}
-|	INTEGER {
-		$$ = $1;
-	}
-
-expression:
-	integer_constant
-|	expression OR expression {
-		$$ = $1 || $3;
-	}
-|	expression AND expression {
-		$$ = $1 && $3;
-	}
-|	expression '|' expression {
-		$$ = $1 | $3;
-	}
-|	expression '^' expression {
-		$$ = $1 ^ $3;
-	}
-|	expression '&' expression {
-		$$ = $1 & $3;
-	}
-|	expression NOT_EQUAL expression {
-		$$ = $1 != $3;
-	}
-|	expression EQUAL expression {
-		$$ = $1 == $3;
-	}
-|	expression GREATER_OR_EQUAL expression {
-		$$ = $1 >= $3;
-	}
-|	expression LESS_OR_EQUAL expression {
-		$$ = $1 <= $3;
-	}
-|	expression '>' expression {
-		$$ = $1 > $3;
-	}
-|	expression '<' expression {
-		$$ = $1 < $3;
-	}
-|	expression RIGHT_SHIFT expression {
-		$$ = $1 >> $3;
-	}
-|	expression LEFT_SHIFT expression {
-		$$ = $1 << $3;
-	}
-|	expression '-' expression {
-		$$ = $1 - $3;
-	}
-|	expression '+' expression {
-		$$ = $1 + $3;
-	}
-|	expression '%' expression {
-		$$ = $1 % $3;
-	}
-|	expression '/' expression {
-		if ($3 == 0) {
-			yyerror (& @1, parser,
-				 "division by 0 in preprocessor directive");
-		} else {
-			$$ = $1 / $3;
-		}
-	}
-|	expression '*' expression {
-		$$ = $1 * $3;
-	}
-|	'!' expression %prec UNARY {
-		$$ = ! $2;
-	}
-|	'~' expression %prec UNARY {
-		$$ = ~ $2;
-	}
-|	'-' expression %prec UNARY {
-		$$ = - $2;
-	}
-|	'+' expression %prec UNARY {
-		$$ = + $2;
-	}
-|	'(' expression ')' {
-		$$ = $2;
-	}
-;
-
-identifier_list:
-	IDENTIFIER {
-		$$ = _string_list_create (parser);
-		_string_list_append_item ($$, $1);
-		talloc_steal ($$, $1);
-	}
-|	identifier_list ',' IDENTIFIER {
-		$$ = $1;	
-		_string_list_append_item ($$, $3);
-		talloc_steal ($$, $3);
-	}
-;
-
-text_line:
-	NEWLINE { $$ = NULL; }
-|	pp_tokens NEWLINE
-;
-
-non_directive:
-	pp_tokens NEWLINE {
-		yyerror (& @1, parser, "Invalid tokens after #");
-	}
-;
-
-replacement_list:
-	/* empty */ { $$ = NULL; }
-|	pp_tokens
-;
-
-junk:
-	/* empty */
-|	pp_tokens {
-		glcpp_warning(&@1, parser, "extra tokens at end of directive");
-	}
-;
-
-conditional_token:
-	/* Handle "defined" operator */
-	DEFINED IDENTIFIER {
-		int v = hash_table_find (parser->defines, $2) ? 1 : 0;
-		$$ = _token_create_ival (parser, INTEGER, v);
-	}
-|	DEFINED '(' IDENTIFIER ')' {
-		int v = hash_table_find (parser->defines, $3) ? 1 : 0;
-		$$ = _token_create_ival (parser, INTEGER, v);
-	}
-|	preprocessing_token
-;
-
-conditional_tokens:
-	/* Exactly the same as pp_tokens, but using conditional_token */
-	conditional_token {
-		$$ = _token_list_create (parser);
-		_token_list_append ($$, $1);
-	}
-|	conditional_tokens conditional_token {
-		$$ = $1;
-		_token_list_append ($$, $2);
-	}
-;
-
-pp_tokens:
-	preprocessing_token {
-		parser->space_tokens = 1;
-		$$ = _token_list_create (parser);
-		_token_list_append ($$, $1);
-	}
-|	pp_tokens preprocessing_token {
-		$$ = $1;
-		_token_list_append ($$, $2);
-	}
-;
-
-preprocessing_token:
-	IDENTIFIER {
-		$$ = _token_create_str (parser, IDENTIFIER, $1);
-		$$->location = yylloc;
-	}
-|	INTEGER_STRING {
-		$$ = _token_create_str (parser, INTEGER_STRING, $1);
-		$$->location = yylloc;
-	}
-|	operator {
-		$$ = _token_create_ival (parser, $1, $1);
-		$$->location = yylloc;
-	}
-|	OTHER {
-		$$ = _token_create_str (parser, OTHER, $1);
-		$$->location = yylloc;
-	}
-|	SPACE {
-		$$ = _token_create_ival (parser, SPACE, SPACE);
-		$$->location = yylloc;
-	}
-;
-
-operator:
-	'['			{ $$ = '['; }
-|	']'			{ $$ = ']'; }
-|	'('			{ $$ = '('; }
-|	')'			{ $$ = ')'; }
-|	'{'			{ $$ = '{'; }
-|	'}'			{ $$ = '}'; }
-|	'.'			{ $$ = '.'; }
-|	'&'			{ $$ = '&'; }
-|	'*'			{ $$ = '*'; }
-|	'+'			{ $$ = '+'; }
-|	'-'			{ $$ = '-'; }
-|	'~'			{ $$ = '~'; }
-|	'!'			{ $$ = '!'; }
-|	'/'			{ $$ = '/'; }
-|	'%'			{ $$ = '%'; }
-|	LEFT_SHIFT		{ $$ = LEFT_SHIFT; }
-|	RIGHT_SHIFT		{ $$ = RIGHT_SHIFT; }
-|	'<'			{ $$ = '<'; }
-|	'>'			{ $$ = '>'; }
-|	LESS_OR_EQUAL		{ $$ = LESS_OR_EQUAL; }
-|	GREATER_OR_EQUAL	{ $$ = GREATER_OR_EQUAL; }
-|	EQUAL			{ $$ = EQUAL; }
-|	NOT_EQUAL		{ $$ = NOT_EQUAL; }
-|	'^'			{ $$ = '^'; }
-|	'|'			{ $$ = '|'; }
-|	AND			{ $$ = AND; }
-|	OR			{ $$ = OR; }
-|	';'			{ $$ = ';'; }
-|	','			{ $$ = ','; }
-|	'='			{ $$ = '='; }
-|	PASTE			{ $$ = PASTE; }
-;
-
-%%
-
-string_list_t *
-_string_list_create (void *ctx)
-{
-	string_list_t *list;
-
-	list = talloc (ctx, string_list_t);
-	list->head = NULL;
-	list->tail = NULL;
-
-	return list;
-}
-
-void
-_string_list_append_item (string_list_t *list, const char *str)
-{
-	string_node_t *node;
-
-	node = talloc (list, string_node_t);
-	node->str = talloc_strdup (node, str);
-
-	node->next = NULL;
-
-	if (list->head == NULL) {
-		list->head = node;
-	} else {
-		list->tail->next = node;
-	}
-
-	list->tail = node;
-}
-
-int
-_string_list_contains (string_list_t *list, const char *member, int *index)
-{
-	string_node_t *node;
-	int i;
-
-	if (list == NULL)
-		return 0;
-
-	for (i = 0, node = list->head; node; i++, node = node->next) {
-		if (strcmp (node->str, member) == 0) {
-			if (index)
-				*index = i;
-			return 1;
-		}
-	}
-
-	return 0;
-}
-
-int
-_string_list_length (string_list_t *list)
-{
-	int length = 0;
-	string_node_t *node;
-
-	if (list == NULL)
-		return 0;
-
-	for (node = list->head; node; node = node->next)
-		length++;
-
-	return length;
-}
-
-int
-_string_list_equal (string_list_t *a, string_list_t *b)
-{
-	string_node_t *node_a, *node_b;
-
-	if (a == NULL && b == NULL)
-		return 1;
-
-	if (a == NULL || b == NULL)
-		return 0;
-
-	for (node_a = a->head, node_b = b->head;
-	     node_a && node_b;
-	     node_a = node_a->next, node_b = node_b->next)
-	{
-		if (strcmp (node_a->str, node_b->str))
-			return 0;
-	}
-
-	/* Catch the case of lists being different lengths, (which
-	 * would cause the loop above to terminate after the shorter
-	 * list). */
-	return node_a == node_b;
-}
-
-argument_list_t *
-_argument_list_create (void *ctx)
-{
-	argument_list_t *list;
-
-	list = talloc (ctx, argument_list_t);
-	list->head = NULL;
-	list->tail = NULL;
-
-	return list;
-}
-
-void
-_argument_list_append (argument_list_t *list, token_list_t *argument)
-{
-	argument_node_t *node;
-
-	node = talloc (list, argument_node_t);
-	node->argument = argument;
-
-	node->next = NULL;
-
-	if (list->head == NULL) {
-		list->head = node;
-	} else {
-		list->tail->next = node;
-	}
-
-	list->tail = node;
-}
-
-int
-_argument_list_length (argument_list_t *list)
-{
-	int length = 0;
-	argument_node_t *node;
-
-	if (list == NULL)
-		return 0;
-
-	for (node = list->head; node; node = node->next)
-		length++;
-
-	return length;
-}
-
-token_list_t *
-_argument_list_member_at (argument_list_t *list, int index)
-{
-	argument_node_t *node;
-	int i;
-
-	if (list == NULL)
-		return NULL;
-
-	node = list->head;
-	for (i = 0; i < index; i++) {
-		node = node->next;
-		if (node == NULL)
-			break;
-	}
-
-	if (node)
-		return node->argument;
-
-	return NULL;
-}
-
-/* Note: This function talloc_steal()s the str pointer. */
-token_t *
-_token_create_str (void *ctx, int type, char *str)
-{
-	token_t *token;
-
-	token = talloc (ctx, token_t);
-	token->type = type;
-	token->value.str = talloc_steal (token, str);
-
-	return token;
-}
-
-token_t *
-_token_create_ival (void *ctx, int type, int ival)
-{
-	token_t *token;
-
-	token = talloc (ctx, token_t);
-	token->type = type;
-	token->value.ival = ival;
-
-	return token;
-}
-
-token_list_t *
-_token_list_create (void *ctx)
-{
-	token_list_t *list;
-
-	list = talloc (ctx, token_list_t);
-	list->head = NULL;
-	list->tail = NULL;
-	list->non_space_tail = NULL;
-
-	return list;
-}
-
-void
-_token_list_append (token_list_t *list, token_t *token)
-{
-	token_node_t *node;
-
-	node = talloc (list, token_node_t);
-	node->token = talloc_steal (list, token);
-
-	node->next = NULL;
-
-	if (list->head == NULL) {
-		list->head = node;
-	} else {
-		list->tail->next = node;
-	}
-
-	list->tail = node;
-	if (token->type != SPACE)
-		list->non_space_tail = node;
-}
-
-void
-_token_list_append_list (token_list_t *list, token_list_t *tail)
-{
-	if (tail == NULL || tail->head == NULL)
-		return;
-
-	if (list->head == NULL) {
-		list->head = tail->head;
-	} else {
-		list->tail->next = tail->head;
-	}
-
-	list->tail = tail->tail;
-	list->non_space_tail = tail->non_space_tail;
-}
-
-static token_list_t *
-_token_list_copy (void *ctx, token_list_t *other)
-{
-	token_list_t *copy;
-	token_node_t *node;
-
-	if (other == NULL)
-		return NULL;
-
-	copy = _token_list_create (ctx);
-	for (node = other->head; node; node = node->next) {
-		token_t *new_token = talloc (copy, token_t);
-		*new_token = *node->token;
-		_token_list_append (copy, new_token);
-	}
-
-	return copy;
-}
-
-static void
-_token_list_trim_trailing_space (token_list_t *list)
-{
-	token_node_t *tail, *next;
-
-	if (list->non_space_tail) {
-		tail = list->non_space_tail->next;
-		list->non_space_tail->next = NULL;
-		list->tail = list->non_space_tail;
-
-		while (tail) {
-			next = tail->next;
-			talloc_free (tail);
-			tail = next;
-		}
-	}
-}
-
-int
-_token_list_is_empty_ignoring_space (token_list_t *l)
-{
-	token_node_t *n;
-
-	if (l == NULL)
-		return 1;
-
-	n = l->head;
-	while (n != NULL && n->token->type == SPACE)
-		n = n->next;
-
-	return n == NULL;
-}
-
-int
-_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b)
-{
-	token_node_t *node_a, *node_b;
-
-	if (a == NULL || b == NULL) {
-		int a_empty = _token_list_is_empty_ignoring_space(a);
-		int b_empty = _token_list_is_empty_ignoring_space(b);
-		return a_empty == b_empty;
-	}
-
-	node_a = a->head;
-	node_b = b->head;
-
-	while (1)
-	{
-		if (node_a == NULL && node_b == NULL)
-			break;
-
-		if (node_a == NULL || node_b == NULL)
-			return 0;
-
-		if (node_a->token->type == SPACE) {
-			node_a = node_a->next;
-			continue;
-		}
-
-		if (node_b->token->type == SPACE) {
-			node_b = node_b->next;
-			continue;
-		}
-
-		if (node_a->token->type != node_b->token->type)
-			return 0;
-
-		switch (node_a->token->type) {
-		case INTEGER:
-			if (node_a->token->value.ival != 
-			    node_b->token->value.ival)
-			{
-				return 0;
-			}
-			break;
-		case IDENTIFIER:
-		case INTEGER_STRING:
-		case OTHER:
-			if (strcmp (node_a->token->value.str,
-				    node_b->token->value.str))
-			{
-				return 0;
-			}
-			break;
-		}
-
-		node_a = node_a->next;
-		node_b = node_b->next;
-	}
-
-	return 1;
-}
-
-static void
-_token_print (char **out, token_t *token)
-{
-	if (token->type < 256) {
-		glcpp_printf (*out, "%c", token->type);
-		return;
-	}
-
-	switch (token->type) {
-	case INTEGER:
-		glcpp_printf (*out, "%" PRIiMAX, token->value.ival);
-		break;
-	case IDENTIFIER:
-	case INTEGER_STRING:
-	case OTHER:
-		glcpp_print (*out, token->value.str);
-		break;
-	case SPACE:
-		glcpp_print (*out, " ");
-		break;
-	case LEFT_SHIFT:
-		glcpp_print (*out, "<<");
-		break;
-	case RIGHT_SHIFT:
-		glcpp_print (*out, ">>");
-		break;
-	case LESS_OR_EQUAL:
-		glcpp_print (*out, "<=");
-		break;
-	case GREATER_OR_EQUAL:
-		glcpp_print (*out, ">=");
-		break;
-	case EQUAL:
-		glcpp_print (*out, "==");
-		break;
-	case NOT_EQUAL:
-		glcpp_print (*out, "!=");
-		break;
-	case AND:
-		glcpp_print (*out, "&&");
-		break;
-	case OR:
-		glcpp_print (*out, "||");
-		break;
-	case PASTE:
-		glcpp_print (*out, "##");
-		break;
-	case COMMA_FINAL:
-		glcpp_print (*out, ",");
-		break;
-	case PLACEHOLDER:
-		/* Nothing to print. */
-		break;
-	default:
-		assert(!"Error: Don't know how to print token.");
-		break;
-	}
-}
-
-/* Return a new token (talloc()ed off of 'token') formed by pasting
- * 'token' and 'other'. Note that this function may return 'token' or
- * 'other' directly rather than allocating anything new.
- *
- * Caution: Only very cursory error-checking is performed to see if
- * the final result is a valid single token. */
-static token_t *
-_token_paste (glcpp_parser_t *parser, token_t *token, token_t *other)
-{
-	token_t *combined = NULL;
-
-	/* Pasting a placeholder onto anything makes no change. */
-	if (other->type == PLACEHOLDER)
-		return token;
-
-	/* When 'token' is a placeholder, just return 'other'. */
-	if (token->type == PLACEHOLDER)
-		return other;
-
-	/* A very few single-character punctuators can be combined
-	 * with another to form a multi-character punctuator. */
-	switch (token->type) {
-	case '<':
-		if (other->type == '<')
-			combined = _token_create_ival (token, LEFT_SHIFT, LEFT_SHIFT);
-		else if (other->type == '=')
-			combined = _token_create_ival (token, LESS_OR_EQUAL, LESS_OR_EQUAL);
-		break;
-	case '>':
-		if (other->type == '>')
-			combined = _token_create_ival (token, RIGHT_SHIFT, RIGHT_SHIFT);
-		else if (other->type == '=')
-			combined = _token_create_ival (token, GREATER_OR_EQUAL, GREATER_OR_EQUAL);
-		break;
-	case '=':
-		if (other->type == '=')
-			combined = _token_create_ival (token, EQUAL, EQUAL);
-		break;
-	case '!':
-		if (other->type == '=')
-			combined = _token_create_ival (token, NOT_EQUAL, NOT_EQUAL);
-		break;
-	case '&':
-		if (other->type == '&')
-			combined = _token_create_ival (token, AND, AND);
-		break;
-	case '|':
-		if (other->type == '|')
-			combined = _token_create_ival (token, OR, OR);
-		break;
-	}
-
-	if (combined != NULL) {
-		/* Inherit the location from the first token */
-		combined->location = token->location;
-		return combined;
-	}
-
-	/* Two string-valued tokens can usually just be mashed
-	 * together.
-	 *
-	 * XXX: This isn't actually legitimate. Several things here
-	 * should result in a diagnostic since the result cannot be a
-	 * valid, single pre-processing token. For example, pasting
-	 * "123" and "abc" is not legal, but we don't catch that
-	 * here. */
-	if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING) &&
-	    (other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING))
-	{
-		char *str;
-
-		str = talloc_asprintf (token, "%s%s", token->value.str,
-				       other->value.str);
-		combined = _token_create_str (token, token->type, str);
-		combined->location = token->location;
-		return combined;
-	}
-
-	glcpp_error (&token->location, parser, "");
-	glcpp_print (parser->info_log, "Pasting \"");
-	_token_print (&parser->info_log, token);
-	glcpp_print (parser->info_log, "\" and \"");
-	_token_print (&parser->info_log, other);
-	glcpp_print (parser->info_log, "\" does not give a valid preprocessing token.\n");
-
-	return token;
-}
-
-static void
-_token_list_print (glcpp_parser_t *parser, token_list_t *list)
-{
-	token_node_t *node;
-
-	if (list == NULL)
-		return;
-
-	for (node = list->head; node; node = node->next)
-		_token_print (&parser->output, node->token);
-}
-
-void
-yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
-{
-	glcpp_error(locp, parser, "%s", error);
-}
-
-static void add_builtin_define(glcpp_parser_t *parser,
-			       const char *name, int value)
-{
-   token_t *tok;
-   token_list_t *list;
-
-   tok = _token_create_ival (parser, INTEGER, value);
-
-   list = _token_list_create(parser);
-   _token_list_append(list, tok);
-   _define_object_macro(parser, NULL, name, list);
-}
-
-glcpp_parser_t *
-glcpp_parser_create (const struct gl_extensions *extensions, int api)
-{
-	glcpp_parser_t *parser;
-	int language_version;
-
-	parser = talloc (NULL, glcpp_parser_t);
-
-	glcpp_lex_init_extra (parser, &parser->scanner);
-	parser->defines = hash_table_ctor (32, hash_table_string_hash,
-					   hash_table_string_compare);
-	parser->active = NULL;
-	parser->lexing_if = 0;
-	parser->space_tokens = 1;
-	parser->newline_as_space = 0;
-	parser->in_control_line = 0;
-	parser->paren_count = 0;
-
-	parser->skip_stack = NULL;
-
-	parser->lex_from_list = NULL;
-	parser->lex_from_node = NULL;
-
-	parser->output = talloc_strdup(parser, "");
-	parser->info_log = talloc_strdup(parser, "");
-	parser->error = 0;
-
-	/* Add pre-defined macros. */
-	add_builtin_define(parser, "GL_ARB_draw_buffers", 1);
-	add_builtin_define(parser, "GL_ARB_texture_rectangle", 1);
-
-	if (api == API_OPENGLES2)
-		add_builtin_define(parser, "GL_ES", 1);
-
-	if (extensions != NULL) {
-	   if (extensions->EXT_texture_array) {
-	      add_builtin_define(parser, "GL_EXT_texture_array", 1);
-	   }
-
-	   if (extensions->ARB_fragment_coord_conventions)
-	      add_builtin_define(parser, "GL_ARB_fragment_coord_conventions",
-				 1);
-
-	   if (extensions->ARB_explicit_attrib_location)
-	      add_builtin_define(parser, "GL_ARB_explicit_attrib_location", 1);
-	   if (extensions->AMD_conservative_depth)
-	      add_builtin_define(parser, "GL_AMD_conservative_depth", 1);
-	}
-
-	language_version = 110;
-	add_builtin_define(parser, "__VERSION__", language_version);
-
-	return parser;
-}
-
-int
-glcpp_parser_parse (glcpp_parser_t *parser)
-{
-	return yyparse (parser);
-}
-
-void
-glcpp_parser_destroy (glcpp_parser_t *parser)
-{
-	glcpp_lex_destroy (parser->scanner);
-	hash_table_dtor (parser->defines);
-	talloc_free (parser);
-}
-
-typedef enum function_status
-{
-	FUNCTION_STATUS_SUCCESS,
-	FUNCTION_NOT_A_FUNCTION,
-	FUNCTION_UNBALANCED_PARENTHESES
-} function_status_t;
-
-/* Find a set of function-like macro arguments by looking for a
- * balanced set of parentheses.
- *
- * When called, 'node' should be the opening-parenthesis token, (or
- * perhaps preceeding SPACE tokens). Upon successful return *last will
- * be the last consumed node, (corresponding to the closing right
- * parenthesis).
- *
- * Return values:
- *
- *   FUNCTION_STATUS_SUCCESS:
- *
- *	Successfully parsed a set of function arguments.	
- *
- *   FUNCTION_NOT_A_FUNCTION:
- *
- *	Macro name not followed by a '('. This is not an error, but
- *	simply that the macro name should be treated as a non-macro.
- *
- *   FUNCTION_UNBALANCED_PARENTHESES
- *
- *	Macro name is not followed by a balanced set of parentheses.
- */
-static function_status_t
-_arguments_parse (argument_list_t *arguments,
-		  token_node_t *node,
-		  token_node_t **last)
-{
-	token_list_t *argument;
-	int paren_count;
-
-	node = node->next;
-
-	/* Ignore whitespace before first parenthesis. */
-	while (node && node->token->type == SPACE)
-		node = node->next;
-
-	if (node == NULL || node->token->type != '(')
-		return FUNCTION_NOT_A_FUNCTION;
-
-	node = node->next;
-
-	argument = _token_list_create (arguments);
-	_argument_list_append (arguments, argument);
-
-	for (paren_count = 1; node; node = node->next) {
-		if (node->token->type == '(')
-		{
-			paren_count++;
-		}
-		else if (node->token->type == ')')
-		{
-			paren_count--;
-			if (paren_count == 0)
-				break;
-		}
-
-		if (node->token->type == ',' &&
-			 paren_count == 1)
-		{
-			_token_list_trim_trailing_space (argument);
-			argument = _token_list_create (arguments);
-			_argument_list_append (arguments, argument);
-		}
-		else {
-			if (argument->head == NULL) {
-				/* Don't treat initial whitespace as
-				 * part of the arguement. */
-				if (node->token->type == SPACE)
-					continue;
-			}
-			_token_list_append (argument, node->token);
-		}
-	}
-
-	if (paren_count)
-		return FUNCTION_UNBALANCED_PARENTHESES;
-
-	*last = node;
-
-	return FUNCTION_STATUS_SUCCESS;
-}
-
-static token_list_t *
-_token_list_create_with_one_space (void *ctx)
-{
-	token_list_t *list;
-	token_t *space;
-
-	list = _token_list_create (ctx);
-	space = _token_create_ival (list, SPACE, SPACE);
-	_token_list_append (list, space);
-
-	return list;
-}
-
-static void
-_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list)
-{
-	token_list_t *expanded;
-	token_t *token;
-
-	expanded = _token_list_create (parser);
-	token = _token_create_ival (parser, type, type);
-	_token_list_append (expanded, token);
-	_glcpp_parser_expand_token_list (parser, list);
-	_token_list_append_list (expanded, list);
-	glcpp_parser_lex_from (parser, expanded);
-}
-
-/* This is a helper function that's essentially part of the
- * implementation of _glcpp_parser_expand_node. It shouldn't be called
- * except for by that function.
- *
- * Returns NULL if node is a simple token with no expansion, (that is,
- * although 'node' corresponds to an identifier defined as a
- * function-like macro, it is not followed with a parenthesized
- * argument list).
- *
- * Compute the complete expansion of node (which is a function-like
- * macro) and subsequent nodes which are arguments.
- *
- * Returns the token list that results from the expansion and sets
- * *last to the last node in the list that was consumed by the
- * expansion. Specifically, *last will be set as follows: as the
- * token of the closing right parenthesis.
- */
-static token_list_t *
-_glcpp_parser_expand_function (glcpp_parser_t *parser,
-			       token_node_t *node,
-			       token_node_t **last)
-			       
-{
-	macro_t *macro;
-	const char *identifier;
-	argument_list_t *arguments;
-	function_status_t status;
-	token_list_t *substituted;
-	int parameter_index;
-
-	identifier = node->token->value.str;
-
-	macro = hash_table_find (parser->defines, identifier);
-
-	assert (macro->is_function);
-
-	arguments = _argument_list_create (parser);
-	status = _arguments_parse (arguments, node, last);
-
-	switch (status) {
-	case FUNCTION_STATUS_SUCCESS:
-		break;
-	case FUNCTION_NOT_A_FUNCTION:
-		return NULL;
-	case FUNCTION_UNBALANCED_PARENTHESES:
-		glcpp_error (&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identifier);
-		return NULL;
-	}
-
-	/* Replace a macro defined as empty with a SPACE token. */
-	if (macro->replacements == NULL) {
-		talloc_free (arguments);
-		return _token_list_create_with_one_space (parser);
-	}
-
-	if (! ((_argument_list_length (arguments) == 
-		_string_list_length (macro->parameters)) ||
-	       (_string_list_length (macro->parameters) == 0 &&
-		_argument_list_length (arguments) == 1 &&
-		arguments->head->argument->head == NULL)))
-	{
-		glcpp_error (&node->token->location, parser,
-			      "Error: macro %s invoked with %d arguments (expected %d)\n",
-			      identifier,
-			      _argument_list_length (arguments),
-			      _string_list_length (macro->parameters));
-		return NULL;
-	}
-
-	/* Perform argument substitution on the replacement list. */
-	substituted = _token_list_create (arguments);
-
-	for (node = macro->replacements->head; node; node = node->next)
-	{
-		if (node->token->type == IDENTIFIER &&
-		    _string_list_contains (macro->parameters,
-					   node->token->value.str,
-					   &parameter_index))
-		{
-			token_list_t *argument;
-			argument = _argument_list_member_at (arguments,
-							     parameter_index);
-			/* Before substituting, we expand the argument
-			 * tokens, or append a placeholder token for
-			 * an empty argument. */
-			if (argument->head) {
-				token_list_t *expanded_argument;
-				expanded_argument = _token_list_copy (parser,
-								      argument);
-				_glcpp_parser_expand_token_list (parser,
-								 expanded_argument);
-				_token_list_append_list (substituted,
-							 expanded_argument);
-			} else {
-				token_t *new_token;
-
-				new_token = _token_create_ival (substituted,
-								PLACEHOLDER,
-								PLACEHOLDER);
-				_token_list_append (substituted, new_token);
-			}
-		} else {
-			_token_list_append (substituted, node->token);
-		}
-	}
-
-	/* After argument substitution, and before further expansion
-	 * below, implement token pasting. */
-
-	_token_list_trim_trailing_space (substituted);
-
-	node = substituted->head;
-	while (node)
-	{
-		token_node_t *next_non_space;
-
-		/* Look ahead for a PASTE token, skipping space. */
-		next_non_space = node->next;
-		while (next_non_space && next_non_space->token->type == SPACE)
-			next_non_space = next_non_space->next;
-
-		if (next_non_space == NULL)
-			break;
-
-		if (next_non_space->token->type != PASTE) {
-			node = next_non_space;
-			continue;
-		}
-
-		/* Now find the next non-space token after the PASTE. */
-		next_non_space = next_non_space->next;
-		while (next_non_space && next_non_space->token->type == SPACE)
-			next_non_space = next_non_space->next;
-
-		if (next_non_space == NULL) {
-			yyerror (&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n");
-			return NULL;
-		}
-
-		node->token = _token_paste (parser, node->token, next_non_space->token);
-		node->next = next_non_space->next;
-		if (next_non_space == substituted->tail)
-			substituted->tail = node;
-
-		node = node->next;
-	}
-
-	substituted->non_space_tail = substituted->tail;
-
-	return substituted;
-}
-
-/* Compute the complete expansion of node, (and subsequent nodes after
- * 'node' in the case that 'node' is a function-like macro and
- * subsequent nodes are arguments).
- *
- * Returns NULL if node is a simple token with no expansion.
- *
- * Otherwise, returns the token list that results from the expansion
- * and sets *last to the last node in the list that was consumed by
- * the expansion. Specifically, *last will be set as follows:
- *
- *	As 'node' in the case of object-like macro expansion.
- *
- *	As the token of the closing right parenthesis in the case of
- *	function-like macro expansion.
- */
-static token_list_t *
-_glcpp_parser_expand_node (glcpp_parser_t *parser,
-			   token_node_t *node,
-			   token_node_t **last)
-{
-	token_t *token = node->token;
-	const char *identifier;
-	macro_t *macro;
-
-	/* We only expand identifiers */
-	if (token->type != IDENTIFIER) {
-		/* We change any COMMA into a COMMA_FINAL to prevent
-		 * it being mistaken for an argument separator
-		 * later. */
-		if (token->type == ',') {
-			token->type = COMMA_FINAL;
-			token->value.ival = COMMA_FINAL;
-		}
-
-		return NULL;
-	}
-
-	/* Look up this identifier in the hash table. */
-	identifier = token->value.str;
-	macro = hash_table_find (parser->defines, identifier);
-
-	/* Not a macro, so no expansion needed. */
-	if (macro == NULL)
-		return NULL;
-
-	/* Finally, don't expand this macro if we're already actively
-	 * expanding it, (to avoid infinite recursion). */
-	if (_active_list_contains (parser->active, identifier)) {
-		/* We change the token type here from IDENTIFIER to
-		 * OTHER to prevent any future expansion of this
-		 * unexpanded token. */
-		char *str;
-		token_list_t *expansion;
-		token_t *final;
-
-		str = talloc_strdup (parser, token->value.str);
-		final = _token_create_str (parser, OTHER, str);
-		expansion = _token_list_create (parser);
-		_token_list_append (expansion, final);
-		*last = node;
-		return expansion;
-	}
-
-	if (! macro->is_function)
-	{
-		*last = node;
-
-		/* Replace a macro defined as empty with a SPACE token. */
-		if (macro->replacements == NULL)
-			return _token_list_create_with_one_space (parser);
-
-		return _token_list_copy (parser, macro->replacements);
-	}
-
-	return _glcpp_parser_expand_function (parser, node, last);
-}
-
-/* Push a new identifier onto the active list, returning the new list.
- *
- * Here, 'marker' is the token node that appears in the list after the
- * expansion of 'identifier'. That is, when the list iterator begins
- * examinging 'marker', then it is time to pop this node from the
- * active stack.
- */
-active_list_t *
-_active_list_push (active_list_t *list,
-		   const char *identifier,
-		   token_node_t *marker)
-{
-	active_list_t *node;
-
-	node = talloc (list, active_list_t);
-	node->identifier = talloc_strdup (node, identifier);
-	node->marker = marker;
-	node->next = list;
-
-	return node;
-}
-
-active_list_t *
-_active_list_pop (active_list_t *list)
-{
-	active_list_t *node = list;
-
-	if (node == NULL)
-		return NULL;
-
-	node = list->next;
-	talloc_free (list);
-
-	return node;
-}
-
-int
-_active_list_contains (active_list_t *list, const char *identifier)
-{
-	active_list_t *node;
-
-	if (list == NULL)
-		return 0;
-
-	for (node = list; node; node = node->next)
-		if (strcmp (node->identifier, identifier) == 0)
-			return 1;
-
-	return 0;
-}
-
-/* Walk over the token list replacing nodes with their expansion.
- * Whenever nodes are expanded the walking will walk over the new
- * nodes, continuing to expand as necessary. The results are placed in
- * 'list' itself;
- */
-static void
-_glcpp_parser_expand_token_list (glcpp_parser_t *parser,
-				 token_list_t *list)
-{
-	token_node_t *node_prev;
-	token_node_t *node, *last = NULL;
-	token_list_t *expansion;
-
-	if (list == NULL)
-		return;
-
-	_token_list_trim_trailing_space (list);
-
-	node_prev = NULL;
-	node = list->head;
-
-	while (node) {
-
-		while (parser->active && parser->active->marker == node)
-			parser->active = _active_list_pop (parser->active);
-
-		/* Find the expansion for node, which will replace all
-		 * nodes from node to last, inclusive. */
-		expansion = _glcpp_parser_expand_node (parser, node, &last);
-		if (expansion) {
-			token_node_t *n;
-
-			for (n = node; n != last->next; n = n->next)
-				while (parser->active &&
-				       parser->active->marker == n)
-				{
-					parser->active = _active_list_pop (parser->active);
-				}
-
-			parser->active = _active_list_push (parser->active,
-							    node->token->value.str,
-							    last->next);
-			
-			/* Splice expansion into list, supporting a
-			 * simple deletion if the expansion is
-			 * empty. */
-			if (expansion->head) {
-				if (node_prev)
-					node_prev->next = expansion->head;
-				else
-					list->head = expansion->head;
-				expansion->tail->next = last->next;
-				if (last == list->tail)
-					list->tail = expansion->tail;
-			} else {
-				if (node_prev)
-					node_prev->next = last->next;
-				else
-					list->head = last->next;
-				if (last == list->tail)
-					list->tail = NULL;
-			}
-		} else {
-			node_prev = node;
-		}
-		node = node_prev ? node_prev->next : list->head;
-	}
-
-	while (parser->active)
-		parser->active = _active_list_pop (parser->active);
-
-	list->non_space_tail = list->tail;
-}
-
-void
-_glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
-					 token_list_t *list)
-{
-	if (list == NULL)
-		return;
-
-	_glcpp_parser_expand_token_list (parser, list);
-
-	_token_list_trim_trailing_space (list);
-
-	_token_list_print (parser, list);
-}
-
-static void
-_check_for_reserved_macro_name (glcpp_parser_t *parser, YYLTYPE *loc,
-				const char *identifier)
-{
-	/* According to the GLSL specification, macro names starting with "__"
-	 * or "GL_" are reserved for future use.  So, don't allow them.
-	 */
-	if (strncmp(identifier, "__", 2) == 0) {
-		glcpp_error (loc, parser, "Macro names starting with \"__\" are reserved.\n");
-	}
-	if (strncmp(identifier, "GL_", 3) == 0) {
-		glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n");
-	}
-}
-
-static int
-_macro_equal (macro_t *a, macro_t *b)
-{
-	if (a->is_function != b->is_function)
-		return 0;
-
-	if (a->is_function) {
-		if (! _string_list_equal (a->parameters, b->parameters))
-			return 0;
-	}
-
-	return _token_list_equal_ignoring_space (a->replacements,
-						 b->replacements);
-}
-
-void
-_define_object_macro (glcpp_parser_t *parser,
-		      YYLTYPE *loc,
-		      const char *identifier,
-		      token_list_t *replacements)
-{
-	macro_t *macro, *previous;
-
-	if (loc != NULL)
-		_check_for_reserved_macro_name(parser, loc, identifier);
-
-	macro = talloc (parser, macro_t);
-
-	macro->is_function = 0;
-	macro->parameters = NULL;
-	macro->identifier = talloc_strdup (macro, identifier);
-	macro->replacements = talloc_steal (macro, replacements);
-
-	previous = hash_table_find (parser->defines, identifier);
-	if (previous) {
-		if (_macro_equal (macro, previous)) {
-			talloc_free (macro);
-			return;
-		}
-		glcpp_warning (loc, parser, "Redefinition of macro %s\n",
-			       identifier);
-	}
-
-	hash_table_insert (parser->defines, macro, identifier);
-}
-
-void
-_define_function_macro (glcpp_parser_t *parser,
-			YYLTYPE *loc,
-			const char *identifier,
-			string_list_t *parameters,
-			token_list_t *replacements)
-{
-	macro_t *macro, *previous;
-
-	_check_for_reserved_macro_name(parser, loc, identifier);
-
-	macro = talloc (parser, macro_t);
-
-	macro->is_function = 1;
-	macro->parameters = talloc_steal (macro, parameters);
-	macro->identifier = talloc_strdup (macro, identifier);
-	macro->replacements = talloc_steal (macro, replacements);
-
-	previous = hash_table_find (parser->defines, identifier);
-	if (previous) {
-		if (_macro_equal (macro, previous)) {
-			talloc_free (macro);
-			return;
-		}
-		glcpp_warning (loc, parser, "Redefinition of macro %s\n",
-			       identifier);
-	}
-
-	hash_table_insert (parser->defines, macro, identifier);
-}
-
-static int
-glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
-{
-	token_node_t *node;
-	int ret;
-
-	if (parser->lex_from_list == NULL) {
-		ret = glcpp_lex (yylval, yylloc, parser->scanner);
-
-		/* XXX: This ugly block of code exists for the sole
-		 * purpose of converting a NEWLINE token into a SPACE
-		 * token, but only in the case where we have seen a
-		 * function-like macro name, but have not yet seen its
-		 * closing parenthesis.
-		 *
-		 * There's perhaps a more compact way to do this with
-		 * mid-rule actions in the grammar.
-		 *
-		 * I'm definitely not pleased with the complexity of
-		 * this code here.
-		 */
-		if (parser->newline_as_space)
-		{
-			if (ret == '(') {
-				parser->paren_count++;
-			} else if (ret == ')') {
-				parser->paren_count--;
-				if (parser->paren_count == 0)
-					parser->newline_as_space = 0;
-			} else if (ret == NEWLINE) {
-				ret = SPACE;
-			} else if (ret != SPACE) {
-				if (parser->paren_count == 0)
-					parser->newline_as_space = 0;
-			}
-		}
-		else if (parser->in_control_line)
-		{
-			if (ret == NEWLINE)
-				parser->in_control_line = 0;
-		}
-		else if (ret == HASH_DEFINE_OBJ || ret == HASH_DEFINE_FUNC ||
-			   ret == HASH_UNDEF || ret == HASH_IF ||
-			   ret == HASH_IFDEF || ret == HASH_IFNDEF ||
-			   ret == HASH_ELIF || ret == HASH_ELSE ||
-			   ret == HASH_ENDIF || ret == HASH)
-		{
-			parser->in_control_line = 1;
-		}
-		else if (ret == IDENTIFIER)
-		{
-			macro_t *macro;
-			macro = hash_table_find (parser->defines,
-						 yylval->str);
-			if (macro && macro->is_function) {
-				parser->newline_as_space = 1;
-				parser->paren_count = 0;
-			}
-		}
-
-		return ret;
-	}
-
-	node = parser->lex_from_node;
-
-	if (node == NULL) {
-		talloc_free (parser->lex_from_list);
-		parser->lex_from_list = NULL;
-		return NEWLINE;
-	}
-
-	*yylval = node->token->value;
-	ret = node->token->type;
-
-	parser->lex_from_node = node->next;
-
-	return ret;
-}
-
-static void
-glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list)
-{
-	token_node_t *node;
-
-	assert (parser->lex_from_list == NULL);
-
-	/* Copy list, eliminating any space tokens. */
-	parser->lex_from_list = _token_list_create (parser);
-
-	for (node = list->head; node; node = node->next) {
-		if (node->token->type == SPACE)
-			continue;
-		_token_list_append (parser->lex_from_list, node->token);
-	}
-
-	talloc_free (list);
-
-	parser->lex_from_node = parser->lex_from_list->head;
-
-	/* It's possible the list consisted of nothing but whitespace. */
-	if (parser->lex_from_node == NULL) {
-		talloc_free (parser->lex_from_list);
-		parser->lex_from_list = NULL;
-	}
-}
-
-static void
-_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
-				  int condition)
-{
-	skip_type_t current = SKIP_NO_SKIP;
-	skip_node_t *node;
-
-	if (parser->skip_stack)
-		current = parser->skip_stack->type;
-
-	node = talloc (parser, skip_node_t);
-	node->loc = *loc;
-
-	if (current == SKIP_NO_SKIP) {
-		if (condition)
-			node->type = SKIP_NO_SKIP;
-		else
-			node->type = SKIP_TO_ELSE;
-	} else {
-		node->type = SKIP_TO_ENDIF;
-	}
-
-	node->next = parser->skip_stack;
-	parser->skip_stack = node;
-}
-
-static void
-_glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
-				    const char *type, int condition)
-{
-	if (parser->skip_stack == NULL) {
-		glcpp_error (loc, parser, "%s without #if\n", type);
-		return;
-	}
-
-	if (parser->skip_stack->type == SKIP_TO_ELSE) {
-		if (condition)
-			parser->skip_stack->type = SKIP_NO_SKIP;
-	} else {
-		parser->skip_stack->type = SKIP_TO_ENDIF;
-	}
-}
-
-static void
-_glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc)
-{
-	skip_node_t *node;
-
-	if (parser->skip_stack == NULL) {
-		glcpp_error (loc, parser, "#endif without #if\n");
-		return;
-	}
-
-	node = parser->skip_stack;
-	parser->skip_stack = node->next;
-	talloc_free (node);
-}
+%{
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <inttypes.h>
+
+#include "glcpp.h"
+#include "main/core.h" /* for struct gl_extensions */
+#include "main/mtypes.h" /* for gl_api enum */
+
+#define glcpp_print(stream, str) stream = talloc_strdup_append(stream, str)
+#define glcpp_printf(stream, fmt, args, ...) \
+	stream = talloc_asprintf_append(stream, fmt, args)
+
+static void
+yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
+
+static void
+_define_object_macro (glcpp_parser_t *parser,
+		      YYLTYPE *loc,
+		      const char *macro,
+		      token_list_t *replacements);
+
+static void
+_define_function_macro (glcpp_parser_t *parser,
+			YYLTYPE *loc,
+			const char *macro,
+			string_list_t *parameters,
+			token_list_t *replacements);
+
+static string_list_t *
+_string_list_create (void *ctx);
+
+static void
+_string_list_append_item (string_list_t *list, const char *str);
+
+static int
+_string_list_contains (string_list_t *list, const char *member, int *index);
+
+static int
+_string_list_length (string_list_t *list);
+
+static int
+_string_list_equal (string_list_t *a, string_list_t *b);
+
+static argument_list_t *
+_argument_list_create (void *ctx);
+
+static void
+_argument_list_append (argument_list_t *list, token_list_t *argument);
+
+static int
+_argument_list_length (argument_list_t *list);
+
+static token_list_t *
+_argument_list_member_at (argument_list_t *list, int index);
+
+/* Note: This function talloc_steal()s the str pointer. */
+static token_t *
+_token_create_str (void *ctx, int type, char *str);
+
+static token_t *
+_token_create_ival (void *ctx, int type, int ival);
+
+static token_list_t *
+_token_list_create (void *ctx);
+
+/* Note: This function calls talloc_steal on token. */
+static void
+_token_list_append (token_list_t *list, token_t *token);
+
+static void
+_token_list_append_list (token_list_t *list, token_list_t *tail);
+
+static int
+_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b);
+
+static active_list_t *
+_active_list_push (active_list_t *list,
+		   const char *identifier,
+		   token_node_t *marker);
+
+static active_list_t *
+_active_list_pop (active_list_t *list);
+
+int
+_active_list_contains (active_list_t *list, const char *identifier);
+
+static void
+_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list);
+
+static void
+_glcpp_parser_expand_token_list (glcpp_parser_t *parser,
+				 token_list_t *list);
+
+static void
+_glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
+					 token_list_t *list);
+
+static void
+_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
+				  int condition);
+
+static void
+_glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
+				    const char *type, int condition);
+
+static void
+_glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc);
+
+#define yylex glcpp_parser_lex
+
+static int
+glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser);
+
+static void
+glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list);
+
+static void
+add_builtin_define(glcpp_parser_t *parser, const char *name, int value);
+
+%}
+
+%pure-parser
+%error-verbose
+
+%locations
+%initial-action {
+	@$.first_line = 1;
+	@$.first_column = 1;
+	@$.last_line = 1;
+	@$.last_column = 1;
+	@$.source = 0;
+}
+
+%parse-param {glcpp_parser_t *parser}
+%lex-param {glcpp_parser_t *parser}
+
+%expect 0
+%token COMMA_FINAL DEFINED ELIF_EXPANDED HASH HASH_DEFINE_FUNC HASH_DEFINE_OBJ HASH_ELIF HASH_ELSE HASH_ENDIF HASH_IF HASH_IFDEF HASH_IFNDEF HASH_UNDEF HASH_VERSION IDENTIFIER IF_EXPANDED INTEGER INTEGER_STRING NEWLINE OTHER PLACEHOLDER SPACE
+%token PASTE
+%type <ival> expression INTEGER operator SPACE integer_constant
+%type <str> IDENTIFIER INTEGER_STRING OTHER
+%type <string_list> identifier_list
+%type <token> preprocessing_token conditional_token
+%type <token_list> pp_tokens replacement_list text_line conditional_tokens
+%left OR
+%left AND
+%left '|'
+%left '^'
+%left '&'
+%left EQUAL NOT_EQUAL
+%left '<' '>' LESS_OR_EQUAL GREATER_OR_EQUAL
+%left LEFT_SHIFT RIGHT_SHIFT
+%left '+' '-'
+%left '*' '/' '%'
+%right UNARY
+
+%%
+
+input:
+	/* empty */
+|	input line
+;
+
+line:
+	control_line {
+		glcpp_print(parser->output, "\n");
+	}
+|	text_line {
+		_glcpp_parser_print_expanded_token_list (parser, $1);
+		glcpp_print(parser->output, "\n");
+		talloc_free ($1);
+	}
+|	expanded_line
+|	HASH non_directive
+;
+
+expanded_line:
+	IF_EXPANDED expression NEWLINE {
+		_glcpp_parser_skip_stack_push_if (parser, & @1, $2);
+	}
+|	ELIF_EXPANDED expression NEWLINE {
+		_glcpp_parser_skip_stack_change_if (parser, & @1, "elif", $2);
+	}
+;
+
+control_line:
+	HASH_DEFINE_OBJ	IDENTIFIER replacement_list NEWLINE {
+		_define_object_macro (parser, & @2, $2, $3);
+	}
+|	HASH_DEFINE_FUNC IDENTIFIER '(' ')' replacement_list NEWLINE {
+		_define_function_macro (parser, & @2, $2, NULL, $5);
+	}
+|	HASH_DEFINE_FUNC IDENTIFIER '(' identifier_list ')' replacement_list NEWLINE {
+		_define_function_macro (parser, & @2, $2, $4, $6);
+	}
+|	HASH_UNDEF IDENTIFIER NEWLINE {
+		macro_t *macro = hash_table_find (parser->defines, $2);
+		if (macro) {
+			hash_table_remove (parser->defines, $2);
+			talloc_free (macro);
+		}
+		talloc_free ($2);
+	}
+|	HASH_IF conditional_tokens NEWLINE {
+		/* Be careful to only evaluate the 'if' expression if
+		 * we are not skipping. When we are skipping, we
+		 * simply push a new 0-valued 'if' onto the skip
+		 * stack.
+		 *
+		 * This avoids generating diagnostics for invalid
+		 * expressions that are being skipped. */
+		if (parser->skip_stack == NULL ||
+		    parser->skip_stack->type == SKIP_NO_SKIP)
+		{
+			_glcpp_parser_expand_if (parser, IF_EXPANDED, $2);
+		}	
+		else
+		{
+			_glcpp_parser_skip_stack_push_if (parser, & @1, 0);
+			parser->skip_stack->type = SKIP_TO_ENDIF;
+		}
+	}
+|	HASH_IF NEWLINE {
+		/* #if without an expression is only an error if we
+		 *  are not skipping */
+		if (parser->skip_stack == NULL ||
+		    parser->skip_stack->type == SKIP_NO_SKIP)
+		{
+			glcpp_error(& @1, parser, "#if with no expression");
+		}	
+		_glcpp_parser_skip_stack_push_if (parser, & @1, 0);
+	}
+|	HASH_IFDEF IDENTIFIER junk NEWLINE {
+		macro_t *macro = hash_table_find (parser->defines, $2);
+		talloc_free ($2);
+		_glcpp_parser_skip_stack_push_if (parser, & @1, macro != NULL);
+	}
+|	HASH_IFNDEF IDENTIFIER junk NEWLINE {
+		macro_t *macro = hash_table_find (parser->defines, $2);
+		talloc_free ($2);
+		_glcpp_parser_skip_stack_push_if (parser, & @1, macro == NULL);
+	}
+|	HASH_ELIF conditional_tokens NEWLINE {
+		/* Be careful to only evaluate the 'elif' expression
+		 * if we are not skipping. When we are skipping, we
+		 * simply change to a 0-valued 'elif' on the skip
+		 * stack.
+		 *
+		 * This avoids generating diagnostics for invalid
+		 * expressions that are being skipped. */
+		if (parser->skip_stack &&
+		    parser->skip_stack->type == SKIP_TO_ELSE)
+		{
+			_glcpp_parser_expand_if (parser, ELIF_EXPANDED, $2);
+		}
+		else
+		{
+			_glcpp_parser_skip_stack_change_if (parser, & @1,
+							    "elif", 0);
+		}
+	}
+|	HASH_ELIF NEWLINE {
+		/* #elif without an expression is an error unless we
+		 * are skipping. */
+		if (parser->skip_stack &&
+		    parser->skip_stack->type == SKIP_TO_ELSE)
+		{
+			glcpp_error(& @1, parser, "#elif with no expression");
+		}
+		else
+		{
+			_glcpp_parser_skip_stack_change_if (parser, & @1,
+							    "elif", 0);
+			glcpp_warning(& @1, parser, "ignoring illegal #elif without expression");
+		}
+	}
+|	HASH_ELSE NEWLINE {
+		_glcpp_parser_skip_stack_change_if (parser, & @1, "else", 1);
+	}
+|	HASH_ENDIF NEWLINE {
+		_glcpp_parser_skip_stack_pop (parser, & @1);
+	}
+|	HASH_VERSION integer_constant NEWLINE {
+		macro_t *macro = hash_table_find (parser->defines, "__VERSION__");
+		if (macro) {
+			hash_table_remove (parser->defines, "__VERSION__");
+			talloc_free (macro);
+		}
+		add_builtin_define (parser, "__VERSION__", $2);
+
+		if ($2 == 100)
+			add_builtin_define (parser, "GL_ES", 1);
+
+		/* Currently, all ES2 implementations support highp in the
+		 * fragment shader, so we always define this macro in ES2.
+		 * If we ever get a driver that doesn't support highp, we'll
+		 * need to add a flag to the gl_context and check that here.
+		 */
+		if ($2 >= 130 || $2 == 100)
+			add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1);
+
+		glcpp_printf(parser->output, "#version %" PRIiMAX, $2);
+	}
+|	HASH NEWLINE
+;
+
+integer_constant:
+	INTEGER_STRING {
+		if (strlen ($1) >= 3 && strncmp ($1, "0x", 2) == 0) {
+			$$ = strtoll ($1 + 2, NULL, 16);
+		} else if ($1[0] == '0') {
+			$$ = strtoll ($1, NULL, 8);
+		} else {
+			$$ = strtoll ($1, NULL, 10);
+		}
+	}
+|	INTEGER {
+		$$ = $1;
+	}
+
+expression:
+	integer_constant
+|	expression OR expression {
+		$$ = $1 || $3;
+	}
+|	expression AND expression {
+		$$ = $1 && $3;
+	}
+|	expression '|' expression {
+		$$ = $1 | $3;
+	}
+|	expression '^' expression {
+		$$ = $1 ^ $3;
+	}
+|	expression '&' expression {
+		$$ = $1 & $3;
+	}
+|	expression NOT_EQUAL expression {
+		$$ = $1 != $3;
+	}
+|	expression EQUAL expression {
+		$$ = $1 == $3;
+	}
+|	expression GREATER_OR_EQUAL expression {
+		$$ = $1 >= $3;
+	}
+|	expression LESS_OR_EQUAL expression {
+		$$ = $1 <= $3;
+	}
+|	expression '>' expression {
+		$$ = $1 > $3;
+	}
+|	expression '<' expression {
+		$$ = $1 < $3;
+	}
+|	expression RIGHT_SHIFT expression {
+		$$ = $1 >> $3;
+	}
+|	expression LEFT_SHIFT expression {
+		$$ = $1 << $3;
+	}
+|	expression '-' expression {
+		$$ = $1 - $3;
+	}
+|	expression '+' expression {
+		$$ = $1 + $3;
+	}
+|	expression '%' expression {
+		$$ = $1 % $3;
+	}
+|	expression '/' expression {
+		if ($3 == 0) {
+			yyerror (& @1, parser,
+				 "division by 0 in preprocessor directive");
+		} else {
+			$$ = $1 / $3;
+		}
+	}
+|	expression '*' expression {
+		$$ = $1 * $3;
+	}
+|	'!' expression %prec UNARY {
+		$$ = ! $2;
+	}
+|	'~' expression %prec UNARY {
+		$$ = ~ $2;
+	}
+|	'-' expression %prec UNARY {
+		$$ = - $2;
+	}
+|	'+' expression %prec UNARY {
+		$$ = + $2;
+	}
+|	'(' expression ')' {
+		$$ = $2;
+	}
+;
+
+identifier_list:
+	IDENTIFIER {
+		$$ = _string_list_create (parser);
+		_string_list_append_item ($$, $1);
+		talloc_steal ($$, $1);
+	}
+|	identifier_list ',' IDENTIFIER {
+		$$ = $1;	
+		_string_list_append_item ($$, $3);
+		talloc_steal ($$, $3);
+	}
+;
+
+text_line:
+	NEWLINE { $$ = NULL; }
+|	pp_tokens NEWLINE
+;
+
+non_directive:
+	pp_tokens NEWLINE {
+		yyerror (& @1, parser, "Invalid tokens after #");
+	}
+;
+
+replacement_list:
+	/* empty */ { $$ = NULL; }
+|	pp_tokens
+;
+
+junk:
+	/* empty */
+|	pp_tokens {
+		glcpp_warning(&@1, parser, "extra tokens at end of directive");
+	}
+;
+
+conditional_token:
+	/* Handle "defined" operator */
+	DEFINED IDENTIFIER {
+		int v = hash_table_find (parser->defines, $2) ? 1 : 0;
+		$$ = _token_create_ival (parser, INTEGER, v);
+	}
+|	DEFINED '(' IDENTIFIER ')' {
+		int v = hash_table_find (parser->defines, $3) ? 1 : 0;
+		$$ = _token_create_ival (parser, INTEGER, v);
+	}
+|	preprocessing_token
+;
+
+conditional_tokens:
+	/* Exactly the same as pp_tokens, but using conditional_token */
+	conditional_token {
+		$$ = _token_list_create (parser);
+		_token_list_append ($$, $1);
+	}
+|	conditional_tokens conditional_token {
+		$$ = $1;
+		_token_list_append ($$, $2);
+	}
+;
+
+pp_tokens:
+	preprocessing_token {
+		parser->space_tokens = 1;
+		$$ = _token_list_create (parser);
+		_token_list_append ($$, $1);
+	}
+|	pp_tokens preprocessing_token {
+		$$ = $1;
+		_token_list_append ($$, $2);
+	}
+;
+
+preprocessing_token:
+	IDENTIFIER {
+		$$ = _token_create_str (parser, IDENTIFIER, $1);
+		$$->location = yylloc;
+	}
+|	INTEGER_STRING {
+		$$ = _token_create_str (parser, INTEGER_STRING, $1);
+		$$->location = yylloc;
+	}
+|	operator {
+		$$ = _token_create_ival (parser, $1, $1);
+		$$->location = yylloc;
+	}
+|	OTHER {
+		$$ = _token_create_str (parser, OTHER, $1);
+		$$->location = yylloc;
+	}
+|	SPACE {
+		$$ = _token_create_ival (parser, SPACE, SPACE);
+		$$->location = yylloc;
+	}
+;
+
+operator:
+	'['			{ $$ = '['; }
+|	']'			{ $$ = ']'; }
+|	'('			{ $$ = '('; }
+|	')'			{ $$ = ')'; }
+|	'{'			{ $$ = '{'; }
+|	'}'			{ $$ = '}'; }
+|	'.'			{ $$ = '.'; }
+|	'&'			{ $$ = '&'; }
+|	'*'			{ $$ = '*'; }
+|	'+'			{ $$ = '+'; }
+|	'-'			{ $$ = '-'; }
+|	'~'			{ $$ = '~'; }
+|	'!'			{ $$ = '!'; }
+|	'/'			{ $$ = '/'; }
+|	'%'			{ $$ = '%'; }
+|	LEFT_SHIFT		{ $$ = LEFT_SHIFT; }
+|	RIGHT_SHIFT		{ $$ = RIGHT_SHIFT; }
+|	'<'			{ $$ = '<'; }
+|	'>'			{ $$ = '>'; }
+|	LESS_OR_EQUAL		{ $$ = LESS_OR_EQUAL; }
+|	GREATER_OR_EQUAL	{ $$ = GREATER_OR_EQUAL; }
+|	EQUAL			{ $$ = EQUAL; }
+|	NOT_EQUAL		{ $$ = NOT_EQUAL; }
+|	'^'			{ $$ = '^'; }
+|	'|'			{ $$ = '|'; }
+|	AND			{ $$ = AND; }
+|	OR			{ $$ = OR; }
+|	';'			{ $$ = ';'; }
+|	','			{ $$ = ','; }
+|	'='			{ $$ = '='; }
+|	PASTE			{ $$ = PASTE; }
+;
+
+%%
+
+string_list_t *
+_string_list_create (void *ctx)
+{
+	string_list_t *list;
+
+	list = talloc (ctx, string_list_t);
+	list->head = NULL;
+	list->tail = NULL;
+
+	return list;
+}
+
+void
+_string_list_append_item (string_list_t *list, const char *str)
+{
+	string_node_t *node;
+
+	node = talloc (list, string_node_t);
+	node->str = talloc_strdup (node, str);
+
+	node->next = NULL;
+
+	if (list->head == NULL) {
+		list->head = node;
+	} else {
+		list->tail->next = node;
+	}
+
+	list->tail = node;
+}
+
+int
+_string_list_contains (string_list_t *list, const char *member, int *index)
+{
+	string_node_t *node;
+	int i;
+
+	if (list == NULL)
+		return 0;
+
+	for (i = 0, node = list->head; node; i++, node = node->next) {
+		if (strcmp (node->str, member) == 0) {
+			if (index)
+				*index = i;
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
+int
+_string_list_length (string_list_t *list)
+{
+	int length = 0;
+	string_node_t *node;
+
+	if (list == NULL)
+		return 0;
+
+	for (node = list->head; node; node = node->next)
+		length++;
+
+	return length;
+}
+
+int
+_string_list_equal (string_list_t *a, string_list_t *b)
+{
+	string_node_t *node_a, *node_b;
+
+	if (a == NULL && b == NULL)
+		return 1;
+
+	if (a == NULL || b == NULL)
+		return 0;
+
+	for (node_a = a->head, node_b = b->head;
+	     node_a && node_b;
+	     node_a = node_a->next, node_b = node_b->next)
+	{
+		if (strcmp (node_a->str, node_b->str))
+			return 0;
+	}
+
+	/* Catch the case of lists being different lengths, (which
+	 * would cause the loop above to terminate after the shorter
+	 * list). */
+	return node_a == node_b;
+}
+
+argument_list_t *
+_argument_list_create (void *ctx)
+{
+	argument_list_t *list;
+
+	list = talloc (ctx, argument_list_t);
+	list->head = NULL;
+	list->tail = NULL;
+
+	return list;
+}
+
+void
+_argument_list_append (argument_list_t *list, token_list_t *argument)
+{
+	argument_node_t *node;
+
+	node = talloc (list, argument_node_t);
+	node->argument = argument;
+
+	node->next = NULL;
+
+	if (list->head == NULL) {
+		list->head = node;
+	} else {
+		list->tail->next = node;
+	}
+
+	list->tail = node;
+}
+
+int
+_argument_list_length (argument_list_t *list)
+{
+	int length = 0;
+	argument_node_t *node;
+
+	if (list == NULL)
+		return 0;
+
+	for (node = list->head; node; node = node->next)
+		length++;
+
+	return length;
+}
+
+token_list_t *
+_argument_list_member_at (argument_list_t *list, int index)
+{
+	argument_node_t *node;
+	int i;
+
+	if (list == NULL)
+		return NULL;
+
+	node = list->head;
+	for (i = 0; i < index; i++) {
+		node = node->next;
+		if (node == NULL)
+			break;
+	}
+
+	if (node)
+		return node->argument;
+
+	return NULL;
+}
+
+/* Note: This function talloc_steal()s the str pointer. */
+token_t *
+_token_create_str (void *ctx, int type, char *str)
+{
+	token_t *token;
+
+	token = talloc (ctx, token_t);
+	token->type = type;
+	token->value.str = talloc_steal (token, str);
+
+	return token;
+}
+
+token_t *
+_token_create_ival (void *ctx, int type, int ival)
+{
+	token_t *token;
+
+	token = talloc (ctx, token_t);
+	token->type = type;
+	token->value.ival = ival;
+
+	return token;
+}
+
+token_list_t *
+_token_list_create (void *ctx)
+{
+	token_list_t *list;
+
+	list = talloc (ctx, token_list_t);
+	list->head = NULL;
+	list->tail = NULL;
+	list->non_space_tail = NULL;
+
+	return list;
+}
+
+void
+_token_list_append (token_list_t *list, token_t *token)
+{
+	token_node_t *node;
+
+	node = talloc (list, token_node_t);
+	node->token = talloc_steal (list, token);
+
+	node->next = NULL;
+
+	if (list->head == NULL) {
+		list->head = node;
+	} else {
+		list->tail->next = node;
+	}
+
+	list->tail = node;
+	if (token->type != SPACE)
+		list->non_space_tail = node;
+}
+
+void
+_token_list_append_list (token_list_t *list, token_list_t *tail)
+{
+	if (tail == NULL || tail->head == NULL)
+		return;
+
+	if (list->head == NULL) {
+		list->head = tail->head;
+	} else {
+		list->tail->next = tail->head;
+	}
+
+	list->tail = tail->tail;
+	list->non_space_tail = tail->non_space_tail;
+}
+
+static token_list_t *
+_token_list_copy (void *ctx, token_list_t *other)
+{
+	token_list_t *copy;
+	token_node_t *node;
+
+	if (other == NULL)
+		return NULL;
+
+	copy = _token_list_create (ctx);
+	for (node = other->head; node; node = node->next) {
+		token_t *new_token = talloc (copy, token_t);
+		*new_token = *node->token;
+		_token_list_append (copy, new_token);
+	}
+
+	return copy;
+}
+
+static void
+_token_list_trim_trailing_space (token_list_t *list)
+{
+	token_node_t *tail, *next;
+
+	if (list->non_space_tail) {
+		tail = list->non_space_tail->next;
+		list->non_space_tail->next = NULL;
+		list->tail = list->non_space_tail;
+
+		while (tail) {
+			next = tail->next;
+			talloc_free (tail);
+			tail = next;
+		}
+	}
+}
+
+int
+_token_list_is_empty_ignoring_space (token_list_t *l)
+{
+	token_node_t *n;
+
+	if (l == NULL)
+		return 1;
+
+	n = l->head;
+	while (n != NULL && n->token->type == SPACE)
+		n = n->next;
+
+	return n == NULL;
+}
+
+int
+_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b)
+{
+	token_node_t *node_a, *node_b;
+
+	if (a == NULL || b == NULL) {
+		int a_empty = _token_list_is_empty_ignoring_space(a);
+		int b_empty = _token_list_is_empty_ignoring_space(b);
+		return a_empty == b_empty;
+	}
+
+	node_a = a->head;
+	node_b = b->head;
+
+	while (1)
+	{
+		if (node_a == NULL && node_b == NULL)
+			break;
+
+		if (node_a == NULL || node_b == NULL)
+			return 0;
+
+		if (node_a->token->type == SPACE) {
+			node_a = node_a->next;
+			continue;
+		}
+
+		if (node_b->token->type == SPACE) {
+			node_b = node_b->next;
+			continue;
+		}
+
+		if (node_a->token->type != node_b->token->type)
+			return 0;
+
+		switch (node_a->token->type) {
+		case INTEGER:
+			if (node_a->token->value.ival != 
+			    node_b->token->value.ival)
+			{
+				return 0;
+			}
+			break;
+		case IDENTIFIER:
+		case INTEGER_STRING:
+		case OTHER:
+			if (strcmp (node_a->token->value.str,
+				    node_b->token->value.str))
+			{
+				return 0;
+			}
+			break;
+		}
+
+		node_a = node_a->next;
+		node_b = node_b->next;
+	}
+
+	return 1;
+}
+
+static void
+_token_print (char **out, token_t *token)
+{
+	if (token->type < 256) {
+		glcpp_printf (*out, "%c", token->type);
+		return;
+	}
+
+	switch (token->type) {
+	case INTEGER:
+		glcpp_printf (*out, "%" PRIiMAX, token->value.ival);
+		break;
+	case IDENTIFIER:
+	case INTEGER_STRING:
+	case OTHER:
+		glcpp_print (*out, token->value.str);
+		break;
+	case SPACE:
+		glcpp_print (*out, " ");
+		break;
+	case LEFT_SHIFT:
+		glcpp_print (*out, "<<");
+		break;
+	case RIGHT_SHIFT:
+		glcpp_print (*out, ">>");
+		break;
+	case LESS_OR_EQUAL:
+		glcpp_print (*out, "<=");
+		break;
+	case GREATER_OR_EQUAL:
+		glcpp_print (*out, ">=");
+		break;
+	case EQUAL:
+		glcpp_print (*out, "==");
+		break;
+	case NOT_EQUAL:
+		glcpp_print (*out, "!=");
+		break;
+	case AND:
+		glcpp_print (*out, "&&");
+		break;
+	case OR:
+		glcpp_print (*out, "||");
+		break;
+	case PASTE:
+		glcpp_print (*out, "##");
+		break;
+	case COMMA_FINAL:
+		glcpp_print (*out, ",");
+		break;
+	case PLACEHOLDER:
+		/* Nothing to print. */
+		break;
+	default:
+		assert(!"Error: Don't know how to print token.");
+		break;
+	}
+}
+
+/* Return a new token (talloc()ed off of 'token') formed by pasting
+ * 'token' and 'other'. Note that this function may return 'token' or
+ * 'other' directly rather than allocating anything new.
+ *
+ * Caution: Only very cursory error-checking is performed to see if
+ * the final result is a valid single token. */
+static token_t *
+_token_paste (glcpp_parser_t *parser, token_t *token, token_t *other)
+{
+	token_t *combined = NULL;
+
+	/* Pasting a placeholder onto anything makes no change. */
+	if (other->type == PLACEHOLDER)
+		return token;
+
+	/* When 'token' is a placeholder, just return 'other'. */
+	if (token->type == PLACEHOLDER)
+		return other;
+
+	/* A very few single-character punctuators can be combined
+	 * with another to form a multi-character punctuator. */
+	switch (token->type) {
+	case '<':
+		if (other->type == '<')
+			combined = _token_create_ival (token, LEFT_SHIFT, LEFT_SHIFT);
+		else if (other->type == '=')
+			combined = _token_create_ival (token, LESS_OR_EQUAL, LESS_OR_EQUAL);
+		break;
+	case '>':
+		if (other->type == '>')
+			combined = _token_create_ival (token, RIGHT_SHIFT, RIGHT_SHIFT);
+		else if (other->type == '=')
+			combined = _token_create_ival (token, GREATER_OR_EQUAL, GREATER_OR_EQUAL);
+		break;
+	case '=':
+		if (other->type == '=')
+			combined = _token_create_ival (token, EQUAL, EQUAL);
+		break;
+	case '!':
+		if (other->type == '=')
+			combined = _token_create_ival (token, NOT_EQUAL, NOT_EQUAL);
+		break;
+	case '&':
+		if (other->type == '&')
+			combined = _token_create_ival (token, AND, AND);
+		break;
+	case '|':
+		if (other->type == '|')
+			combined = _token_create_ival (token, OR, OR);
+		break;
+	}
+
+	if (combined != NULL) {
+		/* Inherit the location from the first token */
+		combined->location = token->location;
+		return combined;
+	}
+
+	/* Two string-valued tokens can usually just be mashed
+	 * together.
+	 *
+	 * XXX: This isn't actually legitimate. Several things here
+	 * should result in a diagnostic since the result cannot be a
+	 * valid, single pre-processing token. For example, pasting
+	 * "123" and "abc" is not legal, but we don't catch that
+	 * here. */
+	if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING) &&
+	    (other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING))
+	{
+		char *str;
+
+		str = talloc_asprintf (token, "%s%s", token->value.str,
+				       other->value.str);
+		combined = _token_create_str (token, token->type, str);
+		combined->location = token->location;
+		return combined;
+	}
+
+	glcpp_error (&token->location, parser, "");
+	glcpp_print (parser->info_log, "Pasting \"");
+	_token_print (&parser->info_log, token);
+	glcpp_print (parser->info_log, "\" and \"");
+	_token_print (&parser->info_log, other);
+	glcpp_print (parser->info_log, "\" does not give a valid preprocessing token.\n");
+
+	return token;
+}
+
+static void
+_token_list_print (glcpp_parser_t *parser, token_list_t *list)
+{
+	token_node_t *node;
+
+	if (list == NULL)
+		return;
+
+	for (node = list->head; node; node = node->next)
+		_token_print (&parser->output, node->token);
+}
+
+void
+yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
+{
+	glcpp_error(locp, parser, "%s", error);
+}
+
+static void add_builtin_define(glcpp_parser_t *parser,
+			       const char *name, int value)
+{
+   token_t *tok;
+   token_list_t *list;
+
+   tok = _token_create_ival (parser, INTEGER, value);
+
+   list = _token_list_create(parser);
+   _token_list_append(list, tok);
+   _define_object_macro(parser, NULL, name, list);
+}
+
+glcpp_parser_t *
+glcpp_parser_create (const struct gl_extensions *extensions, int api)
+{
+	glcpp_parser_t *parser;
+	int language_version;
+
+	parser = talloc (NULL, glcpp_parser_t);
+
+	glcpp_lex_init_extra (parser, &parser->scanner);
+	parser->defines = hash_table_ctor (32, hash_table_string_hash,
+					   hash_table_string_compare);
+	parser->active = NULL;
+	parser->lexing_if = 0;
+	parser->space_tokens = 1;
+	parser->newline_as_space = 0;
+	parser->in_control_line = 0;
+	parser->paren_count = 0;
+
+	parser->skip_stack = NULL;
+
+	parser->lex_from_list = NULL;
+	parser->lex_from_node = NULL;
+
+	parser->output = talloc_strdup(parser, "");
+	parser->info_log = talloc_strdup(parser, "");
+	parser->error = 0;
+
+	/* Add pre-defined macros. */
+	add_builtin_define(parser, "GL_ARB_draw_buffers", 1);
+	add_builtin_define(parser, "GL_ARB_texture_rectangle", 1);
+
+	if (api == API_OPENGLES2)
+		add_builtin_define(parser, "GL_ES", 1);
+
+	if (extensions != NULL) {
+	   if (extensions->EXT_texture_array) {
+	      add_builtin_define(parser, "GL_EXT_texture_array", 1);
+	   }
+
+	   if (extensions->ARB_fragment_coord_conventions)
+	      add_builtin_define(parser, "GL_ARB_fragment_coord_conventions",
+				 1);
+
+	   if (extensions->ARB_explicit_attrib_location)
+	      add_builtin_define(parser, "GL_ARB_explicit_attrib_location", 1);
+	   if (extensions->AMD_conservative_depth)
+	      add_builtin_define(parser, "GL_AMD_conservative_depth", 1);
+	}
+
+	language_version = 110;
+	add_builtin_define(parser, "__VERSION__", language_version);
+
+	return parser;
+}
+
+int
+glcpp_parser_parse (glcpp_parser_t *parser)
+{
+	return yyparse (parser);
+}
+
+void
+glcpp_parser_destroy (glcpp_parser_t *parser)
+{
+	glcpp_lex_destroy (parser->scanner);
+	hash_table_dtor (parser->defines);
+	talloc_free (parser);
+}
+
+typedef enum function_status
+{
+	FUNCTION_STATUS_SUCCESS,
+	FUNCTION_NOT_A_FUNCTION,
+	FUNCTION_UNBALANCED_PARENTHESES
+} function_status_t;
+
+/* Find a set of function-like macro arguments by looking for a
+ * balanced set of parentheses.
+ *
+ * When called, 'node' should be the opening-parenthesis token, (or
+ * perhaps preceeding SPACE tokens). Upon successful return *last will
+ * be the last consumed node, (corresponding to the closing right
+ * parenthesis).
+ *
+ * Return values:
+ *
+ *   FUNCTION_STATUS_SUCCESS:
+ *
+ *	Successfully parsed a set of function arguments.	
+ *
+ *   FUNCTION_NOT_A_FUNCTION:
+ *
+ *	Macro name not followed by a '('. This is not an error, but
+ *	simply that the macro name should be treated as a non-macro.
+ *
+ *   FUNCTION_UNBALANCED_PARENTHESES
+ *
+ *	Macro name is not followed by a balanced set of parentheses.
+ */
+static function_status_t
+_arguments_parse (argument_list_t *arguments,
+		  token_node_t *node,
+		  token_node_t **last)
+{
+	token_list_t *argument;
+	int paren_count;
+
+	node = node->next;
+
+	/* Ignore whitespace before first parenthesis. */
+	while (node && node->token->type == SPACE)
+		node = node->next;
+
+	if (node == NULL || node->token->type != '(')
+		return FUNCTION_NOT_A_FUNCTION;
+
+	node = node->next;
+
+	argument = _token_list_create (arguments);
+	_argument_list_append (arguments, argument);
+
+	for (paren_count = 1; node; node = node->next) {
+		if (node->token->type == '(')
+		{
+			paren_count++;
+		}
+		else if (node->token->type == ')')
+		{
+			paren_count--;
+			if (paren_count == 0)
+				break;
+		}
+
+		if (node->token->type == ',' &&
+			 paren_count == 1)
+		{
+			_token_list_trim_trailing_space (argument);
+			argument = _token_list_create (arguments);
+			_argument_list_append (arguments, argument);
+		}
+		else {
+			if (argument->head == NULL) {
+				/* Don't treat initial whitespace as
+				 * part of the arguement. */
+				if (node->token->type == SPACE)
+					continue;
+			}
+			_token_list_append (argument, node->token);
+		}
+	}
+
+	if (paren_count)
+		return FUNCTION_UNBALANCED_PARENTHESES;
+
+	*last = node;
+
+	return FUNCTION_STATUS_SUCCESS;
+}
+
+static token_list_t *
+_token_list_create_with_one_space (void *ctx)
+{
+	token_list_t *list;
+	token_t *space;
+
+	list = _token_list_create (ctx);
+	space = _token_create_ival (list, SPACE, SPACE);
+	_token_list_append (list, space);
+
+	return list;
+}
+
+static void
+_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list)
+{
+	token_list_t *expanded;
+	token_t *token;
+
+	expanded = _token_list_create (parser);
+	token = _token_create_ival (parser, type, type);
+	_token_list_append (expanded, token);
+	_glcpp_parser_expand_token_list (parser, list);
+	_token_list_append_list (expanded, list);
+	glcpp_parser_lex_from (parser, expanded);
+}
+
+/* This is a helper function that's essentially part of the
+ * implementation of _glcpp_parser_expand_node. It shouldn't be called
+ * except for by that function.
+ *
+ * Returns NULL if node is a simple token with no expansion, (that is,
+ * although 'node' corresponds to an identifier defined as a
+ * function-like macro, it is not followed with a parenthesized
+ * argument list).
+ *
+ * Compute the complete expansion of node (which is a function-like
+ * macro) and subsequent nodes which are arguments.
+ *
+ * Returns the token list that results from the expansion and sets
+ * *last to the last node in the list that was consumed by the
+ * expansion. Specifically, *last will be set as follows: as the
+ * token of the closing right parenthesis.
+ */
+static token_list_t *
+_glcpp_parser_expand_function (glcpp_parser_t *parser,
+			       token_node_t *node,
+			       token_node_t **last)
+			       
+{
+	macro_t *macro;
+	const char *identifier;
+	argument_list_t *arguments;
+	function_status_t status;
+	token_list_t *substituted;
+	int parameter_index;
+
+	identifier = node->token->value.str;
+
+	macro = hash_table_find (parser->defines, identifier);
+
+	assert (macro->is_function);
+
+	arguments = _argument_list_create (parser);
+	status = _arguments_parse (arguments, node, last);
+
+	switch (status) {
+	case FUNCTION_STATUS_SUCCESS:
+		break;
+	case FUNCTION_NOT_A_FUNCTION:
+		return NULL;
+	case FUNCTION_UNBALANCED_PARENTHESES:
+		glcpp_error (&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identifier);
+		return NULL;
+	}
+
+	/* Replace a macro defined as empty with a SPACE token. */
+	if (macro->replacements == NULL) {
+		talloc_free (arguments);
+		return _token_list_create_with_one_space (parser);
+	}
+
+	if (! ((_argument_list_length (arguments) == 
+		_string_list_length (macro->parameters)) ||
+	       (_string_list_length (macro->parameters) == 0 &&
+		_argument_list_length (arguments) == 1 &&
+		arguments->head->argument->head == NULL)))
+	{
+		glcpp_error (&node->token->location, parser,
+			      "Error: macro %s invoked with %d arguments (expected %d)\n",
+			      identifier,
+			      _argument_list_length (arguments),
+			      _string_list_length (macro->parameters));
+		return NULL;
+	}
+
+	/* Perform argument substitution on the replacement list. */
+	substituted = _token_list_create (arguments);
+
+	for (node = macro->replacements->head; node; node = node->next)
+	{
+		if (node->token->type == IDENTIFIER &&
+		    _string_list_contains (macro->parameters,
+					   node->token->value.str,
+					   &parameter_index))
+		{
+			token_list_t *argument;
+			argument = _argument_list_member_at (arguments,
+							     parameter_index);
+			/* Before substituting, we expand the argument
+			 * tokens, or append a placeholder token for
+			 * an empty argument. */
+			if (argument->head) {
+				token_list_t *expanded_argument;
+				expanded_argument = _token_list_copy (parser,
+								      argument);
+				_glcpp_parser_expand_token_list (parser,
+								 expanded_argument);
+				_token_list_append_list (substituted,
+							 expanded_argument);
+			} else {
+				token_t *new_token;
+
+				new_token = _token_create_ival (substituted,
+								PLACEHOLDER,
+								PLACEHOLDER);
+				_token_list_append (substituted, new_token);
+			}
+		} else {
+			_token_list_append (substituted, node->token);
+		}
+	}
+
+	/* After argument substitution, and before further expansion
+	 * below, implement token pasting. */
+
+	_token_list_trim_trailing_space (substituted);
+
+	node = substituted->head;
+	while (node)
+	{
+		token_node_t *next_non_space;
+
+		/* Look ahead for a PASTE token, skipping space. */
+		next_non_space = node->next;
+		while (next_non_space && next_non_space->token->type == SPACE)
+			next_non_space = next_non_space->next;
+
+		if (next_non_space == NULL)
+			break;
+
+		if (next_non_space->token->type != PASTE) {
+			node = next_non_space;
+			continue;
+		}
+
+		/* Now find the next non-space token after the PASTE. */
+		next_non_space = next_non_space->next;
+		while (next_non_space && next_non_space->token->type == SPACE)
+			next_non_space = next_non_space->next;
+
+		if (next_non_space == NULL) {
+			yyerror (&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n");
+			return NULL;
+		}
+
+		node->token = _token_paste (parser, node->token, next_non_space->token);
+		node->next = next_non_space->next;
+		if (next_non_space == substituted->tail)
+			substituted->tail = node;
+
+		node = node->next;
+	}
+
+	substituted->non_space_tail = substituted->tail;
+
+	return substituted;
+}
+
+/* Compute the complete expansion of node, (and subsequent nodes after
+ * 'node' in the case that 'node' is a function-like macro and
+ * subsequent nodes are arguments).
+ *
+ * Returns NULL if node is a simple token with no expansion.
+ *
+ * Otherwise, returns the token list that results from the expansion
+ * and sets *last to the last node in the list that was consumed by
+ * the expansion. Specifically, *last will be set as follows:
+ *
+ *	As 'node' in the case of object-like macro expansion.
+ *
+ *	As the token of the closing right parenthesis in the case of
+ *	function-like macro expansion.
+ */
+static token_list_t *
+_glcpp_parser_expand_node (glcpp_parser_t *parser,
+			   token_node_t *node,
+			   token_node_t **last)
+{
+	token_t *token = node->token;
+	const char *identifier;
+	macro_t *macro;
+
+	/* We only expand identifiers */
+	if (token->type != IDENTIFIER) {
+		/* We change any COMMA into a COMMA_FINAL to prevent
+		 * it being mistaken for an argument separator
+		 * later. */
+		if (token->type == ',') {
+			token->type = COMMA_FINAL;
+			token->value.ival = COMMA_FINAL;
+		}
+
+		return NULL;
+	}
+
+	/* Look up this identifier in the hash table. */
+	identifier = token->value.str;
+	macro = hash_table_find (parser->defines, identifier);
+
+	/* Not a macro, so no expansion needed. */
+	if (macro == NULL)
+		return NULL;
+
+	/* Finally, don't expand this macro if we're already actively
+	 * expanding it, (to avoid infinite recursion). */
+	if (_active_list_contains (parser->active, identifier)) {
+		/* We change the token type here from IDENTIFIER to
+		 * OTHER to prevent any future expansion of this
+		 * unexpanded token. */
+		char *str;
+		token_list_t *expansion;
+		token_t *final;
+
+		str = talloc_strdup (parser, token->value.str);
+		final = _token_create_str (parser, OTHER, str);
+		expansion = _token_list_create (parser);
+		_token_list_append (expansion, final);
+		*last = node;
+		return expansion;
+	}
+
+	if (! macro->is_function)
+	{
+		*last = node;
+
+		/* Replace a macro defined as empty with a SPACE token. */
+		if (macro->replacements == NULL)
+			return _token_list_create_with_one_space (parser);
+
+		return _token_list_copy (parser, macro->replacements);
+	}
+
+	return _glcpp_parser_expand_function (parser, node, last);
+}
+
+/* Push a new identifier onto the active list, returning the new list.
+ *
+ * Here, 'marker' is the token node that appears in the list after the
+ * expansion of 'identifier'. That is, when the list iterator begins
+ * examinging 'marker', then it is time to pop this node from the
+ * active stack.
+ */
+active_list_t *
+_active_list_push (active_list_t *list,
+		   const char *identifier,
+		   token_node_t *marker)
+{
+	active_list_t *node;
+
+	node = talloc (list, active_list_t);
+	node->identifier = talloc_strdup (node, identifier);
+	node->marker = marker;
+	node->next = list;
+
+	return node;
+}
+
+active_list_t *
+_active_list_pop (active_list_t *list)
+{
+	active_list_t *node = list;
+
+	if (node == NULL)
+		return NULL;
+
+	node = list->next;
+	talloc_free (list);
+
+	return node;
+}
+
+int
+_active_list_contains (active_list_t *list, const char *identifier)
+{
+	active_list_t *node;
+
+	if (list == NULL)
+		return 0;
+
+	for (node = list; node; node = node->next)
+		if (strcmp (node->identifier, identifier) == 0)
+			return 1;
+
+	return 0;
+}
+
+/* Walk over the token list replacing nodes with their expansion.
+ * Whenever nodes are expanded the walking will walk over the new
+ * nodes, continuing to expand as necessary. The results are placed in
+ * 'list' itself;
+ */
+static void
+_glcpp_parser_expand_token_list (glcpp_parser_t *parser,
+				 token_list_t *list)
+{
+	token_node_t *node_prev;
+	token_node_t *node, *last = NULL;
+	token_list_t *expansion;
+
+	if (list == NULL)
+		return;
+
+	_token_list_trim_trailing_space (list);
+
+	node_prev = NULL;
+	node = list->head;
+
+	while (node) {
+
+		while (parser->active && parser->active->marker == node)
+			parser->active = _active_list_pop (parser->active);
+
+		/* Find the expansion for node, which will replace all
+		 * nodes from node to last, inclusive. */
+		expansion = _glcpp_parser_expand_node (parser, node, &last);
+		if (expansion) {
+			token_node_t *n;
+
+			for (n = node; n != last->next; n = n->next)
+				while (parser->active &&
+				       parser->active->marker == n)
+				{
+					parser->active = _active_list_pop (parser->active);
+				}
+
+			parser->active = _active_list_push (parser->active,
+							    node->token->value.str,
+							    last->next);
+			
+			/* Splice expansion into list, supporting a
+			 * simple deletion if the expansion is
+			 * empty. */
+			if (expansion->head) {
+				if (node_prev)
+					node_prev->next = expansion->head;
+				else
+					list->head = expansion->head;
+				expansion->tail->next = last->next;
+				if (last == list->tail)
+					list->tail = expansion->tail;
+			} else {
+				if (node_prev)
+					node_prev->next = last->next;
+				else
+					list->head = last->next;
+				if (last == list->tail)
+					list->tail = NULL;
+			}
+		} else {
+			node_prev = node;
+		}
+		node = node_prev ? node_prev->next : list->head;
+	}
+
+	while (parser->active)
+		parser->active = _active_list_pop (parser->active);
+
+	list->non_space_tail = list->tail;
+}
+
+void
+_glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
+					 token_list_t *list)
+{
+	if (list == NULL)
+		return;
+
+	_glcpp_parser_expand_token_list (parser, list);
+
+	_token_list_trim_trailing_space (list);
+
+	_token_list_print (parser, list);
+}
+
+static void
+_check_for_reserved_macro_name (glcpp_parser_t *parser, YYLTYPE *loc,
+				const char *identifier)
+{
+	/* According to the GLSL specification, macro names starting with "__"
+	 * or "GL_" are reserved for future use.  So, don't allow them.
+	 */
+	if (strncmp(identifier, "__", 2) == 0) {
+		glcpp_error (loc, parser, "Macro names starting with \"__\" are reserved.\n");
+	}
+	if (strncmp(identifier, "GL_", 3) == 0) {
+		glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n");
+	}
+}
+
+static int
+_macro_equal (macro_t *a, macro_t *b)
+{
+	if (a->is_function != b->is_function)
+		return 0;
+
+	if (a->is_function) {
+		if (! _string_list_equal (a->parameters, b->parameters))
+			return 0;
+	}
+
+	return _token_list_equal_ignoring_space (a->replacements,
+						 b->replacements);
+}
+
+void
+_define_object_macro (glcpp_parser_t *parser,
+		      YYLTYPE *loc,
+		      const char *identifier,
+		      token_list_t *replacements)
+{
+	macro_t *macro, *previous;
+
+	if (loc != NULL)
+		_check_for_reserved_macro_name(parser, loc, identifier);
+
+	macro = talloc (parser, macro_t);
+
+	macro->is_function = 0;
+	macro->parameters = NULL;
+	macro->identifier = talloc_strdup (macro, identifier);
+	macro->replacements = talloc_steal (macro, replacements);
+
+	previous = hash_table_find (parser->defines, identifier);
+	if (previous) {
+		if (_macro_equal (macro, previous)) {
+			talloc_free (macro);
+			return;
+		}
+		glcpp_error (loc, parser, "Redefinition of macro %s\n",
+			     identifier);
+	}
+
+	hash_table_insert (parser->defines, macro, identifier);
+}
+
+void
+_define_function_macro (glcpp_parser_t *parser,
+			YYLTYPE *loc,
+			const char *identifier,
+			string_list_t *parameters,
+			token_list_t *replacements)
+{
+	macro_t *macro, *previous;
+
+	_check_for_reserved_macro_name(parser, loc, identifier);
+
+	macro = talloc (parser, macro_t);
+
+	macro->is_function = 1;
+	macro->parameters = talloc_steal (macro, parameters);
+	macro->identifier = talloc_strdup (macro, identifier);
+	macro->replacements = talloc_steal (macro, replacements);
+
+	previous = hash_table_find (parser->defines, identifier);
+	if (previous) {
+		if (_macro_equal (macro, previous)) {
+			talloc_free (macro);
+			return;
+		}
+		glcpp_error (loc, parser, "Redefinition of macro %s\n",
+			     identifier);
+	}
+
+	hash_table_insert (parser->defines, macro, identifier);
+}
+
+static int
+glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
+{
+	token_node_t *node;
+	int ret;
+
+	if (parser->lex_from_list == NULL) {
+		ret = glcpp_lex (yylval, yylloc, parser->scanner);
+
+		/* XXX: This ugly block of code exists for the sole
+		 * purpose of converting a NEWLINE token into a SPACE
+		 * token, but only in the case where we have seen a
+		 * function-like macro name, but have not yet seen its
+		 * closing parenthesis.
+		 *
+		 * There's perhaps a more compact way to do this with
+		 * mid-rule actions in the grammar.
+		 *
+		 * I'm definitely not pleased with the complexity of
+		 * this code here.
+		 */
+		if (parser->newline_as_space)
+		{
+			if (ret == '(') {
+				parser->paren_count++;
+			} else if (ret == ')') {
+				parser->paren_count--;
+				if (parser->paren_count == 0)
+					parser->newline_as_space = 0;
+			} else if (ret == NEWLINE) {
+				ret = SPACE;
+			} else if (ret != SPACE) {
+				if (parser->paren_count == 0)
+					parser->newline_as_space = 0;
+			}
+		}
+		else if (parser->in_control_line)
+		{
+			if (ret == NEWLINE)
+				parser->in_control_line = 0;
+		}
+		else if (ret == HASH_DEFINE_OBJ || ret == HASH_DEFINE_FUNC ||
+			   ret == HASH_UNDEF || ret == HASH_IF ||
+			   ret == HASH_IFDEF || ret == HASH_IFNDEF ||
+			   ret == HASH_ELIF || ret == HASH_ELSE ||
+			   ret == HASH_ENDIF || ret == HASH)
+		{
+			parser->in_control_line = 1;
+		}
+		else if (ret == IDENTIFIER)
+		{
+			macro_t *macro;
+			macro = hash_table_find (parser->defines,
+						 yylval->str);
+			if (macro && macro->is_function) {
+				parser->newline_as_space = 1;
+				parser->paren_count = 0;
+			}
+		}
+
+		return ret;
+	}
+
+	node = parser->lex_from_node;
+
+	if (node == NULL) {
+		talloc_free (parser->lex_from_list);
+		parser->lex_from_list = NULL;
+		return NEWLINE;
+	}
+
+	*yylval = node->token->value;
+	ret = node->token->type;
+
+	parser->lex_from_node = node->next;
+
+	return ret;
+}
+
+static void
+glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list)
+{
+	token_node_t *node;
+
+	assert (parser->lex_from_list == NULL);
+
+	/* Copy list, eliminating any space tokens. */
+	parser->lex_from_list = _token_list_create (parser);
+
+	for (node = list->head; node; node = node->next) {
+		if (node->token->type == SPACE)
+			continue;
+		_token_list_append (parser->lex_from_list, node->token);
+	}
+
+	talloc_free (list);
+
+	parser->lex_from_node = parser->lex_from_list->head;
+
+	/* It's possible the list consisted of nothing but whitespace. */
+	if (parser->lex_from_node == NULL) {
+		talloc_free (parser->lex_from_list);
+		parser->lex_from_list = NULL;
+	}
+}
+
+static void
+_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
+				  int condition)
+{
+	skip_type_t current = SKIP_NO_SKIP;
+	skip_node_t *node;
+
+	if (parser->skip_stack)
+		current = parser->skip_stack->type;
+
+	node = talloc (parser, skip_node_t);
+	node->loc = *loc;
+
+	if (current == SKIP_NO_SKIP) {
+		if (condition)
+			node->type = SKIP_NO_SKIP;
+		else
+			node->type = SKIP_TO_ELSE;
+	} else {
+		node->type = SKIP_TO_ENDIF;
+	}
+
+	node->next = parser->skip_stack;
+	parser->skip_stack = node;
+}
+
+static void
+_glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
+				    const char *type, int condition)
+{
+	if (parser->skip_stack == NULL) {
+		glcpp_error (loc, parser, "%s without #if\n", type);
+		return;
+	}
+
+	if (parser->skip_stack->type == SKIP_TO_ELSE) {
+		if (condition)
+			parser->skip_stack->type = SKIP_NO_SKIP;
+	} else {
+		parser->skip_stack->type = SKIP_TO_ENDIF;
+	}
+}
+
+static void
+_glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc)
+{
+	skip_node_t *node;
+
+	if (parser->skip_stack == NULL) {
+		glcpp_error (loc, parser, "#endif without #if\n");
+		return;
+	}
+
+	node = parser->skip_stack;
+	parser->skip_stack = node->next;
+	talloc_free (node);
+}
diff --git a/mesalib/src/mapi/glapi/Makefile b/mesalib/src/mapi/glapi/Makefile
index 203a8abd0..9f1d42f88 100644
--- a/mesalib/src/mapi/glapi/Makefile
+++ b/mesalib/src/mapi/glapi/Makefile
@@ -1,67 +1,77 @@
-# src/mapi/glapi/Makefile
-
-TOP = ../../..
-include $(TOP)/configs/current
-
-TARGET = glapi
-
-MAPI = $(TOP)/src/mapi/mapi
-
-include sources.mak
-include $(MAPI)/sources.mak
-
-glapi_CPPFLAGS := \
-	-I$(TOP)/include \
-	-I$(TOP)/src/mapi \
-	-I$(TOP)/src/mesa \
-	-DMAPI_ABI_HEADER=\"glapi/glapi_mapi_tmp.h\"
-
-ifeq ($(SHARED_GLAPI),1)
-glapi_CPPFLAGS += -DMAPI_MODE_BRIDGE
-glapi_SOURCES := $(addprefix $(MAPI)/, $(MAPI_BRIDGE_SOURCES))
-
-glapi_GLAPI_OBJECTS :=
-glapi_ASM_OBJECTS :=
-glapi_MAPI_OBJECTS := $(MAPI_BRIDGE_SOURCES:.c=.o)
-else
-glapi_CPPFLAGS += -DMAPI_MODE_UTIL
-glapi_SOURCES := $(GLAPI_SOURCES) $(addprefix $(MAPI)/, $(MAPI_UTIL_SOURCES))
-
-glapi_GLAPI_OBJECTS := $(GLAPI_SOURCES:.c=.o)
-glapi_ASM_OBJECTS := $(GLAPI_ASM_SOURCES:.S=.o)
-glapi_MAPI_OBJECTS := $(MAPI_UTIL_SOURCES:.c=.o)
-endif # SHARED_GLAPI
-
-glapi_OBJECTS := \
-	$(glapi_GLAPI_OBJECTS) \
-	$(glapi_ASM_OBJECTS) \
-	$(glapi_MAPI_OBJECTS)
-
-default: depend lib$(TARGET).a
-
-lib$(TARGET).a: $(glapi_OBJECTS)
-	@$(MKLIB) -o $(TARGET) -static $(glapi_OBJECTS)
-
-$(glapi_GLAPI_OBJECTS): %.o: %.c
-	$(CC) -c $(glapi_CPPFLAGS) $(CFLAGS) $< -o $@
-
-$(glapi_ASM_OBJECTS): %.o: %.S
-	$(CC) -c $(glapi_CPPFLAGS) $(CFLAGS) $< -o $@
-
-$(glapi_MAPI_OBJECTS): %.o: $(MAPI)/%.c
-	$(CC) -c $(glapi_CPPFLAGS) $(CFLAGS) $< -o $@
-
-install:
-
-clean:
-	-rm -f $(glapi_OBJECTS)
-	-rm -f lib$(TARGET).a
-	-rm -f depend depend.bak
-
-depend: $(glapi_SOURCES)
-	@ echo "running $(MKDEP)"
-	@ touch depend
-	@$(MKDEP) $(MKDEP_OPTIONS) -f- $(DEFINES) $(glapi_CPPFLAGS) \
-		$(glapi_SOURCES) 2>/dev/null | sed -e 's,^$(MAPI)/,,' > depend
-
--include depend
+# src/mapi/glapi/Makefile
+
+TOP = ../../..
+include $(TOP)/configs/current
+
+TARGET = glapi
+
+MAPI = $(TOP)/src/mapi/mapi
+
+include sources.mak
+include $(MAPI)/sources.mak
+
+glapi_CPPFLAGS := \
+	-I$(TOP)/include \
+	-I$(TOP)/src/mapi \
+	-I$(TOP)/src/mesa
+
+ifeq ($(SHARED_GLAPI),1)
+glapi_CPPFLAGS += \
+	-DMAPI_MODE_BRIDGE \
+	-DMAPI_ABI_HEADER=\"glapi/glapi_mapi_tmp.h\"
+glapi_SOURCES := $(addprefix $(MAPI)/, $(MAPI_BRIDGE_SOURCES))
+
+glapi_GLAPI_OBJECTS :=
+glapi_ASM_OBJECTS :=
+glapi_MAPI_OBJECTS := $(MAPI_BRIDGE_SOURCES:.c=.o)
+else
+glapi_CPPFLAGS += -DMAPI_MODE_UTIL
+glapi_SOURCES := $(GLAPI_SOURCES) $(addprefix $(MAPI)/, $(MAPI_UTIL_SOURCES))
+
+glapi_GLAPI_OBJECTS := $(GLAPI_SOURCES:.c=.o)
+glapi_ASM_OBJECTS := $(GLAPI_ASM_SOURCES:.S=.o)
+glapi_MAPI_OBJECTS := $(MAPI_UTIL_SOURCES:.c=.o)
+endif # SHARED_GLAPI
+
+glapi_OBJECTS := \
+	$(glapi_GLAPI_OBJECTS) \
+	$(glapi_ASM_OBJECTS) \
+	$(glapi_MAPI_OBJECTS)
+
+default: depend lib$(TARGET).a
+
+lib$(TARGET).a: $(glapi_OBJECTS)
+	@$(MKLIB) -o $(TARGET) -static $(glapi_OBJECTS)
+
+$(glapi_GLAPI_OBJECTS): %.o: %.c
+	$(CC) -c $(glapi_CPPFLAGS) $(CFLAGS) $< -o $@
+
+$(glapi_ASM_OBJECTS): %.o: %.S
+	$(CC) -c $(glapi_CPPFLAGS) $(CFLAGS) $< -o $@
+
+$(glapi_MAPI_OBJECTS): %.o: $(MAPI)/%.c
+	$(CC) -c $(glapi_CPPFLAGS) $(CFLAGS) $< -o $@
+
+install:
+
+clean:
+	-rm -f $(glapi_OBJECTS)
+	-rm -f lib$(TARGET).a
+	-rm -f depend depend.bak
+
+ifeq ($(SHARED_GLAPI),1)
+# workaround a bug in makedepend
+makedepend_CPPFLAGS := \
+	$(filter-out -DMAPI_ABI_HEADER=%, $(glapi_CPPFLAGS))
+$(glapi_OBJECTS): glapi_mapi_tmp.h
+else
+makedepend_CPPFLAGS := $(glapi_CPPFLAGS)
+endif
+
+depend: $(glapi_SOURCES)
+	@ echo "running $(MKDEP)"
+	@ touch depend
+	@$(MKDEP) $(MKDEP_OPTIONS) -f- $(DEFINES) $(makedepend_CPPFLAGS) \
+		$(glapi_SOURCES) 2>/dev/null | sed -e 's,^$(MAPI)/,,' > depend
+
+-include depend
diff --git a/mesalib/src/mesa/main/extensions.c b/mesalib/src/mesa/main/extensions.c
index aaef337ac..9f58b45e2 100644
--- a/mesalib/src/mesa/main/extensions.c
+++ b/mesalib/src/mesa/main/extensions.c
@@ -1,915 +1,915 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.6
- *
- * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
- * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * \file
- * \brief Extension handling
- */
-
-
-#include "glheader.h"
-#include "imports.h"
-#include "context.h"
-#include "extensions.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-
-enum {
-   DISABLE = 0,
-   GL  = 1 << API_OPENGL,
-   ES1 = 1 << API_OPENGLES,
-   ES2 = 1 << API_OPENGLES2,
-};
-
-/**
- * \brief An element of the \c extension_table.
- */
-struct extension {
-   /** Name of extension, such as "GL_ARB_depth_clamp". */
-   const char *name;
-
-   /** Offset (in bytes) of the corresponding member in struct gl_extensions. */
-   size_t offset;
-
-   /** Set of API's in which the extension exists, as a bitset. */
-   uint8_t api_set;
-};
-
-
-/**
- * Given a member \c x of struct gl_extensions, return offset of
- * \c x in bytes.
- */
-#define o(x) offsetof(struct gl_extensions, x)
-
-
-/**
- * \brief Table of supported OpenGL extensions for all API's.
- *
- * Note: The GL_MESAX_* extensions are placeholders for future ARB extensions.
- */
-static const struct extension extension_table[] = {
-   /* ARB Extensions */
-   { "GL_ARB_ES2_compatibility",                   o(ARB_ES2_compatibility),                   GL             },
-   { "GL_ARB_blend_func_extended",                 o(ARB_blend_func_extended),                 GL             },
-   { "GL_ARB_copy_buffer",                         o(ARB_copy_buffer),                         GL             },
-   { "GL_ARB_depth_buffer_float",                  o(ARB_depth_buffer_float),                  GL             },
-   { "GL_ARB_depth_clamp",                         o(ARB_depth_clamp),                         GL             },
-   { "GL_ARB_depth_texture",                       o(ARB_depth_texture),                       GL             },
-   { "GL_ARB_draw_buffers",                        o(ARB_draw_buffers),                        GL             },
-   { "GL_ARB_draw_buffers_blend",                  o(ARB_draw_buffers_blend),                  GL             },
-   { "GL_ARB_draw_elements_base_vertex",           o(ARB_draw_elements_base_vertex),           GL             },
-   { "GL_ARB_draw_instanced",                      o(ARB_draw_instanced),                      GL             },
-   { "GL_ARB_explicit_attrib_location",            o(ARB_explicit_attrib_location),            GL             },
-   { "GL_ARB_fragment_coord_conventions",          o(ARB_fragment_coord_conventions),          GL             },
-   { "GL_ARB_fragment_program",                    o(ARB_fragment_program),                    GL             },
-   { "GL_ARB_fragment_program_shadow",             o(ARB_fragment_program_shadow),             GL             },
-   { "GL_ARB_fragment_shader",                     o(ARB_fragment_shader),                     GL             },
-   { "GL_ARB_framebuffer_object",                  o(ARB_framebuffer_object),                  GL             },
-   { "GL_ARB_framebuffer_sRGB",                    o(EXT_framebuffer_sRGB),                    GL             },
-   { "GL_ARB_half_float_pixel",                    o(ARB_half_float_pixel),                    GL             },
-   { "GL_ARB_half_float_vertex",                   o(ARB_half_float_vertex),                   GL             },
-   { "GL_ARB_instanced_arrays",                    o(ARB_instanced_arrays),                    GL             },
-   { "GL_ARB_map_buffer_range",                    o(ARB_map_buffer_range),                    GL             },
-   { "GL_ARB_multisample",                         o(ARB_multisample),                         GL             },
-   { "GL_ARB_multitexture",                        o(ARB_multitexture),                        GL             },
-   { "GL_ARB_occlusion_query2",                    o(ARB_occlusion_query2),                    GL             },
-   { "GL_ARB_occlusion_query",                     o(ARB_occlusion_query),                     GL             },
-   { "GL_ARB_pixel_buffer_object",                 o(EXT_pixel_buffer_object),                 GL             },
-   { "GL_ARB_point_parameters",                    o(EXT_point_parameters),                    GL             },
-   { "GL_ARB_point_sprite",                        o(ARB_point_sprite),                        GL             },
-   { "GL_ARB_provoking_vertex",                    o(EXT_provoking_vertex),                    GL             },
-   { "GL_ARB_sampler_objects",                     o(ARB_sampler_objects),                     GL             },
-   { "GL_ARB_seamless_cube_map",                   o(ARB_seamless_cube_map),                   GL             },
-   { "GL_ARB_shader_objects",                      o(ARB_shader_objects),                      GL             },
-   { "GL_ARB_shader_stencil_export",               o(ARB_shader_stencil_export),               GL             },
-   { "GL_ARB_shading_language_100",                o(ARB_shading_language_100),                GL             },
-   { "GL_ARB_shadow_ambient",                      o(ARB_shadow_ambient),                      GL             },
-   { "GL_ARB_shadow",                              o(ARB_shadow),                              GL             },
-   { "GL_ARB_sync",                                o(ARB_sync),                                GL             },
-   { "GL_ARB_texture_border_clamp",                o(ARB_texture_border_clamp),                GL             },
-   { "GL_ARB_texture_buffer_object",               o(ARB_texture_buffer_object),               GL             },
-   { "GL_ARB_texture_compression",                 o(ARB_texture_compression),                 GL             },
-   { "GL_ARB_texture_compression_rgtc",            o(ARB_texture_compression_rgtc),            GL             },
-   { "GL_ARB_texture_cube_map",                    o(ARB_texture_cube_map),                    GL             },
-   { "GL_ARB_texture_env_add",                     o(EXT_texture_env_add),                     GL             },
-   { "GL_ARB_texture_env_combine",                 o(ARB_texture_env_combine),                 GL             },
-   { "GL_ARB_texture_env_crossbar",                o(ARB_texture_env_crossbar),                GL             },
-   { "GL_ARB_texture_env_dot3",                    o(ARB_texture_env_dot3),                    GL             },
-   { "GL_ARB_texture_mirrored_repeat",             o(ARB_texture_mirrored_repeat),             GL             },
-   { "GL_ARB_texture_multisample",                 o(ARB_texture_multisample),                 GL             },
-   { "GL_ARB_texture_non_power_of_two",            o(ARB_texture_non_power_of_two),            GL             },
-   { "GL_ARB_texture_rectangle",                   o(NV_texture_rectangle),                    GL             },
-   { "GL_ARB_texture_rgb10_a2ui",                  o(ARB_texture_rgb10_a2ui),                  GL             },
-   { "GL_ARB_texture_rg",                          o(ARB_texture_rg),                          GL             },
-   { "GL_ARB_texture_swizzle",                     o(EXT_texture_swizzle),                     GL             },
-   { "GL_ARB_transform_feedback2",                 o(ARB_transform_feedback2),                 GL             },
-   { "GL_ARB_transpose_matrix",                    o(ARB_transpose_matrix),                    GL             },
-   { "GL_ARB_uniform_buffer_object",               o(ARB_uniform_buffer_object),               GL             },
-   { "GL_ARB_vertex_array_bgra",                   o(EXT_vertex_array_bgra),                   GL             },
-   { "GL_ARB_vertex_array_object",                 o(ARB_vertex_array_object),                 GL             },
-   { "GL_ARB_vertex_buffer_object",                o(ARB_vertex_buffer_object),                GL             },
-   { "GL_ARB_vertex_program",                      o(ARB_vertex_program),                      GL             },
-   { "GL_ARB_vertex_shader",                       o(ARB_vertex_shader),                       GL             },
-   { "GL_ARB_vertex_type_2_10_10_10_rev",          o(ARB_vertex_type_2_10_10_10_rev),          GL             },
-   { "GL_ARB_window_pos",                          o(ARB_window_pos),                          GL             },
-
-   /* EXT extensions */
-   { "GL_EXT_abgr",                                o(EXT_abgr),                                GL             },
-   { "GL_EXT_bgra",                                o(EXT_bgra),                                GL             },
-   { "GL_EXT_blend_color",                         o(EXT_blend_color),                         GL             },
-   { "GL_EXT_blend_equation_separate",             o(EXT_blend_equation_separate),             GL             },
-   { "GL_EXT_blend_func_separate",                 o(EXT_blend_func_separate),                 GL             },
-   { "GL_EXT_blend_logic_op",                      o(EXT_blend_logic_op),                      GL             },
-   { "GL_EXT_blend_minmax",                        o(EXT_blend_minmax),                        GL | ES1 | ES2 },
-   { "GL_EXT_blend_subtract",                      o(EXT_blend_subtract),                      GL             },
-   { "GL_EXT_clip_volume_hint",                    o(EXT_clip_volume_hint),                    GL             },
-   { "GL_EXT_compiled_vertex_array",               o(EXT_compiled_vertex_array),               GL             },
-   { "GL_EXT_copy_texture",                        o(EXT_copy_texture),                        GL             },
-   { "GL_EXT_depth_bounds_test",                   o(EXT_depth_bounds_test),                   GL             },
-   { "GL_EXT_draw_buffers2",                       o(EXT_draw_buffers2),                       GL             },
-   { "GL_EXT_draw_instanced",                      o(ARB_draw_instanced),                      GL             },
-   { "GL_EXT_draw_range_elements",                 o(EXT_draw_range_elements),                 GL             },
-   { "GL_EXT_fog_coord",                           o(EXT_fog_coord),                           GL             },
-   { "GL_EXT_framebuffer_blit",                    o(EXT_framebuffer_blit),                    GL             },
-   { "GL_EXT_framebuffer_multisample",             o(EXT_framebuffer_multisample),             GL             },
-   { "GL_EXT_framebuffer_object",                  o(EXT_framebuffer_object),                  GL             },
-   { "GL_EXT_framebuffer_sRGB",                    o(EXT_framebuffer_sRGB),                    GL             },
-   { "GL_EXT_gpu_program_parameters",              o(EXT_gpu_program_parameters),              GL             },
-   { "GL_EXT_gpu_shader4",                         o(EXT_gpu_shader4),                         GL             },
-   { "GL_EXT_multi_draw_arrays",                   o(EXT_multi_draw_arrays),                   GL | ES1 | ES2 },
-   { "GL_EXT_packed_depth_stencil",                o(EXT_packed_depth_stencil),                GL             },
-   { "GL_EXT_packed_float",                        o(EXT_packed_float),                        GL             },
-   { "GL_EXT_packed_pixels",                       o(EXT_packed_pixels),                       GL             },
-   { "GL_EXT_paletted_texture",                    o(EXT_paletted_texture),                    GL             },
-   { "GL_EXT_pixel_buffer_object",                 o(EXT_pixel_buffer_object),                 GL             },
-   { "GL_EXT_point_parameters",                    o(EXT_point_parameters),                    GL             },
-   { "GL_EXT_polygon_offset",                      o(EXT_polygon_offset),                      GL             },
-   { "GL_EXT_provoking_vertex",                    o(EXT_provoking_vertex),                    GL             },
-   { "GL_EXT_rescale_normal",                      o(EXT_rescale_normal),                      GL             },
-   { "GL_EXT_secondary_color",                     o(EXT_secondary_color),                     GL             },
-   { "GL_EXT_separate_shader_objects",             o(EXT_separate_shader_objects),             GL             },
-   { "GL_EXT_separate_specular_color",             o(EXT_separate_specular_color),             GL             },
-   { "GL_EXT_shadow_funcs",                        o(EXT_shadow_funcs),                        GL             },
-   { "GL_EXT_shared_texture_palette",              o(EXT_shared_texture_palette),              GL             },
-   { "GL_EXT_stencil_two_side",                    o(EXT_stencil_two_side),                    GL             },
-   { "GL_EXT_stencil_wrap",                        o(EXT_stencil_wrap),                        GL             },
-   { "GL_EXT_subtexture",                          o(EXT_subtexture),                          GL             },
-   { "GL_EXT_texture3D",                           o(EXT_texture3D),                           GL             },
-   { "GL_EXT_texture_array",                       o(EXT_texture_array),                       GL             },
-   { "GL_EXT_texture_compression_dxt1",            o(EXT_texture_compression_s3tc),            GL | ES1 | ES2 },
-   { "GL_EXT_texture_compression_rgtc",            o(ARB_texture_compression_rgtc),            GL             },
-   { "GL_EXT_texture_compression_s3tc",            o(EXT_texture_compression_s3tc),            GL             },
-   { "GL_EXT_texture_cube_map",                    o(ARB_texture_cube_map),                    GL             },
-   { "GL_EXT_texture_edge_clamp",                  o(SGIS_texture_edge_clamp),                 GL             },
-   { "GL_EXT_texture_env_add",                     o(EXT_texture_env_add),                     GL             },
-   { "GL_EXT_texture_env_combine",                 o(EXT_texture_env_combine),                 GL             },
-   { "GL_EXT_texture_env_dot3",                    o(EXT_texture_env_dot3),                    GL             },
-   { "GL_EXT_texture_filter_anisotropic",          o(EXT_texture_filter_anisotropic),          GL | ES1 | ES2 },
-   { "GL_EXT_texture_format_BGRA8888",             o(EXT_texture_format_BGRA8888),                  ES1 | ES2 },
-   { "GL_EXT_texture_integer",                     o(EXT_texture_integer),                     GL             },
-   { "GL_EXT_texture_lod_bias",                    o(EXT_texture_lod_bias),                    GL | ES1       },
-   { "GL_EXT_texture_mirror_clamp",                o(EXT_texture_mirror_clamp),                GL             },
-   { "GL_EXT_texture_object",                      o(EXT_texture_object),                      GL             },
-   { "GL_EXT_texture",                             o(EXT_texture),                             GL             },
-   { "GL_EXT_texture_rectangle",                   o(NV_texture_rectangle),                    GL             },
-   { "GL_EXT_texture_shared_exponent",             o(EXT_texture_shared_exponent),             GL             },
-   { "GL_EXT_texture_sRGB",                        o(EXT_texture_sRGB),                        GL             },
-   { "GL_EXT_texture_sRGB_decode",                 o(EXT_texture_sRGB_decode),                        GL             },
-   { "GL_EXT_texture_swizzle",                     o(EXT_texture_swizzle),                     GL             },
-   { "GL_EXT_texture_type_2_10_10_10_REV",         o(dummy_true),                                         ES2 },
-   { "GL_EXT_timer_query",                         o(EXT_timer_query),                         GL             },
-   { "GL_EXT_transform_feedback",                  o(EXT_transform_feedback),                  GL             },
-   { "GL_EXT_vertex_array_bgra",                   o(EXT_vertex_array_bgra),                   GL             },
-   { "GL_EXT_vertex_array",                        o(EXT_vertex_array),                        GL             },
-   { "GL_EXT_vertex_array_set",                    o(EXT_vertex_array_set),                    GL             },
-
-   /* OES extensions */
-   { "GL_OES_blend_equation_separate",             o(EXT_blend_equation_separate),                  ES1       },
-   { "GL_OES_blend_func_separate",                 o(EXT_blend_func_separate),                      ES1       },
-   { "GL_OES_blend_subtract",                      o(EXT_blend_subtract),                           ES1       },
-   { "GL_OES_byte_coordinates",                    o(dummy_true),                                   ES1       },
-   { "GL_OES_compressed_paletted_texture",         o(dummy_false),                     DISABLE                },
-   { "GL_OES_depth24",                             o(EXT_framebuffer_object),                       ES1 | ES2 },
-   { "GL_OES_depth32",                             o(dummy_false),                     DISABLE                },
-   { "GL_OES_depth_texture",                       o(ARB_depth_texture),                                  ES2 },
-#if FEATURE_OES_draw_texture
-   { "GL_OES_draw_texture",                        o(OES_draw_texture),                             ES1 | ES2 },
-#endif
-#if FEATURE_OES_EGL_image
-   /*  FIXME: Mesa expects GL_OES_EGL_image to be available in OpenGL contexts. */
-   { "GL_OES_EGL_image",                           o(OES_EGL_image),                           GL | ES1 | ES2 },
-#endif
-   { "GL_OES_element_index_uint",                  o(EXT_vertex_array),                             ES1 | ES2 },
-   { "GL_OES_fbo_render_mipmap",                   o(EXT_framebuffer_object),                       ES1 | ES2 },
-   { "GL_OES_fixed_point",                         o(dummy_true),                                   ES1       },
-   { "GL_OES_framebuffer_object",                  o(EXT_framebuffer_object),                       ES1       },
-   { "GL_OES_mapbuffer",                           o(ARB_vertex_buffer_object),                     ES1 | ES2 },
-   { "GL_OES_matrix_get",                          o(dummy_true),                                   ES1       },
-   { "GL_OES_packed_depth_stencil",                o(EXT_packed_depth_stencil),                     ES1 | ES2 },
-   { "GL_OES_point_size_array",                    o(dummy_true),                                   ES1       },
-   { "GL_OES_point_sprite",                        o(ARB_point_sprite),                             ES1       },
-   { "GL_OES_query_matrix",                        o(dummy_true),                                   ES1       },
-   { "GL_OES_read_format",                         o(OES_read_format),                         GL | ES1       },
-   { "GL_OES_rgb8_rgba8",                          o(EXT_framebuffer_object),                       ES1 | ES2 },
-   { "GL_OES_single_precision",                    o(dummy_true),                                   ES1       },
-   { "GL_OES_standard_derivatives",                o(OES_standard_derivatives),                           ES2 },
-   { "GL_OES_stencil1",                            o(dummy_false),                     DISABLE                },
-   { "GL_OES_stencil4",                            o(dummy_false),                     DISABLE                },
-   { "GL_OES_stencil8",                            o(EXT_framebuffer_object),                       ES1 | ES2 },
-   { "GL_OES_stencil_wrap",                        o(EXT_stencil_wrap),                             ES1       },
-   /* GL_OES_texture_3D is disabled due to missing GLSL support. */
-   { "GL_OES_texture_3D",                          o(EXT_texture3D),                   DISABLE                },
-   { "GL_OES_texture_cube_map",                    o(ARB_texture_cube_map),                         ES1       },
-   { "GL_OES_texture_env_crossbar",                o(ARB_texture_env_crossbar),                     ES1       },
-   { "GL_OES_texture_mirrored_repeat",             o(ARB_texture_mirrored_repeat),                  ES1       },
-   { "GL_OES_texture_npot",                        o(ARB_texture_non_power_of_two),                       ES2 },
-
-   /* Vendor extensions */
-   { "GL_3DFX_texture_compression_FXT1",           o(TDFX_texture_compression_FXT1),           GL             },
-   { "GL_AMD_conservative_depth",                  o(AMD_conservative_depth),                  GL       | ES2 },
-   { "GL_APPLE_client_storage",                    o(APPLE_client_storage),                    GL             },
-   { "GL_APPLE_object_purgeable",                  o(APPLE_object_purgeable),                  GL             },
-   { "GL_APPLE_packed_pixels",                     o(APPLE_packed_pixels),                     GL             },
-   { "GL_APPLE_vertex_array_object",               o(APPLE_vertex_array_object),               GL             },
-   { "GL_ATI_blend_equation_separate",             o(EXT_blend_equation_separate),             GL             },
-   { "GL_ATI_envmap_bumpmap",                      o(ATI_envmap_bumpmap),                      GL             },
-   { "GL_ATI_fragment_shader",                     o(ATI_fragment_shader),                     GL             },
-   { "GL_ATI_separate_stencil",                    o(ATI_separate_stencil),                    GL             },
-   { "GL_ATI_texture_env_combine3",                o(ATI_texture_env_combine3),                GL             },
-   { "GL_ATI_texture_mirror_once",                 o(ATI_texture_mirror_once),                 GL             },
-   { "GL_IBM_multimode_draw_arrays",               o(IBM_multimode_draw_arrays),               GL             },
-   { "GL_IBM_rasterpos_clip",                      o(IBM_rasterpos_clip),                      GL             },
-   { "GL_IBM_texture_mirrored_repeat",             o(ARB_texture_mirrored_repeat),             GL             },
-   { "GL_INGR_blend_func_separate",                o(EXT_blend_func_separate),                 GL             },
-   { "GL_MESA_pack_invert",                        o(MESA_pack_invert),                        GL             },
-   { "GL_MESA_resize_buffers",                     o(MESA_resize_buffers),                     GL             },
-   { "GL_MESA_texture_array",                      o(MESA_texture_array),                      GL             },
-   { "GL_MESA_texture_signed_rgba",                o(MESA_texture_signed_rgba),                GL             },
-   { "GL_MESA_window_pos",                         o(ARB_window_pos),                          GL             },
-   { "GL_MESAX_texture_float",                     o(ARB_texture_float),                       GL             },
-   { "GL_MESA_ycbcr_texture",                      o(MESA_ycbcr_texture),                      GL             },
-   { "GL_NV_blend_square",                         o(NV_blend_square),                         GL             },
-   { "GL_NV_conditional_render",                   o(NV_conditional_render),                   GL             },
-   { "GL_NV_depth_clamp",                          o(ARB_depth_clamp),                         GL             },
-   { "GL_NV_fragment_program",                     o(NV_fragment_program),                     GL             },
-   { "GL_NV_fragment_program_option",              o(NV_fragment_program_option),              GL             },
-   { "GL_NV_light_max_exponent",                   o(NV_light_max_exponent),                   GL             },
-   { "GL_NV_packed_depth_stencil",                 o(EXT_packed_depth_stencil),                GL             },
-   { "GL_NV_point_sprite",                         o(NV_point_sprite),                         GL             },
-   { "GL_NV_primitive_restart",                    o(NV_primitive_restart),                    GL             },
-   { "GL_NV_texgen_reflection",                    o(NV_texgen_reflection),                    GL             },
-   { "GL_NV_texture_env_combine4",                 o(NV_texture_env_combine4),                 GL             },
-   { "GL_NV_texture_rectangle",                    o(NV_texture_rectangle),                    GL             },
-   { "GL_NV_vertex_program1_1",                    o(NV_vertex_program1_1),                    GL             },
-   { "GL_NV_vertex_program",                       o(NV_vertex_program),                       GL             },
-   { "GL_S3_s3tc",                                 o(S3_s3tc),                                 GL             },
-   { "GL_SGIS_generate_mipmap",                    o(SGIS_generate_mipmap),                    GL             },
-   { "GL_SGIS_texture_border_clamp",               o(ARB_texture_border_clamp),                GL             },
-   { "GL_SGIS_texture_edge_clamp",                 o(SGIS_texture_edge_clamp),                 GL             },
-   { "GL_SGIS_texture_lod",                        o(SGIS_texture_lod),                        GL             },
-   { "GL_SGI_texture_color_table",                 o(SGI_texture_color_table),                 GL             },
-   { "GL_SUN_multi_draw_arrays",                   o(EXT_multi_draw_arrays),                   GL             },
-
-   { 0, 0, 0 },
-};
-
-
-/**
- * Given an extension name, lookup up the corresponding member of struct
- * gl_extensions and return that member's offset (in bytes).  If the name is
- * not found in the \c extension_table, return 0.
- *
- * \param name Name of extension.
- * \return Offset of member in struct gl_extensions.
- */
-static size_t
-name_to_offset(const char* name)
-{
-   const struct extension *i;
-
-   if (name == 0)
-      return 0;
-
-   for (i = extension_table; i->name != 0; ++i) {
-      if (strcmp(name, i->name) == 0)
-	 return i->offset;
-   }
-
-   return 0;
-}
-
-
-/**
- * \brief Extensions enabled by default.
- *
- * These extensions are enabled by _mesa_init_extensions().
- *
- * XXX: Should these defaults also apply to GLES?
- */
-static const size_t default_extensions[] = {
-   o(ARB_copy_buffer),
-   o(ARB_draw_buffers),
-   o(ARB_multisample),
-   o(ARB_texture_compression),
-   o(ARB_transpose_matrix),
-   o(ARB_vertex_buffer_object),
-   o(ARB_window_pos),
-
-   o(EXT_abgr),
-   o(EXT_bgra),
-   o(EXT_compiled_vertex_array),
-   o(EXT_copy_texture),
-   o(EXT_draw_range_elements),
-   o(EXT_multi_draw_arrays),
-   o(EXT_packed_pixels),
-   o(EXT_polygon_offset),
-   o(EXT_rescale_normal),
-   o(EXT_separate_specular_color),
-   o(EXT_subtexture),
-   o(EXT_texture),
-   o(EXT_texture3D),
-   o(EXT_texture_object),
-   o(EXT_vertex_array),
-
-   o(OES_read_format),
-   o(OES_standard_derivatives),
-
-   /* Vendor Extensions */
-   o(APPLE_packed_pixels),
-   o(IBM_multimode_draw_arrays),
-   o(IBM_rasterpos_clip),
-   o(NV_light_max_exponent),
-   o(NV_texgen_reflection),
-   o(SGIS_generate_mipmap),
-   o(SGIS_texture_edge_clamp),
-   o(SGIS_texture_lod),
-
-   0,
-};
-
-
-/**
- * Enable all extensions suitable for a software-only renderer.
- * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
- */
-void
-_mesa_enable_sw_extensions(struct gl_context *ctx)
-{
-   /*ctx->Extensions.ARB_copy_buffer = GL_TRUE;*/
-   ctx->Extensions.ARB_depth_clamp = GL_TRUE;
-   ctx->Extensions.ARB_depth_texture = GL_TRUE;
-   /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
-   ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE;
-   ctx->Extensions.ARB_draw_instanced = GL_TRUE;
-   ctx->Extensions.ARB_explicit_attrib_location = GL_TRUE;
-   ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
-#if FEATURE_ARB_fragment_program
-   ctx->Extensions.ARB_fragment_program = GL_TRUE;
-   ctx->Extensions.ARB_fragment_program_shadow = GL_TRUE;
-#endif
-#if FEATURE_ARB_fragment_shader
-   ctx->Extensions.ARB_fragment_shader = GL_TRUE;
-#endif
-#if FEATURE_ARB_framebuffer_object
-   ctx->Extensions.ARB_framebuffer_object = GL_TRUE;
-#endif
-#if FEATURE_ARB_geometry_shader4 && 0
-   /* XXX re-enable when GLSL compiler again supports geometry shaders */
-   ctx->Extensions.ARB_geometry_shader4 = GL_TRUE;
-#endif
-   ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
-   ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
-   ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
-   ctx->Extensions.ARB_multitexture = GL_TRUE;
-#if FEATURE_queryobj
-   ctx->Extensions.ARB_occlusion_query = GL_TRUE;
-   ctx->Extensions.ARB_occlusion_query2 = GL_TRUE;
-#endif
-   ctx->Extensions.ARB_point_sprite = GL_TRUE;
-#if FEATURE_ARB_shader_objects
-   ctx->Extensions.ARB_shader_objects = GL_TRUE;
-   ctx->Extensions.EXT_separate_shader_objects = GL_TRUE;
-#endif
-#if FEATURE_ARB_shading_language_100
-   ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
-#endif
-   ctx->Extensions.ARB_shadow = GL_TRUE;
-   ctx->Extensions.ARB_shadow_ambient = GL_TRUE;
-   ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
-   ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
-   ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
-   ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
-   ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
-   /*ctx->Extensions.ARB_texture_float = GL_TRUE;*/
-   ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
-   ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
-   ctx->Extensions.ARB_texture_rg = GL_TRUE;
-   ctx->Extensions.ARB_vertex_array_object = GL_TRUE;
-#if FEATURE_ARB_vertex_program
-   ctx->Extensions.ARB_vertex_program = GL_TRUE;
-#endif
-#if FEATURE_ARB_vertex_shader
-   ctx->Extensions.ARB_vertex_shader = GL_TRUE;
-#endif
-#if FEATURE_ARB_vertex_buffer_object
-   /*ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;*/
-#endif
-#if FEATURE_ARB_sync
-   ctx->Extensions.ARB_sync = GL_TRUE;
-#endif
-   ctx->Extensions.APPLE_vertex_array_object = GL_TRUE;
-#if FEATURE_APPLE_object_purgeable
-   ctx->Extensions.APPLE_object_purgeable = GL_TRUE;
-#endif
-   ctx->Extensions.ATI_envmap_bumpmap = GL_TRUE;
-#if FEATURE_ATI_fragment_shader
-   ctx->Extensions.ATI_fragment_shader = GL_TRUE;
-#endif
-   ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
-   ctx->Extensions.ATI_texture_mirror_once = GL_TRUE;
-   ctx->Extensions.ATI_separate_stencil = GL_TRUE;
-   ctx->Extensions.EXT_blend_color = GL_TRUE;
-   ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
-   ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
-   ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
-   ctx->Extensions.EXT_blend_minmax = GL_TRUE;
-   ctx->Extensions.EXT_blend_subtract = GL_TRUE;
-   ctx->Extensions.EXT_depth_bounds_test = GL_TRUE;
-   ctx->Extensions.EXT_draw_buffers2 = GL_TRUE;
-   ctx->Extensions.EXT_fog_coord = GL_TRUE;
-#if FEATURE_EXT_framebuffer_object
-   ctx->Extensions.EXT_framebuffer_object = GL_TRUE;
-#endif
-#if FEATURE_EXT_framebuffer_blit
-   ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
-#endif
-#if FEATURE_ARB_framebuffer_object
-   ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE;
-#endif
-   /*ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;*/
-   ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
-   ctx->Extensions.EXT_paletted_texture = GL_TRUE;
-#if FEATURE_EXT_pixel_buffer_object
-   ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
-#endif
-   ctx->Extensions.EXT_point_parameters = GL_TRUE;
-   ctx->Extensions.EXT_provoking_vertex = GL_TRUE;
-   ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
-   ctx->Extensions.EXT_secondary_color = GL_TRUE;
-   ctx->Extensions.EXT_shared_texture_palette = GL_TRUE;
-   ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
-   ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
-   ctx->Extensions.EXT_texture_array = GL_TRUE;
-   ctx->Extensions.EXT_texture_env_add = GL_TRUE;
-   ctx->Extensions.EXT_texture_env_combine = GL_TRUE;
-   ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
-   ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
-   ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
-#if FEATURE_EXT_texture_sRGB
-   ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
-   ctx->Extensions.EXT_texture_sRGB_decode = GL_TRUE;
-#endif
-   ctx->Extensions.EXT_texture_swizzle = GL_TRUE;
-#if FEATURE_EXT_transform_feedback
-   /*ctx->Extensions.EXT_transform_feedback = GL_TRUE;*/
-#endif
-   ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE;
-   /*ctx->Extensions.IBM_multimode_draw_arrays = GL_TRUE;*/
-   ctx->Extensions.MESA_pack_invert = GL_TRUE;
-   ctx->Extensions.MESA_resize_buffers = GL_TRUE;
-   ctx->Extensions.MESA_texture_array = GL_TRUE;
-   ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
-   ctx->Extensions.NV_blend_square = GL_TRUE;
-   ctx->Extensions.NV_conditional_render = GL_TRUE;
-   /*ctx->Extensions.NV_light_max_exponent = GL_TRUE;*/
-   ctx->Extensions.NV_point_sprite = GL_TRUE;
-   ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
-   ctx->Extensions.NV_texture_rectangle = GL_TRUE;
-   /*ctx->Extensions.NV_texgen_reflection = GL_TRUE;*/
-#if FEATURE_NV_vertex_program
-   ctx->Extensions.NV_vertex_program = GL_TRUE;
-   ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
-#endif
-#if FEATURE_NV_fragment_program
-   ctx->Extensions.NV_fragment_program = GL_TRUE;
-#endif
-#if FEATURE_NV_fragment_program && FEATURE_ARB_fragment_program
-   ctx->Extensions.NV_fragment_program_option = GL_TRUE;
-#endif
-   ctx->Extensions.SGI_texture_color_table = GL_TRUE;
-   /*ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;*/
-   ctx->Extensions.SGIS_texture_edge_clamp = GL_TRUE;
-#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
-   ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
-#endif
-#if FEATURE_texture_fxt1
-   _mesa_enable_extension(ctx, "GL_3DFX_texture_compression_FXT1");
-#endif
-#if FEATURE_texture_s3tc
-   if (ctx->Mesa_DXTn) {
-      _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
-      _mesa_enable_extension(ctx, "GL_S3_s3tc");
-   }
-#endif
-}
-
-
-/**
- * Enable common EXT extensions in the ARB_imaging subset.
- */
-void
-_mesa_enable_imaging_extensions(struct gl_context *ctx)
-{
-   ctx->Extensions.EXT_blend_color = GL_TRUE;
-   ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
-   ctx->Extensions.EXT_blend_minmax = GL_TRUE;
-   ctx->Extensions.EXT_blend_subtract = GL_TRUE;
-}
-
-
-
-/**
- * Enable all OpenGL 1.3 features and extensions.
- * A convenience function to be called by drivers.
- */
-void
-_mesa_enable_1_3_extensions(struct gl_context *ctx)
-{
-   /*ctx->Extensions.ARB_multisample = GL_TRUE;*/
-   ctx->Extensions.ARB_multitexture = GL_TRUE;
-   ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
-   /*ctx->Extensions.ARB_texture_compression = GL_TRUE;*/
-   ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
-   ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
-   ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
-   ctx->Extensions.EXT_texture_env_add = GL_TRUE;
-   /*ctx->Extensions.ARB_transpose_matrix = GL_TRUE;*/
-}
-
-
-
-/**
- * Enable all OpenGL 1.4 features and extensions.
- * A convenience function to be called by drivers.
- */
-void
-_mesa_enable_1_4_extensions(struct gl_context *ctx)
-{
-   ctx->Extensions.ARB_depth_texture = GL_TRUE;
-   ctx->Extensions.ARB_shadow = GL_TRUE;
-   ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
-   ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
-   ctx->Extensions.ARB_window_pos = GL_TRUE;
-   ctx->Extensions.EXT_blend_color = GL_TRUE;
-   ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
-   ctx->Extensions.EXT_blend_minmax = GL_TRUE;
-   ctx->Extensions.EXT_blend_subtract = GL_TRUE;
-   ctx->Extensions.EXT_fog_coord = GL_TRUE;
-   /*ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;*/
-   ctx->Extensions.EXT_point_parameters = GL_TRUE;
-   ctx->Extensions.EXT_secondary_color = GL_TRUE;
-   ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
-   ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
-   /*ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;*/
-}
-
-
-/**
- * Enable all OpenGL 1.5 features and extensions.
- * A convenience function to be called by drivers.
- */
-void
-_mesa_enable_1_5_extensions(struct gl_context *ctx)
-{
-   ctx->Extensions.ARB_occlusion_query = GL_TRUE;
-   /*ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;*/
-   ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
-}
-
-
-/**
- * Enable all OpenGL 2.0 features and extensions.
- * A convenience function to be called by drivers.
- */
-void
-_mesa_enable_2_0_extensions(struct gl_context *ctx)
-{
-   /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
-#if FEATURE_ARB_fragment_shader
-   ctx->Extensions.ARB_fragment_shader = GL_TRUE;
-#endif
-   ctx->Extensions.ARB_point_sprite = GL_TRUE;
-   ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
-   ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
-#if FEATURE_ARB_shader_objects
-   ctx->Extensions.ARB_shader_objects = GL_TRUE;
-#endif
-#if FEATURE_ARB_shading_language_100
-   ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
-#endif
-   ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
-#if FEATURE_ARB_vertex_shader
-   ctx->Extensions.ARB_vertex_shader = GL_TRUE;
-#endif
-}
-
-
-/**
- * Enable all OpenGL 2.1 features and extensions.
- * A convenience function to be called by drivers.
- */
-void
-_mesa_enable_2_1_extensions(struct gl_context *ctx)
-{
-#if FEATURE_EXT_pixel_buffer_object
-   ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
-#endif
-#if FEATURE_EXT_texture_sRGB
-   ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
-#endif
-}
-
-
-/**
- * Either enable or disable the named extension.
- * \return GL_TRUE for success, GL_FALSE if invalid extension name
- */
-static GLboolean
-set_extension( struct gl_context *ctx, const char *name, GLboolean state )
-{
-   size_t offset;
-
-   if (ctx->Extensions.String) {
-      /* The string was already queried - can't change it now! */
-      _mesa_problem(ctx, "Trying to enable/disable extension after glGetString(GL_EXTENSIONS): %s", name);
-      return GL_FALSE;
-   }
-
-   offset = name_to_offset(name);
-   if (offset == 0) {
-      _mesa_problem(ctx, "Trying to enable/disable unknown extension %s",
-	            name);
-      return GL_FALSE;
-   } else if (offset == o(dummy_true) && state == GL_FALSE) {
-      _mesa_problem(ctx, "Trying to disable a permanently enabled extension: "
-	                  "%s", name);
-      return GL_FALSE;
-   } else {
-      GLboolean *base = (GLboolean *) &ctx->Extensions;
-      base[offset] = state;
-      return GL_TRUE;
-   }
-}
-
-
-/**
- * Enable the named extension.
- * Typically called by drivers.
- */
-void
-_mesa_enable_extension( struct gl_context *ctx, const char *name )
-{
-   if (!set_extension(ctx, name, GL_TRUE))
-      _mesa_problem(ctx, "Trying to enable unknown extension: %s", name);
-}
-
-
-/**
- * Disable the named extension.
- * XXX is this really needed???
- */
-void
-_mesa_disable_extension( struct gl_context *ctx, const char *name )
-{
-   if (!set_extension(ctx, name, GL_FALSE))
-      _mesa_problem(ctx, "Trying to disable unknown extension: %s", name);
-}
-
-
-/**
- * Test if the named extension is enabled in this context.
- */
-GLboolean
-_mesa_extension_is_enabled( struct gl_context *ctx, const char *name )
-{
-   size_t offset;
-   GLboolean *base;
-
-   if (name == 0)
-      return GL_FALSE;
-
-   offset = name_to_offset(name);
-   if (offset == 0)
-      return GL_FALSE;
-   base = (GLboolean *) &ctx->Extensions;
-   return base[offset];
-}
-
-
-/**
- * \brief Apply the \c MESA_EXTENSION_OVERRIDE environment variable.
- *
- * \c MESA_EXTENSION_OVERRIDE is a space-separated list of extensions to
- * enable or disable. The list is processed thus:
- *    - Enable recognized extension names that are prefixed with '+'.
- *    - Disable recognized extension names that are prefixed with '-'.
- *    - Enable recognized extension names that are not prefixed.
- *    - Collect unrecognized extension names in a new string.
- *
- * \return Space-separated list of unrecognized extension names (which must
- *    be freed). Does not return \c NULL.
- */
-static char *
-get_extension_override( struct gl_context *ctx )
-{
-   const char *env_const= _mesa_getenv("MESA_EXTENSION_OVERRIDE");
-   char *env;
-   char *ext;
-   char *extra_exts;
-   int len;
-
-   if (env_const == NULL) {
-      /* Return the empty string rather than NULL. This simplifies the logic
-       * of client functions. */
-      return calloc(1, sizeof(char));
-   }
-
-   /* extra_exts: List of unrecognized extensions. */
-   extra_exts = calloc(strlen(env_const), sizeof(char));
-
-   /* Copy env_const because strtok() is destructive. */
-   env = strdup(env_const);
-   for (ext = strtok(env, " "); ext != NULL; ext = strtok(NULL, " ")) {
-      int enable;
-      int recognized;
-      switch (ext[0]) {
-      case '+':
-         enable = 1;
-         ++ext;
-         break;
-      case '-':
-         enable = 0;
-         ++ext;
-         break;
-      default:
-         enable = 1;
-         break;
-      }
-      recognized = set_extension(ctx, ext, enable);
-      if (!recognized) {
-         strcat(extra_exts, ext);
-         strcat(extra_exts, " ");
-      }
-   }
-
-   /* Remove trailing space. */
-   len  = strlen(extra_exts);
-   if (extra_exts[len - 1] == ' ')
-      extra_exts[len - 1] = '\0';
-
-   return extra_exts;
-}
-
-
-/**
- * \brief Initialize extension tables and enable default extensions.
- *
- * This should be called during context initialization.
- * Note: Sets gl_extensions.dummy_true to true.
- */
-void
-_mesa_init_extensions( struct gl_context *ctx )
-{
-   GLboolean *base = (GLboolean *) &ctx->Extensions;
-   GLboolean *sentinel = base + o(extension_sentinel);
-   GLboolean *i;
-   const size_t *j;
-
-   /* First, turn all extensions off. */
-   for (i = base; i != sentinel; ++i)
-      *i = GL_FALSE;
-
-   /* Then, selectively turn default extensions on. */
-   ctx->Extensions.dummy_true = GL_TRUE;
-   for (j = default_extensions; *j != 0; ++j)
-      base[*j] = GL_TRUE;
-}
-
-
-/**
- * Construct the GL_EXTENSIONS string.  Called the first time that
- * glGetString(GL_EXTENSIONS) is called.
- */
-GLubyte*
-_mesa_make_extension_string(struct gl_context *ctx)
-{
-   /* The extension string. */
-   char *exts = 0;
-   /* Length of extension string. */
-   size_t length = 0;
-   /* String of extra extensions. */
-   char *extra_extensions = get_extension_override(ctx);
-   GLboolean *base = (GLboolean *) &ctx->Extensions;
-   const struct extension *i;
-
-   /* Compute length of the extension string. */
-   for (i = extension_table; i->name != 0; ++i) {
-      if (base[i->offset] && (i->api_set & (1 << ctx->API))) {
-	 length += strlen(i->name) + 1; /* +1 for space */
-      }
-   }
-   if (extra_extensions != NULL)
-      length += 1 + strlen(extra_extensions); /* +1 for space */
-
-   exts = (char *) calloc(length + 1, sizeof(char));
-   if (exts == NULL) {
-      free(extra_extensions);
-      return NULL;
-   }
-
-   /* Build the extension string.*/
-   for (i = extension_table; i->name != 0; ++i) {
-      if (base[i->offset] && (i->api_set & (1 << ctx->API))) {
-         strcat(exts, i->name);
-         strcat(exts, " ");
-      }
-   }
-   if (extra_extensions != 0) {
-      strcat(exts, extra_extensions);
-      free(extra_extensions);
-   }
-
-   return (GLubyte *) exts;
-}
-
-/**
- * Return number of enabled extensions.
- */
-GLuint
-_mesa_get_extension_count(struct gl_context *ctx)
-{
-   GLboolean *base;
-   const struct extension *i;
-
-   /* only count once */
-   if (ctx->Extensions.Count != 0)
-      return ctx->Extensions.Count;
-
-   base = (GLboolean *) &ctx->Extensions;
-   for (i = extension_table; i->name != 0; ++i) {
-      if (base[i->offset]) {
-	 ctx->Extensions.Count++;
-      }
-   }
-   return ctx->Extensions.Count;
-}
-
-/**
- * Return name of i-th enabled extension
- */
-const GLubyte *
-_mesa_get_enabled_extension(struct gl_context *ctx, GLuint index)
-{
-   const GLboolean *base;
-   size_t n;
-   const struct extension *i;
-
-   if (index < 0)
-      return NULL;
-
-   base = (GLboolean*) &ctx->Extensions;
-   n = 0;
-   for (i = extension_table; i->name != 0; ++i) {
-      if (n == index && base[i->offset]) {
-	 return (GLubyte*) i->name;
-      } else if (base[i->offset]) {
-	 ++n;
-      }
-   }
-
-   return NULL;
-}
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.6
+ *
+ * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
+ * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/**
+ * \file
+ * \brief Extension handling
+ */
+
+
+#include "glheader.h"
+#include "imports.h"
+#include "context.h"
+#include "extensions.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+
+enum {
+   DISABLE = 0,
+   GL  = 1 << API_OPENGL,
+   ES1 = 1 << API_OPENGLES,
+   ES2 = 1 << API_OPENGLES2,
+};
+
+/**
+ * \brief An element of the \c extension_table.
+ */
+struct extension {
+   /** Name of extension, such as "GL_ARB_depth_clamp". */
+   const char *name;
+
+   /** Offset (in bytes) of the corresponding member in struct gl_extensions. */
+   size_t offset;
+
+   /** Set of API's in which the extension exists, as a bitset. */
+   uint8_t api_set;
+};
+
+
+/**
+ * Given a member \c x of struct gl_extensions, return offset of
+ * \c x in bytes.
+ */
+#define o(x) offsetof(struct gl_extensions, x)
+
+
+/**
+ * \brief Table of supported OpenGL extensions for all API's.
+ *
+ * Note: The GL_MESAX_* extensions are placeholders for future ARB extensions.
+ */
+static const struct extension extension_table[] = {
+   /* ARB Extensions */
+   { "GL_ARB_ES2_compatibility",                   o(ARB_ES2_compatibility),                   GL             },
+   { "GL_ARB_blend_func_extended",                 o(ARB_blend_func_extended),                 GL             },
+   { "GL_ARB_copy_buffer",                         o(ARB_copy_buffer),                         GL             },
+   { "GL_ARB_depth_buffer_float",                  o(ARB_depth_buffer_float),                  GL             },
+   { "GL_ARB_depth_clamp",                         o(ARB_depth_clamp),                         GL             },
+   { "GL_ARB_depth_texture",                       o(ARB_depth_texture),                       GL             },
+   { "GL_ARB_draw_buffers",                        o(ARB_draw_buffers),                        GL             },
+   { "GL_ARB_draw_buffers_blend",                  o(ARB_draw_buffers_blend),                  GL             },
+   { "GL_ARB_draw_elements_base_vertex",           o(ARB_draw_elements_base_vertex),           GL             },
+   { "GL_ARB_draw_instanced",                      o(ARB_draw_instanced),                      GL             },
+   { "GL_ARB_explicit_attrib_location",            o(ARB_explicit_attrib_location),            GL             },
+   { "GL_ARB_fragment_coord_conventions",          o(ARB_fragment_coord_conventions),          GL             },
+   { "GL_ARB_fragment_program",                    o(ARB_fragment_program),                    GL             },
+   { "GL_ARB_fragment_program_shadow",             o(ARB_fragment_program_shadow),             GL             },
+   { "GL_ARB_fragment_shader",                     o(ARB_fragment_shader),                     GL             },
+   { "GL_ARB_framebuffer_object",                  o(ARB_framebuffer_object),                  GL             },
+   { "GL_ARB_framebuffer_sRGB",                    o(EXT_framebuffer_sRGB),                    GL             },
+   { "GL_ARB_half_float_pixel",                    o(ARB_half_float_pixel),                    GL             },
+   { "GL_ARB_half_float_vertex",                   o(ARB_half_float_vertex),                   GL             },
+   { "GL_ARB_instanced_arrays",                    o(ARB_instanced_arrays),                    GL             },
+   { "GL_ARB_map_buffer_range",                    o(ARB_map_buffer_range),                    GL             },
+   { "GL_ARB_multisample",                         o(ARB_multisample),                         GL             },
+   { "GL_ARB_multitexture",                        o(ARB_multitexture),                        GL             },
+   { "GL_ARB_occlusion_query2",                    o(ARB_occlusion_query2),                    GL             },
+   { "GL_ARB_occlusion_query",                     o(ARB_occlusion_query),                     GL             },
+   { "GL_ARB_pixel_buffer_object",                 o(EXT_pixel_buffer_object),                 GL             },
+   { "GL_ARB_point_parameters",                    o(EXT_point_parameters),                    GL             },
+   { "GL_ARB_point_sprite",                        o(ARB_point_sprite),                        GL             },
+   { "GL_ARB_provoking_vertex",                    o(EXT_provoking_vertex),                    GL             },
+   { "GL_ARB_sampler_objects",                     o(ARB_sampler_objects),                     GL             },
+   { "GL_ARB_seamless_cube_map",                   o(ARB_seamless_cube_map),                   GL             },
+   { "GL_ARB_shader_objects",                      o(ARB_shader_objects),                      GL             },
+   { "GL_ARB_shader_stencil_export",               o(ARB_shader_stencil_export),               GL             },
+   { "GL_ARB_shading_language_100",                o(ARB_shading_language_100),                GL             },
+   { "GL_ARB_shadow_ambient",                      o(ARB_shadow_ambient),                      GL             },
+   { "GL_ARB_shadow",                              o(ARB_shadow),                              GL             },
+   { "GL_ARB_sync",                                o(ARB_sync),                                GL             },
+   { "GL_ARB_texture_border_clamp",                o(ARB_texture_border_clamp),                GL             },
+   { "GL_ARB_texture_buffer_object",               o(ARB_texture_buffer_object),               GL             },
+   { "GL_ARB_texture_compression",                 o(ARB_texture_compression),                 GL             },
+   { "GL_ARB_texture_compression_rgtc",            o(ARB_texture_compression_rgtc),            GL             },
+   { "GL_ARB_texture_cube_map",                    o(ARB_texture_cube_map),                    GL             },
+   { "GL_ARB_texture_env_add",                     o(EXT_texture_env_add),                     GL             },
+   { "GL_ARB_texture_env_combine",                 o(ARB_texture_env_combine),                 GL             },
+   { "GL_ARB_texture_env_crossbar",                o(ARB_texture_env_crossbar),                GL             },
+   { "GL_ARB_texture_env_dot3",                    o(ARB_texture_env_dot3),                    GL             },
+   { "GL_ARB_texture_mirrored_repeat",             o(ARB_texture_mirrored_repeat),             GL             },
+   { "GL_ARB_texture_multisample",                 o(ARB_texture_multisample),                 GL             },
+   { "GL_ARB_texture_non_power_of_two",            o(ARB_texture_non_power_of_two),            GL             },
+   { "GL_ARB_texture_rectangle",                   o(NV_texture_rectangle),                    GL             },
+   { "GL_ARB_texture_rgb10_a2ui",                  o(ARB_texture_rgb10_a2ui),                  GL             },
+   { "GL_ARB_texture_rg",                          o(ARB_texture_rg),                          GL             },
+   { "GL_ARB_texture_swizzle",                     o(EXT_texture_swizzle),                     GL             },
+   { "GL_ARB_transform_feedback2",                 o(ARB_transform_feedback2),                 GL             },
+   { "GL_ARB_transpose_matrix",                    o(ARB_transpose_matrix),                    GL             },
+   { "GL_ARB_uniform_buffer_object",               o(ARB_uniform_buffer_object),               GL             },
+   { "GL_ARB_vertex_array_bgra",                   o(EXT_vertex_array_bgra),                   GL             },
+   { "GL_ARB_vertex_array_object",                 o(ARB_vertex_array_object),                 GL             },
+   { "GL_ARB_vertex_buffer_object",                o(ARB_vertex_buffer_object),                GL             },
+   { "GL_ARB_vertex_program",                      o(ARB_vertex_program),                      GL             },
+   { "GL_ARB_vertex_shader",                       o(ARB_vertex_shader),                       GL             },
+   { "GL_ARB_vertex_type_2_10_10_10_rev",          o(ARB_vertex_type_2_10_10_10_rev),          GL             },
+   { "GL_ARB_window_pos",                          o(ARB_window_pos),                          GL             },
+
+   /* EXT extensions */
+   { "GL_EXT_abgr",                                o(EXT_abgr),                                GL             },
+   { "GL_EXT_bgra",                                o(EXT_bgra),                                GL             },
+   { "GL_EXT_blend_color",                         o(EXT_blend_color),                         GL             },
+   { "GL_EXT_blend_equation_separate",             o(EXT_blend_equation_separate),             GL             },
+   { "GL_EXT_blend_func_separate",                 o(EXT_blend_func_separate),                 GL             },
+   { "GL_EXT_blend_logic_op",                      o(EXT_blend_logic_op),                      GL             },
+   { "GL_EXT_blend_minmax",                        o(EXT_blend_minmax),                        GL | ES1 | ES2 },
+   { "GL_EXT_blend_subtract",                      o(EXT_blend_subtract),                      GL             },
+   { "GL_EXT_clip_volume_hint",                    o(EXT_clip_volume_hint),                    GL             },
+   { "GL_EXT_compiled_vertex_array",               o(EXT_compiled_vertex_array),               GL             },
+   { "GL_EXT_copy_texture",                        o(EXT_copy_texture),                        GL             },
+   { "GL_EXT_depth_bounds_test",                   o(EXT_depth_bounds_test),                   GL             },
+   { "GL_EXT_draw_buffers2",                       o(EXT_draw_buffers2),                       GL             },
+   { "GL_EXT_draw_instanced",                      o(ARB_draw_instanced),                      GL             },
+   { "GL_EXT_draw_range_elements",                 o(EXT_draw_range_elements),                 GL             },
+   { "GL_EXT_fog_coord",                           o(EXT_fog_coord),                           GL             },
+   { "GL_EXT_framebuffer_blit",                    o(EXT_framebuffer_blit),                    GL             },
+   { "GL_EXT_framebuffer_multisample",             o(EXT_framebuffer_multisample),             GL             },
+   { "GL_EXT_framebuffer_object",                  o(EXT_framebuffer_object),                  GL             },
+   { "GL_EXT_framebuffer_sRGB",                    o(EXT_framebuffer_sRGB),                    GL             },
+   { "GL_EXT_gpu_program_parameters",              o(EXT_gpu_program_parameters),              GL             },
+   { "GL_EXT_gpu_shader4",                         o(EXT_gpu_shader4),                         GL             },
+   { "GL_EXT_multi_draw_arrays",                   o(EXT_multi_draw_arrays),                   GL | ES1 | ES2 },
+   { "GL_EXT_packed_depth_stencil",                o(EXT_packed_depth_stencil),                GL             },
+   { "GL_EXT_packed_float",                        o(EXT_packed_float),                        GL             },
+   { "GL_EXT_packed_pixels",                       o(EXT_packed_pixels),                       GL             },
+   { "GL_EXT_paletted_texture",                    o(EXT_paletted_texture),                    GL             },
+   { "GL_EXT_pixel_buffer_object",                 o(EXT_pixel_buffer_object),                 GL             },
+   { "GL_EXT_point_parameters",                    o(EXT_point_parameters),                    GL             },
+   { "GL_EXT_polygon_offset",                      o(EXT_polygon_offset),                      GL             },
+   { "GL_EXT_provoking_vertex",                    o(EXT_provoking_vertex),                    GL             },
+   { "GL_EXT_rescale_normal",                      o(EXT_rescale_normal),                      GL             },
+   { "GL_EXT_secondary_color",                     o(EXT_secondary_color),                     GL             },
+   { "GL_EXT_separate_shader_objects",             o(EXT_separate_shader_objects),             GL             },
+   { "GL_EXT_separate_specular_color",             o(EXT_separate_specular_color),             GL             },
+   { "GL_EXT_shadow_funcs",                        o(EXT_shadow_funcs),                        GL             },
+   { "GL_EXT_shared_texture_palette",              o(EXT_shared_texture_palette),              GL             },
+   { "GL_EXT_stencil_two_side",                    o(EXT_stencil_two_side),                    GL             },
+   { "GL_EXT_stencil_wrap",                        o(EXT_stencil_wrap),                        GL             },
+   { "GL_EXT_subtexture",                          o(EXT_subtexture),                          GL             },
+   { "GL_EXT_texture3D",                           o(EXT_texture3D),                           GL             },
+   { "GL_EXT_texture_array",                       o(EXT_texture_array),                       GL             },
+   { "GL_EXT_texture_compression_dxt1",            o(EXT_texture_compression_s3tc),            GL | ES1 | ES2 },
+   { "GL_EXT_texture_compression_rgtc",            o(ARB_texture_compression_rgtc),            GL             },
+   { "GL_EXT_texture_compression_s3tc",            o(EXT_texture_compression_s3tc),            GL             },
+   { "GL_EXT_texture_cube_map",                    o(ARB_texture_cube_map),                    GL             },
+   { "GL_EXT_texture_edge_clamp",                  o(SGIS_texture_edge_clamp),                 GL             },
+   { "GL_EXT_texture_env_add",                     o(EXT_texture_env_add),                     GL             },
+   { "GL_EXT_texture_env_combine",                 o(EXT_texture_env_combine),                 GL             },
+   { "GL_EXT_texture_env_dot3",                    o(EXT_texture_env_dot3),                    GL             },
+   { "GL_EXT_texture_filter_anisotropic",          o(EXT_texture_filter_anisotropic),          GL | ES1 | ES2 },
+   { "GL_EXT_texture_format_BGRA8888",             o(EXT_texture_format_BGRA8888),                  ES1 | ES2 },
+   { "GL_EXT_texture_integer",                     o(EXT_texture_integer),                     GL             },
+   { "GL_EXT_texture_lod_bias",                    o(EXT_texture_lod_bias),                    GL | ES1       },
+   { "GL_EXT_texture_mirror_clamp",                o(EXT_texture_mirror_clamp),                GL             },
+   { "GL_EXT_texture_object",                      o(EXT_texture_object),                      GL             },
+   { "GL_EXT_texture",                             o(EXT_texture),                             GL             },
+   { "GL_EXT_texture_rectangle",                   o(NV_texture_rectangle),                    GL             },
+   { "GL_EXT_texture_shared_exponent",             o(EXT_texture_shared_exponent),             GL             },
+   { "GL_EXT_texture_sRGB",                        o(EXT_texture_sRGB),                        GL             },
+   { "GL_EXT_texture_sRGB_decode",                 o(EXT_texture_sRGB_decode),                        GL             },
+   { "GL_EXT_texture_swizzle",                     o(EXT_texture_swizzle),                     GL             },
+   { "GL_EXT_texture_type_2_10_10_10_REV",         o(dummy_true),                                         ES2 },
+   { "GL_EXT_timer_query",                         o(EXT_timer_query),                         GL             },
+   { "GL_EXT_transform_feedback",                  o(EXT_transform_feedback),                  GL             },
+   { "GL_EXT_vertex_array_bgra",                   o(EXT_vertex_array_bgra),                   GL             },
+   { "GL_EXT_vertex_array",                        o(EXT_vertex_array),                        GL             },
+   { "GL_EXT_vertex_array_set",                    o(EXT_vertex_array_set),                    GL             },
+
+   /* OES extensions */
+   { "GL_OES_blend_equation_separate",             o(EXT_blend_equation_separate),                  ES1       },
+   { "GL_OES_blend_func_separate",                 o(EXT_blend_func_separate),                      ES1       },
+   { "GL_OES_blend_subtract",                      o(EXT_blend_subtract),                           ES1       },
+   { "GL_OES_byte_coordinates",                    o(dummy_true),                                   ES1       },
+   { "GL_OES_compressed_paletted_texture",         o(dummy_false),                     DISABLE                },
+   { "GL_OES_depth24",                             o(EXT_framebuffer_object),                       ES1 | ES2 },
+   { "GL_OES_depth32",                             o(dummy_false),                     DISABLE                },
+   { "GL_OES_depth_texture",                       o(ARB_depth_texture),                                  ES2 },
+#if FEATURE_OES_draw_texture
+   { "GL_OES_draw_texture",                        o(OES_draw_texture),                             ES1 | ES2 },
+#endif
+#if FEATURE_OES_EGL_image
+   /*  FIXME: Mesa expects GL_OES_EGL_image to be available in OpenGL contexts. */
+   { "GL_OES_EGL_image",                           o(OES_EGL_image),                           GL | ES1 | ES2 },
+#endif
+   { "GL_OES_element_index_uint",                  o(EXT_vertex_array),                             ES1 | ES2 },
+   { "GL_OES_fbo_render_mipmap",                   o(EXT_framebuffer_object),                       ES1 | ES2 },
+   { "GL_OES_fixed_point",                         o(dummy_true),                                   ES1       },
+   { "GL_OES_framebuffer_object",                  o(EXT_framebuffer_object),                       ES1       },
+   { "GL_OES_mapbuffer",                           o(ARB_vertex_buffer_object),                     ES1 | ES2 },
+   { "GL_OES_matrix_get",                          o(dummy_true),                                   ES1       },
+   { "GL_OES_packed_depth_stencil",                o(EXT_packed_depth_stencil),                     ES1 | ES2 },
+   { "GL_OES_point_size_array",                    o(dummy_true),                                   ES1       },
+   { "GL_OES_point_sprite",                        o(ARB_point_sprite),                             ES1       },
+   { "GL_OES_query_matrix",                        o(dummy_true),                                   ES1       },
+   { "GL_OES_read_format",                         o(OES_read_format),                         GL | ES1       },
+   { "GL_OES_rgb8_rgba8",                          o(EXT_framebuffer_object),                       ES1 | ES2 },
+   { "GL_OES_single_precision",                    o(dummy_true),                                   ES1       },
+   { "GL_OES_standard_derivatives",                o(OES_standard_derivatives),                           ES2 },
+   { "GL_OES_stencil1",                            o(dummy_false),                     DISABLE                },
+   { "GL_OES_stencil4",                            o(dummy_false),                     DISABLE                },
+   { "GL_OES_stencil8",                            o(EXT_framebuffer_object),                       ES1 | ES2 },
+   { "GL_OES_stencil_wrap",                        o(EXT_stencil_wrap),                             ES1       },
+   /* GL_OES_texture_3D is disabled due to missing GLSL support. */
+   { "GL_OES_texture_3D",                          o(EXT_texture3D),                   DISABLE                },
+   { "GL_OES_texture_cube_map",                    o(ARB_texture_cube_map),                         ES1       },
+   { "GL_OES_texture_env_crossbar",                o(ARB_texture_env_crossbar),                     ES1       },
+   { "GL_OES_texture_mirrored_repeat",             o(ARB_texture_mirrored_repeat),                  ES1       },
+   { "GL_OES_texture_npot",                        o(ARB_texture_non_power_of_two),                       ES2 },
+
+   /* Vendor extensions */
+   { "GL_3DFX_texture_compression_FXT1",           o(TDFX_texture_compression_FXT1),           GL             },
+   { "GL_AMD_conservative_depth",                  o(AMD_conservative_depth),                  GL             },
+   { "GL_APPLE_client_storage",                    o(APPLE_client_storage),                    GL             },
+   { "GL_APPLE_object_purgeable",                  o(APPLE_object_purgeable),                  GL             },
+   { "GL_APPLE_packed_pixels",                     o(APPLE_packed_pixels),                     GL             },
+   { "GL_APPLE_vertex_array_object",               o(APPLE_vertex_array_object),               GL             },
+   { "GL_ATI_blend_equation_separate",             o(EXT_blend_equation_separate),             GL             },
+   { "GL_ATI_envmap_bumpmap",                      o(ATI_envmap_bumpmap),                      GL             },
+   { "GL_ATI_fragment_shader",                     o(ATI_fragment_shader),                     GL             },
+   { "GL_ATI_separate_stencil",                    o(ATI_separate_stencil),                    GL             },
+   { "GL_ATI_texture_env_combine3",                o(ATI_texture_env_combine3),                GL             },
+   { "GL_ATI_texture_mirror_once",                 o(ATI_texture_mirror_once),                 GL             },
+   { "GL_IBM_multimode_draw_arrays",               o(IBM_multimode_draw_arrays),               GL             },
+   { "GL_IBM_rasterpos_clip",                      o(IBM_rasterpos_clip),                      GL             },
+   { "GL_IBM_texture_mirrored_repeat",             o(ARB_texture_mirrored_repeat),             GL             },
+   { "GL_INGR_blend_func_separate",                o(EXT_blend_func_separate),                 GL             },
+   { "GL_MESA_pack_invert",                        o(MESA_pack_invert),                        GL             },
+   { "GL_MESA_resize_buffers",                     o(MESA_resize_buffers),                     GL             },
+   { "GL_MESA_texture_array",                      o(MESA_texture_array),                      GL             },
+   { "GL_MESA_texture_signed_rgba",                o(MESA_texture_signed_rgba),                GL             },
+   { "GL_MESA_window_pos",                         o(ARB_window_pos),                          GL             },
+   { "GL_MESAX_texture_float",                     o(ARB_texture_float),                       GL             },
+   { "GL_MESA_ycbcr_texture",                      o(MESA_ycbcr_texture),                      GL             },
+   { "GL_NV_blend_square",                         o(NV_blend_square),                         GL             },
+   { "GL_NV_conditional_render",                   o(NV_conditional_render),                   GL             },
+   { "GL_NV_depth_clamp",                          o(ARB_depth_clamp),                         GL             },
+   { "GL_NV_fragment_program",                     o(NV_fragment_program),                     GL             },
+   { "GL_NV_fragment_program_option",              o(NV_fragment_program_option),              GL             },
+   { "GL_NV_light_max_exponent",                   o(NV_light_max_exponent),                   GL             },
+   { "GL_NV_packed_depth_stencil",                 o(EXT_packed_depth_stencil),                GL             },
+   { "GL_NV_point_sprite",                         o(NV_point_sprite),                         GL             },
+   { "GL_NV_primitive_restart",                    o(NV_primitive_restart),                    GL             },
+   { "GL_NV_texgen_reflection",                    o(NV_texgen_reflection),                    GL             },
+   { "GL_NV_texture_env_combine4",                 o(NV_texture_env_combine4),                 GL             },
+   { "GL_NV_texture_rectangle",                    o(NV_texture_rectangle),                    GL             },
+   { "GL_NV_vertex_program1_1",                    o(NV_vertex_program1_1),                    GL             },
+   { "GL_NV_vertex_program",                       o(NV_vertex_program),                       GL             },
+   { "GL_S3_s3tc",                                 o(S3_s3tc),                                 GL             },
+   { "GL_SGIS_generate_mipmap",                    o(SGIS_generate_mipmap),                    GL             },
+   { "GL_SGIS_texture_border_clamp",               o(ARB_texture_border_clamp),                GL             },
+   { "GL_SGIS_texture_edge_clamp",                 o(SGIS_texture_edge_clamp),                 GL             },
+   { "GL_SGIS_texture_lod",                        o(SGIS_texture_lod),                        GL             },
+   { "GL_SGI_texture_color_table",                 o(SGI_texture_color_table),                 GL             },
+   { "GL_SUN_multi_draw_arrays",                   o(EXT_multi_draw_arrays),                   GL             },
+
+   { 0, 0, 0 },
+};
+
+
+/**
+ * Given an extension name, lookup up the corresponding member of struct
+ * gl_extensions and return that member's offset (in bytes).  If the name is
+ * not found in the \c extension_table, return 0.
+ *
+ * \param name Name of extension.
+ * \return Offset of member in struct gl_extensions.
+ */
+static size_t
+name_to_offset(const char* name)
+{
+   const struct extension *i;
+
+   if (name == 0)
+      return 0;
+
+   for (i = extension_table; i->name != 0; ++i) {
+      if (strcmp(name, i->name) == 0)
+	 return i->offset;
+   }
+
+   return 0;
+}
+
+
+/**
+ * \brief Extensions enabled by default.
+ *
+ * These extensions are enabled by _mesa_init_extensions().
+ *
+ * XXX: Should these defaults also apply to GLES?
+ */
+static const size_t default_extensions[] = {
+   o(ARB_copy_buffer),
+   o(ARB_draw_buffers),
+   o(ARB_multisample),
+   o(ARB_texture_compression),
+   o(ARB_transpose_matrix),
+   o(ARB_vertex_buffer_object),
+   o(ARB_window_pos),
+
+   o(EXT_abgr),
+   o(EXT_bgra),
+   o(EXT_compiled_vertex_array),
+   o(EXT_copy_texture),
+   o(EXT_draw_range_elements),
+   o(EXT_multi_draw_arrays),
+   o(EXT_packed_pixels),
+   o(EXT_polygon_offset),
+   o(EXT_rescale_normal),
+   o(EXT_separate_specular_color),
+   o(EXT_subtexture),
+   o(EXT_texture),
+   o(EXT_texture3D),
+   o(EXT_texture_object),
+   o(EXT_vertex_array),
+
+   o(OES_read_format),
+   o(OES_standard_derivatives),
+
+   /* Vendor Extensions */
+   o(APPLE_packed_pixels),
+   o(IBM_multimode_draw_arrays),
+   o(IBM_rasterpos_clip),
+   o(NV_light_max_exponent),
+   o(NV_texgen_reflection),
+   o(SGIS_generate_mipmap),
+   o(SGIS_texture_edge_clamp),
+   o(SGIS_texture_lod),
+
+   0,
+};
+
+
+/**
+ * Enable all extensions suitable for a software-only renderer.
+ * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
+ */
+void
+_mesa_enable_sw_extensions(struct gl_context *ctx)
+{
+   /*ctx->Extensions.ARB_copy_buffer = GL_TRUE;*/
+   ctx->Extensions.ARB_depth_clamp = GL_TRUE;
+   ctx->Extensions.ARB_depth_texture = GL_TRUE;
+   /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
+   ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE;
+   ctx->Extensions.ARB_draw_instanced = GL_TRUE;
+   ctx->Extensions.ARB_explicit_attrib_location = GL_TRUE;
+   ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
+#if FEATURE_ARB_fragment_program
+   ctx->Extensions.ARB_fragment_program = GL_TRUE;
+   ctx->Extensions.ARB_fragment_program_shadow = GL_TRUE;
+#endif
+#if FEATURE_ARB_fragment_shader
+   ctx->Extensions.ARB_fragment_shader = GL_TRUE;
+#endif
+#if FEATURE_ARB_framebuffer_object
+   ctx->Extensions.ARB_framebuffer_object = GL_TRUE;
+#endif
+#if FEATURE_ARB_geometry_shader4 && 0
+   /* XXX re-enable when GLSL compiler again supports geometry shaders */
+   ctx->Extensions.ARB_geometry_shader4 = GL_TRUE;
+#endif
+   ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
+   ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
+   ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
+   ctx->Extensions.ARB_multitexture = GL_TRUE;
+#if FEATURE_queryobj
+   ctx->Extensions.ARB_occlusion_query = GL_TRUE;
+   ctx->Extensions.ARB_occlusion_query2 = GL_TRUE;
+#endif
+   ctx->Extensions.ARB_point_sprite = GL_TRUE;
+#if FEATURE_ARB_shader_objects
+   ctx->Extensions.ARB_shader_objects = GL_TRUE;
+   ctx->Extensions.EXT_separate_shader_objects = GL_TRUE;
+#endif
+#if FEATURE_ARB_shading_language_100
+   ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
+#endif
+   ctx->Extensions.ARB_shadow = GL_TRUE;
+   ctx->Extensions.ARB_shadow_ambient = GL_TRUE;
+   ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
+   ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
+   ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
+   ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
+   ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
+   /*ctx->Extensions.ARB_texture_float = GL_TRUE;*/
+   ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
+   ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
+   ctx->Extensions.ARB_texture_rg = GL_TRUE;
+   ctx->Extensions.ARB_vertex_array_object = GL_TRUE;
+#if FEATURE_ARB_vertex_program
+   ctx->Extensions.ARB_vertex_program = GL_TRUE;
+#endif
+#if FEATURE_ARB_vertex_shader
+   ctx->Extensions.ARB_vertex_shader = GL_TRUE;
+#endif
+#if FEATURE_ARB_vertex_buffer_object
+   /*ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;*/
+#endif
+#if FEATURE_ARB_sync
+   ctx->Extensions.ARB_sync = GL_TRUE;
+#endif
+   ctx->Extensions.APPLE_vertex_array_object = GL_TRUE;
+#if FEATURE_APPLE_object_purgeable
+   ctx->Extensions.APPLE_object_purgeable = GL_TRUE;
+#endif
+   ctx->Extensions.ATI_envmap_bumpmap = GL_TRUE;
+#if FEATURE_ATI_fragment_shader
+   ctx->Extensions.ATI_fragment_shader = GL_TRUE;
+#endif
+   ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
+   ctx->Extensions.ATI_texture_mirror_once = GL_TRUE;
+   ctx->Extensions.ATI_separate_stencil = GL_TRUE;
+   ctx->Extensions.EXT_blend_color = GL_TRUE;
+   ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
+   ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
+   ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
+   ctx->Extensions.EXT_blend_minmax = GL_TRUE;
+   ctx->Extensions.EXT_blend_subtract = GL_TRUE;
+   ctx->Extensions.EXT_depth_bounds_test = GL_TRUE;
+   ctx->Extensions.EXT_draw_buffers2 = GL_TRUE;
+   ctx->Extensions.EXT_fog_coord = GL_TRUE;
+#if FEATURE_EXT_framebuffer_object
+   ctx->Extensions.EXT_framebuffer_object = GL_TRUE;
+#endif
+#if FEATURE_EXT_framebuffer_blit
+   ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
+#endif
+#if FEATURE_ARB_framebuffer_object
+   ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE;
+#endif
+   /*ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;*/
+   ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
+   ctx->Extensions.EXT_paletted_texture = GL_TRUE;
+#if FEATURE_EXT_pixel_buffer_object
+   ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
+#endif
+   ctx->Extensions.EXT_point_parameters = GL_TRUE;
+   ctx->Extensions.EXT_provoking_vertex = GL_TRUE;
+   ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
+   ctx->Extensions.EXT_secondary_color = GL_TRUE;
+   ctx->Extensions.EXT_shared_texture_palette = GL_TRUE;
+   ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
+   ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
+   ctx->Extensions.EXT_texture_array = GL_TRUE;
+   ctx->Extensions.EXT_texture_env_add = GL_TRUE;
+   ctx->Extensions.EXT_texture_env_combine = GL_TRUE;
+   ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
+   ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
+   ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
+#if FEATURE_EXT_texture_sRGB
+   ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
+   ctx->Extensions.EXT_texture_sRGB_decode = GL_TRUE;
+#endif
+   ctx->Extensions.EXT_texture_swizzle = GL_TRUE;
+#if FEATURE_EXT_transform_feedback
+   /*ctx->Extensions.EXT_transform_feedback = GL_TRUE;*/
+#endif
+   ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE;
+   /*ctx->Extensions.IBM_multimode_draw_arrays = GL_TRUE;*/
+   ctx->Extensions.MESA_pack_invert = GL_TRUE;
+   ctx->Extensions.MESA_resize_buffers = GL_TRUE;
+   ctx->Extensions.MESA_texture_array = GL_TRUE;
+   ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
+   ctx->Extensions.NV_blend_square = GL_TRUE;
+   ctx->Extensions.NV_conditional_render = GL_TRUE;
+   /*ctx->Extensions.NV_light_max_exponent = GL_TRUE;*/
+   ctx->Extensions.NV_point_sprite = GL_TRUE;
+   ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
+   ctx->Extensions.NV_texture_rectangle = GL_TRUE;
+   /*ctx->Extensions.NV_texgen_reflection = GL_TRUE;*/
+#if FEATURE_NV_vertex_program
+   ctx->Extensions.NV_vertex_program = GL_TRUE;
+   ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
+#endif
+#if FEATURE_NV_fragment_program
+   ctx->Extensions.NV_fragment_program = GL_TRUE;
+#endif
+#if FEATURE_NV_fragment_program && FEATURE_ARB_fragment_program
+   ctx->Extensions.NV_fragment_program_option = GL_TRUE;
+#endif
+   ctx->Extensions.SGI_texture_color_table = GL_TRUE;
+   /*ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;*/
+   ctx->Extensions.SGIS_texture_edge_clamp = GL_TRUE;
+#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
+   ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
+#endif
+#if FEATURE_texture_fxt1
+   _mesa_enable_extension(ctx, "GL_3DFX_texture_compression_FXT1");
+#endif
+#if FEATURE_texture_s3tc
+   if (ctx->Mesa_DXTn) {
+      _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
+      _mesa_enable_extension(ctx, "GL_S3_s3tc");
+   }
+#endif
+}
+
+
+/**
+ * Enable common EXT extensions in the ARB_imaging subset.
+ */
+void
+_mesa_enable_imaging_extensions(struct gl_context *ctx)
+{
+   ctx->Extensions.EXT_blend_color = GL_TRUE;
+   ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
+   ctx->Extensions.EXT_blend_minmax = GL_TRUE;
+   ctx->Extensions.EXT_blend_subtract = GL_TRUE;
+}
+
+
+
+/**
+ * Enable all OpenGL 1.3 features and extensions.
+ * A convenience function to be called by drivers.
+ */
+void
+_mesa_enable_1_3_extensions(struct gl_context *ctx)
+{
+   /*ctx->Extensions.ARB_multisample = GL_TRUE;*/
+   ctx->Extensions.ARB_multitexture = GL_TRUE;
+   ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
+   /*ctx->Extensions.ARB_texture_compression = GL_TRUE;*/
+   ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
+   ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
+   ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
+   ctx->Extensions.EXT_texture_env_add = GL_TRUE;
+   /*ctx->Extensions.ARB_transpose_matrix = GL_TRUE;*/
+}
+
+
+
+/**
+ * Enable all OpenGL 1.4 features and extensions.
+ * A convenience function to be called by drivers.
+ */
+void
+_mesa_enable_1_4_extensions(struct gl_context *ctx)
+{
+   ctx->Extensions.ARB_depth_texture = GL_TRUE;
+   ctx->Extensions.ARB_shadow = GL_TRUE;
+   ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
+   ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
+   ctx->Extensions.ARB_window_pos = GL_TRUE;
+   ctx->Extensions.EXT_blend_color = GL_TRUE;
+   ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
+   ctx->Extensions.EXT_blend_minmax = GL_TRUE;
+   ctx->Extensions.EXT_blend_subtract = GL_TRUE;
+   ctx->Extensions.EXT_fog_coord = GL_TRUE;
+   /*ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;*/
+   ctx->Extensions.EXT_point_parameters = GL_TRUE;
+   ctx->Extensions.EXT_secondary_color = GL_TRUE;
+   ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
+   ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
+   /*ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;*/
+}
+
+
+/**
+ * Enable all OpenGL 1.5 features and extensions.
+ * A convenience function to be called by drivers.
+ */
+void
+_mesa_enable_1_5_extensions(struct gl_context *ctx)
+{
+   ctx->Extensions.ARB_occlusion_query = GL_TRUE;
+   /*ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;*/
+   ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
+}
+
+
+/**
+ * Enable all OpenGL 2.0 features and extensions.
+ * A convenience function to be called by drivers.
+ */
+void
+_mesa_enable_2_0_extensions(struct gl_context *ctx)
+{
+   /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
+#if FEATURE_ARB_fragment_shader
+   ctx->Extensions.ARB_fragment_shader = GL_TRUE;
+#endif
+   ctx->Extensions.ARB_point_sprite = GL_TRUE;
+   ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
+   ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
+#if FEATURE_ARB_shader_objects
+   ctx->Extensions.ARB_shader_objects = GL_TRUE;
+#endif
+#if FEATURE_ARB_shading_language_100
+   ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
+#endif
+   ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
+#if FEATURE_ARB_vertex_shader
+   ctx->Extensions.ARB_vertex_shader = GL_TRUE;
+#endif
+}
+
+
+/**
+ * Enable all OpenGL 2.1 features and extensions.
+ * A convenience function to be called by drivers.
+ */
+void
+_mesa_enable_2_1_extensions(struct gl_context *ctx)
+{
+#if FEATURE_EXT_pixel_buffer_object
+   ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
+#endif
+#if FEATURE_EXT_texture_sRGB
+   ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
+#endif
+}
+
+
+/**
+ * Either enable or disable the named extension.
+ * \return GL_TRUE for success, GL_FALSE if invalid extension name
+ */
+static GLboolean
+set_extension( struct gl_context *ctx, const char *name, GLboolean state )
+{
+   size_t offset;
+
+   if (ctx->Extensions.String) {
+      /* The string was already queried - can't change it now! */
+      _mesa_problem(ctx, "Trying to enable/disable extension after glGetString(GL_EXTENSIONS): %s", name);
+      return GL_FALSE;
+   }
+
+   offset = name_to_offset(name);
+   if (offset == 0) {
+      _mesa_problem(ctx, "Trying to enable/disable unknown extension %s",
+	            name);
+      return GL_FALSE;
+   } else if (offset == o(dummy_true) && state == GL_FALSE) {
+      _mesa_problem(ctx, "Trying to disable a permanently enabled extension: "
+	                  "%s", name);
+      return GL_FALSE;
+   } else {
+      GLboolean *base = (GLboolean *) &ctx->Extensions;
+      base[offset] = state;
+      return GL_TRUE;
+   }
+}
+
+
+/**
+ * Enable the named extension.
+ * Typically called by drivers.
+ */
+void
+_mesa_enable_extension( struct gl_context *ctx, const char *name )
+{
+   if (!set_extension(ctx, name, GL_TRUE))
+      _mesa_problem(ctx, "Trying to enable unknown extension: %s", name);
+}
+
+
+/**
+ * Disable the named extension.
+ * XXX is this really needed???
+ */
+void
+_mesa_disable_extension( struct gl_context *ctx, const char *name )
+{
+   if (!set_extension(ctx, name, GL_FALSE))
+      _mesa_problem(ctx, "Trying to disable unknown extension: %s", name);
+}
+
+
+/**
+ * Test if the named extension is enabled in this context.
+ */
+GLboolean
+_mesa_extension_is_enabled( struct gl_context *ctx, const char *name )
+{
+   size_t offset;
+   GLboolean *base;
+
+   if (name == 0)
+      return GL_FALSE;
+
+   offset = name_to_offset(name);
+   if (offset == 0)
+      return GL_FALSE;
+   base = (GLboolean *) &ctx->Extensions;
+   return base[offset];
+}
+
+
+/**
+ * \brief Apply the \c MESA_EXTENSION_OVERRIDE environment variable.
+ *
+ * \c MESA_EXTENSION_OVERRIDE is a space-separated list of extensions to
+ * enable or disable. The list is processed thus:
+ *    - Enable recognized extension names that are prefixed with '+'.
+ *    - Disable recognized extension names that are prefixed with '-'.
+ *    - Enable recognized extension names that are not prefixed.
+ *    - Collect unrecognized extension names in a new string.
+ *
+ * \return Space-separated list of unrecognized extension names (which must
+ *    be freed). Does not return \c NULL.
+ */
+static char *
+get_extension_override( struct gl_context *ctx )
+{
+   const char *env_const= _mesa_getenv("MESA_EXTENSION_OVERRIDE");
+   char *env;
+   char *ext;
+   char *extra_exts;
+   int len;
+
+   if (env_const == NULL) {
+      /* Return the empty string rather than NULL. This simplifies the logic
+       * of client functions. */
+      return calloc(1, sizeof(char));
+   }
+
+   /* extra_exts: List of unrecognized extensions. */
+   extra_exts = calloc(strlen(env_const), sizeof(char));
+
+   /* Copy env_const because strtok() is destructive. */
+   env = strdup(env_const);
+   for (ext = strtok(env, " "); ext != NULL; ext = strtok(NULL, " ")) {
+      int enable;
+      int recognized;
+      switch (ext[0]) {
+      case '+':
+         enable = 1;
+         ++ext;
+         break;
+      case '-':
+         enable = 0;
+         ++ext;
+         break;
+      default:
+         enable = 1;
+         break;
+      }
+      recognized = set_extension(ctx, ext, enable);
+      if (!recognized) {
+         strcat(extra_exts, ext);
+         strcat(extra_exts, " ");
+      }
+   }
+
+   /* Remove trailing space. */
+   len  = strlen(extra_exts);
+   if (extra_exts[len - 1] == ' ')
+      extra_exts[len - 1] = '\0';
+
+   return extra_exts;
+}
+
+
+/**
+ * \brief Initialize extension tables and enable default extensions.
+ *
+ * This should be called during context initialization.
+ * Note: Sets gl_extensions.dummy_true to true.
+ */
+void
+_mesa_init_extensions( struct gl_context *ctx )
+{
+   GLboolean *base = (GLboolean *) &ctx->Extensions;
+   GLboolean *sentinel = base + o(extension_sentinel);
+   GLboolean *i;
+   const size_t *j;
+
+   /* First, turn all extensions off. */
+   for (i = base; i != sentinel; ++i)
+      *i = GL_FALSE;
+
+   /* Then, selectively turn default extensions on. */
+   ctx->Extensions.dummy_true = GL_TRUE;
+   for (j = default_extensions; *j != 0; ++j)
+      base[*j] = GL_TRUE;
+}
+
+
+/**
+ * Construct the GL_EXTENSIONS string.  Called the first time that
+ * glGetString(GL_EXTENSIONS) is called.
+ */
+GLubyte*
+_mesa_make_extension_string(struct gl_context *ctx)
+{
+   /* The extension string. */
+   char *exts = 0;
+   /* Length of extension string. */
+   size_t length = 0;
+   /* String of extra extensions. */
+   char *extra_extensions = get_extension_override(ctx);
+   GLboolean *base = (GLboolean *) &ctx->Extensions;
+   const struct extension *i;
+
+   /* Compute length of the extension string. */
+   for (i = extension_table; i->name != 0; ++i) {
+      if (base[i->offset] && (i->api_set & (1 << ctx->API))) {
+	 length += strlen(i->name) + 1; /* +1 for space */
+      }
+   }
+   if (extra_extensions != NULL)
+      length += 1 + strlen(extra_extensions); /* +1 for space */
+
+   exts = (char *) calloc(length + 1, sizeof(char));
+   if (exts == NULL) {
+      free(extra_extensions);
+      return NULL;
+   }
+
+   /* Build the extension string.*/
+   for (i = extension_table; i->name != 0; ++i) {
+      if (base[i->offset] && (i->api_set & (1 << ctx->API))) {
+         strcat(exts, i->name);
+         strcat(exts, " ");
+      }
+   }
+   if (extra_extensions != 0) {
+      strcat(exts, extra_extensions);
+      free(extra_extensions);
+   }
+
+   return (GLubyte *) exts;
+}
+
+/**
+ * Return number of enabled extensions.
+ */
+GLuint
+_mesa_get_extension_count(struct gl_context *ctx)
+{
+   GLboolean *base;
+   const struct extension *i;
+
+   /* only count once */
+   if (ctx->Extensions.Count != 0)
+      return ctx->Extensions.Count;
+
+   base = (GLboolean *) &ctx->Extensions;
+   for (i = extension_table; i->name != 0; ++i) {
+      if (base[i->offset]) {
+	 ctx->Extensions.Count++;
+      }
+   }
+   return ctx->Extensions.Count;
+}
+
+/**
+ * Return name of i-th enabled extension
+ */
+const GLubyte *
+_mesa_get_enabled_extension(struct gl_context *ctx, GLuint index)
+{
+   const GLboolean *base;
+   size_t n;
+   const struct extension *i;
+
+   if (index < 0)
+      return NULL;
+
+   base = (GLboolean*) &ctx->Extensions;
+   n = 0;
+   for (i = extension_table; i->name != 0; ++i) {
+      if (n == index && base[i->offset]) {
+	 return (GLubyte*) i->name;
+      } else if (base[i->offset]) {
+	 ++n;
+      }
+   }
+
+   return NULL;
+}
diff --git a/mesalib/src/mesa/main/fbobject.c b/mesalib/src/mesa/main/fbobject.c
index 2fe84754b..f20689b82 100644
--- a/mesalib/src/mesa/main/fbobject.c
+++ b/mesalib/src/mesa/main/fbobject.c
@@ -1,2486 +1,2487 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.1
- *
- * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
- * Copyright (C) 1999-2009  VMware, Inc.  All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/*
- * GL_EXT/ARB_framebuffer_object extensions
- *
- * Authors:
- *   Brian Paul
- */
-
-
-#include "buffers.h"
-#include "context.h"
-#include "enums.h"
-#include "fbobject.h"
-#include "formats.h"
-#include "framebuffer.h"
-#include "hash.h"
-#include "macros.h"
-#include "mfeatures.h"
-#include "mtypes.h"
-#include "renderbuffer.h"
-#include "state.h"
-#include "teximage.h"
-#include "texobj.h"
-
-
-/** Set this to 1 to help debug FBO incompleteness problems */
-#define DEBUG_FBO 0
-
-/** Set this to 1 to debug/log glBlitFramebuffer() calls */
-#define DEBUG_BLIT 0
-
-
-/**
- * Notes:
- *
- * None of the GL_EXT_framebuffer_object functions are compiled into
- * display lists.
- */
-
-
-
-/*
- * When glGenRender/FramebuffersEXT() is called we insert pointers to
- * these placeholder objects into the hash table.
- * Later, when the object ID is first bound, we replace the placeholder
- * with the real frame/renderbuffer.
- */
-static struct gl_framebuffer DummyFramebuffer;
-static struct gl_renderbuffer DummyRenderbuffer;
-
-/* We bind this framebuffer when applications pass a NULL
- * drawable/surface in make current. */
-static struct gl_framebuffer IncompleteFramebuffer;
-
-
-#define IS_CUBE_FACE(TARGET) \
-   ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
-    (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
-
-
-static void
-delete_dummy_renderbuffer(struct gl_renderbuffer *rb)
-{
-   /* no op */
-}
-
-static void
-delete_dummy_framebuffer(struct gl_framebuffer *fb)
-{
-   /* no op */
-}
-
-
-void
-_mesa_init_fbobjects(struct gl_context *ctx)
-{
-   _glthread_INIT_MUTEX(DummyFramebuffer.Mutex);
-   _glthread_INIT_MUTEX(DummyRenderbuffer.Mutex);
-   _glthread_INIT_MUTEX(IncompleteFramebuffer.Mutex);
-   DummyFramebuffer.Delete = delete_dummy_framebuffer;
-   DummyRenderbuffer.Delete = delete_dummy_renderbuffer;
-   IncompleteFramebuffer.Delete = delete_dummy_framebuffer;
-}
-
-struct gl_framebuffer *
-_mesa_get_incomplete_framebuffer(void)
-{
-   return &IncompleteFramebuffer;
-}
-
-/**
- * Helper routine for getting a gl_renderbuffer.
- */
-struct gl_renderbuffer *
-_mesa_lookup_renderbuffer(struct gl_context *ctx, GLuint id)
-{
-   struct gl_renderbuffer *rb;
-
-   if (id == 0)
-      return NULL;
-
-   rb = (struct gl_renderbuffer *)
-      _mesa_HashLookup(ctx->Shared->RenderBuffers, id);
-   return rb;
-}
-
-
-/**
- * Helper routine for getting a gl_framebuffer.
- */
-struct gl_framebuffer *
-_mesa_lookup_framebuffer(struct gl_context *ctx, GLuint id)
-{
-   struct gl_framebuffer *fb;
-
-   if (id == 0)
-      return NULL;
-
-   fb = (struct gl_framebuffer *)
-      _mesa_HashLookup(ctx->Shared->FrameBuffers, id);
-   return fb;
-}
-
-
-/**
- * Mark the given framebuffer as invalid.  This will force the
- * test for framebuffer completeness to be done before the framebuffer
- * is used.
- */
-static void
-invalidate_framebuffer(struct gl_framebuffer *fb)
-{
-   fb->_Status = 0; /* "indeterminate" */
-}
-
-
-/**
- * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
- * gl_renderbuffer_attachment object.
- * This function is only used for user-created FB objects, not the
- * default / window-system FB object.
- * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
- * the depth buffer attachment point.
- */
-struct gl_renderbuffer_attachment *
-_mesa_get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
-                     GLenum attachment)
-{
-   GLuint i;
-
-   assert(fb->Name > 0);
-
-   switch (attachment) {
-   case GL_COLOR_ATTACHMENT0_EXT:
-   case GL_COLOR_ATTACHMENT1_EXT:
-   case GL_COLOR_ATTACHMENT2_EXT:
-   case GL_COLOR_ATTACHMENT3_EXT:
-   case GL_COLOR_ATTACHMENT4_EXT:
-   case GL_COLOR_ATTACHMENT5_EXT:
-   case GL_COLOR_ATTACHMENT6_EXT:
-   case GL_COLOR_ATTACHMENT7_EXT:
-   case GL_COLOR_ATTACHMENT8_EXT:
-   case GL_COLOR_ATTACHMENT9_EXT:
-   case GL_COLOR_ATTACHMENT10_EXT:
-   case GL_COLOR_ATTACHMENT11_EXT:
-   case GL_COLOR_ATTACHMENT12_EXT:
-   case GL_COLOR_ATTACHMENT13_EXT:
-   case GL_COLOR_ATTACHMENT14_EXT:
-   case GL_COLOR_ATTACHMENT15_EXT:
-      i = attachment - GL_COLOR_ATTACHMENT0_EXT;
-      if (i >= ctx->Const.MaxColorAttachments) {
-	 return NULL;
-      }
-      return &fb->Attachment[BUFFER_COLOR0 + i];
-   case GL_DEPTH_STENCIL_ATTACHMENT:
-      /* fall-through */
-   case GL_DEPTH_BUFFER:
-      /* fall-through / new in GL 3.0 */
-   case GL_DEPTH_ATTACHMENT_EXT:
-      return &fb->Attachment[BUFFER_DEPTH];
-   case GL_STENCIL_BUFFER:
-      /* fall-through / new in GL 3.0 */
-   case GL_STENCIL_ATTACHMENT_EXT:
-      return &fb->Attachment[BUFFER_STENCIL];
-   default:
-      return NULL;
-   }
-}
-
-
-/**
- * As above, but only used for getting attachments of the default /
- * window-system framebuffer (not user-created framebuffer objects).
- */
-static struct gl_renderbuffer_attachment *
-_mesa_get_fb0_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
-                         GLenum attachment)
-{
-   assert(fb->Name == 0);
-
-   switch (attachment) {
-   case GL_FRONT_LEFT:
-      return &fb->Attachment[BUFFER_FRONT_LEFT];
-   case GL_FRONT_RIGHT:
-      return &fb->Attachment[BUFFER_FRONT_RIGHT];
-   case GL_BACK_LEFT:
-      return &fb->Attachment[BUFFER_BACK_LEFT];
-   case GL_BACK_RIGHT:
-      return &fb->Attachment[BUFFER_BACK_RIGHT];
-   case GL_AUX0:
-      if (fb->Visual.numAuxBuffers == 1) {
-         return &fb->Attachment[BUFFER_AUX0];
-      }
-      return NULL;
-   case GL_DEPTH_BUFFER:
-      /* fall-through / new in GL 3.0 */
-   case GL_DEPTH_ATTACHMENT_EXT:
-      return &fb->Attachment[BUFFER_DEPTH];
-   case GL_STENCIL_BUFFER:
-      /* fall-through / new in GL 3.0 */
-   case GL_STENCIL_ATTACHMENT_EXT:
-      return &fb->Attachment[BUFFER_STENCIL];
-   default:
-      return NULL;
-   }
-}
-
-
-
-/**
- * Remove any texture or renderbuffer attached to the given attachment
- * point.  Update reference counts, etc.
- */
-void
-_mesa_remove_attachment(struct gl_context *ctx,
-                        struct gl_renderbuffer_attachment *att)
-{
-   if (att->Type == GL_TEXTURE) {
-      ASSERT(att->Texture);
-      if (ctx->Driver.FinishRenderTexture) {
-         /* tell driver that we're done rendering to this texture. */
-         ctx->Driver.FinishRenderTexture(ctx, att);
-      }
-      _mesa_reference_texobj(&att->Texture, NULL); /* unbind */
-      ASSERT(!att->Texture);
-   }
-   if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) {
-      ASSERT(!att->Texture);
-      _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */
-      ASSERT(!att->Renderbuffer);
-   }
-   att->Type = GL_NONE;
-   att->Complete = GL_TRUE;
-}
-
-
-/**
- * Bind a texture object to an attachment point.
- * The previous binding, if any, will be removed first.
- */
-void
-_mesa_set_texture_attachment(struct gl_context *ctx,
-                             struct gl_framebuffer *fb,
-                             struct gl_renderbuffer_attachment *att,
-                             struct gl_texture_object *texObj,
-                             GLenum texTarget, GLuint level, GLuint zoffset)
-{
-   if (att->Texture == texObj) {
-      /* re-attaching same texture */
-      ASSERT(att->Type == GL_TEXTURE);
-      if (ctx->Driver.FinishRenderTexture)
-	 ctx->Driver.FinishRenderTexture(ctx, att);
-   }
-   else {
-      /* new attachment */
-      if (ctx->Driver.FinishRenderTexture && att->Texture)
-	 ctx->Driver.FinishRenderTexture(ctx, att);
-      _mesa_remove_attachment(ctx, att);
-      att->Type = GL_TEXTURE;
-      assert(!att->Texture);
-      _mesa_reference_texobj(&att->Texture, texObj);
-   }
-
-   /* always update these fields */
-   att->TextureLevel = level;
-   att->CubeMapFace = _mesa_tex_target_to_face(texTarget);
-   att->Zoffset = zoffset;
-   att->Complete = GL_FALSE;
-
-   if (att->Texture->Image[att->CubeMapFace][att->TextureLevel]) {
-      ctx->Driver.RenderTexture(ctx, fb, att);
-   }
-
-   invalidate_framebuffer(fb);
-}
-
-
-/**
- * Bind a renderbuffer to an attachment point.
- * The previous binding, if any, will be removed first.
- */
-void
-_mesa_set_renderbuffer_attachment(struct gl_context *ctx,
-                                  struct gl_renderbuffer_attachment *att,
-                                  struct gl_renderbuffer *rb)
-{
-   /* XXX check if re-doing same attachment, exit early */
-   _mesa_remove_attachment(ctx, att);
-   att->Type = GL_RENDERBUFFER_EXT;
-   att->Texture = NULL; /* just to be safe */
-   att->Complete = GL_FALSE;
-   _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
-}
-
-
-/**
- * Fallback for ctx->Driver.FramebufferRenderbuffer()
- * Attach a renderbuffer object to a framebuffer object.
- */
-void
-_mesa_framebuffer_renderbuffer(struct gl_context *ctx,
-                               struct gl_framebuffer *fb,
-                               GLenum attachment, struct gl_renderbuffer *rb)
-{
-   struct gl_renderbuffer_attachment *att;
-
-   _glthread_LOCK_MUTEX(fb->Mutex);
-
-   att = _mesa_get_attachment(ctx, fb, attachment);
-   ASSERT(att);
-   if (rb) {
-      _mesa_set_renderbuffer_attachment(ctx, att, rb);
-      if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
-         /* do stencil attachment here (depth already done above) */
-         att = _mesa_get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT);
-         assert(att);
-         _mesa_set_renderbuffer_attachment(ctx, att, rb);
-      }
-   }
-   else {
-      _mesa_remove_attachment(ctx, att);
-   }
-
-   invalidate_framebuffer(fb);
-
-   _glthread_UNLOCK_MUTEX(fb->Mutex);
-}
-
-
-/**
- * Fallback for ctx->Driver.ValidateFramebuffer()
- * Check if the renderbuffer's formats are supported by the software
- * renderer.
- * Drivers should probably override this.
- */
-void
-_mesa_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
-{
-   gl_buffer_index buf;
-   for (buf = 0; buf < BUFFER_COUNT; buf++) {
-      const struct gl_renderbuffer *rb = fb->Attachment[buf].Renderbuffer;
-      if (rb) {
-         switch (rb->_BaseFormat) {
-         case GL_ALPHA:
-         case GL_LUMINANCE_ALPHA:
-         case GL_LUMINANCE:
-         case GL_INTENSITY:
-         case GL_RED:
-         case GL_RG:
-            fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
-            return;
-         default:
-            /* render buffer format is supported by software rendering */
-            ;
-         }
-      }
-   }
-}
-
-
-/**
- * For debug only.
- */
-static void
-att_incomplete(const char *msg)
-{
-#if DEBUG_FBO
-   _mesa_debug(NULL, "attachment incomplete: %s\n", msg);
-#else
-   (void) msg;
-#endif
-}
-
-
-/**
- * For debug only.
- */
-static void
-fbo_incomplete(const char *msg, int index)
-{
-#if DEBUG_FBO
-   _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
-#else
-   (void) msg;
-   (void) index;
-#endif
-}
-
-
-/**
- * Is the given base format a legal format for a color renderbuffer?
- */
-GLboolean
-_mesa_is_legal_color_format(const struct gl_context *ctx, GLenum baseFormat)
-{
-   switch (baseFormat) {
-   case GL_RGB:
-   case GL_RGBA:
-      return GL_TRUE;
-   case GL_LUMINANCE:
-   case GL_LUMINANCE_ALPHA:
-   case GL_INTENSITY:
-   case GL_ALPHA:
-      return ctx->Extensions.ARB_framebuffer_object;
-   case GL_RED:
-   case GL_RG:
-      return ctx->Extensions.ARB_texture_rg;
-   default:
-      return GL_FALSE;
-   }
-}
-
-
-/**
- * Is the given base format a legal format for a depth/stencil renderbuffer?
- */
-static GLboolean
-is_legal_depth_format(const struct gl_context *ctx, GLenum baseFormat)
-{
-   switch (baseFormat) {
-   case GL_DEPTH_COMPONENT:
-   case GL_DEPTH_STENCIL_EXT:
-      return GL_TRUE;
-   default:
-      return GL_FALSE;
-   }
-}
-
-
-/**
- * Test if an attachment point is complete and update its Complete field.
- * \param format if GL_COLOR, this is a color attachment point,
- *               if GL_DEPTH, this is a depth component attachment point,
- *               if GL_STENCIL, this is a stencil component attachment point.
- */
-static void
-test_attachment_completeness(const struct gl_context *ctx, GLenum format,
-                             struct gl_renderbuffer_attachment *att)
-{
-   assert(format == GL_COLOR || format == GL_DEPTH || format == GL_STENCIL);
-
-   /* assume complete */
-   att->Complete = GL_TRUE;
-
-   /* Look for reasons why the attachment might be incomplete */
-   if (att->Type == GL_TEXTURE) {
-      const struct gl_texture_object *texObj = att->Texture;
-      struct gl_texture_image *texImage;
-      GLenum baseFormat;
-
-      if (!texObj) {
-         att_incomplete("no texobj");
-         att->Complete = GL_FALSE;
-         return;
-      }
-
-      texImage = texObj->Image[att->CubeMapFace][att->TextureLevel];
-      if (!texImage) {
-         att_incomplete("no teximage");
-         att->Complete = GL_FALSE;
-         return;
-      }
-      if (texImage->Width < 1 || texImage->Height < 1) {
-         att_incomplete("teximage width/height=0");
-         printf("texobj = %u\n", texObj->Name);
-         printf("level = %d\n", att->TextureLevel);
-         att->Complete = GL_FALSE;
-         return;
-      }
-      if (texObj->Target == GL_TEXTURE_3D && att->Zoffset >= texImage->Depth) {
-         att_incomplete("bad z offset");
-         att->Complete = GL_FALSE;
-         return;
-      }
-
-      baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
-
-      if (format == GL_COLOR) {
-         if (!_mesa_is_legal_color_format(ctx, baseFormat)) {
-            att_incomplete("bad format");
-            att->Complete = GL_FALSE;
-            return;
-         }
-         if (_mesa_is_format_compressed(texImage->TexFormat)) {
-            att_incomplete("compressed internalformat");
-            att->Complete = GL_FALSE;
-            return;
-         }
-      }
-      else if (format == GL_DEPTH) {
-         if (baseFormat == GL_DEPTH_COMPONENT) {
-            /* OK */
-         }
-         else if (ctx->Extensions.EXT_packed_depth_stencil &&
-                  ctx->Extensions.ARB_depth_texture &&
-                  baseFormat == GL_DEPTH_STENCIL_EXT) {
-            /* OK */
-         }
-         else {
-            att->Complete = GL_FALSE;
-            att_incomplete("bad depth format");
-            return;
-         }
-      }
-      else {
-         ASSERT(format == GL_STENCIL);
-         if (ctx->Extensions.EXT_packed_depth_stencil &&
-             ctx->Extensions.ARB_depth_texture &&
-             baseFormat == GL_DEPTH_STENCIL_EXT) {
-            /* OK */
-         }
-         else {
-            /* no such thing as stencil-only textures */
-            att_incomplete("illegal stencil texture");
-            att->Complete = GL_FALSE;
-            return;
-         }
-      }
-   }
-   else if (att->Type == GL_RENDERBUFFER_EXT) {
-      const GLenum baseFormat =
-         _mesa_get_format_base_format(att->Renderbuffer->Format);
-
-      ASSERT(att->Renderbuffer);
-      if (!att->Renderbuffer->InternalFormat ||
-          att->Renderbuffer->Width < 1 ||
-          att->Renderbuffer->Height < 1) {
-         att_incomplete("0x0 renderbuffer");
-         att->Complete = GL_FALSE;
-         return;
-      }
-      if (format == GL_COLOR) {
-         if (!_mesa_is_legal_color_format(ctx, baseFormat)) {
-            att_incomplete("bad renderbuffer color format");
-            att->Complete = GL_FALSE;
-            return;
-         }
-      }
-      else if (format == GL_DEPTH) {
-         if (baseFormat == GL_DEPTH_COMPONENT) {
-            /* OK */
-         }
-         else if (ctx->Extensions.EXT_packed_depth_stencil &&
-                  baseFormat == GL_DEPTH_STENCIL_EXT) {
-            /* OK */
-         }
-         else {
-            att_incomplete("bad renderbuffer depth format");
-            att->Complete = GL_FALSE;
-            return;
-         }
-      }
-      else {
-         assert(format == GL_STENCIL);
-         if (baseFormat == GL_STENCIL_INDEX) {
-            /* OK */
-         }
-         else if (ctx->Extensions.EXT_packed_depth_stencil &&
-                  baseFormat == GL_DEPTH_STENCIL_EXT) {
-            /* OK */
-         }
-         else {
-            att->Complete = GL_FALSE;
-            att_incomplete("bad renderbuffer stencil format");
-            return;
-         }
-      }
-   }
-   else {
-      ASSERT(att->Type == GL_NONE);
-      /* complete */
-      return;
-   }
-}
-
-
-/**
- * Test if the given framebuffer object is complete and update its
- * Status field with the results.
- * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
- * driver to make hardware-specific validation/completeness checks.
- * Also update the framebuffer's Width and Height fields if the
- * framebuffer is complete.
- */
-void
-_mesa_test_framebuffer_completeness(struct gl_context *ctx,
-                                    struct gl_framebuffer *fb)
-{
-   GLuint numImages;
-   GLenum intFormat = GL_NONE; /* color buffers' internal format */
-   GLuint minWidth = ~0, minHeight = ~0, maxWidth = 0, maxHeight = 0;
-   GLint numSamples = -1;
-   GLint i;
-   GLuint j;
-
-   assert(fb->Name != 0);
-
-   numImages = 0;
-   fb->Width = 0;
-   fb->Height = 0;
-
-   /* Start at -2 to more easily loop over all attachment points.
-    *  -2: depth buffer
-    *  -1: stencil buffer
-    * >=0: color buffer
-    */
-   for (i = -2; i < (GLint) ctx->Const.MaxColorAttachments; i++) {
-      struct gl_renderbuffer_attachment *att;
-      GLenum f;
-      gl_format mesaFormat;
-
-      /*
-       * XXX for ARB_fbo, only check color buffers that are named by
-       * GL_READ_BUFFER and GL_DRAW_BUFFERi.
-       */
-
-      /* check for attachment completeness
-       */
-      if (i == -2) {
-         att = &fb->Attachment[BUFFER_DEPTH];
-         test_attachment_completeness(ctx, GL_DEPTH, att);
-         if (!att->Complete) {
-            fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
-            fbo_incomplete("depth attachment incomplete", -1);
-            return;
-         }
-      }
-      else if (i == -1) {
-         att = &fb->Attachment[BUFFER_STENCIL];
-         test_attachment_completeness(ctx, GL_STENCIL, att);
-         if (!att->Complete) {
-            fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
-            fbo_incomplete("stencil attachment incomplete", -1);
-            return;
-         }
-      }
-      else {
-         att = &fb->Attachment[BUFFER_COLOR0 + i];
-         test_attachment_completeness(ctx, GL_COLOR, att);
-         if (!att->Complete) {
-            fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
-            fbo_incomplete("color attachment incomplete", i);
-            return;
-         }
-      }
-
-      /* get width, height, format of the renderbuffer/texture
-       */
-      if (att->Type == GL_TEXTURE) {
-         const struct gl_texture_image *texImg
-            = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
-         minWidth = MIN2(minWidth, texImg->Width);
-         maxWidth = MAX2(maxWidth, texImg->Width);
-         minHeight = MIN2(minHeight, texImg->Height);
-         maxHeight = MAX2(maxHeight, texImg->Height);
-         f = texImg->_BaseFormat;
-         mesaFormat = texImg->TexFormat;
-         numImages++;
-         if (!_mesa_is_legal_color_format(ctx, f) &&
-             !is_legal_depth_format(ctx, f)) {
-            fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
-            fbo_incomplete("texture attachment incomplete", -1);
-            return;
-         }
-      }
-      else if (att->Type == GL_RENDERBUFFER_EXT) {
-         minWidth = MIN2(minWidth, att->Renderbuffer->Width);
-         maxWidth = MAX2(minWidth, att->Renderbuffer->Width);
-         minHeight = MIN2(minHeight, att->Renderbuffer->Height);
-         maxHeight = MAX2(minHeight, att->Renderbuffer->Height);
-         f = att->Renderbuffer->InternalFormat;
-         mesaFormat = att->Renderbuffer->Format;
-         numImages++;
-      }
-      else {
-         assert(att->Type == GL_NONE);
-         continue;
-      }
-
-      if (numSamples < 0) {
-         /* first buffer */
-         numSamples = att->Renderbuffer->NumSamples;
-      }
-
-      /* check if integer color */
-      fb->_IntegerColor = _mesa_is_format_integer_color(mesaFormat);
-
-      /* Error-check width, height, format, samples
-       */
-      if (numImages == 1) {
-         /* save format, num samples */
-         if (i >= 0) {
-            intFormat = f;
-         }
-      }
-      else {
-         if (!ctx->Extensions.ARB_framebuffer_object) {
-            /* check that width, height, format are same */
-            if (minWidth != maxWidth || minHeight != maxHeight) {
-               fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT;
-               fbo_incomplete("width or height mismatch", -1);
-               return;
-            }
-            /* check that all color buffer have same format */
-            if (intFormat != GL_NONE && f != intFormat) {
-               fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
-               fbo_incomplete("format mismatch", -1);
-               return;
-            }
-         }
-         if (att->Renderbuffer &&
-             att->Renderbuffer->NumSamples != numSamples) {
-            fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
-            fbo_incomplete("inconsistant number of samples", i);
-            return;
-         }            
-
-      }
-   }
-
-#if FEATURE_GL
-   if (ctx->API == API_OPENGL) {
-      /* Check that all DrawBuffers are present */
-      for (j = 0; j < ctx->Const.MaxDrawBuffers; j++) {
-	 if (fb->ColorDrawBuffer[j] != GL_NONE) {
-	    const struct gl_renderbuffer_attachment *att
-	       = _mesa_get_attachment(ctx, fb, fb->ColorDrawBuffer[j]);
-	    assert(att);
-	    if (att->Type == GL_NONE) {
-	       fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT;
-	       fbo_incomplete("missing drawbuffer", j);
-	       return;
-	    }
-	 }
-      }
-
-      /* Check that the ReadBuffer is present */
-      if (fb->ColorReadBuffer != GL_NONE) {
-	 const struct gl_renderbuffer_attachment *att
-	    = _mesa_get_attachment(ctx, fb, fb->ColorReadBuffer);
-	 assert(att);
-	 if (att->Type == GL_NONE) {
-	    fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT;
-            fbo_incomplete("missing readbuffer", -1);
-	    return;
-	 }
-      }
-   }
-#else
-   (void) j;
-#endif
-
-   if (numImages == 0) {
-      fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT;
-      fbo_incomplete("no attachments", -1);
-      return;
-   }
-
-   /* Provisionally set status = COMPLETE ... */
-   fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT;
-
-   /* ... but the driver may say the FB is incomplete.
-    * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
-    * if anything.
-    */
-   if (ctx->Driver.ValidateFramebuffer) {
-      ctx->Driver.ValidateFramebuffer(ctx, fb);
-      if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
-         fbo_incomplete("driver marked FBO as incomplete", -1);
-      }
-   }
-
-   if (fb->_Status == GL_FRAMEBUFFER_COMPLETE_EXT) {
-      /*
-       * Note that if ARB_framebuffer_object is supported and the attached
-       * renderbuffers/textures are different sizes, the framebuffer
-       * width/height will be set to the smallest width/height.
-       */
-      fb->Width = minWidth;
-      fb->Height = minHeight;
-
-      /* finally, update the visual info for the framebuffer */
-      _mesa_update_framebuffer_visual(ctx, fb);
-   }
-}
-
-
-GLboolean GLAPIENTRY
-_mesa_IsRenderbufferEXT(GLuint renderbuffer)
-{
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
-   if (renderbuffer) {
-      struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
-      if (rb != NULL && rb != &DummyRenderbuffer)
-         return GL_TRUE;
-   }
-   return GL_FALSE;
-}
-
-
-void GLAPIENTRY
-_mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer)
-{
-   struct gl_renderbuffer *newRb;
-   GET_CURRENT_CONTEXT(ctx);
-
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if (target != GL_RENDERBUFFER_EXT) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glBindRenderbufferEXT(target)");
-      return;
-   }
-
-   /* No need to flush here since the render buffer binding has no
-    * effect on rendering state.
-    */
-
-   if (renderbuffer) {
-      newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
-      if (newRb == &DummyRenderbuffer) {
-         /* ID was reserved, but no real renderbuffer object made yet */
-         newRb = NULL;
-      }
-      else if (!newRb && ctx->Extensions.ARB_framebuffer_object) {
-         /* All RB IDs must be Gen'd */
-         _mesa_error(ctx, GL_INVALID_OPERATION, "glBindRenderbuffer(buffer)");
-         return;
-      }
-
-      if (!newRb) {
-	 /* create new renderbuffer object */
-	 newRb = ctx->Driver.NewRenderbuffer(ctx, renderbuffer);
-	 if (!newRb) {
-	    _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindRenderbufferEXT");
-	    return;
-	 }
-         ASSERT(newRb->AllocStorage);
-         _mesa_HashInsert(ctx->Shared->RenderBuffers, renderbuffer, newRb);
-         newRb->RefCount = 1; /* referenced by hash table */
-      }
-   }
-   else {
-      newRb = NULL;
-   }
-
-   ASSERT(newRb != &DummyRenderbuffer);
-
-   _mesa_reference_renderbuffer(&ctx->CurrentRenderbuffer, newRb);
-}
-
-
-/**
- * If the given renderbuffer is anywhere attached to the framebuffer, detach
- * the renderbuffer.
- * This is used when a renderbuffer object is deleted.
- * The spec calls for unbinding.
- */
-static void
-detach_renderbuffer(struct gl_context *ctx,
-                    struct gl_framebuffer *fb,
-                    struct gl_renderbuffer *rb)
-{
-   GLuint i;
-   for (i = 0; i < BUFFER_COUNT; i++) {
-      if (fb->Attachment[i].Renderbuffer == rb) {
-         _mesa_remove_attachment(ctx, &fb->Attachment[i]);
-      }
-   }
-   invalidate_framebuffer(fb);
-}
-
-
-void GLAPIENTRY
-_mesa_DeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers)
-{
-   GLint i;
-   GET_CURRENT_CONTEXT(ctx);
-
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
-   for (i = 0; i < n; i++) {
-      if (renderbuffers[i] > 0) {
-	 struct gl_renderbuffer *rb;
-	 rb = _mesa_lookup_renderbuffer(ctx, renderbuffers[i]);
-	 if (rb) {
-            /* check if deleting currently bound renderbuffer object */
-            if (rb == ctx->CurrentRenderbuffer) {
-               /* bind default */
-               ASSERT(rb->RefCount >= 2);
-               _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
-            }
-
-            if (ctx->DrawBuffer->Name) {
-               detach_renderbuffer(ctx, ctx->DrawBuffer, rb);
-            }
-            if (ctx->ReadBuffer->Name && ctx->ReadBuffer != ctx->DrawBuffer) {
-               detach_renderbuffer(ctx, ctx->ReadBuffer, rb);
-            }
-
-	    /* Remove from hash table immediately, to free the ID.
-             * But the object will not be freed until it's no longer
-             * referenced anywhere else.
-             */
-	    _mesa_HashRemove(ctx->Shared->RenderBuffers, renderbuffers[i]);
-
-            if (rb != &DummyRenderbuffer) {
-               /* no longer referenced by hash table */
-               _mesa_reference_renderbuffer(&rb, NULL);
-	    }
-	 }
-      }
-   }
-}
-
-
-void GLAPIENTRY
-_mesa_GenRenderbuffersEXT(GLsizei n, GLuint *renderbuffers)
-{
-   GET_CURRENT_CONTEXT(ctx);
-   GLuint first;
-   GLint i;
-
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if (n < 0) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glGenRenderbuffersEXT(n)");
-      return;
-   }
-
-   if (!renderbuffers)
-      return;
-
-   first = _mesa_HashFindFreeKeyBlock(ctx->Shared->RenderBuffers, n);
-
-   for (i = 0; i < n; i++) {
-      GLuint name = first + i;
-      renderbuffers[i] = name;
-      /* insert dummy placeholder into hash table */
-      _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
-      _mesa_HashInsert(ctx->Shared->RenderBuffers, name, &DummyRenderbuffer);
-      _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
-   }
-}
-
-
-/**
- * Given an internal format token for a render buffer, return the
- * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
- * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
- * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
- *
- * This is similar to _mesa_base_tex_format() but the set of valid
- * internal formats is different.
- *
- * Note that even if a format is determined to be legal here, validation
- * of the FBO may fail if the format is not suppoted by the driver/GPU.
- *
- * \param internalFormat  as passed to glRenderbufferStorage()
- * \return the base internal format, or 0 if internalFormat is illegal
- */
-GLenum
-_mesa_base_fbo_format(struct gl_context *ctx, GLenum internalFormat)
-{
-   /*
-    * Notes: some formats such as alpha, luminance, etc. were added
-    * with GL_ARB_framebuffer_object.
-    */
-   switch (internalFormat) {
-   case GL_ALPHA:
-   case GL_ALPHA4:
-   case GL_ALPHA8:
-   case GL_ALPHA12:
-   case GL_ALPHA16:
-      return ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
-   case GL_LUMINANCE:
-   case GL_LUMINANCE4:
-   case GL_LUMINANCE8:
-   case GL_LUMINANCE12:
-   case GL_LUMINANCE16:
-      return ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
-   case GL_LUMINANCE_ALPHA:
-   case GL_LUMINANCE4_ALPHA4:
-   case GL_LUMINANCE6_ALPHA2:
-   case GL_LUMINANCE8_ALPHA8:
-   case GL_LUMINANCE12_ALPHA4:
-   case GL_LUMINANCE12_ALPHA12:
-   case GL_LUMINANCE16_ALPHA16:
-      return ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
-   case GL_INTENSITY:
-   case GL_INTENSITY4:
-   case GL_INTENSITY8:
-   case GL_INTENSITY12:
-   case GL_INTENSITY16:
-      return ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
-   case GL_RGB:
-   case GL_R3_G3_B2:
-   case GL_RGB4:
-   case GL_RGB5:
-   case GL_RGB8:
-   case GL_RGB10:
-   case GL_RGB12:
-   case GL_RGB16:
-   case GL_SRGB8_EXT:
-      return GL_RGB;
-   case GL_RGBA:
-   case GL_RGBA2:
-   case GL_RGBA4:
-   case GL_RGB5_A1:
-   case GL_RGBA8:
-   case GL_RGB10_A2:
-   case GL_RGBA12:
-   case GL_RGBA16:
-   case GL_RGBA16_SNORM:
-   case GL_SRGB8_ALPHA8_EXT:
-      return GL_RGBA;
-   case GL_STENCIL_INDEX:
-   case GL_STENCIL_INDEX1_EXT:
-   case GL_STENCIL_INDEX4_EXT:
-   case GL_STENCIL_INDEX8_EXT:
-   case GL_STENCIL_INDEX16_EXT:
-      return GL_STENCIL_INDEX;
-   case GL_DEPTH_COMPONENT:
-   case GL_DEPTH_COMPONENT16:
-   case GL_DEPTH_COMPONENT24:
-   case GL_DEPTH_COMPONENT32:
-      return GL_DEPTH_COMPONENT;
-   case GL_DEPTH_STENCIL_EXT:
-   case GL_DEPTH24_STENCIL8_EXT:
-      if (ctx->Extensions.EXT_packed_depth_stencil)
-         return GL_DEPTH_STENCIL_EXT;
-      else
-         return 0;
-   case GL_RED:
-   case GL_R8:
-   case GL_R16:
-      return ctx->Extensions.ARB_texture_rg ? GL_RED : 0;
-   case GL_RG:
-   case GL_RG8:
-   case GL_RG16:
-      return ctx->Extensions.ARB_texture_rg ? GL_RG : 0;
-   /* XXX add floating point and integer formats eventually */
-   default:
-      return 0;
-   }
-}
-
-
-/** sentinal value, see below */
-#define NO_SAMPLES 1000
-
-
-/**
- * Helper function used by _mesa_RenderbufferStorageEXT() and 
- * _mesa_RenderbufferStorageMultisample().
- * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
- */
-static void
-renderbuffer_storage(GLenum target, GLenum internalFormat,
-                     GLsizei width, GLsizei height, GLsizei samples)
-{
-   const char *func = samples == NO_SAMPLES ?
-      "glRenderbufferStorage" : "RenderbufferStorageMultisample";
-   struct gl_renderbuffer *rb;
-   GLenum baseFormat;
-   GET_CURRENT_CONTEXT(ctx);
-
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if (target != GL_RENDERBUFFER_EXT) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func);
-      return;
-   }
-
-   baseFormat = _mesa_base_fbo_format(ctx, internalFormat);
-   if (baseFormat == 0) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "%s(internalFormat)", func);
-      return;
-   }
-
-   if (width < 1 || width > (GLsizei) ctx->Const.MaxRenderbufferSize) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "%s(width)", func);
-      return;
-   }
-
-   if (height < 1 || height > (GLsizei) ctx->Const.MaxRenderbufferSize) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "%s(height)", func);
-      return;
-   }
-
-   if (samples == NO_SAMPLES) {
-      /* NumSamples == 0 indicates non-multisampling */
-      samples = 0;
-   }
-   else if (samples > (GLsizei) ctx->Const.MaxSamples) {
-      /* note: driver may choose to use more samples than what's requested */
-      _mesa_error(ctx, GL_INVALID_VALUE, "%s(samples)", func);
-      return;
-   }
-
-   rb = ctx->CurrentRenderbuffer;
-   if (!rb) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
-      return;
-   }
-
-   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
-   if (rb->InternalFormat == internalFormat &&
-       rb->Width == (GLuint) width &&
-       rb->Height == (GLuint) height) {
-      /* no change in allocation needed */
-      return;
-   }
-
-   /* These MUST get set by the AllocStorage func */
-   rb->Format = MESA_FORMAT_NONE;
-   rb->NumSamples = samples;
-
-   /* Now allocate the storage */
-   ASSERT(rb->AllocStorage);
-   if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) {
-      /* No error - check/set fields now */
-      assert(rb->Format != MESA_FORMAT_NONE);
-      assert(rb->Width == (GLuint) width);
-      assert(rb->Height == (GLuint) height);
-      rb->InternalFormat = internalFormat;
-      rb->_BaseFormat = baseFormat;
-      assert(rb->_BaseFormat != 0);
-   }
-   else {
-      /* Probably ran out of memory - clear the fields */
-      rb->Width = 0;
-      rb->Height = 0;
-      rb->Format = MESA_FORMAT_NONE;
-      rb->InternalFormat = GL_NONE;
-      rb->_BaseFormat = GL_NONE;
-      rb->NumSamples = 0;
-   }
-
-   /*
-   test_framebuffer_completeness(ctx, fb);
-   */
-   /* XXX if this renderbuffer is attached anywhere, invalidate attachment
-    * points???
-    */
-}
-
-
-#if FEATURE_OES_EGL_image
-void GLAPIENTRY
-_mesa_EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
-{
-   struct gl_renderbuffer *rb;
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if (!ctx->Extensions.OES_EGL_image) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glEGLImageTargetRenderbufferStorageOES(unsupported)");
-      return;
-   }
-
-   if (target != GL_RENDERBUFFER) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "EGLImageTargetRenderbufferStorageOES");
-      return;
-   }
-
-   rb = ctx->CurrentRenderbuffer;
-   if (!rb) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "EGLImageTargetRenderbufferStorageOES");
-      return;
-   }
-
-   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
-   ctx->Driver.EGLImageTargetRenderbufferStorage(ctx, rb, image);
-}
-#endif
-
-
-/**
- * Helper function for _mesa_GetRenderbufferParameterivEXT() and
- * _mesa_GetFramebufferAttachmentParameterivEXT()
- * We have to be careful to respect the base format.  For example, if a
- * renderbuffer/texture was created with internalFormat=GL_RGB but the
- * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
- * we need to return zero.
- */
-static GLint
-get_component_bits(GLenum pname, GLenum baseFormat, gl_format format)
-{
-   switch (pname) {
-   case GL_RENDERBUFFER_RED_SIZE_EXT:
-   case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
-      if (baseFormat == GL_RGB || baseFormat == GL_RGBA ||
-	  baseFormat == GL_RG || baseFormat == GL_RED)
-         return _mesa_get_format_bits(format, pname);
-      else
-         return 0;
-   case GL_RENDERBUFFER_GREEN_SIZE_EXT:
-   case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
-      if (baseFormat == GL_RGB || baseFormat == GL_RGBA || baseFormat == GL_RG)
-         return _mesa_get_format_bits(format, pname);
-      else
-         return 0;
-   case GL_RENDERBUFFER_BLUE_SIZE_EXT:
-   case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
-      if (baseFormat == GL_RGB || baseFormat == GL_RGBA)
-         return _mesa_get_format_bits(format, pname);
-      else
-         return 0;
-   case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
-   case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
-      if (baseFormat == GL_RGBA || baseFormat == GL_ALPHA ||
-	  baseFormat == GL_LUMINANCE_ALPHA)
-         return _mesa_get_format_bits(format, pname);
-      else
-         return 0;
-   case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
-   case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
-      if (baseFormat == GL_DEPTH_COMPONENT || baseFormat == GL_DEPTH_STENCIL)
-         return _mesa_get_format_bits(format, pname);
-      else
-         return 0;
-   case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
-   case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
-      if (baseFormat == GL_STENCIL_INDEX || baseFormat == GL_DEPTH_STENCIL)
-         return _mesa_get_format_bits(format, pname);
-      else
-         return 0;
-   default:
-      return 0;
-   }
-}
-
-
-
-void GLAPIENTRY
-_mesa_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
-                             GLsizei width, GLsizei height)
-{
-   /* GL_ARB_fbo says calling this function is equivalent to calling
-    * glRenderbufferStorageMultisample() with samples=0.  We pass in
-    * a token value here just for error reporting purposes.
-    */
-   renderbuffer_storage(target, internalFormat, width, height, NO_SAMPLES);
-}
-
-
-void GLAPIENTRY
-_mesa_RenderbufferStorageMultisample(GLenum target, GLsizei samples,
-                                     GLenum internalFormat,
-                                     GLsizei width, GLsizei height)
-{
-   renderbuffer_storage(target, internalFormat, width, height, samples);
-}
-
-
-/**
- * OpenGL ES version of glRenderBufferStorage.
- */
-void GLAPIENTRY
-_es_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
-			   GLsizei width, GLsizei height)
-{
-   switch (internalFormat) {
-   case GL_RGB565:
-      /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
-      /* choose a closest format */
-      internalFormat = GL_RGB5;
-      break;
-   default:
-      break;
-   }
-
-   renderbuffer_storage(target, internalFormat, width, height, 0);
-}
-
-
-void GLAPIENTRY
-_mesa_GetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params)
-{
-   struct gl_renderbuffer *rb;
-   GET_CURRENT_CONTEXT(ctx);
-
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if (target != GL_RENDERBUFFER_EXT) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glGetRenderbufferParameterivEXT(target)");
-      return;
-   }
-
-   rb = ctx->CurrentRenderbuffer;
-   if (!rb) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGetRenderbufferParameterivEXT");
-      return;
-   }
-
-   /* No need to flush here since we're just quering state which is
-    * not effected by rendering.
-    */
-
-   switch (pname) {
-   case GL_RENDERBUFFER_WIDTH_EXT:
-      *params = rb->Width;
-      return;
-   case GL_RENDERBUFFER_HEIGHT_EXT:
-      *params = rb->Height;
-      return;
-   case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT:
-      *params = rb->InternalFormat;
-      return;
-   case GL_RENDERBUFFER_RED_SIZE_EXT:
-   case GL_RENDERBUFFER_GREEN_SIZE_EXT:
-   case GL_RENDERBUFFER_BLUE_SIZE_EXT:
-   case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
-   case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
-   case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
-      *params = get_component_bits(pname, rb->_BaseFormat, rb->Format);
-      break;
-   case GL_RENDERBUFFER_SAMPLES:
-      if (ctx->Extensions.ARB_framebuffer_object) {
-         *params = rb->NumSamples;
-         break;
-      }
-      /* fallthrough */
-   default:
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glGetRenderbufferParameterivEXT(target)");
-      return;
-   }
-}
-
-
-GLboolean GLAPIENTRY
-_mesa_IsFramebufferEXT(GLuint framebuffer)
-{
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
-   if (framebuffer) {
-      struct gl_framebuffer *rb = _mesa_lookup_framebuffer(ctx, framebuffer);
-      if (rb != NULL && rb != &DummyFramebuffer)
-         return GL_TRUE;
-   }
-   return GL_FALSE;
-}
-
-
-/**
- * Check if any of the attachments of the given framebuffer are textures
- * (render to texture).  Call ctx->Driver.RenderTexture() for such
- * attachments.
- */
-static void
-check_begin_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
-{
-   GLuint i;
-   ASSERT(ctx->Driver.RenderTexture);
-
-   if (fb->Name == 0)
-      return; /* can't render to texture with winsys framebuffers */
-
-   for (i = 0; i < BUFFER_COUNT; i++) {
-      struct gl_renderbuffer_attachment *att = fb->Attachment + i;
-      struct gl_texture_object *texObj = att->Texture;
-      if (texObj
-          && texObj->Image[att->CubeMapFace][att->TextureLevel]) {
-         ctx->Driver.RenderTexture(ctx, fb, att);
-      }
-   }
-}
-
-
-/**
- * Examine all the framebuffer's attachments to see if any are textures.
- * If so, call ctx->Driver.FinishRenderTexture() for each texture to
- * notify the device driver that the texture image may have changed.
- */
-static void
-check_end_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
-{
-   if (fb->Name == 0)
-      return; /* can't render to texture with winsys framebuffers */
-
-   if (ctx->Driver.FinishRenderTexture) {
-      GLuint i;
-      for (i = 0; i < BUFFER_COUNT; i++) {
-         struct gl_renderbuffer_attachment *att = fb->Attachment + i;
-         if (att->Texture && att->Renderbuffer) {
-            ctx->Driver.FinishRenderTexture(ctx, att);
-         }
-      }
-   }
-}
-
-
-void GLAPIENTRY
-_mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer)
-{
-   struct gl_framebuffer *newDrawFb, *newReadFb;
-   struct gl_framebuffer *oldDrawFb, *oldReadFb;
-   GLboolean bindReadBuf, bindDrawBuf;
-   GET_CURRENT_CONTEXT(ctx);
-
-#ifdef DEBUG
-   if (ctx->Extensions.ARB_framebuffer_object) {
-      ASSERT(ctx->Extensions.EXT_framebuffer_object);
-      ASSERT(ctx->Extensions.EXT_framebuffer_blit);
-   }
-#endif
-
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if (!ctx->Extensions.EXT_framebuffer_object) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glBindFramebufferEXT(unsupported)");
-      return;
-   }
-
-   switch (target) {
-#if FEATURE_EXT_framebuffer_blit
-   case GL_DRAW_FRAMEBUFFER_EXT:
-      if (!ctx->Extensions.EXT_framebuffer_blit) {
-         _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
-         return;
-      }
-      bindDrawBuf = GL_TRUE;
-      bindReadBuf = GL_FALSE;
-      break;
-   case GL_READ_FRAMEBUFFER_EXT:
-      if (!ctx->Extensions.EXT_framebuffer_blit) {
-         _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
-         return;
-      }
-      bindDrawBuf = GL_FALSE;
-      bindReadBuf = GL_TRUE;
-      break;
-#endif
-   case GL_FRAMEBUFFER_EXT:
-      bindDrawBuf = GL_TRUE;
-      bindReadBuf = GL_TRUE;
-      break;
-   default:
-      _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
-      return;
-   }
-
-   if (framebuffer) {
-      /* Binding a user-created framebuffer object */
-      newDrawFb = _mesa_lookup_framebuffer(ctx, framebuffer);
-      if (newDrawFb == &DummyFramebuffer) {
-         /* ID was reserved, but no real framebuffer object made yet */
-         newDrawFb = NULL;
-      }
-      else if (!newDrawFb && ctx->Extensions.ARB_framebuffer_object) {
-         /* All FBO IDs must be Gen'd */
-         _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFramebuffer(buffer)");
-         return;
-      }
-
-      if (!newDrawFb) {
-	 /* create new framebuffer object */
-	 newDrawFb = ctx->Driver.NewFramebuffer(ctx, framebuffer);
-	 if (!newDrawFb) {
-	    _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT");
-	    return;
-	 }
-         _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newDrawFb);
-      }
-      newReadFb = newDrawFb;
-   }
-   else {
-      /* Binding the window system framebuffer (which was originally set
-       * with MakeCurrent).
-       */
-      newDrawFb = ctx->WinSysDrawBuffer;
-      newReadFb = ctx->WinSysReadBuffer;
-   }
-
-   ASSERT(newDrawFb);
-   ASSERT(newDrawFb != &DummyFramebuffer);
-
-   /* save pointers to current/old framebuffers */
-   oldDrawFb = ctx->DrawBuffer;
-   oldReadFb = ctx->ReadBuffer;
-
-   /* check if really changing bindings */
-   if (oldDrawFb == newDrawFb)
-      bindDrawBuf = GL_FALSE;
-   if (oldReadFb == newReadFb)
-      bindReadBuf = GL_FALSE;
-
-   /*
-    * OK, now bind the new Draw/Read framebuffers, if they're changing.
-    *
-    * We also check if we're beginning and/or ending render-to-texture.
-    * When a framebuffer with texture attachments is unbound, call
-    * ctx->Driver.FinishRenderTexture().
-    * When a framebuffer with texture attachments is bound, call
-    * ctx->Driver.RenderTexture().
-    *
-    * Note that if the ReadBuffer has texture attachments we don't consider
-    * that a render-to-texture case.
-    */
-   if (bindReadBuf) {
-      FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
-      /* check if old readbuffer was render-to-texture */
-      check_end_texture_render(ctx, oldReadFb);
-
-      _mesa_reference_framebuffer(&ctx->ReadBuffer, newReadFb);
-   }
-
-   if (bindDrawBuf) {
-      FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
-      /* check if old read/draw buffers were render-to-texture */
-      if (!bindReadBuf)
-         check_end_texture_render(ctx, oldReadFb);
-
-      if (oldDrawFb != oldReadFb)
-         check_end_texture_render(ctx, oldDrawFb);
-
-      /* check if newly bound framebuffer has any texture attachments */
-      check_begin_texture_render(ctx, newDrawFb);
-
-      _mesa_reference_framebuffer(&ctx->DrawBuffer, newDrawFb);
-   }
-
-   if ((bindDrawBuf || bindReadBuf) && ctx->Driver.BindFramebuffer) {
-      ctx->Driver.BindFramebuffer(ctx, target, newDrawFb, newReadFb);
-   }
-}
-
-
-void GLAPIENTRY
-_mesa_DeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers)
-{
-   GLint i;
-   GET_CURRENT_CONTEXT(ctx);
-
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
-   for (i = 0; i < n; i++) {
-      if (framebuffers[i] > 0) {
-	 struct gl_framebuffer *fb;
-	 fb = _mesa_lookup_framebuffer(ctx, framebuffers[i]);
-	 if (fb) {
-            ASSERT(fb == &DummyFramebuffer || fb->Name == framebuffers[i]);
-
-            /* check if deleting currently bound framebuffer object */
-            if (ctx->Extensions.EXT_framebuffer_blit) {
-               /* separate draw/read binding points */
-               if (fb == ctx->DrawBuffer) {
-                  /* bind default */
-                  ASSERT(fb->RefCount >= 2);
-                  _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
-               }
-               if (fb == ctx->ReadBuffer) {
-                  /* bind default */
-                  ASSERT(fb->RefCount >= 2);
-                  _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
-               }
-            }
-            else {
-               /* only one binding point for read/draw buffers */
-               if (fb == ctx->DrawBuffer || fb == ctx->ReadBuffer) {
-                  /* bind default */
-                  ASSERT(fb->RefCount >= 2);
-                  _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-               }    
-            }
-
-	    /* remove from hash table immediately, to free the ID */
-	    _mesa_HashRemove(ctx->Shared->FrameBuffers, framebuffers[i]);
-
-            if (fb != &DummyFramebuffer) {
-               /* But the object will not be freed until it's no longer
-                * bound in any context.
-                */
-               _mesa_reference_framebuffer(&fb, NULL);
-	    }
-	 }
-      }
-   }
-}
-
-
-void GLAPIENTRY
-_mesa_GenFramebuffersEXT(GLsizei n, GLuint *framebuffers)
-{
-   GET_CURRENT_CONTEXT(ctx);
-   GLuint first;
-   GLint i;
-
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if (n < 0) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glGenFramebuffersEXT(n)");
-      return;
-   }
-
-   if (!framebuffers)
-      return;
-
-   first = _mesa_HashFindFreeKeyBlock(ctx->Shared->FrameBuffers, n);
-
-   for (i = 0; i < n; i++) {
-      GLuint name = first + i;
-      framebuffers[i] = name;
-      /* insert dummy placeholder into hash table */
-      _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
-      _mesa_HashInsert(ctx->Shared->FrameBuffers, name, &DummyFramebuffer);
-      _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
-   }
-}
-
-
-
-GLenum GLAPIENTRY
-_mesa_CheckFramebufferStatusEXT(GLenum target)
-{
-   struct gl_framebuffer *buffer;
-   GET_CURRENT_CONTEXT(ctx);
-
-   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
-
-   switch (target) {
-#if FEATURE_EXT_framebuffer_blit
-   case GL_DRAW_FRAMEBUFFER_EXT:
-      if (!ctx->Extensions.EXT_framebuffer_blit) {
-         _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
-         return 0;
-      }
-      buffer = ctx->DrawBuffer;
-      break;
-   case GL_READ_FRAMEBUFFER_EXT:
-      if (!ctx->Extensions.EXT_framebuffer_blit) {
-         _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
-         return 0;
-      }
-      buffer = ctx->ReadBuffer;
-      break;
-#endif
-   case GL_FRAMEBUFFER_EXT:
-      buffer = ctx->DrawBuffer;
-      break;
-   default:
-      _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
-      return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
-   }
-
-   if (buffer->Name == 0) {
-      /* The window system / default framebuffer is always complete */
-      return GL_FRAMEBUFFER_COMPLETE_EXT;
-   }
-
-   /* No need to flush here */
-
-   if (buffer->_Status != GL_FRAMEBUFFER_COMPLETE) {
-      _mesa_test_framebuffer_completeness(ctx, buffer);
-   }
-
-   return buffer->_Status;
-}
-
-
-
-/**
- * Common code called by glFramebufferTexture1D/2D/3DEXT().
- */
-static void
-framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target, 
-                    GLenum attachment, GLenum textarget, GLuint texture,
-                    GLint level, GLint zoffset)
-{
-   struct gl_renderbuffer_attachment *att;
-   struct gl_texture_object *texObj = NULL;
-   struct gl_framebuffer *fb;
-   GLboolean error = GL_FALSE;
-
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   switch (target) {
-   case GL_READ_FRAMEBUFFER_EXT:
-      error = !ctx->Extensions.EXT_framebuffer_blit;
-      fb = ctx->ReadBuffer;
-      break;
-   case GL_DRAW_FRAMEBUFFER_EXT:
-      error = !ctx->Extensions.EXT_framebuffer_blit;
-      /* fall-through */
-   case GL_FRAMEBUFFER_EXT:
-      fb = ctx->DrawBuffer;
-      break;
-   default:
-      error = GL_TRUE;
-   }
-
-   if (error) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glFramebufferTexture%sEXT(target=0x%x)", caller, target);
-      return;
-   }
-
-   ASSERT(fb);
-
-   /* check framebuffer binding */
-   if (fb->Name == 0) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glFramebufferTexture%sEXT", caller);
-      return;
-   }
-
-
-   /* The textarget, level, and zoffset parameters are only validated if
-    * texture is non-zero.
-    */
-   if (texture) {
-      GLboolean err = GL_TRUE;
-
-      texObj = _mesa_lookup_texture(ctx, texture);
-      if (texObj != NULL) {
-         if (textarget == 0) {
-            /* XXX what's the purpose of this? */
-            err = (texObj->Target != GL_TEXTURE_3D) &&
-                (texObj->Target != GL_TEXTURE_1D_ARRAY_EXT) &&
-                (texObj->Target != GL_TEXTURE_2D_ARRAY_EXT);
-         }
-         else {
-            err = (texObj->Target == GL_TEXTURE_CUBE_MAP)
-                ? !IS_CUBE_FACE(textarget)
-                : (texObj->Target != textarget);
-         }
-      }
-      else {
-         /* can't render to a non-existant texture */
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glFramebufferTexture%sEXT(non existant texture)",
-                     caller);
-         return;
-      }
-
-      if (err) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glFramebufferTexture%sEXT(texture target mismatch)",
-                     caller);
-         return;
-      }
-
-      if (texObj->Target == GL_TEXTURE_3D) {
-         const GLint maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
-         if (zoffset < 0 || zoffset >= maxSize) {
-            _mesa_error(ctx, GL_INVALID_VALUE,
-                        "glFramebufferTexture%sEXT(zoffset)", caller);
-            return;
-         }
-      }
-      else if ((texObj->Target == GL_TEXTURE_1D_ARRAY_EXT) ||
-               (texObj->Target == GL_TEXTURE_2D_ARRAY_EXT)) {
-         if (zoffset < 0 || zoffset >= ctx->Const.MaxArrayTextureLayers) {
-            _mesa_error(ctx, GL_INVALID_VALUE,
-                        "glFramebufferTexture%sEXT(layer)", caller);
-            return;
-         }
-      }
-
-      if ((level < 0) || 
-          (level >= _mesa_max_texture_levels(ctx, texObj->Target))) {
-         _mesa_error(ctx, GL_INVALID_VALUE,
-                     "glFramebufferTexture%sEXT(level)", caller);
-         return;
-      }
-   }
-
-   att = _mesa_get_attachment(ctx, fb, attachment);
-   if (att == NULL) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glFramebufferTexture%sEXT(attachment)", caller);
-      return;
-   }
-
-   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
-   _glthread_LOCK_MUTEX(fb->Mutex);
-   if (texObj) {
-      _mesa_set_texture_attachment(ctx, fb, att, texObj, textarget,
-                                   level, zoffset);
-      /* Set the render-to-texture flag.  We'll check this flag in
-       * glTexImage() and friends to determine if we need to revalidate
-       * any FBOs that might be rendering into this texture.
-       * This flag never gets cleared since it's non-trivial to determine
-       * when all FBOs might be done rendering to this texture.  That's OK
-       * though since it's uncommon to render to a texture then repeatedly
-       * call glTexImage() to change images in the texture.
-       */
-      texObj->_RenderToTexture = GL_TRUE;
-   }
-   else {
-      _mesa_remove_attachment(ctx, att);
-   }
-
-   invalidate_framebuffer(fb);
-
-   _glthread_UNLOCK_MUTEX(fb->Mutex);
-}
-
-
-
-void GLAPIENTRY
-_mesa_FramebufferTexture1DEXT(GLenum target, GLenum attachment,
-                              GLenum textarget, GLuint texture, GLint level)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   if ((texture != 0) && (textarget != GL_TEXTURE_1D)) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glFramebufferTexture1DEXT(textarget)");
-      return;
-   }
-
-   framebuffer_texture(ctx, "1D", target, attachment, textarget, texture,
-                       level, 0);
-}
-
-
-void GLAPIENTRY
-_mesa_FramebufferTexture2DEXT(GLenum target, GLenum attachment,
-                              GLenum textarget, GLuint texture, GLint level)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   if ((texture != 0) &&
-       (textarget != GL_TEXTURE_2D) &&
-       (textarget != GL_TEXTURE_RECTANGLE_ARB) &&
-       (!IS_CUBE_FACE(textarget))) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glFramebufferTexture2DEXT(textarget=0x%x)", textarget);
-      return;
-   }
-
-   framebuffer_texture(ctx, "2D", target, attachment, textarget, texture,
-                       level, 0);
-}
-
-
-void GLAPIENTRY
-_mesa_FramebufferTexture3DEXT(GLenum target, GLenum attachment,
-                              GLenum textarget, GLuint texture,
-                              GLint level, GLint zoffset)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   if ((texture != 0) && (textarget != GL_TEXTURE_3D)) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glFramebufferTexture3DEXT(textarget)");
-      return;
-   }
-
-   framebuffer_texture(ctx, "3D", target, attachment, textarget, texture,
-                       level, zoffset);
-}
-
-
-void GLAPIENTRY
-_mesa_FramebufferTextureLayerEXT(GLenum target, GLenum attachment,
-                                 GLuint texture, GLint level, GLint layer)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   framebuffer_texture(ctx, "Layer", target, attachment, 0, texture,
-                       level, layer);
-}
-
-
-void GLAPIENTRY
-_mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment,
-                                 GLenum renderbufferTarget,
-                                 GLuint renderbuffer)
-{
-   struct gl_renderbuffer_attachment *att;
-   struct gl_framebuffer *fb;
-   struct gl_renderbuffer *rb;
-   GET_CURRENT_CONTEXT(ctx);
-
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   switch (target) {
-#if FEATURE_EXT_framebuffer_blit
-   case GL_DRAW_FRAMEBUFFER_EXT:
-      if (!ctx->Extensions.EXT_framebuffer_blit) {
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "glFramebufferRenderbufferEXT(target)");
-         return;
-      }
-      fb = ctx->DrawBuffer;
-      break;
-   case GL_READ_FRAMEBUFFER_EXT:
-      if (!ctx->Extensions.EXT_framebuffer_blit) {
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "glFramebufferRenderbufferEXT(target)");
-         return;
-      }
-      fb = ctx->ReadBuffer;
-      break;
-#endif
-   case GL_FRAMEBUFFER_EXT:
-      fb = ctx->DrawBuffer;
-      break;
-   default:
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glFramebufferRenderbufferEXT(target)");
-      return;
-   }
-
-   if (renderbufferTarget != GL_RENDERBUFFER_EXT) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glFramebufferRenderbufferEXT(renderbufferTarget)");
-      return;
-   }
-
-   if (fb->Name == 0) {
-      /* Can't attach new renderbuffers to a window system framebuffer */
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glFramebufferRenderbufferEXT");
-      return;
-   }
-
-   att = _mesa_get_attachment(ctx, fb, attachment);
-   if (att == NULL) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glFramebufferRenderbufferEXT(invalid attachment %s)",
-                  _mesa_lookup_enum_by_nr(attachment));
-      return;
-   }
-
-   if (renderbuffer) {
-      rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
-      if (!rb) {
-	 _mesa_error(ctx, GL_INVALID_OPERATION,
-		     "glFramebufferRenderbufferEXT(non-existant"
-                     " renderbuffer %u)", renderbuffer);
-	 return;
-      }
-      else if (rb == &DummyRenderbuffer) {
-         /* This is what NVIDIA does */
-	 _mesa_error(ctx, GL_INVALID_VALUE,
-		     "glFramebufferRenderbufferEXT(renderbuffer %u)",
-                     renderbuffer);
-	 return;
-      }
-   }
-   else {
-      /* remove renderbuffer attachment */
-      rb = NULL;
-   }
-
-   if (attachment == GL_DEPTH_STENCIL_ATTACHMENT &&
-       rb && rb->Format != MESA_FORMAT_NONE) {
-      /* make sure the renderbuffer is a depth/stencil format */
-      const GLenum baseFormat = _mesa_get_format_base_format(rb->Format);
-      if (baseFormat != GL_DEPTH_STENCIL) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glFramebufferRenderbufferEXT(renderbuffer"
-                     " is not DEPTH_STENCIL format)");
-         return;
-      }
-   }
-
-
-   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
-   assert(ctx->Driver.FramebufferRenderbuffer);
-   ctx->Driver.FramebufferRenderbuffer(ctx, fb, attachment, rb);
-
-   /* Some subsequent GL commands may depend on the framebuffer's visual
-    * after the binding is updated.  Update visual info now.
-    */
-   _mesa_update_framebuffer_visual(ctx, fb);
-}
-
-
-void GLAPIENTRY
-_mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment,
-                                             GLenum pname, GLint *params)
-{
-   const struct gl_renderbuffer_attachment *att;
-   struct gl_framebuffer *buffer;
-   GET_CURRENT_CONTEXT(ctx);
-
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   switch (target) {
-#if FEATURE_EXT_framebuffer_blit
-   case GL_DRAW_FRAMEBUFFER_EXT:
-      if (!ctx->Extensions.EXT_framebuffer_blit) {
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "glGetFramebufferAttachmentParameterivEXT(target)");
-         return;
-      }
-      buffer = ctx->DrawBuffer;
-      break;
-   case GL_READ_FRAMEBUFFER_EXT:
-      if (!ctx->Extensions.EXT_framebuffer_blit) {
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "glGetFramebufferAttachmentParameterivEXT(target)");
-         return;
-      }
-      buffer = ctx->ReadBuffer;
-      break;
-#endif
-   case GL_FRAMEBUFFER_EXT:
-      buffer = ctx->DrawBuffer;
-      break;
-   default:
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glGetFramebufferAttachmentParameterivEXT(target)");
-      return;
-   }
-
-   if (buffer->Name == 0) {
-      /* the default / window-system FBO */
-      att = _mesa_get_fb0_attachment(ctx, buffer, attachment);
-   }
-   else {
-      /* user-created framebuffer FBO */
-      att = _mesa_get_attachment(ctx, buffer, attachment);
-   }
-
-   if (att == NULL) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glGetFramebufferAttachmentParameterivEXT(attachment)");
-      return;
-   }
-
-   if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
-      /* the depth and stencil attachments must point to the same buffer */
-      const struct gl_renderbuffer_attachment *depthAtt, *stencilAtt;
-      depthAtt = _mesa_get_attachment(ctx, buffer, GL_DEPTH_ATTACHMENT);
-      stencilAtt = _mesa_get_attachment(ctx, buffer, GL_STENCIL_ATTACHMENT);
-      if (depthAtt->Renderbuffer != stencilAtt->Renderbuffer) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
-                     " attachments differ)");
-         return;
-      }
-   }
-
-   /* No need to flush here */
-
-   switch (pname) {
-   case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT:
-      *params = buffer->Name == 0 ? GL_FRAMEBUFFER_DEFAULT : att->Type;
-      return;
-   case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT:
-      if (att->Type == GL_RENDERBUFFER_EXT) {
-	 *params = att->Renderbuffer->Name;
-      }
-      else if (att->Type == GL_TEXTURE) {
-	 *params = att->Texture->Name;
-      }
-      else {
-         assert(att->Type == GL_NONE);
-         *params = 0;
-      }
-      return;
-   case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT:
-      if (att->Type == GL_TEXTURE) {
-	 *params = att->TextureLevel;
-      }
-      else {
-	 _mesa_error(ctx, GL_INVALID_ENUM,
-		     "glGetFramebufferAttachmentParameterivEXT(pname)");
-      }
-      return;
-   case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT:
-      if (att->Type == GL_TEXTURE) {
-         if (att->Texture && att->Texture->Target == GL_TEXTURE_CUBE_MAP) {
-            *params = GL_TEXTURE_CUBE_MAP_POSITIVE_X + att->CubeMapFace;
-         }
-         else {
-            *params = 0;
-         }
-      }
-      else {
-	 _mesa_error(ctx, GL_INVALID_ENUM,
-		     "glGetFramebufferAttachmentParameterivEXT(pname)");
-      }
-      return;
-   case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT:
-      if (att->Type == GL_TEXTURE) {
-         if (att->Texture && att->Texture->Target == GL_TEXTURE_3D) {
-            *params = att->Zoffset;
-         }
-         else {
-            *params = 0;
-         }
-      }
-      else {
-	 _mesa_error(ctx, GL_INVALID_ENUM,
-		     "glGetFramebufferAttachmentParameterivEXT(pname)");
-      }
-      return;
-   case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
-      if (!ctx->Extensions.ARB_framebuffer_object) {
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "glGetFramebufferAttachmentParameterivEXT(pname)");
-      }
-      else {
-         if (ctx->Extensions.EXT_framebuffer_sRGB) {
-            *params = _mesa_get_format_color_encoding(att->Renderbuffer->Format);
-         }
-         else {
-            /* According to ARB_framebuffer_sRGB, we should return LINEAR
-             * if the sRGB conversion is unsupported. */
-            *params = GL_LINEAR;
-         }
-      }
-      return;
-   case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
-      if (!ctx->Extensions.ARB_framebuffer_object) {
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "glGetFramebufferAttachmentParameterivEXT(pname)");
-         return;
-      }
-      else {
-         gl_format format = att->Renderbuffer->Format;
-         if (format == MESA_FORMAT_CI8 || format == MESA_FORMAT_S8) {
-            /* special cases */
-            *params = GL_INDEX;
-         }
-         else {
-            *params = _mesa_get_format_datatype(format);
-         }
-      }
-      return;
-   case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
-   case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
-   case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
-   case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
-   case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
-   case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
-      if (!ctx->Extensions.ARB_framebuffer_object) {
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "glGetFramebufferAttachmentParameterivEXT(pname)");
-      }
-      else if (att->Texture) {
-         const struct gl_texture_image *texImage =
-            _mesa_select_tex_image(ctx, att->Texture, att->Texture->Target,
-                                   att->TextureLevel);
-         if (texImage) {
-            *params = get_component_bits(pname, texImage->_BaseFormat,
-                                         texImage->TexFormat);
-         }
-         else {
-            *params = 0;
-         }
-      }
-      else if (att->Renderbuffer) {
-         *params = get_component_bits(pname, att->Renderbuffer->_BaseFormat,
-                                      att->Renderbuffer->Format);
-      }
-      else {
-         *params = 0;
-      }
-      return;
-   default:
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glGetFramebufferAttachmentParameterivEXT(pname)");
-      return;
-   }
-}
-
-
-void GLAPIENTRY
-_mesa_GenerateMipmapEXT(GLenum target)
-{
-   struct gl_texture_object *texObj;
-   GET_CURRENT_CONTEXT(ctx);
-
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
-   switch (target) {
-   case GL_TEXTURE_1D:
-   case GL_TEXTURE_2D:
-   case GL_TEXTURE_3D:
-   case GL_TEXTURE_CUBE_MAP:
-      /* OK, legal value */
-      break;
-   default:
-      /* XXX need to implement GL_TEXTURE_1D_ARRAY and GL_TEXTURE_2D_ARRAY */
-      _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmapEXT(target)");
-      return;
-   }
-
-   texObj = _mesa_get_current_tex_object(ctx, target);
-
-   if (texObj->BaseLevel >= texObj->MaxLevel) {
-      /* nothing to do */
-      return;
-   }
-
-   if (texObj->Target == GL_TEXTURE_CUBE_MAP &&
-       !_mesa_cube_complete(texObj)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGenerateMipmap(incomplete cube map)");
-      return;
-   }
-
-   _mesa_lock_texture(ctx, texObj);
-   if (target == GL_TEXTURE_CUBE_MAP) {
-      GLuint face;
-      for (face = 0; face < 6; face++)
-	 ctx->Driver.GenerateMipmap(ctx,
-				    GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + face,
-				    texObj);
-   }
-   else {
-      ctx->Driver.GenerateMipmap(ctx, target, texObj);
-   }
-   _mesa_unlock_texture(ctx, texObj);
-}
-
-
-#if FEATURE_EXT_framebuffer_blit
-
-static const struct gl_renderbuffer_attachment *
-find_attachment(const struct gl_framebuffer *fb, const struct gl_renderbuffer *rb)
-{
-   GLuint i;
-   for (i = 0; i < Elements(fb->Attachment); i++) {
-      if (fb->Attachment[i].Renderbuffer == rb)
-         return &fb->Attachment[i];
-   }
-   return NULL;
-}
-
-
-
-/**
- * Blit rectangular region, optionally from one framebuffer to another.
- *
- * Note, if the src buffer is multisampled and the dest is not, this is
- * when the samples must be resolved to a single color.
- */
-void GLAPIENTRY
-_mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
-                         GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
-                         GLbitfield mask, GLenum filter)
-{
-   const GLbitfield legalMaskBits = (GL_COLOR_BUFFER_BIT |
-                                     GL_DEPTH_BUFFER_BIT |
-                                     GL_STENCIL_BUFFER_BIT);
-   const struct gl_framebuffer *readFb, *drawFb;
-   const struct gl_renderbuffer *colorReadRb, *colorDrawRb;
-   GET_CURRENT_CONTEXT(ctx);
-
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
-
-   if (ctx->NewState) {
-      _mesa_update_state(ctx);
-   }
-
-   readFb = ctx->ReadBuffer;
-   drawFb = ctx->DrawBuffer;
-
-   if (!readFb || !drawFb) {
-      /* This will normally never happen but someday we may want to
-       * support MakeCurrent() with no drawables.
-       */
-      return;
-   }
-
-   /* check for complete framebuffers */
-   if (drawFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT ||
-       readFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
-      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
-                  "glBlitFramebufferEXT(incomplete draw/read buffers)");
-      return;
-   }
-
-   if (filter != GL_NEAREST && filter != GL_LINEAR) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glBlitFramebufferEXT(filter)");
-      return;
-   }
-
-   if (mask & ~legalMaskBits) {
-      _mesa_error( ctx, GL_INVALID_VALUE, "glBlitFramebufferEXT(mask)");
-      return;
-   }
-
-   /* depth/stencil must be blitted with nearest filtering */
-   if ((mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
-        && filter != GL_NEAREST) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-             "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
-      return;
-   }
-
-   /* get color read/draw renderbuffers */
-   if (mask & GL_COLOR_BUFFER_BIT) {
-      colorReadRb = readFb->_ColorReadBuffer;
-      colorDrawRb = drawFb->_ColorDrawBuffers[0];
-   }
-   else {
-      colorReadRb = colorDrawRb = NULL;
-   }
-
-   if (mask & GL_STENCIL_BUFFER_BIT) {
-      struct gl_renderbuffer *readRb = readFb->_StencilBuffer;
-      struct gl_renderbuffer *drawRb = drawFb->_StencilBuffer;
-      if (!readRb ||
-          !drawRb ||
-          _mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS) != 
-          _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS)) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glBlitFramebufferEXT(stencil buffer size mismatch");
-         return;
-      }
-   }
-
-   if (mask & GL_DEPTH_BUFFER_BIT) {
-      struct gl_renderbuffer *readRb = readFb->_DepthBuffer;
-      struct gl_renderbuffer *drawRb = drawFb->_DepthBuffer;
-      if (!readRb ||
-          !drawRb ||
-          _mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS) != 
-          _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS)) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glBlitFramebufferEXT(depth buffer size mismatch");
-         return;
-      }
-   }
-
-   if (readFb->Visual.samples > 0 &&
-       drawFb->Visual.samples > 0 &&
-       readFb->Visual.samples != drawFb->Visual.samples) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glBlitFramebufferEXT(mismatched samples");
-      return;
-   }
-
-   /* extra checks for multisample copies... */
-   if (readFb->Visual.samples > 0 || drawFb->Visual.samples > 0) {
-      /* src and dest region sizes must be the same */
-      if (srcX1 - srcX0 != dstX1 - dstX0 ||
-          srcY1 - srcY0 != dstY1 - dstY0) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                "glBlitFramebufferEXT(bad src/dst multisample region sizes");
-         return;
-      }
-
-      /* color formats must match */
-      if (colorReadRb &&
-          colorDrawRb &&
-          colorReadRb->Format != colorDrawRb->Format) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                "glBlitFramebufferEXT(bad src/dst multisample pixel formats");
-         return;
-      }
-   }
-
-   if (!ctx->Extensions.EXT_framebuffer_blit) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT");
-      return;
-   }
-
-   /* Debug code */
-   if (DEBUG_BLIT) {
-      printf("glBlitFramebuffer(%d, %d, %d, %d,  %d, %d, %d, %d,"
-	     " 0x%x, 0x%x)\n",
-	     srcX0, srcY0, srcX1, srcY1,
-	     dstX0, dstY0, dstX1, dstY1,
-	     mask, filter);
-      if (colorReadRb) {
-         const struct gl_renderbuffer_attachment *att;
-
-         att = find_attachment(readFb, colorReadRb);
-         printf("  Src FBO %u  RB %u (%dx%d)  ",
-		readFb->Name, colorReadRb->Name,
-		colorReadRb->Width, colorReadRb->Height);
-         if (att && att->Texture) {
-            printf("Tex %u  tgt 0x%x  level %u  face %u",
-		   att->Texture->Name,
-		   att->Texture->Target,
-		   att->TextureLevel,
-		   att->CubeMapFace);
-         }
-         printf("\n");
-
-         att = find_attachment(drawFb, colorDrawRb);
-         printf("  Dst FBO %u  RB %u (%dx%d)  ",
-		drawFb->Name, colorDrawRb->Name,
-		colorDrawRb->Width, colorDrawRb->Height);
-         if (att && att->Texture) {
-            printf("Tex %u  tgt 0x%x  level %u  face %u",
-		   att->Texture->Name,
-		   att->Texture->Target,
-		   att->TextureLevel,
-		   att->CubeMapFace);
-         }
-         printf("\n");
-      }
-   }
-
-   ASSERT(ctx->Driver.BlitFramebuffer);
-   ctx->Driver.BlitFramebuffer(ctx,
-                               srcX0, srcY0, srcX1, srcY1,
-                               dstX0, dstY0, dstX1, dstY1,
-                               mask, filter);
-}
-#endif /* FEATURE_EXT_framebuffer_blit */
-
-#if FEATURE_ARB_geometry_shader4
-void GLAPIENTRY
-_mesa_FramebufferTextureARB(GLenum target, GLenum attachment,
-                            GLuint texture, GLint level)
-{
-   GET_CURRENT_CONTEXT(ctx);
-   _mesa_error(ctx, GL_INVALID_OPERATION,
-               "glFramebufferTextureARB "
-               "not implemented!");
-}
-
-void GLAPIENTRY
-_mesa_FramebufferTextureFaceARB(GLenum target, GLenum attachment,
-                                GLuint texture, GLint level, GLenum face)
-{
-   GET_CURRENT_CONTEXT(ctx);
-   _mesa_error(ctx, GL_INVALID_OPERATION,
-               "glFramebufferTextureFaceARB "
-               "not implemented!");
-}
-#endif /* FEATURE_ARB_geometry_shader4 */
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.1
+ *
+ * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2009  VMware, Inc.  All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/*
+ * GL_EXT/ARB_framebuffer_object extensions
+ *
+ * Authors:
+ *   Brian Paul
+ */
+
+
+#include "buffers.h"
+#include "context.h"
+#include "enums.h"
+#include "fbobject.h"
+#include "formats.h"
+#include "framebuffer.h"
+#include "hash.h"
+#include "macros.h"
+#include "mfeatures.h"
+#include "mtypes.h"
+#include "renderbuffer.h"
+#include "state.h"
+#include "teximage.h"
+#include "texobj.h"
+
+
+/** Set this to 1 to help debug FBO incompleteness problems */
+#define DEBUG_FBO 0
+
+/** Set this to 1 to debug/log glBlitFramebuffer() calls */
+#define DEBUG_BLIT 0
+
+
+/**
+ * Notes:
+ *
+ * None of the GL_EXT_framebuffer_object functions are compiled into
+ * display lists.
+ */
+
+
+
+/*
+ * When glGenRender/FramebuffersEXT() is called we insert pointers to
+ * these placeholder objects into the hash table.
+ * Later, when the object ID is first bound, we replace the placeholder
+ * with the real frame/renderbuffer.
+ */
+static struct gl_framebuffer DummyFramebuffer;
+static struct gl_renderbuffer DummyRenderbuffer;
+
+/* We bind this framebuffer when applications pass a NULL
+ * drawable/surface in make current. */
+static struct gl_framebuffer IncompleteFramebuffer;
+
+
+#define IS_CUBE_FACE(TARGET) \
+   ((TARGET) >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && \
+    (TARGET) <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
+
+
+static void
+delete_dummy_renderbuffer(struct gl_renderbuffer *rb)
+{
+   /* no op */
+}
+
+static void
+delete_dummy_framebuffer(struct gl_framebuffer *fb)
+{
+   /* no op */
+}
+
+
+void
+_mesa_init_fbobjects(struct gl_context *ctx)
+{
+   _glthread_INIT_MUTEX(DummyFramebuffer.Mutex);
+   _glthread_INIT_MUTEX(DummyRenderbuffer.Mutex);
+   _glthread_INIT_MUTEX(IncompleteFramebuffer.Mutex);
+   DummyFramebuffer.Delete = delete_dummy_framebuffer;
+   DummyRenderbuffer.Delete = delete_dummy_renderbuffer;
+   IncompleteFramebuffer.Delete = delete_dummy_framebuffer;
+}
+
+struct gl_framebuffer *
+_mesa_get_incomplete_framebuffer(void)
+{
+   return &IncompleteFramebuffer;
+}
+
+/**
+ * Helper routine for getting a gl_renderbuffer.
+ */
+struct gl_renderbuffer *
+_mesa_lookup_renderbuffer(struct gl_context *ctx, GLuint id)
+{
+   struct gl_renderbuffer *rb;
+
+   if (id == 0)
+      return NULL;
+
+   rb = (struct gl_renderbuffer *)
+      _mesa_HashLookup(ctx->Shared->RenderBuffers, id);
+   return rb;
+}
+
+
+/**
+ * Helper routine for getting a gl_framebuffer.
+ */
+struct gl_framebuffer *
+_mesa_lookup_framebuffer(struct gl_context *ctx, GLuint id)
+{
+   struct gl_framebuffer *fb;
+
+   if (id == 0)
+      return NULL;
+
+   fb = (struct gl_framebuffer *)
+      _mesa_HashLookup(ctx->Shared->FrameBuffers, id);
+   return fb;
+}
+
+
+/**
+ * Mark the given framebuffer as invalid.  This will force the
+ * test for framebuffer completeness to be done before the framebuffer
+ * is used.
+ */
+static void
+invalidate_framebuffer(struct gl_framebuffer *fb)
+{
+   fb->_Status = 0; /* "indeterminate" */
+}
+
+
+/**
+ * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
+ * gl_renderbuffer_attachment object.
+ * This function is only used for user-created FB objects, not the
+ * default / window-system FB object.
+ * If \p attachment is GL_DEPTH_STENCIL_ATTACHMENT, return a pointer to
+ * the depth buffer attachment point.
+ */
+struct gl_renderbuffer_attachment *
+_mesa_get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
+                     GLenum attachment)
+{
+   GLuint i;
+
+   assert(fb->Name > 0);
+
+   switch (attachment) {
+   case GL_COLOR_ATTACHMENT0_EXT:
+   case GL_COLOR_ATTACHMENT1_EXT:
+   case GL_COLOR_ATTACHMENT2_EXT:
+   case GL_COLOR_ATTACHMENT3_EXT:
+   case GL_COLOR_ATTACHMENT4_EXT:
+   case GL_COLOR_ATTACHMENT5_EXT:
+   case GL_COLOR_ATTACHMENT6_EXT:
+   case GL_COLOR_ATTACHMENT7_EXT:
+   case GL_COLOR_ATTACHMENT8_EXT:
+   case GL_COLOR_ATTACHMENT9_EXT:
+   case GL_COLOR_ATTACHMENT10_EXT:
+   case GL_COLOR_ATTACHMENT11_EXT:
+   case GL_COLOR_ATTACHMENT12_EXT:
+   case GL_COLOR_ATTACHMENT13_EXT:
+   case GL_COLOR_ATTACHMENT14_EXT:
+   case GL_COLOR_ATTACHMENT15_EXT:
+      i = attachment - GL_COLOR_ATTACHMENT0_EXT;
+      if (i >= ctx->Const.MaxColorAttachments) {
+	 return NULL;
+      }
+      return &fb->Attachment[BUFFER_COLOR0 + i];
+   case GL_DEPTH_STENCIL_ATTACHMENT:
+      /* fall-through */
+   case GL_DEPTH_BUFFER:
+      /* fall-through / new in GL 3.0 */
+   case GL_DEPTH_ATTACHMENT_EXT:
+      return &fb->Attachment[BUFFER_DEPTH];
+   case GL_STENCIL_BUFFER:
+      /* fall-through / new in GL 3.0 */
+   case GL_STENCIL_ATTACHMENT_EXT:
+      return &fb->Attachment[BUFFER_STENCIL];
+   default:
+      return NULL;
+   }
+}
+
+
+/**
+ * As above, but only used for getting attachments of the default /
+ * window-system framebuffer (not user-created framebuffer objects).
+ */
+static struct gl_renderbuffer_attachment *
+_mesa_get_fb0_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
+                         GLenum attachment)
+{
+   assert(fb->Name == 0);
+
+   switch (attachment) {
+   case GL_FRONT_LEFT:
+      return &fb->Attachment[BUFFER_FRONT_LEFT];
+   case GL_FRONT_RIGHT:
+      return &fb->Attachment[BUFFER_FRONT_RIGHT];
+   case GL_BACK_LEFT:
+      return &fb->Attachment[BUFFER_BACK_LEFT];
+   case GL_BACK_RIGHT:
+      return &fb->Attachment[BUFFER_BACK_RIGHT];
+   case GL_AUX0:
+      if (fb->Visual.numAuxBuffers == 1) {
+         return &fb->Attachment[BUFFER_AUX0];
+      }
+      return NULL;
+   case GL_DEPTH_BUFFER:
+      /* fall-through / new in GL 3.0 */
+   case GL_DEPTH_ATTACHMENT_EXT:
+      return &fb->Attachment[BUFFER_DEPTH];
+   case GL_STENCIL_BUFFER:
+      /* fall-through / new in GL 3.0 */
+   case GL_STENCIL_ATTACHMENT_EXT:
+      return &fb->Attachment[BUFFER_STENCIL];
+   default:
+      return NULL;
+   }
+}
+
+
+
+/**
+ * Remove any texture or renderbuffer attached to the given attachment
+ * point.  Update reference counts, etc.
+ */
+void
+_mesa_remove_attachment(struct gl_context *ctx,
+                        struct gl_renderbuffer_attachment *att)
+{
+   if (att->Type == GL_TEXTURE) {
+      ASSERT(att->Texture);
+      if (ctx->Driver.FinishRenderTexture) {
+         /* tell driver that we're done rendering to this texture. */
+         ctx->Driver.FinishRenderTexture(ctx, att);
+      }
+      _mesa_reference_texobj(&att->Texture, NULL); /* unbind */
+      ASSERT(!att->Texture);
+   }
+   if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) {
+      ASSERT(!att->Texture);
+      _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */
+      ASSERT(!att->Renderbuffer);
+   }
+   att->Type = GL_NONE;
+   att->Complete = GL_TRUE;
+}
+
+
+/**
+ * Bind a texture object to an attachment point.
+ * The previous binding, if any, will be removed first.
+ */
+void
+_mesa_set_texture_attachment(struct gl_context *ctx,
+                             struct gl_framebuffer *fb,
+                             struct gl_renderbuffer_attachment *att,
+                             struct gl_texture_object *texObj,
+                             GLenum texTarget, GLuint level, GLuint zoffset)
+{
+   if (att->Texture == texObj) {
+      /* re-attaching same texture */
+      ASSERT(att->Type == GL_TEXTURE);
+      if (ctx->Driver.FinishRenderTexture)
+	 ctx->Driver.FinishRenderTexture(ctx, att);
+   }
+   else {
+      /* new attachment */
+      if (ctx->Driver.FinishRenderTexture && att->Texture)
+	 ctx->Driver.FinishRenderTexture(ctx, att);
+      _mesa_remove_attachment(ctx, att);
+      att->Type = GL_TEXTURE;
+      assert(!att->Texture);
+      _mesa_reference_texobj(&att->Texture, texObj);
+   }
+
+   /* always update these fields */
+   att->TextureLevel = level;
+   att->CubeMapFace = _mesa_tex_target_to_face(texTarget);
+   att->Zoffset = zoffset;
+   att->Complete = GL_FALSE;
+
+   if (att->Texture->Image[att->CubeMapFace][att->TextureLevel]) {
+      ctx->Driver.RenderTexture(ctx, fb, att);
+   }
+
+   invalidate_framebuffer(fb);
+}
+
+
+/**
+ * Bind a renderbuffer to an attachment point.
+ * The previous binding, if any, will be removed first.
+ */
+void
+_mesa_set_renderbuffer_attachment(struct gl_context *ctx,
+                                  struct gl_renderbuffer_attachment *att,
+                                  struct gl_renderbuffer *rb)
+{
+   /* XXX check if re-doing same attachment, exit early */
+   _mesa_remove_attachment(ctx, att);
+   att->Type = GL_RENDERBUFFER_EXT;
+   att->Texture = NULL; /* just to be safe */
+   att->Complete = GL_FALSE;
+   _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
+}
+
+
+/**
+ * Fallback for ctx->Driver.FramebufferRenderbuffer()
+ * Attach a renderbuffer object to a framebuffer object.
+ */
+void
+_mesa_framebuffer_renderbuffer(struct gl_context *ctx,
+                               struct gl_framebuffer *fb,
+                               GLenum attachment, struct gl_renderbuffer *rb)
+{
+   struct gl_renderbuffer_attachment *att;
+
+   _glthread_LOCK_MUTEX(fb->Mutex);
+
+   att = _mesa_get_attachment(ctx, fb, attachment);
+   ASSERT(att);
+   if (rb) {
+      _mesa_set_renderbuffer_attachment(ctx, att, rb);
+      if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
+         /* do stencil attachment here (depth already done above) */
+         att = _mesa_get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT);
+         assert(att);
+         _mesa_set_renderbuffer_attachment(ctx, att, rb);
+      }
+   }
+   else {
+      _mesa_remove_attachment(ctx, att);
+   }
+
+   invalidate_framebuffer(fb);
+
+   _glthread_UNLOCK_MUTEX(fb->Mutex);
+}
+
+
+/**
+ * Fallback for ctx->Driver.ValidateFramebuffer()
+ * Check if the renderbuffer's formats are supported by the software
+ * renderer.
+ * Drivers should probably override this.
+ */
+void
+_mesa_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
+{
+   gl_buffer_index buf;
+   for (buf = 0; buf < BUFFER_COUNT; buf++) {
+      const struct gl_renderbuffer *rb = fb->Attachment[buf].Renderbuffer;
+      if (rb) {
+         switch (rb->_BaseFormat) {
+         case GL_ALPHA:
+         case GL_LUMINANCE_ALPHA:
+         case GL_LUMINANCE:
+         case GL_INTENSITY:
+         case GL_RED:
+         case GL_RG:
+            fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
+            return;
+         default:
+            /* render buffer format is supported by software rendering */
+            ;
+         }
+      }
+   }
+}
+
+
+/**
+ * For debug only.
+ */
+static void
+att_incomplete(const char *msg)
+{
+#if DEBUG_FBO
+   _mesa_debug(NULL, "attachment incomplete: %s\n", msg);
+#else
+   (void) msg;
+#endif
+}
+
+
+/**
+ * For debug only.
+ */
+static void
+fbo_incomplete(const char *msg, int index)
+{
+#if DEBUG_FBO
+   _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
+#else
+   (void) msg;
+   (void) index;
+#endif
+}
+
+
+/**
+ * Is the given base format a legal format for a color renderbuffer?
+ */
+GLboolean
+_mesa_is_legal_color_format(const struct gl_context *ctx, GLenum baseFormat)
+{
+   switch (baseFormat) {
+   case GL_RGB:
+   case GL_RGBA:
+      return GL_TRUE;
+   case GL_LUMINANCE:
+   case GL_LUMINANCE_ALPHA:
+   case GL_INTENSITY:
+   case GL_ALPHA:
+      return ctx->Extensions.ARB_framebuffer_object;
+   case GL_RED:
+   case GL_RG:
+      return ctx->Extensions.ARB_texture_rg;
+   default:
+      return GL_FALSE;
+   }
+}
+
+
+/**
+ * Is the given base format a legal format for a depth/stencil renderbuffer?
+ */
+static GLboolean
+is_legal_depth_format(const struct gl_context *ctx, GLenum baseFormat)
+{
+   switch (baseFormat) {
+   case GL_DEPTH_COMPONENT:
+   case GL_DEPTH_STENCIL_EXT:
+      return GL_TRUE;
+   default:
+      return GL_FALSE;
+   }
+}
+
+
+/**
+ * Test if an attachment point is complete and update its Complete field.
+ * \param format if GL_COLOR, this is a color attachment point,
+ *               if GL_DEPTH, this is a depth component attachment point,
+ *               if GL_STENCIL, this is a stencil component attachment point.
+ */
+static void
+test_attachment_completeness(const struct gl_context *ctx, GLenum format,
+                             struct gl_renderbuffer_attachment *att)
+{
+   assert(format == GL_COLOR || format == GL_DEPTH || format == GL_STENCIL);
+
+   /* assume complete */
+   att->Complete = GL_TRUE;
+
+   /* Look for reasons why the attachment might be incomplete */
+   if (att->Type == GL_TEXTURE) {
+      const struct gl_texture_object *texObj = att->Texture;
+      struct gl_texture_image *texImage;
+      GLenum baseFormat;
+
+      if (!texObj) {
+         att_incomplete("no texobj");
+         att->Complete = GL_FALSE;
+         return;
+      }
+
+      texImage = texObj->Image[att->CubeMapFace][att->TextureLevel];
+      if (!texImage) {
+         att_incomplete("no teximage");
+         att->Complete = GL_FALSE;
+         return;
+      }
+      if (texImage->Width < 1 || texImage->Height < 1) {
+         att_incomplete("teximage width/height=0");
+         printf("texobj = %u\n", texObj->Name);
+         printf("level = %d\n", att->TextureLevel);
+         att->Complete = GL_FALSE;
+         return;
+      }
+      if (texObj->Target == GL_TEXTURE_3D && att->Zoffset >= texImage->Depth) {
+         att_incomplete("bad z offset");
+         att->Complete = GL_FALSE;
+         return;
+      }
+
+      baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
+
+      if (format == GL_COLOR) {
+         if (!_mesa_is_legal_color_format(ctx, baseFormat)) {
+            att_incomplete("bad format");
+            att->Complete = GL_FALSE;
+            return;
+         }
+         if (_mesa_is_format_compressed(texImage->TexFormat)) {
+            att_incomplete("compressed internalformat");
+            att->Complete = GL_FALSE;
+            return;
+         }
+      }
+      else if (format == GL_DEPTH) {
+         if (baseFormat == GL_DEPTH_COMPONENT) {
+            /* OK */
+         }
+         else if (ctx->Extensions.EXT_packed_depth_stencil &&
+                  ctx->Extensions.ARB_depth_texture &&
+                  baseFormat == GL_DEPTH_STENCIL_EXT) {
+            /* OK */
+         }
+         else {
+            att->Complete = GL_FALSE;
+            att_incomplete("bad depth format");
+            return;
+         }
+      }
+      else {
+         ASSERT(format == GL_STENCIL);
+         if (ctx->Extensions.EXT_packed_depth_stencil &&
+             ctx->Extensions.ARB_depth_texture &&
+             baseFormat == GL_DEPTH_STENCIL_EXT) {
+            /* OK */
+         }
+         else {
+            /* no such thing as stencil-only textures */
+            att_incomplete("illegal stencil texture");
+            att->Complete = GL_FALSE;
+            return;
+         }
+      }
+   }
+   else if (att->Type == GL_RENDERBUFFER_EXT) {
+      const GLenum baseFormat =
+         _mesa_get_format_base_format(att->Renderbuffer->Format);
+
+      ASSERT(att->Renderbuffer);
+      if (!att->Renderbuffer->InternalFormat ||
+          att->Renderbuffer->Width < 1 ||
+          att->Renderbuffer->Height < 1) {
+         att_incomplete("0x0 renderbuffer");
+         att->Complete = GL_FALSE;
+         return;
+      }
+      if (format == GL_COLOR) {
+         if (!_mesa_is_legal_color_format(ctx, baseFormat)) {
+            att_incomplete("bad renderbuffer color format");
+            att->Complete = GL_FALSE;
+            return;
+         }
+      }
+      else if (format == GL_DEPTH) {
+         if (baseFormat == GL_DEPTH_COMPONENT) {
+            /* OK */
+         }
+         else if (ctx->Extensions.EXT_packed_depth_stencil &&
+                  baseFormat == GL_DEPTH_STENCIL_EXT) {
+            /* OK */
+         }
+         else {
+            att_incomplete("bad renderbuffer depth format");
+            att->Complete = GL_FALSE;
+            return;
+         }
+      }
+      else {
+         assert(format == GL_STENCIL);
+         if (baseFormat == GL_STENCIL_INDEX) {
+            /* OK */
+         }
+         else if (ctx->Extensions.EXT_packed_depth_stencil &&
+                  baseFormat == GL_DEPTH_STENCIL_EXT) {
+            /* OK */
+         }
+         else {
+            att->Complete = GL_FALSE;
+            att_incomplete("bad renderbuffer stencil format");
+            return;
+         }
+      }
+   }
+   else {
+      ASSERT(att->Type == GL_NONE);
+      /* complete */
+      return;
+   }
+}
+
+
+/**
+ * Test if the given framebuffer object is complete and update its
+ * Status field with the results.
+ * Calls the ctx->Driver.ValidateFramebuffer() function to allow the
+ * driver to make hardware-specific validation/completeness checks.
+ * Also update the framebuffer's Width and Height fields if the
+ * framebuffer is complete.
+ */
+void
+_mesa_test_framebuffer_completeness(struct gl_context *ctx,
+                                    struct gl_framebuffer *fb)
+{
+   GLuint numImages;
+   GLenum intFormat = GL_NONE; /* color buffers' internal format */
+   GLuint minWidth = ~0, minHeight = ~0, maxWidth = 0, maxHeight = 0;
+   GLint numSamples = -1;
+   GLint i;
+   GLuint j;
+
+   assert(fb->Name != 0);
+
+   numImages = 0;
+   fb->Width = 0;
+   fb->Height = 0;
+
+   /* Start at -2 to more easily loop over all attachment points.
+    *  -2: depth buffer
+    *  -1: stencil buffer
+    * >=0: color buffer
+    */
+   for (i = -2; i < (GLint) ctx->Const.MaxColorAttachments; i++) {
+      struct gl_renderbuffer_attachment *att;
+      GLenum f;
+      gl_format mesaFormat;
+
+      /*
+       * XXX for ARB_fbo, only check color buffers that are named by
+       * GL_READ_BUFFER and GL_DRAW_BUFFERi.
+       */
+
+      /* check for attachment completeness
+       */
+      if (i == -2) {
+         att = &fb->Attachment[BUFFER_DEPTH];
+         test_attachment_completeness(ctx, GL_DEPTH, att);
+         if (!att->Complete) {
+            fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
+            fbo_incomplete("depth attachment incomplete", -1);
+            return;
+         }
+      }
+      else if (i == -1) {
+         att = &fb->Attachment[BUFFER_STENCIL];
+         test_attachment_completeness(ctx, GL_STENCIL, att);
+         if (!att->Complete) {
+            fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
+            fbo_incomplete("stencil attachment incomplete", -1);
+            return;
+         }
+      }
+      else {
+         att = &fb->Attachment[BUFFER_COLOR0 + i];
+         test_attachment_completeness(ctx, GL_COLOR, att);
+         if (!att->Complete) {
+            fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
+            fbo_incomplete("color attachment incomplete", i);
+            return;
+         }
+      }
+
+      /* get width, height, format of the renderbuffer/texture
+       */
+      if (att->Type == GL_TEXTURE) {
+         const struct gl_texture_image *texImg
+            = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
+         minWidth = MIN2(minWidth, texImg->Width);
+         maxWidth = MAX2(maxWidth, texImg->Width);
+         minHeight = MIN2(minHeight, texImg->Height);
+         maxHeight = MAX2(maxHeight, texImg->Height);
+         f = texImg->_BaseFormat;
+         mesaFormat = texImg->TexFormat;
+         numImages++;
+         if (!_mesa_is_legal_color_format(ctx, f) &&
+             !is_legal_depth_format(ctx, f)) {
+            fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
+            fbo_incomplete("texture attachment incomplete", -1);
+            return;
+         }
+      }
+      else if (att->Type == GL_RENDERBUFFER_EXT) {
+         minWidth = MIN2(minWidth, att->Renderbuffer->Width);
+         maxWidth = MAX2(minWidth, att->Renderbuffer->Width);
+         minHeight = MIN2(minHeight, att->Renderbuffer->Height);
+         maxHeight = MAX2(minHeight, att->Renderbuffer->Height);
+         f = att->Renderbuffer->InternalFormat;
+         mesaFormat = att->Renderbuffer->Format;
+         numImages++;
+      }
+      else {
+         assert(att->Type == GL_NONE);
+         continue;
+      }
+
+      if (numSamples < 0) {
+         /* first buffer */
+         numSamples = att->Renderbuffer->NumSamples;
+      }
+
+      /* check if integer color */
+      fb->_IntegerColor = _mesa_is_format_integer_color(mesaFormat);
+
+      /* Error-check width, height, format, samples
+       */
+      if (numImages == 1) {
+         /* save format, num samples */
+         if (i >= 0) {
+            intFormat = f;
+         }
+      }
+      else {
+         if (!ctx->Extensions.ARB_framebuffer_object) {
+            /* check that width, height, format are same */
+            if (minWidth != maxWidth || minHeight != maxHeight) {
+               fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT;
+               fbo_incomplete("width or height mismatch", -1);
+               return;
+            }
+            /* check that all color buffer have same format */
+            if (intFormat != GL_NONE && f != intFormat) {
+               fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
+               fbo_incomplete("format mismatch", -1);
+               return;
+            }
+         }
+         if (att->Renderbuffer &&
+             att->Renderbuffer->NumSamples != numSamples) {
+            fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
+            fbo_incomplete("inconsistant number of samples", i);
+            return;
+         }            
+
+      }
+   }
+
+#if FEATURE_GL
+   if (ctx->API == API_OPENGL) {
+      /* Check that all DrawBuffers are present */
+      for (j = 0; j < ctx->Const.MaxDrawBuffers; j++) {
+	 if (fb->ColorDrawBuffer[j] != GL_NONE) {
+	    const struct gl_renderbuffer_attachment *att
+	       = _mesa_get_attachment(ctx, fb, fb->ColorDrawBuffer[j]);
+	    assert(att);
+	    if (att->Type == GL_NONE) {
+	       fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT;
+	       fbo_incomplete("missing drawbuffer", j);
+	       return;
+	    }
+	 }
+      }
+
+      /* Check that the ReadBuffer is present */
+      if (fb->ColorReadBuffer != GL_NONE) {
+	 const struct gl_renderbuffer_attachment *att
+	    = _mesa_get_attachment(ctx, fb, fb->ColorReadBuffer);
+	 assert(att);
+	 if (att->Type == GL_NONE) {
+	    fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT;
+            fbo_incomplete("missing readbuffer", -1);
+	    return;
+	 }
+      }
+   }
+#else
+   (void) j;
+#endif
+
+   if (numImages == 0) {
+      fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT;
+      fbo_incomplete("no attachments", -1);
+      return;
+   }
+
+   /* Provisionally set status = COMPLETE ... */
+   fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT;
+
+   /* ... but the driver may say the FB is incomplete.
+    * Drivers will most likely set the status to GL_FRAMEBUFFER_UNSUPPORTED
+    * if anything.
+    */
+   if (ctx->Driver.ValidateFramebuffer) {
+      ctx->Driver.ValidateFramebuffer(ctx, fb);
+      if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+         fbo_incomplete("driver marked FBO as incomplete", -1);
+      }
+   }
+
+   if (fb->_Status == GL_FRAMEBUFFER_COMPLETE_EXT) {
+      /*
+       * Note that if ARB_framebuffer_object is supported and the attached
+       * renderbuffers/textures are different sizes, the framebuffer
+       * width/height will be set to the smallest width/height.
+       */
+      fb->Width = minWidth;
+      fb->Height = minHeight;
+
+      /* finally, update the visual info for the framebuffer */
+      _mesa_update_framebuffer_visual(ctx, fb);
+   }
+}
+
+
+GLboolean GLAPIENTRY
+_mesa_IsRenderbufferEXT(GLuint renderbuffer)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
+   if (renderbuffer) {
+      struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
+      if (rb != NULL && rb != &DummyRenderbuffer)
+         return GL_TRUE;
+   }
+   return GL_FALSE;
+}
+
+
+void GLAPIENTRY
+_mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer)
+{
+   struct gl_renderbuffer *newRb;
+   GET_CURRENT_CONTEXT(ctx);
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (target != GL_RENDERBUFFER_EXT) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glBindRenderbufferEXT(target)");
+      return;
+   }
+
+   /* No need to flush here since the render buffer binding has no
+    * effect on rendering state.
+    */
+
+   if (renderbuffer) {
+      newRb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
+      if (newRb == &DummyRenderbuffer) {
+         /* ID was reserved, but no real renderbuffer object made yet */
+         newRb = NULL;
+      }
+      else if (!newRb && ctx->Extensions.ARB_framebuffer_object) {
+         /* All RB IDs must be Gen'd */
+         _mesa_error(ctx, GL_INVALID_OPERATION, "glBindRenderbuffer(buffer)");
+         return;
+      }
+
+      if (!newRb) {
+	 /* create new renderbuffer object */
+	 newRb = ctx->Driver.NewRenderbuffer(ctx, renderbuffer);
+	 if (!newRb) {
+	    _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindRenderbufferEXT");
+	    return;
+	 }
+         ASSERT(newRb->AllocStorage);
+         _mesa_HashInsert(ctx->Shared->RenderBuffers, renderbuffer, newRb);
+         newRb->RefCount = 1; /* referenced by hash table */
+      }
+   }
+   else {
+      newRb = NULL;
+   }
+
+   ASSERT(newRb != &DummyRenderbuffer);
+
+   _mesa_reference_renderbuffer(&ctx->CurrentRenderbuffer, newRb);
+}
+
+
+/**
+ * If the given renderbuffer is anywhere attached to the framebuffer, detach
+ * the renderbuffer.
+ * This is used when a renderbuffer object is deleted.
+ * The spec calls for unbinding.
+ */
+static void
+detach_renderbuffer(struct gl_context *ctx,
+                    struct gl_framebuffer *fb,
+                    struct gl_renderbuffer *rb)
+{
+   GLuint i;
+   for (i = 0; i < BUFFER_COUNT; i++) {
+      if (fb->Attachment[i].Renderbuffer == rb) {
+         _mesa_remove_attachment(ctx, &fb->Attachment[i]);
+      }
+   }
+   invalidate_framebuffer(fb);
+}
+
+
+void GLAPIENTRY
+_mesa_DeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers)
+{
+   GLint i;
+   GET_CURRENT_CONTEXT(ctx);
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+   for (i = 0; i < n; i++) {
+      if (renderbuffers[i] > 0) {
+	 struct gl_renderbuffer *rb;
+	 rb = _mesa_lookup_renderbuffer(ctx, renderbuffers[i]);
+	 if (rb) {
+            /* check if deleting currently bound renderbuffer object */
+            if (rb == ctx->CurrentRenderbuffer) {
+               /* bind default */
+               ASSERT(rb->RefCount >= 2);
+               _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
+            }
+
+            if (ctx->DrawBuffer->Name) {
+               detach_renderbuffer(ctx, ctx->DrawBuffer, rb);
+            }
+            if (ctx->ReadBuffer->Name && ctx->ReadBuffer != ctx->DrawBuffer) {
+               detach_renderbuffer(ctx, ctx->ReadBuffer, rb);
+            }
+
+	    /* Remove from hash table immediately, to free the ID.
+             * But the object will not be freed until it's no longer
+             * referenced anywhere else.
+             */
+	    _mesa_HashRemove(ctx->Shared->RenderBuffers, renderbuffers[i]);
+
+            if (rb != &DummyRenderbuffer) {
+               /* no longer referenced by hash table */
+               _mesa_reference_renderbuffer(&rb, NULL);
+	    }
+	 }
+      }
+   }
+}
+
+
+void GLAPIENTRY
+_mesa_GenRenderbuffersEXT(GLsizei n, GLuint *renderbuffers)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   GLuint first;
+   GLint i;
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (n < 0) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "glGenRenderbuffersEXT(n)");
+      return;
+   }
+
+   if (!renderbuffers)
+      return;
+
+   first = _mesa_HashFindFreeKeyBlock(ctx->Shared->RenderBuffers, n);
+
+   for (i = 0; i < n; i++) {
+      GLuint name = first + i;
+      renderbuffers[i] = name;
+      /* insert dummy placeholder into hash table */
+      _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
+      _mesa_HashInsert(ctx->Shared->RenderBuffers, name, &DummyRenderbuffer);
+      _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
+   }
+}
+
+
+/**
+ * Given an internal format token for a render buffer, return the
+ * corresponding base format (one of GL_RGB, GL_RGBA, GL_STENCIL_INDEX,
+ * GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL_EXT, GL_ALPHA, GL_LUMINANCE,
+ * GL_LUMINANCE_ALPHA, GL_INTENSITY, etc).
+ *
+ * This is similar to _mesa_base_tex_format() but the set of valid
+ * internal formats is different.
+ *
+ * Note that even if a format is determined to be legal here, validation
+ * of the FBO may fail if the format is not supported by the driver/GPU.
+ *
+ * \param internalFormat  as passed to glRenderbufferStorage()
+ * \return the base internal format, or 0 if internalFormat is illegal
+ */
+GLenum
+_mesa_base_fbo_format(struct gl_context *ctx, GLenum internalFormat)
+{
+   /*
+    * Notes: some formats such as alpha, luminance, etc. were added
+    * with GL_ARB_framebuffer_object.
+    */
+   switch (internalFormat) {
+   case GL_ALPHA:
+   case GL_ALPHA4:
+   case GL_ALPHA8:
+   case GL_ALPHA12:
+   case GL_ALPHA16:
+      return ctx->Extensions.ARB_framebuffer_object ? GL_ALPHA : 0;
+   case GL_LUMINANCE:
+   case GL_LUMINANCE4:
+   case GL_LUMINANCE8:
+   case GL_LUMINANCE12:
+   case GL_LUMINANCE16:
+      return ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE : 0;
+   case GL_LUMINANCE_ALPHA:
+   case GL_LUMINANCE4_ALPHA4:
+   case GL_LUMINANCE6_ALPHA2:
+   case GL_LUMINANCE8_ALPHA8:
+   case GL_LUMINANCE12_ALPHA4:
+   case GL_LUMINANCE12_ALPHA12:
+   case GL_LUMINANCE16_ALPHA16:
+      return ctx->Extensions.ARB_framebuffer_object ? GL_LUMINANCE_ALPHA : 0;
+   case GL_INTENSITY:
+   case GL_INTENSITY4:
+   case GL_INTENSITY8:
+   case GL_INTENSITY12:
+   case GL_INTENSITY16:
+      return ctx->Extensions.ARB_framebuffer_object ? GL_INTENSITY : 0;
+   case GL_RGB:
+   case GL_R3_G3_B2:
+   case GL_RGB4:
+   case GL_RGB5:
+   case GL_RGB8:
+   case GL_RGB10:
+   case GL_RGB12:
+   case GL_RGB16:
+   case GL_SRGB8_EXT:
+      return GL_RGB;
+   case GL_RGBA:
+   case GL_RGBA2:
+   case GL_RGBA4:
+   case GL_RGB5_A1:
+   case GL_RGBA8:
+   case GL_RGB10_A2:
+   case GL_RGBA12:
+   case GL_RGBA16:
+   case GL_RGBA16_SNORM:
+   case GL_SRGB8_ALPHA8_EXT:
+      return GL_RGBA;
+   case GL_STENCIL_INDEX:
+   case GL_STENCIL_INDEX1_EXT:
+   case GL_STENCIL_INDEX4_EXT:
+   case GL_STENCIL_INDEX8_EXT:
+   case GL_STENCIL_INDEX16_EXT:
+      return GL_STENCIL_INDEX;
+   case GL_DEPTH_COMPONENT:
+   case GL_DEPTH_COMPONENT16:
+   case GL_DEPTH_COMPONENT24:
+   case GL_DEPTH_COMPONENT32:
+      return GL_DEPTH_COMPONENT;
+   case GL_DEPTH_STENCIL_EXT:
+   case GL_DEPTH24_STENCIL8_EXT:
+      if (ctx->Extensions.EXT_packed_depth_stencil)
+         return GL_DEPTH_STENCIL_EXT;
+      else
+         return 0;
+   case GL_RED:
+   case GL_R8:
+   case GL_R16:
+      return ctx->Extensions.ARB_texture_rg ? GL_RED : 0;
+   case GL_RG:
+   case GL_RG8:
+   case GL_RG16:
+      return ctx->Extensions.ARB_texture_rg ? GL_RG : 0;
+   /* XXX add floating point and integer formats eventually */
+   default:
+      return 0;
+   }
+}
+
+
+/** sentinal value, see below */
+#define NO_SAMPLES 1000
+
+
+/**
+ * Helper function used by _mesa_RenderbufferStorageEXT() and 
+ * _mesa_RenderbufferStorageMultisample().
+ * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorageEXT().
+ */
+static void
+renderbuffer_storage(GLenum target, GLenum internalFormat,
+                     GLsizei width, GLsizei height, GLsizei samples)
+{
+   const char *func = samples == NO_SAMPLES ?
+      "glRenderbufferStorage" : "RenderbufferStorageMultisample";
+   struct gl_renderbuffer *rb;
+   GLenum baseFormat;
+   GET_CURRENT_CONTEXT(ctx);
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (target != GL_RENDERBUFFER_EXT) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func);
+      return;
+   }
+
+   baseFormat = _mesa_base_fbo_format(ctx, internalFormat);
+   if (baseFormat == 0) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "%s(internalFormat)", func);
+      return;
+   }
+
+   if (width < 1 || width > (GLsizei) ctx->Const.MaxRenderbufferSize) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "%s(width)", func);
+      return;
+   }
+
+   if (height < 1 || height > (GLsizei) ctx->Const.MaxRenderbufferSize) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "%s(height)", func);
+      return;
+   }
+
+   if (samples == NO_SAMPLES) {
+      /* NumSamples == 0 indicates non-multisampling */
+      samples = 0;
+   }
+   else if (samples > (GLsizei) ctx->Const.MaxSamples) {
+      /* note: driver may choose to use more samples than what's requested */
+      _mesa_error(ctx, GL_INVALID_VALUE, "%s(samples)", func);
+      return;
+   }
+
+   rb = ctx->CurrentRenderbuffer;
+   if (!rb) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
+      return;
+   }
+
+   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+   if (rb->InternalFormat == internalFormat &&
+       rb->Width == (GLuint) width &&
+       rb->Height == (GLuint) height) {
+      /* no change in allocation needed */
+      return;
+   }
+
+   /* These MUST get set by the AllocStorage func */
+   rb->Format = MESA_FORMAT_NONE;
+   rb->NumSamples = samples;
+
+   /* Now allocate the storage */
+   ASSERT(rb->AllocStorage);
+   if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) {
+      /* No error - check/set fields now */
+      assert(rb->Format != MESA_FORMAT_NONE);
+      assert(rb->Width == (GLuint) width);
+      assert(rb->Height == (GLuint) height);
+      rb->InternalFormat = internalFormat;
+      rb->_BaseFormat = baseFormat;
+      assert(rb->_BaseFormat != 0);
+   }
+   else {
+      /* Probably ran out of memory - clear the fields */
+      rb->Width = 0;
+      rb->Height = 0;
+      rb->Format = MESA_FORMAT_NONE;
+      rb->InternalFormat = GL_NONE;
+      rb->_BaseFormat = GL_NONE;
+      rb->NumSamples = 0;
+   }
+
+   /*
+   test_framebuffer_completeness(ctx, fb);
+   */
+   /* XXX if this renderbuffer is attached anywhere, invalidate attachment
+    * points???
+    */
+}
+
+
+#if FEATURE_OES_EGL_image
+void GLAPIENTRY
+_mesa_EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
+{
+   struct gl_renderbuffer *rb;
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (!ctx->Extensions.OES_EGL_image) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glEGLImageTargetRenderbufferStorageOES(unsupported)");
+      return;
+   }
+
+   if (target != GL_RENDERBUFFER) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "EGLImageTargetRenderbufferStorageOES");
+      return;
+   }
+
+   rb = ctx->CurrentRenderbuffer;
+   if (!rb) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "EGLImageTargetRenderbufferStorageOES");
+      return;
+   }
+
+   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+   ctx->Driver.EGLImageTargetRenderbufferStorage(ctx, rb, image);
+}
+#endif
+
+
+/**
+ * Helper function for _mesa_GetRenderbufferParameterivEXT() and
+ * _mesa_GetFramebufferAttachmentParameterivEXT()
+ * We have to be careful to respect the base format.  For example, if a
+ * renderbuffer/texture was created with internalFormat=GL_RGB but the
+ * driver actually chose a GL_RGBA format, when the user queries ALPHA_SIZE
+ * we need to return zero.
+ */
+static GLint
+get_component_bits(GLenum pname, GLenum baseFormat, gl_format format)
+{
+   switch (pname) {
+   case GL_RENDERBUFFER_RED_SIZE_EXT:
+   case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
+      if (baseFormat == GL_RGB || baseFormat == GL_RGBA ||
+	  baseFormat == GL_RG || baseFormat == GL_RED)
+         return _mesa_get_format_bits(format, pname);
+      else
+         return 0;
+   case GL_RENDERBUFFER_GREEN_SIZE_EXT:
+   case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
+      if (baseFormat == GL_RGB || baseFormat == GL_RGBA || baseFormat == GL_RG)
+         return _mesa_get_format_bits(format, pname);
+      else
+         return 0;
+   case GL_RENDERBUFFER_BLUE_SIZE_EXT:
+   case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
+      if (baseFormat == GL_RGB || baseFormat == GL_RGBA)
+         return _mesa_get_format_bits(format, pname);
+      else
+         return 0;
+   case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
+   case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
+      if (baseFormat == GL_RGBA || baseFormat == GL_ALPHA ||
+	  baseFormat == GL_LUMINANCE_ALPHA)
+         return _mesa_get_format_bits(format, pname);
+      else
+         return 0;
+   case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
+   case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
+      if (baseFormat == GL_DEPTH_COMPONENT || baseFormat == GL_DEPTH_STENCIL)
+         return _mesa_get_format_bits(format, pname);
+      else
+         return 0;
+   case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
+   case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
+      if (baseFormat == GL_STENCIL_INDEX || baseFormat == GL_DEPTH_STENCIL)
+         return _mesa_get_format_bits(format, pname);
+      else
+         return 0;
+   default:
+      return 0;
+   }
+}
+
+
+
+void GLAPIENTRY
+_mesa_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
+                             GLsizei width, GLsizei height)
+{
+   /* GL_ARB_fbo says calling this function is equivalent to calling
+    * glRenderbufferStorageMultisample() with samples=0.  We pass in
+    * a token value here just for error reporting purposes.
+    */
+   renderbuffer_storage(target, internalFormat, width, height, NO_SAMPLES);
+}
+
+
+void GLAPIENTRY
+_mesa_RenderbufferStorageMultisample(GLenum target, GLsizei samples,
+                                     GLenum internalFormat,
+                                     GLsizei width, GLsizei height)
+{
+   renderbuffer_storage(target, internalFormat, width, height, samples);
+}
+
+
+/**
+ * OpenGL ES version of glRenderBufferStorage.
+ */
+void GLAPIENTRY
+_es_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
+			   GLsizei width, GLsizei height)
+{
+   switch (internalFormat) {
+   case GL_RGB565:
+      /* XXX this confuses GL_RENDERBUFFER_INTERNAL_FORMAT_OES */
+      /* choose a closest format */
+      internalFormat = GL_RGB5;
+      break;
+   default:
+      break;
+   }
+
+   renderbuffer_storage(target, internalFormat, width, height, 0);
+}
+
+
+void GLAPIENTRY
+_mesa_GetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params)
+{
+   struct gl_renderbuffer *rb;
+   GET_CURRENT_CONTEXT(ctx);
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (target != GL_RENDERBUFFER_EXT) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glGetRenderbufferParameterivEXT(target)");
+      return;
+   }
+
+   rb = ctx->CurrentRenderbuffer;
+   if (!rb) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glGetRenderbufferParameterivEXT");
+      return;
+   }
+
+   /* No need to flush here since we're just quering state which is
+    * not effected by rendering.
+    */
+
+   switch (pname) {
+   case GL_RENDERBUFFER_WIDTH_EXT:
+      *params = rb->Width;
+      return;
+   case GL_RENDERBUFFER_HEIGHT_EXT:
+      *params = rb->Height;
+      return;
+   case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT:
+      *params = rb->InternalFormat;
+      return;
+   case GL_RENDERBUFFER_RED_SIZE_EXT:
+   case GL_RENDERBUFFER_GREEN_SIZE_EXT:
+   case GL_RENDERBUFFER_BLUE_SIZE_EXT:
+   case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
+   case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
+   case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
+      *params = get_component_bits(pname, rb->_BaseFormat, rb->Format);
+      break;
+   case GL_RENDERBUFFER_SAMPLES:
+      if (ctx->Extensions.ARB_framebuffer_object) {
+         *params = rb->NumSamples;
+         break;
+      }
+      /* fallthrough */
+   default:
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glGetRenderbufferParameterivEXT(target)");
+      return;
+   }
+}
+
+
+GLboolean GLAPIENTRY
+_mesa_IsFramebufferEXT(GLuint framebuffer)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
+   if (framebuffer) {
+      struct gl_framebuffer *rb = _mesa_lookup_framebuffer(ctx, framebuffer);
+      if (rb != NULL && rb != &DummyFramebuffer)
+         return GL_TRUE;
+   }
+   return GL_FALSE;
+}
+
+
+/**
+ * Check if any of the attachments of the given framebuffer are textures
+ * (render to texture).  Call ctx->Driver.RenderTexture() for such
+ * attachments.
+ */
+static void
+check_begin_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
+{
+   GLuint i;
+   ASSERT(ctx->Driver.RenderTexture);
+
+   if (fb->Name == 0)
+      return; /* can't render to texture with winsys framebuffers */
+
+   for (i = 0; i < BUFFER_COUNT; i++) {
+      struct gl_renderbuffer_attachment *att = fb->Attachment + i;
+      struct gl_texture_object *texObj = att->Texture;
+      if (texObj
+          && texObj->Image[att->CubeMapFace][att->TextureLevel]) {
+         ctx->Driver.RenderTexture(ctx, fb, att);
+      }
+   }
+}
+
+
+/**
+ * Examine all the framebuffer's attachments to see if any are textures.
+ * If so, call ctx->Driver.FinishRenderTexture() for each texture to
+ * notify the device driver that the texture image may have changed.
+ */
+static void
+check_end_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
+{
+   if (fb->Name == 0)
+      return; /* can't render to texture with winsys framebuffers */
+
+   if (ctx->Driver.FinishRenderTexture) {
+      GLuint i;
+      for (i = 0; i < BUFFER_COUNT; i++) {
+         struct gl_renderbuffer_attachment *att = fb->Attachment + i;
+         if (att->Texture && att->Renderbuffer) {
+            ctx->Driver.FinishRenderTexture(ctx, att);
+         }
+      }
+   }
+}
+
+
+void GLAPIENTRY
+_mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer)
+{
+   struct gl_framebuffer *newDrawFb, *newReadFb;
+   struct gl_framebuffer *oldDrawFb, *oldReadFb;
+   GLboolean bindReadBuf, bindDrawBuf;
+   GET_CURRENT_CONTEXT(ctx);
+
+#ifdef DEBUG
+   if (ctx->Extensions.ARB_framebuffer_object) {
+      ASSERT(ctx->Extensions.EXT_framebuffer_object);
+      ASSERT(ctx->Extensions.EXT_framebuffer_blit);
+   }
+#endif
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (!ctx->Extensions.EXT_framebuffer_object) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glBindFramebufferEXT(unsupported)");
+      return;
+   }
+
+   switch (target) {
+#if FEATURE_EXT_framebuffer_blit
+   case GL_DRAW_FRAMEBUFFER_EXT:
+      if (!ctx->Extensions.EXT_framebuffer_blit) {
+         _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
+         return;
+      }
+      bindDrawBuf = GL_TRUE;
+      bindReadBuf = GL_FALSE;
+      break;
+   case GL_READ_FRAMEBUFFER_EXT:
+      if (!ctx->Extensions.EXT_framebuffer_blit) {
+         _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
+         return;
+      }
+      bindDrawBuf = GL_FALSE;
+      bindReadBuf = GL_TRUE;
+      break;
+#endif
+   case GL_FRAMEBUFFER_EXT:
+      bindDrawBuf = GL_TRUE;
+      bindReadBuf = GL_TRUE;
+      break;
+   default:
+      _mesa_error(ctx, GL_INVALID_ENUM, "glBindFramebufferEXT(target)");
+      return;
+   }
+
+   if (framebuffer) {
+      /* Binding a user-created framebuffer object */
+      newDrawFb = _mesa_lookup_framebuffer(ctx, framebuffer);
+      if (newDrawFb == &DummyFramebuffer) {
+         /* ID was reserved, but no real framebuffer object made yet */
+         newDrawFb = NULL;
+      }
+      else if (!newDrawFb && ctx->Extensions.ARB_framebuffer_object) {
+         /* All FBO IDs must be Gen'd */
+         _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFramebuffer(buffer)");
+         return;
+      }
+
+      if (!newDrawFb) {
+	 /* create new framebuffer object */
+	 newDrawFb = ctx->Driver.NewFramebuffer(ctx, framebuffer);
+	 if (!newDrawFb) {
+	    _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFramebufferEXT");
+	    return;
+	 }
+         _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newDrawFb);
+      }
+      newReadFb = newDrawFb;
+   }
+   else {
+      /* Binding the window system framebuffer (which was originally set
+       * with MakeCurrent).
+       */
+      newDrawFb = ctx->WinSysDrawBuffer;
+      newReadFb = ctx->WinSysReadBuffer;
+   }
+
+   ASSERT(newDrawFb);
+   ASSERT(newDrawFb != &DummyFramebuffer);
+
+   /* save pointers to current/old framebuffers */
+   oldDrawFb = ctx->DrawBuffer;
+   oldReadFb = ctx->ReadBuffer;
+
+   /* check if really changing bindings */
+   if (oldDrawFb == newDrawFb)
+      bindDrawBuf = GL_FALSE;
+   if (oldReadFb == newReadFb)
+      bindReadBuf = GL_FALSE;
+
+   /*
+    * OK, now bind the new Draw/Read framebuffers, if they're changing.
+    *
+    * We also check if we're beginning and/or ending render-to-texture.
+    * When a framebuffer with texture attachments is unbound, call
+    * ctx->Driver.FinishRenderTexture().
+    * When a framebuffer with texture attachments is bound, call
+    * ctx->Driver.RenderTexture().
+    *
+    * Note that if the ReadBuffer has texture attachments we don't consider
+    * that a render-to-texture case.
+    */
+   if (bindReadBuf) {
+      FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+      /* check if old readbuffer was render-to-texture */
+      check_end_texture_render(ctx, oldReadFb);
+
+      _mesa_reference_framebuffer(&ctx->ReadBuffer, newReadFb);
+   }
+
+   if (bindDrawBuf) {
+      FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+      /* check if old read/draw buffers were render-to-texture */
+      if (!bindReadBuf)
+         check_end_texture_render(ctx, oldReadFb);
+
+      if (oldDrawFb != oldReadFb)
+         check_end_texture_render(ctx, oldDrawFb);
+
+      /* check if newly bound framebuffer has any texture attachments */
+      check_begin_texture_render(ctx, newDrawFb);
+
+      _mesa_reference_framebuffer(&ctx->DrawBuffer, newDrawFb);
+   }
+
+   if ((bindDrawBuf || bindReadBuf) && ctx->Driver.BindFramebuffer) {
+      ctx->Driver.BindFramebuffer(ctx, target, newDrawFb, newReadFb);
+   }
+}
+
+
+void GLAPIENTRY
+_mesa_DeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers)
+{
+   GLint i;
+   GET_CURRENT_CONTEXT(ctx);
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+   for (i = 0; i < n; i++) {
+      if (framebuffers[i] > 0) {
+	 struct gl_framebuffer *fb;
+	 fb = _mesa_lookup_framebuffer(ctx, framebuffers[i]);
+	 if (fb) {
+            ASSERT(fb == &DummyFramebuffer || fb->Name == framebuffers[i]);
+
+            /* check if deleting currently bound framebuffer object */
+            if (ctx->Extensions.EXT_framebuffer_blit) {
+               /* separate draw/read binding points */
+               if (fb == ctx->DrawBuffer) {
+                  /* bind default */
+                  ASSERT(fb->RefCount >= 2);
+                  _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
+               }
+               if (fb == ctx->ReadBuffer) {
+                  /* bind default */
+                  ASSERT(fb->RefCount >= 2);
+                  _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
+               }
+            }
+            else {
+               /* only one binding point for read/draw buffers */
+               if (fb == ctx->DrawBuffer || fb == ctx->ReadBuffer) {
+                  /* bind default */
+                  ASSERT(fb->RefCount >= 2);
+                  _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+               }    
+            }
+
+	    /* remove from hash table immediately, to free the ID */
+	    _mesa_HashRemove(ctx->Shared->FrameBuffers, framebuffers[i]);
+
+            if (fb != &DummyFramebuffer) {
+               /* But the object will not be freed until it's no longer
+                * bound in any context.
+                */
+               _mesa_reference_framebuffer(&fb, NULL);
+	    }
+	 }
+      }
+   }
+}
+
+
+void GLAPIENTRY
+_mesa_GenFramebuffersEXT(GLsizei n, GLuint *framebuffers)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   GLuint first;
+   GLint i;
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (n < 0) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "glGenFramebuffersEXT(n)");
+      return;
+   }
+
+   if (!framebuffers)
+      return;
+
+   first = _mesa_HashFindFreeKeyBlock(ctx->Shared->FrameBuffers, n);
+
+   for (i = 0; i < n; i++) {
+      GLuint name = first + i;
+      framebuffers[i] = name;
+      /* insert dummy placeholder into hash table */
+      _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
+      _mesa_HashInsert(ctx->Shared->FrameBuffers, name, &DummyFramebuffer);
+      _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
+   }
+}
+
+
+
+GLenum GLAPIENTRY
+_mesa_CheckFramebufferStatusEXT(GLenum target)
+{
+   struct gl_framebuffer *buffer;
+   GET_CURRENT_CONTEXT(ctx);
+
+   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
+
+   switch (target) {
+#if FEATURE_EXT_framebuffer_blit
+   case GL_DRAW_FRAMEBUFFER_EXT:
+      if (!ctx->Extensions.EXT_framebuffer_blit) {
+         _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
+         return 0;
+      }
+      buffer = ctx->DrawBuffer;
+      break;
+   case GL_READ_FRAMEBUFFER_EXT:
+      if (!ctx->Extensions.EXT_framebuffer_blit) {
+         _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
+         return 0;
+      }
+      buffer = ctx->ReadBuffer;
+      break;
+#endif
+   case GL_FRAMEBUFFER_EXT:
+      buffer = ctx->DrawBuffer;
+      break;
+   default:
+      _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
+      return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
+   }
+
+   if (buffer->Name == 0) {
+      /* The window system / default framebuffer is always complete */
+      return GL_FRAMEBUFFER_COMPLETE_EXT;
+   }
+
+   /* No need to flush here */
+
+   if (buffer->_Status != GL_FRAMEBUFFER_COMPLETE) {
+      _mesa_test_framebuffer_completeness(ctx, buffer);
+   }
+
+   return buffer->_Status;
+}
+
+
+
+/**
+ * Common code called by glFramebufferTexture1D/2D/3DEXT().
+ */
+static void
+framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target, 
+                    GLenum attachment, GLenum textarget, GLuint texture,
+                    GLint level, GLint zoffset)
+{
+   struct gl_renderbuffer_attachment *att;
+   struct gl_texture_object *texObj = NULL;
+   struct gl_framebuffer *fb;
+   GLboolean error = GL_FALSE;
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   switch (target) {
+   case GL_READ_FRAMEBUFFER_EXT:
+      error = !ctx->Extensions.EXT_framebuffer_blit;
+      fb = ctx->ReadBuffer;
+      break;
+   case GL_DRAW_FRAMEBUFFER_EXT:
+      error = !ctx->Extensions.EXT_framebuffer_blit;
+      /* fall-through */
+   case GL_FRAMEBUFFER_EXT:
+      fb = ctx->DrawBuffer;
+      break;
+   default:
+      error = GL_TRUE;
+   }
+
+   if (error) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glFramebufferTexture%sEXT(target=0x%x)", caller, target);
+      return;
+   }
+
+   ASSERT(fb);
+
+   /* check framebuffer binding */
+   if (fb->Name == 0) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glFramebufferTexture%sEXT", caller);
+      return;
+   }
+
+
+   /* The textarget, level, and zoffset parameters are only validated if
+    * texture is non-zero.
+    */
+   if (texture) {
+      GLboolean err = GL_TRUE;
+
+      texObj = _mesa_lookup_texture(ctx, texture);
+      if (texObj != NULL) {
+         if (textarget == 0) {
+            /* XXX what's the purpose of this? */
+            err = (texObj->Target != GL_TEXTURE_3D) &&
+                (texObj->Target != GL_TEXTURE_1D_ARRAY_EXT) &&
+                (texObj->Target != GL_TEXTURE_2D_ARRAY_EXT);
+         }
+         else {
+            err = (texObj->Target == GL_TEXTURE_CUBE_MAP)
+                ? !IS_CUBE_FACE(textarget)
+                : (texObj->Target != textarget);
+         }
+      }
+      else {
+         /* can't render to a non-existant texture */
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glFramebufferTexture%sEXT(non existant texture)",
+                     caller);
+         return;
+      }
+
+      if (err) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glFramebufferTexture%sEXT(texture target mismatch)",
+                     caller);
+         return;
+      }
+
+      if (texObj->Target == GL_TEXTURE_3D) {
+         const GLint maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
+         if (zoffset < 0 || zoffset >= maxSize) {
+            _mesa_error(ctx, GL_INVALID_VALUE,
+                        "glFramebufferTexture%sEXT(zoffset)", caller);
+            return;
+         }
+      }
+      else if ((texObj->Target == GL_TEXTURE_1D_ARRAY_EXT) ||
+               (texObj->Target == GL_TEXTURE_2D_ARRAY_EXT)) {
+         if (zoffset < 0 || zoffset >= ctx->Const.MaxArrayTextureLayers) {
+            _mesa_error(ctx, GL_INVALID_VALUE,
+                        "glFramebufferTexture%sEXT(layer)", caller);
+            return;
+         }
+      }
+
+      if ((level < 0) || 
+          (level >= _mesa_max_texture_levels(ctx, texObj->Target))) {
+         _mesa_error(ctx, GL_INVALID_VALUE,
+                     "glFramebufferTexture%sEXT(level)", caller);
+         return;
+      }
+   }
+
+   att = _mesa_get_attachment(ctx, fb, attachment);
+   if (att == NULL) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glFramebufferTexture%sEXT(attachment)", caller);
+      return;
+   }
+
+   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+   _glthread_LOCK_MUTEX(fb->Mutex);
+   if (texObj) {
+      _mesa_set_texture_attachment(ctx, fb, att, texObj, textarget,
+                                   level, zoffset);
+      /* Set the render-to-texture flag.  We'll check this flag in
+       * glTexImage() and friends to determine if we need to revalidate
+       * any FBOs that might be rendering into this texture.
+       * This flag never gets cleared since it's non-trivial to determine
+       * when all FBOs might be done rendering to this texture.  That's OK
+       * though since it's uncommon to render to a texture then repeatedly
+       * call glTexImage() to change images in the texture.
+       */
+      texObj->_RenderToTexture = GL_TRUE;
+   }
+   else {
+      _mesa_remove_attachment(ctx, att);
+   }
+
+   invalidate_framebuffer(fb);
+
+   _glthread_UNLOCK_MUTEX(fb->Mutex);
+}
+
+
+
+void GLAPIENTRY
+_mesa_FramebufferTexture1DEXT(GLenum target, GLenum attachment,
+                              GLenum textarget, GLuint texture, GLint level)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if ((texture != 0) && (textarget != GL_TEXTURE_1D)) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glFramebufferTexture1DEXT(textarget)");
+      return;
+   }
+
+   framebuffer_texture(ctx, "1D", target, attachment, textarget, texture,
+                       level, 0);
+}
+
+
+void GLAPIENTRY
+_mesa_FramebufferTexture2DEXT(GLenum target, GLenum attachment,
+                              GLenum textarget, GLuint texture, GLint level)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if ((texture != 0) &&
+       (textarget != GL_TEXTURE_2D) &&
+       (textarget != GL_TEXTURE_RECTANGLE_ARB) &&
+       (!IS_CUBE_FACE(textarget))) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glFramebufferTexture2DEXT(textarget=0x%x)", textarget);
+      return;
+   }
+
+   framebuffer_texture(ctx, "2D", target, attachment, textarget, texture,
+                       level, 0);
+}
+
+
+void GLAPIENTRY
+_mesa_FramebufferTexture3DEXT(GLenum target, GLenum attachment,
+                              GLenum textarget, GLuint texture,
+                              GLint level, GLint zoffset)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if ((texture != 0) && (textarget != GL_TEXTURE_3D)) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glFramebufferTexture3DEXT(textarget)");
+      return;
+   }
+
+   framebuffer_texture(ctx, "3D", target, attachment, textarget, texture,
+                       level, zoffset);
+}
+
+
+void GLAPIENTRY
+_mesa_FramebufferTextureLayerEXT(GLenum target, GLenum attachment,
+                                 GLuint texture, GLint level, GLint layer)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   framebuffer_texture(ctx, "Layer", target, attachment, 0, texture,
+                       level, layer);
+}
+
+
+void GLAPIENTRY
+_mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment,
+                                 GLenum renderbufferTarget,
+                                 GLuint renderbuffer)
+{
+   struct gl_renderbuffer_attachment *att;
+   struct gl_framebuffer *fb;
+   struct gl_renderbuffer *rb;
+   GET_CURRENT_CONTEXT(ctx);
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   switch (target) {
+#if FEATURE_EXT_framebuffer_blit
+   case GL_DRAW_FRAMEBUFFER_EXT:
+      if (!ctx->Extensions.EXT_framebuffer_blit) {
+         _mesa_error(ctx, GL_INVALID_ENUM,
+                     "glFramebufferRenderbufferEXT(target)");
+         return;
+      }
+      fb = ctx->DrawBuffer;
+      break;
+   case GL_READ_FRAMEBUFFER_EXT:
+      if (!ctx->Extensions.EXT_framebuffer_blit) {
+         _mesa_error(ctx, GL_INVALID_ENUM,
+                     "glFramebufferRenderbufferEXT(target)");
+         return;
+      }
+      fb = ctx->ReadBuffer;
+      break;
+#endif
+   case GL_FRAMEBUFFER_EXT:
+      fb = ctx->DrawBuffer;
+      break;
+   default:
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glFramebufferRenderbufferEXT(target)");
+      return;
+   }
+
+   if (renderbufferTarget != GL_RENDERBUFFER_EXT) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glFramebufferRenderbufferEXT(renderbufferTarget)");
+      return;
+   }
+
+   if (fb->Name == 0) {
+      /* Can't attach new renderbuffers to a window system framebuffer */
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glFramebufferRenderbufferEXT");
+      return;
+   }
+
+   att = _mesa_get_attachment(ctx, fb, attachment);
+   if (att == NULL) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glFramebufferRenderbufferEXT(invalid attachment %s)",
+                  _mesa_lookup_enum_by_nr(attachment));
+      return;
+   }
+
+   if (renderbuffer) {
+      rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
+      if (!rb) {
+	 _mesa_error(ctx, GL_INVALID_OPERATION,
+		     "glFramebufferRenderbufferEXT(non-existant"
+                     " renderbuffer %u)", renderbuffer);
+	 return;
+      }
+      else if (rb == &DummyRenderbuffer) {
+         /* This is what NVIDIA does */
+	 _mesa_error(ctx, GL_INVALID_VALUE,
+		     "glFramebufferRenderbufferEXT(renderbuffer %u)",
+                     renderbuffer);
+	 return;
+      }
+   }
+   else {
+      /* remove renderbuffer attachment */
+      rb = NULL;
+   }
+
+   if (attachment == GL_DEPTH_STENCIL_ATTACHMENT &&
+       rb && rb->Format != MESA_FORMAT_NONE) {
+      /* make sure the renderbuffer is a depth/stencil format */
+      const GLenum baseFormat = _mesa_get_format_base_format(rb->Format);
+      if (baseFormat != GL_DEPTH_STENCIL) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glFramebufferRenderbufferEXT(renderbuffer"
+                     " is not DEPTH_STENCIL format)");
+         return;
+      }
+   }
+
+
+   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+   assert(ctx->Driver.FramebufferRenderbuffer);
+   ctx->Driver.FramebufferRenderbuffer(ctx, fb, attachment, rb);
+
+   /* Some subsequent GL commands may depend on the framebuffer's visual
+    * after the binding is updated.  Update visual info now.
+    */
+   _mesa_update_framebuffer_visual(ctx, fb);
+}
+
+
+void GLAPIENTRY
+_mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment,
+                                             GLenum pname, GLint *params)
+{
+   const struct gl_renderbuffer_attachment *att;
+   struct gl_framebuffer *buffer;
+   GET_CURRENT_CONTEXT(ctx);
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   switch (target) {
+#if FEATURE_EXT_framebuffer_blit
+   case GL_DRAW_FRAMEBUFFER_EXT:
+      if (!ctx->Extensions.EXT_framebuffer_blit) {
+         _mesa_error(ctx, GL_INVALID_ENUM,
+                     "glGetFramebufferAttachmentParameterivEXT(target)");
+         return;
+      }
+      buffer = ctx->DrawBuffer;
+      break;
+   case GL_READ_FRAMEBUFFER_EXT:
+      if (!ctx->Extensions.EXT_framebuffer_blit) {
+         _mesa_error(ctx, GL_INVALID_ENUM,
+                     "glGetFramebufferAttachmentParameterivEXT(target)");
+         return;
+      }
+      buffer = ctx->ReadBuffer;
+      break;
+#endif
+   case GL_FRAMEBUFFER_EXT:
+      buffer = ctx->DrawBuffer;
+      break;
+   default:
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glGetFramebufferAttachmentParameterivEXT(target)");
+      return;
+   }
+
+   if (buffer->Name == 0) {
+      /* the default / window-system FBO */
+      att = _mesa_get_fb0_attachment(ctx, buffer, attachment);
+   }
+   else {
+      /* user-created framebuffer FBO */
+      att = _mesa_get_attachment(ctx, buffer, attachment);
+   }
+
+   if (att == NULL) {
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glGetFramebufferAttachmentParameterivEXT(attachment)");
+      return;
+   }
+
+   if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
+      /* the depth and stencil attachments must point to the same buffer */
+      const struct gl_renderbuffer_attachment *depthAtt, *stencilAtt;
+      depthAtt = _mesa_get_attachment(ctx, buffer, GL_DEPTH_ATTACHMENT);
+      stencilAtt = _mesa_get_attachment(ctx, buffer, GL_STENCIL_ATTACHMENT);
+      if (depthAtt->Renderbuffer != stencilAtt->Renderbuffer) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glGetFramebufferAttachmentParameterivEXT(DEPTH/STENCIL"
+                     " attachments differ)");
+         return;
+      }
+   }
+
+   /* No need to flush here */
+
+   switch (pname) {
+   case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT:
+      *params = buffer->Name == 0 ? GL_FRAMEBUFFER_DEFAULT : att->Type;
+      return;
+   case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT:
+      if (att->Type == GL_RENDERBUFFER_EXT) {
+	 *params = att->Renderbuffer->Name;
+      }
+      else if (att->Type == GL_TEXTURE) {
+	 *params = att->Texture->Name;
+      }
+      else {
+         assert(att->Type == GL_NONE);
+         *params = 0;
+      }
+      return;
+   case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT:
+      if (att->Type == GL_TEXTURE) {
+	 *params = att->TextureLevel;
+      }
+      else {
+	 _mesa_error(ctx, GL_INVALID_ENUM,
+		     "glGetFramebufferAttachmentParameterivEXT(pname)");
+      }
+      return;
+   case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT:
+      if (att->Type == GL_TEXTURE) {
+         if (att->Texture && att->Texture->Target == GL_TEXTURE_CUBE_MAP) {
+            *params = GL_TEXTURE_CUBE_MAP_POSITIVE_X + att->CubeMapFace;
+         }
+         else {
+            *params = 0;
+         }
+      }
+      else {
+	 _mesa_error(ctx, GL_INVALID_ENUM,
+		     "glGetFramebufferAttachmentParameterivEXT(pname)");
+      }
+      return;
+   case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT:
+      if (att->Type == GL_TEXTURE) {
+         if (att->Texture && att->Texture->Target == GL_TEXTURE_3D) {
+            *params = att->Zoffset;
+         }
+         else {
+            *params = 0;
+         }
+      }
+      else {
+	 _mesa_error(ctx, GL_INVALID_ENUM,
+		     "glGetFramebufferAttachmentParameterivEXT(pname)");
+      }
+      return;
+   case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
+      if (!ctx->Extensions.ARB_framebuffer_object) {
+         _mesa_error(ctx, GL_INVALID_ENUM,
+                     "glGetFramebufferAttachmentParameterivEXT(pname)");
+      }
+      else {
+         if (ctx->Extensions.EXT_framebuffer_sRGB) {
+            *params = _mesa_get_format_color_encoding(att->Renderbuffer->Format);
+         }
+         else {
+            /* According to ARB_framebuffer_sRGB, we should return LINEAR
+             * if the sRGB conversion is unsupported. */
+            *params = GL_LINEAR;
+         }
+      }
+      return;
+   case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
+      if (!ctx->Extensions.ARB_framebuffer_object) {
+         _mesa_error(ctx, GL_INVALID_ENUM,
+                     "glGetFramebufferAttachmentParameterivEXT(pname)");
+         return;
+      }
+      else {
+         gl_format format = att->Renderbuffer->Format;
+         if (format == MESA_FORMAT_CI8 || format == MESA_FORMAT_S8) {
+            /* special cases */
+            *params = GL_INDEX;
+         }
+         else {
+            *params = _mesa_get_format_datatype(format);
+         }
+      }
+      return;
+   case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
+   case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
+   case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
+   case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
+   case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
+   case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
+      if (!ctx->Extensions.ARB_framebuffer_object) {
+         _mesa_error(ctx, GL_INVALID_ENUM,
+                     "glGetFramebufferAttachmentParameterivEXT(pname)");
+      }
+      else if (att->Texture) {
+         const struct gl_texture_image *texImage =
+            _mesa_select_tex_image(ctx, att->Texture, att->Texture->Target,
+                                   att->TextureLevel);
+         if (texImage) {
+            *params = get_component_bits(pname, texImage->_BaseFormat,
+                                         texImage->TexFormat);
+         }
+         else {
+            *params = 0;
+         }
+      }
+      else if (att->Renderbuffer) {
+         *params = get_component_bits(pname, att->Renderbuffer->_BaseFormat,
+                                      att->Renderbuffer->Format);
+      }
+      else {
+         *params = 0;
+      }
+      return;
+   default:
+      _mesa_error(ctx, GL_INVALID_ENUM,
+                  "glGetFramebufferAttachmentParameterivEXT(pname)");
+      return;
+   }
+}
+
+
+void GLAPIENTRY
+_mesa_GenerateMipmapEXT(GLenum target)
+{
+   struct gl_texture_object *texObj;
+   GET_CURRENT_CONTEXT(ctx);
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+   switch (target) {
+   case GL_TEXTURE_1D:
+   case GL_TEXTURE_2D:
+   case GL_TEXTURE_3D:
+   case GL_TEXTURE_CUBE_MAP:
+      /* OK, legal value */
+      break;
+   default:
+      /* XXX need to implement GL_TEXTURE_1D_ARRAY and GL_TEXTURE_2D_ARRAY */
+      _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmapEXT(target)");
+      return;
+   }
+
+   texObj = _mesa_get_current_tex_object(ctx, target);
+
+   if (texObj->BaseLevel >= texObj->MaxLevel) {
+      /* nothing to do */
+      return;
+   }
+
+   if (texObj->Target == GL_TEXTURE_CUBE_MAP &&
+       !_mesa_cube_complete(texObj)) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glGenerateMipmap(incomplete cube map)");
+      return;
+   }
+
+   _mesa_lock_texture(ctx, texObj);
+   if (target == GL_TEXTURE_CUBE_MAP) {
+      GLuint face;
+      for (face = 0; face < 6; face++)
+	 ctx->Driver.GenerateMipmap(ctx,
+				    GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + face,
+				    texObj);
+   }
+   else {
+      ctx->Driver.GenerateMipmap(ctx, target, texObj);
+   }
+   _mesa_unlock_texture(ctx, texObj);
+}
+
+
+#if FEATURE_EXT_framebuffer_blit
+
+static const struct gl_renderbuffer_attachment *
+find_attachment(const struct gl_framebuffer *fb,
+                const struct gl_renderbuffer *rb)
+{
+   GLuint i;
+   for (i = 0; i < Elements(fb->Attachment); i++) {
+      if (fb->Attachment[i].Renderbuffer == rb)
+         return &fb->Attachment[i];
+   }
+   return NULL;
+}
+
+
+
+/**
+ * Blit rectangular region, optionally from one framebuffer to another.
+ *
+ * Note, if the src buffer is multisampled and the dest is not, this is
+ * when the samples must be resolved to a single color.
+ */
+void GLAPIENTRY
+_mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
+                         GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
+                         GLbitfield mask, GLenum filter)
+{
+   const GLbitfield legalMaskBits = (GL_COLOR_BUFFER_BIT |
+                                     GL_DEPTH_BUFFER_BIT |
+                                     GL_STENCIL_BUFFER_BIT);
+   const struct gl_framebuffer *readFb, *drawFb;
+   const struct gl_renderbuffer *colorReadRb, *colorDrawRb;
+   GET_CURRENT_CONTEXT(ctx);
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+   if (ctx->NewState) {
+      _mesa_update_state(ctx);
+   }
+
+   readFb = ctx->ReadBuffer;
+   drawFb = ctx->DrawBuffer;
+
+   if (!readFb || !drawFb) {
+      /* This will normally never happen but someday we may want to
+       * support MakeCurrent() with no drawables.
+       */
+      return;
+   }
+
+   /* check for complete framebuffers */
+   if (drawFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT ||
+       readFb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+                  "glBlitFramebufferEXT(incomplete draw/read buffers)");
+      return;
+   }
+
+   if (filter != GL_NEAREST && filter != GL_LINEAR) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glBlitFramebufferEXT(filter)");
+      return;
+   }
+
+   if (mask & ~legalMaskBits) {
+      _mesa_error( ctx, GL_INVALID_VALUE, "glBlitFramebufferEXT(mask)");
+      return;
+   }
+
+   /* depth/stencil must be blitted with nearest filtering */
+   if ((mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
+        && filter != GL_NEAREST) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+             "glBlitFramebufferEXT(depth/stencil requires GL_NEAREST filter");
+      return;
+   }
+
+   /* get color read/draw renderbuffers */
+   if (mask & GL_COLOR_BUFFER_BIT) {
+      colorReadRb = readFb->_ColorReadBuffer;
+      colorDrawRb = drawFb->_ColorDrawBuffers[0];
+   }
+   else {
+      colorReadRb = colorDrawRb = NULL;
+   }
+
+   if (mask & GL_STENCIL_BUFFER_BIT) {
+      struct gl_renderbuffer *readRb = readFb->_StencilBuffer;
+      struct gl_renderbuffer *drawRb = drawFb->_StencilBuffer;
+      if (!readRb ||
+          !drawRb ||
+          _mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS) != 
+          _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS)) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glBlitFramebufferEXT(stencil buffer size mismatch");
+         return;
+      }
+   }
+
+   if (mask & GL_DEPTH_BUFFER_BIT) {
+      struct gl_renderbuffer *readRb = readFb->_DepthBuffer;
+      struct gl_renderbuffer *drawRb = drawFb->_DepthBuffer;
+      if (!readRb ||
+          !drawRb ||
+          _mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS) != 
+          _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS)) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glBlitFramebufferEXT(depth buffer size mismatch");
+         return;
+      }
+   }
+
+   if (readFb->Visual.samples > 0 &&
+       drawFb->Visual.samples > 0 &&
+       readFb->Visual.samples != drawFb->Visual.samples) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glBlitFramebufferEXT(mismatched samples");
+      return;
+   }
+
+   /* extra checks for multisample copies... */
+   if (readFb->Visual.samples > 0 || drawFb->Visual.samples > 0) {
+      /* src and dest region sizes must be the same */
+      if (srcX1 - srcX0 != dstX1 - dstX0 ||
+          srcY1 - srcY0 != dstY1 - dstY0) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                "glBlitFramebufferEXT(bad src/dst multisample region sizes");
+         return;
+      }
+
+      /* color formats must match */
+      if (colorReadRb &&
+          colorDrawRb &&
+          colorReadRb->Format != colorDrawRb->Format) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                "glBlitFramebufferEXT(bad src/dst multisample pixel formats");
+         return;
+      }
+   }
+
+   if (!ctx->Extensions.EXT_framebuffer_blit) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT");
+      return;
+   }
+
+   /* Debug code */
+   if (DEBUG_BLIT) {
+      printf("glBlitFramebuffer(%d, %d, %d, %d,  %d, %d, %d, %d,"
+	     " 0x%x, 0x%x)\n",
+	     srcX0, srcY0, srcX1, srcY1,
+	     dstX0, dstY0, dstX1, dstY1,
+	     mask, filter);
+      if (colorReadRb) {
+         const struct gl_renderbuffer_attachment *att;
+
+         att = find_attachment(readFb, colorReadRb);
+         printf("  Src FBO %u  RB %u (%dx%d)  ",
+		readFb->Name, colorReadRb->Name,
+		colorReadRb->Width, colorReadRb->Height);
+         if (att && att->Texture) {
+            printf("Tex %u  tgt 0x%x  level %u  face %u",
+		   att->Texture->Name,
+		   att->Texture->Target,
+		   att->TextureLevel,
+		   att->CubeMapFace);
+         }
+         printf("\n");
+
+         att = find_attachment(drawFb, colorDrawRb);
+         printf("  Dst FBO %u  RB %u (%dx%d)  ",
+		drawFb->Name, colorDrawRb->Name,
+		colorDrawRb->Width, colorDrawRb->Height);
+         if (att && att->Texture) {
+            printf("Tex %u  tgt 0x%x  level %u  face %u",
+		   att->Texture->Name,
+		   att->Texture->Target,
+		   att->TextureLevel,
+		   att->CubeMapFace);
+         }
+         printf("\n");
+      }
+   }
+
+   ASSERT(ctx->Driver.BlitFramebuffer);
+   ctx->Driver.BlitFramebuffer(ctx,
+                               srcX0, srcY0, srcX1, srcY1,
+                               dstX0, dstY0, dstX1, dstY1,
+                               mask, filter);
+}
+#endif /* FEATURE_EXT_framebuffer_blit */
+
+#if FEATURE_ARB_geometry_shader4
+void GLAPIENTRY
+_mesa_FramebufferTextureARB(GLenum target, GLenum attachment,
+                            GLuint texture, GLint level)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_error(ctx, GL_INVALID_OPERATION,
+               "glFramebufferTextureARB "
+               "not implemented!");
+}
+
+void GLAPIENTRY
+_mesa_FramebufferTextureFaceARB(GLenum target, GLenum attachment,
+                                GLuint texture, GLint level, GLenum face)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   _mesa_error(ctx, GL_INVALID_OPERATION,
+               "glFramebufferTextureFaceARB "
+               "not implemented!");
+}
+#endif /* FEATURE_ARB_geometry_shader4 */
diff --git a/mesalib/src/mesa/state_tracker/st_atom_pixeltransfer.c b/mesalib/src/mesa/state_tracker/st_atom_pixeltransfer.c
index a9e05c9c4..98be6ab75 100644
--- a/mesalib/src/mesa/state_tracker/st_atom_pixeltransfer.c
+++ b/mesalib/src/mesa/state_tracker/st_atom_pixeltransfer.c
@@ -99,7 +99,7 @@ create_color_map_texture(struct gl_context *ctx)
 
    /* create texture for color map/table */
    pt = st_texture_create(st, PIPE_TEXTURE_2D, format, 0,
-                          texSize, texSize, 1, PIPE_BIND_SAMPLER_VIEW);
+                          texSize, texSize, 1, 1, PIPE_BIND_SAMPLER_VIEW);
    return pt;
 }
 
diff --git a/mesalib/src/mesa/state_tracker/st_cb_bitmap.c b/mesalib/src/mesa/state_tracker/st_cb_bitmap.c
index a3e39dd49..ddd130a81 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_bitmap.c
@@ -276,7 +276,7 @@ make_bitmap_texture(struct gl_context *ctx, GLsizei width, GLsizei height,
     * Create texture to hold bitmap pattern.
     */
    pt = st_texture_create(st, st->internal_target, st->bitmap.tex_format,
-                          0, width, height, 1,
+                          0, width, height, 1, 1,
                           PIPE_BIND_SAMPLER_VIEW);
    if (!pt) {
       _mesa_unmap_pbo_source(ctx, unpack);
@@ -559,7 +559,7 @@ reset_cache(struct st_context *st)
    cache->texture = st_texture_create(st, PIPE_TEXTURE_2D,
                                       st->bitmap.tex_format, 0,
                                       BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
-                                      1,
+                                      1, 1,
 				      PIPE_BIND_SAMPLER_VIEW);
 }
 
diff --git a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
index 8d3eece4d..56c7e8581 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -343,7 +343,7 @@ alloc_texture(struct st_context *st, GLsizei width, GLsizei height,
    struct pipe_resource *pt;
 
    pt = st_texture_create(st, st->internal_target, texFormat, 0,
-                          width, height, 1, PIPE_BIND_SAMPLER_VIEW);
+                          width, height, 1, 1, PIPE_BIND_SAMPLER_VIEW);
 
    return pt;
 }
diff --git a/mesalib/src/mesa/state_tracker/st_cb_texture.c b/mesalib/src/mesa/state_tracker/st_cb_texture.c
index 9653dcd65..ff04f3364 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_texture.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_texture.c
@@ -1,2021 +1,2033 @@
-/**************************************************************************
- * 
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- * 
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- * 
- **************************************************************************/
-
-#include "main/mfeatures.h"
-#include "main/bufferobj.h"
-#include "main/enums.h"
-#include "main/fbobject.h"
-#include "main/formats.h"
-#include "main/image.h"
-#include "main/imports.h"
-#include "main/macros.h"
-#include "main/mipmap.h"
-#include "main/pack.h"
-#include "main/pixeltransfer.h"
-#include "main/texcompress.h"
-#include "main/texfetch.h"
-#include "main/texgetimage.h"
-#include "main/teximage.h"
-#include "main/texobj.h"
-#include "main/texstore.h"
-
-#include "state_tracker/st_debug.h"
-#include "state_tracker/st_context.h"
-#include "state_tracker/st_cb_fbo.h"
-#include "state_tracker/st_cb_flush.h"
-#include "state_tracker/st_cb_texture.h"
-#include "state_tracker/st_format.h"
-#include "state_tracker/st_texture.h"
-#include "state_tracker/st_gen_mipmap.h"
-#include "state_tracker/st_atom.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_defines.h"
-#include "util/u_inlines.h"
-#include "pipe/p_shader_tokens.h"
-#include "util/u_tile.h"
-#include "util/u_blit.h"
-#include "util/u_format.h"
-#include "util/u_surface.h"
-#include "util/u_sampler.h"
-#include "util/u_math.h"
-#include "util/u_box.h"
-
-#define DBG if (0) printf
-
-
-static enum pipe_texture_target
-gl_target_to_pipe(GLenum target)
-{
-   switch (target) {
-   case GL_TEXTURE_1D:
-      return PIPE_TEXTURE_1D;
-   case GL_TEXTURE_2D:
-      return PIPE_TEXTURE_2D;
-   case GL_TEXTURE_RECTANGLE_NV:
-      return PIPE_TEXTURE_RECT;
-   case GL_TEXTURE_3D:
-      return PIPE_TEXTURE_3D;
-   case GL_TEXTURE_CUBE_MAP_ARB:
-      return PIPE_TEXTURE_CUBE;
-   case GL_TEXTURE_1D_ARRAY_EXT:
-      return PIPE_TEXTURE_1D_ARRAY;
-   case GL_TEXTURE_2D_ARRAY_EXT:
-      return PIPE_TEXTURE_2D_ARRAY;
-   default:
-      assert(0);
-      return 0;
-   }
-}
-
-
-/** called via ctx->Driver.NewTextureImage() */
-static struct gl_texture_image *
-st_NewTextureImage(struct gl_context * ctx)
-{
-   DBG("%s\n", __FUNCTION__);
-   (void) ctx;
-   return (struct gl_texture_image *) ST_CALLOC_STRUCT(st_texture_image);
-}
-
-
-/** called via ctx->Driver.NewTextureObject() */
-static struct gl_texture_object *
-st_NewTextureObject(struct gl_context * ctx, GLuint name, GLenum target)
-{
-   struct st_texture_object *obj = ST_CALLOC_STRUCT(st_texture_object);
-
-   DBG("%s\n", __FUNCTION__);
-   _mesa_initialize_texture_object(&obj->base, name, target);
-
-   return &obj->base;
-}
-
-/** called via ctx->Driver.DeleteTextureObject() */
-static void 
-st_DeleteTextureObject(struct gl_context *ctx,
-                       struct gl_texture_object *texObj)
-{
-   struct st_context *st = st_context(ctx);
-   struct st_texture_object *stObj = st_texture_object(texObj);
-   if (stObj->pt)
-      pipe_resource_reference(&stObj->pt, NULL);
-   if (stObj->sampler_view) {
-      if (stObj->sampler_view->context != st->pipe) {
-         /* Take "ownership" of this texture sampler view by setting
-          * its context pointer to this context.  This avoids potential
-          * crashes when the texture object is shared among contexts
-          * and the original/owner context has already been destroyed.
-          */
-         stObj->sampler_view->context = st->pipe;
-      }
-      pipe_sampler_view_reference(&stObj->sampler_view, NULL);
-   }
-   _mesa_delete_texture_object(ctx, texObj);
-}
-
-
-/** called via ctx->Driver.FreeTexImageData() */
-static void
-st_FreeTextureImageData(struct gl_context * ctx, struct gl_texture_image *texImage)
-{
-   struct st_texture_image *stImage = st_texture_image(texImage);
-
-   DBG("%s\n", __FUNCTION__);
-
-   if (stImage->pt) {
-      pipe_resource_reference(&stImage->pt, NULL);
-   }
-
-   if (texImage->Data) {
-      _mesa_align_free(texImage->Data);
-      texImage->Data = NULL;
-   }
-}
-
-
-/**
- * From linux kernel i386 header files, copes with odd sizes better
- * than COPY_DWORDS would:
- * XXX Put this in src/mesa/main/imports.h ???
- */
-#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
-static INLINE void *
-__memcpy(void *to, const void *from, size_t n)
-{
-   int d0, d1, d2;
-   __asm__ __volatile__("rep ; movsl\n\t"
-                        "testb $2,%b4\n\t"
-                        "je 1f\n\t"
-                        "movsw\n"
-                        "1:\ttestb $1,%b4\n\t"
-                        "je 2f\n\t"
-                        "movsb\n" "2:":"=&c"(d0), "=&D"(d1), "=&S"(d2)
-                        :"0"(n / 4), "q"(n), "1"((long) to), "2"((long) from)
-                        :"memory");
-   return (to);
-}
-#else
-#define __memcpy(a,b,c) memcpy(a,b,c)
-#endif
-
-
-/**
- * The system memcpy (at least on ubuntu 5.10) has problems copying
- * to agp (writecombined) memory from a source which isn't 64-byte
- * aligned - there is a 4x performance falloff.
- *
- * The x86 __memcpy is immune to this but is slightly slower
- * (10%-ish) than the system memcpy.
- *
- * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but
- * isn't much faster than x86_memcpy for agp copies.
- * 
- * TODO: switch dynamically.
- */
-static void *
-do_memcpy(void *dest, const void *src, size_t n)
-{
-   if ((((unsigned long) src) & 63) || (((unsigned long) dest) & 63)) {
-      return __memcpy(dest, src, n);
-   }
-   else
-      return memcpy(dest, src, n);
-}
-
-
-/**
- * Return default texture resource binding bitmask for the given format.
- */
-static GLuint
-default_bindings(struct st_context *st, enum pipe_format format)
-{
-   struct pipe_screen *screen = st->pipe->screen;
-   const unsigned target = PIPE_TEXTURE_2D;
-   const unsigned geom = 0x0;
-   unsigned bindings;
-
-   if (util_format_is_depth_or_stencil(format))
-      bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_DEPTH_STENCIL;
-   else
-      bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
-
-   if (screen->is_format_supported(screen, format, target, 0, bindings, geom))
-      return bindings;
-   else
-      return PIPE_BIND_SAMPLER_VIEW;
-}
-
-
-/** Return number of image dimensions (1, 2 or 3) for a texture target. */
-static GLuint
-get_texture_dims(GLenum target)
-{
-   switch (target) {
-   case GL_TEXTURE_1D:
-   case GL_TEXTURE_1D_ARRAY_EXT:
-      return 1;
-   case GL_TEXTURE_2D:
-   case GL_TEXTURE_CUBE_MAP_ARB:
-   case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
-   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
-   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
-   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
-   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
-   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
-   case GL_TEXTURE_RECTANGLE_NV:
-   case GL_TEXTURE_2D_ARRAY_EXT:
-      return 2;
-   case GL_TEXTURE_3D:
-      return 3;
-   default:
-      assert(0 && "invalid texture target in get_texture_dims()");
-      return 1;
-   }
-}
-
-
-/**
- * Try to allocate a pipe_resource object for the given st_texture_object.
- *
- * We use the given st_texture_image as a clue to determine the size of the
- * mipmap image at level=0.
- *
- * \return GL_TRUE for success, GL_FALSE if out of memory.
- */
-static GLboolean
-guess_and_alloc_texture(struct st_context *st,
-			struct st_texture_object *stObj,
-			const struct st_texture_image *stImage)
-{
-   const GLuint dims = get_texture_dims(stObj->base.Target);
-   GLuint level, lastLevel, width, height, depth;
-   GLuint bindings;
-   enum pipe_format fmt;
-
-   DBG("%s\n", __FUNCTION__);
-
-   assert(!stObj->pt);
-
-   level = stImage->level;
-   width = stImage->base.Width2;  /* size w/out border */
-   height = stImage->base.Height2;
-   depth = stImage->base.Depth2;
-
-   assert(width > 0);
-   assert(height > 0);
-   assert(depth > 0);
-
-   /* Depending on the image's size, we can't always make a guess here.
-    */
-   if (level > 0) {
-      if ( (dims >= 1 && width == 1) ||
-           (dims >= 2 && height == 1) ||
-           (dims >= 3 && depth == 1) ) {
-         /* we can't determine the image size at level=0 */
-         stObj->width0 = stObj->height0 = stObj->depth0 = 0;
-         /* this is not an out of memory error */
-         return GL_TRUE;
-      }
-   }
-
-   /* grow the image size until we hit level = 0 */
-   while (level > 0) {
-      if (width != 1)
-         width <<= 1;
-      if (height != 1)
-         height <<= 1;
-      if (depth != 1)
-         depth <<= 1;
-      level--;
-   }      
-
-   assert(level == 0);
-
-   /* At this point, (width x height x depth) is the expected size of
-    * the level=0 mipmap image.
-    */
-
-   /* Guess a reasonable value for lastLevel.  With OpenGL we have no
-    * idea how many mipmap levels will be in a texture until we start
-    * to render with it.  Make an educated guess here but be prepared
-    * to re-allocating a texture buffer with space for more (or fewer)
-    * mipmap levels later.
-    */
-   if ((stObj->base.MinFilter == GL_NEAREST ||
-        stObj->base.MinFilter == GL_LINEAR ||
-        stImage->base._BaseFormat == GL_DEPTH_COMPONENT ||
-        stImage->base._BaseFormat == GL_DEPTH_STENCIL_EXT) &&
-       !stObj->base.GenerateMipmap &&
-       stImage->level == 0) {
-      /* only alloc space for a single mipmap level */
-      lastLevel = 0;
-   }
-   else {
-      /* alloc space for a full mipmap */
-      GLuint l2width = util_logbase2(width);
-      GLuint l2height = util_logbase2(height);
-      GLuint l2depth = util_logbase2(depth);
-      lastLevel = MAX2(MAX2(l2width, l2height), l2depth);
-   }
-
-   /* Save the level=0 dimensions */
-   stObj->width0 = width;
-   stObj->height0 = height;
-   stObj->depth0 = depth;
-
-   fmt = st_mesa_format_to_pipe_format(stImage->base.TexFormat);
-
-   bindings = default_bindings(st, fmt);
-
-   stObj->pt = st_texture_create(st,
-                                 gl_target_to_pipe(stObj->base.Target),
-                                 fmt,
-                                 lastLevel,
-                                 width,
-                                 height,
-                                 depth,
-                                 bindings);
-
-   DBG("%s returning %d\n", __FUNCTION__, (stObj->pt != NULL));
-
-   return stObj->pt != NULL;
-}
-
-
-/**
- * Adjust pixel unpack params and image dimensions to strip off the
- * texture border.
- * Gallium doesn't support texture borders.  They've seldem been used
- * and seldom been implemented correctly anyway.
- * \param unpackNew  returns the new pixel unpack parameters
- */
-static void
-strip_texture_border(GLint border,
-                     GLint *width, GLint *height, GLint *depth,
-                     const struct gl_pixelstore_attrib *unpack,
-                     struct gl_pixelstore_attrib *unpackNew)
-{
-   assert(border > 0);  /* sanity check */
-
-   *unpackNew = *unpack;
-
-   if (unpackNew->RowLength == 0)
-      unpackNew->RowLength = *width;
-
-   if (depth && unpackNew->ImageHeight == 0)
-      unpackNew->ImageHeight = *height;
-
-   unpackNew->SkipPixels += border;
-   if (height)
-      unpackNew->SkipRows += border;
-   if (depth)
-      unpackNew->SkipImages += border;
-
-   assert(*width >= 3);
-   *width = *width - 2 * border;
-   if (height && *height >= 3)
-      *height = *height - 2 * border;
-   if (depth && *depth >= 3)
-      *depth = *depth - 2 * border;
-}
-
-
-/**
- * Try to do texture compression via rendering.  If the Gallium driver
- * can render into a compressed surface this will allow us to do texture
- * compression.
- * \return GL_TRUE for success, GL_FALSE for failure
- */
-static GLboolean
-compress_with_blit(struct gl_context * ctx,
-                   GLenum target, GLint level,
-                   GLint xoffset, GLint yoffset, GLint zoffset,
-                   GLint width, GLint height, GLint depth,
-                   GLenum format, GLenum type, const void *pixels,
-                   const struct gl_pixelstore_attrib *unpack,
-                   struct gl_texture_image *texImage)
-{
-   const GLuint dstImageOffsets[1] = {0};
-   struct st_texture_image *stImage = st_texture_image(texImage);
-   struct st_context *st = st_context(ctx);
-   struct pipe_context *pipe = st->pipe;
-   struct pipe_screen *screen = pipe->screen;
-   gl_format mesa_format;
-   struct pipe_resource templ;
-   struct pipe_resource *src_tex;
-   struct pipe_sampler_view view_templ;
-   struct pipe_sampler_view *src_view;
-   struct pipe_surface *dst_surface, surf_tmpl;
-   struct pipe_transfer *tex_xfer;
-   void *map;
-
-   if (!stImage->pt) {
-      /* XXX: Can this happen? Should we assert? */
-      return GL_FALSE;
-   }
-
-   /* get destination surface (in the compressed texture) */
-   memset(&surf_tmpl, 0, sizeof(surf_tmpl));
-   surf_tmpl.format = stImage->pt->format;
-   surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
-   surf_tmpl.u.tex.level = stImage->level;
-   surf_tmpl.u.tex.first_layer = stImage->face;
-   surf_tmpl.u.tex.last_layer = stImage->face;
-   dst_surface = pipe->create_surface(pipe, stImage->pt, &surf_tmpl);
-   if (!dst_surface) {
-      /* can't render into this format (or other problem) */
-      return GL_FALSE;
-   }
-
-   /* Choose format for the temporary RGBA texture image.
-    */
-   mesa_format = st_ChooseTextureFormat(ctx, GL_RGBA, format, type);
-   assert(mesa_format);
-   if (!mesa_format)
-      return GL_FALSE;
-
-   /* Create the temporary source texture
-    */
-   memset(&templ, 0, sizeof(templ));
-   templ.target = st->internal_target;
-   templ.format = st_mesa_format_to_pipe_format(mesa_format);
-   templ.width0 = width;
-   templ.height0 = height;
-   templ.depth0 = 1;
-   templ.array_size = 1;
-   templ.last_level = 0;
-   templ.usage = PIPE_USAGE_DEFAULT;
-   templ.bind = PIPE_BIND_SAMPLER_VIEW;
-   src_tex = screen->resource_create(screen, &templ);
-
-   if (!src_tex)
-      return GL_FALSE;
-
-   /* Put user's tex data into the temporary texture
-    */
-   tex_xfer = pipe_get_transfer(st_context(ctx)->pipe, src_tex,
-                                0, 0, /* layer, level are zero */
-                                PIPE_TRANSFER_WRITE,
-                                0, 0, width, height); /* x, y, w, h */
-   map = pipe_transfer_map(pipe, tex_xfer);
-
-   _mesa_texstore(ctx, 2, GL_RGBA, mesa_format,
-                  map,              /* dest ptr */
-                  0, 0, 0,          /* dest x/y/z offset */
-                  tex_xfer->stride, /* dest row stride (bytes) */
-                  dstImageOffsets,  /* image offsets (for 3D only) */
-                  width, height, 1, /* size */
-                  format, type,     /* source format/type */
-                  pixels,           /* source data */
-                  unpack);          /* source data packing */
-
-   pipe_transfer_unmap(pipe, tex_xfer);
-   pipe->transfer_destroy(pipe, tex_xfer);
-
-   /* Create temporary sampler view */
-   u_sampler_view_default_template(&view_templ,
-                                   src_tex,
-                                   src_tex->format);
-   src_view = pipe->create_sampler_view(pipe, src_tex, &view_templ);
-
-
-   /* copy / compress image */
-   util_blit_pixels_tex(st->blit,
-                        src_view,         /* sampler view (src) */
-                        0, 0,             /* src x0, y0 */
-                        width, height,    /* src x1, y1 */
-                        dst_surface,      /* pipe_surface (dst) */
-                        xoffset, yoffset, /* dst x0, y0 */
-                        xoffset + width,  /* dst x1 */
-                        yoffset + height, /* dst y1 */
-                        0.0,              /* z */
-                        PIPE_TEX_MIPFILTER_NEAREST);
-
-   pipe_surface_reference(&dst_surface, NULL);
-   pipe_resource_reference(&src_tex, NULL);
-   pipe_sampler_view_reference(&src_view, NULL);
-
-   return GL_TRUE;
-}
-
-
-/**
- * Do glTexImage1/2/3D().
- */
-static void
-st_TexImage(struct gl_context * ctx,
-            GLint dims,
-            GLenum target, GLint level,
-            GLint internalFormat,
-            GLint width, GLint height, GLint depth,
-            GLint border,
-            GLenum format, GLenum type, const void *pixels,
-            const struct gl_pixelstore_attrib *unpack,
-            struct gl_texture_object *texObj,
-            struct gl_texture_image *texImage,
-            GLsizei imageSize, GLboolean compressed_src)
-{
-   struct st_context *st = st_context(ctx);
-   struct pipe_screen *screen = st->pipe->screen;
-   struct st_texture_object *stObj = st_texture_object(texObj);
-   struct st_texture_image *stImage = st_texture_image(texImage);
-   GLuint dstRowStride = 0;
-   struct gl_pixelstore_attrib unpackNB;
-   enum pipe_transfer_usage transfer_usage = 0;
-
-   DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__,
-       _mesa_lookup_enum_by_nr(target), level, width, height, depth, border);
-
-   /* switch to "normal" */
-   if (stObj->surface_based) {
-      gl_format texFormat;
-
-      _mesa_clear_texture_object(ctx, texObj);
-      pipe_resource_reference(&stObj->pt, NULL);
-
-      /* oops, need to init this image again */
-      texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
-                                              internalFormat, format, type);
-
-      _mesa_init_teximage_fields(ctx, target, texImage,
-                                 width, height, depth, border,
-                                 internalFormat, texFormat);
-
-      stObj->surface_based = GL_FALSE;
-   }
-
-   /* gallium does not support texture borders, strip it off */
-   if (border) {
-      strip_texture_border(border, &width, &height, &depth, unpack, &unpackNB);
-      unpack = &unpackNB;
-      texImage->Width = width;
-      texImage->Height = height;
-      texImage->Depth = depth;
-      texImage->Border = 0;
-      border = 0;
-   }
-   else {
-      assert(texImage->Width == width);
-      assert(texImage->Height == height);
-      assert(texImage->Depth == depth);
-   }
-
-   stImage->face = _mesa_tex_target_to_face(target);
-   stImage->level = level;
-
-   _mesa_set_fetch_functions(texImage, dims);
-
-   /* Release the reference to a potentially orphaned buffer.   
-    * Release any old malloced memory.
-    */
-   if (stImage->pt) {
-      pipe_resource_reference(&stImage->pt, NULL);
-      assert(!texImage->Data);
-   }
-   else if (texImage->Data) {
-      _mesa_align_free(texImage->Data);
-   }
-
-   /*
-    * See if the new image is somehow incompatible with the existing
-    * mipmap.  If so, free the old mipmap.
-    */
-   if (stObj->pt) {
-      if (level > (GLint) stObj->pt->last_level ||
-          !st_texture_match_image(stObj->pt, &stImage->base,
-                                  stImage->face, stImage->level)) {
-         DBG("release it\n");
-         pipe_resource_reference(&stObj->pt, NULL);
-         assert(!stObj->pt);
-         pipe_sampler_view_reference(&stObj->sampler_view, NULL);
-      }
-   }
-
-   if (width == 0 || height == 0 || depth == 0) {
-      /* stop after freeing old image */
-      return;
-   }
-
-   if (!stObj->pt) {
-      if (!guess_and_alloc_texture(st, stObj, stImage)) {
-         /* Probably out of memory.
-          * Try flushing any pending rendering, then retry.
-          */
-         st_finish(st);
-         if (!guess_and_alloc_texture(st, stObj, stImage)) {
-            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
-            return;
-         }
-      }
-   }
-
-   assert(!stImage->pt);
-
-   /* Check if this texture image can live inside the texture object's buffer.
-    * If so, store the image there.  Otherwise the image will temporarily live
-    * in its own buffer.
-    */
-   if (stObj->pt &&
-       st_texture_match_image(stObj->pt, &stImage->base,
-                              stImage->face, stImage->level)) {
-
-      pipe_resource_reference(&stImage->pt, stObj->pt);
-      assert(stImage->pt);
-   }
-
-   if (!stImage->pt)
-      DBG("XXX: Image did not fit into texture - storing in local memory!\n");
-
-   /* Pixel data may come from regular user memory or a PBO.  For the later,
-    * do bounds checking and map the PBO to read pixels data from it.
-    *
-    * XXX we should try to use a GPU-accelerated path to copy the image data
-    * from the PBO to the texture.
-    */
-   if (compressed_src) {
-      pixels = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, pixels,
-						      unpack,
-						      "glCompressedTexImage");
-   }
-   else {
-      pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, 1,
-					   format, type,
-					   pixels, unpack, "glTexImage");
-   }
-
-   /* See if we can do texture compression with a blit/render.
-    */
-   if (!compressed_src &&
-       !ctx->Mesa_DXTn &&
-       _mesa_is_format_compressed(texImage->TexFormat) &&
-       screen->is_format_supported(screen,
-                                   stImage->pt->format,
-                                   stImage->pt->target, 0,
-                                   PIPE_BIND_RENDER_TARGET, 0)) {
-      if (!pixels)
-         goto done;
-
-      if (compress_with_blit(ctx, target, level, 0, 0, 0, width, height, depth,
-                             format, type, pixels, unpack, texImage)) {
-         goto done;
-      }
-   }
-
-   /*
-    * Prepare to store the texture data.  Either map the gallium texture buffer
-    * memory or malloc space for it.
-    */
-   if (stImage->pt) {
-      /* Store the image in the gallium texture memory buffer */
-      if (format == GL_DEPTH_COMPONENT &&
-          util_format_is_depth_and_stencil(stImage->pt->format))
-         transfer_usage = PIPE_TRANSFER_READ_WRITE;
-      else
-         transfer_usage = PIPE_TRANSFER_WRITE;
-
-      texImage->Data = st_texture_image_map(st, stImage, 0,
-                                            transfer_usage, 0, 0, width, height);
-      if(stImage->transfer)
-         dstRowStride = stImage->transfer->stride;
-   }
-   else {
-      /* Allocate regular memory and store the image there temporarily.   */
-      GLuint imageSize = _mesa_format_image_size(texImage->TexFormat,
-                                                 width, height, depth);
-      dstRowStride = _mesa_format_row_stride(texImage->TexFormat, width);
-
-      texImage->Data = _mesa_align_malloc(imageSize, 16);
-   }
-
-   if (!texImage->Data) {
-      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
-      return;
-   }
-
-   if (!pixels) {
-      /* We've allocated texture memory, but have no pixel data - all done. */
-      goto done;
-   }
-
-   DBG("Upload image %dx%dx%d row_len %x pitch %x\n",
-       width, height, depth, width, dstRowStride);
-
-   /* Copy user texture image into the texture buffer.
-    */
-   if (compressed_src) {
-      const GLuint srcRowStride =
-         _mesa_format_row_stride(texImage->TexFormat, width);
-      if (dstRowStride == srcRowStride) {
-         memcpy(texImage->Data, pixels, imageSize);
-      }
-      else {
-         char *dst = texImage->Data;
-         const char *src = pixels;
-         GLuint i, bw, bh, lines;
-         _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh);
-         lines = (height + bh - 1) / bh;
-
-         for (i = 0; i < lines; ++i) {
-            memcpy(dst, src, srcRowStride);
-            dst += dstRowStride;
-            src += srcRowStride;
-         }
-      }
-   }
-   else {
-      const GLuint srcImageStride =
-         _mesa_image_image_stride(unpack, width, height, format, type);
-      GLint i;
-      const GLubyte *src = (const GLubyte *) pixels;
-
-      for (i = 0; i < depth; i++) {
-	 if (!_mesa_texstore(ctx, dims, 
-                             texImage->_BaseFormat, 
-                             texImage->TexFormat, 
-                             texImage->Data,
-                             0, 0, 0, /* dstX/Y/Zoffset */
-                             dstRowStride,
-                             texImage->ImageOffsets,
-                             width, height, 1,
-                             format, type, src, unpack)) {
-	    _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
-	 }
-
-	 if (stImage->pt && i + 1 < depth) {
-            /* unmap this slice */
-	    st_texture_image_unmap(st, stImage);
-            /* map next slice of 3D texture */
-	    texImage->Data = st_texture_image_map(st, stImage, i + 1,
-                                                  transfer_usage, 0, 0,
-                                                  width, height);
-	    src += srcImageStride;
-	 }
-      }
-   }
-
-done:
-   _mesa_unmap_teximage_pbo(ctx, unpack);
-
-   if (stImage->pt && texImage->Data) {
-      st_texture_image_unmap(st, stImage);
-      texImage->Data = NULL;
-   }
-}
-
-
-static void
-st_TexImage3D(struct gl_context * ctx,
-              GLenum target, GLint level,
-              GLint internalFormat,
-              GLint width, GLint height, GLint depth,
-              GLint border,
-              GLenum format, GLenum type, const void *pixels,
-              const struct gl_pixelstore_attrib *unpack,
-              struct gl_texture_object *texObj,
-              struct gl_texture_image *texImage)
-{
-   st_TexImage(ctx, 3, target, level, internalFormat, width, height, depth,
-               border, format, type, pixels, unpack, texObj, texImage,
-               0, GL_FALSE);
-}
-
-
-static void
-st_TexImage2D(struct gl_context * ctx,
-              GLenum target, GLint level,
-              GLint internalFormat,
-              GLint width, GLint height, GLint border,
-              GLenum format, GLenum type, const void *pixels,
-              const struct gl_pixelstore_attrib *unpack,
-              struct gl_texture_object *texObj,
-              struct gl_texture_image *texImage)
-{
-   st_TexImage(ctx, 2, target, level, internalFormat, width, height, 1, border,
-               format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
-}
-
-
-static void
-st_TexImage1D(struct gl_context * ctx,
-              GLenum target, GLint level,
-              GLint internalFormat,
-              GLint width, GLint border,
-              GLenum format, GLenum type, const void *pixels,
-              const struct gl_pixelstore_attrib *unpack,
-              struct gl_texture_object *texObj,
-              struct gl_texture_image *texImage)
-{
-   st_TexImage(ctx, 1, target, level, internalFormat, width, 1, 1, border,
-               format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
-}
-
-
-static void
-st_CompressedTexImage2D(struct gl_context *ctx, GLenum target, GLint level,
-                        GLint internalFormat,
-                        GLint width, GLint height, GLint border,
-                        GLsizei imageSize, const GLvoid *data,
-                        struct gl_texture_object *texObj,
-                        struct gl_texture_image *texImage)
-{
-   st_TexImage(ctx, 2, target, level, internalFormat, width, height, 1, border,
-               0, 0, data, &ctx->Unpack, texObj, texImage, imageSize, GL_TRUE);
-}
-
-
-
-/**
- * glGetTexImage() helper: decompress a compressed texture by rendering
- * a textured quad.  Store the results in the user's buffer.
- */
-static void
-decompress_with_blit(struct gl_context * ctx, GLenum target, GLint level,
-                     GLenum format, GLenum type, GLvoid *pixels,
-                     struct gl_texture_object *texObj,
-                     struct gl_texture_image *texImage)
-{
-   struct st_context *st = st_context(ctx);
-   struct pipe_context *pipe = st->pipe;
-   struct st_texture_image *stImage = st_texture_image(texImage);
-   struct st_texture_object *stObj = st_texture_object(texObj);
-   struct pipe_sampler_view *src_view =
-      st_get_texture_sampler_view(stObj, pipe);
-   const GLuint width = texImage->Width;
-   const GLuint height = texImage->Height;
-   struct pipe_surface *dst_surface;
-   struct pipe_resource *dst_texture;
-   struct pipe_transfer *tex_xfer;
-   unsigned bind = (PIPE_BIND_RENDER_TARGET | /* util_blit may choose to render */
-		    PIPE_BIND_TRANSFER_READ);
-
-   /* create temp / dest surface */
-   if (!util_create_rgba_surface(pipe, width, height, bind,
-                                 &dst_texture, &dst_surface)) {
-      _mesa_problem(ctx, "util_create_rgba_surface() failed "
-                    "in decompress_with_blit()");
-      return;
-   }
-
-   /* blit/render/decompress */
-   util_blit_pixels_tex(st->blit,
-                        src_view,      /* pipe_resource (src) */
-                        0, 0,             /* src x0, y0 */
-                        width, height,    /* src x1, y1 */
-                        dst_surface,      /* pipe_surface (dst) */
-                        0, 0,             /* dst x0, y0 */
-                        width, height,    /* dst x1, y1 */
-                        0.0,              /* z */
-                        PIPE_TEX_MIPFILTER_NEAREST);
-
-   /* map the dst_surface so we can read from it */
-   tex_xfer = pipe_get_transfer(st_context(ctx)->pipe,
-                                dst_texture, 0, 0,
-                                PIPE_TRANSFER_READ,
-                                0, 0, width, height);
-
-   pixels = _mesa_map_pbo_dest(ctx, &ctx->Pack, pixels);
-
-   /* copy/pack data into user buffer */
-   if (st_equal_formats(stImage->pt->format, format, type)) {
-      /* memcpy */
-      const uint bytesPerRow = width * util_format_get_blocksize(stImage->pt->format);
-      ubyte *map = pipe_transfer_map(pipe, tex_xfer);
-      GLuint row;
-      for (row = 0; row < height; row++) {
-         GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
-                                              height, format, type, row, 0);
-         memcpy(dest, map, bytesPerRow);
-         map += tex_xfer->stride;
-      }
-      pipe_transfer_unmap(pipe, tex_xfer);
-   }
-   else {
-      /* format translation via floats */
-      GLuint row;
-      enum pipe_format format = util_format_linear(dst_texture->format);
-      for (row = 0; row < height; row++) {
-         const GLbitfield transferOps = 0x0; /* bypassed for glGetTexImage() */
-         GLfloat rgba[4 * MAX_WIDTH];
-         GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
-                                              height, format, type, row, 0);
-
-         if (ST_DEBUG & DEBUG_FALLBACK)
-            debug_printf("%s: fallback format translation\n", __FUNCTION__);
-
-         /* get float[4] rgba row from surface */
-         pipe_get_tile_rgba_format(pipe, tex_xfer, 0, row, width, 1,
-                                   format, rgba);
-
-         _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format,
-                                    type, dest, &ctx->Pack, transferOps);
-      }
-   }
-
-   _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
-
-   pipe->transfer_destroy(pipe, tex_xfer);
-
-   /* destroy the temp / dest surface */
-   util_destroy_rgba_surface(dst_texture, dst_surface);
-}
-
-
-
-/**
- * Need to map texture image into memory before copying image data,
- * then unmap it.
- */
-static void
-st_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
-                 GLenum format, GLenum type, GLvoid * pixels,
-                 struct gl_texture_object *texObj,
-                 struct gl_texture_image *texImage, GLboolean compressed_dst)
-{
-   struct st_context *st = st_context(ctx);
-   struct st_texture_image *stImage = st_texture_image(texImage);
-   const GLuint dstImageStride =
-      _mesa_image_image_stride(&ctx->Pack, texImage->Width, texImage->Height,
-                               format, type);
-   GLuint depth, i;
-   GLubyte *dest;
-
-   if (stImage->pt &&
-       util_format_is_s3tc(stImage->pt->format) &&
-       !compressed_dst) {
-      /* Need to decompress the texture.
-       * We'll do this by rendering a textured quad.
-       * Note that we only expect RGBA formats (no Z/depth formats).
-       */
-      decompress_with_blit(ctx, target, level, format, type, pixels,
-                           texObj, texImage);
-      return;
-   }
-
-   /* Map */
-   if (stImage->pt) {
-      /* Image is stored in hardware format in a buffer managed by the
-       * kernel.  Need to explicitly map and unmap it.
-       */
-      texImage->Data = st_texture_image_map(st, stImage, 0,
-                                            PIPE_TRANSFER_READ, 0, 0,
-                                            stImage->base.Width,
-                                            stImage->base.Height);
-      /* compute stride in texels from stride in bytes */
-      texImage->RowStride = stImage->transfer->stride
-         * util_format_get_blockwidth(stImage->pt->format)
-         / util_format_get_blocksize(stImage->pt->format);
-   }
-   else {
-      /* Otherwise, the image should actually be stored in
-       * texImage->Data.  This is pretty confusing for
-       * everybody, I'd much prefer to separate the two functions of
-       * texImage->Data - storage for texture images in main memory
-       * and access (ie mappings) of images.  In other words, we'd
-       * create a new texImage->Map field and leave Data simply for
-       * storage.
-       */
-      assert(texImage->Data);
-   }
-
-   depth = texImage->Depth;
-   texImage->Depth = 1;
-
-   dest = (GLubyte *) pixels;
-
-   _mesa_set_fetch_functions(texImage, get_texture_dims(target));
-
-   for (i = 0; i < depth; i++) {
-      if (compressed_dst) {
-	 _mesa_get_compressed_teximage(ctx, target, level, dest,
-				       texObj, texImage);
-      }
-      else {
-	 _mesa_get_teximage(ctx, target, level, format, type, dest,
-			    texObj, texImage);
-      }
-
-      if (stImage->pt && i + 1 < depth) {
-         /* unmap this slice */
-	 st_texture_image_unmap(st, stImage);
-         /* map next slice of 3D texture */
-	 texImage->Data = st_texture_image_map(st, stImage, i + 1,
-                                               PIPE_TRANSFER_READ, 0, 0,
-                                               stImage->base.Width,
-                                               stImage->base.Height);
-	 dest += dstImageStride;
-      }
-   }
-
-   texImage->Depth = depth;
-
-   /* Unmap */
-   if (stImage->pt) {
-      st_texture_image_unmap(st, stImage);
-      texImage->Data = NULL;
-   }
-}
-
-
-static void
-st_GetTexImage(struct gl_context * ctx, GLenum target, GLint level,
-               GLenum format, GLenum type, GLvoid * pixels,
-               struct gl_texture_object *texObj,
-               struct gl_texture_image *texImage)
-{
-   st_get_tex_image(ctx, target, level, format, type, pixels, texObj, texImage,
-                    GL_FALSE);
-}
-
-
-static void
-st_GetCompressedTexImage(struct gl_context *ctx, GLenum target, GLint level,
-                         GLvoid *pixels,
-                         struct gl_texture_object *texObj,
-                         struct gl_texture_image *texImage)
-{
-   st_get_tex_image(ctx, target, level, 0, 0, pixels, texObj, texImage,
-                    GL_TRUE);
-}
-
-
-
-static void
-st_TexSubimage(struct gl_context *ctx, GLint dims, GLenum target, GLint level,
-               GLint xoffset, GLint yoffset, GLint zoffset,
-               GLint width, GLint height, GLint depth,
-               GLenum format, GLenum type, const void *pixels,
-               const struct gl_pixelstore_attrib *packing,
-               struct gl_texture_object *texObj,
-               struct gl_texture_image *texImage)
-{
-   struct st_context *st = st_context(ctx);
-   struct pipe_screen *screen = st->pipe->screen;
-   struct st_texture_image *stImage = st_texture_image(texImage);
-   GLuint dstRowStride;
-   const GLuint srcImageStride =
-      _mesa_image_image_stride(packing, width, height, format, type);
-   GLint i;
-   const GLubyte *src;
-   /* init to silence warning only: */
-   enum pipe_transfer_usage transfer_usage = PIPE_TRANSFER_WRITE;
-
-   DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__,
-       _mesa_lookup_enum_by_nr(target),
-       level, xoffset, yoffset, width, height);
-
-   pixels =
-      _mesa_validate_pbo_teximage(ctx, dims, width, height, depth, format,
-                                  type, pixels, packing, "glTexSubImage2D");
-   if (!pixels)
-      return;
-
-   /* See if we can do texture compression with a blit/render.
-    */
-   if (!ctx->Mesa_DXTn &&
-       _mesa_is_format_compressed(texImage->TexFormat) &&
-       screen->is_format_supported(screen,
-                                   stImage->pt->format,
-                                   stImage->pt->target, 0,
-                                   PIPE_BIND_RENDER_TARGET, 0)) {
-      if (compress_with_blit(ctx, target, level,
-                             xoffset, yoffset, zoffset,
-                             width, height, depth,
-                             format, type, pixels, packing, texImage)) {
-         goto done;
-      }
-   }
-
-   /* Map buffer if necessary.  Need to lock to prevent other contexts
-    * from uploading the buffer under us.
-    */
-   if (stImage->pt) {
-      if (format == GL_DEPTH_COMPONENT &&
-          util_format_is_depth_and_stencil(stImage->pt->format))
-         transfer_usage = PIPE_TRANSFER_READ_WRITE;
-      else
-         transfer_usage = PIPE_TRANSFER_WRITE;
-
-      texImage->Data = st_texture_image_map(st, stImage, zoffset, 
-                                            transfer_usage,
-                                            xoffset, yoffset,
-                                            width, height);
-   }
-
-   if (!texImage->Data) {
-      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
-      goto done;
-   }
-
-   src = (const GLubyte *) pixels;
-   dstRowStride = stImage->transfer->stride;
-
-   for (i = 0; i < depth; i++) {
-      if (!_mesa_texstore(ctx, dims, texImage->_BaseFormat,
-                          texImage->TexFormat,
-                          texImage->Data,
-                          0, 0, 0,
-                          dstRowStride,
-                          texImage->ImageOffsets,
-                          width, height, 1,
-                          format, type, src, packing)) {
-	 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
-      }
-
-      if (stImage->pt && i + 1 < depth) {
-         /* unmap this slice */
-	 st_texture_image_unmap(st, stImage);
-         /* map next slice of 3D texture */
-	 texImage->Data = st_texture_image_map(st, stImage,
-                                               zoffset + i + 1,
-                                               transfer_usage,
-                                               xoffset, yoffset,
-                                               width, height);
-	 src += srcImageStride;
-      }
-   }
-
-done:
-   _mesa_unmap_teximage_pbo(ctx, packing);
-
-   if (stImage->pt && texImage->Data) {
-      st_texture_image_unmap(st, stImage);
-      texImage->Data = NULL;
-   }
-}
-
-
-
-static void
-st_TexSubImage3D(struct gl_context *ctx, GLenum target, GLint level,
-                 GLint xoffset, GLint yoffset, GLint zoffset,
-                 GLsizei width, GLsizei height, GLsizei depth,
-                 GLenum format, GLenum type, const GLvoid *pixels,
-                 const struct gl_pixelstore_attrib *packing,
-                 struct gl_texture_object *texObj,
-                 struct gl_texture_image *texImage)
-{
-   st_TexSubimage(ctx, 3, target, level, xoffset, yoffset, zoffset,
-                  width, height, depth, format, type,
-                  pixels, packing, texObj, texImage);
-}
-
-
-static void
-st_TexSubImage2D(struct gl_context *ctx, GLenum target, GLint level,
-                 GLint xoffset, GLint yoffset,
-                 GLsizei width, GLsizei height,
-                 GLenum format, GLenum type, const GLvoid * pixels,
-                 const struct gl_pixelstore_attrib *packing,
-                 struct gl_texture_object *texObj,
-                 struct gl_texture_image *texImage)
-{
-   st_TexSubimage(ctx, 2, target, level, xoffset, yoffset, 0,
-                  width, height, 1, format, type,
-                  pixels, packing, texObj, texImage);
-}
-
-
-static void
-st_TexSubImage1D(struct gl_context *ctx, GLenum target, GLint level,
-                 GLint xoffset, GLsizei width, GLenum format, GLenum type,
-                 const GLvoid * pixels,
-                 const struct gl_pixelstore_attrib *packing,
-                 struct gl_texture_object *texObj,
-                 struct gl_texture_image *texImage)
-{
-   st_TexSubimage(ctx, 1, target, level, xoffset, 0, 0, width, 1, 1,
-                  format, type, pixels, packing, texObj, texImage);
-}
-
-
-static void
-st_CompressedTexSubImage1D(struct gl_context *ctx, GLenum target, GLint level,
-                           GLint xoffset, GLsizei width,
-                           GLenum format,
-                           GLsizei imageSize, const GLvoid *data,
-                           struct gl_texture_object *texObj,
-                           struct gl_texture_image *texImage)
-{
-   assert(0);
-}
-
-
-static void
-st_CompressedTexSubImage2D(struct gl_context *ctx, GLenum target, GLint level,
-                           GLint xoffset, GLint yoffset,
-                           GLsizei width, GLint height,
-                           GLenum format,
-                           GLsizei imageSize, const GLvoid *data,
-                           struct gl_texture_object *texObj,
-                           struct gl_texture_image *texImage)
-{
-   struct st_context *st = st_context(ctx);
-   struct st_texture_image *stImage = st_texture_image(texImage);
-   int srcBlockStride;
-   int dstBlockStride;
-   int y;
-   enum pipe_format pformat;
-
-   if (stImage->pt) {
-      pformat = stImage->pt->format;
-
-      texImage->Data = st_texture_image_map(st, stImage, 0, 
-                                            PIPE_TRANSFER_WRITE,
-                                            xoffset, yoffset,
-                                            width, height);
-      
-      srcBlockStride = util_format_get_stride(pformat, width);
-      dstBlockStride = stImage->transfer->stride;
-   } else {
-      assert(stImage->pt);
-      /* TODO find good values for block and strides */
-      /* TODO also adjust texImage->data for yoffset/xoffset */
-      return;
-   }
-
-   if (!texImage->Data) {
-      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage");
-      return;
-   }
-
-   assert(xoffset % util_format_get_blockwidth(pformat) == 0);
-   assert(yoffset % util_format_get_blockheight(pformat) == 0);
-
-   for (y = 0; y < height; y += util_format_get_blockheight(pformat)) {
-      /* don't need to adjust for xoffset and yoffset as st_texture_image_map does that */
-      const char *src = (const char*)data + srcBlockStride * util_format_get_nblocksy(pformat, y);
-      char *dst = (char*)texImage->Data + dstBlockStride * util_format_get_nblocksy(pformat, y);
-      memcpy(dst, src, util_format_get_stride(pformat, width));
-   }
-
-   if (stImage->pt) {
-      st_texture_image_unmap(st, stImage);
-      texImage->Data = NULL;
-   }
-}
-
-
-static void
-st_CompressedTexSubImage3D(struct gl_context *ctx, GLenum target, GLint level,
-                           GLint xoffset, GLint yoffset, GLint zoffset,
-                           GLsizei width, GLint height, GLint depth,
-                           GLenum format,
-                           GLsizei imageSize, const GLvoid *data,
-                           struct gl_texture_object *texObj,
-                           struct gl_texture_image *texImage)
-{
-   assert(0);
-}
-
-
-
-/**
- * Do a CopyTexSubImage operation using a read transfer from the source,
- * a write transfer to the destination and get_tile()/put_tile() to access
- * the pixels/texels.
- *
- * Note: srcY=0=TOP of renderbuffer
- */
-static void
-fallback_copy_texsubimage(struct gl_context *ctx, GLenum target, GLint level,
-                          struct st_renderbuffer *strb,
-                          struct st_texture_image *stImage,
-                          GLenum baseFormat,
-                          GLint destX, GLint destY, GLint destZ,
-                          GLint srcX, GLint srcY,
-                          GLsizei width, GLsizei height)
-{
-   struct st_context *st = st_context(ctx);
-   struct pipe_context *pipe = st->pipe;
-   struct pipe_transfer *src_trans;
-   GLvoid *texDest;
-   enum pipe_transfer_usage transfer_usage;
-
-   if (ST_DEBUG & DEBUG_FALLBACK)
-      debug_printf("%s: fallback processing\n", __FUNCTION__);
-
-   assert(width <= MAX_WIDTH);
-
-   if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
-      srcY = strb->Base.Height - srcY - height;
-   }
-
-   src_trans = pipe_get_transfer(st_context(ctx)->pipe,
-                                 strb->texture,
-                                 0, 0,
-                                 PIPE_TRANSFER_READ,
-                                 srcX, srcY,
-                                 width, height);
-
-   if ((baseFormat == GL_DEPTH_COMPONENT ||
-        baseFormat == GL_DEPTH_STENCIL) &&
-       util_format_is_depth_and_stencil(stImage->pt->format))
-      transfer_usage = PIPE_TRANSFER_READ_WRITE;
-   else
-      transfer_usage = PIPE_TRANSFER_WRITE;
-
-   /* XXX this used to ignore destZ param */
-   texDest = st_texture_image_map(st, stImage, destZ, transfer_usage,
-                                  destX, destY, width, height);
-
-   if (baseFormat == GL_DEPTH_COMPONENT ||
-       baseFormat == GL_DEPTH_STENCIL) {
-      const GLboolean scaleOrBias = (ctx->Pixel.DepthScale != 1.0F ||
-                                     ctx->Pixel.DepthBias != 0.0F);
-      GLint row, yStep;
-
-      /* determine bottom-to-top vs. top-to-bottom order for src buffer */
-      if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
-         srcY = height - 1;
-         yStep = -1;
-      }
-      else {
-         srcY = 0;
-         yStep = 1;
-      }
-
-      /* To avoid a large temp memory allocation, do copy row by row */
-      for (row = 0; row < height; row++, srcY += yStep) {
-         uint data[MAX_WIDTH];
-         pipe_get_tile_z(pipe, src_trans, 0, srcY, width, 1, data);
-         if (scaleOrBias) {
-            _mesa_scale_and_bias_depth_uint(ctx, width, data);
-         }
-         pipe_put_tile_z(pipe, stImage->transfer, 0, row, width, 1, data);
-      }
-   }
-   else {
-      /* RGBA format */
-      GLfloat *tempSrc =
-         (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
-
-      if (tempSrc && texDest) {
-         const GLint dims = 2;
-         const GLint dstRowStride = stImage->transfer->stride;
-         struct gl_texture_image *texImage = &stImage->base;
-         struct gl_pixelstore_attrib unpack = ctx->DefaultPacking;
-
-         if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
-            unpack.Invert = GL_TRUE;
-         }
-
-         /* get float/RGBA image from framebuffer */
-         /* XXX this usually involves a lot of int/float conversion.
-          * try to avoid that someday.
-          */
-         pipe_get_tile_rgba_format(pipe, src_trans, 0, 0, width, height,
-                                   util_format_linear(strb->texture->format),
-                                   tempSrc);
-
-         /* Store into texture memory.
-          * Note that this does some special things such as pixel transfer
-          * ops and format conversion.  In particular, if the dest tex format
-          * is actually RGBA but the user created the texture as GL_RGB we
-          * need to fill-in/override the alpha channel with 1.0.
-          */
-         _mesa_texstore(ctx, dims,
-                        texImage->_BaseFormat, 
-                        texImage->TexFormat, 
-                        texDest,
-                        0, 0, 0,
-                        dstRowStride,
-                        texImage->ImageOffsets,
-                        width, height, 1,
-                        GL_RGBA, GL_FLOAT, tempSrc, /* src */
-                        &unpack);
-      }
-      else {
-         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
-      }
-
-      if (tempSrc)
-         free(tempSrc);
-   }
-
-   st_texture_image_unmap(st, stImage);
-   pipe->transfer_destroy(pipe, src_trans);
-}
-
-
-
-/**
- * If the format of the src renderbuffer and the format of the dest
- * texture are compatible (in terms of blitting), return a TGSI writemask
- * to be used during the blit.
- * If the src/dest are incompatible, return 0.
- */
-static unsigned
-compatible_src_dst_formats(struct gl_context *ctx,
-                           const struct gl_renderbuffer *src,
-                           const struct gl_texture_image *dst)
-{
-   /* Get logical base formats for the src and dest.
-    * That is, use the user-requested formats and not the actual, device-
-    * chosen formats.
-    * For example, the user may have requested an A8 texture but the
-    * driver may actually be using an RGBA texture format.  When we
-    * copy/blit to that texture, we only want to copy the Alpha channel
-    * and not the RGB channels.
-    *
-    * Similarly, when the src FBO was created an RGB format may have been
-    * requested but the driver actually chose an RGBA format.  In that case,
-    * we don't want to copy the undefined Alpha channel to the dest texture
-    * (it should be 1.0).
-    */
-   const GLenum srcFormat = _mesa_base_fbo_format(ctx, src->InternalFormat);
-   const GLenum dstFormat = _mesa_base_tex_format(ctx, dst->InternalFormat);
-
-   /**
-    * XXX when we have red-only and red/green renderbuffers we'll need
-    * to add more cases here (or implement a general-purpose routine that
-    * queries the existance of the R,G,B,A channels in the src and dest).
-    */
-   if (srcFormat == dstFormat) {
-      /* This is the same as matching_base_formats, which should
-       * always pass, as it did previously.
-       */
-      return TGSI_WRITEMASK_XYZW;
-   }
-   else if (srcFormat == GL_RGB && dstFormat == GL_RGBA) {
-      /* Make sure that A in the dest is 1.  The actual src format
-       * may be RGBA and have undefined A values.
-       */
-      return TGSI_WRITEMASK_XYZ;
-   }
-   else if (srcFormat == GL_RGBA && dstFormat == GL_RGB) {
-      /* Make sure that A in the dest is 1.  The actual dst format
-       * may be RGBA and will need A=1 to provide proper alpha values
-       * when sampled later.
-       */
-      return TGSI_WRITEMASK_XYZ;
-   }
-   else {
-      if (ST_DEBUG & DEBUG_FALLBACK)
-         debug_printf("%s failed for src %s, dst %s\n",
-                      __FUNCTION__, 
-                      _mesa_lookup_enum_by_nr(srcFormat),
-                      _mesa_lookup_enum_by_nr(dstFormat));
-
-      /* Otherwise fail.
-       */
-      return 0;
-   }
-}
-
-
-
-/**
- * Do a CopyTex[Sub]Image1/2/3D() using a hardware (blit) path if possible.
- * Note that the region to copy has already been clipped so we know we
- * won't read from outside the source renderbuffer's bounds.
- *
- * Note: srcY=0=Bottom of renderbuffer (GL convention)
- */
-static void
-st_copy_texsubimage(struct gl_context *ctx,
-                    GLenum target, GLint level,
-                    GLint destX, GLint destY, GLint destZ,
-                    GLint srcX, GLint srcY,
-                    GLsizei width, GLsizei height)
-{
-   struct gl_texture_unit *texUnit =
-      &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-   struct gl_texture_object *texObj =
-      _mesa_select_tex_object(ctx, texUnit, target);
-   struct gl_texture_image *texImage =
-      _mesa_select_tex_image(ctx, texObj, target, level);
-   struct st_texture_image *stImage = st_texture_image(texImage);
-   const GLenum texBaseFormat = texImage->_BaseFormat;
-   struct gl_framebuffer *fb = ctx->ReadBuffer;
-   struct st_renderbuffer *strb;
-   struct st_context *st = st_context(ctx);
-   struct pipe_context *pipe = st->pipe;
-   struct pipe_screen *screen = pipe->screen;
-   enum pipe_format dest_format, src_format;
-   GLboolean use_fallback = GL_TRUE;
-   GLboolean matching_base_formats;
-   GLuint format_writemask, sample_count;
-   struct pipe_surface *dest_surface = NULL;
-   GLboolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP);
-
-   /* make sure finalize_textures has been called? 
-    */
-   if (0) st_validate_state(st);
-
-   /* determine if copying depth or color data */
-   if (texBaseFormat == GL_DEPTH_COMPONENT ||
-       texBaseFormat == GL_DEPTH_STENCIL) {
-      strb = st_renderbuffer(fb->_DepthBuffer);
-      if (strb->Base.Wrapped) {
-         strb = st_renderbuffer(strb->Base.Wrapped);
-      }
-   }
-   else {
-      /* texBaseFormat == GL_RGB, GL_RGBA, GL_ALPHA, etc */
-      strb = st_renderbuffer(fb->_ColorReadBuffer);
-   }
-
-   if (!strb || !strb->surface || !stImage->pt) {
-      debug_printf("%s: null strb or stImage\n", __FUNCTION__);
-      return;
-   }
-
-   sample_count = strb->surface->texture->nr_samples;
-   /* I believe this would be legal, presumably would need to do a resolve
-      for color, and for depth/stencil spec says to just use one of the
-      depth/stencil samples per pixel? Need some transfer clarifications. */
-   assert(sample_count < 2);
-
-   if (srcX < 0) {
-      width -= -srcX;
-      destX += -srcX;
-      srcX = 0;
-   }
-
-   if (srcY < 0) {
-      height -= -srcY;
-      destY += -srcY;
-      srcY = 0;
-   }
-
-   if (destX < 0) {
-      width -= -destX;
-      srcX += -destX;
-      destX = 0;
-   }
-
-   if (destY < 0) {
-      height -= -destY;
-      srcY += -destY;
-      destY = 0;
-   }
-
-   if (width < 0 || height < 0)
-      return;
-
-
-   assert(strb);
-   assert(strb->surface);
-   assert(stImage->pt);
-
-   src_format = strb->surface->format;
-   dest_format = stImage->pt->format;
-
-   /*
-    * Determine if the src framebuffer and dest texture have the same
-    * base format.  We need this to detect a case such as the framebuffer
-    * being GL_RGBA but the texture being GL_RGB.  If the actual hardware
-    * texture format stores RGBA we need to set A=1 (overriding the
-    * framebuffer's alpha values).  We can't do that with the blit or
-    * textured-quad paths.
-    */
-   matching_base_formats =
-      (_mesa_get_format_base_format(strb->Base.Format) ==
-       _mesa_get_format_base_format(texImage->TexFormat));
-   format_writemask = compatible_src_dst_formats(ctx, &strb->Base, texImage);
-
-   if (ctx->_ImageTransferState == 0x0) {
-
-      if (matching_base_formats &&
-          src_format == dest_format &&
-          !do_flip)
-      {
-         /* use surface_copy() / blit */
-         struct pipe_box src_box;
-         u_box_2d_zslice(srcX, srcY, strb->surface->u.tex.first_layer,
-                         width, height, &src_box);
-
-         /* for resource_copy_region(), y=0=top, always */
-         pipe->resource_copy_region(pipe,
-                                    /* dest */
-                                    stImage->pt,
-                                    stImage->level,
-                                    destX, destY, destZ + stImage->face,
-                                    /* src */
-                                    strb->texture,
-                                    strb->surface->u.tex.level,
-                                    &src_box);
-         use_fallback = GL_FALSE;
-      }
-      else if (format_writemask &&
-               texBaseFormat != GL_DEPTH_COMPONENT &&
-               texBaseFormat != GL_DEPTH_STENCIL &&
-               screen->is_format_supported(screen, src_format,
-                                           PIPE_TEXTURE_2D, sample_count,
-                                           PIPE_BIND_SAMPLER_VIEW,
-                                           0) &&
-               screen->is_format_supported(screen, dest_format,
-                                           PIPE_TEXTURE_2D, 0,
-                                           PIPE_BIND_RENDER_TARGET,
-                                           0)) {
-         /* draw textured quad to do the copy */
-         GLint srcY0, srcY1;
-         struct pipe_surface surf_tmpl;
-         memset(&surf_tmpl, 0, sizeof(surf_tmpl));
-         surf_tmpl.format = stImage->pt->format;
-         surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
-         surf_tmpl.u.tex.level = stImage->level;
-         surf_tmpl.u.tex.first_layer = stImage->face + destZ;
-         surf_tmpl.u.tex.last_layer = stImage->face + destZ;
-
-         dest_surface = pipe->create_surface(pipe, stImage->pt,
-                                             &surf_tmpl);
-
-         if (do_flip) {
-            srcY1 = strb->Base.Height - srcY - height;
-            srcY0 = srcY1 + height;
-         }
-         else {
-            srcY0 = srcY;
-            srcY1 = srcY0 + height;
-         }
-
-         util_blit_pixels_writemask(st->blit,
-                                    strb->texture,
-                                    strb->surface->u.tex.level,
-                                    srcX, srcY0,
-                                    srcX + width, srcY1,
-                                    strb->surface->u.tex.first_layer,
-                                    dest_surface,
-                                    destX, destY,
-                                    destX + width, destY + height,
-                                    0.0, PIPE_TEX_MIPFILTER_NEAREST,
-                                    format_writemask);
-         use_fallback = GL_FALSE;
-      }
-
-      if (dest_surface)
-         pipe_surface_reference(&dest_surface, NULL);
-   }
-
-   if (use_fallback) {
-      /* software fallback */
-      fallback_copy_texsubimage(ctx, target, level,
-                                strb, stImage, texBaseFormat,
-                                destX, destY, destZ,
-                                srcX, srcY, width, height);
-   }
-}
-
-
-
-static void
-st_CopyTexImage1D(struct gl_context * ctx, GLenum target, GLint level,
-                  GLenum internalFormat,
-                  GLint x, GLint y, GLsizei width, GLint border)
-{
-   struct gl_texture_unit *texUnit =
-      &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-   struct gl_texture_object *texObj =
-      _mesa_select_tex_object(ctx, texUnit, target);
-   struct gl_texture_image *texImage =
-      _mesa_select_tex_image(ctx, texObj, target, level);
-
-   /* Setup or redefine the texture object, texture and texture
-    * image.  Don't populate yet.  
-    */
-   ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
-                          width, border,
-                          GL_RGBA, CHAN_TYPE, NULL,
-                          &ctx->DefaultPacking, texObj, texImage);
-
-   st_copy_texsubimage(ctx, target, level,
-                       0, 0, 0,  /* destX,Y,Z */
-                       x, y, width, 1);  /* src X, Y, size */
-}
-
-
-static void
-st_CopyTexImage2D(struct gl_context * ctx, GLenum target, GLint level,
-                  GLenum internalFormat,
-                  GLint x, GLint y, GLsizei width, GLsizei height,
-                  GLint border)
-{
-   struct gl_texture_unit *texUnit =
-      &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-   struct gl_texture_object *texObj =
-      _mesa_select_tex_object(ctx, texUnit, target);
-   struct gl_texture_image *texImage =
-      _mesa_select_tex_image(ctx, texObj, target, level);
-
-   /* Setup or redefine the texture object, texture and texture
-    * image.  Don't populate yet.  
-    */
-   ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
-                          width, height, border,
-                          GL_RGBA, CHAN_TYPE, NULL,
-                          &ctx->DefaultPacking, texObj, texImage);
-
-   st_copy_texsubimage(ctx, target, level,
-                       0, 0, 0,  /* destX,Y,Z */
-                       x, y, width, height);  /* src X, Y, size */
-}
-
-
-static void
-st_CopyTexSubImage1D(struct gl_context * ctx, GLenum target, GLint level,
-                     GLint xoffset, GLint x, GLint y, GLsizei width)
-{
-   const GLint yoffset = 0, zoffset = 0;
-   const GLsizei height = 1;
-   st_copy_texsubimage(ctx, target, level,
-                       xoffset, yoffset, zoffset,  /* destX,Y,Z */
-                       x, y, width, height);  /* src X, Y, size */
-}
-
-
-static void
-st_CopyTexSubImage2D(struct gl_context * ctx, GLenum target, GLint level,
-                     GLint xoffset, GLint yoffset,
-                     GLint x, GLint y, GLsizei width, GLsizei height)
-{
-   const GLint zoffset = 0;
-   st_copy_texsubimage(ctx, target, level,
-                       xoffset, yoffset, zoffset,  /* destX,Y,Z */
-                       x, y, width, height);  /* src X, Y, size */
-}
-
-
-static void
-st_CopyTexSubImage3D(struct gl_context * ctx, GLenum target, GLint level,
-                     GLint xoffset, GLint yoffset, GLint zoffset,
-                     GLint x, GLint y, GLsizei width, GLsizei height)
-{
-   st_copy_texsubimage(ctx, target, level,
-                       xoffset, yoffset, zoffset,  /* destX,Y,Z */
-                       x, y, width, height);  /* src X, Y, size */
-}
-
-
-/**
- * Copy image data from stImage into the texture object 'stObj' at level
- * 'dstLevel'.
- */
-static void
-copy_image_data_to_texture(struct st_context *st,
-			   struct st_texture_object *stObj,
-                           GLuint dstLevel,
-			   struct st_texture_image *stImage)
-{
-   /* debug checks */
-   {
-      const struct gl_texture_image *dstImage =
-         stObj->base.Image[stImage->face][stImage->level];
-      assert(dstImage);
-      assert(dstImage->Width == stImage->base.Width);
-      assert(dstImage->Height == stImage->base.Height);
-      assert(dstImage->Depth == stImage->base.Depth);
-   }
-
-   if (stImage->pt) {
-      /* Copy potentially with the blitter:
-       */
-      st_texture_image_copy(st->pipe,
-                            stObj->pt, dstLevel,  /* dest texture, level */
-                            stImage->pt, stImage->level, /* src texture, level */
-                            stImage->face);
-
-      pipe_resource_reference(&stImage->pt, NULL);
-   }
-   else if (stImage->base.Data) {
-      st_texture_image_data(st,
-                            stObj->pt,
-                            stImage->face,
-                            dstLevel,
-                            stImage->base.Data,
-                            stImage->base.RowStride * 
-                            util_format_get_blocksize(stObj->pt->format),
-                            stImage->base.RowStride *
-                            stImage->base.Height *
-                            util_format_get_blocksize(stObj->pt->format));
-      _mesa_align_free(stImage->base.Data);
-      stImage->base.Data = NULL;
-   }
-
-   pipe_resource_reference(&stImage->pt, stObj->pt);
-}
-
-
-/**
- * Called during state validation.  When this function is finished,
- * the texture object should be ready for rendering.
- * \return GL_TRUE for success, GL_FALSE for failure (out of mem)
- */
-GLboolean
-st_finalize_texture(struct gl_context *ctx,
-		    struct pipe_context *pipe,
-		    struct gl_texture_object *tObj)
-{
-   struct st_context *st = st_context(ctx);
-   struct st_texture_object *stObj = st_texture_object(tObj);
-   const GLuint nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
-   GLuint face;
-   struct st_texture_image *firstImage;
-   enum pipe_format firstImageFormat;
-
-   if (stObj->base._Complete) {
-      /* The texture is complete and we know exactly how many mipmap levels
-       * are present/needed.  This is conditional because we may be called
-       * from the st_generate_mipmap() function when the texture object is
-       * incomplete.  In that case, we'll have set stObj->lastLevel before
-       * we get here.
-       */
-      if (stObj->base.MinFilter == GL_LINEAR ||
-          stObj->base.MinFilter == GL_NEAREST)
-         stObj->lastLevel = stObj->base.BaseLevel;
-      else
-         stObj->lastLevel = stObj->base._MaxLevel;
-   }
-
-   firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
-   assert(firstImage);
-
-   /* If both firstImage and stObj point to a texture which can contain
-    * all active images, favour firstImage.  Note that because of the
-    * completeness requirement, we know that the image dimensions
-    * will match.
-    */
-   if (firstImage->pt &&
-       firstImage->pt != stObj->pt &&
-       (!stObj->pt || firstImage->pt->last_level >= stObj->pt->last_level)) {
-      pipe_resource_reference(&stObj->pt, firstImage->pt);
-      pipe_sampler_view_reference(&stObj->sampler_view, NULL);
-   }
-
-   /* Find gallium format for the Mesa texture */
-   firstImageFormat = st_mesa_format_to_pipe_format(firstImage->base.TexFormat);
-
-   /* If we already have a gallium texture, check that it matches the texture
-    * object's format, target, size, num_levels, etc.
-    */
-   if (stObj->pt) {
-      if (stObj->pt->target != gl_target_to_pipe(stObj->base.Target) ||
-          !st_sampler_compat_formats(stObj->pt->format, firstImageFormat) ||
-          stObj->pt->last_level < stObj->lastLevel ||
-          stObj->pt->width0 != stObj->width0 ||
-          stObj->pt->height0 != stObj->height0 ||
-          stObj->pt->depth0 != stObj->depth0)
-      {
-         /* The gallium texture does not match the Mesa texture so delete the
-          * gallium texture now.  We'll make a new one below.
-          */
-         pipe_resource_reference(&stObj->pt, NULL);
-         pipe_sampler_view_reference(&stObj->sampler_view, NULL);
-         st->dirty.st |= ST_NEW_FRAMEBUFFER;
-      }
-   }
-
-   /* May need to create a new gallium texture:
-    */
-   if (!stObj->pt) {
-      GLuint bindings = default_bindings(st, firstImageFormat);
-
-      stObj->pt = st_texture_create(st,
-                                    gl_target_to_pipe(stObj->base.Target),
-                                    firstImageFormat,
-                                    stObj->lastLevel,
-                                    stObj->width0,
-                                    stObj->height0,
-                                    stObj->depth0,
-                                    bindings);
-
-      if (!stObj->pt) {
-         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
-         return GL_FALSE;
-      }
-   }
-
-   /* Pull in any images not in the object's texture:
-    */
-   for (face = 0; face < nr_faces; face++) {
-      GLuint level;
-      for (level = stObj->base.BaseLevel; level <= stObj->lastLevel; level++) {
-         struct st_texture_image *stImage =
-            st_texture_image(stObj->base.Image[face][level]);
-
-         /* Need to import images in main memory or held in other textures.
-          */
-         if (stImage && stObj->pt != stImage->pt) {
-            copy_image_data_to_texture(st, stObj, level, stImage);
-         }
-      }
-   }
-
-   return GL_TRUE;
-}
-
-
-/**
- * Returns pointer to a default/dummy texture.
- * This is typically used when the current shader has tex/sample instructions
- * but the user has not provided a (any) texture(s).
- */
-struct gl_texture_object *
-st_get_default_texture(struct st_context *st)
-{
-   if (!st->default_texture) {
-      static const GLenum target = GL_TEXTURE_2D;
-      GLubyte pixels[16][16][4];
-      struct gl_texture_object *texObj;
-      struct gl_texture_image *texImg;
-      GLuint i, j;
-
-      /* The ARB_fragment_program spec says (0,0,0,1) should be returned
-       * when attempting to sample incomplete textures.
-       */
-      for (i = 0; i < 16; i++) {
-         for (j = 0; j < 16; j++) {
-            pixels[i][j][0] = 0;
-            pixels[i][j][1] = 0;
-            pixels[i][j][2] = 0;
-            pixels[i][j][3] = 255;
-         }
-      }
-
-      texObj = st->ctx->Driver.NewTextureObject(st->ctx, 0, target);
-
-      texImg = _mesa_get_tex_image(st->ctx, texObj, target, 0);
-
-      _mesa_init_teximage_fields(st->ctx, target, texImg,
-                                 16, 16, 1, 0,  /* w, h, d, border */
-                                 GL_RGBA, MESA_FORMAT_RGBA8888);
-
-      st_TexImage(st->ctx, 2, target,
-                  0, GL_RGBA,    /* level, intformat */
-                  16, 16, 1, 0,  /* w, h, d, border */
-                  GL_RGBA, GL_UNSIGNED_BYTE, pixels,
-                  &st->ctx->DefaultPacking,
-                  texObj, texImg,
-                  0, 0);
-
-      texObj->MinFilter = GL_NEAREST;
-      texObj->MagFilter = GL_NEAREST;
-      texObj->_Complete = GL_TRUE;
-
-      st->default_texture = texObj;
-   }
-   return st->default_texture;
-}
-
-
-void
-st_init_texture_functions(struct dd_function_table *functions)
-{
-   functions->ChooseTextureFormat = st_ChooseTextureFormat;
-   functions->TexImage1D = st_TexImage1D;
-   functions->TexImage2D = st_TexImage2D;
-   functions->TexImage3D = st_TexImage3D;
-   functions->TexSubImage1D = st_TexSubImage1D;
-   functions->TexSubImage2D = st_TexSubImage2D;
-   functions->TexSubImage3D = st_TexSubImage3D;
-   functions->CompressedTexSubImage1D = st_CompressedTexSubImage1D;
-   functions->CompressedTexSubImage2D = st_CompressedTexSubImage2D;
-   functions->CompressedTexSubImage3D = st_CompressedTexSubImage3D;
-   functions->CopyTexImage1D = st_CopyTexImage1D;
-   functions->CopyTexImage2D = st_CopyTexImage2D;
-   functions->CopyTexSubImage1D = st_CopyTexSubImage1D;
-   functions->CopyTexSubImage2D = st_CopyTexSubImage2D;
-   functions->CopyTexSubImage3D = st_CopyTexSubImage3D;
-   functions->GenerateMipmap = st_generate_mipmap;
-
-   functions->GetTexImage = st_GetTexImage;
-
-   /* compressed texture functions */
-   functions->CompressedTexImage2D = st_CompressedTexImage2D;
-   functions->GetCompressedTexImage = st_GetCompressedTexImage;
-
-   functions->NewTextureObject = st_NewTextureObject;
-   functions->NewTextureImage = st_NewTextureImage;
-   functions->DeleteTexture = st_DeleteTextureObject;
-   functions->FreeTexImageData = st_FreeTextureImageData;
-
-   functions->TextureMemCpy = do_memcpy;
-
-   /* XXX Temporary until we can query pipe's texture sizes */
-   functions->TestProxyTexImage = _mesa_test_proxy_teximage;
-}
+/**************************************************************************
+ * 
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * 
+ **************************************************************************/
+
+#include "main/mfeatures.h"
+#include "main/bufferobj.h"
+#include "main/enums.h"
+#include "main/fbobject.h"
+#include "main/formats.h"
+#include "main/image.h"
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/mipmap.h"
+#include "main/pack.h"
+#include "main/pixeltransfer.h"
+#include "main/texcompress.h"
+#include "main/texfetch.h"
+#include "main/texgetimage.h"
+#include "main/teximage.h"
+#include "main/texobj.h"
+#include "main/texstore.h"
+
+#include "state_tracker/st_debug.h"
+#include "state_tracker/st_context.h"
+#include "state_tracker/st_cb_fbo.h"
+#include "state_tracker/st_cb_flush.h"
+#include "state_tracker/st_cb_texture.h"
+#include "state_tracker/st_format.h"
+#include "state_tracker/st_texture.h"
+#include "state_tracker/st_gen_mipmap.h"
+#include "state_tracker/st_atom.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
+#include "pipe/p_shader_tokens.h"
+#include "util/u_tile.h"
+#include "util/u_blit.h"
+#include "util/u_format.h"
+#include "util/u_surface.h"
+#include "util/u_sampler.h"
+#include "util/u_math.h"
+#include "util/u_box.h"
+
+#define DBG if (0) printf
+
+
+static enum pipe_texture_target
+gl_target_to_pipe(GLenum target)
+{
+   switch (target) {
+   case GL_TEXTURE_1D:
+      return PIPE_TEXTURE_1D;
+   case GL_TEXTURE_2D:
+      return PIPE_TEXTURE_2D;
+   case GL_TEXTURE_RECTANGLE_NV:
+      return PIPE_TEXTURE_RECT;
+   case GL_TEXTURE_3D:
+      return PIPE_TEXTURE_3D;
+   case GL_TEXTURE_CUBE_MAP_ARB:
+      return PIPE_TEXTURE_CUBE;
+   case GL_TEXTURE_1D_ARRAY_EXT:
+      return PIPE_TEXTURE_1D_ARRAY;
+   case GL_TEXTURE_2D_ARRAY_EXT:
+      return PIPE_TEXTURE_2D_ARRAY;
+   default:
+      assert(0);
+      return 0;
+   }
+}
+
+
+/** called via ctx->Driver.NewTextureImage() */
+static struct gl_texture_image *
+st_NewTextureImage(struct gl_context * ctx)
+{
+   DBG("%s\n", __FUNCTION__);
+   (void) ctx;
+   return (struct gl_texture_image *) ST_CALLOC_STRUCT(st_texture_image);
+}
+
+
+/** called via ctx->Driver.NewTextureObject() */
+static struct gl_texture_object *
+st_NewTextureObject(struct gl_context * ctx, GLuint name, GLenum target)
+{
+   struct st_texture_object *obj = ST_CALLOC_STRUCT(st_texture_object);
+
+   DBG("%s\n", __FUNCTION__);
+   _mesa_initialize_texture_object(&obj->base, name, target);
+
+   return &obj->base;
+}
+
+/** called via ctx->Driver.DeleteTextureObject() */
+static void 
+st_DeleteTextureObject(struct gl_context *ctx,
+                       struct gl_texture_object *texObj)
+{
+   struct st_context *st = st_context(ctx);
+   struct st_texture_object *stObj = st_texture_object(texObj);
+   if (stObj->pt)
+      pipe_resource_reference(&stObj->pt, NULL);
+   if (stObj->sampler_view) {
+      if (stObj->sampler_view->context != st->pipe) {
+         /* Take "ownership" of this texture sampler view by setting
+          * its context pointer to this context.  This avoids potential
+          * crashes when the texture object is shared among contexts
+          * and the original/owner context has already been destroyed.
+          */
+         stObj->sampler_view->context = st->pipe;
+      }
+      pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+   }
+   _mesa_delete_texture_object(ctx, texObj);
+}
+
+
+/** called via ctx->Driver.FreeTexImageData() */
+static void
+st_FreeTextureImageData(struct gl_context * ctx, struct gl_texture_image *texImage)
+{
+   struct st_texture_image *stImage = st_texture_image(texImage);
+
+   DBG("%s\n", __FUNCTION__);
+
+   if (stImage->pt) {
+      pipe_resource_reference(&stImage->pt, NULL);
+   }
+
+   if (texImage->Data) {
+      _mesa_align_free(texImage->Data);
+      texImage->Data = NULL;
+   }
+}
+
+
+/**
+ * From linux kernel i386 header files, copes with odd sizes better
+ * than COPY_DWORDS would:
+ * XXX Put this in src/mesa/main/imports.h ???
+ */
+#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
+static INLINE void *
+__memcpy(void *to, const void *from, size_t n)
+{
+   int d0, d1, d2;
+   __asm__ __volatile__("rep ; movsl\n\t"
+                        "testb $2,%b4\n\t"
+                        "je 1f\n\t"
+                        "movsw\n"
+                        "1:\ttestb $1,%b4\n\t"
+                        "je 2f\n\t"
+                        "movsb\n" "2:":"=&c"(d0), "=&D"(d1), "=&S"(d2)
+                        :"0"(n / 4), "q"(n), "1"((long) to), "2"((long) from)
+                        :"memory");
+   return (to);
+}
+#else
+#define __memcpy(a,b,c) memcpy(a,b,c)
+#endif
+
+
+/**
+ * The system memcpy (at least on ubuntu 5.10) has problems copying
+ * to agp (writecombined) memory from a source which isn't 64-byte
+ * aligned - there is a 4x performance falloff.
+ *
+ * The x86 __memcpy is immune to this but is slightly slower
+ * (10%-ish) than the system memcpy.
+ *
+ * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but
+ * isn't much faster than x86_memcpy for agp copies.
+ * 
+ * TODO: switch dynamically.
+ */
+static void *
+do_memcpy(void *dest, const void *src, size_t n)
+{
+   if ((((unsigned long) src) & 63) || (((unsigned long) dest) & 63)) {
+      return __memcpy(dest, src, n);
+   }
+   else
+      return memcpy(dest, src, n);
+}
+
+
+/**
+ * Return default texture resource binding bitmask for the given format.
+ */
+static GLuint
+default_bindings(struct st_context *st, enum pipe_format format)
+{
+   struct pipe_screen *screen = st->pipe->screen;
+   const unsigned target = PIPE_TEXTURE_2D;
+   const unsigned geom = 0x0;
+   unsigned bindings;
+
+   if (util_format_is_depth_or_stencil(format))
+      bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_DEPTH_STENCIL;
+   else
+      bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
+
+   if (screen->is_format_supported(screen, format, target, 0, bindings, geom))
+      return bindings;
+   else
+      return PIPE_BIND_SAMPLER_VIEW;
+}
+
+
+/** Return number of image dimensions (1, 2 or 3) for a texture target. */
+static GLuint
+get_texture_dims(GLenum target)
+{
+   switch (target) {
+   case GL_TEXTURE_1D:
+   case GL_TEXTURE_1D_ARRAY_EXT:
+      return 1;
+   case GL_TEXTURE_2D:
+   case GL_TEXTURE_CUBE_MAP_ARB:
+   case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
+   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
+   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
+   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
+   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
+   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
+   case GL_TEXTURE_RECTANGLE_NV:
+   case GL_TEXTURE_2D_ARRAY_EXT:
+      return 2;
+   case GL_TEXTURE_3D:
+      return 3;
+   default:
+      assert(0 && "invalid texture target in get_texture_dims()");
+      return 1;
+   }
+}
+
+
+/**
+ * Try to allocate a pipe_resource object for the given st_texture_object.
+ *
+ * We use the given st_texture_image as a clue to determine the size of the
+ * mipmap image at level=0.
+ *
+ * \return GL_TRUE for success, GL_FALSE if out of memory.
+ */
+static GLboolean
+guess_and_alloc_texture(struct st_context *st,
+			struct st_texture_object *stObj,
+			const struct st_texture_image *stImage)
+{
+   const GLuint dims = get_texture_dims(stObj->base.Target);
+   GLuint level, lastLevel, width, height, depth;
+   GLuint bindings;
+   GLuint ptWidth, ptHeight, ptDepth, ptLayers;
+   enum pipe_format fmt;
+
+   DBG("%s\n", __FUNCTION__);
+
+   assert(!stObj->pt);
+
+   level = stImage->level;
+   width = stImage->base.Width2;  /* size w/out border */
+   height = stImage->base.Height2;
+   depth = stImage->base.Depth2;
+
+   assert(width > 0);
+   assert(height > 0);
+   assert(depth > 0);
+
+   /* Depending on the image's size, we can't always make a guess here.
+    */
+   if (level > 0) {
+      if ( (dims >= 1 && width == 1) ||
+           (dims >= 2 && height == 1) ||
+           (dims >= 3 && depth == 1) ) {
+         /* we can't determine the image size at level=0 */
+         stObj->width0 = stObj->height0 = stObj->depth0 = 0;
+         /* this is not an out of memory error */
+         return GL_TRUE;
+      }
+   }
+
+   /* grow the image size until we hit level = 0 */
+   while (level > 0) {
+      if (width != 1)
+         width <<= 1;
+      if (height != 1)
+         height <<= 1;
+      if (depth != 1)
+         depth <<= 1;
+      level--;
+   }      
+
+   assert(level == 0);
+
+   /* At this point, (width x height x depth) is the expected size of
+    * the level=0 mipmap image.
+    */
+
+   /* Guess a reasonable value for lastLevel.  With OpenGL we have no
+    * idea how many mipmap levels will be in a texture until we start
+    * to render with it.  Make an educated guess here but be prepared
+    * to re-allocating a texture buffer with space for more (or fewer)
+    * mipmap levels later.
+    */
+   if ((stObj->base.MinFilter == GL_NEAREST ||
+        stObj->base.MinFilter == GL_LINEAR ||
+        stImage->base._BaseFormat == GL_DEPTH_COMPONENT ||
+        stImage->base._BaseFormat == GL_DEPTH_STENCIL_EXT) &&
+       !stObj->base.GenerateMipmap &&
+       stImage->level == 0) {
+      /* only alloc space for a single mipmap level */
+      lastLevel = 0;
+   }
+   else {
+      /* alloc space for a full mipmap */
+      GLuint l2width = util_logbase2(width);
+      GLuint l2height = util_logbase2(height);
+      GLuint l2depth = util_logbase2(depth);
+      lastLevel = MAX2(MAX2(l2width, l2height), l2depth);
+   }
+
+   /* Save the level=0 dimensions */
+   stObj->width0 = width;
+   stObj->height0 = height;
+   stObj->depth0 = depth;
+
+   fmt = st_mesa_format_to_pipe_format(stImage->base.TexFormat);
+
+   bindings = default_bindings(st, fmt);
+
+   st_gl_texture_dims_to_pipe_dims(stObj->base.Target,
+                                   width, height, depth,
+                                   &ptWidth, &ptHeight, &ptDepth, &ptLayers);
+
+   stObj->pt = st_texture_create(st,
+                                 gl_target_to_pipe(stObj->base.Target),
+                                 fmt,
+                                 lastLevel,
+                                 ptWidth,
+                                 ptHeight,
+                                 ptDepth,
+                                 ptLayers,
+                                 bindings);
+
+   DBG("%s returning %d\n", __FUNCTION__, (stObj->pt != NULL));
+
+   return stObj->pt != NULL;
+}
+
+
+/**
+ * Adjust pixel unpack params and image dimensions to strip off the
+ * texture border.
+ * Gallium doesn't support texture borders.  They've seldem been used
+ * and seldom been implemented correctly anyway.
+ * \param unpackNew  returns the new pixel unpack parameters
+ */
+static void
+strip_texture_border(GLint border,
+                     GLint *width, GLint *height, GLint *depth,
+                     const struct gl_pixelstore_attrib *unpack,
+                     struct gl_pixelstore_attrib *unpackNew)
+{
+   assert(border > 0);  /* sanity check */
+
+   *unpackNew = *unpack;
+
+   if (unpackNew->RowLength == 0)
+      unpackNew->RowLength = *width;
+
+   if (depth && unpackNew->ImageHeight == 0)
+      unpackNew->ImageHeight = *height;
+
+   unpackNew->SkipPixels += border;
+   if (height)
+      unpackNew->SkipRows += border;
+   if (depth)
+      unpackNew->SkipImages += border;
+
+   assert(*width >= 3);
+   *width = *width - 2 * border;
+   if (height && *height >= 3)
+      *height = *height - 2 * border;
+   if (depth && *depth >= 3)
+      *depth = *depth - 2 * border;
+}
+
+
+/**
+ * Try to do texture compression via rendering.  If the Gallium driver
+ * can render into a compressed surface this will allow us to do texture
+ * compression.
+ * \return GL_TRUE for success, GL_FALSE for failure
+ */
+static GLboolean
+compress_with_blit(struct gl_context * ctx,
+                   GLenum target, GLint level,
+                   GLint xoffset, GLint yoffset, GLint zoffset,
+                   GLint width, GLint height, GLint depth,
+                   GLenum format, GLenum type, const void *pixels,
+                   const struct gl_pixelstore_attrib *unpack,
+                   struct gl_texture_image *texImage)
+{
+   const GLuint dstImageOffsets[1] = {0};
+   struct st_texture_image *stImage = st_texture_image(texImage);
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
+   struct pipe_screen *screen = pipe->screen;
+   gl_format mesa_format;
+   struct pipe_resource templ;
+   struct pipe_resource *src_tex;
+   struct pipe_sampler_view view_templ;
+   struct pipe_sampler_view *src_view;
+   struct pipe_surface *dst_surface, surf_tmpl;
+   struct pipe_transfer *tex_xfer;
+   void *map;
+
+   if (!stImage->pt) {
+      /* XXX: Can this happen? Should we assert? */
+      return GL_FALSE;
+   }
+
+   /* get destination surface (in the compressed texture) */
+   memset(&surf_tmpl, 0, sizeof(surf_tmpl));
+   surf_tmpl.format = stImage->pt->format;
+   surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
+   surf_tmpl.u.tex.level = stImage->level;
+   surf_tmpl.u.tex.first_layer = stImage->face;
+   surf_tmpl.u.tex.last_layer = stImage->face;
+   dst_surface = pipe->create_surface(pipe, stImage->pt, &surf_tmpl);
+   if (!dst_surface) {
+      /* can't render into this format (or other problem) */
+      return GL_FALSE;
+   }
+
+   /* Choose format for the temporary RGBA texture image.
+    */
+   mesa_format = st_ChooseTextureFormat(ctx, GL_RGBA, format, type);
+   assert(mesa_format);
+   if (!mesa_format)
+      return GL_FALSE;
+
+   /* Create the temporary source texture
+    */
+   memset(&templ, 0, sizeof(templ));
+   templ.target = st->internal_target;
+   templ.format = st_mesa_format_to_pipe_format(mesa_format);
+   templ.width0 = width;
+   templ.height0 = height;
+   templ.depth0 = 1;
+   templ.array_size = 1;
+   templ.last_level = 0;
+   templ.usage = PIPE_USAGE_DEFAULT;
+   templ.bind = PIPE_BIND_SAMPLER_VIEW;
+   src_tex = screen->resource_create(screen, &templ);
+
+   if (!src_tex)
+      return GL_FALSE;
+
+   /* Put user's tex data into the temporary texture
+    */
+   tex_xfer = pipe_get_transfer(st_context(ctx)->pipe, src_tex,
+                                0, 0, /* layer, level are zero */
+                                PIPE_TRANSFER_WRITE,
+                                0, 0, width, height); /* x, y, w, h */
+   map = pipe_transfer_map(pipe, tex_xfer);
+
+   _mesa_texstore(ctx, 2, GL_RGBA, mesa_format,
+                  map,              /* dest ptr */
+                  0, 0, 0,          /* dest x/y/z offset */
+                  tex_xfer->stride, /* dest row stride (bytes) */
+                  dstImageOffsets,  /* image offsets (for 3D only) */
+                  width, height, 1, /* size */
+                  format, type,     /* source format/type */
+                  pixels,           /* source data */
+                  unpack);          /* source data packing */
+
+   pipe_transfer_unmap(pipe, tex_xfer);
+   pipe->transfer_destroy(pipe, tex_xfer);
+
+   /* Create temporary sampler view */
+   u_sampler_view_default_template(&view_templ,
+                                   src_tex,
+                                   src_tex->format);
+   src_view = pipe->create_sampler_view(pipe, src_tex, &view_templ);
+
+
+   /* copy / compress image */
+   util_blit_pixels_tex(st->blit,
+                        src_view,         /* sampler view (src) */
+                        0, 0,             /* src x0, y0 */
+                        width, height,    /* src x1, y1 */
+                        dst_surface,      /* pipe_surface (dst) */
+                        xoffset, yoffset, /* dst x0, y0 */
+                        xoffset + width,  /* dst x1 */
+                        yoffset + height, /* dst y1 */
+                        0.0,              /* z */
+                        PIPE_TEX_MIPFILTER_NEAREST);
+
+   pipe_surface_reference(&dst_surface, NULL);
+   pipe_resource_reference(&src_tex, NULL);
+   pipe_sampler_view_reference(&src_view, NULL);
+
+   return GL_TRUE;
+}
+
+
+/**
+ * Do glTexImage1/2/3D().
+ */
+static void
+st_TexImage(struct gl_context * ctx,
+            GLint dims,
+            GLenum target, GLint level,
+            GLint internalFormat,
+            GLint width, GLint height, GLint depth,
+            GLint border,
+            GLenum format, GLenum type, const void *pixels,
+            const struct gl_pixelstore_attrib *unpack,
+            struct gl_texture_object *texObj,
+            struct gl_texture_image *texImage,
+            GLsizei imageSize, GLboolean compressed_src)
+{
+   struct st_context *st = st_context(ctx);
+   struct pipe_screen *screen = st->pipe->screen;
+   struct st_texture_object *stObj = st_texture_object(texObj);
+   struct st_texture_image *stImage = st_texture_image(texImage);
+   GLuint dstRowStride = 0;
+   struct gl_pixelstore_attrib unpackNB;
+   enum pipe_transfer_usage transfer_usage = 0;
+
+   DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__,
+       _mesa_lookup_enum_by_nr(target), level, width, height, depth, border);
+
+   /* switch to "normal" */
+   if (stObj->surface_based) {
+      gl_format texFormat;
+
+      _mesa_clear_texture_object(ctx, texObj);
+      pipe_resource_reference(&stObj->pt, NULL);
+
+      /* oops, need to init this image again */
+      texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
+                                              internalFormat, format, type);
+
+      _mesa_init_teximage_fields(ctx, target, texImage,
+                                 width, height, depth, border,
+                                 internalFormat, texFormat);
+
+      stObj->surface_based = GL_FALSE;
+   }
+
+   /* gallium does not support texture borders, strip it off */
+   if (border) {
+      strip_texture_border(border, &width, &height, &depth, unpack, &unpackNB);
+      unpack = &unpackNB;
+      texImage->Width = width;
+      texImage->Height = height;
+      texImage->Depth = depth;
+      texImage->Border = 0;
+      border = 0;
+   }
+   else {
+      assert(texImage->Width == width);
+      assert(texImage->Height == height);
+      assert(texImage->Depth == depth);
+   }
+
+   stImage->face = _mesa_tex_target_to_face(target);
+   stImage->level = level;
+
+   _mesa_set_fetch_functions(texImage, dims);
+
+   /* Release the reference to a potentially orphaned buffer.   
+    * Release any old malloced memory.
+    */
+   if (stImage->pt) {
+      pipe_resource_reference(&stImage->pt, NULL);
+      assert(!texImage->Data);
+   }
+   else if (texImage->Data) {
+      _mesa_align_free(texImage->Data);
+   }
+
+   /*
+    * See if the new image is somehow incompatible with the existing
+    * mipmap.  If so, free the old mipmap.
+    */
+   if (stObj->pt) {
+      if (level > (GLint) stObj->pt->last_level ||
+          !st_texture_match_image(stObj->pt, &stImage->base,
+                                  stImage->face, stImage->level)) {
+         DBG("release it\n");
+         pipe_resource_reference(&stObj->pt, NULL);
+         assert(!stObj->pt);
+         pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+      }
+   }
+
+   if (width == 0 || height == 0 || depth == 0) {
+      /* stop after freeing old image */
+      return;
+   }
+
+   if (!stObj->pt) {
+      if (!guess_and_alloc_texture(st, stObj, stImage)) {
+         /* Probably out of memory.
+          * Try flushing any pending rendering, then retry.
+          */
+         st_finish(st);
+         if (!guess_and_alloc_texture(st, stObj, stImage)) {
+            _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
+            return;
+         }
+      }
+   }
+
+   assert(!stImage->pt);
+
+   /* Check if this texture image can live inside the texture object's buffer.
+    * If so, store the image there.  Otherwise the image will temporarily live
+    * in its own buffer.
+    */
+   if (stObj->pt &&
+       st_texture_match_image(stObj->pt, &stImage->base,
+                              stImage->face, stImage->level)) {
+
+      pipe_resource_reference(&stImage->pt, stObj->pt);
+      assert(stImage->pt);
+   }
+
+   if (!stImage->pt)
+      DBG("XXX: Image did not fit into texture - storing in local memory!\n");
+
+   /* Pixel data may come from regular user memory or a PBO.  For the later,
+    * do bounds checking and map the PBO to read pixels data from it.
+    *
+    * XXX we should try to use a GPU-accelerated path to copy the image data
+    * from the PBO to the texture.
+    */
+   if (compressed_src) {
+      pixels = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, pixels,
+						      unpack,
+						      "glCompressedTexImage");
+   }
+   else {
+      pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, 1,
+					   format, type,
+					   pixels, unpack, "glTexImage");
+   }
+
+   /* See if we can do texture compression with a blit/render.
+    */
+   if (!compressed_src &&
+       !ctx->Mesa_DXTn &&
+       _mesa_is_format_compressed(texImage->TexFormat) &&
+       screen->is_format_supported(screen,
+                                   stImage->pt->format,
+                                   stImage->pt->target, 0,
+                                   PIPE_BIND_RENDER_TARGET, 0)) {
+      if (!pixels)
+         goto done;
+
+      if (compress_with_blit(ctx, target, level, 0, 0, 0, width, height, depth,
+                             format, type, pixels, unpack, texImage)) {
+         goto done;
+      }
+   }
+
+   /*
+    * Prepare to store the texture data.  Either map the gallium texture buffer
+    * memory or malloc space for it.
+    */
+   if (stImage->pt) {
+      /* Store the image in the gallium texture memory buffer */
+      if (format == GL_DEPTH_COMPONENT &&
+          util_format_is_depth_and_stencil(stImage->pt->format))
+         transfer_usage = PIPE_TRANSFER_READ_WRITE;
+      else
+         transfer_usage = PIPE_TRANSFER_WRITE;
+
+      texImage->Data = st_texture_image_map(st, stImage, 0,
+                                            transfer_usage, 0, 0, width, height);
+      if(stImage->transfer)
+         dstRowStride = stImage->transfer->stride;
+   }
+   else {
+      /* Allocate regular memory and store the image there temporarily.   */
+      GLuint imageSize = _mesa_format_image_size(texImage->TexFormat,
+                                                 width, height, depth);
+      dstRowStride = _mesa_format_row_stride(texImage->TexFormat, width);
+
+      texImage->Data = _mesa_align_malloc(imageSize, 16);
+   }
+
+   if (!texImage->Data) {
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
+      return;
+   }
+
+   if (!pixels) {
+      /* We've allocated texture memory, but have no pixel data - all done. */
+      goto done;
+   }
+
+   DBG("Upload image %dx%dx%d row_len %x pitch %x\n",
+       width, height, depth, width, dstRowStride);
+
+   /* Copy user texture image into the texture buffer.
+    */
+   if (compressed_src) {
+      const GLuint srcRowStride =
+         _mesa_format_row_stride(texImage->TexFormat, width);
+      if (dstRowStride == srcRowStride) {
+         memcpy(texImage->Data, pixels, imageSize);
+      }
+      else {
+         char *dst = texImage->Data;
+         const char *src = pixels;
+         GLuint i, bw, bh, lines;
+         _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh);
+         lines = (height + bh - 1) / bh;
+
+         for (i = 0; i < lines; ++i) {
+            memcpy(dst, src, srcRowStride);
+            dst += dstRowStride;
+            src += srcRowStride;
+         }
+      }
+   }
+   else {
+      const GLuint srcImageStride =
+         _mesa_image_image_stride(unpack, width, height, format, type);
+      GLint i;
+      const GLubyte *src = (const GLubyte *) pixels;
+
+      for (i = 0; i < depth; i++) {
+	 if (!_mesa_texstore(ctx, dims, 
+                             texImage->_BaseFormat, 
+                             texImage->TexFormat, 
+                             texImage->Data,
+                             0, 0, 0, /* dstX/Y/Zoffset */
+                             dstRowStride,
+                             texImage->ImageOffsets,
+                             width, height, 1,
+                             format, type, src, unpack)) {
+	    _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
+	 }
+
+	 if (stImage->pt && i + 1 < depth) {
+            /* unmap this slice */
+	    st_texture_image_unmap(st, stImage);
+            /* map next slice of 3D texture */
+	    texImage->Data = st_texture_image_map(st, stImage, i + 1,
+                                                  transfer_usage, 0, 0,
+                                                  width, height);
+	    src += srcImageStride;
+	 }
+      }
+   }
+
+done:
+   _mesa_unmap_teximage_pbo(ctx, unpack);
+
+   if (stImage->pt && texImage->Data) {
+      st_texture_image_unmap(st, stImage);
+      texImage->Data = NULL;
+   }
+}
+
+
+static void
+st_TexImage3D(struct gl_context * ctx,
+              GLenum target, GLint level,
+              GLint internalFormat,
+              GLint width, GLint height, GLint depth,
+              GLint border,
+              GLenum format, GLenum type, const void *pixels,
+              const struct gl_pixelstore_attrib *unpack,
+              struct gl_texture_object *texObj,
+              struct gl_texture_image *texImage)
+{
+   st_TexImage(ctx, 3, target, level, internalFormat, width, height, depth,
+               border, format, type, pixels, unpack, texObj, texImage,
+               0, GL_FALSE);
+}
+
+
+static void
+st_TexImage2D(struct gl_context * ctx,
+              GLenum target, GLint level,
+              GLint internalFormat,
+              GLint width, GLint height, GLint border,
+              GLenum format, GLenum type, const void *pixels,
+              const struct gl_pixelstore_attrib *unpack,
+              struct gl_texture_object *texObj,
+              struct gl_texture_image *texImage)
+{
+   st_TexImage(ctx, 2, target, level, internalFormat, width, height, 1, border,
+               format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
+}
+
+
+static void
+st_TexImage1D(struct gl_context * ctx,
+              GLenum target, GLint level,
+              GLint internalFormat,
+              GLint width, GLint border,
+              GLenum format, GLenum type, const void *pixels,
+              const struct gl_pixelstore_attrib *unpack,
+              struct gl_texture_object *texObj,
+              struct gl_texture_image *texImage)
+{
+   st_TexImage(ctx, 1, target, level, internalFormat, width, 1, 1, border,
+               format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
+}
+
+
+static void
+st_CompressedTexImage2D(struct gl_context *ctx, GLenum target, GLint level,
+                        GLint internalFormat,
+                        GLint width, GLint height, GLint border,
+                        GLsizei imageSize, const GLvoid *data,
+                        struct gl_texture_object *texObj,
+                        struct gl_texture_image *texImage)
+{
+   st_TexImage(ctx, 2, target, level, internalFormat, width, height, 1, border,
+               0, 0, data, &ctx->Unpack, texObj, texImage, imageSize, GL_TRUE);
+}
+
+
+
+/**
+ * glGetTexImage() helper: decompress a compressed texture by rendering
+ * a textured quad.  Store the results in the user's buffer.
+ */
+static void
+decompress_with_blit(struct gl_context * ctx, GLenum target, GLint level,
+                     GLenum format, GLenum type, GLvoid *pixels,
+                     struct gl_texture_object *texObj,
+                     struct gl_texture_image *texImage)
+{
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
+   struct st_texture_image *stImage = st_texture_image(texImage);
+   struct st_texture_object *stObj = st_texture_object(texObj);
+   struct pipe_sampler_view *src_view =
+      st_get_texture_sampler_view(stObj, pipe);
+   const GLuint width = texImage->Width;
+   const GLuint height = texImage->Height;
+   struct pipe_surface *dst_surface;
+   struct pipe_resource *dst_texture;
+   struct pipe_transfer *tex_xfer;
+   unsigned bind = (PIPE_BIND_RENDER_TARGET | /* util_blit may choose to render */
+		    PIPE_BIND_TRANSFER_READ);
+
+   /* create temp / dest surface */
+   if (!util_create_rgba_surface(pipe, width, height, bind,
+                                 &dst_texture, &dst_surface)) {
+      _mesa_problem(ctx, "util_create_rgba_surface() failed "
+                    "in decompress_with_blit()");
+      return;
+   }
+
+   /* blit/render/decompress */
+   util_blit_pixels_tex(st->blit,
+                        src_view,      /* pipe_resource (src) */
+                        0, 0,             /* src x0, y0 */
+                        width, height,    /* src x1, y1 */
+                        dst_surface,      /* pipe_surface (dst) */
+                        0, 0,             /* dst x0, y0 */
+                        width, height,    /* dst x1, y1 */
+                        0.0,              /* z */
+                        PIPE_TEX_MIPFILTER_NEAREST);
+
+   /* map the dst_surface so we can read from it */
+   tex_xfer = pipe_get_transfer(st_context(ctx)->pipe,
+                                dst_texture, 0, 0,
+                                PIPE_TRANSFER_READ,
+                                0, 0, width, height);
+
+   pixels = _mesa_map_pbo_dest(ctx, &ctx->Pack, pixels);
+
+   /* copy/pack data into user buffer */
+   if (st_equal_formats(stImage->pt->format, format, type)) {
+      /* memcpy */
+      const uint bytesPerRow = width * util_format_get_blocksize(stImage->pt->format);
+      ubyte *map = pipe_transfer_map(pipe, tex_xfer);
+      GLuint row;
+      for (row = 0; row < height; row++) {
+         GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
+                                              height, format, type, row, 0);
+         memcpy(dest, map, bytesPerRow);
+         map += tex_xfer->stride;
+      }
+      pipe_transfer_unmap(pipe, tex_xfer);
+   }
+   else {
+      /* format translation via floats */
+      GLuint row;
+      enum pipe_format format = util_format_linear(dst_texture->format);
+      for (row = 0; row < height; row++) {
+         const GLbitfield transferOps = 0x0; /* bypassed for glGetTexImage() */
+         GLfloat rgba[4 * MAX_WIDTH];
+         GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
+                                              height, format, type, row, 0);
+
+         if (ST_DEBUG & DEBUG_FALLBACK)
+            debug_printf("%s: fallback format translation\n", __FUNCTION__);
+
+         /* get float[4] rgba row from surface */
+         pipe_get_tile_rgba_format(pipe, tex_xfer, 0, row, width, 1,
+                                   format, rgba);
+
+         _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format,
+                                    type, dest, &ctx->Pack, transferOps);
+      }
+   }
+
+   _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
+
+   pipe->transfer_destroy(pipe, tex_xfer);
+
+   /* destroy the temp / dest surface */
+   util_destroy_rgba_surface(dst_texture, dst_surface);
+}
+
+
+
+/**
+ * Need to map texture image into memory before copying image data,
+ * then unmap it.
+ */
+static void
+st_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
+                 GLenum format, GLenum type, GLvoid * pixels,
+                 struct gl_texture_object *texObj,
+                 struct gl_texture_image *texImage, GLboolean compressed_dst)
+{
+   struct st_context *st = st_context(ctx);
+   struct st_texture_image *stImage = st_texture_image(texImage);
+   const GLuint dstImageStride =
+      _mesa_image_image_stride(&ctx->Pack, texImage->Width, texImage->Height,
+                               format, type);
+   GLuint depth, i;
+   GLubyte *dest;
+
+   if (stImage->pt &&
+       util_format_is_s3tc(stImage->pt->format) &&
+       !compressed_dst) {
+      /* Need to decompress the texture.
+       * We'll do this by rendering a textured quad.
+       * Note that we only expect RGBA formats (no Z/depth formats).
+       */
+      decompress_with_blit(ctx, target, level, format, type, pixels,
+                           texObj, texImage);
+      return;
+   }
+
+   /* Map */
+   if (stImage->pt) {
+      /* Image is stored in hardware format in a buffer managed by the
+       * kernel.  Need to explicitly map and unmap it.
+       */
+      texImage->Data = st_texture_image_map(st, stImage, 0,
+                                            PIPE_TRANSFER_READ, 0, 0,
+                                            stImage->base.Width,
+                                            stImage->base.Height);
+      /* compute stride in texels from stride in bytes */
+      texImage->RowStride = stImage->transfer->stride
+         * util_format_get_blockwidth(stImage->pt->format)
+         / util_format_get_blocksize(stImage->pt->format);
+   }
+   else {
+      /* Otherwise, the image should actually be stored in
+       * texImage->Data.  This is pretty confusing for
+       * everybody, I'd much prefer to separate the two functions of
+       * texImage->Data - storage for texture images in main memory
+       * and access (ie mappings) of images.  In other words, we'd
+       * create a new texImage->Map field and leave Data simply for
+       * storage.
+       */
+      assert(texImage->Data);
+   }
+
+   depth = texImage->Depth;
+   texImage->Depth = 1;
+
+   dest = (GLubyte *) pixels;
+
+   _mesa_set_fetch_functions(texImage, get_texture_dims(target));
+
+   for (i = 0; i < depth; i++) {
+      if (compressed_dst) {
+	 _mesa_get_compressed_teximage(ctx, target, level, dest,
+				       texObj, texImage);
+      }
+      else {
+	 _mesa_get_teximage(ctx, target, level, format, type, dest,
+			    texObj, texImage);
+      }
+
+      if (stImage->pt && i + 1 < depth) {
+         /* unmap this slice */
+	 st_texture_image_unmap(st, stImage);
+         /* map next slice of 3D texture */
+	 texImage->Data = st_texture_image_map(st, stImage, i + 1,
+                                               PIPE_TRANSFER_READ, 0, 0,
+                                               stImage->base.Width,
+                                               stImage->base.Height);
+	 dest += dstImageStride;
+      }
+   }
+
+   texImage->Depth = depth;
+
+   /* Unmap */
+   if (stImage->pt) {
+      st_texture_image_unmap(st, stImage);
+      texImage->Data = NULL;
+   }
+}
+
+
+static void
+st_GetTexImage(struct gl_context * ctx, GLenum target, GLint level,
+               GLenum format, GLenum type, GLvoid * pixels,
+               struct gl_texture_object *texObj,
+               struct gl_texture_image *texImage)
+{
+   st_get_tex_image(ctx, target, level, format, type, pixels, texObj, texImage,
+                    GL_FALSE);
+}
+
+
+static void
+st_GetCompressedTexImage(struct gl_context *ctx, GLenum target, GLint level,
+                         GLvoid *pixels,
+                         struct gl_texture_object *texObj,
+                         struct gl_texture_image *texImage)
+{
+   st_get_tex_image(ctx, target, level, 0, 0, pixels, texObj, texImage,
+                    GL_TRUE);
+}
+
+
+
+static void
+st_TexSubimage(struct gl_context *ctx, GLint dims, GLenum target, GLint level,
+               GLint xoffset, GLint yoffset, GLint zoffset,
+               GLint width, GLint height, GLint depth,
+               GLenum format, GLenum type, const void *pixels,
+               const struct gl_pixelstore_attrib *packing,
+               struct gl_texture_object *texObj,
+               struct gl_texture_image *texImage)
+{
+   struct st_context *st = st_context(ctx);
+   struct pipe_screen *screen = st->pipe->screen;
+   struct st_texture_image *stImage = st_texture_image(texImage);
+   GLuint dstRowStride;
+   const GLuint srcImageStride =
+      _mesa_image_image_stride(packing, width, height, format, type);
+   GLint i;
+   const GLubyte *src;
+   /* init to silence warning only: */
+   enum pipe_transfer_usage transfer_usage = PIPE_TRANSFER_WRITE;
+
+   DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__,
+       _mesa_lookup_enum_by_nr(target),
+       level, xoffset, yoffset, width, height);
+
+   pixels =
+      _mesa_validate_pbo_teximage(ctx, dims, width, height, depth, format,
+                                  type, pixels, packing, "glTexSubImage2D");
+   if (!pixels)
+      return;
+
+   /* See if we can do texture compression with a blit/render.
+    */
+   if (!ctx->Mesa_DXTn &&
+       _mesa_is_format_compressed(texImage->TexFormat) &&
+       screen->is_format_supported(screen,
+                                   stImage->pt->format,
+                                   stImage->pt->target, 0,
+                                   PIPE_BIND_RENDER_TARGET, 0)) {
+      if (compress_with_blit(ctx, target, level,
+                             xoffset, yoffset, zoffset,
+                             width, height, depth,
+                             format, type, pixels, packing, texImage)) {
+         goto done;
+      }
+   }
+
+   /* Map buffer if necessary.  Need to lock to prevent other contexts
+    * from uploading the buffer under us.
+    */
+   if (stImage->pt) {
+      if (format == GL_DEPTH_COMPONENT &&
+          util_format_is_depth_and_stencil(stImage->pt->format))
+         transfer_usage = PIPE_TRANSFER_READ_WRITE;
+      else
+         transfer_usage = PIPE_TRANSFER_WRITE;
+
+      texImage->Data = st_texture_image_map(st, stImage, zoffset, 
+                                            transfer_usage,
+                                            xoffset, yoffset,
+                                            width, height);
+   }
+
+   if (!texImage->Data) {
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
+      goto done;
+   }
+
+   src = (const GLubyte *) pixels;
+   dstRowStride = stImage->transfer->stride;
+
+   for (i = 0; i < depth; i++) {
+      if (!_mesa_texstore(ctx, dims, texImage->_BaseFormat,
+                          texImage->TexFormat,
+                          texImage->Data,
+                          0, 0, 0,
+                          dstRowStride,
+                          texImage->ImageOffsets,
+                          width, height, 1,
+                          format, type, src, packing)) {
+	 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
+      }
+
+      if (stImage->pt && i + 1 < depth) {
+         /* unmap this slice */
+	 st_texture_image_unmap(st, stImage);
+         /* map next slice of 3D texture */
+	 texImage->Data = st_texture_image_map(st, stImage,
+                                               zoffset + i + 1,
+                                               transfer_usage,
+                                               xoffset, yoffset,
+                                               width, height);
+	 src += srcImageStride;
+      }
+   }
+
+done:
+   _mesa_unmap_teximage_pbo(ctx, packing);
+
+   if (stImage->pt && texImage->Data) {
+      st_texture_image_unmap(st, stImage);
+      texImage->Data = NULL;
+   }
+}
+
+
+
+static void
+st_TexSubImage3D(struct gl_context *ctx, GLenum target, GLint level,
+                 GLint xoffset, GLint yoffset, GLint zoffset,
+                 GLsizei width, GLsizei height, GLsizei depth,
+                 GLenum format, GLenum type, const GLvoid *pixels,
+                 const struct gl_pixelstore_attrib *packing,
+                 struct gl_texture_object *texObj,
+                 struct gl_texture_image *texImage)
+{
+   st_TexSubimage(ctx, 3, target, level, xoffset, yoffset, zoffset,
+                  width, height, depth, format, type,
+                  pixels, packing, texObj, texImage);
+}
+
+
+static void
+st_TexSubImage2D(struct gl_context *ctx, GLenum target, GLint level,
+                 GLint xoffset, GLint yoffset,
+                 GLsizei width, GLsizei height,
+                 GLenum format, GLenum type, const GLvoid * pixels,
+                 const struct gl_pixelstore_attrib *packing,
+                 struct gl_texture_object *texObj,
+                 struct gl_texture_image *texImage)
+{
+   st_TexSubimage(ctx, 2, target, level, xoffset, yoffset, 0,
+                  width, height, 1, format, type,
+                  pixels, packing, texObj, texImage);
+}
+
+
+static void
+st_TexSubImage1D(struct gl_context *ctx, GLenum target, GLint level,
+                 GLint xoffset, GLsizei width, GLenum format, GLenum type,
+                 const GLvoid * pixels,
+                 const struct gl_pixelstore_attrib *packing,
+                 struct gl_texture_object *texObj,
+                 struct gl_texture_image *texImage)
+{
+   st_TexSubimage(ctx, 1, target, level, xoffset, 0, 0, width, 1, 1,
+                  format, type, pixels, packing, texObj, texImage);
+}
+
+
+static void
+st_CompressedTexSubImage1D(struct gl_context *ctx, GLenum target, GLint level,
+                           GLint xoffset, GLsizei width,
+                           GLenum format,
+                           GLsizei imageSize, const GLvoid *data,
+                           struct gl_texture_object *texObj,
+                           struct gl_texture_image *texImage)
+{
+   assert(0);
+}
+
+
+static void
+st_CompressedTexSubImage2D(struct gl_context *ctx, GLenum target, GLint level,
+                           GLint xoffset, GLint yoffset,
+                           GLsizei width, GLint height,
+                           GLenum format,
+                           GLsizei imageSize, const GLvoid *data,
+                           struct gl_texture_object *texObj,
+                           struct gl_texture_image *texImage)
+{
+   struct st_context *st = st_context(ctx);
+   struct st_texture_image *stImage = st_texture_image(texImage);
+   int srcBlockStride;
+   int dstBlockStride;
+   int y;
+   enum pipe_format pformat;
+
+   if (stImage->pt) {
+      pformat = stImage->pt->format;
+
+      texImage->Data = st_texture_image_map(st, stImage, 0, 
+                                            PIPE_TRANSFER_WRITE,
+                                            xoffset, yoffset,
+                                            width, height);
+      
+      srcBlockStride = util_format_get_stride(pformat, width);
+      dstBlockStride = stImage->transfer->stride;
+   } else {
+      assert(stImage->pt);
+      /* TODO find good values for block and strides */
+      /* TODO also adjust texImage->data for yoffset/xoffset */
+      return;
+   }
+
+   if (!texImage->Data) {
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage");
+      return;
+   }
+
+   assert(xoffset % util_format_get_blockwidth(pformat) == 0);
+   assert(yoffset % util_format_get_blockheight(pformat) == 0);
+
+   for (y = 0; y < height; y += util_format_get_blockheight(pformat)) {
+      /* don't need to adjust for xoffset and yoffset as st_texture_image_map does that */
+      const char *src = (const char*)data + srcBlockStride * util_format_get_nblocksy(pformat, y);
+      char *dst = (char*)texImage->Data + dstBlockStride * util_format_get_nblocksy(pformat, y);
+      memcpy(dst, src, util_format_get_stride(pformat, width));
+   }
+
+   if (stImage->pt) {
+      st_texture_image_unmap(st, stImage);
+      texImage->Data = NULL;
+   }
+}
+
+
+static void
+st_CompressedTexSubImage3D(struct gl_context *ctx, GLenum target, GLint level,
+                           GLint xoffset, GLint yoffset, GLint zoffset,
+                           GLsizei width, GLint height, GLint depth,
+                           GLenum format,
+                           GLsizei imageSize, const GLvoid *data,
+                           struct gl_texture_object *texObj,
+                           struct gl_texture_image *texImage)
+{
+   assert(0);
+}
+
+
+
+/**
+ * Do a CopyTexSubImage operation using a read transfer from the source,
+ * a write transfer to the destination and get_tile()/put_tile() to access
+ * the pixels/texels.
+ *
+ * Note: srcY=0=TOP of renderbuffer
+ */
+static void
+fallback_copy_texsubimage(struct gl_context *ctx, GLenum target, GLint level,
+                          struct st_renderbuffer *strb,
+                          struct st_texture_image *stImage,
+                          GLenum baseFormat,
+                          GLint destX, GLint destY, GLint destZ,
+                          GLint srcX, GLint srcY,
+                          GLsizei width, GLsizei height)
+{
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
+   struct pipe_transfer *src_trans;
+   GLvoid *texDest;
+   enum pipe_transfer_usage transfer_usage;
+
+   if (ST_DEBUG & DEBUG_FALLBACK)
+      debug_printf("%s: fallback processing\n", __FUNCTION__);
+
+   assert(width <= MAX_WIDTH);
+
+   if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+      srcY = strb->Base.Height - srcY - height;
+   }
+
+   src_trans = pipe_get_transfer(st_context(ctx)->pipe,
+                                 strb->texture,
+                                 0, 0,
+                                 PIPE_TRANSFER_READ,
+                                 srcX, srcY,
+                                 width, height);
+
+   if ((baseFormat == GL_DEPTH_COMPONENT ||
+        baseFormat == GL_DEPTH_STENCIL) &&
+       util_format_is_depth_and_stencil(stImage->pt->format))
+      transfer_usage = PIPE_TRANSFER_READ_WRITE;
+   else
+      transfer_usage = PIPE_TRANSFER_WRITE;
+
+   /* XXX this used to ignore destZ param */
+   texDest = st_texture_image_map(st, stImage, destZ, transfer_usage,
+                                  destX, destY, width, height);
+
+   if (baseFormat == GL_DEPTH_COMPONENT ||
+       baseFormat == GL_DEPTH_STENCIL) {
+      const GLboolean scaleOrBias = (ctx->Pixel.DepthScale != 1.0F ||
+                                     ctx->Pixel.DepthBias != 0.0F);
+      GLint row, yStep;
+
+      /* determine bottom-to-top vs. top-to-bottom order for src buffer */
+      if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+         srcY = height - 1;
+         yStep = -1;
+      }
+      else {
+         srcY = 0;
+         yStep = 1;
+      }
+
+      /* To avoid a large temp memory allocation, do copy row by row */
+      for (row = 0; row < height; row++, srcY += yStep) {
+         uint data[MAX_WIDTH];
+         pipe_get_tile_z(pipe, src_trans, 0, srcY, width, 1, data);
+         if (scaleOrBias) {
+            _mesa_scale_and_bias_depth_uint(ctx, width, data);
+         }
+         pipe_put_tile_z(pipe, stImage->transfer, 0, row, width, 1, data);
+      }
+   }
+   else {
+      /* RGBA format */
+      GLfloat *tempSrc =
+         (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
+
+      if (tempSrc && texDest) {
+         const GLint dims = 2;
+         const GLint dstRowStride = stImage->transfer->stride;
+         struct gl_texture_image *texImage = &stImage->base;
+         struct gl_pixelstore_attrib unpack = ctx->DefaultPacking;
+
+         if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+            unpack.Invert = GL_TRUE;
+         }
+
+         /* get float/RGBA image from framebuffer */
+         /* XXX this usually involves a lot of int/float conversion.
+          * try to avoid that someday.
+          */
+         pipe_get_tile_rgba_format(pipe, src_trans, 0, 0, width, height,
+                                   util_format_linear(strb->texture->format),
+                                   tempSrc);
+
+         /* Store into texture memory.
+          * Note that this does some special things such as pixel transfer
+          * ops and format conversion.  In particular, if the dest tex format
+          * is actually RGBA but the user created the texture as GL_RGB we
+          * need to fill-in/override the alpha channel with 1.0.
+          */
+         _mesa_texstore(ctx, dims,
+                        texImage->_BaseFormat, 
+                        texImage->TexFormat, 
+                        texDest,
+                        0, 0, 0,
+                        dstRowStride,
+                        texImage->ImageOffsets,
+                        width, height, 1,
+                        GL_RGBA, GL_FLOAT, tempSrc, /* src */
+                        &unpack);
+      }
+      else {
+         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
+      }
+
+      if (tempSrc)
+         free(tempSrc);
+   }
+
+   st_texture_image_unmap(st, stImage);
+   pipe->transfer_destroy(pipe, src_trans);
+}
+
+
+
+/**
+ * If the format of the src renderbuffer and the format of the dest
+ * texture are compatible (in terms of blitting), return a TGSI writemask
+ * to be used during the blit.
+ * If the src/dest are incompatible, return 0.
+ */
+static unsigned
+compatible_src_dst_formats(struct gl_context *ctx,
+                           const struct gl_renderbuffer *src,
+                           const struct gl_texture_image *dst)
+{
+   /* Get logical base formats for the src and dest.
+    * That is, use the user-requested formats and not the actual, device-
+    * chosen formats.
+    * For example, the user may have requested an A8 texture but the
+    * driver may actually be using an RGBA texture format.  When we
+    * copy/blit to that texture, we only want to copy the Alpha channel
+    * and not the RGB channels.
+    *
+    * Similarly, when the src FBO was created an RGB format may have been
+    * requested but the driver actually chose an RGBA format.  In that case,
+    * we don't want to copy the undefined Alpha channel to the dest texture
+    * (it should be 1.0).
+    */
+   const GLenum srcFormat = _mesa_base_fbo_format(ctx, src->InternalFormat);
+   const GLenum dstFormat = _mesa_base_tex_format(ctx, dst->InternalFormat);
+
+   /**
+    * XXX when we have red-only and red/green renderbuffers we'll need
+    * to add more cases here (or implement a general-purpose routine that
+    * queries the existance of the R,G,B,A channels in the src and dest).
+    */
+   if (srcFormat == dstFormat) {
+      /* This is the same as matching_base_formats, which should
+       * always pass, as it did previously.
+       */
+      return TGSI_WRITEMASK_XYZW;
+   }
+   else if (srcFormat == GL_RGB && dstFormat == GL_RGBA) {
+      /* Make sure that A in the dest is 1.  The actual src format
+       * may be RGBA and have undefined A values.
+       */
+      return TGSI_WRITEMASK_XYZ;
+   }
+   else if (srcFormat == GL_RGBA && dstFormat == GL_RGB) {
+      /* Make sure that A in the dest is 1.  The actual dst format
+       * may be RGBA and will need A=1 to provide proper alpha values
+       * when sampled later.
+       */
+      return TGSI_WRITEMASK_XYZ;
+   }
+   else {
+      if (ST_DEBUG & DEBUG_FALLBACK)
+         debug_printf("%s failed for src %s, dst %s\n",
+                      __FUNCTION__, 
+                      _mesa_lookup_enum_by_nr(srcFormat),
+                      _mesa_lookup_enum_by_nr(dstFormat));
+
+      /* Otherwise fail.
+       */
+      return 0;
+   }
+}
+
+
+
+/**
+ * Do a CopyTex[Sub]Image1/2/3D() using a hardware (blit) path if possible.
+ * Note that the region to copy has already been clipped so we know we
+ * won't read from outside the source renderbuffer's bounds.
+ *
+ * Note: srcY=0=Bottom of renderbuffer (GL convention)
+ */
+static void
+st_copy_texsubimage(struct gl_context *ctx,
+                    GLenum target, GLint level,
+                    GLint destX, GLint destY, GLint destZ,
+                    GLint srcX, GLint srcY,
+                    GLsizei width, GLsizei height)
+{
+   struct gl_texture_unit *texUnit =
+      &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   struct gl_texture_object *texObj =
+      _mesa_select_tex_object(ctx, texUnit, target);
+   struct gl_texture_image *texImage =
+      _mesa_select_tex_image(ctx, texObj, target, level);
+   struct st_texture_image *stImage = st_texture_image(texImage);
+   const GLenum texBaseFormat = texImage->_BaseFormat;
+   struct gl_framebuffer *fb = ctx->ReadBuffer;
+   struct st_renderbuffer *strb;
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
+   struct pipe_screen *screen = pipe->screen;
+   enum pipe_format dest_format, src_format;
+   GLboolean use_fallback = GL_TRUE;
+   GLboolean matching_base_formats;
+   GLuint format_writemask, sample_count;
+   struct pipe_surface *dest_surface = NULL;
+   GLboolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP);
+
+   /* make sure finalize_textures has been called? 
+    */
+   if (0) st_validate_state(st);
+
+   /* determine if copying depth or color data */
+   if (texBaseFormat == GL_DEPTH_COMPONENT ||
+       texBaseFormat == GL_DEPTH_STENCIL) {
+      strb = st_renderbuffer(fb->_DepthBuffer);
+      if (strb->Base.Wrapped) {
+         strb = st_renderbuffer(strb->Base.Wrapped);
+      }
+   }
+   else {
+      /* texBaseFormat == GL_RGB, GL_RGBA, GL_ALPHA, etc */
+      strb = st_renderbuffer(fb->_ColorReadBuffer);
+   }
+
+   if (!strb || !strb->surface || !stImage->pt) {
+      debug_printf("%s: null strb or stImage\n", __FUNCTION__);
+      return;
+   }
+
+   sample_count = strb->surface->texture->nr_samples;
+   /* I believe this would be legal, presumably would need to do a resolve
+      for color, and for depth/stencil spec says to just use one of the
+      depth/stencil samples per pixel? Need some transfer clarifications. */
+   assert(sample_count < 2);
+
+   if (srcX < 0) {
+      width -= -srcX;
+      destX += -srcX;
+      srcX = 0;
+   }
+
+   if (srcY < 0) {
+      height -= -srcY;
+      destY += -srcY;
+      srcY = 0;
+   }
+
+   if (destX < 0) {
+      width -= -destX;
+      srcX += -destX;
+      destX = 0;
+   }
+
+   if (destY < 0) {
+      height -= -destY;
+      srcY += -destY;
+      destY = 0;
+   }
+
+   if (width < 0 || height < 0)
+      return;
+
+
+   assert(strb);
+   assert(strb->surface);
+   assert(stImage->pt);
+
+   src_format = strb->surface->format;
+   dest_format = stImage->pt->format;
+
+   /*
+    * Determine if the src framebuffer and dest texture have the same
+    * base format.  We need this to detect a case such as the framebuffer
+    * being GL_RGBA but the texture being GL_RGB.  If the actual hardware
+    * texture format stores RGBA we need to set A=1 (overriding the
+    * framebuffer's alpha values).  We can't do that with the blit or
+    * textured-quad paths.
+    */
+   matching_base_formats =
+      (_mesa_get_format_base_format(strb->Base.Format) ==
+       _mesa_get_format_base_format(texImage->TexFormat));
+   format_writemask = compatible_src_dst_formats(ctx, &strb->Base, texImage);
+
+   if (ctx->_ImageTransferState == 0x0) {
+
+      if (matching_base_formats &&
+          src_format == dest_format &&
+          !do_flip)
+      {
+         /* use surface_copy() / blit */
+         struct pipe_box src_box;
+         u_box_2d_zslice(srcX, srcY, strb->surface->u.tex.first_layer,
+                         width, height, &src_box);
+
+         /* for resource_copy_region(), y=0=top, always */
+         pipe->resource_copy_region(pipe,
+                                    /* dest */
+                                    stImage->pt,
+                                    stImage->level,
+                                    destX, destY, destZ + stImage->face,
+                                    /* src */
+                                    strb->texture,
+                                    strb->surface->u.tex.level,
+                                    &src_box);
+         use_fallback = GL_FALSE;
+      }
+      else if (format_writemask &&
+               texBaseFormat != GL_DEPTH_COMPONENT &&
+               texBaseFormat != GL_DEPTH_STENCIL &&
+               screen->is_format_supported(screen, src_format,
+                                           PIPE_TEXTURE_2D, sample_count,
+                                           PIPE_BIND_SAMPLER_VIEW,
+                                           0) &&
+               screen->is_format_supported(screen, dest_format,
+                                           PIPE_TEXTURE_2D, 0,
+                                           PIPE_BIND_RENDER_TARGET,
+                                           0)) {
+         /* draw textured quad to do the copy */
+         GLint srcY0, srcY1;
+         struct pipe_surface surf_tmpl;
+         memset(&surf_tmpl, 0, sizeof(surf_tmpl));
+         surf_tmpl.format = stImage->pt->format;
+         surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
+         surf_tmpl.u.tex.level = stImage->level;
+         surf_tmpl.u.tex.first_layer = stImage->face + destZ;
+         surf_tmpl.u.tex.last_layer = stImage->face + destZ;
+
+         dest_surface = pipe->create_surface(pipe, stImage->pt,
+                                             &surf_tmpl);
+
+         if (do_flip) {
+            srcY1 = strb->Base.Height - srcY - height;
+            srcY0 = srcY1 + height;
+         }
+         else {
+            srcY0 = srcY;
+            srcY1 = srcY0 + height;
+         }
+
+         util_blit_pixels_writemask(st->blit,
+                                    strb->texture,
+                                    strb->surface->u.tex.level,
+                                    srcX, srcY0,
+                                    srcX + width, srcY1,
+                                    strb->surface->u.tex.first_layer,
+                                    dest_surface,
+                                    destX, destY,
+                                    destX + width, destY + height,
+                                    0.0, PIPE_TEX_MIPFILTER_NEAREST,
+                                    format_writemask);
+         use_fallback = GL_FALSE;
+      }
+
+      if (dest_surface)
+         pipe_surface_reference(&dest_surface, NULL);
+   }
+
+   if (use_fallback) {
+      /* software fallback */
+      fallback_copy_texsubimage(ctx, target, level,
+                                strb, stImage, texBaseFormat,
+                                destX, destY, destZ,
+                                srcX, srcY, width, height);
+   }
+}
+
+
+
+static void
+st_CopyTexImage1D(struct gl_context * ctx, GLenum target, GLint level,
+                  GLenum internalFormat,
+                  GLint x, GLint y, GLsizei width, GLint border)
+{
+   struct gl_texture_unit *texUnit =
+      &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   struct gl_texture_object *texObj =
+      _mesa_select_tex_object(ctx, texUnit, target);
+   struct gl_texture_image *texImage =
+      _mesa_select_tex_image(ctx, texObj, target, level);
+
+   /* Setup or redefine the texture object, texture and texture
+    * image.  Don't populate yet.  
+    */
+   ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
+                          width, border,
+                          GL_RGBA, CHAN_TYPE, NULL,
+                          &ctx->DefaultPacking, texObj, texImage);
+
+   st_copy_texsubimage(ctx, target, level,
+                       0, 0, 0,  /* destX,Y,Z */
+                       x, y, width, 1);  /* src X, Y, size */
+}
+
+
+static void
+st_CopyTexImage2D(struct gl_context * ctx, GLenum target, GLint level,
+                  GLenum internalFormat,
+                  GLint x, GLint y, GLsizei width, GLsizei height,
+                  GLint border)
+{
+   struct gl_texture_unit *texUnit =
+      &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   struct gl_texture_object *texObj =
+      _mesa_select_tex_object(ctx, texUnit, target);
+   struct gl_texture_image *texImage =
+      _mesa_select_tex_image(ctx, texObj, target, level);
+
+   /* Setup or redefine the texture object, texture and texture
+    * image.  Don't populate yet.  
+    */
+   ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
+                          width, height, border,
+                          GL_RGBA, CHAN_TYPE, NULL,
+                          &ctx->DefaultPacking, texObj, texImage);
+
+   st_copy_texsubimage(ctx, target, level,
+                       0, 0, 0,  /* destX,Y,Z */
+                       x, y, width, height);  /* src X, Y, size */
+}
+
+
+static void
+st_CopyTexSubImage1D(struct gl_context * ctx, GLenum target, GLint level,
+                     GLint xoffset, GLint x, GLint y, GLsizei width)
+{
+   const GLint yoffset = 0, zoffset = 0;
+   const GLsizei height = 1;
+   st_copy_texsubimage(ctx, target, level,
+                       xoffset, yoffset, zoffset,  /* destX,Y,Z */
+                       x, y, width, height);  /* src X, Y, size */
+}
+
+
+static void
+st_CopyTexSubImage2D(struct gl_context * ctx, GLenum target, GLint level,
+                     GLint xoffset, GLint yoffset,
+                     GLint x, GLint y, GLsizei width, GLsizei height)
+{
+   const GLint zoffset = 0;
+   st_copy_texsubimage(ctx, target, level,
+                       xoffset, yoffset, zoffset,  /* destX,Y,Z */
+                       x, y, width, height);  /* src X, Y, size */
+}
+
+
+static void
+st_CopyTexSubImage3D(struct gl_context * ctx, GLenum target, GLint level,
+                     GLint xoffset, GLint yoffset, GLint zoffset,
+                     GLint x, GLint y, GLsizei width, GLsizei height)
+{
+   st_copy_texsubimage(ctx, target, level,
+                       xoffset, yoffset, zoffset,  /* destX,Y,Z */
+                       x, y, width, height);  /* src X, Y, size */
+}
+
+
+/**
+ * Copy image data from stImage into the texture object 'stObj' at level
+ * 'dstLevel'.
+ */
+static void
+copy_image_data_to_texture(struct st_context *st,
+			   struct st_texture_object *stObj,
+                           GLuint dstLevel,
+			   struct st_texture_image *stImage)
+{
+   /* debug checks */
+   {
+      const struct gl_texture_image *dstImage =
+         stObj->base.Image[stImage->face][stImage->level];
+      assert(dstImage);
+      assert(dstImage->Width == stImage->base.Width);
+      assert(dstImage->Height == stImage->base.Height);
+      assert(dstImage->Depth == stImage->base.Depth);
+   }
+
+   if (stImage->pt) {
+      /* Copy potentially with the blitter:
+       */
+      st_texture_image_copy(st->pipe,
+                            stObj->pt, dstLevel,  /* dest texture, level */
+                            stImage->pt, stImage->level, /* src texture, level */
+                            stImage->face);
+
+      pipe_resource_reference(&stImage->pt, NULL);
+   }
+   else if (stImage->base.Data) {
+      st_texture_image_data(st,
+                            stObj->pt,
+                            stImage->face,
+                            dstLevel,
+                            stImage->base.Data,
+                            stImage->base.RowStride * 
+                            util_format_get_blocksize(stObj->pt->format),
+                            stImage->base.RowStride *
+                            stImage->base.Height *
+                            util_format_get_blocksize(stObj->pt->format));
+      _mesa_align_free(stImage->base.Data);
+      stImage->base.Data = NULL;
+   }
+
+   pipe_resource_reference(&stImage->pt, stObj->pt);
+}
+
+
+/**
+ * Called during state validation.  When this function is finished,
+ * the texture object should be ready for rendering.
+ * \return GL_TRUE for success, GL_FALSE for failure (out of mem)
+ */
+GLboolean
+st_finalize_texture(struct gl_context *ctx,
+		    struct pipe_context *pipe,
+		    struct gl_texture_object *tObj)
+{
+   struct st_context *st = st_context(ctx);
+   struct st_texture_object *stObj = st_texture_object(tObj);
+   const GLuint nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+   GLuint face;
+   struct st_texture_image *firstImage;
+   enum pipe_format firstImageFormat;
+   GLuint ptWidth, ptHeight, ptDepth, ptLayers;
+
+   if (stObj->base._Complete) {
+      /* The texture is complete and we know exactly how many mipmap levels
+       * are present/needed.  This is conditional because we may be called
+       * from the st_generate_mipmap() function when the texture object is
+       * incomplete.  In that case, we'll have set stObj->lastLevel before
+       * we get here.
+       */
+      if (stObj->base.MinFilter == GL_LINEAR ||
+          stObj->base.MinFilter == GL_NEAREST)
+         stObj->lastLevel = stObj->base.BaseLevel;
+      else
+         stObj->lastLevel = stObj->base._MaxLevel;
+   }
+
+   firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
+   assert(firstImage);
+
+   /* If both firstImage and stObj point to a texture which can contain
+    * all active images, favour firstImage.  Note that because of the
+    * completeness requirement, we know that the image dimensions
+    * will match.
+    */
+   if (firstImage->pt &&
+       firstImage->pt != stObj->pt &&
+       (!stObj->pt || firstImage->pt->last_level >= stObj->pt->last_level)) {
+      pipe_resource_reference(&stObj->pt, firstImage->pt);
+      pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+   }
+
+   /* Find gallium format for the Mesa texture */
+   firstImageFormat = st_mesa_format_to_pipe_format(firstImage->base.TexFormat);
+   st_gl_texture_dims_to_pipe_dims(stObj->base.Target, stObj->width0,
+                                   stObj->height0, stObj->depth0,
+                                   &ptWidth, &ptHeight, &ptDepth, &ptLayers);
+
+   /* If we already have a gallium texture, check that it matches the texture
+    * object's format, target, size, num_levels, etc.
+    */
+   if (stObj->pt) {
+      if (stObj->pt->target != gl_target_to_pipe(stObj->base.Target) ||
+          !st_sampler_compat_formats(stObj->pt->format, firstImageFormat) ||
+          stObj->pt->last_level < stObj->lastLevel ||
+          stObj->pt->width0 != ptWidth ||
+          stObj->pt->height0 != ptHeight ||
+          stObj->pt->depth0 != ptDepth ||
+          stObj->pt->array_size != ptLayers)
+      {
+         /* The gallium texture does not match the Mesa texture so delete the
+          * gallium texture now.  We'll make a new one below.
+          */
+         pipe_resource_reference(&stObj->pt, NULL);
+         pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+         st->dirty.st |= ST_NEW_FRAMEBUFFER;
+      }
+   }
+
+   /* May need to create a new gallium texture:
+    */
+   if (!stObj->pt) {
+      GLuint bindings = default_bindings(st, firstImageFormat);
+
+      stObj->pt = st_texture_create(st,
+                                    gl_target_to_pipe(stObj->base.Target),
+                                    firstImageFormat,
+                                    stObj->lastLevel,
+                                    ptWidth,
+                                    ptHeight,
+                                    ptDepth,
+                                    ptLayers,
+                                    bindings);
+
+      if (!stObj->pt) {
+         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
+         return GL_FALSE;
+      }
+   }
+
+   /* Pull in any images not in the object's texture:
+    */
+   for (face = 0; face < nr_faces; face++) {
+      GLuint level;
+      for (level = stObj->base.BaseLevel; level <= stObj->lastLevel; level++) {
+         struct st_texture_image *stImage =
+            st_texture_image(stObj->base.Image[face][level]);
+
+         /* Need to import images in main memory or held in other textures.
+          */
+         if (stImage && stObj->pt != stImage->pt) {
+            copy_image_data_to_texture(st, stObj, level, stImage);
+         }
+      }
+   }
+
+   return GL_TRUE;
+}
+
+
+/**
+ * Returns pointer to a default/dummy texture.
+ * This is typically used when the current shader has tex/sample instructions
+ * but the user has not provided a (any) texture(s).
+ */
+struct gl_texture_object *
+st_get_default_texture(struct st_context *st)
+{
+   if (!st->default_texture) {
+      static const GLenum target = GL_TEXTURE_2D;
+      GLubyte pixels[16][16][4];
+      struct gl_texture_object *texObj;
+      struct gl_texture_image *texImg;
+      GLuint i, j;
+
+      /* The ARB_fragment_program spec says (0,0,0,1) should be returned
+       * when attempting to sample incomplete textures.
+       */
+      for (i = 0; i < 16; i++) {
+         for (j = 0; j < 16; j++) {
+            pixels[i][j][0] = 0;
+            pixels[i][j][1] = 0;
+            pixels[i][j][2] = 0;
+            pixels[i][j][3] = 255;
+         }
+      }
+
+      texObj = st->ctx->Driver.NewTextureObject(st->ctx, 0, target);
+
+      texImg = _mesa_get_tex_image(st->ctx, texObj, target, 0);
+
+      _mesa_init_teximage_fields(st->ctx, target, texImg,
+                                 16, 16, 1, 0,  /* w, h, d, border */
+                                 GL_RGBA, MESA_FORMAT_RGBA8888);
+
+      st_TexImage(st->ctx, 2, target,
+                  0, GL_RGBA,    /* level, intformat */
+                  16, 16, 1, 0,  /* w, h, d, border */
+                  GL_RGBA, GL_UNSIGNED_BYTE, pixels,
+                  &st->ctx->DefaultPacking,
+                  texObj, texImg,
+                  0, 0);
+
+      texObj->MinFilter = GL_NEAREST;
+      texObj->MagFilter = GL_NEAREST;
+      texObj->_Complete = GL_TRUE;
+
+      st->default_texture = texObj;
+   }
+   return st->default_texture;
+}
+
+
+void
+st_init_texture_functions(struct dd_function_table *functions)
+{
+   functions->ChooseTextureFormat = st_ChooseTextureFormat;
+   functions->TexImage1D = st_TexImage1D;
+   functions->TexImage2D = st_TexImage2D;
+   functions->TexImage3D = st_TexImage3D;
+   functions->TexSubImage1D = st_TexSubImage1D;
+   functions->TexSubImage2D = st_TexSubImage2D;
+   functions->TexSubImage3D = st_TexSubImage3D;
+   functions->CompressedTexSubImage1D = st_CompressedTexSubImage1D;
+   functions->CompressedTexSubImage2D = st_CompressedTexSubImage2D;
+   functions->CompressedTexSubImage3D = st_CompressedTexSubImage3D;
+   functions->CopyTexImage1D = st_CopyTexImage1D;
+   functions->CopyTexImage2D = st_CopyTexImage2D;
+   functions->CopyTexSubImage1D = st_CopyTexSubImage1D;
+   functions->CopyTexSubImage2D = st_CopyTexSubImage2D;
+   functions->CopyTexSubImage3D = st_CopyTexSubImage3D;
+   functions->GenerateMipmap = st_generate_mipmap;
+
+   functions->GetTexImage = st_GetTexImage;
+
+   /* compressed texture functions */
+   functions->CompressedTexImage2D = st_CompressedTexImage2D;
+   functions->GetCompressedTexImage = st_GetCompressedTexImage;
+
+   functions->NewTextureObject = st_NewTextureObject;
+   functions->NewTextureImage = st_NewTextureImage;
+   functions->DeleteTexture = st_DeleteTextureObject;
+   functions->FreeTexImageData = st_FreeTextureImageData;
+
+   functions->TextureMemCpy = do_memcpy;
+
+   /* XXX Temporary until we can query pipe's texture sizes */
+   functions->TestProxyTexImage = _mesa_test_proxy_teximage;
+}
diff --git a/mesalib/src/mesa/state_tracker/st_gen_mipmap.c b/mesalib/src/mesa/state_tracker/st_gen_mipmap.c
index a7dfbea1a..0be66a2c2 100644
--- a/mesalib/src/mesa/state_tracker/st_gen_mipmap.c
+++ b/mesalib/src/mesa/state_tracker/st_gen_mipmap.c
@@ -352,6 +352,7 @@ st_generate_mipmap(struct gl_context *ctx, GLenum target,
                                     oldTex->width0,
                                     oldTex->height0,
                                     oldTex->depth0,
+                                    oldTex->array_size,
                                     oldTex->bind);
 
       /* The texture isn't in a "complete" state yet so set the expected
diff --git a/mesalib/src/mesa/state_tracker/st_texture.c b/mesalib/src/mesa/state_tracker/st_texture.c
index 4d4b238ef..0d5dc8140 100644
--- a/mesalib/src/mesa/state_tracker/st_texture.c
+++ b/mesalib/src/mesa/state_tracker/st_texture.c
@@ -59,6 +59,7 @@ st_texture_create(struct st_context *st,
 		  GLuint width0,
 		  GLuint height0,
 		  GLuint depth0,
+                  GLuint layers,
                   GLuint bind )
 {
    struct pipe_resource pt, *newtex;
@@ -68,6 +69,8 @@ st_texture_create(struct st_context *st,
    assert(width0 > 0);
    assert(height0 > 0);
    assert(depth0 > 0);
+   if (target == PIPE_TEXTURE_CUBE)
+      assert(layers == 6);
 
    DBG("%s target %s format %s last_level %d\n", __FUNCTION__,
        _mesa_lookup_enum_by_nr(target),
@@ -84,7 +87,7 @@ st_texture_create(struct st_context *st,
    pt.width0 = width0;
    pt.height0 = height0;
    pt.depth0 = depth0;
-   pt.array_size = (target == PIPE_TEXTURE_CUBE ? 6 : 1);
+   pt.array_size = (target == PIPE_TEXTURE_CUBE ? 6 : layers);
    pt.usage = PIPE_USAGE_DEFAULT;
    pt.bind = bind;
    pt.flags = 0;
@@ -97,6 +100,72 @@ st_texture_create(struct st_context *st,
 }
 
 
+/**
+ * In OpenGL the number of 1D array texture layers is the "height" and
+ * the number of 2D array texture layers is the "depth".  In Gallium the
+ * number of layers in an array texture is a separate 'array_size' field.
+ * This function converts dimensions from the former to the later.
+ */
+void
+st_gl_texture_dims_to_pipe_dims(GLenum texture,
+                                GLuint widthIn,
+                                GLuint heightIn,
+                                GLuint depthIn,
+                                GLuint *widthOut,
+                                GLuint *heightOut,
+                                GLuint *depthOut,
+                                GLuint *layersOut)
+{
+   switch (texture) {
+   case GL_TEXTURE_1D:
+      assert(heightIn == 1);
+      assert(depthIn == 1);
+      *widthOut = widthIn;
+      *heightOut = 1;
+      *depthOut = 1;
+      *layersOut = 1;
+      break;
+   case GL_TEXTURE_1D_ARRAY:
+      assert(depthIn == 1);
+      *widthOut = widthIn;
+      *heightOut = 1;
+      *depthOut = 1;
+      *layersOut = heightIn;
+      break;
+   case GL_TEXTURE_2D:
+   case GL_TEXTURE_RECTANGLE:
+      assert(depthIn == 1);
+      *widthOut = widthIn;
+      *heightOut = heightIn;
+      *depthOut = 1;
+      *layersOut = 1;
+      break;
+   case GL_TEXTURE_CUBE_MAP:
+      assert(depthIn == 1);
+      *widthOut = widthIn;
+      *heightOut = heightIn;
+      *depthOut = 1;
+      *layersOut = 6;
+      break;
+   case GL_TEXTURE_2D_ARRAY:
+      *widthOut = widthIn;
+      *heightOut = heightIn;
+      *depthOut = 1;
+      *layersOut = depthIn;
+      break;
+   default:
+      assert(0 && "Unexpected texture in st_gl_texture_dims_to_pipe_dims()");
+      /* fall-through */
+   case GL_TEXTURE_3D:
+      *widthOut = widthIn;
+      *heightOut = heightIn;
+      *depthOut = depthIn;
+      *layersOut = 1;
+      break;
+   }
+}
+
+
 /**
  * Check if a texture image can be pulled into a unified mipmap texture.
  */
@@ -105,6 +174,8 @@ st_texture_match_image(const struct pipe_resource *pt,
                        const struct gl_texture_image *image,
                        GLuint face, GLuint level)
 {
+   GLuint ptWidth, ptHeight, ptDepth, ptLayers;
+
    /* Images with borders are never pulled into mipmap textures. 
     */
    if (image->Border) 
@@ -115,12 +186,17 @@ st_texture_match_image(const struct pipe_resource *pt,
    if (st_mesa_format_to_pipe_format(image->TexFormat) != pt->format)
       return GL_FALSE;
 
+   st_gl_texture_dims_to_pipe_dims(image->TexObject->Target,
+                                   image->Width, image->Height, image->Depth,
+                                   &ptWidth, &ptHeight, &ptDepth, &ptLayers);
+
    /* Test if this image's size matches what's expected in the
     * established texture.
     */
-   if (image->Width != u_minify(pt->width0, level) ||
-       image->Height != u_minify(pt->height0, level) ||
-       image->Depth != u_minify(pt->depth0, level))
+   if (ptWidth != u_minify(pt->width0, level) ||
+       ptHeight != u_minify(pt->height0, level) ||
+       ptDepth != u_minify(pt->depth0, level) ||
+       ptLayers != pt->array_size)
       return GL_FALSE;
 
    return GL_TRUE;
@@ -212,14 +288,20 @@ st_texture_image_data(struct st_context *st,
                       GLuint src_row_stride, GLuint src_image_stride)
 {
    struct pipe_context *pipe = st->pipe;
-   GLuint depth = u_minify(dst->depth0, level);
    GLuint i;
    const GLubyte *srcUB = src;
    struct pipe_transfer *dst_transfer;
+   GLuint layers;
+
+   if (dst->target == PIPE_TEXTURE_1D_ARRAY ||
+       dst->target == PIPE_TEXTURE_2D_ARRAY)
+      layers = dst->array_size;
+   else
+      layers = u_minify(dst->depth0, level);
 
    DBG("%s\n", __FUNCTION__);
 
-   for (i = 0; i < depth; i++) {
+   for (i = 0; i < layers; i++) {
       dst_transfer = pipe_get_transfer(st->pipe, dst, level, face + i,
                                        PIPE_TRANSFER_WRITE, 0, 0,
                                        u_minify(dst->width0, level),
diff --git a/mesalib/src/mesa/state_tracker/st_texture.h b/mesalib/src/mesa/state_tracker/st_texture.h
index bca856d71..b25f16410 100644
--- a/mesalib/src/mesa/state_tracker/st_texture.h
+++ b/mesalib/src/mesa/state_tracker/st_texture.h
@@ -1,221 +1,235 @@
-/**************************************************************************
- * 
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- * 
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- * 
- **************************************************************************/
-
-#ifndef ST_TEXTURE_H
-#define ST_TEXTURE_H
-
-
-#include "pipe/p_context.h"
-#include "util/u_sampler.h"
-
-#include "main/mtypes.h"
-
-
-struct pipe_resource;
-
-
-/**
- * Subclass of gl_texure_image.
- */
-struct st_texture_image
-{
-   struct gl_texture_image base;
-
-   /* These aren't stored in gl_texture_image 
-    */
-   GLuint level;
-   GLuint face;
-
-   /* If stImage->pt != NULL, image data is stored here.
-    * Else if stImage->base.Data != NULL, image is stored there.
-    * Else there is no image data.
-    */
-   struct pipe_resource *pt;
-
-   struct pipe_transfer *transfer;
-};
-
-
-/**
- * Subclass of gl_texure_object.
- */
-struct st_texture_object
-{
-   struct gl_texture_object base;       /* The "parent" object */
-
-   /* The texture must include at levels [0..lastLevel] once validated:
-    */
-   GLuint lastLevel;
-
-   /** The size of the level=0 mipmap image */
-   GLuint width0, height0, depth0;
-
-   /* On validation any active images held in main memory or in other
-    * textures will be copied to this texture and the old storage freed.
-    */
-   struct pipe_resource *pt;
-
-   /* Default sampler view attached to this texture object. Created lazily
-    * on first binding.
-    */
-   struct pipe_sampler_view *sampler_view;
-
-   /* True if there is/was a surface bound to this texture object.  It helps
-    * track whether the texture object is surface based or not.
-    */
-   GLboolean surface_based;
-};
-
-
-static INLINE struct st_texture_image *
-st_texture_image(struct gl_texture_image *img)
-{
-   return (struct st_texture_image *) img;
-}
-
-static INLINE struct st_texture_object *
-st_texture_object(struct gl_texture_object *obj)
-{
-   return (struct st_texture_object *) obj;
-}
-
-
-static INLINE struct pipe_resource *
-st_get_texobj_resource(struct gl_texture_object *texObj)
-{
-   struct st_texture_object *stObj = st_texture_object(texObj);
-   return stObj ? stObj->pt : NULL;
-}
-
-
-static INLINE struct pipe_resource *
-st_get_stobj_resource(struct st_texture_object *stObj)
-{
-   return stObj ? stObj->pt : NULL;
-}
-
-
-static INLINE struct pipe_sampler_view *
-st_create_texture_sampler_view(struct pipe_context *pipe,
-                               struct pipe_resource *texture)
-{
-   struct pipe_sampler_view templ;
-
-   u_sampler_view_default_template(&templ, texture, texture->format);
-
-   return pipe->create_sampler_view(pipe, texture, &templ);
-}
-
-
-static INLINE struct pipe_sampler_view *
-st_create_texture_sampler_view_format(struct pipe_context *pipe,
-                                      struct pipe_resource *texture,
-                                      enum pipe_format format)
-{
-   struct pipe_sampler_view templ;
-
-   u_sampler_view_default_template(&templ, texture, format);
-
-   return pipe->create_sampler_view(pipe, texture, &templ);
-}
-
-
-static INLINE struct pipe_sampler_view *
-st_get_texture_sampler_view(struct st_texture_object *stObj,
-                            struct pipe_context *pipe)
-{
-   if (!stObj || !stObj->pt) {
-      return NULL;
-   }
-
-   if (!stObj->sampler_view) {
-      stObj->sampler_view = st_create_texture_sampler_view(pipe, stObj->pt);
-   }
-
-   return stObj->sampler_view;
-}
-
-
-extern struct pipe_resource *
-st_texture_create(struct st_context *st,
-                  enum pipe_texture_target target,
-		  enum pipe_format format,
-                  GLuint last_level,
-                  GLuint width0,
-                  GLuint height0,
-                  GLuint depth0,
-                  GLuint tex_usage );
-
-
-/* Check if an image fits into an existing texture object.
- */
-extern GLboolean
-st_texture_match_image(const struct pipe_resource *pt,
-                       const struct gl_texture_image *image,
-                       GLuint face, GLuint level);
-
-/* Return a pointer to an image within a texture.  Return image stride as
- * well.
- */
-extern GLubyte *
-st_texture_image_map(struct st_context *st,
-                     struct st_texture_image *stImage,
-		     GLuint zoffset,
-                     enum pipe_transfer_usage usage,
-                     unsigned x, unsigned y,
-                     unsigned w, unsigned h);
-
-extern void
-st_texture_image_unmap(struct st_context *st,
-                       struct st_texture_image *stImage);
-
-
-/* Return pointers to each 2d slice within an image.  Indexed by depth
- * value.
- */
-extern const GLuint *
-st_texture_depth_offsets(struct pipe_resource *pt, GLuint level);
-
-
-/* Upload an image into a texture
- */
-extern void
-st_texture_image_data(struct st_context *st,
-                      struct pipe_resource *dst,
-                      GLuint face, GLuint level, void *src,
-                      GLuint src_row_pitch, GLuint src_image_pitch);
-
-
-/* Copy an image between two textures
- */
-extern void
-st_texture_image_copy(struct pipe_context *pipe,
-                      struct pipe_resource *dst, GLuint dstLevel,
-                      struct pipe_resource *src, GLuint srcLevel,
-                      GLuint face);
-
-#endif
+/**************************************************************************
+ * 
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * 
+ **************************************************************************/
+
+#ifndef ST_TEXTURE_H
+#define ST_TEXTURE_H
+
+
+#include "pipe/p_context.h"
+#include "util/u_sampler.h"
+
+#include "main/mtypes.h"
+
+
+struct pipe_resource;
+
+
+/**
+ * Subclass of gl_texure_image.
+ */
+struct st_texture_image
+{
+   struct gl_texture_image base;
+
+   /* These aren't stored in gl_texture_image 
+    */
+   GLuint level;
+   GLuint face;
+
+   /* If stImage->pt != NULL, image data is stored here.
+    * Else if stImage->base.Data != NULL, image is stored there.
+    * Else there is no image data.
+    */
+   struct pipe_resource *pt;
+
+   struct pipe_transfer *transfer;
+};
+
+
+/**
+ * Subclass of gl_texure_object.
+ */
+struct st_texture_object
+{
+   struct gl_texture_object base;       /* The "parent" object */
+
+   /* The texture must include at levels [0..lastLevel] once validated:
+    */
+   GLuint lastLevel;
+
+   /** The size of the level=0 mipmap image.
+    * Note that the number of 1D array layers will be in height0 and the
+    * number of 2D array layers will be in depth0, as in GL.
+    */
+   GLuint width0, height0, depth0;
+
+   /* On validation any active images held in main memory or in other
+    * textures will be copied to this texture and the old storage freed.
+    */
+   struct pipe_resource *pt;
+
+   /* Default sampler view attached to this texture object. Created lazily
+    * on first binding.
+    */
+   struct pipe_sampler_view *sampler_view;
+
+   /* True if there is/was a surface bound to this texture object.  It helps
+    * track whether the texture object is surface based or not.
+    */
+   GLboolean surface_based;
+};
+
+
+static INLINE struct st_texture_image *
+st_texture_image(struct gl_texture_image *img)
+{
+   return (struct st_texture_image *) img;
+}
+
+static INLINE struct st_texture_object *
+st_texture_object(struct gl_texture_object *obj)
+{
+   return (struct st_texture_object *) obj;
+}
+
+
+static INLINE struct pipe_resource *
+st_get_texobj_resource(struct gl_texture_object *texObj)
+{
+   struct st_texture_object *stObj = st_texture_object(texObj);
+   return stObj ? stObj->pt : NULL;
+}
+
+
+static INLINE struct pipe_resource *
+st_get_stobj_resource(struct st_texture_object *stObj)
+{
+   return stObj ? stObj->pt : NULL;
+}
+
+
+static INLINE struct pipe_sampler_view *
+st_create_texture_sampler_view(struct pipe_context *pipe,
+                               struct pipe_resource *texture)
+{
+   struct pipe_sampler_view templ;
+
+   u_sampler_view_default_template(&templ, texture, texture->format);
+
+   return pipe->create_sampler_view(pipe, texture, &templ);
+}
+
+
+static INLINE struct pipe_sampler_view *
+st_create_texture_sampler_view_format(struct pipe_context *pipe,
+                                      struct pipe_resource *texture,
+                                      enum pipe_format format)
+{
+   struct pipe_sampler_view templ;
+
+   u_sampler_view_default_template(&templ, texture, format);
+
+   return pipe->create_sampler_view(pipe, texture, &templ);
+}
+
+
+static INLINE struct pipe_sampler_view *
+st_get_texture_sampler_view(struct st_texture_object *stObj,
+                            struct pipe_context *pipe)
+{
+   if (!stObj || !stObj->pt) {
+      return NULL;
+   }
+
+   if (!stObj->sampler_view) {
+      stObj->sampler_view = st_create_texture_sampler_view(pipe, stObj->pt);
+   }
+
+   return stObj->sampler_view;
+}
+
+
+extern struct pipe_resource *
+st_texture_create(struct st_context *st,
+                  enum pipe_texture_target target,
+		  enum pipe_format format,
+                  GLuint last_level,
+                  GLuint width0,
+                  GLuint height0,
+                  GLuint depth0,
+                  GLuint layers,
+                  GLuint tex_usage );
+
+
+extern void
+st_gl_texture_dims_to_pipe_dims(GLenum texture,
+                                GLuint widthIn,
+                                GLuint heightIn,
+                                GLuint depthIn,
+                                GLuint *widthOut,
+                                GLuint *heightOut,
+                                GLuint *depthOut,
+                                GLuint *layersOut);
+
+/* Check if an image fits into an existing texture object.
+ */
+extern GLboolean
+st_texture_match_image(const struct pipe_resource *pt,
+                       const struct gl_texture_image *image,
+                       GLuint face, GLuint level);
+
+/* Return a pointer to an image within a texture.  Return image stride as
+ * well.
+ */
+extern GLubyte *
+st_texture_image_map(struct st_context *st,
+                     struct st_texture_image *stImage,
+		     GLuint zoffset,
+                     enum pipe_transfer_usage usage,
+                     unsigned x, unsigned y,
+                     unsigned w, unsigned h);
+
+extern void
+st_texture_image_unmap(struct st_context *st,
+                       struct st_texture_image *stImage);
+
+
+/* Return pointers to each 2d slice within an image.  Indexed by depth
+ * value.
+ */
+extern const GLuint *
+st_texture_depth_offsets(struct pipe_resource *pt, GLuint level);
+
+
+/* Upload an image into a texture
+ */
+extern void
+st_texture_image_data(struct st_context *st,
+                      struct pipe_resource *dst,
+                      GLuint face, GLuint level, void *src,
+                      GLuint src_row_pitch, GLuint src_image_pitch);
+
+
+/* Copy an image between two textures
+ */
+extern void
+st_texture_image_copy(struct pipe_context *pipe,
+                      struct pipe_resource *dst, GLuint dstLevel,
+                      struct pipe_resource *src, GLuint srcLevel,
+                      GLuint face);
+
+#endif
-- 
cgit v1.2.3