On 13 October 2011 13:45, Paul Berry <span dir="ltr"><<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Previously, piglit_get_gl_version() had three return values: the GL<br>
version (major and minor version numbers separately) and a boolean<br>
indicating whether or not the API is GL ES. This meant that we had to<br>
jump through hoops in order to use it, e.g.:<br>
<br>
/* Are we using GL with a version of at least 3.1? */<br>
bool es;<br>
int major;<br>
int minor;<br>
piglit_get_gl_version(&es, &major, &minor);<br>
if (!es && (major > 3 || (major == 3 && minor >= 1)))<br>
...<br>
<br>
This patch changes piglit_get_gl_version() so that it returns a single<br>
integer whose value is 10 times the GL version (e.g. 31 for GL version<br>
3.1), and splits off the functionality for checking whether the API is<br>
GL ES to a new function, piglit_is_gles().<br>
<br>
Now the same logic looks like this:<br>
<br>
/* Are we using GL with a version of at least 3.1? */<br>
if (!piglit_is_gles() && piglit_get_gl_version() >= 31)<br>
...<br>
---<br>
tests/glslparsertest/glslparsertest.c | 10 +++---<br>
tests/util/piglit-util.c | 53 +++++++++++++++-----------------<br>
tests/util/piglit-util.h | 14 +++++---<br>
3 files changed, 39 insertions(+), 38 deletions(-)<br>
<br>
diff --git a/tests/glslparsertest/glslparsertest.c b/tests/glslparsertest/glslparsertest.c<br>
index cfe8d10..b7a2dc9 100644<br>
--- a/tests/glslparsertest/glslparsertest.c<br>
+++ b/tests/glslparsertest/glslparsertest.c<br>
@@ -41,7 +41,7 @@<br>
<br>
static char *filename;<br>
static int expected_pass;<br>
-static int gl_major_version = 0;<br>
+static int gl_version_times_10 = 0;<br>
static int check_link = 0;<br>
static float requested_version = 1.10;<br>
<br>
@@ -51,7 +51,7 @@ get_shader_compile_status(GLuint shader)<br>
GLint status;<br>
<br>
#if defined USE_OPENGL<br>
- if (gl_major_version >= 2) {<br>
+ if (gl_version_times_10 >= 20) {<br>
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);<br>
} else {<br>
glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);<br>
@@ -71,7 +71,7 @@ get_shader_info_log_length(GLuint shader)<br>
GLsizei length;<br>
<br>
#if defined USE_OPENGL<br>
- if (gl_major_version >= 2) {<br>
+ if (gl_version_times_10 >= 20) {<br>
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);<br>
} else {<br>
glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);<br>
@@ -308,13 +308,13 @@ int main(int argc, char**argv)<br>
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);<br>
glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);<br>
glutCreateWindow("glslparsertest");<br>
- piglit_get_gl_version(NULL, &gl_major_version, NULL);<br>
+ gl_version_times_10 = piglit_get_gl_version();<br>
<br>
#ifdef USE_OPENGL<br>
glewInit();<br>
#endif<br>
<br>
- if (gl_major_version < 2<br>
+ if (gl_version_times_10 < 20<br>
&& !piglit_is_extension_supported("GL_ARB_shader_objects")) {<br>
printf("Requires OpenGL 2.0\n");<br>
piglit_report_result(PIGLIT_SKIP);<br>
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c<br>
index 358b0dc..026c64e 100644<br>
--- a/tests/util/piglit-util.c<br>
+++ b/tests/util/piglit-util.c<br>
@@ -56,38 +56,35 @@ void piglit_glutInit(int argc, char **argv)<br>
#endif<br>
}<br>
<br>
-void piglit_get_gl_version(bool *es, int* major, int* minor)<br>
+bool piglit_is_gles()<br>
{<br>
- /* Version of OpenGL API. */<br>
- bool es_local;<br>
- int major_local;<br>
- int minor_local;<br>
-<br>
- const char *version_string;<br>
- int c; /* scanf count */<br>
-<br>
- version_string = (const char*) glGetString(GL_VERSION);<br>
- es_local = strncmp("OpenGL ES ", version_string, 10) == 0;<br>
- if (es_local) {<br>
- c = sscanf(version_string,<br>
- "OpenGL ES %i.%i",<br>
- &major_local,<br>
- &minor_local);<br>
- } else {<br>
- c = sscanf(version_string,<br>
- "%i.%i",<br>
- &major_local,<br>
- &minor_local);<br>
+ const char *version_string = (const char *) glGetString(GL_VERSION);<br>
+ return strncmp("OpenGL ES ", version_string, 10) == 0;<br>
+}<br>
+<br>
+int piglit_get_gl_version()<br>
+{<br>
+ const char *version_string = (const char *) glGetString(GL_VERSION);<br>
+ const char *version_number_string;<br>
+ int scanf_count;<br>
+ int major;<br>
+ int minor;<br>
+<br>
+ /* skip to version number */<br>
+ if (strncmp("OpenGL ES ", version_string, 10) == 0)<br>
+ version_number_string = version_string + 10;<br>
+ else<br>
+ version_number_string = version_string;<br>
+<br>
+ /* Interpret version number */<br>
+ scanf_count = sscanf(version_string, "%i.%i", &major, &minor);<br></blockquote><div><br>Whoops, brain fail. This last "version_string" should have been "version_number_string". I didn't quite realize this in time to avoid pushing a bad patch, but I've pushed follow-up patch to correct it.<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
+ if (scanf_count != 2) {<br>
+ printf("Unable to interpret GL_VERSION string: %s\n",<br>
+ version_string);<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ exit(1);<br>
}<br>
- assert(c == 2);<br>
-<br>
- /* Write outputs. */<br>
- if (es != NULL)<br>
- *es = es_local;<br>
- if (major != NULL)<br>
- *major = major_local;<br>
- if (minor != NULL)<br>
- *minor = minor_local;<br>
+ return 10*major+minor;<br>
}<br>
<br>
bool piglit_is_extension_supported(const char *name)<br>
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h<br>
index a12a234..2a423c3 100644<br>
--- a/tests/util/piglit-util.h<br>
+++ b/tests/util/piglit-util.h<br>
@@ -100,13 +100,17 @@ extern const unsigned int fdo_bitmap_height;<br>
void piglit_glutInit(int argc, char **argv);<br>
<br>
/**<br>
- * \brief Get version of OpenGL API.<br>
- *<br>
- * Null parameters are ignored.<br>
+ * Determine if the API is OpenGL ES.<br>
+ */<br>
+bool piglit_is_gles();<br>
+<br>
+/**<br>
+ * \brief Get version of OpenGL or OpenGL ES API.<br>
*<br>
- * \param es Is the API OpenGL or OpenGL ES?<br>
+ * Returned version is multiplied by 10 to make it an integer. So for<br>
+ * example, if the GL version is 2.1, the return value is 21.<br>
*/<br>
-void piglit_get_gl_version(bool *es, int* major, int* minor);<br>
+int piglit_get_gl_version();<br>
<br>
/**<br>
* \precondition name is not null<br>
<font color="#888888">--<br>
1.7.6.4<br>
<br>
</font></blockquote></div><br>