[Piglit] [PATCH] texture: add a 1:1 linear texture test case

Yuanhan Liu yuanhan.liu at linux.intel.com
Tue Oct 18 19:01:12 PDT 2011


On Mon, Oct 17, 2011 at 08:36:26AM -0700, Eric Anholt wrote:
> On Mon, 17 Oct 2011 11:48:57 +0800, Yuanhan Liu <yuanhan.liu at linux.intel.com> wrote:
> > To test that the 1:1 texture with filter set to linear it sampled
> > correctly.
> > 
[snip]
> > + * Tests that the 1:1 texture with filter set to linear is sampled correctly.
> > + */
> > +
> > +#include "piglit-util.h"
> > +
> > +int piglit_width = 100;
> > +int piglit_height = 100;
> > +int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
> > +
> > +#define DATA_SIZE	(piglit_width * piglit_height * 4)
> > +
> > +static void * make_tex_data(void)
> > +{
> > +	int i;
> > +	GLubyte *data = malloc(DATA_SIZE);
> > +
> > +	for (i = 0; i < DATA_SIZE; i++) {
> > +		if (i % 4 == 3)
> > +			data[i] = 255;
> > +		else
> > +			data[i] = random() % 256;
> > +	}
> > +
> > +	return data;
> > +}
> > +
> > +enum piglit_result
> > +piglit_display(void)
> > +{
> > +	GLuint tex;
> > +	GLboolean pass;
> > +	void *tex_data = make_tex_data();
> > +	void *out_data = malloc(DATA_SIZE);
> > +
> > +	glClearColor(0.0, 0.0, 0.0, 1.0);
> 
> ClearColor but no clear?

Oh, forgot it. Sorry for that.

> 
> > +
> > +	glGenTextures(1, &tex);
> > +	glBindTexture(GL_TEXTURE_2D, tex);
> > +	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, piglit_width, piglit_height,
> > +	             0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data);
> > +
> > +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
> > +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
> > +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
> > +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
> > +
> 
> GL_CLAMP has at various points triggered driver fallbacks.
> GL_CLAMP_TO_EDGE instead would ensure that you get hardware rendering,
> which is what we really care about testing.

Thanks for the info. Will change it.

> 
> > +	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
> > +	glEnable(GL_TEXTURE_2D);
> > +
> > +	glBegin(GL_QUADS);
> > +	  glTexCoord2f(0.0, 0.0);
> > +	  glVertex2f(-1.0, -1.0);
> > +	  glTexCoord2f(1.0, 0.0);
> > +	  glVertex2f(1.0, -1.0);
> > +	  glTexCoord2f(1.0, 1.0);
> > +	  glVertex2f(1.0,  1.0);
> > +	  glTexCoord2f(0.0, 1.0);
> > +	  glVertex2f(-1.0,  1.0);
> > +	glEnd();
> > +	glutSwapBuffers();
> > +
> > +	glReadPixels(0, 0, piglit_width, piglit_height, GL_RGBA, 
> > +	             GL_UNSIGNED_BYTE, out_data);
> 
> After a swapbuffers, backbuffer data is undefined.  Put the swap after
> the read to avoid failures in composited environments.
> 
> (Also, using piglit_present_results() instead of glutSwapBuffers() would
> mean that the test could be added as a concurrent test to reduce test
> runtime)

Thanks for the info. Will change it.

> 
> > +
> > +	pass = memcmp(tex_data, out_data, DATA_SIZE) == 0;
> 
> There should be some sort of feedback -- at least what pixel failed and
> some hex values.

Yeah, I should do this. Will add it.

> 
> > +
> > +	free(tex_data);
> > +	free(out_data);
> > +
> > +	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> > +}
> > +
> > +void
> > +piglit_init(int argc, char **argv)
> > +{
> 
> Since you use rectangular textures here, you should require
> GL_ARB_texture_rectangle.

Thanks for the info. Will fix it.


Thanks,
Yuanhan Liu
> 
> > +}
> 




More information about the Piglit mailing list