Пример #1
0
void
piglit_init(int argc, char **argv)
{

	int rgb_tol = 0;
	int alpha_tol = 0;
	const char* blend_rgb_tol = getenv("PIGLIT_BLEND_RGB_TOLERANCE");
	const char* blend_alpha_tol = getenv("PIGLIT_BLEND_ALPHA_TOLERANCE");

	/* 
	 * Hack: Make driver tests on incorrect hardware feasible
	 * We want to be able to perform meaningful tests
	 * even when the blend unit of a GPU simply doesn't have
	 * sufficient precision.
	 */
	if (blend_rgb_tol)
	{
		rgb_tol = atoi(blend_rgb_tol);
		printf("Note: RGB tolerance changed to %i %s.\n", rgb_tol,
			rgb_tol == 1 ? "bit" : "bits");
	}
	if (blend_alpha_tol)
	{
		alpha_tol = atoi(blend_alpha_tol);
		printf("Note: Alpha tolerance changed to %i %s.\n", alpha_tol,
			alpha_tol == 1 ? "bit" : "bits");
	}
	/* A 0 passed in yields the default tolerance of 3.0/(1 << 8) ~= 0.01. */
	piglit_set_tolerance_for_bits(rgb_tol, rgb_tol, rgb_tol, alpha_tol);

	/* Initialize random images. */
	srand(0); 

	/* Fill src and dst with randomness. */
	dst_img.data = random_image_data();
	src_img.data = random_image_data();

	/* Fill exp_img with constant_color. */
	/* 
	 * You can use this as a check to make sure the test is working
	 * properly.
	 */
	exp_img.data = color_fill_data(constant_color[0],
				       constant_color[1],
				       constant_color[2],
				       constant_color[3]);

	image_init(&dst_img);
	image_init(&src_img);
	image_init(&exp_img);

} /* piglit_init */
Пример #2
0
void piglit_init(int argc, char **argv)
{
	glDisable(GL_DITHER);

	/* Set the tolerance a little looser since we're using GL_NEAREST
	 * texture sampling.  GL_NEAREST is fastest for software rendering.
	 * We probably wouldn't have to loosen the tolerance if we used
	 * GL_LINEAR filtering.
	 */
	piglit_set_tolerance_for_bits(7, 7, 7, 7);
	printf("Probe tolerance: %f, %f, %f, %f\n",
	       piglit_tolerance[0],
	       piglit_tolerance[1],
	       piglit_tolerance[2],
	       piglit_tolerance[3]);
}
void piglit_init(int argc, char **argv)
{
	int i;

	piglit_require_extension("GL_ARB_framebuffer_object");
	piglit_require_extension("GL_ARB_texture_storage");
	piglit_require_GLSL_version(120);

	format = GL_RGBA8;
	target = GL_TEXTURE_CUBE_MAP;
	num_layers = 6;

	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "array") == 0) {
			piglit_require_GLSL_version(130);
			piglit_require_extension("GL_ARB_texture_cube_map_array");
			test_array = GL_TRUE;
			target = GL_TEXTURE_CUBE_MAP_ARRAY;
			num_layers = 6 * 5;
		}
		else if (strcmp(argv[i], "RGB9_E5") == 0) {
			/* Test a non-renderable format. */
			piglit_require_extension("GL_EXT_texture_shared_exponent");
			format = GL_RGB9_E5;
		}
		else if (strcmp(argv[i], "S3TC_DXT1") == 0) {
			/* Test a compressed format. */
			piglit_require_extension("GL_EXT_texture_compression_s3tc");
			format = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
			piglit_set_tolerance_for_bits(5, 6, 5, 8);
		}
		else {
			assert(0);
		}
	}

	prog = piglit_build_simple_program(NULL, test_array ? fs_cube_array :
							      fs_cube);

	glClearColor(0.25, 0.25, 0.25, 0.25);
}
Пример #4
0
static enum piglit_result test_format(const struct format_desc *format)
{
	GLboolean pass = GL_TRUE;
	GLuint tex, fb;
	GLenum status;
	int r, g, b, l, a, i;

	float res0[] = {0.3, 0.3, 0.3, 0.0};

	float pos1[] = {-0.66, -1.0, 0.33, 2.0};
        float src1[] = {0.4, 0.9, 0.8, fix_alpha(0.7)};
        float dst1[] = {0.5, 0.4, 0.6, fix_alpha(0.2)};
        float con1[] = {0.2, 0.8, 0.4, fix_alpha(0.6)};
	float res1[] = {dst1[0]*(1-con1[0]) + src1[0]*con1[0],
                        dst1[1]*(1-con1[1]) + src1[1]*con1[1],
                        dst1[2]*(1-con1[2]) + src1[2]*con1[2],
                        dst1[3]*(1-con1[3]) + src1[3]*con1[3]};

	float pos2[] = {-0.33, -1.0, 0.33, 2.0};
	float dst2[] = {0.9, 0.4, 0.7, fix_alpha(0.5)};
        float src2[] = {0.8, 0.3, 0.5, fix_alpha(0.9)};
	float res2[] = {dst2[0]*(1-dst2[0]) + src2[0]*dst2[0],
			dst2[1]*(1-dst2[1]) + src2[1]*dst2[1],
			dst2[2]*(1-dst2[2]) + src2[2]*dst2[2],
			dst2[3]*(1-dst2[3]) + src2[3]*dst2[3]};

