Commit ea88d663 authored by Jordan Justen's avatar Jordan Justen

piglit gl: convert gl extension checking to use an array of strings

This better matches the interface of glGetStringi, which should be used
for GL >= 3.0.
Signed-off-by: Jordan Justen's avatarJordan Justen <jordan.l.justen@intel.com>
Reviewed-by: default avatarChad Versace <chad.versace@linux.intel.com>
parent f288f2cc
...@@ -26,13 +26,13 @@ ...@@ -26,13 +26,13 @@
/** /**
* The GL extension string returned by glGetString(GL_EXTENSIONS). * An array of pointers to extension strings.
* *
* We cache this here because calling glGetString is prohibited * Each extension is pointed to by a separate entry in the array.
* between glBegin and glEnd, and to avoid the inefficiency of *
* redundant glGetString queries. * The end of the array is indicated by a NULL pointer.
*/ */
static const char *gl_extensions = NULL; static const char **gl_extensions = NULL;
bool piglit_is_gles() bool piglit_is_gles()
{ {
...@@ -62,13 +62,47 @@ int piglit_get_gl_version() ...@@ -62,13 +62,47 @@ int piglit_get_gl_version()
return 10*major+minor; return 10*major+minor;
} }
bool piglit_is_extension_supported(const char *name) static const char** split_string(const char *string)
{
char **strings, *string_copy;
int i, length, max_words;
length = strlen(string);
max_words = length / 2;
strings = malloc ((sizeof(char*) * (max_words + 1)) +
(sizeof(char) * (length + 1)));
assert (strings != NULL);
string_copy = (char*) &strings[max_words + 1];
strcpy(string_copy, string);
strings[0] = strtok(string_copy, " ");
for (i = 0; strings[i] != NULL; ++i)
strings[i + 1] = strtok(NULL, " ");
return (const char**) strings;
}
static const char** gl_extension_array_from_getstring()
{
const char *gl_extensions_string;
gl_extensions_string = (const char *) glGetString(GL_EXTENSIONS);
return split_string(gl_extensions_string);
}
static void initialize_piglit_extension_support(void)
{ {
if (gl_extensions == NULL) { if (gl_extensions != NULL) {
gl_extensions = (const char *) glGetString(GL_EXTENSIONS); return;
} }
return piglit_is_extension_in_string(gl_extensions, name); gl_extensions = gl_extension_array_from_getstring();
}
bool piglit_is_extension_supported(const char *name)
{
initialize_piglit_extension_support();
return piglit_is_extension_in_array(gl_extensions, name);
} }
void piglit_require_gl_version(int required_version_times_10) void piglit_require_gl_version(int required_version_times_10)
......
...@@ -101,6 +101,21 @@ int asprintf(char **strp, const char *fmt, ...) ...@@ -101,6 +101,21 @@ int asprintf(char **strp, const char *fmt, ...)
#endif /* _WIN32 */ #endif /* _WIN32 */
bool piglit_is_extension_in_array(const char **haystack, const char *needle)
{
if (needle[0] == 0)
return false;
while (*haystack != NULL) {
if (strcmp(*haystack, needle) == 0) {
return true;
}
haystack++;
}
return false;
}
bool piglit_is_extension_in_string(const char *haystack, const char *needle) bool piglit_is_extension_in_string(const char *haystack, const char *needle)
{ {
const unsigned needle_len = strlen(needle); const unsigned needle_len = strlen(needle);
......
...@@ -119,6 +119,18 @@ enum piglit_result { ...@@ -119,6 +119,18 @@ enum piglit_result {
*/ */
bool piglit_is_extension_in_string(const char *haystack, const char *needle); bool piglit_is_extension_in_string(const char *haystack, const char *needle);
/**
* Determine if an extension is listed in an extension string array
*
* \param haystack Array of all extensions to be searched
* \param needle Extension whose presens is to be detected
*
* \precondition \c haystack is not null
*
* \sa piglit_is_extension_supported, piglit_is_glx_extension_supported
*/
bool piglit_is_extension_in_array(const char **haystack, const char *needle);
int FindLine(const char *program, int position); int FindLine(const char *program, int position);
void piglit_merge_result(enum piglit_result *all, enum piglit_result subtest); void piglit_merge_result(enum piglit_result *all, enum piglit_result subtest);
void piglit_report_result(enum piglit_result result); void piglit_report_result(enum piglit_result result);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment