On 8 October 2011 06:49, Brian Paul <span dir="ltr">&lt;<a href="mailto:brian.e.paul@gmail.com" target="_blank">brian.e.paul@gmail.com</a>&gt;</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">

<div>On Fri, Oct 7, 2011 at 6:28 PM, Paul Berry &lt;<a href="mailto:stereotype441@gmail.com" target="_blank">stereotype441@gmail.com</a>&gt; wrote:<br>
&gt; ---<br>
&gt;  tests/util/piglit-util.c |   12 ++++++++++++<br>
&gt;  tests/util/piglit-util.h |    1 +<br>
&gt;  2 files changed, 13 insertions(+), 0 deletions(-)<br>
&gt;<br>
&gt; diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c<br>
&gt; index 358b0dc..b8a0219 100644<br>
&gt; --- a/tests/util/piglit-util.c<br>
&gt; +++ b/tests/util/piglit-util.c<br>
&gt; @@ -108,6 +108,18 @@ bool piglit_is_extension_supported(const char *name)<br>
&gt;        return found;<br>
&gt;  }<br>
&gt;<br>
&gt; +void piglit_require_GL_version(double required_version)<br>
&gt; +{<br>
&gt; +       double gl_version = strtod((char *) glGetString(GL_VERSION), NULL);<br>
<br>
</div>I don&#39;t think we can use strtod().  The OpenGL version string always<br>
uses &#39;.&#39; while strtod()&#39;s decimal point character is local-dependent.<br>
<br>
I think we could get by with something like<br>
<br>
const GLUbyte *verStr =  glGetString(GL_VERSION);<br>
int version = verStr[0] * 10 + verStr[2];<br></blockquote><div><br>Hmm, I did not think of this.  (...goes and learns a lot about locales...)<br><br>It turns out that my version works ok even if the computer&#39;s default locale uses &#39;,&#39; as the decimal separator, because the computer&#39;s default locale doesn&#39;t take effect until you call setlocale(LC_ALL, &quot;&quot;), which Piglit doesn&#39;t do.  Until then you&#39;re always in the &quot;C&quot; locale, which uses &#39;.&#39; as the decimal separator (see <a href="http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_19.html#SEC323" target="_blank">http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_19.html#SEC323</a>).<br>
<br>However, I still like your version better, because (a) you don&#39;t have to research locales to see why it works, and (b) it neatly avoids any issues with rounding errors.  So I&#39;m going to go with it.<br><br>Incidentally, while investigating this stuff I discovered that a lot of the glean tests don&#39;t use &quot;&gt;=&quot; for their version comparisons where they should.  For example, in tshaderapi.cpp, we have this:<br>
<br>    const char *version = (const char *) glGetString(GL_VERSION);<br>    if (strncmp(version, &quot;2.0&quot;, 3) == 0 ||<br>        strncmp(version, &quot;2.1&quot;, 3) == 0 ||<br>        strncmp(version, &quot;3.0&quot;, 3) == 0) {<br>
        return true;<br>    }<br>    else {<br>        env-&gt;log &lt;&lt; name<br>                 &lt;&lt; &quot;:  skipped.  Requires GL 2.0, 2.1 or 3.0.\n&quot;;<br>        return false;<br>    }<br><br>Which means that the &quot;shaderapi&quot; test gets skipped on a GL implementation that advertises support for GL version 3.1 or newer.  Worse yet, since the test doesn&#39;t use the standard piglit mechanism to report that it&#39;s skipping, this shows up in the Piglit results as a &quot;pass&quot;.  Really this code should be replaced with:<br>
<br>    piglit_require_GL_version(20);<br><br>(taking your suggestion of using an integer to represent ten times the version rather than a floating-point value).<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<br>
BTW, I think a pigilt_get_gl_version() function would be useful too.<br>
<div><div></div><div><br></div></div></blockquote><div><br>It turns out that Piglit already has such a function (I didn&#39;t realize this either until this morning):<br><br>    void piglit_get_gl_version(bool *es, int* major, int* minor);<br>
<br>But this type signature is horrible because it means if you want to compare version numbers you have to jump through hoops:<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(&amp;es, &amp;major, &amp;minor);<br>    if (es &amp;&amp; (major &gt; 3 || (major == 3 &amp;&amp; minor &gt;= 1)))<br><br>I would far rather change this to:<br><br>    bool piglit_is_gles();<br>
    int piglit_get_gl_version(); /* returns 10*major + minor */<br><br>So we could do this:<br><br>    if (piglit_is_gles() &amp;&amp; piglit_get_gl_version() &gt;= 31)<br><br>Fortunately piglit_get_gl_version() is only called from one place right now, so this should be easy to change.<br>
<br><br><br>I&#39;ll go ahead and fold your suggestions on piglit_require_GL_version() into this patch.  I&#39;ll submit a separate patch series to fix the problems with piglit_get_gl_version() and the glean tests.<br><br>
Paul<br>
</div></div>