	float pos3[] = {0.0, -1.0, 0.33, 2.0};
	float dst3[] = {0.6, 0.4, 0.8, fix_alpha(0.5)};
	float src3[] = {0.8, 0.9, 0.7, fix_alpha(0.8)};
	float res3[] = {dst3[0]*(1-src3[0]) + src3[0]*src3[0],
			dst3[1]*(1-src3[1]) + src3[1]*src3[1],
			dst3[2]*(1-src3[2]) + src3[2]*src3[2],
			dst3[3]*(1-src3[3]) + src3[3]*src3[3]};

	float pos4[] = {0.33, -1.0, 0.33, 2.0};
	float dst4[] = {0.9, 0.4, 0.7, fix_alpha(0.5)};
	float src4[] = {0.8, 0.3, 0.5, fix_alpha(0.9)};
	float res4[] = {dst4[0]*(1-dst4[3]) + src4[0]*dst4[3],
			dst4[1]*(1-dst4[3]) + src4[1]*dst4[3],
			dst4[2]*(1-dst4[3]) + src4[2]*dst4[3],
			dst4[3]*(1-dst4[3]) + src4[3]*dst4[3]};
	float res4i = dst4[0]*(1-dst4[0]) + src4[0]*dst4[0]; /* intensity */
	float res4l = src4[0]; /* luminance without alpha */

	float pos5[] = {0.66, -1.0, 0.33, 2.0};
	float dst5[] = {0.6, 0.4, 0.8, fix_alpha(0.5)};
	float src5[] = {0.8, 0.9, 0.7, fix_alpha(0.8)};
	float res5[] = {dst5[0]*(1-src5[3]) + src5[0]*src5[3],
			dst5[1]*(1-src5[3]) + src5[1]*src5[3],
			dst5[2]*(1-src5[3]) + src5[2]*src5[3],
			dst5[3]*(1-src5[3]) + src5[3]*src5[3]};

