예제 #1
0
enum piglit_result
piglit_display(void)
{
	bool pass = true;
	GLint w = pattern_width, h = pattern_height;
	GLfloat *color_buffer = NULL;

	test->draw_to_default_framebuffer();

	/* Read color buffer */
	glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
	color_buffer = (GLfloat *) malloc(w * h * 4 * sizeof(float));
	glReadPixels(0, 0, w, h, GL_RGBA, GL_FLOAT, color_buffer);

	/* Draw the test pattern in to test_fbo with num_samples = 0. This
	 * is to verify if glRenderbufferStorageMultisample() with zero sample
	 * count turns off MSAA.
	 */
	test->test_fbo.set_samples(0);
	test->draw_test_image(&test->test_fbo);

	/* Compare rendered scene with color_buffer */
	glBindFramebuffer(GL_READ_FRAMEBUFFER, test->test_fbo.handle);
	pass = piglit_probe_image_rgba(0, 0, w, h, color_buffer)
	       && pass;

	/* Switch ON MSAA in this FBO by passing num_samples > 0 */
	test->test_fbo.set_samples(num_samples);

	/* Draw test image in multisample FBO */
	test->draw_test_image(&test->test_fbo);

	/* Draw a reference image for MSAA */
	test->draw_reference_image();

	/* Measure the accuracy of MSAA in multisample FBO by comparing the
	 * test image to reference image. This varifies if MSAA is actually
	 * switched on.
	 */
	pass = test->measure_accuracy() && pass;

	/* Switch OFF MSAA again in this FBO */
	test->test_fbo.set_samples(0);
	test->draw_test_image(&test->test_fbo);

	/* Compare rendered scene with color_buffer */
	glBindFramebuffer(GL_READ_FRAMEBUFFER, test->test_fbo.handle);
	pass = piglit_probe_image_rgba(0, 0, w, h, color_buffer)
	       && pass;

	if (!piglit_automatic)
		piglit_present_results();
	return (pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
예제 #2
0
enum piglit_result piglit_display(void)
{
	GLboolean pass = GL_TRUE;
	int i;

	glBindTexture(GL_TEXTURE_2D, tex);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 16, 16, 0, GL_RGBA, GL_FLOAT, tex_data);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
	glViewport(0, 0, 16, 16);

	glUseProgram(prog);
	glUniform1i(texloc, 0);

	for (i = 0; i < PASSES; i++) {
		if (i != 0)
			glTextureBarrierNV();
		piglit_draw_rect_tex(-1, -1, 2, 2, 0, 0, 1, 1);
	}

	pass = piglit_probe_image_rgba(0, 0, 16, 16, res_data);

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

	piglit_draw_rect_tex(-1, -1, 2, 2, 0, 0, 1, 1);

	piglit_present_results();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
예제 #3
0
파일: blit.c 프로젝트: chemecse/piglit
static bool
analyze_image(GLuint fbo)
{
	GLfloat *expected_data = malloc(PATTERN_WIDTH * PATTERN_HEIGHT * 4 *
					sizeof(GLfloat));
	unsigned x, y, component;
	bool pass;

	for (y = 0; y < PATTERN_HEIGHT; ++y) {
		for (x = 0; x < PATTERN_WIDTH; ++x) {
			for (component = 0; component < 4; ++component) {
				float val = x / 255.0;
				if (component < 3 && enable_srgb_framebuffer) {
					if (src_format == GL_SRGB8_ALPHA8)
						val = srgb_to_linear(val);
					if (dst_format == GL_SRGB8_ALPHA8)
						val = linear_to_srgb(val);
				}

				expected_data[(y * PATTERN_WIDTH + x)
					      * 4 + component] = val;
			}
		}
	}

	glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
	pass = piglit_probe_image_rgba(0, 0, PATTERN_WIDTH, PATTERN_HEIGHT,
				       expected_data);
	free(expected_data);
	return pass;
}
예제 #4
0
enum piglit_result
piglit_display(void)
{
	int x, y;
	bool pass = true;
	float expected[64 * 64 * 4];

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

	for (x = 0; x < 8; x++) {
		for (y = 0; y < 8; y++) {
			piglit_Uniform2i(coord1_location, x * 9, y * 9);
			piglit_Uniform2i(coord2_location, x * 9, y * 9);
			piglit_draw_rect(-1.0 + 0.25 * x,
					 -1.0 + 0.25 * y,
					 0.25,
					 0.25);
		}
	}

	for (x = 0; x < 64; x++) {
		for (y = 0; y < 64; y++) {
			int sx = x % 8;
			int sy = y % 8;
			int dx = fabs(sx - x / 8);
			int dy = fabs(sy - y / 8);
			float pixel[4];

			if (dx == 0 && dy == 0) {
				pixel[0] = 0.0;
				pixel[1] = 1.0;
				pixel[2] = 0.0;
				pixel[3] = 0.0;
			} else {
				int i;

				pixel[0] = 0.0;
				pixel[1] = 0.0;
				pixel[2] = 0.0;
				pixel[3] = 0.0;

				for (i = 0; i < 10; i += (dx + dy))
					pixel[2] += 0.1;
			}

			memcpy(expected + (y * 64 + x) * 4, pixel, 4 * 4);
		}
	}

	pass = piglit_probe_image_rgba(0, 0, 64, 64, expected);

	piglit_present_results();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
예제 #5
0
enum piglit_result
piglit_display(void)
{
    float red[4]   = {1.0, 0.0, 0.0, 0.0};
    float green[4] = {0.0, 1.0, 0.0, 0.25};
    float blue[4]  = {0.0, 0.0, 1.0, 0.5};
    float white[4] = {1.0, 1.0, 1.0, 1.0};
    float grey[4]  = {0.5, 0.5, 0.5, 0.5};
    bool pass;
    float *ref_image;

    /* Draw the source image to src_fbo */
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, src_fbo);
    glEnable(GL_SCISSOR_TEST);

    glScissor(0, 0, width / 2, height / 2);
    glClearColor(red[0], red[1], red[2], red[3]);
    glClear(GL_COLOR_BUFFER_BIT);

    glScissor(width / 2, 0, width / 2, height / 2);
    glClearColor(green[0], green[1], green[2], green[3]);
    glClear(GL_COLOR_BUFFER_BIT);

    glScissor(0, height / 2, width / 2, height / 2);
    glClearColor(blue[0], blue[1], blue[2], blue[3]);
    glClear(GL_COLOR_BUFFER_BIT);

    glScissor(width / 2, height / 2, width / 2, height / 2);
    glClearColor(white[0], white[1], white[2], white[3]);
    glClear(GL_COLOR_BUFFER_BIT);

    glDisable(GL_SCISSOR_TEST);

    glClearColor(grey[0], grey[1], grey[2], grey[3]);

    /* Blit to dst_fbo, scissoring the image in an asymmetrical way. */
    glBindFramebuffer(GL_READ_FRAMEBUFFER, src_fbo);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dst_fbo);
    glClear(GL_COLOR_BUFFER_BIT);
    glEnable(GL_SCISSOR_TEST);
    glScissor(10, 20, width - 40, height - 60);
    glBlitFramebuffer(0, 0, width, height,
                      0, 0, width, height,
                      GL_COLOR_BUFFER_BIT, GL_NEAREST);
    glDisable(GL_SCISSOR_TEST);

    /* Blit to ref_fbo, simulating the correct scissoring effect
     * by manually adjusting the coordinates.
     */
    glBindFramebuffer(GL_READ_FRAMEBUFFER, src_fbo);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ref_fbo);
    glClear(GL_COLOR_BUFFER_BIT);
    glBlitFramebuffer(10, 20, width - 30, height - 40,
                      10, 20, width - 30, height - 40,
                      GL_COLOR_BUFFER_BIT, GL_NEAREST);

    /* Read the reference image from ref_fbo */
    ref_image = malloc(sizeof(float) * 4 * width * height);
    glBindFramebuffer(GL_READ_FRAMEBUFFER, ref_fbo);
    glReadPixels(0, 0, width, height, GL_RGBA, GL_FLOAT, ref_image);

    /* Compare the image in dst_fbo with the reference image */
    glBindFramebuffer(GL_READ_FRAMEBUFFER, dst_fbo);
    pass = piglit_probe_image_rgba(0, 0, width, height, ref_image);

    if (dst_fbo != 0) {
        /* Show the contents of dst_fbo in the window */
        glBindFramebuffer(GL_READ_FRAMEBUFFER, dst_fbo);
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
        glBlitFramebuffer(0, 0, width, height,
                          0, 0, width, height,
                          GL_COLOR_BUFFER_BIT, GL_NEAREST);
    }

    piglit_present_results();

    return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
enum piglit_result
piglit_display(void)
{
	GLuint r8_tex, gr88_tex;
	float *ref_rgba_image;

	GLuint va; /* vertex array */
	GLuint vb; /* vertex buffer */
	GLuint prog;

	static const float vb_data[] = {
		-1, -1,
		 1, -1,
		 1,  1,
		-1,  1,
	};

	if (piglit_width != WINDOW_WIDTH ||
	    piglit_height != WINDOW_HEIGHT) {
		piglit_loge("window is not %dx%d",
			    WINDOW_WIDTH, WINDOW_HEIGHT);
		return PIGLIT_FAIL;
	}

	create_textures(&r8_tex, &gr88_tex, &ref_rgba_image);

	prog = piglit_build_simple_program(
		"#version 300 es\n"
		"\n"
		"in vec2 a_position;\n"
		"out vec2 v_texcoord;\n"
		"\n"
		"void main()\n"
		"{\n"
		"	gl_Position = vec4(a_position, 0, 1);\n"
		"\n"
		"	v_texcoord = a_position;\n"
		"	v_texcoord += vec2(1, 1);\n"
		"	v_texcoord /= vec2(2, 2);\n"
		"}\n",

		"#version 300 es\n"
		"\n"
		"precision highp float;\n"
		"uniform sampler2D u_r8_tex;\n"
		"uniform sampler2D u_gr88_tex;\n"
		"in vec2 v_texcoord;\n"
		"out vec4 f_color;\n"
		"\n"
		"void main()\n"
		"{\n"
		"	float y = texture(u_r8_tex, v_texcoord).r;\n"
		"	vec2 uv = texture(u_gr88_tex, v_texcoord).rg;\n"
		"\n"
		"	/* A very fake NV12->RGB conversion */\n"
		"	f_color = vec4(y, uv.r, uv.g, 1);\n"
		"}\n");

	glUseProgram(prog);

	glUniform1i(glGetUniformLocation(prog, "u_r8_tex"), 0);
	glUniform1i(glGetUniformLocation(prog, "u_gr88_tex"), 1);

	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);

	glGenBuffers(1, &vb);
	glBindBuffer(GL_ARRAY_BUFFER, vb);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vb_data), vb_data,
		     GL_STATIC_DRAW);

	glGenVertexArrays(1, &va);
	glBindVertexArray(va);

	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void *) 0);
	glEnableVertexAttribArray(0);

	glViewport(0, 0, piglit_width, piglit_height);
	glClearColor(0.2, 0.2, 0.2, 0.2);
	glClear(GL_COLOR_BUFFER_BIT);
	glDrawArrays(GL_TRIANGLE_FAN, /*first*/ 0, /*count*/ 4);

	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);

	/* Increase the tolerance because the conversion path
	 *     ubyte --(texturing)--> float --(glReadPixels)--> ubyte
	 * is lossy.
	 */
	piglit_tolerance[0] = 0.05;
	piglit_tolerance[1] = 0.05;
	piglit_tolerance[2] = 0.05;
	if (!piglit_probe_image_rgba(0, 0, piglit_width, piglit_height,
				     ref_rgba_image)) {
		return PIGLIT_FAIL;
	}

	return PIGLIT_PASS;
}
예제 #7
0
/* Test for one set of factor levels */
bool
run_factor_set(GLenum src_factor_rgb, GLenum src_factor_a,
	       GLenum dst_factor_rgb, GLenum dst_factor_a,
	       GLenum op_rgb, GLenum op_a,
	       const GLfloat constant_color[4])
{
	int i, j;
	bool pass = true;

	glDisable(GL_DITHER);
	glClear(GL_COLOR_BUFFER_BIT);

	/* Send dst image to the framebuffer. */
	glDisable(GL_BLEND);
	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, dst_img.name);
	piglit_draw_rect_tex(0, 0, img_width, img_height, 0, 0, 1, 1);
	pass &= piglit_check_gl_error(GL_NO_ERROR);

	/*
	 * Read back the contents of the framebuffer, and measure any
	 * difference from what was actually written.  We can't tell
	 * whether errors occurred when writing or when reading back,
	 * but at least we can report anything unusual.
	 */
	pass &= piglit_probe_image_rgba(0, 0, img_width, 
		img_height, dst_img.data);

	/*
	 * Now apply the blending
	 * operation to both the framebuffer and a copy in the image
	 * ``expected''.  Note that a fresh source alpha must be
	 * generated here, because the range of source alpha values is
	 * not limited by the range of alpha values that can be
	 * represented in the framebuffer.  Save the source pixels in
	 * the image ``src'' so we can diagnose any problems we find
	 * later.
	 */

	/* Configure the appropriate blending settings */
	if (have_sep_func)
		glBlendFuncSeparate(src_factor_rgb, dst_factor_rgb,
                                    src_factor_a, dst_factor_a);
	else
		glBlendFunc(src_factor_rgb, dst_factor_rgb);

	if (have_blend_equation_sep)
		glBlendEquationSeparate(op_rgb, op_a);
	else if (have_blend_equation)
		glBlendEquation(op_rgb);


	/* Send src to the framebuffer and let GL blend it with dst */
	glEnable(GL_BLEND);
	glBindTexture(GL_TEXTURE_2D, src_img.name);
	piglit_draw_rect_tex(0, 0, img_width, img_height, 0, 0, 1, 1);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_BLEND);
	pass &= piglit_check_gl_error(GL_NO_ERROR);

	/* Compute the appropriate expected. */
	for (j = 0; j < img_height; ++j) {
		for (i = 0; i < img_width; ++i) {

			int idx = 4*(img_width*j + i);
			
			/* Initialize expected with dst data. */
			exp_img.data[idx + 0] = dst_img.data[idx + 0]; 
			exp_img.data[idx + 1] = dst_img.data[idx + 1];
			exp_img.data[idx + 2] = dst_img.data[idx + 2];
			exp_img.data[idx + 3] = dst_img.data[idx + 3];

			/* Apply the blending. */
			apply_blend(src_factor_rgb, src_factor_a,
				    dst_factor_rgb, dst_factor_a,
				    op_rgb, op_a,
				    &exp_img.data[idx], &src_img.data[idx], 
				    constant_color);
		}
	}

	/*
	 * Compare the image in the framebuffer to the
	 * computed image (``expected'') to see if any pixels are
	 * outside the expected tolerance range. 
	 */
	pass &= piglit_probe_image_rgba(0, 0, img_width, img_height, 
		exp_img.data);


	return pass;
} /* run_factor_set */