Exemplo n.º 1
0
static void test_half_vertices(float fx1, float fy1, float fx2, float fy2, int index)
{
    unsigned short x1, y1, x2, y2, one;
    x1 = piglit_half_from_float(fx1);
    y1 = piglit_half_from_float(fy1);
    x2 = piglit_half_from_float(fx2);
    y2 = piglit_half_from_float(fy2);
    one = piglit_half_from_float(1);

    test_half_vertices_wrapped(x1, y1, x2, y2, one, index);
}
Exemplo n.º 2
0
enum piglit_result
test_format(int format_index)
{
	const struct format *format = &formats[format_index];
	GLuint tex, bo;
	bool is_rg = (format->channels == R ||
		      format->channels == RG);
	bool is_arb = (format->channels == I ||
		       format->channels == L ||
		       format->channels == LA ||
		       format->channels == A);
	bool is_rgb32 = (format->channels == RGB);
	bool pass = true;
	int data_components, num_samples;
	int i;
	bool returns_float = (format->norm ||
			      format->type == GL_FLOAT ||
			      format->type == GL_HALF_FLOAT);
	bool returns_int = (!format->norm &&
			    (format->type == GL_BYTE ||
			     format->type == GL_SHORT ||
			     format->type == GL_INT));
	bool returns_uint = (!format->norm &&
			     (format->type == GL_UNSIGNED_BYTE ||
			      format->type == GL_UNSIGNED_SHORT ||
			      format->type == GL_UNSIGNED_INT));
	struct program *prog;

	if (returns_float)
		prog = &prog_f;
	else if (returns_int)
		prog = &prog_i;
	else
		prog = &prog_u;

	glUseProgram(prog->prog);

	if (test_arb != is_arb)
		return PIGLIT_SKIP;

	if (is_rgb32 && !test_rgb32)
		return PIGLIT_SKIP;

	/* These didn't exist in the extension before being promoted to
	 * GL 3.1.
	 */
	if (is_rg && piglit_get_gl_version() < 31)
		return PIGLIT_SKIP;

	printf("Testing %s\n", piglit_get_gl_enum_name(format->format));

	glGenBuffers(1, &bo);
	glBindBuffer(GL_TEXTURE_BUFFER, bo);

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

	glTexBuffer(GL_TEXTURE_BUFFER, format->format, bo);

	switch (format->type) {
	case GL_BYTE:
	case GL_UNSIGNED_BYTE:
		glBufferData(GL_TEXTURE_BUFFER, sizeof(uint8_data), uint8_data,
			     GL_STATIC_READ);
		data_components = ARRAY_SIZE(uint8_data);
		break;

	case GL_SHORT:
	case GL_UNSIGNED_SHORT:
		glBufferData(GL_TEXTURE_BUFFER, sizeof(uint16_data),
			     uint16_data, GL_STATIC_READ);
		data_components = ARRAY_SIZE(uint16_data);
		break;

	case GL_INT:
	case GL_UNSIGNED_INT:
		glBufferData(GL_TEXTURE_BUFFER, sizeof(uint32_data),
			     uint32_data, GL_STATIC_READ);
		data_components = ARRAY_SIZE(uint32_data);
		break;

	case GL_FLOAT:
		glBufferData(GL_TEXTURE_BUFFER, sizeof(float_data), float_data,
			     GL_STATIC_READ);
		data_components = ARRAY_SIZE(float_data);
		break;

	case GL_HALF_FLOAT: {
		unsigned short hf_data[ARRAY_SIZE(float_data)];
		for (i = 0; i < ARRAY_SIZE(float_data); i++) {
			hf_data[i] = piglit_half_from_float(float_data[i]);
		}
		glBufferData(GL_TEXTURE_BUFFER, sizeof(hf_data), hf_data,
			     GL_STATIC_READ);
		data_components = ARRAY_SIZE(float_data);

		break;
	}

	default:
		printf("line %d, bad type: %s\n", __LINE__,
		       piglit_get_gl_enum_name(format->type));
		return PIGLIT_SKIP;
	}

	num_samples = data_components / format->components;

	for (i = 0; i < num_samples; i++) {
		float x1 = 5 + i * 10;
		float x2 = 10 + i * 10;
		float y1 = piglit_height - (5 + y_index * 10);
		float y2 = piglit_height - (10 + y_index * 10);
		GLfloat verts[8] = {
			transform_x(x1), transform_y(y1),
			transform_x(x2), transform_y(y1),
			transform_x(x2), transform_y(y2),
			transform_x(x1), transform_y(y2),
		};
		float expected_f[4];
		uint32_t expected_i[4];
		const float green[4] = {0, 1, 0, 0};

		if (returns_float) {
			if (!get_expected_f(format, i, expected_f))
				return PIGLIT_SKIP;
			glUniform4fv(prog->expected_location, 1, expected_f);
		} else {
			if (!get_expected_i(format, i, expected_i))
				return PIGLIT_SKIP;
			if (returns_uint) {
				glUniform4uiv(prog->expected_location, 1,
					      expected_i);
			} else {
				glUniform4iv(prog->expected_location, 1,
					     (int *)expected_i);
			}
		}

		glUniform1i(prog->pos_location, i);

		glBufferData(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts,
			     GL_STREAM_DRAW);
		glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

		if (pass &&
		    !piglit_probe_rect_rgba(x1, y2,
					    x2 - x1, y1 - y2, green)) {
			if (returns_int) {
				printf("     Texel: %d %d %d %d\n",
				       expected_i[0], expected_i[1],
				       expected_i[2], expected_i[3]);
			} else if (returns_uint) {
				printf("     Texel: %u %u %u %u\n",
				       expected_i[0], expected_i[1],
				       expected_i[2], expected_i[3]);
			} else {
				printf("     Texel: %f %f %f %f\n",
				       expected_f[0], expected_f[1],
				       expected_f[2], expected_f[3]);
			}
			pass = false;
		}
	}

	glDeleteBuffers(1, &bo);
	glDeleteTextures(1, &tex);

	glUseProgram(0);
	y_index++;

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