        if (format->base_internal_format == GL_DEPTH_COMPONENT ||
            format->base_internal_format == GL_DEPTH_STENCIL)
		return PIGLIT_SKIP;

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
	glViewport(0, 0, piglit_width, piglit_height);

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, tex);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D, 0, format->internalformat,
		     piglit_width, piglit_height, 0,
		     GL_RGBA, GL_FLOAT, NULL);

	l = get_texture_bits(GL_TEXTURE_2D,
			     GL_TEXTURE_LUMINANCE_SIZE,
			     GL_TEXTURE_LUMINANCE_TYPE);
	a = get_texture_bits(GL_TEXTURE_2D,
			     GL_TEXTURE_ALPHA_SIZE,
			     GL_TEXTURE_ALPHA_TYPE);
	i = get_texture_bits(GL_TEXTURE_2D,
			     GL_TEXTURE_INTENSITY_SIZE,
			     GL_TEXTURE_INTENSITY_TYPE);
	r = get_texture_bits(GL_TEXTURE_2D,
			     GL_TEXTURE_RED_SIZE,
			     GL_TEXTURE_RED_TYPE);
	g = get_texture_bits(GL_TEXTURE_2D,
			     GL_TEXTURE_GREEN_SIZE,
			     GL_TEXTURE_GREEN_TYPE);
	b = get_texture_bits(GL_TEXTURE_2D,
			     GL_TEXTURE_BLUE_SIZE,
			     GL_TEXTURE_BLUE_TYPE);

	/* Compute expected result colors when reading back from a texture/FBO */
        if (i) {
		/* expected result = (I, 0, 0, 1) */
		res0[1] = res0[2] = 0.0;   res0[3] = 1.0;
		res1[1] = res1[2] = 0.0;   res1[3] = 1.0;
		res2[1] = res2[2] = 0.0;   res2[3] = 1.0;
		res3[1] = res3[2] = 0.0;   res3[3] = 1.0;
		res4[1] = res4[2] = 0.0;   res4[3] = 1.0;   res4[0] = res4i;
		res5[1] = res5[2] = 0.0;   res5[3] = 1.0;
	} else if (l) {
		/* expected result = (L, 0, 0, A) */
		res0[1] = res0[2] = 0.0;
		res1[1] = res1[2] = 0.0;
		res2[1] = res2[2] = 0.0;
		res3[1] = res3[2] = 0.0;
		res4[1] = res4[2] = 0.0;
		res5[1] = res5[2] = 0.0;
		if (!a) {
			res0[3] = 1;
			res1[3] = 1;
			res2[3] = 1;
			res3[3] = 1;
			res4[3] = 1; res4[0] = res4l;
			res5[3] = 1;
		}
        } else {
		if (!r) {
			res0[0] = 0;
			res1[0] = 0;
			res2[0] = 0;
			res3[0] = 0;
			res4[0] = 0;
			res5[0] = 0;
		}
		if (!g) {
			res0[1] = 0;
			res1[1] = 0;
			res2[1] = 0;
			res3[1] = 0;
			res4[1] = 0;
			res5[1] = 0;
		}
		if (!b) {
			res0[2] = 0;
			res1[2] = 0;
			res2[2] = 0;
			res3[2] = 0;
			res4[2] = 0;
			res5[2] = 0;
		}
		if (!a) {
			/* When there are no bits for the alpha channel, we
			 * always expect to read an alpha value of 1.0.
			 */
			res0[3] = 1;
			res1[3] = 1;
			res2[3] = 1;
			res3[3] = 1;
			res4[3] = 1;
			res5[3] = 1;

			/* Also blending with
			 * DST_ALPHA/ONE_MINUS_DST_ALPHA (as in case
			 * 4) with an implicit destination alpha value
			 * of 1.0 means that the result color should
			 * be identical to the source color, (if there
			 * are any bits to store that color that is).
			 */
			if (r)  {
				res4[0] = src4[0];
			}
			if (g) {
				res4[1] = src4[1];
			}
			if (b) {
				res4[2] = src4[2];
			}
		}
        }

	/* Clamp the bits for the framebuffer, except we aren't checking
	 * the actual framebuffer bits.
	 */
	if (l > 8)
		l = 8;
	if (i > 8)
		i = 8;
	if (r > 8)
		r = 8;
	if (g > 8)
		g = 8;
	if (b > 8)
		b = 8;
	if (a > 8)
		a = 8;

	if (format->internalformat == GL_R11F_G11F_B10F) {
		r = 6; /* precision of mantissa */
		g = 6;
		b = 5;
	}

        if (i) {
		piglit_set_tolerance_for_bits(i, i, i, i);
        } else if (l) {
		piglit_set_tolerance_for_bits(l, l, l, a);
        } else {
		piglit_set_tolerance_for_bits(r, g, b, a);
        }

	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
				  GL_COLOR_ATTACHMENT0_EXT,
				  GL_TEXTURE_2D,
				  tex,
				  0);
	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);

	status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
	printf("Testing %s", format->name);
	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		printf(" - fbo incomplete (status = %s)\n",
		       piglit_get_gl_enum_name(status));
		piglit_report_subtest_result(PIGLIT_SKIP, "%s", format->name);
		return PIGLIT_SKIP;
	}
        printf("\n");

	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	glColor4fv(res0);
	piglit_draw_rect(-1.0, -1.0, 0.33, 2.0);

        blend(pos1, src1, dst1, con1, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
	blend(pos2, src2, dst2, NULL, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR);
	blend(pos3, src3, dst3, NULL, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
	blend(pos4, src4, dst4, NULL, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
	blend(pos5, src5, dst5, NULL, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	if (!piglit_probe_pixel_rgba(piglit_width * 1 / 12, 0, res0)) {
		printf("  when testing FBO result, simple.\n");
		pass = GL_FALSE;
        }
	if (!piglit_probe_pixel_rgba(piglit_width * 3 / 12, 0, res1)) {
		printf("  when testing FBO result, blending with CONSTANT_COLOR.\n");
		pass = GL_FALSE;
        }
	if (!piglit_probe_pixel_rgba(piglit_width * 5 / 12, 0, res2)) {
		printf("  when testing FBO result, blending with DST_COLOR.\n");
		pass = GL_FALSE;
        }
	if (!piglit_probe_pixel_rgba(piglit_width * 7 / 12, 0, res3)) {
		printf("  when testing FBO result, blending with SRC_COLOR.\n");
		pass = GL_FALSE;
        }
	if (!piglit_probe_pixel_rgba(piglit_width * 9 / 12, 0, res4)) {
		printf("  when testing FBO result, blending with DST_ALPHA.\n");
		pass = GL_FALSE;
	}
	if (!piglit_probe_pixel_rgba(piglit_width * 11 / 12, 0, res5)) {
		printf("  when testing FBO result, blending with SRC_ALPHA.\n");
		pass = GL_FALSE;
	}

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
	glViewport(0, 0, piglit_width, piglit_height);

	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB,   GL_REPLACE);
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);

	glColor4f(1, 1, 1, 1);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, tex);
	piglit_draw_rect_tex(-1, -1, 2, 2,
			     0, 0, 1, 1);

	glDisable(GL_TEXTURE_2D);
	glDeleteTextures(1, &tex);
	glBindFramebufferEXT(GL_FRAMEBUFFER, piglit_winsys_fbo);
	glDeleteFramebuffersEXT(1, &fb);

	if (!pass) {
		piglit_present_results();
		piglit_report_subtest_result(PIGLIT_FAIL, "%s", format->name);
		return PIGLIT_FAIL;
	}

	/* Compute expected result colors when reading back from the window */
        if (i) {
		/* expected result = (I, I, I, I) */
		res0[3] = res0[2] = res0[1] = res0[0];
		res1[3] = res1[2] = res1[1] = res1[0];
		res2[3] = res2[2] = res2[1] = res2[0];
		res3[3] = res3[2] = res3[1] = res3[0];
		res4[3] = res4[2] = res4[1] = res4[0] = res4i;
		res5[3] = res5[2] = res5[1] = res5[0];
	} else if (l) {
		/* expected result = (L, L, L, A) */
		res0[2] = res0[1] = res0[0];
		res1[2] = res1[1] = res1[0];
		res2[2] = res2[1] = res2[0];
		res3[2] = res3[1] = res3[0];
		res4[2] = res4[1] = res4[0];
		res5[2] = res5[1] = res5[0];
	} else {
		/* leave 'res' colors as-is from above */
	}

	if (!piglit_probe_pixel_rgba(piglit_width * 1 / 12, 0, res0)) {
		printf("  when testing window result, simple.\n");
		pass = GL_FALSE;
        }
	if (!piglit_probe_pixel_rgba(piglit_width * 3 / 12, 0, res1)) {
		printf("  when testing window result, blending with CONSTANT_COLOR.\n");
		pass = GL_FALSE;
        }
	if (!piglit_probe_pixel_rgba(piglit_width * 5 / 12, 0, res2)) {
		printf("  when testing window result, blending DST_COLOR.\n");
		pass = GL_FALSE;
        }
	if (!piglit_probe_pixel_rgba(piglit_width * 7 / 12, 0, res3)) {
		printf("  when testing window result, blending SRC_COLOR.\n");
		pass = GL_FALSE;
        }
	if (!piglit_probe_pixel_rgba(piglit_width * 9 / 12, 0, res4)) {
		printf("  when testing window result, blending DST_ALPHA.\n");
		pass = GL_FALSE;
	}
	if (!piglit_probe_pixel_rgba(piglit_width * 11 / 12, 0, res5)) {
		printf("  when testing window result, blending SRC_ALPHA.\n");
		pass = GL_FALSE;
	}

	piglit_present_results();

	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
				     "%s", format->name);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Пример #5
