Merge branch 'ext-provoking-vertex'
[profile/ivi/mesa.git] / src / mesa / main / extensions.c
index c5695f8..9655259 100644 (file)
@@ -1,8 +1,9 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.3
+ * 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"),
@@ -44,6 +45,7 @@ static const struct {
    const char *name;
    int flag_offset;
 } default_extensions[] = {
+   { OFF, "GL_ARB_copy_buffer",                F(ARB_copy_buffer) },
    { OFF, "GL_ARB_depth_texture",              F(ARB_depth_texture) },
    { ON,  "GL_ARB_draw_buffers",               F(ARB_draw_buffers) },
    { OFF, "GL_ARB_fragment_program",           F(ARB_fragment_program) },
@@ -52,6 +54,7 @@ static const struct {
    { OFF, "GL_ARB_framebuffer_object",         F(ARB_framebuffer_object) },
    { OFF, "GL_ARB_half_float_pixel",           F(ARB_half_float_pixel) },
    { OFF, "GL_ARB_imaging",                    F(ARB_imaging) },
+   { OFF, "GL_ARB_map_buffer_range",           F(ARB_map_buffer_range) },
    { ON,  "GL_ARB_multisample",                F(ARB_multisample) },
    { OFF, "GL_ARB_multitexture",               F(ARB_multitexture) },
    { OFF, "GL_ARB_occlusion_query",            F(ARB_occlusion_query) },
@@ -184,6 +187,7 @@ static const struct {
 void
 _mesa_enable_sw_extensions(GLcontext *ctx)
 {
+   ctx->Extensions.ARB_copy_buffer = GL_TRUE;
    ctx->Extensions.ARB_depth_texture = GL_TRUE;
    /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
 #if FEATURE_ARB_fragment_program
@@ -198,6 +202,7 @@ _mesa_enable_sw_extensions(GLcontext *ctx)
 #endif
    ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
    ctx->Extensions.ARB_imaging = GL_TRUE;
+   ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
    ctx->Extensions.ARB_multitexture = GL_TRUE;
 #if FEATURE_ARB_occlusion_query
    ctx->Extensions.ARB_occlusion_query = GL_TRUE;
@@ -442,8 +447,9 @@ _mesa_enable_2_1_extensions(GLcontext *ctx)
 
 /**
  * Either enable or disable the named extension.
+ * \return GL_TRUE for success, GL_FALSE if invalid extension name
  */
-static void
+static GLboolean
 set_extension( GLcontext *ctx, const char *name, GLboolean state )
 {
    GLboolean *base = (GLboolean *) &ctx->Extensions;
@@ -452,7 +458,7 @@ set_extension( GLcontext *ctx, const char *name, GLboolean state )
    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;
+      return GL_FALSE;
    }
 
    for (i = 0 ; i < Elements(default_extensions) ; i++) {
@@ -461,10 +467,10 @@ set_extension( GLcontext *ctx, const char *name, GLboolean state )
             GLboolean *enabled = base + default_extensions[i].flag_offset;
             *enabled = state;
          }
-         return;
+         return GL_TRUE;
       }
    }
-   _mesa_problem(ctx, "Trying to enable unknown extension: %s", name);
+   return GL_FALSE;
 }
 
 
@@ -475,7 +481,8 @@ set_extension( GLcontext *ctx, const char *name, GLboolean state )
 void
 _mesa_enable_extension( GLcontext *ctx, const char *name )
 {
-   set_extension(ctx, name, GL_TRUE);
+   if (!set_extension(ctx, name, GL_TRUE))
+      _mesa_problem(ctx, "Trying to enable unknown extension: %s", name);
 }
 
 
@@ -486,7 +493,8 @@ _mesa_enable_extension( GLcontext *ctx, const char *name )
 void
 _mesa_disable_extension( GLcontext *ctx, const char *name )
 {
-   set_extension(ctx, name, GL_FALSE);
+   if (!set_extension(ctx, name, GL_FALSE))
+      _mesa_problem(ctx, "Trying to disable unknown extension: %s", name);
 }
 
 
@@ -511,6 +519,80 @@ _mesa_extension_is_enabled( GLcontext *ctx, const char *name )
 
 
 /**
+ * Append string 'b' onto string 'a'.  Free 'a' and return new string.
+ */
+static char *
+append(const char *a, const char *b)
+{
+   const GLuint aLen = a ? _mesa_strlen(a) : 0;
+   const GLuint bLen = b ? _mesa_strlen(b) : 0;
+   char *s = _mesa_calloc(aLen + bLen + 1);
+   if (s) {
+      if (a)
+         _mesa_memcpy(s, a, aLen);
+      if (b)
+         _mesa_memcpy(s + aLen, b, bLen);
+      s[aLen + bLen] = '\0';
+   }
+   if (a)
+      _mesa_free((void *) a);
+   return s;
+}
+
+
+/**
+ * Check the MESA_EXTENSION_OVERRIDE env var.
+ * For extension names that are recognized, turn them on.  For extension
+ * names that are recognized and prefixed with '-', turn them off.
+ * Return a string of the unknown/leftover names.
+ */
+static const char *
+get_extension_override( GLcontext *ctx )
+{
+   const char *envExt = _mesa_getenv("MESA_EXTENSION_OVERRIDE");
+   char *extraExt = NULL;
+   char ext[1000];
+   GLuint extLen = 0;
+   GLuint i;
+   GLboolean disableExt = GL_FALSE;
+
+   if (!envExt)
+      return NULL;
+
+   for (i = 0; ; i++) {
+      if (envExt[i] == '\0' || envExt[i] == ' ') {
+         /* terminate/process 'ext' if extLen > 0 */
+         if (extLen > 0) {
+            assert(extLen < sizeof(ext));
+            /* enable extension named by 'ext' */
+            ext[extLen] = 0;
+            if (!set_extension(ctx, ext, !disableExt)) {
+               /* unknown extension name, append it to extraExt */
+               if (extraExt) {
+                  extraExt = append(extraExt, " ");
+               }
+               extraExt = append(extraExt, ext);
+            }
+            extLen = 0;
+            disableExt = GL_FALSE;
+         }
+         if (envExt[i] == '\0')
+            break;
+      }
+      else if (envExt[i] == '-') {
+         disableExt = GL_TRUE;
+      }
+      else {
+         /* accumulate this non-space character */
+         ext[extLen++] = envExt[i];
+      }
+   }
+
+   return extraExt;
+}
+
+
+/**
  * Run through the default_extensions array above and set the
  * ctx->Extensions.ARB/EXT_* flags accordingly.
  * To be called during context initialization.
@@ -538,8 +620,9 @@ GLubyte *
 _mesa_make_extension_string( GLcontext *ctx )
 {
    const GLboolean *base = (const GLboolean *) &ctx->Extensions;
+   const char *extraExt = get_extension_override(ctx);
    GLuint extStrLen = 0;
-   GLubyte *s;
+   char *s;
    GLuint i;
 
    /* first, compute length of the extension string */
@@ -549,7 +632,14 @@ _mesa_make_extension_string( GLcontext *ctx )
          extStrLen += (GLuint)_mesa_strlen(default_extensions[i].name) + 1;
       }
    }
-   s = (GLubyte *) _mesa_malloc(extStrLen);
+
+   if (extraExt)
+      extStrLen += _mesa_strlen(extraExt) + 1; /* +1 for space */
+
+   /* allocate the extension string */
+   s = (char *) _mesa_malloc(extStrLen);
+   if (!s)
+      return NULL;
 
    /* second, build the extension string */
    extStrLen = 0;
@@ -559,13 +649,18 @@ _mesa_make_extension_string( GLcontext *ctx )
          GLuint len = (GLuint)_mesa_strlen(default_extensions[i].name);
          _mesa_memcpy(s + extStrLen, default_extensions[i].name, len);
          extStrLen += len;
-         s[extStrLen] = (GLubyte) ' ';
+         s[extStrLen] = ' ';
          extStrLen++;
       }
    }
    ASSERT(extStrLen > 0);
 
-   s[extStrLen - 1] = 0;
+   s[extStrLen - 1] = 0; /* -1 to overwrite trailing the ' ' */
 
-   return s;
+   if (extraExt) {
+      s = append(s, " ");
+      s = append(s, extraExt);
+   }
+
+   return (GLubyte *) s;
 }