bool
test_fbo_attachment_targets(GLenum texOneType, GLenum texTwoType,
				 GLenum expectedFbStatus)
{
	bool pass = true;
	GLuint fbo, texture[2];

	glGenTextures(2, texture);

	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

	/* Setup texture one */
	texture[0] = create_bind_texture(texOneType);
	attach_texture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
		       texOneType, texture[0]);

	/* Setup texture two */
	texture[1] = create_bind_texture(texTwoType);
	attach_texture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
		       texTwoType, texture[1]);

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

	/* Check for expected fb status */
	pass = CheckFramebufferStatus(expectedFbStatus) && pass;

	/* Clean up */
	glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
	glDeleteFramebuffers(1, &fbo);
	glDeleteTextures(2, texture);

	return pass;
}
bool
test_fbo_attachments_layered()
{
	bool pass = true;
	GLuint fbo, texture[2];

	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

	/* Attach first texture as a layered texture */
	texture[0] = create_bind_texture(GL_TEXTURE_3D);
	glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
			     texture[0], 0);

	/* Attach a single layer of the second texture.(Non layered) */
	texture[1] = create_bind_texture(GL_TEXTURE_3D);
	glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
			       GL_TEXTURE_3D, texture[1], 0, 0);

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

	pass = CheckFramebufferStatus(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS)
		&& pass;

	glDeleteFramebuffers(1, &fbo);
	glDeleteTextures(2, texture);

	return pass;
}
bool
test_framebuffertexture(GLenum textureType)
{
	bool pass = true;
	GLuint fbo, texture;

	float expected[] = { 0, 1, 0 };

	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

	texture = create_bind_texture(textureType);

	/* Attach the texture to the framebuffer object */
	glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
			     texture, 0);

	if(!piglit_check_gl_error(GL_NO_ERROR) ||
	   !check_framebuffer_status(GL_FRAMEBUFFER, GL_FRAMEBUFFER_COMPLETE)) {
		glDeleteFramebuffers(1, &fbo);
		glDeleteTextures(1, &texture);
		printf("Texture Type: %s. Error during setup.\n",
		       piglit_get_gl_enum_name(textureType));
		return false;
	}

	piglit_draw_rect(-1, -1, 2, 2);

	/* If the texture is a multisample texture,
	 * convert it to a 2D texture */
	if(textureType == GL_TEXTURE_2D_MULTISAMPLE ||
	   textureType == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) {
		ConvertMultiSample2DToTexture2D(fbo);
	}

	/* Probe for the expected color value */
	if(textureType == GL_TEXTURE_1D ||
	   textureType == GL_TEXTURE_1D_ARRAY) {
		if(!piglit_probe_rect_rgb(0, 0, 6, 1, expected)) {
			pass = false;
		}
	} else {
		if(!piglit_probe_rect_rgb(0, 0, 6, 6, expected)) {
			pass = false;
		}
	}

	/* Clean up */
	glDeleteFramebuffers(1, &fbo);
	glDeleteTextures(1, &texture);

	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	return pass;
}
void
piglit_init(int argc, char **argv)
{
	int i;
	bool pass = true;
	GLenum fbStatus;
	GLuint fbo, texture;
	GLint attachmentLayeredStatus;

	for(i = 0; i < ARRAY_SIZE(textureType); i++) {
		glGenFramebuffers(1, &fbo);
		glBindFramebuffer(GL_FRAMEBUFFER, fbo);

		texture = create_bind_texture(textureType[i]);
		glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
				     texture, 0);

		if(!piglit_check_gl_error(GL_NO_ERROR)) {
			printf("Error creating texture and framebuffer setup\n"
			       "texture type: %s\n",
			       piglit_get_gl_enum_name(textureType[i]));
			glDeleteFramebuffers(1, &fbo);
			glDeleteTextures(1, &texture);
			piglit_report_result(PIGLIT_FAIL);
		}

		fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
		if(fbStatus != GL_FRAMEBUFFER_COMPLETE) {
			printf("Framebuffer Status: %s\n",
				piglit_get_gl_enum_name(fbStatus));
			glDeleteFramebuffers(1, &fbo);
			glDeleteTextures(1, &texture);
			piglit_report_result(PIGLIT_FAIL);
		}

		/* Check if the attachment is layered */
		glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
						      GL_COLOR_ATTACHMENT0,
						      GL_FRAMEBUFFER_ATTACHMENT_LAYERED,
						      &attachmentLayeredStatus);

		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

		if(attachmentLayeredStatus != GL_TRUE) {
			pass = false;
		}

		glDeleteFramebuffers(1, &fbo);
		glDeleteTextures(1, &texture);
	}

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
/* Take a framebuffer object, that has a GL_TEXTURE_2D_MULTISAMPLE
 * or a layer of a GL_TEXTURE_2D_MULTISAMPLE_ARRAY attached to
 * color attachment 0. Then blit that framebuffer object to
 * a new fbo that has a GL_TEXTURE_2D attached. Finally
 * attach the new GL_TEXTURE_2D to the original fbo.
 */