0
/**
 * Test a specific texture target and format combination.
 */
static GLboolean
test_target_and_format(GLint x, GLint y, GLenum target, GLenum format,
		       const GLfloat *expected)
{
	GLboolean pass = GL_TRUE;
	GLuint k;
	GLuint prog = 0;

	printf("Texture target = %s, Internal format = %s",
	       piglit_get_gl_enum_name(target),
	       piglit_get_gl_enum_name(format));

	if (!supported_format(format) ||
	    !supported_target_format(target, format)) {
		printf(" - skipped\n");
		return GL_TRUE; /* not a failure */
	} else {
		printf("\n");
	}

	/* To avoid failures not related to this test case,
	 * loosen up the tolerence for compressed texture
	 * formats
	 */
	if (is_compressed_format(format))
		piglit_set_tolerance_for_bits(5, 5, 5, 5);
	else
		piglit_set_tolerance_for_bits(8, 8, 8, 8);

	switch(target) {

	case GL_TEXTURE_1D:
		draw(format, 1.0);
		glCopyTexImage1D(GL_TEXTURE_1D, 0,
				 format,
				 0, 0, IMAGE_SIZE, 0);
		pass = piglit_check_gl_error(GL_NO_ERROR)
			&& pass;

		glEnable(target);
		piglit_draw_rect_tex(x, y, IMAGE_SIZE, IMAGE_SIZE,
				      0, 0, 1, 1);
		pass = piglit_probe_rect_rgba(x, y, IMAGE_SIZE,
					      IMAGE_SIZE,
					      expected)
			&& pass;
		break;

	case GL_TEXTURE_2D:
		draw(format, 1.0);
		glCopyTexImage2D(GL_TEXTURE_2D, 0, format, 0, 0,
				 IMAGE_SIZE, IMAGE_SIZE, 0);
		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

		glEnable(target);
		piglit_draw_rect_tex(x, y, IMAGE_SIZE, IMAGE_SIZE,
				      0, 0, 1, 1);
		pass = piglit_probe_rect_rgba(x, y, IMAGE_SIZE,
					      IMAGE_SIZE,
					      expected)
			&& pass;
		break;

	case GL_TEXTURE_3D:
		glTexImage3D(GL_TEXTURE_3D, 0, format, IMAGE_SIZE, IMAGE_SIZE, 4,
			     0, GL_RGBA, get_type(format), NULL);

		for (k = 0; k < 4; k++) {
			draw(format, 1.0 - k*0.2);
			glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, k,
					    0, 0, IMAGE_SIZE, IMAGE_SIZE);
		}

		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

		glEnable(target);

		for (k = 0; k < 4; k++) {
			const float tz = k * 0.25;
			draw_rect_tex_3d(x, y, IMAGE_SIZE, IMAGE_SIZE,
					 0, 0, tz, 1, 1);
			pass = probe_rect(x, y, IMAGE_SIZE, IMAGE_SIZE,
					  expected, 1.0 - k*0.2) && pass;
		}
		break;

	case GL_TEXTURE_CUBE_MAP:
		for (k = 0; k < 6; k++) {
			draw(format, 1.0 - k*0.15);
			glCopyTexImage2D(cube_face_targets[k],
					 0, format, 0, 0,
					 IMAGE_SIZE, IMAGE_SIZE, 0);
		}

		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

		glEnable(target);

		for (k = 0; k < 6; k++) {
			draw_rect_tex_cube_face(x, y, IMAGE_SIZE, IMAGE_SIZE, k);
			pass = probe_rect(x, y, IMAGE_SIZE, IMAGE_SIZE,
					  expected, 1.0 - k*0.15) && pass;
		}
		break;

	case GL_TEXTURE_1D_ARRAY:
		glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, format, IMAGE_SIZE, 16,
			     0, get_format(format), get_type(format), NULL);

		for (k = 0; k < 4; k++) {
			draw(format, 1.0 - 0.2*k);
			glCopyTexSubImage2D(GL_TEXTURE_1D_ARRAY, 0, 0, 4*k,
					    0, 0, IMAGE_SIZE, 4);
		}

		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

		prog = piglit_build_simple_program(NULL, array1D_shader_text);
		glUseProgram(prog);
		glDeleteProgram(prog);

		for (k = 0; k < 16; k++) {
			piglit_draw_rect_tex(x, y, IMAGE_SIZE, IMAGE_SIZE,
					      0, k, 1, 0);
			pass = probe_rect(x, y, IMAGE_SIZE, IMAGE_SIZE,
					  expected, 1.0 - 0.2*(k/4)) && pass;
		}
		break;

	case GL_TEXTURE_2D_ARRAY:
		glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, format, IMAGE_SIZE, IMAGE_SIZE, 4,
			     0, get_format(format), get_type(format), NULL);

		for (k = 0; k < 4; k++) {
			draw(format, 1.0 - k*0.2);
			glCopyTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, k,
					    0, 0, IMAGE_SIZE, IMAGE_SIZE);
		}

		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

		prog = piglit_build_simple_program(NULL, array2D_shader_text);
		glUseProgram(prog);
		glDeleteProgram(prog);

		for (k = 0; k < 4; k++) {
			draw_rect_tex_3d(x, y, IMAGE_SIZE, IMAGE_SIZE,
					 0, 0, k, 1, 1);
			pass = probe_rect(x, y, IMAGE_SIZE, IMAGE_SIZE,
					  expected, 1.0 - k*0.2) && pass;
		}
		break;

	case GL_TEXTURE_RECTANGLE:
		draw(format, 1.0);
		glCopyTexImage2D(GL_TEXTURE_RECTANGLE, 0, format, 0, 0,
				 IMAGE_SIZE, IMAGE_SIZE, 0);
		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
		
		glEnable(target);
		piglit_draw_rect_tex(x, y, IMAGE_SIZE, IMAGE_SIZE,
				      0, 0, IMAGE_SIZE - 1, IMAGE_SIZE - 1);
		pass = piglit_probe_rect_rgba(x, y, IMAGE_SIZE,
					      IMAGE_SIZE,
					      expected)
			&& pass;
		break;
	}

	/* If a GLSL program is in use, then the preceeding code should not
	 * have called glEnable(target).  In that case, this code should not
	 * disable it.  For some targets, like GL_TEXTURE_1D_ARRAY,
	 * glDisable(target) will generate an error.
	 */
	if (prog == 0)
		glDisable(target);
	else
		glUseProgram(0);

	return pass;
}
Пример #6
0
static GLboolean
test_mipmap_drawing(int x, int y, int dim, int level, GLuint internalformat)
{
	GLboolean pass = GL_TRUE;
	int half = dim / 2;
	int x1 = x, y1 = y, x2 = x + half, y2 = y + half;
	float r[] = {1, 0, 0, 0};
	float g[] = {0, 1, 0, 0.25};
	float b[] = {0, 0, 1, 0.5};
	float w[] = {1, 1, 1, 1};
	GLint r_size, g_size, b_size, l_size, a_size, d_size, i_size;
	GLint compressed;

	glGetTexLevelParameteriv(GL_TEXTURE_2D, level,
				 GL_TEXTURE_COMPRESSED, &compressed);
	if (compressed && dim < 8)
		return GL_TRUE;

	if (piglit_is_extension_supported("GL_ARB_depth_texture")) {
		glGetTexLevelParameteriv(GL_TEXTURE_2D, level,
					 GL_TEXTURE_DEPTH_SIZE, &d_size);
	} else {
		d_size = 0;
	}
	glGetTexLevelParameteriv(GL_TEXTURE_2D, level,
				 GL_TEXTURE_LUMINANCE_SIZE, &l_size);
	glGetTexLevelParameteriv(GL_TEXTURE_2D, level,
				 GL_TEXTURE_ALPHA_SIZE, &a_size);
	glGetTexLevelParameteriv(GL_TEXTURE_2D, level,
				 GL_TEXTURE_INTENSITY_SIZE, &i_size);
	glGetTexLevelParameteriv(GL_TEXTURE_2D, level,
				 GL_TEXTURE_RED_SIZE, &r_size);
	glGetTexLevelParameteriv(GL_TEXTURE_2D, level,
				 GL_TEXTURE_GREEN_SIZE, &g_size);
	glGetTexLevelParameteriv(GL_TEXTURE_2D, level,
				 GL_TEXTURE_BLUE_SIZE, &b_size);

	if (d_size) {
		for (x1 = x; x1 < x + dim; x1++) {
			float val = (x1 - x + 0.5) / (dim);
			float color[3] = {val, val, val};
			pass = pass && piglit_probe_rect_rgb(x1, y, 1, dim,
							     color);
		}
		return pass;
	}

	if (i_size || l_size) {
		r[0] = 1.0;
		r[1] = 1.0;
		r[2] = 1.0;

		g[0] = 0.0;
		g[1] = 0.0;
		g[2] = 0.0;

		b[0] = 0.0;
		b[1] = 0.0;
		b[2] = 0.0;

		if (i_size) {
			r[3] = 1.0;
			g[3] = 0.0;
			b[3] = 0.0;
		} else if (l_size && !a_size) {
			r[3] = 1.0;
			g[3] = 1.0;
			b[3] = 1.0;
			w[3] = 1.0;
		}
	} else if (a_size && !r_size && !l_size) {
		r[0] = 1.0;
		r[1] = 1.0;
		r[2] = 1.0;
		g[0] = 1.0;
		g[1] = 1.0;
		g[2] = 1.0;
		b[0] = 1.0;
		b[1] = 1.0;
		b[2] = 1.0;
	} else {
		if (!r_size) {
			r[0] = 0.0;
			w[0] = 0.0;
		}

		if (!g_size) {
			g[1] = 0.0;
			w[1] = 0.0;
		}

		if (!b_size) {
			b[2] = 0.0;
			w[2] = 0.0;
		}
		if (!a_size) {
			r[3] = 1.0;
			g[3] = 1.0;
			b[3] = 1.0;
			w[3] = 1.0;
		}
	}

	/* Clamp the bits for the framebuffer, except we aren't checking
	 * the actual framebuffer bits.
	 */
	if (l_size > 8)
		l_size = 8;
	if (i_size > 8)
		i_size = 8;
	if (r_size > 8)
		r_size = 8;
	if (g_size > 8)
		g_size = 8;
	if (b_size > 8)
		b_size = 8;
	if (a_size > 8)
		a_size = 8;

	if (d_size) {
		piglit_set_tolerance_for_bits(8, 8, 8, 8);
	} else if (i_size) {
		piglit_set_tolerance_for_bits(i_size, i_size, i_size, i_size);
	} else if (l_size) {
		piglit_set_tolerance_for_bits(l_size, l_size, l_size, a_size);
	} else {
		piglit_set_tolerance_for_bits(r_size, g_size, b_size, a_size);
	}

	if (internalformat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ||
	    internalformat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT) {
		/* If alpha in DXT1 is < 0.5, the whole pixel should be black. */
		r[0] = r[1] = r[2] = r[3] = 0;
		g[0] = g[1] = g[2] = g[3] = 0;
		/* If alpha in DXT1 is >= 0.5, it should be white. */
		b[3] = 1;
	}

	pass = pass && piglit_probe_rect_rgba(x1, y1, half, half, r);
	pass = pass && piglit_probe_rect_rgba(x2, y1, half, half, g);
	pass = pass && piglit_probe_rect_rgba(x1, y2, half, half, b);
	pass = pass && piglit_probe_rect_rgba(x2, y2, half, half, w);

	return pass;
}
Пример #7
0
void piglit_init(int argc, char **argv)
{
	GLuint tex, fb;
	GLenum status;
	int i, dim;

	piglit_require_GLSL();
	piglit_require_extension("GL_EXT_framebuffer_object");
	piglit_require_extension("GL_ARB_shader_texture_lod");

	prog_tex = piglit_build_simple_program(NULL, sh_tex);
	prog_texgrad = piglit_build_simple_program(NULL, sh_texgrad);

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, tex);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) {
		glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA,
			     dim, dim,
			     0,
			     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	}
	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);

	glBindTexture(GL_TEXTURE_2D, 0);
	glDisable(GL_TEXTURE_2D);

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

	for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) {
		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
					  GL_COLOR_ATTACHMENT0_EXT,
					  GL_TEXTURE_2D,
					  tex,
					  i);

		status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
		if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
			fprintf(stderr, "FBO incomplete\n");
			piglit_report_result(PIGLIT_SKIP);
		}

		glClearColor(colors[i][0],
			     colors[i][1],
			     colors[i][2],
			     0.0);
		glClear(GL_COLOR_BUFFER_BIT);

		if (!piglit_check_gl_error(GL_NO_ERROR))
		        piglit_report_result(PIGLIT_FAIL);
	}
	glDeleteFramebuffersEXT(1, &fb);
	glBindTexture(GL_TEXTURE_2D, tex);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustum(-0.1, 0.1, -0.1, 0.1, 0.1, 1000.0);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(-0.5, -0.5, -1.2);
	glRotatef(68, 0, 1, 0);
	glScalef(2000, 1, 1);

	glEnable(GL_TEXTURE_2D);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	piglit_set_tolerance_for_bits(7, 7, 7, 7);

	printf("Left: texture2D, Right: texture2DGradARB\n");
}
Пример #8
0
static enum piglit_result test_format(const struct format_desc *format)
{
	GLboolean pass = GL_TRUE;
	GLuint tex, fb;
	GLenum status;
	int r, g, b, l, a, i;
	unsigned mask, k;
	float defaults[] = {-1, -1, -1, -1};

