[Piglit] [PATCH] GL-3.2 ARB_draw_elements_base_vertex: Add DrawRangeElementsBaseVertex test.

Matt Turner mattst88 at gmail.com
Tue Jul 30 14:40:54 PDT 2013


Just a bunch of nitpicky things:

On Tue, Jul 30, 2013 at 10:49 AM, Jacob Penner <jkpenner91 at gmail.com> wrote:
> DrawRangeElementsBaseVertex was added in GL-3.2, test that it functions
> properly.
> ---
>  .../CMakeLists.gl.txt                              |   2 +-
>  .../draw-range-elements-base-vertex.c              | 188 +++++++++++++++++++++
>  2 files changed, 189 insertions(+), 1 deletion(-)
>  create mode 100644 tests/spec/arb_draw_elements_base_vertex/draw-range-elements-base-vertex.c
>
> diff --git a/tests/spec/arb_draw_elements_base_vertex/CMakeLists.gl.txt b/tests/spec/arb_draw_elements_base_vertex/CMakeLists.gl.txt
> index adbba29..3a0091e 100644
> --- a/tests/spec/arb_draw_elements_base_vertex/CMakeLists.gl.txt
> +++ b/tests/spec/arb_draw_elements_base_vertex/CMakeLists.gl.txt
> @@ -11,5 +11,5 @@ link_libraries (
>
>  piglit_add_executable (draw-elements-instanced-base-vertex draw-elements-instanced-base-vertex.c)
>  piglit_add_executable (arb_draw_elements_base_vertex-dlist-arb_draw_instanced dlist-arb_draw_instanced.c)
> -
> +piglit_add_executable (draw-ranged-elements-base-vertex draw-range-elements-base-vertex.c)

Typo: ranged instead of range.

>  # vim: ft=cmake:
> diff --git a/tests/spec/arb_draw_elements_base_vertex/draw-range-elements-base-vertex.c b/tests/spec/arb_draw_elements_base_vertex/draw-range-elements-base-vertex.c
> new file mode 100644
> index 0000000..b042716
> --- /dev/null
> +++ b/tests/spec/arb_draw_elements_base_vertex/draw-range-elements-base-vertex.c
> @@ -0,0 +1,188 @@
> +/*
> + * Copyright © 2013 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + */
> +
> +/** @file draw-range-elements-base-vertex.c
> + *
> + * Section 2.8.2(Vertex Arrays) From GL spec 3.2 core:
> + * glDrawRangeElementsBaseVertex was added.
> + *
> + * For DrawRangeElementsBaseVertex, the index values must lie between start
> + * and end inclusive, prior to adding the basevertex offset. Index values
> + * lying outside the range [start, end] are treated in the same way as
> + * DrawRangeElements.
> + *
> + * It is an error for index values other than the primitive restart index
> + * to lie outside the range [start, end], but implementations are not
> + * required to check for this. Such indices will cause implementation-
> + * dependent behavior.
> + *
> + *    (0)-------(1)    Set up indices for quad 1 and 3.
> + *     |    1    |
> + *    (2)-------(3)    Use a basevertex of 2 on quad 3
> + *     |    2    |     draw call to shift quad 3 to quad 4
> + *    (4)-------(5)
> + *     |    3    |    End result quad 1 will be white and quad 2 clear color.
> + *    (6)-------(7)   If index values are compared to start and end values
> + *     |    4    |    prior to adding basevertex quad 3 will be clear color
> + *    (8)-------(9)   while 4 will be white.
> + */
> +
> +#include "piglit-util-gl-common.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +       config.supports_gl_compat_version = 10;
> +       config.supports_gl_core_version = 31;
> +
> +       config.window_width = 48;
> +       config.window_height = 48;

I think we have some kind of minimum window size (150x150) on Windows.
Cc'ing Brian to confirm what it is.

> +       config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +const char *vs_source = {
> +       "#version 130\n"
> +       "in vec2 vertex;\n"
> +       "void main() {\n"
> +       "       gl_Position = vec4(vertex.xy, 0, 1);\n"
> +       "}\n"
> +};
> +
> +const char *fs_source = {
> +       "#version 130\n"
> +       "void main() {\n"
> +       "       gl_FragColor = vec4(1,1,1,1);\n"

Spaces after commas.

> +       "}\n"
> +};
> +
> +static GLuint vao;
> +static GLuint vertexBuffer;
> +static GLuint indexBuffer;
> +
> +
> +// sets of two (x,y)

Use C-style /* */ comments here (and elsewhere).

> +static GLfloat vertices[] = {
> +       -1.0, 1.0,
> +        1.0, 1.0,
> +       -1.0, 0.5,
> +        1.0, 0.5,
> +       -1.0, 0.0,
> +        1.0, 0.0,
> +       -1.0,-0.5,
> +        1.0,-0.5,
> +       -1.0,-1.0,
> +        1.0,-1.0
> +};
> +static GLsizei vertices_size = sizeof(vertices);
> +
> +static GLuint indices[] = {
> +       0, 1, 2, 1, 2, 3, // top square
> +       4, 5, 6, 5, 6, 7, // bot square
> +};
> +static GLsizei indices_size = sizeof(indices);
> +
> +static GLuint square1_basevertex = 0;
> +static GLuint square1_start = 0;
> +static GLuint square1_end = 3;
> +static GLsizei square1_count = 6;
> +static GLvoid *square1_indices_offset = NULL;
> +
> +static GLuint square2_basevertex = 2;
> +static GLuint square2_start = 4;
> +static GLuint square2_end = 7;
> +static GLsizei square2_count = 6;
> +static GLvoid *square2_indices_offset = NULL + sizeof(GLuint)*6;

Spaces around *.

> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +       GLuint program;
> +       GLuint vertex_index;
> +
> +       if (piglit_get_gl_version() < 32) {
> +               piglit_require_extension("GL_ARB_draw_elements_base_vertex");
> +       }
> +
> +       // Create program
> +       program = piglit_build_simple_program(vs_source, fs_source);
> +       glUseProgram(program);
> +
> +       // Gen vertex array buffer
> +       glGenBuffers(1, &vertexBuffer);
> +       glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
> +       glBufferData(GL_ARRAY_BUFFER, vertices_size, vertices, GL_STATIC_DRAW);
> +
> +       // Gen indices array buffer
> +       glGenBuffers(1, &indexBuffer);
> +       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
> +       glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_size,
> +                       indices, GL_STATIC_DRAW);

