[Piglit] [PATCH] primitive-restart: test glArrayElement
Brian Paul
brian.e.paul at gmail.com
Tue May 1 15:36:18 PDT 2012
On Tue, May 1, 2012 at 9:50 AM, Jordan Justen <jordan.l.justen at intel.com> wrote:
> This change expands the function previously named
> test_draw_elements to support testing primitive restart with
> the glArrayElement function.
>
> All the tests previously run in test_draw_elements
> are now repeated using glArrayElement.
>
> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
> ---
> tests/general/primitive-restart.c | 96 ++++++++++++++++++++++++++++++-------
> 1 files changed, 78 insertions(+), 18 deletions(-)
>
> diff --git a/tests/general/primitive-restart.c b/tests/general/primitive-restart.c
> index ceb9d6e..fee1578 100644
> --- a/tests/general/primitive-restart.c
> +++ b/tests/general/primitive-restart.c
> @@ -184,11 +184,41 @@ disable_restart(void)
> }
>
>
> +static void draw_all_indices(GLboolean one_by_one,
> + GLenum mode, GLsizei count,
> + GLenum type, const GLvoid *indices)
> +{
> + GLuint index;
> +
> + if (one_by_one) {
> + glBegin(mode);
> + for (index = 0; index < count; index++) {
> + switch (type) {
> + case GL_UNSIGNED_BYTE:
> + glArrayElement(((GLubyte*)indices)[index]);
> + break;
> + case GL_UNSIGNED_SHORT:
> + glArrayElement(((GLushort*)indices)[index]);
> + break;
> + case GL_UNSIGNED_INT:
> + glArrayElement(((GLuint*)indices)[index]);
> + break;
> + default:
> + assert(0);
> + }
> + }
> + glEnd();
> + } else {
> + glDrawElements(mode, count, type, indices);
> + }
> +}
> +
> +
> /**
> * Test glDrawElements() with glPrimitiveRestartIndexNV().
> */
> static GLboolean
> -test_draw_elements(GLenum primMode, GLenum indexType)
> +test_draw_by_index2(GLboolean one_by_one, GLenum primMode, GLenum indexType)
> {
> #define NUM_VERTS 48
> #define NUM_ELEMS (NUM_VERTS * 5 / 4)
> @@ -295,7 +325,7 @@ test_draw_elements(GLenum primMode, GLenum indexType)
> int i;
> for (i = 0; i < num_elems; i++)
> ub_elements[i] = (GLubyte) elements[i];
> - glDrawElements(primMode, num_elems, GL_UNSIGNED_BYTE, ub_elements);
> + draw_all_indices(one_by_one, primMode, num_elems, GL_UNSIGNED_BYTE, ub_elements);
> }
> break;
> case GL_UNSIGNED_SHORT:
> @@ -304,11 +334,11 @@ test_draw_elements(GLenum primMode, GLenum indexType)
> int i;
> for (i = 0; i < num_elems; i++)
> us_elements[i] = (GLushort) elements[i];
> - glDrawElements(primMode, num_elems, GL_UNSIGNED_SHORT, us_elements);
> + draw_all_indices(one_by_one, primMode, num_elems, GL_UNSIGNED_SHORT, us_elements);
> }
> break;
> case GL_UNSIGNED_INT:
> - glDrawElements(primMode, num_elems, GL_UNSIGNED_INT, elements);
> + draw_all_indices(one_by_one, primMode, num_elems, GL_UNSIGNED_INT, elements);
> break;
> default:
> assert(0);
> @@ -319,8 +349,10 @@ test_draw_elements(GLenum primMode, GLenum indexType)
>
> pass = check_rendering();
> if (!pass) {
> - fprintf(stderr, "%s: failure drawing with glDrawElements(%s, %s)\n",
> - TestName, primStr, typeStr);
> + fprintf(stderr, "%s: failure drawing with %s(%s, %s)\n",
> + TestName,
> + one_by_one ? "glArrayElement" : "glDrawElements",
> + primStr, typeStr);
> }
>
> piglit_present_results();
> @@ -330,6 +362,42 @@ test_draw_elements(GLenum primMode, GLenum indexType)
> }
>
>
> +static GLboolean
> +test_draw_by_index(GLboolean one_by_one)
> +{
> + GLboolean pass = GL_TRUE;
> +
> + pass = pass && test_draw_by_index2(one_by_one, GL_TRIANGLE_STRIP, GL_UNSIGNED_BYTE);
> + pass = pass && test_draw_by_index2(one_by_one, GL_TRIANGLE_STRIP, GL_UNSIGNED_SHORT);
> + pass = pass && test_draw_by_index2(one_by_one, GL_TRIANGLE_STRIP, GL_UNSIGNED_INT);
> + pass = pass && test_draw_by_index2(one_by_one, GL_LINE_STRIP, GL_UNSIGNED_BYTE);
> + pass = pass && test_draw_by_index2(one_by_one, GL_LINE_STRIP, GL_UNSIGNED_SHORT);
> + pass = pass && test_draw_by_index2(one_by_one, GL_LINE_STRIP, GL_UNSIGNED_INT);
> +
> + return pass;
> +}
> +
> +
> +/**
> + * Test glDrawElements() with glPrimitiveRestartIndexNV().
> + */
> +static GLboolean
> +test_draw_elements(void)
> +{
> + return test_draw_by_index(GL_FALSE);
> +}
> +
> +
> +/**
> + * Test glArrayElement() with glPrimitiveRestartIndexNV().
> + */
> +static GLboolean
> +test_array_element(void)
> +{
> + return test_draw_by_index(GL_TRUE);
> +}
> +
> +
> /**
> * Test glDrawArrayss() with glPrimitiveRestartIndexNV().
> * We only test a line strip.
> @@ -446,23 +514,15 @@ piglit_display(void)
> TestGL31 = GL_FALSE;
> pass = pass && test_begin_end(GL_TRIANGLE_STRIP);
> pass = pass && test_begin_end(GL_LINE_STRIP);
> - pass = pass && test_draw_elements(GL_TRIANGLE_STRIP, GL_UNSIGNED_BYTE);
> - pass = pass && test_draw_elements(GL_TRIANGLE_STRIP, GL_UNSIGNED_SHORT);
> - pass = pass && test_draw_elements(GL_TRIANGLE_STRIP, GL_UNSIGNED_INT);
> - pass = pass && test_draw_elements(GL_LINE_STRIP, GL_UNSIGNED_BYTE);
> - pass = pass && test_draw_elements(GL_LINE_STRIP, GL_UNSIGNED_SHORT);
> - pass = pass && test_draw_elements(GL_LINE_STRIP, GL_UNSIGNED_INT);
> + pass = pass && test_draw_elements();
> + pass = pass && test_array_element();
> pass = pass && test_draw_arrays();
> }
>
> if (Have_31) {
> TestGL31 = GL_TRUE;
> - pass = pass && test_draw_elements(GL_TRIANGLE_STRIP, GL_UNSIGNED_BYTE);
> - pass = pass && test_draw_elements(GL_TRIANGLE_STRIP, GL_UNSIGNED_SHORT);
> - pass = pass && test_draw_elements(GL_TRIANGLE_STRIP, GL_UNSIGNED_INT);
> - pass = pass && test_draw_elements(GL_LINE_STRIP, GL_UNSIGNED_BYTE);
> - pass = pass && test_draw_elements(GL_LINE_STRIP, GL_UNSIGNED_SHORT);
> - pass = pass && test_draw_elements(GL_LINE_STRIP, GL_UNSIGNED_INT);
> + pass = pass && test_draw_elements();
> + pass = pass && test_array_element();
> pass = pass && test_draw_arrays();
> }
I think I'd like to see this structured a little differently. I'd
rather see new lines like:
pass = pass && test_array_element(GL_TRIANGLE_STRIP, GL_UNSIGNED_BYTE);
etc...
Yes, it's more verbose but it's much easier to hack the test to only
draw in a single mode when we have to debug/fix a particular failing
case.
-Brian
More information about the Piglit
mailing list