	if (format->base_internal_format == GL_DEPTH_COMPONENT ||
	    format->base_internal_format == GL_DEPTH_STENCIL)
		return PIGLIT_SKIP;

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
	glViewport(0, 0, piglit_width, piglit_height);

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, tex);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D, 0, format->internalformat,
		     piglit_width, piglit_height, 0,
		     GL_RGBA, GL_FLOAT, NULL);

	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
				 GL_TEXTURE_LUMINANCE_SIZE, &l);
	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
				 GL_TEXTURE_ALPHA_SIZE, &a);
	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
				 GL_TEXTURE_INTENSITY_SIZE, &i);
	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
				 GL_TEXTURE_RED_SIZE, &r);
	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
				 GL_TEXTURE_GREEN_SIZE, &g);
	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
				 GL_TEXTURE_BLUE_SIZE, &b);

	/* Set up expected defaults.
	 * We're using glReadPixels from the texture.
	 */
	if (i) {
		/* GL_INTENSITY texture:  result = (I,0,0,1) */
		defaults[3] = 1;
		defaults[2] = defaults[1] = 0;
	} else if (l) {
		/* GL_LUMINANCE texture:  result = (L,0,0,A) */
		defaults[2] = defaults[1] = 0;
		if (!a) {
			defaults[3] = 1;
		}
	} else {
		/* other format */
		if (!r) {
			defaults[0] = 0;
		}
		if (!g) {
			defaults[1] = 0;
		}
		if (!b) {
			defaults[2] = 0;
		}
		if (!a) {
			defaults[3] = 1;
		}
	}

	/* Clamp the bits for the framebuffer, except we aren't checking
	 * the actual framebuffer bits.
	 */
	if (l > 8)
		l = 8;
	if (i > 8)
		i = 8;
	if (r > 8)
		r = 8;
	if (g > 8)
		g = 8;
	if (b > 8)
		b = 8;
	if (a > 8)
		a = 8;

	if (i) {
		piglit_set_tolerance_for_bits(i, i, i, i);
	} else if (l) {
		piglit_set_tolerance_for_bits(l, l, l, a);
	} else {
		piglit_set_tolerance_for_bits(r, g, b, a);
	}

	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
				  GL_COLOR_ATTACHMENT0_EXT,
				  GL_TEXTURE_2D,
				  tex,
				  0);
	assert(glGetError() == 0);

	status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
	printf("Testing %s", format->name);
	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		printf(" - fbo incomplete (status = %s)\n",
		       piglit_get_gl_enum_name(status));
		piglit_report_subtest_result(PIGLIT_SKIP,
					     "%s (fbo incomplete)",
					     format->name);
		return PIGLIT_SKIP;
	}
	printf("\n");

	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	for (mask = 0; mask <= 15; mask++) {
		float rect[4];
		rect[0] = -1 + (mask / 8.0);
		rect[1] = -1;
		rect[2] = 2 / 16.0;
		rect[3] = 2;

		colormask(rect, mask);
	}

	for (mask = 0; mask <= 15; mask++) {
		float color[4], out[4];

		for (k = 0; k < 4; k++) {
			if (defaults[k] >= 0)
				color[k] = defaults[k];
			else
				color[k] = (mask & (1 << k)) ? 1 : 0;
		}

		if (!piglit_probe_pixel_rgba_silent(piglit_width * mask / 16, 0,
						    color, out)) {
			printf("glColorMask(%i, %i, %i, %i)\n",
			       !!(mask & 1), !!(mask & 2),
			       !!(mask & 4), !!(mask & 8));
			printf("  Expected: %f %f %f %f\n",
			       color[0], color[1], color[2], color[3]);
			printf("  Observed: %f %f %f %f\n",
			       out[0], out[1], out[2], out[3]);
			pass = GL_FALSE;
		}
	}

	/*
	 * Display the texture.
	 */
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
	glViewport(0, 0, piglit_width, piglit_height);

	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB,   GL_REPLACE);
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);

	glColor4f(1, 1, 1, 1);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, tex);
	piglit_draw_rect_tex(-1, -1, 2, 2,
			     0, 0, 1, 1);

	glDisable(GL_TEXTURE_2D);
	glDeleteTextures(1, &tex);
	glBindFramebufferEXT(GL_FRAMEBUFFER, piglit_winsys_fbo);
	glDeleteFramebuffersEXT(1, &fb);

	piglit_present_results();

	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
				     "%s", format->name);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Пример #9
