mesa: Add missing include guards
[mesa.git] / src / mesa / main / extensions.c
index 376ea8d4f2aeb995423c48c3741c3e43fee2353b..4d95a072793fa4c13b69eb12b00c383fbb370b9f 100644 (file)
@@ -129,9 +129,7 @@ _mesa_enable_sw_extensions(struct gl_context *ctx)
    ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
    ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
    ctx->Extensions.ARB_texture_filter_anisotropic = GL_TRUE;
-#ifdef TEXTURE_FLOAT_ENABLED
    ctx->Extensions.ARB_texture_float = GL_TRUE;
-#endif
    ctx->Extensions.ARB_texture_mirror_clamp_to_edge = GL_TRUE;
    ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
    ctx->Extensions.ARB_texture_rg = GL_TRUE;
@@ -144,7 +142,6 @@ _mesa_enable_sw_extensions(struct gl_context *ctx)
    ctx->Extensions.ATI_texture_compression_3dc = GL_TRUE;
    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;
@@ -338,6 +335,30 @@ _mesa_extension_supported(const struct gl_context *ctx, extension_index i)
    return (ctx->Version >= ext->version[ctx->API]) && base[ext->offset];
 }
 
+/**
+ * Compare two entries of the extensions table.  Sorts first by year,
+ * then by name.
+ *
+ * Arguments are indices into _mesa_extension_table.
+ */
+static int
+extension_compare(const void *p1, const void *p2)
+{
+   extension_index i1 = * (const extension_index *) p1;
+   extension_index i2 = * (const extension_index *) p2;
+   const struct mesa_extension *e1 = &_mesa_extension_table[i1];
+   const struct mesa_extension *e2 = &_mesa_extension_table[i2];
+   int res;
+
+   res = (int)e1->year - (int)e2->year;
+
+   if (res == 0) {
+      res = strcmp(e1->name, e2->name);
+   }
+
+   return res;
+}
+
 
 /**
  * Construct the GL_EXTENSIONS string.  Called the first time that
@@ -375,8 +396,8 @@ _mesa_make_extension_string(struct gl_context *ctx)
 
       if (i->year <= maxYear &&
           _mesa_extension_supported(ctx, k)) {
-         length += strlen(i->name) + 1; /* +1 for space */
-         extension_indices[count++] = k;
+        length += strlen(i->name) + 1; /* +1 for space */
+        ++count;
       }
    }
    for (k = 0; k < MAX_UNRECOGNIZED_EXTENSIONS; k++)
@@ -388,6 +409,24 @@ _mesa_make_extension_string(struct gl_context *ctx)
       return NULL;
    }
 
+   /* Sort extensions in chronological order because idTech 2/3 games
+    * (e.g., Quake3 demo) store the extension list in a fixed size buffer.
+    * Some cases truncate, while others overflow the buffer. Resulting in
+    * misrendering and crashes, respectively.
+    * Address the former here, while the latter will be addressed by setting
+    * the MESA_EXTENSION_MAX_YEAR environment variable.
+    */
+   j = 0;
+   for (k = 0; k < MESA_EXTENSION_COUNT; ++k) {
+      if (_mesa_extension_table[k].year <= maxYear &&
+         _mesa_extension_supported(ctx, k)) {
+         extension_indices[j++] = k;
+      }
+   }
+   assert(j == count);
+   qsort(extension_indices, count,
+         sizeof *extension_indices, extension_compare);
+
    /* Build the extension string.*/
    for (j = 0; j < count; ++j) {
       const struct mesa_extension *i = &_mesa_extension_table[extension_indices[j]];
@@ -421,6 +460,11 @@ _mesa_get_extension_count(struct gl_context *ctx)
       if (_mesa_extension_supported(ctx, k))
         ctx->Extensions.Count++;
    }
+
+   for (k = 0; k < MAX_UNRECOGNIZED_EXTENSIONS; ++k) {
+      if (ctx->Extensions.unrecognized_extensions[k])
+        ctx->Extensions.Count++;
+   }
    return ctx->Extensions.Count;
 }
 
@@ -442,5 +486,13 @@ _mesa_get_enabled_extension(struct gl_context *ctx, GLuint index)
       }
    }
 
+   for (i = 0; i < MAX_UNRECOGNIZED_EXTENSIONS; ++i) {
+      if (ctx->Extensions.unrecognized_extensions[i]) {
+         if (n == index)
+            return (const GLubyte*) ctx->Extensions.unrecognized_extensions[i];
+         else
+            ++n;
+      }
+   }
    return NULL;
 }