Typically, indent with tabs until you'd go over and then use spaces to
align with the previous line.

> +       // Gen VAO
> +       glGenVertexArrays(1, &vao);
> +       glBindVertexArray(vao);
> +
> +       // Retrieve indices from vs
> +       vertex_index = glGetAttribLocation(program, "vertex");
> +
> +       // Enable vertex attrib array
> +       glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
> +       glEnableVertexAttribArray(vertex_index);
> +       glVertexAttribPointer(vertex_index, 2, GL_FLOAT, GL_FALSE, 0, 0);
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +       bool pass = true;
> +
> +       float white[] = {1,1,1};
> +       float clear[] = {0,0,0};

Spaces after commas.

Can we use red and green or something? Really, just not black and
white. Black and white are often the colors of undefined behavior :)

Actually, I tried red {1.0, 0.0, 0.0} and gray {0.8, 0.8, 0.8|

> +
> +       glClearColor(clear[0], clear[1], clear[2], 1.0);
> +       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

Don't need GL_DEPTH_BUFFER_BIT.

> +
> +       glBindVertexArray(vao);
> +       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
> +
> +
> +        //With base vertex of 0
> +       glDrawRangeElementsBaseVertex(GL_TRIANGLES, square1_start, square1_end,
> +                               square1_count, GL_UNSIGNED_INT,
> +                               square1_indices_offset, square1_basevertex);
> +
> +       //With base vertex of 2
> +       glDrawRangeElementsBaseVertex(GL_TRIANGLES, square2_start, square2_end,
> +                               square2_count, GL_UNSIGNED_INT,
> +                               square2_indices_offset, square2_basevertex);

I would get rid of the square?_* variables and just inline the
constants here to make it easier to follow.

Otherwise, the test looks good.

Reviewed-by: Matt Turner <mattst88 at gmail.com>


More information about the Piglit mailing list