0
enum piglit_result
piglit_display(void)
{
	GLfloat buf_fcolor[IMAGE_SIZE][IMAGE_SIZE][4];
	GLuint tex;
	GLboolean pass = GL_TRUE;
	GLenum format;
	const GLfloat *expected;
	int i, j;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	/* Image data setup */
	for (i = 0; i < IMAGE_SIZE; i++) {
		for (j = 0; j < IMAGE_SIZE; j++) {
			buf_fcolor[i][j][0] = 0.5;
			buf_fcolor[i][j][1] = 0.2;
			buf_fcolor[i][j][2] = 0.8;
			buf_fcolor[i][j][3] = 0.4;
		}
	}

	/* Do glCopyPixels and draw a textured rectangle for each format
	 * and each texture target
	 */
	for (j = 0; j < ARRAY_SIZE(target); j++) {

		/* Draw a pixel rectangle with float color data. As per OpenGL 3.0
		 * specification integer formats are not allowed in glDrawPixels
		 */
		glDrawPixels(IMAGE_SIZE, IMAGE_SIZE, GL_RGBA,
			     GL_FLOAT, buf_fcolor);

		/* Texture setup */
		glGenTextures(1, &tex);
		glBindTexture(target[j], tex);
		glTexParameteri(target[j],
				GL_TEXTURE_MIN_FILTER,
				GL_NEAREST);
		glTexParameteri(target[j],
				GL_TEXTURE_MAG_FILTER,
				GL_NEAREST);
		glTexParameteri(target[j],
				GL_GENERATE_MIPMAP,
				GL_FALSE);

		glEnableClientState(GL_TEXTURE_COORD_ARRAY);

		for (i = 0; i < ARRAY_SIZE(test_vectors); i++) {
			GLint x = IMAGE_SIZE * (i + 1);
			GLint y = 0;
			GLfloat vertices_1d[2][2] = { {x, y},
						      {x + IMAGE_SIZE, y} };

			format = test_vectors[i].format;
			expected = (const float*)test_vectors[i].expected;

			if(!piglit_automatic)
				printf("Texture target = %s, Internal"
				       " format = %s\n",
				       piglit_get_gl_enum_name(target[j]),
				       piglit_get_gl_enum_name(format));

			if (!supported_format(format) ||
			    !supported_target_format(target[j], format)) {
				if (!piglit_automatic)
					printf("Internal format = %s skipped\n",
					       piglit_get_gl_enum_name(format));
				continue;
			}

			/* To avoid failures not related to this test case,
			 * loosen up the tolerence for compressed texture
			 * formats
			 */
			if (is_compressed_format(format))
				piglit_set_tolerance_for_bits(7, 7, 7, 7);
			else
				piglit_set_tolerance_for_bits(8, 8, 8, 8);

			switch(target[j]) {

			case GL_TEXTURE_1D:
				glCopyTexImage1D(GL_TEXTURE_1D, 0,
						 format,
						 0, 0, IMAGE_SIZE, 0);
				pass = piglit_check_gl_error(GL_NO_ERROR)
				       && pass;

				glEnable(target[j]);
				glEnableClientState(GL_VERTEX_ARRAY);
				glTexCoordPointer(1, GL_FLOAT, 0, texCoords_1d);
				glVertexPointer(2, GL_FLOAT, 0, vertices_1d);

				glDrawArrays(GL_LINES, 0, 2);
				pass = piglit_probe_pixel_rgba(x, 0, expected)
				       && pass;
				pass = piglit_probe_pixel_rgba(x + IMAGE_SIZE - 1,
							       0, expected)
				       && pass;
				break;

			case GL_TEXTURE_2D:
				glCopyTexImage2D(GL_TEXTURE_2D, 0, format, 0, 0,
						 IMAGE_SIZE, IMAGE_SIZE, 0);
				pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

				glEnable(target[j]);
				glTexCoordPointer(2, GL_FLOAT, 0, texCoords_2d);

				piglit_draw_rect(x, y, IMAGE_SIZE, IMAGE_SIZE);
				pass = piglit_probe_rect_rgba(x, y, IMAGE_SIZE,
							      IMAGE_SIZE,
							      expected)
				       && pass;
				break;

			case GL_TEXTURE_CUBE_MAP:
				glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,
						 0, format, 0, 0,
						 IMAGE_SIZE, IMAGE_SIZE, 0);
				glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
						 0, format, 0, 0,
						 IMAGE_SIZE, IMAGE_SIZE, 0);
				glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
						 0, format, 0, 0,
						 IMAGE_SIZE, IMAGE_SIZE, 0);
				glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
						 0, format, 0, 0,
						 IMAGE_SIZE, IMAGE_SIZE, 0);
				glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
						 0, format, 0, 0,
						 IMAGE_SIZE, IMAGE_SIZE, 0);
				glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
						 0, format, 0, 0,
						 IMAGE_SIZE, IMAGE_SIZE, 0);
				pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

				glEnable(target[j]);

				/* Draw a rect with +X cubemap face as texture */
				glTexCoordPointer(3, GL_FLOAT, 0,
						  cube_face_texcoords[0]);
				piglit_draw_rect(x, y, IMAGE_SIZE, IMAGE_SIZE);
				pass = piglit_probe_rect_rgba(x, y,
				       IMAGE_SIZE, IMAGE_SIZE, expected)
				       && pass;

				/* Draw a rect with +Z cubemap face as texture */
				glTexCoordPointer(3, GL_FLOAT, 0,
						  cube_face_texcoords[2]);
				piglit_draw_rect(x, y, IMAGE_SIZE, IMAGE_SIZE);
				pass = piglit_probe_rect_rgba(x, y,
				       IMAGE_SIZE, IMAGE_SIZE, expected)
				       && pass;
				break;
			}
			glDisable(target[j]);
		}
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDeleteTextures(1, &tex);
	}
	if (!piglit_automatic)
		piglit_present_results();
	return (pass ? PIGLIT_PASS : PIGLIT_FAIL);
}