Fredrik Höglund <fred...@kde.org> writes:
> diff --git a/tests/spec/arb_vertex_attrib_binding/format.c 
> b/tests/spec/arb_vertex_attrib_binding/format.c
> new file mode 100644
> index 0000000..130b65a
> --- /dev/null
> +++ b/tests/spec/arb_vertex_attrib_binding/format.c

> +/**
> + * @file offsets.c

format.c

> + * Tests that changing formats between draw calls works as expected.
> + */
> +
> +#include "piglit-util-gl-common.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +     config.supports_gl_compat_version = 10;

Also core?

> +     config.window_width = 128;
> +     config.window_height = 128;

These lines cause problems on windows, and I think this test is pretty
size-agnostic, so just drop them and take the defaults, I think.

> +     config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +const char *vs_source =
> +     "attribute vec4 pos;\n"
> +     "attribute vec4 color;\n"
> +     "uniform vec2 offset;\n"
> +     "varying vec4 col;\n"
> +     "void main() {\n"
> +     "    col = color;\n"
> +     "    gl_Position = pos + vec4(offset, vec2(0,0));\n"
> +     "}";
> +
> +const char *fs_source =
> +     "varying vec4 col;\n"
> +     "void main() {\n"
> +     "    gl_FragColor = col;\n"
> +     "}";
> +
> +struct Vertex
> +{
> +     float pos[2];
> +     unsigned char color[4];
> +};
> +
> +static GLuint program;
> +static GLuint pos, color, offset;
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +     const struct Vertex verts[] = {

lower case "vertex" for more piglit style.

> +             { { -.25,  .25 }, { 255,   255,   0, 255 } },
> +             { {  .25,  .25 }, { 255,   255,   0, 255 } },
> +             { { -.25, -.25 }, { 255,   255,   0, 255 } },
> +             { {  .25, -.25 }, { 255,   255,   0, 255 } },
> +     };
> +
> +     const float yellow[]= { 1.0, 1.0, 0.0, 1.0 };
> +     const float cyan[]  = { 0.0, 1.0, 1.0, 1.0 };
> +
> +     GLuint vbo, vao;
> +     bool pass = true;
> +
> +     glGenVertexArrays(1, &vao);
> +     glBindVertexArray(vao);
> +
> +     glGenBuffers(1, &vbo);
> +     glBindBuffer(GL_ARRAY_BUFFER, vbo);
> +     glBufferData(GL_ARRAY_BUFFER, sizeof(verts), (const GLvoid *) verts, 
> GL_STATIC_DRAW);

wrap at 80

> +     /* Bind the vertex buffer to binding point 0 */
> +     glBindVertexBuffer(0, vbo, 0, sizeof(struct Vertex));
> +
> +     /* Set up the attrib -> binding mapping */
> +     glVertexAttribBinding(pos,   0);
> +     glVertexAttribBinding(color, 0);
> +
> +     /* Set up the format and offset for the position */
> +     glVertexAttribFormat(pos, 2, GL_FLOAT, GL_FALSE, offsetof(struct 
> Vertex, pos));
> +
> +     glEnableVertexAttribArray(pos);
> +     glEnableVertexAttribArray(color);
> +
> +     glViewport(0, 0, piglit_width, piglit_height);
> +     glClearColor(0.0, 0.0, 0.0, 1.0);
> +     glClear(GL_COLOR_BUFFER_BIT);
> +
> +     glUseProgram(program);
> +
> +     /* Set the color format to RGBA order */
> +     glUniform2f(offset, -.4, 0);
> +     glVertexAttribFormat(color, 4, GL_UNSIGNED_BYTE, GL_TRUE, 
> offsetof(struct Vertex, color));
> +     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
> +
> +     /* Set the color format to BGRA order */
> +     glUniform2f(offset,  .4, 0);
> +     glVertexAttribFormat(color, GL_BGRA, GL_UNSIGNED_BYTE, GL_TRUE, 
> offsetof(struct Vertex, color));
> +     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
> +
> +     pass = piglit_probe_pixel_rgba(piglit_width * .25, piglit_height * .5, 
> yellow);
> +     pass = piglit_probe_pixel_rgba(piglit_width * .75, piglit_height * .5, 
> cyan);

To reduce state updates between draws even more, you could have 8 verts
total in the buffer, one quad covering the left half of the screen and
one the right (so you can piglit_probe_rect_rgba instead of just a
single pixel), use glDrawArrays(GL_TRIANGLE_STRIP, 4, 4) for the second
one, and drop the "offset" uniform.  It means that you don't get any
testing of fetched vertex caching by rereading the same data in
different formats, but it reduces the chances of stray state updates
From the uniform change making the test false pass.

Either way, though.  I'm really happy to see a test like this as part of
the test series, and wish we did more of them.

> +void
> +piglit_init(int argc, char **argv)
> +{
> +     GLuint vs, fs;
> +
> +     piglit_require_extension("GL_ARB_vertex_attrib_binding");
> +
> +     vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
> +     fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
> +     program = piglit_link_simple_program(vs, fs);

There's now "piglit_build_simple_program(vs_source, fs_source)"
available.

Attachment: pgpmGNdDiYo51.pgp
Description: PGP signature

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to