[Piglit] [PATCH 6/7] arb_vertex_attrib_binding: Test instance-divisor

Eric Anholt eric at anholt.net
Mon Nov 4 11:30:40 PST 2013


Fredrik Höglund <fredrik at kde.org> writes:

> On Wednesday 30 October 2013, Eric Anholt wrote:
>> Fredrik Höglund <fredrik at kde.org> writes:
>> > diff --git a/tests/spec/arb_vertex_attrib_binding/instance-divisor.c b/tests/spec/arb_vertex_attrib_binding/instance-divisor.c
>> > new file mode 100644
>> > index 0000000..88ae454
>> > --- /dev/null
>> > +++ b/tests/spec/arb_vertex_attrib_binding/instance-divisor.c
>> 
>> > +const char *vs_source =
>> > +	"attribute vec4 pos;\n"
>> > +	"attribute vec2 offset;\n"
>> > +	"attribute vec4 color;\n"
>> > +	"uniform vec2 global_offset;\n"
>> > +	"varying vec4 col;\n"
>> > +	"void main() {\n"
>> > +	"    col = color;\n"
>> > +	"    gl_Position = pos + vec4(global_offset + offset, vec2(0, 0));\n"
>> > +	"}";
>> 
>> > +enum piglit_result
>> > +piglit_display(void)
>> > +{
>> > +	const struct vec2 quad[] = {
>> > +		{ -0.125,  0.125 }, { 0.125,  0.125 },
>> > +		{ -0.125, -0.125 }, { 0.125, -0.125 }
>> > +	};
>> > +
>> > +	const struct vec2 offsets[] = {
>> > +		{ -.75, 0 }, { -.25, 0 }, { .25, 0 }, { .75, 0 }
>> > +	};
>> > +
>> > +	const struct vec4 colors[] = {
>> > +		{ 1.0, 0.0, 0.0, 1.0 },
>> > +		{ 0.0, 1.0, 0.0, 1.0 },
>> > +		{ 0.0, 0.0, 1.0, 1.0 },
>> > +		{ 1.0, 1.0, 1.0, 1.0 }
>> > +	};
>> > +
>> > +	GLuint vbo1, vbo2, vbo3, vao;
>> > +	bool pass = true;
>> > +
>> > +	glGenVertexArrays(1, &vao);
>> > +	glBindVertexArray(vao);
>> > +
>> > +	glGenBuffers(1, &vbo1);
>> > +	glGenBuffers(1, &vbo2);
>> > +	glGenBuffers(1, &vbo3);
>> > +
>> > +	glBindBuffer(GL_ARRAY_BUFFER, vbo1);
>> > +	glBufferData(GL_ARRAY_BUFFER, sizeof(quad), (const GLvoid *) quad, GL_STATIC_DRAW);
>> > +
>> > +	glBindBuffer(GL_ARRAY_BUFFER, vbo2);
>> > +	glBufferData(GL_ARRAY_BUFFER, sizeof(offsets), (const GLvoid *) offsets, GL_STATIC_DRAW);
>> 
>> I'm confused why there's both pos/quad (with two names) and offset.
>> Could you just have a single pre-baked pos vec2?
>
> quad is the quad we're drawing multiple instances of, and offset is how
> much the quad is offset in each instance.  The positions can't be
> pre-baked, since pos/quad advances per-vertex, and offset per-instance.
>
> I could add some comments to make that more clear, and maybe
> rename the quad array.  Another option is to remove the offsets array
> and offset the positions by gl_InstanceID multiplied by some value
> in the shader.  Or hardcode the quad array in the shader and index
> into it using gl_VertexID.  But both those options have the drawback
> that they add more dependencies.

Oh, yeah.  I had misread glVertexBindingDivisor(1, 1) as "reset to
normal non-instanced drawing" not "step offset by instance" due to
unfamiliarity with instancing.

Looks fine.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20131104/c98ccd0f/attachment.pgp>


More information about the Piglit mailing list