void
ConvertMultiSample2DToTexture2D(GLuint fboRead) {
	GLuint fboDraw, texture;

	glGenFramebuffers(1, &fboDraw);
	glGenTextures(1, &texture);

	glBindFramebuffer(GL_READ_FRAMEBUFFER, fboRead);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboDraw);

	texture = create_bind_texture(GL_TEXTURE_2D);
	glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
			       GL_TEXTURE_2D, texture, 0);

	if(!check_framebuffer_status(GL_DRAW_FRAMEBUFFER,
				     GL_FRAMEBUFFER_COMPLETE) ||
	   !check_framebuffer_status(GL_READ_FRAMEBUFFER,
				     GL_FRAMEBUFFER_COMPLETE)) {

		piglit_report_result(PIGLIT_FAIL);
	}

	glBlitFramebuffer(0, 0, 6, 6, 0, 0, 6, 6,
			  GL_COLOR_BUFFER_BIT, GL_NEAREST);

	if(!piglit_check_gl_error(GL_NO_ERROR)) {
		glDeleteTextures(1, &texture);
		piglit_report_result(PIGLIT_FAIL);
	}

	glBindFramebuffer(GL_FRAMEBUFFER, fboRead);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
			       GL_TEXTURE_2D, texture, 0);

	glDeleteFramebuffers(1, &fboDraw);

	if(!piglit_check_gl_error(GL_NO_ERROR)) {
		glDeleteTextures(1, &texture);
		piglit_report_result(PIGLIT_FAIL);
	}
}
void
piglit_init(int argc, char **argv)
{
	int j;
	bool pass = true;
	GLuint fbo, texture, program;

	static const float colors[6*3] = {
		0, 0, 1,
		0, 1, 0,
		0, 1, 1,
		1, 0, 0,
		1, 0, 1,
		1, 1, 0
	};

	program = piglit_build_simple_program_multiple_shaders(
					GL_VERTEX_SHADER, vs_source,
					GL_GEOMETRY_SHADER, gs_source,
					GL_FRAGMENT_SHADER, fs_source,
					0);
	glUseProgram(program);

	/* Retrieve index from vs */
	color_uniform = glGetUniformLocation(program, "color");
	layer_uniform = glGetUniformLocation(program, "layer");

	/* Gen textures */
	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

	texture = create_bind_texture();
	glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
			     texture, 0);

	if(!check_framebuffer_status(GL_FRAMEBUFFER,
				     GL_FRAMEBUFFER_COMPLETE) ||
	   !piglit_check_gl_error(GL_NO_ERROR)) {
		printf("Error with setup\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	/* draw quad on each layer with set color*/
	glProvokingVertex(GL_LAST_VERTEX_CONVENTION);
	for(j = 0; j < 6; j++) {
		if (j == 3) {
			glProvokingVertex(GL_FIRST_VERTEX_CONVENTION);
		}
		glUniform1i(layer_uniform, j);
		glUniform3fv(color_uniform, 1, &colors[j*3]);
		/* rect larger than vp */
		piglit_draw_rect(-2, -2, 4, 4);
	}

	pass = probe_texture_layered_rgb(texture,
					 0, 0, 0, 6, 6, 6, colors) && pass;

	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	/* Clean up */
	glDeleteTextures(1, &texture);
	glDeleteFramebuffers(1, &fbo);

	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
Example #7
0
File: blit.c Project: Zoxc/piglit
bool
testFramebufferBlitLayered(int x, int y, bool srcLayered, bool dstLayered)
{
	bool pass = true;
	GLuint srcFBO, dstFBO;
	GLuint srcTex, dstTex;
	GLenum fbStatus;

	/* Set up source fbo */
	glGenFramebuffers(1, &srcFBO);
	glBindFramebuffer(GL_FRAMEBUFFER, srcFBO);

	piglit_check_gl_error(GL_NO_ERROR);
	if (srcLayered) {
		srcTex = create_bind_texture(GL_TEXTURE_3D, true);
		glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
				     srcTex, 0);
	} else {
		srcTex = create_bind_texture(GL_TEXTURE_2D, true);
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
				     GL_TEXTURE_2D, srcTex, 0);
	}

	/* Check source framebuffer status */
	fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
	if (fbStatus != GL_FRAMEBUFFER_COMPLETE) {
		printf("testFramebufferBlitLayered srcFBO Status: %s\n",
		       piglit_get_gl_enum_name(fbStatus));
		return false;
	}

	/* Set up dstt fbo */
	glGenFramebuffers(1, &dstFBO);
	glBindFramebuffer(GL_FRAMEBUFFER, dstFBO);

	if (dstLayered) {
		dstTex = create_bind_texture(GL_TEXTURE_3D, false);
		glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
				     dstTex, 0);
	} else {
		dstTex = create_bind_texture(GL_TEXTURE_2D, false);
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
				       GL_TEXTURE_2D, dstTex, 0);
	}

	/* Check destination framebuffer status */
	fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
	if (fbStatus != GL_FRAMEBUFFER_COMPLETE) {
		printf("testFramebufferBlitLayered dstFBO Status: %s\n",
		       piglit_get_gl_enum_name(fbStatus));
		return false;
	}

	/* Check for if any errors have occured */
	if (!piglit_check_gl_error(GL_NO_ERROR)) {
		printf("Error setting up framebuffers for test.\n");
		return false;
	}

	/* Blit from source to destination framebuffers */
	glBindFramebuffer(GL_READ_FRAMEBUFFER, srcFBO);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dstFBO);
	glBlitFramebuffer(0, 0, texWidth, texHeight,
			  0, 0, texWidth, texHeight,
			  GL_COLOR_BUFFER_BIT, GL_LINEAR);

	/* Display the results */
	display_texture(x, y, srcTex, srcLayered ? texDepth : 1);
	display_texture(x + texWidth, y, dstTex, dstLayered ? texDepth : 1);

	/* Check for pass condition */
	if (dstLayered) {
		pass = piglit_probe_rect_rgb(x + texWidth, y,
                                texWidth, texHeight, srcColors[0]) && pass;
		pass = piglit_probe_rect_rgb(x + texWidth, y + texHeight,
                                texWidth, texHeight, dstColors[1]) && pass;
	} else {
		pass = piglit_probe_rect_rgb(x + texWidth, y, texWidth,
                                texDepth * texHeight, srcColors[0]) && pass;
	}

	/* Clean up */
	glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
	glDeleteFramebuffers(1, &srcFBO);
	glDeleteFramebuffers(1, &dstFBO);
	glDeleteTextures(1, &srcTex);
	glDeleteTextures(1, &dstTex);

	/* Check for if any errors have occured */
	if (!piglit_check_gl_error(GL_NO_ERROR)) {
		printf("Error setting up framebuffers for test.\n");
		return false;
	}

	return pass;
}