Example #1
0
static bool
test_3d_tex_format(GLenum internalFormat)
{
	GLint width, height, depth;
	bool pass = true;
	unsigned mbytes;

	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	/* use proxy texture to find actual max texture size */
	width = height = depth = 0;
	find_max_tex3d_size(internalFormat, MaxSize,
			    &width, &height, &depth);

	mbytes = tex_size(internalFormat, width, height, depth);
	printf("Actual max 3D texture size for %s: %d x %d x %d (%u MB)\n",
	       piglit_get_gl_enum_name(internalFormat),
	       width, height, depth, mbytes);

	/* first, try some smaller res 3D texture rendering */
	pass = test_render(internalFormat, width, height, depth/4);
	pass = test_render(internalFormat, width, height, depth/2) && pass;

	/* test largest 3D texture size */
	pass = test_render(internalFormat, width, height, depth) && pass;

	return pass;
}
Example #2
0
enum piglit_result
piglit_display(void)
{
	GLuint tex;
	GLint maxsize, width, height, depth;
	GLenum err;
	char *data;
	int i, j;
	GLboolean pass = GL_TRUE;
	float c1[4] = {0.25, 0.25, 0.25, 1.0};
	float c2[4] = {0.75, 0.75, 0.75, 1.0};

	glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &maxsize);

	/* Create the texture. */
	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_3D, tex);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	if (glGetError())
		return PIGLIT_FAIL;

	glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, maxsize, maxsize, maxsize, 0,
		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);

	err = glGetError();

	if (err == GL_OUT_OF_MEMORY) {

		/* use proxy texture to find working max texture size */
		find_max_tex3d_size(maxsize, &width, &height, &depth);

		glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, width, height, depth, 0,
			     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
		err = glGetError();

		if (err == GL_OUT_OF_MEMORY)
			return PIGLIT_PASS;
	}
	else {
		/* the max 3D texture size actually worked */
		width = height = depth = maxsize;
	}

	if (err != GL_NO_ERROR) {
		printf("%s: unexpected glTexImage3D error: 0x%x\n",
		       TestName, err);
		return PIGLIT_FAIL;
	}

	if (0)
		printf("max 3D texture size = %d x %d x %d\n",
		       width, height, depth);

	/* Set its pixels, slice by slice. */
	data = malloc(width * height * 4);
	for (j = 0; j < height; j++)
		for (i = 0; i < width; i++) {
			int a = (j * width + i) * 4;
			data[a+0] =
			data[a+1] =
			data[a+2] =
			data[a+3] = (i * 255) / (width - 1);
		}

	for (i = 0; i < depth; i++) {
		glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, i, width, height, 1,
				GL_RGBA, GL_UNSIGNED_BYTE, data);
	}
	free(data);

	/* Now try basic rendering. */
	glEnable(GL_TEXTURE_3D);
	glBegin(GL_QUADS);
	glTexCoord3f(0, 0, 1);
	glVertex2f(0, 0);
	glTexCoord3f(0, 1, 1);
	glVertex2f(0, piglit_height);
	glTexCoord3f(1, 1, 1);
	glVertex2f(piglit_width, piglit_height);
	glTexCoord3f(1, 0, 1);
	glVertex2f(piglit_width, 0);
	glEnd();
	glDeleteTextures(1, &tex);

	pass = piglit_probe_pixel_rgb(piglit_width * 1 / 4,
				      piglit_height * 1 / 4, c1) && pass;
	pass = piglit_probe_pixel_rgb(piglit_width * 3 / 4,
				      piglit_height * 1 / 4, c2) && pass;
	pass = piglit_probe_pixel_rgb(piglit_width * 1 / 4,
				      piglit_height * 3 / 4, c1) && pass;
	pass = piglit_probe_pixel_rgb(piglit_width * 3 / 4,
				      piglit_height * 3 / 4, c2) && pass;
	glutSwapBuffers();

	if (!pass) {
		printf("%s: failed at size %d x %d x %d\n", TestName,
		       width, height, depth);
	}

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}