/** * 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; /* Number of extensions */ unsigned count; /* Indices of the extensions sorted by year */ extension_index *extension_indices; /* String of extra extensions. */ char *extra_extensions = get_extension_override(ctx); GLboolean *base = (GLboolean *) &ctx->Extensions; const struct extension *i; unsigned j; unsigned maxYear = ~0; unsigned api_set = (1 << ctx->API); if (_mesa_is_gles3(ctx)) api_set |= ES3; /* Check if the MESA_EXTENSION_MAX_YEAR env var is set */ { const char *env = getenv("MESA_EXTENSION_MAX_YEAR"); if (env) { maxYear = atoi(env); _mesa_debug(ctx, "Note: limiting GL extensions to %u or earlier\n", maxYear); } } /* Compute length of the extension string. */ count = 0; for (i = extension_table; i->name != 0; ++i) { if (base[i->offset] && i->year <= maxYear && (i->api_set & api_set)) { length += strlen(i->name) + 1; /* +1 for space */ ++count; } } if (extra_extensions != NULL) length += 1 + strlen(extra_extensions); /* +1 for space */ exts = calloc(ALIGN(length + 1, 4), sizeof(char)); if (exts == NULL) { free(extra_extensions); return NULL; } extension_indices = malloc(count * sizeof(extension_index)); if (extension_indices == NULL) { free(exts); free(extra_extensions); return NULL; } /* Sort extensions in chronological order because certain old applications (e.g., * Quake3 demo) store the extension list in a static size buffer so chronologically * order ensure that the extensions that such applications expect will fit into * that buffer. */ j = 0; for (i = extension_table; i->name != 0; ++i) { if (base[i->offset] && i->year <= maxYear && (i->api_set & api_set)) { extension_indices[j++] = i - extension_table; } } assert(j == count); qsort(extension_indices, count, sizeof *extension_indices, extension_compare); /* Build the extension string.*/ for (j = 0; j < count; ++j) { i = &extension_table[extension_indices[j]]; assert(base[i->offset] && (i->api_set & api_set)); strcat(exts, i->name); strcat(exts, " "); } free(extension_indices); if (extra_extensions != 0) { strcat(exts, extra_extensions); free(extra_extensions); } return (GLubyte *) exts; }
/** * 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; /* Number of extensions */ unsigned count; /* Indices of the extensions sorted by year */ extension_index *extension_indices; /* String of extra extensions. */ char *extra_extensions = get_extension_override(ctx); unsigned k; unsigned j; unsigned maxYear = ~0; /* Check if the MESA_EXTENSION_MAX_YEAR env var is set */ { const char *env = getenv("MESA_EXTENSION_MAX_YEAR"); if (env) { maxYear = atoi(env); _mesa_debug(ctx, "Note: limiting GL extensions to %u or earlier\n", maxYear); } } /* Compute length of the extension string. */ count = 0; for (k = 0; k < MESA_EXTENSION_COUNT; ++k) { const struct mesa_extension *i = _mesa_extension_table + k; if (i->year <= maxYear && _mesa_extension_supported(ctx, k)) { length += strlen(i->name) + 1; /* +1 for space */ ++count; } } if (extra_extensions != NULL) length += 1 + strlen(extra_extensions); /* +1 for space */ exts = calloc(ALIGN(length + 1, 4), sizeof(char)); if (exts == NULL) { free(extra_extensions); return NULL; } extension_indices = malloc(count * sizeof(extension_index)); if (extension_indices == NULL) { free(exts); free(extra_extensions); return NULL; } /* Sort extensions in chronological order because certain old applications * (e.g., Quake3 demo) store the extension list in a static size buffer so * chronologically order ensure that the extensions that such applications * expect will fit into that buffer. */ 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]]; assert(_mesa_extension_supported(ctx, extension_indices[j])); strcat(exts, i->name); strcat(exts, " "); } free(extension_indices); if (extra_extensions != 0) { strcat(exts, extra_extensions); free(extra_extensions); } return (GLubyte *) exts; }