Example #1
0
float *
get_image_chunk(texture_info * tex, int xmin, int ymin, int xmax, int ymax)
{
    int xbound;
    int ybound;
    float * image_buf = NULL;

    constrain_boundaries(&xmin, &ymin, &xmax, &ymax, tex->width, tex->height);

    xbound = xmax - xmin + 1;
    ybound = ymax - ymin + 1;

    image_buf = allocate_texture(xbound, ybound);

    for(int y = 0; y < ybound; y++)
        for(int x = 0; x < xbound; x++) {
            int buf_index = 4 * (x + y * xbound);

            int offset = calc_pixel_offset(tex, x + xmin, y + ymin);

            color_copy(tex->td_array + offset, image_buf + buf_index);
        }

    return image_buf;
}
Example #2
0
void
piglit_init(int argc, char **argv)
{
	GLuint vs, fs_paint_red, fs_sample;
	GLenum fb_status;

	/* Parse params */
	if (argc != 3)
		print_usage_and_exit(argv[0]);
	if (strcmp(argv[1], "sample") == 0)
		subtest = SUBTEST_SAMPLE;
	else if (strcmp(argv[1], "read_pixels") == 0)
		subtest = SUBTEST_READ_PIXELS;
	else if (strcmp(argv[1], "blit") == 0)
		subtest = SUBTEST_BLIT;
	else if (strcmp(argv[1], "copy") == 0)
		subtest = SUBTEST_COPY;
	else
		print_usage_and_exit(argv[0]);
	if (strcmp(argv[2], "rb") == 0)
		use_texture = false;
	else if (strcmp(argv[2], "tex") == 0)
		use_texture = true;
	else
		print_usage_and_exit(argv[0]);

	/* Detect parameter conflicts */
	if (subtest == SUBTEST_SAMPLE && !use_texture) {
		printf("Subtest 'sample' requires buffer_type 'tex'.\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	/* Requirements */
	piglit_require_gl_version(11);
	piglit_require_GLSL_version(110);
	piglit_require_extension("GL_ARB_framebuffer_object");

	/* Compile shaders */
	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
	fs_paint_red = piglit_compile_shader_text(GL_FRAGMENT_SHADER,
						  fs_text_paint_red);
	prog_paint_red = piglit_link_simple_program(vs, fs_paint_red);
	if (!prog_paint_red)
		piglit_report_result(PIGLIT_FAIL);
	fs_sample = piglit_compile_shader_text(GL_FRAGMENT_SHADER,
					       fs_text_sample);
	prog_sample = piglit_link_simple_program(vs, fs_sample);
	if (!prog_sample)
		piglit_report_result(PIGLIT_FAIL);
	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);

	/* Set up framebuffer */
	glGenFramebuffers(1, &fb);
	glBindFramebuffer(GL_FRAMEBUFFER, fb);
	if (use_texture) {
		tex1 = allocate_texture();
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
				       GL_TEXTURE_2D, tex1, 0 /* level */);
	} else {
		GLuint rb;
		glGenRenderbuffers(1, &rb);
		glBindRenderbuffer(GL_RENDERBUFFER, rb);
		glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA,
				      TEX_WIDTH, TEX_HEIGHT);
		glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
					  GL_RENDERBUFFER, rb);
	}
	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);
	fb_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
	if (fb_status != GL_FRAMEBUFFER_COMPLETE) {
		printf("Framebuffer status: %s\n",
		       piglit_get_gl_enum_name(fb_status));
		piglit_report_result(PIGLIT_FAIL);
	}

	/* Set up second texture (used by "copy" test only) */
	if (subtest == SUBTEST_COPY)
		tex2 = allocate_texture();
	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);
}